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