Live hack: Skip some work on empty category/link sets
[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 title (not an actual URL) including interwiki
693 * @return string the URL-encoded form
694 * @access public
695 */
696 function getPrefixedURL() {
697 $s = $this->prefix( $this->mDbkeyform );
698 $s = str_replace( ' ', '_', $s );
699
700 $s = wfUrlencode ( $s ) ;
701
702 # Cleaning up URL to make it look nice -- is this safe?
703 $s = str_replace( '%28', '(', $s );
704 $s = str_replace( '%29', ')', $s );
705
706 return $s;
707 }
708
709 /**
710 * Get a real URL referring to this title, with interwiki link and
711 * fragment
712 *
713 * @param string $query an optional query string, not used
714 * for interwiki links
715 * @return string the URL
716 * @access public
717 */
718 function getFullURL( $query = '' ) {
719 global $wgContLang, $wgServer, $wgRequest;
720
721 if ( '' == $this->mInterwiki ) {
722 $url = $this->getLocalUrl( $query );
723
724 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
725 // Correct fix would be to move the prepending elsewhere.
726 if ($wgRequest->getVal('action') != 'render') {
727 $url = $wgServer . $url;
728 }
729 } else {
730 $baseUrl = $this->getInterwikiLink( $this->mInterwiki );
731
732 $namespace = $wgContLang->getNsText( $this->mNamespace );
733 if ( '' != $namespace ) {
734 # Can this actually happen? Interwikis shouldn't be parsed.
735 $namespace .= ':';
736 }
737 $url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );
738 if( $query != '' ) {
739 if( false === strpos( $url, '?' ) ) {
740 $url .= '?';
741 } else {
742 $url .= '&';
743 }
744 $url .= $query;
745 }
746 if ( '' != $this->mFragment ) {
747 $url .= '#' . $this->mFragment;
748 }
749 }
750 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
751 return $url;
752 }
753
754 /**
755 * Get a URL with no fragment or server name. If this page is generated
756 * with action=render, $wgServer is prepended.
757 * @param string $query an optional query string; if not specified,
758 * $wgArticlePath will be used.
759 * @return string the URL
760 * @access public
761 */
762 function getLocalURL( $query = '' ) {
763 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
764
765 if ( $this->isExternal() ) {
766 $url = $this->getFullURL();
767 if ( $query ) {
768 // This is currently only used for edit section links in the
769 // context of interwiki transclusion. In theory we should
770 // append the query to the end of any existing query string,
771 // but interwiki transclusion is already broken in that case.
772 $url .= "?$query";
773 }
774 } else {
775 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
776 if ( $query == '' ) {
777 $url = str_replace( '$1', $dbkey, $wgArticlePath );
778 } else {
779 global $wgActionPaths;
780 $url = false;
781 if( !empty( $wgActionPaths ) &&
782 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
783 {
784 $action = urldecode( $matches[2] );
785 if( isset( $wgActionPaths[$action] ) ) {
786 $query = $matches[1];
787 if( isset( $matches[4] ) ) $query .= $matches[4];
788 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
789 if( $query != '' ) $url .= '?' . $query;
790 }
791 }
792 if ( $url === false ) {
793 if ( $query == '-' ) {
794 $query = '';
795 }
796 $url = "{$wgScript}?title={$dbkey}&{$query}";
797 }
798 }
799
800 // FIXME: this causes breakage in various places when we
801 // actually expected a local URL and end up with dupe prefixes.
802 if ($wgRequest->getVal('action') == 'render') {
803 $url = $wgServer . $url;
804 }
805 }
806 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
807 return $url;
808 }
809
810 /**
811 * Get an HTML-escaped version of the URL form, suitable for
812 * using in a link, without a server name or fragment
813 * @param string $query an optional query string
814 * @return string the URL
815 * @access public
816 */
817 function escapeLocalURL( $query = '' ) {
818 return htmlspecialchars( $this->getLocalURL( $query ) );
819 }
820
821 /**
822 * Get an HTML-escaped version of the URL form, suitable for
823 * using in a link, including the server name and fragment
824 *
825 * @return string the URL
826 * @param string $query an optional query string
827 * @access public
828 */
829 function escapeFullURL( $query = '' ) {
830 return htmlspecialchars( $this->getFullURL( $query ) );
831 }
832
833 /**
834 * Get the URL form for an internal link.
835 * - Used in various Squid-related code, in case we have a different
836 * internal hostname for the server from the exposed one.
837 *
838 * @param string $query an optional query string
839 * @return string the URL
840 * @access public
841 */
842 function getInternalURL( $query = '' ) {
843 global $wgInternalServer;
844 $url = $wgInternalServer . $this->getLocalURL( $query );
845 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
846 return $url;
847 }
848
849 /**
850 * Get the edit URL for this Title
851 * @return string the URL, or a null string if this is an
852 * interwiki link
853 * @access public
854 */
855 function getEditURL() {
856 if ( '' != $this->mInterwiki ) { return ''; }
857 $s = $this->getLocalURL( 'action=edit' );
858
859 return $s;
860 }
861
862 /**
863 * Get the HTML-escaped displayable text form.
864 * Used for the title field in <a> tags.
865 * @return string the text, including any prefixes
866 * @access public
867 */
868 function getEscapedText() {
869 return htmlspecialchars( $this->getPrefixedText() );
870 }
871
872 /**
873 * Is this Title interwiki?
874 * @return boolean
875 * @access public
876 */
877 function isExternal() { return ( '' != $this->mInterwiki ); }
878
879 /**
880 * Is this page "semi-protected" - the *only* protection is autoconfirm?
881 *
882 * @param string Action to check (default: edit)
883 * @return bool
884 */
885 function isSemiProtected( $action = 'edit' ) {
886 $restrictions = $this->getRestrictions( $action );
887 # We do a full compare because this could be an array
888 foreach( $restrictions as $restriction ) {
889 if( strtolower( $restriction ) != 'autoconfirmed' ) {
890 return( false );
891 }
892 }
893 return( true );
894 }
895
896 /**
897 * Does the title correspond to a protected article?
898 * @param string $what the action the page is protected from,
899 * by default checks move and edit
900 * @return boolean
901 * @access public
902 */
903 function isProtected( $action = '' ) {
904 global $wgRestrictionLevels;
905 if ( -1 == $this->mNamespace ) { return true; }
906
907 if( $action == 'edit' || $action == '' ) {
908 $r = $this->getRestrictions( 'edit' );
909 foreach( $wgRestrictionLevels as $level ) {
910 if( in_array( $level, $r ) && $level != '' ) {
911 return( true );
912 }
913 }
914 }
915
916 if( $action == 'move' || $action == '' ) {
917 $r = $this->getRestrictions( 'move' );
918 foreach( $wgRestrictionLevels as $level ) {
919 if( in_array( $level, $r ) && $level != '' ) {
920 return( true );
921 }
922 }
923 }
924
925 return false;
926 }
927
928 /**
929 * Is $wgUser is watching this page?
930 * @return boolean
931 * @access public
932 */
933 function userIsWatching() {
934 global $wgUser;
935
936 if ( is_null( $this->mWatched ) ) {
937 if ( -1 == $this->mNamespace || 0 == $wgUser->getID()) {
938 $this->mWatched = false;
939 } else {
940 $this->mWatched = $wgUser->isWatched( $this );
941 }
942 }
943 return $this->mWatched;
944 }
945
946 /**
947 * Can $wgUser perform $action this page?
948 * @param string $action action that permission needs to be checked for
949 * @return boolean
950 * @access private
951 */
952 function userCan($action) {
953 $fname = 'Title::userCan';
954 wfProfileIn( $fname );
955
956 global $wgUser;
957
958 $result = true;
959 if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) ) ) {
960 wfProfileOut( $fname );
961 return $result;
962 }
963
964 if( NS_SPECIAL == $this->mNamespace ) {
965 wfProfileOut( $fname );
966 return false;
967 }
968 // XXX: This is the code that prevents unprotecting a page in NS_MEDIAWIKI
969 // from taking effect -ævar
970 if( NS_MEDIAWIKI == $this->mNamespace &&
971 !$wgUser->isAllowed('editinterface') ) {
972 wfProfileOut( $fname );
973 return false;
974 }
975
976 if( $this->mDbkeyform == '_' ) {
977 # FIXME: Is this necessary? Shouldn't be allowed anyway...
978 wfProfileOut( $fname );
979 return false;
980 }
981
982 # protect global styles and js
983 if ( NS_MEDIAWIKI == $this->mNamespace
984 && preg_match("/\\.(css|js)$/", $this->mTextform )
985 && !$wgUser->isAllowed('editinterface') ) {
986 wfProfileOut( $fname );
987 return false;
988 }
989
990 # protect css/js subpages of user pages
991 # XXX: this might be better using restrictions
992 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
993 if( NS_USER == $this->mNamespace
994 && preg_match("/\\.(css|js)$/", $this->mTextform )
995 && !$wgUser->isAllowed('editinterface')
996 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) {
997 wfProfileOut( $fname );
998 return false;
999 }
1000
1001 foreach( $this->getRestrictions($action) as $right ) {
1002 // Backwards compatibility, rewrite sysop -> protect
1003 if ( $right == 'sysop' ) {
1004 $right = 'protect';
1005 }
1006 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1007 wfProfileOut( $fname );
1008 return false;
1009 }
1010 }
1011
1012 if( $action == 'move' &&
1013 !( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
1014 wfProfileOut( $fname );
1015 return false;
1016 }
1017
1018 if( $action == 'create' ) {
1019 if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
1020 ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
1021 return false;
1022 }
1023 }
1024
1025 wfProfileOut( $fname );
1026 return true;
1027 }
1028
1029 /**
1030 * Can $wgUser edit this page?
1031 * @return boolean
1032 * @access public
1033 */
1034 function userCanEdit() {
1035 return $this->userCan('edit');
1036 }
1037
1038 /**
1039 * Can $wgUser move this page?
1040 * @return boolean
1041 * @access public
1042 */
1043 function userCanMove() {
1044 return $this->userCan('move');
1045 }
1046
1047 /**
1048 * Would anybody with sufficient privileges be able to move this page?
1049 * Some pages just aren't movable.
1050 *
1051 * @return boolean
1052 * @access public
1053 */
1054 function isMovable() {
1055 return Namespace::isMovable( $this->getNamespace() )
1056 && $this->getInterwiki() == '';
1057 }
1058
1059 /**
1060 * Can $wgUser read this page?
1061 * @return boolean
1062 * @access public
1063 */
1064 function userCanRead() {
1065 global $wgUser;
1066
1067 $result = true;
1068 if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, "read", &$result ) ) ) {
1069 return $result;
1070 }
1071
1072 if( $wgUser->isAllowed('read') ) {
1073 return true;
1074 } else {
1075 global $wgWhitelistRead;
1076
1077 /** If anon users can create an account,
1078 they need to reach the login page first! */
1079 if( $wgUser->isAllowed( 'createaccount' )
1080 && $this->getNamespace() == NS_SPECIAL
1081 && $this->getText() == 'Userlogin' ) {
1082 return true;
1083 }
1084
1085 /** some pages are explicitly allowed */
1086 $name = $this->getPrefixedText();
1087 if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead ) ) {
1088 return true;
1089 }
1090
1091 # Compatibility with old settings
1092 if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN ) {
1093 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
1094 return true;
1095 }
1096 }
1097 }
1098 return false;
1099 }
1100
1101 /**
1102 * Is this a talk page of some sort?
1103 * @return bool
1104 * @access public
1105 */
1106 function isTalkPage() {
1107 return Namespace::isTalk( $this->getNamespace() );
1108 }
1109
1110 /**
1111 * Is this a .css or .js subpage of a user page?
1112 * @return bool
1113 * @access public
1114 */
1115 function isCssJsSubpage() {
1116 return ( NS_USER == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) );
1117 }
1118 /**
1119 * Is this a *valid* .css or .js subpage of a user page?
1120 * Check that the corresponding skin exists
1121 */
1122 function isValidCssJsSubpage() {
1123 global $wgValidSkinNames;
1124 return( $this->isCssJsSubpage() && array_key_exists( $this->getSkinFromCssJsSubpage(), $wgValidSkinNames ) );
1125 }
1126 /**
1127 * Trim down a .css or .js subpage title to get the corresponding skin name
1128 */
1129 function getSkinFromCssJsSubpage() {
1130 $subpage = explode( '/', $this->mTextform );
1131 $subpage = $subpage[ count( $subpage ) - 1 ];
1132 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1133 }
1134 /**
1135 * Is this a .css subpage of a user page?
1136 * @return bool
1137 * @access public
1138 */
1139 function isCssSubpage() {
1140 return ( NS_USER == $this->mNamespace and preg_match("/\\.css$/", $this->mTextform ) );
1141 }
1142 /**
1143 * Is this a .js subpage of a user page?
1144 * @return bool
1145 * @access public
1146 */
1147 function isJsSubpage() {
1148 return ( NS_USER == $this->mNamespace and preg_match("/\\.js$/", $this->mTextform ) );
1149 }
1150 /**
1151 * Protect css/js subpages of user pages: can $wgUser edit
1152 * this page?
1153 *
1154 * @return boolean
1155 * @todo XXX: this might be better using restrictions
1156 * @access public
1157 */
1158 function userCanEditCssJsSubpage() {
1159 global $wgUser;
1160 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
1161 }
1162
1163 /**
1164 * Loads a string into mRestrictions array
1165 * @param string $res restrictions in string format
1166 * @access public
1167 */
1168 function loadRestrictions( $res ) {
1169 foreach( explode( ':', trim( $res ) ) as $restrict ) {
1170 $temp = explode( '=', trim( $restrict ) );
1171 if(count($temp) == 1) {
1172 // old format should be treated as edit/move restriction
1173 $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
1174 $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
1175 } else {
1176 $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
1177 }
1178 }
1179 $this->mRestrictionsLoaded = true;
1180 }
1181
1182 /**
1183 * Accessor/initialisation for mRestrictions
1184 * @param string $action action that permission needs to be checked for
1185 * @return array the array of groups allowed to edit this article
1186 * @access public
1187 */
1188 function getRestrictions($action) {
1189 $id = $this->getArticleID();
1190 if ( 0 == $id ) { return array(); }
1191
1192 if ( ! $this->mRestrictionsLoaded ) {
1193 $dbr =& wfGetDB( DB_SLAVE );
1194 $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
1195 $this->loadRestrictions( $res );
1196 }
1197 if( isset( $this->mRestrictions[$action] ) ) {
1198 return $this->mRestrictions[$action];
1199 }
1200 return array();
1201 }
1202
1203 /**
1204 * Is there a version of this page in the deletion archive?
1205 * @return int the number of archived revisions
1206 * @access public
1207 */
1208 function isDeleted() {
1209 $fname = 'Title::isDeleted';
1210 if ( $this->getNamespace() < 0 ) {
1211 $n = 0;
1212 } else {
1213 $dbr =& wfGetDB( DB_SLAVE );
1214 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1215 'ar_title' => $this->getDBkey() ), $fname );
1216 }
1217 return (int)$n;
1218 }
1219
1220 /**
1221 * Get the article ID for this Title from the link cache,
1222 * adding it if necessary
1223 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1224 * for update
1225 * @return int the ID
1226 * @access public
1227 */
1228 function getArticleID( $flags = 0 ) {
1229 $linkCache =& LinkCache::singleton();
1230 if ( $flags & GAID_FOR_UPDATE ) {
1231 $oldUpdate = $linkCache->forUpdate( true );
1232 $this->mArticleID = $linkCache->addLinkObj( $this );
1233 $linkCache->forUpdate( $oldUpdate );
1234 } else {
1235 if ( -1 == $this->mArticleID ) {
1236 $this->mArticleID = $linkCache->addLinkObj( $this );
1237 }
1238 }
1239 return $this->mArticleID;
1240 }
1241
1242 function getLatestRevID() {
1243 if ($this->mLatestID !== false)
1244 return $this->mLatestID;
1245
1246 $db =& wfGetDB(DB_SLAVE);
1247 return $this->mLatestID = $db->selectField( 'revision',
1248 "max(rev_id)",
1249 array('rev_page' => $this->getArticleID()),
1250 'Title::getLatestRevID' );
1251 }
1252
1253 /**
1254 * This clears some fields in this object, and clears any associated
1255 * keys in the "bad links" section of the link cache.
1256 *
1257 * - This is called from Article::insertNewArticle() to allow
1258 * loading of the new page_id. It's also called from
1259 * Article::doDeleteArticle()
1260 *
1261 * @param int $newid the new Article ID
1262 * @access public
1263 */
1264 function resetArticleID( $newid ) {
1265 $linkCache =& LinkCache::singleton();
1266 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1267
1268 if ( 0 == $newid ) { $this->mArticleID = -1; }
1269 else { $this->mArticleID = $newid; }
1270 $this->mRestrictionsLoaded = false;
1271 $this->mRestrictions = array();
1272 }
1273
1274 /**
1275 * Updates page_touched for this page; called from LinksUpdate.php
1276 * @return bool true if the update succeded
1277 * @access public
1278 */
1279 function invalidateCache() {
1280 global $wgUseFileCache;
1281
1282 if ( wfReadOnly() ) {
1283 return;
1284 }
1285
1286 $dbw =& wfGetDB( DB_MASTER );
1287 $success = $dbw->update( 'page',
1288 array( /* SET */
1289 'page_touched' => $dbw->timestamp()
1290 ), array( /* WHERE */
1291 'page_namespace' => $this->getNamespace() ,
1292 'page_title' => $this->getDBkey()
1293 ), 'Title::invalidateCache'
1294 );
1295
1296 if ($wgUseFileCache) {
1297 $cache = new CacheManager($this);
1298 @unlink($cache->fileCacheName());
1299 }
1300
1301 return $success;
1302 }
1303
1304 /**
1305 * Prefix some arbitrary text with the namespace or interwiki prefix
1306 * of this object
1307 *
1308 * @param string $name the text
1309 * @return string the prefixed text
1310 * @access private
1311 */
1312 /* private */ function prefix( $name ) {
1313 global $wgContLang;
1314
1315 $p = '';
1316 if ( '' != $this->mInterwiki ) {
1317 $p = $this->mInterwiki . ':';
1318 }
1319 if ( 0 != $this->mNamespace ) {
1320 $p .= $wgContLang->getNsText( $this->mNamespace ) . ':';
1321 }
1322 return $p . $name;
1323 }
1324
1325 /**
1326 * Secure and split - main initialisation function for this object
1327 *
1328 * Assumes that mDbkeyform has been set, and is urldecoded
1329 * and uses underscores, but not otherwise munged. This function
1330 * removes illegal characters, splits off the interwiki and
1331 * namespace prefixes, sets the other forms, and canonicalizes
1332 * everything.
1333 * @return bool true on success
1334 * @access private
1335 */
1336 /* private */ function secureAndSplit() {
1337 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1338 $fname = 'Title::secureAndSplit';
1339
1340 # Initialisation
1341 static $rxTc = false;
1342 if( !$rxTc ) {
1343 # % is needed as well
1344 $rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1345 }
1346
1347 $this->mInterwiki = $this->mFragment = '';
1348 $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
1349
1350 # Clean up whitespace
1351 #
1352 $t = preg_replace( '/[ _]+/', '_', $this->mDbkeyform );
1353 $t = trim( $t, '_' );
1354
1355 if ( '' == $t ) {
1356 return false;
1357 }
1358
1359 if( false !== strpos( $t, UTF8_REPLACEMENT ) ) {
1360 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1361 return false;
1362 }
1363
1364 $this->mDbkeyform = $t;
1365
1366 # Initial colon indicates main namespace rather than specified default
1367 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
1368 if ( ':' == $t{0} ) {
1369 $this->mNamespace = NS_MAIN;
1370 $t = substr( $t, 1 ); # remove the colon but continue processing
1371 }
1372
1373 # Namespace or interwiki prefix
1374 $firstPass = true;
1375 do {
1376 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
1377 $p = $m[1];
1378 $lowerNs = strtolower( $p );
1379 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1380 # Canonical namespace
1381 $t = $m[2];
1382 $this->mNamespace = $ns;
1383 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1384 # Ordinary namespace
1385 $t = $m[2];
1386 $this->mNamespace = $ns;
1387 } elseif( $this->getInterwikiLink( $p ) ) {
1388 if( !$firstPass ) {
1389 # Can't make a local interwiki link to an interwiki link.
1390 # That's just crazy!
1391 return false;
1392 }
1393
1394 # Interwiki link
1395 $t = $m[2];
1396 $this->mInterwiki = strtolower( $p );
1397
1398 # Redundant interwiki prefix to the local wiki
1399 if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
1400 if( $t == '' ) {
1401 # Can't have an empty self-link
1402 return false;
1403 }
1404 $this->mInterwiki = '';
1405 $firstPass = false;
1406 # Do another namespace split...
1407 continue;
1408 }
1409
1410 # If there's an initial colon after the interwiki, that also
1411 # resets the default namespace
1412 if ( $t !== '' && $t[0] == ':' ) {
1413 $this->mNamespace = NS_MAIN;
1414 $t = substr( $t, 1 );
1415 }
1416 }
1417 # If there's no recognized interwiki or namespace,
1418 # then let the colon expression be part of the title.
1419 }
1420 break;
1421 } while( true );
1422 $r = $t;
1423
1424 # We already know that some pages won't be in the database!
1425 #
1426 if ( '' != $this->mInterwiki || -1 == $this->mNamespace ) {
1427 $this->mArticleID = 0;
1428 }
1429 $f = strstr( $r, '#' );
1430 if ( false !== $f ) {
1431 $this->mFragment = substr( $f, 1 );
1432 $r = substr( $r, 0, strlen( $r ) - strlen( $f ) );
1433 # remove whitespace again: prevents "Foo_bar_#"
1434 # becoming "Foo_bar_"
1435 $r = preg_replace( '/_*$/', '', $r );
1436 }
1437
1438 # Reject illegal characters.
1439 #
1440 if( preg_match( $rxTc, $r ) ) {
1441 return false;
1442 }
1443
1444 /**
1445 * Pages with "/./" or "/../" appearing in the URLs will
1446 * often be unreachable due to the way web browsers deal
1447 * with 'relative' URLs. Forbid them explicitly.
1448 */
1449 if ( strpos( $r, '.' ) !== false &&
1450 ( $r === '.' || $r === '..' ||
1451 strpos( $r, './' ) === 0 ||
1452 strpos( $r, '../' ) === 0 ||
1453 strpos( $r, '/./' ) !== false ||
1454 strpos( $r, '/../' ) !== false ) )
1455 {
1456 return false;
1457 }
1458
1459 # We shouldn't need to query the DB for the size.
1460 #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
1461 if ( strlen( $r ) > 255 ) {
1462 return false;
1463 }
1464
1465 /**
1466 * Normally, all wiki links are forced to have
1467 * an initial capital letter so [[foo]] and [[Foo]]
1468 * point to the same place.
1469 *
1470 * Don't force it for interwikis, since the other
1471 * site might be case-sensitive.
1472 */
1473 if( $wgCapitalLinks && $this->mInterwiki == '') {
1474 $t = $wgContLang->ucfirst( $r );
1475 } else {
1476 $t = $r;
1477 }
1478
1479 /**
1480 * Can't make a link to a namespace alone...
1481 * "empty" local links can only be self-links
1482 * with a fragment identifier.
1483 */
1484 if( $t == '' &&
1485 $this->mInterwiki == '' &&
1486 $this->mNamespace != NS_MAIN ) {
1487 return false;
1488 }
1489
1490 # Fill fields
1491 $this->mDbkeyform = $t;
1492 $this->mUrlform = wfUrlencode( $t );
1493
1494 $this->mTextform = str_replace( '_', ' ', $t );
1495
1496 return true;
1497 }
1498
1499 /**
1500 * Get a Title object associated with the talk page of this article
1501 * @return Title the object for the talk page
1502 * @access public
1503 */
1504 function getTalkPage() {
1505 return Title::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1506 }
1507
1508 /**
1509 * Get a title object associated with the subject page of this
1510 * talk page
1511 *
1512 * @return Title the object for the subject page
1513 * @access public
1514 */
1515 function getSubjectPage() {
1516 return Title::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1517 }
1518
1519 /**
1520 * Get an array of Title objects linking to this Title
1521 * Also stores the IDs in the link cache.
1522 *
1523 * @param string $options may be FOR UPDATE
1524 * @return array the Title objects linking here
1525 * @access public
1526 */
1527 function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
1528 $linkCache =& LinkCache::singleton();
1529 $id = $this->getArticleID();
1530
1531 if ( $options ) {
1532 $db =& wfGetDB( DB_MASTER );
1533 } else {
1534 $db =& wfGetDB( DB_SLAVE );
1535 }
1536
1537 $res = $db->select( array( 'page', $table ),
1538 array( 'page_namespace', 'page_title', 'page_id' ),
1539 array(
1540 "{$prefix}_from=page_id",
1541 "{$prefix}_namespace" => $this->getNamespace(),
1542 "{$prefix}_title" => $this->getDbKey() ),
1543 'Title::getLinksTo',
1544 $options );
1545
1546 $retVal = array();
1547 if ( $db->numRows( $res ) ) {
1548 while ( $row = $db->fetchObject( $res ) ) {
1549 if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
1550 $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
1551 $retVal[] = $titleObj;
1552 }
1553 }
1554 }
1555 $db->freeResult( $res );
1556 return $retVal;
1557 }
1558
1559 /**
1560 * Get an array of Title objects using this Title as a template
1561 * Also stores the IDs in the link cache.
1562 *
1563 * @param string $options may be FOR UPDATE
1564 * @return array the Title objects linking here
1565 * @access public
1566 */
1567 function getTemplateLinksTo( $options = '' ) {
1568 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
1569 }
1570
1571 /**
1572 * Get an array of Title objects referring to non-existent articles linked from this page
1573 *
1574 * @param string $options may be FOR UPDATE
1575 * @return array the Title objects
1576 * @access public
1577 */
1578 function getBrokenLinksFrom( $options = '' ) {
1579 if ( $options ) {
1580 $db =& wfGetDB( DB_MASTER );
1581 } else {
1582 $db =& wfGetDB( DB_SLAVE );
1583 }
1584
1585 $res = $db->safeQuery(
1586 "SELECT pl_namespace, pl_title
1587 FROM !
1588 LEFT JOIN !
1589 ON pl_namespace=page_namespace
1590 AND pl_title=page_title
1591 WHERE pl_from=?
1592 AND page_namespace IS NULL
1593 !",
1594 $db->tableName( 'pagelinks' ),
1595 $db->tableName( 'page' ),
1596 $this->getArticleId(),
1597 $options );
1598
1599 $retVal = array();
1600 if ( $db->numRows( $res ) ) {
1601 while ( $row = $db->fetchObject( $res ) ) {
1602 $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
1603 }
1604 }
1605 $db->freeResult( $res );
1606 return $retVal;
1607 }
1608
1609
1610 /**
1611 * Get a list of URLs to purge from the Squid cache when this
1612 * page changes
1613 *
1614 * @return array the URLs
1615 * @access public
1616 */
1617 function getSquidURLs() {
1618 return array(
1619 $this->getInternalURL(),
1620 $this->getInternalURL( 'action=history' )
1621 );
1622 }
1623
1624 /**
1625 * Move this page without authentication
1626 * @param Title &$nt the new page Title
1627 * @access public
1628 */
1629 function moveNoAuth( &$nt ) {
1630 return $this->moveTo( $nt, false );
1631 }
1632
1633 /**
1634 * Check whether a given move operation would be valid.
1635 * Returns true if ok, or a message key string for an error message
1636 * if invalid. (Scarrrrry ugly interface this.)
1637 * @param Title &$nt the new title
1638 * @param bool $auth indicates whether $wgUser's permissions
1639 * should be checked
1640 * @return mixed true on success, message name on failure
1641 * @access public
1642 */
1643 function isValidMoveOperation( &$nt, $auth = true ) {
1644 if( !$this or !$nt ) {
1645 return 'badtitletext';
1646 }
1647 if( $this->equals( $nt ) ) {
1648 return 'selfmove';
1649 }
1650 if( !$this->isMovable() || !$nt->isMovable() ) {
1651 return 'immobile_namespace';
1652 }
1653
1654 $oldid = $this->getArticleID();
1655 $newid = $nt->getArticleID();
1656
1657 if ( strlen( $nt->getDBkey() ) < 1 ) {
1658 return 'articleexists';
1659 }
1660 if ( ( '' == $this->getDBkey() ) ||
1661 ( !$oldid ) ||
1662 ( '' == $nt->getDBkey() ) ) {
1663 return 'badarticleerror';
1664 }
1665
1666 if ( $auth && (
1667 !$this->userCanEdit() || !$nt->userCanEdit() ||
1668 !$this->userCanMove() || !$nt->userCanMove() ) ) {
1669 return 'protectedpage';
1670 }
1671
1672 # The move is allowed only if (1) the target doesn't exist, or
1673 # (2) the target is a redirect to the source, and has no history
1674 # (so we can undo bad moves right after they're done).
1675
1676 if ( 0 != $newid ) { # Target exists; check for validity
1677 if ( ! $this->isValidMoveTarget( $nt ) ) {
1678 return 'articleexists';
1679 }
1680 }
1681 return true;
1682 }
1683
1684 /**
1685 * Move a title to a new location
1686 * @param Title &$nt the new title
1687 * @param bool $auth indicates whether $wgUser's permissions
1688 * should be checked
1689 * @return mixed true on success, message name on failure
1690 * @access public
1691 */
1692 function moveTo( &$nt, $auth = true, $reason = '' ) {
1693 $err = $this->isValidMoveOperation( $nt, $auth );
1694 if( is_string( $err ) ) {
1695 return $err;
1696 }
1697
1698 $pageid = $this->getArticleID();
1699 if( $nt->exists() ) {
1700 $this->moveOverExistingRedirect( $nt, $reason );
1701 $pageCountChange = 0;
1702 } else { # Target didn't exist, do normal move.
1703 $this->moveToNewTitle( $nt, $reason );
1704 $pageCountChange = 1;
1705 }
1706 $redirid = $this->getArticleID();
1707
1708 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
1709 $dbw =& wfGetDB( DB_MASTER );
1710 $categorylinks = $dbw->tableName( 'categorylinks' );
1711 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
1712 " WHERE cl_from=" . $dbw->addQuotes( $pageid ) .
1713 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
1714 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
1715
1716 # Update watchlists
1717
1718 $oldnamespace = $this->getNamespace() & ~1;
1719 $newnamespace = $nt->getNamespace() & ~1;
1720 $oldtitle = $this->getDBkey();
1721 $newtitle = $nt->getDBkey();
1722
1723 if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) {
1724 WatchedItem::duplicateEntries( $this, $nt );
1725 }
1726
1727 # Update search engine
1728 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
1729 $u->doUpdate();
1730 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
1731 $u->doUpdate();
1732
1733 # Update site_stats
1734 if ( $this->getNamespace() == NS_MAIN and $nt->getNamespace() != NS_MAIN ) {
1735 # Moved out of main namespace
1736 # not viewed, edited, removing
1737 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange);
1738 } elseif ( $this->getNamespace() != NS_MAIN and $nt->getNamespace() == NS_MAIN ) {
1739 # Moved into main namespace
1740 # not viewed, edited, adding
1741 $u = new SiteStatsUpdate( 0, 1, +1, $pageCountChange );
1742 } elseif ( $pageCountChange ) {
1743 # Added redirect
1744 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
1745 } else{
1746 $u = false;
1747 }
1748 if ( $u ) {
1749 $u->doUpdate();
1750 }
1751
1752 global $wgUser;
1753 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
1754 return true;
1755 }
1756
1757 /**
1758 * Move page to a title which is at present a redirect to the
1759 * source page
1760 *
1761 * @param Title &$nt the page to move to, which should currently
1762 * be a redirect
1763 * @access private
1764 */
1765 function moveOverExistingRedirect( &$nt, $reason = '' ) {
1766 global $wgUseSquid, $wgMwRedir;
1767 $fname = 'Title::moveOverExistingRedirect';
1768 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1769
1770 if ( $reason ) {
1771 $comment .= ": $reason";
1772 }
1773
1774 $now = wfTimestampNow();
1775 $rand = wfRandom();
1776 $newid = $nt->getArticleID();
1777 $oldid = $this->getArticleID();
1778 $dbw =& wfGetDB( DB_MASTER );
1779 $linkCache =& LinkCache::singleton();
1780
1781 # Delete the old redirect. We don't save it to history since
1782 # by definition if we've got here it's rather uninteresting.
1783 # We have to remove it so that the next step doesn't trigger
1784 # a conflict on the unique namespace+title index...
1785 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
1786
1787 # Save a null revision in the page's history notifying of the move
1788 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
1789 $nullRevId = $nullRevision->insertOn( $dbw );
1790
1791 # Change the name of the target page:
1792 $dbw->update( 'page',
1793 /* SET */ array(
1794 'page_touched' => $dbw->timestamp($now),
1795 'page_namespace' => $nt->getNamespace(),
1796 'page_title' => $nt->getDBkey(),
1797 'page_latest' => $nullRevId,
1798 ),
1799 /* WHERE */ array( 'page_id' => $oldid ),
1800 $fname
1801 );
1802 $linkCache->clearLink( $nt->getPrefixedDBkey() );
1803
1804 # Recreate the redirect, this time in the other direction.
1805 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1806 $redirectArticle = new Article( $this );
1807 $newid = $redirectArticle->insertOn( $dbw );
1808 $redirectRevision = new Revision( array(
1809 'page' => $newid,
1810 'comment' => $comment,
1811 'text' => $redirectText ) );
1812 $revid = $redirectRevision->insertOn( $dbw );
1813 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1814 $linkCache->clearLink( $this->getPrefixedDBkey() );
1815
1816 # Log the move
1817 $log = new LogPage( 'move' );
1818 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
1819
1820 # Now, we record the link from the redirect to the new title.
1821 # It should have no other outgoing links...
1822 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
1823 $dbw->insert( 'pagelinks',
1824 array(
1825 'pl_from' => $newid,
1826 'pl_namespace' => $nt->getNamespace(),
1827 'pl_title' => $nt->getDbKey() ),
1828 $fname );
1829
1830 # Purge squid
1831 if ( $wgUseSquid ) {
1832 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
1833 $u = new SquidUpdate( $urls );
1834 $u->doUpdate();
1835 }
1836 }
1837
1838 /**
1839 * Move page to non-existing title.
1840 * @param Title &$nt the new Title
1841 * @access private
1842 */
1843 function moveToNewTitle( &$nt, $reason = '' ) {
1844 global $wgUseSquid;
1845 global $wgMwRedir;
1846 $fname = 'MovePageForm::moveToNewTitle';
1847 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1848 if ( $reason ) {
1849 $comment .= ": $reason";
1850 }
1851
1852 $newid = $nt->getArticleID();
1853 $oldid = $this->getArticleID();
1854 $dbw =& wfGetDB( DB_MASTER );
1855 $now = $dbw->timestamp();
1856 $rand = wfRandom();
1857 $linkCache =& LinkCache::singleton();
1858
1859 # Save a null revision in the page's history notifying of the move
1860 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
1861 $nullRevId = $nullRevision->insertOn( $dbw );
1862
1863 # Rename cur entry
1864 $dbw->update( 'page',
1865 /* SET */ array(
1866 'page_touched' => $now,
1867 'page_namespace' => $nt->getNamespace(),
1868 'page_title' => $nt->getDBkey(),
1869 'page_latest' => $nullRevId,
1870 ),
1871 /* WHERE */ array( 'page_id' => $oldid ),
1872 $fname
1873 );
1874
1875 $linkCache->clearLink( $nt->getPrefixedDBkey() );
1876
1877 # Insert redirect
1878 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1879 $redirectArticle = new Article( $this );
1880 $newid = $redirectArticle->insertOn( $dbw );
1881 $redirectRevision = new Revision( array(
1882 'page' => $newid,
1883 'comment' => $comment,
1884 'text' => $redirectText ) );
1885 $revid = $redirectRevision->insertOn( $dbw );
1886 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1887 $linkCache->clearLink( $this->getPrefixedDBkey() );
1888
1889 # Log the move
1890 $log = new LogPage( 'move' );
1891 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
1892
1893 # Purge caches as per article creation
1894 Article::onArticleCreate( $nt );
1895
1896 # Record the just-created redirect's linking to the page
1897 $dbw->insert( 'pagelinks',
1898 array(
1899 'pl_from' => $newid,
1900 'pl_namespace' => $nt->getNamespace(),
1901 'pl_title' => $nt->getDBkey() ),
1902 $fname );
1903
1904 # Non-existent target may have had broken links to it; these must
1905 # now be touched to update link coloring.
1906 $nt->touchLinks();
1907
1908 # Purge old title from squid
1909 # The new title, and links to the new title, are purged in Article::onArticleCreate()
1910 $titles = $nt->getLinksTo();
1911 if ( $wgUseSquid ) {
1912 $urls = $this->getSquidURLs();
1913 foreach ( $titles as $linkTitle ) {
1914 $urls[] = $linkTitle->getInternalURL();
1915 }
1916 $u = new SquidUpdate( $urls );
1917 $u->doUpdate();
1918 }
1919 }
1920
1921 /**
1922 * Checks if $this can be moved to a given Title
1923 * - Selects for update, so don't call it unless you mean business
1924 *
1925 * @param Title &$nt the new title to check
1926 * @access public
1927 */
1928 function isValidMoveTarget( $nt ) {
1929
1930 $fname = 'Title::isValidMoveTarget';
1931 $dbw =& wfGetDB( DB_MASTER );
1932
1933 # Is it a redirect?
1934 $id = $nt->getArticleID();
1935 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
1936 array( 'page_is_redirect','old_text','old_flags' ),
1937 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
1938 $fname, 'FOR UPDATE' );
1939
1940 if ( !$obj || 0 == $obj->page_is_redirect ) {
1941 # Not a redirect
1942 return false;
1943 }
1944 $text = Revision::getRevisionText( $obj );
1945
1946 # Does the redirect point to the source?
1947 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
1948 $redirTitle = Title::newFromText( $m[1] );
1949 if( !is_object( $redirTitle ) ||
1950 $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
1951 return false;
1952 }
1953 } else {
1954 # Fail safe
1955 return false;
1956 }
1957
1958 # Does the article have a history?
1959 $row = $dbw->selectRow( array( 'page', 'revision'),
1960 array( 'rev_id' ),
1961 array( 'page_namespace' => $nt->getNamespace(),
1962 'page_title' => $nt->getDBkey(),
1963 'page_id=rev_page AND page_latest != rev_id'
1964 ), $fname, 'FOR UPDATE'
1965 );
1966
1967 # Return true if there was no history
1968 return $row === false;
1969 }
1970
1971 /**
1972 * Create a redirect; fails if the title already exists; does
1973 * not notify RC
1974 *
1975 * @param Title $dest the destination of the redirect
1976 * @param string $comment the comment string describing the move
1977 * @return bool true on success
1978 * @access public
1979 */
1980 function createRedirect( $dest, $comment ) {
1981 if ( $this->getArticleID() ) {
1982 return false;
1983 }
1984
1985 $fname = 'Title::createRedirect';
1986 $dbw =& wfGetDB( DB_MASTER );
1987
1988 $article = new Article( $this );
1989 $newid = $article->insertOn( $dbw );
1990 $revision = new Revision( array(
1991 'page' => $newid,
1992 'comment' => $comment,
1993 'text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n",
1994 ) );
1995 $revisionId = $revision->insertOn( $dbw );
1996 $article->updateRevisionOn( $dbw, $revision, 0 );
1997
1998 # Link table
1999 $dbw->insert( 'pagelinks',
2000 array(
2001 'pl_from' => $newid,
2002 'pl_namespace' => $dest->getNamespace(),
2003 'pl_title' => $dest->getDbKey()
2004 ), $fname
2005 );
2006
2007 Article::onArticleCreate( $this );
2008 return true;
2009 }
2010
2011 /**
2012 * Get categories to which this Title belongs and return an array of
2013 * categories' names.
2014 *
2015 * @return array an array of parents in the form:
2016 * $parent => $currentarticle
2017 * @access public
2018 */
2019 function getParentCategories() {
2020 global $wgContLang;
2021
2022 $titlekey = $this->getArticleId();
2023 $dbr =& wfGetDB( DB_SLAVE );
2024 $categorylinks = $dbr->tableName( 'categorylinks' );
2025
2026 # NEW SQL
2027 $sql = "SELECT * FROM $categorylinks"
2028 ." WHERE cl_from='$titlekey'"
2029 ." AND cl_from <> '0'"
2030 ." ORDER BY cl_sortkey";
2031
2032 $res = $dbr->query ( $sql ) ;
2033
2034 if($dbr->numRows($res) > 0) {
2035 while ( $x = $dbr->fetchObject ( $res ) )
2036 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2037 $data[$wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText();
2038 $dbr->freeResult ( $res ) ;
2039 } else {
2040 $data = '';
2041 }
2042 return $data;
2043 }
2044
2045 /**
2046 * Get a tree of parent categories
2047 * @param array $children an array with the children in the keys, to check for circular refs
2048 * @return array
2049 * @access public
2050 */
2051 function getParentCategoryTree( $children = array() ) {
2052 $parents = $this->getParentCategories();
2053
2054 if($parents != '') {
2055 foreach($parents as $parent => $current) {
2056 if ( array_key_exists( $parent, $children ) ) {
2057 # Circular reference
2058 $stack[$parent] = array();
2059 } else {
2060 $nt = Title::newFromText($parent);
2061 $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) );
2062 }
2063 }
2064 return $stack;
2065 } else {
2066 return array();
2067 }
2068 }
2069
2070
2071 /**
2072 * Get an associative array for selecting this title from
2073 * the "page" table
2074 *
2075 * @return array
2076 * @access public
2077 */
2078 function pageCond() {
2079 return array( 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform );
2080 }
2081
2082 /**
2083 * Get the revision ID of the previous revision
2084 *
2085 * @param integer $revision Revision ID. Get the revision that was before this one.
2086 * @return interger $oldrevision|false
2087 */
2088 function getPreviousRevisionID( $revision ) {
2089 $dbr =& wfGetDB( DB_SLAVE );
2090 return $dbr->selectField( 'revision', 'rev_id',
2091 'rev_page=' . intval( $this->getArticleId() ) .
2092 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
2093 }
2094
2095 /**
2096 * Get the revision ID of the next revision
2097 *
2098 * @param integer $revision Revision ID. Get the revision that was after this one.
2099 * @return interger $oldrevision|false
2100 */
2101 function getNextRevisionID( $revision ) {
2102 $dbr =& wfGetDB( DB_SLAVE );
2103 return $dbr->selectField( 'revision', 'rev_id',
2104 'rev_page=' . intval( $this->getArticleId() ) .
2105 ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
2106 }
2107
2108 /**
2109 * Compare with another title.
2110 *
2111 * @param Title $title
2112 * @return bool
2113 */
2114 function equals( $title ) {
2115 // Note: === is necessary for proper matching of number-like titles.
2116 return $this->getInterwiki() === $title->getInterwiki()
2117 && $this->getNamespace() == $title->getNamespace()
2118 && $this->getDbkey() === $title->getDbkey();
2119 }
2120
2121 /**
2122 * Check if page exists
2123 * @return bool
2124 */
2125 function exists() {
2126 return $this->getArticleId() != 0;
2127 }
2128
2129 /**
2130 * Should a link should be displayed as a known link, just based on its title?
2131 *
2132 * Currently, a self-link with a fragment and special pages are in
2133 * this category. Special pages never exist in the database.
2134 */
2135 function isAlwaysKnown() {
2136 return $this->isExternal() || ( 0 == $this->mNamespace && "" == $this->mDbkeyform )
2137 || NS_SPECIAL == $this->mNamespace;
2138 }
2139
2140 /**
2141 * Update page_touched timestamps on pages linking to this title.
2142 * In principal, this could be backgrounded and could also do squid
2143 * purging.
2144 */
2145 function touchLinks() {
2146 $fname = 'Title::touchLinks';
2147
2148 $dbw =& wfGetDB( DB_MASTER );
2149
2150 $res = $dbw->select( 'pagelinks',
2151 array( 'pl_from' ),
2152 array(
2153 'pl_namespace' => $this->getNamespace(),
2154 'pl_title' => $this->getDbKey() ),
2155 $fname );
2156
2157 $toucharr = array();
2158 while( $row = $dbw->fetchObject( $res ) ) {
2159 $toucharr[] = $row->pl_from;
2160 }
2161 $dbw->freeResult( $res );
2162
2163 if( $this->getNamespace() == NS_CATEGORY ) {
2164 // Categories show up in a separate set of links as well
2165 $res = $dbw->select( 'categorylinks',
2166 array( 'cl_from' ),
2167 array( 'cl_to' => $this->getDbKey() ),
2168 $fname );
2169 while( $row = $dbw->fetchObject( $res ) ) {
2170 $toucharr[] = $row->cl_from;
2171 }
2172 $dbw->freeResult( $res );
2173 }
2174
2175 if (!count($toucharr))
2176 return;
2177 $dbw->update( 'page', /* SET */ array( 'page_touched' => $dbw->timestamp() ),
2178 /* WHERE */ array( 'page_id' => $toucharr ),$fname);
2179 }
2180
2181 function trackbackURL() {
2182 global $wgTitle, $wgScriptPath, $wgServer;
2183
2184 return "$wgServer$wgScriptPath/trackback.php?article="
2185 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
2186 }
2187
2188 function trackbackRDF() {
2189 $url = htmlspecialchars($this->getFullURL());
2190 $title = htmlspecialchars($this->getText());
2191 $tburl = $this->trackbackURL();
2192
2193 return "
2194 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
2195 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
2196 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
2197 <rdf:Description
2198 rdf:about=\"$url\"
2199 dc:identifier=\"$url\"
2200 dc:title=\"$title\"
2201 trackback:ping=\"$tburl\" />
2202 </rdf:RDF>";
2203 }
2204
2205 /**
2206 * Generate strings used for xml 'id' names in monobook tabs
2207 * @return string
2208 */
2209 function getNamespaceKey() {
2210 switch ($this->getNamespace()) {
2211 case NS_MAIN:
2212 case NS_TALK:
2213 return 'nstab-main';
2214 case NS_USER:
2215 case NS_USER_TALK:
2216 return 'nstab-user';
2217 case NS_MEDIA:
2218 return 'nstab-media';
2219 case NS_SPECIAL:
2220 return 'nstab-special';
2221 case NS_PROJECT:
2222 case NS_PROJECT_TALK:
2223 return 'nstab-wp';
2224 case NS_IMAGE:
2225 case NS_IMAGE_TALK:
2226 return 'nstab-image';
2227 case NS_MEDIAWIKI:
2228 case NS_MEDIAWIKI_TALK:
2229 return 'nstab-mediawiki';
2230 case NS_TEMPLATE:
2231 case NS_TEMPLATE_TALK:
2232 return 'nstab-template';
2233 case NS_HELP:
2234 case NS_HELP_TALK:
2235 return 'nstab-help';
2236 case NS_CATEGORY:
2237 case NS_CATEGORY_TALK:
2238 return 'nstab-category';
2239 default:
2240 return 'nstab-' . strtolower( $this->getSubjectNsText() );
2241 }
2242 }
2243 }
2244 ?>