Squid integration changes
[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, $text );
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() );
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 # Every 1000th edit, prune the recent changes table.
548 wfSeedRandom();
549 if ( 0 == mt_rand( 0, 999 ) ) {
550 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
551 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
552 wfQuery( $sql, DB_WRITE );
553 }
554
555 if( $wgMwRedir->matchStart( $text ) )
556 $r = "redirect=no";
557 else
558 $r = "";
559 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL(), $r ) );
560 }
561
562 # Add this page to my watchlist
563
564 function watch( $add = true )
565 {
566 global $wgUser, $wgOut, $wgLang;
567 global $wgDeferredUpdateList;
568
569 if ( 0 == $wgUser->getID() ) {
570 $wgOut->errorpage( "watchnologin", "watchnologintext" );
571 return;
572 }
573 if ( wfReadOnly() ) {
574 $wgOut->readOnlyPage();
575 return;
576 }
577 if( $add )
578 $wgUser->addWatch( $this->mTitle );
579 else
580 $wgUser->removeWatch( $this->mTitle );
581
582 $wgOut->setPagetitle( wfMsg( $add ? "addedwatch" : "removedwatch" ) );
583 $wgOut->setRobotpolicy( "noindex,follow" );
584
585 $sk = $wgUser->getSkin() ;
586 $link = $sk->makeKnownLink ( $this->mTitle->getPrefixedText() ) ;
587
588 if($add)
589 $text = wfMsg( "addedwatchtext", $link );
590 else
591 $text = wfMsg( "removedwatchtext", $link );
592 $wgOut->addHTML( $text );
593
594 $up = new UserUpdate();
595 array_push( $wgDeferredUpdateList, $up );
596
597 $wgOut->returnToMain( false );
598 }
599
600 function unwatch()
601 {
602 $this->watch( false );
603 }
604
605 function protect( $limit = "sysop" )
606 {
607 global $wgUser, $wgOut;
608
609 if ( ! $wgUser->isSysop() ) {
610 $wgOut->sysopRequired();
611 return;
612 }
613 if ( wfReadOnly() ) {
614 $wgOut->readOnlyPage();
615 return;
616 }
617 $id = $this->mTitle->getArticleID();
618 if ( 0 == $id ) {
619 $wgOut->fatalEror( wfMsg( "badarticleerror" ) );
620 return;
621 }
622 $sql = "UPDATE cur SET cur_touched='" . wfTimestampNow() . "'," .
623 "cur_restrictions='{$limit}' WHERE cur_id={$id}";
624 wfQuery( $sql, DB_WRITE, "Article::protect" );
625
626 $log = new LogPage( wfMsg( "protectlogpage" ), wfMsg( "protectlogtext" ) );
627 if ( $limit === "" ) {
628 $log->addEntry( wfMsg( "unprotectedarticle", $this->mTitle->getPrefixedText() ), "" );
629 } else {
630 $log->addEntry( wfMsg( "protectedarticle", $this->mTitle->getPrefixedText() ), "" );
631 }
632 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL() ) );
633 }
634
635 function unprotect()
636 {
637 return $this->protect( "" );
638 }
639
640 function delete()
641 {
642 global $wgUser, $wgOut, $wgMessageCache;
643 global $wpConfirm, $wpReason, $image, $oldimage;
644
645 # This code desperately needs to be totally rewritten
646
647 if ( ( ! $wgUser->isSysop() ) ) {
648 $wgOut->sysopRequired();
649 return;
650 }
651 if ( wfReadOnly() ) {
652 $wgOut->readOnlyPage();
653 return;
654 }
655
656 # Can't delete cached MediaWiki namespace (i.e. vital messages)
657 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && $wgMessageCache->isCacheable( $this->mTitle->getDBkey() ) ) {
658 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
659 return;
660 }
661
662 # Better double-check that it hasn't been deleted yet!
663 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
664 if ( ( "" == trim( $this->mTitle->getText() ) )
665 or ( $this->mTitle->getArticleId() == 0 ) ) {
666 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
667 return;
668 }
669
670 if ( $_POST["wpConfirm"] ) {
671 $this->doDelete();
672 return;
673 }
674
675 # determine whether this page has earlier revisions
676 # and insert a warning if it does
677 # we select the text because it might be useful below
678 $ns = $this->mTitle->getNamespace();
679 $title = $this->mTitle->getDBkey();
680 $etitle = wfStrencode( $title );
681 $sql = "SELECT old_text,old_flags FROM old WHERE old_namespace=$ns and old_title='$etitle' ORDER BY inverse_timestamp LIMIT 1";
682 $res = wfQuery( $sql, DB_READ, $fname );
683 if( ($old=wfFetchObject($res)) && !$wpConfirm ) {
684 $skin=$wgUser->getSkin();
685 $wgOut->addHTML("<B>".wfMsg("historywarning"));
686 $wgOut->addHTML( $skin->historyLink() ."</B><P>");
687 }
688
689 $sql="SELECT cur_text FROM cur WHERE cur_namespace=$ns and cur_title='$etitle'";
690 $res=wfQuery($sql, DB_READ, $fname);
691 if( ($s=wfFetchObject($res))) {
692
693 # if this is a mini-text, we can paste part of it into the deletion reason
694
695 #if this is empty, an earlier revision may contain "useful" text
696 if($s->cur_text!="") {
697 $text=$s->cur_text;
698 } else {
699 if($old) {
700 $text = Article::getRevisionText( $old );
701 $blanked=1;
702 }
703
704 }
705
706 $length=strlen($text);
707
708 # this should not happen, since it is not possible to store an empty, new
709 # page. Let's insert a standard text in case it does, though
710 if($length==0 && !$wpReason) { $wpReason=wfmsg("exblank");}
711
712
713 if($length < 500 && !$wpReason) {
714
715 # comment field=255, let's grep the first 150 to have some user
716 # space left
717 $text=substr($text,0,150);
718 # let's strip out newlines and HTML tags
719 $text=preg_replace("/\"/","'",$text);
720 $text=preg_replace("/\</","&lt;",$text);
721 $text=preg_replace("/\>/","&gt;",$text);
722 $text=preg_replace("/[\n\r]/","",$text);
723 if(!$blanked) {
724 $wpReason=wfMsg("excontent"). " '".$text;
725 } else {
726 $wpReason=wfMsg("exbeforeblank") . " '".$text;
727 }
728 if($length>150) { $wpReason .= "..."; } # we've only pasted part of the text
729 $wpReason.="'";
730 }
731 }
732
733 return $this->confirmDelete();
734 }
735
736 function confirmDelete( $par = "" )
737 {
738 global $wgOut;
739 global $wpReason;
740
741 wfDebug( "Article::confirmDelete\n" );
742
743 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
744 $wgOut->setSubtitle( wfMsg( "deletesub", $sub ) );
745 $wgOut->setRobotpolicy( "noindex,nofollow" );
746 $wgOut->addWikiText( wfMsg( "confirmdeletetext" ) );
747
748 $t = $this->mTitle->getPrefixedURL();
749
750 $formaction = wfEscapeHTML( wfLocalUrl( $t, "action=delete" . $par ) );
751 $confirm = wfMsg( "confirm" );
752 $check = wfMsg( "confirmcheck" );
753 $delcom = wfMsg( "deletecomment" );
754
755 $wgOut->addHTML( "
756 <form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
757 <table border=0><tr><td align=right>
758 {$delcom}:</td><td align=left>
759 <input type=text size=60 name=\"wpReason\" value=\"" . htmlspecialchars( $wpReason ) . "\">
760 </td></tr><tr><td>&nbsp;</td></tr>
761 <tr><td align=right>
762 <input type=checkbox name=\"wpConfirm\" value='1' id=\"wpConfirm\">
763 </td><td><label for=\"wpConfirm\">{$check}</label></td>
764 </tr><tr><td>&nbsp;</td><td>
765 <input type=submit name=\"wpConfirmB\" value=\"{$confirm}\">
766 </td></tr></table></form>\n" );
767
768 $wgOut->returnToMain( false );
769 }
770
771 function doDelete()
772 {
773 global $wgOut, $wgUser, $wgLang;
774 global $wpReason;
775 $fname = "Article::doDelete";
776 wfDebug( "$fname\n" );
777
778 $this->doDeleteArticle( $this->mTitle );
779 $deleted = $this->mTitle->getPrefixedText();
780
781 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
782 $wgOut->setRobotpolicy( "noindex,nofollow" );
783
784 $sk = $wgUser->getSkin();
785 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
786 Namespace::getWikipedia() ) .
787 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
788
789 $text = wfMsg( "deletedtext", $deleted, $loglink );
790
791 $wgOut->addHTML( "<p>" . $text );
792 $wgOut->returnToMain( false );
793 }
794
795 function doDeleteArticle( $title )
796 {
797 global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList;
798
799 $fname = "Article::doDeleteArticle";
800 wfDebug( "$fname\n" );
801
802 $ns = $title->getNamespace();
803 $t = wfStrencode( $title->getDBkey() );
804 $id = $title->getArticleID();
805
806 if ( "" == $t ) {
807 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
808 return;
809 }
810
811 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
812 array_push( $wgDeferredUpdateList, $u );
813
814 # Move article and history to the "archive" table
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 cur_namespace,cur_title,cur_text,cur_comment," .
818 "cur_user,cur_user_text,cur_timestamp,cur_minor_edit,0 FROM cur " .
819 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
820 wfQuery( $sql, DB_WRITE, $fname );
821
822 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
823 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
824 "ar_flags) SELECT old_namespace,old_title,old_text,old_comment," .
825 "old_user,old_user_text,old_timestamp,old_minor_edit,old_flags " .
826 "FROM old WHERE old_namespace={$ns} AND old_title='{$t}'";
827 wfQuery( $sql, DB_WRITE, $fname );
828
829 # Now that it's safely backed up, delete it
830
831 $sql = "DELETE FROM cur WHERE cur_namespace={$ns} AND " .
832 "cur_title='{$t}'";
833 wfQuery( $sql, DB_WRITE, $fname );
834
835 $sql = "DELETE FROM old WHERE old_namespace={$ns} AND " .
836 "old_title='{$t}'";
837 wfQuery( $sql, DB_WRITE, $fname );
838
839 $sql = "DELETE FROM recentchanges WHERE rc_namespace={$ns} AND " .
840 "rc_title='{$t}'";
841 wfQuery( $sql, DB_WRITE, $fname );
842
843 # Finally, clean up the link tables
844
845 if ( 0 != $id ) {
846
847 $t = wfStrencode( $title->getPrefixedDBkey() );
848
849 Article::onArticleDelete( $title );
850
851 $sql = "SELECT l_from FROM links WHERE l_to={$id}";
852 $res = wfQuery( $sql, DB_READ, $fname );
853
854 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
855 $now = wfTimestampNow();
856 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
857 $first = true;
858
859 while ( $s = wfFetchObject( $res ) ) {
860 $nt = Title::newFromDBkey( $s->l_from );
861 $lid = $nt->getArticleID();
862
863 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
864 $first = false;
865 $sql .= "({$lid},'{$t}')";
866 $sql2 .= "{$lid}";
867 }
868 $sql2 .= ")";
869 if ( ! $first ) {
870 wfQuery( $sql, DB_WRITE, $fname );
871 wfQuery( $sql2, DB_WRITE, $fname );
872 }
873 wfFreeResult( $res );
874
875 $sql = "DELETE FROM links WHERE l_to={$id}";
876 wfQuery( $sql, DB_WRITE, $fname );
877
878 $sql = "DELETE FROM links WHERE l_from='{$t}'";
879 wfQuery( $sql, DB_WRITE, $fname );
880
881 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
882 wfQuery( $sql, DB_WRITE, $fname );
883
884 $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
885 wfQuery( $sql, DB_WRITE, $fname );
886 }
887
888 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
889 $art = $title->getPrefixedText();
890 $wpReason = wfCleanQueryVar( $wpReason );
891 $log->addEntry( wfMsg( "deletedarticle", $art ), $wpReason );
892
893 # Clear the cached article id so the interface doesn't act like we exist
894 $this->mTitle->resetArticleID( 0 );
895 $this->mTitle->mArticleID = 0;
896 }
897
898 function rollback()
899 {
900 global $wgUser, $wgLang, $wgOut, $from;
901
902 if ( ! $wgUser->isSysop() ) {
903 $wgOut->sysopRequired();
904 return;
905 }
906 if ( wfReadOnly() ) {
907 $wgOut->readOnlyPage( $this->getContent() );
908 return;
909 }
910
911 # Enhanced rollback, marks edits rc_bot=1
912 $bot = !!$_REQUEST['bot'];
913
914 # Replace all this user's current edits with the next one down
915 $tt = wfStrencode( $this->mTitle->getDBKey() );
916 $n = $this->mTitle->getNamespace();
917
918 # Get the last editor
919 $sql = "SELECT cur_id,cur_user,cur_user_text,cur_comment FROM cur WHERE cur_title='{$tt}' AND cur_namespace={$n}";
920 $res = wfQuery( $sql, DB_READ );
921 if( ($x = wfNumRows( $res )) != 1 ) {
922 # Something wrong
923 $wgOut->addHTML( wfMsg( "notanarticle" ) );
924 return;
925 }
926 $s = wfFetchObject( $res );
927 $ut = wfStrencode( $s->cur_user_text );
928 $uid = $s->cur_user;
929 $pid = $s->cur_id;
930
931 $from = str_replace( '_', ' ', wfCleanQueryVar( $from ) );
932 if( $from != $s->cur_user_text ) {
933 $wgOut->setPageTitle(wfmsg("rollbackfailed"));
934 $wgOut->addWikiText( wfMsg( "alreadyrolled",
935 htmlspecialchars( $this->mTitle->getPrefixedText()),
936 htmlspecialchars( $from ),
937 htmlspecialchars( $s->cur_user_text ) ) );
938 if($s->cur_comment != "") {
939 $wgOut->addHTML(
940 wfMsg("editcomment",
941 htmlspecialchars( $s->cur_comment ) ) );
942 }
943 return;
944 }
945
946 # Get the last edit not by this guy
947 $sql = "SELECT old_text,old_user,old_user_text,old_timestamp,old_flags
948 FROM old USE INDEX (name_title_timestamp)
949 WHERE old_namespace={$n} AND old_title='{$tt}'
950 AND (old_user <> {$uid} OR old_user_text <> '{$ut}')
951 ORDER BY inverse_timestamp LIMIT 1";
952 $res = wfQuery( $sql, DB_READ );
953 if( wfNumRows( $res ) != 1 ) {
954 # Something wrong
955 $wgOut->setPageTitle(wfMsg("rollbackfailed"));
956 $wgOut->addHTML( wfMsg( "cantrollback" ) );
957 return;
958 }
959 $s = wfFetchObject( $res );
960
961 if ( $bot ) {
962 # Mark all reverted edits as bot
963 $sql = "UPDATE recentchanges SET rc_bot=1 WHERE
964 rc_cur_id=$pid AND rc_user=$uid AND rc_timestamp > '{$s->old_timestamp}'";
965 wfQuery( $sql, DB_WRITE, $fname );
966 }
967
968 # Save it!
969 $newcomment = wfMsg( "revertpage", $s->old_user_text, $from );
970 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
971 $wgOut->setRobotpolicy( "noindex,nofollow" );
972 $wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
973 $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), "", $bot );
974
975 Article::onArticleEdit( $this->mTitle );
976 $wgOut->returnToMain( false );
977 }
978
979
980 # Do standard deferred updates after page view
981
982 /* private */ function viewUpdates()
983 {
984 global $wgDeferredUpdateList;
985 if ( 0 != $this->getID() ) {
986 global $wgDisableCounters;
987 if( !$wgDisableCounters ) {
988 Article::incViewCount( $this->getID() );
989 $u = new SiteStatsUpdate( 1, 0, 0 );
990 array_push( $wgDeferredUpdateList, $u );
991 }
992 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
993 $this->mTitle->getDBkey() );
994 array_push( $wgDeferredUpdateList, $u );
995 }
996 }
997
998
999
1000 /* private */ function setOldSubtitle()
1001 {
1002 global $wgLang, $wgOut;
1003
1004 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1005 $r = wfMsg( "revisionasof", $td );
1006 $wgOut->setSubtitle( "({$r})" );
1007 }
1008
1009 # This function is called right before saving the wikitext,
1010 # so we can do things like signatures and links-in-context.
1011
1012 function preSaveTransform( $text )
1013 {
1014 $s = "";
1015 while ( "" != $text ) {
1016 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
1017 $s .= $this->pstPass2( $p[0] );
1018
1019 if ( ( count( $p ) < 2 ) || ( "" == $p[1] ) ) { $text = ""; }
1020 else {
1021 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
1022 $s .= "<nowiki>{$q[0]}</nowiki>";
1023 $text = $q[1];
1024 }
1025 }
1026 return rtrim( $s );
1027 }
1028
1029 /* private */ function pstPass2( $text )
1030 {
1031 global $wgUser, $wgLang, $wgLocaltimezone;
1032
1033 # Signatures
1034 #
1035 $n = $wgUser->getName();
1036 $k = $wgUser->getOption( "nickname" );
1037 if ( "" == $k ) { $k = $n; }
1038 if(isset($wgLocaltimezone)) {
1039 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1040 }
1041 /* Note: this is an ugly timezone hack for the European wikis */
1042 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
1043 " (" . date( "T" ) . ")";
1044 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1045
1046 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1047 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1048 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1049 Namespace::getUser() ) . ":$n|$k]]", $text );
1050
1051 # Context links: [[|name]] and [[name (context)|]]
1052 #
1053 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1054 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1055 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
1056 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1057
1058 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1059 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1060 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
1061 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
1062 # [[ns:page (cont)|]]
1063 $context = "";
1064 $t = $this->mTitle->getText();
1065 if ( preg_match( $conpat, $t, $m ) ) {
1066 $context = $m[2];
1067 }
1068 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1069 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1070 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1071
1072 if ( "" == $context ) {
1073 $text = preg_replace( $p2, "[[\\1]]", $text );
1074 } else {
1075 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1076 }
1077
1078 # {{SUBST:xxx}} variables
1079 #
1080 $mw =& MagicWord::get( MAG_SUBST );
1081 $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
1082
1083 /* Experimental:
1084 # Trim trailing whitespace
1085 # MAG_END (__END__) tag allows for trailing
1086 # whitespace to be deliberately included
1087 $text = rtrim( $text );
1088 $mw =& MagicWord::get( MAG_END );
1089 $mw->matchAndRemove( $text );
1090 */
1091 return $text;
1092 }
1093
1094 /* Caching functions */
1095
1096 # checkLastModified returns true iff it has taken care of all
1097 # output to the client that is necessary for this request.
1098 # (that is, it has sent a cached version of the page)
1099 function tryFileCache() {
1100 static $called = false;
1101 if( $called ) {
1102 wfDebug( " tryFileCache() -- called twice!?\n" );
1103 return;
1104 }
1105 $called = true;
1106 if($this->isFileCacheable()) {
1107 $touched = $this->mTouched;
1108 if( $this->mTitle->getPrefixedDBkey() == wfMsg( "mainpage" ) ) {
1109 # Expire the main page quicker
1110 $expire = wfUnix2Timestamp( time() - 3600 );
1111 $touched = max( $expire, $touched );
1112 }
1113 $cache = new CacheManager( $this->mTitle );
1114 if($cache->isFileCacheGood( $touched )) {
1115 global $wgOut;
1116 wfDebug( " tryFileCache() - about to load\n" );
1117 $cache->loadFromFileCache();
1118 return true;
1119 } else {
1120 wfDebug( " tryFileCache() - starting buffer\n" );
1121 ob_start( array(&$cache, 'saveToFileCache' ) );
1122 }
1123 } else {
1124 wfDebug( " tryFileCache() - not cacheable\n" );
1125 }
1126 }
1127
1128 function isFileCacheable() {
1129 global $wgUser, $wgUseFileCache, $wgShowIPinHeader;
1130 global $action, $oldid, $diff, $redirect, $printable;
1131 return $wgUseFileCache
1132 and (!$wgShowIPinHeader)
1133 and ($this->getID() != 0)
1134 and ($wgUser->getId() == 0)
1135 and (!$wgUser->getNewtalk())
1136 and ($this->mTitle->getNamespace() != Namespace::getSpecial())
1137 and ($action == "view")
1138 and (!isset($oldid))
1139 and (!isset($diff))
1140 and (!isset($redirect))
1141 and (!isset($printable))
1142 and (!$this->mRedirectedFrom);
1143 }
1144
1145 function checkTouched() {
1146 $id = $this->getID();
1147 $sql = "SELECT cur_touched,cur_is_redirect FROM cur WHERE cur_id=$id";
1148 $res = wfQuery( $sql, DB_READ, "Article::checkTouched" );
1149 if( $s = wfFetchObject( $res ) ) {
1150 $this->mTouched = $s->cur_touched;
1151 return !$s->cur_is_redirect;
1152 } else {
1153 return false;
1154 }
1155 }
1156
1157 /* static */ function incViewCount( $id )
1158 {
1159 $id = intval( $id );
1160 global $wgHitcounterUpdateFreq;
1161
1162 if( $wgHitcounterUpdateFreq <= 1 ){ //
1163 wfQuery("UPDATE cur SET cur_counter = cur_counter + 1 " .
1164 "WHERE cur_id = $id", DB_WRITE);
1165 return;
1166 }
1167
1168 # Not important enough to warrant an error page in case of failure
1169 $oldignore = wfIgnoreSQLErrors( true );
1170
1171 wfQuery("INSERT INTO hitcounter (hc_id) VALUES ({$id})", DB_WRITE);
1172
1173 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
1174 if( (rand() % $checkfreq != 0) or (wfLastErrno() != 0) ){
1175 # Most of the time (or on SQL errors), skip row count check
1176 wfIgnoreSQLErrors( $oldignore );
1177 return;
1178 }
1179
1180 $res = wfQuery("SELECT COUNT(*) as n FROM hitcounter", DB_WRITE);
1181 $row = wfFetchObject( $res );
1182 $rown = intval( $row->n );
1183 if( $rown >= $wgHitcounterUpdateFreq ){
1184 wfProfileIn( "Article::incViewCount-collect" );
1185 $old_user_abort = ignore_user_abort( true );
1186
1187 wfQuery("LOCK TABLES hitcounter WRITE", DB_WRITE);
1188 wfQuery("CREATE TEMPORARY TABLE acchits TYPE=HEAP ".
1189 "SELECT hc_id,COUNT(*) AS hc_n FROM hitcounter ".
1190 "GROUP BY hc_id", DB_WRITE);
1191 wfQuery("DELETE FROM hitcounter", DB_WRITE);
1192 wfQuery("UNLOCK TABLES", DB_WRITE);
1193 wfQuery("UPDATE cur,acchits SET cur_counter=cur_counter + hc_n ".
1194 "WHERE cur_id = hc_id", DB_WRITE);
1195 wfQuery("DROP TABLE acchits", DB_WRITE);
1196
1197 ignore_user_abort( $old_user_abort );
1198 wfProfileOut( "Article::incViewCount-collect" );
1199 }
1200 wfIgnoreSQLErrors( $oldignore );
1201 }
1202
1203 # The onArticle*() functions are supposed to be a kind of hooks
1204 # which should be called whenever any of the specified actions
1205 # are done.
1206 #
1207 # This is a good place to put code to clear caches, for instance.
1208
1209 /* static */ function onArticleCreate($title_obj,$text=''){
1210 global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid;
1211 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1212 global $wgMessageCache, $wgInternalServer;
1213 # Do standard deferred updates after page edit.
1214 $id = $title_obj->getArticleID();
1215 $title = $title_obj->getPrefixedDBkey();
1216 $shortTitle = $title_obj->getDBkey();
1217
1218 $adj = $this->mCountAdjustment;
1219
1220 if ( 0 != $id ) {
1221 $u = new LinksUpdate( $id, $title );
1222 array_push( $wgDeferredUpdateList, $u );
1223 $u = new SiteStatsUpdate( 0, 1, $adj );
1224 array_push( $wgDeferredUpdateList, $u );
1225 $u = new SearchUpdate( $id, $title, $text );
1226 array_push( $wgDeferredUpdateList, $u );
1227
1228 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
1229 array_push( $wgDeferredUpdateList, $u );
1230
1231 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1232 $wgMessageCache->replace( $shortTitle, $text );
1233 }
1234 }
1235 if ( $wgEnablePersistentLC ) {
1236 LinkCache::linksccClearBrokenLinksTo( $title );
1237 }
1238 if ( $wgEnableParserCache ) {
1239 OutputPage::parsercacheClearBrokenLinksTo( $title );
1240 }
1241 if ( $wgUseSquid ) {
1242 $urlArr = Array(
1243 $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL())
1244 );
1245 wfPurgeSquidServers($urlArr);
1246 /* this needs to be done after LinksUpdate */
1247 $u = new SquidUpdate($title_obj);
1248 array_push( $wgDeferredUpdateList, $u );
1249 }
1250 }
1251
1252 /* static */ function onArticleDelete($title_obj,$text=''){
1253 global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid, $wgDeferredUpdateList;
1254 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1255 global $wgMessageCache, $wgInternalServer;
1256
1257 $id = $title_obj->getArticleID();
1258 $title = $title_obj->getPrefixedDBkey();
1259 $shortTitle = $title_obj->getDBkey();
1260
1261 if ( $wgEnablePersistentLC ) {
1262 LinkCache::linksccClearLinksTo( $id );
1263 }
1264 if ( $wgEnableParserCache ) {
1265 OutputPage::parsercacheClearLinksTo( $id );
1266 }
1267 if ( $wgUseSquid ) {
1268 $urlArr = Array(
1269 $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL())
1270 );
1271 wfPurgeSquidServers($urlArr);
1272
1273 /* prepare the list of urls to purge */
1274 $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
1275 $res = wfQuery ( $sql, DB_READ ) ;
1276 while ( $BL = wfFetchObject ( $res ) )
1277 {
1278 $t = Title::newFromDBkey( $BL->l_from) ;
1279 $blurlArr[] = $wgInternalServer.wfLocalUrl( $t->getPrefixedURL() );
1280 }
1281 wfFreeResult ( $res ) ;
1282 $u = new SquidUpdate( $title_obj, $blurlArr );
1283 array_push( $wgDeferredUpdateList, $u );
1284
1285 }
1286 }
1287
1288 /* static */ function onArticleEdit($title_obj,$text=''){
1289 global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid;
1290 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1291 global $wgMessageCache, $wgInternalServer;
1292
1293 $id = $title_obj->getArticleID();
1294 $title = $title_obj->getPrefixedDBkey();
1295 $shortTitle = $title_obj->getDBkey();
1296
1297 $adj = $this->mCountAdjustment;
1298
1299 if ( 0 != $id ) {
1300 $u = new LinksUpdate( $id, $title );
1301 array_push( $wgDeferredUpdateList, $u );
1302 $u = new SiteStatsUpdate( 0, 1, $adj );
1303 array_push( $wgDeferredUpdateList, $u );
1304 $u = new SearchUpdate( $id, $title, $text );
1305 array_push( $wgDeferredUpdateList, $u );
1306
1307 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
1308 array_push( $wgDeferredUpdateList, $u );
1309
1310 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1311 $wgMessageCache->replace( $shortTitle, $text );
1312 }
1313 }
1314 if ( $wgEnablePersistentLC ) {
1315 LinkCache::linksccClearPage( $id );
1316 }
1317 if ( $wgEnableParserCache ) {
1318 OutputPage::parsercacheClearPage( $id );
1319 }
1320 if ( $wgUseSquid ) {
1321 $urlArr = Array(
1322 $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL()),
1323 );
1324 wfPurgeSquidServers($urlArr);
1325 }
1326 }
1327 }
1328
1329 function wfReplaceSubstVar( $matches ) {
1330 return wfMsg( $matches[1] );
1331 }
1332
1333 ?>