8 if ( !class_exists( 'UtfNormal' ) ) {
9 require_once( dirname(__FILE__
) . '/normal/UtfNormal.php' );
12 define ( 'GAID_FOR_UPDATE', 1 );
14 # Title::newFromTitle maintains a cache to avoid
15 # expensive re-normalization of commonly used titles.
16 # On a batch operation this can become a memory leak
17 # if not bounded. After hitting this many titles,
19 define( 'MW_TITLECACHE_MAX', 1000 );
21 # Constants for pr_cascade bitfield
22 define( 'CASCADE', 1 );
26 * - Represents a title, which may contain an interwiki designation or namespace
27 * - Can fetch various kinds of data from the database, albeit inefficiently.
32 * Static cache variables
34 static private $titleCache=array();
35 static private $interwikiCache=array();
39 * All member variables should be considered private
40 * Please use the accessor functions
47 var $mTextform; # Text form (spaces not underscores) of the main part
48 var $mUrlform; # URL-encoded form of the main part
49 var $mDbkeyform; # Main part with underscores
50 var $mUserCaseDBKey; # DB key with the initial letter in the case specified by the user
51 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
52 var $mInterwiki; # Interwiki prefix (or null string)
53 var $mFragment; # Title fragment (i.e. the bit after the #)
54 var $mArticleID; # Article ID, fetched from the link cache on demand
55 var $mLatestID; # ID of most recent revision
56 var $mRestrictions; # Array of groups allowed to edit this article
57 var $mCascadeRestriction; # Cascade restrictions on this page to included templates and images?
58 var $mRestrictionsExpiry; # When do the restrictions on this page expire?
59 var $mHasCascadingRestrictions; # Are cascading restrictions in effect on this page?
60 var $mCascadeRestrictionSources;# Where are the cascading restrictions coming from on this page?
61 var $mRestrictionsLoaded; # Boolean for initialisation on demand
62 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
63 var $mDefaultNamespace; # Namespace index when there is no namespace
64 # Zero except in {{transclusion}} tags
65 var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
66 var $mLength; # The page length, 0 for special pages
67 var $mRedirect; # Is the article at this title a redirect?
75 /* private */ function __construct() {
76 $this->mInterwiki
= $this->mUrlform
=
77 $this->mTextform
= $this->mDbkeyform
= '';
78 $this->mArticleID
= -1;
79 $this->mNamespace
= NS_MAIN
;
80 $this->mRestrictionsLoaded
= false;
81 $this->mRestrictions
= array();
82 # Dont change the following, NS_MAIN is hardcoded in several place
84 $this->mDefaultNamespace
= NS_MAIN
;
85 $this->mWatched
= NULL;
86 $this->mLatestID
= false;
87 $this->mOldRestrictions
= false;
89 $this->mRedirect
= NULL;
93 * Create a new Title from a prefixed DB key
94 * @param string $key The database key, which has underscores
95 * instead of spaces, possibly including namespace and
97 * @return Title the new object, or NULL on an error
99 public static function newFromDBkey( $key ) {
101 $t->mDbkeyform
= $key;
102 if( $t->secureAndSplit() )
109 * Create a new Title from text, such as what one would
110 * find in a link. Decodes any HTML entities in the text.
112 * @param string $text the link text; spaces, prefixes,
113 * and an initial ':' indicating the main namespace
115 * @param int $defaultNamespace the namespace to use if
116 * none is specified by a prefix
117 * @return Title the new object, or NULL on an error
119 public static function newFromText( $text, $defaultNamespace = NS_MAIN
) {
120 if( is_object( $text ) ) {
121 throw new MWException( 'Title::newFromText given an object' );
125 * Wiki pages often contain multiple links to the same page.
126 * Title normalization and parsing can become expensive on
127 * pages with many links, so we can save a little time by
130 * In theory these are value objects and won't get changed...
132 if( $defaultNamespace == NS_MAIN
&& isset( Title
::$titleCache[$text] ) ) {
133 return Title
::$titleCache[$text];
137 * Convert things like é ā or 〗 into real text...
139 $filteredText = Sanitizer
::decodeCharReferences( $text );
142 $t->mDbkeyform
= str_replace( ' ', '_', $filteredText );
143 $t->mDefaultNamespace
= $defaultNamespace;
145 static $cachedcount = 0 ;
146 if( $t->secureAndSplit() ) {
147 if( $defaultNamespace == NS_MAIN
) {
148 if( $cachedcount >= MW_TITLECACHE_MAX
) {
149 # Avoid memory leaks on mass operations...
150 Title
::$titleCache = array();
154 Title
::$titleCache[$text] =& $t;
164 * Create a new Title from URL-encoded text. Ensures that
165 * the given title's length does not exceed the maximum.
166 * @param string $url the title, as might be taken from a URL
167 * @return Title the new object, or NULL on an error
169 public static function newFromURL( $url ) {
170 global $wgLegalTitleChars;
173 # For compatibility with old buggy URLs. "+" is usually not valid in titles,
174 # but some URLs used it as a space replacement and they still come
175 # from some external search tools.
176 if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
177 $url = str_replace( '+', ' ', $url );
180 $t->mDbkeyform
= str_replace( ' ', '_', $url );
181 if( $t->secureAndSplit() ) {
189 * Create a new Title from an article ID
191 * @todo This is inefficiently implemented, the page row is requested
192 * but not used for anything else
194 * @param int $id the page_id corresponding to the Title to create
195 * @param int $flags, use GAID_FOR_UPDATE to use master
196 * @return Title the new object, or NULL on an error
198 public static function newFromID( $id, $flags = 0 ) {
199 $fname = 'Title::newFromID';
200 $db = ($flags & GAID_FOR_UPDATE
) ?
wfGetDB( DB_MASTER
) : wfGetDB( DB_SLAVE
);
201 $row = $db->selectRow( 'page', array( 'page_namespace', 'page_title' ),
202 array( 'page_id' => $id ), $fname );
203 if ( $row !== false ) {
204 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
212 * Make an array of titles from an array of IDs
214 public static function newFromIDs( $ids ) {
215 if ( !count( $ids ) ) {
218 $dbr = wfGetDB( DB_SLAVE
);
219 $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ),
220 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__
);
223 while ( $row = $dbr->fetchObject( $res ) ) {
224 $titles[] = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
230 * Make a Title object from a DB row
231 * @param Row $row (needs at least page_title,page_namespace)
233 public static function newFromRow( $row ) {
234 $t = self
::makeTitle( $row->page_namespace
, $row->page_title
);
236 $t->mArticleID
= isset($row->page_id
) ?
intval($row->page_id
) : -1;
237 $t->mLength
= isset($row->page_len
) ?
intval($row->page_len
) : -1;
238 $t->mRedirect
= isset($row->page_is_redirect
) ?
(bool)$row->page_is_redirect
: NULL;
239 $t->mLatestID
= isset($row->page_latest
) ?
$row->page_latest
: false;
245 * Create a new Title from a namespace index and a DB key.
246 * It's assumed that $ns and $title are *valid*, for instance when
247 * they came directly from the database or a special page name.
248 * For convenience, spaces are converted to underscores so that
249 * eg user_text fields can be used directly.
251 * @param int $ns the namespace of the article
252 * @param string $title the unprefixed database key form
253 * @return Title the new object
255 public static function &makeTitle( $ns, $title ) {
259 $t->mNamespace
= $ns = intval( $ns );
260 $t->mDbkeyform
= str_replace( ' ', '_', $title );
261 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
262 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
263 $t->mTextform
= str_replace( '_', ' ', $title );
268 * Create a new Title from a namespace index and a DB key.
269 * The parameters will be checked for validity, which is a bit slower
270 * than makeTitle() but safer for user-provided data.
272 * @param int $ns the namespace of the article
273 * @param string $title the database key form
274 * @return Title the new object, or NULL on an error
276 public static function makeTitleSafe( $ns, $title ) {
278 $t->mDbkeyform
= Title
::makeName( $ns, $title );
279 if( $t->secureAndSplit() ) {
287 * Create a new Title for the Main Page
288 * @return Title the new object
290 public static function newMainPage() {
291 $title = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
292 // Don't give fatal errors if the message is broken
294 $title = Title
::newFromText( 'Main Page' );
300 * Extract a redirect destination from a string and return the
301 * Title, or null if the text doesn't contain a valid redirect
303 * @param string $text Text with possible redirect
306 public static function newFromRedirect( $text ) {
307 $redir = MagicWord
::get( 'redirect' );
308 if( $redir->matchStart( trim($text) ) ) {
309 // Extract the first link and see if it's usable
311 if( preg_match( '!\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) {
312 // Strip preceding colon used to "escape" categories, etc.
313 // and URL-decode links
314 if( strpos( $m[1], '%' ) !== false ) {
315 // Match behavior of inline link parsing here;
316 // don't interpret + as " " most of the time!
317 // It might be safe to just use rawurldecode instead, though.
318 $m[1] = urldecode( ltrim( $m[1], ':' ) );
320 $title = Title
::newFromText( $m[1] );
321 // Redirects to Special:Userlogout are not permitted
322 if( $title instanceof Title
&& !$title->isSpecial( 'Userlogout' ) )
329 #----------------------------------------------------------------------------
331 #----------------------------------------------------------------------------
334 * Get the prefixed DB key associated with an ID
335 * @param int $id the page_id of the article
336 * @return Title an object representing the article, or NULL
337 * if no such article was found
341 function nameOf( $id ) {
342 $fname = 'Title::nameOf';
343 $dbr = wfGetDB( DB_SLAVE
);
345 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
346 if ( $s === false ) { return NULL; }
348 $n = Title
::makeName( $s->page_namespace
, $s->page_title
);
353 * Get a regex character class describing the legal characters in a link
354 * @return string the list of characters, not delimited
356 public static function legalChars() {
357 global $wgLegalTitleChars;
358 return $wgLegalTitleChars;
362 * Get a string representation of a title suitable for
363 * including in a search index
365 * @param int $ns a namespace index
366 * @param string $title text-form main part
367 * @return string a stripped-down title string ready for the
370 public static function indexTitle( $ns, $title ) {
373 $lc = SearchEngine
::legalSearchChars() . '&#;';
374 $t = $wgContLang->stripForSearch( $title );
375 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
376 $t = $wgContLang->lc( $t );
379 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
380 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
382 $t = preg_replace( "/\\s+/", ' ', $t );
384 if ( $ns == NS_IMAGE
) {
385 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
391 * Make a prefixed DB key from a DB key and a namespace index
392 * @param int $ns numerical representation of the namespace
393 * @param string $title the DB key form the title
394 * @return string the prefixed form of the title
396 public static function makeName( $ns, $title ) {
399 $n = $wgContLang->getNsText( $ns );
400 return $n == '' ?
$title : "$n:$title";
404 * Returns the URL associated with an interwiki prefix
405 * @param string $key the interwiki prefix (e.g. "MeatBall")
406 * @return the associated URL, containing "$1", which should be
407 * replaced by an article title
410 public function getInterwikiLink( $key ) {
411 global $wgMemc, $wgInterwikiExpiry;
412 global $wgInterwikiCache, $wgContLang;
413 $fname = 'Title::getInterwikiLink';
415 $key = $wgContLang->lc( $key );
417 $k = wfMemcKey( 'interwiki', $key );
418 if( array_key_exists( $k, Title
::$interwikiCache ) ) {
419 return Title
::$interwikiCache[$k]->iw_url
;
422 if ($wgInterwikiCache) {
423 return Title
::getInterwikiCached( $key );
426 $s = $wgMemc->get( $k );
427 # Ignore old keys with no iw_local
428 if( $s && isset( $s->iw_local
) && isset($s->iw_trans
)) {
429 Title
::$interwikiCache[$k] = $s;
433 $dbr = wfGetDB( DB_SLAVE
);
434 $res = $dbr->select( 'interwiki',
435 array( 'iw_url', 'iw_local', 'iw_trans' ),
436 array( 'iw_prefix' => $key ), $fname );
441 $s = $dbr->fetchObject( $res );
443 # Cache non-existence: create a blank object and save it to memcached
449 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
450 Title
::$interwikiCache[$k] = $s;
456 * Fetch interwiki prefix data from local cache in constant database
458 * More logic is explained in DefaultSettings
460 * @return string URL of interwiki site
462 public static function getInterwikiCached( $key ) {
463 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
467 $db=dba_open($wgInterwikiCache,'r','cdb');
468 /* Resolve site name */
469 if ($wgInterwikiScopes>=3 and !$site) {
470 $site = dba_fetch('__sites:' . wfWikiID(), $db);
472 $site = $wgInterwikiFallbackSite;
474 $value = dba_fetch( wfMemcKey( $key ), $db);
475 if ($value=='' and $wgInterwikiScopes>=3) {
477 $value = dba_fetch("_{$site}:{$key}", $db);
479 if ($value=='' and $wgInterwikiScopes>=2) {
481 $value = dba_fetch("__global:{$key}", $db);
490 list($local,$url)=explode(' ',$value,2);
492 $s->iw_local
=(int)$local;
494 Title
::$interwikiCache[wfMemcKey( 'interwiki', $key )] = $s;
498 * Determine whether the object refers to a page within
501 * @return bool TRUE if this is an in-project interwiki link
502 * or a wikilink, FALSE otherwise
504 public function isLocal() {
505 if ( $this->mInterwiki
!= '' ) {
506 # Make sure key is loaded into cache
507 $this->getInterwikiLink( $this->mInterwiki
);
508 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
509 return (bool)(Title
::$interwikiCache[$k]->iw_local
);
516 * Determine whether the object refers to a page within
517 * this project and is transcludable.
519 * @return bool TRUE if this is transcludable
521 public function isTrans() {
522 if ($this->mInterwiki
== '')
524 # Make sure key is loaded into cache
525 $this->getInterwikiLink( $this->mInterwiki
);
526 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
527 return (bool)(Title
::$interwikiCache[$k]->iw_trans
);
531 * Escape a text fragment, say from a link, for a URL
533 static function escapeFragmentForURL( $fragment ) {
534 $fragment = str_replace( ' ', '_', $fragment );
535 $fragment = urlencode( Sanitizer
::decodeCharReferences( $fragment ) );
536 $replaceArray = array(
540 return strtr( $fragment, $replaceArray );
543 #----------------------------------------------------------------------------
545 #----------------------------------------------------------------------------
547 /** Simple accessors */
549 * Get the text form (spaces not underscores) of the main part
552 public function getText() { return $this->mTextform
; }
554 * Get the URL-encoded form of the main part
557 public function getPartialURL() { return $this->mUrlform
; }
559 * Get the main part with underscores
562 public function getDBkey() { return $this->mDbkeyform
; }
564 * Get the namespace index, i.e. one of the NS_xxxx constants
567 public function getNamespace() { return $this->mNamespace
; }
569 * Get the namespace text
572 public function getNsText() {
573 global $wgContLang, $wgCanonicalNamespaceNames;
575 if ( '' != $this->mInterwiki
) {
576 // This probably shouldn't even happen. ohh man, oh yuck.
577 // But for interwiki transclusion it sometimes does.
578 // Shit. Shit shit shit.
580 // Use the canonical namespaces if possible to try to
581 // resolve a foreign namespace.
582 if( isset( $wgCanonicalNamespaceNames[$this->mNamespace
] ) ) {
583 return $wgCanonicalNamespaceNames[$this->mNamespace
];
586 return $wgContLang->getNsText( $this->mNamespace
);
589 * Get the DB key with the initial letter case as specified by the user
591 function getUserCaseDBKey() {
592 return $this->mUserCaseDBKey
;
595 * Get the namespace text of the subject (rather than talk) page
598 public function getSubjectNsText() {
600 return $wgContLang->getNsText( MWNamespace
::getSubject( $this->mNamespace
) );
604 * Get the namespace text of the talk page
607 public function getTalkNsText() {
609 return( $wgContLang->getNsText( MWNamespace
::getTalk( $this->mNamespace
) ) );
613 * Could this title have a corresponding talk page?
616 public function canTalk() {
617 return( MWNamespace
::canTalk( $this->mNamespace
) );
621 * Get the interwiki prefix (or null string)
624 public function getInterwiki() { return $this->mInterwiki
; }
626 * Get the Title fragment (i.e. the bit after the #) in text form
629 public function getFragment() { return $this->mFragment
; }
631 * Get the fragment in URL form, including the "#" character if there is one
634 public function getFragmentForURL() {
635 if ( $this->mFragment
== '' ) {
638 return '#' . Title
::escapeFragmentForURL( $this->mFragment
);
642 * Get the default namespace index, for when there is no namespace
645 public function getDefaultNamespace() { return $this->mDefaultNamespace
; }
648 * Get title for search index
649 * @return string a stripped-down title string ready for the
652 public function getIndexTitle() {
653 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
657 * Get the prefixed database key form
658 * @return string the prefixed title, with underscores and
659 * any interwiki and namespace prefixes
661 public function getPrefixedDBkey() {
662 $s = $this->prefix( $this->mDbkeyform
);
663 $s = str_replace( ' ', '_', $s );
668 * Get the prefixed title with spaces.
669 * This is the form usually used for display
670 * @return string the prefixed title, with spaces
672 public function getPrefixedText() {
673 if ( empty( $this->mPrefixedText
) ) { // FIXME: bad usage of empty() ?
674 $s = $this->prefix( $this->mTextform
);
675 $s = str_replace( '_', ' ', $s );
676 $this->mPrefixedText
= $s;
678 return $this->mPrefixedText
;
682 * Get the prefixed title with spaces, plus any fragment
683 * (part beginning with '#')
684 * @return string the prefixed title, with spaces and
685 * the fragment, including '#'
687 public function getFullText() {
688 $text = $this->getPrefixedText();
689 if( '' != $this->mFragment
) {
690 $text .= '#' . $this->mFragment
;
696 * Get the base name, i.e. the leftmost parts before the /
697 * @return string Base name
699 public function getBaseText() {
700 global $wgNamespacesWithSubpages;
701 if( !empty( $wgNamespacesWithSubpages[$this->mNamespace
] ) ) {
702 $parts = explode( '/', $this->getText() );
703 # Don't discard the real title if there's no subpage involved
704 if( count( $parts ) > 1 )
705 unset( $parts[ count( $parts ) - 1 ] );
706 return implode( '/', $parts );
708 return $this->getText();
713 * Get the lowest-level subpage name, i.e. the rightmost part after /
714 * @return string Subpage name
716 public function getSubpageText() {
717 global $wgNamespacesWithSubpages;
718 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
719 $parts = explode( '/', $this->mTextform
);
720 return( $parts[ count( $parts ) - 1 ] );
722 return( $this->mTextform
);
727 * Get a URL-encoded form of the subpage text
728 * @return string URL-encoded subpage name
730 public function getSubpageUrlForm() {
731 $text = $this->getSubpageText();
732 $text = wfUrlencode( str_replace( ' ', '_', $text ) );
733 $text = str_replace( '%28', '(', str_replace( '%29', ')', $text ) ); # Clean up the URL; per below, this might not be safe
738 * Get a URL-encoded title (not an actual URL) including interwiki
739 * @return string the URL-encoded form
741 public function getPrefixedURL() {
742 $s = $this->prefix( $this->mDbkeyform
);
743 $s = str_replace( ' ', '_', $s );
745 $s = wfUrlencode ( $s ) ;
747 # Cleaning up URL to make it look nice -- is this safe?
748 $s = str_replace( '%28', '(', $s );
749 $s = str_replace( '%29', ')', $s );
755 * Get a real URL referring to this title, with interwiki link and
758 * @param string $query an optional query string, not used
759 * for interwiki links
760 * @param string $variant language variant of url (for sr, zh..)
761 * @return string the URL
763 public function getFullURL( $query = '', $variant = false ) {
764 global $wgContLang, $wgServer, $wgRequest;
766 if ( '' == $this->mInterwiki
) {
767 $url = $this->getLocalUrl( $query, $variant );
769 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
770 // Correct fix would be to move the prepending elsewhere.
771 if ($wgRequest->getVal('action') != 'render') {
772 $url = $wgServer . $url;
775 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
777 $namespace = wfUrlencode( $this->getNsText() );
778 if ( '' != $namespace ) {
779 # Can this actually happen? Interwikis shouldn't be parsed.
780 # Yes! It can in interwiki transclusion. But... it probably shouldn't.
783 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
784 $url = wfAppendQuery( $url, $query );
787 # Finally, add the fragment.
788 $url .= $this->getFragmentForURL();
790 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
795 * Get a URL with no fragment or server name. If this page is generated
796 * with action=render, $wgServer is prepended.
797 * @param string $query an optional query string; if not specified,
798 * $wgArticlePath will be used.
799 * @param string $variant language variant of url (for sr, zh..)
800 * @return string the URL
802 public function getLocalURL( $query = '', $variant = false ) {
803 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
804 global $wgVariantArticlePath, $wgContLang, $wgUser;
806 // internal links should point to same variant as current page (only anonymous users)
807 if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
808 $pref = $wgContLang->getPreferredVariant(false);
809 if($pref != $wgContLang->getCode())
813 if ( $this->isExternal() ) {
814 $url = $this->getFullURL();
816 // This is currently only used for edit section links in the
817 // context of interwiki transclusion. In theory we should
818 // append the query to the end of any existing query string,
819 // but interwiki transclusion is already broken in that case.
823 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
824 if ( $query == '' ) {
825 if( $variant != false && $wgContLang->hasVariants() ) {
826 if( $wgVariantArticlePath == false ) {
827 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
829 $variantArticlePath = $wgVariantArticlePath;
831 $url = str_replace( '$2', urlencode( $variant ), $variantArticlePath );
832 $url = str_replace( '$1', $dbkey, $url );
834 $url = str_replace( '$1', $dbkey, $wgArticlePath );
837 global $wgActionPaths;
840 if( !empty( $wgActionPaths ) &&
841 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
843 $action = urldecode( $matches[2] );
844 if( isset( $wgActionPaths[$action] ) ) {
845 $query = $matches[1];
846 if( isset( $matches[4] ) ) $query .= $matches[4];
847 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
848 if( $query != '' ) $url .= '?' . $query;
851 if ( $url === false ) {
852 if ( $query == '-' ) {
855 $url = "{$wgScript}?title={$dbkey}&{$query}";
859 // FIXME: this causes breakage in various places when we
860 // actually expected a local URL and end up with dupe prefixes.
861 if ($wgRequest->getVal('action') == 'render') {
862 $url = $wgServer . $url;
865 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
870 * Get an HTML-escaped version of the URL form, suitable for
871 * using in a link, without a server name or fragment
872 * @param string $query an optional query string
873 * @return string the URL
875 public function escapeLocalURL( $query = '' ) {
876 return htmlspecialchars( $this->getLocalURL( $query ) );
880 * Get an HTML-escaped version of the URL form, suitable for
881 * using in a link, including the server name and fragment
883 * @return string the URL
884 * @param string $query an optional query string
886 public function escapeFullURL( $query = '' ) {
887 return htmlspecialchars( $this->getFullURL( $query ) );
891 * Get the URL form for an internal link.
892 * - Used in various Squid-related code, in case we have a different
893 * internal hostname for the server from the exposed one.
895 * @param string $query an optional query string
896 * @param string $variant language variant of url (for sr, zh..)
897 * @return string the URL
899 public function getInternalURL( $query = '', $variant = false ) {
900 global $wgInternalServer;
901 $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
902 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
907 * Get the edit URL for this Title
908 * @return string the URL, or a null string if this is an
911 public function getEditURL() {
912 if ( '' != $this->mInterwiki
) { return ''; }
913 $s = $this->getLocalURL( 'action=edit' );
919 * Get the HTML-escaped displayable text form.
920 * Used for the title field in <a> tags.
921 * @return string the text, including any prefixes
923 public function getEscapedText() {
924 return htmlspecialchars( $this->getPrefixedText() );
928 * Is this Title interwiki?
931 public function isExternal() { return ( '' != $this->mInterwiki
); }
934 * Is this page "semi-protected" - the *only* protection is autoconfirm?
936 * @param string Action to check (default: edit)
939 public function isSemiProtected( $action = 'edit' ) {
940 if( $this->exists() ) {
941 $restrictions = $this->getRestrictions( $action );
942 if( count( $restrictions ) > 0 ) {
943 foreach( $restrictions as $restriction ) {
944 if( strtolower( $restriction ) != 'autoconfirmed' )
953 # If it doesn't exist, it can't be protected
959 * Does the title correspond to a protected article?
960 * @param string $what the action the page is protected from,
961 * by default checks move and edit
964 public function isProtected( $action = '' ) {
965 global $wgRestrictionLevels, $wgRestrictionTypes;
967 # Special pages have inherent protection
968 if( $this->getNamespace() == NS_SPECIAL
)
971 # Check regular protection levels
972 foreach( $wgRestrictionTypes as $type ){
973 if( $action == $type ||
$action == '' ) {
974 $r = $this->getRestrictions( $type );
975 foreach( $wgRestrictionLevels as $level ) {
976 if( in_array( $level, $r ) && $level != '' ) {
987 * Is $wgUser watching this page?
990 public function userIsWatching() {
993 if ( is_null( $this->mWatched
) ) {
994 if ( NS_SPECIAL
== $this->mNamespace ||
!$wgUser->isLoggedIn()) {
995 $this->mWatched
= false;
997 $this->mWatched
= $wgUser->isWatched( $this );
1000 return $this->mWatched
;
1004 * Can $wgUser perform $action on this page?
1005 * This skips potentially expensive cascading permission checks.
1007 * Suitable for use for nonessential UI controls in common cases, but
1008 * _not_ for functional access control.
1010 * May provide false positives, but should never provide a false negative.
1012 * @param string $action action that permission needs to be checked for
1015 public function quickUserCan( $action ) {
1016 return $this->userCan( $action, false );
1020 * Determines if $wgUser is unable to edit this page because it has been protected
1021 * by $wgNamespaceProtection.
1025 public function isNamespaceProtected() {
1026 global $wgNamespaceProtection, $wgUser;
1027 if( isset( $wgNamespaceProtection[ $this->mNamespace
] ) ) {
1028 foreach( (array)$wgNamespaceProtection[ $this->mNamespace
] as $right ) {
1029 if( $right != '' && !$wgUser->isAllowed( $right ) )
1037 * Can $wgUser perform $action on this page?
1038 * @param string $action action that permission needs to be checked for
1039 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
1042 public function userCan( $action, $doExpensiveQueries = true ) {
1044 return ( $this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries ) === array());
1048 * Can $user perform $action on this page?
1050 * FIXME: This *does not* check throttles (User::pingLimiter()).
1052 * @param string $action action that permission needs to be checked for
1053 * @param User $user user to check
1054 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
1055 * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
1057 public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) {
1058 $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
1062 global $wgEmailConfirmToEdit;
1064 if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) {
1065 $errors[] = array( 'confirmedittext' );
1068 if ( $user->isBlockedFrom( $this ) ) {
1069 $block = $user->mBlock
;
1071 // This is from OutputPage::blockedPage
1072 // Copied at r23888 by werdna
1074 $id = $user->blockedBy();
1075 $reason = $user->blockedFor();
1076 if( $reason == '' ) {
1077 $reason = wfMsg( 'blockednoreason' );
1081 if ( is_numeric( $id ) ) {
1082 $name = User
::whoIs( $id );
1087 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
1088 $blockid = $block->mId
;
1089 $blockExpiry = $user->mBlock
->mExpiry
;
1090 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $user->mBlock
->mTimestamp
), true );
1092 if ( $blockExpiry == 'infinity' ) {
1093 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1094 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1096 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1097 if ( strpos( $option, ':' ) == false )
1100 list ($show, $value) = explode( ":", $option );
1102 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
1103 $blockExpiry = $show;
1108 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
1111 $intended = $user->mBlock
->mAddress
;
1113 $errors[] = array( ($block->mAuto ?
'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name,
1114 $blockid, $blockExpiry, $intended, $blockTimestamp );
1121 * Can $user perform $action on this page? This is an internal function,
1122 * which checks ONLY that previously checked by userCan (i.e. it leaves out
1123 * checks on wfReadOnly() and blocks)
1125 * @param string $action action that permission needs to be checked for
1126 * @param User $user user to check
1127 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
1128 * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
1130 private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
1131 wfProfileIn( __METHOD__
);
1135 // Use getUserPermissionsErrors instead
1136 if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) {
1137 wfProfileOut( __METHOD__
);
1138 return $result ?
array() : array( array( 'badaccess-group0' ) );
1141 if (!wfRunHooks( 'getUserPermissionsErrors', array( &$this, &$user, $action, &$result ) ) ) {
1142 if ($result != array() && is_array($result) && !is_array($result[0]))
1143 $errors[] = $result; # A single array representing an error
1144 else if (is_array($result) && is_array($result[0]))
1145 $errors = array_merge( $errors, $result ); # A nested array representing multiple errors
1146 else if ($result != '' && $result != null && $result !== true && $result !== false)
1147 $errors[] = array($result); # A string representing a message-id
1148 else if ($result === false )
1149 $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that"
1151 if ($doExpensiveQueries && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) {
1152 if ($result != array() && is_array($result) && !is_array($result[0]))
1153 $errors[] = $result; # A single array representing an error
1154 else if (is_array($result) && is_array($result[0]))
1155 $errors = array_merge( $errors, $result ); # A nested array representing multiple errors
1156 else if ($result != '' && $result != null && $result !== true && $result !== false)
1157 $errors[] = array($result); # A string representing a message-id
1158 else if ($result === false )
1159 $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that"
1162 $specialOKActions = array( 'createaccount', 'execute' );
1163 if( NS_SPECIAL
== $this->mNamespace
&& !in_array( $action, $specialOKActions) ) {
1164 $errors[] = array('ns-specialprotected');
1167 if ( $this->isNamespaceProtected() ) {
1168 $ns = $this->getNamespace() == NS_MAIN
1169 ?
wfMsg( 'nstab-main' )
1170 : $this->getNsText();
1171 $errors[] = (NS_MEDIAWIKI
== $this->mNamespace
1172 ?
array('protectedinterface')
1173 : array( 'namespaceprotected', $ns ) );
1176 if( $this->mDbkeyform
== '_' ) {
1177 # FIXME: Is this necessary? Shouldn't be allowed anyway...
1178 $errors[] = array('badaccess-group0');
1181 # protect css/js subpages of user pages
1182 # XXX: this might be better using restrictions
1183 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
1184 if( $this->isCssJsSubpage()
1185 && !$user->isAllowed('editusercssjs')
1186 && !preg_match('/^'.preg_quote($user->getName(), '/').'\//', $this->mTextform
) ) {
1187 $errors[] = array('customcssjsprotected');
1190 if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
1191 # We /could/ use the protection level on the source page, but it's fairly ugly
1192 # as we have to establish a precedence hierarchy for pages included by multiple
1193 # cascade-protected pages. So just restrict it to people with 'protect' permission,
1194 # as they could remove the protection anyway.
1195 list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources();
1196 # Cascading protection depends on more than this page...
1197 # Several cascading protected pages may include this page...
1198 # Check each cascading level
1199 # This is only for protection restrictions, not for all actions
1200 if( $cascadingSources > 0 && isset($restrictions[$action]) ) {
1201 foreach( $restrictions[$action] as $right ) {
1202 $right = ( $right == 'sysop' ) ?
'protect' : $right;
1203 if( '' != $right && !$user->isAllowed( $right ) ) {
1205 foreach( $cascadingSources as $page )
1206 $pages .= '* [[:' . $page->getPrefixedText() . "]]\n";
1207 $errors[] = array( 'cascadeprotected', count( $cascadingSources ), $pages );
1213 foreach( $this->getRestrictions($action) as $right ) {
1214 // Backwards compatibility, rewrite sysop -> protect
1215 if ( $right == 'sysop' ) {
1218 if( '' != $right && !$user->isAllowed( $right ) ) {
1219 //Users with 'editprotected' permission can edit protected pages
1220 if( $action=='edit' && $user->isAllowed( 'editprotected' ) ) {
1221 //Users with 'editprotected' permission cannot edit protected pages
1222 //with cascading option turned on.
1223 if($this->mCascadeRestriction
) {
1224 $errors[] = array( 'protectedpagetext', $right );
1226 //Nothing, user can edit!
1229 $errors[] = array( 'protectedpagetext', $right );
1234 if ($action == 'protect') {
1235 if ($this->getUserPermissionsErrors('edit', $user) != array()) {
1236 $errors[] = array( 'protect-cantedit' ); // If they can't edit, they shouldn't protect.
1240 if ($action == 'create') {
1241 $title_protection = $this->getTitleProtection();
1243 if (is_array($title_protection)) {
1244 extract($title_protection);
1246 if ($pt_create_perm == 'sysop')
1247 $pt_create_perm = 'protect';
1249 if ($pt_create_perm == '' ||
!$user->isAllowed($pt_create_perm)) {
1250 $errors[] = array ( 'titleprotected', User
::whoIs($pt_user), $pt_reason );
1254 if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
1255 ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) {
1256 $errors[] = $user->isAnon() ?
array ('nocreatetext') : array ('nocreate-loggedin');
1258 } elseif( $action == 'move' && !( $this->isMovable() && $user->isAllowed( 'move' ) ) ) {
1259 $errors[] = $user->isAnon() ?
array ( 'movenologintext' ) : array ('movenotallowed');
1260 } elseif ( !$user->isAllowed( $action ) ) {
1263 global $wgGroupPermissions;
1264 foreach( $wgGroupPermissions as $key => $value ) {
1265 if( isset( $value[$action] ) && $value[$action] == true ) {
1266 $groupName = User
::getGroupName( $key );
1267 $groupPage = User
::getGroupPage( $key );
1269 $groups[] = '[['.$groupPage->getPrefixedText().'|'.$groupName.']]';
1271 $groups[] = $groupName;
1275 $n = count( $groups );
1276 $groups = implode( ', ', $groups );
1281 $return = array( "badaccess-group$n", $groups );
1284 $return = array( 'badaccess-groups', $groups );
1286 $errors[] = $return;
1289 wfProfileOut( __METHOD__
);
1294 * Is this title subject to title protection?
1295 * @return mixed An associative array representing any existent title
1296 * protection, or false if there's none.
1298 private function getTitleProtection() {
1299 // Can't protect pages in special namespaces
1300 if ( $this->getNamespace() < 0 ) {
1304 $dbr = wfGetDB( DB_SLAVE
);
1305 $res = $dbr->select( 'protected_titles', '*',
1306 array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()) );
1308 if ($row = $dbr->fetchRow( $res )) {
1315 public function updateTitleProtection( $create_perm, $reason, $expiry ) {
1316 global $wgGroupPermissions,$wgUser,$wgContLang;
1318 if ($create_perm == implode(',',$this->getRestrictions('create'))
1319 && $expiry == $this->mRestrictionsExpiry
) {
1324 list ($namespace, $title) = array( $this->getNamespace(), $this->getDBkey() );
1326 $dbw = wfGetDB( DB_MASTER
);
1328 $encodedExpiry = Block
::encodeExpiry($expiry, $dbw );
1330 $expiry_description = '';
1331 if ( $encodedExpiry != 'infinity' ) {
1332 $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
1335 # Update protection table
1336 if ($create_perm != '' ) {
1337 $dbw->replace( 'protected_titles', array(array('pt_namespace', 'pt_title')),
1338 array( 'pt_namespace' => $namespace, 'pt_title' => $title
1339 , 'pt_create_perm' => $create_perm
1340 , 'pt_timestamp' => Block
::encodeExpiry(wfTimestampNow(), $dbw)
1341 , 'pt_expiry' => $encodedExpiry
1342 , 'pt_user' => $wgUser->getId(), 'pt_reason' => $reason ), __METHOD__
);
1344 $dbw->delete( 'protected_titles', array( 'pt_namespace' => $namespace,
1345 'pt_title' => $title ), __METHOD__
);
1347 # Update the protection log
1348 $log = new LogPage( 'protect' );
1350 if( $create_perm ) {
1351 $log->addEntry( $this->mRestrictions
['create'] ?
'modify' : 'protect', $this, trim( $reason . " [create=$create_perm] $expiry_description" ) );
1353 $log->addEntry( 'unprotect', $this, $reason );
1360 * Remove any title protection (due to page existing
1362 public function deleteTitleProtection() {
1363 $dbw = wfGetDB( DB_MASTER
);
1365 $dbw->delete( 'protected_titles',
1366 array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()), __METHOD__
);
1370 * Can $wgUser edit this page?
1372 * @deprecated use userCan('edit')
1374 public function userCanEdit( $doExpensiveQueries = true ) {
1375 return $this->userCan( 'edit', $doExpensiveQueries );
1379 * Can $wgUser create this page?
1381 * @deprecated use userCan('create')
1383 public function userCanCreate( $doExpensiveQueries = true ) {
1384 return $this->userCan( 'create', $doExpensiveQueries );
1388 * Can $wgUser move this page?
1390 * @deprecated use userCan('move')
1392 public function userCanMove( $doExpensiveQueries = true ) {
1393 return $this->userCan( 'move', $doExpensiveQueries );
1397 * Would anybody with sufficient privileges be able to move this page?
1398 * Some pages just aren't movable.
1402 public function isMovable() {
1403 return MWNamespace
::isMovable( $this->getNamespace() )
1404 && $this->getInterwiki() == '';
1408 * Can $wgUser read this page?
1410 * @todo fold these checks into userCan()
1412 public function userCanRead() {
1413 global $wgUser, $wgGroupPermissions;
1416 wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
1417 if ( $result !== null ) {
1421 # Shortcut for public wikis, allows skipping quite a bit of code
1422 if ($wgGroupPermissions['*']['read'])
1425 if( $wgUser->isAllowed( 'read' ) ) {
1428 global $wgWhitelistRead;
1431 * Always grant access to the login page.
1432 * Even anons need to be able to log in.
1434 if( $this->isSpecial( 'Userlogin' ) ||
$this->isSpecial( 'Resetpass' ) ) {
1439 * Bail out if there isn't whitelist
1441 if( !is_array($wgWhitelistRead) ) {
1446 * Check for explicit whitelisting
1448 $name = $this->getPrefixedText();
1449 $dbName = $this->getPrefixedDBKey();
1450 // Check with and without underscores
1451 if( in_array($name,$wgWhitelistRead,true) ||
in_array($dbName,$wgWhitelistRead,true) )
1455 * Old settings might have the title prefixed with
1456 * a colon for main-namespace pages
1458 if( $this->getNamespace() == NS_MAIN
) {
1459 if( in_array( ':' . $name, $wgWhitelistRead ) )
1464 * If it's a special page, ditch the subpage bit
1467 if( $this->getNamespace() == NS_SPECIAL
) {
1468 $name = $this->getDBkey();
1469 list( $name, /* $subpage */) = SpecialPage
::resolveAliasWithSubpage( $name );
1470 if ( $name === false ) {
1471 # Invalid special page, but we show standard login required message
1475 $pure = SpecialPage
::getTitleFor( $name )->getPrefixedText();
1476 if( in_array( $pure, $wgWhitelistRead, true ) )
1485 * Is this a talk page of some sort?
1488 public function isTalkPage() {
1489 return MWNamespace
::isTalk( $this->getNamespace() );
1493 * Is this a subpage?
1496 public function isSubpage() {
1497 global $wgNamespacesWithSubpages;
1499 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) ) {
1500 return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace
] == true );
1507 * Does this have subpages? (Warning, usually requires an extra DB query.)
1510 public function hasSubpages() {
1511 global $wgNamespacesWithSubpages;
1513 if( !isset( $wgNamespacesWithSubpages[$this->mNamespace
] ) ) {
1518 # We dynamically add a member variable for the purpose of this method
1519 # alone to cache the result. There's no point in having it hanging
1520 # around uninitialized in every Title object; therefore we only add it
1521 # if needed and don't declare it statically.
1522 if( isset( $this->mHasSubpages
) ) {
1523 return $this->mHasSubpages
;
1526 $db = wfGetDB( DB_SLAVE
);
1527 return $this->mHasSubpages
= (bool)$db->selectField( 'page', '1',
1528 "page_namespace = {$this->mNamespace} AND page_title LIKE '"
1529 . $db->escapeLike( $this->mDbkeyform
) . "/%'",
1535 * Could this page contain custom CSS or JavaScript, based
1540 public function isCssOrJsPage() {
1541 return $this->mNamespace
== NS_MEDIAWIKI
1542 && preg_match( '!\.(?:css|js)$!u', $this->mTextform
) > 0;
1546 * Is this a .css or .js subpage of a user page?
1549 public function isCssJsSubpage() {
1550 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.(?:css|js)$/", $this->mTextform
) );
1553 * Is this a *valid* .css or .js subpage of a user page?
1554 * Check that the corresponding skin exists
1556 public function isValidCssJsSubpage() {
1557 if ( $this->isCssJsSubpage() ) {
1558 $skinNames = Skin
::getSkinNames();
1559 return array_key_exists( $this->getSkinFromCssJsSubpage(), $skinNames );
1565 * Trim down a .css or .js subpage title to get the corresponding skin name
1567 public function getSkinFromCssJsSubpage() {
1568 $subpage = explode( '/', $this->mTextform
);
1569 $subpage = $subpage[ count( $subpage ) - 1 ];
1570 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1573 * Is this a .css subpage of a user page?
1576 public function isCssSubpage() {
1577 return ( NS_USER
== $this->mNamespace
&& preg_match("/\\/.*\\.css$/", $this->mTextform
) );
1580 * Is this a .js subpage of a user page?
1583 public function isJsSubpage() {
1584 return ( NS_USER
== $this->mNamespace
&& preg_match("/\\/.*\\.js$/", $this->mTextform
) );
1587 * Protect css/js subpages of user pages: can $wgUser edit
1591 * @todo XXX: this might be better using restrictions
1593 public function userCanEditCssJsSubpage() {
1595 return ( $wgUser->isAllowed('editusercssjs') ||
preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
1599 * Cascading protection: Return true if cascading restrictions apply to this page, false if not.
1601 * @return bool If the page is subject to cascading restrictions.
1603 public function isCascadeProtected() {
1604 list( $sources, /* $restrictions */ ) = $this->getCascadeProtectionSources( false );
1605 return ( $sources > 0 );
1609 * Cascading protection: Get the source of any cascading restrictions on this page.
1611 * @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
1612 * @return array( mixed title array, restriction array)
1613 * Array of the Title objects of the pages from which cascading restrictions have come, false for none, or true if such restrictions exist, but $get_pages was not set.
1614 * The restriction array is an array of each type, each of which contains an array of unique groups
1616 public function getCascadeProtectionSources( $get_pages = true ) {
1617 global $wgEnableCascadingProtection, $wgRestrictionTypes;
1619 # Define our dimension of restrictions types
1620 $pagerestrictions = array();
1621 foreach( $wgRestrictionTypes as $action )
1622 $pagerestrictions[$action] = array();
1624 if (!$wgEnableCascadingProtection)
1625 return array( false, $pagerestrictions );
1627 if ( isset( $this->mCascadeSources
) && $get_pages ) {
1628 return array( $this->mCascadeSources
, $this->mCascadingRestrictions
);
1629 } else if ( isset( $this->mHasCascadingRestrictions
) && !$get_pages ) {
1630 return array( $this->mHasCascadingRestrictions
, $pagerestrictions );
1633 wfProfileIn( __METHOD__
);
1635 $dbr = wfGetDb( DB_SLAVE
);
1637 if ( $this->getNamespace() == NS_IMAGE
) {
1638 $tables = array ('imagelinks', 'page_restrictions');
1639 $where_clauses = array(
1640 'il_to' => $this->getDBkey(),
1642 'pr_cascade' => 1 );
1644 $tables = array ('templatelinks', 'page_restrictions');
1645 $where_clauses = array(
1646 'tl_namespace' => $this->getNamespace(),
1647 'tl_title' => $this->getDBkey(),
1649 'pr_cascade' => 1 );
1653 $cols = array('pr_page', 'page_namespace', 'page_title', 'pr_expiry', 'pr_type', 'pr_level' );
1654 $where_clauses[] = 'page_id=pr_page';
1657 $cols = array( 'pr_expiry' );
1660 $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__
);
1662 $sources = $get_pages ?
array() : false;
1663 $now = wfTimestampNow();
1664 $purgeExpired = false;
1666 while( $row = $dbr->fetchObject( $res ) ) {
1667 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1668 if( $expiry > $now ) {
1670 $page_id = $row->pr_page
;
1671 $page_ns = $row->page_namespace
;
1672 $page_title = $row->page_title
;
1673 $sources[$page_id] = Title
::makeTitle($page_ns, $page_title);
1674 # Add groups needed for each restriction type if its not already there
1675 # Make sure this restriction type still exists
1676 if ( isset($pagerestrictions[$row->pr_type
]) && !in_array($row->pr_level
, $pagerestrictions[$row->pr_type
]) ) {
1677 $pagerestrictions[$row->pr_type
][]=$row->pr_level
;
1683 // Trigger lazy purge of expired restrictions from the db
1684 $purgeExpired = true;
1687 if( $purgeExpired ) {
1688 Title
::purgeExpiredRestrictions();
1691 wfProfileOut( __METHOD__
);
1694 $this->mCascadeSources
= $sources;
1695 $this->mCascadingRestrictions
= $pagerestrictions;
1697 $this->mHasCascadingRestrictions
= $sources;
1700 return array( $sources, $pagerestrictions );
1703 function areRestrictionsCascading() {
1704 if (!$this->mRestrictionsLoaded
) {
1705 $this->loadRestrictions();
1708 return $this->mCascadeRestriction
;
1712 * Loads a string into mRestrictions array
1713 * @param resource $res restrictions as an SQL result.
1715 private function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
1716 global $wgRestrictionTypes;
1717 $dbr = wfGetDB( DB_SLAVE
);
1719 foreach( $wgRestrictionTypes as $type ){
1720 $this->mRestrictions
[$type] = array();
1723 $this->mCascadeRestriction
= false;
1724 $this->mRestrictionsExpiry
= Block
::decodeExpiry('');
1726 # Backwards-compatibility: also load the restrictions from the page record (old format).
1728 if ( $oldFashionedRestrictions === NULL ) {
1729 $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__
);
1732 if ($oldFashionedRestrictions != '') {
1734 foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
1735 $temp = explode( '=', trim( $restrict ) );
1736 if(count($temp) == 1) {
1737 // old old format should be treated as edit/move restriction
1738 $this->mRestrictions
['edit'] = explode( ',', trim( $temp[0] ) );
1739 $this->mRestrictions
['move'] = explode( ',', trim( $temp[0] ) );
1741 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
1745 $this->mOldRestrictions
= true;
1749 if( $dbr->numRows( $res ) ) {
1750 # Current system - load second to make them override.
1751 $now = wfTimestampNow();
1752 $purgeExpired = false;
1754 while ($row = $dbr->fetchObject( $res ) ) {
1755 # Cycle through all the restrictions.
1757 // Don't take care of restrictions types that aren't in $wgRestrictionTypes
1758 if( !in_array( $row->pr_type
, $wgRestrictionTypes ) )
1761 // This code should be refactored, now that it's being used more generally,
1762 // But I don't really see any harm in leaving it in Block for now -werdna
1763 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1765 // Only apply the restrictions if they haven't expired!
1766 if ( !$expiry ||
$expiry > $now ) {
1767 $this->mRestrictionsExpiry
= $expiry;
1768 $this->mRestrictions
[$row->pr_type
] = explode( ',', trim( $row->pr_level
) );
1770 $this->mCascadeRestriction |
= $row->pr_cascade
;
1772 // Trigger a lazy purge of expired restrictions
1773 $purgeExpired = true;
1777 if( $purgeExpired ) {
1778 Title
::purgeExpiredRestrictions();
1782 $this->mRestrictionsLoaded
= true;
1785 public function loadRestrictions( $oldFashionedRestrictions = NULL ) {
1786 if( !$this->mRestrictionsLoaded
) {
1787 if ($this->exists()) {
1788 $dbr = wfGetDB( DB_SLAVE
);
1790 $res = $dbr->select( 'page_restrictions', '*',
1791 array ( 'pr_page' => $this->getArticleId() ), __METHOD__
);
1793 $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions );
1795 $title_protection = $this->getTitleProtection();
1797 if (is_array($title_protection)) {
1798 extract($title_protection);
1800 $now = wfTimestampNow();
1801 $expiry = Block
::decodeExpiry($pt_expiry);
1803 if (!$expiry ||
$expiry > $now) {
1804 // Apply the restrictions
1805 $this->mRestrictionsExpiry
= $expiry;
1806 $this->mRestrictions
['create'] = explode(',', trim($pt_create_perm) );
1807 } else { // Get rid of the old restrictions
1808 Title
::purgeExpiredRestrictions();
1811 $this->mRestrictionsLoaded
= true;
1817 * Purge expired restrictions from the page_restrictions table
1819 static function purgeExpiredRestrictions() {
1820 $dbw = wfGetDB( DB_MASTER
);
1821 $dbw->delete( 'page_restrictions',
1822 array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
1825 $dbw->delete( 'protected_titles',
1826 array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
1831 * Accessor/initialisation for mRestrictions
1833 * @param string $action action that permission needs to be checked for
1834 * @return array the array of groups allowed to edit this article
1836 public function getRestrictions( $action ) {
1837 if( !$this->mRestrictionsLoaded
) {
1838 $this->loadRestrictions();
1840 return isset( $this->mRestrictions
[$action] )
1841 ?
$this->mRestrictions
[$action]
1846 * Is there a version of this page in the deletion archive?
1847 * @return int the number of archived revisions
1849 public function isDeleted() {
1850 $fname = 'Title::isDeleted';
1851 if ( $this->getNamespace() < 0 ) {
1854 $dbr = wfGetDB( DB_SLAVE
);
1855 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1856 'ar_title' => $this->getDBkey() ), $fname );
1857 if( $this->getNamespace() == NS_IMAGE
) {
1858 $n +
= $dbr->selectField( 'filearchive', 'COUNT(*)',
1859 array( 'fa_name' => $this->getDBkey() ), $fname );
1866 * Get the article ID for this Title from the link cache,
1867 * adding it if necessary
1868 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1870 * @return int the ID
1872 public function getArticleID( $flags = 0 ) {
1873 $linkCache = LinkCache
::singleton();
1874 if ( $flags & GAID_FOR_UPDATE
) {
1875 $oldUpdate = $linkCache->forUpdate( true );
1876 $this->mArticleID
= $linkCache->addLinkObj( $this );
1877 $linkCache->forUpdate( $oldUpdate );
1879 if ( -1 == $this->mArticleID
) {
1880 $this->mArticleID
= $linkCache->addLinkObj( $this );
1883 return $this->mArticleID
;
1887 * Is this an article that is a redirect page?
1888 * Uses link cache, adding it if necessary
1889 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
1892 public function isRedirect( $flags = 0 ) {
1893 if( !is_null($this->mRedirect
) )
1894 return $this->mRedirect
;
1895 # Zero for special pages.
1896 # Also, calling getArticleID() loads the field from cache!
1897 if( !$this->getArticleID($flags) ||
$this->getNamespace() == NS_SPECIAL
) {
1900 $linkCache = LinkCache
::singleton();
1901 $this->mRedirect
= (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
1903 return $this->mRedirect
;
1907 * What is the length of this page?
1908 * Uses link cache, adding it if necessary
1909 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
1912 public function getLength( $flags = 0 ) {
1913 if( $this->mLength
!= -1 )
1914 return $this->mLength
;
1915 # Zero for special pages.
1916 # Also, calling getArticleID() loads the field from cache!
1917 if( !$this->getArticleID($flags) ||
$this->getNamespace() == NS_SPECIAL
) {
1920 $linkCache = LinkCache
::singleton();
1921 $this->mLength
= intval( $linkCache->getGoodLinkFieldObj( $this, 'length' ) );
1923 return $this->mLength
;
1927 * What is the page_latest field for this page?
1928 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
1931 public function getLatestRevID( $flags = 0 ) {
1932 if ($this->mLatestID
!== false)
1933 return $this->mLatestID
;
1935 $db = ($flags & GAID_FOR_UPDATE
) ?
wfGetDB(DB_MASTER
) : wfGetDB(DB_SLAVE
);
1936 return $this->mLatestID
= $db->selectField( 'revision',
1938 array('rev_page' => $this->getArticleID($flags)),
1939 'Title::getLatestRevID' );
1943 * This clears some fields in this object, and clears any associated
1944 * keys in the "bad links" section of the link cache.
1946 * - This is called from Article::insertNewArticle() to allow
1947 * loading of the new page_id. It's also called from
1948 * Article::doDeleteArticle()
1950 * @param int $newid the new Article ID
1952 public function resetArticleID( $newid ) {
1953 $linkCache = LinkCache
::singleton();
1954 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1956 if ( 0 == $newid ) { $this->mArticleID
= -1; }
1957 else { $this->mArticleID
= $newid; }
1958 $this->mRestrictionsLoaded
= false;
1959 $this->mRestrictions
= array();
1963 * Updates page_touched for this page; called from LinksUpdate.php
1964 * @return bool true if the update succeded
1966 public function invalidateCache() {
1967 global $wgUseFileCache;
1969 if ( wfReadOnly() ) {
1973 $dbw = wfGetDB( DB_MASTER
);
1974 $success = $dbw->update( 'page',
1976 'page_touched' => $dbw->timestamp()
1977 ), array( /* WHERE */
1978 'page_namespace' => $this->getNamespace() ,
1979 'page_title' => $this->getDBkey()
1980 ), 'Title::invalidateCache'
1983 if ($wgUseFileCache) {
1984 $cache = new HTMLFileCache($this);
1985 @unlink
($cache->fileCacheName());
1992 * Prefix some arbitrary text with the namespace or interwiki prefix
1995 * @param string $name the text
1996 * @return string the prefixed text
1999 /* private */ function prefix( $name ) {
2001 if ( '' != $this->mInterwiki
) {
2002 $p = $this->mInterwiki
. ':';
2004 if ( 0 != $this->mNamespace
) {
2005 $p .= $this->getNsText() . ':';
2011 * Secure and split - main initialisation function for this object
2013 * Assumes that mDbkeyform has been set, and is urldecoded
2014 * and uses underscores, but not otherwise munged. This function
2015 * removes illegal characters, splits off the interwiki and
2016 * namespace prefixes, sets the other forms, and canonicalizes
2018 * @return bool true on success
2020 private function secureAndSplit() {
2021 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
2024 static $rxTc = false;
2026 # Matching titles will be held as illegal.
2028 # Any character not allowed is forbidden...
2029 '[^' . Title
::legalChars() . ']' .
2030 # URL percent encoding sequences interfere with the ability
2031 # to round-trip titles -- you can't link to them consistently.
2032 '|%[0-9A-Fa-f]{2}' .
2033 # XML/HTML character references produce similar issues.
2034 '|&[A-Za-z0-9\x80-\xff]+;' .
2036 '|&#x[0-9A-Fa-f]+;' .
2040 $this->mInterwiki
= $this->mFragment
= '';
2041 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
2043 $dbkey = $this->mDbkeyform
;
2045 # Strip Unicode bidi override characters.
2046 # Sometimes they slip into cut-n-pasted page titles, where the
2047 # override chars get included in list displays.
2048 $dbkey = str_replace( "\xE2\x80\x8E", '', $dbkey ); // 200E LEFT-TO-RIGHT MARK
2049 $dbkey = str_replace( "\xE2\x80\x8F", '', $dbkey ); // 200F RIGHT-TO-LEFT MARK
2051 # Clean up whitespace
2053 $dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
2054 $dbkey = trim( $dbkey, '_' );
2056 if ( '' == $dbkey ) {
2060 if( false !== strpos( $dbkey, UTF8_REPLACEMENT
) ) {
2061 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
2065 $this->mDbkeyform
= $dbkey;
2067 # Initial colon indicates main namespace rather than specified default
2068 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
2069 if ( ':' == $dbkey{0} ) {
2070 $this->mNamespace
= NS_MAIN
;
2071 $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing
2072 $dbkey = trim( $dbkey, '_' ); # remove any subsequent whitespace
2075 # Namespace or interwiki prefix
2079 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $dbkey, $m ) ) {
2081 if ( $ns = $wgContLang->getNsIndex( $p )) {
2082 # Ordinary namespace
2084 $this->mNamespace
= $ns;
2085 } elseif( $this->getInterwikiLink( $p ) ) {
2087 # Can't make a local interwiki link to an interwiki link.
2088 # That's just crazy!
2094 $this->mInterwiki
= $wgContLang->lc( $p );
2096 # Redundant interwiki prefix to the local wiki
2097 if ( 0 == strcasecmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
2098 if( $dbkey == '' ) {
2099 # Can't have an empty self-link
2102 $this->mInterwiki
= '';
2104 # Do another namespace split...
2108 # If there's an initial colon after the interwiki, that also
2109 # resets the default namespace
2110 if ( $dbkey !== '' && $dbkey[0] == ':' ) {
2111 $this->mNamespace
= NS_MAIN
;
2112 $dbkey = substr( $dbkey, 1 );
2115 # If there's no recognized interwiki or namespace,
2116 # then let the colon expression be part of the title.
2121 # We already know that some pages won't be in the database!
2123 if ( '' != $this->mInterwiki || NS_SPECIAL
== $this->mNamespace
) {
2124 $this->mArticleID
= 0;
2126 $fragment = strstr( $dbkey, '#' );
2127 if ( false !== $fragment ) {
2128 $this->setFragment( $fragment );
2129 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
2130 # remove whitespace again: prevents "Foo_bar_#"
2131 # becoming "Foo_bar_"
2132 $dbkey = preg_replace( '/_*$/', '', $dbkey );
2135 # Reject illegal characters.
2137 if( preg_match( $rxTc, $dbkey ) ) {
2142 * Pages with "/./" or "/../" appearing in the URLs will
2143 * often be unreachable due to the way web browsers deal
2144 * with 'relative' URLs. Forbid them explicitly.
2146 if ( strpos( $dbkey, '.' ) !== false &&
2147 ( $dbkey === '.' ||
$dbkey === '..' ||
2148 strpos( $dbkey, './' ) === 0 ||
2149 strpos( $dbkey, '../' ) === 0 ||
2150 strpos( $dbkey, '/./' ) !== false ||
2151 strpos( $dbkey, '/../' ) !== false ||
2152 substr( $dbkey, -2 ) == '/.' ||
2153 substr( $dbkey, -3 ) == '/..' ) )
2159 * Magic tilde sequences? Nu-uh!
2161 if( strpos( $dbkey, '~~~' ) !== false ) {
2166 * Limit the size of titles to 255 bytes.
2167 * This is typically the size of the underlying database field.
2168 * We make an exception for special pages, which don't need to be stored
2169 * in the database, and may edge over 255 bytes due to subpage syntax
2170 * for long titles, e.g. [[Special:Block/Long name]]
2172 if ( ( $this->mNamespace
!= NS_SPECIAL
&& strlen( $dbkey ) > 255 ) ||
2173 strlen( $dbkey ) > 512 )
2179 * Normally, all wiki links are forced to have
2180 * an initial capital letter so [[foo]] and [[Foo]]
2181 * point to the same place.
2183 * Don't force it for interwikis, since the other
2184 * site might be case-sensitive.
2186 $this->mUserCaseDBKey
= $dbkey;
2187 if( $wgCapitalLinks && $this->mInterwiki
== '') {
2188 $dbkey = $wgContLang->ucfirst( $dbkey );
2192 * Can't make a link to a namespace alone...
2193 * "empty" local links can only be self-links
2194 * with a fragment identifier.
2197 $this->mInterwiki
== '' &&
2198 $this->mNamespace
!= NS_MAIN
) {
2201 // Allow IPv6 usernames to start with '::' by canonicalizing IPv6 titles.
2202 // IP names are not allowed for accounts, and can only be referring to
2203 // edits from the IP. Given '::' abbreviations and caps/lowercaps,
2204 // there are numerous ways to present the same IP. Having sp:contribs scan
2205 // them all is silly and having some show the edits and others not is
2206 // inconsistent. Same for talk/userpages. Keep them normalized instead.
2207 $dbkey = ($this->mNamespace
== NS_USER ||
$this->mNamespace
== NS_USER_TALK
) ?
2208 IP
::sanitizeIP( $dbkey ) : $dbkey;
2209 // Any remaining initial :s are illegal.
2210 if ( $dbkey !== '' && ':' == $dbkey{0} ) {
2215 $this->mDbkeyform
= $dbkey;
2216 $this->mUrlform
= wfUrlencode( $dbkey );
2218 $this->mTextform
= str_replace( '_', ' ', $dbkey );
2224 * Set the fragment for this title
2225 * This is kind of bad, since except for this rarely-used function, Title objects
2226 * are immutable. The reason this is here is because it's better than setting the
2227 * members directly, which is what Linker::formatComment was doing previously.
2229 * @param string $fragment text
2230 * @todo clarify whether access is supposed to be public (was marked as "kind of public")
2232 public function setFragment( $fragment ) {
2233 $this->mFragment
= str_replace( '_', ' ', substr( $fragment, 1 ) );
2237 * Get a Title object associated with the talk page of this article
2238 * @return Title the object for the talk page
2240 public function getTalkPage() {
2241 return Title
::makeTitle( MWNamespace
::getTalk( $this->getNamespace() ), $this->getDBkey() );
2245 * Get a title object associated with the subject page of this
2248 * @return Title the object for the subject page
2250 public function getSubjectPage() {
2251 return Title
::makeTitle( MWNamespace
::getSubject( $this->getNamespace() ), $this->getDBkey() );
2255 * Get an array of Title objects linking to this Title
2256 * Also stores the IDs in the link cache.
2258 * WARNING: do not use this function on arbitrary user-supplied titles!
2259 * On heavily-used templates it will max out the memory.
2261 * @param string $options may be FOR UPDATE
2262 * @return array the Title objects linking here
2264 public function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
2265 $linkCache = LinkCache
::singleton();
2268 $db = wfGetDB( DB_MASTER
);
2270 $db = wfGetDB( DB_SLAVE
);
2273 $res = $db->select( array( 'page', $table ),
2274 array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ),
2276 "{$prefix}_from=page_id",
2277 "{$prefix}_namespace" => $this->getNamespace(),
2278 "{$prefix}_title" => $this->getDBkey() ),
2279 'Title::getLinksTo',
2283 if ( $db->numRows( $res ) ) {
2284 while ( $row = $db->fetchObject( $res ) ) {
2285 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
2286 $linkCache->addGoodLinkObj( $row->page_id
, $titleObj, $row->page_len
, $row->page_is_redirect
);
2287 $retVal[] = $titleObj;
2291 $db->freeResult( $res );
2296 * Get an array of Title objects using this Title as a template
2297 * Also stores the IDs in the link cache.
2299 * WARNING: do not use this function on arbitrary user-supplied titles!
2300 * On heavily-used templates it will max out the memory.
2302 * @param string $options may be FOR UPDATE
2303 * @return array the Title objects linking here
2305 public function getTemplateLinksTo( $options = '' ) {
2306 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
2310 * Get an array of Title objects referring to non-existent articles linked from this page
2312 * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case)
2313 * @param string $options may be FOR UPDATE
2314 * @return array the Title objects
2316 public function getBrokenLinksFrom( $options = '' ) {
2317 if ( $this->getArticleId() == 0 ) {
2318 # All links from article ID 0 are false positives
2323 $db = wfGetDB( DB_MASTER
);
2325 $db = wfGetDB( DB_SLAVE
);
2328 $res = $db->safeQuery(
2329 "SELECT pl_namespace, pl_title
2332 ON pl_namespace=page_namespace
2333 AND pl_title=page_title
2335 AND page_namespace IS NULL
2337 $db->tableName( 'pagelinks' ),
2338 $db->tableName( 'page' ),
2339 $this->getArticleId(),
2343 if ( $db->numRows( $res ) ) {
2344 while ( $row = $db->fetchObject( $res ) ) {
2345 $retVal[] = Title
::makeTitle( $row->pl_namespace
, $row->pl_title
);
2348 $db->freeResult( $res );
2354 * Get a list of URLs to purge from the Squid cache when this
2357 * @return array the URLs
2359 public function getSquidURLs() {
2363 $this->getInternalURL(),
2364 $this->getInternalURL( 'action=history' )
2367 // purge variant urls as well
2368 if($wgContLang->hasVariants()){
2369 $variants = $wgContLang->getVariants();
2370 foreach($variants as $vCode){
2371 if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
2372 $urls[] = $this->getInternalURL('',$vCode);
2379 public function purgeSquid() {
2381 if ( $wgUseSquid ) {
2382 $urls = $this->getSquidURLs();
2383 $u = new SquidUpdate( $urls );
2389 * Move this page without authentication
2390 * @param Title &$nt the new page Title
2392 public function moveNoAuth( &$nt ) {
2393 return $this->moveTo( $nt, false );
2397 * Check whether a given move operation would be valid.
2398 * Returns true if ok, or a message key string for an error message
2399 * if invalid. (Scarrrrry ugly interface this.)
2400 * @param Title &$nt the new title
2401 * @param bool $auth indicates whether $wgUser's permissions
2403 * @return mixed true on success, message name on failure
2405 public function isValidMoveOperation( &$nt, $auth = true ) {
2406 if( !$this or !$nt ) {
2407 return 'badtitletext';
2409 if( $this->equals( $nt ) ) {
2412 if( !$this->isMovable() ||
!$nt->isMovable() ) {
2413 return 'immobile_namespace';
2416 $oldid = $this->getArticleID();
2417 $newid = $nt->getArticleID();
2419 if ( strlen( $nt->getDBkey() ) < 1 ) {
2420 return 'articleexists';
2422 if ( ( '' == $this->getDBkey() ) ||
2424 ( '' == $nt->getDBkey() ) ) {
2425 return 'badarticleerror';
2428 // Image-specific checks
2429 if( $this->getNamespace() == NS_IMAGE
) {
2430 $file = wfLocalFile( $this );
2431 if( $file->exists() ) {
2432 if( $nt->getNamespace() != NS_IMAGE
) {
2433 return 'imagenocrossnamespace';
2435 if( !File
::checkExtensionCompatibility( $file, $nt->getDbKey() ) ) {
2436 return 'imagetypemismatch';
2443 $errors = array_merge($this->getUserPermissionsErrors('move', $wgUser),
2444 $this->getUserPermissionsErrors('edit', $wgUser),
2445 $nt->getUserPermissionsErrors('move', $wgUser),
2446 $nt->getUserPermissionsErrors('edit', $wgUser));
2447 if($errors !== array())
2448 return $errors[0][0];
2453 if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err ) ) ) {
2454 return 'hookaborted';
2457 # The move is allowed only if (1) the target doesn't exist, or
2458 # (2) the target is a redirect to the source, and has no history
2459 # (so we can undo bad moves right after they're done).
2461 if ( 0 != $newid ) { # Target exists; check for validity
2462 if ( ! $this->isValidMoveTarget( $nt ) ) {
2463 return 'articleexists';
2466 $tp = $nt->getTitleProtection();
2467 $right = ( $tp['pt_create_perm'] == 'sysop' ) ?
'protect' : $tp['pt_create_perm'];
2468 if ( $tp and !$wgUser->isAllowed( $right ) ) {
2469 return 'cantmove-titleprotected';
2476 * Move a title to a new location
2477 * @param Title &$nt the new title
2478 * @param bool $auth indicates whether $wgUser's permissions
2480 * @param string $reason The reason for the move
2481 * @param bool $createRedirect Whether to create a redirect from the old title to the new title.
2482 * Ignored if the user doesn't have the suppressredirect right.
2483 * @return mixed true on success, message name on failure
2485 public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
2486 $err = $this->isValidMoveOperation( $nt, $auth );
2487 if( is_string( $err ) ) {
2491 $pageid = $this->getArticleID();
2492 if( $nt->exists() ) {
2493 $err = $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
2494 $pageCountChange = ($createRedirect ?
0 : -1);
2495 } else { # Target didn't exist, do normal move.
2496 $err = $this->moveToNewTitle( $nt, $reason, $createRedirect );
2497 $pageCountChange = ($createRedirect ?
1 : 0);
2499 if( is_string( $err ) ) {
2502 $redirid = $this->getArticleID();
2504 // Category memberships include a sort key which may be customized.
2505 // If it's left as the default (the page title), we need to update
2506 // the sort key to match the new title.
2508 // Be careful to avoid resetting cl_timestamp, which may disturb
2509 // time-based lists on some sites.
2511 // Warning -- if the sort key is *explicitly* set to the old title,
2512 // we can't actually distinguish it from a default here, and it'll
2513 // be set to the new title even though it really shouldn't.
2514 // It'll get corrected on the next edit, but resetting cl_timestamp.
2515 $dbw = wfGetDB( DB_MASTER
);
2516 $dbw->update( 'categorylinks',
2518 'cl_sortkey' => $nt->getPrefixedText(),
2519 'cl_timestamp=cl_timestamp' ),
2521 'cl_from' => $pageid,
2522 'cl_sortkey' => $this->getPrefixedText() ),
2527 $oldnamespace = $this->getNamespace() & ~
1;
2528 $newnamespace = $nt->getNamespace() & ~
1;
2529 $oldtitle = $this->getDBkey();
2530 $newtitle = $nt->getDBkey();
2532 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
2533 WatchedItem
::duplicateEntries( $this, $nt );
2536 # Update search engine
2537 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
2539 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
2543 if( $this->isContentPage() && !$nt->isContentPage() ) {
2544 # No longer a content page
2545 # Not viewed, edited, removing
2546 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange );
2547 } elseif( !$this->isContentPage() && $nt->isContentPage() ) {
2548 # Now a content page
2549 # Not viewed, edited, adding
2550 $u = new SiteStatsUpdate( 0, 1, +
1, $pageCountChange );
2551 } elseif( $pageCountChange ) {
2553 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
2560 # Update message cache for interface messages
2561 if( $nt->getNamespace() == NS_MEDIAWIKI
) {
2562 global $wgMessageCache;
2563 $oldarticle = new Article( $this );
2564 $wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
2565 $newarticle = new Article( $nt );
2566 $wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
2570 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
2575 * Move page to a title which is at present a redirect to the
2578 * @param Title &$nt the page to move to, which should currently
2580 * @param string $reason The reason for the move
2581 * @param bool $createRedirect Whether to leave a redirect at the old title.
2582 * Ignored if the user doesn't have the suppressredirect right
2584 private function moveOverExistingRedirect( &$nt, $reason = '', $createRedirect = true ) {
2585 global $wgUseSquid, $wgUser;
2586 $fname = 'Title::moveOverExistingRedirect';
2587 $comment = wfMsgForContent( '1movedto2_redir', $this->getPrefixedText(), $nt->getPrefixedText() );
2590 $comment .= ": $reason";
2593 $now = wfTimestampNow();
2594 $newid = $nt->getArticleID();
2595 $oldid = $this->getArticleID();
2596 $dbw = wfGetDB( DB_MASTER
);
2598 # Move an image if it is
2599 if( $this->getNamespace() == NS_IMAGE
) {
2600 $file = wfLocalFile( $this );
2601 if( $file->exists() ) {
2602 $status = $file->move( $nt );
2603 if( !$status->isOk() ) {
2604 return $status->getWikiText();
2609 # Delete the old redirect. We don't save it to history since
2610 # by definition if we've got here it's rather uninteresting.
2611 # We have to remove it so that the next step doesn't trigger
2612 # a conflict on the unique namespace+title index...
2613 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
2614 if ( !$dbw->cascadingDeletes() ) {
2615 $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__
);
2616 global $wgUseTrackbacks;
2617 if ($wgUseTrackbacks)
2618 $dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__
);
2619 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__
);
2620 $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__
);
2621 $dbw->delete( 'categorylinks', array( 'cl_from' => $newid ), __METHOD__
);
2622 $dbw->delete( 'templatelinks', array( 'tl_from' => $newid ), __METHOD__
);
2623 $dbw->delete( 'externallinks', array( 'el_from' => $newid ), __METHOD__
);
2624 $dbw->delete( 'langlinks', array( 'll_from' => $newid ), __METHOD__
);
2625 $dbw->delete( 'redirect', array( 'rd_from' => $newid ), __METHOD__
);
2628 # Save a null revision in the page's history notifying of the move
2629 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2630 $nullRevId = $nullRevision->insertOn( $dbw );
2632 $article = new Article( $nt );
2634 # Change the name of the target page:
2635 $dbw->update( 'page',
2637 'page_touched' => $dbw->timestamp($now),
2638 'page_namespace' => $nt->getNamespace(),
2639 'page_title' => $nt->getDBkey(),
2640 'page_latest' => $nullRevId,
2642 /* WHERE */ array( 'page_id' => $oldid ),
2645 $nt->resetArticleID( $oldid );
2647 wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
2649 # Recreate the redirect, this time in the other direction.
2650 if($createRedirect ||
!$wgUser->isAllowed('suppressredirect'))
2652 $mwRedir = MagicWord
::get( 'redirect' );
2653 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2654 $redirectArticle = new Article( $this );
2655 $newid = $redirectArticle->insertOn( $dbw );
2656 $redirectRevision = new Revision( array(
2658 'comment' => $comment,
2659 'text' => $redirectText ) );
2660 $redirectRevision->insertOn( $dbw );
2661 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2663 wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false) );
2665 # Now, we record the link from the redirect to the new title.
2666 # It should have no other outgoing links...
2667 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
2668 $dbw->insert( 'pagelinks',
2670 'pl_from' => $newid,
2671 'pl_namespace' => $nt->getNamespace(),
2672 'pl_title' => $nt->getDBkey() ),
2675 $this->resetArticleID( 0 );
2679 $log = new LogPage( 'move' );
2680 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
2683 if ( $wgUseSquid ) {
2684 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
2685 $u = new SquidUpdate( $urls );
2691 * Move page to non-existing title.
2692 * @param Title &$nt the new Title
2693 * @param string $reason The reason for the move
2694 * @param bool $createRedirect Whether to create a redirect from the old title to the new title
2695 * Ignored if the user doesn't have the suppressredirect right
2697 private function moveToNewTitle( &$nt, $reason = '', $createRedirect = true ) {
2698 global $wgUseSquid, $wgUser;
2699 $fname = 'MovePageForm::moveToNewTitle';
2700 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
2702 $comment .= ": $reason";
2705 $newid = $nt->getArticleID();
2706 $oldid = $this->getArticleID();
2707 $dbw = wfGetDB( DB_MASTER
);
2708 $now = $dbw->timestamp();
2710 # Move an image if it is
2711 if( $this->getNamespace() == NS_IMAGE
) {
2712 $file = wfLocalFile( $this );
2713 if( $file->exists() ) {
2714 $status = $file->move( $nt );
2715 if( !$status->isOk() ) {
2716 return $status->getWikiText();
2721 # Save a null revision in the page's history notifying of the move
2722 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2723 $nullRevId = $nullRevision->insertOn( $dbw );
2725 $article = new Article( $nt );
2728 $dbw->update( 'page',
2730 'page_touched' => $now,
2731 'page_namespace' => $nt->getNamespace(),
2732 'page_title' => $nt->getDBkey(),
2733 'page_latest' => $nullRevId,
2735 /* WHERE */ array( 'page_id' => $oldid ),
2738 $nt->resetArticleID( $oldid );
2740 wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
2742 if($createRedirect ||
!$wgUser->isAllowed('suppressredirect'))
2745 $mwRedir = MagicWord
::get( 'redirect' );
2746 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2747 $redirectArticle = new Article( $this );
2748 $newid = $redirectArticle->insertOn( $dbw );
2749 $redirectRevision = new Revision( array(
2751 'comment' => $comment,
2752 'text' => $redirectText ) );
2753 $redirectRevision->insertOn( $dbw );
2754 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2756 wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false) );
2758 # Record the just-created redirect's linking to the page
2759 $dbw->insert( 'pagelinks',
2761 'pl_from' => $newid,
2762 'pl_namespace' => $nt->getNamespace(),
2763 'pl_title' => $nt->getDBkey() ),
2766 $this->resetArticleID( 0 );
2770 $log = new LogPage( 'move' );
2771 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
2773 # Purge caches as per article creation
2774 Article
::onArticleCreate( $nt );
2776 # Purge old title from squid
2777 # The new title, and links to the new title, are purged in Article::onArticleCreate()
2778 $this->purgeSquid();
2782 * Checks if $this can be moved to a given Title
2783 * - Selects for update, so don't call it unless you mean business
2785 * @param Title &$nt the new title to check
2787 public function isValidMoveTarget( $nt ) {
2789 $fname = 'Title::isValidMoveTarget';
2790 $dbw = wfGetDB( DB_MASTER
);
2792 # Is it an existsing file?
2793 if( $nt->getNamespace() == NS_IMAGE
) {
2794 $file = wfLocalFile( $nt );
2795 if( $file->exists() ) {
2796 wfDebug( __METHOD__
. ": file exists\n" );
2802 $id = $nt->getArticleID();
2803 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
2804 array( 'page_is_redirect','old_text','old_flags' ),
2805 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
2806 $fname, 'FOR UPDATE' );
2808 if ( !$obj ||
0 == $obj->page_is_redirect
) {
2810 wfDebug( __METHOD__
. ": not a redirect\n" );
2813 $text = Revision
::getRevisionText( $obj );
2815 # Does the redirect point to the source?
2816 # Or is it a broken self-redirect, usually caused by namespace collisions?
2818 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
2819 $redirTitle = Title
::newFromText( $m[1] );
2820 if( !is_object( $redirTitle ) ||
2821 ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
2822 $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) {
2823 wfDebug( __METHOD__
. ": redirect points to other page\n" );
2828 wfDebug( __METHOD__
. ": failsafe\n" );
2832 # Does the article have a history?
2833 $row = $dbw->selectRow( array( 'page', 'revision'),
2835 array( 'page_namespace' => $nt->getNamespace(),
2836 'page_title' => $nt->getDBkey(),
2837 'page_id=rev_page AND page_latest != rev_id'
2838 ), $fname, 'FOR UPDATE'
2841 # Return true if there was no history
2842 return $row === false;
2846 * Can this title be added to a user's watchlist?
2850 public function isWatchable() {
2851 return !$this->isExternal()
2852 && MWNamespace
::isWatchable( $this->getNamespace() );
2856 * Get categories to which this Title belongs and return an array of
2857 * categories' names.
2859 * @return array an array of parents in the form:
2860 * $parent => $currentarticle
2862 public function getParentCategories() {
2865 $titlekey = $this->getArticleId();
2866 $dbr = wfGetDB( DB_SLAVE
);
2867 $categorylinks = $dbr->tableName( 'categorylinks' );
2870 $sql = "SELECT * FROM $categorylinks"
2871 ." WHERE cl_from='$titlekey'"
2872 ." AND cl_from <> '0'"
2873 ." ORDER BY cl_sortkey";
2875 $res = $dbr->query ( $sql ) ;
2877 if($dbr->numRows($res) > 0) {
2878 while ( $x = $dbr->fetchObject ( $res ) )
2879 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2880 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
2881 $dbr->freeResult ( $res ) ;
2889 * Get a tree of parent categories
2890 * @param array $children an array with the children in the keys, to check for circular refs
2893 public function getParentCategoryTree( $children = array() ) {
2895 $parents = $this->getParentCategories();
2898 foreach($parents as $parent => $current) {
2899 if ( array_key_exists( $parent, $children ) ) {
2900 # Circular reference
2901 $stack[$parent] = array();
2903 $nt = Title
::newFromText($parent);
2905 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
2917 * Get an associative array for selecting this title from
2922 public function pageCond() {
2923 return array( 'page_namespace' => $this->mNamespace
, 'page_title' => $this->mDbkeyform
);
2927 * Get the revision ID of the previous revision
2929 * @param integer $revision Revision ID. Get the revision that was before this one.
2930 * @param integer $flags, GAID_FOR_UPDATE
2931 * @return integer $oldrevision|false
2933 public function getPreviousRevisionID( $revision, $flags=0 ) {
2934 $db = ($flags & GAID_FOR_UPDATE
) ?
wfGetDB( DB_MASTER
) : wfGetDB( DB_SLAVE
);
2935 return $db->selectField( 'revision', 'rev_id',
2937 'rev_page' => $this->getArticleId($flags),
2938 'rev_id < ' . intval( $revision )
2941 array( 'ORDER BY' => 'rev_id DESC' )
2946 * Get the revision ID of the next revision
2948 * @param integer $revision Revision ID. Get the revision that was after this one.
2949 * @param integer $flags, GAID_FOR_UPDATE
2950 * @return integer $oldrevision|false
2952 public function getNextRevisionID( $revision, $flags=0 ) {
2953 $db = ($flags & GAID_FOR_UPDATE
) ?
wfGetDB( DB_MASTER
) : wfGetDB( DB_SLAVE
);
2954 return $db->selectField( 'revision', 'rev_id',
2956 'rev_page' => $this->getArticleId($flags),
2957 'rev_id > ' . intval( $revision )
2960 array( 'ORDER BY' => 'rev_id' )
2965 * Get the number of revisions between the given revision IDs.
2966 * Used for diffs and other things that really need it.
2968 * @param integer $old Revision ID.
2969 * @param integer $new Revision ID.
2970 * @return integer Number of revisions between these IDs.
2972 public function countRevisionsBetween( $old, $new ) {
2973 $dbr = wfGetDB( DB_SLAVE
);
2974 return $dbr->selectField( 'revision', 'count(*)',
2975 'rev_page = ' . intval( $this->getArticleId() ) .
2976 ' AND rev_id > ' . intval( $old ) .
2977 ' AND rev_id < ' . intval( $new ),
2979 array( 'USE INDEX' => 'PRIMARY' ) );
2983 * Compare with another title.
2985 * @param Title $title
2988 public function equals( $title ) {
2989 // Note: === is necessary for proper matching of number-like titles.
2990 return $this->getInterwiki() === $title->getInterwiki()
2991 && $this->getNamespace() == $title->getNamespace()
2992 && $this->getDBkey() === $title->getDBkey();
2996 * Callback for usort() to do title sorts by (namespace, title)
2998 static function compare( $a, $b ) {
2999 if( $a->getNamespace() == $b->getNamespace() ) {
3000 return strcmp( $a->getText(), $b->getText() );
3002 return $a->getNamespace() - $b->getNamespace();
3007 * Return a string representation of this title
3011 public function __toString() {
3012 return $this->getPrefixedText();
3016 * Check if page exists
3019 public function exists() {
3020 return $this->getArticleId() != 0;
3024 * Do we know that this title definitely exists, or should we otherwise
3025 * consider that it exists?
3029 public function isAlwaysKnown() {
3030 // If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes
3031 // the full l10n of that language to be loaded. That takes much memory and
3032 // isn't needed. So we strip the language part away.
3033 // Also, extension messages which are not loaded, are shown as red, because
3034 // we don't call MessageCache::loadAllMessages.
3035 list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform
, 2 );
3036 return $this->isExternal()
3037 ||
( $this->mNamespace
== NS_MAIN
&& $this->mDbkeyform
== '' )
3038 ||
( $this->mNamespace
== NS_MEDIAWIKI
&& wfMsgWeirdKey( $basename ) );
3042 * Update page_touched timestamps and send squid purge messages for
3043 * pages linking to this title. May be sent to the job queue depending
3044 * on the number of links. Typically called on create and delete.
3046 public function touchLinks() {
3047 $u = new HTMLCacheUpdate( $this, 'pagelinks' );
3050 if ( $this->getNamespace() == NS_CATEGORY
) {
3051 $u = new HTMLCacheUpdate( $this, 'categorylinks' );
3057 * Get the last touched timestamp
3059 public function getTouched() {
3060 $dbr = wfGetDB( DB_SLAVE
);
3061 $touched = $dbr->selectField( 'page', 'page_touched',
3063 'page_namespace' => $this->getNamespace(),
3064 'page_title' => $this->getDBkey()
3070 public function trackbackURL() {
3071 global $wgTitle, $wgScriptPath, $wgServer;
3073 return "$wgServer$wgScriptPath/trackback.php?article="
3074 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
3077 public function trackbackRDF() {
3078 $url = htmlspecialchars($this->getFullURL());
3079 $title = htmlspecialchars($this->getText());
3080 $tburl = $this->trackbackURL();
3082 // Autodiscovery RDF is placed in comments so HTML validator
3083 // won't barf. This is a rather icky workaround, but seems
3084 // frequently used by this kind of RDF thingy.
3086 // Spec: http://www.sixapart.com/pronet/docs/trackback_spec
3088 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
3089 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
3090 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
3093 dc:identifier=\"$url\"
3095 trackback:ping=\"$tburl\" />
3101 * Generate strings used for xml 'id' names in monobook tabs
3104 public function getNamespaceKey() {
3106 switch ($this->getNamespace()) {
3109 return 'nstab-main';
3112 return 'nstab-user';
3114 return 'nstab-media';
3116 return 'nstab-special';
3118 case NS_PROJECT_TALK
:
3119 return 'nstab-project';
3122 return 'nstab-image';
3124 case NS_MEDIAWIKI_TALK
:
3125 return 'nstab-mediawiki';
3127 case NS_TEMPLATE_TALK
:
3128 return 'nstab-template';
3131 return 'nstab-help';
3133 case NS_CATEGORY_TALK
:
3134 return 'nstab-category';
3136 return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
3141 * Returns true if this title resolves to the named special page
3142 * @param string $name The special page name
3144 public function isSpecial( $name ) {
3145 if ( $this->getNamespace() == NS_SPECIAL
) {
3146 list( $thisName, /* $subpage */ ) = SpecialPage
::resolveAliasWithSubpage( $this->getDBkey() );
3147 if ( $name == $thisName ) {
3155 * If the Title refers to a special page alias which is not the local default,
3156 * returns a new Title which points to the local default. Otherwise, returns $this.
3158 public function fixSpecialName() {
3159 if ( $this->getNamespace() == NS_SPECIAL
) {
3160 $canonicalName = SpecialPage
::resolveAlias( $this->mDbkeyform
);
3161 if ( $canonicalName ) {
3162 $localName = SpecialPage
::getLocalNameFor( $canonicalName );
3163 if ( $localName != $this->mDbkeyform
) {
3164 return Title
::makeTitle( NS_SPECIAL
, $localName );
3172 * Is this Title in a namespace which contains content?
3173 * In other words, is this a content page, for the purposes of calculating
3178 public function isContentPage() {
3179 return MWNamespace
::isContent( $this->getNamespace() );
3182 public function getRedirectsHere( $ns = null ) {
3185 $dbr = wfGetDB( DB_SLAVE
);
3187 'rd_namespace' => $this->getNamespace(),
3188 'rd_title' => $this->getDBkey(),
3191 if ( !is_null($ns) ) $where['page_namespace'] = $ns;
3193 $result = $dbr->select(
3194 array( 'redirect', 'page' ),
3195 array( 'page_namespace', 'page_title' ),
3201 while( $row = $dbr->fetchObject( $result ) ) {
3202 $redirs[] = self
::newFromRow( $row );