11 public function register() {
15 'getNsIndex' => [ $this,
'getNsIndex' ],
16 'pagesInCategory' => [ $this,
'pagesInCategory' ],
17 'pagesInNamespace' => [ $this,
'pagesInNamespace' ],
18 'usersInGroup' => [ $this,
'usersInGroup' ],
19 'interwikiMap' => [ $this,
'interwikiMap' ],
23 'siteName' =>
$GLOBALS[
'wgSitename'],
25 'scriptPath' =>
$GLOBALS[
'wgScriptPath'],
26 'stylePath' =>
$GLOBALS[
'wgStylePath'],
28 '', $parser ? $parser->getTargetLanguage() :
$wgContLang
32 if ( !self::$namespacesCache || self::$namespacesCacheLang !==
$wgContLang->getCode() ) {
34 $namespacesByName = [];
40 'canonicalName' => strtr( $canonical,
'_',
' ' ),
57 $namespaces[$ns][
'subject'] = $ns;
59 $namespacesByName[strtr(
$title,
' ',
'_' )] = $ns;
61 $namespacesByName[$canonical] = $ns;
66 foreach ( $aliases as
$title => $ns ) {
67 if ( !isset( $namespacesByName[
$title] ) && isset( $namespaces[$ns] ) ) {
68 $ct = count( $namespaces[$ns][
'aliases'] );
69 $namespaces[$ns][
'aliases'][$ct + 1] =
$title;
70 $namespacesByName[
$title] = $ns;
74 $namespaces[
NS_MAIN][
'displayName'] =
wfMessage(
'blanknamespace' )->inContentLanguage()->text();
76 self::$namespacesCache = $namespaces;
77 self::$namespacesCacheLang =
$wgContLang->getCode();
91 return $this->
getEngine()->registerInterface(
'mw.site.lua', $lib, $info );
102 $this->
checkType(
'pagesInCategory', 1, $category,
'string' );
109 $cacheKey =
$title->getDBkey();
111 if ( !isset( $this->pagesInCategoryCache[$cacheKey] ) ) {
113 $category = Category::newFromTitle(
$title );
115 'all' => (int)$category->getPageCount(),
116 'subcats' => (int)$category->getSubcatCount(),
117 'files' => (int)$category->getFileCount(),
119 $counts[
'pages'] = $counts[
'all'] - $counts[
'subcats'] - $counts[
'files'];
120 $this->pagesInCategoryCache[$cacheKey] = $counts;
122 if ( $which ===
'*' ) {
123 return [ $this->pagesInCategoryCache[$cacheKey] ];
125 if ( !isset( $this->pagesInCategoryCache[$cacheKey][$which] ) ) {
127 'pagesInCategory', 2, $which,
"one of '*', 'all', 'pages', 'subcats', or 'files'"
130 return [ $this->pagesInCategoryCache[$cacheKey][$which] ];
140 $this->
checkType(
'pagesInNamespace', 1, $ns,
'number' );
151 $this->
checkType(
'usersInGroup', 1, $group,
'string' );
163 $this->
checkType(
'getNsIndex', 1, $name,
'string' );
165 $name = trim( preg_replace(
'/[\s_]+/',
'_', $name ),
'_' );
181 } elseif (
$filter ===
'!local' ) {
183 } elseif (
$filter !==
null ) {
185 "bad argument #1 to 'interwikiMap' (unknown filter '$filter')"
189 if ( !isset( self::$interwikiMapCache[$cacheKey] ) ) {
193 $lookup = MediaWikiServices::getInstance()->getInterwikiLookup();
194 $prefixes = $lookup->getAllPrefixes( $local );
195 foreach ( $prefixes as $row ) {
196 $prefix = $row[
'iw_prefix'];
200 'isProtocolRelative' => substr( $row[
'iw_url'], 0, 2 ) ===
'//',
201 'isLocal' => isset( $row[
'iw_local'] ) && $row[
'iw_local'] ==
'1',
202 'isTranscludable' => isset( $row[
'iw_trans'] ) && $row[
'iw_trans'] ==
'1',
206 if ( $val[
'isExtraLanguageLink'] ) {
207 $displayText =
wfMessage(
"interlanguage-link-$prefix" );
208 if ( !$displayText->isDisabled() ) {
209 $val[
'displayText'] = $displayText->text();
211 $tooltip =
wfMessage(
"interlanguage-link-sitename-$prefix" );
212 if ( !$tooltip->isDisabled() ) {
213 $val[
'tooltip'] = $tooltip->text();
216 $interwikiMap[$prefix] = $val;
218 self::$interwikiMapCache[$cacheKey] = $interwikiMap;
220 return [ self::$interwikiMapCache[$cacheKey] ];
$wgExtraInterlanguageLinkPrefixes
List of additional interwiki prefixes that should be treated as interlanguage links (i....
$wgLocalInterwikis
Array for multiple $wgLocalInterwiki values, in case there are several interwiki prefixes that point ...
$wgNamespaceAliases
Namespace aliases.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static getSubject( $index)
Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA,...
static isSubject( $index)
Is the given namespace is a subject (non-talk) namespace?
static getCanonicalName( $index)
Returns the canonical (English) name for a given index.
static isCapitalized( $index)
Is the namespace first-letter capitalized?
static hasSubpages( $index)
Does the namespace allow subpages?
static isNonincludable( $index)
It is not possible to use pages from this namespace as template?
static hasGenderDistinction( $index)
Does the namespace (potentially) have different aliases for different genders.
static isTalk( $index)
Is the given namespace a talk namespace?
static getTalk( $index)
Get the talk namespace index for a given namespace.
static isMovable( $index)
Can pages in the given namespace be moved?
static isContent( $index)
Does this namespace contain content, for the purposes of calculating statistics, etc?
static getAssociated( $index)
Get the associated namespace.
static getNamespaceContentModel( $index)
Get the default content model for a namespace This does not mean that all pages in that namespace hav...
This class provides some basic services that Lua libraries will probably need.
checkType( $name, $argIdx, $arg, $expectType)
Check the type of a variable.
getEngine()
Get the engine.
checkTypeOptional( $name, $argIdx, &$arg, $expectType, $default)
Check the type of a variable, with default if null.
getParser()
Get the parser.
incrementExpensiveFunctionCount()
Increment the expensive function count, and throw if limit exceeded.
static $interwikiMapCache
pagesInCategory( $category=null, $which=null)
Handler for pagesInCategory.
usersInGroup( $group=null)
Handler for usersInGroup.
static $namespacesCacheLang
pagesInNamespace( $ns=null)
Handler for pagesInNamespace.
getNsIndex( $name=null)
Handler for getNsIndex.
interwikiMap( $filter=null)
Handler for interwikiMap.
static numberingroup( $group)
Find the number of users in a given user group.
static getVersion( $flags='', $lang=null)
Return a string of the MediaWiki version with Git revision if available.