MediaWiki  1.30.0
InputBox.hooks.php
Go to the documentation of this file.
1 <?php
9 // InputBox hooks
11  // Initialization
12  public static function register( Parser &$parser ) {
13  // Register the hook with the parser
14  $parser->setHook( 'inputbox', [ 'InputBoxHooks', 'render' ] );
15 
16  // Continue
17  return true;
18  }
19 
20  // Prepend prefix to wpNewTitle if necessary
21  public static function onSpecialPageBeforeExecute( $special, $subPage ) {
22  $request = $special->getRequest();
23  $prefix = $request->getText( 'prefix', '' );
24  $title = $request->getText( 'wpNewTitle', '' );
25  $search = $request->getText( 'search', '' );
26  $searchfilter = $request->getText( 'searchfilter', '' );
27  if ( $special->getName() == 'Movepage' && $prefix !== '' && $title !== '' ) {
28  $request->setVal( 'wpNewTitle', $prefix . $title );
29  $request->unsetVal( 'prefix' );
30  }
31  if ( $special->getName() == 'Search' && $searchfilter !== '' ) {
32  $request->setVal( 'search', $search . ' ' . $searchfilter );
33  }
34  return true;
35  }
36 
37  // Render the input box
38  public static function render( $input, $args, Parser $parser ) {
39  // Create InputBox
40  $inputBox = new InputBox( $parser );
41 
42  // Configure InputBox
43  $inputBox->extractOptions( $parser->replaceVariables( $input ) );
44 
45  // Return output
46  return $inputBox->render();
47  }
48 
61  public static function onMediaWikiPerformAction(
62  $output,
63  $article,
64  $title,
65  $user,
66  $request,
67  $wiki
68  ) {
69  if ( $wiki->getAction( $request ) !== 'edit' ) {
70  // not our problem
71  return true;
72  }
73  if ( $request->getText( 'prefix', '' ) === '' ) {
74  // Fine
75  return true;
76  }
77 
78  $params = $request->getValues();
79  $title = $params['prefix'];
80  if ( isset( $params['title'] ) ) {
81  $title .= $params['title'];
82  }
83  unset( $params['prefix'] );
84  $params['title'] = $title;
85 
87  $output->redirect( wfAppendQuery( $wgScript, $params ), '301' );
88  return false;
89  }
90 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
InputBoxHooks::onSpecialPageBeforeExecute
static onSpecialPageBeforeExecute( $special, $subPage)
Definition: InputBox.hooks.php:21
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:202
InputBoxHooks::render
static render( $input, $args, Parser $parser)
Definition: InputBox.hooks.php:38
$params
$params
Definition: styleTest.css.php:40
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2198
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
InputBox
Definition: InputBox.classes.php:10
InputBoxHooks::onMediaWikiPerformAction
static onMediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki)
<inputbox type="create..."> sends requests with action=edit, and possibly a &prefix=Foo.
Definition: InputBox.hooks.php:61
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:534
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
InputBoxHooks
Definition: InputBox.hooks.php:10
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
$article
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
Definition: hooks.txt:77
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:2572
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$request
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2581
$special
this hook is for auditing only RecentChangesLinked and Watchlist $special
Definition: hooks.txt:988
$args
if( $line===false) $args
Definition: cdb.php:63