Merge "rdbms: document Database::doQuery() return value"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 1 Mar 2019 03:00:21 +0000 (03:00 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 1 Mar 2019 03:00:21 +0000 (03:00 +0000)
32 files changed:
includes/AjaxResponse.php
includes/FeedUtils.php
includes/Html.php
includes/Title.php
includes/api/ApiFeedWatchlist.php
includes/api/ApiMain.php
includes/api/ApiQuery.php
includes/changes/ChangesFeed.php
includes/changetags/ChangeTagsLogItem.php
includes/clientpool/SquidPurgeClient.php
includes/config/EtcdConfig.php
includes/deferred/WANCacheReapUpdate.php
includes/diff/DifferenceEngine.php
includes/jobqueue/JobQueueDB.php
includes/libs/objectcache/WANObjectCache.php
includes/media/DjVuHandler.php
includes/media/Exif.php
includes/page/WikiPage.php
includes/parser/CoreParserFunctions.php
includes/preferences/DefaultPreferencesFactory.php
includes/resourceloader/ResourceLoaderImageModule.php
includes/resourceloader/ResourceLoaderModule.php
includes/resourceloader/ResourceLoaderWikiModule.php
includes/revisiondelete/RevDelLogItem.php
includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialNewpages.php
includes/specials/SpecialTags.php
includes/user/BotPassword.php
maintenance/syncFileBackend.php
resources/Resources.php
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.SaveFiltersPopupButtonWidget.less
tests/phpunit/includes/linker/LinkRendererTest.php

index dfcf467..8f4ed40 100644 (file)
@@ -282,7 +282,8 @@ class AjaxResponse {
                        return false;
                }
 
-               $mcvalue = ObjectCache::getMainWANInstance()->get( $mckey );
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $mcvalue = $cache->get( $mckey );
                if ( $mcvalue ) {
                        # Check to see if the value has been invalidated
                        if ( $touched <= $mcvalue['timestamp'] ) {
@@ -304,11 +305,13 @@ class AjaxResponse {
         * @return bool
         */
        function storeInMemcached( $mckey, $expiry = 86400 ) {
-               ObjectCache::getMainWANInstance()->set( $mckey,
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $cache->set( $mckey,
                        [
                                'timestamp' => wfTimestampNow(),
                                'value' => $this->mText
-                       ], $expiry
+                       ],
+                       $expiry
                );
 
                return true;
index 899ac09..0a88b23 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Feed
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Helper functions for feeds
@@ -41,7 +42,7 @@ class FeedUtils {
                $purge = $wgRequest->getVal( 'action' ) === 'purge';
                // Allow users with 'purge' right to clear feed caches
                if ( $purge && $wgUser->isAllowed( 'purge' ) ) {
-                       $cache = ObjectCache::getMainWANInstance();
+                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                        $cache->delete( $timekey, 1 );
                        $cache->delete( $key, 1 );
                }
index 0aea7ea..1e597b6 100644 (file)
@@ -983,7 +983,6 @@ class Html {
                                $attribs["xmlns:$tag"] = $ns;
                        }
                } else { // HTML5
-                       // DOCTYPE
                        $ret .= "<!DOCTYPE html>\n";
                }
 
index 4075bd5..2582fe2 100644 (file)
@@ -3337,7 +3337,7 @@ class Title implements LinkTarget, IDBAccessObject {
                                $dbr = wfGetDB( DB_MASTER );
                                $rows = $loadRestrictionsFromDb( $dbr );
                        } else {
-                               $cache = ObjectCache::getMainWANInstance();
+                               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                                $rows = $cache->getWithSetCallback(
                                        // Page protections always leave a new null revision
                                        $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
index 935bb09..11b5d91 100644 (file)
@@ -102,10 +102,8 @@ class ApiFeedWatchlist extends ApiBase {
                                $fauxReqArr['wlallrev'] = '';
                        }
 
-                       // Create the request
                        $fauxReq = new FauxRequest( $fauxReqArr );
 
-                       // Execute
                        $module = new ApiMain( $fauxReq );
                        $module->execute();
 
index 8255269..680e7dc 100644 (file)
@@ -1592,17 +1592,14 @@ class ApiMain extends ApiBase {
                        $this->setupExternalResponse( $module, $params );
                }
 
-               // Execute
                $module->execute();
                Hooks::run( 'APIAfterExecute', [ &$module ] );
 
                $this->reportUnusedParams();
 
                if ( !$this->mInternalMode ) {
-                       // append Debug information
                        MWDebug::appendDebugInfoToApiResult( $this->getContext(), $this->getResult() );
 
-                       // Print result data
                        $this->printResult();
                }
        }
index c68ec2b..ae6b1a1 100644 (file)
@@ -287,7 +287,7 @@ class ApiQuery extends ApiBase {
                        }
                } elseif ( $modCacheMode === 'public' ) {
                        // do nothing, if it's public already it will stay public
-               } else { // private
+               } else {
                        $cacheMode = 'private';
                }
 
index 7ac8cd0..fe9d24c 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 use Wikimedia\Rdbms\ResultWrapper;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Feed to Special:RecentChanges and Special:RecentChangesLiked
@@ -82,7 +83,7 @@ class ChangesFeed {
                        return null;
                }
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $optionsHash = md5( serialize( $opts->getAllValues() ) ) . $wgRenderHashAppend;
                $timekey = $cache->makeKey(
                        $this->type, $this->format, $wgLang->getCode(), $optionsHash, 'timestamp' );
@@ -119,7 +120,7 @@ class ChangesFeed {
         * @param string $key Memcached key of the content
         */
        public function saveToCache( $feed, $timekey, $key ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $cache->set( $key, $feed, $cache::TTL_DAY );
                $cache->set( $timekey, wfTimestamp( TS_MW ), $cache::TTL_DAY );
        }
@@ -135,7 +136,7 @@ class ChangesFeed {
        public function loadFromCache( $lastmod, $timekey, $key ) {
                global $wgFeedCacheTimeout, $wgOut;
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $feedLastmod = $cache->get( $timekey );
 
                if ( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) {
index a248c6e..75b713e 100644 (file)
@@ -85,7 +85,7 @@ class ChangeTagsLogItem extends RevisionItemBase {
                $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
                // User links and action text
                $action = $formatter->getActionText();
-               // Comment
+
                $comment = $this->list->getLanguage()->getDirMark() .
                        $formatter->getComment();
 
index 36d72c2..005b326 100644 (file)
@@ -315,7 +315,7 @@ class SquidPurgeClient {
                                }
                                if ( $this->readState == 'status' ) {
                                        $this->processStatusLine( $lines[0] );
-                               } else { // header
+                               } else {
                                        $this->processHeaderLine( $lines[0] );
                                }
                                $this->readBuffer = $lines[1];
index 7020159..09d0189 100644 (file)
@@ -326,7 +326,7 @@ class EtcdConfig implements Config, LoggerAwareInterface {
        private function unserialize( $string ) {
                if ( $this->encoding === 'YAML' ) {
                        return yaml_parse( $string );
-               } else { // JSON
+               } else {
                        return json_decode( $string, true );
                }
        }
index 604f205..a218f76 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Linker\LinkTarget;
 use Psr\Log\LoggerInterface;
 use Wikimedia\Rdbms\IDatabase;
@@ -39,7 +40,7 @@ class WANCacheReapUpdate implements DeferrableUpdate {
 
        function doUpdate() {
                $reaper = new WANObjectCacheReaper(
-                       ObjectCache::getMainWANInstance(),
+                       MediaWikiServices::getInstance()->getMainWANObjectCache(),
                        ObjectCache::getLocalClusterInstance(),
                        [ $this, 'getTitleChangeEvents' ],
                        [ $this, 'getEventAffectedKeys' ],
index 8e2b96d..e39334f 100644 (file)
@@ -1024,7 +1024,7 @@ class DifferenceEngine extends ContextSource {
 
                // Cacheable?
                $key = false;
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                if ( $this->mOldid && $this->mNewid ) {
                        // Check if subclass is still using the old way
                        // for backwards-compatibility
index cda0636..65c27d8 100644 (file)
@@ -56,7 +56,7 @@ class JobQueueDB extends JobQueue {
                parent::__construct( $params );
 
                $this->cluster = $params['cluster'] ?? false;
-               $this->cache = ObjectCache::getMainWANInstance();
+               $this->cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
        }
 
        protected function supportedOrders() {
index 976c176..0480d71 100644 (file)
@@ -1271,13 +1271,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                                $this->stats->increment( "wanobjectcache.$kClass.hit.good" );
 
                                return $value;
-                       } elseif ( $this->asyncHandler ) {
-                               // Update the cache value later, such during post-send of an HTTP request
-                               $func = $this->asyncHandler;
-                               $func( function () use ( $key, $ttl, $callback, $opts, $asOf ) {
-                                       $opts['minAsOf'] = INF; // force a refresh
-                                       $this->doGetWithSetCallback( $key, $ttl, $callback, $opts, $asOf );
-                               } );
+                       } elseif ( $this->scheduleAsyncRefresh( $key, $ttl, $callback, $opts ) ) {
                                $this->stats->increment( "wanobjectcache.$kClass.hit.refresh" );
 
                                return $value;
@@ -2012,6 +2006,28 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                return $ok;
        }
 
+       /**
+        * @param string $key
+        * @param int $ttl
+        * @param callable $callback
+        * @param array $opts
+        * @return bool Success
+        */
+       private function scheduleAsyncRefresh( $key, $ttl, $callback, $opts ) {
+               if ( !$this->asyncHandler ) {
+                       return false;
+               }
+               // Update the cache value later, such during post-send of an HTTP request
+               $func = $this->asyncHandler;
+               $func( function () use ( $key, $ttl, $callback, $opts ) {
+                       $asOf = null; // unused
+                       $opts['minAsOf'] = INF; // force a refresh
+                       $this->doGetWithSetCallback( $key, $ttl, $callback, $opts, $asOf );
+               } );
+
+               return true;
+       }
+
        /**
         * Check if a key is fresh or in the grace window and thus due for randomized reuse
         *
index ed62ba1..a0e7f2c 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Media
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Handler for DjVu images
@@ -402,7 +403,7 @@ class DjVuHandler extends ImageHandler {
        }
 
        protected function getDimensionInfo( File $file ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
                        $cache->makeKey( 'file-djvu', 'dimensions', $file->getSha1() ),
                        $cache::TTL_INDEFINITE,
index c32a720..0fde386 100644 (file)
@@ -455,8 +455,7 @@ class Exif {
                        $val = substr( $this->mFilteredExifData[$prop], 8 );
 
                        switch ( $charCode ) {
-                               case "\x4A\x49\x53\x00\x00\x00\x00\x00":
-                                       // JIS
+                               case "JIS\x00\x00\x00\x00\x00":
                                        $charset = "Shift-JIS";
                                        break;
                                case "UNICODE\x00":
index df9259b..32b35f7 100644 (file)
@@ -637,7 +637,7 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public function getContentModel() {
                if ( $this->exists() ) {
-                       $cache = ObjectCache::getMainWANInstance();
+                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
 
                        return $cache->getWithSetCallback(
                                $cache->makeKey( 'page-content-model', $this->getLatest() ),
index 8ab5c31..d1d1a9c 100644 (file)
@@ -327,7 +327,6 @@ class CoreParserFunctions {
 
                $username = trim( $username );
 
-               // default
                $gender = User::getDefaultOption( 'gender' );
 
                // allow prefix and normalize (e.g. "&#42;foo" -> "*foo" ).
index ea78b68..e012c71 100644 (file)
@@ -373,7 +373,6 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                        ];
                }
 
-               // Language
                $languages = Language::fetchLanguageNames( null, 'mwfile' );
                $languageCode = $this->config->get( 'LanguageCode' );
                if ( !array_key_exists( $languageCode, $languages ) ) {
index c555eb8..d06e8ac 100644 (file)
@@ -184,9 +184,9 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                                                $option = [ 'default' => $option ];
                                        }
                                        foreach ( $option as $skin => $data ) {
-                                               if ( !is_array( $option ) ) {
+                                               if ( !is_array( $data ) ) {
                                                        throw new InvalidArgumentException(
-                                                               "Invalid list error. '$option' given, array expected."
+                                                               "Invalid list error. '$data' given, array expected."
                                                        );
                                                }
                                        }
index b392625..eb174f0 100644 (file)
@@ -734,7 +734,6 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                }
                $content['scripts'] = $scripts;
 
-               // Styles
                $styles = [];
                // Don't create empty stylesheets like [ '' => '' ] for modules
                // that don't *have* any stylesheets (T40024).
@@ -944,7 +943,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                if ( !$this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
                        return $contents;
                }
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
                        $cache->makeGlobalKey(
                                'resourceloader',
index ecb1a09..a91537f 100644 (file)
@@ -26,6 +26,7 @@ use MediaWiki\Linker\LinkTarget;
 use Wikimedia\Assert\Assert;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Abstraction for ResourceLoader modules which pull from wiki pages
@@ -482,7 +483,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule {
                $func = [ static::class, 'fetchTitleInfo' ];
                $fname = __METHOD__;
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $allInfo = $cache->getWithSetCallback(
                        $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID(), $hash ),
                        $cache::TTL_HOUR,
@@ -549,7 +550,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule {
                }
 
                if ( $purge ) {
-                       $cache = ObjectCache::getMainWANInstance();
+                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                        $key = $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $domain );
                        $cache->touchCheckKey( $key );
                }
index bf28f60..54a715d 100644 (file)
@@ -105,7 +105,7 @@ class RevDelLogItem extends RevDelItem {
                $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
                // User links and action text
                $action = $formatter->getActionText();
-               // Comment
+
                $comment = CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
                $comment = $this->list->getLanguage()->getDirMark()
                        . Linker::commentBlock( $comment );
index c96cf8e..a8271ac 100644 (file)
@@ -25,6 +25,7 @@ use Wikimedia\Rdbms\DBQueryTimeoutError;
 use Wikimedia\Rdbms\IResultWrapper;
 use Wikimedia\Rdbms\FakeResultWrapper;
 use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Special page which uses a ChangesList to show query results.
@@ -845,7 +846,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
         * @return array Tag data
         */
        protected static function getChangeTagList( ResourceLoaderContext $context ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
                        $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage() ),
                        $cache::TTL_MINUTE * 10,
index 2bbc0bf..1f81cf0 100644 (file)
@@ -40,7 +40,6 @@ class SpecialNewpages extends IncludableSpecialPage {
        }
 
        protected function setup( $par ) {
-               // Options
                $opts = new FormOptions();
                $this->opts = $opts; // bind
                $opts->add( 'hideliu', false );
@@ -63,13 +62,11 @@ class SpecialNewpages extends IncludableSpecialPage {
                        $opts->add( $key, $params['default'] );
                }
 
-               // Set values
                $opts->fetchValuesFromRequest( $this->getRequest() );
                if ( $par ) {
                        $this->parseParams( $par );
                }
 
-               // Validate
                $opts->validateIntBounds( 'limit', 0, 5000 );
        }
 
index 0c74e76..110fb1f 100644 (file)
@@ -237,10 +237,8 @@ class SpecialTags extends SpecialPage {
                // add raw $hitcount for sorting, because tags-hitcount contains numbers and letters
                $newRow .= Xml::tags( 'td', [ 'data-sort-value' => $hitcount ], $hitcountLabel );
 
-               // actions
                $actionLinks = [];
 
-               // delete
                if ( $showDeleteActions && ChangeTags::canDeleteTag( $tag )->isOK() ) {
                        $actionLinks[] = $linkRenderer->makeKnownLink(
                                $this->getPageTitle( 'delete' ),
@@ -250,7 +248,6 @@ class SpecialTags extends SpecialPage {
                }
 
                if ( $showManageActions ) { // we've already checked that the user had the requisite userright
-                       // activate
                        if ( ChangeTags::canActivateTag( $tag )->isOK() ) {
                                $actionLinks[] = $linkRenderer->makeKnownLink(
                                        $this->getPageTitle( 'activate' ),
@@ -259,7 +256,6 @@ class SpecialTags extends SpecialPage {
                                        [ 'tag' => $tag ] );
                        }
 
-                       // deactivate
                        if ( ChangeTags::canDeactivateTag( $tag )->isOK() ) {
                                $actionLinks[] = $linkRenderer->makeKnownLink(
                                        $this->getPageTitle( 'deactivate' ),
index e8cd94a..6db219d 100644 (file)
@@ -473,7 +473,6 @@ class BotPassword implements IDBAccessObject {
                        return Status::newFatal( 'botpasswords-locked' );
                }
 
-               // Throttle
                $throttle = null;
                if ( !empty( $wgPasswordAttemptThrottle ) ) {
                        $throttle = new MediaWiki\Auth\Throttler( $wgPasswordAttemptThrottle, [
index 49627c3..76a5721 100644 (file)
@@ -254,7 +254,7 @@ class SyncFileBackend extends Maintenance {
                                        'src' => $fsFile->getPath(), 'dst' => $dPath, 'overwrite' => 1 ];
                        } elseif ( $sExists === false ) { // does not exist in source
                                $ops[] = [ 'op' => 'delete', 'src' => $dPath, 'ignoreMissingSource' => 1 ];
-                       } else { // error
+                       } else {
                                $this->error( "Unable to sync '$dPath': could not stat file." );
                                $status->fatal( 'backend-fail-internal', $src->getName() );
 
index 65e6855..7c6682e 100644 (file)
@@ -643,7 +643,7 @@ return [
                'group' => 'jquery.ui',
                'targets' => [ 'desktop', 'mobile' ],
        ],
-       // Effects
+
        'jquery.effects.core' => [
                'deprecated' => true,
                'scripts' => 'resources/lib/jquery.ui/jquery.ui.effect.js',
index 9f9378a..557bb3c 100644 (file)
                        padding-right: 1.875em + 0.5em;
 
                        > .oo-ui-buttonWidget {
-                               top: 50%;
-                               .transform( translateY( -50% ) );
+                               top: 0.5em;
                        }
 
                        > .oo-ui-iconWidget {
-                               float: none;
-                               display: inline-block;
-                               margin: 0;
+                               vertical-align: top;
                        }
 
                        > .oo-ui-labelElement-label {
                                float: none;
                                display: inline-block;
+                               // Label doesn't wrap without `max-width`. First setting a pretty arbitrary percentage value.
+                               max-width: 80%;
+                               // Overwrite it with `calc` reduced by icon width and left margin combined.
+                               max-width: calc( ~'100% - 1.42857143em - 0.25em' );
+                               margin: 0 0 0 0.25em;
                                font-size: 1.2em;
-                               margin: 0;
                                font-weight: bold;
-                               vertical-align: middle;
+                               line-height: 1.25;
+                               vertical-align: top;
                        }
                }
        }
index d550dcb..9b1a3dd 100644 (file)
@@ -55,7 +55,6 @@ class LinkRendererTest extends MediaWikiLangTestCase {
                        $linkRenderer->makeKnownLink( $target, null, [], [ 'foo' => 'bar' ] )
                );
 
-               // forcearticlepath
                $linkRenderer->setForceArticlePath( true );
                $this->assertEquals(
                        '<a href="/wiki/Foobar?foo=bar" title="Foobar">Foobar</a>',