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