* 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;
$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 );
$useReplica = ( $rigor !== 'secure' );
$block = $user->getBlock( $useReplica );
- // The block may explicitly allow an action (like "read" or "upload").
- if ( $block && $block->prevents( $action ) === false ) {
+ // If the user does not have a block, or the block they do have explicitly
+ // allows the action (like "read" or "upload").
+ if ( !$block || $block->appliesToRight( $action ) === false ) {
return $errors;
}
if ( !$actionObj || $actionObj->requiresUnblock() ) {
if ( $user->isBlockedFrom( $this, $useReplica ) ) {
// @todo FIXME: Pass the relevant context into this function.
- $errors[] = $block
- ? $block->getPermissionsError( RequestContext::getMain() )
- : [ 'actionblockedtext' ];
+ $errors[] = $block->getPermissionsError( RequestContext::getMain() );
}
}
$dbr = wfGetDB( DB_MASTER );
$rows = $loadRestrictionsFromDb( $dbr );
} else {
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$rows = $cache->getWithSetCallback(
// Page protections always leave a new null revision
$cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
return $errors ?: true;
}
- /**
- * Check if the requested move target is a valid file move target
- * @todo move this to MovePage
- * @param Title $nt Target title
- * @return array List of errors
- */
- protected function validateFileMoveOperation( $nt ) {
- global $wgUser;
-
- $errors = [];
-
- $destFile = wfLocalFile( $nt );
- $destFile->load( File::READ_LATEST );
- if ( !$wgUser->isAllowed( 'reupload-shared' )
- && !$destFile->exists() && wfFindFile( $nt )
- ) {
- $errors[] = [ 'file-exists-sharedrepo' ];
- }
-
- return $errors;
- }
-
/**
* Move a title to a new location
*