8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
17 * Class representing a MediaWiki article and history.
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
29 var $mContent, $mContentLoaded;
30 var $mUser, $mTimestamp, $mUserText;
31 var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
32 var $mMinorEdit, $mRedirectedFrom;
33 var $mTouched, $mFileCache, $mTitle;
42 * Constructor and clear the article
43 * @param mixed &$title
45 function Article( &$title ) {
46 $this->mTitle
=& $title;
51 * get the title object of the article
63 $this->mDataLoaded
= false;
64 $this->mContentLoaded
= false;
66 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
67 $this->mRedirectedFrom
= $this->mUserText
=
68 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
69 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
70 $this->mTouched
= '19700101000000';
71 $this->mForUpdate
= false;
72 $this->mIsRedirect
= false;
73 $this->mRevIdFetched
= 0;
77 * Note that getContent/loadContent may follow redirects if
78 * not told otherwise, and so may cause a change to mTitle.
81 * @return Return the text of this revision
83 function getContent( $noredir ) {
84 global $wgRequest, $wgUser, $wgOut;
86 # Get variables from query string :P
87 $action = $wgRequest->getText( 'action', 'view' );
88 $section = $wgRequest->getText( 'section' );
89 $preload = $wgRequest->getText( 'preload' );
91 $fname = 'Article::getContent';
92 wfProfileIn( $fname );
94 if ( 0 == $this->getID() ) {
95 if ( 'edit' == $action ) {
96 wfProfileOut( $fname );
98 # If requested, preload some text.
99 $text=$this->getPreloadedText($preload);
101 # We used to put MediaWiki:Newarticletext here if
102 # $text was empty at this point.
103 # This is now shown above the edit box instead.
106 wfProfileOut( $fname );
107 $wgOut->setRobotpolicy( 'noindex,nofollow' );
109 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
110 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
112 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
115 return "<div class='noarticletext'>$ret</div>";
117 $this->loadContent( $noredir );
118 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
119 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
120 $wgUser->isIP($this->mTitle
->getText()) &&
123 wfProfileOut( $fname );
124 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
126 if($action=='edit') {
128 if($section=='new') {
129 wfProfileOut( $fname );
130 $text=$this->getPreloadedText($preload);
134 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
135 # comments to be stripped as well)
136 $rv=$this->getSection($this->mContent
,$section);
137 wfProfileOut( $fname );
141 wfProfileOut( $fname );
142 return $this->mContent
;
148 This function accepts a title string as parameter
149 ($preload). If this string is non-empty, it attempts
150 to fetch the current revision text. It respects
153 function getPreloadedText($preload) {
155 $preloadTitle=Title
::newFromText($preload);
156 if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
157 $rev=Revision
::newFromTitle($preloadTitle);
159 $text=$rev->getText();
160 $text=preg_replace('/<\/?includeonly>/i','',$text);
169 * This function returns the text of a section, specified by a number ($section).
170 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
171 * the first section before any such heading (section 0).
173 * If a section contains subsections, these are also returned.
175 * @param string $text text to look in
176 * @param integer $section section number
177 * @return string text of the requested section
179 function getSection($text,$section) {
181 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
182 # comments to be stripped as well)
184 $parser=new Parser();
185 $parser->mOutputType
=OT_WIKI
;
186 $parser->mOptions
= new ParserOptions();
187 $striptext=$parser->strip($text, $striparray, true);
189 # now that we can be sure that no pseudo-sections are in the source,
190 # split it up by section
193 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
195 PREG_SPLIT_DELIM_CAPTURE
);
199 $headline=$secs[$section*2-1];
200 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
203 # translate wiki heading into level
204 if(strpos($hlevel,'=')!==false) {
205 $hlevel=strlen($hlevel);
208 $rv=$headline. $secs[$section*2];
212 while(!empty($secs[$count*2-1]) && !$break) {
214 $subheadline=$secs[$count*2-1];
215 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
216 $subhlevel=$matches[1];
217 if(strpos($subhlevel,'=')!==false) {
218 $subhlevel=strlen($subhlevel);
220 if($subhlevel > $hlevel) {
221 $rv.=$subheadline.$secs[$count*2];
223 if($subhlevel <= $hlevel) {
230 # reinsert stripped tags
231 $rv=$parser->unstrip($rv,$striparray);
232 $rv=$parser->unstripNoWiki($rv,$striparray);
239 * Return the oldid of the article that is to be shown.
240 * For requests with a "direction", this is not the oldid of the
243 function getOldID() {
244 global $wgRequest, $wgOut;
247 if ( isset( $lastid ) ) {
251 $oldid = $wgRequest->getVal( 'oldid' );
252 if ( isset( $oldid ) ) {
253 $oldid = intval( $oldid );
254 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
255 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
259 $wgOut->redirect( $this->mTitle
->getFullURL( 'redirect=no' ) );
261 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
262 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
271 return @$oldid; # "@" to be able to return "unset" without PHP complaining
276 * Load the revision (including cur_text) into this object
278 function loadContent( $noredir = false ) {
279 global $wgOut, $wgRequest;
281 if ( $this->mContentLoaded
) return;
284 $oldid = $this->getOldID();
285 $redirect = $wgRequest->getVal( 'redirect' );
287 $fname = 'Article::loadContent';
289 # Pre-fill content with error message so that if something
290 # fails we'll have something telling us what we intended.
292 $t = $this->mTitle
->getPrefixedText();
294 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no')
295 ||
$wgRequest->getCheck( 'rdfrom' );
296 $this->mOldId
= $oldid;
297 $this->fetchContent( $oldid, $noredir, true );
302 * Fetch a page record with the given conditions
303 * @param Database $dbr
304 * @param array $conditions
307 function pageData( &$dbr, $conditions ) {
320 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
321 $row = $dbr->selectRow( 'page',
324 'Article::pageData' );
325 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
329 function pageDataFromTitle( &$dbr, $title ) {
330 return $this->pageData( $dbr, array(
331 'page_namespace' => $title->getNamespace(),
332 'page_title' => $title->getDBkey() ) );
335 function pageDataFromId( &$dbr, $id ) {
336 return $this->pageData( $dbr, array(
337 'page_id' => intval( $id ) ) );
341 * Set the general counter, title etc data loaded from
344 * @param object $data
347 function loadPageData( $data ) {
348 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
349 $this->mTitle
->mRestrictionsLoaded
= true;
351 $this->mCounter
= $data->page_counter
;
352 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
353 $this->mIsRedirect
= $data->page_is_redirect
;
354 $this->mLatest
= $data->page_latest
;
356 $this->mDataLoaded
= true;
360 * Get text of an article from database
361 * @param int $oldid 0 for whatever the latest revision is
362 * @param bool $noredir Set to false to follow redirects
363 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
366 function fetchContent( $oldid = 0, $noredir = true, $globalTitle = false ) {
367 if ( $this->mContentLoaded
) {
368 return $this->mContent
;
371 $dbr =& $this->getDB();
372 $fname = 'Article::fetchContent';
374 # Pre-fill content with error message so that if something
375 # fails we'll have something telling us what we intended.
376 $t = $this->mTitle
->getPrefixedText();
378 $t .= ',oldid='.$oldid;
380 if( isset( $redirect ) ) {
381 $redirect = ($redirect == 'no') ?
'no' : 'yes';
382 $t .= ',redirect='.$redirect;
384 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
387 $revision = Revision
::newFromId( $oldid );
388 if( is_null( $revision ) ) {
389 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
392 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
394 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
397 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
398 $this->loadPageData( $data );
400 if( !$this->mDataLoaded
) {
401 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
403 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
406 $this->loadPageData( $data );
408 $revision = Revision
::newFromId( $this->mLatest
);
409 if( is_null( $revision ) ) {
410 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
415 # If we got a redirect, follow it (unless we've been told
416 # not to by either the function parameter or the query
417 if ( !$oldid && !$noredir ) {
418 $rt = Title
::newFromRedirect( $revision->getText() );
419 # process if title object is valid and not special:userlogout
420 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
421 # Gotta hand redirects to special pages differently:
422 # Fill the HTTP response "Location" header and ignore
423 # the rest of the page we're on.
424 global $wgDisableHardRedirects;
425 if( $globalTitle && !$wgDisableHardRedirects ) {
427 if ( $rt->getInterwiki() != '' && $rt->isLocal() ) {
428 $source = $this->mTitle
->getFullURL( 'redirect=no' );
429 $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ;
432 if ( $rt->getNamespace() == NS_SPECIAL
) {
433 $wgOut->redirect( $rt->getFullURL() );
437 if( $rt->getInterwiki() == '' ) {
438 $redirData = $this->pageDataFromTitle( $dbr, $rt );
440 $redirRev = Revision
::newFromId( $redirData->page_latest
);
441 if( !is_null( $redirRev ) ) {
442 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
445 $this->loadPageData( $data );
446 $revision = $redirRev;
453 # if the title's different from expected, update...
456 if( !$this->mTitle
->equals( $wgTitle ) ) {
457 $wgTitle = $this->mTitle
;
461 # Back to the business at hand...
462 $this->mContent
= $revision->getText();
464 $this->mUser
= $revision->getUser();
465 $this->mUserText
= $revision->getUserText();
466 $this->mComment
= $revision->getComment();
467 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
469 $this->mRevIdFetched
= $revision->getID();
470 $this->mContentLoaded
= true;
471 $this->mRevision
=& $revision;
473 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
475 return $this->mContent
;
479 * Gets the article text without using so many damn globals
480 * Returns false on error
482 * @param integer $oldid
484 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
485 return $this->fetchContent( $oldid, $noredir, false );
489 * Read/write accessor to select FOR UPDATE
491 function forUpdate( $x = NULL ) {
492 return wfSetVar( $this->mForUpdate
, $x );
496 * Get the database which should be used for reads
499 $ret =& wfGetDB( DB_MASTER
);
501 #if ( $this->mForUpdate ) {
502 $ret =& wfGetDB( DB_MASTER
);
504 # $ret =& wfGetDB( DB_SLAVE );
510 * Get options for all SELECT statements
511 * Can pass an option array, to which the class-wide options will be appended
513 function getSelectOptions( $options = '' ) {
514 if ( $this->mForUpdate
) {
515 if ( is_array( $options ) ) {
516 $options[] = 'FOR UPDATE';
518 $options = 'FOR UPDATE';
525 * Return the Article ID
528 if( $this->mTitle
) {
529 return $this->mTitle
->getArticleID();
536 * Returns true if this article exists in the database.
540 return $this->getId() != 0;
544 * Get the view count for this article
546 function getCount() {
547 if ( -1 == $this->mCounter
) {
548 $id = $this->getID();
549 $dbr =& $this->getDB();
550 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
551 'Article::getCount', $this->getSelectOptions() );
553 return $this->mCounter
;
557 * Would the given text make this article a "good" article (i.e.,
558 * suitable for including in the article count)?
559 * @param string $text Text to analyze
560 * @return integer 1 if it can be counted else 0
562 function isCountable( $text ) {
563 global $wgUseCommaCount;
565 if ( NS_MAIN
!= $this->mTitle
->getNamespace() ) { return 0; }
566 if ( $this->isRedirect( $text ) ) { return 0; }
567 $token = ($wgUseCommaCount ?
',' : '[[' );
568 if ( false === strstr( $text, $token ) ) { return 0; }
573 * Tests if the article text represents a redirect
575 function isRedirect( $text = false ) {
576 if ( $text === false ) {
577 $this->loadContent();
578 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
580 $titleObj = Title
::newFromRedirect( $text );
582 return $titleObj !== NULL;
586 * Returns true if the currently-referenced revision is the current edit
587 * to this page (and it exists).
590 function isCurrent() {
591 return $this->exists() &&
592 isset( $this->mRevision
) &&
593 $this->mRevision
->isCurrent();
597 * Loads everything except the text
598 * This isn't necessary for all uses, so it's only done if needed.
601 function loadLastEdit() {
604 if ( -1 != $this->mUser
)
607 # New or non-existent articles have no user information
608 $id = $this->getID();
609 if ( 0 == $id ) return;
611 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
612 if( !is_null( $this->mLastRevision
) ) {
613 $this->mUser
= $this->mLastRevision
->getUser();
614 $this->mUserText
= $this->mLastRevision
->getUserText();
615 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
616 $this->mComment
= $this->mLastRevision
->getComment();
617 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
621 function getTimestamp() {
622 $this->loadLastEdit();
623 return wfTimestamp(TS_MW
, $this->mTimestamp
);
627 $this->loadLastEdit();
631 function getUserText() {
632 $this->loadLastEdit();
633 return $this->mUserText
;
636 function getComment() {
637 $this->loadLastEdit();
638 return $this->mComment
;
641 function getMinorEdit() {
642 $this->loadLastEdit();
643 return $this->mMinorEdit
;
646 function getRevIdFetched() {
647 $this->loadLastEdit();
648 return $this->mRevIdFetched
;
651 function getContributors($limit = 0, $offset = 0) {
652 $fname = 'Article::getContributors';
654 # XXX: this is expensive; cache this info somewhere.
656 $title = $this->mTitle
;
658 $dbr =& $this->getDB();
659 $revTable = $dbr->tableName( 'revision' );
660 $userTable = $dbr->tableName( 'user' );
661 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
662 $ns = $title->getNamespace();
663 $user = $this->getUser();
664 $pageId = $this->getId();
666 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
667 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
668 WHERE rev_page = $pageId
669 AND rev_user != $user
670 GROUP BY rev_user, rev_user_text, user_real_name
671 ORDER BY timestamp DESC";
673 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
674 $sql .= ' '. $this->getSelectOptions();
676 $res = $dbr->query($sql, $fname);
678 while ( $line = $dbr->fetchObject( $res ) ) {
679 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
682 $dbr->freeResult($res);
687 * This is the default action of the script: just view the page of
691 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
692 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
693 global $wgParserCache, $wgUseTrackbacks;
694 $sk = $wgUser->getSkin();
696 $fname = 'Article::view';
697 wfProfileIn( $fname );
698 # Get variables from query string
699 $oldid = $this->getOldID();
700 $diff = $wgRequest->getVal( 'diff' );
701 $rcid = $wgRequest->getVal( 'rcid' );
702 $rdfrom = $wgRequest->getVal( 'rdfrom' );
704 $wgOut->setArticleFlag( true );
705 $wgOut->setRobotpolicy( 'index,follow' );
706 # If we got diff and oldid in the query, we want to see a
707 # diff page instead of the article.
709 if ( !is_null( $diff ) ) {
710 require_once( 'DifferenceEngine.php' );
711 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
713 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
714 // DifferenceEngine directly fetched the revision:
715 $this->mRevIdFetched
= $de->mNewid
;
719 # Run view updates for current revision only
720 $this->viewUpdates();
722 wfProfileOut( $fname );
726 if ( empty( $oldid ) && $this->checkTouched() ) {
727 $wgOut->setETag($wgParserCache->getETag($this, $wgUser));
729 if( $wgOut->checkLastModified( $this->mTouched
) ){
730 wfProfileOut( $fname );
732 } else if ( $this->tryFileCache() ) {
733 # tell wgOut that output is taken care of
735 $this->viewUpdates();
736 wfProfileOut( $fname );
740 # Should the parser cache be used?
741 $pcache = $wgEnableParserCache &&
742 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
745 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
746 if ( $wgUser->getOption( 'stubthreshold' ) ) {
747 wfIncrStats( 'pcache_miss_stub' );
752 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
756 if ( !$outputDone ) {
757 $text = $this->getContent( false ); # May change mTitle by following a redirect
759 # Another whitelist check in case oldid or redirects are altering the title
760 if ( !$this->mTitle
->userCanRead() ) {
761 $wgOut->loginToUse();
766 # We're looking at an old revision
768 if ( !empty( $oldid ) ) {
769 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
770 $wgOut->setRobotpolicy( 'noindex,follow' );
772 $wasRedirected = false;
773 if ( '' != $this->mRedirectedFrom
) {
774 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
775 $sk = $wgUser->getSkin();
776 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '', 'redirect=no' );
777 $s = wfMsg( 'redirectedfrom', $redir );
778 $wgOut->setSubtitle( $s );
780 // Check the parser cache again, for the target page
782 if( $wgOut->tryParserCache( $this, $wgUser ) ) {
786 $wasRedirected = true;
788 } elseif ( !empty( $rdfrom ) ) {
789 global $wgRedirectSources;
790 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
791 $sk = $wgUser->getSkin();
792 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
793 $s = wfMsg( 'redirectedfrom', $redir );
794 $wgOut->setSubtitle( $s );
795 $wasRedirected = true;
801 * @fixme: this hook doesn't work most of the time, as it doesn't
802 * trigger when the parser cache is used.
804 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
805 # wrap user css and user js in pre and don't parse
806 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
808 $this->mTitle
->getNamespace() == NS_USER
&&
809 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
811 $wgOut->setRevisionId( $this->getRevIdFetched() );
812 $wgOut->addWikiText( wfMsg('clearyourcache'));
813 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
814 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
816 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
817 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
818 if( !$wasRedirected ) {
819 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
821 $targetUrl = $rt->escapeLocalURL();
822 $titleText = htmlspecialchars( $rt->getPrefixedText() );
823 $link = $sk->makeLinkObj( $rt );
825 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
826 '<span class="redirectText">'.$link.'</span>' );
828 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
829 $catlinks = $parseout->getCategoryLinks();
830 $wgOut->addCategoryLinks($catlinks);
831 $skin = $wgUser->getSkin();
832 } else if ( $pcache ) {
833 # Display content and save to parser cache
834 $wgOut->setRevisionId( $this->getRevIdFetched() );
835 $wgOut->addPrimaryWikiText( $text, $this );
837 # Display content, don't attempt to save to parser cache
839 # Don't show section-edit links on old revisions... this way lies madness.
840 if( !$this->isCurrent() ) {
841 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
843 $wgOut->setRevisionId( $this->getRevIdFetched() );
844 $wgOut->addWikiText( $text );
846 if( !$this->isCurrent() ) {
847 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
851 /* title may have been set from the cache */
852 $t = $wgOut->getPageTitle();
854 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
857 # If we have been passed an &rcid= parameter, we want to give the user a
858 # chance to mark this new article as patrolled.
862 && $wgUser->isLoggedIn()
863 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
866 "<div class='patrollink'>" .
867 wfMsg ( 'markaspatrolledlink',
868 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
875 if ($wgUseTrackbacks)
876 $this->addTrackbacks();
878 # Add link titles as META keywords
879 $wgOut->addMetaTags() ;
881 $this->viewUpdates();
882 wfProfileOut( $fname );
885 function addTrackbacks() {
886 global $wgOut, $wgUser;
888 $dbr =& wfGetDB(DB_SLAVE
);
890 /* FROM */ 'trackbacks',
891 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
892 /* WHERE */ array('tb_page' => $this->getID())
895 if (!$dbr->numrows($tbs))
899 while ($o = $dbr->fetchObject($tbs)) {
901 if ($wgUser->isSysop()) {
902 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
903 . $o->tb_id
. "&token=" . $wgUser->editToken());
904 $rmvtxt = wfMsg('trackbackremove', $delurl);
906 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
913 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
916 function deletetrackback() {
917 global $wgUser, $wgRequest, $wgOut, $wgTitle;
919 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
920 $wgOut->addWikitext(wfMsg('sessionfailure'));
924 if ((!$wgUser->isAllowed('delete'))) {
925 $wgOut->sysopRequired();
930 $wgOut->readOnlyPage();
934 $db =& wfGetDB(DB_MASTER
);
935 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
936 $wgTitle->invalidateCache();
937 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
943 $wgOut->setArticleBodyOnly(true);
948 global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
950 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
951 // Invalidate the cache
952 $this->mTitle
->invalidateCache();
955 // Commit the transaction before the purge is sent
956 $dbw = wfGetDB( DB_MASTER
);
957 $dbw->immediateCommit();
960 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
965 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
966 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
967 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
968 $msg = str_replace( '$1',
969 "<form method=\"post\" action=\"$action\">\n" .
970 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
973 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
974 $wgOut->setRobotpolicy( 'noindex,nofollow' );
975 $wgOut->addHTML( $msg );
980 * Insert a new empty page record for this article.
981 * This *must* be followed up by creating a revision
982 * and running $this->updateToLatest( $rev_id );
983 * or else the record will be left in a funky state.
984 * Best if all done inside a transaction.
986 * @param Database $dbw
987 * @param string $restrictions
988 * @return int The newly created page_id key
991 function insertOn( &$dbw, $restrictions = '' ) {
992 $fname = 'Article::insertOn';
993 wfProfileIn( $fname );
995 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
996 $dbw->insert( 'page', array(
997 'page_id' => $page_id,
998 'page_namespace' => $this->mTitle
->getNamespace(),
999 'page_title' => $this->mTitle
->getDBkey(),
1000 'page_counter' => 0,
1001 'page_restrictions' => $restrictions,
1002 'page_is_redirect' => 0, # Will set this shortly...
1004 'page_random' => wfRandom(),
1005 'page_touched' => $dbw->timestamp(),
1006 'page_latest' => 0, # Fill this in shortly...
1007 'page_len' => 0, # Fill this in shortly...
1009 $newid = $dbw->insertId();
1011 $this->mTitle
->resetArticleId( $newid );
1013 wfProfileOut( $fname );
1018 * Update the page record to point to a newly saved revision.
1020 * @param Database $dbw
1021 * @param Revision $revision -- for ID number, and text used to set
1022 length and redirect status fields
1023 * @param int $lastRevision -- if given, will not overwrite the page field
1024 * when different from the currently set value.
1025 * Giving 0 indicates the new page flag should
1027 * @return bool true on success, false on failure
1030 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1031 $fname = 'Article::updateToRevision';
1032 wfProfileIn( $fname );
1034 $conditions = array( 'page_id' => $this->getId() );
1035 if( !is_null( $lastRevision ) ) {
1036 # An extra check against threads stepping on each other
1037 $conditions['page_latest'] = $lastRevision;
1040 $text = $revision->getText();
1041 $dbw->update( 'page',
1043 'page_latest' => $revision->getId(),
1044 'page_touched' => $dbw->timestamp(),
1045 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1046 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1047 'page_len' => strlen( $text ),
1052 wfProfileOut( $fname );
1053 return ( $dbw->affectedRows() != 0 );
1057 * If the given revision is newer than the currently set page_latest,
1058 * update the page record. Otherwise, do nothing.
1060 * @param Database $dbw
1061 * @param Revision $revision
1063 function updateIfNewerOn( &$dbw, $revision ) {
1064 $fname = 'Article::updateIfNewerOn';
1065 wfProfileIn( $fname );
1067 $row = $dbw->selectRow(
1068 array( 'revision', 'page' ),
1069 array( 'rev_id', 'rev_timestamp' ),
1071 'page_id' => $this->getId(),
1072 'page_latest=rev_id' ),
1075 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1076 wfProfileOut( $fname );
1079 $prev = $row->rev_id
;
1081 # No or missing previous revision; mark the page as new
1085 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1086 wfProfileOut( $fname );
1091 * Theoretically we could defer these whole insert and update
1092 * functions for after display, but that's taking a big leap
1093 * of faith, and we want to be able to report database
1094 * errors at some point.
1097 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1098 global $wgOut, $wgUser, $wgUseSquid;
1100 $fname = 'Article::insertNewArticle';
1101 wfProfileIn( $fname );
1103 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1104 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1105 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1106 wfProfileOut( $fname );
1110 $this->mGoodAdjustment
= $this->isCountable( $text );
1111 $this->mTotalAdjustment
= 1;
1113 $ns = $this->mTitle
->getNamespace();
1114 $ttl = $this->mTitle
->getDBkey();
1116 # If this is a comment, add the summary as headline
1117 if($comment && $summary!="") {
1118 $text="== {$summary} ==\n\n".$text;
1120 $text = $this->preSaveTransform( $text );
1121 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1122 $now = wfTimestampNow();
1124 $dbw =& wfGetDB( DB_MASTER
);
1126 # Add the page record; stake our claim on this title!
1127 $newid = $this->insertOn( $dbw );
1129 # Save the revision text...
1130 $revision = new Revision( array(
1132 'comment' => $summary,
1133 'minor_edit' => $isminor,
1136 $revisionId = $revision->insertOn( $dbw );
1138 $this->mTitle
->resetArticleID( $newid );
1140 # Update the page record with revision data
1141 $this->updateRevisionOn( $dbw, $revision, 0 );
1143 Article
::onArticleCreate( $this->mTitle
);
1145 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1146 '', strlen( $text ), $revisionId );
1150 if(!$this->mTitle
->userIsWatching()) $this->watch();
1152 if ( $this->mTitle
->userIsWatching() ) {
1157 # The talk page isn't in the regular link tables, so we need to update manually:
1158 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1159 $dbw->update( 'page',
1160 array( 'page_touched' => $dbw->timestamp($now) ),
1161 array( 'page_namespace' => $talkns,
1162 'page_title' => $ttl ),
1165 # standard deferred updates
1166 $this->editUpdates( $text, $summary, $isminor, $now );
1168 $oldid = 0; # new article
1169 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid, $revisionId );
1171 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1173 $watchthis, NULL ) );
1174 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1176 $watchthis, NULL ) );
1177 wfProfileOut( $fname );
1180 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1181 $this->replaceSection( $section, $text, $summary, $edittime );
1185 * @return string Complete article text, or null if error
1187 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1188 $fname = 'Article::replaceSection';
1189 wfProfileIn( $fname );
1191 if ($section != '') {
1192 if( is_null( $edittime ) ) {
1193 $rev = Revision
::newFromTitle( $this->mTitle
);
1195 $dbw =& wfGetDB( DB_MASTER
);
1196 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1198 if( is_null( $rev ) ) {
1199 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1200 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1203 $oldtext = $rev->getText();
1205 if($section=='new') {
1206 if($summary) $subject="== {$summary} ==\n\n";
1207 $text=$oldtext."\n\n".$subject.$text;
1210 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1211 # comments to be stripped as well)
1212 $striparray=array();
1213 $parser=new Parser();
1214 $parser->mOutputType
=OT_WIKI
;
1215 $parser->mOptions
= new ParserOptions();
1216 $oldtext=$parser->strip($oldtext, $striparray, true);
1218 # now that we can be sure that no pseudo-sections are in the source,
1220 # Unfortunately we can't simply do a preg_replace because that might
1221 # replace the wrong section, so we have to use the section counter instead
1222 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1223 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1224 $secs[$section*2]=$text."\n\n"; // replace with edited
1226 # section 0 is top (intro) section
1229 # headline of old section - we need to go through this section
1230 # to determine if there are any subsections that now need to
1231 # be erased, as the mother section has been replaced with
1232 # the text of all subsections.
1233 $headline=$secs[$section*2-1];
1234 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1235 $hlevel=$matches[1];
1237 # determine headline level for wikimarkup headings
1238 if(strpos($hlevel,'=')!==false) {
1239 $hlevel=strlen($hlevel);
1242 $secs[$section*2-1]=''; // erase old headline
1245 while(!empty($secs[$count*2-1]) && !$break) {
1247 $subheadline=$secs[$count*2-1];
1249 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1250 $subhlevel=$matches[1];
1251 if(strpos($subhlevel,'=')!==false) {
1252 $subhlevel=strlen($subhlevel);
1254 if($subhlevel > $hlevel) {
1255 // erase old subsections
1256 $secs[$count*2-1]='';
1259 if($subhlevel <= $hlevel) {
1267 $text=join('',$secs);
1268 # reinsert the stuff that we stripped out earlier
1269 $text=$parser->unstrip($text,$striparray);
1270 $text=$parser->unstripNoWiki($text,$striparray);
1274 wfProfileOut( $fname );
1279 * Change an existing article. Puts the previous version back into the old table, updates RC
1280 * and all necessary caches, mostly via the deferred update array.
1282 * It is possible to call this function from a command-line script, but note that you should
1283 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1285 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1286 global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
1287 global $wgPostCommitUpdateList, $wgUseFileCache;
1289 $fname = 'Article::updateArticle';
1290 wfProfileIn( $fname );
1293 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1295 &$watchthis, &$sectionanchor ) ) ) {
1296 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1297 wfProfileOut( $fname );
1301 $isminor = ( $minor && $wgUser->isLoggedIn() );
1302 if ( $this->isRedirect( $text ) ) {
1303 # Remove all content but redirect
1304 # This could be done by reconstructing the redirect from a title given by
1305 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1307 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1309 $text = $m[1] . "\n";
1312 else { $redir = 0; }
1314 $text = $this->preSaveTransform( $text );
1315 $dbw =& wfGetDB( DB_MASTER
);
1316 $now = wfTimestampNow();
1318 # Update article, but only if changed.
1320 # It's important that we either rollback or complete, otherwise an attacker could
1321 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1322 # could conceivably have the same effect, especially if cur is locked for long periods.
1323 if( !$wgDBtransactions ) {
1324 $userAbort = ignore_user_abort( true );
1327 $oldtext = $this->getContent( true );
1328 $oldsize = strlen( $oldtext );
1329 $newsize = strlen( $text );
1333 if ( 0 != strcmp( $text, $oldtext ) ) {
1334 $this->mGoodAdjustment
= $this->isCountable( $text )
1335 - $this->isCountable( $oldtext );
1336 $this->mTotalAdjustment
= 0;
1337 $now = wfTimestampNow();
1339 $lastRevision = $dbw->selectField(
1340 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1342 $revision = new Revision( array(
1343 'page' => $this->getId(),
1344 'comment' => $summary,
1345 'minor_edit' => $isminor,
1349 $dbw->immediateCommit();
1351 $revisionId = $revision->insertOn( $dbw );
1354 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1357 /* Belated edit conflict! Run away!! */
1361 # Update recentchanges and purge cache and whatnot
1362 $bot = (int)($wgUser->isBot() ||
$forceBot);
1363 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1364 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1368 // Update caches outside the main transaction
1369 Article
::onArticleEdit( $this->mTitle
);
1373 if( !$wgDBtransactions ) {
1374 ignore_user_abort( $userAbort );
1379 if (!$this->mTitle
->userIsWatching()) {
1380 $dbw->immediateCommit();
1386 if ( $this->mTitle
->userIsWatching() ) {
1387 $dbw->immediateCommit();
1393 # standard deferred updates
1394 $this->editUpdates( $text, $summary, $minor, $now );
1397 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
1399 wfRunHooks( 'ArticleSaveComplete',
1400 array( &$this, &$wgUser, $text,
1402 $watchthis, $sectionanchor ) );
1403 wfProfileOut( $fname );
1408 * After we've either updated or inserted the article, update
1409 * the link tables and redirect to the new page.
1411 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
1412 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache;
1413 global $wgUseEnotif;
1415 $fname = 'Article::showArticle';
1416 wfProfileIn( $fname );
1418 $wgLinkCache = new LinkCache();
1420 if ( !$wgUseDumbLinkUpdate ) {
1421 # Preload links to reduce lock time
1422 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1423 $wgLinkCache->preFill( $this->mTitle
);
1424 $wgLinkCache->clear();
1428 # Parse the text and save it to the parser cache
1429 $wgOut = new OutputPage();
1430 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
1431 $wgOut->setRevisionId( $newid );
1432 $wgOut->addPrimaryWikiText( $text, $this );
1434 if ( !$wgUseDumbLinkUpdate ) {
1435 # Move the current links back to the second register
1436 $wgLinkCache->swapRegisters();
1438 # Get old version of link table to allow incremental link updates
1439 # Lock this data now since it is needed for an update
1440 $wgLinkCache->forUpdate( true );
1441 $wgLinkCache->preFill( $this->mTitle
);
1443 # Swap this old version back into its rightful place
1444 $wgLinkCache->swapRegisters();
1447 if( $this->isRedirect( $text ) )
1451 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1453 wfProfileOut( $fname );
1457 * Mark this particular edit as patrolled
1459 function markpatrolled() {
1460 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1461 $wgOut->setRobotpolicy( 'noindex,follow' );
1463 if ( !$wgUseRCPatrol )
1465 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1468 if ( $wgUser->isAnon() )
1470 $wgOut->loginToUse();
1473 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1475 $wgOut->sysopRequired();
1478 $rcid = $wgRequest->getVal( 'rcid' );
1479 if ( !is_null ( $rcid ) )
1481 RecentChange
::markPatrolled( $rcid );
1482 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1483 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1485 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1486 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1490 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1495 * Add this page to $wgUser's watchlist
1500 global $wgUser, $wgOut;
1502 if ( $wgUser->isAnon() ) {
1503 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1506 if ( wfReadOnly() ) {
1507 $wgOut->readOnlyPage();
1511 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1513 $wgUser->addWatch( $this->mTitle
);
1514 $wgUser->saveSettings();
1516 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1518 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1519 $wgOut->setRobotpolicy( 'noindex,follow' );
1521 $link = $this->mTitle
->getPrefixedText();
1522 $text = wfMsg( 'addedwatchtext', $link );
1523 $wgOut->addWikiText( $text );
1526 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1530 * Stop watching a page
1533 function unwatch() {
1535 global $wgUser, $wgOut;
1537 if ( $wgUser->isAnon() ) {
1538 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1541 if ( wfReadOnly() ) {
1542 $wgOut->readOnlyPage();
1546 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1548 $wgUser->removeWatch( $this->mTitle
);
1549 $wgUser->saveSettings();
1551 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1553 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1554 $wgOut->setRobotpolicy( 'noindex,follow' );
1556 $link = $this->mTitle
->getPrefixedText();
1557 $text = wfMsg( 'removedwatchtext', $link );
1558 $wgOut->addWikiText( $text );
1561 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1565 * action=protect handler
1567 function protect() {
1568 require_once 'ProtectionForm.php';
1569 $form = new ProtectionForm( $this );
1574 * action=unprotect handler (alias)
1576 function unprotect() {
1581 * Update the article's restriction field, and leave a log entry.
1583 * @param array $limit set of restriction keys
1584 * @param string $reason
1585 * @return bool true on success
1587 function updateRestrictions( $limit = array(), $reason = '' ) {
1588 global $wgUser, $wgOut, $wgRequest;
1590 if ( !$wgUser->isAllowed( 'protect' ) ) {
1594 if( wfReadOnly() ) {
1598 $id = $this->mTitle
->getArticleID();
1603 $flat = Article
::flattenRestrictions( $limit );
1604 $protecting = ($flat != '');
1606 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser,
1607 $limit, $reason ) ) ) {
1609 $dbw =& wfGetDB( DB_MASTER
);
1610 $dbw->update( 'page',
1612 'page_touched' => $dbw->timestamp(),
1613 'page_restrictions' => $flat
1614 ), array( /* WHERE */
1616 ), 'Article::protect'
1619 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser,
1620 $limit, $reason ) );
1622 $log = new LogPage( 'protect' );
1624 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$flat]" ) );
1626 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1633 * Take an array of page restrictions and flatten it to a string
1634 * suitable for insertion into the page_restrictions field.
1635 * @param array $limit
1639 function flattenRestrictions( $limit ) {
1640 if( !is_array( $limit ) ) {
1641 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1644 foreach( $limit as $action => $restrictions ) {
1645 if( $restrictions != '' ) {
1646 $bits[] = "$action=$restrictions";
1649 return implode( ':', $bits );
1653 * UI entry point for page deletion
1656 global $wgUser, $wgOut, $wgRequest;
1657 $fname = 'Article::delete';
1658 $confirm = $wgRequest->wasPosted() &&
1659 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1660 $reason = $wgRequest->getText( 'wpReason' );
1662 # This code desperately needs to be totally rewritten
1665 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1666 $wgOut->sysopRequired();
1669 if( wfReadOnly() ) {
1670 $wgOut->readOnlyPage();
1674 # Better double-check that it hasn't been deleted yet!
1675 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1676 if( !$this->mTitle
->exists() ) {
1677 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1682 $this->doDelete( $reason );
1686 # determine whether this page has earlier revisions
1687 # and insert a warning if it does
1688 # we select the text because it might be useful below
1689 $dbr =& $this->getDB();
1690 $ns = $this->mTitle
->getNamespace();
1691 $title = $this->mTitle
->getDBkey();
1692 $revisions = $dbr->select( array( 'page', 'revision' ),
1693 array( 'rev_id', 'rev_user_text' ),
1695 'page_namespace' => $ns,
1696 'page_title' => $title,
1697 'rev_page = page_id'
1698 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1701 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1702 $skin=$wgUser->getSkin();
1703 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1704 $wgOut->addHTML( $skin->historyLink() .'</b>');
1708 $rev = Revision
::newFromTitle( $this->mTitle
);
1710 # Fetch name(s) of contributors
1712 $all_same_user = true;
1713 while( $row = $dbr->fetchObject( $revisions ) ) {
1714 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1715 $all_same_user = false;
1717 $rev_name = $row->rev_user_text
;
1721 if( !is_null( $rev ) ) {
1722 # if this is a mini-text, we can paste part of it into the deletion reason
1723 $text = $rev->getText();
1725 #if this is empty, an earlier revision may contain "useful" text
1728 $prev = $rev->getPrevious();
1730 $text = $prev->getText();
1735 $length = strlen( $text );
1737 # this should not happen, since it is not possible to store an empty, new
1738 # page. Let's insert a standard text in case it does, though
1739 if( $length == 0 && $reason === '' ) {
1740 $reason = wfMsgForContent( 'exblank' );
1743 if( $length < 500 && $reason === '' ) {
1744 # comment field=255, let's grep the first 150 to have some user
1747 $text = $wgContLang->truncate( $text, 150, '...' );
1749 # let's strip out newlines
1750 $text = preg_replace( "/[\n\r]/", '', $text );
1753 if( !$all_same_user ) {
1754 $reason = wfMsgForContent( 'excontent', $text );
1756 $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
1759 $reason = wfMsgForContent( 'exbeforeblank', $text );
1764 return $this->confirmDelete( '', $reason );
1768 * Output deletion confirmation dialog
1770 function confirmDelete( $par, $reason ) {
1771 global $wgOut, $wgUser;
1773 wfDebug( "Article::confirmDelete\n" );
1775 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1776 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1777 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1778 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1780 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1782 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1783 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1784 $token = htmlspecialchars( $wgUser->editToken() );
1787 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1791 <label for='wpReason'>{$delcom}:</label>
1794 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1800 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1804 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1807 $wgOut->returnToMain( false );
1812 * Perform a deletion and output success or failure messages
1814 function doDelete( $reason ) {
1815 global $wgOut, $wgUser, $wgContLang;
1816 $fname = 'Article::doDelete';
1817 wfDebug( $fname."\n" );
1819 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1820 if ( $this->doDeleteArticle( $reason ) ) {
1821 $deleted = $this->mTitle
->getPrefixedText();
1823 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1824 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1826 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1827 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1829 $wgOut->addWikiText( $text );
1830 $wgOut->returnToMain( false );
1831 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1833 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1839 * Back-end article deletion
1840 * Deletes the article with database consistency, writes logs, purges caches
1843 function doDeleteArticle( $reason ) {
1844 global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
1845 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1847 $fname = 'Article::doDeleteArticle';
1848 wfDebug( $fname."\n" );
1850 $dbw =& wfGetDB( DB_MASTER
);
1851 $ns = $this->mTitle
->getNamespace();
1852 $t = $this->mTitle
->getDBkey();
1853 $id = $this->mTitle
->getArticleID();
1855 if ( $t == '' ||
$id == 0 ) {
1859 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1860 array_push( $wgDeferredUpdateList, $u );
1862 $linksTo = $this->mTitle
->getLinksTo();
1865 if ( $wgUseSquid ) {
1867 $this->mTitle
->getInternalURL(),
1868 $this->mTitle
->getInternalURL( 'history' )
1871 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1872 array_push( $wgPostCommitUpdateList, $u );
1876 # Client and file cache invalidation
1877 Title
::touchArray( $linksTo );
1880 // For now, shunt the revision data into the archive table.
1881 // Text is *not* removed from the text table; bulk storage
1882 // is left intact to avoid breaking block-compression or
1883 // immutable storage schemes.
1885 // For backwards compatibility, note that some older archive
1886 // table entries will have ar_text and ar_flags fields still.
1888 // In the future, we may keep revisions and mark them with
1889 // the rev_deleted field, which is reserved for this purpose.
1890 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1892 'ar_namespace' => 'page_namespace',
1893 'ar_title' => 'page_title',
1894 'ar_comment' => 'rev_comment',
1895 'ar_user' => 'rev_user',
1896 'ar_user_text' => 'rev_user_text',
1897 'ar_timestamp' => 'rev_timestamp',
1898 'ar_minor_edit' => 'rev_minor_edit',
1899 'ar_rev_id' => 'rev_id',
1900 'ar_text_id' => 'rev_text_id',
1903 'page_id = rev_page'
1907 # Now that it's safely backed up, delete it
1908 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1909 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1911 if ($wgUseTrackbacks)
1912 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1914 # Clean up recentchanges entries...
1915 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1917 # Finally, clean up the link tables
1918 $t = $this->mTitle
->getPrefixedDBkey();
1920 Article
::onArticleDelete( $this->mTitle
);
1922 # Delete outgoing links
1923 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1924 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1925 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1928 $log = new LogPage( 'delete' );
1929 $log->addEntry( 'delete', $this->mTitle
, $reason );
1931 # Clear the cached article id so the interface doesn't act like we exist
1932 $this->mTitle
->resetArticleID( 0 );
1933 $this->mTitle
->mArticleID
= 0;
1938 * Revert a modification
1940 function rollback() {
1941 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
1942 $fname = 'Article::rollback';
1944 if ( ! $wgUser->isAllowed('rollback') ) {
1945 $wgOut->sysopRequired();
1948 if ( wfReadOnly() ) {
1949 $wgOut->readOnlyPage( $this->getContent( true ) );
1952 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
1953 array( $this->mTitle
->getPrefixedText(),
1954 $wgRequest->getVal( 'from' ) ) ) ) {
1955 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1956 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
1959 $dbw =& wfGetDB( DB_MASTER
);
1961 # Enhanced rollback, marks edits rc_bot=1
1962 $bot = $wgRequest->getBool( 'bot' );
1964 # Replace all this user's current edits with the next one down
1965 $tt = $this->mTitle
->getDBKey();
1966 $n = $this->mTitle
->getNamespace();
1968 # Get the last editor, lock table exclusively
1970 $current = Revision
::newFromTitle( $this->mTitle
);
1971 if( is_null( $current ) ) {
1972 # Something wrong... no page?
1974 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1978 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1979 if( $from != $current->getUserText() ) {
1980 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
1981 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1982 htmlspecialchars( $this->mTitle
->getPrefixedText()),
1983 htmlspecialchars( $from ),
1984 htmlspecialchars( $current->getUserText() ) ) );
1985 if( $current->getComment() != '') {
1987 wfMsg( 'editcomment',
1988 htmlspecialchars( $current->getComment() ) ) );
1993 # Get the last edit not by this guy
1994 $user = intval( $current->getUser() );
1995 $user_text = $dbw->addQuotes( $current->getUserText() );
1996 $s = $dbw->selectRow( 'revision',
1997 array( 'rev_id', 'rev_timestamp' ),
1999 'rev_page' => $current->getPage(),
2000 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2003 'USE INDEX' => 'page_timestamp',
2004 'ORDER BY' => 'rev_timestamp DESC' )
2006 if( $s === false ) {
2009 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2010 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2016 # Mark all reverted edits as bot
2019 if ( $wgUseRCPatrol ) {
2020 # Mark all reverted edits as patrolled
2021 $set['rc_patrolled'] = 1;
2025 $dbw->update( 'recentchanges', $set,
2027 'rc_cur_id' => $current->getPage(),
2028 'rc_user_text' => $current->getUserText(),
2029 "rc_timestamp > '{$s->rev_timestamp}'",
2034 # Get the edit summary
2035 $target = Revision
::newFromId( $s->rev_id
);
2036 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2037 $newComment = $wgRequest->getText( 'summary', $newComment );
2040 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2041 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2042 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2044 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2045 Article
::onArticleEdit( $this->mTitle
);
2048 $wgOut->returnToMain( false );
2053 * Do standard deferred updates after page view
2056 function viewUpdates() {
2057 global $wgDeferredUpdateList;
2059 if ( 0 != $this->getID() ) {
2060 global $wgDisableCounters;
2061 if( !$wgDisableCounters ) {
2062 Article
::incViewCount( $this->getID() );
2063 $u = new SiteStatsUpdate( 1, 0, 0 );
2064 array_push( $wgDeferredUpdateList, $u );
2068 # Update newtalk / watchlist notification status
2070 $wgUser->clearNotification( $this->mTitle
);
2074 * Do standard deferred updates after page edit.
2075 * Every 1000th edit, prune the recent changes table.
2077 * @param string $text
2079 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2080 global $wgDeferredUpdateList, $wgMessageCache, $wgUser;
2082 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2084 if ( 0 == mt_rand( 0, 999 ) ) {
2085 # Periodically flush old entries from the recentchanges table.
2088 $dbw =& wfGetDB( DB_MASTER
);
2089 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2090 $recentchanges = $dbw->tableName( 'recentchanges' );
2091 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2092 $dbw->query( $sql );
2096 $id = $this->getID();
2097 $title = $this->mTitle
->getPrefixedDBkey();
2098 $shortTitle = $this->mTitle
->getDBkey();
2101 $u = new LinksUpdate( $id, $title );
2102 array_push( $wgDeferredUpdateList, $u );
2103 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2104 array_push( $wgDeferredUpdateList, $u );
2105 $u = new SearchUpdate( $id, $title, $text );
2106 array_push( $wgDeferredUpdateList, $u );
2108 # If this is another user's talk page, update newtalk
2110 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2111 $other = User
::newFromName( $shortTitle );
2112 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2113 // An anonymous user
2114 $other = new User();
2115 $other->setName( $shortTitle );
2118 $other->setNewtalk( true );
2122 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2123 $wgMessageCache->replace( $shortTitle, $text );
2129 * @todo document this function
2131 * @param string $oldid Revision ID of this article revision
2133 function setOldSubtitle( $oldid=0 ) {
2134 global $wgLang, $wgOut, $wgUser;
2136 $current = ( $oldid == $this->mLatest
);
2137 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2138 $sk = $wgUser->getSkin();
2140 ?
wfMsg( 'currentrevisionlink' )
2141 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2142 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2143 $nextlink = $current
2144 ?
wfMsg( 'nextrevision' )
2145 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2146 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2147 $wgOut->setSubtitle( $r );
2151 * This function is called right before saving the wikitext,
2152 * so we can do things like signatures and links-in-context.
2154 * @param string $text
2156 function preSaveTransform( $text ) {
2157 global $wgParser, $wgUser;
2158 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2161 /* Caching functions */
2164 * checkLastModified returns true if it has taken care of all
2165 * output to the client that is necessary for this request.
2166 * (that is, it has sent a cached version of the page)
2168 function tryFileCache() {
2169 static $called = false;
2171 wfDebug( " tryFileCache() -- called twice!?\n" );
2175 if($this->isFileCacheable()) {
2176 $touched = $this->mTouched
;
2177 $cache = new CacheManager( $this->mTitle
);
2178 if($cache->isFileCacheGood( $touched )) {
2180 wfDebug( " tryFileCache() - about to load\n" );
2181 $cache->loadFromFileCache();
2184 wfDebug( " tryFileCache() - starting buffer\n" );
2185 ob_start( array(&$cache, 'saveToFileCache' ) );
2188 wfDebug( " tryFileCache() - not cacheable\n" );
2193 * Check if the page can be cached
2196 function isFileCacheable() {
2197 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2198 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2200 return $wgUseFileCache
2201 and (!$wgShowIPinHeader)
2202 and ($this->getID() != 0)
2203 and ($wgUser->isAnon())
2204 and (!$wgUser->getNewtalk())
2205 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2206 and (empty( $action ) ||
$action == 'view')
2207 and (!isset($oldid))
2209 and (!isset($redirect))
2210 and (!isset($printable))
2211 and (!$this->mRedirectedFrom
);
2215 * Loads cur_touched and returns a value indicating if it should be used
2218 function checkTouched() {
2219 $fname = 'Article::checkTouched';
2220 if( !$this->mDataLoaded
) {
2221 $dbr =& $this->getDB();
2222 $data = $this->pageDataFromId( $dbr, $this->getId() );
2224 $this->loadPageData( $data );
2227 return !$this->mIsRedirect
;
2231 * Edit an article without doing all that other stuff
2232 * The article must already exist; link tables etc
2233 * are not updated, caches are not flushed.
2235 * @param string $text text submitted
2236 * @param string $comment comment submitted
2237 * @param bool $minor whereas it's a minor modification
2239 function quickEdit( $text, $comment = '', $minor = 0 ) {
2240 $fname = 'Article::quickEdit';
2241 wfProfileIn( $fname );
2243 $dbw =& wfGetDB( DB_MASTER
);
2245 $revision = new Revision( array(
2246 'page' => $this->getId(),
2248 'comment' => $comment,
2249 'minor_edit' => $minor ?
1 : 0,
2251 $revisionId = $revision->insertOn( $dbw );
2252 $this->updateRevisionOn( $dbw, $revision );
2255 wfProfileOut( $fname );
2259 * Used to increment the view counter
2262 * @param integer $id article id
2264 function incViewCount( $id ) {
2265 $id = intval( $id );
2266 global $wgHitcounterUpdateFreq;
2268 $dbw =& wfGetDB( DB_MASTER
);
2269 $pageTable = $dbw->tableName( 'page' );
2270 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2271 $acchitsTable = $dbw->tableName( 'acchits' );
2273 if( $wgHitcounterUpdateFreq <= 1 ){ //
2274 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2278 # Not important enough to warrant an error page in case of failure
2279 $oldignore = $dbw->ignoreErrors( true );
2281 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2283 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2284 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2285 # Most of the time (or on SQL errors), skip row count check
2286 $dbw->ignoreErrors( $oldignore );
2290 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2291 $row = $dbw->fetchObject( $res );
2292 $rown = intval( $row->n
);
2293 if( $rown >= $wgHitcounterUpdateFreq ){
2294 wfProfileIn( 'Article::incViewCount-collect' );
2295 $old_user_abort = ignore_user_abort( true );
2297 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2298 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2299 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2301 $dbw->query("DELETE FROM $hitcounterTable");
2302 $dbw->query('UNLOCK TABLES');
2303 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2304 'WHERE page_id = hc_id');
2305 $dbw->query("DROP TABLE $acchitsTable");
2307 ignore_user_abort( $old_user_abort );
2308 wfProfileOut( 'Article::incViewCount-collect' );
2310 $dbw->ignoreErrors( $oldignore );
2314 * The onArticle*() functions are supposed to be a kind of hooks
2315 * which should be called whenever any of the specified actions
2318 * This is a good place to put code to clear caches, for instance.
2320 * This is called on page move and undelete, as well as edit
2322 * @param $title_obj a title object
2325 function onArticleCreate($title_obj) {
2326 global $wgUseSquid, $wgPostCommitUpdateList;
2328 $title_obj->touchLinks();
2329 $titles = $title_obj->getLinksTo();
2332 if ( $wgUseSquid ) {
2333 $urls = $title_obj->getSquidURLs();
2334 foreach ( $titles as $linkTitle ) {
2335 $urls[] = $linkTitle->getInternalURL();
2337 $u = new SquidUpdate( $urls );
2338 array_push( $wgPostCommitUpdateList, $u );
2342 function onArticleDelete( $title ) {
2343 global $wgMessageCache;
2345 $title->touchLinks();
2347 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2348 $wgMessageCache->replace( $title->getDBkey(), false );
2353 * Purge caches on page update etc
2355 function onArticleEdit( $title ) {
2356 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2360 // Template namespace? Purge all articles linking here.
2361 // FIXME: When a templatelinks table arrives, use it for all includes.
2362 if ( $title->getNamespace() == NS_TEMPLATE
) {
2363 $titles = $title->getLinksTo();
2364 Title
::touchArray( $titles );
2365 if ( $wgUseSquid ) {
2366 foreach ( $titles as $link ) {
2367 $urls[] = $link->getInternalURL();
2373 if ( $wgUseSquid ) {
2374 $urls = array_merge( $urls, $title->getSquidURLs() );
2375 $u = new SquidUpdate( $urls );
2376 array_push( $wgPostCommitUpdateList, $u );
2380 if ( $wgUseFileCache ) {
2381 $cm = new CacheManager( $title );
2382 @unlink
( $cm->fileCacheName() );
2389 * Info about this page
2390 * Called for ?action=info when $wgAllowPageInfo is on.
2395 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2396 $fname = 'Article::info';
2398 if ( !$wgAllowPageInfo ) {
2399 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2403 $page = $this->mTitle
->getSubjectPage();
2405 $wgOut->setPagetitle( $page->getPrefixedText() );
2406 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2408 # first, see if the page exists at all.
2409 $exists = $page->getArticleId() != 0;
2411 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2412 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2414 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2417 $dbr =& $this->getDB( DB_SLAVE
);
2419 'wl_title' => $page->getDBkey(),
2420 'wl_namespace' => $page->getNamespace() );
2421 $numwatchers = $dbr->selectField(
2426 $this->getSelectOptions() );
2428 $pageInfo = $this->pageCountInfo( $page );
2429 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2431 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2432 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2434 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2436 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2438 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2440 $wgOut->addHTML( '</ul>' );
2446 * Return the total number of edits and number of unique editors
2447 * on a given page. If page does not exist, returns false.
2449 * @param Title $title
2453 function pageCountInfo( $title ) {
2454 $id = $title->getArticleId();
2459 $dbr =& $this->getDB( DB_SLAVE
);
2461 $rev_clause = array( 'rev_page' => $id );
2462 $fname = 'Article::pageCountInfo';
2464 $edits = $dbr->selectField(
2469 $this->getSelectOptions() );
2471 $authors = $dbr->selectField(
2473 'COUNT(DISTINCT rev_user_text)',
2476 $this->getSelectOptions() );
2478 return array( 'edits' => $edits, 'authors' => $authors );
2482 * Return a list of templates used by this article.
2483 * Uses the links table to find the templates
2487 function getUsedTemplates() {
2489 $id = $this->mTitle
->getArticleID();
2491 $db =& wfGetDB( DB_SLAVE
);
2492 $res = $db->select( array( 'pagelinks' ),
2493 array( 'pl_title' ),
2496 'pl_namespace' => NS_TEMPLATE
),
2497 'Article:getUsedTemplates' );
2498 if ( false !== $res ) {
2499 if ( $db->numRows( $res ) ) {
2500 while ( $row = $db->fetchObject( $res ) ) {
2501 $result[] = $row->pl_title
;
2505 $db->freeResult( $res );