2008-10-27 20:33:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Hooks for InputBox extension
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
2017-10-14 13:45:46 +00:00
|
|
|
/**
|
|
|
|
* InputBox hooks
|
|
|
|
*/
|
2008-10-27 20:33:18 +00:00
|
|
|
class InputBoxHooks {
|
2017-10-14 13:45:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization
|
|
|
|
* @param Parser &$parser
|
|
|
|
* @return true
|
|
|
|
*/
|
2012-08-30 16:20:32 +00:00
|
|
|
public static function register( Parser &$parser ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
// Register the hook with the parser
|
2017-05-18 18:09:49 +00:00
|
|
|
$parser->setHook( 'inputbox', [ 'InputBoxHooks', 'render' ] );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Continue
|
|
|
|
return true;
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2017-10-14 13:45:46 +00:00
|
|
|
/**
|
|
|
|
* Prepend prefix to wpNewTitle if necessary
|
|
|
|
* @param SpecialPage $special
|
|
|
|
* @param string $subPage
|
|
|
|
* @return true
|
|
|
|
*/
|
2014-04-05 20:43:15 +00:00
|
|
|
public static function onSpecialPageBeforeExecute( $special, $subPage ) {
|
|
|
|
$request = $special->getRequest();
|
|
|
|
$prefix = $request->getText( 'prefix', '' );
|
|
|
|
$title = $request->getText( 'wpNewTitle', '' );
|
2017-06-06 18:45:30 +00:00
|
|
|
$search = $request->getText( 'search', '' );
|
|
|
|
$searchfilter = $request->getText( 'searchfilter', '' );
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $special->getName() == 'Movepage' && $prefix !== '' && $title !== '' ) {
|
2014-04-05 20:43:15 +00:00
|
|
|
$request->setVal( 'wpNewTitle', $prefix . $title );
|
|
|
|
$request->unsetVal( 'prefix' );
|
|
|
|
}
|
2017-06-06 18:45:30 +00:00
|
|
|
if ( $special->getName() == 'Search' && $searchfilter !== '' ) {
|
|
|
|
$request->setVal( 'search', $search . ' ' . $searchfilter );
|
|
|
|
}
|
2014-04-05 20:43:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-14 13:45:46 +00:00
|
|
|
/**
|
|
|
|
* Render the input box
|
|
|
|
* @param string $input
|
|
|
|
* @param array $args
|
|
|
|
* @param Parser $parser
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-08-30 16:20:32 +00:00
|
|
|
public static function render( $input, $args, Parser $parser ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
// Create InputBox
|
|
|
|
$inputBox = new InputBox( $parser );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Configure InputBox
|
|
|
|
$inputBox->extractOptions( $parser->replaceVariables( $input ) );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Return output
|
|
|
|
return $inputBox->render();
|
|
|
|
}
|
2014-05-18 09:07:27 +00:00
|
|
|
|
2010-03-18 19:11:12 +00:00
|
|
|
/**
|
2014-05-18 09:07:27 +00:00
|
|
|
* <inputbox type=create...> sends requests with action=edit, and
|
|
|
|
* possibly a &prefix=Foo. So we pick that up here, munge prefix
|
2010-03-18 19:11:12 +00:00
|
|
|
* and title together, and redirect back out to the real page
|
2017-10-14 13:45:46 +00:00
|
|
|
* @param OutputPage $output
|
|
|
|
* @param Article $article
|
|
|
|
* @param Title $title
|
|
|
|
* @param User $user
|
|
|
|
* @param WebRequest $request
|
|
|
|
* @param MediaWiki $wiki
|
2012-08-30 16:20:32 +00:00
|
|
|
* @return bool
|
2010-03-18 19:11:12 +00:00
|
|
|
*/
|
2014-05-18 09:07:27 +00:00
|
|
|
public static function onMediaWikiPerformAction(
|
|
|
|
$output,
|
|
|
|
$article,
|
|
|
|
$title,
|
|
|
|
$user,
|
|
|
|
$request,
|
|
|
|
$wiki
|
|
|
|
) {
|
2017-06-20 07:09:00 +00:00
|
|
|
if ( $wiki->getAction( $request ) !== 'edit' ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
// not our problem
|
2010-03-18 19:11:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-20 07:09:00 +00:00
|
|
|
if ( $request->getText( 'prefix', '' ) === '' ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
// Fine
|
2010-03-18 19:11:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-18 09:07:27 +00:00
|
|
|
|
2010-03-18 19:11:12 +00:00
|
|
|
$params = $request->getValues();
|
2010-03-18 20:04:20 +00:00
|
|
|
$title = $params['prefix'];
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( isset( $params['title'] ) ) {
|
2010-03-18 20:04:20 +00:00
|
|
|
$title .= $params['title'];
|
2010-03-18 19:11:12 +00:00
|
|
|
}
|
2010-03-18 20:04:20 +00:00
|
|
|
unset( $params['prefix'] );
|
|
|
|
$params['title'] = $title;
|
2014-05-18 09:07:27 +00:00
|
|
|
|
2010-03-18 19:11:12 +00:00
|
|
|
global $wgScript;
|
2010-03-18 20:04:20 +00:00
|
|
|
$output->redirect( wfAppendQuery( $wgScript, $params ), '301' );
|
2010-03-18 19:11:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
}
|