Add back the slower version of Title::makeTitle as Title::makeTitleSafe()
[lhc/web/wiklou.git] / includes / Title.php
1 <?php
2 # See title.doc
3
4 $wgTitleInterwikiCache = array();
5
6 # Title class
7 #
8 # * Represents a title, which may contain an interwiki designation or namespace
9 # * Can fetch various kinds of data from the database, albeit inefficiently.
10 #
11
12 define ( 'GAID_FOR_UPDATE', 1 );
13
14 class Title {
15 # All member variables should be considered private
16 # Please use the accessor functions
17
18 var $mTextform; # Text form (spaces not underscores) of the main part
19 var $mUrlform; # URL-encoded form of the main part
20 var $mDbkeyform; # Main part with underscores
21 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
22 var $mInterwiki; # Interwiki prefix (or null string)
23 var $mFragment; # Title fragment (i.e. the bit after the #)
24 var $mArticleID; # Article ID, fetched from the link cache on demand
25 var $mRestrictions; # Array of groups allowed to edit this article
26 # Only null or "sysop" are supported
27 var $mRestrictionsLoaded; # Boolean for initialisation on demand
28 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
29 var $mDefaultNamespace; # Namespace index when there is no namespace
30 # Zero except in {{transclusion}} tags
31
32 #----------------------------------------------------------------------------
33 # Construction
34 #----------------------------------------------------------------------------
35
36 /* private */ function Title() {
37 $this->mInterwiki = $this->mUrlform =
38 $this->mTextform = $this->mDbkeyform = '';
39 $this->mArticleID = -1;
40 $this->mNamespace = 0;
41 $this->mRestrictionsLoaded = false;
42 $this->mRestrictions = array();
43 $this->mDefaultNamespace = 0;
44 }
45
46 # From a prefixed DB key
47 /* static */ function newFromDBkey( $key ) {
48 $t = new Title();
49 $t->mDbkeyform = $key;
50 if( $t->secureAndSplit() )
51 return $t;
52 else
53 return NULL;
54 }
55
56 # From text, such as what you would find in a link
57 /* static */ function newFromText( $text, $defaultNamespace = 0 ) {
58 $fname = 'Title::newFromText';
59 wfProfileIn( $fname );
60
61 if( is_object( $text ) ) {
62 wfDebugDieBacktrace( 'Called with object instead of string.' );
63 }
64 global $wgInputEncoding;
65 $text = do_html_entity_decode( $text, ENT_COMPAT, $wgInputEncoding );
66
67 $text = wfMungeToUtf8( $text );
68
69
70 # What was this for? TS 2004-03-03
71 # $text = urldecode( $text );
72
73 $t = new Title();
74 $t->mDbkeyform = str_replace( ' ', '_', $text );
75 $t->mDefaultNamespace = $defaultNamespace;
76
77 wfProfileOut( $fname );
78 if ( !is_object( $t ) ) {
79 var_dump( debug_backtrace() );
80 }
81 if( $t->secureAndSplit() ) {
82 return $t;
83 } else {
84 return NULL;
85 }
86 }
87
88 # From a URL-encoded title
89 /* static */ function newFromURL( $url ) {
90 global $wgLang, $wgServer;
91 $t = new Title();
92
93 # For compatibility with old buggy URLs. "+" is not valid in titles,
94 # but some URLs used it as a space replacement and they still come
95 # from some external search tools.
96 $s = str_replace( '+', ' ', $url );
97
98 # For links that came from outside, check for alternate/legacy
99 # character encoding.
100 wfDebug( "Servr: $wgServer\n" );
101 if( empty( $_SERVER['HTTP_REFERER'] ) ||
102 strncmp($wgServer, $_SERVER['HTTP_REFERER'], strlen( $wgServer ) ) )
103 {
104 $s = $wgLang->checkTitleEncoding( $s );
105 } else {
106 wfDebug( "Refer: {$_SERVER['HTTP_REFERER']}\n" );
107 }
108
109 $t->mDbkeyform = str_replace( ' ', '_', $s );
110 if( $t->secureAndSplit() ) {
111 # check that length of title is < cur_title size
112 $dbr =& wfGetDB( DB_SLAVE );
113 $maxSize = $dbr->textFieldSize( 'cur', 'cur_title' );
114 if ( $maxSize != -1 && strlen( $t->mDbkeyform ) > $maxSize ) {
115 return NULL;
116 }
117
118 return $t;
119 } else {
120 return NULL;
121 }
122 }
123
124 # From a cur_id
125 # This is inefficiently implemented, the cur row is requested but not
126 # used for anything else
127 /* static */ function newFromID( $id ) {
128 $fname = 'Title::newFromID';
129 $dbr =& wfGetDB( DB_SLAVE );
130 $row = $dbr->getArray( 'cur', array( 'cur_namespace', 'cur_title' ),
131 array( 'cur_id' => $id ), $fname );
132 if ( $row !== false ) {
133 $title = Title::makeTitle( $row->cur_namespace, $row->cur_title );
134 } else {
135 $title = NULL;
136 }
137 return $title;
138 }
139
140 # From a namespace index and a DB key.
141 # It's assumed that $ns and $title are *valid*, for instance when
142 # they came directly from the database or a special page name.
143 /* static */ function &makeTitle( $ns, $title ) {
144 $t =& new Title();
145 $t->mInterwiki = '';
146 $t->mFragment = '';
147 $t->mNamespace = $ns;
148 $t->mDbkeyform = $title;
149 $t->mArticleID = ( $ns >= 0 ) ? 0 : -1;
150 $t->mUrlform = wfUrlencode( $title );
151 $t->mTextform = str_replace( '_', ' ', $title );
152 return $t;
153 }
154
155 # From a namespace index and a DB key.
156 # These will be checked for validity, which is a bit slower
157 # than makeTitle() but safer for user-provided data.
158 /* static */ function makeTitleSafe( $ns, $title ) {
159 $t = new Title();
160 $t->mDbkeyform = Title::makeName( $ns, $title );
161 if( $t->secureAndSplit() ) {
162 return $t;
163 } else {
164 return NULL;
165 }
166 }
167
168 /* static */ function newMainPage() {
169 return Title::newFromText( wfMsg( 'mainpage' ) );
170 }
171
172 # Get the title object for a redirect
173 # Returns NULL if the text is not a valid redirect
174 /* static */ function newFromRedirect( $text ) {
175 global $wgMwRedir;
176 $rt = NULL;
177 if ( $wgMwRedir->matchStart( $text ) ) {
178 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/', $text, $m ) ) {
179 # categories are escaped using : for example one can enter:
180 # #REDIRECT [[:Category:Music]]. Need to remove it.
181 if ( substr($m[1],0,1) == ':') {
182 # We don't want to keep the ':'
183 $m[1] = substr( $m[1], 1 );
184 }
185
186 $rt = Title::newFromText( $m[1] );
187 }
188 }
189 return $rt;
190 }
191
192 #----------------------------------------------------------------------------
193 # Static functions
194 #----------------------------------------------------------------------------
195
196 # Get the prefixed DB key associated with an ID
197 /* static */ function nameOf( $id ) {
198 $fname = 'Title::nameOf';
199 $dbr =& wfGetDB( DB_SLAVE );
200
201 $s = $dbr->getArray( 'cur', array( 'cur_namespace','cur_title' ), array( 'cur_id' => $id ), $fname );
202 if ( $s === false ) { return NULL; }
203
204 $n = Title::makeName( $s->cur_namespace, $s->cur_title );
205 return $n;
206 }
207
208 # Get a regex character class describing the legal characters in a link
209 /* static */ function legalChars() {
210 # Missing characters:
211 # * []|# Needed for link syntax
212 # * % and + are corrupted by Apache when they appear in the path
213 #
214 # % seems to work though
215 #
216 # The problem with % is that URLs are double-unescaped: once by Apache's
217 # path conversion code, and again by PHP. So %253F, for example, becomes "?".
218 # Our code does not double-escape to compensate for this, indeed double escaping
219 # would break if the double-escaped title was passed in the query string
220 # rather than the path. This is a minor security issue because articles can be
221 # created such that they are hard to view or edit. -- TS
222 #
223 # Theoretically 0x80-0x9F of ISO 8859-1 should be disallowed, but
224 # this breaks interlanguage links
225
226 $set = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z{}~\\x80-\\xFF";
227 return $set;
228 }
229
230 # Returns a stripped-down a title string ready for the search index
231 # Takes a namespace index and a text-form main part
232 /* static */ function indexTitle( $ns, $title ) {
233 global $wgDBminWordLen, $wgLang;
234 require_once( 'SearchEngine.php' );
235
236 $lc = SearchEngine::legalSearchChars() . '&#;';
237 $t = $wgLang->stripForSearch( $title );
238 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
239 $t = strtolower( $t );
240
241 # Handle 's, s'
242 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
243 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
244
245 $t = preg_replace( "/\\s+/", ' ', $t );
246
247 if ( $ns == Namespace::getImage() ) {
248 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
249 }
250 return trim( $t );
251 }
252
253 # Make a prefixed DB key from a DB key and a namespace index
254 /* static */ function makeName( $ns, $title ) {
255 global $wgLang;
256
257 $n = $wgLang->getNsText( $ns );
258 if ( '' == $n ) { return $title; }
259 else { return $n.':'.$title; }
260 }
261
262 # Arguably static
263 # Returns the URL associated with an interwiki prefix
264 # The URL contains $1, which is replaced by the title
265 function getInterwikiLink( $key ) {
266 global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
267 $fname = 'Title::getInterwikiLink';
268 $k = $wgDBname.':interwiki:'.$key;
269
270 if( array_key_exists( $k, $wgTitleInterwikiCache ) )
271 return $wgTitleInterwikiCache[$k]->iw_url;
272
273 $s = $wgMemc->get( $k );
274 # Ignore old keys with no iw_local
275 if( $s && isset( $s->iw_local ) ) {
276 $wgTitleInterwikiCache[$k] = $s;
277 return $s->iw_url;
278 }
279 $dbr =& wfGetDB( DB_SLAVE );
280 $res = $dbr->select( 'interwiki', array( 'iw_url', 'iw_local' ), array( 'iw_prefix' => $key ), $fname );
281 if(!$res) return '';
282
283 $s = $dbr->fetchObject( $res );
284 if(!$s) {
285 # Cache non-existence: create a blank object and save it to memcached
286 $s = (object)false;
287 $s->iw_url = '';
288 $s->iw_local = 0;
289 }
290 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
291 $wgTitleInterwikiCache[$k] = $s;
292 return $s->iw_url;
293 }
294
295 function isLocal() {
296 global $wgTitleInterwikiCache, $wgDBname;
297
298 if ( $this->mInterwiki != '' ) {
299 # Make sure key is loaded into cache
300 $this->getInterwikiLink( $this->mInterwiki );
301 $k = $wgDBname.':interwiki:' . $this->mInterwiki;
302 return (bool)($wgTitleInterwikiCache[$k]->iw_local);
303 } else {
304 return true;
305 }
306 }
307
308 # Update the cur_touched field for an array of title objects
309 # Inefficient unless the IDs are already loaded into the link cache
310 /* static */ function touchArray( $titles, $timestamp = '' ) {
311 if ( count( $titles ) == 0 ) {
312 return;
313 }
314 if ( $timestamp == '' ) {
315 $timestamp = wfTimestampNow();
316 }
317 $dbw =& wfGetDB( DB_MASTER );
318 $cur = $dbw->tableName( 'cur' );
319 $sql = "UPDATE $cur SET cur_touched='{$timestamp}' WHERE cur_id IN (";
320 $first = true;
321
322 foreach ( $titles as $title ) {
323 if ( ! $first ) {
324 $sql .= ',';
325 }
326 $first = false;
327 $sql .= $title->getArticleID();
328 }
329 $sql .= ')';
330 if ( ! $first ) {
331 $dbw->query( $sql, 'Title::touchArray' );
332 }
333 }
334
335 #----------------------------------------------------------------------------
336 # Other stuff
337 #----------------------------------------------------------------------------
338
339 # Simple accessors
340 # See the definitions at the top of this file
341
342 function getText() { return $this->mTextform; }
343 function getPartialURL() { return $this->mUrlform; }
344 function getDBkey() { return $this->mDbkeyform; }
345 function getNamespace() { return $this->mNamespace; }
346 function setNamespace( $n ) { $this->mNamespace = $n; }
347 function getInterwiki() { return $this->mInterwiki; }
348 function getFragment() { return $this->mFragment; }
349 function getDefaultNamespace() { return $this->mDefaultNamespace; }
350
351 # Get title for search index
352 function getIndexTitle() {
353 return Title::indexTitle( $this->mNamespace, $this->mTextform );
354 }
355
356 # Get prefixed title with underscores
357 function getPrefixedDBkey() {
358 $s = $this->prefix( $this->mDbkeyform );
359 $s = str_replace( ' ', '_', $s );
360 return $s;
361 }
362
363 # Get prefixed title with spaces
364 # This is the form usually used for display
365 function getPrefixedText() {
366 if ( empty( $this->mPrefixedText ) ) {
367 $s = $this->prefix( $this->mTextform );
368 $s = str_replace( '_', ' ', $s );
369 $this->mPrefixedText = $s;
370 }
371 return $this->mPrefixedText;
372 }
373
374 # As getPrefixedText(), plus fragment.
375 function getFullText() {
376 $text = $this->getPrefixedText();
377 if( '' != $this->mFragment ) {
378 $text .= '#' . $this->mFragment;
379 }
380 return $text;
381 }
382
383 # Get a URL-encoded title (not an actual URL) including interwiki
384 function getPrefixedURL() {
385 $s = $this->prefix( $this->mDbkeyform );
386 $s = str_replace( ' ', '_', $s );
387
388 $s = wfUrlencode ( $s ) ;
389
390 # Cleaning up URL to make it look nice -- is this safe?
391 $s = preg_replace( '/%3[Aa]/', ':', $s );
392 $s = preg_replace( '/%2[Ff]/', '/', $s );
393 $s = str_replace( '%28', '(', $s );
394 $s = str_replace( '%29', ')', $s );
395
396 return $s;
397 }
398
399 # Get a real URL referring to this title, with interwiki link and fragment
400 function getFullURL( $query = '' ) {
401 global $wgLang, $wgArticlePath, $wgServer, $wgScript;
402
403 if ( '' == $this->mInterwiki ) {
404 $p = $wgArticlePath;
405 return $wgServer . $this->getLocalUrl( $query );
406 } else {
407 $baseUrl = $this->getInterwikiLink( $this->mInterwiki );
408 $namespace = $wgLang->getNsText( $this->mNamespace );
409 if ( '' != $namespace ) {
410 # Can this actually happen? Interwikis shouldn't be parsed.
411 $namepace .= ':';
412 }
413 $url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );
414 if ( '' != $this->mFragment ) {
415 $url .= '#' . $this->mFragment;
416 }
417 return $url;
418 }
419 }
420
421 # Get a URL with an optional query string, no fragment
422 # * If $query=="", it will use $wgArticlePath
423 # * Returns a full for an interwiki link, loses any query string
424 # * Optionally adds the server and escapes for HTML
425 # * Setting $query to "-" makes an old-style URL with nothing in the
426 # query except a title
427
428 function getURL() {
429 die( 'Call to obsolete obsolete function Title::getURL()' );
430 }
431
432 function getLocalURL( $query = '' ) {
433 global $wgLang, $wgArticlePath, $wgScript;
434
435 if ( $this->isExternal() ) {
436 return $this->getFullURL();
437 }
438
439 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
440 if ( $query == '' ) {
441 $url = str_replace( '$1', $dbkey, $wgArticlePath );
442 } else {
443 if ( $query == '-' ) {
444 $query = '';
445 }
446 if ( $wgScript != '' ) {
447 $url = "{$wgScript}?title={$dbkey}&{$query}";
448 } else {
449 # Top level wiki
450 $url = "/{$dbkey}?{$query}";
451 }
452 }
453 return $url;
454 }
455
456 function escapeLocalURL( $query = '' ) {
457 return htmlspecialchars( $this->getLocalURL( $query ) );
458 }
459
460 function escapeFullURL( $query = '' ) {
461 return htmlspecialchars( $this->getFullURL( $query ) );
462 }
463
464 function getInternalURL( $query = '' ) {
465 # Used in various Squid-related code, in case we have a different
466 # internal hostname for the server than the exposed one.
467 global $wgInternalServer;
468 return $wgInternalServer . $this->getLocalURL( $query );
469 }
470
471 # Get the edit URL, or a null string if it is an interwiki link
472 function getEditURL() {
473 global $wgServer, $wgScript;
474
475 if ( '' != $this->mInterwiki ) { return ''; }
476 $s = $this->getLocalURL( 'action=edit' );
477
478 return $s;
479 }
480
481 # Get HTML-escaped displayable text
482 # For the title field in <a> tags
483 function getEscapedText() {
484 return htmlspecialchars( $this->getPrefixedText() );
485 }
486
487 # Is the title interwiki?
488 function isExternal() { return ( '' != $this->mInterwiki ); }
489
490 # Does the title correspond to a protected article?
491 function isProtected() {
492 if ( -1 == $this->mNamespace ) { return true; }
493 $a = $this->getRestrictions();
494 if ( in_array( 'sysop', $a ) ) { return true; }
495 return false;
496 }
497
498 # Is the page a log page, i.e. one where the history is messed up by
499 # LogPage.php? This used to be used for suppressing diff links in recent
500 # changes, but now that's done by setting a flag in the recentchanges
501 # table. Hence, this probably is no longer used.
502 function isLog() {
503 if ( $this->mNamespace != Namespace::getWikipedia() ) {
504 return false;
505 }
506 if ( ( 0 == strcmp( wfMsg( 'uploadlogpage' ), $this->mDbkeyform ) ) ||
507 ( 0 == strcmp( wfMsg( 'dellogpage' ), $this->mDbkeyform ) ) ) {
508 return true;
509 }
510 return false;
511 }
512
513 # Is $wgUser is watching this page?
514 function userIsWatching() {
515 global $wgUser;
516
517 if ( -1 == $this->mNamespace ) { return false; }
518 if ( 0 == $wgUser->getID() ) { return false; }
519
520 return $wgUser->isWatched( $this );
521 }
522
523 # Can $wgUser edit this page?
524 function userCanEdit() {
525 global $wgUser;
526 if ( -1 == $this->mNamespace ) { return false; }
527 if ( NS_MEDIAWIKI == $this->mNamespace && !$wgUser->isSysop() ) { return false; }
528 # if ( 0 == $this->getArticleID() ) { return false; }
529 if ( $this->mDbkeyform == '_' ) { return false; }
530 # protect global styles and js
531 if ( NS_MEDIAWIKI == $this->mNamespace
532 && preg_match("/\\.(css|js)$/", $this->mTextform )
533 && !$wgUser->isSysop() )
534 { return false; }
535 //if ( $this->isCssJsSubpage() and !$this->userCanEditCssJsSubpage() ) { return false; }
536 # protect css/js subpages of user pages
537 # XXX: this might be better using restrictions
538 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
539 if( Namespace::getUser() == $this->mNamespace
540 and preg_match("/\\.(css|js)$/", $this->mTextform )
541 and !$wgUser->isSysop()
542 and !preg_match('/^'.preg_quote($wgUser->getName(), '/').'/', $this->mTextform) )
543 { return false; }
544 $ur = $wgUser->getRights();
545 foreach ( $this->getRestrictions() as $r ) {
546 if ( '' != $r && ( ! in_array( $r, $ur ) ) ) {
547 return false;
548 }
549 }
550 return true;
551 }
552
553 function userCanRead() {
554 global $wgUser;
555 global $wgWhitelistRead;
556
557 if( 0 != $wgUser->getID() ) return true;
558 if( !is_array( $wgWhitelistRead ) ) return true;
559
560 $name = $this->getPrefixedText();
561 if( in_array( $name, $wgWhitelistRead ) ) return true;
562
563 # Compatibility with old settings
564 if( $this->getNamespace() == NS_MAIN ) {
565 if( in_array( ':' . $name, $wgWhitelistRead ) ) return true;
566 }
567 return false;
568 }
569
570 function isCssJsSubpage() {
571 return ( Namespace::getUser() == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) );
572 }
573 function isCssSubpage() {
574 return ( Namespace::getUser() == $this->mNamespace and preg_match("/\\.css$/", $this->mTextform ) );
575 }
576 function isJsSubpage() {
577 return ( Namespace::getUser() == $this->mNamespace and preg_match("/\\.js$/", $this->mTextform ) );
578 }
579 function userCanEditCssJsSubpage() {
580 # protect css/js subpages of user pages
581 # XXX: this might be better using restrictions
582 global $wgUser;
583 return ( $wgUser->isSysop() or preg_match('/^'.preg_quote($wgUser->getName()).'/', $this->mTextform) );
584 }
585
586 # Accessor/initialisation for mRestrictions
587 function getRestrictions() {
588 $id = $this->getArticleID();
589 if ( 0 == $id ) { return array(); }
590
591 if ( ! $this->mRestrictionsLoaded ) {
592 $dbr =& wfGetDB( DB_SLAVE );
593 $res = $dbr->getField( 'cur', 'cur_restrictions', 'cur_id='.$id );
594 $this->mRestrictions = explode( ',', trim( $res ) );
595 $this->mRestrictionsLoaded = true;
596 }
597 return $this->mRestrictions;
598 }
599
600 # Is there a version of this page in the deletion archive?
601 # Returns the number of archived revisions
602 function isDeleted() {
603 $fname = 'Title::isDeleted';
604 $dbr =& wfGetDB( DB_SLAVE );
605 $n = $dbr->getField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
606 'ar_title' => $this->getDBkey() ), $fname );
607 return (int)$n;
608 }
609
610 # Get the article ID from the link cache
611 # $flags is a bit field, may be GAID_FOR_UPDATE to select for update
612 function getArticleID( $flags = 0 ) {
613 global $wgLinkCache;
614
615 if ( $flags & GAID_FOR_UPDATE ) {
616 $oldUpdate = $wgLinkCache->forUpdate( true );
617 $this->mArticleID = $wgLinkCache->addLinkObj( $this );
618 $wgLinkCache->forUpdate( $oldUpdate );
619 } else {
620 if ( -1 == $this->mArticleID ) {
621 $this->mArticleID = $wgLinkCache->addLinkObj( $this );
622 }
623 }
624 return $this->mArticleID;
625 }
626
627 # This clears some fields in this object, and clears any associated keys in the
628 # "bad links" section of $wgLinkCache. This is called from Article::insertNewArticle()
629 # to allow loading of the new cur_id. It's also called from Article::doDeleteArticle()
630 function resetArticleID( $newid ) {
631 global $wgLinkCache;
632 $wgLinkCache->clearBadLink( $this->getPrefixedDBkey() );
633
634 if ( 0 == $newid ) { $this->mArticleID = -1; }
635 else { $this->mArticleID = $newid; }
636 $this->mRestrictionsLoaded = false;
637 $this->mRestrictions = array();
638 }
639
640 # Updates cur_touched
641 # Called from LinksUpdate.php
642 function invalidateCache() {
643 $now = wfTimestampNow();
644 $dbw =& wfGetDB( DB_MASTER );
645 $success = $dbw->updateArray( 'cur',
646 array( /* SET */
647 'cur_touched' => wfTimestampNow()
648 ), array( /* WHERE */
649 'cur_namespace' => $this->getNamespace() ,
650 'cur_title' => $this->getDBkey()
651 ), 'Title::invalidateCache'
652 );
653 return $success;
654 }
655
656 # Prefixes some arbitrary text with the namespace or interwiki prefix of this object
657 /* private */ function prefix( $name ) {
658 global $wgLang;
659
660 $p = '';
661 if ( '' != $this->mInterwiki ) {
662 $p = $this->mInterwiki . ':';
663 }
664 if ( 0 != $this->mNamespace ) {
665 $p .= $wgLang->getNsText( $this->mNamespace ) . ':';
666 }
667 return $p . $name;
668 }
669
670 # Secure and split - main initialisation function for this object
671 #
672 # Assumes that mDbkeyform has been set, and is urldecoded
673 # and uses underscores, but not otherwise munged. This function
674 # removes illegal characters, splits off the interwiki and
675 # namespace prefixes, sets the other forms, and canonicalizes
676 # everything.
677 #
678 /* private */ function secureAndSplit()
679 {
680 global $wgLang, $wgLocalInterwiki, $wgCapitalLinks;
681 $fname = 'Title::secureAndSplit';
682 wfProfileIn( $fname );
683
684 static $imgpre = false;
685 static $rxTc = false;
686
687 # Initialisation
688 if ( $imgpre === false ) {
689 $imgpre = ':' . $wgLang->getNsText( Namespace::getImage() ) . ':';
690 # % is needed as well
691 $rxTc = '/[^' . Title::legalChars() . ']/';
692 }
693
694 $this->mInterwiki = $this->mFragment = '';
695 $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
696
697 # Clean up whitespace
698 #
699 $t = preg_replace( "/[\\s_]+/", '_', $this->mDbkeyform );
700 $t = preg_replace( '/^_*(.*?)_*$/', '$1', $t );
701
702 if ( '' == $t ) {
703 wfProfileOut( $fname );
704 return false;
705 }
706
707 $this->mDbkeyform = $t;
708 $done = false;
709
710 # :Image: namespace
711 if ( 0 == strncasecmp( $imgpre, $t, strlen( $imgpre ) ) ) {
712 $t = substr( $t, 1 );
713 }
714
715 # Initial colon indicating main namespace
716 if ( ':' == $t{0} ) {
717 $r = substr( $t, 1 );
718 $this->mNamespace = NS_MAIN;
719 } else {
720 # Namespace or interwiki prefix
721 if ( preg_match( "/^(.+?)_*:_*(.*)$/", $t, $m ) ) {
722 #$p = strtolower( $m[1] );
723 $p = $m[1];
724 $lowerNs = strtolower( $p );
725 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
726 # Canonical namespace
727 $t = $m[2];
728 $this->mNamespace = $ns;
729 } elseif ( $ns = $wgLang->getNsIndex( $lowerNs )) {
730 # Ordinary namespace
731 $t = $m[2];
732 $this->mNamespace = $ns;
733 } elseif ( $this->getInterwikiLink( $p ) ) {
734 # Interwiki link
735 $t = $m[2];
736 $this->mInterwiki = $p;
737
738 if ( !preg_match( "/^([A-Za-z0-9_\\x80-\\xff]+):(.*)$/", $t, $m ) ) {
739 $done = true;
740 } elseif($this->mInterwiki != $wgLocalInterwiki) {
741 $done = true;
742 }
743 }
744 }
745 $r = $t;
746 }
747
748 # Redundant interwiki prefix to the local wiki
749 if ( 0 == strcmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
750 $this->mInterwiki = '';
751 }
752 # We already know that some pages won't be in the database!
753 #
754 if ( '' != $this->mInterwiki || -1 == $this->mNamespace ) {
755 $this->mArticleID = 0;
756 }
757 $f = strstr( $r, '#' );
758 if ( false !== $f ) {
759 $this->mFragment = substr( $f, 1 );
760 $r = substr( $r, 0, strlen( $r ) - strlen( $f ) );
761 }
762
763 # Reject illegal characters.
764 #
765 if( preg_match( $rxTc, $r ) ) {
766 wfProfileOut( $fname );
767 return false;
768 }
769
770 # "." and ".." conflict with the directories of those namesa
771 if ( strpos( $r, '.' ) !== false &&
772 ( $r === '.' || $r === '..' ||
773 strpos( $r, './' ) === 0 ||
774 strpos( $r, '../' ) === 0 ||
775 strpos( $r, '/./' ) !== false ||
776 strpos( $r, '/../' ) !== false ) )
777 {
778 wfProfileOut( $fname );
779 return false;
780 }
781
782 # Initial capital letter
783 if( $wgCapitalLinks && $this->mInterwiki == '') {
784 $t = $wgLang->ucfirst( $r );
785 } else {
786 $t = $r;
787 }
788
789 # Fill fields
790 $this->mDbkeyform = $t;
791 $this->mUrlform = wfUrlencode( $t );
792
793 $this->mTextform = str_replace( '_', ' ', $t );
794
795 wfProfileOut( $fname );
796 return true;
797 }
798
799 # Get a title object associated with the talk page of this article
800 function getTalkPage() {
801 return Title::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
802 }
803
804 # Get a title object associated with the subject page of this talk page
805 function getSubjectPage() {
806 return Title::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
807 }
808
809 # Get an array of Title objects linking to this title
810 # Also stores the IDs in the link cache
811 # $options may be FOR UPDATE
812 function getLinksTo( $options = '' ) {
813 global $wgLinkCache;
814 $id = $this->getArticleID();
815
816 if ( $options ) {
817 $db =& wfGetDB( DB_MASTER );
818 } else {
819 $db =& wfGetDB( DB_SLAVE );
820 }
821 $cur = $db->tableName( 'cur' );
822 $links = $db->tableName( 'links' );
823
824 $sql = "SELECT cur_namespace,cur_title,cur_id FROM $cur,$links WHERE l_from=cur_id AND l_to={$id} $options";
825 $res = $db->query( $sql, 'Title::getLinksTo' );
826 $retVal = array();
827 if ( $db->numRows( $res ) ) {
828 while ( $row = $db->fetchObject( $res ) ) {
829 if ( $titleObj = Title::makeTitle( $row->cur_namespace, $row->cur_title ) ) {
830 $wgLinkCache->addGoodLink( $row->cur_id, $titleObj->getPrefixedDBkey() );
831 $retVal[] = $titleObj;
832 }
833 }
834 }
835 $db->freeResult( $res );
836 return $retVal;
837 }
838
839 # Get an array of Title objects linking to this non-existent title
840 # Also stores the IDs in the link cache
841 function getBrokenLinksTo( $options = '' ) {
842 global $wgLinkCache;
843
844 if ( $options ) {
845 $db =& wfGetDB( DB_MASTER );
846 } else {
847 $db =& wfGetDB( DB_SLAVE );
848 }
849 $cur = $db->tableName( 'cur' );
850 $brokenlinks = $db->tableName( 'brokenlinks' );
851 $encTitle = $db->strencode( $this->getPrefixedDBkey() );
852
853 $sql = "SELECT cur_namespace,cur_title,cur_id FROM $brokenlinks,$cur " .
854 "WHERE bl_from=cur_id AND bl_to='$encTitle' $options";
855 $res = $db->query( $sql, "Title::getBrokenLinksTo" );
856 $retVal = array();
857 if ( $db->numRows( $res ) ) {
858 while ( $row = $db->fetchObject( $res ) ) {
859 $titleObj = Title::makeTitle( $row->cur_namespace, $row->cur_title );
860 $wgLinkCache->addGoodLink( $row->cur_id, $titleObj->getPrefixedDBkey() );
861 $retVal[] = $titleObj;
862 }
863 }
864 $db->freeResult( $res );
865 return $retVal;
866 }
867
868 function getSquidURLs() {
869 return array(
870 $this->getInternalURL(),
871 $this->getInternalURL( 'action=history' )
872 );
873 }
874
875 function moveNoAuth( &$nt ) {
876 return $this->moveTo( $nt, false );
877 }
878
879 # Move a title to a new location
880 # Returns true on success, message name on failure
881 # auth indicates whether wgUser's permissions should be checked
882 function moveTo( &$nt, $auth = true ) {
883 if( !$this or !$nt ) {
884 return 'badtitletext';
885 }
886
887 $fname = 'Title::move';
888 $oldid = $this->getArticleID();
889 $newid = $nt->getArticleID();
890
891 if ( strlen( $nt->getDBkey() ) < 1 ) {
892 return 'articleexists';
893 }
894 if ( ( ! Namespace::isMovable( $this->getNamespace() ) ) ||
895 ( '' == $this->getDBkey() ) ||
896 ( '' != $this->getInterwiki() ) ||
897 ( !$oldid ) ||
898 ( ! Namespace::isMovable( $nt->getNamespace() ) ) ||
899 ( '' == $nt->getDBkey() ) ||
900 ( '' != $nt->getInterwiki() ) ) {
901 return 'badarticleerror';
902 }
903
904 if ( $auth && ( !$this->userCanEdit() || !$nt->userCanEdit() ) ) {
905 return 'protectedpage';
906 }
907
908 # The move is allowed only if (1) the target doesn't exist, or
909 # (2) the target is a redirect to the source, and has no history
910 # (so we can undo bad moves right after they're done).
911
912 if ( 0 != $newid ) { # Target exists; check for validity
913 if ( ! $this->isValidMoveTarget( $nt ) ) {
914 return 'articleexists';
915 }
916 $this->moveOverExistingRedirect( $nt );
917 } else { # Target didn't exist, do normal move.
918 $this->moveToNewTitle( $nt, $newid );
919 }
920
921 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
922
923 $dbw =& wfGetDB( DB_MASTER );
924 $sql = "UPDATE categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
925 " WHERE cl_from=" . $dbw->addQuotes( $this->getArticleID() ) .
926 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
927 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
928
929 # Update watchlists
930
931 $oldnamespace = $this->getNamespace() & ~1;
932 $newnamespace = $nt->getNamespace() & ~1;
933 $oldtitle = $this->getDBkey();
934 $newtitle = $nt->getDBkey();
935
936 if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) {
937 WatchedItem::duplicateEntries( $this, $nt );
938 }
939
940 # Update search engine
941 $u = new SearchUpdate( $oldid, $nt->getPrefixedDBkey() );
942 $u->doUpdate();
943 $u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), '' );
944 $u->doUpdate();
945
946 return true;
947 }
948
949 # Move page to title which is presently a redirect to the source page
950
951 /* private */ function moveOverExistingRedirect( &$nt ) {
952 global $wgUser, $wgLinkCache, $wgUseSquid, $wgMwRedir;
953 $fname = 'Title::moveOverExistingRedirect';
954 $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
955
956 $now = wfTimestampNow();
957 $won = wfInvertTimestamp( $now );
958 $newid = $nt->getArticleID();
959 $oldid = $this->getArticleID();
960 $dbw =& wfGetDB( DB_MASTER );
961 $links = $dbw->tableName( 'links' );
962
963 # Change the name of the target page:
964 $dbw->updateArray( 'cur',
965 /* SET */ array(
966 'cur_touched' => $now,
967 'cur_namespace' => $nt->getNamespace(),
968 'cur_title' => $nt->getDBkey()
969 ),
970 /* WHERE */ array( 'cur_id' => $oldid ),
971 $fname
972 );
973 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
974
975 # Repurpose the old redirect. We don't save it to history since
976 # by definition if we've got here it's rather uninteresting.
977
978 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
979 $dbw->updateArray( 'cur',
980 /* SET */ array(
981 'cur_touched' => $now,
982 'cur_timestamp' => $now,
983 'inverse_timestamp' => $won,
984 'cur_namespace' => $this->getNamespace(),
985 'cur_title' => $this->getDBkey(),
986 'cur_text' => $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n",
987 'cur_comment' => $comment,
988 'cur_user' => $wgUser->getID(),
989 'cur_minor_edit' => 0,
990 'cur_counter' => 0,
991 'cur_restrictions' => '',
992 'cur_user_text' => $wgUser->getName(),
993 'cur_is_redirect' => 1,
994 'cur_is_new' => 1
995 ),
996 /* WHERE */ array( 'cur_id' => $newid ),
997 $fname
998 );
999
1000 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1001
1002 # Fix the redundant names for the past revisions of the target page.
1003 # The redirect should have no old revisions.
1004 $dbw->updateArray(
1005 /* table */ 'old',
1006 /* SET */ array(
1007 'old_namespace' => $nt->getNamespace(),
1008 'old_title' => $nt->getDBkey(),
1009 ),
1010 /* WHERE */ array(
1011 'old_namespace' => $this->getNamespace(),
1012 'old_title' => $this->getDBkey(),
1013 ),
1014 $fname
1015 );
1016
1017 RecentChange::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
1018
1019 # Swap links
1020
1021 # Load titles and IDs
1022 $linksToOld = $this->getLinksTo( 'FOR UPDATE' );
1023 $linksToNew = $nt->getLinksTo( 'FOR UPDATE' );
1024
1025 # Delete them all
1026 $sql = "DELETE FROM $links WHERE l_to=$oldid OR l_to=$newid";
1027 $dbw->query( $sql, $fname );
1028
1029 # Reinsert
1030 if ( count( $linksToOld ) || count( $linksToNew )) {
1031 $sql = "INSERT INTO $links (l_from,l_to) VALUES ";
1032 $first = true;
1033
1034 # Insert links to old title
1035 foreach ( $linksToOld as $linkTitle ) {
1036 if ( $first ) {
1037 $first = false;
1038 } else {
1039 $sql .= ',';
1040 }
1041 $id = $linkTitle->getArticleID();
1042 $sql .= "($id,$newid)";
1043 }
1044
1045 # Insert links to new title
1046 foreach ( $linksToNew as $linkTitle ) {
1047 if ( $first ) {
1048 $first = false;
1049 } else {
1050 $sql .= ',';
1051 }
1052 $id = $linkTitle->getArticleID();
1053 $sql .= "($id, $oldid)";
1054 }
1055
1056 $dbw->query( $sql, DB_MASTER, $fname );
1057 }
1058
1059 # Now, we record the link from the redirect to the new title.
1060 # It should have no other outgoing links...
1061 $dbw->delete( 'links', array( 'l_from' => $newid ) );
1062 $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
1063
1064 # Clear linkscc
1065 LinkCache::linksccClearLinksTo( $oldid );
1066 LinkCache::linksccClearLinksTo( $newid );
1067
1068 # Purge squid
1069 if ( $wgUseSquid ) {
1070 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
1071 $u = new SquidUpdate( $urls );
1072 $u->doUpdate();
1073 }
1074 }
1075
1076 # Move page to non-existing title.
1077 # Sets $newid to be the new article ID
1078
1079 /* private */ function moveToNewTitle( &$nt, &$newid ) {
1080 global $wgUser, $wgLinkCache, $wgUseSquid;
1081 $fname = 'MovePageForm::moveToNewTitle';
1082 $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1083
1084 $now = wfTimestampNow();
1085 $won = wfInvertTimestamp( $now );
1086 $newid = $nt->getArticleID();
1087 $oldid = $this->getArticleID();
1088 $dbw =& wfGetDB( DB_MASTER );
1089
1090 # Rename cur entry
1091 $dbw->updateArray( 'cur',
1092 /* SET */ array(
1093 'cur_touched' => $now,
1094 'cur_namespace' => $nt->getNamespace(),
1095 'cur_title' => $nt->getDBkey()
1096 ),
1097 /* WHERE */ array( 'cur_id' => $oldid ),
1098 $fname
1099 );
1100
1101 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
1102
1103 # Insert redirct
1104 $dbw->insertArray( 'cur', array(
1105 'cur_namespace' => $this->getNamespace(),
1106 'cur_title' => $this->getDBkey(),
1107 'cur_comment' => $comment,
1108 'cur_user' => $wgUser->getID(),
1109 'cur_user_text' => $wgUser->getName(),
1110 'cur_timestamp' => $now,
1111 'inverse_timestamp' => $won,
1112 'cur_touched' => $now,
1113 'cur_is_redirect' => 1,
1114 'cur_is_new' => 1,
1115 'cur_text' => "#REDIRECT [[" . $nt->getPrefixedText() . "]]\n" ), $fname
1116 );
1117 $newid = $dbw->insertId();
1118 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1119
1120 # Rename old entries
1121 $dbw->updateArray(
1122 /* table */ 'old',
1123 /* SET */ array(
1124 'old_namespace' => $nt->getNamespace(),
1125 'old_title' => $nt->getDBkey()
1126 ),
1127 /* WHERE */ array(
1128 'old_namespace' => $this->getNamespace(),
1129 'old_title' => $this->getDBkey()
1130 ), $fname
1131 );
1132
1133 # Record in RC
1134 RecentChange::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
1135
1136 # Purge squid and linkscc as per article creation
1137 Article::onArticleCreate( $nt );
1138
1139 # Any text links to the old title must be reassigned to the redirect
1140 $dbw->updateArray( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
1141 LinkCache::linksccClearLinksTo( $oldid );
1142
1143 # Record the just-created redirect's linking to the page
1144 $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
1145
1146 # Non-existent target may have had broken links to it; these must
1147 # now be removed and made into good links.
1148 $update = new LinksUpdate( $oldid, $nt->getPrefixedDBkey() );
1149 $update->fixBrokenLinks();
1150
1151 # Purge old title from squid
1152 # The new title, and links to the new title, are purged in Article::onArticleCreate()
1153 $titles = $nt->getLinksTo();
1154 if ( $wgUseSquid ) {
1155 $urls = $this->getSquidURLs();
1156 foreach ( $titles as $linkTitle ) {
1157 $urls[] = $linkTitle->getInternalURL();
1158 }
1159 $u = new SquidUpdate( $urls );
1160 $u->doUpdate();
1161 }
1162 }
1163
1164 # Checks if $this can be moved to $nt
1165 # Selects for update, so don't call it unless you mean business
1166 function isValidMoveTarget( $nt ) {
1167 $fname = 'Title::isValidMoveTarget';
1168 $dbw =& wfGetDB( DB_MASTER );
1169
1170 # Is it a redirect?
1171 $id = $nt->getArticleID();
1172 $obj = $dbw->getArray( 'cur', array( 'cur_is_redirect','cur_text' ),
1173 array( 'cur_id' => $id ), $fname, 'FOR UPDATE' );
1174
1175 if ( !$obj || 0 == $obj->cur_is_redirect ) {
1176 # Not a redirect
1177 return false;
1178 }
1179
1180 # Does the redirect point to the source?
1181 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $obj->cur_text, $m ) ) {
1182 $redirTitle = Title::newFromText( $m[1] );
1183 if( !is_object( $redirTitle ) ||
1184 $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
1185 return false;
1186 }
1187 }
1188
1189 # Does the article have a history?
1190 $row = $dbw->getArray( 'old', array( 'old_id' ),
1191 array(
1192 'old_namespace' => $nt->getNamespace(),
1193 'old_title' => $nt->getDBkey()
1194 ), $fname, 'FOR UPDATE'
1195 );
1196
1197 # Return true if there was no history
1198 return $row === false;
1199 }
1200
1201 # Create a redirect, fails if the title already exists, does not notify RC
1202 # Returns success
1203 function createRedirect( $dest, $comment ) {
1204 global $wgUser;
1205 if ( $this->getArticleID() ) {
1206 return false;
1207 }
1208
1209 $fname = 'Title::createRedirect';
1210 $dbw =& wfGetDB( DB_MASTER );
1211 $now = wfTimestampNow();
1212 $won = wfInvertTimestamp( $now );
1213 $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
1214
1215 $dbw->insertArray( 'cur', array(
1216 'cur_id' => $seqVal,
1217 'cur_namespace' => $this->getNamespace(),
1218 'cur_title' => $this->getDBkey(),
1219 'cur_comment' => $comment,
1220 'cur_user' => $wgUser->getID(),
1221 'cur_user_text' => $wgUser->getName(),
1222 'cur_timestamp' => $now,
1223 'inverse_timestamp' => $won,
1224 'cur_touched' => $now,
1225 'cur_is_redirect' => 1,
1226 'cur_is_new' => 1,
1227 'cur_text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n"
1228 ), $fname );
1229 $newid = $dbw->insertId();
1230 $this->resetArticleID( $newid );
1231
1232 # Link table
1233 if ( $dest->getArticleID() ) {
1234 $dbw->insertArray( 'links',
1235 array(
1236 'l_to' => $dest->getArticleID(),
1237 'l_from' => $newid
1238 ), $fname
1239 );
1240 } else {
1241 $dbw->insertArray( 'brokenlinks',
1242 array(
1243 'bl_to' => $dest->getPrefixedDBkey(),
1244 'bl_from' => $newid
1245 ), $fname
1246 );
1247 }
1248
1249 Article::onArticleCreate( $this );
1250 return true;
1251 }
1252
1253 # Get categories to wich belong this title and return an array of
1254 # categories names.
1255 function getParentCategories( ) {
1256 global $wgLang,$wgUser;
1257
1258 $titlekey = $this->getArticleId();
1259 $cns = Namespace::getCategory();
1260 $sk =& $wgUser->getSkin();
1261 $parents = array();
1262 $dbr =& wfGetDB( DB_SLAVE );
1263 $cur = $dbr->tableName( 'cur' );
1264 $categorylinks = $dbr->tableName( 'categorylinks' );
1265
1266 # get the parents categories of this title from the database
1267 $sql = "SELECT DISTINCT cur_id FROM $cur,$categorylinks
1268 WHERE cl_from='$titlekey' AND cl_to=cur_title AND cur_namespace='$cns'
1269 ORDER BY cl_sortkey" ;
1270 $res = $dbr->query ( $sql ) ;
1271
1272 if($dbr->numRows($res) > 0) {
1273 while ( $x = $dbr->fetchObject ( $res ) ) $data[] = $x ;
1274 $dbr->freeResult ( $res ) ;
1275 } else {
1276 $data = '';
1277 }
1278 return $data;
1279 }
1280
1281 # will get the parents and grand-parents
1282 # TODO : not sure what's happening when a loop happen like:
1283 # Encyclopedia > Astronomy > Encyclopedia
1284 function getAllParentCategories(&$stack) {
1285 global $wgUser,$wgLang;
1286 $result = '';
1287
1288 # getting parents
1289 $parents = $this->getParentCategories( );
1290
1291 if($parents == '')
1292 {
1293 # The current element has no more parent so we dump the stack
1294 # and make a clean line of categories
1295 $sk =& $wgUser->getSkin() ;
1296
1297 foreach ( array_reverse($stack) as $child => $parent )
1298 {
1299 # make a link of that parent
1300 $result .= $sk->makeLink($wgLang->getNSText ( Namespace::getCategory() ).':'.$parent,$parent);
1301 $result .= ' &gt; ';
1302 $lastchild = $child;
1303 }
1304 # append the last child.
1305 # TODO : We should have a last child unless there is an error in the
1306 # "categorylinks" table.
1307 if(isset($lastchild)) { $result .= $lastchild; }
1308
1309 $result .= "<br/>\n";
1310
1311 # now we can empty the stack
1312 $stack = array();
1313
1314 } else {
1315 # look at parents of current category
1316 foreach($parents as $parent)
1317 {
1318 # create a title object for the parent
1319 $tpar = Title::newFromID($parent->cur_id);
1320 # add it to the stack
1321 $stack[$this->getText()] = $tpar->getText();
1322 # grab its parents
1323 $result .= $tpar->getAllParentCategories($stack);
1324 }
1325 }
1326
1327 if(isset($result)) { return $result; }
1328 else { return ''; };
1329 }
1330
1331 # Returns an associative array for selecting this title from cur
1332 function curCond() {
1333 return array( 'cur_namespace' => $this->mNamespace, 'cur_title' => $this->mDbkeyform );
1334 }
1335
1336 function oldCond() {
1337 return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
1338 }
1339 }
1340 ?>