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