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