]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - extensions/InputBox/InputBox.hooks.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / extensions / InputBox / InputBox.hooks.php
1 <?php
2 /**
3  * Hooks for InputBox extension
4  *
5  * @file
6  * @ingroup Extensions
7  */
8
9 // InputBox hooks
10 class InputBoxHooks {
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
49         /**
50          * <inputbox type=create...> sends requests with action=edit, and
51          * possibly a &prefix=Foo.  So we pick that up here, munge prefix
52          * and title together, and redirect back out to the real page
53          * @param $output OutputPage
54          * @param $article Article
55          * @param $title Title
56          * @param $user User
57          * @param $request WebRequest
58          * @param $wiki MediaWiki
59          * @return bool
60          */
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
86                 global $wgScript;
87                 $output->redirect( wfAppendQuery( $wgScript, $params ), '301' );
88                 return false;
89         }
90 }