Merge "Recalculate user default options for each test"
[lhc/web/wiklou.git] / includes / Title.php
index 82e79b3..ce0b959 100644 (file)
@@ -437,6 +437,7 @@ class Title implements LinkTarget, IDBAccessObject {
                } else {
                        $title = null;
                }
+
                return $title;
        }
 
@@ -1701,16 +1702,18 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return string Base name
         */
        public function getBaseText() {
+               $text = $this->getText();
                if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
-                       return $this->getText();
+                       return $text;
                }
 
-               $parts = explode( '/', $this->getText() );
-               # Don't discard the real title if there's no subpage involved
-               if ( count( $parts ) > 1 ) {
-                       unset( $parts[count( $parts ) - 1] );
+               $lastSlashPos = strrpos( $text, '/' );
+               // Don't discard the real title if there's no subpage involved
+               if ( $lastSlashPos === false ) {
+                       return $text;
                }
-               return implode( '/', $parts );
+
+               return substr( $text, 0, $lastSlashPos );
        }
 
        /**
@@ -3254,8 +3257,9 @@ class Title implements LinkTarget, IDBAccessObject {
                }
 
                if ( $this->mOldRestrictions === false ) {
-                       $this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions',
-                               [ 'page_id' => $this->getArticleID() ], __METHOD__ );
+                       $linkCache = MediaWikiServices::getInstance()->getLinkCache();
+                       $linkCache->addLinkObj( $this ); # in case we already had an article ID
+                       $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
                }
 
                if ( $this->mOldRestrictions != '' ) {
@@ -3340,12 +3344,17 @@ class Title implements LinkTarget, IDBAccessObject {
                                $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                                $rows = $cache->getWithSetCallback(
                                        // Page protections always leave a new null revision
-                                       $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
+                                       $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
                                        $cache::TTL_DAY,
                                        function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
                                                $dbr = wfGetDB( DB_REPLICA );
 
                                                $setOpts += Database::getCacheSetOptions( $dbr );
+                                               $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+                                               if ( $lb->hasOrMadeRecentMasterChanges() ) {
+                                                       // @TODO: cleanup Title cache and caller assumption mess in general
+                                                       $ttl = WANObjectCache::TTL_UNCACHEABLE;
+                                               }
 
                                                return $loadRestrictionsFromDb( $dbr );
                                        }
@@ -3720,6 +3729,7 @@ class Title implements LinkTarget, IDBAccessObject {
                // @todo: get rid of secureAndSplit, refactor parsing code.
                // @note: getTitleParser() returns a TitleParser implementation which does not have a
                //        splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
+               /** @var MediaWikiTitleCodec $titleCodec */
                $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
                // MalformedTitleException can be thrown here
                $parts = $titleCodec->splitTitleString( $this->mDbkeyform, $this->mDefaultNamespace );
@@ -4995,9 +5005,7 @@ class Title implements LinkTarget, IDBAccessObject {
        public function canUseNoindex() {
                global $wgExemptFromUserRobotsControl;
 
-               $bannedNamespaces = is_null( $wgExemptFromUserRobotsControl )
-                       ? MWNamespace::getContentNamespaces()
-                       : $wgExemptFromUserRobotsControl;
+               $bannedNamespaces = $wgExemptFromUserRobotsControl ?? MWNamespace::getContentNamespaces();
 
                return !in_array( $this->mNamespace, $bannedNamespaces );
        }