ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 $titleCache = array()
 Static cache variables. More...
 
static $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 87 of file Title.php.

References NS_MAIN, and null.

88  {
89  $this->mInterwiki = $this->mUrlform =
90  $this->mTextform = $this->mDbkeyform = '';
91  $this->mArticleID = -1;
92  $this->mNamespace = NS_MAIN;
93  $this->mRestrictionsLoaded = false;
94  $this->mRestrictions = array();
95  # Dont change the following, NS_MAIN is hardcoded in several place
96  # See bug #696
97  $this->mDefaultNamespace = NS_MAIN;
98  $this->mWatched = null;
99  $this->mLatestID = false;
100  $this->mOldRestrictions = false;
101  }
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
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

Member Function Documentation

◆ equals()

Title::equals (   $title)

Compare with another title.

Parameters
Title$title
Returns
bool

Definition at line 488 of file Title.php.

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

489  {
490  // Note: === is necessary for proper matching of number-like titles.
491  return $this->getInterwiki() === $title->getInterwiki()
492  && $this->getNamespace() == $title->getNamespace()
493  && $this->getDBkey() === $title->getDBkey();
494  }
getDBkey()
Get the main part with underscores.
Definition: Title.php:206
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:214
getInterwiki()
Get the interwiki prefix (or null string)
Definition: Title.php:243
+ Here is the call graph for this function:

◆ getDBkey()

Title::getDBkey ( )

Get the main part with underscores.

Returns
string

Definition at line 206 of file Title.php.

References $mDbkeyform.

Referenced by equals().

207  {
208  return $this->mDbkeyform;
209  }
$mDbkeyform
Definition: Title.php:64
+ 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 251 of file Title.php.

References $mFragment.

252  {
253  return $this->mFragment;
254  }
$mFragment
Definition: Title.php:67

◆ getInterwiki()

Title::getInterwiki ( )

Get the interwiki prefix (or null string)

Returns
string

Definition at line 243 of file Title.php.

References $mInterwiki.

Referenced by equals().

244  {
245  return $this->mInterwiki;
246  }
$mInterwiki
Definition: Title.php:66
+ 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 183 of file Title.php.

Referenced by secureAndSplit().

184  {
185  return "";
186  }
+ 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 214 of file Title.php.

References $mNamespace.

Referenced by equals().

215  {
216  return $this->mNamespace;
217  }
$mNamespace
Definition: Title.php:65
+ Here is the caller graph for this function:

◆ getNsText()

Title::getNsText ( )

Get the namespace text.

Returns
string

Definition at line 222 of file Title.php.

References $mNamespace.

Referenced by prefix().

223  {
224  global $wgContLang, $wgCanonicalNamespaceNames;
225 
226  if ('' != $this->mInterwiki) {
227  // This probably shouldn't even happen. ohh man, oh yuck.
228  // But for interwiki transclusion it sometimes does.
229  // Shit. Shit shit shit.
230  //
231  // Use the canonical namespaces if possible to try to
232  // resolve a foreign namespace.
233  if (isset($wgCanonicalNamespaceNames[$this->mNamespace])) {
234  return $wgCanonicalNamespaceNames[$this->mNamespace];
235  }
236  }
237  return $wgContLang->getNsText($this->mNamespace);
238  }
$mNamespace
Definition: Title.php:65
+ 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 197 of file Title.php.

References $mTextform.

198  {
199  return $this->mTextform;
200  }
$mTextform
All member variables should be considered private Please use the accessor functions.
Definition: Title.php:62

◆ 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 166 of file Title.php.

Referenced by secureAndSplit().

167  {
168  global $wgLegalTitleChars;
169 
170  $wgLegalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
171 
172  return $wgLegalTitleChars;
173  }
+ 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 115 of file Title.php.

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

Referenced by ilWikiUtil\processInternalLinks().

116  {
125  if ($defaultNamespace == NS_MAIN && isset(Title::$titleCache[$text])) {
126  return Title::$titleCache[$text];
127  }
128 
132  $filteredText = Sanitizer::decodeCharReferences($text);
133 
134  $t = new Title();
135  $t->mDbkeyform = str_replace(' ', '_', $filteredText);
136  $t->mDefaultNamespace = $defaultNamespace;
137 
138  static $cachedcount = 0 ;
139  if ($t->secureAndSplit()) {
140  if ($defaultNamespace == NS_MAIN) {
141  if ($cachedcount >= MW_TITLECACHE_MAX) {
142  # Avoid memory leaks on mass operations...
143  Title::$titleCache = array();
144  $cachedcount = 0;
145  }
146  $cachedcount++;
147  Title::$titleCache[$text] = &$t;
148  }
149  return $t;
150  } else {
151  $ret = null;
152  return $ret;
153  }
154  }
Title class.
Definition: Title.php:41
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
static decodeCharReferences($text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string...
Definition: Sanitizer.php:373
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static $titleCache
Static cache variables.
Definition: Title.php:46
const MW_TITLECACHE_MAX
Definition: Title.php:30
+ Here is the call graph for this function:
+ Here is the caller 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 264 of file Title.php.

References getNsText().

265  {
266  $p = '';
267  if ('' != $this->mInterwiki) {
268  $p = $this->mInterwiki . ':';
269  }
270  if (0 != $this->mNamespace) {
271  $p .= $this->getNsText() . ':';
272  }
273  return $p . $name;
274  }
getNsText()
Get the namespace text.
Definition: Title.php:222
+ 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 286 of file Title.php.

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

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

Referenced by secureAndSplit().

478  {
479  $this->mFragment = str_replace('_', ' ', substr($fragment, 1));
480  }
+ Here is the caller graph for this function:

Field Documentation

◆ $interwikiCache

Title::$interwikiCache = array()
staticprivate

Definition at line 47 of file Title.php.

◆ $mArticleID

Title::$mArticleID

Definition at line 68 of file Title.php.

◆ $mCascadeRestriction

Title::$mCascadeRestriction

Definition at line 71 of file Title.php.

◆ $mCascadeRestrictionSources

Title::$mCascadeRestrictionSources

Definition at line 74 of file Title.php.

◆ $mDbkeyform

Title::$mDbkeyform

Definition at line 64 of file Title.php.

Referenced by getDBkey(), and secureAndSplit().

◆ $mDefaultNamespace

Title::$mDefaultNamespace

Definition at line 77 of file Title.php.

Referenced by secureAndSplit().

◆ $mFragment

Title::$mFragment

Definition at line 67 of file Title.php.

Referenced by getFragment().

◆ $mHasCascadingRestrictions

Title::$mHasCascadingRestrictions

Definition at line 73 of file Title.php.

◆ $mInterwiki

Title::$mInterwiki

Definition at line 66 of file Title.php.

Referenced by getInterwiki().

◆ $mLatestID

Title::$mLatestID

Definition at line 69 of file Title.php.

◆ $mNamespace

Title::$mNamespace

Definition at line 65 of file Title.php.

Referenced by getNamespace(), and getNsText().

◆ $mOldRestrictions

bool Title::$mOldRestrictions
protected

Definition at line 51 of file Title.php.

◆ $mPrefixedText

Title::$mPrefixedText

Definition at line 76 of file Title.php.

◆ $mRestrictions

Title::$mRestrictions

Definition at line 70 of file Title.php.

◆ $mRestrictionsExpiry

Title::$mRestrictionsExpiry

Definition at line 72 of file Title.php.

◆ $mRestrictionsLoaded

Title::$mRestrictionsLoaded

Definition at line 75 of file Title.php.

◆ $mTextform

Title::$mTextform

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

#+

Definition at line 62 of file Title.php.

Referenced by getText().

◆ $mUrlform

Title::$mUrlform

Definition at line 63 of file Title.php.

◆ $mWatched

Title::$mWatched

Definition at line 79 of file Title.php.

◆ $titleCache

Title::$titleCache = array()
staticprivate

Static cache variables.

Definition at line 46 of file Title.php.

Referenced by newFromText().


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