Merge "mw.loader: Don't assume var 'loading' assigns before Promise resolves"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 12 Apr 2017 17:52:18 +0000 (17:52 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 12 Apr 2017 17:52:18 +0000 (17:52 +0000)
18 files changed:
RELEASE-NOTES-1.29
UPGRADE
includes/OutputPage.php
includes/Sanitizer.php
includes/Title.php
includes/WatchedItemQueryService.php
includes/WikiMap.php
includes/auth/Throttler.php
includes/changes/RecentChange.php
includes/deferred/LinksUpdate.php
includes/htmlform/OOUIHTMLForm.php
includes/http/CurlHttpRequest.php
includes/jobqueue/JobQueueGroup.php
includes/resourceloader/ResourceLoaderSkinModule.php
includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialEmailuser.php
includes/specials/SpecialWatchlist.php
tests/phpunit/includes/OutputPageTest.php

index e86ab1c..33d917c 100644 (file)
@@ -325,8 +325,8 @@ changes to languages because of Phabricator reports.
 MediaWiki 1.29 requires PHP 5.5.9 or later. There is experimental support for
 HHVM 3.6.5 or later.
 
-MySQL is the recommended DBMS. PostgreSQL or SQLite can also be used, but
-support for them is somewhat less mature. There is experimental support for
+MySQL/MariaDB is the recommended DBMS. PostgreSQL or SQLite can also be used,
+but support for them is somewhat less mature. There is experimental support for
 Oracle and Microsoft SQL Server.
 
 The supported versions are:
@@ -344,20 +344,10 @@ updates. Note that due to changes to some very large tables like the revision
 table, the schema update may take quite long (minutes on a medium sized site,
 many hours on a large site).
 
-If upgrading from before 1.11, and you are using a wiki as a commons
-repository, make sure that it is updated as well. Otherwise, errors may arise
-due to database schema changes.
-
-If upgrading from before 1.7, you may want to run refreshLinks.php to ensure
-new database fields are filled with data.
-
-If you are upgrading from MediaWiki 1.4.x or earlier, you should upgrade to
-1.5 first. The upgrade script maintenance/upgrade1_5.php has been removed
-with MediaWiki 1.21.
-
 Don't forget to always back up your database before upgrading!
 
-See the file UPGRADE for more detailed upgrade instructions.
+See the file UPGRADE for more detailed upgrade instructions, including
+important information when upgrading from versions prior to 1.11.
 
 For notes on 1.28.x and older releases, see HISTORY.
 
diff --git a/UPGRADE b/UPGRADE
index 3ec1a22..0e6ad9b 100644 (file)
--- a/UPGRADE
+++ b/UPGRADE
@@ -109,6 +109,12 @@ In the "maintenance" directory, run the updateDoubleWidthSearch.php
 script.  This will update the searchindex table for those pages that
 contain double-byte latin characters.
 
+== Upgrading from 1.10 or earlier ==
+
+If upgrading from before 1.11, and you are using a wiki as a commons
+repository, make sure that it is updated as well. Otherwise, errors may arise
+due to database schema changes.
+
 == Upgrading from 1.8 or earlier ==
 
 MediaWiki 1.9 and later no longer keep default localized message text
@@ -135,6 +141,9 @@ to set only specific items as recommended in DefaultSettings.php.
 
 $wgLocalTZoffset was in hours, it is now using minutes.
 
+If upgrading from before 1.7, you may want to run refreshLinks.php to ensure
+new database fields are filled with data.
+
 == Upgrading from 1.5 or earlier ==
 
 Major changes have been made to the schema from 1.4.x. The updater
@@ -149,7 +158,7 @@ UTF-8; an experimental command-line upgrade helper script,
 'upgrade1_5.php', can do this -- run it prior to 'update.php' or
 the web upgrader.
 
-NOTE that upgrade1_5.php does not work properly with recent version
+NOTE that upgrade1_5.php does not work properly with recent versions
 of MediaWiki. If upgrading a 1.4.x wiki, you should upgrade to 1.5
 first.  upgrade1_5.php has been removed from MediaWiki 1.21.
 
index a25ea9c..df49bf6 100644 (file)
@@ -302,6 +302,11 @@ class OutputPage extends ContextSource {
        /** @var array Profiling data */
        private $limitReportJSData = [];
 
+       /**
+        * Link: header contents
+        */
+       private $mLinkHeader = [];
+
        /**
         * Constructor for OutputPage. This should not be called directly.
         * Instead a new RequestContext should be created and it will implicitly create
@@ -2105,6 +2110,28 @@ class OutputPage extends ContextSource {
                return 'Vary: ' . implode( ', ', array_keys( $this->mVaryHeader ) );
        }
 
+       /**
+        * Add an HTTP Link: header
+        *
+        * @param string $header Header value
+        */
+       public function addLinkHeader( $header ) {
+               $this->mLinkHeader[] = $header;
+       }
+
+       /**
+        * Return a Link: header. Based on the values of $mLinkHeader.
+        *
+        * @return string
+        */
+       public function getLinkHeader() {
+               if ( !$this->mLinkHeader ) {
+                       return false;
+               }
+
+               return 'Link: ' . implode( ',', $this->mLinkHeader );
+       }
+
        /**
         * Get a complete Key header
         *
@@ -2361,6 +2388,12 @@ class OutputPage extends ContextSource {
                // jQuery etc. can work correctly.
                $response->header( 'X-UA-Compatible: IE=Edge' );
 
+               $this->addLogoPreloadLinkHeaders();
+               $linkHeader = $this->getLinkHeader();
+               if ( $linkHeader ) {
+                       $response->header( $linkHeader );
+               }
+
                // Prevent framing, if requested
                $frameOptions = $this->getFrameOptions();
                if ( $frameOptions ) {
@@ -3965,4 +3998,82 @@ class OutputPage extends ContextSource {
                        'mediawiki.widgets.styles',
                ] );
        }
+
+       /**
+        * Add Link headers for preloading the wiki's logo.
+        *
+        * @since 1.26
+        */
+       protected function addLogoPreloadLinkHeaders() {
+               $logo = $this->getConfig()->get( 'Logo' ); // wgLogo
+               $logoHD = $this->getConfig()->get( 'LogoHD' ); // wgLogoHD
+
+               $tags = [];
+               $logosPerDppx = [];
+               $logos = [];
+
+               $logosPerDppx['1.0'] = $logo;
+
+               if ( !$logoHD ) {
+                       // No media queries required if we only have one variant
+                       $this->addLinkHeader( '<' . $logo . '>;rel=preload;as=image' );
+                       return;
+               }
+
+               foreach ( $logoHD as $dppx => $src ) {
+                       // Only 1.5x and 2x are supported
+                       // Note: Keep in sync with ResourceLoaderSkinModule
+                       if ( in_array( $dppx, [ '1.5x', '2x' ] ) ) {
+                               // LogoHD uses a string in this format: "1.5x"
+                               $dppx = substr( $dppx, 0, -1 );
+                               $logosPerDppx[$dppx] = $src;
+                       }
+               }
+
+               // Because PHP can't have floats as array keys
+               uksort( $logosPerDppx, function ( $a , $b ) {
+                       $a = floatval( $a );
+                       $b = floatval( $b );
+
+                       if ( $a == $b ) {
+                               return 0;
+                       }
+                       // Sort from smallest to largest (e.g. 1x, 1.5x, 2x)
+                       return ( $a < $b ) ? -1 : 1;
+               } );
+
+               foreach ( $logosPerDppx as $dppx => $src ) {
+                       $logos[] = [ 'dppx' => $dppx, 'src' => $src ];
+               }
+
+               $logosCount = count( $logos );
+               // Logic must match ResourceLoaderSkinModule:
+               // - 1x applies to resolution < 1.5dppx
+               // - 1.5x applies to resolution >= 1.5dppx && < 2dppx
+               // - 2x applies to resolution >= 2dppx
+               // Note that min-resolution and max-resolution are both inclusive.
+               for ( $i = 0; $i < $logosCount; $i++ ) {
+                       if ( $i === 0 ) {
+                               // Smallest dppx
+                               // min-resolution is ">=" (larger than or equal to)
+                               // "not min-resolution" is essentially "<"
+                               $media_query = 'not all and (min-resolution: ' . $logos[ 1 ]['dppx'] . 'dppx)';
+                       } elseif ( $i !== $logosCount - 1 ) {
+                               // In between
+                               // Media query expressions can only apply "not" to the entire expression
+                               // (e.g. can't express ">= 1.5 and not >= 2).
+                               // Workaround: Use <= 1.9999 in place of < 2.
+                               $upper_bound = floatval( $logos[ $i + 1 ]['dppx'] ) - 0.000001;
+                               $media_query = '(min-resolution: ' . $logos[ $i ]['dppx'] .
+                                       'dppx) and (max-resolution: ' . $upper_bound . 'dppx)';
+                       } else {
+                               // Largest dppx
+                               $media_query = '(min-resolution: ' . $logos[ $i ]['dppx'] . 'dppx)';
+                       }
+
+                       $this->addLinkHeader(
+                               '<' . $logos[$i]['src'] . '>;rel=preload;as=image;media=' . $media_query
+                       );
+               }
+       }
 }
index 5f6abee..e9519c3 100644 (file)
@@ -1784,7 +1784,7 @@ class Sanitizer {
                        'rb'         => $common,
                        'rp'         => $common,
                        'rt'         => $common, # array_merge( $common, array( 'rbspan' ) ),
-                       'rtc'         => $common,
+                       'rtc'        => $common,
 
                        # MathML root element, where used for extensions
                        # 'title' may not be 100% valid here; it's XHTML
index 28db064..95bb1d9 100644 (file)
@@ -4650,7 +4650,7 @@ class Title implements LinkTarget {
        }
 
        /**
-        * Whether the magic words __INDEX__ and __NOINDEX__ function for  this page.
+        * Whether the magic words __INDEX__ and __NOINDEX__ function for this page.
         *
         * @return bool
         */
index ba77074..22d5439 100644 (file)
@@ -390,7 +390,7 @@ class WatchedItemQueryService {
                }
 
                if ( array_key_exists( 'rcTypes', $options ) ) {
-                       $conds['rc_type'] = array_map( 'intval',  $options['rcTypes'] );
+                       $conds['rc_type'] = array_map( 'intval', $options['rcTypes'] );
                }
 
                $conds = array_merge(
@@ -565,7 +565,7 @@ class WatchedItemQueryService {
                }
                if ( isset( $options['filter'] ) ) {
                        $filter = $options['filter'];
-                       if ( $filter ===  self::FILTER_CHANGED ) {
+                       if ( $filter === self::FILTER_CHANGED ) {
                                $conds[] = 'wl_notificationtimestamp IS NOT NULL';
                        } else {
                                $conds[] = 'wl_notificationtimestamp IS NULL';
index f7b8d2f..0f479ac 100644 (file)
@@ -182,7 +182,7 @@ class WikiMap {
 class WikiReference {
        private $mCanonicalServer; ///< canonical server URL, e.g. 'https://www.mediawiki.org'
        private $mServer; ///< server URL, may be protocol-relative, e.g. '//www.mediawiki.org'
-       private $mPath;   ///< path, '/wiki/$1'
+       private $mPath; ///< path, '/wiki/$1'
 
        /**
         * @param string $canonicalServer
index 6d3b2f4..8a10ecb 100644 (file)
@@ -130,7 +130,7 @@ class Throttler implements LoggerAwareInterface {
                        $throttleKey = wfGlobalCacheKey( 'throttler', $this->type, $index, $ipKey, $userKey );
                        $throttleCount = $this->cache->get( $throttleKey );
 
-                       if ( !$throttleCount ) {  // counter not started yet
+                       if ( !$throttleCount ) { // counter not started yet
                                $this->cache->add( $throttleKey, 1, $expiry );
                        } elseif ( $throttleCount < $count ) { // throttle limited not yet reached
                                $this->cache->incr( $throttleKey );
index dcab158..35f8b3b 100644 (file)
@@ -874,7 +874,7 @@ class RecentChange {
                        'rc_logid' => 0,
                        'rc_log_type' => null,
                        'rc_log_action' => '',
-                       'rc_params' =>  serialize( [
+                       'rc_params' => serialize( [
                                'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
                        ] )
                ];
index 5697960..a629458 100644 (file)
@@ -409,7 +409,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
 
                $deleteWheres = []; // list of WHERE clause arrays for each DB delete() call
                if ( $table === 'pagelinks' || $table === 'templatelinks' || $table === 'iwlinks' ) {
-                       $baseKey =  ( $table === 'iwlinks' ) ? 'iwl_prefix' : "{$prefix}_namespace";
+                       $baseKey = ( $table === 'iwlinks' ) ? 'iwl_prefix' : "{$prefix}_namespace";
 
                        $curBatchSize = 0;
                        $curDeletionBatch = [];
index 54bdf04..549edde 100644 (file)
@@ -207,7 +207,7 @@ class OOUIHTMLForm extends HTMLForm {
                                        $error = array_merge( [ $error['message'] ], $error['params'] );
                                }
                        }
-               } elseif ( $elementsType === 'errors' )  {
+               } elseif ( $elementsType === 'errors' ) {
                        $errors = $elements;
                        if ( !is_array( $errors ) ) {
                                $errors = [ $errors ];
index f958ff6..3da3eb3 100644 (file)
@@ -145,7 +145,7 @@ class CurlHttpRequest extends MWHttpRequest {
                $this->parseHeader();
                $this->setStatus();
 
-               return Status::wrap( $this->status );  // TODO B/C; move this to callers
+               return Status::wrap( $this->status ); // TODO B/C; move this to callers
        }
 
        /**
index 71d68d9..9f78404 100644 (file)
@@ -170,7 +170,7 @@ class JobQueueGroup {
         * @since 1.26
         */
        public function lazyPush( $jobs ) {
-               if ( PHP_SAPI === 'cli' ) {
+               if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
                        $this->push( $jobs );
                        return;
                }
index d72b3af..7d37944 100644 (file)
@@ -40,6 +40,8 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
                $styles['all'][] = '.mw-wiki-logo { background-image: ' .
                        CSSMin::buildUrlValue( $logo1 ) .
                        '; }';
+               // Only 1.5x and 2x are supported
+               // Note: Keep in sync with OutputPage::addLogoPreloadLinkHeaders()
                if ( $logoHD ) {
                        if ( isset( $logoHD['1.5x'] ) ) {
                                $styles[
index ad9a248..97d1dcb 100644 (file)
@@ -379,7 +379,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                                },
                                                'cssClassSuffix' => 'patrolled',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
-                                                                                    return $rc->getAttribute( 'rc_patrolled' );
+                                                       return $rc->getAttribute( 'rc_patrolled' );
                                                },
                                        ],
                                        [
@@ -394,7 +394,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                                },
                                                'cssClassSuffix' => 'unpatrolled',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
-                                                                                    return !$rc->getAttribute( 'rc_patrolled' );
+                                                       return !$rc->getAttribute( 'rc_patrolled' );
                                                },
                                        ],
                                ],
@@ -1169,9 +1169,9 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels ) {
 
                global $wgLearnerEdits,
-                          $wgExperiencedUserEdits,
-                          $wgLearnerMemberSince,
-                          $wgExperiencedUserMemberSince;
+                       $wgExperiencedUserEdits,
+                       $wgLearnerMemberSince,
+                       $wgExperiencedUserMemberSince;
 
                $LEVEL_COUNT = 3;
 
@@ -1207,7 +1207,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                );
 
                if ( $selectedExpLevels === [ 'newcomer' ] ) {
-                       $conds[] =  "NOT ( $aboveNewcomer )";
+                       $conds[] = "NOT ( $aboveNewcomer )";
                } elseif ( $selectedExpLevels === [ 'learner' ] ) {
                        $conds[] = $dbr->makeList(
                                [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
index a69406c..830b438 100644 (file)
@@ -289,7 +289,7 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                                'text',
                                [
                                        'id' => 'emailusertarget',
-                                       'class' => 'mw-autocomplete-user',  // used by mediawiki.userSuggest
+                                       'class' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
                                        'autofocus' => true,
                                        'size' => 30,
                                ]
index c1c9ab0..e9d3f26 100644 (file)
@@ -111,7 +111,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
         */
        protected function transformFilterDefinition( array $filterDefinition ) {
                if ( isset( $filterDefinition['showHideSuffix'] ) ) {
-                         $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
+                       $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
                }
 
                return $filterDefinition;
index 59441ce..7571e26 100644 (file)
@@ -472,13 +472,93 @@ class OutputPageTest extends MediaWikiTestCase {
                $this->assertEquals( [ 0 => 'Test' ], $outputPage->getCategories( 'hidden' ) );
        }
 
+       /**
+        * @dataProvider provideLinkHeaders
+        * @covers OutputPage::addLinkHeader
+        * @covers OutputPage::getLinkHeader
+        */
+       public function testLinkHeaders( $headers, $result ) {
+               $outputPage = $this->newInstance();
+
+               foreach ( $headers as $header ) {
+                       $outputPage->addLinkHeader( $header );
+               }
+
+               $this->assertEquals( $result, $outputPage->getLinkHeader() );
+       }
+
+       public function provideLinkHeaders() {
+               return [
+                       [
+                               [],
+                               false
+                       ],
+                       [
+                               [ '<https://foo/bar.jpg>;rel=preload;as=image' ],
+                               'Link: <https://foo/bar.jpg>;rel=preload;as=image',
+                       ],
+                       [
+                               [ '<https://foo/bar.jpg>;rel=preload;as=image','<https://foo/baz.jpg>;rel=preload;as=image' ],
+                               'Link: <https://foo/bar.jpg>;rel=preload;as=image,<https://foo/baz.jpg>;rel=preload;as=image',
+                       ],
+               ];
+       }
+
+       /**
+        * @dataProvider providePreloadLinkHeaders
+        * @covers OutputPage::addLogoPreloadLinkHeaders
+        */
+       public function testPreloadLinkHeaders( $config, $result ) {
+               $out = TestingAccessWrapper::newFromObject( $this->newInstance( $config ) );
+               $out->addLogoPreloadLinkHeaders();
+
+               $this->assertEquals( $result, $out->getLinkHeader() );
+       }
+
+       public function providePreloadLinkHeaders() {
+               return [
+                       [
+                               [
+                                       'Logo' => '/img/default.png',
+                                       'LogoHD' => [
+                                               '1.5x' => '/img/one-point-five.png',
+                                               '2x' => '/img/two-x.png',
+                                       ],
+                               ],
+                               'Link: </img/default.png>;rel=preload;as=image;media=' .
+                               'not all and (min-resolution: 1.5dppx),' .
+                               '</img/one-point-five.png>;rel=preload;as=image;media=' .
+                               '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' .
+                               '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
+                       ],
+                       [
+                               [
+                                       'Logo' => '/img/default.png',
+                                       'LogoHD' => false,
+                               ],
+                               'Link: </img/default.png>;rel=preload;as=image'
+                       ],
+                       [
+                               [
+                                       'Logo' => '/img/default.png',
+                                       'LogoHD' => [
+                                               '2x' => '/img/two-x.png',
+                                       ],
+                               ],
+                               'Link: </img/default.png>;rel=preload;as=image;media=' .
+                               'not all and (min-resolution: 2dppx),' .
+                               '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
+                       ],
+               ];
+       }
+
        /**
         * @return OutputPage
         */
-       private function newInstance() {
+       private function newInstance( $config = [] ) {
                $context = new RequestContext();
 
-               $context->setConfig( new HashConfig( [
+               $context->setConfig( new HashConfig( $config + [
                        'AppleTouchIcon' => false,
                        'DisableLangConversion' => true,
                        'EnableAPI' => false,