8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
12 global $wgArticleCurContentFields, $wgArticleOldContentFields;
14 $wgArticleCurContentFields = false;
15 $wgArticleOldContentFields = false;
18 * Class representing a MediaWiki article and history.
20 * See design.txt for an overview.
21 * Note: edit user interface and cache support functions have been
22 * moved to separate EditPage and CacheManager classes.
32 var $mContentLoaded; //!<
36 var $mGoodAdjustment; //!<
41 var $mRedirectedFrom; //!<
42 var $mRedirectUrl; //!<
43 var $mRevIdFetched; //!<
48 var $mTotalAdjustment; //!<
55 * Constructor and clear the article
56 * @param $title Reference to a Title object.
57 * @param $oldId Integer revision ID, null to fetch from request, zero for current
59 function Article( &$title, $oldId = null ) {
60 $this->mTitle
=& $title;
61 $this->mOldId
= $oldId;
66 * Tell the page view functions that this view was redirected
67 * from another page on the wiki.
68 * @param $from Title object.
70 function setRedirectedFrom( $from ) {
71 $this->mRedirectedFrom
= $from;
75 * @return mixed false, Title of in-wiki target, or string with URL
77 function followRedirect() {
78 $text = $this->getContent();
79 $rt = Title
::newFromRedirect( $text );
81 # process if title object is valid and not special:userlogout
83 if( $rt->getInterwiki() != '' ) {
84 if( $rt->isLocal() ) {
85 // Offsite wikis need an HTTP redirect.
87 // This can be hard to reverse and may produce loops,
88 // so they may be disabled in the site configuration.
90 $source = $this->mTitle
->getFullURL( 'redirect=no' );
91 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
94 if( $rt->getNamespace() == NS_SPECIAL
) {
95 // Gotta hand redirects to special pages differently:
96 // Fill the HTTP response "Location" header and ignore
97 // the rest of the page we're on.
99 // This can be hard to reverse, so they may be disabled.
101 if( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) {
104 return $rt->getFullURL();
111 // No or invalid redirect
116 * get the title object of the article
118 function getTitle() {
119 return $this->mTitle
;
127 $this->mDataLoaded
= false;
128 $this->mContentLoaded
= false;
130 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
131 $this->mRedirectedFrom
= null; # Title object if set
133 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
134 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
135 $this->mTouched
= '19700101000000';
136 $this->mForUpdate
= false;
137 $this->mIsRedirect
= false;
138 $this->mRevIdFetched
= 0;
139 $this->mRedirectUrl
= false;
140 $this->mLatest
= false;
144 * Note that getContent/loadContent do not follow redirects anymore.
145 * If you need to fetch redirectable content easily, try
146 * the shortcut in Article::followContent()
148 * @todo There are still side-effects in this!
149 * In general, you should use the Revision class, not Article,
150 * to fetch text for purposes other than page views.
152 * @return Return the text of this revision
154 function getContent() {
155 global $wgRequest, $wgUser, $wgOut;
157 # Get variables from query string :P
158 $action = $wgRequest->getText( 'action', 'view' );
159 $section = $wgRequest->getText( 'section' );
160 $preload = $wgRequest->getText( 'preload' );
162 $fname = 'Article::getContent';
163 wfProfileIn( $fname );
165 if ( 0 == $this->getID() ) {
166 if ( 'edit' == $action ) {
167 wfProfileOut( $fname );
169 # If requested, preload some text.
170 $text=$this->getPreloadedText($preload);
172 # We used to put MediaWiki:Newarticletext here if
173 # $text was empty at this point.
174 # This is now shown above the edit box instead.
177 wfProfileOut( $fname );
178 $wgOut->setRobotpolicy( 'noindex,nofollow' );
180 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
181 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
183 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
186 return "<div class='noarticletext'>$ret</div>";
188 $this->loadContent();
189 if($action=='edit') {
191 if($section=='new') {
192 wfProfileOut( $fname );
193 $text=$this->getPreloadedText($preload);
197 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
198 # comments to be stripped as well)
199 $rv=$this->getSection($this->mContent
,$section);
200 wfProfileOut( $fname );
204 wfProfileOut( $fname );
205 return $this->mContent
;
210 * Get the contents of a page from its title and remove includeonly tags
212 * @param $preload String: the title of the page.
213 * @return string The contents of the page.
215 function getPreloadedText($preload) {
216 if ( $preload === '' )
219 $preloadTitle = Title
::newFromText( $preload );
220 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
221 $rev=Revision
::newFromTitle($preloadTitle);
222 if ( is_object( $rev ) ) {
223 $text = $rev->getText();
224 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
225 // its own mini-parser! -ævar
226 $text = preg_replace( '~</?includeonly>~', '', $text );
235 * This function returns the text of a section, specified by a number ($section).
236 * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
237 * the first section before any such heading (section 0).
239 * If a section contains subsections, these are also returned.
241 * @param $text String: text to look in
242 * @param $section Integer: section number
243 * @return string text of the requested section
245 function getSection($text,$section) {
247 return $wgParser->getSection( $text, $section );
251 * @return int The oldid of the article that is to be shown, 0 for the
254 function getOldID() {
255 if ( is_null( $this->mOldId
) ) {
256 $this->mOldId
= $this->getOldIDFromRequest();
258 return $this->mOldId
;
262 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
264 * @return int The old id for the request
266 function getOldIDFromRequest() {
268 $this->mRedirectUrl
= false;
269 $oldid = $wgRequest->getVal( 'oldid' );
270 if ( isset( $oldid ) ) {
271 $oldid = intval( $oldid );
272 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
273 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
277 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
279 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
280 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
297 * Load the revision (including text) into this object
299 function loadContent() {
300 if ( $this->mContentLoaded
) return;
303 $oldid = $this->getOldID();
305 # Pre-fill content with error message so that if something
306 # fails we'll have something telling us what we intended.
308 $t = $this->mTitle
->getPrefixedText();
310 $this->mOldId
= $oldid;
311 $this->fetchContent( $oldid );
316 * Fetch a page record with the given conditions
317 * @param Database $dbr
318 * @param array $conditions
321 function pageData( &$dbr, $conditions ) {
334 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
335 $row = $dbr->selectRow( 'page',
338 'Article::pageData' );
339 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
344 * @param Database $dbr
345 * @param Title $title
347 function pageDataFromTitle( &$dbr, $title ) {
348 return $this->pageData( $dbr, array(
349 'page_namespace' => $title->getNamespace(),
350 'page_title' => $title->getDBkey() ) );
354 * @param Database $dbr
357 function pageDataFromId( &$dbr, $id ) {
358 return $this->pageData( $dbr, array( 'page_id' => $id ) );
362 * Set the general counter, title etc data loaded from
365 * @param object $data
368 function loadPageData( $data = 'fromdb' ) {
369 if ( $data === 'fromdb' ) {
370 $dbr =& $this->getDB();
371 $data = $this->pageDataFromId( $dbr, $this->getId() );
374 $lc =& LinkCache
::singleton();
376 $lc->addGoodLinkObj( $data->page_id
, $this->mTitle
);
378 $this->mTitle
->mArticleID
= $data->page_id
;
379 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
380 $this->mTitle
->mRestrictionsLoaded
= true;
382 $this->mCounter
= $data->page_counter
;
383 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
384 $this->mIsRedirect
= $data->page_is_redirect
;
385 $this->mLatest
= $data->page_latest
;
387 if ( is_object( $this->mTitle
) ) {
388 $lc->addBadLinkObj( $this->mTitle
);
390 $this->mTitle
->mArticleID
= 0;
393 $this->mDataLoaded
= true;
397 * Get text of an article from database
398 * Does *NOT* follow redirects.
399 * @param int $oldid 0 for whatever the latest revision is
402 function fetchContent( $oldid = 0 ) {
403 if ( $this->mContentLoaded
) {
404 return $this->mContent
;
407 $dbr =& $this->getDB();
408 $fname = 'Article::fetchContent';
410 # Pre-fill content with error message so that if something
411 # fails we'll have something telling us what we intended.
412 $t = $this->mTitle
->getPrefixedText();
414 $t .= ',oldid='.$oldid;
416 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
419 $revision = Revision
::newFromId( $oldid );
420 if( is_null( $revision ) ) {
421 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
424 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
426 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
429 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
430 $this->loadPageData( $data );
432 if( !$this->mDataLoaded
) {
433 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
435 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
438 $this->loadPageData( $data );
440 $revision = Revision
::newFromId( $this->mLatest
);
441 if( is_null( $revision ) ) {
442 wfDebug( "$fname failed to retrieve current page, rev_id {$data->page_latest}\n" );
447 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
448 // We should instead work with the Revision object when we need it...
449 $this->mContent
= $revision->userCan( Revision
::MW_REV_DELETED_TEXT
) ?
$revision->getRawText() : "";
450 //$this->mContent = $revision->getText();
452 $this->mUser
= $revision->getUser();
453 $this->mUserText
= $revision->getUserText();
454 $this->mComment
= $revision->getComment();
455 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
457 $this->mRevIdFetched
= $revision->getID();
458 $this->mContentLoaded
= true;
459 $this->mRevision
=& $revision;
461 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
463 return $this->mContent
;
467 * Read/write accessor to select FOR UPDATE
469 * @param $x Mixed: FIXME
471 function forUpdate( $x = NULL ) {
472 return wfSetVar( $this->mForUpdate
, $x );
476 * Get the database which should be used for reads
481 $ret =& wfGetDB( DB_MASTER
);
486 * Get options for all SELECT statements
488 * @param $options Array: an optional options array which'll be appended to
490 * @return Array: options
492 function getSelectOptions( $options = '' ) {
493 if ( $this->mForUpdate
) {
494 if ( is_array( $options ) ) {
495 $options[] = 'FOR UPDATE';
497 $options = 'FOR UPDATE';
504 * @return int Page ID
507 if( $this->mTitle
) {
508 return $this->mTitle
->getArticleID();
515 * @return bool Whether or not the page exists in the database
518 return $this->getId() != 0;
522 * @return int The view count for the page
524 function getCount() {
525 if ( -1 == $this->mCounter
) {
526 $id = $this->getID();
530 $dbr =& wfGetDB( DB_SLAVE
);
531 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
532 'Article::getCount', $this->getSelectOptions() );
535 return $this->mCounter
;
539 * Determine whether a page would be suitable for being counted as an
540 * article in the site_stats table based on the title & its content
542 * @param $text String: text to analyze
545 function isCountable( $text ) {
546 global $wgUseCommaCount;
548 $token = $wgUseCommaCount ?
',' : '[[';
550 $this->mTitle
->getNamespace() == NS_MAIN
551 && ! $this->isRedirect( $text )
552 && in_string( $token, $text );
556 * Tests if the article text represents a redirect
558 * @param $text String: FIXME
561 function isRedirect( $text = false ) {
562 if ( $text === false ) {
563 $this->loadContent();
564 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
566 $titleObj = Title
::newFromRedirect( $text );
568 return $titleObj !== NULL;
572 * Returns true if the currently-referenced revision is the current edit
573 * to this page (and it exists).
576 function isCurrent() {
577 return $this->exists() &&
578 isset( $this->mRevision
) &&
579 $this->mRevision
->isCurrent();
583 * Loads everything except the text
584 * This isn't necessary for all uses, so it's only done if needed.
587 function loadLastEdit() {
588 if ( -1 != $this->mUser
)
591 # New or non-existent articles have no user information
592 $id = $this->getID();
593 if ( 0 == $id ) return;
595 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
596 if( !is_null( $this->mLastRevision
) ) {
597 $this->mUser
= $this->mLastRevision
->getUser();
598 $this->mUserText
= $this->mLastRevision
->getUserText();
599 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
600 $this->mComment
= $this->mLastRevision
->getComment();
601 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
602 $this->mRevIdFetched
= $this->mLastRevision
->getID();
606 function getTimestamp() {
607 // Check if the field has been filled by ParserCache::get()
608 if ( !$this->mTimestamp
) {
609 $this->loadLastEdit();
611 return wfTimestamp(TS_MW
, $this->mTimestamp
);
615 $this->loadLastEdit();
619 function getUserText() {
620 $this->loadLastEdit();
621 return $this->mUserText
;
624 function getComment() {
625 $this->loadLastEdit();
626 return $this->mComment
;
629 function getMinorEdit() {
630 $this->loadLastEdit();
631 return $this->mMinorEdit
;
634 function getRevIdFetched() {
635 $this->loadLastEdit();
636 return $this->mRevIdFetched
;
640 * @todo Document, fixme $offset never used.
641 * @param $limit Integer: default 0.
642 * @param $offset Integer: default 0.
644 function getContributors($limit = 0, $offset = 0) {
645 $fname = 'Article::getContributors';
647 # XXX: this is expensive; cache this info somewhere.
649 $title = $this->mTitle
;
651 $dbr =& wfGetDB( DB_SLAVE
);
652 $revTable = $dbr->tableName( 'revision' );
653 $userTable = $dbr->tableName( 'user' );
654 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
655 $ns = $title->getNamespace();
656 $user = $this->getUser();
657 $pageId = $this->getId();
659 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
660 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
661 WHERE rev_page = $pageId
662 AND rev_user != $user
663 GROUP BY rev_user, rev_user_text, user_real_name
664 ORDER BY timestamp DESC";
666 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
667 $sql .= ' '. $this->getSelectOptions();
669 $res = $dbr->query($sql, $fname);
671 while ( $line = $dbr->fetchObject( $res ) ) {
672 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
675 $dbr->freeResult($res);
680 * This is the default action of the script: just view the page of
684 global $wgUser, $wgOut, $wgRequest, $wgContLang;
685 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
686 global $wgUseTrackbacks, $wgNamespaceRobotPolicies;
687 $sk = $wgUser->getSkin();
689 $fname = 'Article::view';
690 wfProfileIn( $fname );
692 $parserCache =& ParserCache
::singleton();
693 $ns = $this->mTitle
->getNamespace(); # shortcut
695 # Get variables from query string
696 $oldid = $this->getOldID();
698 # getOldID may want us to redirect somewhere else
699 if ( $this->mRedirectUrl
) {
700 $wgOut->redirect( $this->mRedirectUrl
);
701 wfProfileOut( $fname );
705 $diff = $wgRequest->getVal( 'diff' );
706 $rcid = $wgRequest->getVal( 'rcid' );
707 $rdfrom = $wgRequest->getVal( 'rdfrom' );
709 $wgOut->setArticleFlag( true );
710 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
711 $policy = $wgNamespaceRobotPolicies[$ns];
713 $policy = 'index,follow';
715 $wgOut->setRobotpolicy( $policy );
717 # If we got diff and oldid in the query, we want to see a
718 # diff page instead of the article.
720 if ( !is_null( $diff ) ) {
721 require_once( 'DifferenceEngine.php' );
722 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
724 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
725 // DifferenceEngine directly fetched the revision:
726 $this->mRevIdFetched
= $de->mNewid
;
730 # Run view updates for current revision only
731 $this->viewUpdates();
733 wfProfileOut( $fname );
737 if ( empty( $oldid ) && $this->checkTouched() ) {
738 $wgOut->setETag($parserCache->getETag($this, $wgUser));
740 if( $wgOut->checkLastModified( $this->mTouched
) ){
741 wfProfileOut( $fname );
743 } else if ( $this->tryFileCache() ) {
744 # tell wgOut that output is taken care of
746 $this->viewUpdates();
747 wfProfileOut( $fname );
751 # Should the parser cache be used?
752 $pcache = $wgEnableParserCache &&
753 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
756 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
757 if ( $wgUser->getOption( 'stubthreshold' ) ) {
758 wfIncrStats( 'pcache_miss_stub' );
761 $wasRedirected = false;
762 if ( isset( $this->mRedirectedFrom
) ) {
763 // This is an internally redirected page view.
764 // We'll need a backlink to the source page for navigation.
765 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
766 $sk = $wgUser->getSkin();
767 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
768 $s = wfMsg( 'redirectedfrom', $redir );
769 $wgOut->setSubtitle( $s );
770 $wasRedirected = true;
772 } elseif ( !empty( $rdfrom ) ) {
773 // This is an externally redirected view, from some other wiki.
774 // If it was reported from a trusted site, supply a backlink.
775 global $wgRedirectSources;
776 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
777 $sk = $wgUser->getSkin();
778 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
779 $s = wfMsg( 'redirectedfrom', $redir );
780 $wgOut->setSubtitle( $s );
781 $wasRedirected = true;
787 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
791 if ( !$outputDone ) {
792 $text = $this->getContent();
793 if ( $text === false ) {
794 # Failed to load, replace text with error message
795 $t = $this->mTitle
->getPrefixedText();
797 $t .= ',oldid='.$oldid;
798 $text = wfMsg( 'missingarticle', $t );
800 $text = wfMsg( 'noarticletext', $t );
804 # Another whitelist check in case oldid is altering the title
805 if ( !$this->mTitle
->userCanRead() ) {
806 $wgOut->loginToUse();
811 # We're looking at an old revision
813 if ( !empty( $oldid ) ) {
814 $wgOut->setRobotpolicy( 'noindex,nofollow' );
815 if( is_null( $this->mRevision
) ) {
816 // FIXME: This would be a nice place to load the 'no such page' text.
818 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
819 if( $this->mRevision
->isDeleted( Revision
::MW_REV_DELETED_TEXT
) ) {
820 if( !$this->mRevision
->userCan( Revision
::MW_REV_DELETED_TEXT
) ) {
821 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
822 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
825 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
826 // and we are allowed to see...
835 * @fixme: this hook doesn't work most of the time, as it doesn't
836 * trigger when the parser cache is used.
838 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
839 $wgOut->setRevisionId( $this->getRevIdFetched() );
840 # wrap user css and user js in pre and don't parse
841 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
844 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
846 $wgOut->addWikiText( wfMsg('clearyourcache'));
847 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
848 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
850 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
851 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
852 # Don't overwrite the subtitle if this was an old revision
853 if( !$wasRedirected && $this->isCurrent() ) {
854 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
856 $targetUrl = $rt->escapeLocalURL();
857 #Â fixme unused $titleText :
858 $titleText = htmlspecialchars( $rt->getPrefixedText() );
859 $link = $sk->makeLinkObj( $rt );
861 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
862 '<span class="redirectText">'.$link.'</span>' );
864 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
865 $wgOut->addParserOutputNoText( $parseout );
866 } else if ( $pcache ) {
867 # Display content and save to parser cache
868 $wgOut->addPrimaryWikiText( $text, $this );
870 # Display content, don't attempt to save to parser cache
872 # Don't show section-edit links on old revisions... this way lies madness.
873 if( !$this->isCurrent() ) {
874 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
876 # Display content and don't save to parser cache
877 $wgOut->addPrimaryWikiText( $text, $this, false );
879 if( !$this->isCurrent() ) {
880 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
884 /* title may have been set from the cache */
885 $t = $wgOut->getPageTitle();
887 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
890 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
891 if( $ns == NS_USER_TALK
&&
892 User
::isIP( $this->mTitle
->getText() ) ) {
893 $wgOut->addWikiText( wfMsg('anontalkpagetext') );
896 # If we have been passed an &rcid= parameter, we want to give the user a
897 # chance to mark this new article as patrolled.
898 if ( $wgUseRCPatrol && !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
900 "<div class='patrollink'>" .
901 wfMsg ( 'markaspatrolledlink',
902 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
909 if ($wgUseTrackbacks)
910 $this->addTrackbacks();
912 $this->viewUpdates();
913 wfProfileOut( $fname );
916 function addTrackbacks() {
917 global $wgOut, $wgUser;
919 $dbr =& wfGetDB(DB_SLAVE
);
921 /* FROM */ 'trackbacks',
922 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
923 /* WHERE */ array('tb_page' => $this->getID())
926 if (!$dbr->numrows($tbs))
930 while ($o = $dbr->fetchObject($tbs)) {
932 if ($wgUser->isAllowed( 'trackback' )) {
933 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
934 . $o->tb_id
. "&token=" . $wgUser->editToken());
935 $rmvtxt = wfMsg('trackbackremove', $delurl);
937 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
944 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
947 function deletetrackback() {
948 global $wgUser, $wgRequest, $wgOut, $wgTitle;
950 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
951 $wgOut->addWikitext(wfMsg('sessionfailure'));
955 if ((!$wgUser->isAllowed('delete'))) {
956 $wgOut->sysopRequired();
961 $wgOut->readOnlyPage();
965 $db =& wfGetDB(DB_MASTER
);
966 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
967 $wgTitle->invalidateCache();
968 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
974 $wgOut->setArticleBodyOnly(true);
979 * Handle action=purge
982 global $wgUser, $wgRequest, $wgOut;
984 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
985 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
989 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
990 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
991 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
992 $msg = str_replace( '$1',
993 "<form method=\"post\" action=\"$action\">\n" .
994 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
997 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
998 $wgOut->setRobotpolicy( 'noindex,nofollow' );
999 $wgOut->addHTML( $msg );
1004 * Perform the actions of a page purging
1006 function doPurge() {
1008 // Invalidate the cache
1009 $this->mTitle
->invalidateCache();
1011 if ( $wgUseSquid ) {
1012 // Commit the transaction before the purge is sent
1013 $dbw = wfGetDB( DB_MASTER
);
1014 $dbw->immediateCommit();
1017 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
1018 $update->doUpdate();
1024 * Insert a new empty page record for this article.
1025 * This *must* be followed up by creating a revision
1026 * and running $this->updateToLatest( $rev_id );
1027 * or else the record will be left in a funky state.
1028 * Best if all done inside a transaction.
1030 * @param Database $dbw
1031 * @param string $restrictions
1032 * @return int The newly created page_id key
1035 function insertOn( &$dbw, $restrictions = '' ) {
1036 $fname = 'Article::insertOn';
1037 wfProfileIn( $fname );
1039 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1040 $dbw->insert( 'page', array(
1041 'page_id' => $page_id,
1042 'page_namespace' => $this->mTitle
->getNamespace(),
1043 'page_title' => $this->mTitle
->getDBkey(),
1044 'page_counter' => 0,
1045 'page_restrictions' => $restrictions,
1046 'page_is_redirect' => 0, # Will set this shortly...
1048 'page_random' => wfRandom(),
1049 'page_touched' => $dbw->timestamp(),
1050 'page_latest' => 0, # Fill this in shortly...
1051 'page_len' => 0, # Fill this in shortly...
1053 $newid = $dbw->insertId();
1055 $this->mTitle
->resetArticleId( $newid );
1057 wfProfileOut( $fname );
1062 * Update the page record to point to a newly saved revision.
1064 * @param Database $dbw
1065 * @param Revision $revision For ID number, and text used to set
1066 length and redirect status fields
1067 * @param int $lastRevision If given, will not overwrite the page field
1068 * when different from the currently set value.
1069 * Giving 0 indicates the new page flag should
1071 * @return bool true on success, false on failure
1074 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1075 $fname = 'Article::updateToRevision';
1076 wfProfileIn( $fname );
1078 $conditions = array( 'page_id' => $this->getId() );
1079 if( !is_null( $lastRevision ) ) {
1080 # An extra check against threads stepping on each other
1081 $conditions['page_latest'] = $lastRevision;
1084 $text = $revision->getText();
1085 $dbw->update( 'page',
1087 'page_latest' => $revision->getId(),
1088 'page_touched' => $dbw->timestamp(),
1089 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1090 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1091 'page_len' => strlen( $text ),
1096 wfProfileOut( $fname );
1097 return ( $dbw->affectedRows() != 0 );
1101 * If the given revision is newer than the currently set page_latest,
1102 * update the page record. Otherwise, do nothing.
1104 * @param Database $dbw
1105 * @param Revision $revision
1107 function updateIfNewerOn( &$dbw, $revision ) {
1108 $fname = 'Article::updateIfNewerOn';
1109 wfProfileIn( $fname );
1111 $row = $dbw->selectRow(
1112 array( 'revision', 'page' ),
1113 array( 'rev_id', 'rev_timestamp' ),
1115 'page_id' => $this->getId(),
1116 'page_latest=rev_id' ),
1119 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1120 wfProfileOut( $fname );
1123 $prev = $row->rev_id
;
1125 # No or missing previous revision; mark the page as new
1129 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1130 wfProfileOut( $fname );
1135 * Insert a new article into the database
1138 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1141 $fname = 'Article::insertNewArticle';
1142 wfProfileIn( $fname );
1144 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1145 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1146 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1147 wfProfileOut( $fname );
1151 $ns = $this->mTitle
->getNamespace();
1152 $ttl = $this->mTitle
->getDBkey();
1154 # If this is a comment, add the summary as headline
1155 if($comment && $summary!="") {
1156 $text="== {$summary} ==\n\n".$text;
1158 $text = $this->preSaveTransform( $text );
1161 # Set statistics members
1162 # We work out if it's countable after PST to avoid counter drift
1163 # when articles are created with {{subst:}}
1164 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1165 $this->mTotalAdjustment
= 1;
1167 /* Silently ignore minoredit if not allowed */
1168 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1169 $now = wfTimestampNow();
1171 $dbw =& wfGetDB( DB_MASTER
);
1173 # Add the page record; stake our claim on this title!
1174 $newid = $this->insertOn( $dbw );
1176 # Save the revision text...
1177 $revision = new Revision( array(
1179 'comment' => $summary,
1180 'minor_edit' => $isminor,
1183 $revisionId = $revision->insertOn( $dbw );
1185 $this->mTitle
->resetArticleID( $newid );
1187 # Update the page record with revision data
1188 $this->updateRevisionOn( $dbw, $revision, 0 );
1190 Article
::onArticleCreate( $this->mTitle
);
1192 require_once( 'RecentChange.php' );
1193 $rcid = RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1194 '', strlen( $text ), $revisionId );
1195 # Mark as patrolled if the user can and has the option set
1196 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1197 RecentChange
::markPatrolled( $rcid );
1202 if(!$this->mTitle
->userIsWatching()) $this->doWatch();
1204 if ( $this->mTitle
->userIsWatching() ) {
1209 # The talk page isn't in the regular link tables, so we need to update manually:
1210 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1211 $dbw->update( 'page',
1212 array( 'page_touched' => $dbw->timestamp($now) ),
1213 array( 'page_namespace' => $talkns,
1214 'page_title' => $ttl ),
1217 # standard deferred updates
1218 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1220 $oldid = 0; # new article
1221 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1223 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1225 $watchthis, NULL ) );
1226 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1228 $watchthis, NULL ) );
1229 wfProfileOut( $fname );
1233 * @return string Complete article text, or null if error
1235 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1236 $fname = 'Article::replaceSection';
1237 wfProfileIn( $fname );
1239 if( $section == '' ) {
1240 // Whole-page edit; let the text through unmolested.
1242 if( is_null( $edittime ) ) {
1243 $rev = Revision
::newFromTitle( $this->mTitle
);
1245 $dbw =& wfGetDB( DB_MASTER
);
1246 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1248 if( is_null( $rev ) ) {
1249 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1250 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1253 $oldtext = $rev->getText();
1255 if($section=='new') {
1256 if($summary) $subject="== {$summary} ==\n\n";
1257 $text=$oldtext."\n\n".$subject.$text;
1260 $text = $wgParser->replaceSection( $oldtext, $section, $text );
1264 wfProfileOut( $fname );
1269 * Change an existing article. Puts the previous version back into the old table, updates RC
1270 * and all necessary caches, mostly via the deferred update array.
1272 * It is possible to call this function from a command-line script, but note that you should
1273 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1275 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1276 global $wgUser, $wgDBtransactions, $wgUseSquid;
1277 global $wgPostCommitUpdateList, $wgUseFileCache;
1279 $fname = 'Article::updateArticle';
1280 wfProfileIn( $fname );
1283 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1285 &$watchthis, &$sectionanchor ) ) ) {
1286 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1287 wfProfileOut( $fname );
1291 $isminor = $minor && $wgUser->isAllowed('minoredit');
1293 $text = $this->preSaveTransform( $text );
1294 $dbw =& wfGetDB( DB_MASTER
);
1295 $now = wfTimestampNow();
1297 # Update article, but only if changed.
1299 # It's important that we either rollback or complete, otherwise an attacker could
1300 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1301 # could conceivably have the same effect, especially if cur is locked for long periods.
1302 if( !$wgDBtransactions ) {
1303 $userAbort = ignore_user_abort( true );
1306 $oldtext = $this->getContent();
1307 $oldsize = strlen( $oldtext );
1308 $newsize = strlen( $text );
1312 if ( 0 != strcmp( $text, $oldtext ) ) {
1313 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1314 - (int)$this->isCountable( $oldtext );
1315 $this->mTotalAdjustment
= 0;
1316 $now = wfTimestampNow();
1318 $lastRevision = $dbw->selectField(
1319 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1321 $revision = new Revision( array(
1322 'page' => $this->getId(),
1323 'comment' => $summary,
1324 'minor_edit' => $isminor,
1328 $dbw->immediateCommit();
1330 $revisionId = $revision->insertOn( $dbw );
1333 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1336 /* Belated edit conflict! Run away!! */
1340 # Update recentchanges and purge cache and whatnot
1341 require_once( 'RecentChange.php' );
1342 $bot = (int)($wgUser->isBot() ||
$forceBot);
1343 $rcid = RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1344 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1347 # Mark as patrolled if the user can do so and has it set in their options
1348 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1349 RecentChange
::markPatrolled( $rcid );
1354 // Update caches outside the main transaction
1355 Article
::onArticleEdit( $this->mTitle
);
1358 // Keep the same revision ID, but do some updates on it
1359 $revisionId = $this->getRevIdFetched();
1362 if( !$wgDBtransactions ) {
1363 ignore_user_abort( $userAbort );
1368 if (!$this->mTitle
->userIsWatching()) {
1369 $dbw->immediateCommit();
1375 if ( $this->mTitle
->userIsWatching() ) {
1376 $dbw->immediateCommit();
1382 # standard deferred updates
1383 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1387 # Invalidate caches of all articles using this article as a template
1389 # Template namespace
1390 # Purge all articles linking here
1391 $titles = $this->mTitle
->getTemplateLinksTo();
1392 Title
::touchArray( $titles );
1393 if ( $wgUseSquid ) {
1394 foreach ( $titles as $title ) {
1395 $urls[] = $title->getInternalURL();
1400 if ( $wgUseSquid ) {
1401 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1402 $u = new SquidUpdate( $urls );
1403 array_push( $wgPostCommitUpdateList, $u );
1407 if ( $wgUseFileCache ) {
1408 $cm = new CacheManager($this->mTitle
);
1409 @unlink
($cm->fileCacheName());
1412 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1414 wfRunHooks( 'ArticleSaveComplete',
1415 array( &$this, &$wgUser, $text,
1417 $watchthis, $sectionanchor ) );
1418 wfProfileOut( $fname );
1423 * After we've either updated or inserted the article, update
1424 * the link tables and redirect to the new page.
1425 * @todo FIXME some function arguments never used
1427 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1430 $fname = 'Article::showArticle';
1431 wfProfileIn( $fname );
1433 # Output the redirect
1434 if( $this->isRedirect( $text ) )
1438 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1440 wfProfileOut( $fname );
1444 * Mark this particular edit as patrolled
1446 function markpatrolled() {
1447 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
1448 $wgOut->setRobotpolicy( 'noindex,follow' );
1450 # Check RC patrol config. option
1451 if( !$wgUseRCPatrol ) {
1452 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1457 if( !$wgUser->isAllowed( 'patrol' ) ) {
1458 $wgOut->permissionRequired( 'patrol' );
1462 $rcid = $wgRequest->getVal( 'rcid' );
1463 if ( !is_null ( $rcid ) ) {
1464 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
1465 require_once( 'RecentChange.php' );
1466 RecentChange
::markPatrolled( $rcid );
1467 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1468 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1469 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1471 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1472 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1475 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1480 * User-interface handler for the "watch" action
1485 global $wgUser, $wgOut;
1487 if ( $wgUser->isAnon() ) {
1488 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1491 if ( wfReadOnly() ) {
1492 $wgOut->readOnlyPage();
1496 if( $this->doWatch() ) {
1497 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1498 $wgOut->setRobotpolicy( 'noindex,follow' );
1500 $link = $this->mTitle
->getPrefixedText();
1501 $text = wfMsg( 'addedwatchtext', $link );
1502 $wgOut->addWikiText( $text );
1505 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1509 * Add this page to $wgUser's watchlist
1510 * @return bool true on successful watch operation
1512 function doWatch() {
1514 if( $wgUser->isAnon() ) {
1518 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1519 $wgUser->addWatch( $this->mTitle
);
1520 $wgUser->saveSettings();
1522 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1529 * User interface handler for the "unwatch" action.
1531 function unwatch() {
1533 global $wgUser, $wgOut;
1535 if ( $wgUser->isAnon() ) {
1536 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1539 if ( wfReadOnly() ) {
1540 $wgOut->readOnlyPage();
1544 if( $this->doUnwatch() ) {
1545 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1546 $wgOut->setRobotpolicy( 'noindex,follow' );
1548 $link = $this->mTitle
->getPrefixedText();
1549 $text = wfMsg( 'removedwatchtext', $link );
1550 $wgOut->addWikiText( $text );
1553 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1557 * Stop watching a page
1558 * @return bool true on successful unwatch
1560 function doUnwatch() {
1562 if( $wgUser->isAnon() ) {
1566 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1567 $wgUser->removeWatch( $this->mTitle
);
1568 $wgUser->saveSettings();
1570 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1577 * action=protect handler
1579 function protect() {
1580 require_once 'ProtectionForm.php';
1581 $form = new ProtectionForm( $this );
1586 * action=unprotect handler (alias)
1588 function unprotect() {
1593 * Update the article's restriction field, and leave a log entry.
1595 * @param array $limit set of restriction keys
1596 * @param string $reason
1597 * @return bool true on success
1599 function updateRestrictions( $limit = array(), $reason = '' ) {
1600 global $wgUser, $wgRestrictionTypes, $wgContLang;
1602 $id = $this->mTitle
->getArticleID();
1603 if( !$wgUser->isAllowed( 'protect' ) ||
wfReadOnly() ||
$id == 0 ) {
1607 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1608 # we expect a single selection, but the schema allows otherwise.
1610 foreach( $wgRestrictionTypes as $action )
1611 $current[$action] = implode( '', $this->mTitle
->getRestrictions( $action ) );
1613 $current = Article
::flattenRestrictions( $current );
1614 $updated = Article
::flattenRestrictions( $limit );
1616 $changed = ( $current != $updated );
1617 $protect = ( $updated != '' );
1619 # If nothing's changed, do nothing
1621 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1623 $dbw =& wfGetDB( DB_MASTER
);
1625 # Prepare a null revision to be added to the history
1626 $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ?
'protectedarticle' : 'unprotectedarticle', $this->mTitle
->getPrefixedText() ) );
1628 $comment .= ": $reason";
1630 $comment .= " [$updated]";
1631 $nullRevision = Revision
::newNullRevision( $dbw, $id, $comment, true );
1632 $nullRevId = $nullRevision->insertOn( $dbw );
1634 # Update page record
1635 $dbw->update( 'page',
1637 'page_touched' => $dbw->timestamp(),
1638 'page_restrictions' => $updated,
1639 'page_latest' => $nullRevId
1640 ), array( /* WHERE */
1642 ), 'Article::protect'
1644 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1646 # Update the protection log
1647 $log = new LogPage( 'protect' );
1649 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$updated]" ) );
1651 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1655 } # End "changed" check
1661 * Take an array of page restrictions and flatten it to a string
1662 * suitable for insertion into the page_restrictions field.
1663 * @param array $limit
1667 function flattenRestrictions( $limit ) {
1668 if( !is_array( $limit ) ) {
1669 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1673 foreach( $limit as $action => $restrictions ) {
1674 if( $restrictions != '' ) {
1675 $bits[] = "$action=$restrictions";
1678 return implode( ':', $bits );
1682 * UI entry point for page deletion
1685 global $wgUser, $wgOut, $wgRequest;
1686 $fname = 'Article::delete';
1687 $confirm = $wgRequest->wasPosted() &&
1688 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1689 $reason = $wgRequest->getText( 'wpReason' );
1691 # This code desperately needs to be totally rewritten
1694 if( $wgUser->isAllowed( 'delete' ) ) {
1695 if( $wgUser->isBlocked() ) {
1696 $wgOut->blockedPage();
1700 $wgOut->permissionRequired( 'delete' );
1704 if( wfReadOnly() ) {
1705 $wgOut->readOnlyPage();
1709 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1711 # Better double-check that it hasn't been deleted yet!
1712 $dbw =& wfGetDB( DB_MASTER
);
1713 $conds = $this->mTitle
->pageCond();
1714 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1715 if ( $latest === false ) {
1716 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1721 $this->doDelete( $reason );
1725 # determine whether this page has earlier revisions
1726 # and insert a warning if it does
1728 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1730 if( count( $authors ) > 1 && !$confirm ) {
1731 $skin=$wgUser->getSkin();
1732 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
1735 # If a single user is responsible for all revisions, find out who they are
1736 if ( count( $authors ) == $maxRevisions ) {
1737 // Query bailed out, too many revisions to find out if they're all the same
1738 $authorOfAll = false;
1740 $authorOfAll = reset( $authors );
1741 foreach ( $authors as $author ) {
1742 if ( $authorOfAll != $author ) {
1743 $authorOfAll = false;
1748 # Fetch article text
1749 $rev = Revision
::newFromTitle( $this->mTitle
);
1751 if( !is_null( $rev ) ) {
1752 # if this is a mini-text, we can paste part of it into the deletion reason
1753 $text = $rev->getText();
1755 #if this is empty, an earlier revision may contain "useful" text
1758 $prev = $rev->getPrevious();
1760 $text = $prev->getText();
1765 $length = strlen( $text );
1767 # this should not happen, since it is not possible to store an empty, new
1768 # page. Let's insert a standard text in case it does, though
1769 if( $length == 0 && $reason === '' ) {
1770 $reason = wfMsgForContent( 'exblank' );
1773 if( $length < 500 && $reason === '' ) {
1774 # comment field=255, let's grep the first 150 to have some user
1777 $text = $wgContLang->truncate( $text, 150, '...' );
1779 # let's strip out newlines
1780 $text = preg_replace( "/[\n\r]/", '', $text );
1783 if( $authorOfAll === false ) {
1784 $reason = wfMsgForContent( 'excontent', $text );
1786 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1789 $reason = wfMsgForContent( 'exbeforeblank', $text );
1794 return $this->confirmDelete( '', $reason );
1798 * Get the last N authors
1799 * @param int $num Number of revisions to get
1800 * @param string $revLatest The latest rev_id, selected from the master (optional)
1801 * @return array Array of authors, duplicates not removed
1803 function getLastNAuthors( $num, $revLatest = 0 ) {
1804 $fname = 'Article::getLastNAuthors';
1805 wfProfileIn( $fname );
1807 // First try the slave
1808 // If that doesn't have the latest revision, try the master
1810 $db =& wfGetDB( DB_SLAVE
);
1812 $res = $db->select( array( 'page', 'revision' ),
1813 array( 'rev_id', 'rev_user_text' ),
1815 'page_namespace' => $this->mTitle
->getNamespace(),
1816 'page_title' => $this->mTitle
->getDBkey(),
1817 'rev_page = page_id'
1818 ), $fname, $this->getSelectOptions( array(
1819 'ORDER BY' => 'rev_timestamp DESC',
1824 wfProfileOut( $fname );
1827 $row = $db->fetchObject( $res );
1828 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1829 $db =& wfGetDB( DB_MASTER
);
1834 } while ( $continue );
1836 $authors = array( $row->rev_user_text
);
1837 while ( $row = $db->fetchObject( $res ) ) {
1838 $authors[] = $row->rev_user_text
;
1840 wfProfileOut( $fname );
1845 * Output deletion confirmation dialog
1847 function confirmDelete( $par, $reason ) {
1848 global $wgOut, $wgUser;
1850 wfDebug( "Article::confirmDelete\n" );
1852 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1853 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1854 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1855 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1857 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1859 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1860 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1861 $token = htmlspecialchars( $wgUser->editToken() );
1864 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1868 <label for='wpReason'>{$delcom}:</label>
1871 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1877 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1881 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1884 $wgOut->returnToMain( false );
1889 * Perform a deletion and output success or failure messages
1891 function doDelete( $reason ) {
1892 global $wgOut, $wgUser;
1893 $fname = 'Article::doDelete';
1894 wfDebug( $fname."\n" );
1896 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1897 if ( $this->doDeleteArticle( $reason ) ) {
1898 $deleted = $this->mTitle
->getPrefixedText();
1900 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1901 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1903 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1904 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1906 $wgOut->addWikiText( $text );
1907 $wgOut->returnToMain( false );
1908 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1910 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1916 * Back-end article deletion
1917 * Deletes the article with database consistency, writes logs, purges caches
1920 function doDeleteArticle( $reason ) {
1921 global $wgUseSquid, $wgDeferredUpdateList;
1922 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1924 $fname = 'Article::doDeleteArticle';
1925 wfDebug( $fname."\n" );
1927 $dbw =& wfGetDB( DB_MASTER
);
1928 $ns = $this->mTitle
->getNamespace();
1929 $t = $this->mTitle
->getDBkey();
1930 $id = $this->mTitle
->getArticleID();
1932 if ( $t == '' ||
$id == 0 ) {
1936 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1937 array_push( $wgDeferredUpdateList, $u );
1939 $linksTo = $this->mTitle
->getLinksTo();
1942 if ( $wgUseSquid ) {
1944 $this->mTitle
->getInternalURL(),
1945 $this->mTitle
->getInternalURL( 'history' )
1948 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1949 array_push( $wgPostCommitUpdateList, $u );
1953 # Client and file cache invalidation
1954 Title
::touchArray( $linksTo );
1957 // For now, shunt the revision data into the archive table.
1958 // Text is *not* removed from the text table; bulk storage
1959 // is left intact to avoid breaking block-compression or
1960 // immutable storage schemes.
1962 // For backwards compatibility, note that some older archive
1963 // table entries will have ar_text and ar_flags fields still.
1965 // In the future, we may keep revisions and mark them with
1966 // the rev_deleted field, which is reserved for this purpose.
1967 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1969 'ar_namespace' => 'page_namespace',
1970 'ar_title' => 'page_title',
1971 'ar_comment' => 'rev_comment',
1972 'ar_user' => 'rev_user',
1973 'ar_user_text' => 'rev_user_text',
1974 'ar_timestamp' => 'rev_timestamp',
1975 'ar_minor_edit' => 'rev_minor_edit',
1976 'ar_rev_id' => 'rev_id',
1977 'ar_text_id' => 'rev_text_id',
1980 'page_id = rev_page'
1984 # Now that it's safely backed up, delete it
1985 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1986 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1988 if ($wgUseTrackbacks)
1989 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1991 # Clean up recentchanges entries...
1992 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1994 # Finally, clean up the link tables
1995 $t = $this->mTitle
->getPrefixedDBkey();
1997 Article
::onArticleDelete( $this->mTitle
);
1999 # Delete outgoing links
2000 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2001 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2002 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2003 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
2004 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
2005 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
2008 $log = new LogPage( 'delete' );
2009 $log->addEntry( 'delete', $this->mTitle
, $reason );
2011 # Clear the cached article id so the interface doesn't act like we exist
2012 $this->mTitle
->resetArticleID( 0 );
2013 $this->mTitle
->mArticleID
= 0;
2018 * Revert a modification
2020 function rollback() {
2021 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2022 $fname = 'Article::rollback';
2024 if( $wgUser->isAllowed( 'rollback' ) ) {
2025 if( $wgUser->isBlocked() ) {
2026 $wgOut->blockedPage();
2030 $wgOut->permissionRequired( 'rollback' );
2034 if ( wfReadOnly() ) {
2035 $wgOut->readOnlyPage( $this->getContent() );
2038 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2039 array( $this->mTitle
->getPrefixedText(),
2040 $wgRequest->getVal( 'from' ) ) ) ) {
2041 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2042 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2045 $dbw =& wfGetDB( DB_MASTER
);
2047 # Enhanced rollback, marks edits rc_bot=1
2048 $bot = $wgRequest->getBool( 'bot' );
2050 # Replace all this user's current edits with the next one down
2051 $tt = $this->mTitle
->getDBKey();
2052 $n = $this->mTitle
->getNamespace();
2054 # Get the last editor, lock table exclusively
2056 $current = Revision
::newFromTitle( $this->mTitle
);
2057 if( is_null( $current ) ) {
2058 # Something wrong... no page?
2060 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2064 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2065 if( $from != $current->getUserText() ) {
2066 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2067 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2068 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2069 htmlspecialchars( $from ),
2070 htmlspecialchars( $current->getUserText() ) ) );
2071 if( $current->getComment() != '') {
2073 wfMsg( 'editcomment',
2074 htmlspecialchars( $current->getComment() ) ) );
2079 # Get the last edit not by this guy
2080 $user = intval( $current->getUser() );
2081 $user_text = $dbw->addQuotes( $current->getUserText() );
2082 $s = $dbw->selectRow( 'revision',
2083 array( 'rev_id', 'rev_timestamp' ),
2085 'rev_page' => $current->getPage(),
2086 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2089 'USE INDEX' => 'page_timestamp',
2090 'ORDER BY' => 'rev_timestamp DESC' )
2092 if( $s === false ) {
2095 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2096 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2102 # Mark all reverted edits as bot
2105 if ( $wgUseRCPatrol ) {
2106 # Mark all reverted edits as patrolled
2107 $set['rc_patrolled'] = 1;
2111 $dbw->update( 'recentchanges', $set,
2113 'rc_cur_id' => $current->getPage(),
2114 'rc_user_text' => $current->getUserText(),
2115 "rc_timestamp > '{$s->rev_timestamp}'",
2120 # Get the edit summary
2121 $target = Revision
::newFromId( $s->rev_id
);
2122 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2123 $newComment = $wgRequest->getText( 'summary', $newComment );
2126 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2127 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2128 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2130 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2131 Article
::onArticleEdit( $this->mTitle
);
2134 $wgOut->returnToMain( false );
2139 * Do standard deferred updates after page view
2142 function viewUpdates() {
2143 global $wgDeferredUpdateList;
2145 if ( 0 != $this->getID() ) {
2146 global $wgDisableCounters;
2147 if( !$wgDisableCounters ) {
2148 Article
::incViewCount( $this->getID() );
2149 $u = new SiteStatsUpdate( 1, 0, 0 );
2150 array_push( $wgDeferredUpdateList, $u );
2154 # Update newtalk / watchlist notification status
2156 $wgUser->clearNotification( $this->mTitle
);
2160 * Do standard deferred updates after page edit.
2161 * Every 1000th edit, prune the recent changes table.
2163 * @param string $text
2165 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2166 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2168 $fname = 'Article::editUpdates';
2169 wfProfileIn( $fname );
2172 $options = new ParserOptions
;
2173 $options->setTidy(true);
2174 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2176 # Save it to the parser cache
2177 $parserCache =& ParserCache
::singleton();
2178 $parserCache->save( $poutput, $this, $wgUser );
2180 # Update the links tables
2181 $u = new LinksUpdate( $this->mTitle
, $poutput );
2184 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2186 if ( 0 == mt_rand( 0, 999 ) ) {
2187 # Periodically flush old entries from the recentchanges table.
2190 $dbw =& wfGetDB( DB_MASTER
);
2191 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2192 $recentchanges = $dbw->tableName( 'recentchanges' );
2193 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2194 $dbw->query( $sql );
2198 $id = $this->getID();
2199 $title = $this->mTitle
->getPrefixedDBkey();
2200 $shortTitle = $this->mTitle
->getDBkey();
2203 wfProfileOut( $fname );
2207 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2208 array_push( $wgDeferredUpdateList, $u );
2209 $u = new SearchUpdate( $id, $title, $text );
2210 array_push( $wgDeferredUpdateList, $u );
2212 # If this is another user's talk page, update newtalk
2214 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2215 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2216 $other = User
::newFromName( $shortTitle );
2217 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2218 // An anonymous user
2219 $other = new User();
2220 $other->setName( $shortTitle );
2223 $other->setNewtalk( true );
2228 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2229 $wgMessageCache->replace( $shortTitle, $text );
2232 wfProfileOut( $fname );
2236 * Generate the navigation links when browsing through an article revisions
2237 * It shows the information as:
2238 * Revision as of \<date\>; view current revision
2239 * \<- Previous version | Next Version -\>
2242 * @param string $oldid Revision ID of this article revision
2244 function setOldSubtitle( $oldid=0 ) {
2245 global $wgLang, $wgOut, $wgUser;
2247 $current = ( $oldid == $this->mLatest
);
2248 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2249 $sk = $wgUser->getSkin();
2251 ?
wfMsg( 'currentrevisionlink' )
2252 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2253 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2255 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2256 : wfMsg( 'previousrevision' );
2257 $nextlink = $current
2258 ?
wfMsg( 'nextrevision' )
2259 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2260 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2261 $wgOut->setSubtitle( $r );
2265 * This function is called right before saving the wikitext,
2266 * so we can do things like signatures and links-in-context.
2268 * @param string $text
2270 function preSaveTransform( $text ) {
2271 global $wgParser, $wgUser;
2272 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2275 /* Caching functions */
2278 * checkLastModified returns true if it has taken care of all
2279 * output to the client that is necessary for this request.
2280 * (that is, it has sent a cached version of the page)
2282 function tryFileCache() {
2283 static $called = false;
2285 wfDebug( " tryFileCache() -- called twice!?\n" );
2289 if($this->isFileCacheable()) {
2290 $touched = $this->mTouched
;
2291 $cache = new CacheManager( $this->mTitle
);
2292 if($cache->isFileCacheGood( $touched )) {
2293 wfDebug( " tryFileCache() - about to load\n" );
2294 $cache->loadFromFileCache();
2297 wfDebug( " tryFileCache() - starting buffer\n" );
2298 ob_start( array(&$cache, 'saveToFileCache' ) );
2301 wfDebug( " tryFileCache() - not cacheable\n" );
2306 * Check if the page can be cached
2309 function isFileCacheable() {
2310 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2311 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2313 return $wgUseFileCache
2314 and (!$wgShowIPinHeader)
2315 and ($this->getID() != 0)
2316 and ($wgUser->isAnon())
2317 and (!$wgUser->getNewtalk())
2318 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2319 and (empty( $action ) ||
$action == 'view')
2320 and (!isset($oldid))
2322 and (!isset($redirect))
2323 and (!isset($printable))
2324 and (!$this->mRedirectedFrom
);
2328 * Loads page_touched and returns a value indicating if it should be used
2331 function checkTouched() {
2332 $fname = 'Article::checkTouched';
2333 if( !$this->mDataLoaded
) {
2334 $this->loadPageData();
2336 return !$this->mIsRedirect
;
2340 * Get the page_touched field
2342 function getTouched() {
2343 # Ensure that page data has been loaded
2344 if( !$this->mDataLoaded
) {
2345 $this->loadPageData();
2347 return $this->mTouched
;
2351 * Get the page_latest field
2353 function getLatest() {
2354 if ( !$this->mDataLoaded
) {
2355 $this->loadPageData();
2357 return $this->mLatest
;
2361 * Edit an article without doing all that other stuff
2362 * The article must already exist; link tables etc
2363 * are not updated, caches are not flushed.
2365 * @param string $text text submitted
2366 * @param string $comment comment submitted
2367 * @param bool $minor whereas it's a minor modification
2369 function quickEdit( $text, $comment = '', $minor = 0 ) {
2370 $fname = 'Article::quickEdit';
2371 wfProfileIn( $fname );
2373 $dbw =& wfGetDB( DB_MASTER
);
2375 $revision = new Revision( array(
2376 'page' => $this->getId(),
2378 'comment' => $comment,
2379 'minor_edit' => $minor ?
1 : 0,
2381 # fixme : $revisionId never used
2382 $revisionId = $revision->insertOn( $dbw );
2383 $this->updateRevisionOn( $dbw, $revision );
2386 wfProfileOut( $fname );
2390 * Used to increment the view counter
2393 * @param integer $id article id
2395 function incViewCount( $id ) {
2396 $id = intval( $id );
2397 global $wgHitcounterUpdateFreq, $wgDBtype;
2399 $dbw =& wfGetDB( DB_MASTER
);
2400 $pageTable = $dbw->tableName( 'page' );
2401 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2402 $acchitsTable = $dbw->tableName( 'acchits' );
2404 if( $wgHitcounterUpdateFreq <= 1 ){ //
2405 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2409 # Not important enough to warrant an error page in case of failure
2410 $oldignore = $dbw->ignoreErrors( true );
2412 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2414 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2415 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2416 # Most of the time (or on SQL errors), skip row count check
2417 $dbw->ignoreErrors( $oldignore );
2421 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2422 $row = $dbw->fetchObject( $res );
2423 $rown = intval( $row->n
);
2424 if( $rown >= $wgHitcounterUpdateFreq ){
2425 wfProfileIn( 'Article::incViewCount-collect' );
2426 $old_user_abort = ignore_user_abort( true );
2428 if ($wgDBtype == 'mysql')
2429 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2430 $tabletype = $wgDBtype == 'mysql' ?
"ENGINE=HEAP " : '';
2431 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
2432 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2434 $dbw->query("DELETE FROM $hitcounterTable");
2435 if ($wgDBtype == 'mysql')
2436 $dbw->query('UNLOCK TABLES');
2437 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2438 'WHERE page_id = hc_id');
2439 $dbw->query("DROP TABLE $acchitsTable");
2441 ignore_user_abort( $old_user_abort );
2442 wfProfileOut( 'Article::incViewCount-collect' );
2444 $dbw->ignoreErrors( $oldignore );
2448 * The onArticle*() functions are supposed to be a kind of hooks
2449 * which should be called whenever any of the specified actions
2452 * This is a good place to put code to clear caches, for instance.
2454 * This is called on page move and undelete, as well as edit
2456 * @param $title_obj a title object
2459 function onArticleCreate($title_obj) {
2460 global $wgUseSquid, $wgPostCommitUpdateList;
2462 $title_obj->touchLinks();
2463 $titles = $title_obj->getLinksTo();
2466 if ( $wgUseSquid ) {
2467 $urls = $title_obj->getSquidURLs();
2468 foreach ( $titles as $linkTitle ) {
2469 $urls[] = $linkTitle->getInternalURL();
2471 $u = new SquidUpdate( $urls );
2472 array_push( $wgPostCommitUpdateList, $u );
2476 function onArticleDelete( $title ) {
2477 global $wgMessageCache;
2479 $title->touchLinks();
2481 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2482 $wgMessageCache->replace( $title->getDBkey(), false );
2487 * Purge caches on page update etc
2489 function onArticleEdit( $title ) {
2490 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2494 // Template namespace? Purge all articles linking here.
2495 // FIXME: When a templatelinks table arrives, use it for all includes.
2496 if ( $title->getNamespace() == NS_TEMPLATE
) {
2497 $titles = $title->getLinksTo();
2498 Title
::touchArray( $titles );
2499 if ( $wgUseSquid ) {
2500 foreach ( $titles as $link ) {
2501 $urls[] = $link->getInternalURL();
2507 if ( $wgUseSquid ) {
2508 $urls = array_merge( $urls, $title->getSquidURLs() );
2509 $u = new SquidUpdate( $urls );
2510 array_push( $wgPostCommitUpdateList, $u );
2514 if ( $wgUseFileCache ) {
2515 $cm = new CacheManager( $title );
2516 @unlink
( $cm->fileCacheName() );
2523 * Info about this page
2524 * Called for ?action=info when $wgAllowPageInfo is on.
2529 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2530 $fname = 'Article::info';
2532 if ( !$wgAllowPageInfo ) {
2533 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2537 $page = $this->mTitle
->getSubjectPage();
2539 $wgOut->setPagetitle( $page->getPrefixedText() );
2540 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2542 # first, see if the page exists at all.
2543 $exists = $page->getArticleId() != 0;
2545 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2546 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2548 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2551 $dbr =& wfGetDB( DB_SLAVE
);
2553 'wl_title' => $page->getDBkey(),
2554 'wl_namespace' => $page->getNamespace() );
2555 $numwatchers = $dbr->selectField(
2560 $this->getSelectOptions() );
2562 $pageInfo = $this->pageCountInfo( $page );
2563 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2565 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2566 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2568 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2570 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2572 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2574 $wgOut->addHTML( '</ul>' );
2580 * Return the total number of edits and number of unique editors
2581 * on a given page. If page does not exist, returns false.
2583 * @param Title $title
2587 function pageCountInfo( $title ) {
2588 $id = $title->getArticleId();
2593 $dbr =& wfGetDB( DB_SLAVE
);
2595 $rev_clause = array( 'rev_page' => $id );
2596 $fname = 'Article::pageCountInfo';
2598 $edits = $dbr->selectField(
2603 $this->getSelectOptions() );
2605 $authors = $dbr->selectField(
2607 'COUNT(DISTINCT rev_user_text)',
2610 $this->getSelectOptions() );
2612 return array( 'edits' => $edits, 'authors' => $authors );
2616 * Return a list of templates used by this article.
2617 * Uses the templatelinks table
2619 * @return array Array of Title objects
2621 function getUsedTemplates() {
2623 $id = $this->mTitle
->getArticleID();
2628 $dbr =& wfGetDB( DB_SLAVE
);
2629 $res = $dbr->select( array( 'templatelinks' ),
2630 array( 'tl_namespace', 'tl_title' ),
2631 array( 'tl_from' => $id ),
2632 'Article:getUsedTemplates' );
2633 if ( false !== $res ) {
2634 if ( $dbr->numRows( $res ) ) {
2635 while ( $row = $dbr->fetchObject( $res ) ) {
2636 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2640 $dbr->freeResult( $res );