Merge "Protected function UploadBase->validateName changed to public"
[lhc/web/wiklou.git] / includes / Title.php
index 46b0524..a40e444 100644 (file)
@@ -96,7 +96,7 @@ class Title {
        /**
         * Create a new Title from a prefixed DB key
         *
-        * @param $key String the database key, which has underscores
+        * @param string $key the database key, which has underscores
         *      instead of spaces, possibly including namespace and
         *      interwiki prefixes
         * @return Title, or NULL on an error
@@ -115,10 +115,10 @@ class Title {
         * Create a new Title from text, such as what one would find in a link. De-
         * codes any HTML entities in the text.
         *
-        * @param $text String the link text; spaces, prefixes, and an
+        * @param string $text the link text; spaces, prefixes, and an
         *   initial ':' indicating the main namespace are accepted.
-        * @param $defaultNamespace Int the namespace to use if none is speci-
-        *   fied by a prefix.  If you want to force a specific namespace even if
+        * @param int $defaultNamespace the namespace to use if none is specified
+        *   by a prefix.  If you want to force a specific namespace even if
         *   $text might begin with a namespace prefix, use makeTitle() or
         *   makeTitleSafe().
         * @throws MWException
@@ -178,7 +178,7 @@ class Title {
         * Create a new Title from URL-encoded text. Ensures that
         * the given title's length does not exceed the maximum.
         *
-        * @param $url String the title, as might be taken from a URL
+        * @param string $url the title, as might be taken from a URL
         * @return Title the new object, or NULL on an error
         */
        public static function newFromURL( $url ) {
@@ -223,8 +223,8 @@ class Title {
        /**
         * Create a new Title from an article ID
         *
-        * @param $id Int the page_id corresponding to the Title to create
-        * @param $flags Int use Title::GAID_FOR_UPDATE to use master
+        * @param int $id the page_id corresponding to the Title to create
+        * @param int $flags use Title::GAID_FOR_UPDATE to use master
         * @return Title the new object, or NULL on an error
         */
        public static function newFromID( $id, $flags = 0 ) {
@@ -246,7 +246,7 @@ class Title {
        /**
         * Make an array of titles from an array of IDs
         *
-        * @param $ids Array of Int Array of IDs
+        * @param array $ids of Int Array of IDs
         * @return Array of Titles
         */
        public static function newFromIDs( $ids ) {
@@ -317,10 +317,10 @@ class Title {
         * For convenience, spaces are converted to underscores so that
         * eg user_text fields can be used directly.
         *
-        * @param $ns Int the namespace of the article
-        * @param $title String the unprefixed database key form
-        * @param $fragment String the link fragment (after the "#")
-        * @param $interwiki String the interwiki prefix
+        * @param int $ns the namespace of the article
+        * @param string $title the unprefixed database key form
+        * @param string $fragment the link fragment (after the "#")
+        * @param string $interwiki the interwiki prefix
         * @return Title the new object
         */
        public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
@@ -341,10 +341,10 @@ class Title {
         * The parameters will be checked for validity, which is a bit slower
         * than makeTitle() but safer for user-provided data.
         *
-        * @param $ns Int the namespace of the article
-        * @param $title String database key form
-        * @param $fragment String the link fragment (after the "#")
-        * @param $interwiki String interwiki prefix
+        * @param int $ns the namespace of the article
+        * @param string $title database key form
+        * @param string $fragment the link fragment (after the "#")
+        * @param string $interwiki interwiki prefix
         * @return Title the new object, or NULL on an error
         */
        public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
@@ -381,7 +381,7 @@ class Title {
         * This will only return the very next target, useful for
         * the redirect table and other checks that don't need full recursion
         *
-        * @param $text String: Text with possible redirect
+        * @param string $text Text with possible redirect
         * @return Title: The corresponding Title
         * @deprecated since 1.21, use Content::getRedirectTarget instead.
         */
@@ -398,7 +398,7 @@ class Title {
         * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit
         * in order to provide (hopefully) the Title of the final destination instead of another redirect
         *
-        * @param $text String Text with possible redirect
+        * @param string $text Text with possible redirect
         * @return Title
         * @deprecated since 1.21, use Content::getUltimateRedirectTarget instead.
         */
@@ -415,7 +415,7 @@ class Title {
         * The last element in the array is the final destination after all redirects
         * have been resolved (up to $wgMaxRedirects times)
         *
-        * @param $text String Text with possible redirect
+        * @param string $text Text with possible redirect
         * @return Array of Titles, with the destination last
         * @deprecated since 1.21, use Content::getRedirectChain instead.
         */
@@ -429,7 +429,7 @@ class Title {
        /**
         * Get the prefixed DB key associated with an ID
         *
-        * @param $id Int the page_id of the article
+        * @param int $id the page_id of the article
         * @return Title an object representing the article, or NULL if no such article was found
         */
        public static function nameOf( $id ) {
@@ -490,8 +490,8 @@ class Title {
         * Get a string representation of a title suitable for
         * including in a search index
         *
-        * @param $ns Int a namespace index
-        * @param $title String text-form main part
+        * @param int $ns a namespace index
+        * @param string $title text-form main part
         * @return String a stripped-down title string ready for the search index
         */
        public static function indexTitle( $ns, $title ) {
@@ -517,10 +517,10 @@ class Title {
        /**
         * Make a prefixed DB key from a DB key and a namespace index
         *
-        * @param $ns Int numerical representation of the namespace
-        * @param $title String the DB key form the title
-        * @param $fragment String The link fragment (after the "#")
-        * @param $interwiki String The interwiki prefix
+        * @param int $ns numerical representation of the namespace
+        * @param string $title the DB key form the title
+        * @param string $fragment The link fragment (after the "#")
+        * @param string $interwiki The interwiki prefix
         * @return String the prefixed form of the title
         */
        public static function makeName( $ns, $title, $fragment = '', $interwiki = '' ) {
@@ -540,7 +540,7 @@ class Title {
        /**
         * Escape a text fragment, say from a link, for a URL
         *
-        * @param $fragment string containing a URL or link fragment (after the "#")
+        * @param string $fragment containing a URL or link fragment (after the "#")
         * @return String: escaped string
         */
        static function escapeFragmentForURL( $fragment ) {
@@ -680,7 +680,6 @@ class Title {
        public function getContentModel() {
                if ( !$this->mContentModel ) {
                        $linkCache = LinkCache::singleton();
-                       $linkCache->addLinkObj( $this );
                        $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
                }
 
@@ -698,7 +697,7 @@ class Title {
        /**
         * Convenience method for checking a title's content model name
         *
-        * @param String $id The content model ID (use the CONTENT_MODEL_XXX constants).
+        * @param string $id The content model ID (use the CONTENT_MODEL_XXX constants).
         * @return Boolean true if $this->getContentModel() == $id
         */
        public function hasContentModel( $id ) {
@@ -794,7 +793,7 @@ class Title {
        /**
         * Returns true if this title resolves to the named special page
         *
-        * @param $name String The special page name
+        * @param string $name The special page name
         * @return boolean
         */
        public function isSpecial( $name ) {
@@ -832,7 +831,7 @@ class Title {
         * Please make use of this instead of comparing to getNamespace()
         * This function is much more resistant to changes we may make
         * to namespaces than code that makes direct comparisons.
-        * @param $ns int The namespace
+        * @param int $ns The namespace
         * @return bool
         * @since 1.19
         */
@@ -869,7 +868,7 @@ class Title {
         * is either NS_USER or NS_USER_TALK since both of them have NS_USER
         * as their subject namespace.
         *
-        * This is MUCH simpler than individually testing for equivilance
+        * This is MUCH simpler than individually testing for equivalence
         * against both NS_USER and NS_USER_TALK, and is also forward compatible.
         * @since 1.19
         * @param $ns int
@@ -911,7 +910,7 @@ class Title {
         * Is this the mainpage?
         * @note Title::newFromText seems to be sufficiently optimized by the title
         * cache that we don't need to over-optimize by doing direct comparisons and
-        * acidentally creating new bugs where $title->equals( Title::newFromText() )
+        * accidentally creating new bugs where $title->equals( Title::newFromText() )
         * ends up reporting something differently than $title->isMainPage();
         *
         * @since 1.18
@@ -970,7 +969,7 @@ class Title {
                                || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) );
 
                #NOTE: this hook is also called in ContentHandler::getDefaultModel. It's called here again to make sure
-               #      hook funktions can force this method to return true even outside the mediawiki namespace.
+               #      hook functions can force this method to return true even outside the mediawiki namespace.
 
                wfRunHooks( 'TitleIsCssOrJsPage', array( $this, &$isCssOrJsPage ) );
 
@@ -994,7 +993,7 @@ class Title {
         */
        public function getSkinFromCssJsSubpage() {
                $subpage = explode( '/', $this->mTextform );
-               $subpage = $subpage[ count( $subpage ) - 1 ];
+               $subpage = $subpage[count( $subpage ) - 1];
                $lastdot = strrpos( $subpage, '.' );
                if ( $lastdot === false )
                        return $subpage; # Never happens: only called for names ending in '.css' or '.js'
@@ -1102,7 +1101,7 @@ class Title {
         * Deprecated for public use, use Title::makeTitle() with fragment parameter.
         * Still in active use privately.
         *
-        * @param $fragment String text
+        * @param string $fragment text
         */
        public function setFragment( $fragment ) {
                $this->mFragment = str_replace( '_', ' ', substr( $fragment, 1 ) );
@@ -1112,7 +1111,7 @@ class Title {
         * Prefix some arbitrary text with the namespace or interwiki prefix
         * of this object
         *
-        * @param $name String the text
+        * @param string $name the text
         * @return String the prefixed text
         * @private
         */
@@ -1283,7 +1282,7 @@ class Title {
         * # returns: Title{User:Foo/Bar/Baz/Asdf}
         * @endcode
         *
-        * @param $text String The subpage name to add to the title
+        * @param string $text The subpage name to add to the title
         * @return Title Subpage title
         * @since 1.20
         */
@@ -1331,7 +1330,7 @@ class Title {
         * second argument named variant. This was deprecated in favor
         * of passing an array of option with a "variant" key
         * Once $query2 is removed for good, this helper can be dropped
-        * andthe wfArrayToCgi moved to getLocalURL();
+        * and the wfArrayToCgi moved to getLocalURL();
         *
         * @since 1.19 (r105919)
         * @param $query
@@ -1399,7 +1398,7 @@ class Title {
         * with action=render, $wgServer is prepended.
         *
 
-        * @param $query string|array an optional query string,
+        * @param string|array $query an optional query string,
         *   not used for interwiki links. Can be specified as an associative array as well,
         *   e.g., array( 'action' => 'edit' ) (keys and values will be URL-escaped).
         *   Some query patterns will trigger various shorturl path replacements.
@@ -1664,7 +1663,7 @@ class Title {
         *
         * May provide false positives, but should never provide a false negative.
         *
-        * @param $action String action that permission needs to be checked for
+        * @param string $action action that permission needs to be checked for
         * @param $user User to check (since 1.19); $wgUser will be used if not
         *              provided.
         * @return Bool
@@ -1676,10 +1675,10 @@ class Title {
        /**
         * Can $user perform $action on this page?
         *
-        * @param $action String action that permission needs to be checked for
+        * @param string $action action that permission needs to be checked for
         * @param $user User to check (since 1.19); $wgUser will be used if not
         *   provided.
-        * @param $doExpensiveQueries Bool Set this to false to avoid doing
+        * @param bool $doExpensiveQueries Set this to false to avoid doing
         *   unnecessary queries.
         * @return Bool
         */
@@ -1696,11 +1695,11 @@ class Title {
         *
         * @todo FIXME: This *does not* check throttles (User::pingLimiter()).
         *
-        * @param $action String action that permission needs to be checked for
+        * @param string $action action that permission needs to be checked for
         * @param $user User to check
-        * @param $doExpensiveQueries Bool Set this to false to avoid doing unnecessary
+        * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary
         *   queries by skipping checks for cascading protections and user blocks.
-        * @param $ignoreErrors Array of Strings Set this to a list of message keys
+        * @param array $ignoreErrors of Strings Set this to a list of message keys
         *   whose corresponding errors may be ignored.
         * @return Array of arguments to wfMessage to explain permissions problems.
         */
@@ -1722,9 +1721,9 @@ class Title {
        /**
         * Permissions checks that fail most often, and which are easiest to test.
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User user to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -1780,7 +1779,7 @@ class Title {
        /**
         * Add the resulting error code to the errors array
         *
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $result Mixed result of errors
         *
         * @return Array list of errors
@@ -1805,9 +1804,9 @@ class Title {
        /**
         * Check various permission hooks
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User user to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -1838,9 +1837,9 @@ class Title {
        /**
         * Check permissions on special pages & namespaces
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User user to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -1867,9 +1866,9 @@ class Title {
        /**
         * Check CSS/JS sub-page permissions
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User user to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -1896,9 +1895,9 @@ class Title {
         * page. The user must possess all required rights for this
         * action.
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User user to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -1927,9 +1926,9 @@ class Title {
        /**
         * Check restrictions on cascading pages.
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -1966,9 +1965,9 @@ class Title {
        /**
         * Check action permissions not already checked in checkQuickPermissions
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -2020,11 +2019,11 @@ class Title {
        }
 
        /**
-        * Check that the user isn't blocked from editting.
+        * Check that the user isn't blocked from editing.
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -2087,9 +2086,9 @@ class Title {
        /**
         * Check that the user is allowed to read this page.
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $user User to check
-        * @param $errors Array list of current errors
+        * @param array $errors list of current errors
         * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
         * @param $short Boolean short circuit on first error
         *
@@ -2140,7 +2139,7 @@ class Title {
                        # Time to check the whitelist
                        # Only do these checks is there's something to check against
                        $name = $this->getPrefixedText();
-                       $dbName = $this->getPrefixedDBKey();
+                       $dbName = $this->getPrefixedDBkey();
 
                        // Check for explicit whitelisting with and without underscores
                        if ( in_array( $name, $wgWhitelistRead, true ) || in_array( $dbName, $wgWhitelistRead, true ) ) {
@@ -2190,7 +2189,7 @@ class Title {
         * Get a description array when the user doesn't have the right to perform
         * $action (i.e. when User::isAllowed() returns false)
         *
-        * @param $action String the action to check
+        * @param string $action the action to check
         * @param $short Boolean short circuit on first error
         * @return Array list of errors
         */
@@ -2220,10 +2219,10 @@ class Title {
         * which checks ONLY that previously checked by userCan (i.e. it leaves out
         * checks on wfReadOnly() and blocks)
         *
-        * @param $action String action that permission needs to be checked for
+        * @param string $action action that permission needs to be checked for
         * @param $user User to check
-        * @param $doExpensiveQueries Bool Set this to false to avoid doing unnecessary queries.
-        * @param $short Bool Set this to true to stop after the first permission error.
+        * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
+        * @param bool $short Set this to true to stop after the first permission error.
         * @return Array of arrays of the arguments to wfMessage to explain permissions problems.
         */
        protected function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true, $short = false ) {
@@ -2372,8 +2371,8 @@ class Title {
         *
         * @deprecated in 1.19; will be removed in 1.20. Use WikiPage::doUpdateRestrictions() instead.
         * @param $create_perm String Permission required for creation
-        * @param $reason String Reason for protection
-        * @param $expiry String Expiry timestamp
+        * @param string $reason Reason for protection
+        * @param string $expiry Expiry timestamp
         * @return boolean true
         */
        public function updateTitleProtection( $create_perm, $reason, $expiry ) {
@@ -2408,7 +2407,7 @@ class Title {
        /**
         * Is this page "semi-protected" - the *only* protection is autoconfirm?
         *
-        * @param $action String Action to check (default: edit)
+        * @param string $action Action to check (default: edit)
         * @return Bool
         */
        public function isSemiProtected( $action = 'edit' ) {
@@ -2434,7 +2433,7 @@ class Title {
        /**
         * Does the title correspond to a protected article?
         *
-        * @param $action String the action the page is protected from,
+        * @param string $action the action the page is protected from,
         * by default checks all actions.
         * @return Bool
         */
@@ -2496,7 +2495,7 @@ class Title {
        /**
         * Cascading protection: Get the source of any cascading restrictions on this page.
         *
-        * @param $getPages Bool Whether or not to retrieve the actual pages
+        * @param bool $getPages Whether or not to retrieve the actual pages
         *        that the restrictions have come from.
         * @return Mixed Array of Title objects of the pages from which cascading restrictions
         *     have come, false for none, or true if such restrictions exist, but $getPages
@@ -2596,7 +2595,7 @@ class Title {
        /**
         * Accessor/initialisation for mRestrictions
         *
-        * @param $action String action that permission needs to be checked for
+        * @param string $action action that permission needs to be checked for
         * @return Array of Strings the array of groups allowed to edit this article
         */
        public function getRestrictions( $action ) {
@@ -2639,7 +2638,7 @@ class Title {
         * Loads a string into mRestrictions array
         *
         * @param $res Resource restrictions as an SQL result.
-        * @param $oldFashionedRestrictions String comma-separated list of page
+        * @param string $oldFashionedRestrictions comma-separated list of page
         *        restrictions from page table (pre 1.10)
         */
        private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) {
@@ -2657,8 +2656,8 @@ class Title {
         * and page_restrictions table for this existing page.
         * Public for usage by LiquidThreads.
         *
-        * @param $rows array of db result objects
-        * @param $oldFashionedRestrictions string comma-separated list of page
+        * @param array $rows of db result objects
+        * @param string $oldFashionedRestrictions comma-separated list of page
         *        restrictions from page table (pre 1.10)
         */
        public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
@@ -2740,7 +2739,7 @@ class Title {
        /**
         * Load restrictions from the page_restrictions table
         *
-        * @param $oldFashionedRestrictions String comma-separated list of page
+        * @param string $oldFashionedRestrictions comma-separated list of page
         *        restrictions from page table (pre 1.10)
         */
        public function loadRestrictions( $oldFashionedRestrictions = null ) {
@@ -2840,7 +2839,7 @@ class Title {
        /**
         * Get all subpages of this page.
         *
-        * @param $limit Int maximum number of subpages to fetch; -1 for no limit
+        * @param int $limit maximum number of subpages to fetch; -1 for no limit
         * @return mixed TitleArray, or empty array if this page's namespace
         *  doesn't allow subpages
         */
@@ -2918,7 +2917,7 @@ class Title {
         * Get the article ID for this Title from the link cache,
         * adding it if necessary
         *
-        * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select
+        * @param int $flags a bit field; may be Title::GAID_FOR_UPDATE to select
         *  for update
         * @return Int the ID
         */
@@ -2944,25 +2943,26 @@ class Title {
         * Is this an article that is a redirect page?
         * Uses link cache, adding it if necessary
         *
-        * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @param int $flags a bit field; may be Title::GAID_FOR_UPDATE to select for update
         * @return Bool
         */
        public function isRedirect( $flags = 0 ) {
-               if ( !( $flags & Title::GAID_FOR_UPDATE ) && !is_null( $this->mRedirect ) ) {
+               if ( !is_null( $this->mRedirect ) ) {
                        return $this->mRedirect;
                }
-
+               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mRedirect = false;
                }
 
                $linkCache = LinkCache::singleton();
-               $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
-
                if ( $cached === null ) {
-                       // Should not happen
-                       throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() );
+                       // TODO: check the assumption that the cache actually knows about this title
+                       // and handle this, such as get the title from the database.
+                       // See https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
+                       wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
+                       wfDebug( wfBacktrace() );
                }
 
                $this->mRedirect = (bool)$cached;
@@ -2974,25 +2974,24 @@ class Title {
         * What is the length of this page?
         * Uses link cache, adding it if necessary
         *
-        * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @param int $flags a bit field; may be Title::GAID_FOR_UPDATE to select for update
         * @return Int
         */
        public function getLength( $flags = 0 ) {
-               if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLength != -1 ) {
+               if ( $this->mLength != -1 ) {
                        return $this->mLength;
                }
-
+               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mLength = 0;
                }
-
                $linkCache = LinkCache::singleton();
-               $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
-
-               if ( $cached === null ) {
-                       // Should not happen
-                       throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() );
+               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
+                       # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
+                       #      as a stop gap, perhaps log this, but don't throw an exception?
+                       wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
+                       wfDebug( wfBacktrace() );
                }
 
                $this->mLength = intval( $cached );
@@ -3003,7 +3002,7 @@ class Title {
        /**
         * What is the page_latest field for this page?
         *
-        * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @param int $flags a bit field; may be Title::GAID_FOR_UPDATE to select for update
         * @throws MWException
         * @return Int or 0 if the page doesn't exist
         */
@@ -3011,18 +3010,17 @@ class Title {
                if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) {
                        return intval( $this->mLatestID );
                }
-
+               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mLatestID = 0;
                }
-
                $linkCache = LinkCache::singleton();
                $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
-
-               if ( $cached === null ) {
-                       // Should not happen
-                       throw new MWException( "LinkCache doesn't know latest revision ID of this title: " . $this->getPrefixedDBkey() );
+               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
+                       # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
+                       #      as a stop gap, perhaps log this, but don't throw an exception?
+                       throw new MWException( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
                }
 
                $this->mLatestID = intval( $cached );
@@ -3038,7 +3036,7 @@ class Title {
         * loading of the new page_id. It's also called from
         * WikiPage::doDeleteArticleReal()
         *
-        * @param $newid Int the new Article ID
+        * @param int $newid the new Article ID
         */
        public function resetArticleID( $newid ) {
                $linkCache = LinkCache::singleton();
@@ -3061,8 +3059,8 @@ class Title {
        /**
         * Capitalize a text string for a title if it belongs to a namespace that capitalizes
         *
-        * @param $text String containing title to capitalize
-        * @param $ns int namespace index, defaults to NS_MAIN
+        * @param string $text containing title to capitalize
+        * @param int $ns namespace index, defaults to NS_MAIN
         * @return String containing capitalized title
         */
        public static function capitalize( $text, $ns = NS_MAIN ) {
@@ -3283,9 +3281,9 @@ class Title {
         * WARNING: do not use this function on arbitrary user-supplied titles!
         * On heavily-used templates it will max out the memory.
         *
-        * @param $options Array: may be FOR UPDATE
-        * @param $table String: table name
-        * @param $prefix String: fields prefix
+        * @param array $options may be FOR UPDATE
+        * @param string $table table name
+        * @param string $prefix fields prefix
         * @return Array of Title objects linking here
         */
        public function getLinksTo( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) {
@@ -3327,7 +3325,7 @@ class Title {
         * WARNING: do not use this function on arbitrary user-supplied titles!
         * On heavily-used templates it will max out the memory.
         *
-        * @param $options Array: may be FOR UPDATE
+        * @param array $options may be FOR UPDATE
         * @return Array of Title the Title objects linking here
         */
        public function getTemplateLinksTo( $options = array() ) {
@@ -3341,9 +3339,9 @@ class Title {
         * WARNING: do not use this function on arbitrary user-supplied titles!
         * On heavily-used templates it will max out the memory.
         *
-        * @param $options Array: may be FOR UPDATE
-        * @param $table String: table name
-        * @param $prefix String: fields prefix
+        * @param array $options may be FOR UPDATE
+        * @param string $table table name
+        * @param string $prefix fields prefix
         * @return Array of Title objects linking here
         */
        public function getLinksFrom( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) {
@@ -3402,7 +3400,7 @@ class Title {
         * WARNING: do not use this function on arbitrary user-supplied titles!
         * On heavily-used templates it will max out the memory.
         *
-        * @param $options Array: may be FOR UPDATE
+        * @param array $options may be FOR UPDATE
         * @return Array of Title the Title objects used here
         */
        public function getTemplateLinksFrom( $options = array() ) {
@@ -3495,9 +3493,9 @@ class Title {
         * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise
         *
         * @param $nt Title the new title
-        * @param $auth Bool indicates whether $wgUser's permissions
+        * @param bool $auth indicates whether $wgUser's permissions
         *  should be checked
-        * @param $reason String is the log summary of the move, used for spam checking
+        * @param string $reason is the log summary of the move, used for spam checking
         * @return Mixed True on success, getUserPermissionsErrors()-like array on failure
         */
        public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
@@ -3639,10 +3637,10 @@ class Title {
         * Move a title to a new location
         *
         * @param $nt Title the new title
-        * @param $auth Bool indicates whether $wgUser's permissions
+        * @param bool $auth indicates whether $wgUser's permissions
         *  should be checked
-        * @param $reason String the reason for the move
-        * @param $createRedirect Bool Whether to create a redirect from the old title to the new title.
+        * @param string $reason the reason for the move
+        * @param bool $createRedirect Whether to create a redirect from the old title to the new title.
         *  Ignored if the user doesn't have the suppressredirect right.
         * @return Mixed true on success, getUserPermissionsErrors()-like array on failure
         */
@@ -3757,8 +3755,8 @@ class Title {
         * source page or nonexistent
         *
         * @param $nt Title the page to move to, which should be a redirect or nonexistent
-        * @param $reason String The reason for the move
-        * @param $createRedirect Bool Whether to leave a redirect at the old title. Does not check
+        * @param string $reason The reason for the move
+        * @param bool $createRedirect Whether to leave a redirect at the old title. Does not check
         *   if the user has the suppressredirect right
         * @throws MWException
         */
@@ -3838,6 +3836,7 @@ class Title {
 
                $this->resetArticleID( 0 );
                $nt->resetArticleID( $oldid );
+               $newpage->loadPageData( WikiPage::READ_LOCKING ); // bug 46397
 
                $newpage->updateRevisionOn( $dbw, $nullRevision );
 
@@ -3855,6 +3854,7 @@ class Title {
                        WikiPage::onArticleDelete( $this );
                } else {
                        $redirectArticle = WikiPage::factory( $this );
+                       $redirectArticle->loadFromRow( false, WikiPage::READ_LOCKING ); // bug 46397
                        $newid = $redirectArticle->insertOn( $dbw );
                        if ( $newid ) { // sanity
                                $redirectRevision = new Revision( array(
@@ -3881,9 +3881,9 @@ class Title {
         * Move this page's subpages to be subpages of $nt
         *
         * @param $nt Title Move target
-        * @param $auth bool Whether $wgUser's permissions should be checked
-        * @param $reason string The reason for the move
-        * @param $createRedirect bool Whether to create redirects from the old subpages to
+        * @param bool $auth Whether $wgUser's permissions should be checked
+        * @param string $reason The reason for the move
+        * @param bool $createRedirect Whether to create redirects from the old subpages to
         *     the new ones Ignored if the user doesn't have the 'suppressredirect' right
         * @return mixed array with old page titles as keys, and strings (new page titles) or
         *     arrays (errors) as values, or an error array with numeric indices if no pages
@@ -4070,8 +4070,8 @@ class Title {
 
                if ( $res->numRows() > 0 ) {
                        foreach ( $res as $row ) {
-                               // $data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to);
-                               $data[$wgContLang->getNSText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText();
+                               // $data[] = Title::newFromText($wgContLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
+                               $data[$wgContLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText();
                        }
                }
                return $data;
@@ -4080,7 +4080,7 @@ class Title {
        /**
         * Get a tree of parent categories
         *
-        * @param $children Array with the children in the keys, to check for circular refs
+        * @param array $children with the children in the keys, to check for circular refs
         * @return Array Tree of parent categories
         */
        public function getParentCategoryTree( $children = array() ) {
@@ -4122,8 +4122,8 @@ class Title {
        /**
         * Get the revision ID of the previous revision
         *
-        * @param $revId Int Revision ID. Get the revision that was before this one.
-        * @param $flags Int Title::GAID_FOR_UPDATE
+        * @param int $revId Revision ID. Get the revision that was before this one.
+        * @param int $flags Title::GAID_FOR_UPDATE
         * @return Int|Bool Old revision ID, or FALSE if none exists
         */
        public function getPreviousRevisionID( $revId, $flags = 0 ) {
@@ -4147,8 +4147,8 @@ class Title {
        /**
         * Get the revision ID of the next revision
         *
-        * @param $revId Int Revision ID. Get the revision that was after this one.
-        * @param $flags Int Title::GAID_FOR_UPDATE
+        * @param int $revId Revision ID. Get the revision that was after this one.
+        * @param int $flags Title::GAID_FOR_UPDATE
         * @return Int|Bool Next revision ID, or FALSE if none exists
         */
        public function getNextRevisionID( $revId, $flags = 0 ) {
@@ -4172,7 +4172,7 @@ class Title {
        /**
         * Get the first revision of the page
         *
-        * @param $flags Int Title::GAID_FOR_UPDATE
+        * @param int $flags Title::GAID_FOR_UPDATE
         * @return Revision|Null if page doesn't exist
         */
        public function getFirstRevision( $flags = 0 ) {
@@ -4194,7 +4194,7 @@ class Title {
        /**
         * Get the oldest revision timestamp of this page
         *
-        * @param $flags Int Title::GAID_FOR_UPDATE
+        * @param int $flags Title::GAID_FOR_UPDATE
         * @return String: MW timestamp
         */
        public function getEarliestRevTime( $flags = 0 ) {
@@ -4251,8 +4251,8 @@ class Title {
         * Get the number of revisions between the given revision.
         * Used for diffs and other things that really need it.
         *
-        * @param $old int|Revision Old revision or rev ID (first before range)
-        * @param $new int|Revision New revision or rev ID (first after range)
+        * @param int|Revision $old Old revision or rev ID (first before range)
+        * @param int|Revision $new New revision or rev ID (first after range)
         * @return Int Number of revisions between these revisions.
         */
        public function countRevisionsBetween( $old, $new ) {
@@ -4280,10 +4280,10 @@ class Title {
         * Get the number of authors between the given revisions or revision IDs.
         * Used for diffs and other things that really need it.
         *
-        * @param $old int|Revision Old revision or rev ID (first before range by default)
-        * @param $new int|Revision New revision or rev ID (first after range by default)
-        * @param $limit int Maximum number of authors
-        * @param $options string|array (Optional): Single option, or an array of options:
+        * @param int|Revision $old Old revision or rev ID (first before range by default)
+        * @param int|Revision $new New revision or rev ID (first after range by default)
+        * @param int $limit Maximum number of authors
+        * @param string|array $options (Optional): Single option, or an array of options:
         *     'include_old' Include $old in the range; $new is excluded.
         *     'include_new' Include $new in the range; $old is excluded.
         *     'include_both' Include both $old and $new in the range.
@@ -4464,7 +4464,7 @@ class Title {
                        // Use always content language to avoid loading hundreds of languages
                        // to get the link color.
                        global $wgContLang;
-                       list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) );
+                       list( $name, ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) );
                        $message = wfMessage( $name )->inLanguage( $wgContLang )->useDatabase( false );
                        return $message->exists();
                }
@@ -4497,27 +4497,34 @@ class Title {
        /**
         * Updates page_touched for this page; called from LinksUpdate.php
         *
-        * @return Bool true if the update succeded
+        * @return Bool true if the update succeeded
         */
        public function invalidateCache() {
                global $wgMemc;
+
                if ( wfReadOnly() ) {
                        return false;
                }
+
                $dbw = wfGetDB( DB_MASTER );
-               $success = $dbw->update(
-                       'page',
-                       array( 'page_touched' => $dbw->timestamp() ),
-                       $this->pageCond(),
-                       __METHOD__
-               );
+               $conds = $this->pageCond();
+               $dbw->onTransactionIdle( function() use ( $dbw, $conds ) {
+                       $dbw->update(
+                               'page',
+                               array( 'page_touched' => $dbw->timestamp() ),
+                               $conds,
+                               __METHOD__
+                       );
+               } );
                HTMLFileCache::clearFileCache( $this );
 
                // Clear page info.
                $revision = WikiPage::factory( $this )->getRevision();
-               if( $revision !== null ) {
+               if ( $revision !== null ) {
                        $memcKey = wfMemcKey( 'infoaction', $this->getPrefixedText(), $revision->getId() );
-                       $success = $success && $wgMemc->delete( $memcKey );
+                       $success = $wgMemc->delete( $memcKey );
+               } else {
+                       $success = true;
                }
 
                return $success;
@@ -4591,14 +4598,14 @@ class Title {
        /**
         * Generate strings used for xml 'id' names in monobook tabs
         *
-        * @param $prepend string defaults to 'nstab-'
+        * @param string $prepend defaults to 'nstab-'
         * @return String XML 'id' name
         */
        public function getNamespaceKey( $prepend = 'nstab-' ) {
                global $wgContLang;
                // Gets the subject namespace if this title
                $namespace = MWNamespace::getSubject( $this->getNamespace() );
-               // Checks if cononical namespace name exists for namespace
+               // Checks if canonical namespace name exists for namespace
                if ( MWNamespace::exists( $this->getNamespace() ) ) {
                        // Uses canonical namespace name
                        $namespaceKey = MWNamespace::getCanonicalName( $namespace );
@@ -4622,7 +4629,7 @@ class Title {
        /**
         * Get all extant redirects to this Title
         *
-        * @param $ns Int|Null Single namespace to consider; NULL to consider all namespaces
+        * @param int|Null $ns Single namespace to consider; NULL to consider all namespaces
         * @return Array of Title redirects to this title
         */
        public function getRedirectsHere( $ns = null ) {
@@ -4664,7 +4671,7 @@ class Title {
        public function isValidRedirectTarget() {
                global $wgInvalidRedirectTargets;
 
-               // invalid redirect targets are stored in a global array, but explicity disallow Userlogout here
+               // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
                if ( $this->isSpecial( 'Userlogout' ) ) {
                        return false;
                }
@@ -4708,7 +4715,7 @@ class Title {
         * prefix.  This will be fed to Collation::getSortKey() to get a
         * binary sortkey that can be used for actual sorting.
         *
-        * @param $prefix string The prefix to be used, specified using
+        * @param string $prefix The prefix to be used, specified using
         *   {{defaultsort:}} or like [[Category:Foo|prefix]].  Empty for no
         *   prefix.
         * @return string