jenkins-bot has submitted this change and it was merged.
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. For simplicity,
it is hidden by default, but custom JavaScript or similar techniques allow
it to be used.
Change-Id: Ib7a6b65d0caa58e9a39e8e6dbb647a911a32c780
---
M TemplateSandbox.hooks.php
M TemplateSandbox.i18n.php
2 files changed, 25 insertions(+), 3 deletions(-)
Approvals:
Anomie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/TemplateSandbox.hooks.php b/TemplateSandbox.hooks.php
index 76decc3..616a07f 100644
--- a/TemplateSandbox.hooks.php
+++ b/TemplateSandbox.hooks.php
@@ -24,10 +24,12 @@
* @return bool
*/
public static function importFormData( $editpage, $request ) {
- $editpage->templatesandbox_page = '';
+ $editpage->templatesandbox_template = $request->getText(
+ 'wpTemplateSandboxTemplate',
$editpage->getTitle()->getFullText()
+ );
+ $editpage->templatesandbox_page = $request->getText(
'wpTemplateSandboxPage' );
if ( $request->wasPosted() ) {
- $editpage->templatesandbox_page = $request->getText(
'wpTemplateSandboxPage' );
if ( $request->getCheck( 'wpTemplateSandboxPreview' ) )
{
$editpage->templatesandbox_preview = true;
@@ -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 {
@@ -231,6 +245,10 @@
$html .= Xml::tags( 'div', $textAttrs, $text->parse() )
. "\n";
}
+ $html .= Html::input( 'wpTemplateSandboxTemplate',
+ $editpage->templatesandbox_template, 'hidden', array(
'id' => 'wpTemplateSandboxTemplate' )
+ );
+
$labelText = wfMessage( 'templatesandbox-editform-page-label' );
if ( !$labelText->isDisabled() ) {
$spanLabelAttrs = array(
diff --git a/TemplateSandbox.i18n.php b/TemplateSandbox.i18n.php
index 2f358be..63d50c5 100644
--- a/TemplateSandbox.i18n.php
+++ b/TemplateSandbox.i18n.php
@@ -41,7 +41,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.',
);
@@ -86,7 +88,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: merged
Gerrit-Change-Id: Ib7a6b65d0caa58e9a39e8e6dbb647a911a32c780
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/TemplateSandbox
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits