* Create a new Title from a prefixed DB key
*
* @param string $key The database key, which has underscores
- * instead of spaces, possibly including namespace and
- * interwiki prefixes
+ * instead of spaces, possibly including namespace and
+ * interwiki prefixes
* @return Title|null Title, or null on an error
*/
public static function newFromDBkey( $key ) {
* @return int Result of string comparison, or namespace comparison
*/
public static function compare( LinkTarget $a, LinkTarget $b ) {
- if ( $a->getNamespace() == $b->getNamespace() ) {
- return strcmp( $a->getText(), $b->getText() );
- } else {
- return $a->getNamespace() - $b->getNamespace();
- }
+ return $a->getNamespace() <=> $b->getNamespace()
+ ?: strcmp( $a->getText(), $b->getText() );
}
/**
&& ( !$this->mContentModel || $flags === self::GAID_FOR_UPDATE )
&& $this->getArticleID( $flags )
) {
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->addLinkObj( $this ); # in case we already had an article ID
$this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
}
return $errors;
}
- if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) {
+ if ( $wgEmailConfirmToEdit
+ && !$user->isEmailConfirmed()
+ && $action === 'edit'
+ ) {
$errors[] = [ 'confirmedittext' ];
}
if ( !$this->mRestrictionsLoaded ) {
$this->loadRestrictions();
}
- return isset( $this->mRestrictions[$action] )
- ? $this->mRestrictions[$action]
- : [];
+ return $this->mRestrictions[$action] ?? [];
}
/**
if ( !$this->mRestrictionsLoaded ) {
$this->loadRestrictions();
}
- return isset( $this->mRestrictionsExpiry[$action] ) ? $this->mRestrictionsExpiry[$action] : false;
+ return $this->mRestrictionsExpiry[$action] ?? false;
}
/**
$this->mArticleID = 0;
return $this->mArticleID;
}
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
if ( $flags & self::GAID_FOR_UPDATE ) {
$oldUpdate = $linkCache->forUpdate( true );
$linkCache->clearLink( $this );
return $this->mRedirect;
}
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->addLinkObj( $this ); # in case we already had an article ID
$cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
if ( $cached === null ) {
$this->mLength = 0;
return $this->mLength;
}
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->addLinkObj( $this ); # in case we already had an article ID
$cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
if ( $cached === null ) {
$this->mLatestID = 0;
return $this->mLatestID;
}
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->addLinkObj( $this ); # in case we already had an article ID
$cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
if ( $cached === null ) {
* @param int $newid The new Article ID
*/
public function resetArticleID( $newid ) {
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->clearLink( $this );
if ( $newid === false ) {
}
public static function clearCaches() {
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->clear();
$titleCache = self::getTitleCache();
$retVal = [];
if ( $res->numRows() ) {
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
foreach ( $res as $row ) {
$titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
if ( $titleObj ) {
);
$retVal = [];
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
foreach ( $res as $row ) {
if ( $row->page_id ) {
$titleObj = self::newFromRow( $row );
// check, if the page language could be saved in the database, and if so and
// the value is not requested already, lookup the page language using LinkCache
if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->addLinkObj( $this );
$this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
}
$langObj = $contentHandler->getPageLanguage( $this );
$this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
} else {
- $langObj = wfGetLangObj( $this->mPageLanguage[0] );
+ $langObj = Language::factory( $this->mPageLanguage[0] );
}
return $langObj;