* and does not rely on global state or the database.
*/
class Title implements LinkTarget, IDBAccessObject {
- /** @var MapCacheLRU */
+ /** @var MapCacheLRU|null */
private static $titleCache = null;
/**
* Only public to share cache with TitleFormatter
*
* @private
- * @var string
+ * @var string|null
*/
public $prefixedText = null;
* the database or false if not loaded, yet. */
private $mDbPageLanguage = false;
- /** @var TitleValue A corresponding TitleValue object */
+ /** @var TitleValue|null A corresponding TitleValue object */
private $mTitleValue = null;
- /** @var bool Would deleting this page be a big deletion? */
+ /** @var bool|null Would deleting this page be a big deletion? */
private $mIsBigDeletion = null;
// @}
* @return Title|null Title, or null on an error
*/
public static function newFromDBkey( $key ) {
- $t = new Title();
+ $t = new self();
$t->mDbkeyform = $key;
try {
}
try {
- return self::newFromTextThrow( strval( $text ), $defaultNamespace );
+ return self::newFromTextThrow( (string)$text, $defaultNamespace );
} catch ( MalformedTitleException $ex ) {
return null;
}
$t = new Title();
$t->mDbkeyform = strtr( $filteredText, ' ', '_' );
- $t->mDefaultNamespace = intval( $defaultNamespace );
+ $t->mDefaultNamespace = (int)$defaultNamespace;
$t->secureAndSplit();
if ( $defaultNamespace == NS_MAIN ) {
* @return MapCacheLRU
*/
private static function getTitleCache() {
- if ( self::$titleCache == null ) {
+ if ( self::$titleCache === null ) {
self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
}
return self::$titleCache;
} else {
$title = null;
}
+
return $title;
}
$this->mLatestID = (int)$row->page_latest;
}
if ( !$this->mForcedContentModel && isset( $row->page_content_model ) ) {
- $this->mContentModel = strval( $row->page_content_model );
+ $this->mContentModel = (string)$row->page_content_model;
} elseif ( !$this->mForcedContentModel ) {
$this->mContentModel = false; # initialized lazily in getContentModel()
}
$t = new Title();
$t->mInterwiki = $interwiki;
$t->mFragment = $fragment;
- $t->mNamespace = $ns = intval( $ns );
+ $t->mNamespace = $ns = (int)$ns;
$t->mDbkeyform = strtr( $title, ' ', '_' );
$t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
$t->mUrlform = wfUrlencode( $t->mDbkeyform );
}
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 != '' ) {
$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 );
}
// @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 );
public function canUseNoindex() {
global $wgExemptFromUserRobotsControl;
- $bannedNamespaces = is_null( $wgExemptFromUserRobotsControl )
- ? MWNamespace::getContentNamespaces()
- : $wgExemptFromUserRobotsControl;
+ $bannedNamespaces = $wgExemptFromUserRobotsControl ?? MWNamespace::getContentNamespaces();
return !in_array( $this->mNamespace, $bannedNamespaces );
}