Allow InputBoxes to be used to move pages

Add an option to InputBoxes to allow them to prefill Special:MovePage with
prefixes and other similar options to pages being created

Change-Id: I1740497030b5e9872162a1a261ac38791bb1373a
This commit is contained in:
Jackmcbarn 2014-04-05 16:43:15 -04:00
parent f14419180a
commit c3fd290fff
5 changed files with 89 additions and 0 deletions

View file

@ -52,6 +52,8 @@ class InputBox {
case 'create':
case 'comment':
return $this->getCreateForm();
case 'move':
return $this->getMoveForm();
case 'commenttitle':
return $this->getCommentForm();
case 'search':
@ -420,6 +422,78 @@ class InputBox {
return $htmlOut;
}
/**
* Generate move page form
*/
public function getMoveForm() {
global $wgScript;
if ( !$this->mButtonLabel ) {
$this->mButtonLabel = wfMessage( 'inputbox-movearticle' )->text();
}
$htmlOut = Xml::openElement( 'div',
array(
'style' => 'margin-left: auto; margin-right: auto; text-align: center; background-color:' . $this->mBGColor
)
);
$moveBoxParams = array(
'name' => 'movebox',
'class' => 'mw-movebox',
'action' => $wgScript,
'method' => 'get'
);
if( $this->mID !== '' ) {
$moveBoxParams['id'] = Sanitizer::escapeId( $this->mID );
}
$htmlOut .= Xml::openElement( 'form', $moveBoxParams );
$htmlOut .= Xml::openElement( 'input',
array(
'type' => 'hidden',
'name' => 'title',
'value' => SpecialPage::getTitleFor( 'Movepage', $this->mPage )->getPrefixedText(),
)
);
$htmlOut .= Xml::openElement( 'input',
array(
'type' => 'hidden',
'name' => 'wpReason',
'value' => $this->mSummary,
)
);
$htmlOut .= Xml::openElement( 'input',
array(
'type' => 'hidden',
'name' => 'prefix',
'value' => $this->mPrefix,
)
);
$htmlOut .= Xml::openElement( 'input',
array(
'type' => $this->mHidden ? 'hidden' : 'text',
'name' => 'wpNewTitle',
'class' => 'mw-moveboxInput',
'value' => $this->mDefaultText,
'placeholder' => $this->mPlaceholderText,
'size' => $this->mWidth,
'dir' => $this->mDir,
)
);
$htmlOut .= $this->mBR;
$htmlOut .= Xml::openElement( 'input',
array(
'type' => 'submit',
'class' => 'mw-moveboxButton',
'value' => $this->mButtonLabel
)
);
$htmlOut .= Xml::closeElement( 'form' );
$htmlOut .= Xml::closeElement( 'div' );
// Return HTML
return $htmlOut;
}
/**
* Generate new section form
*/

View file

@ -17,6 +17,18 @@ class InputBoxHooks {
return true;
}
// Prepend prefix to wpNewTitle if necessary
public static function onSpecialPageBeforeExecute( $special, $subPage ) {
$request = $special->getRequest();
$prefix = $request->getText( 'prefix', '' );
$title = $request->getText( 'wpNewTitle', '' );
if( $special->getName() == 'Movepage' && $prefix !== '' && $title !== '' ) {
$request->setVal( 'wpNewTitle', $prefix . $title );
$request->unsetVal( 'prefix' );
}
return true;
}
// Render the input box
public static function render( $input, $args, Parser $parser ) {
// Create InputBox

View file

@ -53,3 +53,4 @@ $wgAutoloadClasses['InputBox'] = $dir . 'InputBox.classes.php';
// Register parser hook
$wgHooks['ParserFirstCallInit'][] = 'InputBoxHooks::register';
$wgHooks['MediaWikiPerformAction'][] = 'InputBoxHooks::onMediaWikiPerformAction';
$wgHooks['SpecialPageBeforeExecute'][] = 'InputBoxHooks::onSpecialPageBeforeExecute';

View file

@ -8,5 +8,6 @@
"inputbox-tryexact": "Try exact match",
"inputbox-searchfulltext": "Search full text",
"inputbox-createarticle": "Create page",
"inputbox-movearticle": "Move page",
"inputbox-ns-main": "Main"
}

View file

@ -15,5 +15,6 @@
"tryexact": "Part of the \"Inputbox\" extension. This message is the text of the button to search the page you typed in the inputbox. If the page with the exact name exists, you will go directly to that page.",
"searchfulltext": "Part of the \"Inputbox\" extension. This message is the text of the button to search the page you typed in the inputbox. This button always goes to the search page, even if the page with the exact name exists.\n\nSee also:\n* {{msg-mw|Search}}\n* {{msg-mw|Accesskey-search-fulltext}}\n* {{msg-mw|Tooltip-search-fulltext}}",
"createarticle": "Part of the \"Inputbox\" extension. This message is the text of the button to create the page you typed in the inputbox.\n{{Identical|Create page}}",
"inputbox-movearticle": "Part of the \"Inputbox\" extension. This message is the text of the button to move the page to the name you typed in the inputbox.",
"inputbox-ns-main": "Probably refers to the main namespace.\n{{Identical|Main}}"
}