diff --git a/InputBox.classes.php b/InputBox.classes.php index b3fdd0cb..1b34519b 100644 --- a/InputBox.classes.php +++ b/InputBox.classes.php @@ -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 */ diff --git a/InputBox.hooks.php b/InputBox.hooks.php index 7cc60549..75fe6790 100644 --- a/InputBox.hooks.php +++ b/InputBox.hooks.php @@ -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 diff --git a/InputBox.php b/InputBox.php index c54065a7..6473bd7b 100644 --- a/InputBox.php +++ b/InputBox.php @@ -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'; diff --git a/i18n/en.json b/i18n/en.json index 2d04c8ee..07879202 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -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" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 35c944f3..0a8e9212 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -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}}" } \ No newline at end of file