7fedeee6adf6e9267877d9f719d37048f7391e7f
[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 ) {
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 # Add link titles as META keywords
730 $wgOut->addMetaTags() ;
731
732 $this->viewUpdates();
733 wfProfileOut( $fname );
734 }
735
736 # Theoretically we could defer these whole insert and update
737 # functions for after display, but that's taking a big leap
738 # of faith, and we want to be able to report database
739 # errors at some point.
740
741 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis ) {
742 global $wgOut, $wgUser, $wgMwRedir;
743 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
744
745 $fname = 'Article::insertNewArticle';
746
747 $this->mCountAdjustment = $this->isCountable( $text );
748
749 $ns = $this->mTitle->getNamespace();
750 $ttl = $this->mTitle->getDBkey();
751 $text = $this->preSaveTransform( $text );
752 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
753 else { $redir = 0; }
754
755 $now = wfTimestampNow();
756 $won = wfInvertTimestamp( $now );
757 wfSeedRandom();
758 $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
759 $dbw =& wfGetDB( DB_MASTER );
760
761 $cur_id = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
762
763 $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
764
765 $dbw->insertArray( 'cur', array(
766 'cur_id' => $cur_id,
767 'cur_namespace' => $ns,
768 'cur_title' => $ttl,
769 'cur_text' => $text,
770 'cur_comment' => $summary,
771 'cur_user' => $wgUser->getID(),
772 'cur_timestamp' => $now,
773 'cur_minor_edit' => $isminor,
774 'cur_counter' => 0,
775 'cur_restrictions' => '',
776 'cur_user_text' => $wgUser->getName(),
777 'cur_is_redirect' => $redir,
778 'cur_is_new' => 1,
779 'cur_random' => $rand,
780 'cur_touched' => $now,
781 'inverse_timestamp' => $won,
782 ), $fname );
783
784 $newid = $dbw->insertId();
785 $this->mTitle->resetArticleID( $newid );
786
787 Article::onArticleCreate( $this->mTitle );
788 RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
789
790 if ($watchthis) {
791 if(!$this->mTitle->userIsWatching()) $this->watch();
792 } else {
793 if ( $this->mTitle->userIsWatching() ) {
794 $this->unwatch();
795 }
796 }
797
798 # The talk page isn't in the regular link tables, so we need to update manually:
799 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
800 $dbw->updateArray( 'cur', array( 'cur_touched' => $now ), array( 'cur_namespace' => $talkns, 'cur_title' => $ttl ), $fname );
801
802 # standard deferred updates
803 $this->editUpdates( $text );
804
805 $this->showArticle( $text, wfMsg( 'newarticle' ) );
806 }
807
808
809 /* Side effects: loads last edit */
810 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '') {
811 $this->loadLastEdit();
812 $oldtext = $this->getContent( true );
813 if ($section != '') {
814 if($section=='new') {
815 if($summary) $subject="== {$summary} ==\n\n";
816 $text=$oldtext."\n\n".$subject.$text;
817 } else {
818
819 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
820 # comments to be stripped as well)
821 $striparray=array();
822 $parser=new Parser();
823 $parser->mOutputType=OT_WIKI;
824 $oldtext=$parser->strip($oldtext, $striparray, true);
825
826 # now that we can be sure that no pseudo-sections are in the source,
827 # split it up
828 # Unfortunately we can't simply do a preg_replace because that might
829 # replace the wrong section, so we have to use the section counter instead
830 $secs=preg_split('/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
831 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
832 $secs[$section*2]=$text."\n\n"; // replace with edited
833
834 # section 0 is top (intro) section
835 if($section!=0) {
836
837 # headline of old section - we need to go through this section
838 # to determine if there are any subsections that now need to
839 # be erased, as the mother section has been replaced with
840 # the text of all subsections.
841 $headline=$secs[$section*2-1];
842 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
843 $hlevel=$matches[1];
844
845 # determine headline level for wikimarkup headings
846 if(strpos($hlevel,'=')!==false) {
847 $hlevel=strlen($hlevel);
848 }
849
850 $secs[$section*2-1]=''; // erase old headline
851 $count=$section+1;
852 $break=false;
853 while(!empty($secs[$count*2-1]) && !$break) {
854
855 $subheadline=$secs[$count*2-1];
856 preg_match(
857 '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
858 $subhlevel=$matches[1];
859 if(strpos($subhlevel,'=')!==false) {
860 $subhlevel=strlen($subhlevel);
861 }
862 if($subhlevel > $hlevel) {
863 // erase old subsections
864 $secs[$count*2-1]='';
865 $secs[$count*2]='';
866 }
867 if($subhlevel <= $hlevel) {
868 $break=true;
869 }
870 $count++;
871
872 }
873
874 }
875 $text=join('',$secs);
876 # reinsert the stuff that we stripped out earlier
877 $text=$parser->unstrip($text,$striparray);
878 $text=$parser->unstripNoWiki($text,$striparray);
879 }
880
881 }
882 return $text;
883 }
884
885 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
886 global $wgOut, $wgUser;
887 global $wgDBtransactions, $wgMwRedir;
888 global $wgUseSquid, $wgInternalServer;
889
890 $fname = 'Article::updateArticle';
891 $good = true;
892
893 if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
894 if ( $minor && $wgUser->getID() ) { $me2 = 1; } else { $me2 = 0; }
895 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
896 $redir = 1;
897 $text = $m[1] . "\n"; # Remove all content but redirect
898 }
899 else { $redir = 0; }
900
901 $text = $this->preSaveTransform( $text );
902 $dbw =& wfGetDB( DB_MASTER );
903
904 # Update article, but only if changed.
905
906 # It's important that we either rollback or complete, otherwise an attacker could
907 # overwrite cur entries by sending precisely timed user aborts. Random bored users
908 # could conceivably have the same effect, especially if cur is locked for long periods.
909 if( $wgDBtransactions ) {
910 $dbw->query( 'BEGIN', $fname );
911 } else {
912 $userAbort = ignore_user_abort( true );
913 }
914
915 $oldtext = $this->getContent( true );
916
917 if ( 0 != strcmp( $text, $oldtext ) ) {
918 $this->mCountAdjustment = $this->isCountable( $text )
919 - $this->isCountable( $oldtext );
920 $now = wfTimestampNow();
921 $won = wfInvertTimestamp( $now );
922
923 # First update the cur row
924 $dbw->updateArray( 'cur',
925 array( /* SET */
926 'cur_text' => $text,
927 'cur_comment' => $summary,
928 'cur_minor_edit' => $me2,
929 'cur_user' => $wgUser->getID(),
930 'cur_timestamp' => $now,
931 'cur_user_text' => $wgUser->getName(),
932 'cur_is_redirect' => $redir,
933 'cur_is_new' => 0,
934 'cur_touched' => $now,
935 'inverse_timestamp' => $won
936 ), array( /* WHERE */
937 'cur_id' => $this->getID(),
938 'cur_timestamp' => $this->getTimestamp()
939 ), $fname
940 );
941
942 if( $dbw->affectedRows() == 0 ) {
943 /* Belated edit conflict! Run away!! */
944 $good = false;
945 } else {
946 # Now insert the previous revision into old
947
948 # This overwrites $oldtext if revision compression is on
949 $flags = Article::compressRevisionText( $oldtext );
950
951 $dbw->insertArray( 'old',
952 array(
953 'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
954 'old_namespace' => $this->mTitle->getNamespace(),
955 'old_title' => $this->mTitle->getDBkey(),
956 'old_text' => $oldtext,
957 'old_comment' => $this->getComment(),
958 'old_user' => $this->getUser(),
959 'old_user_text' => $this->getUserText(),
960 'old_timestamp' => $this->getTimestamp(),
961 'old_minor_edit' => $me1,
962 'inverse_timestamp' => wfInvertTimestamp( $this->getTimestamp() ),
963 'old_flags' => $flags,
964 ), $fname
965 );
966
967 $oldid = $dbw->insertId();
968
969 $bot = (int)($wgUser->isBot() || $forceBot);
970 RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
971 $oldid, $this->getTimestamp(), $bot );
972 Article::onArticleEdit( $this->mTitle );
973 }
974 }
975
976 if( $wgDBtransactions ) {
977 $dbw->query( 'COMMIT', $fname );
978 } else {
979 ignore_user_abort( $userAbort );
980 }
981
982 if ( $good ) {
983 if ($watchthis) {
984 if (!$this->mTitle->userIsWatching()) $this->watch();
985 } else {
986 if ( $this->mTitle->userIsWatching() ) {
987 $this->unwatch();
988 }
989 }
990 # standard deferred updates
991 $this->editUpdates( $text );
992
993
994 $urls = array();
995 # Template namespace
996 # Purge all articles linking here
997 if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
998 $titles = $this->mTitle->getLinksTo();
999 Title::touchArray( $titles );
1000 if ( $wgUseSquid ) {
1001 foreach ( $titles as $title ) {
1002 $urls[] = $title->getInternalURL();
1003 }
1004 }
1005 }
1006
1007 # Squid updates
1008 if ( $wgUseSquid ) {
1009 $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
1010 $u = new SquidUpdate( $urls );
1011 $u->doUpdate();
1012 }
1013
1014 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor );
1015 }
1016 return $good;
1017 }
1018
1019 # After we've either updated or inserted the article, update
1020 # the link tables and redirect to the new page.
1021
1022 function showArticle( $text, $subtitle , $sectionanchor = '' ) {
1023 global $wgOut, $wgUser, $wgLinkCache;
1024 global $wgMwRedir;
1025
1026 $wgLinkCache = new LinkCache();
1027 # Select for update
1028 $wgLinkCache->forUpdate( true );
1029
1030 # Get old version of link table to allow incremental link updates
1031 $wgLinkCache->preFill( $this->mTitle );
1032 $wgLinkCache->clear();
1033
1034 # Switch on use of link cache in the skin
1035 $sk =& $wgUser->getSkin();
1036 $sk->postParseLinkColour( false );
1037
1038 # Now update the link cache by parsing the text
1039 $wgOut = new OutputPage();
1040 $wgOut->addWikiText( $text );
1041
1042 if( $wgMwRedir->matchStart( $text ) )
1043 $r = 'redirect=no';
1044 else
1045 $r = '';
1046 $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
1047 }
1048
1049 # Validate article
1050
1051 function validate () {
1052 global $wgOut ;
1053 $wgOut->setPagetitle( wfMsg( 'validate' ) . ": " . $this->mTitle->getPrefixedText() );
1054 $wgOut->setRobotpolicy( 'noindex,follow' );
1055 if ( $this->mTitle->getNamespace() != 0 )
1056 {
1057 $wgOut->addHTML ( wfMsg ( 'val_validate_article_namespace_only' ) ) ;
1058 return ;
1059 }
1060 $v = new Validation ;
1061 $v->validate_form ( $this->mTitle->getDBkey() ) ;
1062 }
1063
1064 # Mark this particular edit as patrolled
1065 function markpatrolled() {
1066 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1067 $wgOut->setRobotpolicy( 'noindex,follow' );
1068
1069 if ( !$wgUseRCPatrol )
1070 {
1071 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1072 return;
1073 }
1074 if ( $wgUser->getID() == 0 )
1075 {
1076 $wgOut->loginToUse();
1077 return;
1078 }
1079 if ( $wgOnlySysopsCanPatrol && !$wgUser->isSysop() )
1080 {
1081 $wgOut->sysopRequired();
1082 return;
1083 }
1084 $rcid = $wgRequest->getVal( 'rcid' );
1085 if ( !is_null ( $rcid ) )
1086 {
1087 RecentChange::markPatrolled( $rcid );
1088 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1089 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1090 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1091 }
1092 else
1093 {
1094 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1095 }
1096 }
1097
1098
1099 # Add this page to my watchlist
1100
1101 function watch( $add = true ) {
1102 global $wgUser, $wgOut, $wgLang;
1103 global $wgDeferredUpdateList;
1104
1105 if ( 0 == $wgUser->getID() ) {
1106 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1107 return;
1108 }
1109 if ( wfReadOnly() ) {
1110 $wgOut->readOnlyPage();
1111 return;
1112 }
1113 if( $add )
1114 $wgUser->addWatch( $this->mTitle );
1115 else
1116 $wgUser->removeWatch( $this->mTitle );
1117
1118 $wgOut->setPagetitle( wfMsg( $add ? 'addedwatch' : 'removedwatch' ) );
1119 $wgOut->setRobotpolicy( 'noindex,follow' );
1120
1121 $sk = $wgUser->getSkin() ;
1122 $link = $this->mTitle->getPrefixedText();
1123
1124 if($add)
1125 $text = wfMsg( 'addedwatchtext', $link );
1126 else
1127 $text = wfMsg( 'removedwatchtext', $link );
1128 $wgOut->addWikiText( $text );
1129
1130 $up = new UserUpdate();
1131 array_push( $wgDeferredUpdateList, $up );
1132
1133 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1134 }
1135
1136 function unwatch() {
1137 $this->watch( false );
1138 }
1139
1140 # protect a page
1141
1142 function protect( $limit = 'sysop' ) {
1143 global $wgUser, $wgOut, $wgRequest;
1144
1145 if ( ! $wgUser->isSysop() ) {
1146 $wgOut->sysopRequired();
1147 return;
1148 }
1149 if ( wfReadOnly() ) {
1150 $wgOut->readOnlyPage();
1151 return;
1152 }
1153 $id = $this->mTitle->getArticleID();
1154 if ( 0 == $id ) {
1155 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1156 return;
1157 }
1158
1159 $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
1160 $reason = $wgRequest->getText( 'wpReasonProtect' );
1161
1162 if ( $confirm ) {
1163 $dbw =& wfGetDB( DB_MASTER );
1164 $dbw->updateArray( 'cur',
1165 array( /* SET */
1166 'cur_touched' => wfTimestampNow(),
1167 'cur_restrictions' => (string)$limit
1168 ), array( /* WHERE */
1169 'cur_id' => $id
1170 ), 'Article::protect'
1171 );
1172
1173 $log = new LogPage( wfMsg( 'protectlogpage' ), wfMsg( 'protectlogtext' ) );
1174 if ( $limit === "" ) {
1175 $log->addEntry( wfMsg( 'unprotectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1176 } else {
1177 $log->addEntry( wfMsg( 'protectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1178 }
1179 $wgOut->redirect( $this->mTitle->getFullURL() );
1180 return;
1181 } else {
1182 $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
1183 return $this->confirmProtect( '', $reason, $limit );
1184 }
1185 }
1186
1187 # Output protection confirmation dialog
1188
1189 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1190 global $wgOut;
1191
1192 wfDebug( "Article::confirmProtect\n" );
1193
1194 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1195 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1196
1197 $check = '';
1198 $protcom = '';
1199
1200 if ( $limit === '' ) {
1201 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1202 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1203 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1204 $check = htmlspecialchars( wfMsg( 'confirmunprotect' ) );
1205 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1206 $formaction = $this->mTitle->escapeLocalURL( 'action=unprotect' . $par );
1207 } else {
1208 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1209 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1210 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1211 $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
1212 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1213 $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
1214 }
1215
1216 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1217
1218 $wgOut->addHTML( "
1219 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1220 <table border='0'>
1221 <tr>
1222 <td align='right'>
1223 <label for='wpReasonProtect'>{$protcom}:</label>
1224 </td>
1225 <td align='left'>
1226 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1227 </td>
1228 </tr>
1229 <tr>
1230 <td>&nbsp;</td>
1231 </tr>
1232 <tr>
1233 <td align='right'>
1234 <input type='checkbox' name='wpConfirmProtect' value='1' id='wpConfirmProtect' />
1235 </td>
1236 <td>
1237 <label for='wpConfirmProtect'>{$check}</label>
1238 </td>
1239 </tr>
1240 <tr>
1241 <td>&nbsp;</td>
1242 <td>
1243 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1244 </td>
1245 </tr>
1246 </table>
1247 </form>\n" );
1248
1249 $wgOut->returnToMain( false );
1250 }
1251
1252 function unprotect() {
1253 return $this->protect( '' );
1254 }
1255
1256 # UI entry point for page deletion
1257
1258 function delete() {
1259 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1260 $fname = 'Article::delete';
1261 $confirm = $wgRequest->getBool( 'wpConfirm' ) && $wgRequest->wasPosted();
1262 $reason = $wgRequest->getText( 'wpReason' );
1263
1264 # This code desperately needs to be totally rewritten
1265
1266 # Check permissions
1267 if ( ( ! $wgUser->isSysop() ) ) {
1268 $wgOut->sysopRequired();
1269 return;
1270 }
1271 if ( wfReadOnly() ) {
1272 $wgOut->readOnlyPage();
1273 return;
1274 }
1275
1276 # Better double-check that it hasn't been deleted yet!
1277 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1278 if ( ( '' == trim( $this->mTitle->getText() ) )
1279 or ( $this->mTitle->getArticleId() == 0 ) ) {
1280 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1281 return;
1282 }
1283
1284 if ( $confirm ) {
1285 $this->doDelete( $reason );
1286 return;
1287 }
1288
1289 # determine whether this page has earlier revisions
1290 # and insert a warning if it does
1291 # we select the text because it might be useful below
1292 $dbr =& wfGetDB( DB_SLAVE );
1293 $ns = $this->mTitle->getNamespace();
1294 $title = $this->mTitle->getDBkey();
1295 $old = $dbr->getArray( 'old',
1296 array( 'old_text', 'old_flags' ),
1297 array(
1298 'old_namespace' => $ns,
1299 'old_title' => $title,
1300 ), $fname, array( 'ORDER BY' => 'inverse_timestamp' )
1301 );
1302
1303 if( $old !== false && !$confirm ) {
1304 $skin=$wgUser->getSkin();
1305 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1306 $wgOut->addHTML( $skin->historyLink() .'</b>');
1307 }
1308
1309 # Fetch cur_text
1310 $s = $dbr->getArray( 'cur',
1311 array( 'cur_text' ),
1312 array(
1313 'cur_namespace' => $ns,
1314 'cur_title' => $title,
1315 ), $fname
1316 );
1317
1318 if( $s !== false ) {
1319 # if this is a mini-text, we can paste part of it into the deletion reason
1320
1321 #if this is empty, an earlier revision may contain "useful" text
1322 $blanked = false;
1323 if($s->cur_text!="") {
1324 $text=$s->cur_text;
1325 } else {
1326 if($old) {
1327 $text = Article::getRevisionText( $old );
1328 $blanked = true;
1329 }
1330
1331 }
1332
1333 $length=strlen($text);
1334
1335 # this should not happen, since it is not possible to store an empty, new
1336 # page. Let's insert a standard text in case it does, though
1337 if($length == 0 && $reason === '') {
1338 $reason = wfMsg('exblank');
1339 }
1340
1341 if($length < 500 && $reason === '') {
1342
1343 # comment field=255, let's grep the first 150 to have some user
1344 # space left
1345 $text=substr($text,0,150);
1346 # let's strip out newlines and HTML tags
1347 $text=preg_replace('/\"/',"'",$text);
1348 $text=preg_replace('/\</','&lt;',$text);
1349 $text=preg_replace('/\>/','&gt;',$text);
1350 $text=preg_replace("/[\n\r]/",'',$text);
1351 if(!$blanked) {
1352 $reason=wfMsg('excontent'). " '".$text;
1353 } else {
1354 $reason=wfMsg('exbeforeblank') . " '".$text;
1355 }
1356 if($length>150) { $reason .= '...'; } # we've only pasted part of the text
1357 $reason.="'";
1358 }
1359 }
1360
1361 return $this->confirmDelete( '', $reason );
1362 }
1363
1364 # Output deletion confirmation dialog
1365
1366 function confirmDelete( $par, $reason ) {
1367 global $wgOut;
1368
1369 wfDebug( "Article::confirmDelete\n" );
1370
1371 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1372 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1373 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1374 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1375
1376 $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
1377
1378 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1379 $check = htmlspecialchars( wfMsg( 'confirmcheck' ) );
1380 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1381
1382 $wgOut->addHTML( "
1383 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1384 <table border='0'>
1385 <tr>
1386 <td align='right'>
1387 <label for='wpReason'>{$delcom}:</label>
1388 </td>
1389 <td align='left'>
1390 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1391 </td>
1392 </tr>
1393 <tr>
1394 <td>&nbsp;</td>
1395 </tr>
1396 <tr>
1397 <td align='right'>
1398 <input type='checkbox' name='wpConfirm' value='1' id='wpConfirm' />
1399 </td>
1400 <td>
1401 <label for='wpConfirm'>{$check}</label>
1402 </td>
1403 </tr>
1404 <tr>
1405 <td>&nbsp;</td>
1406 <td>
1407 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1408 </td>
1409 </tr>
1410 </table>
1411 </form>\n" );
1412
1413 $wgOut->returnToMain( false );
1414 }
1415
1416
1417 # Perform a deletion and output success or failure messages
1418
1419 function doDelete( $reason ) {
1420 global $wgOut, $wgUser, $wgLang;
1421 $fname = 'Article::doDelete';
1422 wfDebug( "$fname\n" );
1423
1424 if ( $this->doDeleteArticle( $reason ) ) {
1425 $deleted = $this->mTitle->getPrefixedText();
1426
1427 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1428 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1429
1430 $sk = $wgUser->getSkin();
1431 $loglink = $sk->makeKnownLink( $wgLang->getNsText( NS_WIKIPEDIA ) .
1432 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
1433
1434 $text = wfMsg( "deletedtext", $deleted, $loglink );
1435
1436 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
1437 $wgOut->returnToMain( false );
1438 } else {
1439 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1440 }
1441 }
1442
1443 # Back-end article deletion
1444 # Deletes the article with database consistency, writes logs, purges caches
1445 # Returns success
1446 function doDeleteArticle( $reason ) {
1447 global $wgUser, $wgLang;
1448 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1449
1450 $fname = 'Article::doDeleteArticle';
1451 wfDebug( $fname."\n" );
1452
1453 $dbw =& wfGetDB( DB_MASTER );
1454 $ns = $this->mTitle->getNamespace();
1455 $t = $this->mTitle->getDBkey();
1456 $id = $this->mTitle->getArticleID();
1457
1458 if ( '' == $t || $id == 0 ) {
1459 return false;
1460 }
1461
1462 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1463 array_push( $wgDeferredUpdateList, $u );
1464
1465 $linksTo = $this->mTitle->getLinksTo();
1466
1467 # Squid purging
1468 if ( $wgUseSquid ) {
1469 $urls = array(
1470 $this->mTitle->getInternalURL(),
1471 $this->mTitle->getInternalURL( 'history' )
1472 );
1473 foreach ( $linksTo as $linkTo ) {
1474 $urls[] = $linkTo->getInternalURL();
1475 }
1476
1477 $u = new SquidUpdate( $urls );
1478 array_push( $wgDeferredUpdateList, $u );
1479
1480 }
1481
1482 # Client and file cache invalidation
1483 Title::touchArray( $linksTo );
1484
1485 # Move article and history to the "archive" table
1486 $archiveTable = $dbw->tableName( 'archive' );
1487 $oldTable = $dbw->tableName( 'old' );
1488 $curTable = $dbw->tableName( 'cur' );
1489 $recentchangesTable = $dbw->tableName( 'recentchanges' );
1490 $linksTable = $dbw->tableName( 'links' );
1491 $brokenlinksTable = $dbw->tableName( 'brokenlinks' );
1492
1493 $dbw->insertSelect( 'archive', 'cur',
1494 array(
1495 'ar_namespace' => 'cur_namespace',
1496 'ar_title' => 'cur_title',
1497 'ar_text' => 'cur_text',
1498 'ar_comment' => 'cur_comment',
1499 'ar_user' => 'cur_user',
1500 'ar_user_text' => 'cur_user_text',
1501 'ar_timestamp' => 'cur_timestamp',
1502 'ar_minor_edit' => 'cur_minor_edit',
1503 'ar_flags' => 0,
1504 ), array(
1505 'cur_namespace' => $ns,
1506 'cur_title' => $t,
1507 ), $fname
1508 );
1509
1510 $dbw->insertSelect( 'archive', 'old',
1511 array(
1512 'ar_namespace' => 'old_namespace',
1513 'ar_title' => 'old_title',
1514 'ar_text' => 'old_text',
1515 'ar_comment' => 'old_comment',
1516 'ar_user' => 'old_user',
1517 'ar_user_text' => 'old_user_text',
1518 'ar_timestamp' => 'old_timestamp',
1519 'ar_minor_edit' => 'old_minor_edit',
1520 'ar_flags' => 'old_flags'
1521 ), array(
1522 'old_namespace' => $ns,
1523 'old_title' => $t,
1524 ), $fname
1525 );
1526
1527 # Now that it's safely backed up, delete it
1528
1529 $dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
1530 $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
1531 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1532
1533 # Finally, clean up the link tables
1534 $t = $this->mTitle->getPrefixedDBkey();
1535
1536 Article::onArticleDelete( $this->mTitle );
1537
1538 # Insert broken links
1539 $brokenLinks = array();
1540 foreach ( $linksTo as $titleObj ) {
1541 # Get article ID. Efficient because it was loaded into the cache by getLinksTo().
1542 $linkID = $titleObj->getArticleID();
1543 $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
1544 }
1545 $dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' );
1546
1547 # Delete live links
1548 $dbw->delete( 'links', array( 'l_to' => $id ) );
1549 $dbw->delete( 'links', array( 'l_from' => $id ) );
1550 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1551 $dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) );
1552 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1553
1554 # Log the deletion
1555 $log = new LogPage( wfMsg( 'dellogpage' ), wfMsg( 'dellogpagetext' ) );
1556 $art = $this->mTitle->getPrefixedText();
1557 $log->addEntry( wfMsg( 'deletedarticle', $art ), $reason );
1558
1559 # Clear the cached article id so the interface doesn't act like we exist
1560 $this->mTitle->resetArticleID( 0 );
1561 $this->mTitle->mArticleID = 0;
1562 return true;
1563 }
1564
1565 function rollback() {
1566 global $wgUser, $wgLang, $wgOut, $wgRequest;
1567 $fname = "Article::rollback";
1568
1569 if ( ! $wgUser->isSysop() ) {
1570 $wgOut->sysopRequired();
1571 return;
1572 }
1573 if ( wfReadOnly() ) {
1574 $wgOut->readOnlyPage( $this->getContent( true ) );
1575 return;
1576 }
1577 $dbw =& wfGetDB( DB_MASTER );
1578
1579 # Enhanced rollback, marks edits rc_bot=1
1580 $bot = $wgRequest->getBool( 'bot' );
1581
1582 # Replace all this user's current edits with the next one down
1583 $tt = $this->mTitle->getDBKey();
1584 $n = $this->mTitle->getNamespace();
1585
1586 # Get the last editor, lock table exclusively
1587 $s = $dbw->getArray( 'cur',
1588 array( 'cur_id','cur_user','cur_user_text','cur_comment' ),
1589 array( 'cur_title' => $tt, 'cur_namespace' => $n ),
1590 $fname, 'FOR UPDATE'
1591 );
1592 if( $s === false ) {
1593 # Something wrong
1594 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1595 return;
1596 }
1597 $ut = $dbw->strencode( $s->cur_user_text );
1598 $uid = $s->cur_user;
1599 $pid = $s->cur_id;
1600
1601 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1602 if( $from != $s->cur_user_text ) {
1603 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1604 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1605 htmlspecialchars( $this->mTitle->getPrefixedText()),
1606 htmlspecialchars( $from ),
1607 htmlspecialchars( $s->cur_user_text ) ) );
1608 if($s->cur_comment != '') {
1609 $wgOut->addHTML(
1610 wfMsg('editcomment',
1611 htmlspecialchars( $s->cur_comment ) ) );
1612 }
1613 return;
1614 }
1615
1616 # Get the last edit not by this guy
1617 $s = $dbw->getArray( 'old',
1618 array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
1619 array(
1620 'old_namespace' => $n,
1621 'old_title' => $tt,
1622 "old_user <> {$uid} OR old_user_text <> '{$ut}'"
1623 ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
1624 );
1625 if( $s === false ) {
1626 # Something wrong
1627 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
1628 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
1629 return;
1630 }
1631
1632 if ( $bot ) {
1633 # Mark all reverted edits as bot
1634 $dbw->updateArray( 'recentchanges',
1635 array( /* SET */
1636 'rc_bot' => 1
1637 ), array( /* WHERE */
1638 'rc_user' => $uid,
1639 "rc_timestamp > '{$s->old_timestamp}'",
1640 ), $fname
1641 );
1642 }
1643
1644 # Save it!
1645 $newcomment = wfMsg( 'revertpage', $s->old_user_text, $from );
1646 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1647 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1648 $wgOut->addHTML( '<h2>' . $newcomment . "</h2>\n<hr />\n" );
1649 $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
1650 Article::onArticleEdit( $this->mTitle );
1651 $wgOut->returnToMain( false );
1652 }
1653
1654
1655 # Do standard deferred updates after page view
1656
1657 /* private */ function viewUpdates() {
1658 global $wgDeferredUpdateList;
1659 if ( 0 != $this->getID() ) {
1660 global $wgDisableCounters;
1661 if( !$wgDisableCounters ) {
1662 Article::incViewCount( $this->getID() );
1663 $u = new SiteStatsUpdate( 1, 0, 0 );
1664 array_push( $wgDeferredUpdateList, $u );
1665 }
1666 }
1667 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1668 $this->mTitle->getDBkey() );
1669 array_push( $wgDeferredUpdateList, $u );
1670 }
1671
1672 # Do standard deferred updates after page edit.
1673 # Every 1000th edit, prune the recent changes table.
1674
1675 /* private */ function editUpdates( $text ) {
1676 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1677 global $wgMessageCache;
1678
1679 wfSeedRandom();
1680 if ( 0 == mt_rand( 0, 999 ) ) {
1681 $dbw =& wfGetDB( DB_MASTER );
1682 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1683 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1684 $dbw->query( $sql );
1685 }
1686 $id = $this->getID();
1687 $title = $this->mTitle->getPrefixedDBkey();
1688 $shortTitle = $this->mTitle->getDBkey();
1689
1690 $adj = $this->mCountAdjustment;
1691
1692 if ( 0 != $id ) {
1693 $u = new LinksUpdate( $id, $title );
1694 array_push( $wgDeferredUpdateList, $u );
1695 $u = new SiteStatsUpdate( 0, 1, $adj );
1696 array_push( $wgDeferredUpdateList, $u );
1697 $u = new SearchUpdate( $id, $title, $text );
1698 array_push( $wgDeferredUpdateList, $u );
1699
1700 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
1701 array_push( $wgDeferredUpdateList, $u );
1702
1703 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1704 $wgMessageCache->replace( $shortTitle, $text );
1705 }
1706 }
1707 }
1708
1709 /* private */ function setOldSubtitle() {
1710 global $wgLang, $wgOut;
1711
1712 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1713 $r = wfMsg( 'revisionasof', $td );
1714 $wgOut->setSubtitle( "({$r})" );
1715 }
1716
1717 # This function is called right before saving the wikitext,
1718 # so we can do things like signatures and links-in-context.
1719
1720 function preSaveTransform( $text ) {
1721 global $wgParser, $wgUser;
1722 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
1723 }
1724
1725 /* Caching functions */
1726
1727 # checkLastModified returns true if it has taken care of all
1728 # output to the client that is necessary for this request.
1729 # (that is, it has sent a cached version of the page)
1730 function tryFileCache() {
1731 static $called = false;
1732 if( $called ) {
1733 wfDebug( " tryFileCache() -- called twice!?\n" );
1734 return;
1735 }
1736 $called = true;
1737 if($this->isFileCacheable()) {
1738 $touched = $this->mTouched;
1739 if( $this->mTitle->getPrefixedDBkey() == wfMsg( 'mainpage' ) ) {
1740 # Expire the main page quicker
1741 $expire = wfUnix2Timestamp( time() - 3600 );
1742 $touched = max( $expire, $touched );
1743 }
1744 $cache = new CacheManager( $this->mTitle );
1745 if($cache->isFileCacheGood( $touched )) {
1746 global $wgOut;
1747 wfDebug( " tryFileCache() - about to load\n" );
1748 $cache->loadFromFileCache();
1749 return true;
1750 } else {
1751 wfDebug( " tryFileCache() - starting buffer\n" );
1752 ob_start( array(&$cache, 'saveToFileCache' ) );
1753 }
1754 } else {
1755 wfDebug( " tryFileCache() - not cacheable\n" );
1756 }
1757 }
1758
1759 function isFileCacheable() {
1760 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
1761 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
1762
1763 return $wgUseFileCache
1764 and (!$wgShowIPinHeader)
1765 and ($this->getID() != 0)
1766 and ($wgUser->getId() == 0)
1767 and (!$wgUser->getNewtalk())
1768 and ($this->mTitle->getNamespace() != NS_SPECIAL )
1769 and (empty( $action ) || $action == 'view')
1770 and (!isset($oldid))
1771 and (!isset($diff))
1772 and (!isset($redirect))
1773 and (!isset($printable))
1774 and (!$this->mRedirectedFrom);
1775 }
1776
1777 # Loads cur_touched and returns a value indicating if it should be used
1778 function checkTouched() {
1779 $fname = 'Article::checkTouched';
1780
1781 $id = $this->getID();
1782 $dbr =& wfGetDB( DB_SLAVE );
1783 $s = $dbr->getArray( 'cur', array( 'cur_touched', 'cur_is_redirect' ),
1784 array( 'cur_id' => $id ), $fname );
1785 if( $s !== false ) {
1786 $this->mTouched = $s->cur_touched;
1787 return !$s->cur_is_redirect;
1788 } else {
1789 return false;
1790 }
1791 }
1792
1793 # Edit an article without doing all that other stuff
1794 function quickEdit( $text, $comment = '', $minor = 0 ) {
1795 global $wgUser, $wgMwRedir;
1796 $fname = 'Article::quickEdit';
1797 wfProfileIn( $fname );
1798
1799 $dbw =& wfGetDB( DB_MASTER );
1800 $ns = $this->mTitle->getNamespace();
1801 $dbkey = $this->mTitle->getDBkey();
1802 $encDbKey = $dbw->strencode( $dbkey );
1803 $timestamp = wfTimestampNow();
1804
1805 # Save to history
1806 $dbw->insertSelect( 'old', 'cur',
1807 array(
1808 'old_namespace' => 'cur_namespace',
1809 'old_title' => 'cur_title',
1810 'old_text' => 'cur_text',
1811 'old_comment' => 'cur_comment',
1812 'old_user' => 'cur_user',
1813 'old_user_text' => 'cur_user_text',
1814 'old_timestamp' => 'cur_timestamp',
1815 'inverse_timestamp' => '99999999999999-cur_timestamp',
1816 ), array(
1817 'cur_namespace' => $ns,
1818 'cur_title' => $dbkey,
1819 ), $fname
1820 );
1821
1822 # Use the affected row count to determine if the article is new
1823 $numRows = $dbw->affectedRows();
1824
1825 # Make an array of fields to be inserted
1826 $fields = array(
1827 'cur_text' => $text,
1828 'cur_timestamp' => $timestamp,
1829 'cur_user' => $wgUser->getID(),
1830 'cur_user_text' => $wgUser->getName(),
1831 'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
1832 'cur_comment' => $comment,
1833 'cur_is_redirect' => $wgMwRedir->matchStart( $text ) ? 1 : 0,
1834 'cur_minor_edit' => intval($minor),
1835 'cur_touched' => $timestamp,
1836 );
1837
1838 if ( $numRows ) {
1839 # Update article
1840 $fields['cur_is_new'] = 0;
1841 $dbw->updateArray( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname );
1842 } else {
1843 # Insert new article
1844 $fields['cur_is_new'] = 1;
1845 $fields['cur_namespace'] = $ns;
1846 $fields['cur_title'] = $dbkey;
1847 $fields['cur_random'] = $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
1848 $dbw->insertArray( 'cur', $fields, $fname );
1849 }
1850 wfProfileOut( $fname );
1851 }
1852
1853 /* static */ function incViewCount( $id ) {
1854 $id = intval( $id );
1855 global $wgHitcounterUpdateFreq;
1856
1857 $dbw =& wfGetDB( DB_MASTER );
1858 $curTable = $dbw->tableName( 'cur' );
1859 $hitcounterTable = $dbw->tableName( 'hitcounter' );
1860 $acchitsTable = $dbw->tableName( 'acchits' );
1861
1862 if( $wgHitcounterUpdateFreq <= 1 ){ //
1863 $dbw->query( "UPDATE $curTable SET cur_counter = cur_counter + 1 WHERE cur_id = $id" );
1864 return;
1865 }
1866
1867 # Not important enough to warrant an error page in case of failure
1868 $oldignore = $dbw->ignoreErrors( true );
1869
1870 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
1871
1872 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
1873 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
1874 # Most of the time (or on SQL errors), skip row count check
1875 $dbw->ignoreErrors( $oldignore );
1876 return;
1877 }
1878
1879 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
1880 $row = $dbw->fetchObject( $res );
1881 $rown = intval( $row->n );
1882 if( $rown >= $wgHitcounterUpdateFreq ){
1883 wfProfileIn( 'Article::incViewCount-collect' );
1884 $old_user_abort = ignore_user_abort( true );
1885
1886 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
1887 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
1888 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
1889 'GROUP BY hc_id');
1890 $dbw->query("DELETE FROM $hitcounterTable");
1891 $dbw->query('UNLOCK TABLES');
1892 $dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ".
1893 'WHERE cur_id = hc_id');
1894 $dbw->query("DROP TABLE $acchitsTable");
1895
1896 ignore_user_abort( $old_user_abort );
1897 wfProfileOut( 'Article::incViewCount-collect' );
1898 }
1899 $dbw->ignoreErrors( $oldignore );
1900 }
1901
1902 # The onArticle*() functions are supposed to be a kind of hooks
1903 # which should be called whenever any of the specified actions
1904 # are done.
1905 #
1906 # This is a good place to put code to clear caches, for instance.
1907
1908 # This is called on page move and undelete, as well as edit
1909 /* static */ function onArticleCreate($title_obj) {
1910 global $wgUseSquid, $wgDeferredUpdateList;
1911
1912 $titles = $title_obj->getBrokenLinksTo();
1913
1914 # Purge squid
1915 if ( $wgUseSquid ) {
1916 $urls = $title_obj->getSquidURLs();
1917 foreach ( $titles as $linkTitle ) {
1918 $urls[] = $linkTitle->getInternalURL();
1919 }
1920 $u = new SquidUpdate( $urls );
1921 array_push( $wgDeferredUpdateList, $u );
1922 }
1923
1924 # Clear persistent link cache
1925 LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
1926 }
1927
1928 /* static */ function onArticleDelete($title_obj) {
1929 LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
1930 }
1931
1932 /* static */ function onArticleEdit($title_obj) {
1933 LinkCache::linksccClearPage( $title_obj->getArticleID() );
1934 }
1935
1936
1937 # Info about this page
1938
1939 function info() {
1940 global $wgUser, $wgTitle, $wgOut, $wgLang, $wgAllowPageInfo;
1941 $fname = 'Article::info';
1942
1943 if ( !$wgAllowPageInfo ) {
1944 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
1945 return;
1946 }
1947
1948 $dbr =& wfGetDB( DB_SLAVE );
1949
1950 $basenamespace = $wgTitle->getNamespace() & (~1);
1951 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
1952 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
1953 $wl_clause = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
1954 $fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
1955 $wgOut->setPagetitle( $fullTitle );
1956 $wgOut->setSubtitle( wfMsg( "infosubtitle" ));
1957
1958 # first, see if the page exists at all.
1959 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1960 if ($exists < 1) {
1961 $wgOut->addHTML( wfMsg("noarticletext") );
1962 } else {
1963 $numwatchers = $dbr->selectField( 'watchlist', 'COUNT(*)', $wl_clause, $fname );
1964 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $numwatchers) . "</li>" );
1965 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1966 $wgOut->addHTML( "<li>" . wfMsg("numedits", $old + 1) . "</li>");
1967
1968 # to find number of distinct authors, we need to do some
1969 # funny stuff because of the cur/old table split:
1970 # - first, find the name of the 'cur' author
1971 # - then, find the number of *other* authors in 'old'
1972
1973 # find 'cur' author
1974 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
1975
1976 # find number of 'old' authors excluding 'cur' author
1977 $authors = $dbr->selectField( 'old', 'COUNT(DISTINCT old_user_text)',
1978 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname ) + 1;
1979
1980 # now for the Talk page ...
1981 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+1 );
1982 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+1 );
1983
1984 # does it exist?
1985 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1986
1987 # number of edits
1988 if ($exists > 0) {
1989 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1990 $wgOut->addHTML( "<li>" . wfMsg("numtalkedits", $old + 1) . "</li>");
1991 }
1992 $wgOut->addHTML( "<li>" . wfMsg("numauthors", $authors) . "</li>" );
1993
1994 # number of authors
1995 if ($exists > 0) {
1996 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
1997 $authors = $dbr->selectField( 'cur', 'COUNT(DISTINCT old_user_text)',
1998 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname );
1999
2000 $wgOut->addHTML( "<li>" . wfMsg("numtalkauthors", $authors) . "</li></ul>" );
2001 }
2002 }
2003 }
2004 }
2005
2006 ?>