Merge "OutputPage: Reduce getTitleInfo() calls (improve preloading)"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 20 Oct 2016 22:18:38 +0000 (22:18 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 20 Oct 2016 22:18:38 +0000 (22:18 +0000)
includes/OutputPage.php
includes/exception/PermissionsError.php
includes/installer/DatabaseUpdater.php
includes/specialpage/FormSpecialPage.php

index 8e34a5a..dea5292 100644 (file)
@@ -2392,10 +2392,14 @@ class OutputPage extends ContextSource {
        /**
         * Output a standard permission error page
         *
-        * @param array $errors Error message keys
+        * @param array $errors Error message keys or [key, param...] arrays
         * @param string $action Action that was denied or null if unknown
         */
        public function showPermissionsErrorPage( array $errors, $action = null ) {
+               foreach ( $errors as $key => $error ) {
+                       $errors[$key] = (array)$error;
+               }
+
                // For some action (read, edit, create and upload), display a "login to do this action"
                // error if all of the following conditions are met:
                // 1. the user is not logged in
index bd0b120..e31374c 100644 (file)
@@ -29,12 +29,19 @@ class PermissionsError extends ErrorPageError {
        public $permission, $errors;
 
        /**
-        * @param string $permission A permission name.
-        * @param string[] $errors Error message keys
+        * @param string|null $permission A permission name or null if unknown
+        * @param array $errors Error message keys or [key, param...] arrays; must not be empty if
+        *   $permission is null
+        * @throws \InvalidArgumentException
         */
        public function __construct( $permission, $errors = [] ) {
                global $wgLang;
 
+               if ( $permission === null && !$errors ) {
+                       throw new \InvalidArgumentException( __METHOD__ .
+                               ': $permission and $errors cannot both be empty' );
+               }
+
                $this->permission = $permission;
 
                if ( !count( $errors ) ) {
index 6f066ce..6a702e9 100644 (file)
@@ -222,12 +222,11 @@ abstract class DatabaseUpdater {
         *
         * @since 1.17
         *
-        * @param array $update The update to run. Format is the following:
-        *                first item is the callback function, it also can be a
-        *                simple string with the name of a function in this class,
-        *                following elements are parameters to the function.
-        *                Note that callback functions will receive this object as
-        *                first parameter.
+        * @param array $update The update to run. Format is [ $callback, $params... ]
+        *   $callback is the method to call; either a DatabaseUpdater method name or a callable.
+        *   Must be serializable (ie. no anonymous functions allowed). The rest of the parameters
+        *   (if any) will be passed to the callback. The first parameter passed to the callback
+        *   is always this object.
         */
        public function addExtensionUpdate( array $update ) {
                $this->extensionUpdates[] = $update;
index c28c456..66c7d47 100644 (file)
@@ -107,14 +107,15 @@ abstract class FormSpecialPage extends SpecialPage {
                        $form->addHeaderText( $headerMsg->parseAsBlock() );
                }
 
-               // Retain query parameters (uselang etc)
-               $params = array_diff_key(
-                       $this->getRequest()->getQueryValues(), [ 'title' => null ] );
-               $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
-
                $form->addPreText( $this->preText() );
                $form->addPostText( $this->postText() );
                $this->alterForm( $form );
+               if ( $form->getMethod() == 'post' ) {
+                       // Retain query parameters (uselang etc) on POST requests
+                       $params = array_diff_key(
+                               $this->getRequest()->getQueryValues(), [ 'title' => null ] );
+                       $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
+               }
 
                // Give hooks a chance to alter the form, adding extra fields or text etc
                Hooks::run( 'SpecialPageBeforeFormDisplay', [ $this->getName(), &$form ] );