[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/extensions/InputBox/ -> InputBox.hooks.php (source)

   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', array( '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          if ( $special->getName() == 'Movepage' && $prefix !== '' && $title !== '' ) {
  26              $request->setVal( 'wpNewTitle', $prefix . $title );
  27              $request->unsetVal( 'prefix' );
  28          }
  29          return true;
  30      }
  31  
  32      // Render the input box
  33  	public static function render( $input, $args, Parser $parser ) {
  34          // Create InputBox
  35          $inputBox = new InputBox( $parser );
  36  
  37          // Configure InputBox
  38          $inputBox->extractOptions( $parser->replaceVariables( $input ) );
  39  
  40          // Return output
  41          return $inputBox->render();
  42      }
  43  
  44      /**
  45       * <inputbox type=create...> sends requests with action=edit, and
  46       * possibly a &prefix=Foo.  So we pick that up here, munge prefix
  47       * and title together, and redirect back out to the real page
  48       * @param $output OutputPage
  49       * @param $article Article
  50       * @param $title Title
  51       * @param $user User
  52       * @param $request WebRequest
  53       * @param $wiki MediaWiki
  54       * @return bool
  55       */
  56  	public static function onMediaWikiPerformAction(
  57          $output,
  58          $article,
  59          $title,
  60          $user,
  61          $request,
  62          $wiki
  63      ) {
  64          if( $wiki->getAction( $request ) !== 'edit' ){
  65              # not our problem
  66              return true;
  67          }
  68          if( $request->getText( 'prefix', '' ) === '' ){
  69              # Fine
  70              return true;
  71          }
  72  
  73          $params = $request->getValues();
  74          $title = $params['prefix'];
  75          if ( isset( $params['title'] ) ) {
  76              $title .= $params['title'];
  77          }
  78          unset( $params['prefix'] );
  79          $params['title'] = $title;
  80  
  81          global $wgScript;
  82          $output->redirect( wfAppendQuery( $wgScript, $params ), '301' );
  83          return false;
  84      }
  85  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1