Jackmcbarn has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/83389


Change subject: Allow changing name of template being previewed
......................................................................

Allow changing name of template being previewed

Allow the template being replaced to be one with a different name than the
one being edited. This allows, for example, Template:X/sandbox to be
edited, but the change previewed as if it were Template:X.

Change-Id: Ib7a6b65d0caa58e9a39e8e6dbb647a911a32c780
---
M TemplateSandbox.hooks.php
M TemplateSandbox.i18n.php
2 files changed, 45 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateSandbox 
refs/changes/89/83389/1

diff --git a/TemplateSandbox.hooks.php b/TemplateSandbox.hooks.php
index 76decc3..d7b8971 100644
--- a/TemplateSandbox.hooks.php
+++ b/TemplateSandbox.hooks.php
@@ -24,9 +24,11 @@
         * @return bool
         */
        public static function importFormData( $editpage, $request ) {
+               $editpage->templatesandbox_template = 
$editpage->getTitle()->getFullText();
                $editpage->templatesandbox_page = '';
 
                if ( $request->wasPosted() ) {
+                       $editpage->templatesandbox_template = 
$request->getText( 'wpTemplateSandboxTemplate' );
                        $editpage->templatesandbox_page = $request->getText( 
'wpTemplateSandboxPage' );
 
                        if ( $request->getCheck( 'wpTemplateSandboxPreview' ) ) 
{
@@ -70,8 +72,20 @@
                        return true;
                }
 
+               if ( $editpage->templatesandbox_template === '' || 
$editpage->templatesandbox_template === null ) {
+                       $out = TemplateSandboxHooks::wrapErrorMsg( 
'templatesandbox-editform-need-template' );
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
                if ( $editpage->templatesandbox_page === '' || 
$editpage->templatesandbox_page === null ) {
                        $out = TemplateSandboxHooks::wrapErrorMsg( 
'templatesandbox-editform-need-title' );
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+
+               $templatetitle = Title::newFromText( 
$editpage->templatesandbox_template );
+               if ( !$templatetitle instanceof Title ) {
+                       $out = TemplateSandboxHooks::wrapErrorMsg( 
'templatesandbox-editform-invalid-template' );
                        wfProfileOut( __METHOD__ );
                        return false;
                }
@@ -93,7 +107,7 @@
                $parserOutput = null;
 
                try {
-                       TemplateSandboxHooks::$template = 
$editpage->getTitle()->getFullText();
+                       TemplateSandboxHooks::$template = 
$templatetitle->getFullText();
                        if ( $editpage->sectiontitle !== '' ) {
                                $sectionTitle = $editpage->sectiontitle;
                        } else {
@@ -216,6 +230,13 @@
 
                $html = '';
 
+               $templateInputAttrs = array(
+                       'id' => 'wpTemplateSandboxTemplate',
+                       'tabindex' => ++$tabindex,
+                       'size' => 60,
+                       'spellcheck' => 'true',
+               );
+
                $inputAttrs = array(
                        'id' => 'wpTemplateSandboxPage',
                        'tabindex' => ++$tabindex,
@@ -231,6 +252,23 @@
                        $html .= Xml::tags( 'div', $textAttrs, $text->parse() ) 
. "\n";
                }
 
+               $templateLabelText = wfMessage( 
'templatesandbox-editform-template-label' );
+               if ( !$templateLabelText->isDisabled() ) {
+                       $spanTemplateLabelAttrs = array(
+                               'class' => 'mw-templatesandbox-template',
+                               'id' => "wpTemplateSandboxTemplateLabel"
+                       );
+                       $tlabel = Xml::tags( 'label', array( 'for' => 
$inputAttrs['id'] ), $templateLabelText->parse() );
+                       $tlabel = Xml::tags( 'span', $spanTemplateLabelAttrs, 
$tlabel );
+                       $html .= $tlabel . " ";
+               }
+
+               $html .= Html::input( 'wpTemplateSandboxTemplate',
+                       $editpage->templatesandbox_template, 'text', 
$templateInputAttrs
+               );
+
+               $html .= "<br />\n";
+
                $labelText = wfMessage( 'templatesandbox-editform-page-label' );
                if ( !$labelText->isDisabled() ) {
                        $spanLabelAttrs = array(
diff --git a/TemplateSandbox.i18n.php b/TemplateSandbox.i18n.php
index 2f358be..feaccd2 100644
--- a/TemplateSandbox.i18n.php
+++ b/TemplateSandbox.i18n.php
@@ -27,6 +27,7 @@
 
        'templatesandbox-editform-legend' => 'Preview page with this template',
        'templatesandbox-editform-text' => '',
+       'templatesandbox-editform-template-label' => 'Template name:',
        'templatesandbox-editform-page-label' => 'Page title:',
        'templatesandbox-editform-view-label' => 'Show preview',
        'templatesandbox-editform-helptext' => '',
@@ -41,7 +42,9 @@
        'templatesandbox-prefix-not-local' => 'The sandbox prefix you specified 
is not local.',
        'templatesandbox-page-or-revid' => 'You must enter either a page title 
or a revision ID number.',
 
+       'templatesandbox-editform-need-template' => 'To preview another page 
with this template, a template name must be specified.',
        'templatesandbox-editform-need-title' => 'To preview another page with 
this template, a page title must be specified.',
+       'templatesandbox-editform-invalid-template' => 'The name of the 
template you specified is invalid.',
        'templatesandbox-editform-invalid-title' => 'The title you specified 
for previewing is invalid.',
        'templatesandbox-editform-title-not-exists' => 'The title you specified 
for previewing does not exist.',
 );
@@ -62,6 +65,7 @@
 
 The form has fieldset label {{msg-mw|Templatesandbox-legend}}.',
        'templatesandbox-prefix-label' => 'Label for the "prefix" input field.',
+       'templatesandbox-template-label' => 'Label for the "template" input 
field on the special page.',
        'templatesandbox-page-label' => 'Label for the "page" input field on 
the special page.',
        'templatesandbox-revid-label' => 'Label for the "revid" input field on 
the special page.',
        'templatesandbox-text-label' => 'Label for the "text" input field on 
the special page.',
@@ -86,7 +90,9 @@
        'templatesandbox-invalid-prefix' => 'Error message displayed when the 
sandbox prefix specified in the special page is invalid.',
        'templatesandbox-prefix-not-local' => 'Error message displayed when the 
sandbox prefix specified in the special page is not local.',
        'templatesandbox-page-or-revid' => 'Error message displayed when 
neither a page title nor rev_id is given in the special page.',
+       'templatesandbox-editform-need-template' => 'Error message displayed 
when no template name is given for the editpage form.',
        'templatesandbox-editform-need-title' => 'Error message displayed when 
no page title is given for the editpage form.',
+       'templatesandbox-editform-invalid-template' => 'Error message displayed 
when the template name specified for the editpage form is invalid.',
        'templatesandbox-editform-invalid-title' => 'Error message displayed 
when the title specified for the editpage form is invalid.',
        'templatesandbox-editform-title-not-exists' => 'Error message displayed 
when the title specified for the editpage form does not exist.',
 );

-- 
To view, visit https://gerrit.wikimedia.org/r/83389
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7a6b65d0caa58e9a39e8e6dbb647a911a32c780
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateSandbox
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to