fix class_exists() for not existing classes
[lhc/web/wiklou.git] / includes / Article.php
1 <?php
2 /**
3 * File for articles
4 * @package MediaWiki
5 */
6
7 $wgArticleCurContentFields = false;
8 $wgArticleOldContentFields = false;
9
10 /**
11 * Class representing a MediaWiki article and history.
12 *
13 * See design.txt for an overview.
14 * Note: edit user interface and cache support functions have been
15 * moved to separate EditPage and CacheManager classes.
16 *
17 * @package MediaWiki
18 */
19 class Article {
20 /**@{{
21 * @private
22 */
23 var $mComment; //!<
24 var $mContent; //!<
25 var $mContentLoaded; //!<
26 var $mCounter; //!<
27 var $mFileCache; //!<
28 var $mForUpdate; //!<
29 var $mGoodAdjustment; //!<
30 var $mId; //!<
31 var $mLatest; //!<
32 var $mMinorEdit; //!<
33 var $mOldId; //!<
34 var $mRedirectedFrom; //!<
35 var $mRedirectUrl; //!<
36 var $mRevIdFetched; //!<
37 var $mRevision; //!<
38 var $mTable; //!<
39 var $mTimestamp; //!<
40 var $mTitle; //!<
41 var $mTotalAdjustment; //!<
42 var $mTouched; //!<
43 var $mUser; //!<
44 var $mUserText; //!<
45 /**@}}*/
46
47 /**
48 * Constructor and clear the article
49 * @param $title Reference to a Title object.
50 * @param $oldId Integer revision ID, null to fetch from request, zero for current
51 */
52 function Article( &$title, $oldId = null ) {
53 $this->mTitle =& $title;
54 $this->mOldId = $oldId;
55 $this->clear();
56 }
57
58 /**
59 * Tell the page view functions that this view was redirected
60 * from another page on the wiki.
61 * @param $from Title object.
62 */
63 function setRedirectedFrom( $from ) {
64 $this->mRedirectedFrom = $from;
65 }
66
67 /**
68 * @return mixed false, Title of in-wiki target, or string with URL
69 */
70 function followRedirect() {
71 $text = $this->getContent();
72 $rt = Title::newFromRedirect( $text );
73
74 # process if title object is valid and not special:userlogout
75 if( $rt ) {
76 if( $rt->getInterwiki() != '' ) {
77 if( $rt->isLocal() ) {
78 // Offsite wikis need an HTTP redirect.
79 //
80 // This can be hard to reverse and may produce loops,
81 // so they may be disabled in the site configuration.
82
83 $source = $this->mTitle->getFullURL( 'redirect=no' );
84 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
85 }
86 } else {
87 if( $rt->getNamespace() == NS_SPECIAL ) {
88 // Gotta hand redirects to special pages differently:
89 // Fill the HTTP response "Location" header and ignore
90 // the rest of the page we're on.
91 //
92 // This can be hard to reverse, so they may be disabled.
93
94 if( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) {
95 // rolleyes
96 } else {
97 return $rt->getFullURL();
98 }
99 }
100 return $rt;
101 }
102 }
103
104 // No or invalid redirect
105 return false;
106 }
107
108 /**
109 * get the title object of the article
110 */
111 function getTitle() {
112 return $this->mTitle;
113 }
114
115 /**
116 * Clear the object
117 * @private
118 */
119 function clear() {
120 $this->mDataLoaded = false;
121 $this->mContentLoaded = false;
122
123 $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
124 $this->mRedirectedFrom = null; # Title object if set
125 $this->mUserText =
126 $this->mTimestamp = $this->mComment = $this->mFileCache = '';
127 $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
128 $this->mTouched = '19700101000000';
129 $this->mForUpdate = false;
130 $this->mIsRedirect = false;
131 $this->mRevIdFetched = 0;
132 $this->mRedirectUrl = false;
133 $this->mLatest = false;
134 }
135
136 /**
137 * Note that getContent/loadContent do not follow redirects anymore.
138 * If you need to fetch redirectable content easily, try
139 * the shortcut in Article::followContent()
140 * FIXME
141 * @todo There are still side-effects in this!
142 * In general, you should use the Revision class, not Article,
143 * to fetch text for purposes other than page views.
144 *
145 * @return Return the text of this revision
146 */
147 function getContent() {
148 global $wgRequest, $wgUser, $wgOut;
149
150 # Get variables from query string :P
151 $action = $wgRequest->getText( 'action', 'view' );
152 $section = $wgRequest->getText( 'section' );
153 $preload = $wgRequest->getText( 'preload' );
154
155 $fname = 'Article::getContent';
156 wfProfileIn( $fname );
157
158 if ( 0 == $this->getID() ) {
159 if ( 'edit' == $action ) {
160 wfProfileOut( $fname );
161
162 # If requested, preload some text.
163 $text=$this->getPreloadedText($preload);
164
165 # We used to put MediaWiki:Newarticletext here if
166 # $text was empty at this point.
167 # This is now shown above the edit box instead.
168 return $text;
169 }
170 wfProfileOut( $fname );
171 $wgOut->setRobotpolicy( 'noindex,nofollow' );
172
173 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
174 $ret = wfMsgWeirdKey ( $this->mTitle->getText() ) ;
175 } else {
176 $ret = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
177 }
178
179 return "<div class='noarticletext'>$ret</div>";
180 } else {
181 $this->loadContent();
182 if($action=='edit') {
183 if($section!='') {
184 if($section=='new') {
185 wfProfileOut( $fname );
186 $text=$this->getPreloadedText($preload);
187 return $text;
188 }
189
190 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
191 # comments to be stripped as well)
192 $rv=$this->getSection($this->mContent,$section);
193 wfProfileOut( $fname );
194 return $rv;
195 }
196 }
197 wfProfileOut( $fname );
198 return $this->mContent;
199 }
200 }
201
202 /**
203 * Get the contents of a page from its title and remove includeonly tags
204 *
205 * @param $preload String: the title of the page.
206 * @return string The contents of the page.
207 */
208 function getPreloadedText($preload) {
209 if ( $preload === '' )
210 return '';
211 else {
212 $preloadTitle = Title::newFromText( $preload );
213 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
214 $rev=Revision::newFromTitle($preloadTitle);
215 if ( is_object( $rev ) ) {
216 $text = $rev->getText();
217 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
218 // its own mini-parser! -ævar
219 $text = preg_replace( '~</?includeonly>~', '', $text );
220 return $text;
221 } else
222 return '';
223 }
224 }
225 }
226
227 /**
228 * This function returns the text of a section, specified by a number ($section).
229 * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
230 * the first section before any such heading (section 0).
231 *
232 * If a section contains subsections, these are also returned.
233 *
234 * @param $text String: text to look in
235 * @param $section Integer: section number
236 * @return string text of the requested section
237 */
238 function getSection($text,$section) {
239
240 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
241 # comments to be stripped as well)
242 $striparray=array();
243 $parser=new Parser();
244 $parser->mOutputType=OT_WIKI;
245 $parser->mOptions = new ParserOptions();
246 $striptext=$parser->strip($text, $striparray, true);
247
248 # now that we can be sure that no pseudo-sections are in the source,
249 # split it up by section
250 $secs =
251 preg_split(
252 '/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
253 $striptext, -1,
254 PREG_SPLIT_DELIM_CAPTURE);
255 if($section==0) {
256 $rv=$secs[0];
257 } else {
258 $headline=$secs[$section*2-1];
259 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
260 $hlevel=$matches[1];
261
262 # translate wiki heading into level
263 if(strpos($hlevel,'=')!==false) {
264 $hlevel=strlen($hlevel);
265 }
266
267 $rv=$headline. $secs[$section*2];
268 $count=$section+1;
269
270 $break=false;
271 while(!empty($secs[$count*2-1]) && !$break) {
272
273 $subheadline=$secs[$count*2-1];
274 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
275 $subhlevel=$matches[1];
276 if(strpos($subhlevel,'=')!==false) {
277 $subhlevel=strlen($subhlevel);
278 }
279 if($subhlevel > $hlevel) {
280 $rv.=$subheadline.$secs[$count*2];
281 }
282 if($subhlevel <= $hlevel) {
283 $break=true;
284 }
285 $count++;
286
287 }
288 }
289 # reinsert stripped tags
290 $rv=$parser->unstrip($rv,$striparray);
291 $rv=$parser->unstripNoWiki($rv,$striparray);
292 $rv=trim($rv);
293 return $rv;
294
295 }
296
297 /**
298 * @return int The oldid of the article that is to be shown, 0 for the
299 * current revision
300 */
301 function getOldID() {
302 if ( is_null( $this->mOldId ) ) {
303 $this->mOldId = $this->getOldIDFromRequest();
304 }
305 return $this->mOldId;
306 }
307
308 /**
309 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
310 *
311 * @return int The old id for the request
312 */
313 function getOldIDFromRequest() {
314 global $wgRequest;
315 $this->mRedirectUrl = false;
316 $oldid = $wgRequest->getVal( 'oldid' );
317 if ( isset( $oldid ) ) {
318 $oldid = intval( $oldid );
319 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
320 $nextid = $this->mTitle->getNextRevisionID( $oldid );
321 if ( $nextid ) {
322 $oldid = $nextid;
323 } else {
324 $this->mRedirectUrl = $this->mTitle->getFullURL( 'redirect=no' );
325 }
326 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
327 $previd = $this->mTitle->getPreviousRevisionID( $oldid );
328 if ( $previd ) {
329 $oldid = $previd;
330 } else {
331 # TODO
332 }
333 }
334 # unused:
335 # $lastid = $oldid;
336 }
337 if ( !$oldid ) {
338 $oldid = 0;
339 }
340 return $oldid;
341 }
342
343 /**
344 * Load the revision (including text) into this object
345 */
346 function loadContent() {
347 if ( $this->mContentLoaded ) return;
348
349 # Query variables :P
350 $oldid = $this->getOldID();
351
352 # Pre-fill content with error message so that if something
353 # fails we'll have something telling us what we intended.
354
355 $t = $this->mTitle->getPrefixedText();
356
357 $this->mOldId = $oldid;
358 $this->fetchContent( $oldid );
359 }
360
361
362 /**
363 * Fetch a page record with the given conditions
364 * @param Database $dbr
365 * @param array $conditions
366 * @private
367 */
368 function pageData( &$dbr, $conditions ) {
369 $fields = array(
370 'page_id',
371 'page_namespace',
372 'page_title',
373 'page_restrictions',
374 'page_counter',
375 'page_is_redirect',
376 'page_is_new',
377 'page_random',
378 'page_touched',
379 'page_latest',
380 'page_len' ) ;
381 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
382 $row = $dbr->selectRow( 'page',
383 $fields,
384 $conditions,
385 'Article::pageData' );
386 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
387 return $row ;
388 }
389
390 /**
391 * @param Database $dbr
392 * @param Title $title
393 */
394 function pageDataFromTitle( &$dbr, $title ) {
395 return $this->pageData( $dbr, array(
396 'page_namespace' => $title->getNamespace(),
397 'page_title' => $title->getDBkey() ) );
398 }
399
400 /**
401 * @param Database $dbr
402 * @param int $id
403 */
404 function pageDataFromId( &$dbr, $id ) {
405 return $this->pageData( $dbr, array( 'page_id' => $id ) );
406 }
407
408 /**
409 * Set the general counter, title etc data loaded from
410 * some source.
411 *
412 * @param object $data
413 * @private
414 */
415 function loadPageData( $data = 'fromdb' ) {
416 if ( $data === 'fromdb' ) {
417 $dbr =& $this->getDB();
418 $data = $this->pageDataFromId( $dbr, $this->getId() );
419 }
420
421 $lc =& LinkCache::singleton();
422 if ( $data ) {
423 $lc->addGoodLinkObj( $data->page_id, $this->mTitle );
424
425 $this->mTitle->mArticleID = $data->page_id;
426 $this->mTitle->loadRestrictions( $data->page_restrictions );
427 $this->mTitle->mRestrictionsLoaded = true;
428
429 $this->mCounter = $data->page_counter;
430 $this->mTouched = wfTimestamp( TS_MW, $data->page_touched );
431 $this->mIsRedirect = $data->page_is_redirect;
432 $this->mLatest = $data->page_latest;
433 } else {
434 if ( is_object( $this->mTitle ) ) {
435 $lc->addBadLinkObj( $this->mTitle );
436 }
437 $this->mTitle->mArticleID = 0;
438 }
439
440 $this->mDataLoaded = true;
441 }
442
443 /**
444 * Get text of an article from database
445 * Does *NOT* follow redirects.
446 * @param int $oldid 0 for whatever the latest revision is
447 * @return string
448 */
449 function fetchContent( $oldid = 0 ) {
450 if ( $this->mContentLoaded ) {
451 return $this->mContent;
452 }
453
454 $dbr =& $this->getDB();
455 $fname = 'Article::fetchContent';
456
457 # Pre-fill content with error message so that if something
458 # fails we'll have something telling us what we intended.
459 $t = $this->mTitle->getPrefixedText();
460 if( $oldid ) {
461 $t .= ',oldid='.$oldid;
462 }
463 $this->mContent = wfMsg( 'missingarticle', $t ) ;
464
465 if( $oldid ) {
466 $revision = Revision::newFromId( $oldid );
467 if( is_null( $revision ) ) {
468 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
469 return false;
470 }
471 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
472 if( !$data ) {
473 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
474 return false;
475 }
476 $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
477 $this->loadPageData( $data );
478 } else {
479 if( !$this->mDataLoaded ) {
480 $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
481 if( !$data ) {
482 wfDebug( "$fname failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
483 return false;
484 }
485 $this->loadPageData( $data );
486 }
487 $revision = Revision::newFromId( $this->mLatest );
488 if( is_null( $revision ) ) {
489 wfDebug( "$fname failed to retrieve current page, rev_id {$data->page_latest}\n" );
490 return false;
491 }
492 }
493
494 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
495 // We should instead work with the Revision object when we need it...
496 $this->mContent = $revision->userCan( MW_REV_DELETED_TEXT ) ? $revision->getRawText() : "";
497 //$this->mContent = $revision->getText();
498
499 $this->mUser = $revision->getUser();
500 $this->mUserText = $revision->getUserText();
501 $this->mComment = $revision->getComment();
502 $this->mTimestamp = wfTimestamp( TS_MW, $revision->getTimestamp() );
503
504 $this->mRevIdFetched = $revision->getID();
505 $this->mContentLoaded = true;
506 $this->mRevision =& $revision;
507
508 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ) ;
509
510 return $this->mContent;
511 }
512
513 /**
514 * Read/write accessor to select FOR UPDATE
515 *
516 * @param $x Mixed: FIXME
517 */
518 function forUpdate( $x = NULL ) {
519 return wfSetVar( $this->mForUpdate, $x );
520 }
521
522 /**
523 * Get the database which should be used for reads
524 *
525 * @return Database
526 */
527 function &getDB() {
528 $ret =& wfGetDB( DB_MASTER );
529 return $ret;
530 }
531
532 /**
533 * Get options for all SELECT statements
534 *
535 * @param $options Array: an optional options array which'll be appended to
536 * the default
537 * @return Array: options
538 */
539 function getSelectOptions( $options = '' ) {
540 if ( $this->mForUpdate ) {
541 if ( is_array( $options ) ) {
542 $options[] = 'FOR UPDATE';
543 } else {
544 $options = 'FOR UPDATE';
545 }
546 }
547 return $options;
548 }
549
550 /**
551 * @return int Page ID
552 */
553 function getID() {
554 if( $this->mTitle ) {
555 return $this->mTitle->getArticleID();
556 } else {
557 return 0;
558 }
559 }
560
561 /**
562 * @return bool Whether or not the page exists in the database
563 */
564 function exists() {
565 return $this->getId() != 0;
566 }
567
568 /**
569 * @return int The view count for the page
570 */
571 function getCount() {
572 if ( -1 == $this->mCounter ) {
573 $id = $this->getID();
574 if ( $id == 0 ) {
575 $this->mCounter = 0;
576 } else {
577 $dbr =& wfGetDB( DB_SLAVE );
578 $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
579 'Article::getCount', $this->getSelectOptions() );
580 }
581 }
582 return $this->mCounter;
583 }
584
585 /**
586 * Determine whether a page would be suitable for being counted as an
587 * article in the site_stats table based on the title & its content
588 *
589 * @param $text String: text to analyze
590 * @return bool
591 */
592 function isCountable( $text ) {
593 global $wgUseCommaCount;
594
595 $token = $wgUseCommaCount ? ',' : '[[';
596 return
597 $this->mTitle->getNamespace() == NS_MAIN
598 && ! $this->isRedirect( $text )
599 && in_string( $token, $text );
600 }
601
602 /**
603 * Tests if the article text represents a redirect
604 *
605 * @param $text String: FIXME
606 * @return bool
607 */
608 function isRedirect( $text = false ) {
609 if ( $text === false ) {
610 $this->loadContent();
611 $titleObj = Title::newFromRedirect( $this->fetchContent() );
612 } else {
613 $titleObj = Title::newFromRedirect( $text );
614 }
615 return $titleObj !== NULL;
616 }
617
618 /**
619 * Returns true if the currently-referenced revision is the current edit
620 * to this page (and it exists).
621 * @return bool
622 */
623 function isCurrent() {
624 return $this->exists() &&
625 isset( $this->mRevision ) &&
626 $this->mRevision->isCurrent();
627 }
628
629 /**
630 * Loads everything except the text
631 * This isn't necessary for all uses, so it's only done if needed.
632 * @private
633 */
634 function loadLastEdit() {
635 if ( -1 != $this->mUser )
636 return;
637
638 # New or non-existent articles have no user information
639 $id = $this->getID();
640 if ( 0 == $id ) return;
641
642 $this->mLastRevision = Revision::loadFromPageId( $this->getDB(), $id );
643 if( !is_null( $this->mLastRevision ) ) {
644 $this->mUser = $this->mLastRevision->getUser();
645 $this->mUserText = $this->mLastRevision->getUserText();
646 $this->mTimestamp = $this->mLastRevision->getTimestamp();
647 $this->mComment = $this->mLastRevision->getComment();
648 $this->mMinorEdit = $this->mLastRevision->isMinor();
649 $this->mRevIdFetched = $this->mLastRevision->getID();
650 }
651 }
652
653 function getTimestamp() {
654 // Check if the field has been filled by ParserCache::get()
655 if ( !$this->mTimestamp ) {
656 $this->loadLastEdit();
657 }
658 return wfTimestamp(TS_MW, $this->mTimestamp);
659 }
660
661 function getUser() {
662 $this->loadLastEdit();
663 return $this->mUser;
664 }
665
666 function getUserText() {
667 $this->loadLastEdit();
668 return $this->mUserText;
669 }
670
671 function getComment() {
672 $this->loadLastEdit();
673 return $this->mComment;
674 }
675
676 function getMinorEdit() {
677 $this->loadLastEdit();
678 return $this->mMinorEdit;
679 }
680
681 function getRevIdFetched() {
682 $this->loadLastEdit();
683 return $this->mRevIdFetched;
684 }
685
686 /**
687 * @todo Document, fixme $offset never used.
688 * @param $limit Integer: default 0.
689 * @param $offset Integer: default 0.
690 */
691 function getContributors($limit = 0, $offset = 0) {
692 $fname = 'Article::getContributors';
693
694 # XXX: this is expensive; cache this info somewhere.
695
696 $title = $this->mTitle;
697 $contribs = array();
698 $dbr =& wfGetDB( DB_SLAVE );
699 $revTable = $dbr->tableName( 'revision' );
700 $userTable = $dbr->tableName( 'user' );
701 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
702 $ns = $title->getNamespace();
703 $user = $this->getUser();
704 $pageId = $this->getId();
705
706 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
707 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
708 WHERE rev_page = $pageId
709 AND rev_user != $user
710 GROUP BY rev_user, rev_user_text, user_real_name
711 ORDER BY timestamp DESC";
712
713 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
714 $sql .= ' '. $this->getSelectOptions();
715
716 $res = $dbr->query($sql, $fname);
717
718 while ( $line = $dbr->fetchObject( $res ) ) {
719 $contribs[] = array($line->rev_user, $line->rev_user_text, $line->user_real_name);
720 }
721
722 $dbr->freeResult($res);
723 return $contribs;
724 }
725
726 /**
727 * This is the default action of the script: just view the page of
728 * the given title.
729 */
730 function view() {
731 global $wgUser, $wgOut, $wgRequest, $wgContLang;
732 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
733 global $wgUseTrackbacks;
734 $sk = $wgUser->getSkin();
735
736 $fname = 'Article::view';
737 wfProfileIn( $fname );
738 $parserCache =& ParserCache::singleton();
739 # Get variables from query string
740 $oldid = $this->getOldID();
741
742 # getOldID may want us to redirect somewhere else
743 if ( $this->mRedirectUrl ) {
744 $wgOut->redirect( $this->mRedirectUrl );
745 wfProfileOut( $fname );
746 return;
747 }
748
749 $diff = $wgRequest->getVal( 'diff' );
750 $rcid = $wgRequest->getVal( 'rcid' );
751 $rdfrom = $wgRequest->getVal( 'rdfrom' );
752
753 $wgOut->setArticleFlag( true );
754 $wgOut->setRobotpolicy( 'index,follow' );
755 # If we got diff and oldid in the query, we want to see a
756 # diff page instead of the article.
757
758 if ( !is_null( $diff ) ) {
759 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
760
761 $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
762 // DifferenceEngine directly fetched the revision:
763 $this->mRevIdFetched = $de->mNewid;
764 $de->showDiffPage();
765
766 if( $diff == 0 ) {
767 # Run view updates for current revision only
768 $this->viewUpdates();
769 }
770 wfProfileOut( $fname );
771 return;
772 }
773
774 if ( empty( $oldid ) && $this->checkTouched() ) {
775 $wgOut->setETag($parserCache->getETag($this, $wgUser));
776
777 if( $wgOut->checkLastModified( $this->mTouched ) ){
778 wfProfileOut( $fname );
779 return;
780 } else if ( $this->tryFileCache() ) {
781 # tell wgOut that output is taken care of
782 $wgOut->disable();
783 $this->viewUpdates();
784 wfProfileOut( $fname );
785 return;
786 }
787 }
788 # Should the parser cache be used?
789 $pcache = $wgEnableParserCache &&
790 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
791 $this->exists() &&
792 empty( $oldid );
793 wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" );
794 if ( $wgUser->getOption( 'stubthreshold' ) ) {
795 wfIncrStats( 'pcache_miss_stub' );
796 }
797
798 $wasRedirected = false;
799 if ( isset( $this->mRedirectedFrom ) ) {
800 // This is an internally redirected page view.
801 // We'll need a backlink to the source page for navigation.
802 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
803 $sk = $wgUser->getSkin();
804 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom, '', 'redirect=no' );
805 $s = wfMsg( 'redirectedfrom', $redir );
806 $wgOut->setSubtitle( $s );
807 $wasRedirected = true;
808 }
809 } elseif ( !empty( $rdfrom ) ) {
810 // This is an externally redirected view, from some other wiki.
811 // If it was reported from a trusted site, supply a backlink.
812 global $wgRedirectSources;
813 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
814 $sk = $wgUser->getSkin();
815 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
816 $s = wfMsg( 'redirectedfrom', $redir );
817 $wgOut->setSubtitle( $s );
818 $wasRedirected = true;
819 }
820 }
821
822 $outputDone = false;
823 if ( $pcache ) {
824 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
825 $outputDone = true;
826 }
827 }
828 if ( !$outputDone ) {
829 $text = $this->getContent();
830 if ( $text === false ) {
831 # Failed to load, replace text with error message
832 $t = $this->mTitle->getPrefixedText();
833 if( $oldid ) {
834 $t .= ',oldid='.$oldid;
835 $text = wfMsg( 'missingarticle', $t );
836 } else {
837 $text = wfMsg( 'noarticletext', $t );
838 }
839 }
840
841 # Another whitelist check in case oldid is altering the title
842 if ( !$this->mTitle->userCanRead() ) {
843 $wgOut->loginToUse();
844 $wgOut->output();
845 exit;
846 }
847
848 # We're looking at an old revision
849
850 if ( !empty( $oldid ) ) {
851 $wgOut->setRobotpolicy( 'noindex,nofollow' );
852 if( is_null( $this->mRevision ) ) {
853 // FIXME: This would be a nice place to load the 'no such page' text.
854 } else {
855 $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
856 if( $this->mRevision->isDeleted( MW_REV_DELETED_TEXT ) ) {
857 if( !$this->mRevision->userCan( MW_REV_DELETED_TEXT ) ) {
858 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
859 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
860 return;
861 } else {
862 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
863 // and we are allowed to see...
864 }
865 }
866 }
867
868 }
869 }
870 if( !$outputDone ) {
871 /**
872 * @fixme: this hook doesn't work most of the time, as it doesn't
873 * trigger when the parser cache is used.
874 */
875 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
876 $wgOut->setRevisionId( $this->getRevIdFetched() );
877 # wrap user css and user js in pre and don't parse
878 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
879 if (
880 $this->mTitle->getNamespace() == NS_USER &&
881 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
882 ) {
883 $wgOut->addWikiText( wfMsg('clearyourcache'));
884 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
885 } else if ( $rt = Title::newFromRedirect( $text ) ) {
886 # Display redirect
887 $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
888 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
889 # Don't overwrite the subtitle if this was an old revision
890 if( !$wasRedirected && $this->isCurrent() ) {
891 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
892 }
893 $targetUrl = $rt->escapeLocalURL();
894 # fixme unused $titleText :
895 $titleText = htmlspecialchars( $rt->getPrefixedText() );
896 $link = $sk->makeLinkObj( $rt );
897
898 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
899 '<span class="redirectText">'.$link.'</span>' );
900
901 $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
902 $wgOut->addParserOutputNoText( $parseout );
903 } else if ( $pcache ) {
904 # Display content and save to parser cache
905 $wgOut->addPrimaryWikiText( $text, $this );
906 } else {
907 # Display content, don't attempt to save to parser cache
908
909 # Don't show section-edit links on old revisions... this way lies madness.
910 if( !$this->isCurrent() ) {
911 $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
912 }
913 # Display content and don't save to parser cache
914 $wgOut->addPrimaryWikiText( $text, $this, false );
915
916 if( !$this->isCurrent() ) {
917 $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting );
918 }
919 }
920 }
921 /* title may have been set from the cache */
922 $t = $wgOut->getPageTitle();
923 if( empty( $t ) ) {
924 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
925 }
926
927 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
928 if( $this->mTitle->getNamespace() == NS_USER_TALK &&
929 User::isIP( $this->mTitle->getText() ) ) {
930 $wgOut->addWikiText( wfMsg('anontalkpagetext') );
931 }
932
933 # If we have been passed an &rcid= parameter, we want to give the user a
934 # chance to mark this new article as patrolled.
935 if ( $wgUseRCPatrol && !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
936 $wgOut->addHTML(
937 "<div class='patrollink'>" .
938 wfMsg ( 'markaspatrolledlink',
939 $sk->makeKnownLinkObj( $this->mTitle, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
940 ) .
941 '</div>'
942 );
943 }
944
945 # Trackbacks
946 if ($wgUseTrackbacks)
947 $this->addTrackbacks();
948
949 $this->viewUpdates();
950 wfProfileOut( $fname );
951 }
952
953 function addTrackbacks() {
954 global $wgOut, $wgUser;
955
956 $dbr =& wfGetDB(DB_SLAVE);
957 $tbs = $dbr->select(
958 /* FROM */ 'trackbacks',
959 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
960 /* WHERE */ array('tb_page' => $this->getID())
961 );
962
963 if (!$dbr->numrows($tbs))
964 return;
965
966 $tbtext = "";
967 while ($o = $dbr->fetchObject($tbs)) {
968 $rmvtxt = "";
969 if ($wgUser->isAllowed( 'trackback' )) {
970 $delurl = $this->mTitle->getFullURL("action=deletetrackback&tbid="
971 . $o->tb_id . "&token=" . $wgUser->editToken());
972 $rmvtxt = wfMsg('trackbackremove', $delurl);
973 }
974 $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback',
975 $o->tb_title,
976 $o->tb_url,
977 $o->tb_ex,
978 $o->tb_name,
979 $rmvtxt);
980 }
981 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
982 }
983
984 function deletetrackback() {
985 global $wgUser, $wgRequest, $wgOut, $wgTitle;
986
987 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
988 $wgOut->addWikitext(wfMsg('sessionfailure'));
989 return;
990 }
991
992 if ((!$wgUser->isAllowed('delete'))) {
993 $wgOut->sysopRequired();
994 return;
995 }
996
997 if (wfReadOnly()) {
998 $wgOut->readOnlyPage();
999 return;
1000 }
1001
1002 $db =& wfGetDB(DB_MASTER);
1003 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
1004 $wgTitle->invalidateCache();
1005 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
1006 }
1007
1008 function render() {
1009 global $wgOut;
1010
1011 $wgOut->setArticleBodyOnly(true);
1012 $this->view();
1013 }
1014
1015 /**
1016 * Handle action=purge
1017 */
1018 function purge() {
1019 global $wgUser, $wgRequest, $wgOut;
1020
1021 if ( $wgUser->isLoggedIn() || $wgRequest->wasPosted() ) {
1022 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
1023 $this->doPurge();
1024 }
1025 } else {
1026 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
1027 $action = $this->mTitle->escapeLocalURL( 'action=purge' );
1028 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
1029 $msg = str_replace( '$1',
1030 "<form method=\"post\" action=\"$action\">\n" .
1031 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
1032 "</form>\n", $msg );
1033
1034 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
1035 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1036 $wgOut->addHTML( $msg );
1037 }
1038 }
1039
1040 /**
1041 * Perform the actions of a page purging
1042 */
1043 function doPurge() {
1044 global $wgUseSquid;
1045 // Invalidate the cache
1046 $this->mTitle->invalidateCache();
1047
1048 if ( $wgUseSquid ) {
1049 // Commit the transaction before the purge is sent
1050 $dbw = wfGetDB( DB_MASTER );
1051 $dbw->immediateCommit();
1052
1053 // Send purge
1054 $update = SquidUpdate::newSimplePurge( $this->mTitle );
1055 $update->doUpdate();
1056 }
1057 $this->view();
1058 }
1059
1060 /**
1061 * Insert a new empty page record for this article.
1062 * This *must* be followed up by creating a revision
1063 * and running $this->updateToLatest( $rev_id );
1064 * or else the record will be left in a funky state.
1065 * Best if all done inside a transaction.
1066 *
1067 * @param Database $dbw
1068 * @param string $restrictions
1069 * @return int The newly created page_id key
1070 * @private
1071 */
1072 function insertOn( &$dbw, $restrictions = '' ) {
1073 $fname = 'Article::insertOn';
1074 wfProfileIn( $fname );
1075
1076 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1077 $dbw->insert( 'page', array(
1078 'page_id' => $page_id,
1079 'page_namespace' => $this->mTitle->getNamespace(),
1080 'page_title' => $this->mTitle->getDBkey(),
1081 'page_counter' => 0,
1082 'page_restrictions' => $restrictions,
1083 'page_is_redirect' => 0, # Will set this shortly...
1084 'page_is_new' => 1,
1085 'page_random' => wfRandom(),
1086 'page_touched' => $dbw->timestamp(),
1087 'page_latest' => 0, # Fill this in shortly...
1088 'page_len' => 0, # Fill this in shortly...
1089 ), $fname );
1090 $newid = $dbw->insertId();
1091
1092 $this->mTitle->resetArticleId( $newid );
1093
1094 wfProfileOut( $fname );
1095 return $newid;
1096 }
1097
1098 /**
1099 * Update the page record to point to a newly saved revision.
1100 *
1101 * @param Database $dbw
1102 * @param Revision $revision For ID number, and text used to set
1103 length and redirect status fields
1104 * @param int $lastRevision If given, will not overwrite the page field
1105 * when different from the currently set value.
1106 * Giving 0 indicates the new page flag should
1107 * be set on.
1108 * @return bool true on success, false on failure
1109 * @private
1110 */
1111 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1112 $fname = 'Article::updateToRevision';
1113 wfProfileIn( $fname );
1114
1115 $conditions = array( 'page_id' => $this->getId() );
1116 if( !is_null( $lastRevision ) ) {
1117 # An extra check against threads stepping on each other
1118 $conditions['page_latest'] = $lastRevision;
1119 }
1120
1121 $text = $revision->getText();
1122 $dbw->update( 'page',
1123 array( /* SET */
1124 'page_latest' => $revision->getId(),
1125 'page_touched' => $dbw->timestamp(),
1126 'page_is_new' => ($lastRevision === 0) ? 1 : 0,
1127 'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0,
1128 'page_len' => strlen( $text ),
1129 ),
1130 $conditions,
1131 $fname );
1132
1133 wfProfileOut( $fname );
1134 return ( $dbw->affectedRows() != 0 );
1135 }
1136
1137 /**
1138 * If the given revision is newer than the currently set page_latest,
1139 * update the page record. Otherwise, do nothing.
1140 *
1141 * @param Database $dbw
1142 * @param Revision $revision
1143 */
1144 function updateIfNewerOn( &$dbw, $revision ) {
1145 $fname = 'Article::updateIfNewerOn';
1146 wfProfileIn( $fname );
1147
1148 $row = $dbw->selectRow(
1149 array( 'revision', 'page' ),
1150 array( 'rev_id', 'rev_timestamp' ),
1151 array(
1152 'page_id' => $this->getId(),
1153 'page_latest=rev_id' ),
1154 $fname );
1155 if( $row ) {
1156 if( wfTimestamp(TS_MW, $row->rev_timestamp) >= $revision->getTimestamp() ) {
1157 wfProfileOut( $fname );
1158 return false;
1159 }
1160 $prev = $row->rev_id;
1161 } else {
1162 # No or missing previous revision; mark the page as new
1163 $prev = 0;
1164 }
1165
1166 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1167 wfProfileOut( $fname );
1168 return $ret;
1169 }
1170
1171 /**
1172 * Insert a new article into the database
1173 * @private
1174 */
1175 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1176 global $wgUser;
1177
1178 $fname = 'Article::insertNewArticle';
1179 wfProfileIn( $fname );
1180
1181 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1182 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1183 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1184 wfProfileOut( $fname );
1185 return false;
1186 }
1187
1188 $ns = $this->mTitle->getNamespace();
1189 $ttl = $this->mTitle->getDBkey();
1190
1191 # If this is a comment, add the summary as headline
1192 if($comment && $summary!="") {
1193 $text="== {$summary} ==\n\n".$text;
1194 }
1195 $text = $this->preSaveTransform( $text );
1196
1197
1198 # Set statistics members
1199 # We work out if it's countable after PST to avoid counter drift
1200 # when articles are created with {{subst:}}
1201 $this->mGoodAdjustment = (int)$this->isCountable( $text );
1202 $this->mTotalAdjustment = 1;
1203
1204 /* Silently ignore minoredit if not allowed */
1205 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1206 $now = wfTimestampNow();
1207
1208 $dbw =& wfGetDB( DB_MASTER );
1209
1210 # Add the page record; stake our claim on this title!
1211 $newid = $this->insertOn( $dbw );
1212
1213 # Save the revision text...
1214 $revision = new Revision( array(
1215 'page' => $newid,
1216 'comment' => $summary,
1217 'minor_edit' => $isminor,
1218 'text' => $text
1219 ) );
1220 $revisionId = $revision->insertOn( $dbw );
1221
1222 $this->mTitle->resetArticleID( $newid );
1223
1224 # Update the page record with revision data
1225 $this->updateRevisionOn( $dbw, $revision, 0 );
1226
1227 Article::onArticleCreate( $this->mTitle );
1228 if(!$suppressRC) {
1229 $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, 'default',
1230 '', strlen( $text ), $revisionId );
1231 # Mark as patrolled if the user can and has the option set
1232 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1233 RecentChange::markPatrolled( $rcid );
1234 }
1235 }
1236
1237 if ($watchthis) {
1238 if(!$this->mTitle->userIsWatching()) $this->doWatch();
1239 } else {
1240 if ( $this->mTitle->userIsWatching() ) {
1241 $this->doUnwatch();
1242 }
1243 }
1244
1245 # The talk page isn't in the regular link tables, so we need to update manually:
1246 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
1247 $dbw->update( 'page',
1248 array( 'page_touched' => $dbw->timestamp($now) ),
1249 array( 'page_namespace' => $talkns,
1250 'page_title' => $ttl ),
1251 $fname );
1252
1253 # standard deferred updates
1254 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1255
1256 $oldid = 0; # new article
1257 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1258
1259 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1260 $summary, $isminor,
1261 $watchthis, NULL ) );
1262 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1263 $summary, $isminor,
1264 $watchthis, NULL ) );
1265 wfProfileOut( $fname );
1266 }
1267
1268 /**
1269 * @return string Complete article text, or null if error
1270 */
1271 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1272 $fname = 'Article::replaceSection';
1273 wfProfileIn( $fname );
1274
1275 if ($section != '') {
1276 if( is_null( $edittime ) ) {
1277 $rev = Revision::newFromTitle( $this->mTitle );
1278 } else {
1279 $dbw =& wfGetDB( DB_MASTER );
1280 $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
1281 }
1282 if( is_null( $rev ) ) {
1283 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1284 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1285 return null;
1286 }
1287 $oldtext = $rev->getText();
1288
1289 if($section=='new') {
1290 if($summary) $subject="== {$summary} ==\n\n";
1291 $text=$oldtext."\n\n".$subject.$text;
1292 } else {
1293
1294 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1295 # comments to be stripped as well)
1296 $striparray=array();
1297 $parser=new Parser();
1298 $parser->mOutputType=OT_WIKI;
1299 $parser->mOptions = new ParserOptions();
1300 $oldtext=$parser->strip($oldtext, $striparray, true);
1301
1302 # now that we can be sure that no pseudo-sections are in the source,
1303 # split it up
1304 # Unfortunately we can't simply do a preg_replace because that might
1305 # replace the wrong section, so we have to use the section counter instead
1306 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
1307 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
1308 $secs[$section*2]=$text."\n\n"; // replace with edited
1309
1310 # section 0 is top (intro) section
1311 if($section!=0) {
1312
1313 # headline of old section - we need to go through this section
1314 # to determine if there are any subsections that now need to
1315 # be erased, as the mother section has been replaced with
1316 # the text of all subsections.
1317 $headline=$secs[$section*2-1];
1318 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
1319 $hlevel=$matches[1];
1320
1321 # determine headline level for wikimarkup headings
1322 if(strpos($hlevel,'=')!==false) {
1323 $hlevel=strlen($hlevel);
1324 }
1325
1326 $secs[$section*2-1]=''; // erase old headline
1327 $count=$section+1;
1328 $break=false;
1329 while(!empty($secs[$count*2-1]) && !$break) {
1330
1331 $subheadline=$secs[$count*2-1];
1332 preg_match(
1333 '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
1334 $subhlevel=$matches[1];
1335 if(strpos($subhlevel,'=')!==false) {
1336 $subhlevel=strlen($subhlevel);
1337 }
1338 if($subhlevel > $hlevel) {
1339 // erase old subsections
1340 $secs[$count*2-1]='';
1341 $secs[$count*2]='';
1342 }
1343 if($subhlevel <= $hlevel) {
1344 $break=true;
1345 }
1346 $count++;
1347
1348 }
1349
1350 }
1351 $text=join('',$secs);
1352 # reinsert the stuff that we stripped out earlier
1353 $text=$parser->unstrip($text,$striparray);
1354 $text=$parser->unstripNoWiki($text,$striparray);
1355 }
1356
1357 }
1358 wfProfileOut( $fname );
1359 return $text;
1360 }
1361
1362 /**
1363 * Change an existing article. Puts the previous version back into the old table, updates RC
1364 * and all necessary caches, mostly via the deferred update array.
1365 *
1366 * It is possible to call this function from a command-line script, but note that you should
1367 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1368 */
1369 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1370 global $wgUser, $wgDBtransactions, $wgUseSquid;
1371 global $wgPostCommitUpdateList, $wgUseFileCache;
1372
1373 $fname = 'Article::updateArticle';
1374 wfProfileIn( $fname );
1375 $good = true;
1376
1377 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1378 &$summary, &$minor,
1379 &$watchthis, &$sectionanchor ) ) ) {
1380 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1381 wfProfileOut( $fname );
1382 return false;
1383 }
1384
1385 $isminor = $minor && $wgUser->isAllowed('minoredit');
1386
1387 $text = $this->preSaveTransform( $text );
1388 $dbw =& wfGetDB( DB_MASTER );
1389 $now = wfTimestampNow();
1390
1391 # Update article, but only if changed.
1392
1393 # It's important that we either rollback or complete, otherwise an attacker could
1394 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1395 # could conceivably have the same effect, especially if cur is locked for long periods.
1396 if( !$wgDBtransactions ) {
1397 $userAbort = ignore_user_abort( true );
1398 }
1399
1400 $oldtext = $this->getContent();
1401 $oldsize = strlen( $oldtext );
1402 $newsize = strlen( $text );
1403 $lastRevision = 0;
1404 $revisionId = 0;
1405
1406 if ( 0 != strcmp( $text, $oldtext ) ) {
1407 $this->mGoodAdjustment = (int)$this->isCountable( $text )
1408 - (int)$this->isCountable( $oldtext );
1409 $this->mTotalAdjustment = 0;
1410 $now = wfTimestampNow();
1411
1412 $lastRevision = $dbw->selectField(
1413 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1414
1415 $revision = new Revision( array(
1416 'page' => $this->getId(),
1417 'comment' => $summary,
1418 'minor_edit' => $isminor,
1419 'text' => $text
1420 ) );
1421
1422 $dbw->immediateCommit();
1423 $dbw->begin();
1424 $revisionId = $revision->insertOn( $dbw );
1425
1426 # Update page
1427 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1428
1429 if( !$ok ) {
1430 /* Belated edit conflict! Run away!! */
1431 $good = false;
1432 $dbw->rollback();
1433 } else {
1434 # Update recentchanges and purge cache and whatnot
1435 $bot = (int)($wgUser->isBot() || $forceBot);
1436 $rcid = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
1437 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1438 $revisionId );
1439
1440 # Mark as patrolled if the user can do so and has it set in their options
1441 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1442 RecentChange::markPatrolled( $rcid );
1443 }
1444
1445 $dbw->commit();
1446
1447 // Update caches outside the main transaction
1448 Article::onArticleEdit( $this->mTitle );
1449 }
1450 } else {
1451 // Keep the same revision ID, but do some updates on it
1452 $revisionId = $this->getRevIdFetched();
1453 }
1454
1455 if( !$wgDBtransactions ) {
1456 ignore_user_abort( $userAbort );
1457 }
1458
1459 if ( $good ) {
1460 if ($watchthis) {
1461 if (!$this->mTitle->userIsWatching()) {
1462 $dbw->immediateCommit();
1463 $dbw->begin();
1464 $this->doWatch();
1465 $dbw->commit();
1466 }
1467 } else {
1468 if ( $this->mTitle->userIsWatching() ) {
1469 $dbw->immediateCommit();
1470 $dbw->begin();
1471 $this->doUnwatch();
1472 $dbw->commit();
1473 }
1474 }
1475 # standard deferred updates
1476 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1477
1478
1479 $urls = array();
1480 # Invalidate caches of all articles using this article as a template
1481
1482 # Template namespace
1483 # Purge all articles linking here
1484 $titles = $this->mTitle->getTemplateLinksTo();
1485 Title::touchArray( $titles );
1486 if ( $wgUseSquid ) {
1487 foreach ( $titles as $title ) {
1488 $urls[] = $title->getInternalURL();
1489 }
1490 }
1491
1492 # Squid updates
1493 if ( $wgUseSquid ) {
1494 $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
1495 $u = new SquidUpdate( $urls );
1496 array_push( $wgPostCommitUpdateList, $u );
1497 }
1498
1499 # File cache
1500 if ( $wgUseFileCache ) {
1501 $cm = new CacheManager($this->mTitle);
1502 @unlink($cm->fileCacheName());
1503 }
1504
1505 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1506 }
1507 wfRunHooks( 'ArticleSaveComplete',
1508 array( &$this, &$wgUser, $text,
1509 $summary, $minor,
1510 $watchthis, $sectionanchor ) );
1511 wfProfileOut( $fname );
1512 return $good;
1513 }
1514
1515 /**
1516 * After we've either updated or inserted the article, update
1517 * the link tables and redirect to the new page.
1518 * @todo FIXME some function arguments never used
1519 */
1520 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1521 global $wgOut;
1522
1523 $fname = 'Article::showArticle';
1524 wfProfileIn( $fname );
1525
1526 # Output the redirect
1527 if( $this->isRedirect( $text ) )
1528 $r = 'redirect=no';
1529 else
1530 $r = '';
1531 $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
1532
1533 wfProfileOut( $fname );
1534 }
1535
1536 /**
1537 * Mark this particular edit as patrolled
1538 */
1539 function markpatrolled() {
1540 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
1541 $wgOut->setRobotpolicy( 'noindex,follow' );
1542
1543 # Check RC patrol config. option
1544 if( !$wgUseRCPatrol ) {
1545 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1546 return;
1547 }
1548
1549 # Check permissions
1550 if( !$wgUser->isAllowed( 'patrol' ) ) {
1551 $wgOut->permissionRequired( 'patrol' );
1552 return;
1553 }
1554
1555 $rcid = $wgRequest->getVal( 'rcid' );
1556 if ( !is_null ( $rcid ) ) {
1557 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
1558 RecentChange::markPatrolled( $rcid );
1559 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1560 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1561 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1562 }
1563 $rcTitle = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
1564 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1565 }
1566 else {
1567 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1568 }
1569 }
1570
1571 /**
1572 * User-interface handler for the "watch" action
1573 */
1574
1575 function watch() {
1576
1577 global $wgUser, $wgOut;
1578
1579 if ( $wgUser->isAnon() ) {
1580 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1581 return;
1582 }
1583 if ( wfReadOnly() ) {
1584 $wgOut->readOnlyPage();
1585 return;
1586 }
1587
1588 if( $this->doWatch() ) {
1589 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1590 $wgOut->setRobotpolicy( 'noindex,follow' );
1591
1592 $link = $this->mTitle->getPrefixedText();
1593 $text = wfMsg( 'addedwatchtext', $link );
1594 $wgOut->addWikiText( $text );
1595 }
1596
1597 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1598 }
1599
1600 /**
1601 * Add this page to $wgUser's watchlist
1602 * @return bool true on successful watch operation
1603 */
1604 function doWatch() {
1605 global $wgUser;
1606 if( $wgUser->isAnon() ) {
1607 return false;
1608 }
1609
1610 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1611 $wgUser->addWatch( $this->mTitle );
1612 $wgUser->saveSettings();
1613
1614 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1615 }
1616
1617 return false;
1618 }
1619
1620 /**
1621 * User interface handler for the "unwatch" action.
1622 */
1623 function unwatch() {
1624
1625 global $wgUser, $wgOut;
1626
1627 if ( $wgUser->isAnon() ) {
1628 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1629 return;
1630 }
1631 if ( wfReadOnly() ) {
1632 $wgOut->readOnlyPage();
1633 return;
1634 }
1635
1636 if( $this->doUnwatch() ) {
1637 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1638 $wgOut->setRobotpolicy( 'noindex,follow' );
1639
1640 $link = $this->mTitle->getPrefixedText();
1641 $text = wfMsg( 'removedwatchtext', $link );
1642 $wgOut->addWikiText( $text );
1643 }
1644
1645 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1646 }
1647
1648 /**
1649 * Stop watching a page
1650 * @return bool true on successful unwatch
1651 */
1652 function doUnwatch() {
1653 global $wgUser;
1654 if( $wgUser->isAnon() ) {
1655 return false;
1656 }
1657
1658 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1659 $wgUser->removeWatch( $this->mTitle );
1660 $wgUser->saveSettings();
1661
1662 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1663 }
1664
1665 return false;
1666 }
1667
1668 /**
1669 * action=protect handler
1670 */
1671 function protect() {
1672 $form = new ProtectionForm( $this );
1673 $form->show();
1674 }
1675
1676 /**
1677 * action=unprotect handler (alias)
1678 */
1679 function unprotect() {
1680 $this->protect();
1681 }
1682
1683 /**
1684 * Update the article's restriction field, and leave a log entry.
1685 *
1686 * @param array $limit set of restriction keys
1687 * @param string $reason
1688 * @return bool true on success
1689 */
1690 function updateRestrictions( $limit = array(), $reason = '' ) {
1691 global $wgUser, $wgRestrictionTypes, $wgContLang;
1692
1693 $id = $this->mTitle->getArticleID();
1694 if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) {
1695 return false;
1696 }
1697
1698 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1699 # we expect a single selection, but the schema allows otherwise.
1700 $current = array();
1701 foreach( $wgRestrictionTypes as $action )
1702 $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
1703
1704 $current = Article::flattenRestrictions( $current );
1705 $updated = Article::flattenRestrictions( $limit );
1706
1707 $changed = ( $current != $updated );
1708 $protect = ( $updated != '' );
1709
1710 # If nothing's changed, do nothing
1711 if( $changed ) {
1712 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1713
1714 $dbw =& wfGetDB( DB_MASTER );
1715
1716 # Prepare a null revision to be added to the history
1717 $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ? 'protectedarticle' : 'unprotectedarticle', $this->mTitle->getPrefixedText() ) );
1718 if( $reason )
1719 $comment .= ": $reason";
1720 if( $protect )
1721 $comment .= " [$updated]";
1722 $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
1723 $nullRevId = $nullRevision->insertOn( $dbw );
1724
1725 # Update page record
1726 $dbw->update( 'page',
1727 array( /* SET */
1728 'page_touched' => $dbw->timestamp(),
1729 'page_restrictions' => $updated,
1730 'page_latest' => $nullRevId
1731 ), array( /* WHERE */
1732 'page_id' => $id
1733 ), 'Article::protect'
1734 );
1735 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1736
1737 # Update the protection log
1738 $log = new LogPage( 'protect' );
1739 if( $protect ) {
1740 $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]" ) );
1741 } else {
1742 $log->addEntry( 'unprotect', $this->mTitle, $reason );
1743 }
1744
1745 } # End hook
1746 } # End "changed" check
1747
1748 return true;
1749 }
1750
1751 /**
1752 * Take an array of page restrictions and flatten it to a string
1753 * suitable for insertion into the page_restrictions field.
1754 * @param array $limit
1755 * @return string
1756 * @private
1757 */
1758 function flattenRestrictions( $limit ) {
1759 if( !is_array( $limit ) ) {
1760 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1761 }
1762 $bits = array();
1763 ksort( $limit );
1764 foreach( $limit as $action => $restrictions ) {
1765 if( $restrictions != '' ) {
1766 $bits[] = "$action=$restrictions";
1767 }
1768 }
1769 return implode( ':', $bits );
1770 }
1771
1772 /*
1773 * UI entry point for page deletion
1774 */
1775 function delete() {
1776 global $wgUser, $wgOut, $wgRequest;
1777 $fname = 'Article::delete';
1778 $confirm = $wgRequest->wasPosted() &&
1779 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1780 $reason = $wgRequest->getText( 'wpReason' );
1781
1782 # This code desperately needs to be totally rewritten
1783
1784 # Check permissions
1785 if( $wgUser->isAllowed( 'delete' ) ) {
1786 if( $wgUser->isBlocked() ) {
1787 $wgOut->blockedPage();
1788 return;
1789 }
1790 } else {
1791 $wgOut->permissionRequired( 'delete' );
1792 return;
1793 }
1794
1795 if( wfReadOnly() ) {
1796 $wgOut->readOnlyPage();
1797 return;
1798 }
1799
1800 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1801
1802 # Better double-check that it hasn't been deleted yet!
1803 $dbw =& wfGetDB( DB_MASTER );
1804 $conds = $this->mTitle->pageCond();
1805 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1806 if ( $latest === false ) {
1807 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1808 return;
1809 }
1810
1811 if( $confirm ) {
1812 $this->doDelete( $reason );
1813 return;
1814 }
1815
1816 # determine whether this page has earlier revisions
1817 # and insert a warning if it does
1818 $maxRevisions = 20;
1819 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1820
1821 if( count( $authors ) > 1 && !$confirm ) {
1822 $skin=$wgUser->getSkin();
1823 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
1824 }
1825
1826 # If a single user is responsible for all revisions, find out who they are
1827 if ( count( $authors ) == $maxRevisions ) {
1828 // Query bailed out, too many revisions to find out if they're all the same
1829 $authorOfAll = false;
1830 } else {
1831 $authorOfAll = reset( $authors );
1832 foreach ( $authors as $author ) {
1833 if ( $authorOfAll != $author ) {
1834 $authorOfAll = false;
1835 break;
1836 }
1837 }
1838 }
1839 # Fetch article text
1840 $rev = Revision::newFromTitle( $this->mTitle );
1841
1842 if( !is_null( $rev ) ) {
1843 # if this is a mini-text, we can paste part of it into the deletion reason
1844 $text = $rev->getText();
1845
1846 #if this is empty, an earlier revision may contain "useful" text
1847 $blanked = false;
1848 if( $text == '' ) {
1849 $prev = $rev->getPrevious();
1850 if( $prev ) {
1851 $text = $prev->getText();
1852 $blanked = true;
1853 }
1854 }
1855
1856 $length = strlen( $text );
1857
1858 # this should not happen, since it is not possible to store an empty, new
1859 # page. Let's insert a standard text in case it does, though
1860 if( $length == 0 && $reason === '' ) {
1861 $reason = wfMsgForContent( 'exblank' );
1862 }
1863
1864 if( $length < 500 && $reason === '' ) {
1865 # comment field=255, let's grep the first 150 to have some user
1866 # space left
1867 global $wgContLang;
1868 $text = $wgContLang->truncate( $text, 150, '...' );
1869
1870 # let's strip out newlines
1871 $text = preg_replace( "/[\n\r]/", '', $text );
1872
1873 if( !$blanked ) {
1874 if( $authorOfAll === false ) {
1875 $reason = wfMsgForContent( 'excontent', $text );
1876 } else {
1877 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1878 }
1879 } else {
1880 $reason = wfMsgForContent( 'exbeforeblank', $text );
1881 }
1882 }
1883 }
1884
1885 return $this->confirmDelete( '', $reason );
1886 }
1887
1888 /**
1889 * Get the last N authors
1890 * @param int $num Number of revisions to get
1891 * @param string $revLatest The latest rev_id, selected from the master (optional)
1892 * @return array Array of authors, duplicates not removed
1893 */
1894 function getLastNAuthors( $num, $revLatest = 0 ) {
1895 $fname = 'Article::getLastNAuthors';
1896 wfProfileIn( $fname );
1897
1898 // First try the slave
1899 // If that doesn't have the latest revision, try the master
1900 $continue = 2;
1901 $db =& wfGetDB( DB_SLAVE );
1902 do {
1903 $res = $db->select( array( 'page', 'revision' ),
1904 array( 'rev_id', 'rev_user_text' ),
1905 array(
1906 'page_namespace' => $this->mTitle->getNamespace(),
1907 'page_title' => $this->mTitle->getDBkey(),
1908 'rev_page = page_id'
1909 ), $fname, $this->getSelectOptions( array(
1910 'ORDER BY' => 'rev_timestamp DESC',
1911 'LIMIT' => $num
1912 ) )
1913 );
1914 if ( !$res ) {
1915 wfProfileOut( $fname );
1916 return array();
1917 }
1918 $row = $db->fetchObject( $res );
1919 if ( $continue == 2 && $revLatest && $row->rev_id != $revLatest ) {
1920 $db =& wfGetDB( DB_MASTER );
1921 $continue--;
1922 } else {
1923 $continue = 0;
1924 }
1925 } while ( $continue );
1926
1927 $authors = array( $row->rev_user_text );
1928 while ( $row = $db->fetchObject( $res ) ) {
1929 $authors[] = $row->rev_user_text;
1930 }
1931 wfProfileOut( $fname );
1932 return $authors;
1933 }
1934
1935 /**
1936 * Output deletion confirmation dialog
1937 */
1938 function confirmDelete( $par, $reason ) {
1939 global $wgOut, $wgUser;
1940
1941 wfDebug( "Article::confirmDelete\n" );
1942
1943 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1944 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1945 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1946 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1947
1948 $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
1949
1950 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1951 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1952 $token = htmlspecialchars( $wgUser->editToken() );
1953
1954 $wgOut->addHTML( "
1955 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1956 <table border='0'>
1957 <tr>
1958 <td align='right'>
1959 <label for='wpReason'>{$delcom}:</label>
1960 </td>
1961 <td align='left'>
1962 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1963 </td>
1964 </tr>
1965 <tr>
1966 <td>&nbsp;</td>
1967 <td>
1968 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1969 </td>
1970 </tr>
1971 </table>
1972 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1973 </form>\n" );
1974
1975 $wgOut->returnToMain( false );
1976 }
1977
1978
1979 /**
1980 * Perform a deletion and output success or failure messages
1981 */
1982 function doDelete( $reason ) {
1983 global $wgOut, $wgUser;
1984 $fname = 'Article::doDelete';
1985 wfDebug( $fname."\n" );
1986
1987 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1988 if ( $this->doDeleteArticle( $reason ) ) {
1989 $deleted = $this->mTitle->getPrefixedText();
1990
1991 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1992 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1993
1994 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1995 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1996
1997 $wgOut->addWikiText( $text );
1998 $wgOut->returnToMain( false );
1999 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
2000 } else {
2001 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
2002 }
2003 }
2004 }
2005
2006 /**
2007 * Back-end article deletion
2008 * Deletes the article with database consistency, writes logs, purges caches
2009 * Returns success
2010 */
2011 function doDeleteArticle( $reason ) {
2012 global $wgUseSquid, $wgDeferredUpdateList;
2013 global $wgPostCommitUpdateList, $wgUseTrackbacks;
2014
2015 $fname = 'Article::doDeleteArticle';
2016 wfDebug( $fname."\n" );
2017
2018 $dbw =& wfGetDB( DB_MASTER );
2019 $ns = $this->mTitle->getNamespace();
2020 $t = $this->mTitle->getDBkey();
2021 $id = $this->mTitle->getArticleID();
2022
2023 if ( $t == '' || $id == 0 ) {
2024 return false;
2025 }
2026
2027 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
2028 array_push( $wgDeferredUpdateList, $u );
2029
2030 $linksTo = $this->mTitle->getLinksTo();
2031
2032 # Squid purging
2033 if ( $wgUseSquid ) {
2034 $urls = array(
2035 $this->mTitle->getInternalURL(),
2036 $this->mTitle->getInternalURL( 'history' )
2037 );
2038
2039 $u = SquidUpdate::newFromTitles( $linksTo, $urls );
2040 array_push( $wgPostCommitUpdateList, $u );
2041
2042 }
2043
2044 # Client and file cache invalidation
2045 Title::touchArray( $linksTo );
2046
2047
2048 // For now, shunt the revision data into the archive table.
2049 // Text is *not* removed from the text table; bulk storage
2050 // is left intact to avoid breaking block-compression or
2051 // immutable storage schemes.
2052 //
2053 // For backwards compatibility, note that some older archive
2054 // table entries will have ar_text and ar_flags fields still.
2055 //
2056 // In the future, we may keep revisions and mark them with
2057 // the rev_deleted field, which is reserved for this purpose.
2058 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
2059 array(
2060 'ar_namespace' => 'page_namespace',
2061 'ar_title' => 'page_title',
2062 'ar_comment' => 'rev_comment',
2063 'ar_user' => 'rev_user',
2064 'ar_user_text' => 'rev_user_text',
2065 'ar_timestamp' => 'rev_timestamp',
2066 'ar_minor_edit' => 'rev_minor_edit',
2067 'ar_rev_id' => 'rev_id',
2068 'ar_text_id' => 'rev_text_id',
2069 ), array(
2070 'page_id' => $id,
2071 'page_id = rev_page'
2072 ), $fname
2073 );
2074
2075 # Now that it's safely backed up, delete it
2076 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
2077 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
2078
2079 if ($wgUseTrackbacks)
2080 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
2081
2082 # Clean up recentchanges entries...
2083 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
2084
2085 # Finally, clean up the link tables
2086 $t = $this->mTitle->getPrefixedDBkey();
2087
2088 Article::onArticleDelete( $this->mTitle );
2089
2090 # Delete outgoing links
2091 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2092 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2093 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2094 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
2095 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
2096 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
2097
2098 # Log the deletion
2099 $log = new LogPage( 'delete' );
2100 $log->addEntry( 'delete', $this->mTitle, $reason );
2101
2102 # Clear the cached article id so the interface doesn't act like we exist
2103 $this->mTitle->resetArticleID( 0 );
2104 $this->mTitle->mArticleID = 0;
2105 return true;
2106 }
2107
2108 /**
2109 * Revert a modification
2110 */
2111 function rollback() {
2112 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2113 $fname = 'Article::rollback';
2114
2115 if( $wgUser->isAllowed( 'rollback' ) ) {
2116 if( $wgUser->isBlocked() ) {
2117 $wgOut->blockedPage();
2118 return;
2119 }
2120 } else {
2121 $wgOut->permissionRequired( 'rollback' );
2122 return;
2123 }
2124
2125 if ( wfReadOnly() ) {
2126 $wgOut->readOnlyPage( $this->getContent() );
2127 return;
2128 }
2129 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2130 array( $this->mTitle->getPrefixedText(),
2131 $wgRequest->getVal( 'from' ) ) ) ) {
2132 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2133 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2134 return;
2135 }
2136 $dbw =& wfGetDB( DB_MASTER );
2137
2138 # Enhanced rollback, marks edits rc_bot=1
2139 $bot = $wgRequest->getBool( 'bot' );
2140
2141 # Replace all this user's current edits with the next one down
2142 $tt = $this->mTitle->getDBKey();
2143 $n = $this->mTitle->getNamespace();
2144
2145 # Get the last editor, lock table exclusively
2146 $dbw->begin();
2147 $current = Revision::newFromTitle( $this->mTitle );
2148 if( is_null( $current ) ) {
2149 # Something wrong... no page?
2150 $dbw->rollback();
2151 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2152 return;
2153 }
2154
2155 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2156 if( $from != $current->getUserText() ) {
2157 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2158 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2159 htmlspecialchars( $this->mTitle->getPrefixedText()),
2160 htmlspecialchars( $from ),
2161 htmlspecialchars( $current->getUserText() ) ) );
2162 if( $current->getComment() != '') {
2163 $wgOut->addHTML(
2164 wfMsg( 'editcomment',
2165 htmlspecialchars( $current->getComment() ) ) );
2166 }
2167 return;
2168 }
2169
2170 # Get the last edit not by this guy
2171 $user = intval( $current->getUser() );
2172 $user_text = $dbw->addQuotes( $current->getUserText() );
2173 $s = $dbw->selectRow( 'revision',
2174 array( 'rev_id', 'rev_timestamp' ),
2175 array(
2176 'rev_page' => $current->getPage(),
2177 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2178 ), $fname,
2179 array(
2180 'USE INDEX' => 'page_timestamp',
2181 'ORDER BY' => 'rev_timestamp DESC' )
2182 );
2183 if( $s === false ) {
2184 # Something wrong
2185 $dbw->rollback();
2186 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2187 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2188 return;
2189 }
2190
2191 $set = array();
2192 if ( $bot ) {
2193 # Mark all reverted edits as bot
2194 $set['rc_bot'] = 1;
2195 }
2196 if ( $wgUseRCPatrol ) {
2197 # Mark all reverted edits as patrolled
2198 $set['rc_patrolled'] = 1;
2199 }
2200
2201 if ( $set ) {
2202 $dbw->update( 'recentchanges', $set,
2203 array( /* WHERE */
2204 'rc_cur_id' => $current->getPage(),
2205 'rc_user_text' => $current->getUserText(),
2206 "rc_timestamp > '{$s->rev_timestamp}'",
2207 ), $fname
2208 );
2209 }
2210
2211 # Get the edit summary
2212 $target = Revision::newFromId( $s->rev_id );
2213 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2214 $newComment = $wgRequest->getText( 'summary', $newComment );
2215
2216 # Save it!
2217 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2218 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2219 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2220
2221 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle->userIsWatching(), $bot );
2222 Article::onArticleEdit( $this->mTitle );
2223
2224 $dbw->commit();
2225 $wgOut->returnToMain( false );
2226 }
2227
2228
2229 /**
2230 * Do standard deferred updates after page view
2231 * @private
2232 */
2233 function viewUpdates() {
2234 global $wgDeferredUpdateList;
2235
2236 if ( 0 != $this->getID() ) {
2237 global $wgDisableCounters;
2238 if( !$wgDisableCounters ) {
2239 Article::incViewCount( $this->getID() );
2240 $u = new SiteStatsUpdate( 1, 0, 0 );
2241 array_push( $wgDeferredUpdateList, $u );
2242 }
2243 }
2244
2245 # Update newtalk / watchlist notification status
2246 global $wgUser;
2247 $wgUser->clearNotification( $this->mTitle );
2248 }
2249
2250 /**
2251 * Do standard deferred updates after page edit.
2252 * Every 1000th edit, prune the recent changes table.
2253 * @private
2254 * @param string $text
2255 */
2256 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2257 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2258
2259 $fname = 'Article::editUpdates';
2260 wfProfileIn( $fname );
2261
2262 # Parse the text
2263 $options = new ParserOptions;
2264 $options->setTidy(true);
2265 $poutput = $wgParser->parse( $text, $this->mTitle, $options, true, true, $newid );
2266
2267 # Save it to the parser cache
2268 $parserCache =& ParserCache::singleton();
2269 $parserCache->save( $poutput, $this, $wgUser );
2270
2271 # Update the links tables
2272 $u = new LinksUpdate( $this->mTitle, $poutput );
2273 $u->doUpdate();
2274
2275 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2276 wfSeedRandom();
2277 if ( 0 == mt_rand( 0, 999 ) ) {
2278 # Periodically flush old entries from the recentchanges table.
2279 global $wgRCMaxAge;
2280
2281 $dbw =& wfGetDB( DB_MASTER );
2282 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2283 $recentchanges = $dbw->tableName( 'recentchanges' );
2284 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2285 $dbw->query( $sql );
2286 }
2287 }
2288
2289 $id = $this->getID();
2290 $title = $this->mTitle->getPrefixedDBkey();
2291 $shortTitle = $this->mTitle->getDBkey();
2292
2293 if ( 0 == $id ) {
2294 wfProfileOut( $fname );
2295 return;
2296 }
2297
2298 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment );
2299 array_push( $wgDeferredUpdateList, $u );
2300 $u = new SearchUpdate( $id, $title, $text );
2301 array_push( $wgDeferredUpdateList, $u );
2302
2303 # If this is another user's talk page, update newtalk
2304
2305 if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
2306 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2307 $other = User::newFromName( $shortTitle );
2308 if( is_null( $other ) && User::isIP( $shortTitle ) ) {
2309 // An anonymous user
2310 $other = new User();
2311 $other->setName( $shortTitle );
2312 }
2313 if( $other ) {
2314 $other->setNewtalk( true );
2315 }
2316 }
2317 }
2318
2319 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
2320 $wgMessageCache->replace( $shortTitle, $text );
2321 }
2322
2323 wfProfileOut( $fname );
2324 }
2325
2326 /**
2327 * Generate the navigation links when browsing through an article revisions
2328 * It shows the information as:
2329 * Revision as of \<date\>; view current revision
2330 * \<- Previous version | Next Version -\>
2331 *
2332 * @private
2333 * @param string $oldid Revision ID of this article revision
2334 */
2335 function setOldSubtitle( $oldid=0 ) {
2336 global $wgLang, $wgOut, $wgUser;
2337
2338 $current = ( $oldid == $this->mLatest );
2339 $td = $wgLang->timeanddate( $this->mTimestamp, true );
2340 $sk = $wgUser->getSkin();
2341 $lnk = $current
2342 ? wfMsg( 'currentrevisionlink' )
2343 : $lnk = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'currentrevisionlink' ) );
2344 $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
2345 $prevlink = $prev
2346 ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2347 : wfMsg( 'previousrevision' );
2348 $nextlink = $current
2349 ? wfMsg( 'nextrevision' )
2350 : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2351 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2352 $wgOut->setSubtitle( $r );
2353 }
2354
2355 /**
2356 * This function is called right before saving the wikitext,
2357 * so we can do things like signatures and links-in-context.
2358 *
2359 * @param string $text
2360 */
2361 function preSaveTransform( $text ) {
2362 global $wgParser, $wgUser;
2363 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
2364 }
2365
2366 /* Caching functions */
2367
2368 /**
2369 * checkLastModified returns true if it has taken care of all
2370 * output to the client that is necessary for this request.
2371 * (that is, it has sent a cached version of the page)
2372 */
2373 function tryFileCache() {
2374 static $called = false;
2375 if( $called ) {
2376 wfDebug( " tryFileCache() -- called twice!?\n" );
2377 return;
2378 }
2379 $called = true;
2380 if($this->isFileCacheable()) {
2381 $touched = $this->mTouched;
2382 $cache = new CacheManager( $this->mTitle );
2383 if($cache->isFileCacheGood( $touched )) {
2384 wfDebug( " tryFileCache() - about to load\n" );
2385 $cache->loadFromFileCache();
2386 return true;
2387 } else {
2388 wfDebug( " tryFileCache() - starting buffer\n" );
2389 ob_start( array(&$cache, 'saveToFileCache' ) );
2390 }
2391 } else {
2392 wfDebug( " tryFileCache() - not cacheable\n" );
2393 }
2394 }
2395
2396 /**
2397 * Check if the page can be cached
2398 * @return bool
2399 */
2400 function isFileCacheable() {
2401 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2402 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2403
2404 return $wgUseFileCache
2405 and (!$wgShowIPinHeader)
2406 and ($this->getID() != 0)
2407 and ($wgUser->isAnon())
2408 and (!$wgUser->getNewtalk())
2409 and ($this->mTitle->getNamespace() != NS_SPECIAL )
2410 and (empty( $action ) || $action == 'view')
2411 and (!isset($oldid))
2412 and (!isset($diff))
2413 and (!isset($redirect))
2414 and (!isset($printable))
2415 and (!$this->mRedirectedFrom);
2416 }
2417
2418 /**
2419 * Loads page_touched and returns a value indicating if it should be used
2420 *
2421 */
2422 function checkTouched() {
2423 $fname = 'Article::checkTouched';
2424 if( !$this->mDataLoaded ) {
2425 $this->loadPageData();
2426 }
2427 return !$this->mIsRedirect;
2428 }
2429
2430 /**
2431 * Get the page_touched field
2432 */
2433 function getTouched() {
2434 # Ensure that page data has been loaded
2435 if( !$this->mDataLoaded ) {
2436 $this->loadPageData();
2437 }
2438 return $this->mTouched;
2439 }
2440
2441 /**
2442 * Get the page_latest field
2443 */
2444 function getLatest() {
2445 if ( !$this->mDataLoaded ) {
2446 $this->loadPageData();
2447 }
2448 return $this->mLatest;
2449 }
2450
2451 /**
2452 * Edit an article without doing all that other stuff
2453 * The article must already exist; link tables etc
2454 * are not updated, caches are not flushed.
2455 *
2456 * @param string $text text submitted
2457 * @param string $comment comment submitted
2458 * @param bool $minor whereas it's a minor modification
2459 */
2460 function quickEdit( $text, $comment = '', $minor = 0 ) {
2461 $fname = 'Article::quickEdit';
2462 wfProfileIn( $fname );
2463
2464 $dbw =& wfGetDB( DB_MASTER );
2465 $dbw->begin();
2466 $revision = new Revision( array(
2467 'page' => $this->getId(),
2468 'text' => $text,
2469 'comment' => $comment,
2470 'minor_edit' => $minor ? 1 : 0,
2471 ) );
2472 # fixme : $revisionId never used
2473 $revisionId = $revision->insertOn( $dbw );
2474 $this->updateRevisionOn( $dbw, $revision );
2475 $dbw->commit();
2476
2477 wfProfileOut( $fname );
2478 }
2479
2480 /**
2481 * Used to increment the view counter
2482 *
2483 * @static
2484 * @param integer $id article id
2485 */
2486 function incViewCount( $id ) {
2487 $id = intval( $id );
2488 global $wgHitcounterUpdateFreq, $wgDBtype;
2489
2490 $dbw =& wfGetDB( DB_MASTER );
2491 $pageTable = $dbw->tableName( 'page' );
2492 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2493 $acchitsTable = $dbw->tableName( 'acchits' );
2494
2495 if( $wgHitcounterUpdateFreq <= 1 ){ //
2496 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2497 return;
2498 }
2499
2500 # Not important enough to warrant an error page in case of failure
2501 $oldignore = $dbw->ignoreErrors( true );
2502
2503 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2504
2505 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
2506 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2507 # Most of the time (or on SQL errors), skip row count check
2508 $dbw->ignoreErrors( $oldignore );
2509 return;
2510 }
2511
2512 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2513 $row = $dbw->fetchObject( $res );
2514 $rown = intval( $row->n );
2515 if( $rown >= $wgHitcounterUpdateFreq ){
2516 wfProfileIn( 'Article::incViewCount-collect' );
2517 $old_user_abort = ignore_user_abort( true );
2518
2519 if ($wgDBtype == 'mysql')
2520 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2521 $tabletype = $wgDBtype == 'mysql' ? "ENGINE=HEAP " : '';
2522 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
2523 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2524 'GROUP BY hc_id');
2525 $dbw->query("DELETE FROM $hitcounterTable");
2526 if ($wgDBtype == 'mysql')
2527 $dbw->query('UNLOCK TABLES');
2528 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2529 'WHERE page_id = hc_id');
2530 $dbw->query("DROP TABLE $acchitsTable");
2531
2532 ignore_user_abort( $old_user_abort );
2533 wfProfileOut( 'Article::incViewCount-collect' );
2534 }
2535 $dbw->ignoreErrors( $oldignore );
2536 }
2537
2538 /**#@+
2539 * The onArticle*() functions are supposed to be a kind of hooks
2540 * which should be called whenever any of the specified actions
2541 * are done.
2542 *
2543 * This is a good place to put code to clear caches, for instance.
2544 *
2545 * This is called on page move and undelete, as well as edit
2546 * @static
2547 * @param $title_obj a title object
2548 */
2549
2550 function onArticleCreate($title_obj) {
2551 global $wgUseSquid, $wgPostCommitUpdateList;
2552
2553 $title_obj->touchLinks();
2554 $titles = $title_obj->getLinksTo();
2555
2556 # Purge squid
2557 if ( $wgUseSquid ) {
2558 $urls = $title_obj->getSquidURLs();
2559 foreach ( $titles as $linkTitle ) {
2560 $urls[] = $linkTitle->getInternalURL();
2561 }
2562 $u = new SquidUpdate( $urls );
2563 array_push( $wgPostCommitUpdateList, $u );
2564 }
2565 }
2566
2567 function onArticleDelete( $title ) {
2568 global $wgMessageCache;
2569
2570 $title->touchLinks();
2571
2572 if( $title->getNamespace() == NS_MEDIAWIKI) {
2573 $wgMessageCache->replace( $title->getDBkey(), false );
2574 }
2575 }
2576
2577 /**
2578 * Purge caches on page update etc
2579 */
2580 function onArticleEdit( $title ) {
2581 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2582
2583 $urls = array();
2584
2585 // Template namespace? Purge all articles linking here.
2586 // FIXME: When a templatelinks table arrives, use it for all includes.
2587 if ( $title->getNamespace() == NS_TEMPLATE) {
2588 $titles = $title->getLinksTo();
2589 Title::touchArray( $titles );
2590 if ( $wgUseSquid ) {
2591 foreach ( $titles as $link ) {
2592 $urls[] = $link->getInternalURL();
2593 }
2594 }
2595 }
2596
2597 # Squid updates
2598 if ( $wgUseSquid ) {
2599 $urls = array_merge( $urls, $title->getSquidURLs() );
2600 $u = new SquidUpdate( $urls );
2601 array_push( $wgPostCommitUpdateList, $u );
2602 }
2603
2604 # File cache
2605 if ( $wgUseFileCache ) {
2606 $cm = new CacheManager( $title );
2607 @unlink( $cm->fileCacheName() );
2608 }
2609 }
2610
2611 /**#@-*/
2612
2613 /**
2614 * Info about this page
2615 * Called for ?action=info when $wgAllowPageInfo is on.
2616 *
2617 * @public
2618 */
2619 function info() {
2620 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2621 $fname = 'Article::info';
2622
2623 if ( !$wgAllowPageInfo ) {
2624 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2625 return;
2626 }
2627
2628 $page = $this->mTitle->getSubjectPage();
2629
2630 $wgOut->setPagetitle( $page->getPrefixedText() );
2631 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2632
2633 # first, see if the page exists at all.
2634 $exists = $page->getArticleId() != 0;
2635 if( !$exists ) {
2636 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
2637 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle->getText() ) );
2638 } else {
2639 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) );
2640 }
2641 } else {
2642 $dbr =& wfGetDB( DB_SLAVE );
2643 $wl_clause = array(
2644 'wl_title' => $page->getDBkey(),
2645 'wl_namespace' => $page->getNamespace() );
2646 $numwatchers = $dbr->selectField(
2647 'watchlist',
2648 'COUNT(*)',
2649 $wl_clause,
2650 $fname,
2651 $this->getSelectOptions() );
2652
2653 $pageInfo = $this->pageCountInfo( $page );
2654 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2655
2656 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2657 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2658 if( $talkInfo ) {
2659 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2660 }
2661 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2662 if( $talkInfo ) {
2663 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2664 }
2665 $wgOut->addHTML( '</ul>' );
2666
2667 }
2668 }
2669
2670 /**
2671 * Return the total number of edits and number of unique editors
2672 * on a given page. If page does not exist, returns false.
2673 *
2674 * @param Title $title
2675 * @return array
2676 * @private
2677 */
2678 function pageCountInfo( $title ) {
2679 $id = $title->getArticleId();
2680 if( $id == 0 ) {
2681 return false;
2682 }
2683
2684 $dbr =& wfGetDB( DB_SLAVE );
2685
2686 $rev_clause = array( 'rev_page' => $id );
2687 $fname = 'Article::pageCountInfo';
2688
2689 $edits = $dbr->selectField(
2690 'revision',
2691 'COUNT(rev_page)',
2692 $rev_clause,
2693 $fname,
2694 $this->getSelectOptions() );
2695
2696 $authors = $dbr->selectField(
2697 'revision',
2698 'COUNT(DISTINCT rev_user_text)',
2699 $rev_clause,
2700 $fname,
2701 $this->getSelectOptions() );
2702
2703 return array( 'edits' => $edits, 'authors' => $authors );
2704 }
2705
2706 /**
2707 * Return a list of templates used by this article.
2708 * Uses the templatelinks table
2709 *
2710 * @return array Array of Title objects
2711 */
2712 function getUsedTemplates() {
2713 $result = array();
2714 $id = $this->mTitle->getArticleID();
2715 if( $id == 0 ) {
2716 return array();
2717 }
2718
2719 $dbr =& wfGetDB( DB_SLAVE );
2720 $res = $dbr->select( array( 'templatelinks' ),
2721 array( 'tl_namespace', 'tl_title' ),
2722 array( 'tl_from' => $id ),
2723 'Article:getUsedTemplates' );
2724 if ( false !== $res ) {
2725 if ( $dbr->numRows( $res ) ) {
2726 while ( $row = $dbr->fetchObject( $res ) ) {
2727 $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
2728 }
2729 }
2730 }
2731 $dbr->freeResult( $res );
2732 return $result;
2733 }
2734 }
2735
2736 ?>