8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
13 * Class representing a MediaWiki article and history.
15 * See design.txt for an overview.
16 * Note: edit user interface and cache support functions have been
17 * moved to separate EditPage and CacheManager classes.
27 var $mContentLoaded; //!<
30 var $mGoodAdjustment; //!<
34 var $mRedirectedFrom; //!<
35 var $mRedirectUrl; //!<
36 var $mRevIdFetched; //!<
40 var $mTotalAdjustment; //!<
47 * Constructor and clear the article
48 * @param $title Reference to a Title object.
49 * @param $oldId Integer revision ID, null to fetch from request, zero for current
51 function Article( &$title, $oldId = null ) {
52 $this->mTitle
=& $title;
53 $this->mOldId
= $oldId;
58 * Tell the page view functions that this view was redirected
59 * from another page on the wiki.
60 * @param $from Title object.
62 function setRedirectedFrom( $from ) {
63 $this->mRedirectedFrom
= $from;
67 * @return mixed false, Title of in-wiki target, or string with URL
69 function followRedirect() {
70 $text = $this->getContent();
71 $rt = Title
::newFromRedirect( $text );
73 # process if title object is valid and not special:userlogout
75 if( $rt->getInterwiki() != '' ) {
76 if( $rt->isLocal() ) {
77 // Offsite wikis need an HTTP redirect.
79 // This can be hard to reverse and may produce loops,
80 // so they may be disabled in the site configuration.
82 $source = $this->mTitle
->getFullURL( 'redirect=no' );
83 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
86 if( $rt->getNamespace() == NS_SPECIAL
) {
87 // Gotta hand redirects to special pages differently:
88 // Fill the HTTP response "Location" header and ignore
89 // the rest of the page we're on.
91 // This can be hard to reverse, so they may be disabled.
93 if( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) {
96 return $rt->getFullURL();
103 // No or invalid redirect
108 * get the title object of the article
110 function getTitle() {
111 return $this->mTitle
;
119 $this->mDataLoaded
= false;
120 $this->mContentLoaded
= false;
122 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
123 $this->mRedirectedFrom
= null; # Title object if set
125 $this->mTimestamp
= $this->mComment
= '';
126 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
127 $this->mTouched
= '19700101000000';
128 $this->mForUpdate
= false;
129 $this->mIsRedirect
= false;
130 $this->mRevIdFetched
= 0;
131 $this->mRedirectUrl
= false;
132 $this->mLatest
= false;
136 * Note that getContent/loadContent do not follow redirects anymore.
137 * If you need to fetch redirectable content easily, try
138 * the shortcut in Article::followContent()
140 * @todo There are still side-effects in this!
141 * In general, you should use the Revision class, not Article,
142 * to fetch text for purposes other than page views.
144 * @return Return the text of this revision
146 function getContent() {
147 global $wgRequest, $wgUser, $wgOut;
149 wfProfileIn( __METHOD__
);
151 if ( 0 == $this->getID() ) {
152 wfProfileOut( __METHOD__
);
153 $wgOut->setRobotpolicy( 'noindex,nofollow' );
155 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
156 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
158 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
161 return "<div class='noarticletext'>$ret</div>";
163 $this->loadContent();
164 wfProfileOut( __METHOD__
);
165 return $this->mContent
;
170 * This function returns the text of a section, specified by a number ($section).
171 * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
172 * the first section before any such heading (section 0).
174 * If a section contains subsections, these are also returned.
176 * @param $text String: text to look in
177 * @param $section Integer: section number
178 * @return string text of the requested section
181 function getSection($text,$section) {
183 return $wgParser->getSection( $text, $section );
187 * @return int The oldid of the article that is to be shown, 0 for the
190 function getOldID() {
191 if ( is_null( $this->mOldId
) ) {
192 $this->mOldId
= $this->getOldIDFromRequest();
194 return $this->mOldId
;
198 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
200 * @return int The old id for the request
202 function getOldIDFromRequest() {
204 $this->mRedirectUrl
= false;
205 $oldid = $wgRequest->getVal( 'oldid' );
206 if ( isset( $oldid ) ) {
207 $oldid = intval( $oldid );
208 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
209 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
213 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
215 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
216 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
234 * Load the revision (including text) into this object
236 function loadContent() {
237 if ( $this->mContentLoaded
) return;
240 $oldid = $this->getOldID();
242 # Pre-fill content with error message so that if something
243 # fails we'll have something telling us what we intended.
245 $t = $this->mTitle
->getPrefixedText();
247 $this->mOldId
= $oldid;
248 $this->fetchContent( $oldid );
253 * Fetch a page record with the given conditions
254 * @param Database $dbr
255 * @param array $conditions
258 function pageData( &$dbr, $conditions ) {
271 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
272 $row = $dbr->selectRow( 'page',
275 'Article::pageData' );
276 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
281 * @param Database $dbr
282 * @param Title $title
284 function pageDataFromTitle( &$dbr, $title ) {
285 return $this->pageData( $dbr, array(
286 'page_namespace' => $title->getNamespace(),
287 'page_title' => $title->getDBkey() ) );
291 * @param Database $dbr
294 function pageDataFromId( &$dbr, $id ) {
295 return $this->pageData( $dbr, array( 'page_id' => $id ) );
299 * Set the general counter, title etc data loaded from
302 * @param object $data
305 function loadPageData( $data = 'fromdb' ) {
306 if ( $data === 'fromdb' ) {
307 $dbr =& $this->getDB();
308 $data = $this->pageDataFromId( $dbr, $this->getId() );
311 $lc =& LinkCache
::singleton();
313 $lc->addGoodLinkObj( $data->page_id
, $this->mTitle
);
315 $this->mTitle
->mArticleID
= $data->page_id
;
316 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
317 $this->mTitle
->mRestrictionsLoaded
= true;
319 $this->mCounter
= $data->page_counter
;
320 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
321 $this->mIsRedirect
= $data->page_is_redirect
;
322 $this->mLatest
= $data->page_latest
;
324 if ( is_object( $this->mTitle
) ) {
325 $lc->addBadLinkObj( $this->mTitle
);
327 $this->mTitle
->mArticleID
= 0;
330 $this->mDataLoaded
= true;
334 * Get text of an article from database
335 * Does *NOT* follow redirects.
336 * @param int $oldid 0 for whatever the latest revision is
339 function fetchContent( $oldid = 0 ) {
340 if ( $this->mContentLoaded
) {
341 return $this->mContent
;
344 $dbr =& $this->getDB();
346 # Pre-fill content with error message so that if something
347 # fails we'll have something telling us what we intended.
348 $t = $this->mTitle
->getPrefixedText();
350 $t .= ',oldid='.$oldid;
352 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
355 $revision = Revision
::newFromId( $oldid );
356 if( is_null( $revision ) ) {
357 wfDebug( __METHOD__
." failed to retrieve specified revision, id $oldid\n" );
360 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
362 wfDebug( __METHOD__
." failed to get page data linked to revision id $oldid\n" );
365 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
366 $this->loadPageData( $data );
368 if( !$this->mDataLoaded
) {
369 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
371 wfDebug( __METHOD__
." failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
374 $this->loadPageData( $data );
376 $revision = Revision
::newFromId( $this->mLatest
);
377 if( is_null( $revision ) ) {
378 wfDebug( __METHOD__
." failed to retrieve current page, rev_id {$data->page_latest}\n" );
383 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
384 // We should instead work with the Revision object when we need it...
385 $this->mContent
= $revision->userCan( Revision
::DELETED_TEXT
) ?
$revision->getRawText() : "";
386 //$this->mContent = $revision->getText();
388 $this->mUser
= $revision->getUser();
389 $this->mUserText
= $revision->getUserText();
390 $this->mComment
= $revision->getComment();
391 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
393 $this->mRevIdFetched
= $revision->getID();
394 $this->mContentLoaded
= true;
395 $this->mRevision
=& $revision;
397 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
399 return $this->mContent
;
403 * Read/write accessor to select FOR UPDATE
405 * @param $x Mixed: FIXME
407 function forUpdate( $x = NULL ) {
408 return wfSetVar( $this->mForUpdate
, $x );
412 * Get the database which should be used for reads
417 $ret =& wfGetDB( DB_MASTER
);
422 * Get options for all SELECT statements
424 * @param $options Array: an optional options array which'll be appended to
426 * @return Array: options
428 function getSelectOptions( $options = '' ) {
429 if ( $this->mForUpdate
) {
430 if ( is_array( $options ) ) {
431 $options[] = 'FOR UPDATE';
433 $options = 'FOR UPDATE';
440 * @return int Page ID
443 if( $this->mTitle
) {
444 return $this->mTitle
->getArticleID();
451 * @return bool Whether or not the page exists in the database
454 return $this->getId() != 0;
458 * @return int The view count for the page
460 function getCount() {
461 if ( -1 == $this->mCounter
) {
462 $id = $this->getID();
466 $dbr =& wfGetDB( DB_SLAVE
);
467 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
468 'Article::getCount', $this->getSelectOptions() );
471 return $this->mCounter
;
475 * Determine whether a page would be suitable for being counted as an
476 * article in the site_stats table based on the title & its content
478 * @param $text String: text to analyze
481 function isCountable( $text ) {
482 global $wgUseCommaCount, $wgContentNamespaces;
484 $token = $wgUseCommaCount ?
',' : '[[';
486 array_search( $this->mTitle
->getNamespace(), $wgContentNamespaces ) !== false
487 && ! $this->isRedirect( $text )
488 && in_string( $token, $text );
492 * Tests if the article text represents a redirect
494 * @param $text String: FIXME
497 function isRedirect( $text = false ) {
498 if ( $text === false ) {
499 $this->loadContent();
500 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
502 $titleObj = Title
::newFromRedirect( $text );
504 return $titleObj !== NULL;
508 * Returns true if the currently-referenced revision is the current edit
509 * to this page (and it exists).
512 function isCurrent() {
513 return $this->exists() &&
514 isset( $this->mRevision
) &&
515 $this->mRevision
->isCurrent();
519 * Loads everything except the text
520 * This isn't necessary for all uses, so it's only done if needed.
523 function loadLastEdit() {
524 if ( -1 != $this->mUser
)
527 # New or non-existent articles have no user information
528 $id = $this->getID();
529 if ( 0 == $id ) return;
531 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
532 if( !is_null( $this->mLastRevision
) ) {
533 $this->mUser
= $this->mLastRevision
->getUser();
534 $this->mUserText
= $this->mLastRevision
->getUserText();
535 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
536 $this->mComment
= $this->mLastRevision
->getComment();
537 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
538 $this->mRevIdFetched
= $this->mLastRevision
->getID();
542 function getTimestamp() {
543 // Check if the field has been filled by ParserCache::get()
544 if ( !$this->mTimestamp
) {
545 $this->loadLastEdit();
547 return wfTimestamp(TS_MW
, $this->mTimestamp
);
551 $this->loadLastEdit();
555 function getUserText() {
556 $this->loadLastEdit();
557 return $this->mUserText
;
560 function getComment() {
561 $this->loadLastEdit();
562 return $this->mComment
;
565 function getMinorEdit() {
566 $this->loadLastEdit();
567 return $this->mMinorEdit
;
570 function getRevIdFetched() {
571 $this->loadLastEdit();
572 return $this->mRevIdFetched
;
576 * @todo Document, fixme $offset never used.
577 * @param $limit Integer: default 0.
578 * @param $offset Integer: default 0.
580 function getContributors($limit = 0, $offset = 0) {
581 # XXX: this is expensive; cache this info somewhere.
583 $title = $this->mTitle
;
585 $dbr =& wfGetDB( DB_SLAVE
);
586 $revTable = $dbr->tableName( 'revision' );
587 $userTable = $dbr->tableName( 'user' );
588 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
589 $ns = $title->getNamespace();
590 $user = $this->getUser();
591 $pageId = $this->getId();
593 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
594 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
595 WHERE rev_page = $pageId
596 AND rev_user != $user
597 GROUP BY rev_user, rev_user_text, user_real_name
598 ORDER BY timestamp DESC";
600 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
601 $sql .= ' '. $this->getSelectOptions();
603 $res = $dbr->query($sql, __METHOD__
);
605 while ( $line = $dbr->fetchObject( $res ) ) {
606 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
609 $dbr->freeResult($res);
614 * This is the default action of the script: just view the page of
618 global $wgUser, $wgOut, $wgRequest, $wgContLang;
619 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
620 global $wgUseTrackbacks, $wgNamespaceRobotPolicies;
621 $sk = $wgUser->getSkin();
623 wfProfileIn( __METHOD__
);
625 $parserCache =& ParserCache
::singleton();
626 $ns = $this->mTitle
->getNamespace(); # shortcut
628 # Get variables from query string
629 $oldid = $this->getOldID();
631 # getOldID may want us to redirect somewhere else
632 if ( $this->mRedirectUrl
) {
633 $wgOut->redirect( $this->mRedirectUrl
);
634 wfProfileOut( __METHOD__
);
638 $diff = $wgRequest->getVal( 'diff' );
639 $rcid = $wgRequest->getVal( 'rcid' );
640 $rdfrom = $wgRequest->getVal( 'rdfrom' );
642 $wgOut->setArticleFlag( true );
643 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
644 $policy = $wgNamespaceRobotPolicies[$ns];
646 $policy = 'index,follow';
648 $wgOut->setRobotpolicy( $policy );
650 # If we got diff and oldid in the query, we want to see a
651 # diff page instead of the article.
653 if ( !is_null( $diff ) ) {
654 require_once( 'DifferenceEngine.php' );
655 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
657 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
658 // DifferenceEngine directly fetched the revision:
659 $this->mRevIdFetched
= $de->mNewid
;
663 # Run view updates for current revision only
664 $this->viewUpdates();
666 wfProfileOut( __METHOD__
);
670 if ( empty( $oldid ) && $this->checkTouched() ) {
671 $wgOut->setETag($parserCache->getETag($this, $wgUser));
673 if( $wgOut->checkLastModified( $this->mTouched
) ){
674 wfProfileOut( __METHOD__
);
676 } else if ( $this->tryFileCache() ) {
677 # tell wgOut that output is taken care of
679 $this->viewUpdates();
680 wfProfileOut( __METHOD__
);
685 # Should the parser cache be used?
686 $pcache = $wgEnableParserCache &&
687 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
690 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
691 if ( $wgUser->getOption( 'stubthreshold' ) ) {
692 wfIncrStats( 'pcache_miss_stub' );
695 $wasRedirected = false;
696 if ( isset( $this->mRedirectedFrom
) ) {
697 // This is an internally redirected page view.
698 // We'll need a backlink to the source page for navigation.
699 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
700 $sk = $wgUser->getSkin();
701 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
702 $s = wfMsg( 'redirectedfrom', $redir );
703 $wgOut->setSubtitle( $s );
704 $wasRedirected = true;
706 } elseif ( !empty( $rdfrom ) ) {
707 // This is an externally redirected view, from some other wiki.
708 // If it was reported from a trusted site, supply a backlink.
709 global $wgRedirectSources;
710 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
711 $sk = $wgUser->getSkin();
712 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
713 $s = wfMsg( 'redirectedfrom', $redir );
714 $wgOut->setSubtitle( $s );
715 $wasRedirected = true;
721 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
725 if ( !$outputDone ) {
726 $text = $this->getContent();
727 if ( $text === false ) {
728 # Failed to load, replace text with error message
729 $t = $this->mTitle
->getPrefixedText();
731 $t .= ',oldid='.$oldid;
732 $text = wfMsg( 'missingarticle', $t );
734 $text = wfMsg( 'noarticletext', $t );
738 # Another whitelist check in case oldid is altering the title
739 if ( !$this->mTitle
->userCanRead() ) {
740 $wgOut->loginToUse();
745 # We're looking at an old revision
747 if ( !empty( $oldid ) ) {
748 $wgOut->setRobotpolicy( 'noindex,nofollow' );
749 if( is_null( $this->mRevision
) ) {
750 // FIXME: This would be a nice place to load the 'no such page' text.
752 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
753 if( $this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
754 if( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
755 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
756 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
759 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
760 // and we are allowed to see...
769 * @fixme: this hook doesn't work most of the time, as it doesn't
770 * trigger when the parser cache is used.
772 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
773 $wgOut->setRevisionId( $this->getRevIdFetched() );
774 # wrap user css and user js in pre and don't parse
775 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
778 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
780 $wgOut->addWikiText( wfMsg('clearyourcache'));
781 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
782 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
784 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
785 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
786 # Don't overwrite the subtitle if this was an old revision
787 if( !$wasRedirected && $this->isCurrent() ) {
788 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
790 $targetUrl = $rt->escapeLocalURL();
791 #Â fixme unused $titleText :
792 $titleText = htmlspecialchars( $rt->getPrefixedText() );
793 $link = $sk->makeLinkObj( $rt );
795 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
796 '<span class="redirectText">'.$link.'</span>' );
798 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
799 $wgOut->addParserOutputNoText( $parseout );
800 } else if ( $pcache ) {
801 # Display content and save to parser cache
802 $wgOut->addPrimaryWikiText( $text, $this );
804 # Display content, don't attempt to save to parser cache
805 # Don't show section-edit links on old revisions... this way lies madness.
806 if( !$this->isCurrent() ) {
807 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
809 # Display content and don't save to parser cache
810 $wgOut->addPrimaryWikiText( $text, $this, false );
812 if( !$this->isCurrent() ) {
813 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
817 /* title may have been set from the cache */
818 $t = $wgOut->getPageTitle();
820 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
823 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
824 if( $ns == NS_USER_TALK
&&
825 User
::isIP( $this->mTitle
->getText() ) ) {
826 $wgOut->addWikiText( wfMsg('anontalkpagetext') );
829 # If we have been passed an &rcid= parameter, we want to give the user a
830 # chance to mark this new article as patrolled.
831 if ( $wgUseRCPatrol && !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
833 "<div class='patrollink'>" .
834 wfMsg ( 'markaspatrolledlink',
835 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
842 if ($wgUseTrackbacks)
843 $this->addTrackbacks();
845 $this->viewUpdates();
846 wfProfileOut( __METHOD__
);
849 function addTrackbacks() {
850 global $wgOut, $wgUser;
852 $dbr =& wfGetDB(DB_SLAVE
);
854 /* FROM */ 'trackbacks',
855 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
856 /* WHERE */ array('tb_page' => $this->getID())
859 if (!$dbr->numrows($tbs))
863 while ($o = $dbr->fetchObject($tbs)) {
865 if ($wgUser->isAllowed( 'trackback' )) {
866 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
867 . $o->tb_id
. "&token=" . $wgUser->editToken());
868 $rmvtxt = wfMsg('trackbackremove', $delurl);
870 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
877 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
880 function deletetrackback() {
881 global $wgUser, $wgRequest, $wgOut, $wgTitle;
883 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
884 $wgOut->addWikitext(wfMsg('sessionfailure'));
888 if ((!$wgUser->isAllowed('delete'))) {
889 $wgOut->sysopRequired();
894 $wgOut->readOnlyPage();
898 $db =& wfGetDB(DB_MASTER
);
899 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
900 $wgTitle->invalidateCache();
901 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
907 $wgOut->setArticleBodyOnly(true);
912 * Handle action=purge
915 global $wgUser, $wgRequest, $wgOut;
917 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
918 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
922 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
923 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
924 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
925 $msg = str_replace( '$1',
926 "<form method=\"post\" action=\"$action\">\n" .
927 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
930 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
931 $wgOut->setRobotpolicy( 'noindex,nofollow' );
932 $wgOut->addHTML( $msg );
937 * Perform the actions of a page purging
941 // Invalidate the cache
942 $this->mTitle
->invalidateCache();
945 // Commit the transaction before the purge is sent
946 $dbw = wfGetDB( DB_MASTER
);
947 $dbw->immediateCommit();
950 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
957 * Insert a new empty page record for this article.
958 * This *must* be followed up by creating a revision
959 * and running $this->updateToLatest( $rev_id );
960 * or else the record will be left in a funky state.
961 * Best if all done inside a transaction.
963 * @param Database $dbw
964 * @param string $restrictions
965 * @return int The newly created page_id key
968 function insertOn( &$dbw, $restrictions = '' ) {
969 wfProfileIn( __METHOD__
);
971 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
972 $dbw->insert( 'page', array(
973 'page_id' => $page_id,
974 'page_namespace' => $this->mTitle
->getNamespace(),
975 'page_title' => $this->mTitle
->getDBkey(),
977 'page_restrictions' => $restrictions,
978 'page_is_redirect' => 0, # Will set this shortly...
980 'page_random' => wfRandom(),
981 'page_touched' => $dbw->timestamp(),
982 'page_latest' => 0, # Fill this in shortly...
983 'page_len' => 0, # Fill this in shortly...
985 $newid = $dbw->insertId();
987 $this->mTitle
->resetArticleId( $newid );
989 wfProfileOut( __METHOD__
);
994 * Update the page record to point to a newly saved revision.
996 * @param Database $dbw
997 * @param Revision $revision For ID number, and text used to set
998 length and redirect status fields
999 * @param int $lastRevision If given, will not overwrite the page field
1000 * when different from the currently set value.
1001 * Giving 0 indicates the new page flag should
1003 * @return bool true on success, false on failure
1006 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1007 wfProfileIn( __METHOD__
);
1009 $conditions = array( 'page_id' => $this->getId() );
1010 if( !is_null( $lastRevision ) ) {
1011 # An extra check against threads stepping on each other
1012 $conditions['page_latest'] = $lastRevision;
1015 $text = $revision->getText();
1016 $dbw->update( 'page',
1018 'page_latest' => $revision->getId(),
1019 'page_touched' => $dbw->timestamp(),
1020 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1021 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1022 'page_len' => strlen( $text ),
1027 wfProfileOut( __METHOD__
);
1028 return ( $dbw->affectedRows() != 0 );
1032 * If the given revision is newer than the currently set page_latest,
1033 * update the page record. Otherwise, do nothing.
1035 * @param Database $dbw
1036 * @param Revision $revision
1038 function updateIfNewerOn( &$dbw, $revision ) {
1039 wfProfileIn( __METHOD__
);
1041 $row = $dbw->selectRow(
1042 array( 'revision', 'page' ),
1043 array( 'rev_id', 'rev_timestamp' ),
1045 'page_id' => $this->getId(),
1046 'page_latest=rev_id' ),
1049 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1050 wfProfileOut( __METHOD__
);
1053 $prev = $row->rev_id
;
1055 # No or missing previous revision; mark the page as new
1059 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1060 wfProfileOut( __METHOD__
);
1065 * @return string Complete article text, or null if error
1067 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1068 wfProfileIn( __METHOD__
);
1070 if( $section == '' ) {
1071 // Whole-page edit; let the text through unmolested.
1073 if( is_null( $edittime ) ) {
1074 $rev = Revision
::newFromTitle( $this->mTitle
);
1076 $dbw =& wfGetDB( DB_MASTER
);
1077 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1079 if( is_null( $rev ) ) {
1080 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1081 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1084 $oldtext = $rev->getText();
1086 if($section=='new') {
1087 if($summary) $subject="== {$summary} ==\n\n";
1088 $text=$oldtext."\n\n".$subject.$text;
1091 $text = $wgParser->replaceSection( $oldtext, $section, $text );
1095 wfProfileOut( __METHOD__
);
1100 * @deprecated use Article::doEdit()
1102 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1103 $flags = EDIT_NEW | EDIT_DEFER_UPDATES |
1104 ( $isminor ? EDIT_MINOR
: 0 ) |
1105 ( $suppressRC ? EDIT_SUPPRESS_RC
: 0 );
1107 # If this is a comment, add the summary as headline
1108 if ( $comment && $summary != "" ) {
1109 $text = "== {$summary} ==\n\n".$text;
1112 $this->doEdit( $text, $summary, $flags );
1114 $dbw =& wfGetDB( DB_MASTER
);
1116 if (!$this->mTitle
->userIsWatching()) {
1122 if ( $this->mTitle
->userIsWatching() ) {
1128 $this->doRedirect( $this->isRedirect( $text ) );
1132 * @deprecated use Article::doEdit()
1134 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1135 $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES |
1136 ( $minor ? EDIT_MINOR
: 0 ) |
1137 ( $forceBot ? EDIT_FORCE_BOT
: 0 );
1139 $good = $this->doEdit( $text, $summary, $flags );
1141 $dbw =& wfGetDB( DB_MASTER
);
1143 if (!$this->mTitle
->userIsWatching()) {
1149 if ( $this->mTitle
->userIsWatching() ) {
1156 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
1164 * Change an existing article or create a new article. Updates RC and all necessary caches,
1165 * optionally via the deferred update array.
1167 * $wgUser must be set before calling this function.
1169 * @param string $text New text
1170 * @param string $summary Edit summary
1171 * @param integer $flags bitfield:
1173 * Article is known or assumed to be non-existent, create a new one
1175 * Article is known or assumed to be pre-existing, update it
1177 * Mark this edit minor, if the user is allowed to do so
1179 * Do not log the change in recentchanges
1181 * Mark the edit a "bot" edit regardless of user rights
1182 * EDIT_DEFER_UPDATES
1183 * Defer some of the updates until the end of index.php
1185 * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
1186 * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If
1187 * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
1188 * to be thrown from the Database. These two conditions are also possible with auto-detection due
1189 * to MediaWiki's performance-optimised locking strategy.
1191 * @return bool success
1193 function doEdit( $text, $summary, $flags = 0 ) {
1194 global $wgUser, $wgDBtransactions;
1196 wfProfileIn( __METHOD__
);
1199 if ( !($flags & EDIT_NEW
) && !($flags & EDIT_UPDATE
) ) {
1200 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
1202 $flags |
= EDIT_UPDATE
;
1208 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1209 &$summary, $flags & EDIT_MINOR
,
1210 null, null, &$flags ) ) )
1212 wfDebug( __METHOD__
. ": ArticleSave hook aborted save!\n" );
1213 wfProfileOut( __METHOD__
);
1217 # Silently ignore EDIT_MINOR if not allowed
1218 $isminor = ( $flags & EDIT_MINOR
) && $wgUser->isAllowed('minoredit');
1219 $bot = $wgUser->isAllowed( 'bot' ) ||
( $flags & EDIT_FORCE_BOT
);
1221 $text = $this->preSaveTransform( $text );
1223 $dbw =& wfGetDB( DB_MASTER
);
1224 $now = wfTimestampNow();
1226 if ( $flags & EDIT_UPDATE
) {
1227 # Update article, but only if changed.
1229 # Make sure the revision is either completely inserted or not inserted at all
1230 if( !$wgDBtransactions ) {
1231 $userAbort = ignore_user_abort( true );
1234 $oldtext = $this->getContent();
1235 $oldsize = strlen( $oldtext );
1236 $newsize = strlen( $text );
1240 if ( 0 != strcmp( $text, $oldtext ) ) {
1241 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1242 - (int)$this->isCountable( $oldtext );
1243 $this->mTotalAdjustment
= 0;
1245 $lastRevision = $dbw->selectField(
1246 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1248 if ( !$lastRevision ) {
1249 # Article gone missing
1250 wfDebug( __METHOD__
.": EDIT_UPDATE specified but article doesn't exist\n" );
1251 wfProfileOut( __METHOD__
);
1255 $revision = new Revision( array(
1256 'page' => $this->getId(),
1257 'comment' => $summary,
1258 'minor_edit' => $isminor,
1263 $revisionId = $revision->insertOn( $dbw );
1266 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1269 /* Belated edit conflict! Run away!! */
1273 # Update recentchanges
1274 if( !( $flags & EDIT_SUPPRESS_RC
) ) {
1275 $rcid = RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1276 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1279 # Mark as patrolled if the user can do so and has it set in their options
1280 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1281 RecentChange
::markPatrolled( $rcid );
1287 // Keep the same revision ID, but do some updates on it
1288 $revisionId = $this->getRevIdFetched();
1289 // Update page_touched, this is usually implicit in the page update
1290 // Other cache updates are done in onArticleEdit()
1291 $this->mTitle
->invalidateCache();
1294 if( !$wgDBtransactions ) {
1295 ignore_user_abort( $userAbort );
1299 # Invalidate cache of this article and all pages using this article
1300 # as a template. Partly deferred.
1301 Article
::onArticleEdit( $this->mTitle
);
1303 # Update links tables, site stats, etc.
1304 $changed = ( strcmp( $oldtext, $text ) != 0 );
1305 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
1308 # Create new article
1310 # Set statistics members
1311 # We work out if it's countable after PST to avoid counter drift
1312 # when articles are created with {{subst:}}
1313 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1314 $this->mTotalAdjustment
= 1;
1318 # Add the page record; stake our claim on this title!
1319 # This will fail with a database query exception if the article already exists
1320 $newid = $this->insertOn( $dbw );
1322 # Save the revision text...
1323 $revision = new Revision( array(
1325 'comment' => $summary,
1326 'minor_edit' => $isminor,
1329 $revisionId = $revision->insertOn( $dbw );
1331 $this->mTitle
->resetArticleID( $newid );
1333 # Update the page record with revision data
1334 $this->updateRevisionOn( $dbw, $revision, 0 );
1336 if( !( $flags & EDIT_SUPPRESS_RC
) ) {
1337 $rcid = RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, $bot,
1338 '', strlen( $text ), $revisionId );
1339 # Mark as patrolled if the user can and has the option set
1340 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1341 RecentChange
::markPatrolled( $rcid );
1346 # Update links, etc.
1347 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
1350 Article
::onArticleCreate( $this->mTitle
);
1352 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1353 $summary, $flags & EDIT_MINOR
,
1354 null, null, &$flags ) );
1357 if ( $good && !( $flags & EDIT_DEFER_UPDATES
) ) {
1361 wfRunHooks( 'ArticleSaveComplete',
1362 array( &$this, &$wgUser, $text,
1363 $summary, $flags & EDIT_MINOR
,
1364 null, null, &$flags ) );
1366 wfProfileOut( __METHOD__
);
1371 * @deprecated wrapper for doRedirect
1373 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1374 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
1378 * Output a redirect back to the article.
1379 * This is typically used after an edit.
1381 * @param boolean $noRedir Add redirect=no
1382 * @param string $sectionAnchor section to redirect to, including "#"
1384 function doRedirect( $noRedir = false, $sectionAnchor = '' ) {
1387 $query = 'redirect=no';
1391 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) . $sectionAnchor );
1395 * Mark this particular edit as patrolled
1397 function markpatrolled() {
1398 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
1399 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1401 # Check RC patrol config. option
1402 if( !$wgUseRCPatrol ) {
1403 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1408 if( !$wgUser->isAllowed( 'patrol' ) ) {
1409 $wgOut->permissionRequired( 'patrol' );
1413 $rcid = $wgRequest->getVal( 'rcid' );
1414 if ( !is_null ( $rcid ) ) {
1415 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
1416 RecentChange
::markPatrolled( $rcid );
1417 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1418 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1419 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1421 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1422 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1425 $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1430 * User-interface handler for the "watch" action
1435 global $wgUser, $wgOut;
1437 if ( $wgUser->isAnon() ) {
1438 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1441 if ( wfReadOnly() ) {
1442 $wgOut->readOnlyPage();
1446 if( $this->doWatch() ) {
1447 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1448 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1450 $link = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1451 $text = wfMsg( 'addedwatchtext', $link );
1452 $wgOut->addWikiText( $text );
1455 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1459 * Add this page to $wgUser's watchlist
1460 * @return bool true on successful watch operation
1462 function doWatch() {
1464 if( $wgUser->isAnon() ) {
1468 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1469 $wgUser->addWatch( $this->mTitle
);
1470 $wgUser->saveSettings();
1472 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1479 * User interface handler for the "unwatch" action.
1481 function unwatch() {
1483 global $wgUser, $wgOut;
1485 if ( $wgUser->isAnon() ) {
1486 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1489 if ( wfReadOnly() ) {
1490 $wgOut->readOnlyPage();
1494 if( $this->doUnwatch() ) {
1495 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1496 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1498 $link = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1499 $text = wfMsg( 'removedwatchtext', $link );
1500 $wgOut->addWikiText( $text );
1503 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1507 * Stop watching a page
1508 * @return bool true on successful unwatch
1510 function doUnwatch() {
1512 if( $wgUser->isAnon() ) {
1516 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1517 $wgUser->removeWatch( $this->mTitle
);
1518 $wgUser->saveSettings();
1520 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1527 * action=protect handler
1529 function protect() {
1530 require_once 'ProtectionForm.php';
1531 $form = new ProtectionForm( $this );
1536 * action=unprotect handler (alias)
1538 function unprotect() {
1543 * Update the article's restriction field, and leave a log entry.
1545 * @param array $limit set of restriction keys
1546 * @param string $reason
1547 * @return bool true on success
1549 function updateRestrictions( $limit = array(), $reason = '' ) {
1550 global $wgUser, $wgRestrictionTypes, $wgContLang;
1552 $id = $this->mTitle
->getArticleID();
1553 if( !$wgUser->isAllowed( 'protect' ) ||
wfReadOnly() ||
$id == 0 ) {
1557 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1558 # we expect a single selection, but the schema allows otherwise.
1560 foreach( $wgRestrictionTypes as $action )
1561 $current[$action] = implode( '', $this->mTitle
->getRestrictions( $action ) );
1563 $current = Article
::flattenRestrictions( $current );
1564 $updated = Article
::flattenRestrictions( $limit );
1566 $changed = ( $current != $updated );
1567 $protect = ( $updated != '' );
1569 # If nothing's changed, do nothing
1571 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1573 $dbw =& wfGetDB( DB_MASTER
);
1575 # Prepare a null revision to be added to the history
1576 $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ?
'protectedarticle' : 'unprotectedarticle', $this->mTitle
->getPrefixedText() ) );
1578 $comment .= ": $reason";
1580 $comment .= " [$updated]";
1581 $nullRevision = Revision
::newNullRevision( $dbw, $id, $comment, true );
1582 $nullRevId = $nullRevision->insertOn( $dbw );
1584 # Update page record
1585 $dbw->update( 'page',
1587 'page_touched' => $dbw->timestamp(),
1588 'page_restrictions' => $updated,
1589 'page_latest' => $nullRevId
1590 ), array( /* WHERE */
1592 ), 'Article::protect'
1594 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1596 # Update the protection log
1597 $log = new LogPage( 'protect' );
1599 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$updated]" ) );
1601 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1605 } # End "changed" check
1611 * Take an array of page restrictions and flatten it to a string
1612 * suitable for insertion into the page_restrictions field.
1613 * @param array $limit
1617 function flattenRestrictions( $limit ) {
1618 if( !is_array( $limit ) ) {
1619 throw new MWException( 'Article::flattenRestrictions given non-array restriction set' );
1623 foreach( $limit as $action => $restrictions ) {
1624 if( $restrictions != '' ) {
1625 $bits[] = "$action=$restrictions";
1628 return implode( ':', $bits );
1632 * UI entry point for page deletion
1635 global $wgUser, $wgOut, $wgRequest;
1636 $confirm = $wgRequest->wasPosted() &&
1637 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1638 $reason = $wgRequest->getText( 'wpReason' );
1640 # This code desperately needs to be totally rewritten
1643 if( $wgUser->isAllowed( 'delete' ) ) {
1644 if( $wgUser->isBlocked( !$confirm ) ) {
1645 $wgOut->blockedPage();
1649 $wgOut->permissionRequired( 'delete' );
1653 if( wfReadOnly() ) {
1654 $wgOut->readOnlyPage();
1658 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1660 # Better double-check that it hasn't been deleted yet!
1661 $dbw =& wfGetDB( DB_MASTER
);
1662 $conds = $this->mTitle
->pageCond();
1663 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1664 if ( $latest === false ) {
1665 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
1670 $this->doDelete( $reason );
1674 # determine whether this page has earlier revisions
1675 # and insert a warning if it does
1677 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1679 if( count( $authors ) > 1 && !$confirm ) {
1680 $skin=$wgUser->getSkin();
1681 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
1684 # If a single user is responsible for all revisions, find out who they are
1685 if ( count( $authors ) == $maxRevisions ) {
1686 // Query bailed out, too many revisions to find out if they're all the same
1687 $authorOfAll = false;
1689 $authorOfAll = reset( $authors );
1690 foreach ( $authors as $author ) {
1691 if ( $authorOfAll != $author ) {
1692 $authorOfAll = false;
1697 # Fetch article text
1698 $rev = Revision
::newFromTitle( $this->mTitle
);
1700 if( !is_null( $rev ) ) {
1701 # if this is a mini-text, we can paste part of it into the deletion reason
1702 $text = $rev->getText();
1704 #if this is empty, an earlier revision may contain "useful" text
1707 $prev = $rev->getPrevious();
1709 $text = $prev->getText();
1714 $length = strlen( $text );
1716 # this should not happen, since it is not possible to store an empty, new
1717 # page. Let's insert a standard text in case it does, though
1718 if( $length == 0 && $reason === '' ) {
1719 $reason = wfMsgForContent( 'exblank' );
1722 if( $length < 500 && $reason === '' ) {
1723 # comment field=255, let's grep the first 150 to have some user
1726 $text = $wgContLang->truncate( $text, 150, '...' );
1728 # let's strip out newlines
1729 $text = preg_replace( "/[\n\r]/", '', $text );
1732 if( $authorOfAll === false ) {
1733 $reason = wfMsgForContent( 'excontent', $text );
1735 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1738 $reason = wfMsgForContent( 'exbeforeblank', $text );
1743 return $this->confirmDelete( '', $reason );
1747 * Get the last N authors
1748 * @param int $num Number of revisions to get
1749 * @param string $revLatest The latest rev_id, selected from the master (optional)
1750 * @return array Array of authors, duplicates not removed
1752 function getLastNAuthors( $num, $revLatest = 0 ) {
1753 wfProfileIn( __METHOD__
);
1755 // First try the slave
1756 // If that doesn't have the latest revision, try the master
1758 $db =& wfGetDB( DB_SLAVE
);
1760 $res = $db->select( array( 'page', 'revision' ),
1761 array( 'rev_id', 'rev_user_text' ),
1763 'page_namespace' => $this->mTitle
->getNamespace(),
1764 'page_title' => $this->mTitle
->getDBkey(),
1765 'rev_page = page_id'
1766 ), __METHOD__
, $this->getSelectOptions( array(
1767 'ORDER BY' => 'rev_timestamp DESC',
1772 wfProfileOut( __METHOD__
);
1775 $row = $db->fetchObject( $res );
1776 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1777 $db =& wfGetDB( DB_MASTER
);
1782 } while ( $continue );
1784 $authors = array( $row->rev_user_text
);
1785 while ( $row = $db->fetchObject( $res ) ) {
1786 $authors[] = $row->rev_user_text
;
1788 wfProfileOut( __METHOD__
);
1793 * Output deletion confirmation dialog
1795 function confirmDelete( $par, $reason ) {
1796 global $wgOut, $wgUser;
1798 wfDebug( "Article::confirmDelete\n" );
1800 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1801 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1802 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1803 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1805 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1807 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1808 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1809 $token = htmlspecialchars( $wgUser->editToken() );
1812 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1816 <label for='wpReason'>{$delcom}:</label>
1819 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1825 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1829 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1832 $wgOut->returnToMain( false );
1837 * Perform a deletion and output success or failure messages
1839 function doDelete( $reason ) {
1840 global $wgOut, $wgUser;
1841 wfDebug( __METHOD__
."\n" );
1843 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1844 if ( $this->doDeleteArticle( $reason ) ) {
1845 $deleted = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1847 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1848 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1850 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1851 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1853 $wgOut->addWikiText( $text );
1854 $wgOut->returnToMain( false );
1855 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1857 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
1863 * Back-end article deletion
1864 * Deletes the article with database consistency, writes logs, purges caches
1867 function doDeleteArticle( $reason ) {
1868 global $wgUseSquid, $wgDeferredUpdateList;
1869 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1871 wfDebug( __METHOD__
."\n" );
1873 $dbw =& wfGetDB( DB_MASTER
);
1874 $ns = $this->mTitle
->getNamespace();
1875 $t = $this->mTitle
->getDBkey();
1876 $id = $this->mTitle
->getArticleID();
1878 if ( $t == '' ||
$id == 0 ) {
1882 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1883 array_push( $wgDeferredUpdateList, $u );
1885 // For now, shunt the revision data into the archive table.
1886 // Text is *not* removed from the text table; bulk storage
1887 // is left intact to avoid breaking block-compression or
1888 // immutable storage schemes.
1890 // For backwards compatibility, note that some older archive
1891 // table entries will have ar_text and ar_flags fields still.
1893 // In the future, we may keep revisions and mark them with
1894 // the rev_deleted field, which is reserved for this purpose.
1895 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1897 'ar_namespace' => 'page_namespace',
1898 'ar_title' => 'page_title',
1899 'ar_comment' => 'rev_comment',
1900 'ar_user' => 'rev_user',
1901 'ar_user_text' => 'rev_user_text',
1902 'ar_timestamp' => 'rev_timestamp',
1903 'ar_minor_edit' => 'rev_minor_edit',
1904 'ar_rev_id' => 'rev_id',
1905 'ar_text_id' => 'rev_text_id',
1908 'page_id = rev_page'
1912 # Now that it's safely backed up, delete it
1913 $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__
);
1915 # If using cascading deletes, we can skip some explicit deletes
1916 if ( !$dbw->cascadingDeletes() ) {
1918 $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__
);
1920 if ($wgUseTrackbacks)
1921 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__
);
1923 # Delete outgoing links
1924 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1925 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1926 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1927 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
1928 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
1929 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
1932 # If using cleanup triggers, we can skip some manual deletes
1933 if ( !$dbw->cleanupTriggers() ) {
1935 # Clean up recentchanges entries...
1936 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__
);
1940 Article
::onArticleDelete( $this->mTitle
);
1943 $log = new LogPage( 'delete' );
1944 $log->addEntry( 'delete', $this->mTitle
, $reason );
1946 # Clear the cached article id so the interface doesn't act like we exist
1947 $this->mTitle
->resetArticleID( 0 );
1948 $this->mTitle
->mArticleID
= 0;
1953 * Revert a modification
1955 function rollback() {
1956 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
1958 if( $wgUser->isAllowed( 'rollback' ) ) {
1959 if( $wgUser->isBlocked() ) {
1960 $wgOut->blockedPage();
1964 $wgOut->permissionRequired( 'rollback' );
1968 if ( wfReadOnly() ) {
1969 $wgOut->readOnlyPage( $this->getContent() );
1972 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
1973 array( $this->mTitle
->getPrefixedText(),
1974 $wgRequest->getVal( 'from' ) ) ) ) {
1975 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1976 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
1979 $dbw =& wfGetDB( DB_MASTER
);
1981 # Enhanced rollback, marks edits rc_bot=1
1982 $bot = $wgRequest->getBool( 'bot' );
1984 # Replace all this user's current edits with the next one down
1985 $tt = $this->mTitle
->getDBKey();
1986 $n = $this->mTitle
->getNamespace();
1988 # Get the last editor
1989 $current = Revision
::newFromTitle( $this->mTitle
);
1990 if( is_null( $current ) ) {
1991 # Something wrong... no page?
1992 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1996 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1997 if( $from != $current->getUserText() ) {
1998 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
1999 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2000 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2001 htmlspecialchars( $from ),
2002 htmlspecialchars( $current->getUserText() ) ) );
2003 if( $current->getComment() != '') {
2005 wfMsg( 'editcomment',
2006 htmlspecialchars( $current->getComment() ) ) );
2011 # Get the last edit not by this guy
2012 $user = intval( $current->getUser() );
2013 $user_text = $dbw->addQuotes( $current->getUserText() );
2014 $s = $dbw->selectRow( 'revision',
2015 array( 'rev_id', 'rev_timestamp' ),
2017 'rev_page' => $current->getPage(),
2018 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2021 'USE INDEX' => 'page_timestamp',
2022 'ORDER BY' => 'rev_timestamp DESC' )
2024 if( $s === false ) {
2026 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2027 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2033 # Mark all reverted edits as bot
2036 if ( $wgUseRCPatrol ) {
2037 # Mark all reverted edits as patrolled
2038 $set['rc_patrolled'] = 1;
2042 $dbw->update( 'recentchanges', $set,
2044 'rc_cur_id' => $current->getPage(),
2045 'rc_user_text' => $current->getUserText(),
2046 "rc_timestamp > '{$s->rev_timestamp}'",
2051 # Get the edit summary
2052 $target = Revision
::newFromId( $s->rev_id
);
2053 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2054 $newComment = $wgRequest->getText( 'summary', $newComment );
2057 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2058 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2059 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2061 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2063 $wgOut->returnToMain( false );
2068 * Do standard deferred updates after page view
2071 function viewUpdates() {
2072 global $wgDeferredUpdateList;
2074 if ( 0 != $this->getID() ) {
2075 global $wgDisableCounters;
2076 if( !$wgDisableCounters ) {
2077 Article
::incViewCount( $this->getID() );
2078 $u = new SiteStatsUpdate( 1, 0, 0 );
2079 array_push( $wgDeferredUpdateList, $u );
2083 # Update newtalk / watchlist notification status
2085 $wgUser->clearNotification( $this->mTitle
);
2089 * Do standard deferred updates after page edit.
2090 * Update links tables, site stats, search index and message cache.
2091 * Every 1000th edit, prune the recent changes table.
2094 * @param $text New text of the article
2095 * @param $summary Edit summary
2096 * @param $minoredit Minor edit
2097 * @param $timestamp_of_pagechange Timestamp associated with the page change
2098 * @param $newid rev_id value of the new revision
2099 * @param $changed Whether or not the content actually changed
2101 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
2102 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2104 wfProfileIn( __METHOD__
);
2107 $options = new ParserOptions
;
2108 $options->setTidy(true);
2109 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2111 # Save it to the parser cache
2112 $parserCache =& ParserCache
::singleton();
2113 $parserCache->save( $poutput, $this, $wgUser );
2115 # Update the links tables
2116 $u = new LinksUpdate( $this->mTitle
, $poutput );
2119 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2121 if ( 0 == mt_rand( 0, 999 ) ) {
2122 # Periodically flush old entries from the recentchanges table.
2125 $dbw =& wfGetDB( DB_MASTER
);
2126 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2127 $recentchanges = $dbw->tableName( 'recentchanges' );
2128 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2129 $dbw->query( $sql );
2133 $id = $this->getID();
2134 $title = $this->mTitle
->getPrefixedDBkey();
2135 $shortTitle = $this->mTitle
->getDBkey();
2138 wfProfileOut( __METHOD__
);
2142 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2143 array_push( $wgDeferredUpdateList, $u );
2144 $u = new SearchUpdate( $id, $title, $text );
2145 array_push( $wgDeferredUpdateList, $u );
2147 # If this is another user's talk page, update newtalk
2148 # Don't do this if $changed = false otherwise some idiot can null-edit a
2149 # load of user talk pages and piss people off
2150 if( $this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getTitleKey() && $changed ) {
2151 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2152 $other = User
::newFromName( $shortTitle );
2153 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2154 // An anonymous user
2155 $other = new User();
2156 $other->setName( $shortTitle );
2159 $other->setNewtalk( true );
2164 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2165 $wgMessageCache->replace( $shortTitle, $text );
2168 wfProfileOut( __METHOD__
);
2172 * Generate the navigation links when browsing through an article revisions
2173 * It shows the information as:
2174 * Revision as of \<date\>; view current revision
2175 * \<- Previous version | Next Version -\>
2178 * @param string $oldid Revision ID of this article revision
2180 function setOldSubtitle( $oldid=0 ) {
2181 global $wgLang, $wgOut, $wgUser;
2183 $revision = Revision
::newFromId( $oldid );
2185 $current = ( $oldid == $this->mLatest
);
2186 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2187 $sk = $wgUser->getSkin();
2189 ?
wfMsg( 'currentrevisionlink' )
2190 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2191 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2193 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2194 : wfMsg( 'previousrevision' );
2196 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'diff' ), 'diff=prev&oldid='.$oldid )
2198 $nextlink = $current
2199 ?
wfMsg( 'nextrevision' )
2200 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2201 $nextdiff = $current
2203 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'diff' ), 'diff=next&oldid='.$oldid );
2205 $userlinks = $sk->userLink( $revision->getUser(), $revision->getUserText() )
2206 . $sk->userToolLinks( $revision->getUser(), $revision->getUserText() );
2208 $r = wfMsg( 'old-revision-navigation', $td, $lnk, $prevlink, $nextlink, $userlinks, $prevdiff, $nextdiff );
2209 $wgOut->setSubtitle( $r );
2213 * This function is called right before saving the wikitext,
2214 * so we can do things like signatures and links-in-context.
2216 * @param string $text
2218 function preSaveTransform( $text ) {
2219 global $wgParser, $wgUser;
2220 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2223 /* Caching functions */
2226 * checkLastModified returns true if it has taken care of all
2227 * output to the client that is necessary for this request.
2228 * (that is, it has sent a cached version of the page)
2230 function tryFileCache() {
2231 static $called = false;
2233 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2237 if($this->isFileCacheable()) {
2238 $touched = $this->mTouched
;
2239 $cache = new CacheManager( $this->mTitle
);
2240 if($cache->isFileCacheGood( $touched )) {
2241 wfDebug( "Article::tryFileCache(): about to load file\n" );
2242 $cache->loadFromFileCache();
2245 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2246 ob_start( array(&$cache, 'saveToFileCache' ) );
2249 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2254 * Check if the page can be cached
2257 function isFileCacheable() {
2258 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2259 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2261 return $wgUseFileCache
2262 and (!$wgShowIPinHeader)
2263 and ($this->getID() != 0)
2264 and ($wgUser->isAnon())
2265 and (!$wgUser->getNewtalk())
2266 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2267 and (empty( $action ) ||
$action == 'view')
2268 and (!isset($oldid))
2270 and (!isset($redirect))
2271 and (!isset($printable))
2272 and (!$this->mRedirectedFrom
);
2276 * Loads page_touched and returns a value indicating if it should be used
2279 function checkTouched() {
2280 if( !$this->mDataLoaded
) {
2281 $this->loadPageData();
2283 return !$this->mIsRedirect
;
2287 * Get the page_touched field
2289 function getTouched() {
2290 # Ensure that page data has been loaded
2291 if( !$this->mDataLoaded
) {
2292 $this->loadPageData();
2294 return $this->mTouched
;
2298 * Get the page_latest field
2300 function getLatest() {
2301 if ( !$this->mDataLoaded
) {
2302 $this->loadPageData();
2304 return $this->mLatest
;
2308 * Edit an article without doing all that other stuff
2309 * The article must already exist; link tables etc
2310 * are not updated, caches are not flushed.
2312 * @param string $text text submitted
2313 * @param string $comment comment submitted
2314 * @param bool $minor whereas it's a minor modification
2316 function quickEdit( $text, $comment = '', $minor = 0 ) {
2317 wfProfileIn( __METHOD__
);
2319 $dbw =& wfGetDB( DB_MASTER
);
2321 $revision = new Revision( array(
2322 'page' => $this->getId(),
2324 'comment' => $comment,
2325 'minor_edit' => $minor ?
1 : 0,
2327 # fixme : $revisionId never used
2328 $revisionId = $revision->insertOn( $dbw );
2329 $this->updateRevisionOn( $dbw, $revision );
2332 wfProfileOut( __METHOD__
);
2336 * Used to increment the view counter
2339 * @param integer $id article id
2341 function incViewCount( $id ) {
2342 $id = intval( $id );
2343 global $wgHitcounterUpdateFreq, $wgDBtype;
2345 $dbw =& wfGetDB( DB_MASTER
);
2346 $pageTable = $dbw->tableName( 'page' );
2347 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2348 $acchitsTable = $dbw->tableName( 'acchits' );
2350 if( $wgHitcounterUpdateFreq <= 1 ){ //
2351 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2355 # Not important enough to warrant an error page in case of failure
2356 $oldignore = $dbw->ignoreErrors( true );
2358 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2360 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2361 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2362 # Most of the time (or on SQL errors), skip row count check
2363 $dbw->ignoreErrors( $oldignore );
2367 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2368 $row = $dbw->fetchObject( $res );
2369 $rown = intval( $row->n
);
2370 if( $rown >= $wgHitcounterUpdateFreq ){
2371 wfProfileIn( 'Article::incViewCount-collect' );
2372 $old_user_abort = ignore_user_abort( true );
2374 if ($wgDBtype == 'mysql')
2375 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2376 $tabletype = $wgDBtype == 'mysql' ?
"ENGINE=HEAP " : '';
2377 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
2378 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2380 $dbw->query("DELETE FROM $hitcounterTable");
2381 if ($wgDBtype == 'mysql')
2382 $dbw->query('UNLOCK TABLES');
2383 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2384 'WHERE page_id = hc_id');
2385 $dbw->query("DROP TABLE $acchitsTable");
2387 ignore_user_abort( $old_user_abort );
2388 wfProfileOut( 'Article::incViewCount-collect' );
2390 $dbw->ignoreErrors( $oldignore );
2394 * The onArticle*() functions are supposed to be a kind of hooks
2395 * which should be called whenever any of the specified actions
2398 * This is a good place to put code to clear caches, for instance.
2400 * This is called on page move and undelete, as well as edit
2402 * @param $title_obj a title object
2405 static function onArticleCreate($title) {
2406 # The talk page isn't in the regular link tables, so we need to update manually:
2407 if ( $title->isTalkPage() ) {
2408 $other = $title->getSubjectPage();
2410 $other = $title->getTalkPage();
2412 $other->invalidateCache();
2413 $other->purgeSquid();
2415 $title->touchLinks();
2416 $title->purgeSquid();
2419 static function onArticleDelete( $title ) {
2420 global $wgUseFileCache, $wgMessageCache;
2422 $title->touchLinks();
2423 $title->purgeSquid();
2426 if ( $wgUseFileCache ) {
2427 $cm = new CacheManager( $title );
2428 @unlink
( $cm->fileCacheName() );
2431 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2432 $wgMessageCache->replace( $title->getDBkey(), false );
2437 * Purge caches on page update etc
2439 static function onArticleEdit( $title ) {
2440 global $wgDeferredUpdateList, $wgUseFileCache;
2444 // Invalidate caches of articles which include this page
2445 $update = new HTMLCacheUpdate( $title, 'templatelinks' );
2446 $wgDeferredUpdateList[] = $update;
2448 # Purge squid for this page only
2449 $title->purgeSquid();
2452 if ( $wgUseFileCache ) {
2453 $cm = new CacheManager( $title );
2454 @unlink
( $cm->fileCacheName() );
2461 * Info about this page
2462 * Called for ?action=info when $wgAllowPageInfo is on.
2467 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2469 if ( !$wgAllowPageInfo ) {
2470 $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
2474 $page = $this->mTitle
->getSubjectPage();
2476 $wgOut->setPagetitle( $page->getPrefixedText() );
2477 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2479 # first, see if the page exists at all.
2480 $exists = $page->getArticleId() != 0;
2482 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2483 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2485 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2488 $dbr =& wfGetDB( DB_SLAVE
);
2490 'wl_title' => $page->getDBkey(),
2491 'wl_namespace' => $page->getNamespace() );
2492 $numwatchers = $dbr->selectField(
2497 $this->getSelectOptions() );
2499 $pageInfo = $this->pageCountInfo( $page );
2500 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2502 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2503 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2505 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2507 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2509 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2511 $wgOut->addHTML( '</ul>' );
2517 * Return the total number of edits and number of unique editors
2518 * on a given page. If page does not exist, returns false.
2520 * @param Title $title
2524 function pageCountInfo( $title ) {
2525 $id = $title->getArticleId();
2530 $dbr =& wfGetDB( DB_SLAVE
);
2532 $rev_clause = array( 'rev_page' => $id );
2534 $edits = $dbr->selectField(
2539 $this->getSelectOptions() );
2541 $authors = $dbr->selectField(
2543 'COUNT(DISTINCT rev_user_text)',
2546 $this->getSelectOptions() );
2548 return array( 'edits' => $edits, 'authors' => $authors );
2552 * Return a list of templates used by this article.
2553 * Uses the templatelinks table
2555 * @return array Array of Title objects
2557 function getUsedTemplates() {
2559 $id = $this->mTitle
->getArticleID();
2564 $dbr =& wfGetDB( DB_SLAVE
);
2565 $res = $dbr->select( array( 'templatelinks' ),
2566 array( 'tl_namespace', 'tl_title' ),
2567 array( 'tl_from' => $id ),
2568 'Article:getUsedTemplates' );
2569 if ( false !== $res ) {
2570 if ( $dbr->numRows( $res ) ) {
2571 while ( $row = $dbr->fetchObject( $res ) ) {
2572 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2576 $dbr->freeResult( $res );