Merge "Tests: Provide clearer error when config is accessed via unit test"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 5 Sep 2019 19:26:10 +0000 (19:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 5 Sep 2019 19:26:10 +0000 (19:26 +0000)
18 files changed:
includes/PathRouter.php
includes/Setup.php
includes/Title.php
includes/WebRequest.php
includes/cache/HTMLFileCache.php
includes/debug/MWDebug.php
includes/libs/http/MultiHttpClient.php
includes/libs/objectcache/wancache/WANObjectCache.php
includes/libs/rdbms/database/DatabaseMysqli.php
includes/page/Article.php
includes/registration/ExtensionRegistry.php
includes/resourceloader/ResourceLoaderFileModule.php
maintenance/Doxyfile
maintenance/importImages.php
maintenance/mwdocgen.php
maintenance/rebuildFileCache.php
tests/phpunit/MediaWikiIntegrationTestCase.php
tests/phpunit/includes/registration/ExtensionRegistryTest.php

index 2882e66..4d7bd38 100644 (file)
@@ -401,4 +401,22 @@ class PathRouter {
 
                return $value;
        }
+
+       /**
+        * @internal For use by Title and WebRequest only.
+        * @param array $actionPaths
+        * @param string $articlePath
+        * @return string[]|false
+        */
+       public static function getActionPaths( array $actionPaths, $articlePath ) {
+               if ( !$actionPaths ) {
+                       return false;
+               }
+               // Processing of urls for this feature requires that 'view' is set.
+               // By default, set it to the pretty article path.
+               if ( !isset( $actionPaths['view'] ) ) {
+                       $actionPaths['view'] = $articlePath;
+               }
+               return $actionPaths;
+       }
 }
index d629021..cfb2ac1 100644 (file)
@@ -156,12 +156,6 @@ if ( $wgArticlePath === false ) {
        }
 }
 
-if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
-       // 'view' is assumed the default action path everywhere in the code
-       // but is rarely filled in $wgActionPaths
-       $wgActionPaths['view'] = $wgArticlePath;
-}
-
 if ( $wgResourceBasePath === null ) {
        $wgResourceBasePath = $wgScriptPath;
 }
@@ -537,12 +531,6 @@ if ( isset( $wgSquidMaxage ) ) {
        $wgSquidMaxage = $wgCdnMaxAge;
 }
 
-// Easy to forget to falsify $wgDebugToolbar for static caches.
-// If file cache or CDN cache is on, just disable this (DWIMD).
-if ( $wgUseFileCache || $wgUseCdn ) {
-       $wgDebugToolbar = false;
-}
-
 // Blacklisted file extensions shouldn't appear on the "allowed" list
 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
 
@@ -611,12 +599,7 @@ if ( defined( 'MW_NO_SESSION' ) ) {
        $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable';
 }
 
-// Disable MWDebug for command line mode, this prevents MWDebug from eating up
-// all the memory from logging SQL queries on maintenance scripts
-global $wgCommandLineMode;
-if ( $wgDebugToolbar && !$wgCommandLineMode ) {
-       MWDebug::init();
-}
+MWDebug::setup();
 
 // Reset the global service locator, so any services that have already been created will be
 // re-created while taking into account any custom settings and extensions.
index 547b28c..1e93c44 100644 (file)
@@ -51,10 +51,11 @@ class Title implements LinkTarget, IDBAccessObject {
        const CACHE_MAX = 1000;
 
        /**
-        * Used to be GAID_FOR_UPDATE define. Used with getArticleID() and friends
-        * to use the master DB
+        * Used to be GAID_FOR_UPDATE define(). Used with getArticleID() and friends
+        * to use the master DB and inject it into link cache.
+        * @deprecated since 1.34, use Title::READ_LATEST instead.
         */
-       const GAID_FOR_UPDATE = 1;
+       const GAID_FOR_UPDATE = 512;
 
        /**
         * Flag for use with factory methods like newFromLinkTarget() that have
@@ -74,25 +75,18 @@ class Title implements LinkTarget, IDBAccessObject {
 
        /** @var string Text form (spaces not underscores) of the main part */
        public $mTextform = '';
-
        /** @var string URL-encoded form of the main part */
        public $mUrlform = '';
-
        /** @var string Main part with underscores */
        public $mDbkeyform = '';
-
        /** @var string Database key with the initial letter in the case specified by the user */
        protected $mUserCaseDBKey;
-
        /** @var int Namespace index, i.e. one of the NS_xxxx constants */
        public $mNamespace = NS_MAIN;
-
        /** @var string Interwiki prefix */
        public $mInterwiki = '';
-
        /** @var bool Was this Title created from a string with a local interwiki prefix? */
        private $mLocalInterwiki = false;
-
        /** @var string Title fragment (i.e. the bit after the #) */
        public $mFragment = '';
 
@@ -467,16 +461,18 @@ class Title implements LinkTarget, IDBAccessObject {
         * Create a new Title from an article ID
         *
         * @param int $id The page_id corresponding to the Title to create
-        * @param int $flags Use Title::GAID_FOR_UPDATE to use master
+        * @param int $flags Bitfield of class READ_* constants
         * @return Title|null The new object, or null on an error
         */
        public static function newFromID( $id, $flags = 0 ) {
-               $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_REPLICA );
-               $row = $db->selectRow(
+               $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
+               list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
+               $row = wfGetDB( $index )->selectRow(
                        'page',
                        self::getSelectFields(),
                        [ 'page_id' => $id ],
-                       __METHOD__
+                       __METHOD__,
+                       $options
                );
                if ( $row !== false ) {
                        $title = self::newFromRow( $row );
@@ -545,10 +541,10 @@ class Title implements LinkTarget, IDBAccessObject {
                        if ( isset( $row->page_latest ) ) {
                                $this->mLatestID = (int)$row->page_latest;
                        }
-                       if ( !$this->mForcedContentModel && isset( $row->page_content_model ) ) {
-                               $this->mContentModel = (string)$row->page_content_model;
-                       } elseif ( !$this->mForcedContentModel ) {
-                               $this->mContentModel = false; # initialized lazily in getContentModel()
+                       if ( isset( $row->page_content_model ) ) {
+                               $this->lazyFillContentModel( $row->page_content_model );
+                       } else {
+                               $this->lazyFillContentModel( false ); // lazily-load getContentModel()
                        }
                        if ( isset( $row->page_lang ) ) {
                                $this->mDbPageLanguage = (string)$row->page_lang;
@@ -561,9 +557,7 @@ class Title implements LinkTarget, IDBAccessObject {
                        $this->mLength = 0;
                        $this->mRedirect = false;
                        $this->mLatestID = 0;
-                       if ( !$this->mForcedContentModel ) {
-                               $this->mContentModel = false; # initialized lazily in getContentModel()
-                       }
+                       $this->lazyFillContentModel( false ); // lazily-load getContentModel()
                }
        }
 
@@ -598,7 +592,6 @@ class Title implements LinkTarget, IDBAccessObject {
                $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
                $t->mUrlform = wfUrlencode( $t->mDbkeyform );
                $t->mTextform = strtr( $title, '_', ' ' );
-               $t->mContentModel = false; # initialized lazily in getContentModel()
                return $t;
        }
 
@@ -676,7 +669,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * Get the prefixed DB key associated with an ID
         *
         * @param int $id The page_id of the article
-        * @return Title|null An object representing the article, or null if no such article was found
+        * @return string|null An object representing the article, or null if no such article was found
         */
        public static function nameOf( $id ) {
                $dbr = wfGetDB( DB_REPLICA );
@@ -691,8 +684,7 @@ class Title implements LinkTarget, IDBAccessObject {
                        return null;
                }
 
-               $n = self::makeName( $s->page_namespace, $s->page_title );
-               return $n;
+               return self::makeName( $s->page_namespace, $s->page_title );
        }
 
        /**
@@ -1051,21 +1043,31 @@ class Title implements LinkTarget, IDBAccessObject {
         *
         * @todo Deprecate this in favor of SlotRecord::getModel()
         *
-        * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @param int $flags Either a bitfield of class READ_* constants or GAID_FOR_UPDATE
         * @return string Content model id
         */
        public function getContentModel( $flags = 0 ) {
-               if ( !$this->mForcedContentModel
-                       && ( !$this->mContentModel || $flags === self::GAID_FOR_UPDATE )
-                       && $this->getArticleID( $flags )
+               if ( $this->mForcedContentModel ) {
+                       if ( !$this->mContentModel ) {
+                               throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
+                       }
+                       // Content model is locked to the currently loaded one
+                       return $this->mContentModel;
+               }
+
+               if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
+                       $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
+               } elseif (
+                       ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
+                       $this->getArticleId( $flags )
                ) {
                        $linkCache = MediaWikiServices::getInstance()->getLinkCache();
                        $linkCache->addLinkObj( $this ); # in case we already had an article ID
-                       $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
+                       $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
                }
 
                if ( !$this->mContentModel ) {
-                       $this->mContentModel = ContentHandler::getDefaultModelFor( $this );
+                       $this->lazyFillContentModel( ContentHandler::getDefaultModelFor( $this ) );
                }
 
                return $this->mContentModel;
@@ -1082,21 +1084,38 @@ class Title implements LinkTarget, IDBAccessObject {
        }
 
        /**
-        * Set a proposed content model for the page for permissions
-        * checking. This does not actually change the content model
-        * of a title!
+        * Set a proposed content model for the page for permissions checking
+        *
+        * This does not actually change the content model of a title in the DB.
+        * It only affects this particular Title instance. The content model is
+        * forced to remain this value until another setContentModel() call.
         *
-        * Additionally, you should make sure you've checked
-        * ContentHandler::canBeUsedOn() first.
+        * ContentHandler::canBeUsedOn() should be checked before calling this
+        * if there is any doubt regarding the applicability of the content model
         *
         * @since 1.28
         * @param string $model CONTENT_MODEL_XXX constant
         */
        public function setContentModel( $model ) {
+               if ( (string)$model === '' ) {
+                       throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
+               }
+
                $this->mContentModel = $model;
                $this->mForcedContentModel = true;
        }
 
+       /**
+        * If the content model field is not frozen then update it with a retreived value
+        *
+        * @param string|bool $model CONTENT_MODEL_XXX constant or false
+        */
+       private function lazyFillContentModel( $model ) {
+               if ( !$this->mForcedContentModel ) {
+                       $this->mContentModel = ( $model === false ) ? false : (string)$model;
+               }
+       }
+
        /**
         * Get the namespace text
         *
@@ -2068,16 +2087,18 @@ class Title implements LinkTarget, IDBAccessObject {
                                $url = false;
                                $matches = [];
 
-                               if ( !empty( $wgActionPaths )
+                               $articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath );
+
+                               if ( $articlePaths
                                        && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
                                ) {
                                        $action = urldecode( $matches[2] );
-                                       if ( isset( $wgActionPaths[$action] ) ) {
+                                       if ( isset( $articlePaths[$action] ) ) {
                                                $query = $matches[1];
                                                if ( isset( $matches[4] ) ) {
                                                        $query .= $matches[4];
                                                }
-                                               $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
+                                               $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
                                                if ( $query != '' ) {
                                                        $url = wfAppendQuery( $url, $query );
                                                }
@@ -2796,10 +2817,7 @@ class Title implements LinkTarget, IDBAccessObject {
                        return;
                }
 
-               // TODO: should probably pass $flags into getArticleID, but it seems hacky
-               // to mix READ_LATEST and GAID_FOR_UPDATE, even if they have the same value.
-               // Maybe deprecate GAID_FOR_UPDATE now that we implement IDBAccessObject?
-               $id = $this->getArticleID();
+               $id = $this->getArticleID( $flags );
                if ( $id ) {
                        $fname = __METHOD__;
                        $loadRestrictionsFromDb = function ( IDatabase $dbr ) use ( $fname, $id ) {
@@ -3023,24 +3041,28 @@ class Title implements LinkTarget, IDBAccessObject {
         * Get the article ID for this Title from the link cache,
         * adding it if necessary
         *
-        * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select
-        *  for update
+        * @param int $flags Either a bitfield of class READ_* constants or GAID_FOR_UPDATE
         * @return int The ID
         */
        public function getArticleID( $flags = 0 ) {
                if ( $this->mNamespace < 0 ) {
                        $this->mArticleID = 0;
+
                        return $this->mArticleID;
                }
+
                $linkCache = MediaWikiServices::getInstance()->getLinkCache();
                if ( $flags & self::GAID_FOR_UPDATE ) {
                        $oldUpdate = $linkCache->forUpdate( true );
                        $linkCache->clearLink( $this );
                        $this->mArticleID = $linkCache->addLinkObj( $this );
                        $linkCache->forUpdate( $oldUpdate );
+               } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
+                       $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
                } elseif ( $this->mArticleID == -1 ) {
                        $this->mArticleID = $linkCache->addLinkObj( $this );
                }
+
                return $this->mArticleID;
        }
 
@@ -3048,33 +3070,27 @@ class Title implements LinkTarget, IDBAccessObject {
         * Is this an article that is a redirect page?
         * Uses link cache, adding it if necessary
         *
-        * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @param int $flags Either a bitfield of class READ_* constants or GAID_FOR_UPDATE
         * @return bool
         */
        public function isRedirect( $flags = 0 ) {
-               if ( !is_null( $this->mRedirect ) ) {
-                       return $this->mRedirect;
-               }
-               if ( !$this->getArticleID( $flags ) ) {
-                       $this->mRedirect = false;
-                       return $this->mRedirect;
-               }
+               if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
+                       $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
+               } else {
+                       if ( $this->mRedirect !== null ) {
+                               return $this->mRedirect;
+                       } elseif ( !$this->getArticleID( $flags ) ) {
+                               $this->mRedirect = false;
 
-               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
-               $linkCache->addLinkObj( $this ); # in case we already had an article ID
-               $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
-               if ( $cached === null ) {
-                       # Trust LinkCache's state over our own
-                       # LinkCache is telling us that the page doesn't exist, despite there being cached
-                       # data relating to an existing page in $this->mArticleID. Updaters should clear
-                       # LinkCache as appropriate, or use $flags = Title::GAID_FOR_UPDATE. If that flag is
-                       # set, then LinkCache will definitely be up to date here, since getArticleID() forces
-                       # LinkCache to refresh its data from the master.
-                       $this->mRedirect = false;
-                       return $this->mRedirect;
-               }
+                               return $this->mRedirect;
+                       }
 
-               $this->mRedirect = (bool)$cached;
+                       $linkCache = MediaWikiServices::getInstance()->getLinkCache();
+                       $linkCache->addLinkObj( $this ); // in case we already had an article ID
+                       // Note that LinkCache returns null if it thinks the page does not exist;
+                       // always trust the state of LinkCache over that of this Title instance.
+                       $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
+               }
 
                return $this->mRedirect;
        }
@@ -3083,27 +3099,26 @@ class Title implements LinkTarget, IDBAccessObject {
         * What is the length of this page?
         * Uses link cache, adding it if necessary
         *
-        * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @param int $flags Either a bitfield of class READ_* constants or GAID_FOR_UPDATE
         * @return int
         */
        public function getLength( $flags = 0 ) {
-               if ( $this->mLength != -1 ) {
-                       return $this->mLength;
-               }
-               if ( !$this->getArticleID( $flags ) ) {
-                       $this->mLength = 0;
-                       return $this->mLength;
-               }
-               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
-               $linkCache->addLinkObj( $this ); # in case we already had an article ID
-               $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
-               if ( $cached === null ) {
-                       # Trust LinkCache's state over our own, as for isRedirect()
-                       $this->mLength = 0;
-                       return $this->mLength;
-               }
+               if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
+                       $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
+               } else {
+                       if ( $this->mLength != -1 ) {
+                               return $this->mLength;
+                       } elseif ( !$this->getArticleID( $flags ) ) {
+                               $this->mLength = 0;
+                               return $this->mLength;
+                       }
 
-               $this->mLength = intval( $cached );
+                       $linkCache = MediaWikiServices::getInstance()->getLinkCache();
+                       $linkCache->addLinkObj( $this ); // in case we already had an article ID
+                       // Note that LinkCache returns null if it thinks the page does not exist;
+                       // always trust the state of LinkCache over that of this Title instance.
+                       $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
+               }
 
                return $this->mLength;
        }
@@ -3111,49 +3126,46 @@ class Title implements LinkTarget, IDBAccessObject {
        /**
         * What is the page_latest field for this page?
         *
-        * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @param int $flags Either a bitfield of class READ_* constants or GAID_FOR_UPDATE
         * @return int Int or 0 if the page doesn't exist
         */
        public function getLatestRevID( $flags = 0 ) {
-               if ( !( $flags & self::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) {
-                       return intval( $this->mLatestID );
-               }
-               if ( !$this->getArticleID( $flags ) ) {
-                       $this->mLatestID = 0;
-                       return $this->mLatestID;
-               }
-               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
-               $linkCache->addLinkObj( $this ); # in case we already had an article ID
-               $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
-               if ( $cached === null ) {
-                       # Trust LinkCache's state over our own, as for isRedirect()
-                       $this->mLatestID = 0;
-                       return $this->mLatestID;
-               }
+               if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
+                       $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
+               } else {
+                       if ( $this->mLatestID !== false ) {
+                               return (int)$this->mLatestID;
+                       } elseif ( !$this->getArticleID( $flags ) ) {
+                               $this->mLatestID = 0;
+
+                               return $this->mLatestID;
+                       }
 
-               $this->mLatestID = intval( $cached );
+                       $linkCache = MediaWikiServices::getInstance()->getLinkCache();
+                       $linkCache->addLinkObj( $this ); // in case we already had an article ID
+                       // Note that LinkCache returns null if it thinks the page does not exist;
+                       // always trust the state of LinkCache over that of this Title instance.
+                       $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
+               }
 
                return $this->mLatestID;
        }
 
        /**
-        * This clears some fields in this object, and clears any associated
-        * keys in the "bad links" section of the link cache.
+        * Inject a page ID, reset DB-loaded fields, and clear the link cache for this title
+        *
+        * This can be called on page insertion to allow loading of the new page_id without
+        * having to create a new Title instance. Likewise with deletion.
         *
-        * - This is called from WikiPage::doEditContent() and WikiPage::insertOn() to allow
-        * loading of the new page_id. It's also called from
-        * WikiPage::doDeleteArticleReal()
+        * @note This overrides Title::setContentModel()
         *
-        * @param int $newid The new Article ID
+        * @param int|bool $id Page ID, 0 for non-existant, or false for "unknown" (lazy-load)
         */
-       public function resetArticleID( $newid ) {
-               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
-               $linkCache->clearLink( $this );
-
-               if ( $newid === false ) {
+       public function resetArticleID( $id ) {
+               if ( $id === false ) {
                        $this->mArticleID = -1;
                } else {
-                       $this->mArticleID = intval( $newid );
+                       $this->mArticleID = (int)$id;
                }
                $this->mRestrictionsLoaded = false;
                $this->mRestrictions = [];
@@ -3162,10 +3174,13 @@ class Title implements LinkTarget, IDBAccessObject {
                $this->mLength = -1;
                $this->mLatestID = false;
                $this->mContentModel = false;
+               $this->mForcedContentModel = false;
                $this->mEstimateRevisions = null;
                $this->mPageLanguage = null;
                $this->mDbPageLanguage = false;
                $this->mIsBigDeletion = null;
+
+               MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
        }
 
        public static function clearCaches() {
@@ -3499,6 +3514,7 @@ class Title implements LinkTarget, IDBAccessObject {
 
                $mp = MediaWikiServices::getInstance()->getMovePageFactory()->newMovePage( $this, $nt );
                $method = $auth ? 'moveIfAllowed' : 'move';
+               /** @var Status $status */
                $status = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags );
                if ( $status->isOK() ) {
                        return true;
@@ -3531,6 +3547,7 @@ class Title implements LinkTarget, IDBAccessObject {
 
                $mp = new MovePage( $this, $nt );
                $method = $auth ? 'moveSubpagesIfAllowed' : 'moveSubpages';
+               /** @var Status $result */
                $result = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags );
 
                if ( !$result->isOK() ) {
@@ -3539,6 +3556,7 @@ class Title implements LinkTarget, IDBAccessObject {
 
                $retval = [];
                foreach ( $result->getValue() as $key => $status ) {
+                       /** @var Status $status */
                        if ( $status->isOK() ) {
                                $retval[$key] = $status->getValue();
                        } else {
@@ -3549,8 +3567,9 @@ class Title implements LinkTarget, IDBAccessObject {
        }
 
        /**
-        * Checks if this page is just a one-rev redirect.
-        * Adds lock, so don't use just for light purposes.
+        * Locks the page row and check if this page is single revision redirect
+        *
+        * This updates the cached fields of this instance via Title::loadFromRow()
         *
         * @return bool
         */
@@ -3730,24 +3749,22 @@ class Title implements LinkTarget, IDBAccessObject {
        /**
         * Get next/previous revision ID relative to another revision ID
         * @param int $revId Revision ID. Get the revision that was before this one.
-        * @param int $flags Title::GAID_FOR_UPDATE
+        * @param int $flags Bitfield of class READ_* constants
         * @param string $dir 'next' or 'prev'
         * @return int|bool New revision ID, or false if none exists
         */
        private function getRelativeRevisionID( $revId, $flags, $dir ) {
                $rl = MediaWikiServices::getInstance()->getRevisionLookup();
-               $rlFlags = $flags === self::GAID_FOR_UPDATE ? IDBAccessObject::READ_LATEST : 0;
-               $rev = $rl->getRevisionById( $revId, $rlFlags );
+               $rev = $rl->getRevisionById( $revId, $flags );
                if ( !$rev ) {
                        return false;
                }
-               $oldRev = $dir === 'next'
-                       ? $rl->getNextRevision( $rev, $rlFlags )
-                       : $rl->getPreviousRevision( $rev, $rlFlags );
-               if ( !$oldRev ) {
-                       return false;
-               }
-               return $oldRev->getId();
+
+               $oldRev = ( $dir === 'next' )
+                       ? $rl->getNextRevision( $rev, $flags )
+                       : $rl->getPreviousRevision( $rev, $flags );
+
+               return $oldRev ? $oldRev->getId() : false;
        }
 
        /**
@@ -3755,7 +3772,7 @@ class Title implements LinkTarget, IDBAccessObject {
         *
         * @deprecated since 1.34, use RevisionLookup::getPreviousRevision
         * @param int $revId Revision ID. Get the revision that was before this one.
-        * @param int $flags Title::GAID_FOR_UPDATE
+        * @param int $flags Bitfield of class READ_* constants
         * @return int|bool Old revision ID, or false if none exists
         */
        public function getPreviousRevisionID( $revId, $flags = 0 ) {
@@ -3767,7 +3784,7 @@ class Title implements LinkTarget, IDBAccessObject {
         *
         * @deprecated since 1.34, use RevisionLookup::getNextRevision
         * @param int $revId Revision ID. Get the revision that was after this one.
-        * @param int $flags Title::GAID_FOR_UPDATE
+        * @param int $flags Bitfield of class READ_* constants
         * @return int|bool Next revision ID, or false if none exists
         */
        public function getNextRevisionID( $revId, $flags = 0 ) {
@@ -3777,21 +3794,26 @@ class Title implements LinkTarget, IDBAccessObject {
        /**
         * Get the first revision of the page
         *
-        * @param int $flags Title::GAID_FOR_UPDATE
+        * @param int $flags Bitfield of class READ_* constants
         * @return Revision|null If page doesn't exist
         */
        public function getFirstRevision( $flags = 0 ) {
                $pageId = $this->getArticleID( $flags );
                if ( $pageId ) {
-                       $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_REPLICA );
+                       $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
+                       list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
                        $revQuery = Revision::getQueryInfo();
-                       $row = $db->selectRow( $revQuery['tables'], $revQuery['fields'],
+                       $row = wfGetDB( $index )->selectRow(
+                               $revQuery['tables'], $revQuery['fields'],
                                [ 'rev_page' => $pageId ],
                                __METHOD__,
-                               [
-                                       'ORDER BY' => 'rev_timestamp ASC, rev_id ASC',
-                                       'IGNORE INDEX' => [ 'revision' => 'rev_timestamp' ], // See T159319
-                               ],
+                               array_merge(
+                                       [
+                                               'ORDER BY' => 'rev_timestamp ASC, rev_id ASC',
+                                               'IGNORE INDEX' => [ 'revision' => 'rev_timestamp' ], // See T159319
+                                       ],
+                                       $options
+                               ),
                                $revQuery['joins']
                        );
                        if ( $row ) {
@@ -3804,7 +3826,7 @@ class Title implements LinkTarget, IDBAccessObject {
        /**
         * Get the oldest revision timestamp of this page
         *
-        * @param int $flags Title::GAID_FOR_UPDATE
+        * @param int $flags Bitfield of class READ_* constants
         * @return string|null MW timestamp
         */
        public function getEarliestRevTime( $flags = 0 ) {
@@ -4035,8 +4057,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * If you want to know if a title can be meaningfully viewed, you should
         * probably call the isKnown() method instead.
         *
-        * @param int $flags An optional bit field; may be Title::GAID_FOR_UPDATE to check
-        *   from master/for update
+        * @param int $flags Either a bitfield of class READ_* constants or GAID_FOR_UPDATE
         * @return bool
         */
        public function exists( $flags = 0 ) {
@@ -4632,6 +4653,27 @@ class Title implements LinkTarget, IDBAccessObject {
                return $notices;
        }
 
+       /**
+        * @param int $flags Bitfield of class READ_* constants
+        * @return string|bool
+        */
+       private function loadFieldFromDB( $field, $flags ) {
+               if ( !in_array( $field, self::getSelectFields(), true ) ) {
+                       return false; // field does not exist
+               }
+
+               $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
+               list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
+
+               return wfGetDB( $index )->selectField(
+                       'page',
+                       $field,
+                       $this->pageCond(),
+                       __METHOD__,
+                       $options
+               );
+       }
+
        /**
         * @return array
         */
index 9b8f5a6..7b14667 100644 (file)
@@ -162,8 +162,9 @@ class WebRequest {
                        }
 
                        global $wgActionPaths;
-                       if ( $wgActionPaths ) {
-                               $router->add( $wgActionPaths, [ 'action' => '$key' ] );
+                       $articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath );
+                       if ( $articlePaths ) {
+                               $router->add( $articlePaths, [ 'action' => '$key' ] );
                        }
 
                        global $wgVariantArticlePath;
index a0d61b2..ab78ee4 100644 (file)
@@ -94,10 +94,6 @@ class HTMLFileCache extends FileCacheBase {
                $config = MediaWikiServices::getInstance()->getMainConfig();
 
                if ( !$config->get( 'UseFileCache' ) && $mode !== self::MODE_REBUILD ) {
-                       return false;
-               } elseif ( $config->get( 'DebugToolbar' ) ) {
-                       wfDebug( "HTML file cache skipped. \$wgDebugToolbar on\n" );
-
                        return false;
                }
 
index e877836..6bcb0e6 100644 (file)
@@ -67,6 +67,30 @@ class MWDebug {
         */
        protected static $deprecationWarnings = [];
 
+       /**
+        * @internal For use by Setup.php only.
+        */
+       public static function setup() {
+               global $wgDebugToolbar,
+                       $wgUseCdn, $wgUseFileCache, $wgCommandLineMode;
+
+               if (
+                       // Easy to forget to falsify $wgDebugToolbar for static caches.
+                       // If file cache or CDN cache is on, just disable this (DWIMD).
+                       $wgUseCdn ||
+                       $wgUseFileCache ||
+                       // Keep MWDebug off on CLI. This prevents MWDebug from eating up
+                       // all the memory for logging SQL queries in maintenance scripts.
+                       $wgCommandLineMode
+               ) {
+                       return;
+               }
+
+               if ( $wgDebugToolbar ) {
+                       self::init();
+               }
+       }
+
        /**
         * Enabled the debugger and load resource module.
         * This is called by Setup.php when $wgDebugToolbar is true.
index 2e3aa70..e099fdb 100644 (file)
@@ -161,6 +161,8 @@ class MultiHttpClient implements LoggerAwareInterface {
         */
        public function runMulti( array $reqs, array $opts = [] ) {
                $this->normalizeRequests( $reqs );
+               $opts += [ 'connTimeout' => $this->connTimeout, 'reqTimeout' => $this->reqTimeout ];
+
                if ( $this->isCurlEnabled() ) {
                        return $this->runMultiCurl( $reqs, $opts );
                } else {
@@ -195,7 +197,7 @@ class MultiHttpClient implements LoggerAwareInterface {
         * @throws Exception
         * @suppress PhanTypeInvalidDimOffset
         */
-       private function runMultiCurl( array $reqs, array $opts = [] ) {
+       private function runMultiCurl( array $reqs, array $opts ) {
                $chm = $this->getCurlMulti();
 
                $selectTimeout = $this->getSelectTimeout( $opts );
@@ -293,20 +295,18 @@ class MultiHttpClient implements LoggerAwareInterface {
        /**
         * @param array &$req HTTP request map
         * @param array $opts
-        *   - connTimeout    : default connection timeout
-        *   - reqTimeout     : default request timeout
+        *   - connTimeout : default connection timeout
+        *   - reqTimeout : default request timeout
         * @return resource
         * @throws Exception
         * @suppress PhanTypeMismatchArgumentInternal
         */
-       protected function getCurlHandle( array &$req, array $opts = [] ) {
+       protected function getCurlHandle( array &$req, array $opts ) {
                $ch = curl_init();
 
-               curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT_MS,
-                       ( $opts['connTimeout'] ?? $this->connTimeout ) * 1000 );
                curl_setopt( $ch, CURLOPT_PROXY, $req['proxy'] ?? $this->proxy );
-               curl_setopt( $ch, CURLOPT_TIMEOUT_MS,
-                       ( $opts['reqTimeout'] ?? $this->reqTimeout ) * 1000 );
+               curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT_MS, intval( $opts['connTimeout'] * 1e3 ) );
+               curl_setopt( $ch, CURLOPT_TIMEOUT_MS, intval( $opts['reqTimeout'] * 1e3 ) );
                curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
                curl_setopt( $ch, CURLOPT_MAXREDIRS, 4 );
                curl_setopt( $ch, CURLOPT_HEADER, 0 );
@@ -322,11 +322,8 @@ class MultiHttpClient implements LoggerAwareInterface {
                        $url .= strpos( $req['url'], '?' ) === false ? "?$query" : "&$query";
                }
                curl_setopt( $ch, CURLOPT_URL, $url );
-
                curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $req['method'] );
-               if ( $req['method'] === 'HEAD' ) {
-                       curl_setopt( $ch, CURLOPT_NOBODY, 1 );
-               }
+               curl_setopt( $ch, CURLOPT_NOBODY, ( $req['method'] === 'HEAD' ) );
 
                if ( $req['method'] === 'PUT' ) {
                        curl_setopt( $ch, CURLOPT_PUT, 1 );
@@ -358,10 +355,6 @@ class MultiHttpClient implements LoggerAwareInterface {
                        );
                } elseif ( $req['method'] === 'POST' ) {
                        curl_setopt( $ch, CURLOPT_POST, 1 );
-                       // Don't interpret POST parameters starting with '@' as file uploads, because this
-                       // makes it impossible to POST plain values starting with '@' (and causes security
-                       // issues potentially exposing the contents of local files).
-                       curl_setopt( $ch, CURLOPT_SAFE_UPLOAD, true );
                        curl_setopt( $ch, CURLOPT_POSTFIELDS, $req['body'] );
                } else {
                        if ( is_resource( $req['body'] ) || $req['body'] !== '' ) {
@@ -410,23 +403,19 @@ class MultiHttpClient implements LoggerAwareInterface {
                        }
                );
 
-               if ( isset( $req['stream'] ) ) {
-                       // Don't just use CURLOPT_FILE as that might give:
-                       // curl_setopt(): cannot represent a stream of type Output as a STDIO FILE*
-                       // The callback here handles both normal files and php://temp handles.
-                       curl_setopt( $ch, CURLOPT_WRITEFUNCTION,
-                               function ( $ch, $data ) use ( &$req ) {
+               // This works with both file and php://temp handles (unlike CURLOPT_FILE)
+               $hasOutputStream = isset( $req['stream'] );
+               curl_setopt( $ch, CURLOPT_WRITEFUNCTION,
+                       function ( $ch, $data ) use ( &$req, $hasOutputStream ) {
+                               if ( $hasOutputStream ) {
                                        return fwrite( $req['stream'], $data );
-                               }
-                       );
-               } else {
-                       curl_setopt( $ch, CURLOPT_WRITEFUNCTION,
-                               function ( $ch, $data ) use ( &$req ) {
+                               } else {
                                        $req['response']['body'] .= $data;
+
                                        return strlen( $data );
                                }
-                       );
-               }
+                       }
+               );
 
                return $ch;
        }
index a090e16..629d2cd 100644 (file)
@@ -125,7 +125,7 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt
        /** @var callable|null Function that takes a WAN cache callback and runs it later */
        protected $asyncHandler;
 
-       /** @bar bool Whether to use mcrouter key prefixing for routing */
+       /** @var bool Whether to use mcrouter key prefixing for routing */
        protected $mcrouterAware;
        /** @var string Physical region for mcrouter use */
        protected $region;
index 106772b..b9a1af6 100644 (file)
@@ -26,6 +26,7 @@ use mysqli;
 use mysqli_result;
 use IP;
 use stdClass;
+use Wikimedia\AtEase\AtEase;
 
 /**
  * Database abstraction object for PHP extension mysqli.
@@ -41,7 +42,11 @@ class DatabaseMysqli extends DatabaseMysqlBase {
         * @return mysqli_result|bool
         */
        protected function doQuery( $sql ) {
-               return $this->getBindingHandle()->query( $sql );
+               AtEase::suppressWarnings();
+               $res = $this->getBindingHandle()->query( $sql );
+               AtEase::restoreWarnings();
+
+               return $res;
        }
 
        /**
index 0149171..1c2e782 100644 (file)
@@ -587,7 +587,7 @@ class Article implements Page {
         * page of the given title.
         */
        public function view() {
-               global $wgUseFileCache, $wgDebugToolbar;
+               global $wgUseFileCache;
 
                # Get variables from query string
                # As side effect this will load the revision and update the title
@@ -643,7 +643,7 @@ class Article implements Page {
                }
 
                # Try client and file cache
-               if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
+               if ( $oldid === 0 && $this->mPage->checkTouched() ) {
                        # Try to stream the output from file cache
                        if ( $wgUseFileCache && $this->tryFileCache() ) {
                                wfDebug( __METHOD__ . ": done file cache\n" );
index 07fe318..c5d4b4a 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Composer\Semver\Semver;
+use Wikimedia\AtEase\AtEase;
 use Wikimedia\ScopedCallback;
 use MediaWiki\Shell\Shell;
 use MediaWiki\ShellDisabledError;
@@ -126,15 +127,13 @@ class ExtensionRegistry {
 
                $mtime = $wgExtensionInfoMTime;
                if ( $mtime === false ) {
-                       if ( file_exists( $path ) ) {
-                               $mtime = filemtime( $path );
-                       } else {
-                               throw new Exception( "$path does not exist!" );
-                       }
+                       AtEase::suppressWarnings();
+                       $mtime = filemtime( $path );
+                       AtEase::restoreWarnings();
                        // @codeCoverageIgnoreStart
                        if ( $mtime === false ) {
                                $err = error_get_last();
-                               throw new Exception( "Couldn't stat $path: {$err['message']}" );
+                               throw new Exception( "Unable to open file $path: {$err['message']}" );
                                // @codeCoverageIgnoreEnd
                        }
                }
index d308d50..f2d0856 100644 (file)
@@ -798,9 +798,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        /**
         * Get a list of file paths for all styles in this module, in order of proper inclusion.
         *
-        * This is considered a private method. Exposed for internal use by WebInstallerOutput.
-        *
-        * @private
+        * @internal Exposed only for use by WebInstallerOutput.
         * @param ResourceLoaderContext $context
         * @return array List of file paths
         */
index e5a8d98..dcd147f 100644 (file)
@@ -55,13 +55,17 @@ ALIASES                = "type{1}=<b> \1 </b>:" \
                          "protected=\access protected" \
                          "copyright=\note" \
                          "license=\note" \
+                         "inheritDoc=\inheritdoc" \
                          "codeCoverageIgnore=" \
+                         "codingStandardsIgnoreEnd=" \
                          "codingStandardsIgnoreStart=" \
-                         "group=" \
                          "covers=" \
                          "dataProvider=" \
                          "expectedException=" \
-                         "expectedExceptionMessage="
+                         "expectedExceptionMessage=" \
+                         "group=" \
+                         "phan=" \
+                         "suppress="
 TCL_SUBST              =
 OPTIMIZE_OUTPUT_FOR_C  = NO
 OPTIMIZE_OUTPUT_JAVA   = NO
index 4065978..d0d8a4b 100644 (file)
  * @author Mij <mij@bitchx.it>
  */
 
-use MediaWiki\MediaWikiServices;
-
 require_once __DIR__ . '/Maintenance.php';
 
+use MediaWiki\MediaWikiServices;
+
 class ImportImages extends Maintenance {
 
        public function __construct() {
@@ -127,6 +127,8 @@ class ImportImages extends Maintenance {
        public function execute() {
                global $wgFileExtensions, $wgUser, $wgRestrictionLevels;
 
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+
                $processed = $added = $ignored = $skipped = $overwritten = $failed = 0;
 
                $this->output( "Importing Files\n\n" );
@@ -213,10 +215,12 @@ class ImportImages extends Maintenance {
 
                                if ( $checkUserBlock && ( ( $processed % $checkUserBlock ) == 0 ) ) {
                                        $user->clearInstanceCache( 'name' ); // reload from DB!
-                                       // @TODO Use PermissionManager::isBlockedFrom() instead.
-                                       if ( $user->getBlock() ) {
-                                               $this->output( $user->getName() . " was blocked! Aborting.\n" );
-                                               break;
+                                       if ( $permissionManager->isBlockedFrom( $user, $title ) ) {
+                                               $this->output(
+                                                       "{$user->getName()} is blocked from {$title->getPrefixedText()}! skipping.\n"
+                                               );
+                                               $skipped++;
+                                               continue;
                                        }
                                }
 
index 791b360..e2c2629 100644 (file)
@@ -99,6 +99,7 @@ class MWDocGen extends Maintenance {
                $this->excludes = [
                        'vendor',
                        'node_modules',
+                       'resources/lib',
                        'images',
                        'static',
                ];
index 2cdf418..d484392 100644 (file)
@@ -43,18 +43,18 @@ class RebuildFileCache extends Maintenance {
        }
 
        public function finalSetup() {
-               global $wgDebugToolbar, $wgUseFileCache;
+               global $wgUseFileCache;
 
                $this->enabled = $wgUseFileCache;
                // Script will handle capturing output and saving it itself
                $wgUseFileCache = false;
-               // Debug toolbar makes content uncacheable so we disable it.
-               // Has to be done before Setup.php initialize MWDebug
-               $wgDebugToolbar = false;
                //  Avoid DB writes (like enotif/counters)
                MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
                        ->setReason( 'Building cache' );
 
+               // Ensure no debug-specific logic ends up in the cache (must be after Setup.php)
+               MWDebug::deinit();
+
                parent::finalSetup();
        }
 
index 41c65b2..b738312 100644 (file)
@@ -1830,6 +1830,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        $pageTables = [
                                'page', 'revision', 'ip_changes', 'revision_comment_temp', 'comment', 'archive',
                                'revision_actor_temp', 'slots', 'content', 'content_models', 'slot_roles',
+                               'change_tag',
                        ];
                        $coreDBDataTables = array_merge( $userTables, $pageTables );
 
index 5de1b0c..106cca3 100644 (file)
@@ -19,7 +19,7 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                $path = __DIR__ . '/doesnotexist.json';
                $this->setExpectedException(
                        Exception::class,
-                       "$path does not exist!"
+                       "file $path"
                );
                $registry->queue( $path );
        }