Merge "RCFilters: Make the interface not jump around while loading"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 21 Sep 2017 18:03:34 +0000 (18:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 21 Sep 2017 18:03:35 +0000 (18:03 +0000)
12 files changed:
RELEASE-NOTES-1.30
includes/DefaultSettings.php
includes/EditPage.php
includes/api/ApiEditPage.php
includes/media/MediaHandler.php
includes/registration/ExtensionJsonValidator.php
languages/i18n/en.json
languages/i18n/qqq.json
maintenance/refreshFileHeaders.php
resources/src/mediawiki.rcfilters/mw.rcfilters.init.js
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.MenuSelectWidget.js
tests/phpunit/includes/EditPageTest.php

index 8517a8f..513dc3a 100644 (file)
@@ -73,6 +73,7 @@ section).
 * (T138166) Added ability for users to prohibit other users from sending them
   emails with Special:Emailuser. Can be enabled by setting
   $wgEnableUserEmailBlacklist to true.
+* $wgBrowserBlacklist is deprecated, and changing it will have no effect.
 
 === External library changes in 1.30 ===
 
@@ -221,6 +222,7 @@ changes to languages because of Phabricator reports.
 * wfShellExec() and related functions are deprecated, use Shell::command().
 * (T138166) SpecialEmailUser::getTarget() now requires a second argument, the sending
   user object. Using the method without the second argument is deprecated.
+* (T67297) Browsers that don't support Unicode will have their edits rejected.
 
 == Compatibility ==
 MediaWiki 1.30 requires PHP 5.5.9 or later. There is experimental support for
index cdb7ce8..5630dcb 100644 (file)
@@ -2980,46 +2980,9 @@ $wgAllUnicodeFixes = false;
 $wgLegacyEncoding = false;
 
 /**
- * Browser Blacklist for unicode non compliant browsers. Contains a list of
- * regexps : "/regexp/"  matching problematic browsers. These browsers will
- * be served encoded unicode in the edit box instead of real unicode.
+ * @deprecated since 1.30, does nothing
  */
-$wgBrowserBlackList = [
-       /**
-        * Netscape 2-4 detection
-        * The minor version may contain strings such as "Gold" or "SGoldC-SGI"
-        * Lots of non-netscape user agents have "compatible", so it's useful to check for that
-        * with a negative assertion. The [UIN] identifier specifies the level of security
-        * in a Netscape/Mozilla browser, checking for it rules out a number of fakers.
-        * The language string is unreliable, it is missing on NS4 Mac.
-        *
-        * Reference: http://www.psychedelix.com/agents/index.shtml
-        */
-       '/^Mozilla\/2\.[^ ]+ [^(]*?\((?!compatible).*; [UIN]/',
-       '/^Mozilla\/3\.[^ ]+ [^(]*?\((?!compatible).*; [UIN]/',
-       '/^Mozilla\/4\.[^ ]+ [^(]*?\((?!compatible).*; [UIN]/',
-
-       /**
-        * MSIE on Mac OS 9 is teh sux0r, converts þ to <thorn>, ð to <eth>,
-        * Þ to <THORN> and Ð to <ETH>
-        *
-        * Known useragents:
-        * - Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)
-        * - Mozilla/4.0 (compatible; MSIE 5.15; Mac_PowerPC)
-        * - Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)
-        * - [...]
-        *
-        * @link https://en.wikipedia.org/w/index.php?diff=12356041&oldid=12355864
-        * @link https://en.wikipedia.org/wiki/Template%3AOS9
-        */
-       '/^Mozilla\/4\.0 \(compatible; MSIE \d+\.\d+; Mac_PowerPC\)/',
-
-       /**
-        * Google wireless transcoder, seems to eat a lot of chars alive
-        * https://it.wikipedia.org/w/index.php?title=Luciano_Ligabue&diff=prev&oldid=8857361
-        */
-       '/^Mozilla\/4\.0 \(compatible; MSIE 6.0; Windows NT 5.0; Google Wireless Transcoder;\)/'
-];
+$wgBrowserBlackList = [];
 
 /**
  * If set to true, the MediaWiki 1.4 to 1.5 schema conversion will
index 0ea61c0..1588f82 100644 (file)
@@ -40,6 +40,11 @@ use Wikimedia\ScopedCallback;
  * headaches, which may be fatal.
  */
 class EditPage {
+       /**
+        * Used for Unicode support checks
+        */
+       const UNICODE_CHECK = 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ';
+
        /**
         * Status: Article successfully updated
         */
@@ -177,6 +182,11 @@ class EditPage {
         */
        const AS_CANNOT_USE_CUSTOM_MODEL = 241;
 
+       /**
+        * Status: edit rejected because browser doesn't support Unicode.
+        */
+       const AS_UNICODE_NOT_SUPPORTED = 242;
+
        /**
         * HTML id and name for the beginning of the edit form.
         */
@@ -203,12 +213,18 @@ class EditPage {
         */
        const POST_EDIT_COOKIE_DURATION = 1200;
 
-       /** @var Article */
+       /**
+        * @deprecated for public usage since 1.30 use EditPage::getArticle()
+        * @var Article
+        */
        public $mArticle;
        /** @var WikiPage */
        private $page;
 
-       /** @var Title */
+       /**
+        * @deprecated for public usage since 1.30 use EditPage::getTitle()
+        * @var Title
+        */
        public $mTitle;
 
        /** @var null|Title */
@@ -220,16 +236,28 @@ class EditPage {
        /** @var bool */
        public $isConflict = false;
 
-       /** @var bool */
+       /**
+        * @deprecated since 1.30 use Title::isCssJsSubpage()
+        * @var bool
+        */
        public $isCssJsSubpage = false;
 
-       /** @var bool */
+       /**
+        * @deprecated since 1.30 use Title::isCssSubpage()
+        * @var bool
+        */
        public $isCssSubpage = false;
 
-       /** @var bool */
+       /**
+        * @deprecated since 1.30 use Title::isJsSubpage()
+        * @var bool
+        */
        public $isJsSubpage = false;
 
-       /** @var bool */
+       /**
+        * @deprecated since 1.30
+        * @var bool
+        */
        public $isWrongCaseCssJsPage = false;
 
        /** @var bool New page or new section */
@@ -413,6 +441,11 @@ class EditPage {
         */
        private $isOldRev = false;
 
+       /**
+        * @var string|null What the user submitted in the 'wpUnicodeCheck' field
+        */
+       private $unicodeCheck;
+
        /**
         * @param Article $article
         */
@@ -612,10 +645,11 @@ class EditPage {
 
                $this->isConflict = false;
                // css / js subpages of user pages get a special treatment
+               // The following member variables are deprecated since 1.30,
+               // the functions should be used instead.
                $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage();
                $this->isCssSubpage = $this->mTitle->isCssSubpage();
                $this->isJsSubpage = $this->mTitle->isJsSubpage();
-               // @todo FIXME: Silly assignment.
                $this->isWrongCaseCssJsPage = $this->isWrongCaseCssJsPage();
 
                # Show applicable editing introductions
@@ -787,7 +821,7 @@ class EditPage {
         * @return bool
         */
        protected function previewOnOpen() {
-               global $wgPreviewOnOpenNamespaces;
+               $previewOnOpenNamespaces = $this->context->getConfig()->get( 'PreviewOnOpenNamespaces' );
                $request = $this->context->getRequest();
                if ( $request->getVal( 'preview' ) == 'yes' ) {
                        // Explicit override from request
@@ -804,8 +838,8 @@ class EditPage {
                        // Standard preference behavior
                        return true;
                } elseif ( !$this->mTitle->exists()
-                       && isset( $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()] )
-                       && $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()]
+                       && isset( $previewOnOpenNamespaces[$this->mTitle->getNamespace()] )
+                       && $previewOnOpenNamespaces[$this->mTitle->getNamespace()]
                ) {
                        // Categories are special
                        return true;
@@ -865,7 +899,7 @@ class EditPage {
                        # These fields need to be checked for encoding.
                        # Also remove trailing whitespace, but don't remove _initial_
                        # whitespace from the text boxes. This may be significant formatting.
-                       $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
+                       $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
                        if ( !$request->getCheck( 'wpTextbox2' ) ) {
                                // Skip this if wpTextbox2 has input, it indicates that we came
                                // from a conflict page with raw page text, not a custom form
@@ -876,6 +910,8 @@ class EditPage {
                                }
                        }
 
+                       $this->unicodeCheck = $request->getText( 'wpUnicodeCheck' );
+
                        $this->summary = $request->getText( 'wpSummary' );
 
                        # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the
@@ -1544,6 +1580,7 @@ class EditPage {
 
                        case self::AS_CANNOT_USE_CUSTOM_MODEL:
                        case self::AS_PARSE_ERROR:
+                       case self::AS_UNICODE_NOT_SUPPORTED:
                                $out->addWikiText( '<div class="error">' . "\n" . $status->getWikiText() . '</div>' );
                                return true;
 
@@ -1732,9 +1769,6 @@ class EditPage {
         * time.
         */
        public function internalAttemptSave( &$result, $bot = false ) {
-               global $wgMaxArticleSize;
-               global $wgContentHandlerUseDB;
-
                $status = Status::newGood();
                $user = $this->context->getUser();
 
@@ -1745,6 +1779,12 @@ class EditPage {
                        return $status;
                }
 
+               if ( $this->unicodeCheck !== self::UNICODE_CHECK ) {
+                       $status->fatal( 'unicode-support-fail' );
+                       $status->value = self::AS_UNICODE_NOT_SUPPORTED;
+                       return $status;
+               }
+
                $request = $this->context->getRequest();
                $spam = $request->getText( 'wpAntispam' );
                if ( $spam !== '' ) {
@@ -1840,7 +1880,9 @@ class EditPage {
                }
 
                $this->contentLength = strlen( $this->textbox1 );
-               if ( $this->contentLength > $wgMaxArticleSize * 1024 ) {
+               $config = $this->context->getConfig();
+               $maxArticleSize = $config->get( 'MaxArticleSize' );
+               if ( $this->contentLength > $maxArticleSize * 1024 ) {
                        // Error will be displayed by showEditForm()
                        $this->tooBig = true;
                        $status->setResult( false, self::AS_CONTENT_TOO_BIG );
@@ -1860,7 +1902,7 @@ class EditPage {
 
                $changingContentModel = false;
                if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
-                       if ( !$wgContentHandlerUseDB ) {
+                       if ( !$config->get( 'ContentHandlerUseDB' ) ) {
                                $status->fatal( 'editpage-cannot-use-custom-model' );
                                $status->value = self::AS_CANNOT_USE_CUSTOM_MODEL;
                                return $status;
@@ -2139,7 +2181,7 @@ class EditPage {
 
                // Check for length errors again now that the section is merged in
                $this->contentLength = strlen( $this->toEditText( $content ) );
-               if ( $this->contentLength > $wgMaxArticleSize * 1024 ) {
+               if ( $this->contentLength > $maxArticleSize * 1024 ) {
                        $this->tooBig = true;
                        $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED );
                        return $status;
@@ -2340,8 +2382,6 @@ class EditPage {
        }
 
        public function setHeaders() {
-               global $wgAjaxEditStash;
-
                $out = $this->context->getOutput();
 
                $out->addModules( 'mediawiki.action.edit' );
@@ -2393,7 +2433,7 @@ class EditPage {
                # Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys
                $out->addJsConfigVars( [
                        'wgEditMessage' => $msg,
-                       'wgAjaxEditStash' => $wgAjaxEditStash,
+                       'wgAjaxEditStash' => $this->context->getConfig()->get( 'AjaxEditStash' ),
                ] );
        }
 
@@ -2673,6 +2713,9 @@ class EditPage {
                        call_user_func_array( $formCallback, [ &$out ] );
                }
 
+               // Add a check for Unicode support
+               $out->addHTML( Html::hidden( 'wpUnicodeCheck', self::UNICODE_CHECK ) );
+
                // Add an empty field to trip up spambots
                $out->addHTML(
                        Xml::openElement( 'div', [ 'id' => 'antispam-container', 'style' => 'display: none;' ] )
@@ -2768,7 +2811,7 @@ class EditPage {
 
                $out->addHTML( $this->editFormTextBeforeContent );
 
-               if ( !$this->isCssJsSubpage && $showToolbar && $user->getOption( 'showtoolbar' ) ) {
+               if ( !$this->mTitle->isCssJsSubpage() && $showToolbar && $user->getOption( 'showtoolbar' ) ) {
                        $out->addHTML( self::getEditToolbar( $this->mTitle ) );
                }
 
@@ -2892,8 +2935,6 @@ class EditPage {
        }
 
        protected function showHeader() {
-               global $wgAllowUserCss, $wgAllowUserJs;
-
                $out = $this->context->getOutput();
                $user = $this->context->getUser();
                if ( $this->isConflict ) {
@@ -2947,10 +2988,6 @@ class EditPage {
                                $out->addWikiText( $this->hookError );
                        }
 
-                       if ( !$this->checkUnicodeCompliantBrowser() ) {
-                               $out->addWikiMsg( 'nonunicodebrowser' );
-                       }
-
                        if ( $this->section != 'new' ) {
                                $revision = $this->mArticle->getRevisionFetched();
                                if ( $revision ) {
@@ -3008,27 +3045,29 @@ class EditPage {
                                );
                        }
                } else {
-                       if ( $this->isCssJsSubpage ) {
+                       if ( $this->mTitle->isCssJsSubpage() ) {
                                # Check the skin exists
-                               if ( $this->isWrongCaseCssJsPage ) {
+                               if ( $this->isWrongCaseCssJsPage() ) {
                                        $out->wrapWikiMsg(
                                                "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>",
                                                [ 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ]
                                        );
                                }
                                if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) {
+                                       $isCssSubpage = $this->mTitle->isCssSubpage();
                                        $out->wrapWikiMsg( '<div class="mw-usercssjspublic">$1</div>',
-                                               $this->isCssSubpage ? 'usercssispublic' : 'userjsispublic'
+                                               $isCssSubpage ? 'usercssispublic' : 'userjsispublic'
                                        );
                                        if ( $this->formtype !== 'preview' ) {
-                                               if ( $this->isCssSubpage && $wgAllowUserCss ) {
+                                               $config = $this->context->getConfig();
+                                               if ( $isCssSubpage && $config->get( 'AllowUserCss' ) ) {
                                                        $out->wrapWikiMsg(
                                                                "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
                                                                [ 'usercssyoucanpreview' ]
                                                        );
                                                }
 
-                                               if ( $this->isJsSubpage && $wgAllowUserJs ) {
+                                               if ( $this->mTitle->isJsSubpage() && $config->get( 'AllowUserJs' ) ) {
                                                        $out->wrapWikiMsg(
                                                                "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
                                                                [ 'userjsyoucanpreview' ]
@@ -3221,10 +3260,6 @@ class EditPage {
                $out->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) );
                $out->addHTML( Html::hidden( 'editRevId', $this->editRevId ) );
                $out->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) );
-
-               if ( !$this->checkUnicodeCompliantBrowser() ) {
-                       $out->addHTML( Html::hidden( 'safemode', '1' ) );
-               }
        }
 
        protected function showFormAfterText() {
@@ -3318,8 +3353,7 @@ class EditPage {
        }
 
        protected function showTextbox( $text, $name, $customAttribs = [] ) {
-               $wikitext = $this->safeUnicodeOutput( $text );
-               $wikitext = $this->addNewLineAtEnd( $wikitext );
+               $wikitext = $this->addNewLineAtEnd( $text );
 
                $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $this->context->getUser() );
 
@@ -3788,12 +3822,10 @@ class EditPage {
         * @return string
         */
        public function getPreviewText() {
-               global $wgRawHtml;
-               global $wgAllowUserCss, $wgAllowUserJs;
-
                $out = $this->context->getOutput();
+               $config = $this->context->getConfig();
 
-               if ( $wgRawHtml && !$this->mTokenOk ) {
+               if ( $config->get( 'RawHtml' ) && !$this->mTokenOk ) {
                        // Could be an offsite preview attempt. This is very unsafe if
                        // HTML is enabled, as it could be an attack.
                        $parsedNote = '';
@@ -3856,12 +3888,12 @@ class EditPage {
 
                                if ( $content->getModel() == CONTENT_MODEL_CSS ) {
                                        $format = 'css';
-                                       if ( $level === 'user' && !$wgAllowUserCss ) {
+                                       if ( $level === 'user' && !$config->get( 'AllowUserCss' ) ) {
                                                $format = false;
                                        }
                                } elseif ( $content->getModel() == CONTENT_MODEL_JAVASCRIPT ) {
                                        $format = 'js';
-                                       if ( $level === 'user' && !$wgAllowUserJs ) {
+                                       if ( $level === 'user' && !$config->get( 'AllowUserJs' ) ) {
                                                $format = false;
                                        }
                                } else {
@@ -4461,138 +4493,31 @@ class EditPage {
                $out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] );
        }
 
-       /**
-        * Check if the browser is on a blacklist of user-agents known to
-        * mangle UTF-8 data on form submission. Returns true if Unicode
-        * should make it through, false if it's known to be a problem.
-        * @return bool
-        */
-       private function checkUnicodeCompliantBrowser() {
-               global $wgBrowserBlackList;
-
-               $currentbrowser = $this->context->getRequest()->getHeader( 'User-Agent' );
-               if ( $currentbrowser === false ) {
-                       // No User-Agent header sent? Trust it by default...
-                       return true;
-               }
-
-               foreach ( $wgBrowserBlackList as $browser ) {
-                       if ( preg_match( $browser, $currentbrowser ) ) {
-                               return false;
-                       }
-               }
-               return true;
-       }
-
        /**
         * Filter an input field through a Unicode de-armoring process if it
         * came from an old browser with known broken Unicode editing issues.
         *
+        * @deprecated since 1.30, does nothing
+        *
         * @param WebRequest $request
         * @param string $field
         * @return string
         */
        protected function safeUnicodeInput( $request, $field ) {
-               $text = rtrim( $request->getText( $field ) );
-               return $request->getBool( 'safemode' )
-                       ? $this->unmakeSafe( $text )
-                       : $text;
+               return rtrim( $request->getText( $field ) );
        }
 
        /**
         * Filter an output field through a Unicode armoring process if it is
         * going to an old browser with known broken Unicode editing issues.
         *
+        * @deprecated since 1.30, does nothing
+        *
         * @param string $text
         * @return string
         */
        protected function safeUnicodeOutput( $text ) {
-               return $this->checkUnicodeCompliantBrowser()
-                       ? $text
-                       : $this->makeSafe( $text );
-       }
-
-       /**
-        * A number of web browsers are known to corrupt non-ASCII characters
-        * in a UTF-8 text editing environment. To protect against this,
-        * detected browsers will be served an armored version of the text,
-        * with non-ASCII chars converted to numeric HTML character references.
-        *
-        * Preexisting such character references will have a 0 added to them
-        * to ensure that round-trips do not alter the original data.
-        *
-        * @param string $invalue
-        * @return string
-        */
-       private function makeSafe( $invalue ) {
-               // Armor existing references for reversibility.
-               $invalue = strtr( $invalue, [ "&#x" => "&#x0" ] );
-
-               $bytesleft = 0;
-               $result = "";
-               $working = 0;
-               $valueLength = strlen( $invalue );
-               for ( $i = 0; $i < $valueLength; $i++ ) {
-                       $bytevalue = ord( $invalue[$i] );
-                       if ( $bytevalue <= 0x7F ) { // 0xxx xxxx
-                               $result .= chr( $bytevalue );
-                               $bytesleft = 0;
-                       } elseif ( $bytevalue <= 0xBF ) { // 10xx xxxx
-                               $working = $working << 6;
-                               $working += ( $bytevalue & 0x3F );
-                               $bytesleft--;
-                               if ( $bytesleft <= 0 ) {
-                                       $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
-                               }
-                       } elseif ( $bytevalue <= 0xDF ) { // 110x xxxx
-                               $working = $bytevalue & 0x1F;
-                               $bytesleft = 1;
-                       } elseif ( $bytevalue <= 0xEF ) { // 1110 xxxx
-                               $working = $bytevalue & 0x0F;
-                               $bytesleft = 2;
-                       } else { // 1111 0xxx
-                               $working = $bytevalue & 0x07;
-                               $bytesleft = 3;
-                       }
-               }
-               return $result;
-       }
-
-       /**
-        * Reverse the previously applied transliteration of non-ASCII characters
-        * back to UTF-8. Used to protect data from corruption by broken web browsers
-        * as listed in $wgBrowserBlackList.
-        *
-        * @param string $invalue
-        * @return string
-        */
-       private function unmakeSafe( $invalue ) {
-               $result = "";
-               $valueLength = strlen( $invalue );
-               for ( $i = 0; $i < $valueLength; $i++ ) {
-                       if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i + 3] != '0' ) ) {
-                               $i += 3;
-                               $hexstring = "";
-                               do {
-                                       $hexstring .= $invalue[$i];
-                                       $i++;
-                               } while ( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
-
-                               // Do some sanity checks. These aren't needed for reversibility,
-                               // but should help keep the breakage down if the editor
-                               // breaks one of the entities whilst editing.
-                               if ( ( substr( $invalue, $i, 1 ) == ";" ) && ( strlen( $hexstring ) <= 6 ) ) {
-                                       $codepoint = hexdec( $hexstring );
-                                       $result .= UtfNormal\Utils::codepointToUtf8( $codepoint );
-                               } else {
-                                       $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
-                               }
-                       } else {
-                               $result .= substr( $invalue, $i, 1 );
-                       }
-               }
-               // reverse the transform that we made for reversibility reasons.
-               return strtr( $result, [ "&#x0" => "&#x" ] );
+               return $text;
        }
 
        /**
@@ -4628,20 +4553,19 @@ class EditPage {
         * @since 1.29
         */
        protected function addLongPageWarningHeader() {
-               global $wgMaxArticleSize;
-
                if ( $this->contentLength === false ) {
                        $this->contentLength = strlen( $this->textbox1 );
                }
 
                $out = $this->context->getOutput();
                $lang = $this->context->getLanguage();
-               if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) {
+               $maxArticleSize = $this->context->getConfig()->get( 'MaxArticleSize' );
+               if ( $this->tooBig || $this->contentLength > $maxArticleSize * 1024 ) {
                        $out->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
                                [
                                        'longpageerror',
                                        $lang->formatNum( round( $this->contentLength / 1024, 3 ) ),
-                                       $lang->formatNum( $wgMaxArticleSize )
+                                       $lang->formatNum( $maxArticleSize )
                                ]
                        );
                } else {
index 4360b4d..94d6e97 100644 (file)
@@ -266,6 +266,7 @@ class ApiEditPage extends ApiBase {
                        'wpIgnoreBlankArticle' => true,
                        'wpIgnoreSelfRedirect' => true,
                        'bot' => $params['bot'],
+                       'wpUnicodeCheck' => EditPage::UNICODE_CHECK,
                ];
 
                if ( !is_null( $params['summary'] ) ) {
index aa7c62b..481e880 100644 (file)
@@ -921,6 +921,6 @@ abstract class MediaHandler {
         * @since 1.30
         */
        public function getContentHeaders( $metadata ) {
-               return [];
+               return [ 'X-Content-Dimensions' => '' ]; // T175689
        }
 }
index 8142111..c8e5e19 100644 (file)
@@ -105,7 +105,7 @@ class ExtensionJsonValidator {
                        // All good.
                        return true;
                } else {
-                       $out = "$path did pass validation.\n";
+                       $out = "$path did not pass validation.\n";
                        foreach ( $validator->getErrors() as $error ) {
                                $out .= "[{$error['property']}] {$error['message']}\n";
                        }
index 47e6205..6d06e40 100644 (file)
        "explainconflict": "Someone else has changed this page since you started editing it.\nThe upper text area contains the page text as it currently exists.\nYour changes are shown in the lower text area.\nYou will have to merge your changes into the existing text.\n<strong>Only</strong> the text in the upper text area will be saved when you press \"$1\".",
        "yourtext": "Your text",
        "storedversion": "Stored revision",
-       "nonunicodebrowser": "<strong>Warning: Your browser is not Unicode compliant.</strong>\nA workaround is in place to allow you to safely edit pages: Non-ASCII characters will appear in the edit box as hexadecimal codes.",
        "editingold": "<strong>Warning: You are editing an out-of-date revision of this page.</strong>\nIf you save it, any changes made since this revision will be lost.",
+       "unicode-support-fail": "It appears that your browser does not support Unicode. It is required to edit pages, so your edit was not saved.",
        "yourdiff": "Differences",
        "copyrightwarning": "Please note that all contributions to {{SITENAME}} are considered to be released under the $2 (see $1 for details).\nIf you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.<br />\nYou are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.\n<strong>Do not submit copyrighted work without permission!</strong>",
        "copyrightwarning2": "Please note that all contributions to {{SITENAME}} may be edited, altered, or removed by other contributors.\nIf you do not want your writing to be edited mercilessly, then do not submit it here.<br />\nYou are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see $1 for details).\n<strong>Do not submit copyrighted work without permission!</strong>",
index 0a6e91b..7534322 100644 (file)
        "explainconflict": "Appears at the top of a page when there is an edit conflict.\n\nParameters:\n* $1 – The label of the save button – one of {{msg-mw|savearticle}} or {{msg-mw|savechanges}} on save-labelled wiki, or {{msg-mw|publishpage}} or {{msg-mw|publishchanges}} on publish-labelled wikis.\n\nSee also:\n* {{msg-mw|Savearticle}}",
        "yourtext": "Used in Diff Preview page. The diff is between {{msg-mw|currentrev}} and {{msg-mw|yourtext}}.\n\nAlso used in Edit Conflict page; the diff between {{msg-mw|yourtext}} and {{msg-mw|storedversion}}.",
        "storedversion": "This is used in an edit conflict as the label for the top revision that has been stored, as opposed to your version {{msg-mw|yourtext}} that has not been stored which is shown at the bottom of the page.",
-       "nonunicodebrowser": "Used as warning when editing page.",
        "editingold": "Used as warning when editing an old revision of a page.",
+       "unicode-support-fail": "Error message shown to users if their browser doesn't support Unicode",
        "yourdiff": "Used as h2 header for the diff of the current version of a page with the user's version in case there is an edit conflict or a spam filter hit.",
        "copyrightwarning": "Copyright warning displayed under the edit box in editor. Parameters:\n* $1 - link\n* $2 - license name",
        "copyrightwarning2": "Copyright warning displayed under the edit box in editor\n*$1 - license name",
index bca1c96..fd3faeb 100644 (file)
@@ -37,6 +37,9 @@ class RefreshFileHeaders extends Maintenance {
                $this->addOption( 'verbose', 'Output information about each file.', false, false, 'v' );
                $this->addOption( 'start', 'Name of file to start with', false, true );
                $this->addOption( 'end', 'Name of file to end with', false, true );
+               $this->addOption( 'media_type', 'Media type to filter for', false, true );
+               $this->addOption( 'major_mime', 'Major mime type to filter for', false, true );
+               $this->addOption( 'minor_mime', 'Minor mime type to filter for', false, true );
                $this->setBatchSize( 200 );
        }
 
@@ -44,6 +47,12 @@ class RefreshFileHeaders extends Maintenance {
                $repo = RepoGroup::singleton()->getLocalRepo();
                $start = str_replace( ' ', '_', $this->getOption( 'start', '' ) ); // page on img_name
                $end = str_replace( ' ', '_', $this->getOption( 'end', '' ) ); // page on img_name
+                // filter by img_media_type
+               $media_type = str_replace( ' ', '_', $this->getOption( 'media_type', '' ) );
+                // filter by img_major_mime
+               $major_mime = str_replace( ' ', '_', $this->getOption( 'major_mime', '' ) );
+                // filter by img_minor_mime
+               $minor_mime = str_replace( ' ', '_', $this->getOption( 'minor_mime', '' ) );
 
                $count = 0;
                $dbr = $this->getDB( DB_REPLICA );
@@ -55,6 +64,18 @@ class RefreshFileHeaders extends Maintenance {
                                $conds[] = "img_name <= {$dbr->addQuotes( $end )}";
                        }
 
+                       if ( strlen( $media_type ) ) {
+                               $conds[] = "img_media_type = {$dbr->addQuotes( $media_type )}";
+                       }
+
+                       if ( strlen( $major_mime ) ) {
+                               $conds[] = "img_major_mime = {$dbr->addQuotes( $major_mime )}";
+                       }
+
+                       if ( strlen( $minor_mime ) ) {
+                               $conds[] = "img_minor_mime = {$dbr->addQuotes( $minor_mime )}";
+                       }
+
                        $res = $dbr->select( 'image', '*', $conds,
                                __METHOD__, [ 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'img_name ASC' ] );
 
index 20c1463..5ab32ea 100644 (file)
                }
        };
 
-       $( rcfilters.init );
+       // Early execute of init
+       if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
+               rcfilters.init();
+       } else {
+               $( rcfilters.init );
+       }
 
        module.exports = rcfilters;
 
index 07d4506..5ba42e7 100644 (file)
@@ -32,6 +32,7 @@
                this.views = {};
                this.userSelecting = false;
 
+               this.menuInitialized = false;
                this.inputValue = '';
                this.$overlay = config.$overlay || this.$element;
                this.$body = $( '<div>' ).addClass( 'mw-rcfilters-ui-menuSelectWidget-body' );
        };
 
        /**
-        * Respond to model initialize event. Populate the menu from the model
+        * @inheritdoc
         */
-       mw.rcfilters.ui.MenuSelectWidget.prototype.onModelInitialize = function () {
+       mw.rcfilters.ui.MenuSelectWidget.prototype.toggle = function ( show ) {
+               this.lazyMenuCreation();
+               mw.rcfilters.ui.MenuSelectWidget.parent.prototype.toggle.call( this, show );
+       };
+
+       /**
+        * lazy creation of the menu
+        */
+       mw.rcfilters.ui.MenuSelectWidget.prototype.lazyMenuCreation = function () {
                var widget = this,
                        viewGroupCount = {},
                        groups = this.model.getFilterGroups();
 
+               if ( this.menuInitialized ) {
+                       return;
+               }
+
+               this.menuInitialized = true;
                // Reset
                this.clearItems();
 
                this.switchView( this.model.getCurrentView() );
        };
 
+       /**
+        * Respond to model initialize event. Populate the menu from the model
+        */
+       mw.rcfilters.ui.MenuSelectWidget.prototype.onModelInitialize = function () {
+               this.menuInitialized = false;
+       };
+
        /**
         * Switch view
         *
         * @return {mw.rcfilters.ui.ItemMenuOptionWidget} Option widget
         */
        mw.rcfilters.ui.MenuSelectWidget.prototype.getItemFromModel = function ( model ) {
+               this.lazyMenuCreation();
                return this.views[ model.getGroupModel().getView() ].filter( function ( item ) {
                        return item.getName() === model.getName();
                } )[ 0 ];
index 9507811..ad0d07a 100644 (file)
@@ -165,6 +165,10 @@ class EditPageTest extends MediaWikiLangTestCase {
                        $edit['wpStarttime'] = wfTimestampNow();
                }
 
+               if ( !isset( $edit['wpUnicodeCheck'] ) ) {
+                       $edit['wpUnicodeCheck'] = EditPage::UNICODE_CHECK;
+               }
+
                $req = new FauxRequest( $edit, true ); // session ??
 
                $article = new Article( $title );
@@ -697,7 +701,8 @@ hello
                        'wpTextbox1' => serialize( 'non-text content' ),
                        'wpEditToken' => $user->getEditToken(),
                        'wpEdittime' => '',
-                       'wpStarttime' => wfTimestampNow()
+                       'wpStarttime' => wfTimestampNow(),
+                       'wpUnicodeCheck' => EditPage::UNICODE_CHECK,
                ];
 
                $req = new FauxRequest( $edit, true );