mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/InputBox
synced 2024-11-27 16:39:59 +00:00
(bug 6640) add a prefix= parameter to creation inputboxes; using a intercept/munge/redirect method stolen from Wikia.
This commit is contained in:
parent
0003f0e6d9
commit
c30239bf87
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,3 +49,4 @@ $wgAutoloadClasses['InputBox'] = $dir . 'InputBox.classes.php';
|
|||
|
||||
// Register parser hook
|
||||
$wgHooks['ParserFirstCallInit'][] = 'InputBoxHooks::register';
|
||||
$wgHooks['MediaWikiPerformAction'][] = 'InputBoxHooks::onMediaWikiPerformAction';
|
||||
|
|
Loading…
Reference in a new issue