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