ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
Title Class Reference

Title class. More...

+ Collaboration diagram for Title:

Public Member Functions

 __construct ()
 #- More...
 
 getText ()
 Simple accessors. More...
 
 getDBkey ()
 Get the main part with underscores. More...
 
 getNamespace ()
 Get the namespace index, i.e. More...
 
 getNsText ()
 Get the namespace text. More...
 
 getInterwiki ()
 Get the interwiki prefix (or null string) More...
 
 getFragment ()
 Get the Title fragment (i.e. More...
 
 prefix ($name)
 Prefix some arbitrary text with the namespace or interwiki prefix of this object. More...
 
 setFragment ($fragment)
 Set the fragment for this title This is kind of bad, since except for this rarely-used function, Title objects are immutable. More...
 
 equals ($title)
 Compare with another title. More...
 

Static Public Member Functions

static newFromText ($text, $defaultNamespace=NS_MAIN)
 Create a new Title from text, such as what one would find in a link. More...
 
static legalChars ()
 Get a regex character class describing the legal characters in a link. More...
 
 getInterwikiLink ($key)
 Returns the URL associated with an interwiki prefix. More...
 

Data Fields

 $mTextform
 All member variables should be considered private Please use the accessor functions. More...
 
 $mUrlform
 
 $mDbkeyform
 
 $mNamespace
 
 $mInterwiki
 
 $mFragment
 
 $mArticleID
 
 $mLatestID
 
 $mRestrictions
 
 $mCascadeRestriction
 
 $mRestrictionsExpiry
 
 $mHasCascadingRestrictions
 
 $mCascadeRestrictionSources
 
 $mRestrictionsLoaded
 
 $mPrefixedText
 
 $mDefaultNamespace
 
 $mWatched
 

Protected Attributes

bool $mOldRestrictions
 

Private Member Functions

 secureAndSplit ()
 Secure and split - main initialisation function for this object. More...
 

Static Private Attributes

static array $titleCache = array()
 
static array $interwikiCache = array()
 

Detailed Description

Title class.

  • Represents a title, which may contain an interwiki designation or namespace
  • Can fetch various kinds of data from the database, albeit inefficiently.

Definition at line 41 of file Title.php.

Constructor & Destructor Documentation

◆ __construct()

Title::__construct ( )

#-

Constructor

Definition at line 81 of file Title.php.

82 {
83 $this->mInterwiki = $this->mUrlform =
84 $this->mTextform = $this->mDbkeyform = '';
85 $this->mArticleID = -1;
86 $this->mNamespace = NS_MAIN;
87 $this->mRestrictionsLoaded = false;
88 $this->mRestrictions = array();
89 # Dont change the following, NS_MAIN is hardcoded in several place
90 # See bug #696
91 $this->mDefaultNamespace = NS_MAIN;
92 $this->mWatched = null;
93 $this->mLatestID = false;
94 $this->mOldRestrictions = false;
95 }
const NS_MAIN
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Title.php:20

References NS_MAIN.

Member Function Documentation

◆ equals()

Title::equals (   $title)

Compare with another title.

Parameters
Title$title
Returns
bool

Definition at line 482 of file Title.php.

483 {
484 // Note: === is necessary for proper matching of number-like titles.
485 return $this->getInterwiki() === $title->getInterwiki()
486 && $this->getNamespace() == $title->getNamespace()
487 && $this->getDBkey() === $title->getDBkey();
488 }
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:208
getDBkey()
Get the main part with underscores.
Definition: Title.php:200
getInterwiki()
Get the interwiki prefix (or null string)
Definition: Title.php:237

References getDBkey(), getInterwiki(), and getNamespace().

+ Here is the call graph for this function:

◆ getDBkey()

Title::getDBkey ( )

Get the main part with underscores.

Returns
string

Definition at line 200 of file Title.php.

201 {
202 return $this->mDbkeyform;
203 }
$mDbkeyform
Definition: Title.php:58

References $mDbkeyform.

Referenced by equals().

+ Here is the caller graph for this function:

◆ getFragment()

Title::getFragment ( )

Get the Title fragment (i.e.

the bit after the #) in text form

Returns
string

Definition at line 245 of file Title.php.

246 {
247 return $this->mFragment;
248 }
$mFragment
Definition: Title.php:61

References $mFragment.

◆ getInterwiki()

Title::getInterwiki ( )

Get the interwiki prefix (or null string)

Returns
string

Definition at line 237 of file Title.php.

238 {
239 return $this->mInterwiki;
240 }
$mInterwiki
Definition: Title.php:60

References $mInterwiki.

Referenced by equals().

+ Here is the caller graph for this function:

◆ getInterwikiLink()

Title::getInterwikiLink (   $key)
static

Returns the URL associated with an interwiki prefix.

Parameters
string$keythe interwiki prefix (e.g. "MeatBall")
Returns
string the associated URL, containing "$1", which should be replaced by an article title (arguably)

Definition at line 177 of file Title.php.

178 {
179 return "";
180 }

Referenced by secureAndSplit().

+ Here is the caller graph for this function:

◆ getNamespace()

Title::getNamespace ( )

Get the namespace index, i.e.

one of the NS_xxxx constants

Returns
int

Definition at line 208 of file Title.php.

209 {
210 return $this->mNamespace;
211 }
$mNamespace
Definition: Title.php:59

References $mNamespace.

Referenced by equals().

+ Here is the caller graph for this function:

◆ getNsText()

Title::getNsText ( )

Get the namespace text.

Returns
string

Definition at line 216 of file Title.php.

217 {
218 global $wgContLang, $wgCanonicalNamespaceNames;
219
220 if ('' != $this->mInterwiki) {
221 // This probably shouldn't even happen. ohh man, oh yuck.
222 // But for interwiki transclusion it sometimes does.
223 // Shit. Shit shit shit.
224 //
225 // Use the canonical namespaces if possible to try to
226 // resolve a foreign namespace.
227 if (isset($wgCanonicalNamespaceNames[$this->mNamespace])) {
228 return $wgCanonicalNamespaceNames[$this->mNamespace];
229 }
230 }
231 return $wgContLang->getNsText($this->mNamespace);
232 }

References $mNamespace.

Referenced by prefix().

+ Here is the caller graph for this function:

◆ getText()

Title::getText ( )

Simple accessors.

Get the text form (spaces not underscores) of the main part

Returns
string

Definition at line 191 of file Title.php.

192 {
193 return $this->mTextform;
194 }
$mTextform
All member variables should be considered private Please use the accessor functions.
Definition: Title.php:56

References $mTextform.

◆ legalChars()

static Title::legalChars ( )
static

Get a regex character class describing the legal characters in a link.

Returns
string the list of characters, not delimited

Definition at line 160 of file Title.php.

161 {
162 global $wgLegalTitleChars;
163
164 $wgLegalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
165
166 return $wgLegalTitleChars;
167 }

Referenced by secureAndSplit().

+ Here is the caller graph for this function:

◆ newFromText()

static Title::newFromText (   $text,
  $defaultNamespace = NS_MAIN 
)
static

Create a new Title from text, such as what one would find in a link.

Decodes any HTML entities in the text.

Parameters
string$textthe link text; spaces, prefixes, and an initial ':' indicating the main namespace are accepted
int$defaultNamespacethe namespace to use if none is specified by a prefix
Returns
Title the new object, or NULL on an error

Wiki pages often contain multiple links to the same page. Title normalization and parsing can become expensive on pages with many links, so we can save a little time by caching them.

In theory these are value objects and won't get changed...

Convert things like é ā or 〗 into real text...

Definition at line 109 of file Title.php.

110 {
119 if ($defaultNamespace == NS_MAIN && isset(Title::$titleCache[$text])) {
121 }
122
126 $filteredText = Sanitizer::decodeCharReferences($text);
127
128 $t = new Title();
129 $t->mDbkeyform = str_replace(' ', '_', $filteredText);
130 $t->mDefaultNamespace = $defaultNamespace;
131
132 static $cachedcount = 0 ;
133 if ($t->secureAndSplit()) {
134 if ($defaultNamespace == NS_MAIN) {
135 if ($cachedcount >= MW_TITLECACHE_MAX) {
136 # Avoid memory leaks on mass operations...
137 Title::$titleCache = array();
138 $cachedcount = 0;
139 }
140 $cachedcount++;
142 }
143 return $t;
144 } else {
145 $ret = null;
146 return $ret;
147 }
148 }
const MW_TITLECACHE_MAX
Definition: Title.php:30
static decodeCharReferences($text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string.
Definition: Sanitizer.php:374
Title class.
Definition: Title.php:42
static array $titleCache
Definition: Title.php:43
$text
Definition: xapiexit.php:21

References $text, $titleCache, Sanitizer\decodeCharReferences(), MW_TITLECACHE_MAX, and NS_MAIN.

+ Here is the call graph for this function:

◆ prefix()

Title::prefix (   $name)

Prefix some arbitrary text with the namespace or interwiki prefix of this object.

Parameters
string$namethe text
Returns
string the prefixed text

Definition at line 258 of file Title.php.

259 {
260 $p = '';
261 if ('' != $this->mInterwiki) {
262 $p = $this->mInterwiki . ':';
263 }
264 if (0 != $this->mNamespace) {
265 $p .= $this->getNsText() . ':';
266 }
267 return $p . $name;
268 }
getNsText()
Get the namespace text.
Definition: Title.php:216

References getNsText().

+ Here is the call graph for this function:

◆ secureAndSplit()

Title::secureAndSplit ( )
private

Secure and split - main initialisation function for this object.

Assumes that mDbkeyform has been set, and is urldecoded and uses underscores, but not otherwise munged. This function removes illegal characters, splits off the interwiki and namespace prefixes, sets the other forms, and canonicalizes everything.

Returns
bool true on success

Pages with "/./" or "/../" appearing in the URLs will often be unreachable due to the way web browsers deal with 'relative' URLs. Forbid them explicitly.

Magic tilde sequences? Nu-uh!

Limit the size of titles to 255 bytes. This is typically the size of the underlying database field. We make an exception for special pages, which don't need to be stored in the database, and may edge over 255 bytes due to subpage syntax for long titles, e.g. [[Special:Block/Long name]]

Normally, all wiki links are forced to have an initial capital letter so [[foo]] and [[Foo]] point to the same place.

Don't force it for interwikis, since the other site might be case-sensitive.

Can't make a link to a namespace alone... "empty" local links can only be self-links with a fragment identifier.

Definition at line 280 of file Title.php.

281 {
282 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
283
284 # Initialisation
285 static $rxTc = false;
286 if (!$rxTc) {
287 # % is needed as well
288 $rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
289 }
290
291 $this->mInterwiki = $this->mFragment = '';
292 $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
293
294 $dbkey = $this->mDbkeyform;
295
296 # Strip Unicode bidi override characters.
297 # Sometimes they slip into cut-n-pasted page titles, where the
298 # override chars get included in list displays.
299 $dbkey = str_replace("\xE2\x80\x8E", '', $dbkey); // 200E LEFT-TO-RIGHT MARK
300 $dbkey = str_replace("\xE2\x80\x8F", '', $dbkey); // 200F RIGHT-TO-LEFT MARK
301
302 # Clean up whitespace
303 #
304 $dbkey = preg_replace('/[ _]+/', '_', $dbkey);
305 $dbkey = trim($dbkey, '_');
306
307 if ('' == $dbkey) {
308 return false;
309 }
310
311 if (false !== strpos($dbkey, UTF8_REPLACEMENT)) {
312 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
313 return false;
314 }
315
316 $this->mDbkeyform = $dbkey;
317
318 # Initial colon indicates main namespace rather than specified default
319 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
320 if (':' == $dbkey[0]) {
321 $this->mNamespace = NS_MAIN;
322 $dbkey = substr($dbkey, 1); # remove the colon but continue processing
323 $dbkey = trim($dbkey, '_'); # remove any subsequent whitespace
324 }
325
326 # Namespace or interwiki prefix
327 $firstPass = true;
328 do {
329 $m = array();
330 if (preg_match("/^(.+?)_*:_*(.*)$/S", $dbkey, $m)) {
331 $p = $m[1];
332 if ($ns = $wgContLang->getNsIndex($p)) {
333 # Ordinary namespace
334 $dbkey = $m[2];
335 $this->mNamespace = $ns;
336 } elseif ($this->getInterwikiLink($p)) {
337 if (!$firstPass) {
338 # Can't make a local interwiki link to an interwiki link.
339 # That's just crazy!
340 return false;
341 }
342
343 # Interwiki link
344 $dbkey = $m[2];
345 $this->mInterwiki = $wgContLang->lc($p);
346
347 # Redundant interwiki prefix to the local wiki
348 if (0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) {
349 if ($dbkey == '') {
350 # Can't have an empty self-link
351 return false;
352 }
353 $this->mInterwiki = '';
354 $firstPass = false;
355 # Do another namespace split...
356 continue;
357 }
358
359 # If there's an initial colon after the interwiki, that also
360 # resets the default namespace
361 if ($dbkey !== '' && $dbkey[0] == ':') {
362 $this->mNamespace = NS_MAIN;
363 $dbkey = substr($dbkey, 1);
364 }
365 }
366 # If there's no recognized interwiki or namespace,
367 # then let the colon expression be part of the title.
368 }
369 break;
370 } while (true);
371
372 # We already know that some pages won't be in the database!
373 #
374 if ('' != $this->mInterwiki || NS_SPECIAL == $this->mNamespace) {
375 $this->mArticleID = 0;
376 }
377 $fragment = strstr($dbkey, '#');
378 if (false !== $fragment) {
379 $this->setFragment($fragment);
380 $dbkey = substr($dbkey, 0, strlen($dbkey) - strlen($fragment));
381 # remove whitespace again: prevents "Foo_bar_#"
382 # becoming "Foo_bar_"
383 $dbkey = preg_replace('/_*$/', '', $dbkey);
384 }
385
386 # Reject illegal characters.
387 #
388 if (preg_match($rxTc, $dbkey)) {
389 return false;
390 }
391
397 if (strpos($dbkey, '.') !== false &&
398 ($dbkey === '.' || $dbkey === '..' ||
399 strpos($dbkey, './') === 0 ||
400 strpos($dbkey, '../') === 0 ||
401 strpos($dbkey, '/./') !== false ||
402 strpos($dbkey, '/../') !== false)) {
403 return false;
404 }
405
409 if (strpos($dbkey, '~~~') !== false) {
410 return false;
411 }
412
420 if (($this->mNamespace != NS_SPECIAL && strlen($dbkey) > 255) ||
421 strlen($dbkey) > 512) {
422 return false;
423 }
424
433 if ($wgCapitalLinks && $this->mInterwiki == '') {
434 $dbkey = $wgContLang->ucfirst($dbkey);
435 }
436
442 if ($dbkey == '' &&
443 $this->mInterwiki == '' &&
444 $this->mNamespace != NS_MAIN) {
445 return false;
446 }
447
448 // Any remaining initial :s are illegal.
449 if ($dbkey !== '' && ':' == $dbkey[0]) {
450 return false;
451 }
452
453 # Fill fields
454 $this->mDbkeyform = $dbkey;
455 $this->mUrlform = ilWikiUtil::wfUrlencode($dbkey);
456
457 $this->mTextform = str_replace('_', ' ', $dbkey);
458
459 return true;
460 }
const NS_SPECIAL
Definition: Title.php:21
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:160
setFragment($fragment)
Set the fragment for this title This is kind of bad, since except for this rarely-used function,...
Definition: Title.php:471
getInterwikiLink($key)
Returns the URL associated with an interwiki prefix.
Definition: Title.php:177
$mDefaultNamespace
Definition: Title.php:71
static wfUrlencode(string $s)

References $mDbkeyform, $mDefaultNamespace, getInterwikiLink(), legalChars(), NS_MAIN, NS_SPECIAL, setFragment(), and ilWikiUtil\wfUrlencode().

+ Here is the call graph for this function:

◆ setFragment()

Title::setFragment (   $fragment)

Set the fragment for this title This is kind of bad, since except for this rarely-used function, Title objects are immutable.

The reason this is here is because it's better than setting the members directly, which is what Linker::formatComment was doing previously.

Parameters
string$fragmenttext
Todo:
clarify whether access is supposed to be public (was marked as "kind of public")

Definition at line 471 of file Title.php.

472 {
473 $this->mFragment = str_replace('_', ' ', substr($fragment, 1));
474 }

Referenced by secureAndSplit().

+ Here is the caller graph for this function:

Field Documentation

◆ $interwikiCache

array Title::$interwikiCache = array()
staticprivate

Definition at line 44 of file Title.php.

◆ $mArticleID

Title::$mArticleID

Definition at line 62 of file Title.php.

◆ $mCascadeRestriction

Title::$mCascadeRestriction

Definition at line 65 of file Title.php.

◆ $mCascadeRestrictionSources

Title::$mCascadeRestrictionSources

Definition at line 68 of file Title.php.

◆ $mDbkeyform

Title::$mDbkeyform

Definition at line 58 of file Title.php.

Referenced by getDBkey(), and secureAndSplit().

◆ $mDefaultNamespace

Title::$mDefaultNamespace

Definition at line 71 of file Title.php.

Referenced by secureAndSplit().

◆ $mFragment

Title::$mFragment

Definition at line 61 of file Title.php.

Referenced by getFragment().

◆ $mHasCascadingRestrictions

Title::$mHasCascadingRestrictions

Definition at line 67 of file Title.php.

◆ $mInterwiki

Title::$mInterwiki

Definition at line 60 of file Title.php.

Referenced by getInterwiki().

◆ $mLatestID

Title::$mLatestID

Definition at line 63 of file Title.php.

◆ $mNamespace

Title::$mNamespace

Definition at line 59 of file Title.php.

Referenced by getNamespace(), and getNsText().

◆ $mOldRestrictions

bool Title::$mOldRestrictions
protected

Definition at line 45 of file Title.php.

◆ $mPrefixedText

Title::$mPrefixedText

Definition at line 70 of file Title.php.

◆ $mRestrictions

Title::$mRestrictions

Definition at line 64 of file Title.php.

◆ $mRestrictionsExpiry

Title::$mRestrictionsExpiry

Definition at line 66 of file Title.php.

◆ $mRestrictionsLoaded

Title::$mRestrictionsLoaded

Definition at line 69 of file Title.php.

◆ $mTextform

Title::$mTextform

All member variables should be considered private Please use the accessor functions.

#+

Definition at line 56 of file Title.php.

Referenced by getText().

◆ $mUrlform

Title::$mUrlform

Definition at line 57 of file Title.php.

◆ $mWatched

Title::$mWatched

Definition at line 73 of file Title.php.

◆ $titleCache

array Title::$titleCache = array()
staticprivate

Definition at line 43 of file Title.php.

Referenced by newFromText().


The documentation for this class was generated from the following file: