Go to the documentation of this file.
11 public function register() {
13 'newTitle' => [ $this,
'newTitle' ],
14 'makeTitle' => [ $this,
'makeTitle' ],
15 'getExpensiveData' => [ $this,
'getExpensiveData' ],
16 'getUrl' => [ $this,
'getUrl' ],
17 'getContent' => [ $this,
'getContent' ],
18 'getFileInfo' => [ $this,
'getFileInfo' ],
19 'protectionLevels' => [ $this,
'protectionLevels' ],
20 'cascadingProtection' => [ $this,
'cascadingProtection' ],
21 'redirectTarget' => [ $this,
'redirectTarget' ],
23 return $this->
getEngine()->registerInterface(
'mw.title.lua', $lib, [
32 if ( $arg ===
null && $default !==
null ) {
34 } elseif ( is_numeric( $arg ) ) {
38 "bad argument #$argIdx to '$name' (unrecognized namespace number '$arg')"
41 } elseif ( is_string( $arg ) ) {
43 if ( $ns ===
false ) {
45 "bad argument #$argIdx to '$name' (unrecognized namespace name '$arg')"
50 $this->
checkType( $name, $argIdx, $arg,
'namespace number or name' );
61 $ns =
$title->getNamespace();
63 'isLocal' => (bool)
$title->isLocal(),
64 'interwiki' =>
$title->getInterwiki(),
66 'nsText' =>
$title->getNsText(),
67 'text' =>
$title->getText(),
68 'fragment' =>
$title->getFragment(),
69 'thePartialUrl' =>
$title->getPartialURL(),
74 $this->
getParser()->getOutput()->addLink( $title );
96 $this->
checkType(
'getExpensiveData', 1, $text,
'string' );
101 $dbKey =
$title->getPrefixedDBkey();
102 if ( isset( $this->titleCache[$dbKey] ) ) {
104 $title = $this->titleCache[$dbKey];
106 if ( !
$title->equals( $this->getTitle() ) ) {
116 $this->titleCache[$dbKey] =
$title;
117 if (
$title->getArticleID() > 0 ) {
123 'isRedirect' => (bool)
$title->isRedirect(),
124 'id' =>
$title->getArticleID(),
125 'contentModel' =>
$title->getContentModel(),
131 $ret[
'exists'] =
$title->exists();
148 public function newTitle( $text_or_id, $defaultNamespace =
null ) {
150 if (
$type ===
'number' ) {
151 if ( array_key_exists( $text_or_id, $this->idCache ) ) {
152 $title = $this->idCache[$text_or_id];
156 $this->idCache[$text_or_id] =
$title;
168 } elseif (
$type ===
'string' ) {
179 $this->
checkType(
'title.new', 1, $text_or_id,
'number or string' );
197 public function makeTitle( $ns, $text, $fragment =
null, $interwiki =
null ) {
199 $this->
checkType(
'makeTitle', 2, $text,
'string' );
222 public function getUrl( $text, $which, $query =
null, $proto =
null ) {
230 $this->
checkType(
'getUrl', 1, $text,
'string' );
231 $this->
checkType(
'getUrl', 2, $which,
'string' );
232 if ( !in_array( $which, [
'fullUrl',
'localUrl',
'canonicalUrl' ],
true ) ) {
233 $this->
checkType(
'getUrl', 2, $which,
"'fullUrl', 'localUrl', or 'canonicalUrl'" );
238 $func =
"get" . ucfirst( $which );
240 $args = [ $query, false ];
241 if ( !is_string( $query ) && !is_array( $query ) ) {
244 if ( $which ===
'fullUrl' ) {
246 if ( !isset( $protoMap[$proto] ) ) {
247 $this->
checkType( $which, 2, $proto,
"'http', 'https', 'relative', or 'canonical'" );
249 $args[] = $protoMap[$proto];
274 $this->
getParser()->getOutput()->addTemplate(
280 if (
$title->equals( $this->getTitle() ) ) {
281 $parserOutput = $this->
getParser()->getOutput();
282 $parserOutput->setFlag(
'vary-revision-sha1' );
283 $parserOutput->setRevisionUsedSha1Base36( $rev ? $rev->getSha1() :
'' );
284 wfDebug( __METHOD__ .
": set vary-revision-sha1 for '$title'" );
287 return $rev ? $rev->getContent() :
null;
297 $this->
checkType(
'getContent', 1, $text,
'string' );
309 $this->
checkType(
'getFileInfo', 1, $text,
'string' );
314 $ns =
$title->getNamespace();
322 return [ [
'exists' => false ] ];
324 $this->
getParser()->getOutput()->addImage(
327 if ( !
$file->exists() ) {
328 return [ [
'exists' => false ] ];
330 $pageCount =
$file->pageCount();
331 if ( $pageCount ===
false ) {
335 for ( $i = 1; $i <= $pageCount; ++$i ) {
337 'width' =>
$file->getWidth( $i ),
338 'height' =>
$file->getHeight( $i )
344 'width' =>
$file->getWidth(),
345 'height' =>
$file->getHeight(),
346 'mimeType' =>
$file->getMimeType(),
347 'size' =>
$file->getSize(),
353 if ( empty( $arr ) ) {
356 return array_combine( range( 1, count( $arr ) ), array_values( $arr ) );
366 $this->
checkType(
'protectionLevels', 1, $text,
'string' );
372 if ( !
$title->areRestrictionsLoaded() ) {
376 'Scribunto_LuaTitleLibrary::makeArrayOneBased',
$title->getAllRestrictions()
387 $this->
checkType(
'cascadingProtection', 1, $text,
'string' );
393 if ( !
$title->areCascadeProtectionSourcesLoaded() ) {
396 list( $sources, $restrictions ) =
$title->getCascadeProtectionSources();
400 return $t->getPrefixedText();
403 'restrictions' => array_map(
'Scribunto_LuaTitleLibrary::makeArrayOneBased', $restrictions )
414 $this->
checkType(
'redirectTarget', 1, $text,
'string' );
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
getContent( $text)
Handler for getContent.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
getUrl( $text, $which, $query=null, $proto=null)
Get a URL referring to this title.
equals(LinkTarget $title)
Compare with another title.
getEngine()
Get the engine.
newTitle( $text_or_id, $defaultNamespace=null)
Handler for title.new.
getParser()
Get the parser.
checkNamespace( $name, $argIdx, &$arg, $default=null)
checkType( $name, $argIdx, $arg, $expectType)
Check the type of a variable.
static makeArrayOneBased( $arr)
getInexpensiveTitleData(Title $title)
Extract inexpensive information from a Title object for return to Lua.
cascadingProtection( $text)
Handler for cascadingProtection.
protectionLevels( $text)
Handler for protectionLevels.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
checkTypeOptional( $name, $argIdx, &$arg, $expectType, $default)
Check the type of a variable, with default if null.
This class provides some basic services that Lua libraries will probably need.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static exists( $index)
Returns whether the specified namespace exists.
getContentInternal( $text)
Utility to get a Content object from a title.
wfFindFile( $title, $options=[])
Find a file.
Represents a title within MediaWiki.
incrementExpensiveFunctionCount()
Increment the expensive function count, and throw if limit exceeded.
getExpensiveData( $text)
Extract expensive information from a Title object for return to Lua.
makeTitle( $ns, $text, $fragment=null, $interwiki=null)
Handler for title.makeTitle.
redirectTarget( $text)
Handler for redirectTarget.
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
getLuaType( $var)
Get the Lua type corresponding to the type of the variable.
getFileInfo( $text)
Handler for getFileInfo.