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