Commit JeLuF's register_globals fixes, first phase
[lhc/web/wiklou.git] / includes / Article.php
1 <?
2 # Class representing a Wikipedia article and history.
3 # See design.doc for an overview.
4
5 # Note: edit user interface and cache support functions have been
6 # moved to separate EditPage and CacheManager classes.
7
8 /* CHECK MERGE @@@
9 TEST THIS @@@
10
11 * s/\$wgTitle/\$this->mTitle/ performed, many replacements
12 * mTitle variable added to class
13 */
14
15 include_once( "CacheManager.php" );
16
17 class Article {
18 /* private */ var $mContent, $mContentLoaded;
19 /* private */ var $mUser, $mTimestamp, $mUserText;
20 /* private */ var $mCounter, $mComment, $mCountAdjustment;
21 /* private */ var $mMinorEdit, $mRedirectedFrom;
22 /* private */ var $mTouched, $mFileCache, $mTitle;
23
24 function Article( &$title ) {
25 $this->mTitle =& $title;
26 $this->clear();
27 }
28
29 /* private */ function clear()
30 {
31 $this->mContentLoaded = false;
32 $this->mUser = $this->mCounter = -1; # Not loaded
33 $this->mRedirectedFrom = $this->mUserText =
34 $this->mTimestamp = $this->mComment = $this->mFileCache = "";
35 $this->mCountAdjustment = 0;
36 $this->mTouched = "19700101000000";
37 }
38
39 # Note that getContent/loadContent may follow redirects if
40 # not told otherwise, and so may cause a change to mTitle.
41
42 function getContent( $noredir = false )
43 {
44 global $action,$section,$count; # From query string
45 $section = $_REQUEST["section"];
46 $count = $_REQUEST['count'];
47 $fname = "Article::getContent";
48 wfProfileIn( $fname );
49
50 if ( 0 == $this->getID() ) {
51 if ( "edit" == $action ) {
52 wfProfileOut( $fname );
53 return ""; # was "newarticletext", now moved above the box)
54 }
55 wfProfileOut( $fname );
56 return wfMsg( "noarticletext" );
57 } else {
58 $this->loadContent( $noredir );
59
60 if(
61 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
62 ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
63 preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle->getText()) &&
64 $action=="view"
65 )
66 {
67 wfProfileOut( $fname );
68 return $this->mContent . "\n" .wfMsg("anontalkpagetext"); }
69 else {
70 if($action=="edit") {
71 if($section!="") {
72 if($section=="new") {
73 wfProfileOut( $fname );
74 return "";
75 }
76
77 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
78 $this->mContent, -1,
79 PREG_SPLIT_DELIM_CAPTURE);
80 if($section==0) {
81 wfProfileOut( $fname );
82 return trim($secs[0]);
83 } else {
84 wfProfileOut( $fname );
85 return trim($secs[$section*2-1] . $secs[$section*2]);
86 }
87 }
88 }
89 wfProfileOut( $fname );
90 return $this->mContent;
91 }
92 }
93 }
94
95 function loadContent( $noredir = false )
96 {
97 global $wgOut, $wgMwRedir;
98 global $oldid, $redirect; # From query
99
100 if ( $this->mContentLoaded ) return;
101 $fname = "Article::loadContent";
102
103 # Pre-fill content with error message so that if something
104 # fails we'll have something telling us what we intended.
105
106 $t = $this->mTitle->getPrefixedText();
107 if ( isset( $oldid ) ) {
108 $oldid = IntVal( $oldid );
109 $t .= ",oldid={$oldid}";
110 }
111 if ( isset( $redirect ) ) {
112 $redirect = ($redirect == "no") ? "no" : "yes";
113 $t .= ",redirect={$redirect}";
114 }
115 $this->mContent = wfMsg( "missingarticle", $t );
116
117 if ( ! $oldid ) { # Retrieve current version
118 $id = $this->getID();
119 if ( 0 == $id ) return;
120
121 $sql = "SELECT " .
122 "cur_text,cur_timestamp,cur_user,cur_counter,cur_restrictions,cur_touched " .
123 "FROM cur WHERE cur_id={$id}";
124 wfDebug( "$sql\n" );
125 $res = wfQuery( $sql, DB_READ, $fname );
126 if ( 0 == wfNumRows( $res ) ) {
127 return;
128 }
129
130 $s = wfFetchObject( $res );
131 # If we got a redirect, follow it (unless we've been told
132 # not to by either the function parameter or the query
133 if ( ( "no" != $redirect ) && ( false == $noredir ) &&
134 ( $wgMwRedir->matchStart( $s->cur_text ) ) ) {
135 if ( preg_match( "/\\[\\[([^\\]\\|]+)[\\]\\|]/",
136 $s->cur_text, $m ) ) {
137 $rt = Title::newFromText( $m[1] );
138
139 # Gotta hand redirects to special pages differently:
140 # Fill the HTTP response "Location" header and ignore
141 # the rest of the page we're on.
142
143 if ( $rt->getInterwiki() != "" ) {
144 $wgOut->redirect( $rt->getFullURL() ) ;
145 return;
146 }
147 if ( $rt->getNamespace() == Namespace::getSpecial() ) {
148 $wgOut->redirect( wfLocalUrl(
149 $rt->getPrefixedURL() ) );
150 return;
151 }
152 $rid = $rt->getArticleID();
153 if ( 0 != $rid ) {
154 $sql = "SELECT cur_text,cur_timestamp,cur_user," .
155 "cur_counter,cur_restrictions,cur_touched FROM cur WHERE cur_id={$rid}";
156 $res = wfQuery( $sql, DB_READ, $fname );
157
158 if ( 0 != wfNumRows( $res ) ) {
159 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
160 $this->mTitle = $rt;
161 $s = wfFetchObject( $res );
162 }
163 }
164 }
165 }
166
167 $this->mContent = $s->cur_text;
168 $this->mUser = $s->cur_user;
169 $this->mCounter = $s->cur_counter;
170 $this->mTimestamp = $s->cur_timestamp;
171 $this->mTouched = $s->cur_touched;
172 $this->mTitle->mRestrictions = explode( ",", trim( $s->cur_restrictions ) );
173 $this->mTitle->mRestrictionsLoaded = true;
174 wfFreeResult( $res );
175 } else { # oldid set, retrieve historical version
176 $sql = "SELECT old_text,old_timestamp,old_user FROM old " .
177 "WHERE old_id={$oldid}";
178 $res = wfQuery( $sql, DB_READ, $fname );
179 if ( 0 == wfNumRows( $res ) ) { return; }
180
181 $s = wfFetchObject( $res );
182 $this->mContent = $s->old_text;
183 $this->mUser = $s->old_user;
184 $this->mCounter = 0;
185 $this->mTimestamp = $s->old_timestamp;
186 wfFreeResult( $res );
187 }
188 $this->mContentLoaded = true;
189 }
190
191 function getID() { return $this->mTitle->getArticleID(); }
192
193 function getCount()
194 {
195 if ( -1 == $this->mCounter ) {
196 $id = $this->getID();
197 $this->mCounter = wfGetSQL( "cur", "cur_counter", "cur_id={$id}" );
198 }
199 return $this->mCounter;
200 }
201
202 # Would the given text make this article a "good" article (i.e.,
203 # suitable for including in the article count)?
204
205 function isCountable( $text )
206 {
207 global $wgUseCommaCount, $wgMwRedir;
208
209 if ( 0 != $this->mTitle->getNamespace() ) { return 0; }
210 if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
211 $token = ($wgUseCommaCount ? "," : "[[" );
212 if ( false === strstr( $text, $token ) ) { return 0; }
213 return 1;
214 }
215
216 # Load the field related to the last edit time of the article.
217 # This isn't necessary for all uses, so it's only done if needed.
218
219 /* private */ function loadLastEdit()
220 {
221 global $wgOut;
222 if ( -1 != $this->mUser ) return;
223
224 $sql = "SELECT cur_user,cur_user_text,cur_timestamp," .
225 "cur_comment,cur_minor_edit FROM cur WHERE " .
226 "cur_id=" . $this->getID();
227 $res = wfQuery( $sql, DB_READ, "Article::loadLastEdit" );
228
229 if ( wfNumRows( $res ) > 0 ) {
230 $s = wfFetchObject( $res );
231 $this->mUser = $s->cur_user;
232 $this->mUserText = $s->cur_user_text;
233 $this->mTimestamp = $s->cur_timestamp;
234 $this->mComment = $s->cur_comment;
235 $this->mMinorEdit = $s->cur_minor_edit;
236 }
237 }
238
239 function getTimestamp()
240 {
241 $this->loadLastEdit();
242 return $this->mTimestamp;
243 }
244
245 function getUser()
246 {
247 $this->loadLastEdit();
248 return $this->mUser;
249 }
250
251 function getUserText()
252 {
253 $this->loadLastEdit();
254 return $this->mUserText;
255 }
256
257 function getComment()
258 {
259 $this->loadLastEdit();
260 return $this->mComment;
261 }
262
263 function getMinorEdit()
264 {
265 $this->loadLastEdit();
266 return $this->mMinorEdit;
267 }
268
269 # This is the default action of the script: just view the page of
270 # the given title.
271
272 function view()
273 {
274 global $wgUser, $wgOut, $wgLang;
275 global $oldid, $diff; # From query
276 global $wgLinkCache, $IP;
277 $fname = "Article::view";
278 wfProfileIn( $fname );
279
280 $wgOut->setArticleFlag( true );
281 $wgOut->setRobotpolicy( "index,follow" );
282
283 # If we got diff and oldid in the query, we want to see a
284 # diff page instead of the article.
285
286 if ( isset( $diff ) ) {
287 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
288 $de = new DifferenceEngine( $oldid, $diff );
289 $de->showDiffPage();
290 wfProfileOut( $fname );
291 return;
292 }
293
294 if ( !isset( $oldid ) ) {
295 if( $this->checkTouched() ) {
296 $wgOut->checkLastModified( $this->mTouched );
297 $this->tryFileCache();
298 }
299 }
300
301 $text = $this->getContent(); # May change mTitle
302 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
303 $wgOut->setHTMLTitle( $this->mTitle->getPrefixedText() .
304 " - " . wfMsg( "wikititlesuffix" ) );
305
306 # We're looking at an old revision
307
308 if ( $oldid ) {
309 $this->setOldSubtitle();
310 $wgOut->setRobotpolicy( "noindex,follow" );
311 }
312 if ( "" != $this->mRedirectedFrom ) {
313 $sk = $wgUser->getSkin();
314 $redir = $sk->makeKnownLink( $this->mRedirectedFrom, "",
315 "redirect=no" );
316 $s = wfMsg( "redirectedfrom", $redir );
317 $wgOut->setSubtitle( $s );
318 }
319 $wgOut->checkLastModified( $this->mTouched );
320 $this->tryFileCache();
321 $wgLinkCache->preFill( $this->mTitle );
322 $wgOut->addWikiText( $text );
323
324 $this->viewUpdates();
325 wfProfileOut( $fname );
326 }
327
328 # Theoretically we could defer these whole insert and update
329 # functions for after display, but that's taking a big leap
330 # of faith, and we want to be able to report database
331 # errors at some point.
332
333 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
334 {
335 global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir;
336 global $wgEnablePersistentLC;
337
338 $fname = "Article::insertNewArticle";
339
340 $ns = $this->mTitle->getNamespace();
341 $ttl = $this->mTitle->getDBkey();
342 $text = $this->preSaveTransform( $text );
343 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
344 else { $redir = 0; }
345
346 $now = wfTimestampNow();
347 $won = wfInvertTimestamp( $now );
348 wfSeedRandom();
349 $rand = number_format( mt_rand() / mt_getrandmax(), 12, ".", "" );
350 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
351 "cur_comment,cur_user,cur_timestamp,cur_minor_edit,cur_counter," .
352 "cur_restrictions,cur_user_text,cur_is_redirect," .
353 "cur_is_new,cur_random,cur_touched,inverse_timestamp) VALUES ({$ns},'" . wfStrencode( $ttl ) . "', '" .
354 wfStrencode( $text ) . "', '" .
355 wfStrencode( $summary ) . "', '" .
356 $wgUser->getID() . "', '{$now}', " .
357 ( $isminor ? 1 : 0 ) . ", 0, '', '" .
358 wfStrencode( $wgUser->getName() ) . "', $redir, 1, $rand, '{$now}', '{$won}')";
359 $res = wfQuery( $sql, DB_WRITE, $fname );
360
361 $newid = wfInsertId();
362 $this->mTitle->resetArticleID( $newid );
363
364 if ( $wgEnablePersistentLC ) {
365 // Purge related entries in links cache on new page, to heal broken links
366 $ptitle = wfStrencode( $ttl );
367 wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
368 "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE);
369 }
370
371 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
372 "rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," .
373 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot) VALUES (" .
374 "'{$now}','{$now}',{$ns},'" . wfStrencode( $ttl ) . "',1," .
375 ( $isminor ? 1 : 0 ) . ",{$newid}," . $wgUser->getID() . ",'" .
376 wfStrencode( $wgUser->getName() ) . "','" .
377 wfStrencode( $summary ) . "',0,0," .
378 ( $wgUser->isBot() ? 1 : 0 ) . ")";
379 wfQuery( $sql, DB_WRITE, $fname );
380 if ($watchthis) {
381 if(!$this->mTitle->userIsWatching()) $this->watch();
382 } else {
383 if ( $this->mTitle->userIsWatching() ) {
384 $this->unwatch();
385 }
386 }
387
388 # The talk page isn't in the regular link tables, so we need to update manually:
389 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
390 $sql = "UPDATE cur set cur_touched='$now' WHERE cur_namespace=$talkns AND cur_title='" . wfStrencode( $ttl ) . "'";
391 wfQuery( $sql, DB_WRITE );
392
393 $this->showArticle( $text, wfMsg( "newarticle" ) );
394 }
395
396 function updateArticle( $text, $summary, $minor, $watchthis, $section = "")
397 {
398 global $wgOut, $wgUser, $wgLinkCache;
399 global $wgDBtransactions, $wgMwRedir;
400 $fname = "Article::updateArticle";
401
402 $this->loadLastEdit();
403
404 // insert updated section into old text if we have only edited part
405 // of the article
406 if ($section != "") {
407 $oldtext=$this->getContent();
408 if($section=="new") {
409 if($summary) $subject="== {$summary} ==\n\n";
410 $text=$oldtext."\n\n".$subject.$text;
411 } else {
412 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
413 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
414 $secs[$section*2]=$text."\n\n"; // replace with edited
415 if($section) { $secs[$section*2-1]=""; } // erase old headline
416 $text=join("",$secs);
417 }
418 }
419 if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
420 if ( $minor ) { $me2 = 1; } else { $me2 = 0; }
421 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ")[^\\n]+)/i", $text, $m ) ) {
422 $redir = 1;
423 $text = $m[1] . "\n"; # Remove all content but redirect
424 }
425 else { $redir = 0; }
426
427 $text = $this->preSaveTransform( $text );
428
429 # Update article, but only if changed.
430
431 if( $wgDBtransactions ) {
432 $sql = "BEGIN";
433 wfQuery( $sql, DB_WRITE );
434 }
435 $oldtext = $this->getContent( true );
436
437 if ( 0 != strcmp( $text, $oldtext ) ) {
438 $this->mCountAdjustment = $this->isCountable( $text )
439 - $this->isCountable( $oldtext );
440
441 $now = wfTimestampNow();
442 $won = wfInvertTimestamp( $now );
443 $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
444 "',cur_comment='" . wfStrencode( $summary ) .
445 "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
446 ",cur_timestamp='{$now}',cur_user_text='" .
447 wfStrencode( $wgUser->getName() ) .
448 "',cur_is_redirect={$redir}, cur_is_new=0, cur_touched='{$now}', inverse_timestamp='{$won}' " .
449 "WHERE cur_id=" . $this->getID() .
450 " AND cur_timestamp='" . $this->getTimestamp() . "'";
451 $res = wfQuery( $sql, DB_WRITE, $fname );
452
453 if( wfAffectedRows() == 0 ) {
454 /* Belated edit conflict! Run away!! */
455 return false;
456 }
457
458 $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
459 "old_comment,old_user,old_user_text,old_timestamp," .
460 "old_minor_edit,inverse_timestamp) VALUES (" .
461 $this->mTitle->getNamespace() . ", '" .
462 wfStrencode( $this->mTitle->getDBkey() ) . "', '" .
463 wfStrencode( $oldtext ) . "', '" .
464 wfStrencode( $this->getComment() ) . "', " .
465 $this->getUser() . ", '" .
466 wfStrencode( $this->getUserText() ) . "', '" .
467 $this->getTimestamp() . "', " . $me1 . ", '" .
468 wfInvertTimestamp( $this->getTimestamp() ) . "')";
469 $res = wfQuery( $sql, DB_WRITE, $fname );
470 $oldid = wfInsertID( $res );
471
472 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
473 "rc_namespace,rc_title,rc_new,rc_minor,rc_bot,rc_cur_id,rc_user," .
474 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid) VALUES (" .
475 "'{$now}','{$now}'," . $this->mTitle->getNamespace() . ",'" .
476 wfStrencode( $this->mTitle->getDBkey() ) . "',0,{$me2}," .
477 ( $wgUser->isBot() ? 1 : 0 ) . "," .
478 $this->getID() . "," . $wgUser->getID() . ",'" .
479 wfStrencode( $wgUser->getName() ) . "','" .
480 wfStrencode( $summary ) . "',0,{$oldid})";
481 wfQuery( $sql, DB_WRITE, $fname );
482
483 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
484 "WHERE rc_namespace=" . $this->mTitle->getNamespace() . " AND " .
485 "rc_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' AND " .
486 "rc_timestamp='" . $this->getTimestamp() . "'";
487 wfQuery( $sql, DB_WRITE, $fname );
488
489 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
490 "WHERE rc_cur_id=" . $this->getID();
491 wfQuery( $sql, DB_WRITE, $fname );
492
493 if ( $wgEnablePersistentLC ) {
494
495 // Purge link cache for this page
496 $pageid=$this->getID();
497 wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pageid}'", DB_WRITE);
498
499 // This next query just makes sure stub colored links to this page
500 // are updated correctly (I think). If performance is more important
501 // than real-time updating of stub links, we really should skip
502 // this query.
503 wfQuery("DELETE linkscc FROM linkscc,links ".
504 "WHERE lcc_title=links.l_from AND l_to={$pageid}", DB_WRITE);
505 }
506
507 }
508 if( $wgDBtransactions ) {
509 $sql = "COMMIT";
510 wfQuery( $sql, DB_WRITE );
511 }
512
513 if ($watchthis) {
514 if (!$this->mTitle->userIsWatching()) $this->watch();
515 } else {
516 if ( $this->mTitle->userIsWatching() ) {
517 $this->unwatch();
518 }
519 }
520
521 $this->showArticle( $text, wfMsg( "updated" ) );
522 return true;
523 }
524
525 # After we've either updated or inserted the article, update
526 # the link tables and redirect to the new page.
527
528 function showArticle( $text, $subtitle )
529 {
530 global $wgOut, $wgUser, $wgLinkCache, $wgUseBetterLinksUpdate;
531 global $wgMwRedir;
532
533 $wgLinkCache = new LinkCache();
534
535 # Get old version of link table to allow incremental link updates
536 if ( $wgUseBetterLinksUpdate ) {
537 $wgLinkCache->preFill( $this->mTitle );
538 $wgLinkCache->clear();
539 }
540
541 # Now update the link cache by parsing the text
542 $wgOut = new OutputPage();
543 $wgOut->addWikiText( $text );
544
545 $this->editUpdates( $text );
546 if( $wgMwRedir->matchStart( $text ) )
547 $r = "redirect=no";
548 else
549 $r = "";
550 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL(), $r ) );
551 }
552
553 # Add this page to my watchlist
554
555 function watch( $add = true )
556 {
557 global $wgUser, $wgOut, $wgLang;
558 global $wgDeferredUpdateList;
559
560 if ( 0 == $wgUser->getID() ) {
561 $wgOut->errorpage( "watchnologin", "watchnologintext" );
562 return;
563 }
564 if ( wfReadOnly() ) {
565 $wgOut->readOnlyPage();
566 return;
567 }
568 if( $add )
569 $wgUser->addWatch( $this->mTitle );
570 else
571 $wgUser->removeWatch( $this->mTitle );
572
573 $wgOut->setPagetitle( wfMsg( $add ? "addedwatch" : "removedwatch" ) );
574 $wgOut->setRobotpolicy( "noindex,follow" );
575
576 $sk = $wgUser->getSkin() ;
577 $link = $sk->makeKnownLink ( $this->mTitle->getPrefixedText() ) ;
578
579 if($add)
580 $text = wfMsg( "addedwatchtext", $link );
581 else
582 $text = wfMsg( "removedwatchtext", $link );
583 $wgOut->addHTML( $text );
584
585 $up = new UserUpdate();
586 array_push( $wgDeferredUpdateList, $up );
587
588 $wgOut->returnToMain( false );
589 }
590
591 function unwatch()
592 {
593 $this->watch( false );
594 }
595
596 # This shares a lot of issues (and code) with Recent Changes
597
598 function history()
599 {
600 global $wgUser, $wgOut, $wgLang, $offset, $limit;
601
602 # If page hasn't changed, client can cache this
603
604 $wgOut->checkLastModified( $this->getTimestamp() );
605 $fname = "Article::history";
606 wfProfileIn( $fname );
607
608 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
609 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
610 $wgOut->setArticleFlag( false );
611 $wgOut->setRobotpolicy( "noindex,nofollow" );
612
613 if( $this->mTitle->getArticleID() == 0 ) {
614 $wgOut->addHTML( wfMsg( "nohistory" ) );
615 wfProfileOut( $fname );
616 return;
617 }
618
619 $offset = (int)$offset;
620 $limit = (int)$limit;
621 if( $limit == 0 ) $limit = 50;
622 $namespace = $this->mTitle->getNamespace();
623 $title = $this->mTitle->getText();
624 $sql = "SELECT old_id,old_user," .
625 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
626 "FROM old USE INDEX (name_title_timestamp) " .
627 "WHERE old_namespace={$namespace} AND " .
628 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
629 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
630 $res = wfQuery( $sql, DB_READ, "Article::history" );
631
632 $revs = wfNumRows( $res );
633 if( $this->mTitle->getArticleID() == 0 ) {
634 $wgOut->addHTML( wfMsg( "nohistory" ) );
635 wfProfileOut( $fname );
636 return;
637 }
638
639 $sk = $wgUser->getSkin();
640 $numbar = wfViewPrevNext(
641 $offset, $limit,
642 $this->mTitle->getPrefixedText(),
643 "action=history" );
644 $s = $numbar;
645 $s .= $sk->beginHistoryList();
646
647 if($offset == 0 )
648 $s .= $sk->historyLine( $this->getTimestamp(), $this->getUser(),
649 $this->getUserText(), $namespace,
650 $title, 0, $this->getComment(),
651 ( $this->getMinorEdit() > 0 ) );
652
653 $revs = wfNumRows( $res );
654 while ( $line = wfFetchObject( $res ) ) {
655 $s .= $sk->historyLine( $line->old_timestamp, $line->old_user,
656 $line->old_user_text, $namespace,
657 $title, $line->old_id,
658 $line->old_comment, ( $line->old_minor_edit > 0 ) );
659 }
660 $s .= $sk->endHistoryList();
661 $s .= $numbar;
662 $wgOut->addHTML( $s );
663 wfProfileOut( $fname );
664 }
665
666 function protect( $limit = "sysop" )
667 {
668 global $wgUser, $wgOut;
669
670 if ( ! $wgUser->isSysop() ) {
671 $wgOut->sysopRequired();
672 return;
673 }
674 if ( wfReadOnly() ) {
675 $wgOut->readOnlyPage();
676 return;
677 }
678 $id = $this->mTitle->getArticleID();
679 if ( 0 == $id ) {
680 $wgOut->fatalEror( wfMsg( "badarticleerror" ) );
681 return;
682 }
683 $sql = "UPDATE cur SET cur_touched='" . wfTimestampNow() . "'," .
684 "cur_restrictions='{$limit}' WHERE cur_id={$id}";
685 wfQuery( $sql, DB_WRITE, "Article::protect" );
686
687 $log = new LogPage( wfMsg( "protectlogpage" ), wfMsg( "protectlogtext" ) );
688 if ( $limit === "" ) {
689 $log->addEntry( wfMsg( "unprotectedarticle", $this->mTitle->getPrefixedText() ), "" );
690 } else {
691 $log->addEntry( wfMsg( "protectedarticle", $this->mTitle->getPrefixedText() ), "" );
692 }
693 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL() ) );
694 }
695
696 function unprotect()
697 {
698 return $this->protect( "" );
699 }
700
701 function delete()
702 {
703 global $wgUser, $wgOut;
704 global $wpConfirm, $wpReason, $image, $oldimage;
705 $wpReason = $_REQUEST["wpReason"];
706 $wpConfirm = $_REQUEST["wpConfirm"];
707
708 # This code desperately needs to be totally rewritten
709
710 if ( ( ! $wgUser->isSysop() ) ) {
711 $wgOut->sysopRequired();
712 return;
713 }
714 if ( wfReadOnly() ) {
715 $wgOut->readOnlyPage();
716 return;
717 }
718
719 # Better double-check that it hasn't been deleted yet!
720 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
721 if ( ( "" == trim( $this->mTitle->getText() ) )
722 or ( $this->mTitle->getArticleId() == 0 ) ) {
723 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
724 return;
725 }
726
727 if ( $wpConfirm ) {
728 $this->doDelete();
729 return;
730 }
731
732 # determine whether this page has earlier revisions
733 # and insert a warning if it does
734 # we select the text because it might be useful below
735 $sql="SELECT old_text FROM old WHERE old_namespace=0 and old_title='" . wfStrencode($this->mTitle->getPrefixedDBkey())."' ORDER BY inverse_timestamp LIMIT 1";
736 $res=wfQuery($sql, DB_READ, $fname);
737 if( ($old=wfFetchObject($res)) && !$wpConfirm ) {
738 $skin=$wgUser->getSkin();
739 $wgOut->addHTML("<B>".wfMsg("historywarning"));
740 $wgOut->addHTML( $skin->historyLink() ."</B><P>");
741 }
742
743 $sql="SELECT cur_text FROM cur WHERE cur_namespace=0 and cur_title='" . wfStrencode($this->mTitle->getPrefixedDBkey())."'";
744 $res=wfQuery($sql, DB_READ, $fname);
745 if( ($s=wfFetchObject($res))) {
746
747 # if this is a mini-text, we can paste part of it into the deletion reason
748
749 #if this is empty, an earlier revision may contain "useful" text
750 if($s->cur_text!="") {
751 $text=$s->cur_text;
752 } else {
753 if($old) {
754 $text=$old->old_text;
755 $blanked=1;
756 }
757
758 }
759
760 $length=strlen($text);
761
762 # this should not happen, since it is not possible to store an empty, new
763 # page. Let's insert a standard text in case it does, though
764 if($length==0 && !$wpReason) { $wpReason=wfmsg("exblank");}
765
766
767 if($length < 500 && !$wpReason) {
768
769 # comment field=255, let's grep the first 150 to have some user
770 # space left
771 $text=substr($text,0,150);
772 # let's strip out newlines and HTML tags
773 $text=preg_replace("/\"/","'",$text);
774 $text=preg_replace("/\</","&lt;",$text);
775 $text=preg_replace("/\>/","&gt;",$text);
776 $text=preg_replace("/[\n\r]/","",$text);
777 if(!$blanked) {
778 $wpReason=wfMsg("excontent"). " '".$text;
779 } else {
780 $wpReason=wfMsg("exbeforeblank") . " '".$text;
781 }
782 if($length>150) { $wpReason .= "..."; } # we've only pasted part of the text
783 $wpReason.="'";
784 }
785 }
786
787 return $this->confirmDelete();
788 }
789
790 function confirmDelete( $par = "" )
791 {
792 global $wgOut;
793
794 wfDebug( "Article::confirmDelete\n" );
795
796 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
797 $wgOut->setSubtitle( wfMsg( "deletesub", $sub ) );
798 $wgOut->setRobotpolicy( "noindex,nofollow" );
799 $wgOut->addWikiText( wfMsg( "confirmdeletetext" ) );
800
801 $t = $this->mTitle->getPrefixedURL();
802
803 $formaction = wfEscapeHTML( wfLocalUrl( $t, "action=delete" . $par ) );
804 $confirm = wfMsg( "confirm" );
805 $check = wfMsg( "confirmcheck" );
806 $delcom = wfMsg( "deletecomment" );
807
808 $wgOut->addHTML( "
809 <form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
810 <table border=0><tr><td align=right>
811 {$delcom}:</td><td align=left>
812 <input type=text size=60 name=\"wpReason\" value=\"{$wpReason}\">
813 </td></tr><tr><td>&nbsp;</td></tr>
814 <tr><td align=right>
815 <input type=checkbox name=\"wpConfirm\" value='1' id=\"wpConfirm\">
816 </td><td><label for=\"wpConfirm\">{$check}</label></td>
817 </tr><tr><td>&nbsp;</td><td>
818 <input type=submit name=\"wpConfirmB\" value=\"{$confirm}\">
819 </td></tr></table></form>\n" );
820
821 $wgOut->returnToMain( false );
822 }
823
824 function doDelete()
825 {
826 global $wgOut, $wgUser, $wgLang;
827 global $wpReason;
828 $fname = "Article::doDelete";
829 wfDebug( "$fname\n" );
830
831 $this->doDeleteArticle( $this->mTitle );
832 $deleted = $this->mTitle->getPrefixedText();
833
834 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
835 $wgOut->setRobotpolicy( "noindex,nofollow" );
836
837 $sk = $wgUser->getSkin();
838 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
839 Namespace::getWikipedia() ) .
840 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
841
842 $text = wfMsg( "deletedtext", $deleted, $loglink );
843
844 $wgOut->addHTML( "<p>" . $text );
845 $wgOut->returnToMain( false );
846 }
847
848 function doDeleteArticle( $title )
849 {
850 global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList;
851
852 $fname = "Article::doDeleteArticle";
853 wfDebug( "$fname\n" );
854
855 $ns = $title->getNamespace();
856 $t = wfStrencode( $title->getDBkey() );
857 $id = $title->getArticleID();
858
859 if ( "" == $t ) {
860 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
861 return;
862 }
863
864 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
865 array_push( $wgDeferredUpdateList, $u );
866
867 # Move article and history to the "archive" table
868 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
869 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
870 "ar_flags) SELECT cur_namespace,cur_title,cur_text,cur_comment," .
871 "cur_user,cur_user_text,cur_timestamp,cur_minor_edit,0 FROM cur " .
872 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
873 wfQuery( $sql, DB_WRITE, $fname );
874
875 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
876 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
877 "ar_flags) SELECT old_namespace,old_title,old_text,old_comment," .
878 "old_user,old_user_text,old_timestamp,old_minor_edit,old_flags " .
879 "FROM old WHERE old_namespace={$ns} AND old_title='{$t}'";
880 wfQuery( $sql, DB_WRITE, $fname );
881
882 # Now that it's safely backed up, delete it
883
884 $sql = "DELETE FROM cur WHERE cur_namespace={$ns} AND " .
885 "cur_title='{$t}'";
886 wfQuery( $sql, DB_WRITE, $fname );
887
888 $sql = "DELETE FROM old WHERE old_namespace={$ns} AND " .
889 "old_title='{$t}'";
890 wfQuery( $sql, DB_WRITE, $fname );
891
892 $sql = "DELETE FROM recentchanges WHERE rc_namespace={$ns} AND " .
893 "rc_title='{$t}'";
894 wfQuery( $sql, DB_WRITE, $fname );
895
896 # Finally, clean up the link tables
897
898 if ( 0 != $id ) {
899
900 $t = wfStrencode( $title->getPrefixedDBkey() );
901
902 if ( $wgEnablePersistentLC ) {
903 // Purge related entries in links cache on delete,
904 wfQuery("DELETE linkscc FROM linkscc,links ".
905 "WHERE lcc_title=links.l_from AND l_to={$id}", DB_WRITE);
906 wfQuery("DELETE FROM linkscc WHERE lcc_title='{$t}'", DB_WRITE);
907 }
908
909 $sql = "SELECT l_from FROM links WHERE l_to={$id}";
910 $res = wfQuery( $sql, DB_READ, $fname );
911
912 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
913 $now = wfTimestampNow();
914 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
915 $first = true;
916
917 while ( $s = wfFetchObject( $res ) ) {
918 $nt = Title::newFromDBkey( $s->l_from );
919 $lid = $nt->getArticleID();
920
921 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
922 $first = false;
923 $sql .= "({$lid},'{$t}')";
924 $sql2 .= "{$lid}";
925 }
926 $sql2 .= ")";
927 if ( ! $first ) {
928 wfQuery( $sql, DB_WRITE, $fname );
929 wfQuery( $sql2, DB_WRITE, $fname );
930 }
931 wfFreeResult( $res );
932
933 $sql = "DELETE FROM links WHERE l_to={$id}";
934 wfQuery( $sql, DB_WRITE, $fname );
935
936 $sql = "DELETE FROM links WHERE l_from='{$t}'";
937 wfQuery( $sql, DB_WRITE, $fname );
938
939 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
940 wfQuery( $sql, DB_WRITE, $fname );
941
942 $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
943 wfQuery( $sql, DB_WRITE, $fname );
944 }
945
946 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
947 $art = $title->getPrefixedText();
948 $wpReason = wfCleanQueryVar( $wpReason );
949 $log->addEntry( wfMsg( "deletedarticle", $art ), $wpReason );
950
951 # Clear the cached article id so the interface doesn't act like we exist
952 $this->mTitle->resetArticleID( 0 );
953 $this->mTitle->mArticleID = 0;
954 }
955
956 function rollback()
957 {
958 global $wgUser, $wgLang, $wgOut, $from;
959 $from = $_REQUEST["from"];
960
961 if ( ! $wgUser->isSysop() ) {
962 $wgOut->sysopRequired();
963 return;
964 }
965
966 # Replace all this user's current edits with the next one down
967 $tt = wfStrencode( $this->mTitle->getDBKey() );
968 $n = $this->mTitle->getNamespace();
969
970 # Get the last editor
971 $sql = "SELECT cur_id,cur_user,cur_user_text,cur_comment FROM cur WHERE cur_title='{$tt}' AND cur_namespace={$n}";
972 $res = wfQuery( $sql, DB_READ );
973 if( ($x = wfNumRows( $res )) != 1 ) {
974 # Something wrong
975 $wgOut->addHTML( wfMsg( "notanarticle" ) );
976 return;
977 }
978 $s = wfFetchObject( $res );
979 $ut = wfStrencode( $s->cur_user_text );
980 $uid = $s->cur_user;
981 $pid = $s->cur_id;
982
983 $from = str_replace( '_', ' ', wfCleanQueryVar( $from ) );
984 if( $from != $s->cur_user_text ) {
985 $wgOut->setPageTitle(wfmsg("rollbackfailed"));
986 $wgOut->addWikiText( wfMsg( "alreadyrolled",
987 htmlspecialchars( $this->mTitle->getPrefixedText()),
988 htmlspecialchars( $from ),
989 htmlspecialchars( $s->cur_user_text ) ) );
990 if($s->cur_comment != "") {
991 $wgOut->addHTML(
992 wfMsg("editcomment",
993 htmlspecialchars( $s->cur_comment ) ) );
994 }
995 return;
996 }
997
998 # Get the last edit not by this guy
999 $sql = "SELECT old_text,old_user,old_user_text
1000 FROM old USE INDEX (name_title_timestamp)
1001 WHERE old_namespace={$n} AND old_title='{$tt}'
1002 AND (old_user <> {$uid} OR old_user_text <> '{$ut}')
1003 ORDER BY inverse_timestamp LIMIT 1";
1004 $res = wfQuery( $sql, DB_READ );
1005 if( wfNumRows( $res ) != 1 ) {
1006 # Something wrong
1007 $wgOut->setPageTitle(wfMsg("rollbackfailed"));
1008 $wgOut->addHTML( wfMsg( "cantrollback" ) );
1009 return;
1010 }
1011 $s = wfFetchObject( $res );
1012
1013 # Save it!
1014 $newcomment = wfMsg( "revertpage", $s->old_user_text );
1015 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1016 $wgOut->setRobotpolicy( "noindex,nofollow" );
1017 $wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
1018 $this->updateArticle( $s->old_text, $newcomment, 1, $this->mTitle->userIsWatching() );
1019
1020 $wgOut->returnToMain( false );
1021 }
1022
1023
1024 # Do standard deferred updates after page view
1025
1026 /* private */ function viewUpdates()
1027 {
1028 global $wgDeferredUpdateList;
1029
1030 if ( 0 != $this->getID() ) {
1031 global $wgDisableCounters;
1032 if( !$wgDisableCounters ) {
1033 $u = new ViewCountUpdate( $this->getID() );
1034 array_push( $wgDeferredUpdateList, $u );
1035 $u = new SiteStatsUpdate( 1, 0, 0 );
1036 array_push( $wgDeferredUpdateList, $u );
1037 }
1038 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1039 $this->mTitle->getDBkey() );
1040 array_push( $wgDeferredUpdateList, $u );
1041 }
1042 }
1043
1044 # Do standard deferred updates after page edit.
1045 # Every 1000th edit, prune the recent changes table.
1046
1047 /* private */ function editUpdates( $text )
1048 {
1049 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1050
1051 wfSeedRandom();
1052 if ( 0 == mt_rand( 0, 999 ) ) {
1053 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1054 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1055 wfQuery( $sql, DB_WRITE );
1056 }
1057 $id = $this->getID();
1058 $title = $this->mTitle->getPrefixedDBkey();
1059 $adj = $this->mCountAdjustment;
1060
1061 if ( 0 != $id ) {
1062 $u = new LinksUpdate( $id, $title );
1063 array_push( $wgDeferredUpdateList, $u );
1064 $u = new SiteStatsUpdate( 0, 1, $adj );
1065 array_push( $wgDeferredUpdateList, $u );
1066 $u = new SearchUpdate( $id, $title, $text );
1067 array_push( $wgDeferredUpdateList, $u );
1068
1069 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(),
1070 $this->mTitle->getDBkey() );
1071 array_push( $wgDeferredUpdateList, $u );
1072
1073 if ( $this->getNamespace == NS_MEDIAWIKI ) {
1074 $messageCache = $wgMemc->get( "$wgDBname:messages" );
1075 if (!$messageCache) {
1076 $messageCache = wfLoadAllMessages();
1077 }
1078 $messageCache[$title] = $text;
1079 $wgMemc->set( "$wgDBname:messages" );
1080 }
1081 }
1082 }
1083
1084 /* private */ function setOldSubtitle()
1085 {
1086 global $wgLang, $wgOut;
1087
1088 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1089 $r = wfMsg( "revisionasof", $td );
1090 $wgOut->setSubtitle( "({$r})" );
1091 }
1092
1093 # This function is called right before saving the wikitext,
1094 # so we can do things like signatures and links-in-context.
1095
1096 function preSaveTransform( $text )
1097 {
1098 $s = "";
1099 while ( "" != $text ) {
1100 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
1101 $s .= $this->pstPass2( $p[0] );
1102
1103 if ( ( count( $p ) < 2 ) || ( "" == $p[1] ) ) { $text = ""; }
1104 else {
1105 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
1106 $s .= "<nowiki>{$q[0]}</nowiki>";
1107 $text = $q[1];
1108 }
1109 }
1110 return rtrim( $s );
1111 }
1112
1113 /* private */ function pstPass2( $text )
1114 {
1115 global $wgUser, $wgLang, $wgLocaltimezone;
1116
1117 # Signatures
1118 #
1119 $n = $wgUser->getName();
1120 $k = $wgUser->getOption( "nickname" );
1121 if ( "" == $k ) { $k = $n; }
1122 if(isset($wgLocaltimezone)) {
1123 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1124 }
1125 /* Note: this is an ugly timezone hack for the European wikis */
1126 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
1127 " (" . date( "T" ) . ")";
1128 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1129
1130 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1131 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1132 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1133 Namespace::getUser() ) . ":$n|$k]]", $text );
1134
1135 # Context links: [[|name]] and [[name (context)|]]
1136 #
1137 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1138 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1139 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
1140 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1141
1142 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1143 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1144 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
1145 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
1146 # [[ns:page (cont)|]]
1147 $context = "";
1148 $t = $this->mTitle->getText();
1149 if ( preg_match( $conpat, $t, $m ) ) {
1150 $context = $m[2];
1151 }
1152 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1153 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1154 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1155
1156 if ( "" == $context ) {
1157 $text = preg_replace( $p2, "[[\\1]]", $text );
1158 } else {
1159 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1160 }
1161
1162 # {{SUBST:xxx}} variables
1163 #
1164 $mw =& MagicWord::get( MAG_SUBST );
1165 $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
1166
1167 return $text;
1168 }
1169
1170 /* Caching functions */
1171
1172 function tryFileCache() {
1173 if($this->isFileCacheable()) {
1174 $touched = $this->mTouched;
1175 if( strpos( $this->mContent, "{{" ) !== false ) {
1176 # Expire pages with variable replacements in an hour
1177 $expire = wfUnix2Timestamp( time() - 3600 );
1178 $touched = max( $expire, $touched );
1179 }
1180 $cache = new CacheManager( $this->mTitle );
1181 if($cache->isFileCacheGood( $touched )) {
1182 global $wgOut;
1183 wfDebug( " tryFileCache() - about to load\n" );
1184 $cache->loadFromFileCache();
1185 $wgOut->reportTime(); # For profiling
1186 exit;
1187 } else {
1188 wfDebug( " tryFileCache() - starting buffer\n" );
1189 if($cache->useGzip() && wfClientAcceptsGzip()) {
1190 /* For some reason, adding this header line over in
1191 CacheManager::saveToFileCache() fails on my test
1192 setup at home, though it works on the live install.
1193 Make double-sure... --brion */
1194 header( "Content-Encoding: gzip" );
1195 }
1196 ob_start( array(&$cache, 'saveToFileCache' ) );
1197 }
1198 } else {
1199 wfDebug( " tryFileCache() - not cacheable\n" );
1200 }
1201 }
1202
1203 function isFileCacheable() {
1204 global $wgUser, $wgUseFileCache, $wgShowIPinHeader;
1205 global $action, $oldid, $diff, $redirect, $printable;
1206 return $wgUseFileCache
1207 and (!$wgShowIPinHeader)
1208 and ($this->getID() != 0)
1209 and ($wgUser->getId() == 0)
1210 and (!$wgUser->getNewtalk())
1211 and ($this->mTitle->getNamespace != Namespace::getSpecial())
1212 and ($action == "view")
1213 and (!isset($oldid))
1214 and (!isset($diff))
1215 and (!isset($redirect))
1216 and (!isset($printable))
1217 and (!$this->mRedirectedFrom);
1218 }
1219
1220 function checkTouched() {
1221 $id = $this->getID();
1222 $sql = "SELECT cur_touched,cur_is_redirect FROM cur WHERE cur_id=$id";
1223 $res = wfQuery( $sql, DB_READ, "Article::checkTouched" );
1224 if( $s = wfFetchObject( $res ) ) {
1225 $this->mTouched = $s->cur_touched;
1226 return !$s->cur_is_redirect;
1227 } else {
1228 return false;
1229 }
1230 }
1231 }
1232
1233 function wfReplaceSubstVar( $matches ) {
1234 return wfMsg( $matches[1] );
1235 }
1236
1237 ?>