(bug 6640) add a prefix= parameter to creation inputboxes; using a intercept/munge/redirect method stolen from Wikia.

This commit is contained in:
Happy-melon 2010-03-18 19:11:12 +00:00
parent 0003f0e6d9
commit c30239bf87
3 changed files with 54 additions and 0 deletions

View file

@ -325,6 +325,13 @@ class InputBox {
'value' => $this->mSummary,
)
);
$htmlOut .= Xml::openElement( 'input',
array(
'type' => 'hidden',
'name' => 'prefix',
'value' => $this->mPrefix,
)
);
$htmlOut .= Xml::openElement( 'input',
array(
'type' => 'hidden',

View file

@ -31,4 +31,50 @@ class InputBoxHooks {
// Return output
return $inputBox->render();
}
/**
* <inputbox type=create...> sends requests with action=edit, and
* possibly a &prefix=Foo. So we pick that up here, munge prefix
* and title together, and redirect back out to the real page
* @param $output OutputPage
* @param $article Article
* @param $title Title
* @param $user User
* @param $request WebRequest
* @param $wiki MediaWiki
* @return True
*/
public static function onMediaWikiPerformAction(
$output,
$article,
$title,
$user,
$request,
$wiki )
{
$action = $wiki->getVal( 'Action' );
if( $action !== 'edit' ){
# not our problem
return true;
}
if( $request->getText( 'prefix', '' ) === '' ){
# Fine
return true;
}
$params = $request->getValues();
$title = $params['prefix'] . @$params['title'];
unset( $params['prefix'] );
unset( $params['title'] );
$url = "?title=$title";
foreach( $params as $key => $value ){
if( $key ){
$url .= "&{$key}={$value}";
}
}
global $wgScript;
$output->redirect( $wgScript . $url, '301' );
return false;
}
}

View file

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