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
65 public $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
67 public
$mFragment;
# Title fragment (i.e. the bit after the #)
78 # Zero except in {{transclusion}} tags
79 public $mWatched; # Is $wgUser watching
this page?
NULL if unfilled, accessed through userIsWatching()
89 $this->mInterwiki = $this->mUrlform =
90 $this->mTextform = $this->mDbkeyform =
'';
91 $this->mArticleID = -1;
93 $this->mRestrictionsLoaded =
false;
94 $this->mRestrictions = array();
95 # Dont change the following, NS_MAIN is hardcoded in several place
97 $this->mDefaultNamespace =
NS_MAIN;
98 $this->mWatched =
null;
99 $this->mLatestID =
false;
100 $this->mOldRestrictions =
false;
135 $t->mDbkeyform = str_replace(
' ',
'_', $filteredText);
136 $t->mDefaultNamespace = $defaultNamespace;
138 static $cachedcount = 0 ;
139 if ($t->secureAndSplit()) {
140 if ($defaultNamespace ==
NS_MAIN) {
142 # Avoid memory leaks on mass operations...
157 #----------------------------------------------------------------------------
159 #----------------------------------------------------------------------------
168 global $wgLegalTitleChars;
170 $wgLegalTitleChars =
" %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
172 return $wgLegalTitleChars;
188 #----------------------------------------------------------------------------
190 #----------------------------------------------------------------------------
224 global $wgContLang, $wgCanonicalNamespaceNames;
226 if (
'' != $this->mInterwiki) {
233 if (isset($wgCanonicalNamespaceNames[$this->mNamespace])) {
237 return $wgContLang->getNsText($this->mNamespace);
267 if (
'' != $this->mInterwiki) {
268 $p = $this->mInterwiki .
':';
270 if (0 != $this->mNamespace) {
288 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
291 static $rxTc =
false;
293 # % is needed as well
297 $this->mInterwiki = $this->mFragment =
'';
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);
306 $dbkey = str_replace(
"\xE2\x80\x8F",
'', $dbkey);
308 # Clean up whitespace
310 $dbkey = preg_replace(
'/[ _]+/',
'_', $dbkey);
311 $dbkey = trim($dbkey,
'_');
317 if (
false !== strpos($dbkey, UTF8_REPLACEMENT)) {
318 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
322 $this->mDbkeyform = $dbkey;
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]) {
328 $dbkey = substr($dbkey, 1); #
remove the colon but
continue processing
329 $dbkey = trim($dbkey,
'_'); #
remove any subsequent whitespace
332 # Namespace or interwiki prefix
336 if (preg_match(
"/^(.+?)_*:_*(.*)$/S", $dbkey, $m)) {
338 if ($ns = $wgContLang->getNsIndex($p)) {
341 $this->mNamespace = $ns;
344 # Can't make a local interwiki link to an interwiki link.
351 $this->mInterwiki = $wgContLang->lc($p);
353 # Redundant interwiki prefix to the local wiki
354 if (0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) {
356 # Can't have an empty self-link
359 $this->mInterwiki =
'';
361 # Do another namespace split...
365 # If there's an initial colon after the interwiki, that also
366 # resets the default namespace
367 if ($dbkey !==
'' && $dbkey[0] ==
':') {
369 $dbkey = substr($dbkey, 1);
372 # If there's no recognized interwiki or namespace,
373 # then let the colon expression be part of the title.
378 # We already know that some pages won't be in the database!
380 if (
'' != $this->mInterwiki ||
NS_SPECIAL == $this->mNamespace) {
381 $this->mArticleID = 0;
383 $fragment = strstr($dbkey,
'#');
384 if (
false !== $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);
392 # Reject illegal characters.
394 if (preg_match($rxTc, $dbkey)) {
403 if (strpos($dbkey,
'.') !==
false &&
404 ($dbkey ===
'.' || $dbkey ===
'..' ||
405 strpos($dbkey,
'./') === 0 ||
406 strpos($dbkey,
'../') === 0 ||
407 strpos($dbkey,
'/./') !==
false ||
408 strpos($dbkey,
'/../') !==
false)) {
415 if (strpos($dbkey,
'~~~') !==
false) {
426 if (($this->mNamespace !=
NS_SPECIAL && strlen($dbkey) > 255) ||
427 strlen($dbkey) > 512) {
439 if ($wgCapitalLinks && $this->mInterwiki ==
'') {
440 $dbkey = $wgContLang->ucfirst($dbkey);
449 $this->mInterwiki ==
'' &&
450 $this->mNamespace !=
NS_MAIN) {
455 if ($dbkey !==
'' &&
':' == $dbkey[0]) {
460 $this->mDbkeyform = $dbkey;
463 $this->mTextform = str_replace(
'_',
' ', $dbkey);
479 $this->mFragment = str_replace(
'_',
' ', substr($fragment, 1));
493 && $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.
static $titleCache
Static cache variables.
$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.
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( $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.