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