091083e17ffdbd0a8e52ff51666be87555fe0139
[lhc/web/wiklou.git] / includes / Article.php
1 <?php
2 # $Id$
3 #
4 # Class representing a Wikipedia article and history.
5 # See design.doc for an overview.
6
7 # Note: edit user interface and cache support functions have been
8 # moved to separate EditPage and CacheManager classes.
9
10 require_once ( 'CacheManager.php' );
11 include_once ( 'SpecialValidate.php' ) ;
12
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
15
16 class Article {
17 /* private */ var $mContent, $mContentLoaded;
18 /* private */ var $mUser, $mTimestamp, $mUserText;
19 /* private */ var $mCounter, $mComment, $mCountAdjustment;
20 /* private */ var $mMinorEdit, $mRedirectedFrom;
21 /* private */ var $mTouched, $mFileCache, $mTitle;
22 /* private */ var $mId, $mTable;
23
24 function Article( &$title ) {
25 $this->mTitle =& $title;
26 $this->clear();
27 }
28
29 /* private */ function clear() {
30 $this->mContentLoaded = false;
31 $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
32 $this->mRedirectedFrom = $this->mUserText =
33 $this->mTimestamp = $this->mComment = $this->mFileCache = '';
34 $this->mCountAdjustment = 0;
35 $this->mTouched = '19700101000000';
36 }
37
38 # Get revision text associated with an old or archive row
39 # $row is usually an object from wfFetchRow(), both the flags and the text field must be included
40 /* static */ function getRevisionText( $row, $prefix = 'old_' ) {
41 # Get data
42 $textField = $prefix . 'text';
43 $flagsField = $prefix . 'flags';
44
45 if ( isset( $row->$flagsField ) ) {
46 $flags = explode( ",", $row->$flagsField );
47 } else {
48 $flags = array();
49 }
50
51 if ( isset( $row->$textField ) ) {
52 $text = $row->$textField;
53 } else {
54 return false;
55 }
56
57 if ( in_array( 'link', $flags ) ) {
58 # Handle link type
59 $text = Article::followLink( $text );
60 } elseif ( in_array( 'gzip', $flags ) ) {
61 # Deal with optional compression of archived pages.
62 # This can be done periodically via maintenance/compressOld.php, and
63 # as pages are saved if $wgCompressRevisions is set.
64 return gzinflate( $text );
65 }
66 return $text;
67 }
68
69 /* static */ function compressRevisionText( &$text ) {
70 global $wgCompressRevisions;
71 if( !$wgCompressRevisions ) {
72 return '';
73 }
74 if( !function_exists( 'gzdeflate' ) ) {
75 wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" );
76 return '';
77 }
78 $text = gzdeflate( $text );
79 return 'gzip';
80 }
81
82 # Returns the text associated with a "link" type old table row
83 /* static */ function followLink( $link ) {
84 # Split the link into fields and values
85 $lines = explode( '\n', $link );
86 $hash = '';
87 $locations = array();
88 foreach ( $lines as $line ) {
89 # Comments
90 if ( $line{0} == '#' ) {
91 continue;
92 }
93 # Field/value pairs
94 if ( preg_match( '/^(.*?)\s*:\s*(.*)$/', $line, $matches ) ) {
95 $field = strtolower($matches[1]);
96 $value = $matches[2];
97 if ( $field == 'hash' ) {
98 $hash = $value;
99 } elseif ( $field == 'location' ) {
100 $locations[] = $value;
101 }
102 }
103 }
104
105 if ( $hash === '' ) {
106 return false;
107 }
108
109 # Look in each specified location for the text
110 $text = false;
111 foreach ( $locations as $location ) {
112 $text = Article::fetchFromLocation( $location, $hash );
113 if ( $text !== false ) {
114 break;
115 }
116 }
117
118 return $text;
119 }
120
121 /* static */ function fetchFromLocation( $location, $hash ) {
122 global $wgLoadBalancer;
123 $fname = 'fetchFromLocation';
124 wfProfileIn( $fname );
125
126 $p = strpos( $location, ':' );
127 if ( $p === false ) {
128 wfProfileOut( $fname );
129 return false;
130 }
131
132 $type = substr( $location, 0, $p );
133 $text = false;
134 switch ( $type ) {
135 case 'mysql':
136 # MySQL locations are specified by mysql://<machineID>/<dbname>/<tblname>/<index>
137 # Machine ID 0 is the current connection
138 if ( preg_match( '/^mysql:\/\/(\d+)\/([A-Za-z_]+)\/([A-Za-z_]+)\/([A-Za-z_]+)$/',
139 $location, $matches ) ) {
140 $machineID = $matches[1];
141 $dbName = $matches[2];
142 $tblName = $matches[3];
143 $index = $matches[4];
144 if ( $machineID == 0 ) {
145 # Current connection
146 $db =& wfGetDB( DB_SLAVE );
147 } else {
148 # Alternate connection
149 $db =& $wgLoadBalancer->getConnection( $machineID );
150
151 if ( array_key_exists( $machineId, $wgKnownMysqlServers ) ) {
152 # Try to open, return false on failure
153 $params = $wgKnownDBServers[$machineId];
154 $db = Database::newFromParams( $params['server'], $params['user'], $params['password'],
155 $dbName, 1, DBO_IGNORE );
156 }
157 }
158 if ( $db->isOpen() ) {
159 $index = $db->strencode( $index );
160 $res = $db->query( "SELECT blob_data FROM $dbName.$tblName WHERE blob_index='$index'", $fname );
161 $row = $db->fetchObject( $res );
162 $text = $row->text_data;
163 }
164 }
165 break;
166 case 'file':
167 # File locations are of the form file://<filename>, relative to the current directory
168 if ( preg_match( '/^file:\/\/(.*)$', $location, $matches ) )
169 $filename = strstr( $location, 'file://' );
170 $text = @file_get_contents( $matches[1] );
171 }
172 if ( $text !== false ) {
173 # Got text, now we need to interpret it
174 # The first line contains information about how to do this
175 $p = strpos( $text, '\n' );
176 $type = substr( $text, 0, $p );
177 $text = substr( $text, $p + 1 );
178 switch ( $type ) {
179 case 'plain':
180 break;
181 case 'gzip':
182 $text = gzinflate( $text );
183 break;
184 case 'object':
185 $object = unserialize( $text );
186 $text = $object->getItem( $hash );
187 break;
188 default:
189 $text = false;
190 }
191 }
192 wfProfileOut( $fname );
193 return $text;
194 }
195
196 # Note that getContent/loadContent may follow redirects if
197 # not told otherwise, and so may cause a change to mTitle.
198
199 # Return the text of this revision
200 function getContent( $noredir ) {
201 global $wgRequest;
202
203 # Get variables from query string :P
204 $action = $wgRequest->getText( 'action', 'view' );
205 $section = $wgRequest->getText( 'section' );
206
207 $fname = 'Article::getContent';
208 wfProfileIn( $fname );
209
210 if ( 0 == $this->getID() ) {
211 if ( 'edit' == $action ) {
212 wfProfileOut( $fname );
213 return ''; # was "newarticletext", now moved above the box)
214 }
215 wfProfileOut( $fname );
216 return wfMsg( 'noarticletext' );
217 } else {
218 $this->loadContent( $noredir );
219 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
220 if ( $this->mTitle->getNamespace() == NS_USER_TALK &&
221 preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
222 $action=='view'
223 ) {
224 wfProfileOut( $fname );
225 return $this->mContent . "\n" .wfMsg('anontalkpagetext');
226 } else {
227 if($action=='edit') {
228 if($section!='') {
229 if($section=='new') {
230 wfProfileOut( $fname );
231 return '';
232 }
233
234 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
235 # comments to be stripped as well)
236 $rv=$this->getSection($this->mContent,$section);
237 wfProfileOut( $fname );
238 return $rv;
239 }
240 }
241 wfProfileOut( $fname );
242 return $this->mContent;
243 }
244 }
245 }
246
247 # This function returns the text of a section, specified by a number ($section).
248 # A section is text under a heading like == Heading == or <h1>Heading</h1>, or
249 # the first section before any such heading (section 0).
250 #
251 # If a section contains subsections, these are also returned.
252 #
253 function getSection($text,$section) {
254
255 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
256 # comments to be stripped as well)
257 $striparray=array();
258 $parser=new Parser();
259 $parser->mOutputType=OT_WIKI;
260 $striptext=$parser->strip($text, $striparray, true);
261
262 # now that we can be sure that no pseudo-sections are in the source,
263 # split it up by section
264 $secs =
265 preg_split(
266 '/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
267 $striptext, -1,
268 PREG_SPLIT_DELIM_CAPTURE);
269 if($section==0) {
270 $rv=$secs[0];
271 } else {
272 $headline=$secs[$section*2-1];
273 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
274 $hlevel=$matches[1];
275
276 # translate wiki heading into level
277 if(strpos($hlevel,'=')!==false) {
278 $hlevel=strlen($hlevel);
279 }
280
281 $rv=$headline. $secs[$section*2];
282 $count=$section+1;
283
284 $break=false;
285 while(!empty($secs[$count*2-1]) && !$break) {
286
287 $subheadline=$secs[$count*2-1];
288 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
289 $subhlevel=$matches[1];
290 if(strpos($subhlevel,'=')!==false) {
291 $subhlevel=strlen($subhlevel);
292 }
293 if($subhlevel > $hlevel) {
294 $rv.=$subheadline.$secs[$count*2];
295 }
296 if($subhlevel <= $hlevel) {
297 $break=true;
298 }
299 $count++;
300
301 }
302 }
303 # reinsert stripped tags
304 $rv=$parser->unstrip($rv,$striparray);
305 $rv=$parser->unstripNoWiki($rv,$striparray);
306 $rv=trim($rv);
307 return $rv;
308
309 }
310
311 # Return an array of the columns of the "cur"-table
312 function &getCurContentFields() {
313 global $wgArticleCurContentFields;
314 if ( !$wgArticleCurContentFields ) {
315 $wgArticleCurContentFields = array( 'cur_text','cur_timestamp','cur_user', 'cur_user_text',
316 'cur_comment','cur_counter','cur_restrictions','cur_touched' );
317 }
318 return $wgArticleCurContentFields;
319 }
320
321 # Return an array of the columns of the "old"-table
322 function &getOldContentFields() {
323 global $wgArticleOldContentFields;
324 if ( !$wgArticleOldContentFields ) {
325 $wgArticleOldContentFields = array( 'old_namespace','old_title','old_text','old_timestamp',
326 'old_user','old_user_text','old_comment','old_flags' );
327 }
328 return $wgArticleOldContentFields;
329 }
330
331 # Load the revision (including cur_text) into this object
332 function loadContent( $noredir = false ) {
333 global $wgOut, $wgMwRedir, $wgRequest;
334
335 $dbr =& wfGetDB( DB_SLAVE );
336 # Query variables :P
337 $oldid = $wgRequest->getVal( 'oldid' );
338 $redirect = $wgRequest->getVal( 'redirect' );
339
340 if ( $this->mContentLoaded ) return;
341 $fname = 'Article::loadContent';
342
343 # Pre-fill content with error message so that if something
344 # fails we'll have something telling us what we intended.
345
346 $t = $this->mTitle->getPrefixedText();
347 if ( isset( $oldid ) ) {
348 $oldid = IntVal( $oldid );
349 $t .= ",oldid={$oldid}";
350 }
351 if ( isset( $redirect ) ) {
352 $redirect = ($redirect == 'no') ? 'no' : 'yes';
353 $t .= ",redirect={$redirect}";
354 }
355 $this->mContent = wfMsg( 'missingarticle', $t );
356
357 if ( ! $oldid ) { # Retrieve current version
358 $id = $this->getID();
359 if ( 0 == $id ) return;
360
361 $s = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname );
362 if ( $s === false ) {
363 return;
364 }
365
366 # If we got a redirect, follow it (unless we've been told
367 # not to by either the function parameter or the query
368 if ( ( 'no' != $redirect ) && ( false == $noredir ) ) {
369 $rt = Title::newFromRedirect( $s->cur_text );
370 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) ) {
371 # Gotta hand redirects to special pages differently:
372 # Fill the HTTP response "Location" header and ignore
373 # the rest of the page we're on.
374
375 if ( $rt->getInterwiki() != '' ) {
376 $wgOut->redirect( $rt->getFullURL() ) ;
377 return;
378 }
379 if ( $rt->getNamespace() == NS_SPECIAL ) {
380 $wgOut->redirect( $rt->getFullURL() );
381 return;
382 }
383 $rid = $rt->getArticleID();
384 if ( 0 != $rid ) {
385 $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
386
387 if ( $redirRow !== false ) {
388 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
389 $this->mTitle = $rt;
390 $s = $redirRow;
391 }
392 }
393 }
394 }
395
396 $this->mContent = $s->cur_text;
397 $this->mUser = $s->cur_user;
398 $this->mUserText = $s->cur_user_text;
399 $this->mComment = $s->cur_comment;
400 $this->mCounter = $s->cur_counter;
401 $this->mTimestamp = $s->cur_timestamp;
402 $this->mTouched = $s->cur_touched;
403 $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
404 $this->mTitle->mRestrictionsLoaded = true;
405 } else { # oldid set, retrieve historical version
406 $s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ), $fname );
407 if ( $s === false ) {
408 return;
409 }
410
411 if( $this->mTitle->getNamespace() != $s->old_namespace ||
412 $this->mTitle->getDBkey() != $s->old_title ) {
413 $oldTitle = Title::makeTitle( $s->old_namesapce, $s->old_title );
414 $this->mTitle = $oldTitle;
415 $wgTitle = $oldTitle;
416 }
417 $this->mContent = Article::getRevisionText( $s );
418 $this->mUser = $s->old_user;
419 $this->mUserText = $s->old_user_text;
420 $this->mComment = $s->old_comment;
421 $this->mCounter = 0;
422 $this->mTimestamp = $s->old_timestamp;
423 }
424 $this->mContentLoaded = true;
425 return $this->mContent;
426 }
427
428 # Gets the article text without using so many damn globals
429 # Returns false on error
430 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
431 global $wgMwRedir;
432
433 if ( $this->mContentLoaded ) {
434 return $this->mContent;
435 }
436 $this->mContent = false;
437
438 $fname = 'Article::getContentWithout';
439 $dbr =& wfGetDB( DB_SLAVE );
440
441 if ( ! $oldid ) { # Retrieve current version
442 $id = $this->getID();
443 if ( 0 == $id ) {
444 return false;
445 }
446
447 $s = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname );
448 if ( $s === false ) {
449 return false;
450 }
451
452 # If we got a redirect, follow it (unless we've been told
453 # not to by either the function parameter or the query
454 if ( !$noredir ) {
455 $rt = Title::newFromRedirect( $s->cur_text );
456 if( $rt && $rt->getInterwiki() == '' && $rt->getNamespace() != NS_SPECIAL ) {
457 $rid = $rt->getArticleID();
458 if ( 0 != $rid ) {
459 $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
460
461 if ( $redirRow !== false ) {
462 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
463 $this->mTitle = $rt;
464 $s = $redirRow;
465 }
466 }
467 }
468 }
469
470 $this->mContent = $s->cur_text;
471 $this->mUser = $s->cur_user;
472 $this->mUserText = $s->cur_user_text;
473 $this->mComment = $s->cur_comment;
474 $this->mCounter = $s->cur_counter;
475 $this->mTimestamp = $s->cur_timestamp;
476 $this->mTouched = $s->cur_touched;
477 $this->mTitle->mRestrictions = explode( ",", trim( $s->cur_restrictions ) );
478 $this->mTitle->mRestrictionsLoaded = true;
479 } else { # oldid set, retrieve historical version
480 $s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ) );
481 if ( $s === false ) {
482 return false;
483 }
484 $this->mContent = Article::getRevisionText( $s );
485 $this->mUser = $s->old_user;
486 $this->mUserText = $s->old_user_text;
487 $this->mComment = $s->old_comment;
488 $this->mCounter = 0;
489 $this->mTimestamp = $s->old_timestamp;
490 }
491 $this->mContentLoaded = true;
492 return $this->mContent;
493 }
494
495 function getID() {
496 if( $this->mTitle ) {
497 return $this->mTitle->getArticleID();
498 } else {
499 return 0;
500 }
501 }
502
503 function getCount() {
504 if ( -1 == $this->mCounter ) {
505 $id = $this->getID();
506 $dbr =& wfGetDB( DB_SLAVE );
507 $this->mCounter = $dbr->getField( 'cur', 'cur_counter', "cur_id={$id}" );
508 }
509 return $this->mCounter;
510 }
511
512 # Would the given text make this article a "good" article (i.e.,
513 # suitable for including in the article count)?
514 function isCountable( $text ) {
515 global $wgUseCommaCount, $wgMwRedir;
516
517 if ( 0 != $this->mTitle->getNamespace() ) { return 0; }
518 if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
519 $token = ($wgUseCommaCount ? ',' : '[[' );
520 if ( false === strstr( $text, $token ) ) { return 0; }
521 return 1;
522 }
523
524 # Loads everything from cur except cur_text
525 # This isn't necessary for all uses, so it's only done if needed.
526 /* private */ function loadLastEdit() {
527 global $wgOut;
528 if ( -1 != $this->mUser ) return;
529
530 $fname = 'Article::loadLastEdit';
531
532 $dbr =& wfGetDB( DB_SLAVE );
533 $s = $dbr->getArray( 'cur',
534 array( 'cur_user','cur_user_text','cur_timestamp', 'cur_comment','cur_minor_edit' ),
535 array( 'cur_id' => $this->getID() ), $fname );
536
537 if ( $s !== false ) {
538 $this->mUser = $s->cur_user;
539 $this->mUserText = $s->cur_user_text;
540 $this->mTimestamp = $s->cur_timestamp;
541 $this->mComment = $s->cur_comment;
542 $this->mMinorEdit = $s->cur_minor_edit;
543 }
544 }
545
546 function getTimestamp() {
547 $this->loadLastEdit();
548 return $this->mTimestamp;
549 }
550
551 function getUser() {
552 $this->loadLastEdit();
553 return $this->mUser;
554 }
555
556 function getUserText() {
557 $this->loadLastEdit();
558 return $this->mUserText;
559 }
560
561 function getComment() {
562 $this->loadLastEdit();
563 return $this->mComment;
564 }
565
566 function getMinorEdit() {
567 $this->loadLastEdit();
568 return $this->mMinorEdit;
569 }
570
571 function getContributors($limit = 0, $offset = 0) {
572 $fname = 'Article::getContributors';
573
574 # XXX: this is expensive; cache this info somewhere.
575
576 $title = $this->mTitle;
577 $contribs = array();
578 $dbr =& wfGetDB( DB_SLAVE );
579 $oldTable = $dbr->tableName( 'old' );
580 $userTable = $dbr->tableName( 'user' );
581 $encDBkey = $dbr->strencode( $title->getDBkey() );
582 $ns = $title->getNamespace();
583 $user = $this->getUser();
584
585 $sql = "SELECT old_user, old_user_text, user_real_name, MAX(old_timestamp) as timestamp
586 FROM $oldTable LEFT JOIN $userTable ON old_user = user_id
587 WHERE old_namespace = $user
588 AND old_title = $encDBkey
589 AND old_user != $user
590 GROUP BY old_user
591 ORDER BY timestamp DESC";
592
593 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
594
595 $res = $dbr->query($sql, $fname);
596
597 while ( $line = $dbr->fetchObject( $res ) ) {
598 $contribs[] = array($line->old_user, $line->old_user_text, $line->user_real_name);
599 }
600
601 $dbr->freeResult($res);
602 return $contribs;
603 }
604
605 # This is the default action of the script: just view the page of
606 # the given title.
607
608 function view() {
609 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMwRedir, $wgOnlySysopsCanPatrol;
610 global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
611 $sk = $wgUser->getSkin();
612
613 $fname = 'Article::view';
614 wfProfileIn( $fname );
615
616 # Get variables from query string
617 $oldid = $wgRequest->getVal( 'oldid' );
618 $diff = $wgRequest->getVal( 'diff' );
619 $rcid = $wgRequest->getVal( 'rcid' );
620
621 $wgOut->setArticleFlag( true );
622 $wgOut->setRobotpolicy( 'index,follow' );
623
624 # If we got diff and oldid in the query, we want to see a
625 # diff page instead of the article.
626
627 if ( !is_null( $diff ) ) {
628 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
629 $de = new DifferenceEngine( intval($oldid), intval($diff), intval($rcid) );
630 $de->showDiffPage();
631 wfProfileOut( $fname );
632 if( $diff == 0 ) {
633 # Run view updates for current revision only
634 $this->viewUpdates();
635 }
636 return;
637 }
638
639 if ( empty( $oldid ) && $this->checkTouched() ) {
640 if( $wgOut->checkLastModified( $this->mTouched ) ){
641 return;
642 } else if ( $this->tryFileCache() ) {
643 # tell wgOut that output is taken care of
644 $wgOut->disable();
645 $this->viewUpdates();
646 return;
647 }
648 }
649
650 # Should the parser cache be used?
651 if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) ) {
652 $pcache = true;
653 } else {
654 $pcache = false;
655 }
656
657 $outputDone = false;
658 if ( $pcache ) {
659 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
660 $outputDone = true;
661 }
662 }
663
664 if ( !$outputDone ) {
665 $text = $this->getContent( false ); # May change mTitle by following a redirect
666
667 # Another whitelist check in case oldid or redirects are altering the title
668 if ( !$this->mTitle->userCanRead() ) {
669 $wgOut->loginToUse();
670 $wgOut->output();
671 exit;
672 }
673
674
675 # We're looking at an old revision
676
677 if ( !empty( $oldid ) ) {
678 $this->setOldSubtitle();
679 $wgOut->setRobotpolicy( 'noindex,follow' );
680 }
681 if ( '' != $this->mRedirectedFrom ) {
682 $sk = $wgUser->getSkin();
683 $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '',
684 'redirect=no' );
685 $s = wfMsg( 'redirectedfrom', $redir );
686 $wgOut->setSubtitle( $s );
687
688 # Can't cache redirects
689 $pcache = false;
690 }
691
692 # wrap user css and user js in pre and don't parse
693 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
694 if (
695 $this->mTitle->getNamespace() == NS_USER &&
696 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
697 ) {
698 $wgOut->addWikiText( wfMsg('clearyourcache'));
699 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
700 } else if ( $rt = Title::newFromRedirect( $text ) ) {
701 # Display redirect
702 $imageUrl = "$wgStylePath/images/redirect.png";
703 $targetUrl = $rt->escapeLocalURL();
704 $titleText = htmlspecialchars( $rt->getPrefixedText() );
705 $link = $sk->makeLinkObj( $rt );
706 $wgOut->addHTML( "<img valign=\"center\" src=\"$imageUrl\">" .
707 "<span class=\"redirectText\">$link</span>" );
708 } else if ( $pcache ) {
709 # Display content and save to parser cache
710 $wgOut->addWikiText( $text, true, $this );
711 } else {
712 # Display content, don't attempt to save to parser cache
713 $wgOut->addWikiText( $text );
714 }
715 }
716 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
717
718 # If we have been passed an &rcid= parameter, we want to give the user a
719 # chance to mark this new article as patrolled.
720 if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->getID() != 0 &&
721 ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) )
722 {
723 $wgOut->addHTML( wfMsg ( 'markaspatrolledlink',
724 $sk->makeKnownLinkObj ( $this->mTitle, wfMsg ( 'markaspatrolledtext' ),
725 "action=markpatrolled&rcid={$rcid}" )
726 ) );
727 }
728
729 # Put link titles into the link cache
730 $wgOut->replaceLinkHolders();
731 # Add link titles as META keywords
732 $wgOut->addMetaTags() ;
733
734 $this->viewUpdates();
735 wfProfileOut( $fname );
736 }
737
738 # Theoretically we could defer these whole insert and update
739 # functions for after display, but that's taking a big leap
740 # of faith, and we want to be able to report database
741 # errors at some point.
742
743 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis ) {
744 global $wgOut, $wgUser, $wgMwRedir;
745 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
746
747 $fname = 'Article::insertNewArticle';
748
749 $this->mCountAdjustment = $this->isCountable( $text );
750
751 $ns = $this->mTitle->getNamespace();
752 $ttl = $this->mTitle->getDBkey();
753 $text = $this->preSaveTransform( $text );
754 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
755 else { $redir = 0; }
756
757 $now = wfTimestampNow();
758 $won = wfInvertTimestamp( $now );
759 wfSeedRandom();
760 $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
761 $dbw =& wfGetDB( DB_MASTER );
762
763 $cur_id = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
764
765 $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
766
767 $dbw->insertArray( 'cur', array(
768 'cur_id' => $cur_id,
769 'cur_namespace' => $ns,
770 'cur_title' => $ttl,
771 'cur_text' => $text,
772 'cur_comment' => $summary,
773 'cur_user' => $wgUser->getID(),
774 'cur_timestamp' => $dbw->timestamp($now),
775 'cur_minor_edit' => $isminor,
776 'cur_counter' => 0,
777 'cur_restrictions' => '',
778 'cur_user_text' => $wgUser->getName(),
779 'cur_is_redirect' => $redir,
780 'cur_is_new' => 1,
781 'cur_random' => $rand,
782 'cur_touched' => $dbw->timestamp($now),
783 'inverse_timestamp' => $won,
784 ), $fname );
785
786 $newid = $dbw->insertId();
787 $this->mTitle->resetArticleID( $newid );
788
789 Article::onArticleCreate( $this->mTitle );
790 RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
791
792 if ($watchthis) {
793 if(!$this->mTitle->userIsWatching()) $this->watch();
794 } else {
795 if ( $this->mTitle->userIsWatching() ) {
796 $this->unwatch();
797 }
798 }
799
800 # The talk page isn't in the regular link tables, so we need to update manually:
801 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
802 $dbw->updateArray( 'cur', array('cur_touched' => $dbw->timestamp($now) ),
803 array( 'cur_namespace' => $talkns, 'cur_title' => $ttl ), $fname );
804
805 # standard deferred updates
806 $this->editUpdates( $text );
807
808 $this->showArticle( $text, wfMsg( 'newarticle' ) );
809 }
810
811
812 /* Side effects: loads last edit */
813 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '') {
814 $this->loadLastEdit();
815 $oldtext = $this->getContent( true );
816 if ($section != '') {
817 if($section=='new') {
818 if($summary) $subject="== {$summary} ==\n\n";
819 $text=$oldtext."\n\n".$subject.$text;
820 } else {
821
822 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
823 # comments to be stripped as well)
824 $striparray=array();
825 $parser=new Parser();
826 $parser->mOutputType=OT_WIKI;
827 $oldtext=$parser->strip($oldtext, $striparray, true);
828
829 # now that we can be sure that no pseudo-sections are in the source,
830 # split it up
831 # Unfortunately we can't simply do a preg_replace because that might
832 # replace the wrong section, so we have to use the section counter instead
833 $secs=preg_split('/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
834 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
835 $secs[$section*2]=$text."\n\n"; // replace with edited
836
837 # section 0 is top (intro) section
838 if($section!=0) {
839
840 # headline of old section - we need to go through this section
841 # to determine if there are any subsections that now need to
842 # be erased, as the mother section has been replaced with
843 # the text of all subsections.
844 $headline=$secs[$section*2-1];
845 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
846 $hlevel=$matches[1];
847
848 # determine headline level for wikimarkup headings
849 if(strpos($hlevel,'=')!==false) {
850 $hlevel=strlen($hlevel);
851 }
852
853 $secs[$section*2-1]=''; // erase old headline
854 $count=$section+1;
855 $break=false;
856 while(!empty($secs[$count*2-1]) && !$break) {
857
858 $subheadline=$secs[$count*2-1];
859 preg_match(
860 '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
861 $subhlevel=$matches[1];
862 if(strpos($subhlevel,'=')!==false) {
863 $subhlevel=strlen($subhlevel);
864 }
865 if($subhlevel > $hlevel) {
866 // erase old subsections
867 $secs[$count*2-1]='';
868 $secs[$count*2]='';
869 }
870 if($subhlevel <= $hlevel) {
871 $break=true;
872 }
873 $count++;
874
875 }
876
877 }
878 $text=join('',$secs);
879 # reinsert the stuff that we stripped out earlier
880 $text=$parser->unstrip($text,$striparray);
881 $text=$parser->unstripNoWiki($text,$striparray);
882 }
883
884 }
885 return $text;
886 }
887
888 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
889 global $wgOut, $wgUser;
890 global $wgDBtransactions, $wgMwRedir;
891 global $wgUseSquid, $wgInternalServer;
892
893 $fname = 'Article::updateArticle';
894 $good = true;
895
896 if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
897 if ( $minor && $wgUser->getID() ) { $me2 = 1; } else { $me2 = 0; }
898 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
899 $redir = 1;
900 $text = $m[1] . "\n"; # Remove all content but redirect
901 }
902 else { $redir = 0; }
903
904 $text = $this->preSaveTransform( $text );
905 $dbw =& wfGetDB( DB_MASTER );
906
907 # Update article, but only if changed.
908
909 # It's important that we either rollback or complete, otherwise an attacker could
910 # overwrite cur entries by sending precisely timed user aborts. Random bored users
911 # could conceivably have the same effect, especially if cur is locked for long periods.
912 if( $wgDBtransactions ) {
913 $dbw->query( 'BEGIN', $fname );
914 } else {
915 $userAbort = ignore_user_abort( true );
916 }
917
918 $oldtext = $this->getContent( true );
919
920 if ( 0 != strcmp( $text, $oldtext ) ) {
921 $this->mCountAdjustment = $this->isCountable( $text )
922 - $this->isCountable( $oldtext );
923 $now = wfTimestampNow();
924 $won = wfInvertTimestamp( $now );
925
926 # First update the cur row
927 $dbw->updateArray( 'cur',
928 array( /* SET */
929 'cur_text' => $text,
930 'cur_comment' => $summary,
931 'cur_minor_edit' => $me2,
932 'cur_user' => $wgUser->getID(),
933 'cur_timestamp' => $now,
934 'cur_user_text' => $wgUser->getName(),
935 'cur_is_redirect' => $redir,
936 'cur_is_new' => 0,
937 'cur_touched' => $now,
938 'inverse_timestamp' => $won
939 ), array( /* WHERE */
940 'cur_id' => $this->getID(),
941 'cur_timestamp' => $this->getTimestamp()
942 ), $fname
943 );
944
945 if( $dbw->affectedRows() == 0 ) {
946 /* Belated edit conflict! Run away!! */
947 $good = false;
948 } else {
949 # Now insert the previous revision into old
950
951 # This overwrites $oldtext if revision compression is on
952 $flags = Article::compressRevisionText( $oldtext );
953
954 $dbw->insertArray( 'old',
955 array(
956 'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
957 'old_namespace' => $this->mTitle->getNamespace(),
958 'old_title' => $this->mTitle->getDBkey(),
959 'old_text' => $oldtext,
960 'old_comment' => $this->getComment(),
961 'old_user' => $this->getUser(),
962 'old_user_text' => $this->getUserText(),
963 'old_timestamp' => $this->getTimestamp(),
964 'old_minor_edit' => $me1,
965 'inverse_timestamp' => wfInvertTimestamp( $this->getTimestamp() ),
966 'old_flags' => $flags,
967 ), $fname
968 );
969
970 $oldid = $dbw->insertId();
971
972 $bot = (int)($wgUser->isBot() || $forceBot);
973 RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
974 $oldid, $this->getTimestamp(), $bot );
975 Article::onArticleEdit( $this->mTitle );
976 }
977 }
978
979 if( $wgDBtransactions ) {
980 $dbw->query( 'COMMIT', $fname );
981 } else {
982 ignore_user_abort( $userAbort );
983 }
984
985 if ( $good ) {
986 if ($watchthis) {
987 if (!$this->mTitle->userIsWatching()) $this->watch();
988 } else {
989 if ( $this->mTitle->userIsWatching() ) {
990 $this->unwatch();
991 }
992 }
993 # standard deferred updates
994 $this->editUpdates( $text );
995
996
997 $urls = array();
998 # Template namespace
999 # Purge all articles linking here
1000 if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
1001 $titles = $this->mTitle->getLinksTo();
1002 Title::touchArray( $titles );
1003 if ( $wgUseSquid ) {
1004 foreach ( $titles as $title ) {
1005 $urls[] = $title->getInternalURL();
1006 }
1007 }
1008 }
1009
1010 # Squid updates
1011 if ( $wgUseSquid ) {
1012 $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
1013 $u = new SquidUpdate( $urls );
1014 $u->doUpdate();
1015 }
1016
1017 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor );
1018 }
1019 return $good;
1020 }
1021
1022 # After we've either updated or inserted the article, update
1023 # the link tables and redirect to the new page.
1024
1025 function showArticle( $text, $subtitle , $sectionanchor = '' ) {
1026 global $wgOut, $wgUser, $wgLinkCache;
1027 global $wgMwRedir;
1028
1029 $wgLinkCache = new LinkCache();
1030 # Select for update
1031 $wgLinkCache->forUpdate( true );
1032
1033 # Get old version of link table to allow incremental link updates
1034 $wgLinkCache->preFill( $this->mTitle );
1035 $wgLinkCache->clear();
1036
1037 # Parse the text and replace links with placeholders
1038 $wgOut = new OutputPage();
1039 $wgOut->addWikiText( $text );
1040
1041 # Look up the links in the DB and add them to the link cache
1042 $wgOut->replaceLinkHolders( RLH_FOR_UPDATE );
1043
1044 if( $wgMwRedir->matchStart( $text ) )
1045 $r = 'redirect=no';
1046 else
1047 $r = '';
1048 $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
1049 }
1050
1051 # Validate article
1052
1053 function validate () {
1054 global $wgOut, $wgUseValidation;
1055 if( $wgUseValidation ) {
1056 $wgOut->setPagetitle( wfMsg( 'validate' ) . ": " . $this->mTitle->getPrefixedText() );
1057 $wgOut->setRobotpolicy( 'noindex,follow' );
1058 if( $this->mTitle->getNamespace() != 0 ) {
1059 $wgOut->addHTML( wfMsg( 'val_validate_article_namespace_only' ) );
1060 return;
1061 }
1062 $v = new Validation;
1063 $v->validate_form( $this->mTitle->getDBkey() );
1064 } else {
1065 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
1066 }
1067 }
1068
1069 # Mark this particular edit as patrolled
1070 function markpatrolled() {
1071 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1072 $wgOut->setRobotpolicy( 'noindex,follow' );
1073
1074 if ( !$wgUseRCPatrol )
1075 {
1076 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1077 return;
1078 }
1079 if ( $wgUser->getID() == 0 )
1080 {
1081 $wgOut->loginToUse();
1082 return;
1083 }
1084 if ( $wgOnlySysopsCanPatrol && !$wgUser->isSysop() )
1085 {
1086 $wgOut->sysopRequired();
1087 return;
1088 }
1089 $rcid = $wgRequest->getVal( 'rcid' );
1090 if ( !is_null ( $rcid ) )
1091 {
1092 RecentChange::markPatrolled( $rcid );
1093 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1094 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1095 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1096 }
1097 else
1098 {
1099 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1100 }
1101 }
1102
1103
1104 # Add this page to my watchlist
1105
1106 function watch( $add = true ) {
1107 global $wgUser, $wgOut, $wgLang;
1108 global $wgDeferredUpdateList;
1109
1110 if ( 0 == $wgUser->getID() ) {
1111 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1112 return;
1113 }
1114 if ( wfReadOnly() ) {
1115 $wgOut->readOnlyPage();
1116 return;
1117 }
1118 if( $add )
1119 $wgUser->addWatch( $this->mTitle );
1120 else
1121 $wgUser->removeWatch( $this->mTitle );
1122
1123 $wgOut->setPagetitle( wfMsg( $add ? 'addedwatch' : 'removedwatch' ) );
1124 $wgOut->setRobotpolicy( 'noindex,follow' );
1125
1126 $sk = $wgUser->getSkin() ;
1127 $link = $this->mTitle->getPrefixedText();
1128
1129 if($add)
1130 $text = wfMsg( 'addedwatchtext', $link );
1131 else
1132 $text = wfMsg( 'removedwatchtext', $link );
1133 $wgOut->addWikiText( $text );
1134
1135 $up = new UserUpdate();
1136 array_push( $wgDeferredUpdateList, $up );
1137
1138 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1139 }
1140
1141 function unwatch() {
1142 $this->watch( false );
1143 }
1144
1145 # protect a page
1146
1147 function protect( $limit = 'sysop' ) {
1148 global $wgUser, $wgOut, $wgRequest;
1149
1150 if ( ! $wgUser->isSysop() ) {
1151 $wgOut->sysopRequired();
1152 return;
1153 }
1154 if ( wfReadOnly() ) {
1155 $wgOut->readOnlyPage();
1156 return;
1157 }
1158 $id = $this->mTitle->getArticleID();
1159 if ( 0 == $id ) {
1160 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1161 return;
1162 }
1163
1164 $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
1165 $reason = $wgRequest->getText( 'wpReasonProtect' );
1166
1167 if ( $confirm ) {
1168 $dbw =& wfGetDB( DB_MASTER );
1169 $dbw->updateArray( 'cur',
1170 array( /* SET */
1171 'cur_touched' => wfTimestampNow(),
1172 'cur_restrictions' => (string)$limit
1173 ), array( /* WHERE */
1174 'cur_id' => $id
1175 ), 'Article::protect'
1176 );
1177
1178 $log = new LogPage( wfMsg( 'protectlogpage' ), wfMsg( 'protectlogtext' ) );
1179 if ( $limit === "" ) {
1180 $log->addEntry( wfMsg( 'unprotectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1181 } else {
1182 $log->addEntry( wfMsg( 'protectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1183 }
1184 $wgOut->redirect( $this->mTitle->getFullURL() );
1185 return;
1186 } else {
1187 $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
1188 return $this->confirmProtect( '', $reason, $limit );
1189 }
1190 }
1191
1192 # Output protection confirmation dialog
1193
1194 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1195 global $wgOut;
1196
1197 wfDebug( "Article::confirmProtect\n" );
1198
1199 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1200 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1201
1202 $check = '';
1203 $protcom = '';
1204
1205 if ( $limit === '' ) {
1206 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1207 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1208 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1209 $check = htmlspecialchars( wfMsg( 'confirmunprotect' ) );
1210 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1211 $formaction = $this->mTitle->escapeLocalURL( 'action=unprotect' . $par );
1212 } else {
1213 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1214 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1215 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1216 $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
1217 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1218 $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
1219 }
1220
1221 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1222
1223 $wgOut->addHTML( "
1224 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1225 <table border='0'>
1226 <tr>
1227 <td align='right'>
1228 <label for='wpReasonProtect'>{$protcom}:</label>
1229 </td>
1230 <td align='left'>
1231 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1232 </td>
1233 </tr>
1234 <tr>
1235 <td>&nbsp;</td>
1236 </tr>
1237 <tr>
1238 <td align='right'>
1239 <input type='checkbox' name='wpConfirmProtect' value='1' id='wpConfirmProtect' />
1240 </td>
1241 <td>
1242 <label for='wpConfirmProtect'>{$check}</label>
1243 </td>
1244 </tr>
1245 <tr>
1246 <td>&nbsp;</td>
1247 <td>
1248 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1249 </td>
1250 </tr>
1251 </table>
1252 </form>\n" );
1253
1254 $wgOut->returnToMain( false );
1255 }
1256
1257 function unprotect() {
1258 return $this->protect( '' );
1259 }
1260
1261 # UI entry point for page deletion
1262
1263 function delete() {
1264 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1265 $fname = 'Article::delete';
1266 $confirm = $wgRequest->getBool( 'wpConfirm' ) && $wgRequest->wasPosted();
1267 $reason = $wgRequest->getText( 'wpReason' );
1268
1269 # This code desperately needs to be totally rewritten
1270
1271 # Check permissions
1272 if ( ( ! $wgUser->isSysop() ) ) {
1273 $wgOut->sysopRequired();
1274 return;
1275 }
1276 if ( wfReadOnly() ) {
1277 $wgOut->readOnlyPage();
1278 return;
1279 }
1280
1281 # Better double-check that it hasn't been deleted yet!
1282 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1283 if ( ( '' == trim( $this->mTitle->getText() ) )
1284 or ( $this->mTitle->getArticleId() == 0 ) ) {
1285 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1286 return;
1287 }
1288
1289 if ( $confirm ) {
1290 $this->doDelete( $reason );
1291 return;
1292 }
1293
1294 # determine whether this page has earlier revisions
1295 # and insert a warning if it does
1296 # we select the text because it might be useful below
1297 $dbr =& wfGetDB( DB_SLAVE );
1298 $ns = $this->mTitle->getNamespace();
1299 $title = $this->mTitle->getDBkey();
1300 $old = $dbr->getArray( 'old',
1301 array( 'old_text', 'old_flags' ),
1302 array(
1303 'old_namespace' => $ns,
1304 'old_title' => $title,
1305 ), $fname, array( 'ORDER BY' => 'inverse_timestamp' )
1306 );
1307
1308 if( $old !== false && !$confirm ) {
1309 $skin=$wgUser->getSkin();
1310 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1311 $wgOut->addHTML( $skin->historyLink() .'</b>');
1312 }
1313
1314 # Fetch cur_text
1315 $s = $dbr->getArray( 'cur',
1316 array( 'cur_text' ),
1317 array(
1318 'cur_namespace' => $ns,
1319 'cur_title' => $title,
1320 ), $fname
1321 );
1322
1323 if( $s !== false ) {
1324 # if this is a mini-text, we can paste part of it into the deletion reason
1325
1326 #if this is empty, an earlier revision may contain "useful" text
1327 $blanked = false;
1328 if($s->cur_text != '') {
1329 $text=$s->cur_text;
1330 } else {
1331 if($old) {
1332 $text = Article::getRevisionText( $old );
1333 $blanked = true;
1334 }
1335
1336 }
1337
1338 $length=strlen($text);
1339
1340 # this should not happen, since it is not possible to store an empty, new
1341 # page. Let's insert a standard text in case it does, though
1342 if($length == 0 && $reason === '') {
1343 $reason = wfMsg('exblank');
1344 }
1345
1346 if($length < 500 && $reason === '') {
1347
1348 # comment field=255, let's grep the first 150 to have some user
1349 # space left
1350 $text=substr($text,0,150);
1351 # let's strip out newlines and HTML tags
1352 $text=preg_replace('/\"/',"'",$text);
1353 $text=preg_replace('/\</','&lt;',$text);
1354 $text=preg_replace('/\>/','&gt;',$text);
1355 $text=preg_replace("/[\n\r]/",'',$text);
1356 if(!$blanked) {
1357 $reason=wfMsg('excontent'). " '".$text;
1358 } else {
1359 $reason=wfMsg('exbeforeblank') . " '".$text;
1360 }
1361 if($length>150) { $reason .= '...'; } # we've only pasted part of the text
1362 $reason.="'";
1363 }
1364 }
1365
1366 return $this->confirmDelete( '', $reason );
1367 }
1368
1369 # Output deletion confirmation dialog
1370
1371 function confirmDelete( $par, $reason ) {
1372 global $wgOut;
1373
1374 wfDebug( "Article::confirmDelete\n" );
1375
1376 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1377 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1378 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1379 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1380
1381 $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
1382
1383 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1384 $check = htmlspecialchars( wfMsg( 'confirmcheck' ) );
1385 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1386
1387 $wgOut->addHTML( "
1388 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1389 <table border='0'>
1390 <tr>
1391 <td align='right'>
1392 <label for='wpReason'>{$delcom}:</label>
1393 </td>
1394 <td align='left'>
1395 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1396 </td>
1397 </tr>
1398 <tr>
1399 <td>&nbsp;</td>
1400 </tr>
1401 <tr>
1402 <td align='right'>
1403 <input type='checkbox' name='wpConfirm' value='1' id='wpConfirm' />
1404 </td>
1405 <td>
1406 <label for='wpConfirm'>{$check}</label>
1407 </td>
1408 </tr>
1409 <tr>
1410 <td>&nbsp;</td>
1411 <td>
1412 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1413 </td>
1414 </tr>
1415 </table>
1416 </form>\n" );
1417
1418 $wgOut->returnToMain( false );
1419 }
1420
1421
1422 # Perform a deletion and output success or failure messages
1423
1424 function doDelete( $reason ) {
1425 global $wgOut, $wgUser, $wgLang;
1426 $fname = 'Article::doDelete';
1427 wfDebug( "$fname\n" );
1428
1429 if ( $this->doDeleteArticle( $reason ) ) {
1430 $deleted = $this->mTitle->getPrefixedText();
1431
1432 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1433 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1434
1435 $sk = $wgUser->getSkin();
1436 $loglink = $sk->makeKnownLink( $wgLang->getNsText( NS_WIKIPEDIA ) .
1437 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
1438
1439 $text = wfMsg( "deletedtext", $deleted, $loglink );
1440
1441 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
1442 $wgOut->returnToMain( false );
1443 } else {
1444 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1445 }
1446 }
1447
1448 # Back-end article deletion
1449 # Deletes the article with database consistency, writes logs, purges caches
1450 # Returns success
1451 function doDeleteArticle( $reason ) {
1452 global $wgUser, $wgLang;
1453 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1454
1455 $fname = 'Article::doDeleteArticle';
1456 wfDebug( $fname."\n" );
1457
1458 $dbw =& wfGetDB( DB_MASTER );
1459 $ns = $this->mTitle->getNamespace();
1460 $t = $this->mTitle->getDBkey();
1461 $id = $this->mTitle->getArticleID();
1462
1463 if ( $t == '' || $id == 0 ) {
1464 return false;
1465 }
1466
1467 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1468 array_push( $wgDeferredUpdateList, $u );
1469
1470 $linksTo = $this->mTitle->getLinksTo();
1471
1472 # Squid purging
1473 if ( $wgUseSquid ) {
1474 $urls = array(
1475 $this->mTitle->getInternalURL(),
1476 $this->mTitle->getInternalURL( 'history' )
1477 );
1478 foreach ( $linksTo as $linkTo ) {
1479 $urls[] = $linkTo->getInternalURL();
1480 }
1481
1482 $u = new SquidUpdate( $urls );
1483 array_push( $wgDeferredUpdateList, $u );
1484
1485 }
1486
1487 # Client and file cache invalidation
1488 Title::touchArray( $linksTo );
1489
1490 # Move article and history to the "archive" table
1491 $archiveTable = $dbw->tableName( 'archive' );
1492 $oldTable = $dbw->tableName( 'old' );
1493 $curTable = $dbw->tableName( 'cur' );
1494 $recentchangesTable = $dbw->tableName( 'recentchanges' );
1495 $linksTable = $dbw->tableName( 'links' );
1496 $brokenlinksTable = $dbw->tableName( 'brokenlinks' );
1497
1498 $dbw->insertSelect( 'archive', 'cur',
1499 array(
1500 'ar_namespace' => 'cur_namespace',
1501 'ar_title' => 'cur_title',
1502 'ar_text' => 'cur_text',
1503 'ar_comment' => 'cur_comment',
1504 'ar_user' => 'cur_user',
1505 'ar_user_text' => 'cur_user_text',
1506 'ar_timestamp' => 'cur_timestamp',
1507 'ar_minor_edit' => 'cur_minor_edit',
1508 'ar_flags' => 0,
1509 ), array(
1510 'cur_namespace' => $ns,
1511 'cur_title' => $t,
1512 ), $fname
1513 );
1514
1515 $dbw->insertSelect( 'archive', 'old',
1516 array(
1517 'ar_namespace' => 'old_namespace',
1518 'ar_title' => 'old_title',
1519 'ar_text' => 'old_text',
1520 'ar_comment' => 'old_comment',
1521 'ar_user' => 'old_user',
1522 'ar_user_text' => 'old_user_text',
1523 'ar_timestamp' => 'old_timestamp',
1524 'ar_minor_edit' => 'old_minor_edit',
1525 'ar_flags' => 'old_flags'
1526 ), array(
1527 'old_namespace' => $ns,
1528 'old_title' => $t,
1529 ), $fname
1530 );
1531
1532 # Now that it's safely backed up, delete it
1533
1534 $dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
1535 $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
1536 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1537
1538 # Finally, clean up the link tables
1539 $t = $this->mTitle->getPrefixedDBkey();
1540
1541 Article::onArticleDelete( $this->mTitle );
1542
1543 # Insert broken links
1544 $brokenLinks = array();
1545 foreach ( $linksTo as $titleObj ) {
1546 # Get article ID. Efficient because it was loaded into the cache by getLinksTo().
1547 $linkID = $titleObj->getArticleID();
1548 $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
1549 }
1550 $dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' );
1551
1552 # Delete live links
1553 $dbw->delete( 'links', array( 'l_to' => $id ) );
1554 $dbw->delete( 'links', array( 'l_from' => $id ) );
1555 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1556 $dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) );
1557 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1558
1559 # Log the deletion
1560 $log = new LogPage( wfMsg( 'dellogpage' ), wfMsg( 'dellogpagetext' ) );
1561 $art = $this->mTitle->getPrefixedText();
1562 $log->addEntry( wfMsg( 'deletedarticle', $art ), $reason );
1563
1564 # Clear the cached article id so the interface doesn't act like we exist
1565 $this->mTitle->resetArticleID( 0 );
1566 $this->mTitle->mArticleID = 0;
1567 return true;
1568 }
1569
1570 function rollback() {
1571 global $wgUser, $wgLang, $wgOut, $wgRequest;
1572 $fname = "Article::rollback";
1573
1574 if ( ! $wgUser->isSysop() ) {
1575 $wgOut->sysopRequired();
1576 return;
1577 }
1578 if ( wfReadOnly() ) {
1579 $wgOut->readOnlyPage( $this->getContent( true ) );
1580 return;
1581 }
1582 $dbw =& wfGetDB( DB_MASTER );
1583
1584 # Enhanced rollback, marks edits rc_bot=1
1585 $bot = $wgRequest->getBool( 'bot' );
1586
1587 # Replace all this user's current edits with the next one down
1588 $tt = $this->mTitle->getDBKey();
1589 $n = $this->mTitle->getNamespace();
1590
1591 # Get the last editor, lock table exclusively
1592 $s = $dbw->getArray( 'cur',
1593 array( 'cur_id','cur_user','cur_user_text','cur_comment' ),
1594 array( 'cur_title' => $tt, 'cur_namespace' => $n ),
1595 $fname, 'FOR UPDATE'
1596 );
1597 if( $s === false ) {
1598 # Something wrong
1599 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1600 return;
1601 }
1602 $ut = $dbw->strencode( $s->cur_user_text );
1603 $uid = $s->cur_user;
1604 $pid = $s->cur_id;
1605
1606 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1607 if( $from != $s->cur_user_text ) {
1608 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1609 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1610 htmlspecialchars( $this->mTitle->getPrefixedText()),
1611 htmlspecialchars( $from ),
1612 htmlspecialchars( $s->cur_user_text ) ) );
1613 if($s->cur_comment != '') {
1614 $wgOut->addHTML(
1615 wfMsg('editcomment',
1616 htmlspecialchars( $s->cur_comment ) ) );
1617 }
1618 return;
1619 }
1620
1621 # Get the last edit not by this guy
1622 $s = $dbw->getArray( 'old',
1623 array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
1624 array(
1625 'old_namespace' => $n,
1626 'old_title' => $tt,
1627 "old_user <> {$uid} OR old_user_text <> '{$ut}'"
1628 ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
1629 );
1630 if( $s === false ) {
1631 # Something wrong
1632 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
1633 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
1634 return;
1635 }
1636
1637 if ( $bot ) {
1638 # Mark all reverted edits as bot
1639 $dbw->updateArray( 'recentchanges',
1640 array( /* SET */
1641 'rc_bot' => 1
1642 ), array( /* WHERE */
1643 'rc_user' => $uid,
1644 "rc_timestamp > '{$s->old_timestamp}'",
1645 ), $fname
1646 );
1647 }
1648
1649 # Save it!
1650 $newcomment = wfMsg( 'revertpage', $s->old_user_text, $from );
1651 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1652 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1653 $wgOut->addHTML( '<h2>' . $newcomment . "</h2>\n<hr />\n" );
1654 $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
1655 Article::onArticleEdit( $this->mTitle );
1656 $wgOut->returnToMain( false );
1657 }
1658
1659
1660 # Do standard deferred updates after page view
1661
1662 /* private */ function viewUpdates() {
1663 global $wgDeferredUpdateList;
1664 if ( 0 != $this->getID() ) {
1665 global $wgDisableCounters;
1666 if( !$wgDisableCounters ) {
1667 Article::incViewCount( $this->getID() );
1668 $u = new SiteStatsUpdate( 1, 0, 0 );
1669 array_push( $wgDeferredUpdateList, $u );
1670 }
1671 }
1672 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1673 $this->mTitle->getDBkey() );
1674 array_push( $wgDeferredUpdateList, $u );
1675 }
1676
1677 # Do standard deferred updates after page edit.
1678 # Every 1000th edit, prune the recent changes table.
1679
1680 /* private */ function editUpdates( $text ) {
1681 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1682 global $wgMessageCache;
1683
1684 wfSeedRandom();
1685 if ( 0 == mt_rand( 0, 999 ) ) {
1686 $dbw =& wfGetDB( DB_MASTER );
1687 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1688 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1689 $dbw->query( $sql );
1690 }
1691 $id = $this->getID();
1692 $title = $this->mTitle->getPrefixedDBkey();
1693 $shortTitle = $this->mTitle->getDBkey();
1694
1695 $adj = $this->mCountAdjustment;
1696
1697 if ( 0 != $id ) {
1698 $u = new LinksUpdate( $id, $title );
1699 array_push( $wgDeferredUpdateList, $u );
1700 $u = new SiteStatsUpdate( 0, 1, $adj );
1701 array_push( $wgDeferredUpdateList, $u );
1702 $u = new SearchUpdate( $id, $title, $text );
1703 array_push( $wgDeferredUpdateList, $u );
1704
1705 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
1706 array_push( $wgDeferredUpdateList, $u );
1707
1708 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1709 $wgMessageCache->replace( $shortTitle, $text );
1710 }
1711 }
1712 }
1713
1714 /* private */ function setOldSubtitle() {
1715 global $wgLang, $wgOut;
1716
1717 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1718 $r = wfMsg( 'revisionasof', $td );
1719 $wgOut->setSubtitle( "({$r})" );
1720 }
1721
1722 # This function is called right before saving the wikitext,
1723 # so we can do things like signatures and links-in-context.
1724
1725 function preSaveTransform( $text ) {
1726 global $wgParser, $wgUser;
1727 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
1728 }
1729
1730 /* Caching functions */
1731
1732 # checkLastModified returns true if it has taken care of all
1733 # output to the client that is necessary for this request.
1734 # (that is, it has sent a cached version of the page)
1735 function tryFileCache() {
1736 static $called = false;
1737 if( $called ) {
1738 wfDebug( " tryFileCache() -- called twice!?\n" );
1739 return;
1740 }
1741 $called = true;
1742 if($this->isFileCacheable()) {
1743 $touched = $this->mTouched;
1744 if( $this->mTitle->getPrefixedDBkey() == wfMsg( 'mainpage' ) ) {
1745 # Expire the main page quicker
1746 $expire = wfUnix2Timestamp( time() - 3600 );
1747 $touched = max( $expire, $touched );
1748 }
1749 $cache = new CacheManager( $this->mTitle );
1750 if($cache->isFileCacheGood( $touched )) {
1751 global $wgOut;
1752 wfDebug( " tryFileCache() - about to load\n" );
1753 $cache->loadFromFileCache();
1754 return true;
1755 } else {
1756 wfDebug( " tryFileCache() - starting buffer\n" );
1757 ob_start( array(&$cache, 'saveToFileCache' ) );
1758 }
1759 } else {
1760 wfDebug( " tryFileCache() - not cacheable\n" );
1761 }
1762 }
1763
1764 function isFileCacheable() {
1765 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
1766 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
1767
1768 return $wgUseFileCache
1769 and (!$wgShowIPinHeader)
1770 and ($this->getID() != 0)
1771 and ($wgUser->getId() == 0)
1772 and (!$wgUser->getNewtalk())
1773 and ($this->mTitle->getNamespace() != NS_SPECIAL )
1774 and (empty( $action ) || $action == 'view')
1775 and (!isset($oldid))
1776 and (!isset($diff))
1777 and (!isset($redirect))
1778 and (!isset($printable))
1779 and (!$this->mRedirectedFrom);
1780 }
1781
1782 # Loads cur_touched and returns a value indicating if it should be used
1783 function checkTouched() {
1784 $fname = 'Article::checkTouched';
1785
1786 $id = $this->getID();
1787 $dbr =& wfGetDB( DB_SLAVE );
1788 $s = $dbr->getArray( 'cur', array( 'cur_touched', 'cur_is_redirect' ),
1789 array( 'cur_id' => $id ), $fname );
1790 if( $s !== false ) {
1791 $this->mTouched = $s->cur_touched;
1792 return !$s->cur_is_redirect;
1793 } else {
1794 return false;
1795 }
1796 }
1797
1798 # Edit an article without doing all that other stuff
1799 function quickEdit( $text, $comment = '', $minor = 0 ) {
1800 global $wgUser, $wgMwRedir;
1801 $fname = 'Article::quickEdit';
1802 wfProfileIn( $fname );
1803
1804 $dbw =& wfGetDB( DB_MASTER );
1805 $ns = $this->mTitle->getNamespace();
1806 $dbkey = $this->mTitle->getDBkey();
1807 $encDbKey = $dbw->strencode( $dbkey );
1808 $timestamp = wfTimestampNow();
1809
1810 # Save to history
1811 $dbw->insertSelect( 'old', 'cur',
1812 array(
1813 'old_namespace' => 'cur_namespace',
1814 'old_title' => 'cur_title',
1815 'old_text' => 'cur_text',
1816 'old_comment' => 'cur_comment',
1817 'old_user' => 'cur_user',
1818 'old_user_text' => 'cur_user_text',
1819 'old_timestamp' => 'cur_timestamp',
1820 'inverse_timestamp' => '99999999999999-cur_timestamp',
1821 ), array(
1822 'cur_namespace' => $ns,
1823 'cur_title' => $dbkey,
1824 ), $fname
1825 );
1826
1827 # Use the affected row count to determine if the article is new
1828 $numRows = $dbw->affectedRows();
1829
1830 # Make an array of fields to be inserted
1831 $fields = array(
1832 'cur_text' => $text,
1833 'cur_timestamp' => $timestamp,
1834 'cur_user' => $wgUser->getID(),
1835 'cur_user_text' => $wgUser->getName(),
1836 'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
1837 'cur_comment' => $comment,
1838 'cur_is_redirect' => $wgMwRedir->matchStart( $text ) ? 1 : 0,
1839 'cur_minor_edit' => intval($minor),
1840 'cur_touched' => $timestamp,
1841 );
1842
1843 if ( $numRows ) {
1844 # Update article
1845 $fields['cur_is_new'] = 0;
1846 $dbw->updateArray( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname );
1847 } else {
1848 # Insert new article
1849 $fields['cur_is_new'] = 1;
1850 $fields['cur_namespace'] = $ns;
1851 $fields['cur_title'] = $dbkey;
1852 $fields['cur_random'] = $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
1853 $dbw->insertArray( 'cur', $fields, $fname );
1854 }
1855 wfProfileOut( $fname );
1856 }
1857
1858 /* static */ function incViewCount( $id ) {
1859 $id = intval( $id );
1860 global $wgHitcounterUpdateFreq;
1861
1862 $dbw =& wfGetDB( DB_MASTER );
1863 $curTable = $dbw->tableName( 'cur' );
1864 $hitcounterTable = $dbw->tableName( 'hitcounter' );
1865 $acchitsTable = $dbw->tableName( 'acchits' );
1866
1867 if( $wgHitcounterUpdateFreq <= 1 ){ //
1868 $dbw->query( "UPDATE $curTable SET cur_counter = cur_counter + 1 WHERE cur_id = $id" );
1869 return;
1870 }
1871
1872 # Not important enough to warrant an error page in case of failure
1873 $oldignore = $dbw->ignoreErrors( true );
1874
1875 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
1876
1877 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
1878 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
1879 # Most of the time (or on SQL errors), skip row count check
1880 $dbw->ignoreErrors( $oldignore );
1881 return;
1882 }
1883
1884 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
1885 $row = $dbw->fetchObject( $res );
1886 $rown = intval( $row->n );
1887 if( $rown >= $wgHitcounterUpdateFreq ){
1888 wfProfileIn( 'Article::incViewCount-collect' );
1889 $old_user_abort = ignore_user_abort( true );
1890
1891 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
1892 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
1893 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
1894 'GROUP BY hc_id');
1895 $dbw->query("DELETE FROM $hitcounterTable");
1896 $dbw->query('UNLOCK TABLES');
1897 $dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ".
1898 'WHERE cur_id = hc_id');
1899 $dbw->query("DROP TABLE $acchitsTable");
1900
1901 ignore_user_abort( $old_user_abort );
1902 wfProfileOut( 'Article::incViewCount-collect' );
1903 }
1904 $dbw->ignoreErrors( $oldignore );
1905 }
1906
1907 # The onArticle*() functions are supposed to be a kind of hooks
1908 # which should be called whenever any of the specified actions
1909 # are done.
1910 #
1911 # This is a good place to put code to clear caches, for instance.
1912
1913 # This is called on page move and undelete, as well as edit
1914 /* static */ function onArticleCreate($title_obj) {
1915 global $wgUseSquid, $wgDeferredUpdateList;
1916
1917 $titles = $title_obj->getBrokenLinksTo();
1918
1919 # Purge squid
1920 if ( $wgUseSquid ) {
1921 $urls = $title_obj->getSquidURLs();
1922 foreach ( $titles as $linkTitle ) {
1923 $urls[] = $linkTitle->getInternalURL();
1924 }
1925 $u = new SquidUpdate( $urls );
1926 array_push( $wgDeferredUpdateList, $u );
1927 }
1928
1929 # Clear persistent link cache
1930 LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
1931 }
1932
1933 /* static */ function onArticleDelete($title_obj) {
1934 LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
1935 }
1936
1937 /* static */ function onArticleEdit($title_obj) {
1938 LinkCache::linksccClearPage( $title_obj->getArticleID() );
1939 }
1940
1941
1942 # Info about this page
1943
1944 function info() {
1945 global $wgUser, $wgTitle, $wgOut, $wgLang, $wgAllowPageInfo;
1946 $fname = 'Article::info';
1947
1948 if ( !$wgAllowPageInfo ) {
1949 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
1950 return;
1951 }
1952
1953 $dbr =& wfGetDB( DB_SLAVE );
1954
1955 $basenamespace = $wgTitle->getNamespace() & (~1);
1956 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
1957 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
1958 $wl_clause = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
1959 $fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
1960 $wgOut->setPagetitle( $fullTitle );
1961 $wgOut->setSubtitle( wfMsg( "infosubtitle" ));
1962
1963 # first, see if the page exists at all.
1964 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1965 if ($exists < 1) {
1966 $wgOut->addHTML( wfMsg("noarticletext") );
1967 } else {
1968 $numwatchers = $dbr->selectField( 'watchlist', 'COUNT(*)', $wl_clause, $fname );
1969 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $numwatchers) . "</li>" );
1970 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1971 $wgOut->addHTML( "<li>" . wfMsg("numedits", $old + 1) . "</li>");
1972
1973 # to find number of distinct authors, we need to do some
1974 # funny stuff because of the cur/old table split:
1975 # - first, find the name of the 'cur' author
1976 # - then, find the number of *other* authors in 'old'
1977
1978 # find 'cur' author
1979 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
1980
1981 # find number of 'old' authors excluding 'cur' author
1982 $authors = $dbr->selectField( 'old', 'COUNT(DISTINCT old_user_text)',
1983 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname ) + 1;
1984
1985 # now for the Talk page ...
1986 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+1 );
1987 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+1 );
1988
1989 # does it exist?
1990 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1991
1992 # number of edits
1993 if ($exists > 0) {
1994 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1995 $wgOut->addHTML( "<li>" . wfMsg("numtalkedits", $old + 1) . "</li>");
1996 }
1997 $wgOut->addHTML( "<li>" . wfMsg("numauthors", $authors) . "</li>" );
1998
1999 # number of authors
2000 if ($exists > 0) {
2001 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
2002 $authors = $dbr->selectField( 'cur', 'COUNT(DISTINCT old_user_text)',
2003 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname );
2004
2005 $wgOut->addHTML( "<li>" . wfMsg("numtalkauthors", $authors) . "</li></ul>" );
2006 }
2007 }
2008 }
2009 }
2010
2011 ?>