/** @var TitleFormatter */
private $titleFormatter;
+ /** @var NamespaceInfo */
+ private $nsInfo;
+
/**
* How many Titles to store. There are two caches, so the amount actually
* stored in memory can be up to twice this.
*/
const MAX_SIZE = 10000;
- public function __construct( TitleFormatter $titleFormatter, WANObjectCache $cache ) {
+ public function __construct(
+ TitleFormatter $titleFormatter,
+ WANObjectCache $cache,
+ NamespaceInfo $nsInfo = null
+ ) {
+ if ( !$nsInfo ) {
+ wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
+ $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+ }
$this->goodLinks = new MapCacheLRU( self::MAX_SIZE );
$this->badLinks = new MapCacheLRU( self::MAX_SIZE );
$this->wanCache = $cache;
$this->titleFormatter = $titleFormatter;
+ $this->nsInfo = $nsInfo;
}
/**
*
* @param bool|null $update
* @return bool
+ * @deprecated Since 1.34
*/
public function forUpdate( $update = null ) {
return wfSetVar( $this->mForUpdate, $update );
'revision' => (int)$revision,
'model' => $model ? (string)$model : null,
'lang' => $lang ? (string)$lang : null,
+ 'restrictions' => null
] );
}
'length' => intval( $row->page_len ),
'redirect' => intval( $row->page_is_redirect ),
'revision' => intval( $row->page_latest ),
- 'model' => !empty( $row->page_content_model ) ? strval( $row->page_content_model ) : null,
- 'lang' => !empty( $row->page_lang ) ? strval( $row->page_lang ) : null,
+ 'model' => !empty( $row->page_content_model )
+ ? strval( $row->page_content_model )
+ : null,
+ 'lang' => !empty( $row->page_lang )
+ ? strval( $row->page_lang )
+ : null,
+ 'restrictions' => !empty( $row->page_restrictions )
+ ? strval( $row->page_restrictions )
+ : null
] );
}
public static function getSelectFields() {
global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
- $fields = [ 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ];
+ $fields = [
+ 'page_id',
+ 'page_len',
+ 'page_is_redirect',
+ 'page_latest',
+ 'page_restrictions'
+ ];
if ( $wgContentHandlerUseDB ) {
$fields[] = 'page_content_model';
}
*/
public function addLinkObj( LinkTarget $nt ) {
$key = $this->titleFormatter->getPrefixedDBkey( $nt );
- if ( $this->isBadLink( $key ) || $nt->isExternal()
- || $nt->inNamespace( NS_SPECIAL )
- ) {
+ if ( $this->isBadLink( $key ) || $nt->isExternal() || $nt->getNamespace() < 0 ) {
return 0;
}
$id = $this->getGoodLinkID( $key );
}
private function isCacheable( LinkTarget $title ) {
- return ( $title->inNamespace( NS_TEMPLATE ) || $title->inNamespace( NS_FILE ) );
+ $ns = $title->getNamespace();
+ if ( in_array( $ns, [ NS_TEMPLATE, NS_FILE, NS_CATEGORY, NS_MEDIAWIKI ] ) ) {
+ return true;
+ }
+ // Focus on transcluded pages more than the main content
+ if ( $this->nsInfo->isContent( $ns ) ) {
+ return false;
+ }
+ // Non-talk extension namespaces (e.g. NS_MODULE)
+ return ( $ns >= 100 && $this->nsInfo->isSubject( $ns ) );
}
private function fetchPageRow( IDatabase $db, LinkTarget $nt ) {