New global config setting $wgMaxTocLevel: Maximum indent level of toc.
[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_SLAVE );
147 } else {
148 # Alternate connection
149 $db =& $wgLoadBalancer->getConnection( $machineID );
150
151 if ( array_key_exists( $machineId, $wgKnownMysqlServers ) ) {
152 # Try to open, return false on failure
153 $params = $wgKnownDBServers[$machineId];
154 $db = Database::newFromParams( $params['server'], $params['user'], $params['password'],
155 $dbName, 1, 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_SLAVE );
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_SLAVE );
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_SLAVE );
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_SLAVE );
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_SLAVE );
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_MASTER );
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_MASTER );
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 # Select for update
1033 $wgLinkCache->forUpdate( true );
1034
1035 # Get old version of link table to allow incremental link updates
1036 $wgLinkCache->preFill( $this->mTitle );
1037 $wgLinkCache->clear();
1038
1039 # Now update the link cache by parsing the text
1040 $wgOut = new OutputPage();
1041 $wgOut->addWikiText( $text );
1042
1043 if( $wgMwRedir->matchStart( $text ) )
1044 $r = 'redirect=no';
1045 else
1046 $r = '';
1047 $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
1048 }
1049
1050 # Add this page to my watchlist
1051
1052 function watch( $add = true )
1053 {
1054 global $wgUser, $wgOut, $wgLang;
1055 global $wgDeferredUpdateList;
1056
1057 if ( 0 == $wgUser->getID() ) {
1058 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1059 return;
1060 }
1061 if ( wfReadOnly() ) {
1062 $wgOut->readOnlyPage();
1063 return;
1064 }
1065 if( $add )
1066 $wgUser->addWatch( $this->mTitle );
1067 else
1068 $wgUser->removeWatch( $this->mTitle );
1069
1070 $wgOut->setPagetitle( wfMsg( $add ? 'addedwatch' : 'removedwatch' ) );
1071 $wgOut->setRobotpolicy( 'noindex,follow' );
1072
1073 $sk = $wgUser->getSkin() ;
1074 $link = $this->mTitle->getPrefixedText();
1075
1076 if($add)
1077 $text = wfMsg( 'addedwatchtext', $link );
1078 else
1079 $text = wfMsg( 'removedwatchtext', $link );
1080 $wgOut->addWikiText( $text );
1081
1082 $up = new UserUpdate();
1083 array_push( $wgDeferredUpdateList, $up );
1084
1085 $wgOut->returnToMain( false );
1086 }
1087
1088 function unwatch()
1089 {
1090 $this->watch( false );
1091 }
1092
1093 function protect( $limit = 'sysop' )
1094 {
1095 global $wgUser, $wgOut, $wgRequest;
1096
1097 if ( ! $wgUser->isSysop() ) {
1098 $wgOut->sysopRequired();
1099 return;
1100 }
1101 if ( wfReadOnly() ) {
1102 $wgOut->readOnlyPage();
1103 return;
1104 }
1105 $id = $this->mTitle->getArticleID();
1106 if ( 0 == $id ) {
1107 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1108 return;
1109 }
1110
1111 $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
1112 $reason = $wgRequest->getText( 'wpReasonProtect' );
1113
1114 if ( $confirm ) {
1115 $dbw =& wfGetDB( DB_MASTER );
1116 $dbw->updateArray( 'cur',
1117 array( /* SET */
1118 'cur_touched' => wfTimestampNow(),
1119 'cur_restrictions' => (string)$limit
1120 ), array( /* WHERE */
1121 'cur_id' => $id
1122 ), 'Article::protect'
1123 );
1124
1125 $log = new LogPage( wfMsg( 'protectlogpage' ), wfMsg( 'protectlogtext' ) );
1126 if ( $limit === "" ) {
1127 $log->addEntry( wfMsg( 'unprotectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1128 } else {
1129 $log->addEntry( wfMsg( 'protectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1130 }
1131 $wgOut->redirect( $this->mTitle->getFullURL() );
1132 return;
1133 } else {
1134 $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
1135 return $this->confirmProtect( '', $reason, $limit );
1136 }
1137 }
1138
1139 # Output protection confirmation dialog
1140 function confirmProtect( $par, $reason, $limit = 'sysop' )
1141 {
1142 global $wgOut;
1143
1144 wfDebug( "Article::confirmProtect\n" );
1145
1146 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1147 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1148
1149 $check = '';
1150 $protcom = '';
1151
1152 if ( $limit === '' ) {
1153 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1154 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1155 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1156 $check = htmlspecialchars( wfMsg( 'confirmunprotect' ) );
1157 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1158 $formaction = $this->mTitle->escapeLocalURL( 'action=unprotect' . $par );
1159 } else {
1160 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1161 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1162 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1163 $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
1164 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1165 $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
1166 }
1167
1168 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1169
1170 $wgOut->addHTML( "
1171 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1172 <table border='0'>
1173 <tr>
1174 <td align='right'>
1175 <label for='wpReasonProtect'>{$protcom}:</label>
1176 </td>
1177 <td align='left'>
1178 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1179 </td>
1180 </tr>
1181 <tr>
1182 <td>&nbsp;</td>
1183 </tr>
1184 <tr>
1185 <td align='right'>
1186 <input type='checkbox' name='wpConfirmProtect' value='1' id='wpConfirmProtect' />
1187 </td>
1188 <td>
1189 <label for='wpConfirmProtect'>{$check}</label>
1190 </td>
1191 </tr>
1192 <tr>
1193 <td>&nbsp;</td>
1194 <td>
1195 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1196 </td>
1197 </tr>
1198 </table>
1199 </form>\n" );
1200
1201 $wgOut->returnToMain( false );
1202 }
1203
1204 function unprotect()
1205 {
1206 return $this->protect( '' );
1207 }
1208
1209 # UI entry point for page deletion
1210 function delete()
1211 {
1212 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1213 $fname = 'Article::delete';
1214 $confirm = $wgRequest->getBool( 'wpConfirm' ) && $wgRequest->wasPosted();
1215 $reason = $wgRequest->getText( 'wpReason' );
1216
1217 # This code desperately needs to be totally rewritten
1218
1219 # Check permissions
1220 if ( ( ! $wgUser->isSysop() ) ) {
1221 $wgOut->sysopRequired();
1222 return;
1223 }
1224 if ( wfReadOnly() ) {
1225 $wgOut->readOnlyPage();
1226 return;
1227 }
1228
1229 # Better double-check that it hasn't been deleted yet!
1230 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1231 if ( ( '' == trim( $this->mTitle->getText() ) )
1232 or ( $this->mTitle->getArticleId() == 0 ) ) {
1233 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1234 return;
1235 }
1236
1237 if ( $confirm ) {
1238 $this->doDelete( $reason );
1239 return;
1240 }
1241
1242 # determine whether this page has earlier revisions
1243 # and insert a warning if it does
1244 # we select the text because it might be useful below
1245 $dbr =& wfGetDB( DB_SLAVE );
1246 $ns = $this->mTitle->getNamespace();
1247 $title = $this->mTitle->getDBkey();
1248 $old = $dbr->getArray( 'old',
1249 array( 'old_text', 'old_flags' ),
1250 array(
1251 'old_namespace' => $ns,
1252 'old_title' => $title,
1253 ), $fname, array( 'ORDER BY' => 'inverse_timestamp' )
1254 );
1255
1256 if( $old !== false && !$confirm ) {
1257 $skin=$wgUser->getSkin();
1258 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1259 $wgOut->addHTML( $skin->historyLink() .'</b>');
1260 }
1261
1262 # Fetch cur_text
1263 $s = $dbr->getArray( 'cur',
1264 array( 'cur_text' ),
1265 array(
1266 'cur_namespace' => $ns,
1267 'cur_title' => $title,
1268 ), $fname
1269 );
1270
1271 if( $s !== false ) {
1272 # if this is a mini-text, we can paste part of it into the deletion reason
1273
1274 #if this is empty, an earlier revision may contain "useful" text
1275 $blanked = false;
1276 if($s->cur_text!="") {
1277 $text=$s->cur_text;
1278 } else {
1279 if($old) {
1280 $text = Article::getRevisionText( $old );
1281 $blanked = true;
1282 }
1283
1284 }
1285
1286 $length=strlen($text);
1287
1288 # this should not happen, since it is not possible to store an empty, new
1289 # page. Let's insert a standard text in case it does, though
1290 if($length == 0 && $reason === '') {
1291 $reason = wfMsg('exblank');
1292 }
1293
1294 if($length < 500 && $reason === '') {
1295
1296 # comment field=255, let's grep the first 150 to have some user
1297 # space left
1298 $text=substr($text,0,150);
1299 # let's strip out newlines and HTML tags
1300 $text=preg_replace('/\"/',"'",$text);
1301 $text=preg_replace('/\</','&lt;',$text);
1302 $text=preg_replace('/\>/','&gt;',$text);
1303 $text=preg_replace("/[\n\r]/",'',$text);
1304 if(!$blanked) {
1305 $reason=wfMsg('excontent'). " '".$text;
1306 } else {
1307 $reason=wfMsg('exbeforeblank') . " '".$text;
1308 }
1309 if($length>150) { $reason .= '...'; } # we've only pasted part of the text
1310 $reason.="'";
1311 }
1312 }
1313
1314 return $this->confirmDelete( '', $reason );
1315 }
1316
1317 # Output deletion confirmation dialog
1318 function confirmDelete( $par, $reason )
1319 {
1320 global $wgOut;
1321
1322 wfDebug( "Article::confirmDelete\n" );
1323
1324 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1325 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1326 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1327 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1328
1329 $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
1330
1331 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1332 $check = htmlspecialchars( wfMsg( 'confirmcheck' ) );
1333 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1334
1335 $wgOut->addHTML( "
1336 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1337 <table border='0'>
1338 <tr>
1339 <td align='right'>
1340 <label for='wpReason'>{$delcom}:</label>
1341 </td>
1342 <td align='left'>
1343 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1344 </td>
1345 </tr>
1346 <tr>
1347 <td>&nbsp;</td>
1348 </tr>
1349 <tr>
1350 <td align='right'>
1351 <input type='checkbox' name='wpConfirm' value='1' id='wpConfirm' />
1352 </td>
1353 <td>
1354 <label for='wpConfirm'>{$check}</label>
1355 </td>
1356 </tr>
1357 <tr>
1358 <td>&nbsp;</td>
1359 <td>
1360 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1361 </td>
1362 </tr>
1363 </table>
1364 </form>\n" );
1365
1366 $wgOut->returnToMain( false );
1367 }
1368
1369 # Perform a deletion and output success or failure messages
1370 function doDelete( $reason )
1371 {
1372 global $wgOut, $wgUser, $wgLang;
1373 $fname = 'Article::doDelete';
1374 wfDebug( "$fname\n" );
1375
1376 if ( $this->doDeleteArticle( $reason ) ) {
1377 $deleted = $this->mTitle->getPrefixedText();
1378
1379 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1380 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1381
1382 $sk = $wgUser->getSkin();
1383 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
1384 Namespace::getWikipedia() ) .
1385 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
1386
1387 $text = wfMsg( "deletedtext", $deleted, $loglink );
1388
1389 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
1390 $wgOut->returnToMain( false );
1391 } else {
1392 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1393 }
1394 }
1395
1396 # Back-end article deletion
1397 # Deletes the article with database consistency, writes logs, purges caches
1398 # Returns success
1399 function doDeleteArticle( $reason )
1400 {
1401 global $wgUser, $wgLang;
1402 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1403
1404 $fname = 'Article::doDeleteArticle';
1405 wfDebug( $fname."\n" );
1406
1407 $dbw =& wfGetDB( DB_MASTER );
1408 $ns = $this->mTitle->getNamespace();
1409 $t = $this->mTitle->getDBkey();
1410 $id = $this->mTitle->getArticleID();
1411
1412 if ( '' == $t || $id == 0 ) {
1413 return false;
1414 }
1415
1416 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1417 array_push( $wgDeferredUpdateList, $u );
1418
1419 $linksTo = $this->mTitle->getLinksTo();
1420
1421 # Squid purging
1422 if ( $wgUseSquid ) {
1423 $urls = array(
1424 $this->mTitle->getInternalURL(),
1425 $this->mTitle->getInternalURL( 'history' )
1426 );
1427 foreach ( $linksTo as $linkTo ) {
1428 $urls[] = $linkTo->getInternalURL();
1429 }
1430
1431 $u = new SquidUpdate( $urls );
1432 array_push( $wgDeferredUpdateList, $u );
1433
1434 }
1435
1436 # Client and file cache invalidation
1437 Title::touchArray( $linksTo );
1438
1439 # Move article and history to the "archive" table
1440 $archiveTable = $dbw->tableName( 'archive' );
1441 $oldTable = $dbw->tableName( 'old' );
1442 $curTable = $dbw->tableName( 'cur' );
1443 $recentchangesTable = $dbw->tableName( 'recentchanges' );
1444 $linksTable = $dbw->tableName( 'links' );
1445 $brokenlinksTable = $dbw->tableName( 'brokenlinks' );
1446
1447 $dbw->insertSelect( 'archive', 'cur',
1448 array(
1449 'ar_namespace' => 'cur_namespace',
1450 'ar_title' => 'cur_title',
1451 'ar_text' => 'cur_text',
1452 'ar_comment' => 'cur_comment',
1453 'ar_user' => 'cur_user',
1454 'ar_user_text' => 'cur_user_text',
1455 'ar_timestamp' => 'cur_timestamp',
1456 'ar_minor_edit' => 'cur_minor_edit',
1457 'ar_flags' => 0,
1458 ), array(
1459 'cur_namespace' => $ns,
1460 'cur_title' => $t,
1461 ), $fname
1462 );
1463
1464 $dbw->insertSelect( 'archive', 'old',
1465 array(
1466 'ar_namespace' => 'old_namespace',
1467 'ar_title' => 'old_title',
1468 'ar_text' => 'old_text',
1469 'ar_comment' => 'old_comment',
1470 'ar_user' => 'old_user',
1471 'ar_user_text' => 'old_user_text',
1472 'ar_timestamp' => 'old_timestamp',
1473 'ar_minor_edit' => 'old_minor_edit',
1474 'ar_flags' => 'old_flags'
1475 ), array(
1476 'old_namespace' => $ns,
1477 'old_title' => $t,
1478 ), $fname
1479 );
1480
1481 # Now that it's safely backed up, delete it
1482
1483 $dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
1484 $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
1485 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1486
1487 # Finally, clean up the link tables
1488 $t = $this->mTitle->getPrefixedDBkey();
1489
1490 Article::onArticleDelete( $this->mTitle );
1491
1492 # Insert broken links
1493 $brokenLinks = array();
1494 foreach ( $linksTo as $titleObj ) {
1495 # Get article ID. Efficient because it was loaded into the cache by getLinksTo().
1496 $linkID = $titleObj->getArticleID();
1497 $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
1498 }
1499 $dbw->insertArray( 'brokenlinks', $brokenLinks, $fname );
1500
1501 # Delete live links
1502 $dbw->delete( 'links', array( 'l_to' => $id ) );
1503 $dbw->delete( 'links', array( 'l_from' => $id ) );
1504 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1505 $dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) );
1506 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1507
1508 # Log the deletion
1509 $log = new LogPage( wfMsg( 'dellogpage' ), wfMsg( 'dellogpagetext' ) );
1510 $art = $this->mTitle->getPrefixedText();
1511 $log->addEntry( wfMsg( 'deletedarticle', $art ), $reason );
1512
1513 # Clear the cached article id so the interface doesn't act like we exist
1514 $this->mTitle->resetArticleID( 0 );
1515 $this->mTitle->mArticleID = 0;
1516 return true;
1517 }
1518
1519 function rollback()
1520 {
1521 global $wgUser, $wgLang, $wgOut, $wgRequest;
1522 $fname = "Article::rollback";
1523
1524 if ( ! $wgUser->isSysop() ) {
1525 $wgOut->sysopRequired();
1526 return;
1527 }
1528 if ( wfReadOnly() ) {
1529 $wgOut->readOnlyPage( $this->getContent( true ) );
1530 return;
1531 }
1532 $dbw =& wfGetDB( DB_MASTER );
1533
1534 # Enhanced rollback, marks edits rc_bot=1
1535 $bot = $wgRequest->getBool( 'bot' );
1536
1537 # Replace all this user's current edits with the next one down
1538 $tt = $this->mTitle->getDBKey();
1539 $n = $this->mTitle->getNamespace();
1540
1541 # Get the last editor, lock table exclusively
1542 $s = $dbw->getArray( 'cur',
1543 array( 'cur_id','cur_user','cur_user_text','cur_comment' ),
1544 array( 'cur_title' => $tt, 'cur_namespace' => $n ),
1545 $fname, 'FOR UPDATE'
1546 );
1547 if( $s === false ) {
1548 # Something wrong
1549 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1550 return;
1551 }
1552 $ut = $dbw->strencode( $s->cur_user_text );
1553 $uid = $s->cur_user;
1554 $pid = $s->cur_id;
1555
1556 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1557 if( $from != $s->cur_user_text ) {
1558 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1559 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1560 htmlspecialchars( $this->mTitle->getPrefixedText()),
1561 htmlspecialchars( $from ),
1562 htmlspecialchars( $s->cur_user_text ) ) );
1563 if($s->cur_comment != '') {
1564 $wgOut->addHTML(
1565 wfMsg('editcomment',
1566 htmlspecialchars( $s->cur_comment ) ) );
1567 }
1568 return;
1569 }
1570
1571 # Get the last edit not by this guy
1572 $s = $dbw->getArray( 'old',
1573 array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
1574 array(
1575 'old_namespace' => $n,
1576 'old_title' => $tt,
1577 "old_user <> {$uid} OR old_user_text <> '{$ut}'"
1578 ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
1579 );
1580 if( $s === false ) {
1581 # Something wrong
1582 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
1583 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
1584 return;
1585 }
1586
1587 if ( $bot ) {
1588 # Mark all reverted edits as bot
1589 $dbw->updateArray( 'recentchanges',
1590 array( /* SET */
1591 'rc_bot' => 1
1592 ), array( /* WHERE */
1593 'rc_user' => $uid,
1594 "rc_timestamp > '{$s->old_timestamp}'",
1595 ), $fname
1596 );
1597 }
1598
1599 # Save it!
1600 $newcomment = wfMsg( 'revertpage', $s->old_user_text, $from );
1601 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1602 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1603 $wgOut->addHTML( '<h2>' . $newcomment . "</h2>\n<hr />\n" );
1604 $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
1605 Article::onArticleEdit( $this->mTitle );
1606 $wgOut->returnToMain( false );
1607 }
1608
1609
1610 # Do standard deferred updates after page view
1611
1612 /* private */ function viewUpdates()
1613 {
1614 global $wgDeferredUpdateList;
1615 if ( 0 != $this->getID() ) {
1616 global $wgDisableCounters;
1617 if( !$wgDisableCounters ) {
1618 Article::incViewCount( $this->getID() );
1619 $u = new SiteStatsUpdate( 1, 0, 0 );
1620 array_push( $wgDeferredUpdateList, $u );
1621 }
1622 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1623 $this->mTitle->getDBkey() );
1624 array_push( $wgDeferredUpdateList, $u );
1625 }
1626 }
1627
1628 # Do standard deferred updates after page edit.
1629 # Every 1000th edit, prune the recent changes table.
1630
1631 /* private */ function editUpdates( $text )
1632 {
1633 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1634 global $wgMessageCache;
1635
1636 wfSeedRandom();
1637 if ( 0 == mt_rand( 0, 999 ) ) {
1638 $dbw =& wfGetDB( DB_MASTER );
1639 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1640 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1641 $dbw->query( $sql );
1642 }
1643 $id = $this->getID();
1644 $title = $this->mTitle->getPrefixedDBkey();
1645 $shortTitle = $this->mTitle->getDBkey();
1646
1647 $adj = $this->mCountAdjustment;
1648
1649 if ( 0 != $id ) {
1650 $u = new LinksUpdate( $id, $title );
1651 array_push( $wgDeferredUpdateList, $u );
1652 $u = new SiteStatsUpdate( 0, 1, $adj );
1653 array_push( $wgDeferredUpdateList, $u );
1654 $u = new SearchUpdate( $id, $title, $text );
1655 array_push( $wgDeferredUpdateList, $u );
1656
1657 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
1658 array_push( $wgDeferredUpdateList, $u );
1659
1660 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1661 $wgMessageCache->replace( $shortTitle, $text );
1662 }
1663 }
1664 }
1665
1666 /* private */ function setOldSubtitle()
1667 {
1668 global $wgLang, $wgOut;
1669
1670 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1671 $r = wfMsg( 'revisionasof', $td );
1672 $wgOut->setSubtitle( "({$r})" );
1673 }
1674
1675 # This function is called right before saving the wikitext,
1676 # so we can do things like signatures and links-in-context.
1677
1678 function preSaveTransform( $text )
1679 {
1680 global $wgParser, $wgUser;
1681 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
1682 }
1683
1684 /* Caching functions */
1685
1686 # checkLastModified returns true if it has taken care of all
1687 # output to the client that is necessary for this request.
1688 # (that is, it has sent a cached version of the page)
1689 function tryFileCache() {
1690 static $called = false;
1691 if( $called ) {
1692 wfDebug( " tryFileCache() -- called twice!?\n" );
1693 return;
1694 }
1695 $called = true;
1696 if($this->isFileCacheable()) {
1697 $touched = $this->mTouched;
1698 if( $this->mTitle->getPrefixedDBkey() == wfMsg( 'mainpage' ) ) {
1699 # Expire the main page quicker
1700 $expire = wfUnix2Timestamp( time() - 3600 );
1701 $touched = max( $expire, $touched );
1702 }
1703 $cache = new CacheManager( $this->mTitle );
1704 if($cache->isFileCacheGood( $touched )) {
1705 global $wgOut;
1706 wfDebug( " tryFileCache() - about to load\n" );
1707 $cache->loadFromFileCache();
1708 return true;
1709 } else {
1710 wfDebug( " tryFileCache() - starting buffer\n" );
1711 ob_start( array(&$cache, 'saveToFileCache' ) );
1712 }
1713 } else {
1714 wfDebug( " tryFileCache() - not cacheable\n" );
1715 }
1716 }
1717
1718 function isFileCacheable() {
1719 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
1720 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
1721
1722 return $wgUseFileCache
1723 and (!$wgShowIPinHeader)
1724 and ($this->getID() != 0)
1725 and ($wgUser->getId() == 0)
1726 and (!$wgUser->getNewtalk())
1727 and ($this->mTitle->getNamespace() != Namespace::getSpecial())
1728 and ($action == 'view')
1729 and (!isset($oldid))
1730 and (!isset($diff))
1731 and (!isset($redirect))
1732 and (!isset($printable))
1733 and (!$this->mRedirectedFrom);
1734 }
1735
1736 # Loads cur_touched and returns a value indicating if it should be used
1737 function checkTouched() {
1738 $fname = 'Article::checkTouched';
1739
1740 $id = $this->getID();
1741 $dbr =& wfGetDB( DB_SLAVE );
1742 $s = $dbr->getArray( 'cur', array( 'cur_touched', 'cur_is_redirect' ),
1743 array( 'cur_id' => $id ), $fname );
1744 if( $s !== false ) {
1745 $this->mTouched = $s->cur_touched;
1746 return !$s->cur_is_redirect;
1747 } else {
1748 return false;
1749 }
1750 }
1751
1752 # Edit an article without doing all that other stuff
1753 function quickEdit( $text, $comment = '', $minor = 0 ) {
1754 global $wgUser, $wgMwRedir;
1755 $fname = 'Article::quickEdit';
1756 wfProfileIn( $fname );
1757
1758 $dbw =& wfGetDB( DB_MASTER );
1759 $ns = $this->mTitle->getNamespace();
1760 $dbkey = $this->mTitle->getDBkey();
1761 $encDbKey = $dbw->strencode( $dbkey );
1762 $timestamp = wfTimestampNow();
1763
1764 # Save to history
1765 $dbw->insertSelect( 'old', 'cur',
1766 array(
1767 'old_namespace' => 'cur_namespace',
1768 'old_title' => 'cur_title',
1769 'old_text' => 'cur_text',
1770 'old_comment' => 'cur_comment',
1771 'old_user' => 'cur_user',
1772 'old_user_text' => 'cur_user_text',
1773 'old_timestamp' => 'cur_timestamp',
1774 'inverse_timestamp' => '99999999999999-cur_timestamp',
1775 ), array(
1776 'cur_namespace' => $ns,
1777 'cur_title' => $dbkey,
1778 ), $fname
1779 );
1780
1781 # Use the affected row count to determine if the article is new
1782 $numRows = $dbw->affectedRows();
1783
1784 # Make an array of fields to be inserted
1785 $fields = array(
1786 'cur_text' => $text,
1787 'cur_timestamp' => $timestamp,
1788 'cur_user' => $wgUser->getID(),
1789 'cur_user_text' => $wgUser->getName(),
1790 'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
1791 'cur_comment' => $comment,
1792 'cur_is_redirect' => $wgMwRedir->matchStart( $text ) ? 1 : 0,
1793 'cur_minor_edit' => intval($minor),
1794 'cur_touched' => $timestamp,
1795 );
1796
1797 if ( $numRows ) {
1798 # Update article
1799 $fields['cur_is_new'] = 0;
1800 $dbw->updateArray( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname );
1801 } else {
1802 # Insert new article
1803 $fields['cur_is_new'] = 1;
1804 $fields['cur_namespace'] = $ns;
1805 $fields['cur_title'] = $dbkey;
1806 $fields['cur_random'] = $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
1807 $dbw->insertArray( 'cur', $fields, $fname );
1808 }
1809 wfProfileOut( $fname );
1810 }
1811
1812 /* static */ function incViewCount( $id )
1813 {
1814 $id = intval( $id );
1815 global $wgHitcounterUpdateFreq;
1816
1817 $dbw =& wfGetDB( DB_MASTER );
1818 $curTable = $dbw->tableName( 'cur' );
1819 $hitcounterTable = $dbw->tableName( 'hitcounter' );
1820 $acchitsTable = $dbw->tableName( 'acchits' );
1821
1822 if( $wgHitcounterUpdateFreq <= 1 ){ //
1823 $dbw->query( "UPDATE $curTable SET cur_counter = cur_counter + 1 WHERE cur_id = $id" );
1824 return;
1825 }
1826
1827 # Not important enough to warrant an error page in case of failure
1828 $oldignore = $dbw->setIgnoreErrors( true );
1829
1830 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
1831
1832 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
1833 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
1834 # Most of the time (or on SQL errors), skip row count check
1835 $dbw->setIgnoreErrors( $oldignore );
1836 return;
1837 }
1838
1839 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
1840 $row = $dbw->fetchObject( $res );
1841 $rown = intval( $row->n );
1842 if( $rown >= $wgHitcounterUpdateFreq ){
1843 wfProfileIn( 'Article::incViewCount-collect' );
1844 $old_user_abort = ignore_user_abort( true );
1845
1846 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
1847 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
1848 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
1849 'GROUP BY hc_id');
1850 $dbw->query("DELETE FROM $hitcounterTable");
1851 $dbw->query('UNLOCK TABLES');
1852 $dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ".
1853 'WHERE cur_id = hc_id');
1854 $dbw->query("DROP TABLE $acchitsTable");
1855
1856 ignore_user_abort( $old_user_abort );
1857 wfProfileOut( 'Article::incViewCount-collect' );
1858 }
1859 $dbw->setIgnoreErrors( $oldignore );
1860 }
1861
1862 # The onArticle*() functions are supposed to be a kind of hooks
1863 # which should be called whenever any of the specified actions
1864 # are done.
1865 #
1866 # This is a good place to put code to clear caches, for instance.
1867
1868 # This is called on page move and undelete, as well as edit
1869 /* static */ function onArticleCreate($title_obj){
1870 global $wgUseSquid, $wgDeferredUpdateList;
1871
1872 $titles = $title_obj->getBrokenLinksTo();
1873
1874 # Purge squid
1875 if ( $wgUseSquid ) {
1876 $urls = $title_obj->getSquidURLs();
1877 foreach ( $titles as $linkTitle ) {
1878 $urls[] = $linkTitle->getInternalURL();
1879 }
1880 $u = new SquidUpdate( $urls );
1881 array_push( $wgDeferredUpdateList, $u );
1882 }
1883
1884 # Clear persistent link cache
1885 LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
1886 }
1887
1888 /* static */ function onArticleDelete($title_obj){
1889 LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
1890 }
1891
1892 /* static */ function onArticleEdit($title_obj){
1893 LinkCache::linksccClearPage( $title_obj->getArticleID() );
1894 }
1895
1896 # Info about this page
1897
1898 function info()
1899 {
1900 global $wgUser, $wgTitle, $wgOut, $wgLang, $wgAllowPageInfo;
1901 $fname = 'Article::info';
1902
1903 if ( !$wgAllowPageInfo ) {
1904 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
1905 return;
1906 }
1907
1908 $dbr =& wfGetDB( DB_SLAVE );
1909
1910 $basenamespace = $wgTitle->getNamespace() & (~1);
1911 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
1912 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
1913 $wl_clause = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
1914 $fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
1915 $wgOut->setPagetitle( $fullTitle );
1916 $wgOut->setSubtitle( wfMsg( "infosubtitle" ));
1917
1918 # first, see if the page exists at all.
1919 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1920 if ($exists < 1) {
1921 $wgOut->addHTML( wfMsg("noarticletext") );
1922 } else {
1923 $numwatchers = $dbr->selectField( 'watchlist', 'COUNT(*)', $wl_clause, $fname );
1924 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $numwatchers) . "</li>" );
1925 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1926 $wgOut->addHTML( "<li>" . wfMsg("numedits", $old + 1) . "</li>");
1927
1928 # to find number of distinct authors, we need to do some
1929 # funny stuff because of the cur/old table split:
1930 # - first, find the name of the 'cur' author
1931 # - then, find the number of *other* authors in 'old'
1932
1933 # find 'cur' author
1934 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
1935
1936 # find number of 'old' authors excluding 'cur' author
1937 $authors = $dbr->selectField( 'old', 'COUNT(DISTINCT old_user_text)',
1938 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname ) + 1;
1939
1940 # now for the Talk page ...
1941 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+1 );
1942 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+1 );
1943
1944 # does it exist?
1945 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1946
1947 # number of edits
1948 if ($exists > 0) {
1949 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1950 $wgOut->addHTML( "<li>" . wfMsg("numtalkedits", $old + 1) . "</li>");
1951 }
1952 $wgOut->addHTML( "<li>" . wfMsg("numauthors", $authors) . "</li>" );
1953
1954 # number of authors
1955 if ($exists > 0) {
1956 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
1957 $authors = $dbr->selectField( 'cur', 'COUNT(DISTINCT old_user_text)',
1958 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname );
1959
1960 $wgOut->addHTML( "<li>" . wfMsg("numtalkauthors", $authors) . "</li></ul>" );
1961 }
1962 }
1963 }
1964 }
1965
1966 ?>