20define(
'NS_MAIN',
"nsmain");
21define(
'NS_SPECIAL',
"nsspecial");
23define(
'GAID_FOR_UPDATE', 1);
25# Title::newFromTitle maintains a cache to avoid
26# expensive re-normalization of commonly used titles.
27# On a batch operation this can become a memory leak
28# if not bounded. After hitting this many titles,
30define(
'MW_TITLECACHE_MAX', 1000);
32# Constants for pr_cascade bitfield
59 public $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
61 public
$mFragment;
# Title fragment (i.e. the bit after the #)
72 # Zero except in {{transclusion}} tags
73 public $mWatched; # Is $wgUser watching
this page?
NULL if unfilled, accessed through userIsWatching()
83 $this->mInterwiki = $this->mUrlform =
84 $this->mTextform = $this->mDbkeyform =
'';
85 $this->mArticleID = -1;
87 $this->mRestrictionsLoaded =
false;
88 $this->mRestrictions = array();
89 # Dont change the following, NS_MAIN is hardcoded in several place
91 $this->mDefaultNamespace =
NS_MAIN;
92 $this->mWatched =
null;
93 $this->mLatestID =
false;
94 $this->mOldRestrictions =
false;
129 $t->mDbkeyform = str_replace(
' ',
'_', $filteredText);
130 $t->mDefaultNamespace = $defaultNamespace;
132 static $cachedcount = 0 ;
133 if ($t->secureAndSplit()) {
134 if ($defaultNamespace ==
NS_MAIN) {
136 # Avoid memory leaks on mass operations...
151 #----------------------------------------------------------------------------
153 #----------------------------------------------------------------------------
162 global $wgLegalTitleChars;
164 $wgLegalTitleChars =
" %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
166 return $wgLegalTitleChars;
182 #----------------------------------------------------------------------------
184 #----------------------------------------------------------------------------
218 global $wgContLang, $wgCanonicalNamespaceNames;
220 if (
'' != $this->mInterwiki) {
227 if (isset($wgCanonicalNamespaceNames[$this->mNamespace])) {
231 return $wgContLang->getNsText($this->mNamespace);
261 if (
'' != $this->mInterwiki) {
262 $p = $this->mInterwiki .
':';
264 if (0 != $this->mNamespace) {
282 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
285 static $rxTc =
false;
287 # % is needed as well
291 $this->mInterwiki = $this->mFragment =
'';
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);
300 $dbkey = str_replace(
"\xE2\x80\x8F",
'', $dbkey);
302 # Clean up whitespace
304 $dbkey = preg_replace(
'/[ _]+/',
'_', $dbkey);
305 $dbkey = trim($dbkey,
'_');
311 if (
false !== strpos($dbkey, UTF8_REPLACEMENT)) {
312 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
316 $this->mDbkeyform = $dbkey;
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]) {
322 $dbkey = substr($dbkey, 1); #
remove the colon but
continue processing
323 $dbkey = trim($dbkey,
'_'); #
remove any subsequent whitespace
326 # Namespace or interwiki prefix
330 if (preg_match(
"/^(.+?)_*:_*(.*)$/S", $dbkey, $m)) {
332 if ($ns = $wgContLang->getNsIndex($p)) {
335 $this->mNamespace = $ns;
338 # Can't make a local interwiki link to an interwiki link.
345 $this->mInterwiki = $wgContLang->lc($p);
347 # Redundant interwiki prefix to the local wiki
348 if (0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) {
350 # Can't have an empty self-link
353 $this->mInterwiki =
'';
355 # Do another namespace split...
359 # If there's an initial colon after the interwiki, that also
360 # resets the default namespace
361 if ($dbkey !==
'' && $dbkey[0] ==
':') {
363 $dbkey = substr($dbkey, 1);
366 # If there's no recognized interwiki or namespace,
367 # then let the colon expression be part of the title.
372 # We already know that some pages won't be in the database!
374 if (
'' != $this->mInterwiki ||
NS_SPECIAL == $this->mNamespace) {
375 $this->mArticleID = 0;
377 $fragment = strstr($dbkey,
'#');
378 if (
false !== $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);
386 # Reject illegal characters.
388 if (preg_match($rxTc, $dbkey)) {
397 if (strpos($dbkey,
'.') !==
false &&
398 ($dbkey ===
'.' || $dbkey ===
'..' ||
399 strpos($dbkey,
'./') === 0 ||
400 strpos($dbkey,
'../') === 0 ||
401 strpos($dbkey,
'/./') !==
false ||
402 strpos($dbkey,
'/../') !==
false)) {
409 if (strpos($dbkey,
'~~~') !==
false) {
420 if (($this->mNamespace !=
NS_SPECIAL && strlen($dbkey) > 255) ||
421 strlen($dbkey) > 512) {
433 if ($wgCapitalLinks && $this->mInterwiki ==
'') {
434 $dbkey = $wgContLang->ucfirst($dbkey);
443 $this->mInterwiki ==
'' &&
444 $this->mNamespace !=
NS_MAIN) {
449 if ($dbkey !==
'' &&
':' == $dbkey[0]) {
454 $this->mDbkeyform = $dbkey;
457 $this->mTextform = str_replace(
'_',
' ', $dbkey);
473 $this->mFragment = str_replace(
'_',
' ', substr($fragment, 1));
487 && $this->
getDBkey() === $title->getDBkey();
static decodeCharReferences($text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string.
getNamespace()
Get the namespace index, i.e.
$mHasCascadingRestrictions
$mTextform
All member variables should be considered private Please use the accessor functions.
secureAndSplit()
Secure and split - main initialisation function for this object.
getFragment()
Get the Title fragment (i.e.
prefix($name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
$mCascadeRestrictionSources
static legalChars()
Get a regex character class describing the legal characters in a link.
getNsText()
Get the namespace text.
equals($title)
Compare with another title.
static array $interwikiCache
getDBkey()
Get the main part with underscores.
getText()
Simple accessors.
setFragment($fragment)
Set the fragment for this title This is kind of bad, since except for this rarely-used function,...
getInterwikiLink($key)
Returns the URL associated with an interwiki prefix.
getInterwiki()
Get the interwiki prefix (or null string)
static wfUrlencode(string $s)
form(?array $class_path, string $cmd, string $submit_caption="")
link(string $caption, string $href, bool $new_viewport=false)
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.