Merge "Add WatchedItemStoreUnitTest::newWatchedItemStore"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 1 Apr 2016 14:54:13 +0000 (14:54 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 1 Apr 2016 14:54:13 +0000 (14:54 +0000)
14 files changed:
RELEASE-NOTES-1.27
includes/htmlform/HTMLAutoCompleteSelectField.php
includes/htmlform/HTMLButtonField.php
includes/htmlform/HTMLEditTools.php
includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php
includes/htmlform/HTMLFormFieldCloner.php
includes/htmlform/HTMLSelectAndOtherField.php
includes/htmlform/HTMLTextAreaField.php
includes/htmlform/HTMLTextField.php
includes/libs/StatusValue.php
includes/session/Session.php
includes/specials/SpecialUserrights.php
includes/upload/UploadBase.php

index 915b93b..e8924ef 100644 (file)
@@ -259,6 +259,7 @@ HHVM 3.1.
 * OutputPage::getScript() was removed (deprecated since 1.24).
 * OutputPage::out() was removed (deprecated since 1.22).
 * OutputPage::setAllowedModules() was removed (deprecated since 1.24).
+* UserrightsPage::makeGroupNameListForLog() was removed (deprecated since 1.21).
 
 === Languages updated in 1.27 ===
 
index 6606ca3..76a88d5 100644 (file)
@@ -53,7 +53,7 @@ class HTMLAutoCompleteSelectField extends HTMLTextField {
                $this->getOptions();
                if ( $this->mOptions && !in_array( 'other', $this->mOptions, true ) ) {
                        if ( isset( $params['other-message'] ) ) {
-                               $msg = wfMessage( $params['other-message'] )->text();
+                               $msg = $this->getMessage( $params['other-message'] )->text();
                        } elseif ( isset( $params['other'] ) ) {
                                $msg = $params['other'];
                        } else {
index 16417fc..70bbf6c 100644 (file)
@@ -35,16 +35,7 @@ class HTMLButtonField extends HTMLFormField {
 
                # Generate the label from a message, if possible
                if ( isset( $info['buttonlabel-message'] ) ) {
-                       $msgInfo = $info['buttonlabel-message'];
-
-                       if ( is_array( $msgInfo ) ) {
-                               $msg = array_shift( $msgInfo );
-                       } else {
-                               $msg = $msgInfo;
-                               $msgInfo = [];
-                       }
-
-                       $this->buttonLabel = $this->msg( $msg, $msgInfo )->parse();
+                       $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
                } elseif ( isset( $info['buttonlabel'] ) ) {
                        if ( $info['buttonlabel'] === '&#160;' ) {
                                // Apparently some things set &nbsp directly and in an odd format
@@ -79,13 +70,14 @@ class HTMLButtonField extends HTMLFormField {
                        'id' => $this->mID,
                        'type' => $this->buttonType,
                        'name' => $this->mName,
-                       'value' => $value,
+                       'value' => $this->getDefault(),
                ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
 
                if ( $this->isBadIE() ) {
                        return Html::element( 'input', $attr );
                } else {
-                       return Html::rawElement( 'button', $attr, $this->buttonLabel ?: htmlspecialchars( $value ) );
+                       return Html::rawElement( 'button', $attr,
+                               $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
                }
        }
 
@@ -97,10 +89,10 @@ class HTMLButtonField extends HTMLFormField {
        public function getInputOOUI( $value ) {
                return new OOUI\ButtonInputWidget( [
                        'name' => $this->mName,
-                       'value' => $value,
+                       'value' => $this->getDefault(),
                        'label' => !$this->isBadIE() && $this->buttonLabel
                                ? new OOUI\HtmlSnippet( $this->buttonLabel )
-                               : $value,
+                               : $this->getDefault(),
                        'type' => $this->buttonType,
                        'classes' => [ 'mw-htmlform-submit', $this->mClass ],
                        'id' => $this->mID,
index 77924ef..1b5d1fb 100644 (file)
@@ -39,7 +39,7 @@ class HTMLEditTools extends HTMLFormField {
                if ( empty( $this->mParams['message'] ) ) {
                        $msg = $this->msg( 'edittools' );
                } else {
-                       $msg = $this->msg( $this->mParams['message'] );
+                       $msg = $this->getMessage( $this->mParams['message'] );
                        if ( $msg->isDisabled() ) {
                                $msg = $this->msg( 'edittools' );
                        }
index bf46e55..25e7f8c 100644 (file)
  *                             Some field types support multi-level arrays.
  *    'options-messages'    -- associative array mapping message keys to values.
  *                             Some field types support multi-level arrays.
- *    'options-message'     -- message key to be parsed to extract the list of
+ *    'options-message'     -- message key or object to be parsed to extract the list of
  *                             options (like 'ipbreason-dropdown').
- *    'label-message'       -- message key for a message to use as the label.
+ *    'label-message'       -- message key or object for a message to use as the label.
  *                             can be an array of msg key and then parameters to
  *                             the message.
  *    'label'               -- alternatively, a raw text message. Overridden by
  *                             label-message
  *    'help'                -- message text for a message to use as a help text.
- *    'help-message'        -- message key for a message to use as a help text.
+ *    'help-message'        -- message key or object for a message to use as a help text.
  *                             can be an array of msg key and then parameters to
  *                             the message.
  *                             Overwrites 'help-messages' and 'help'.
- *    'help-messages'       -- array of message key. As above, each item can
+ *    'help-messages'       -- array of message keys/objects. As above, each item can
  *                             be an array of msg key and then parameters.
  *                             Overwrites 'help'.
  *    'required'            -- passed through to the object, indicating that it
@@ -180,6 +180,7 @@ class HTMLForm extends ContextSource {
        protected $mSectionFooters = [];
        protected $mPost = '';
        protected $mId;
+       protected $mName;
        protected $mTableId = '';
 
        protected $mSubmitID;
@@ -1006,6 +1007,9 @@ class HTMLForm extends ContextSource {
                if ( !empty( $this->mAutocomplete ) ) {
                        $attribs['autocomplete'] = $this->mAutocomplete;
                }
+               if ( !empty ( $this->mName ) ) {
+                       $attribs['name'] = $this->mName;
+               }
                return $attribs;
        }
 
@@ -1347,6 +1351,16 @@ class HTMLForm extends ContextSource {
                return $this;
        }
 
+       /**
+        * @param string$ name 'name' attribute for the form
+        * @return HTMLForm $this for chaining calls
+        */
+       public function setName( $name ) {
+               $this->mName = $name;
+
+               return $this;
+       }
+
        /**
         * Prompt the whole form to be wrapped in a "<fieldset>", with
         * this text as its "<legend>" element.
index a9c7632..e86d4c4 100644 (file)
@@ -179,7 +179,7 @@ abstract class HTMLFormField {
                                        return true;
 
                                case 'OR':
-                                       foreach ( $params as $p ) {
+                                       foreach ( $params as $i => $p ) {
                                                if ( !is_array( $p ) ) {
                                                        throw new MWException(
                                                                "Expected array, found " . gettype( $p ) . " at index $i"
@@ -205,7 +205,7 @@ abstract class HTMLFormField {
                                        return false;
 
                                case 'NOR':
-                                       foreach ( $params as $p ) {
+                                       foreach ( $params as $i => $p ) {
                                                if ( !is_array( $p ) ) {
                                                        throw new MWException(
                                                                "Expected array, found " . gettype( $p ) . " at index $i"
@@ -381,16 +381,7 @@ abstract class HTMLFormField {
 
                # Generate the label from a message, if possible
                if ( isset( $params['label-message'] ) ) {
-                       $msgInfo = $params['label-message'];
-
-                       if ( is_array( $msgInfo ) ) {
-                               $msg = array_shift( $msgInfo );
-                       } else {
-                               $msg = $msgInfo;
-                               $msgInfo = [];
-                       }
-
-                       $this->mLabel = $this->msg( $msg, $msgInfo )->parse();
+                       $this->mLabel = $this->getMessage( $params['label-message'] )->parse();
                } elseif ( isset( $params['label'] ) ) {
                        if ( $params['label'] === '&#160;' ) {
                                // Apparently some things set &nbsp directly and in an odd format
@@ -783,9 +774,8 @@ abstract class HTMLFormField {
                }
 
                if ( isset( $this->mParams['help-messages'] ) ) {
-                       foreach ( $this->mParams['help-messages'] as $name ) {
-                               $helpMessage = (array)$name;
-                               $msg = $this->msg( array_shift( $helpMessage ), $helpMessage );
+                       foreach ( $this->mParams['help-messages'] as $msg ) {
+                               $msg = $this->getMessage( $msg );
 
                                if ( $msg->exists() ) {
                                        if ( is_null( $helptext ) ) {
@@ -988,7 +978,7 @@ abstract class HTMLFormField {
                                $this->mOptions = self::forceToStringRecursive( $this->mParams['options'] );
                        } elseif ( array_key_exists( 'options-message', $this->mParams ) ) {
                                /** @todo This is copied from Xml::listDropDown(), deprecate/avoid duplication? */
-                               $message = $this->msg( $this->mParams['options-message'] )->inContentLanguage()->plain();
+                               $message = $this->getMessage( $this->mParams['options-message'] )->inContentLanguage()->plain();
 
                                $optgroup = false;
                                $this->mOptions = [];
@@ -1097,4 +1087,23 @@ abstract class HTMLFormField {
                        return Html::rawElement( 'span', [ 'class' => 'error' ], $errors );
                }
        }
+
+       /**
+        * Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a
+        * name + parameters array) into a Message.
+        * @param mixed $value
+        * @return Message
+        */
+       protected function getMessage( $value ) {
+               if ( $value instanceof Message ) {
+                       return $value;
+               } elseif ( $value instanceof MessageSpecifier ) {
+                       return Message::newFromKey( $value );
+               } elseif ( is_array( $value ) ) {
+                       $msg = array_shift( $value );
+                       return $this->msg( $msg, $value );
+               } else {
+                       return $this->msg( $value, [] );
+               }
+       }
 }
index 6553b56..4f2460f 100644 (file)
@@ -14,9 +14,9 @@
  *     'table', 'div', or 'raw'.
  *   row-legend - If non-empty, each group of subfields will be enclosed in a
  *     fieldset. The value is the name of a message key to use as the legend.
- *   create-button-message - Message key to use as the text of the button to
+ *   create-button-message - Message to use as the text of the button to
  *     add an additional group of fields.
- *   delete-button-message - Message key to use as the text of automatically-
+ *   delete-button-message - Message to use as the text of automatically-
  *     generated 'delete' button. Ignored if 'delete' is included in 'fields'.
  *
  * In the generated HTML, the subfields will be named along the lines of
@@ -299,7 +299,7 @@ class HTMLFormFieldCloner extends HTMLFormField {
                                'name' => $name,
                                'id' => Sanitizer::escapeId( "{$this->mID}--$key--delete" ),
                                'cssclass' => 'mw-htmlform-cloner-delete-button',
-                               'default' => $this->msg( $label )->text(),
+                               'default' => $this->getMessage( $label )->text(),
                        ], $this->mParent );
                        $v = $field->getDefault();
 
@@ -371,7 +371,7 @@ class HTMLFormFieldCloner extends HTMLFormField {
                        'name' => $name,
                        'id' => Sanitizer::escapeId( "{$this->mID}--create" ),
                        'cssclass' => 'mw-htmlform-cloner-create-button',
-                       'default' => $this->msg( $label )->text(),
+                       'default' => $this->getMessage( $label )->text(),
                ], $this->mParent );
                $html .= $field->getInputHTML( $field->getDefault() );
 
index e44ffa3..e75c2b2 100644 (file)
@@ -15,9 +15,9 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                if ( array_key_exists( 'other', $params ) ) {
                        // Do nothing
                } elseif ( array_key_exists( 'other-message', $params ) ) {
-                       $params['other'] = wfMessage( $params['other-message'] )->plain();
+                       $params['other'] = $this->getMessage( $params['other-message'] )->plain();
                } else {
-                       $params['other'] = wfMessage( 'htmlform-selectorother-other' )->plain();
+                       $params['other'] = $this->msg( 'htmlform-selectorother-other' )->plain();
                }
 
                parent::__construct( $params );
index 973f1cb..8ffff43 100644 (file)
@@ -4,6 +4,24 @@ class HTMLTextAreaField extends HTMLFormField {
        const DEFAULT_COLS = 80;
        const DEFAULT_ROWS = 25;
 
+       protected $mPlaceholder = '';
+
+       /**
+        * @param array $params
+        *   - cols, rows: textarea size
+        *   - placeholder/placeholder-message: set HTML placeholder attribute
+        *   - spellcheck: set HTML spellcheck attribute
+        */
+       public function __construct( $params ) {
+               parent::__construct( $params );
+
+               if ( isset( $params['placeholder-message'] ) ) {
+                       $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->parse();
+               } elseif ( isset( $params['placeholder'] ) ) {
+                       $this->mPlaceholder = $params['placeholder'];
+               }
+       }
+
        function getCols() {
                return isset( $this->mParams['cols'] ) ? $this->mParams['cols'] : static::DEFAULT_COLS;
        }
@@ -32,9 +50,11 @@ class HTMLTextAreaField extends HTMLFormField {
                if ( $this->mClass !== '' ) {
                        $attribs['class'] = $this->mClass;
                }
+               if ( $this->mPlaceholder !== '' ) {
+                       $attribs['placeholder'] = $this->mPlaceholder;
+               }
 
                $allowedParams = [
-                       'placeholder',
                        'tabindex',
                        'disabled',
                        'readonly',
@@ -56,9 +76,11 @@ class HTMLTextAreaField extends HTMLFormField {
                if ( $this->mClass !== '' ) {
                        $attribs['classes'] = [ $this->mClass ];
                }
+               if ( $this->mPlaceholder !== '' ) {
+                       $attribs['placeholder'] = $this->mPlaceholder;
+               }
 
                $allowedParams = [
-                       'placeholder',
                        'tabindex',
                        'disabled',
                        'readonly',
index 4d5bcab..3ab7176 100644 (file)
@@ -1,6 +1,27 @@
 <?php
 
 class HTMLTextField extends HTMLFormField {
+       protected $mPlaceholder = '';
+
+       /**
+        * @param array $params
+        *   - type: HTML textfield type
+        *   - size: field size in characters (defaults to 45)
+        *   - placeholder/placeholder-message: set HTML placeholder attribute
+        *   - spellcheck: set HTML spellcheck attribute
+        *   - persistent: upon unsuccessful requests, retain the value (defaults to true, except
+        *     for password fields)
+        */
+       public function __construct( $params ) {
+               parent::__construct( $params );
+
+               if ( isset( $params['placeholder-message'] ) ) {
+                       $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->parse();
+               } elseif ( isset( $params['placeholder'] ) ) {
+                       $this->mPlaceholder = $params['placeholder'];
+               }
+       }
+
        function getSize() {
                return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
        }
@@ -14,7 +35,19 @@ class HTMLTextField extends HTMLFormField {
                return null;
        }
 
+       public function isPersistent() {
+               if ( isset( $this->mParams['persistent'] ) ) {
+                       return $this->mParams['persistent'];
+               }
+               // don't put passwords into the HTML body, they could get cached or otherwise leaked
+               return !( isset( $this->mParams['type'] ) && $this->mParams['type'] === 'password' );
+       }
+
        function getInputHTML( $value ) {
+               if ( !$this->isPersistent() ) {
+                       $value = '';
+               }
+
                $attribs = [
                                'id' => $this->mID,
                                'name' => $this->mName,
@@ -27,6 +60,9 @@ class HTMLTextField extends HTMLFormField {
                if ( $this->mClass !== '' ) {
                        $attribs['class'] = $this->mClass;
                }
+               if ( $this->mPlaceholder !== '' ) {
+                       $attribs['placeholder'] = $this->mPlaceholder;
+               }
 
                # @todo Enforce pattern, step, required, readonly on the server side as
                # well
@@ -37,7 +73,6 @@ class HTMLTextField extends HTMLFormField {
                        'pattern',
                        'title',
                        'step',
-                       'placeholder',
                        'list',
                        'maxlength',
                        'tabindex',
@@ -85,11 +120,18 @@ class HTMLTextField extends HTMLFormField {
        }
 
        function getInputOOUI( $value ) {
+               if ( !$this->isPersistent() ) {
+                       $value = '';
+               }
+
                $attribs = $this->getTooltipAndAccessKey();
 
                if ( $this->mClass !== '' ) {
                        $attribs['classes'] = [ $this->mClass ];
                }
+               if ( $this->mPlaceholder !== '' ) {
+                       $attribs['placeholder'] = $this->mPlaceholder;
+               }
 
                # @todo Enforce pattern, step, required, readonly on the server side as
                # well
@@ -100,7 +142,6 @@ class HTMLTextField extends HTMLFormField {
                        'flags',
                        'indicator',
                        'maxlength',
-                       'placeholder',
                        'readonly',
                        'required',
                        'tabindex',
index b4206a2..10d4c71 100644 (file)
@@ -58,7 +58,7 @@ class StatusValue {
         * Factory function for fatal errors
         *
         * @param string|MessageSpecifier $message Message key or object
-        * @return Status
+        * @return StatusValue
         */
        public static function newFatal( $message /*, parameters...*/ ) {
                $params = func_get_args();
@@ -71,7 +71,7 @@ class StatusValue {
         * Factory function for good results
         *
         * @param mixed $value
-        * @return Status
+        * @return StatusValue
         */
        public static function newGood( $value = null ) {
                $result = new static();
index 0fd8fa8..b410e03 100644 (file)
@@ -335,7 +335,7 @@ final class Session implements \Countable, \Iterator, \ArrayAccess {
         *
         * @param string|string[] $salt Token salt
         * @param string $key Token key
-        * @return MediaWiki\\Session\\SessionToken
+        * @return MediaWiki\\Session\\Token
         */
        public function getToken( $salt = '', $key = 'default' ) {
                $new = false;
index 740f2f7..be110aa 100644 (file)
@@ -417,28 +417,18 @@ class UserrightsPage extends SpecialPage {
                return Status::newGood( $user );
        }
 
-       function makeGroupNameList( $ids ) {
-               if ( empty( $ids ) ) {
-                       return $this->msg( 'rightsnone' )->inContentLanguage()->text();
-               } else {
-                       return implode( ', ', $ids );
-               }
-       }
-
        /**
-        * Make a list of group names to be stored as parameter for log entries
+        * @since 1.15
         *
-        * @deprecated since 1.21; use LogFormatter instead.
         * @param array $ids
+        *
         * @return string
         */
-       function makeGroupNameListForLog( $ids ) {
-               wfDeprecated( __METHOD__, '1.21' );
-
+       public function makeGroupNameList( $ids ) {
                if ( empty( $ids ) ) {
-                       return '';
+                       return $this->msg( 'rightsnone' )->inContentLanguage()->text();
                } else {
-                       return $this->makeGroupNameList( $ids );
+                       return implode( ', ', $ids );
                }
        }
 
index 9d7b294..1185c4d 100644 (file)
@@ -645,9 +645,6 @@ abstract class UploadBase {
 
                if ( $this->mDesiredDestName != $filename && $comparableName != $filename ) {
                        $warnings['badfilename'] = $filename;
-                       // Debugging for bug 62241
-                       wfDebugLog( 'upload', "Filename: '$filename', mDesiredDestName: "
-                               . "'$this->mDesiredDestName', comparableName: '$comparableName'" );
                }
 
                // Check whether the file extension is on the unwanted list
@@ -666,7 +663,7 @@ abstract class UploadBase {
                }
 
                if ( $this->mFileSize == 0 ) {
-                       $warnings['emptyfile'] = true;
+                       $warnings['empty-file'] = true;
                }
 
                $exists = self::getExistsWarning( $localFile );