Prevent registration/login with the username "MediaWiki default"
[lhc/web/wiklou.git] / includes / Title.php
1 <?php
2 /**
3 * See title.txt
4 *
5 * @package MediaWiki
6 */
7
8 /** */
9 require_once( 'normal/UtfNormal.php' );
10
11 $wgTitleInterwikiCache = array();
12 $wgTitleCache = array();
13
14 define ( 'GAID_FOR_UPDATE', 1 );
15
16 # Title::newFromTitle maintains a cache to avoid
17 # expensive re-normalization of commonly used titles.
18 # On a batch operation this can become a memory leak
19 # if not bounded. After hitting this many titles,
20 # reset the cache.
21 define( 'MW_TITLECACHE_MAX', 1000 );
22
23 /**
24 * Title class
25 * - Represents a title, which may contain an interwiki designation or namespace
26 * - Can fetch various kinds of data from the database, albeit inefficiently.
27 *
28 * @package MediaWiki
29 */
30 class Title {
31 /**
32 * All member variables should be considered private
33 * Please use the accessor functions
34 */
35
36 /**#@+
37 * @access private
38 */
39
40 var $mTextform; # Text form (spaces not underscores) of the main part
41 var $mUrlform; # URL-encoded form of the main part
42 var $mDbkeyform; # Main part with underscores
43 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
44 var $mInterwiki; # Interwiki prefix (or null string)
45 var $mFragment; # Title fragment (i.e. the bit after the #)
46 var $mArticleID; # Article ID, fetched from the link cache on demand
47 var $mLatestID; # ID of most recent revision
48 var $mRestrictions; # Array of groups allowed to edit this article
49 # Only null or "sysop" are supported
50 var $mRestrictionsLoaded; # Boolean for initialisation on demand
51 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
52 var $mDefaultNamespace; # Namespace index when there is no namespace
53 # Zero except in {{transclusion}} tags
54 var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
55 /**#@-*/
56
57
58 /**
59 * Constructor
60 * @access private
61 */
62 /* private */ function Title() {
63 $this->mInterwiki = $this->mUrlform =
64 $this->mTextform = $this->mDbkeyform = '';
65 $this->mArticleID = -1;
66 $this->mNamespace = NS_MAIN;
67 $this->mRestrictionsLoaded = false;
68 $this->mRestrictions = array();
69 # Dont change the following, NS_MAIN is hardcoded in several place
70 # See bug #696
71 $this->mDefaultNamespace = NS_MAIN;
72 $this->mWatched = NULL;
73 $this->mLatestID = false;
74 }
75
76 /**
77 * Create a new Title from a prefixed DB key
78 * @param string $key The database key, which has underscores
79 * instead of spaces, possibly including namespace and
80 * interwiki prefixes
81 * @return Title the new object, or NULL on an error
82 * @static
83 * @access public
84 */
85 /* static */ function newFromDBkey( $key ) {
86 $t = new Title();
87 $t->mDbkeyform = $key;
88 if( $t->secureAndSplit() )
89 return $t;
90 else
91 return NULL;
92 }
93
94 /**
95 * Create a new Title from text, such as what one would
96 * find in a link. Decodes any HTML entities in the text.
97 *
98 * @param string $text the link text; spaces, prefixes,
99 * and an initial ':' indicating the main namespace
100 * are accepted
101 * @param int $defaultNamespace the namespace to use if
102 * none is specified by a prefix
103 * @return Title the new object, or NULL on an error
104 * @static
105 * @access public
106 */
107 function newFromText( $text, $defaultNamespace = NS_MAIN ) {
108 global $wgTitleCache;
109 $fname = 'Title::newFromText';
110
111 if( is_object( $text ) ) {
112 wfDebugDieBacktrace( 'Title::newFromText given an object' );
113 }
114
115 /**
116 * Wiki pages often contain multiple links to the same page.
117 * Title normalization and parsing can become expensive on
118 * pages with many links, so we can save a little time by
119 * caching them.
120 *
121 * In theory these are value objects and won't get changed...
122 */
123 if( $defaultNamespace == NS_MAIN && isset( $wgTitleCache[$text] ) ) {
124 return $wgTitleCache[$text];
125 }
126
127 /**
128 * Convert things like &eacute; &#257; or &#x3017; into real text...
129 */
130 $filteredText = Sanitizer::decodeCharReferences( $text );
131
132 $t =& new Title();
133 $t->mDbkeyform = str_replace( ' ', '_', $filteredText );
134 $t->mDefaultNamespace = $defaultNamespace;
135
136 static $cachedcount = 0 ;
137 if( $t->secureAndSplit() ) {
138 if( $defaultNamespace == NS_MAIN ) {
139 if( $cachedcount >= MW_TITLECACHE_MAX ) {
140 # Avoid memory leaks on mass operations...
141 $wgTitleCache = array();
142 $cachedcount=0;
143 }
144 $cachedcount++;
145 $wgTitleCache[$text] =& $t;
146 }
147 return $t;
148 } else {
149 $ret = NULL;
150 return $ret;
151 }
152 }
153
154 /**
155 * Create a new Title from URL-encoded text. Ensures that
156 * the given title's length does not exceed the maximum.
157 * @param string $url the title, as might be taken from a URL
158 * @return Title the new object, or NULL on an error
159 * @static
160 * @access public
161 */
162 function newFromURL( $url ) {
163 global $wgLegalTitleChars;
164 $t = new Title();
165
166 # For compatibility with old buggy URLs. "+" is usually not valid in titles,
167 # but some URLs used it as a space replacement and they still come
168 # from some external search tools.
169 if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
170 $url = str_replace( '+', ' ', $url );
171 }
172
173 $t->mDbkeyform = str_replace( ' ', '_', $url );
174 if( $t->secureAndSplit() ) {
175 return $t;
176 } else {
177 return NULL;
178 }
179 }
180
181 /**
182 * Create a new Title from an article ID
183 *
184 * @todo This is inefficiently implemented, the page row is requested
185 * but not used for anything else
186 *
187 * @param int $id the page_id corresponding to the Title to create
188 * @return Title the new object, or NULL on an error
189 * @access public
190 * @static
191 */
192 function newFromID( $id ) {
193 $fname = 'Title::newFromID';
194 $dbr =& wfGetDB( DB_SLAVE );
195 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
196 array( 'page_id' => $id ), $fname );
197 if ( $row !== false ) {
198 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
199 } else {
200 $title = NULL;
201 }
202 return $title;
203 }
204
205 /**
206 * Create a new Title from a namespace index and a DB key.
207 * It's assumed that $ns and $title are *valid*, for instance when
208 * they came directly from the database or a special page name.
209 * For convenience, spaces are converted to underscores so that
210 * eg user_text fields can be used directly.
211 *
212 * @param int $ns the namespace of the article
213 * @param string $title the unprefixed database key form
214 * @return Title the new object
215 * @static
216 * @access public
217 */
218 function &makeTitle( $ns, $title ) {
219 $t =& new Title();
220 $t->mInterwiki = '';
221 $t->mFragment = '';
222 $t->mNamespace = intval( $ns );
223 $t->mDbkeyform = str_replace( ' ', '_', $title );
224 $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
225 $t->mUrlform = wfUrlencode( $t->mDbkeyform );
226 $t->mTextform = str_replace( '_', ' ', $title );
227 return $t;
228 }
229
230 /**
231 * Create a new Title frrom a namespace index and a DB key.
232 * The parameters will be checked for validity, which is a bit slower
233 * than makeTitle() but safer for user-provided data.
234 *
235 * @param int $ns the namespace of the article
236 * @param string $title the database key form
237 * @return Title the new object, or NULL on an error
238 * @static
239 * @access public
240 */
241 function makeTitleSafe( $ns, $title ) {
242 $t = new Title();
243 $t->mDbkeyform = Title::makeName( $ns, $title );
244 if( $t->secureAndSplit() ) {
245 return $t;
246 } else {
247 return NULL;
248 }
249 }
250
251 /**
252 * Create a new Title for the Main Page
253 *
254 * @static
255 * @return Title the new object
256 * @access public
257 */
258 function newMainPage() {
259 return Title::newFromText( wfMsgForContent( 'mainpage' ) );
260 }
261
262 /**
263 * Create a new Title for a redirect
264 * @param string $text the redirect title text
265 * @return Title the new object, or NULL if the text is not a
266 * valid redirect
267 * @static
268 * @access public
269 */
270 function newFromRedirect( $text ) {
271 global $wgMwRedir;
272 $rt = NULL;
273 if ( $wgMwRedir->matchStart( $text ) ) {
274 if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) {
275 # categories are escaped using : for example one can enter:
276 # #REDIRECT [[:Category:Music]]. Need to remove it.
277 if ( substr($m[1],0,1) == ':') {
278 # We don't want to keep the ':'
279 $m[1] = substr( $m[1], 1 );
280 }
281
282 $rt = Title::newFromText( $m[1] );
283 # Disallow redirects to Special:Userlogout
284 if ( !is_null($rt) && $rt->getNamespace() == NS_SPECIAL && preg_match( '/^Userlogout/i', $rt->getText() ) ) {
285 $rt = NULL;
286 }
287 }
288 }
289 return $rt;
290 }
291
292 #----------------------------------------------------------------------------
293 # Static functions
294 #----------------------------------------------------------------------------
295
296 /**
297 * Get the prefixed DB key associated with an ID
298 * @param int $id the page_id of the article
299 * @return Title an object representing the article, or NULL
300 * if no such article was found
301 * @static
302 * @access public
303 */
304 function nameOf( $id ) {
305 $fname = 'Title::nameOf';
306 $dbr =& wfGetDB( DB_SLAVE );
307
308 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
309 if ( $s === false ) { return NULL; }
310
311 $n = Title::makeName( $s->page_namespace, $s->page_title );
312 return $n;
313 }
314
315 /**
316 * Get a regex character class describing the legal characters in a link
317 * @return string the list of characters, not delimited
318 * @static
319 * @access public
320 */
321 function legalChars() {
322 global $wgLegalTitleChars;
323 return $wgLegalTitleChars;
324 }
325
326 /**
327 * Get a string representation of a title suitable for
328 * including in a search index
329 *
330 * @param int $ns a namespace index
331 * @param string $title text-form main part
332 * @return string a stripped-down title string ready for the
333 * search index
334 */
335 /* static */ function indexTitle( $ns, $title ) {
336 global $wgContLang;
337 require_once( 'SearchEngine.php' );
338
339 $lc = SearchEngine::legalSearchChars() . '&#;';
340 $t = $wgContLang->stripForSearch( $title );
341 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
342 $t = strtolower( $t );
343
344 # Handle 's, s'
345 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
346 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
347
348 $t = preg_replace( "/\\s+/", ' ', $t );
349
350 if ( $ns == NS_IMAGE ) {
351 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
352 }
353 return trim( $t );
354 }
355
356 /*
357 * Make a prefixed DB key from a DB key and a namespace index
358 * @param int $ns numerical representation of the namespace
359 * @param string $title the DB key form the title
360 * @return string the prefixed form of the title
361 */
362 /* static */ function makeName( $ns, $title ) {
363 global $wgContLang;
364
365 $n = $wgContLang->getNsText( $ns );
366 return $n == '' ? $title : "$n:$title";
367 }
368
369 /**
370 * Returns the URL associated with an interwiki prefix
371 * @param string $key the interwiki prefix (e.g. "MeatBall")
372 * @return the associated URL, containing "$1", which should be
373 * replaced by an article title
374 * @static (arguably)
375 * @access public
376 */
377 function getInterwikiLink( $key ) {
378 global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
379 global $wgInterwikiCache;
380 $fname = 'Title::getInterwikiLink';
381
382 $key = strtolower( $key );
383
384 $k = $wgDBname.':interwiki:'.$key;
385 if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
386 return $wgTitleInterwikiCache[$k]->iw_url;
387 }
388
389 if ($wgInterwikiCache) {
390 return Title::getInterwikiCached( $key );
391 }
392
393 $s = $wgMemc->get( $k );
394 # Ignore old keys with no iw_local
395 if( $s && isset( $s->iw_local ) && isset($s->iw_trans)) {
396 $wgTitleInterwikiCache[$k] = $s;
397 return $s->iw_url;
398 }
399
400 $dbr =& wfGetDB( DB_SLAVE );
401 $res = $dbr->select( 'interwiki',
402 array( 'iw_url', 'iw_local', 'iw_trans' ),
403 array( 'iw_prefix' => $key ), $fname );
404 if( !$res ) {
405 return '';
406 }
407
408 $s = $dbr->fetchObject( $res );
409 if( !$s ) {
410 # Cache non-existence: create a blank object and save it to memcached
411 $s = (object)false;
412 $s->iw_url = '';
413 $s->iw_local = 0;
414 $s->iw_trans = 0;
415 }
416 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
417 $wgTitleInterwikiCache[$k] = $s;
418
419 return $s->iw_url;
420 }
421
422 /**
423 * Fetch interwiki prefix data from local cache in constant database
424 *
425 * More logic is explained in DefaultSettings
426 *
427 * @return string URL of interwiki site
428 * @access public
429 */
430 function getInterwikiCached( $key ) {
431 global $wgDBname, $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
432 global $wgTitleInterwikiCache;
433 static $db, $site;
434
435 if (!$db)
436 $db=dba_open($wgInterwikiCache,'r','cdb');
437 /* Resolve site name */
438 if ($wgInterwikiScopes>=3 and !$site) {
439 $site = dba_fetch("__sites:{$wgDBname}", $db);
440 if ($site=="")
441 $site = $wgInterwikiFallbackSite;
442 }
443 $value = dba_fetch("{$wgDBname}:{$key}", $db);
444 if ($value=='' and $wgInterwikiScopes>=3) {
445 /* try site-level */
446 $value = dba_fetch("_{$site}:{$key}", $db);
447 }
448 if ($value=='' and $wgInterwikiScopes>=2) {
449 /* try globals */
450 $value = dba_fetch("__global:{$key}", $db);
451 }
452 if ($value=='undef')
453 $value='';
454 $s = (object)false;
455 $s->iw_url = '';
456 $s->iw_local = 0;
457 $s->iw_trans = 0;
458 if ($value!='') {
459 list($local,$url)=explode(' ',$value,2);
460 $s->iw_url=$url;
461 $s->iw_local=(int)$local;
462 }
463 $wgTitleInterwikiCache[$wgDBname.':interwiki:'.$key] = $s;
464 return $s->iw_url;
465 }
466 /**
467 * Determine whether the object refers to a page within
468 * this project.
469 *
470 * @return bool TRUE if this is an in-project interwiki link
471 * or a wikilink, FALSE otherwise
472 * @access public
473 */
474 function isLocal() {
475 global $wgTitleInterwikiCache, $wgDBname;
476
477 if ( $this->mInterwiki != '' ) {
478 # Make sure key is loaded into cache
479 $this->getInterwikiLink( $this->mInterwiki );
480 $k = $wgDBname.':interwiki:' . $this->mInterwiki;
481 return (bool)($wgTitleInterwikiCache[$k]->iw_local);
482 } else {
483 return true;
484 }
485 }
486
487 /**
488 * Determine whether the object refers to a page within
489 * this project and is transcludable.
490 *
491 * @return bool TRUE if this is transcludable
492 * @access public
493 */
494 function isTrans() {
495 global $wgTitleInterwikiCache, $wgDBname;
496
497 if ($this->mInterwiki == '')
498 return false;
499 # Make sure key is loaded into cache
500 $this->getInterwikiLink( $this->mInterwiki );
501 $k = $wgDBname.':interwiki:' . $this->mInterwiki;
502 return (bool)($wgTitleInterwikiCache[$k]->iw_trans);
503 }
504
505 /**
506 * Update the page_touched field for an array of title objects
507 * @todo Inefficient unless the IDs are already loaded into the
508 * link cache
509 * @param array $titles an array of Title objects to be touched
510 * @param string $timestamp the timestamp to use instead of the
511 * default current time
512 * @static
513 * @access public
514 */
515 function touchArray( $titles, $timestamp = '' ) {
516
517 if ( count( $titles ) == 0 ) {
518 return;
519 }
520 $dbw =& wfGetDB( DB_MASTER );
521 if ( $timestamp == '' ) {
522 $timestamp = $dbw->timestamp();
523 }
524 /*
525 $page = $dbw->tableName( 'page' );
526 $sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";
527 $first = true;
528
529 foreach ( $titles as $title ) {
530 if ( $wgUseFileCache ) {
531 $cm = new CacheManager($title);
532 @unlink($cm->fileCacheName());
533 }
534
535 if ( ! $first ) {
536 $sql .= ',';
537 }
538 $first = false;
539 $sql .= $title->getArticleID();
540 }
541 $sql .= ')';
542 if ( ! $first ) {
543 $dbw->query( $sql, 'Title::touchArray' );
544 }
545 */
546 // hack hack hack -- brion 2005-07-11. this was unfriendly to db.
547 // do them in small chunks:
548 $fname = 'Title::touchArray';
549 foreach( $titles as $title ) {
550 $dbw->update( 'page',
551 array( 'page_touched' => $timestamp ),
552 array(
553 'page_namespace' => $title->getNamespace(),
554 'page_title' => $title->getDBkey() ),
555 $fname );
556 }
557 }
558
559 #----------------------------------------------------------------------------
560 # Other stuff
561 #----------------------------------------------------------------------------
562
563 /** Simple accessors */
564 /**
565 * Get the text form (spaces not underscores) of the main part
566 * @return string
567 * @access public
568 */
569 function getText() { return $this->mTextform; }
570 /**
571 * Get the URL-encoded form of the main part
572 * @return string
573 * @access public
574 */
575 function getPartialURL() { return $this->mUrlform; }
576 /**
577 * Get the main part with underscores
578 * @return string
579 * @access public
580 */
581 function getDBkey() { return $this->mDbkeyform; }
582 /**
583 * Get the namespace index, i.e. one of the NS_xxxx constants
584 * @return int
585 * @access public
586 */
587 function getNamespace() { return $this->mNamespace; }
588 /**
589 * Get the namespace text
590 * @return string
591 * @access public
592 */
593 function getNsText() {
594 global $wgContLang;
595 return $wgContLang->getNsText( $this->mNamespace );
596 }
597 /**
598 * Get the namespace text of the subject (rather than talk) page
599 * @return string
600 * @access public
601 */
602 function getSubjectNsText() {
603 global $wgContLang;
604 return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace ) );
605 }
606
607 /**
608 * Get the interwiki prefix (or null string)
609 * @return string
610 * @access public
611 */
612 function getInterwiki() { return $this->mInterwiki; }
613 /**
614 * Get the Title fragment (i.e. the bit after the #)
615 * @return string
616 * @access public
617 */
618 function getFragment() { return $this->mFragment; }
619 /**
620 * Get the default namespace index, for when there is no namespace
621 * @return int
622 * @access public
623 */
624 function getDefaultNamespace() { return $this->mDefaultNamespace; }
625
626 /**
627 * Get title for search index
628 * @return string a stripped-down title string ready for the
629 * search index
630 */
631 function getIndexTitle() {
632 return Title::indexTitle( $this->mNamespace, $this->mTextform );
633 }
634
635 /**
636 * Get the prefixed database key form
637 * @return string the prefixed title, with underscores and
638 * any interwiki and namespace prefixes
639 * @access public
640 */
641 function getPrefixedDBkey() {
642 $s = $this->prefix( $this->mDbkeyform );
643 $s = str_replace( ' ', '_', $s );
644 return $s;
645 }
646
647 /**
648 * Get the prefixed title with spaces.
649 * This is the form usually used for display
650 * @return string the prefixed title, with spaces
651 * @access public
652 */
653 function getPrefixedText() {
654 if ( empty( $this->mPrefixedText ) ) { // FIXME: bad usage of empty() ?
655 $s = $this->prefix( $this->mTextform );
656 $s = str_replace( '_', ' ', $s );
657 $this->mPrefixedText = $s;
658 }
659 return $this->mPrefixedText;
660 }
661
662 /**
663 * Get the prefixed title with spaces, plus any fragment
664 * (part beginning with '#')
665 * @return string the prefixed title, with spaces and
666 * the fragment, including '#'
667 * @access public
668 */
669 function getFullText() {
670 $text = $this->getPrefixedText();
671 if( '' != $this->mFragment ) {
672 $text .= '#' . $this->mFragment;
673 }
674 return $text;
675 }
676
677 /**
678 * Get the lowest-level subpage name, i.e. the rightmost part after /
679 * @return string Subpage name
680 */
681 function getSubpageText() {
682 global $wgNamespacesWithSubpages;
683 if( $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
684 $parts = explode( '/', $this->mTextform );
685 return( $parts[ count( $parts ) - 1 ] );
686 } else {
687 return( $this->mTextform );
688 }
689 }
690
691 /**
692 * Get a URL-encoded form of the subpage text
693 * @return string URL-encoded subpage name
694 */
695 function getSubpageUrlForm() {
696 $text = $this->getSubpageText();
697 $text = wfUrlencode( str_replace( ' ', '_', $text ) );
698 $text = str_replace( '%28', '(', str_replace( '%29', ')', $text ) ); # Clean up the URL; per below, this might not be safe
699 return( $text );
700 }
701
702 /**
703 * Get a URL-encoded title (not an actual URL) including interwiki
704 * @return string the URL-encoded form
705 * @access public
706 */
707 function getPrefixedURL() {
708 $s = $this->prefix( $this->mDbkeyform );
709 $s = str_replace( ' ', '_', $s );
710
711 $s = wfUrlencode ( $s ) ;
712
713 # Cleaning up URL to make it look nice -- is this safe?
714 $s = str_replace( '%28', '(', $s );
715 $s = str_replace( '%29', ')', $s );
716
717 return $s;
718 }
719
720 /**
721 * Get a real URL referring to this title, with interwiki link and
722 * fragment
723 *
724 * @param string $query an optional query string, not used
725 * for interwiki links
726 * @return string the URL
727 * @access public
728 */
729 function getFullURL( $query = '' ) {
730 global $wgContLang, $wgServer, $wgRequest;
731
732 if ( '' == $this->mInterwiki ) {
733 $url = $this->getLocalUrl( $query );
734
735 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
736 // Correct fix would be to move the prepending elsewhere.
737 if ($wgRequest->getVal('action') != 'render') {
738 $url = $wgServer . $url;
739 }
740 } else {
741 $baseUrl = $this->getInterwikiLink( $this->mInterwiki );
742
743 $namespace = $wgContLang->getNsText( $this->mNamespace );
744 if ( '' != $namespace ) {
745 # Can this actually happen? Interwikis shouldn't be parsed.
746 $namespace .= ':';
747 }
748 $url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );
749 if( $query != '' ) {
750 if( false === strpos( $url, '?' ) ) {
751 $url .= '?';
752 } else {
753 $url .= '&';
754 }
755 $url .= $query;
756 }
757 if ( '' != $this->mFragment ) {
758 $url .= '#' . $this->mFragment;
759 }
760 }
761 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
762 return $url;
763 }
764
765 /**
766 * Get a URL with no fragment or server name. If this page is generated
767 * with action=render, $wgServer is prepended.
768 * @param string $query an optional query string; if not specified,
769 * $wgArticlePath will be used.
770 * @return string the URL
771 * @access public
772 */
773 function getLocalURL( $query = '' ) {
774 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
775
776 if ( $this->isExternal() ) {
777 $url = $this->getFullURL();
778 if ( $query ) {
779 // This is currently only used for edit section links in the
780 // context of interwiki transclusion. In theory we should
781 // append the query to the end of any existing query string,
782 // but interwiki transclusion is already broken in that case.
783 $url .= "?$query";
784 }
785 } else {
786 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
787 if ( $query == '' ) {
788 $url = str_replace( '$1', $dbkey, $wgArticlePath );
789 } else {
790 global $wgActionPaths;
791 $url = false;
792 if( !empty( $wgActionPaths ) &&
793 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
794 {
795 $action = urldecode( $matches[2] );
796 if( isset( $wgActionPaths[$action] ) ) {
797 $query = $matches[1];
798 if( isset( $matches[4] ) ) $query .= $matches[4];
799 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
800 if( $query != '' ) $url .= '?' . $query;
801 }
802 }
803 if ( $url === false ) {
804 if ( $query == '-' ) {
805 $query = '';
806 }
807 $url = "{$wgScript}?title={$dbkey}&{$query}";
808 }
809 }
810
811 // FIXME: this causes breakage in various places when we
812 // actually expected a local URL and end up with dupe prefixes.
813 if ($wgRequest->getVal('action') == 'render') {
814 $url = $wgServer . $url;
815 }
816 }
817 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
818 return $url;
819 }
820
821 /**
822 * Get an HTML-escaped version of the URL form, suitable for
823 * using in a link, without a server name or fragment
824 * @param string $query an optional query string
825 * @return string the URL
826 * @access public
827 */
828 function escapeLocalURL( $query = '' ) {
829 return htmlspecialchars( $this->getLocalURL( $query ) );
830 }
831
832 /**
833 * Get an HTML-escaped version of the URL form, suitable for
834 * using in a link, including the server name and fragment
835 *
836 * @return string the URL
837 * @param string $query an optional query string
838 * @access public
839 */
840 function escapeFullURL( $query = '' ) {
841 return htmlspecialchars( $this->getFullURL( $query ) );
842 }
843
844 /**
845 * Get the URL form for an internal link.
846 * - Used in various Squid-related code, in case we have a different
847 * internal hostname for the server from the exposed one.
848 *
849 * @param string $query an optional query string
850 * @return string the URL
851 * @access public
852 */
853 function getInternalURL( $query = '' ) {
854 global $wgInternalServer;
855 $url = $wgInternalServer . $this->getLocalURL( $query );
856 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
857 return $url;
858 }
859
860 /**
861 * Get the edit URL for this Title
862 * @return string the URL, or a null string if this is an
863 * interwiki link
864 * @access public
865 */
866 function getEditURL() {
867 if ( '' != $this->mInterwiki ) { return ''; }
868 $s = $this->getLocalURL( 'action=edit' );
869
870 return $s;
871 }
872
873 /**
874 * Get the HTML-escaped displayable text form.
875 * Used for the title field in <a> tags.
876 * @return string the text, including any prefixes
877 * @access public
878 */
879 function getEscapedText() {
880 return htmlspecialchars( $this->getPrefixedText() );
881 }
882
883 /**
884 * Is this Title interwiki?
885 * @return boolean
886 * @access public
887 */
888 function isExternal() { return ( '' != $this->mInterwiki ); }
889
890 /**
891 * Is this page "semi-protected" - the *only* protection is autoconfirm?
892 *
893 * @param string Action to check (default: edit)
894 * @return bool
895 */
896 function isSemiProtected( $action = 'edit' ) {
897 $restrictions = $this->getRestrictions( $action );
898 # We do a full compare because this could be an array
899 foreach( $restrictions as $restriction ) {
900 if( strtolower( $restriction ) != 'autoconfirmed' ) {
901 return( false );
902 }
903 }
904 return( true );
905 }
906
907 /**
908 * Does the title correspond to a protected article?
909 * @param string $what the action the page is protected from,
910 * by default checks move and edit
911 * @return boolean
912 * @access public
913 */
914 function isProtected( $action = '' ) {
915 global $wgRestrictionLevels;
916 if ( -1 == $this->mNamespace ) { return true; }
917
918 if( $action == 'edit' || $action == '' ) {
919 $r = $this->getRestrictions( 'edit' );
920 foreach( $wgRestrictionLevels as $level ) {
921 if( in_array( $level, $r ) && $level != '' ) {
922 return( true );
923 }
924 }
925 }
926
927 if( $action == 'move' || $action == '' ) {
928 $r = $this->getRestrictions( 'move' );
929 foreach( $wgRestrictionLevels as $level ) {
930 if( in_array( $level, $r ) && $level != '' ) {
931 return( true );
932 }
933 }
934 }
935
936 return false;
937 }
938
939 /**
940 * Is $wgUser is watching this page?
941 * @return boolean
942 * @access public
943 */
944 function userIsWatching() {
945 global $wgUser;
946
947 if ( is_null( $this->mWatched ) ) {
948 if ( -1 == $this->mNamespace || 0 == $wgUser->getID()) {
949 $this->mWatched = false;
950 } else {
951 $this->mWatched = $wgUser->isWatched( $this );
952 }
953 }
954 return $this->mWatched;
955 }
956
957 /**
958 * Can $wgUser perform $action this page?
959 * @param string $action action that permission needs to be checked for
960 * @return boolean
961 * @access private
962 */
963 function userCan($action) {
964 $fname = 'Title::userCan';
965 wfProfileIn( $fname );
966
967 global $wgUser;
968
969 $result = true;
970 if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) ) ) {
971 wfProfileOut( $fname );
972 return $result;
973 }
974
975 if( NS_SPECIAL == $this->mNamespace ) {
976 wfProfileOut( $fname );
977 return false;
978 }
979 // XXX: This is the code that prevents unprotecting a page in NS_MEDIAWIKI
980 // from taking effect -ævar
981 if( NS_MEDIAWIKI == $this->mNamespace &&
982 !$wgUser->isAllowed('editinterface') ) {
983 wfProfileOut( $fname );
984 return false;
985 }
986
987 if( $this->mDbkeyform == '_' ) {
988 # FIXME: Is this necessary? Shouldn't be allowed anyway...
989 wfProfileOut( $fname );
990 return false;
991 }
992
993 # protect global styles and js
994 if ( NS_MEDIAWIKI == $this->mNamespace
995 && preg_match("/\\.(css|js)$/", $this->mTextform )
996 && !$wgUser->isAllowed('editinterface') ) {
997 wfProfileOut( $fname );
998 return false;
999 }
1000
1001 # protect css/js subpages of user pages
1002 # XXX: this might be better using restrictions
1003 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
1004 if( NS_USER == $this->mNamespace
1005 && preg_match("/\\.(css|js)$/", $this->mTextform )
1006 && !$wgUser->isAllowed('editinterface')
1007 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) {
1008 wfProfileOut( $fname );
1009 return false;
1010 }
1011
1012 foreach( $this->getRestrictions($action) as $right ) {
1013 // Backwards compatibility, rewrite sysop -> protect
1014 if ( $right == 'sysop' ) {
1015 $right = 'protect';
1016 }
1017 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1018 wfProfileOut( $fname );
1019 return false;
1020 }
1021 }
1022
1023 if( $action == 'move' &&
1024 !( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
1025 wfProfileOut( $fname );
1026 return false;
1027 }
1028
1029 if( $action == 'create' ) {
1030 if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
1031 ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
1032 return false;
1033 }
1034 }
1035
1036 wfProfileOut( $fname );
1037 return true;
1038 }
1039
1040 /**
1041 * Can $wgUser edit this page?
1042 * @return boolean
1043 * @access public
1044 */
1045 function userCanEdit() {
1046 return $this->userCan('edit');
1047 }
1048
1049 /**
1050 * Can $wgUser move this page?
1051 * @return boolean
1052 * @access public
1053 */
1054 function userCanMove() {
1055 return $this->userCan('move');
1056 }
1057
1058 /**
1059 * Would anybody with sufficient privileges be able to move this page?
1060 * Some pages just aren't movable.
1061 *
1062 * @return boolean
1063 * @access public
1064 */
1065 function isMovable() {
1066 return Namespace::isMovable( $this->getNamespace() )
1067 && $this->getInterwiki() == '';
1068 }
1069
1070 /**
1071 * Can $wgUser read this page?
1072 * @return boolean
1073 * @access public
1074 */
1075 function userCanRead() {
1076 global $wgUser;
1077
1078 $result = true;
1079 if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, "read", &$result ) ) ) {
1080 return $result;
1081 }
1082
1083 if( $wgUser->isAllowed('read') ) {
1084 return true;
1085 } else {
1086 global $wgWhitelistRead;
1087
1088 /** If anon users can create an account,
1089 they need to reach the login page first! */
1090 if( $wgUser->isAllowed( 'createaccount' )
1091 && $this->getNamespace() == NS_SPECIAL
1092 && $this->getText() == 'Userlogin' ) {
1093 return true;
1094 }
1095
1096 /** some pages are explicitly allowed */
1097 $name = $this->getPrefixedText();
1098 if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead ) ) {
1099 return true;
1100 }
1101
1102 # Compatibility with old settings
1103 if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN ) {
1104 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
1105 return true;
1106 }
1107 }
1108 }
1109 return false;
1110 }
1111
1112 /**
1113 * Is this a talk page of some sort?
1114 * @return bool
1115 * @access public
1116 */
1117 function isTalkPage() {
1118 return Namespace::isTalk( $this->getNamespace() );
1119 }
1120
1121 /**
1122 * Is this a .css or .js subpage of a user page?
1123 * @return bool
1124 * @access public
1125 */
1126 function isCssJsSubpage() {
1127 return ( NS_USER == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) );
1128 }
1129 /**
1130 * Is this a *valid* .css or .js subpage of a user page?
1131 * Check that the corresponding skin exists
1132 */
1133 function isValidCssJsSubpage() {
1134 global $wgValidSkinNames;
1135 return( $this->isCssJsSubpage() && array_key_exists( $this->getSkinFromCssJsSubpage(), $wgValidSkinNames ) );
1136 }
1137 /**
1138 * Trim down a .css or .js subpage title to get the corresponding skin name
1139 */
1140 function getSkinFromCssJsSubpage() {
1141 $subpage = explode( '/', $this->mTextform );
1142 $subpage = $subpage[ count( $subpage ) - 1 ];
1143 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1144 }
1145 /**
1146 * Is this a .css subpage of a user page?
1147 * @return bool
1148 * @access public
1149 */
1150 function isCssSubpage() {
1151 return ( NS_USER == $this->mNamespace and preg_match("/\\.css$/", $this->mTextform ) );
1152 }
1153 /**
1154 * Is this a .js subpage of a user page?
1155 * @return bool
1156 * @access public
1157 */
1158 function isJsSubpage() {
1159 return ( NS_USER == $this->mNamespace and preg_match("/\\.js$/", $this->mTextform ) );
1160 }
1161 /**
1162 * Protect css/js subpages of user pages: can $wgUser edit
1163 * this page?
1164 *
1165 * @return boolean
1166 * @todo XXX: this might be better using restrictions
1167 * @access public
1168 */
1169 function userCanEditCssJsSubpage() {
1170 global $wgUser;
1171 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
1172 }
1173
1174 /**
1175 * Loads a string into mRestrictions array
1176 * @param string $res restrictions in string format
1177 * @access public
1178 */
1179 function loadRestrictions( $res ) {
1180 foreach( explode( ':', trim( $res ) ) as $restrict ) {
1181 $temp = explode( '=', trim( $restrict ) );
1182 if(count($temp) == 1) {
1183 // old format should be treated as edit/move restriction
1184 $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
1185 $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
1186 } else {
1187 $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
1188 }
1189 }
1190 $this->mRestrictionsLoaded = true;
1191 }
1192
1193 /**
1194 * Accessor/initialisation for mRestrictions
1195 * @param string $action action that permission needs to be checked for
1196 * @return array the array of groups allowed to edit this article
1197 * @access public
1198 */
1199 function getRestrictions($action) {
1200 $id = $this->getArticleID();
1201 if ( 0 == $id ) { return array(); }
1202
1203 if ( ! $this->mRestrictionsLoaded ) {
1204 $dbr =& wfGetDB( DB_SLAVE );
1205 $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
1206 $this->loadRestrictions( $res );
1207 }
1208 if( isset( $this->mRestrictions[$action] ) ) {
1209 return $this->mRestrictions[$action];
1210 }
1211 return array();
1212 }
1213
1214 /**
1215 * Is there a version of this page in the deletion archive?
1216 * @return int the number of archived revisions
1217 * @access public
1218 */
1219 function isDeleted() {
1220 $fname = 'Title::isDeleted';
1221 if ( $this->getNamespace() < 0 ) {
1222 $n = 0;
1223 } else {
1224 $dbr =& wfGetDB( DB_SLAVE );
1225 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1226 'ar_title' => $this->getDBkey() ), $fname );
1227 }
1228 return (int)$n;
1229 }
1230
1231 /**
1232 * Get the article ID for this Title from the link cache,
1233 * adding it if necessary
1234 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1235 * for update
1236 * @return int the ID
1237 * @access public
1238 */
1239 function getArticleID( $flags = 0 ) {
1240 $linkCache =& LinkCache::singleton();
1241 if ( $flags & GAID_FOR_UPDATE ) {
1242 $oldUpdate = $linkCache->forUpdate( true );
1243 $this->mArticleID = $linkCache->addLinkObj( $this );
1244 $linkCache->forUpdate( $oldUpdate );
1245 } else {
1246 if ( -1 == $this->mArticleID ) {
1247 $this->mArticleID = $linkCache->addLinkObj( $this );
1248 }
1249 }
1250 return $this->mArticleID;
1251 }
1252
1253 function getLatestRevID() {
1254 if ($this->mLatestID !== false)
1255 return $this->mLatestID;
1256
1257 $db =& wfGetDB(DB_SLAVE);
1258 return $this->mLatestID = $db->selectField( 'revision',
1259 "max(rev_id)",
1260 array('rev_page' => $this->getArticleID()),
1261 'Title::getLatestRevID' );
1262 }
1263
1264 /**
1265 * This clears some fields in this object, and clears any associated
1266 * keys in the "bad links" section of the link cache.
1267 *
1268 * - This is called from Article::insertNewArticle() to allow
1269 * loading of the new page_id. It's also called from
1270 * Article::doDeleteArticle()
1271 *
1272 * @param int $newid the new Article ID
1273 * @access public
1274 */
1275 function resetArticleID( $newid ) {
1276 $linkCache =& LinkCache::singleton();
1277 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1278
1279 if ( 0 == $newid ) { $this->mArticleID = -1; }
1280 else { $this->mArticleID = $newid; }
1281 $this->mRestrictionsLoaded = false;
1282 $this->mRestrictions = array();
1283 }
1284
1285 /**
1286 * Updates page_touched for this page; called from LinksUpdate.php
1287 * @return bool true if the update succeded
1288 * @access public
1289 */
1290 function invalidateCache() {
1291 global $wgUseFileCache;
1292
1293 if ( wfReadOnly() ) {
1294 return;
1295 }
1296
1297 $dbw =& wfGetDB( DB_MASTER );
1298 $success = $dbw->update( 'page',
1299 array( /* SET */
1300 'page_touched' => $dbw->timestamp()
1301 ), array( /* WHERE */
1302 'page_namespace' => $this->getNamespace() ,
1303 'page_title' => $this->getDBkey()
1304 ), 'Title::invalidateCache'
1305 );
1306
1307 if ($wgUseFileCache) {
1308 $cache = new CacheManager($this);
1309 @unlink($cache->fileCacheName());
1310 }
1311
1312 return $success;
1313 }
1314
1315 /**
1316 * Prefix some arbitrary text with the namespace or interwiki prefix
1317 * of this object
1318 *
1319 * @param string $name the text
1320 * @return string the prefixed text
1321 * @access private
1322 */
1323 /* private */ function prefix( $name ) {
1324 global $wgContLang;
1325
1326 $p = '';
1327 if ( '' != $this->mInterwiki ) {
1328 $p = $this->mInterwiki . ':';
1329 }
1330 if ( 0 != $this->mNamespace ) {
1331 $p .= $wgContLang->getNsText( $this->mNamespace ) . ':';
1332 }
1333 return $p . $name;
1334 }
1335
1336 /**
1337 * Secure and split - main initialisation function for this object
1338 *
1339 * Assumes that mDbkeyform has been set, and is urldecoded
1340 * and uses underscores, but not otherwise munged. This function
1341 * removes illegal characters, splits off the interwiki and
1342 * namespace prefixes, sets the other forms, and canonicalizes
1343 * everything.
1344 * @return bool true on success
1345 * @access private
1346 */
1347 /* private */ function secureAndSplit() {
1348 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1349 $fname = 'Title::secureAndSplit';
1350
1351 # Initialisation
1352 static $rxTc = false;
1353 if( !$rxTc ) {
1354 # % is needed as well
1355 $rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1356 }
1357
1358 $this->mInterwiki = $this->mFragment = '';
1359 $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
1360
1361 # Clean up whitespace
1362 #
1363 $t = preg_replace( '/[ _]+/', '_', $this->mDbkeyform );
1364 $t = trim( $t, '_' );
1365
1366 if ( '' == $t ) {
1367 return false;
1368 }
1369
1370 if( false !== strpos( $t, UTF8_REPLACEMENT ) ) {
1371 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1372 return false;
1373 }
1374
1375 $this->mDbkeyform = $t;
1376
1377 # Initial colon indicates main namespace rather than specified default
1378 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
1379 if ( ':' == $t{0} ) {
1380 $this->mNamespace = NS_MAIN;
1381 $t = substr( $t, 1 ); # remove the colon but continue processing
1382 }
1383
1384 # Namespace or interwiki prefix
1385 $firstPass = true;
1386 do {
1387 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
1388 $p = $m[1];
1389 $lowerNs = strtolower( $p );
1390 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1391 # Canonical namespace
1392 $t = $m[2];
1393 $this->mNamespace = $ns;
1394 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1395 # Ordinary namespace
1396 $t = $m[2];
1397 $this->mNamespace = $ns;
1398 } elseif( $this->getInterwikiLink( $p ) ) {
1399 if( !$firstPass ) {
1400 # Can't make a local interwiki link to an interwiki link.
1401 # That's just crazy!
1402 return false;
1403 }
1404
1405 # Interwiki link
1406 $t = $m[2];
1407 $this->mInterwiki = strtolower( $p );
1408
1409 # Redundant interwiki prefix to the local wiki
1410 if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
1411 if( $t == '' ) {
1412 # Can't have an empty self-link
1413 return false;
1414 }
1415 $this->mInterwiki = '';
1416 $firstPass = false;
1417 # Do another namespace split...
1418 continue;
1419 }
1420
1421 # If there's an initial colon after the interwiki, that also
1422 # resets the default namespace
1423 if ( $t !== '' && $t[0] == ':' ) {
1424 $this->mNamespace = NS_MAIN;
1425 $t = substr( $t, 1 );
1426 }
1427 }
1428 # If there's no recognized interwiki or namespace,
1429 # then let the colon expression be part of the title.
1430 }
1431 break;
1432 } while( true );
1433 $r = $t;
1434
1435 # We already know that some pages won't be in the database!
1436 #
1437 if ( '' != $this->mInterwiki || -1 == $this->mNamespace ) {
1438 $this->mArticleID = 0;
1439 }
1440 $f = strstr( $r, '#' );
1441 if ( false !== $f ) {
1442 $this->mFragment = substr( $f, 1 );
1443 $r = substr( $r, 0, strlen( $r ) - strlen( $f ) );
1444 # remove whitespace again: prevents "Foo_bar_#"
1445 # becoming "Foo_bar_"
1446 $r = preg_replace( '/_*$/', '', $r );
1447 }
1448
1449 # Reject illegal characters.
1450 #
1451 if( preg_match( $rxTc, $r ) ) {
1452 return false;
1453 }
1454
1455 /**
1456 * Pages with "/./" or "/../" appearing in the URLs will
1457 * often be unreachable due to the way web browsers deal
1458 * with 'relative' URLs. Forbid them explicitly.
1459 */
1460 if ( strpos( $r, '.' ) !== false &&
1461 ( $r === '.' || $r === '..' ||
1462 strpos( $r, './' ) === 0 ||
1463 strpos( $r, '../' ) === 0 ||
1464 strpos( $r, '/./' ) !== false ||
1465 strpos( $r, '/../' ) !== false ) )
1466 {
1467 return false;
1468 }
1469
1470 # We shouldn't need to query the DB for the size.
1471 #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
1472 if ( strlen( $r ) > 255 ) {
1473 return false;
1474 }
1475
1476 /**
1477 * Normally, all wiki links are forced to have
1478 * an initial capital letter so [[foo]] and [[Foo]]
1479 * point to the same place.
1480 *
1481 * Don't force it for interwikis, since the other
1482 * site might be case-sensitive.
1483 */
1484 if( $wgCapitalLinks && $this->mInterwiki == '') {
1485 $t = $wgContLang->ucfirst( $r );
1486 } else {
1487 $t = $r;
1488 }
1489
1490 /**
1491 * Can't make a link to a namespace alone...
1492 * "empty" local links can only be self-links
1493 * with a fragment identifier.
1494 */
1495 if( $t == '' &&
1496 $this->mInterwiki == '' &&
1497 $this->mNamespace != NS_MAIN ) {
1498 return false;
1499 }
1500
1501 # Fill fields
1502 $this->mDbkeyform = $t;
1503 $this->mUrlform = wfUrlencode( $t );
1504
1505 $this->mTextform = str_replace( '_', ' ', $t );
1506
1507 return true;
1508 }
1509
1510 /**
1511 * Get a Title object associated with the talk page of this article
1512 * @return Title the object for the talk page
1513 * @access public
1514 */
1515 function getTalkPage() {
1516 return Title::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1517 }
1518
1519 /**
1520 * Get a title object associated with the subject page of this
1521 * talk page
1522 *
1523 * @return Title the object for the subject page
1524 * @access public
1525 */
1526 function getSubjectPage() {
1527 return Title::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1528 }
1529
1530 /**
1531 * Get an array of Title objects linking to this Title
1532 * Also stores the IDs in the link cache.
1533 *
1534 * @param string $options may be FOR UPDATE
1535 * @return array the Title objects linking here
1536 * @access public
1537 */
1538 function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
1539 $linkCache =& LinkCache::singleton();
1540 $id = $this->getArticleID();
1541
1542 if ( $options ) {
1543 $db =& wfGetDB( DB_MASTER );
1544 } else {
1545 $db =& wfGetDB( DB_SLAVE );
1546 }
1547
1548 $res = $db->select( array( 'page', $table ),
1549 array( 'page_namespace', 'page_title', 'page_id' ),
1550 array(
1551 "{$prefix}_from=page_id",
1552 "{$prefix}_namespace" => $this->getNamespace(),
1553 "{$prefix}_title" => $this->getDbKey() ),
1554 'Title::getLinksTo',
1555 $options );
1556
1557 $retVal = array();
1558 if ( $db->numRows( $res ) ) {
1559 while ( $row = $db->fetchObject( $res ) ) {
1560 if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
1561 $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
1562 $retVal[] = $titleObj;
1563 }
1564 }
1565 }
1566 $db->freeResult( $res );
1567 return $retVal;
1568 }
1569
1570 /**
1571 * Get an array of Title objects using this Title as a template
1572 * Also stores the IDs in the link cache.
1573 *
1574 * @param string $options may be FOR UPDATE
1575 * @return array the Title objects linking here
1576 * @access public
1577 */
1578 function getTemplateLinksTo( $options = '' ) {
1579 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
1580 }
1581
1582 /**
1583 * Get an array of Title objects referring to non-existent articles linked from this page
1584 *
1585 * @param string $options may be FOR UPDATE
1586 * @return array the Title objects
1587 * @access public
1588 */
1589 function getBrokenLinksFrom( $options = '' ) {
1590 if ( $options ) {
1591 $db =& wfGetDB( DB_MASTER );
1592 } else {
1593 $db =& wfGetDB( DB_SLAVE );
1594 }
1595
1596 $res = $db->safeQuery(
1597 "SELECT pl_namespace, pl_title
1598 FROM !
1599 LEFT JOIN !
1600 ON pl_namespace=page_namespace
1601 AND pl_title=page_title
1602 WHERE pl_from=?
1603 AND page_namespace IS NULL
1604 !",
1605 $db->tableName( 'pagelinks' ),
1606 $db->tableName( 'page' ),
1607 $this->getArticleId(),
1608 $options );
1609
1610 $retVal = array();
1611 if ( $db->numRows( $res ) ) {
1612 while ( $row = $db->fetchObject( $res ) ) {
1613 $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
1614 }
1615 }
1616 $db->freeResult( $res );
1617 return $retVal;
1618 }
1619
1620
1621 /**
1622 * Get a list of URLs to purge from the Squid cache when this
1623 * page changes
1624 *
1625 * @return array the URLs
1626 * @access public
1627 */
1628 function getSquidURLs() {
1629 return array(
1630 $this->getInternalURL(),
1631 $this->getInternalURL( 'action=history' )
1632 );
1633 }
1634
1635 /**
1636 * Move this page without authentication
1637 * @param Title &$nt the new page Title
1638 * @access public
1639 */
1640 function moveNoAuth( &$nt ) {
1641 return $this->moveTo( $nt, false );
1642 }
1643
1644 /**
1645 * Check whether a given move operation would be valid.
1646 * Returns true if ok, or a message key string for an error message
1647 * if invalid. (Scarrrrry ugly interface this.)
1648 * @param Title &$nt the new title
1649 * @param bool $auth indicates whether $wgUser's permissions
1650 * should be checked
1651 * @return mixed true on success, message name on failure
1652 * @access public
1653 */
1654 function isValidMoveOperation( &$nt, $auth = true ) {
1655 if( !$this or !$nt ) {
1656 return 'badtitletext';
1657 }
1658 if( $this->equals( $nt ) ) {
1659 return 'selfmove';
1660 }
1661 if( !$this->isMovable() || !$nt->isMovable() ) {
1662 return 'immobile_namespace';
1663 }
1664
1665 $oldid = $this->getArticleID();
1666 $newid = $nt->getArticleID();
1667
1668 if ( strlen( $nt->getDBkey() ) < 1 ) {
1669 return 'articleexists';
1670 }
1671 if ( ( '' == $this->getDBkey() ) ||
1672 ( !$oldid ) ||
1673 ( '' == $nt->getDBkey() ) ) {
1674 return 'badarticleerror';
1675 }
1676
1677 if ( $auth && (
1678 !$this->userCanEdit() || !$nt->userCanEdit() ||
1679 !$this->userCanMove() || !$nt->userCanMove() ) ) {
1680 return 'protectedpage';
1681 }
1682
1683 # The move is allowed only if (1) the target doesn't exist, or
1684 # (2) the target is a redirect to the source, and has no history
1685 # (so we can undo bad moves right after they're done).
1686
1687 if ( 0 != $newid ) { # Target exists; check for validity
1688 if ( ! $this->isValidMoveTarget( $nt ) ) {
1689 return 'articleexists';
1690 }
1691 }
1692 return true;
1693 }
1694
1695 /**
1696 * Move a title to a new location
1697 * @param Title &$nt the new title
1698 * @param bool $auth indicates whether $wgUser's permissions
1699 * should be checked
1700 * @return mixed true on success, message name on failure
1701 * @access public
1702 */
1703 function moveTo( &$nt, $auth = true, $reason = '' ) {
1704 $err = $this->isValidMoveOperation( $nt, $auth );
1705 if( is_string( $err ) ) {
1706 return $err;
1707 }
1708
1709 $pageid = $this->getArticleID();
1710 if( $nt->exists() ) {
1711 $this->moveOverExistingRedirect( $nt, $reason );
1712 $pageCountChange = 0;
1713 } else { # Target didn't exist, do normal move.
1714 $this->moveToNewTitle( $nt, $reason );
1715 $pageCountChange = 1;
1716 }
1717 $redirid = $this->getArticleID();
1718
1719 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
1720 $dbw =& wfGetDB( DB_MASTER );
1721 $categorylinks = $dbw->tableName( 'categorylinks' );
1722 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
1723 " WHERE cl_from=" . $dbw->addQuotes( $pageid ) .
1724 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
1725 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
1726
1727 # Update watchlists
1728
1729 $oldnamespace = $this->getNamespace() & ~1;
1730 $newnamespace = $nt->getNamespace() & ~1;
1731 $oldtitle = $this->getDBkey();
1732 $newtitle = $nt->getDBkey();
1733
1734 if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) {
1735 WatchedItem::duplicateEntries( $this, $nt );
1736 }
1737
1738 # Update search engine
1739 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
1740 $u->doUpdate();
1741 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
1742 $u->doUpdate();
1743
1744 # Update site_stats
1745 if ( $this->getNamespace() == NS_MAIN and $nt->getNamespace() != NS_MAIN ) {
1746 # Moved out of main namespace
1747 # not viewed, edited, removing
1748 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange);
1749 } elseif ( $this->getNamespace() != NS_MAIN and $nt->getNamespace() == NS_MAIN ) {
1750 # Moved into main namespace
1751 # not viewed, edited, adding
1752 $u = new SiteStatsUpdate( 0, 1, +1, $pageCountChange );
1753 } elseif ( $pageCountChange ) {
1754 # Added redirect
1755 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
1756 } else{
1757 $u = false;
1758 }
1759 if ( $u ) {
1760 $u->doUpdate();
1761 }
1762
1763 global $wgUser;
1764 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
1765 return true;
1766 }
1767
1768 /**
1769 * Move page to a title which is at present a redirect to the
1770 * source page
1771 *
1772 * @param Title &$nt the page to move to, which should currently
1773 * be a redirect
1774 * @access private
1775 */
1776 function moveOverExistingRedirect( &$nt, $reason = '' ) {
1777 global $wgUseSquid, $wgMwRedir;
1778 $fname = 'Title::moveOverExistingRedirect';
1779 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1780
1781 if ( $reason ) {
1782 $comment .= ": $reason";
1783 }
1784
1785 $now = wfTimestampNow();
1786 $rand = wfRandom();
1787 $newid = $nt->getArticleID();
1788 $oldid = $this->getArticleID();
1789 $dbw =& wfGetDB( DB_MASTER );
1790 $linkCache =& LinkCache::singleton();
1791
1792 # Delete the old redirect. We don't save it to history since
1793 # by definition if we've got here it's rather uninteresting.
1794 # We have to remove it so that the next step doesn't trigger
1795 # a conflict on the unique namespace+title index...
1796 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
1797
1798 # Save a null revision in the page's history notifying of the move
1799 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
1800 $nullRevId = $nullRevision->insertOn( $dbw );
1801
1802 # Change the name of the target page:
1803 $dbw->update( 'page',
1804 /* SET */ array(
1805 'page_touched' => $dbw->timestamp($now),
1806 'page_namespace' => $nt->getNamespace(),
1807 'page_title' => $nt->getDBkey(),
1808 'page_latest' => $nullRevId,
1809 ),
1810 /* WHERE */ array( 'page_id' => $oldid ),
1811 $fname
1812 );
1813 $linkCache->clearLink( $nt->getPrefixedDBkey() );
1814
1815 # Recreate the redirect, this time in the other direction.
1816 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1817 $redirectArticle = new Article( $this );
1818 $newid = $redirectArticle->insertOn( $dbw );
1819 $redirectRevision = new Revision( array(
1820 'page' => $newid,
1821 'comment' => $comment,
1822 'text' => $redirectText ) );
1823 $revid = $redirectRevision->insertOn( $dbw );
1824 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1825 $linkCache->clearLink( $this->getPrefixedDBkey() );
1826
1827 # Log the move
1828 $log = new LogPage( 'move' );
1829 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
1830
1831 # Now, we record the link from the redirect to the new title.
1832 # It should have no other outgoing links...
1833 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
1834 $dbw->insert( 'pagelinks',
1835 array(
1836 'pl_from' => $newid,
1837 'pl_namespace' => $nt->getNamespace(),
1838 'pl_title' => $nt->getDbKey() ),
1839 $fname );
1840
1841 # Purge squid
1842 if ( $wgUseSquid ) {
1843 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
1844 $u = new SquidUpdate( $urls );
1845 $u->doUpdate();
1846 }
1847 }
1848
1849 /**
1850 * Move page to non-existing title.
1851 * @param Title &$nt the new Title
1852 * @access private
1853 */
1854 function moveToNewTitle( &$nt, $reason = '' ) {
1855 global $wgUseSquid;
1856 global $wgMwRedir;
1857 $fname = 'MovePageForm::moveToNewTitle';
1858 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1859 if ( $reason ) {
1860 $comment .= ": $reason";
1861 }
1862
1863 $newid = $nt->getArticleID();
1864 $oldid = $this->getArticleID();
1865 $dbw =& wfGetDB( DB_MASTER );
1866 $now = $dbw->timestamp();
1867 $rand = wfRandom();
1868 $linkCache =& LinkCache::singleton();
1869
1870 # Save a null revision in the page's history notifying of the move
1871 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
1872 $nullRevId = $nullRevision->insertOn( $dbw );
1873
1874 # Rename cur entry
1875 $dbw->update( 'page',
1876 /* SET */ array(
1877 'page_touched' => $now,
1878 'page_namespace' => $nt->getNamespace(),
1879 'page_title' => $nt->getDBkey(),
1880 'page_latest' => $nullRevId,
1881 ),
1882 /* WHERE */ array( 'page_id' => $oldid ),
1883 $fname
1884 );
1885
1886 $linkCache->clearLink( $nt->getPrefixedDBkey() );
1887
1888 # Insert redirect
1889 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1890 $redirectArticle = new Article( $this );
1891 $newid = $redirectArticle->insertOn( $dbw );
1892 $redirectRevision = new Revision( array(
1893 'page' => $newid,
1894 'comment' => $comment,
1895 'text' => $redirectText ) );
1896 $revid = $redirectRevision->insertOn( $dbw );
1897 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1898 $linkCache->clearLink( $this->getPrefixedDBkey() );
1899
1900 # Log the move
1901 $log = new LogPage( 'move' );
1902 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
1903
1904 # Purge caches as per article creation
1905 Article::onArticleCreate( $nt );
1906
1907 # Record the just-created redirect's linking to the page
1908 $dbw->insert( 'pagelinks',
1909 array(
1910 'pl_from' => $newid,
1911 'pl_namespace' => $nt->getNamespace(),
1912 'pl_title' => $nt->getDBkey() ),
1913 $fname );
1914
1915 # Non-existent target may have had broken links to it; these must
1916 # now be touched to update link coloring.
1917 $nt->touchLinks();
1918
1919 # Purge old title from squid
1920 # The new title, and links to the new title, are purged in Article::onArticleCreate()
1921 $titles = $nt->getLinksTo();
1922 if ( $wgUseSquid ) {
1923 $urls = $this->getSquidURLs();
1924 foreach ( $titles as $linkTitle ) {
1925 $urls[] = $linkTitle->getInternalURL();
1926 }
1927 $u = new SquidUpdate( $urls );
1928 $u->doUpdate();
1929 }
1930 }
1931
1932 /**
1933 * Checks if $this can be moved to a given Title
1934 * - Selects for update, so don't call it unless you mean business
1935 *
1936 * @param Title &$nt the new title to check
1937 * @access public
1938 */
1939 function isValidMoveTarget( $nt ) {
1940
1941 $fname = 'Title::isValidMoveTarget';
1942 $dbw =& wfGetDB( DB_MASTER );
1943
1944 # Is it a redirect?
1945 $id = $nt->getArticleID();
1946 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
1947 array( 'page_is_redirect','old_text','old_flags' ),
1948 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
1949 $fname, 'FOR UPDATE' );
1950
1951 if ( !$obj || 0 == $obj->page_is_redirect ) {
1952 # Not a redirect
1953 return false;
1954 }
1955 $text = Revision::getRevisionText( $obj );
1956
1957 # Does the redirect point to the source?
1958 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
1959 $redirTitle = Title::newFromText( $m[1] );
1960 if( !is_object( $redirTitle ) ||
1961 $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
1962 return false;
1963 }
1964 } else {
1965 # Fail safe
1966 return false;
1967 }
1968
1969 # Does the article have a history?
1970 $row = $dbw->selectRow( array( 'page', 'revision'),
1971 array( 'rev_id' ),
1972 array( 'page_namespace' => $nt->getNamespace(),
1973 'page_title' => $nt->getDBkey(),
1974 'page_id=rev_page AND page_latest != rev_id'
1975 ), $fname, 'FOR UPDATE'
1976 );
1977
1978 # Return true if there was no history
1979 return $row === false;
1980 }
1981
1982 /**
1983 * Create a redirect; fails if the title already exists; does
1984 * not notify RC
1985 *
1986 * @param Title $dest the destination of the redirect
1987 * @param string $comment the comment string describing the move
1988 * @return bool true on success
1989 * @access public
1990 */
1991 function createRedirect( $dest, $comment ) {
1992 if ( $this->getArticleID() ) {
1993 return false;
1994 }
1995
1996 $fname = 'Title::createRedirect';
1997 $dbw =& wfGetDB( DB_MASTER );
1998
1999 $article = new Article( $this );
2000 $newid = $article->insertOn( $dbw );
2001 $revision = new Revision( array(
2002 'page' => $newid,
2003 'comment' => $comment,
2004 'text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n",
2005 ) );
2006 $revisionId = $revision->insertOn( $dbw );
2007 $article->updateRevisionOn( $dbw, $revision, 0 );
2008
2009 # Link table
2010 $dbw->insert( 'pagelinks',
2011 array(
2012 'pl_from' => $newid,
2013 'pl_namespace' => $dest->getNamespace(),
2014 'pl_title' => $dest->getDbKey()
2015 ), $fname
2016 );
2017
2018 Article::onArticleCreate( $this );
2019 return true;
2020 }
2021
2022 /**
2023 * Get categories to which this Title belongs and return an array of
2024 * categories' names.
2025 *
2026 * @return array an array of parents in the form:
2027 * $parent => $currentarticle
2028 * @access public
2029 */
2030 function getParentCategories() {
2031 global $wgContLang;
2032
2033 $titlekey = $this->getArticleId();
2034 $dbr =& wfGetDB( DB_SLAVE );
2035 $categorylinks = $dbr->tableName( 'categorylinks' );
2036
2037 # NEW SQL
2038 $sql = "SELECT * FROM $categorylinks"
2039 ." WHERE cl_from='$titlekey'"
2040 ." AND cl_from <> '0'"
2041 ." ORDER BY cl_sortkey";
2042
2043 $res = $dbr->query ( $sql ) ;
2044
2045 if($dbr->numRows($res) > 0) {
2046 while ( $x = $dbr->fetchObject ( $res ) )
2047 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2048 $data[$wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText();
2049 $dbr->freeResult ( $res ) ;
2050 } else {
2051 $data = '';
2052 }
2053 return $data;
2054 }
2055
2056 /**
2057 * Get a tree of parent categories
2058 * @param array $children an array with the children in the keys, to check for circular refs
2059 * @return array
2060 * @access public
2061 */
2062 function getParentCategoryTree( $children = array() ) {
2063 $parents = $this->getParentCategories();
2064
2065 if($parents != '') {
2066 foreach($parents as $parent => $current) {
2067 if ( array_key_exists( $parent, $children ) ) {
2068 # Circular reference
2069 $stack[$parent] = array();
2070 } else {
2071 $nt = Title::newFromText($parent);
2072 $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) );
2073 }
2074 }
2075 return $stack;
2076 } else {
2077 return array();
2078 }
2079 }
2080
2081
2082 /**
2083 * Get an associative array for selecting this title from
2084 * the "page" table
2085 *
2086 * @return array
2087 * @access public
2088 */
2089 function pageCond() {
2090 return array( 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform );
2091 }
2092
2093 /**
2094 * Get the revision ID of the previous revision
2095 *
2096 * @param integer $revision Revision ID. Get the revision that was before this one.
2097 * @return interger $oldrevision|false
2098 */
2099 function getPreviousRevisionID( $revision ) {
2100 $dbr =& wfGetDB( DB_SLAVE );
2101 return $dbr->selectField( 'revision', 'rev_id',
2102 'rev_page=' . intval( $this->getArticleId() ) .
2103 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
2104 }
2105
2106 /**
2107 * Get the revision ID of the next revision
2108 *
2109 * @param integer $revision Revision ID. Get the revision that was after this one.
2110 * @return interger $oldrevision|false
2111 */
2112 function getNextRevisionID( $revision ) {
2113 $dbr =& wfGetDB( DB_SLAVE );
2114 return $dbr->selectField( 'revision', 'rev_id',
2115 'rev_page=' . intval( $this->getArticleId() ) .
2116 ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
2117 }
2118
2119 /**
2120 * Compare with another title.
2121 *
2122 * @param Title $title
2123 * @return bool
2124 */
2125 function equals( $title ) {
2126 // Note: === is necessary for proper matching of number-like titles.
2127 return $this->getInterwiki() === $title->getInterwiki()
2128 && $this->getNamespace() == $title->getNamespace()
2129 && $this->getDbkey() === $title->getDbkey();
2130 }
2131
2132 /**
2133 * Check if page exists
2134 * @return bool
2135 */
2136 function exists() {
2137 return $this->getArticleId() != 0;
2138 }
2139
2140 /**
2141 * Should a link should be displayed as a known link, just based on its title?
2142 *
2143 * Currently, a self-link with a fragment and special pages are in
2144 * this category. Special pages never exist in the database.
2145 */
2146 function isAlwaysKnown() {
2147 return $this->isExternal() || ( 0 == $this->mNamespace && "" == $this->mDbkeyform )
2148 || NS_SPECIAL == $this->mNamespace;
2149 }
2150
2151 /**
2152 * Update page_touched timestamps on pages linking to this title.
2153 * In principal, this could be backgrounded and could also do squid
2154 * purging.
2155 */
2156 function touchLinks() {
2157 $fname = 'Title::touchLinks';
2158
2159 $dbw =& wfGetDB( DB_MASTER );
2160
2161 $res = $dbw->select( 'pagelinks',
2162 array( 'pl_from' ),
2163 array(
2164 'pl_namespace' => $this->getNamespace(),
2165 'pl_title' => $this->getDbKey() ),
2166 $fname );
2167
2168 $toucharr = array();
2169 while( $row = $dbw->fetchObject( $res ) ) {
2170 $toucharr[] = $row->pl_from;
2171 }
2172 $dbw->freeResult( $res );
2173
2174 if( $this->getNamespace() == NS_CATEGORY ) {
2175 // Categories show up in a separate set of links as well
2176 $res = $dbw->select( 'categorylinks',
2177 array( 'cl_from' ),
2178 array( 'cl_to' => $this->getDbKey() ),
2179 $fname );
2180 while( $row = $dbw->fetchObject( $res ) ) {
2181 $toucharr[] = $row->cl_from;
2182 }
2183 $dbw->freeResult( $res );
2184 }
2185
2186 if (!count($toucharr))
2187 return;
2188 $dbw->update( 'page', /* SET */ array( 'page_touched' => $dbw->timestamp() ),
2189 /* WHERE */ array( 'page_id' => $toucharr ),$fname);
2190 }
2191
2192 function trackbackURL() {
2193 global $wgTitle, $wgScriptPath, $wgServer;
2194
2195 return "$wgServer$wgScriptPath/trackback.php?article="
2196 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
2197 }
2198
2199 function trackbackRDF() {
2200 $url = htmlspecialchars($this->getFullURL());
2201 $title = htmlspecialchars($this->getText());
2202 $tburl = $this->trackbackURL();
2203
2204 return "
2205 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
2206 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
2207 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
2208 <rdf:Description
2209 rdf:about=\"$url\"
2210 dc:identifier=\"$url\"
2211 dc:title=\"$title\"
2212 trackback:ping=\"$tburl\" />
2213 </rdf:RDF>";
2214 }
2215
2216 /**
2217 * Generate strings used for xml 'id' names in monobook tabs
2218 * @return string
2219 */
2220 function getNamespaceKey() {
2221 switch ($this->getNamespace()) {
2222 case NS_MAIN:
2223 case NS_TALK:
2224 return 'nstab-main';
2225 case NS_USER:
2226 case NS_USER_TALK:
2227 return 'nstab-user';
2228 case NS_MEDIA:
2229 return 'nstab-media';
2230 case NS_SPECIAL:
2231 return 'nstab-special';
2232 case NS_PROJECT:
2233 case NS_PROJECT_TALK:
2234 return 'nstab-wp';
2235 case NS_IMAGE:
2236 case NS_IMAGE_TALK:
2237 return 'nstab-image';
2238 case NS_MEDIAWIKI:
2239 case NS_MEDIAWIKI_TALK:
2240 return 'nstab-mediawiki';
2241 case NS_TEMPLATE:
2242 case NS_TEMPLATE_TALK:
2243 return 'nstab-template';
2244 case NS_HELP:
2245 case NS_HELP_TALK:
2246 return 'nstab-help';
2247 case NS_CATEGORY:
2248 case NS_CATEGORY_TALK:
2249 return 'nstab-category';
2250 default:
2251 return 'nstab-' . strtolower( $this->getSubjectNsText() );
2252 }
2253 }
2254 }
2255 ?>