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 ) ) {
722 wfRunHooks( 'ArticleViewHeader', array( &$this ) );
726 if ( !$outputDone ) {
727 $text = $this->getContent();
728 if ( $text === false ) {
729 # Failed to load, replace text with error message
730 $t = $this->mTitle
->getPrefixedText();
732 $t .= ',oldid='.$oldid;
733 $text = wfMsg( 'missingarticle', $t );
735 $text = wfMsg( 'noarticletext', $t );
739 # Another whitelist check in case oldid is altering the title
740 if ( !$this->mTitle
->userCanRead() ) {
741 $wgOut->loginToUse();
746 # We're looking at an old revision
748 if ( !empty( $oldid ) ) {
749 $wgOut->setRobotpolicy( 'noindex,nofollow' );
750 if( is_null( $this->mRevision
) ) {
751 // FIXME: This would be a nice place to load the 'no such page' text.
753 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
754 if( $this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
755 if( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
756 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
757 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
760 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
761 // and we are allowed to see...
770 * @fixme: this hook doesn't work most of the time, as it doesn't
771 * trigger when the parser cache is used.
773 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
774 $wgOut->setRevisionId( $this->getRevIdFetched() );
775 # wrap user css and user js in pre and don't parse
776 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
779 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
781 $wgOut->addWikiText( wfMsg('clearyourcache'));
782 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
783 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
785 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
786 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
787 # Don't overwrite the subtitle if this was an old revision
788 if( !$wasRedirected && $this->isCurrent() ) {
789 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
791 $targetUrl = $rt->escapeLocalURL();
792 #Â fixme unused $titleText :
793 $titleText = htmlspecialchars( $rt->getPrefixedText() );
794 $link = $sk->makeLinkObj( $rt );
796 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
797 '<span class="redirectText">'.$link.'</span>' );
799 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
800 $wgOut->addParserOutputNoText( $parseout );
801 } else if ( $pcache ) {
802 # Display content and save to parser cache
803 $wgOut->addPrimaryWikiText( $text, $this );
805 # Display content, don't attempt to save to parser cache
806 # Don't show section-edit links on old revisions... this way lies madness.
807 if( !$this->isCurrent() ) {
808 $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
810 # Display content and don't save to parser cache
811 $wgOut->addPrimaryWikiText( $text, $this, false );
813 if( !$this->isCurrent() ) {
814 $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
818 /* title may have been set from the cache */
819 $t = $wgOut->getPageTitle();
821 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
824 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
825 if( $ns == NS_USER_TALK
&&
826 User
::isIP( $this->mTitle
->getText() ) ) {
827 $wgOut->addWikiText( wfMsg('anontalkpagetext') );
830 # If we have been passed an &rcid= parameter, we want to give the user a
831 # chance to mark this new article as patrolled.
832 if ( $wgUseRCPatrol && !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
834 "<div class='patrollink'>" .
835 wfMsg ( 'markaspatrolledlink',
836 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
843 if ($wgUseTrackbacks)
844 $this->addTrackbacks();
846 $this->viewUpdates();
847 wfProfileOut( __METHOD__
);
850 function addTrackbacks() {
851 global $wgOut, $wgUser;
853 $dbr =& wfGetDB(DB_SLAVE
);
855 /* FROM */ 'trackbacks',
856 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
857 /* WHERE */ array('tb_page' => $this->getID())
860 if (!$dbr->numrows($tbs))
864 while ($o = $dbr->fetchObject($tbs)) {
866 if ($wgUser->isAllowed( 'trackback' )) {
867 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
868 . $o->tb_id
. "&token=" . $wgUser->editToken());
869 $rmvtxt = wfMsg('trackbackremove', $delurl);
871 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
878 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
881 function deletetrackback() {
882 global $wgUser, $wgRequest, $wgOut, $wgTitle;
884 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
885 $wgOut->addWikitext(wfMsg('sessionfailure'));
889 if ((!$wgUser->isAllowed('delete'))) {
890 $wgOut->permissionRequired( 'delete' );
895 $wgOut->readOnlyPage();
899 $db =& wfGetDB(DB_MASTER
);
900 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
901 $wgTitle->invalidateCache();
902 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
908 $wgOut->setArticleBodyOnly(true);
913 * Handle action=purge
916 global $wgUser, $wgRequest, $wgOut;
918 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
919 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
923 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
924 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
925 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
926 $msg = str_replace( '$1',
927 "<form method=\"post\" action=\"$action\">\n" .
928 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
931 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
932 $wgOut->setRobotpolicy( 'noindex,nofollow' );
933 $wgOut->addHTML( $msg );
938 * Perform the actions of a page purging
942 // Invalidate the cache
943 $this->mTitle
->invalidateCache();
946 // Commit the transaction before the purge is sent
947 $dbw = wfGetDB( DB_MASTER
);
948 $dbw->immediateCommit();
951 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
958 * Insert a new empty page record for this article.
959 * This *must* be followed up by creating a revision
960 * and running $this->updateToLatest( $rev_id );
961 * or else the record will be left in a funky state.
962 * Best if all done inside a transaction.
964 * @param Database $dbw
965 * @param string $restrictions
966 * @return int The newly created page_id key
969 function insertOn( &$dbw, $restrictions = '' ) {
970 wfProfileIn( __METHOD__
);
972 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
973 $dbw->insert( 'page', array(
974 'page_id' => $page_id,
975 'page_namespace' => $this->mTitle
->getNamespace(),
976 'page_title' => $this->mTitle
->getDBkey(),
978 'page_restrictions' => $restrictions,
979 'page_is_redirect' => 0, # Will set this shortly...
981 'page_random' => wfRandom(),
982 'page_touched' => $dbw->timestamp(),
983 'page_latest' => 0, # Fill this in shortly...
984 'page_len' => 0, # Fill this in shortly...
986 $newid = $dbw->insertId();
988 $this->mTitle
->resetArticleId( $newid );
990 wfProfileOut( __METHOD__
);
995 * Update the page record to point to a newly saved revision.
997 * @param Database $dbw
998 * @param Revision $revision For ID number, and text used to set
999 length and redirect status fields
1000 * @param int $lastRevision If given, will not overwrite the page field
1001 * when different from the currently set value.
1002 * Giving 0 indicates the new page flag should
1004 * @return bool true on success, false on failure
1007 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1008 wfProfileIn( __METHOD__
);
1010 $conditions = array( 'page_id' => $this->getId() );
1011 if( !is_null( $lastRevision ) ) {
1012 # An extra check against threads stepping on each other
1013 $conditions['page_latest'] = $lastRevision;
1016 $text = $revision->getText();
1017 $dbw->update( 'page',
1019 'page_latest' => $revision->getId(),
1020 'page_touched' => $dbw->timestamp(),
1021 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1022 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1023 'page_len' => strlen( $text ),
1028 wfProfileOut( __METHOD__
);
1029 return ( $dbw->affectedRows() != 0 );
1033 * If the given revision is newer than the currently set page_latest,
1034 * update the page record. Otherwise, do nothing.
1036 * @param Database $dbw
1037 * @param Revision $revision
1039 function updateIfNewerOn( &$dbw, $revision ) {
1040 wfProfileIn( __METHOD__
);
1042 $row = $dbw->selectRow(
1043 array( 'revision', 'page' ),
1044 array( 'rev_id', 'rev_timestamp' ),
1046 'page_id' => $this->getId(),
1047 'page_latest=rev_id' ),
1050 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1051 wfProfileOut( __METHOD__
);
1054 $prev = $row->rev_id
;
1056 # No or missing previous revision; mark the page as new
1060 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1061 wfProfileOut( __METHOD__
);
1066 * @return string Complete article text, or null if error
1068 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1069 wfProfileIn( __METHOD__
);
1071 if( $section == '' ) {
1072 // Whole-page edit; let the text through unmolested.
1074 if( is_null( $edittime ) ) {
1075 $rev = Revision
::newFromTitle( $this->mTitle
);
1077 $dbw =& wfGetDB( DB_MASTER
);
1078 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1080 if( is_null( $rev ) ) {
1081 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1082 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1085 $oldtext = $rev->getText();
1087 if($section=='new') {
1088 if($summary) $subject="== {$summary} ==\n\n";
1089 $text=$oldtext."\n\n".$subject.$text;
1092 $text = $wgParser->replaceSection( $oldtext, $section, $text );
1096 wfProfileOut( __METHOD__
);
1101 * @deprecated use Article::doEdit()
1103 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1104 $flags = EDIT_NEW | EDIT_DEFER_UPDATES |
1105 ( $isminor ? EDIT_MINOR
: 0 ) |
1106 ( $suppressRC ? EDIT_SUPPRESS_RC
: 0 );
1108 # If this is a comment, add the summary as headline
1109 if ( $comment && $summary != "" ) {
1110 $text = "== {$summary} ==\n\n".$text;
1113 $this->doEdit( $text, $summary, $flags );
1115 $dbw =& wfGetDB( DB_MASTER
);
1117 if (!$this->mTitle
->userIsWatching()) {
1123 if ( $this->mTitle
->userIsWatching() ) {
1129 $this->doRedirect( $this->isRedirect( $text ) );
1133 * @deprecated use Article::doEdit()
1135 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1136 $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES |
1137 ( $minor ? EDIT_MINOR
: 0 ) |
1138 ( $forceBot ? EDIT_FORCE_BOT
: 0 );
1140 $good = $this->doEdit( $text, $summary, $flags );
1142 $dbw =& wfGetDB( DB_MASTER
);
1144 if (!$this->mTitle
->userIsWatching()) {
1150 if ( $this->mTitle
->userIsWatching() ) {
1157 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
1165 * Change an existing article or create a new article. Updates RC and all necessary caches,
1166 * optionally via the deferred update array.
1168 * $wgUser must be set before calling this function.
1170 * @param string $text New text
1171 * @param string $summary Edit summary
1172 * @param integer $flags bitfield:
1174 * Article is known or assumed to be non-existent, create a new one
1176 * Article is known or assumed to be pre-existing, update it
1178 * Mark this edit minor, if the user is allowed to do so
1180 * Do not log the change in recentchanges
1182 * Mark the edit a "bot" edit regardless of user rights
1183 * EDIT_DEFER_UPDATES
1184 * Defer some of the updates until the end of index.php
1186 * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
1187 * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If
1188 * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
1189 * to be thrown from the Database. These two conditions are also possible with auto-detection due
1190 * to MediaWiki's performance-optimised locking strategy.
1192 * @return bool success
1194 function doEdit( $text, $summary, $flags = 0 ) {
1195 global $wgUser, $wgDBtransactions;
1197 wfProfileIn( __METHOD__
);
1200 if ( !($flags & EDIT_NEW
) && !($flags & EDIT_UPDATE
) ) {
1201 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
1203 $flags |
= EDIT_UPDATE
;
1209 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1210 &$summary, $flags & EDIT_MINOR
,
1211 null, null, &$flags ) ) )
1213 wfDebug( __METHOD__
. ": ArticleSave hook aborted save!\n" );
1214 wfProfileOut( __METHOD__
);
1218 # Silently ignore EDIT_MINOR if not allowed
1219 $isminor = ( $flags & EDIT_MINOR
) && $wgUser->isAllowed('minoredit');
1220 $bot = $wgUser->isAllowed( 'bot' ) ||
( $flags & EDIT_FORCE_BOT
);
1222 $text = $this->preSaveTransform( $text );
1224 $dbw =& wfGetDB( DB_MASTER
);
1225 $now = wfTimestampNow();
1227 if ( $flags & EDIT_UPDATE
) {
1228 # Update article, but only if changed.
1230 # Make sure the revision is either completely inserted or not inserted at all
1231 if( !$wgDBtransactions ) {
1232 $userAbort = ignore_user_abort( true );
1235 $oldtext = $this->getContent();
1236 $oldsize = strlen( $oldtext );
1237 $newsize = strlen( $text );
1241 if ( 0 != strcmp( $text, $oldtext ) ) {
1242 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1243 - (int)$this->isCountable( $oldtext );
1244 $this->mTotalAdjustment
= 0;
1246 $lastRevision = $dbw->selectField(
1247 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1249 if ( !$lastRevision ) {
1250 # Article gone missing
1251 wfDebug( __METHOD__
.": EDIT_UPDATE specified but article doesn't exist\n" );
1252 wfProfileOut( __METHOD__
);
1256 $revision = new Revision( array(
1257 'page' => $this->getId(),
1258 'comment' => $summary,
1259 'minor_edit' => $isminor,
1264 $revisionId = $revision->insertOn( $dbw );
1267 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1270 /* Belated edit conflict! Run away!! */
1274 # Update recentchanges
1275 if( !( $flags & EDIT_SUPPRESS_RC
) ) {
1276 $rcid = RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1277 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1280 # Mark as patrolled if the user can do so and has it set in their options
1281 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1282 RecentChange
::markPatrolled( $rcid );
1288 // Keep the same revision ID, but do some updates on it
1289 $revisionId = $this->getRevIdFetched();
1290 // Update page_touched, this is usually implicit in the page update
1291 // Other cache updates are done in onArticleEdit()
1292 $this->mTitle
->invalidateCache();
1295 if( !$wgDBtransactions ) {
1296 ignore_user_abort( $userAbort );
1300 # Invalidate cache of this article and all pages using this article
1301 # as a template. Partly deferred.
1302 Article
::onArticleEdit( $this->mTitle
);
1304 # Update links tables, site stats, etc.
1305 $changed = ( strcmp( $oldtext, $text ) != 0 );
1306 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
1309 # Create new article
1311 # Set statistics members
1312 # We work out if it's countable after PST to avoid counter drift
1313 # when articles are created with {{subst:}}
1314 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1315 $this->mTotalAdjustment
= 1;
1319 # Add the page record; stake our claim on this title!
1320 # This will fail with a database query exception if the article already exists
1321 $newid = $this->insertOn( $dbw );
1323 # Save the revision text...
1324 $revision = new Revision( array(
1326 'comment' => $summary,
1327 'minor_edit' => $isminor,
1330 $revisionId = $revision->insertOn( $dbw );
1332 $this->mTitle
->resetArticleID( $newid );
1334 # Update the page record with revision data
1335 $this->updateRevisionOn( $dbw, $revision, 0 );
1337 if( !( $flags & EDIT_SUPPRESS_RC
) ) {
1338 $rcid = RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, $bot,
1339 '', strlen( $text ), $revisionId );
1340 # Mark as patrolled if the user can and has the option set
1341 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1342 RecentChange
::markPatrolled( $rcid );
1347 # Update links, etc.
1348 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
1351 Article
::onArticleCreate( $this->mTitle
);
1353 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1354 $summary, $flags & EDIT_MINOR
,
1355 null, null, &$flags ) );
1358 if ( $good && !( $flags & EDIT_DEFER_UPDATES
) ) {
1362 wfRunHooks( 'ArticleSaveComplete',
1363 array( &$this, &$wgUser, $text,
1364 $summary, $flags & EDIT_MINOR
,
1365 null, null, &$flags ) );
1367 wfProfileOut( __METHOD__
);
1372 * @deprecated wrapper for doRedirect
1374 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1375 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
1379 * Output a redirect back to the article.
1380 * This is typically used after an edit.
1382 * @param boolean $noRedir Add redirect=no
1383 * @param string $sectionAnchor section to redirect to, including "#"
1385 function doRedirect( $noRedir = false, $sectionAnchor = '' ) {
1388 $query = 'redirect=no';
1392 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) . $sectionAnchor );
1396 * Mark this particular edit as patrolled
1398 function markpatrolled() {
1399 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
1400 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1402 # Check RC patrol config. option
1403 if( !$wgUseRCPatrol ) {
1404 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1409 if( !$wgUser->isAllowed( 'patrol' ) ) {
1410 $wgOut->permissionRequired( 'patrol' );
1414 $rcid = $wgRequest->getVal( 'rcid' );
1415 if ( !is_null ( $rcid ) ) {
1416 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
1417 RecentChange
::markPatrolled( $rcid );
1418 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1419 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1420 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1422 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1423 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1426 $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1431 * User-interface handler for the "watch" action
1436 global $wgUser, $wgOut;
1438 if ( $wgUser->isAnon() ) {
1439 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1442 if ( wfReadOnly() ) {
1443 $wgOut->readOnlyPage();
1447 if( $this->doWatch() ) {
1448 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1449 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1451 $link = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1452 $text = wfMsg( 'addedwatchtext', $link );
1453 $wgOut->addWikiText( $text );
1456 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1460 * Add this page to $wgUser's watchlist
1461 * @return bool true on successful watch operation
1463 function doWatch() {
1465 if( $wgUser->isAnon() ) {
1469 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1470 $wgUser->addWatch( $this->mTitle
);
1471 $wgUser->saveSettings();
1473 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1480 * User interface handler for the "unwatch" action.
1482 function unwatch() {
1484 global $wgUser, $wgOut;
1486 if ( $wgUser->isAnon() ) {
1487 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1490 if ( wfReadOnly() ) {
1491 $wgOut->readOnlyPage();
1495 if( $this->doUnwatch() ) {
1496 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1497 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1499 $link = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1500 $text = wfMsg( 'removedwatchtext', $link );
1501 $wgOut->addWikiText( $text );
1504 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1508 * Stop watching a page
1509 * @return bool true on successful unwatch
1511 function doUnwatch() {
1513 if( $wgUser->isAnon() ) {
1517 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1518 $wgUser->removeWatch( $this->mTitle
);
1519 $wgUser->saveSettings();
1521 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1528 * action=protect handler
1530 function protect() {
1531 require_once 'ProtectionForm.php';
1532 $form = new ProtectionForm( $this );
1537 * action=unprotect handler (alias)
1539 function unprotect() {
1544 * Update the article's restriction field, and leave a log entry.
1546 * @param array $limit set of restriction keys
1547 * @param string $reason
1548 * @return bool true on success
1550 function updateRestrictions( $limit = array(), $reason = '' ) {
1551 global $wgUser, $wgRestrictionTypes, $wgContLang;
1553 $id = $this->mTitle
->getArticleID();
1554 if( !$wgUser->isAllowed( 'protect' ) ||
wfReadOnly() ||
$id == 0 ) {
1558 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1559 # we expect a single selection, but the schema allows otherwise.
1561 foreach( $wgRestrictionTypes as $action )
1562 $current[$action] = implode( '', $this->mTitle
->getRestrictions( $action ) );
1564 $current = Article
::flattenRestrictions( $current );
1565 $updated = Article
::flattenRestrictions( $limit );
1567 $changed = ( $current != $updated );
1568 $protect = ( $updated != '' );
1570 # If nothing's changed, do nothing
1572 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1574 $dbw =& wfGetDB( DB_MASTER
);
1576 # Prepare a null revision to be added to the history
1577 $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ?
'protectedarticle' : 'unprotectedarticle', $this->mTitle
->getPrefixedText() ) );
1579 $comment .= ": $reason";
1581 $comment .= " [$updated]";
1582 $nullRevision = Revision
::newNullRevision( $dbw, $id, $comment, true );
1583 $nullRevId = $nullRevision->insertOn( $dbw );
1585 # Update page record
1586 $dbw->update( 'page',
1588 'page_touched' => $dbw->timestamp(),
1589 'page_restrictions' => $updated,
1590 'page_latest' => $nullRevId
1591 ), array( /* WHERE */
1593 ), 'Article::protect'
1595 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1597 # Update the protection log
1598 $log = new LogPage( 'protect' );
1600 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$updated]" ) );
1602 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1606 } # End "changed" check
1612 * Take an array of page restrictions and flatten it to a string
1613 * suitable for insertion into the page_restrictions field.
1614 * @param array $limit
1618 function flattenRestrictions( $limit ) {
1619 if( !is_array( $limit ) ) {
1620 throw new MWException( 'Article::flattenRestrictions given non-array restriction set' );
1624 foreach( $limit as $action => $restrictions ) {
1625 if( $restrictions != '' ) {
1626 $bits[] = "$action=$restrictions";
1629 return implode( ':', $bits );
1633 * UI entry point for page deletion
1636 global $wgUser, $wgOut, $wgRequest;
1637 $confirm = $wgRequest->wasPosted() &&
1638 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1639 $reason = $wgRequest->getText( 'wpReason' );
1641 # This code desperately needs to be totally rewritten
1644 if( $wgUser->isAllowed( 'delete' ) ) {
1645 if( $wgUser->isBlocked( !$confirm ) ) {
1646 $wgOut->blockedPage();
1650 $wgOut->permissionRequired( 'delete' );
1654 if( wfReadOnly() ) {
1655 $wgOut->readOnlyPage();
1659 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1661 # Better double-check that it hasn't been deleted yet!
1662 $dbw =& wfGetDB( DB_MASTER
);
1663 $conds = $this->mTitle
->pageCond();
1664 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1665 if ( $latest === false ) {
1666 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
1671 $this->doDelete( $reason );
1675 # determine whether this page has earlier revisions
1676 # and insert a warning if it does
1678 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1680 if( count( $authors ) > 1 && !$confirm ) {
1681 $skin=$wgUser->getSkin();
1682 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
1685 # If a single user is responsible for all revisions, find out who they are
1686 if ( count( $authors ) == $maxRevisions ) {
1687 // Query bailed out, too many revisions to find out if they're all the same
1688 $authorOfAll = false;
1690 $authorOfAll = reset( $authors );
1691 foreach ( $authors as $author ) {
1692 if ( $authorOfAll != $author ) {
1693 $authorOfAll = false;
1698 # Fetch article text
1699 $rev = Revision
::newFromTitle( $this->mTitle
);
1701 if( !is_null( $rev ) ) {
1702 # if this is a mini-text, we can paste part of it into the deletion reason
1703 $text = $rev->getText();
1705 #if this is empty, an earlier revision may contain "useful" text
1708 $prev = $rev->getPrevious();
1710 $text = $prev->getText();
1715 $length = strlen( $text );
1717 # this should not happen, since it is not possible to store an empty, new
1718 # page. Let's insert a standard text in case it does, though
1719 if( $length == 0 && $reason === '' ) {
1720 $reason = wfMsgForContent( 'exblank' );
1723 if( $length < 500 && $reason === '' ) {
1724 # comment field=255, let's grep the first 150 to have some user
1727 $text = $wgContLang->truncate( $text, 150, '...' );
1729 # let's strip out newlines
1730 $text = preg_replace( "/[\n\r]/", '', $text );
1733 if( $authorOfAll === false ) {
1734 $reason = wfMsgForContent( 'excontent', $text );
1736 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1739 $reason = wfMsgForContent( 'exbeforeblank', $text );
1744 return $this->confirmDelete( '', $reason );
1748 * Get the last N authors
1749 * @param int $num Number of revisions to get
1750 * @param string $revLatest The latest rev_id, selected from the master (optional)
1751 * @return array Array of authors, duplicates not removed
1753 function getLastNAuthors( $num, $revLatest = 0 ) {
1754 wfProfileIn( __METHOD__
);
1756 // First try the slave
1757 // If that doesn't have the latest revision, try the master
1759 $db =& wfGetDB( DB_SLAVE
);
1761 $res = $db->select( array( 'page', 'revision' ),
1762 array( 'rev_id', 'rev_user_text' ),
1764 'page_namespace' => $this->mTitle
->getNamespace(),
1765 'page_title' => $this->mTitle
->getDBkey(),
1766 'rev_page = page_id'
1767 ), __METHOD__
, $this->getSelectOptions( array(
1768 'ORDER BY' => 'rev_timestamp DESC',
1773 wfProfileOut( __METHOD__
);
1776 $row = $db->fetchObject( $res );
1777 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1778 $db =& wfGetDB( DB_MASTER
);
1783 } while ( $continue );
1785 $authors = array( $row->rev_user_text
);
1786 while ( $row = $db->fetchObject( $res ) ) {
1787 $authors[] = $row->rev_user_text
;
1789 wfProfileOut( __METHOD__
);
1794 * Output deletion confirmation dialog
1796 function confirmDelete( $par, $reason ) {
1797 global $wgOut, $wgUser;
1799 wfDebug( "Article::confirmDelete\n" );
1801 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1802 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1803 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1804 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1806 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1808 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1809 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1810 $token = htmlspecialchars( $wgUser->editToken() );
1813 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1817 <label for='wpReason'>{$delcom}:</label>
1820 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1826 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1830 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1833 $wgOut->returnToMain( false );
1838 * Perform a deletion and output success or failure messages
1840 function doDelete( $reason ) {
1841 global $wgOut, $wgUser;
1842 wfDebug( __METHOD__
."\n" );
1844 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1845 if ( $this->doDeleteArticle( $reason ) ) {
1846 $deleted = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1848 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1849 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1851 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1852 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1854 $wgOut->addWikiText( $text );
1855 $wgOut->returnToMain( false );
1856 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1858 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
1864 * Back-end article deletion
1865 * Deletes the article with database consistency, writes logs, purges caches
1868 function doDeleteArticle( $reason ) {
1869 global $wgUseSquid, $wgDeferredUpdateList;
1870 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1872 wfDebug( __METHOD__
."\n" );
1874 $dbw =& wfGetDB( DB_MASTER
);
1875 $ns = $this->mTitle
->getNamespace();
1876 $t = $this->mTitle
->getDBkey();
1877 $id = $this->mTitle
->getArticleID();
1879 if ( $t == '' ||
$id == 0 ) {
1883 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1884 array_push( $wgDeferredUpdateList, $u );
1886 // For now, shunt the revision data into the archive table.
1887 // Text is *not* removed from the text table; bulk storage
1888 // is left intact to avoid breaking block-compression or
1889 // immutable storage schemes.
1891 // For backwards compatibility, note that some older archive
1892 // table entries will have ar_text and ar_flags fields still.
1894 // In the future, we may keep revisions and mark them with
1895 // the rev_deleted field, which is reserved for this purpose.
1896 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1898 'ar_namespace' => 'page_namespace',
1899 'ar_title' => 'page_title',
1900 'ar_comment' => 'rev_comment',
1901 'ar_user' => 'rev_user',
1902 'ar_user_text' => 'rev_user_text',
1903 'ar_timestamp' => 'rev_timestamp',
1904 'ar_minor_edit' => 'rev_minor_edit',
1905 'ar_rev_id' => 'rev_id',
1906 'ar_text_id' => 'rev_text_id',
1909 'page_id = rev_page'
1913 # Now that it's safely backed up, delete it
1914 $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__
);
1916 # If using cascading deletes, we can skip some explicit deletes
1917 if ( !$dbw->cascadingDeletes() ) {
1919 $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__
);
1921 if ($wgUseTrackbacks)
1922 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__
);
1924 # Delete outgoing links
1925 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1926 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1927 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1928 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
1929 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
1930 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
1933 # If using cleanup triggers, we can skip some manual deletes
1934 if ( !$dbw->cleanupTriggers() ) {
1936 # Clean up recentchanges entries...
1937 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__
);
1941 Article
::onArticleDelete( $this->mTitle
);
1944 $log = new LogPage( 'delete' );
1945 $log->addEntry( 'delete', $this->mTitle
, $reason );
1947 # Clear the cached article id so the interface doesn't act like we exist
1948 $this->mTitle
->resetArticleID( 0 );
1949 $this->mTitle
->mArticleID
= 0;
1954 * Revert a modification
1956 function rollback() {
1957 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
1959 if( $wgUser->isAllowed( 'rollback' ) ) {
1960 if( $wgUser->isBlocked() ) {
1961 $wgOut->blockedPage();
1965 $wgOut->permissionRequired( 'rollback' );
1969 if ( wfReadOnly() ) {
1970 $wgOut->readOnlyPage( $this->getContent() );
1973 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
1974 array( $this->mTitle
->getPrefixedText(),
1975 $wgRequest->getVal( 'from' ) ) ) ) {
1976 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1977 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
1980 $dbw =& wfGetDB( DB_MASTER
);
1982 # Enhanced rollback, marks edits rc_bot=1
1983 $bot = $wgRequest->getBool( 'bot' );
1985 # Replace all this user's current edits with the next one down
1986 $tt = $this->mTitle
->getDBKey();
1987 $n = $this->mTitle
->getNamespace();
1989 # Get the last editor
1990 $current = Revision
::newFromTitle( $this->mTitle
);
1991 if( is_null( $current ) ) {
1992 # Something wrong... no page?
1993 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1997 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1998 if( $from != $current->getUserText() ) {
1999 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2000 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2001 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2002 htmlspecialchars( $from ),
2003 htmlspecialchars( $current->getUserText() ) ) );
2004 if( $current->getComment() != '') {
2006 wfMsg( 'editcomment',
2007 htmlspecialchars( $current->getComment() ) ) );
2012 # Get the last edit not by this guy
2013 $user = intval( $current->getUser() );
2014 $user_text = $dbw->addQuotes( $current->getUserText() );
2015 $s = $dbw->selectRow( 'revision',
2016 array( 'rev_id', 'rev_timestamp' ),
2018 'rev_page' => $current->getPage(),
2019 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2022 'USE INDEX' => 'page_timestamp',
2023 'ORDER BY' => 'rev_timestamp DESC' )
2025 if( $s === false ) {
2027 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2028 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2034 # Mark all reverted edits as bot
2037 if ( $wgUseRCPatrol ) {
2038 # Mark all reverted edits as patrolled
2039 $set['rc_patrolled'] = 1;
2043 $dbw->update( 'recentchanges', $set,
2045 'rc_cur_id' => $current->getPage(),
2046 'rc_user_text' => $current->getUserText(),
2047 "rc_timestamp > '{$s->rev_timestamp}'",
2052 # Get the edit summary
2053 $target = Revision
::newFromId( $s->rev_id
);
2054 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2055 $newComment = $wgRequest->getText( 'summary', $newComment );
2058 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2059 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2060 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2062 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2064 $wgOut->returnToMain( false );
2069 * Do standard deferred updates after page view
2072 function viewUpdates() {
2073 global $wgDeferredUpdateList;
2075 if ( 0 != $this->getID() ) {
2076 global $wgDisableCounters;
2077 if( !$wgDisableCounters ) {
2078 Article
::incViewCount( $this->getID() );
2079 $u = new SiteStatsUpdate( 1, 0, 0 );
2080 array_push( $wgDeferredUpdateList, $u );
2084 # Update newtalk / watchlist notification status
2086 $wgUser->clearNotification( $this->mTitle
);
2090 * Do standard deferred updates after page edit.
2091 * Update links tables, site stats, search index and message cache.
2092 * Every 1000th edit, prune the recent changes table.
2095 * @param $text New text of the article
2096 * @param $summary Edit summary
2097 * @param $minoredit Minor edit
2098 * @param $timestamp_of_pagechange Timestamp associated with the page change
2099 * @param $newid rev_id value of the new revision
2100 * @param $changed Whether or not the content actually changed
2102 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
2103 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2105 wfProfileIn( __METHOD__
);
2108 $options = new ParserOptions
;
2109 $options->setTidy(true);
2110 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2112 # Save it to the parser cache
2113 $parserCache =& ParserCache
::singleton();
2114 $parserCache->save( $poutput, $this, $wgUser );
2116 # Update the links tables
2117 $u = new LinksUpdate( $this->mTitle
, $poutput );
2120 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2122 if ( 0 == mt_rand( 0, 999 ) ) {
2123 # Periodically flush old entries from the recentchanges table.
2126 $dbw =& wfGetDB( DB_MASTER
);
2127 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2128 $recentchanges = $dbw->tableName( 'recentchanges' );
2129 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2130 $dbw->query( $sql );
2134 $id = $this->getID();
2135 $title = $this->mTitle
->getPrefixedDBkey();
2136 $shortTitle = $this->mTitle
->getDBkey();
2139 wfProfileOut( __METHOD__
);
2143 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2144 array_push( $wgDeferredUpdateList, $u );
2145 $u = new SearchUpdate( $id, $title, $text );
2146 array_push( $wgDeferredUpdateList, $u );
2148 # If this is another user's talk page, update newtalk
2149 # Don't do this if $changed = false otherwise some idiot can null-edit a
2150 # load of user talk pages and piss people off
2151 if( $this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getTitleKey() && $changed ) {
2152 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2153 $other = User
::newFromName( $shortTitle );
2154 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2155 // An anonymous user
2156 $other = new User();
2157 $other->setName( $shortTitle );
2160 $other->setNewtalk( true );
2165 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2166 $wgMessageCache->replace( $shortTitle, $text );
2169 wfProfileOut( __METHOD__
);
2173 * Generate the navigation links when browsing through an article revisions
2174 * It shows the information as:
2175 * Revision as of \<date\>; view current revision
2176 * \<- Previous version | Next Version -\>
2179 * @param string $oldid Revision ID of this article revision
2181 function setOldSubtitle( $oldid=0 ) {
2182 global $wgLang, $wgOut, $wgUser;
2184 if ( !wfRunHooks( 'DisplayOldSubtitle', array(&$this, &$oldid) ) ) {
2188 $revision = Revision
::newFromId( $oldid );
2190 $current = ( $oldid == $this->mLatest
);
2191 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2192 $sk = $wgUser->getSkin();
2194 ?
wfMsg( 'currentrevisionlink' )
2195 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2196 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2198 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2199 : wfMsg( 'previousrevision' );
2201 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'diff' ), 'diff=prev&oldid='.$oldid )
2203 $nextlink = $current
2204 ?
wfMsg( 'nextrevision' )
2205 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2206 $nextdiff = $current
2208 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'diff' ), 'diff=next&oldid='.$oldid );
2210 $userlinks = $sk->userLink( $revision->getUser(), $revision->getUserText() )
2211 . $sk->userToolLinks( $revision->getUser(), $revision->getUserText() );
2213 $r = wfMsg( 'old-revision-navigation', $td, $lnk, $prevlink, $nextlink, $userlinks, $prevdiff, $nextdiff );
2214 $wgOut->setSubtitle( $r );
2218 * This function is called right before saving the wikitext,
2219 * so we can do things like signatures and links-in-context.
2221 * @param string $text
2223 function preSaveTransform( $text ) {
2224 global $wgParser, $wgUser;
2225 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2228 /* Caching functions */
2231 * checkLastModified returns true if it has taken care of all
2232 * output to the client that is necessary for this request.
2233 * (that is, it has sent a cached version of the page)
2235 function tryFileCache() {
2236 static $called = false;
2238 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2242 if($this->isFileCacheable()) {
2243 $touched = $this->mTouched
;
2244 $cache = new CacheManager( $this->mTitle
);
2245 if($cache->isFileCacheGood( $touched )) {
2246 wfDebug( "Article::tryFileCache(): about to load file\n" );
2247 $cache->loadFromFileCache();
2250 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2251 ob_start( array(&$cache, 'saveToFileCache' ) );
2254 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2259 * Check if the page can be cached
2262 function isFileCacheable() {
2263 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2264 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2266 return $wgUseFileCache
2267 and (!$wgShowIPinHeader)
2268 and ($this->getID() != 0)
2269 and ($wgUser->isAnon())
2270 and (!$wgUser->getNewtalk())
2271 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2272 and (empty( $action ) ||
$action == 'view')
2273 and (!isset($oldid))
2275 and (!isset($redirect))
2276 and (!isset($printable))
2277 and (!$this->mRedirectedFrom
);
2281 * Loads page_touched and returns a value indicating if it should be used
2284 function checkTouched() {
2285 if( !$this->mDataLoaded
) {
2286 $this->loadPageData();
2288 return !$this->mIsRedirect
;
2292 * Get the page_touched field
2294 function getTouched() {
2295 # Ensure that page data has been loaded
2296 if( !$this->mDataLoaded
) {
2297 $this->loadPageData();
2299 return $this->mTouched
;
2303 * Get the page_latest field
2305 function getLatest() {
2306 if ( !$this->mDataLoaded
) {
2307 $this->loadPageData();
2309 return $this->mLatest
;
2313 * Edit an article without doing all that other stuff
2314 * The article must already exist; link tables etc
2315 * are not updated, caches are not flushed.
2317 * @param string $text text submitted
2318 * @param string $comment comment submitted
2319 * @param bool $minor whereas it's a minor modification
2321 function quickEdit( $text, $comment = '', $minor = 0 ) {
2322 wfProfileIn( __METHOD__
);
2324 $dbw =& wfGetDB( DB_MASTER
);
2326 $revision = new Revision( array(
2327 'page' => $this->getId(),
2329 'comment' => $comment,
2330 'minor_edit' => $minor ?
1 : 0,
2332 # fixme : $revisionId never used
2333 $revisionId = $revision->insertOn( $dbw );
2334 $this->updateRevisionOn( $dbw, $revision );
2337 wfProfileOut( __METHOD__
);
2341 * Used to increment the view counter
2344 * @param integer $id article id
2346 function incViewCount( $id ) {
2347 $id = intval( $id );
2348 global $wgHitcounterUpdateFreq, $wgDBtype;
2350 $dbw =& wfGetDB( DB_MASTER
);
2351 $pageTable = $dbw->tableName( 'page' );
2352 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2353 $acchitsTable = $dbw->tableName( 'acchits' );
2355 if( $wgHitcounterUpdateFreq <= 1 ){ //
2356 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2360 # Not important enough to warrant an error page in case of failure
2361 $oldignore = $dbw->ignoreErrors( true );
2363 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2365 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2366 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2367 # Most of the time (or on SQL errors), skip row count check
2368 $dbw->ignoreErrors( $oldignore );
2372 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2373 $row = $dbw->fetchObject( $res );
2374 $rown = intval( $row->n
);
2375 if( $rown >= $wgHitcounterUpdateFreq ){
2376 wfProfileIn( 'Article::incViewCount-collect' );
2377 $old_user_abort = ignore_user_abort( true );
2379 if ($wgDBtype == 'mysql')
2380 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2381 $tabletype = $wgDBtype == 'mysql' ?
"ENGINE=HEAP " : '';
2382 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
2383 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2385 $dbw->query("DELETE FROM $hitcounterTable");
2386 if ($wgDBtype == 'mysql')
2387 $dbw->query('UNLOCK TABLES');
2388 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2389 'WHERE page_id = hc_id');
2390 $dbw->query("DROP TABLE $acchitsTable");
2392 ignore_user_abort( $old_user_abort );
2393 wfProfileOut( 'Article::incViewCount-collect' );
2395 $dbw->ignoreErrors( $oldignore );
2399 * The onArticle*() functions are supposed to be a kind of hooks
2400 * which should be called whenever any of the specified actions
2403 * This is a good place to put code to clear caches, for instance.
2405 * This is called on page move and undelete, as well as edit
2407 * @param $title_obj a title object
2410 static function onArticleCreate($title) {
2411 # The talk page isn't in the regular link tables, so we need to update manually:
2412 if ( $title->isTalkPage() ) {
2413 $other = $title->getSubjectPage();
2415 $other = $title->getTalkPage();
2417 $other->invalidateCache();
2418 $other->purgeSquid();
2420 $title->touchLinks();
2421 $title->purgeSquid();
2424 static function onArticleDelete( $title ) {
2425 global $wgUseFileCache, $wgMessageCache;
2427 $title->touchLinks();
2428 $title->purgeSquid();
2431 if ( $wgUseFileCache ) {
2432 $cm = new CacheManager( $title );
2433 @unlink
( $cm->fileCacheName() );
2436 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2437 $wgMessageCache->replace( $title->getDBkey(), false );
2442 * Purge caches on page update etc
2444 static function onArticleEdit( $title ) {
2445 global $wgDeferredUpdateList, $wgUseFileCache;
2449 // Invalidate caches of articles which include this page
2450 $update = new HTMLCacheUpdate( $title, 'templatelinks' );
2451 $wgDeferredUpdateList[] = $update;
2453 # Purge squid for this page only
2454 $title->purgeSquid();
2457 if ( $wgUseFileCache ) {
2458 $cm = new CacheManager( $title );
2459 @unlink
( $cm->fileCacheName() );
2466 * Info about this page
2467 * Called for ?action=info when $wgAllowPageInfo is on.
2472 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2474 if ( !$wgAllowPageInfo ) {
2475 $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
2479 $page = $this->mTitle
->getSubjectPage();
2481 $wgOut->setPagetitle( $page->getPrefixedText() );
2482 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2484 # first, see if the page exists at all.
2485 $exists = $page->getArticleId() != 0;
2487 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2488 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2490 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2493 $dbr =& wfGetDB( DB_SLAVE
);
2495 'wl_title' => $page->getDBkey(),
2496 'wl_namespace' => $page->getNamespace() );
2497 $numwatchers = $dbr->selectField(
2502 $this->getSelectOptions() );
2504 $pageInfo = $this->pageCountInfo( $page );
2505 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2507 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2508 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2510 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2512 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2514 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2516 $wgOut->addHTML( '</ul>' );
2522 * Return the total number of edits and number of unique editors
2523 * on a given page. If page does not exist, returns false.
2525 * @param Title $title
2529 function pageCountInfo( $title ) {
2530 $id = $title->getArticleId();
2535 $dbr =& wfGetDB( DB_SLAVE
);
2537 $rev_clause = array( 'rev_page' => $id );
2539 $edits = $dbr->selectField(
2544 $this->getSelectOptions() );
2546 $authors = $dbr->selectField(
2548 'COUNT(DISTINCT rev_user_text)',
2551 $this->getSelectOptions() );
2553 return array( 'edits' => $edits, 'authors' => $authors );
2557 * Return a list of templates used by this article.
2558 * Uses the templatelinks table
2560 * @return array Array of Title objects
2562 function getUsedTemplates() {
2564 $id = $this->mTitle
->getArticleID();
2569 $dbr =& wfGetDB( DB_SLAVE
);
2570 $res = $dbr->select( array( 'templatelinks' ),
2571 array( 'tl_namespace', 'tl_title' ),
2572 array( 'tl_from' => $id ),
2573 'Article:getUsedTemplates' );
2574 if ( false !== $res ) {
2575 if ( $dbr->numRows( $res ) ) {
2576 while ( $row = $dbr->fetchObject( $res ) ) {
2577 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2581 $dbr->freeResult( $res );