6bffff297cb5812d04f3157a89d98906ea89ae3d
8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
17 * Class representing a MediaWiki article and history.
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
31 var $mContentLoaded; //!<
35 var $mGoodAdjustment; //!<
40 var $mRedirectedFrom; //!<
41 var $mRedirectUrl; //!<
42 var $mRevIdFetched; //!<
47 var $mTotalAdjustment; //!<
54 * Constructor and clear the article
55 * @param $title Reference to a Title object.
56 * @param $oldId Integer revision ID, null to fetch from request, zero for current
58 function Article( &$title, $oldId = null ) {
59 $this->mTitle
=& $title;
60 $this->mOldId
= $oldId;
65 * Tell the page view functions that this view was redirected
66 * from another page on the wiki.
67 * @param $from Title object.
69 function setRedirectedFrom( $from ) {
70 $this->mRedirectedFrom
= $from;
74 * @return mixed false, Title of in-wiki target, or string with URL
76 function followRedirect() {
77 $text = $this->getContent();
78 $rt = Title
::newFromRedirect( $text );
80 # process if title object is valid and not special:userlogout
82 if( $rt->getInterwiki() != '' ) {
83 if( $rt->isLocal() ) {
84 // Offsite wikis need an HTTP redirect.
86 // This can be hard to reverse and may produce loops,
87 // so they may be disabled in the site configuration.
89 $source = $this->mTitle
->getFullURL( 'redirect=no' );
90 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
93 if( $rt->getNamespace() == NS_SPECIAL
) {
94 // Gotta hand redirects to special pages differently:
95 // Fill the HTTP response "Location" header and ignore
96 // the rest of the page we're on.
98 // This can be hard to reverse, so they may be disabled.
100 if( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) {
103 return $rt->getFullURL();
110 // No or invalid redirect
115 * get the title object of the article
117 function getTitle() {
118 return $this->mTitle
;
126 $this->mDataLoaded
= false;
127 $this->mContentLoaded
= false;
129 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
130 $this->mRedirectedFrom
= null; # Title object if set
132 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
133 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
134 $this->mTouched
= '19700101000000';
135 $this->mForUpdate
= false;
136 $this->mIsRedirect
= false;
137 $this->mRevIdFetched
= 0;
138 $this->mRedirectUrl
= false;
139 $this->mLatest
= false;
143 * Note that getContent/loadContent do not follow redirects anymore.
144 * If you need to fetch redirectable content easily, try
145 * the shortcut in Article::followContent()
147 * @todo There are still side-effects in this!
148 * In general, you should use the Revision class, not Article,
149 * to fetch text for purposes other than page views.
151 * @return Return the text of this revision
153 function getContent() {
154 global $wgRequest, $wgUser, $wgOut;
156 # Get variables from query string :P
157 $action = $wgRequest->getText( 'action', 'view' );
158 $section = $wgRequest->getText( 'section' );
159 $preload = $wgRequest->getText( 'preload' );
161 $fname = 'Article::getContent';
162 wfProfileIn( $fname );
164 if ( 0 == $this->getID() ) {
165 if ( 'edit' == $action ) {
166 wfProfileOut( $fname );
168 # If requested, preload some text.
169 $text=$this->getPreloadedText($preload);
171 # We used to put MediaWiki:Newarticletext here if
172 # $text was empty at this point.
173 # This is now shown above the edit box instead.
176 wfProfileOut( $fname );
177 $wgOut->setRobotpolicy( 'noindex,nofollow' );
179 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
180 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
182 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
185 return "<div class='noarticletext'>$ret</div>";
187 $this->loadContent();
188 if($action=='edit') {
190 if($section=='new') {
191 wfProfileOut( $fname );
192 $text=$this->getPreloadedText($preload);
196 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
197 # comments to be stripped as well)
198 $rv=$this->getSection($this->mContent
,$section);
199 wfProfileOut( $fname );
203 wfProfileOut( $fname );
204 return $this->mContent
;
209 * Get the contents of a page from its title and remove includeonly tags
211 * @param $preload String: the title of the page.
212 * @return string The contents of the page.
214 function getPreloadedText($preload) {
215 if ( $preload === '' )
218 $preloadTitle = Title
::newFromText( $preload );
219 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
220 $rev=Revision
::newFromTitle($preloadTitle);
221 if ( is_object( $rev ) ) {
222 $text = $rev->getText();
223 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
224 // its own mini-parser! -ævar
225 $text = preg_replace( '~</?includeonly>~', '', $text );
234 * This function returns the text of a section, specified by a number ($section).
235 * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
236 * the first section before any such heading (section 0).
238 * If a section contains subsections, these are also returned.
240 * @param $text String: text to look in
241 * @param $section Integer: section number
242 * @return string text of the requested section
244 function getSection($text,$section) {
246 return $wgParser->getSection( $text, $section );
250 * @return int The oldid of the article that is to be shown, 0 for the
253 function getOldID() {
254 if ( is_null( $this->mOldId
) ) {
255 $this->mOldId
= $this->getOldIDFromRequest();
257 return $this->mOldId
;
261 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
263 * @return int The old id for the request
265 function getOldIDFromRequest() {
267 $this->mRedirectUrl
= false;
268 $oldid = $wgRequest->getVal( 'oldid' );
269 if ( isset( $oldid ) ) {
270 $oldid = intval( $oldid );
271 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
272 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
276 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
278 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
279 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
296 * Load the revision (including text) into this object
298 function loadContent() {
299 if ( $this->mContentLoaded
) return;
302 $oldid = $this->getOldID();
304 # Pre-fill content with error message so that if something
305 # fails we'll have something telling us what we intended.
307 $t = $this->mTitle
->getPrefixedText();
309 $this->mOldId
= $oldid;
310 $this->fetchContent( $oldid );
315 * Fetch a page record with the given conditions
316 * @param Database $dbr
317 * @param array $conditions
320 function pageData( &$dbr, $conditions ) {
333 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
334 $row = $dbr->selectRow( 'page',
337 'Article::pageData' );
338 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
343 * @param Database $dbr
344 * @param Title $title
346 function pageDataFromTitle( &$dbr, $title ) {
347 return $this->pageData( $dbr, array(
348 'page_namespace' => $title->getNamespace(),
349 'page_title' => $title->getDBkey() ) );
353 * @param Database $dbr
356 function pageDataFromId( &$dbr, $id ) {
357 return $this->pageData( $dbr, array( 'page_id' => $id ) );
361 * Set the general counter, title etc data loaded from
364 * @param object $data
367 function loadPageData( $data = 'fromdb' ) {
368 if ( $data === 'fromdb' ) {
369 $dbr =& $this->getDB();
370 $data = $this->pageDataFromId( $dbr, $this->getId() );
373 $lc =& LinkCache
::singleton();
375 $lc->addGoodLinkObj( $data->page_id
, $this->mTitle
);
377 $this->mTitle
->mArticleID
= $data->page_id
;
378 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
379 $this->mTitle
->mRestrictionsLoaded
= true;
381 $this->mCounter
= $data->page_counter
;
382 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
383 $this->mIsRedirect
= $data->page_is_redirect
;
384 $this->mLatest
= $data->page_latest
;
386 if ( is_object( $this->mTitle
) ) {
387 $lc->addBadLinkObj( $this->mTitle
);
389 $this->mTitle
->mArticleID
= 0;
392 $this->mDataLoaded
= true;
396 * Get text of an article from database
397 * Does *NOT* follow redirects.
398 * @param int $oldid 0 for whatever the latest revision is
401 function fetchContent( $oldid = 0 ) {
402 if ( $this->mContentLoaded
) {
403 return $this->mContent
;
406 $dbr =& $this->getDB();
407 $fname = 'Article::fetchContent';
409 # Pre-fill content with error message so that if something
410 # fails we'll have something telling us what we intended.
411 $t = $this->mTitle
->getPrefixedText();
413 $t .= ',oldid='.$oldid;
415 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
418 $revision = Revision
::newFromId( $oldid );
419 if( is_null( $revision ) ) {
420 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
423 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
425 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
428 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
429 $this->loadPageData( $data );
431 if( !$this->mDataLoaded
) {
432 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
434 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
437 $this->loadPageData( $data );
439 $revision = Revision
::newFromId( $this->mLatest
);
440 if( is_null( $revision ) ) {
441 wfDebug( "$fname failed to retrieve current page, rev_id {$data->page_latest}\n" );
446 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
447 // We should instead work with the Revision object when we need it...
448 $this->mContent
= $revision->userCan( Revision
::MW_REV_DELETED_TEXT
) ?
$revision->getRawText() : "";
449 //$this->mContent = $revision->getText();
451 $this->mUser
= $revision->getUser();
452 $this->mUserText
= $revision->getUserText();
453 $this->mComment
= $revision->getComment();
454 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
456 $this->mRevIdFetched
= $revision->getID();
457 $this->mContentLoaded
= true;
458 $this->mRevision
=& $revision;
460 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
462 return $this->mContent
;
466 * Read/write accessor to select FOR UPDATE
468 * @param $x Mixed: FIXME
470 function forUpdate( $x = NULL ) {
471 return wfSetVar( $this->mForUpdate
, $x );
475 * Get the database which should be used for reads
480 $ret =& wfGetDB( DB_MASTER
);
485 * Get options for all SELECT statements
487 * @param $options Array: an optional options array which'll be appended to
489 * @return Array: options
491 function getSelectOptions( $options = '' ) {
492 if ( $this->mForUpdate
) {
493 if ( is_array( $options ) ) {
494 $options[] = 'FOR UPDATE';
496 $options = 'FOR UPDATE';
503 * @return int Page ID
506 if( $this->mTitle
) {
507 return $this->mTitle
->getArticleID();
514 * @return bool Whether or not the page exists in the database
517 return $this->getId() != 0;
521 * @return int The view count for the page
523 function getCount() {
524 if ( -1 == $this->mCounter
) {
525 $id = $this->getID();
529 $dbr =& wfGetDB( DB_SLAVE
);
530 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
531 'Article::getCount', $this->getSelectOptions() );
534 return $this->mCounter
;
538 * Determine whether a page would be suitable for being counted as an
539 * article in the site_stats table based on the title & its content
541 * @param $text String: text to analyze
544 function isCountable( $text ) {
545 global $wgUseCommaCount;
547 $token = $wgUseCommaCount ?
',' : '[[';
549 $this->mTitle
->getNamespace() == NS_MAIN
550 && ! $this->isRedirect( $text )
551 && in_string( $token, $text );
555 * Tests if the article text represents a redirect
557 * @param $text String: FIXME
560 function isRedirect( $text = false ) {
561 if ( $text === false ) {
562 $this->loadContent();
563 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
565 $titleObj = Title
::newFromRedirect( $text );
567 return $titleObj !== NULL;
571 * Returns true if the currently-referenced revision is the current edit
572 * to this page (and it exists).
575 function isCurrent() {
576 return $this->exists() &&
577 isset( $this->mRevision
) &&
578 $this->mRevision
->isCurrent();
582 * Loads everything except the text
583 * This isn't necessary for all uses, so it's only done if needed.
586 function loadLastEdit() {
587 if ( -1 != $this->mUser
)
590 # New or non-existent articles have no user information
591 $id = $this->getID();
592 if ( 0 == $id ) return;
594 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
595 if( !is_null( $this->mLastRevision
) ) {
596 $this->mUser
= $this->mLastRevision
->getUser();
597 $this->mUserText
= $this->mLastRevision
->getUserText();
598 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
599 $this->mComment
= $this->mLastRevision
->getComment();
600 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
601 $this->mRevIdFetched
= $this->mLastRevision
->getID();
605 function getTimestamp() {
606 // Check if the field has been filled by ParserCache::get()
607 if ( !$this->mTimestamp
) {
608 $this->loadLastEdit();
610 return wfTimestamp(TS_MW
, $this->mTimestamp
);
614 $this->loadLastEdit();
618 function getUserText() {
619 $this->loadLastEdit();
620 return $this->mUserText
;
623 function getComment() {
624 $this->loadLastEdit();
625 return $this->mComment
;
628 function getMinorEdit() {
629 $this->loadLastEdit();
630 return $this->mMinorEdit
;
633 function getRevIdFetched() {
634 $this->loadLastEdit();
635 return $this->mRevIdFetched
;
639 * @todo Document, fixme $offset never used.
640 * @param $limit Integer: default 0.
641 * @param $offset Integer: default 0.
643 function getContributors($limit = 0, $offset = 0) {
644 $fname = 'Article::getContributors';
646 # XXX: this is expensive; cache this info somewhere.
648 $title = $this->mTitle
;
650 $dbr =& wfGetDB( DB_SLAVE
);
651 $revTable = $dbr->tableName( 'revision' );
652 $userTable = $dbr->tableName( 'user' );
653 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
654 $ns = $title->getNamespace();
655 $user = $this->getUser();
656 $pageId = $this->getId();
658 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
659 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
660 WHERE rev_page = $pageId
661 AND rev_user != $user
662 GROUP BY rev_user, rev_user_text, user_real_name
663 ORDER BY timestamp DESC";
665 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
666 $sql .= ' '. $this->getSelectOptions();
668 $res = $dbr->query($sql, $fname);
670 while ( $line = $dbr->fetchObject( $res ) ) {
671 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
674 $dbr->freeResult($res);
679 * This is the default action of the script: just view the page of
683 global $wgUser, $wgOut, $wgRequest, $wgContLang;
684 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
685 global $wgUseTrackbacks, $wgNamespaceRobotPolicies;
686 $sk = $wgUser->getSkin();
688 $fname = 'Article::view';
689 wfProfileIn( $fname );
691 $parserCache =& ParserCache
::singleton();
692 $ns = $this->mTitle
->getNamespace(); # shortcut
694 # Get variables from query string
695 $oldid = $this->getOldID();
697 # getOldID may want us to redirect somewhere else
698 if ( $this->mRedirectUrl
) {
699 $wgOut->redirect( $this->mRedirectUrl
);
700 wfProfileOut( $fname );
704 $diff = $wgRequest->getVal( 'diff' );
705 $rcid = $wgRequest->getVal( 'rcid' );
706 $rdfrom = $wgRequest->getVal( 'rdfrom' );
708 $wgOut->setArticleFlag( true );
709 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
710 $policy = $wgNamespaceRobotPolicies[$ns];
712 $policy = 'index,follow';
714 $wgOut->setRobotpolicy( $policy );
716 # If we got diff and oldid in the query, we want to see a
717 # diff page instead of the article.
719 if ( !is_null( $diff ) ) {
720 require_once( 'DifferenceEngine.php' );
721 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
723 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
724 // DifferenceEngine directly fetched the revision:
725 $this->mRevIdFetched
= $de->mNewid
;
729 # Run view updates for current revision only
730 $this->viewUpdates();
732 wfProfileOut( $fname );
736 if ( empty( $oldid ) && $this->checkTouched() ) {
737 $wgOut->setETag($parserCache->getETag($this, $wgUser));
739 if( $wgOut->checkLastModified( $this->mTouched
) ){
740 wfProfileOut( $fname );
742 } else if ( $this->tryFileCache() ) {
743 # tell wgOut that output is taken care of
745 $this->viewUpdates();
746 wfProfileOut( $fname );
750 # Should the parser cache be used?
751 $pcache = $wgEnableParserCache &&
752 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
755 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
756 if ( $wgUser->getOption( 'stubthreshold' ) ) {
757 wfIncrStats( 'pcache_miss_stub' );
760 $wasRedirected = false;
761 if ( isset( $this->mRedirectedFrom
) ) {
762 // This is an internally redirected page view.
763 // We'll need a backlink to the source page for navigation.
764 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
765 $sk = $wgUser->getSkin();
766 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
767 $s = wfMsg( 'redirectedfrom', $redir );
768 $wgOut->setSubtitle( $s );
769 $wasRedirected = true;
771 } elseif ( !empty( $rdfrom ) ) {
772 // This is an externally redirected view, from some other wiki.
773 // If it was reported from a trusted site, supply a backlink.
774 global $wgRedirectSources;
775 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
776 $sk = $wgUser->getSkin();
777 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
778 $s = wfMsg( 'redirectedfrom', $redir );
779 $wgOut->setSubtitle( $s );
780 $wasRedirected = true;
786 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
790 if ( !$outputDone ) {
791 $text = $this->getContent();
792 if ( $text === false ) {
793 # Failed to load, replace text with error message
794 $t = $this->mTitle
->getPrefixedText();
796 $t .= ',oldid='.$oldid;
797 $text = wfMsg( 'missingarticle', $t );
799 $text = wfMsg( 'noarticletext', $t );
803 # Another whitelist check in case oldid is altering the title
804 if ( !$this->mTitle
->userCanRead() ) {
805 $wgOut->loginToUse();
810 # We're looking at an old revision
812 if ( !empty( $oldid ) ) {
813 $wgOut->setRobotpolicy( 'noindex,nofollow' );
814 if( is_null( $this->mRevision
) ) {
815 // FIXME: This would be a nice place to load the 'no such page' text.
817 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
818 if( $this->mRevision
->isDeleted( Revision
::MW_REV_DELETED_TEXT
) ) {
819 if( !$this->mRevision
->userCan( Revision
::MW_REV_DELETED_TEXT
) ) {
820 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
821 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
824 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
825 // and we are allowed to see...
834 * @fixme: this hook doesn't work most of the time, as it doesn't
835 * trigger when the parser cache is used.
837 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
838 $wgOut->setRevisionId( $this->getRevIdFetched() );
839 # wrap user css and user js in pre and don't parse
840 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
843 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
845 $wgOut->addWikiText( wfMsg('clearyourcache'));
846 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
847 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
849 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
850 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
851 # Don't overwrite the subtitle if this was an old revision
852 if( !$wasRedirected && $this->isCurrent() ) {
853 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
855 $targetUrl = $rt->escapeLocalURL();
856 #Â fixme unused $titleText :
857 $titleText = htmlspecialchars( $rt->getPrefixedText() );
858 $link = $sk->makeLinkObj( $rt );
860 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
861 '<span class="redirectText">'.$link.'</span>' );
863 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
864 $wgOut->addParserOutputNoText( $parseout );
865 } else if ( $pcache ) {
866 # Display content and save to parser cache
867 $wgOut->addPrimaryWikiText( $text, $this );
869 # Display content, don't attempt to save to parser cache
871 # Don't show section-edit links on old revisions... this way lies madness.
872 if( !$this->isCurrent() ) {
873 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
875 # Display content and don't save to parser cache
876 $wgOut->addPrimaryWikiText( $text, $this, false );
878 if( !$this->isCurrent() ) {
879 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
883 /* title may have been set from the cache */
884 $t = $wgOut->getPageTitle();
886 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
889 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
890 if( $ns == NS_USER_TALK
&&
891 User
::isIP( $this->mTitle
->getText() ) ) {
892 $wgOut->addWikiText( wfMsg('anontalkpagetext') );
895 # If we have been passed an &rcid= parameter, we want to give the user a
896 # chance to mark this new article as patrolled.
897 if ( $wgUseRCPatrol && !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
899 "<div class='patrollink'>" .
900 wfMsg ( 'markaspatrolledlink',
901 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
908 if ($wgUseTrackbacks)
909 $this->addTrackbacks();
911 $this->viewUpdates();
912 wfProfileOut( $fname );
915 function addTrackbacks() {
916 global $wgOut, $wgUser;
918 $dbr =& wfGetDB(DB_SLAVE
);
920 /* FROM */ 'trackbacks',
921 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
922 /* WHERE */ array('tb_page' => $this->getID())
925 if (!$dbr->numrows($tbs))
929 while ($o = $dbr->fetchObject($tbs)) {
931 if ($wgUser->isAllowed( 'trackback' )) {
932 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
933 . $o->tb_id
. "&token=" . $wgUser->editToken());
934 $rmvtxt = wfMsg('trackbackremove', $delurl);
936 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
943 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
946 function deletetrackback() {
947 global $wgUser, $wgRequest, $wgOut, $wgTitle;
949 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
950 $wgOut->addWikitext(wfMsg('sessionfailure'));
954 if ((!$wgUser->isAllowed('delete'))) {
955 $wgOut->sysopRequired();
960 $wgOut->readOnlyPage();
964 $db =& wfGetDB(DB_MASTER
);
965 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
966 $wgTitle->invalidateCache();
967 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
973 $wgOut->setArticleBodyOnly(true);
978 * Handle action=purge
981 global $wgUser, $wgRequest, $wgOut;
983 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
984 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
988 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
989 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
990 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
991 $msg = str_replace( '$1',
992 "<form method=\"post\" action=\"$action\">\n" .
993 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
996 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
997 $wgOut->setRobotpolicy( 'noindex,nofollow' );
998 $wgOut->addHTML( $msg );
1003 * Perform the actions of a page purging
1005 function doPurge() {
1007 // Invalidate the cache
1008 $this->mTitle
->invalidateCache();
1010 if ( $wgUseSquid ) {
1011 // Commit the transaction before the purge is sent
1012 $dbw = wfGetDB( DB_MASTER
);
1013 $dbw->immediateCommit();
1016 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
1017 $update->doUpdate();
1023 * Insert a new empty page record for this article.
1024 * This *must* be followed up by creating a revision
1025 * and running $this->updateToLatest( $rev_id );
1026 * or else the record will be left in a funky state.
1027 * Best if all done inside a transaction.
1029 * @param Database $dbw
1030 * @param string $restrictions
1031 * @return int The newly created page_id key
1034 function insertOn( &$dbw, $restrictions = '' ) {
1035 $fname = 'Article::insertOn';
1036 wfProfileIn( $fname );
1038 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1039 $dbw->insert( 'page', array(
1040 'page_id' => $page_id,
1041 'page_namespace' => $this->mTitle
->getNamespace(),
1042 'page_title' => $this->mTitle
->getDBkey(),
1043 'page_counter' => 0,
1044 'page_restrictions' => $restrictions,
1045 'page_is_redirect' => 0, # Will set this shortly...
1047 'page_random' => wfRandom(),
1048 'page_touched' => $dbw->timestamp(),
1049 'page_latest' => 0, # Fill this in shortly...
1050 'page_len' => 0, # Fill this in shortly...
1052 $newid = $dbw->insertId();
1054 $this->mTitle
->resetArticleId( $newid );
1056 wfProfileOut( $fname );
1061 * Update the page record to point to a newly saved revision.
1063 * @param Database $dbw
1064 * @param Revision $revision For ID number, and text used to set
1065 length and redirect status fields
1066 * @param int $lastRevision If given, will not overwrite the page field
1067 * when different from the currently set value.
1068 * Giving 0 indicates the new page flag should
1070 * @return bool true on success, false on failure
1073 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1074 $fname = 'Article::updateToRevision';
1075 wfProfileIn( $fname );
1077 $conditions = array( 'page_id' => $this->getId() );
1078 if( !is_null( $lastRevision ) ) {
1079 # An extra check against threads stepping on each other
1080 $conditions['page_latest'] = $lastRevision;
1083 $text = $revision->getText();
1084 $dbw->update( 'page',
1086 'page_latest' => $revision->getId(),
1087 'page_touched' => $dbw->timestamp(),
1088 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1089 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1090 'page_len' => strlen( $text ),
1095 wfProfileOut( $fname );
1096 return ( $dbw->affectedRows() != 0 );
1100 * If the given revision is newer than the currently set page_latest,
1101 * update the page record. Otherwise, do nothing.
1103 * @param Database $dbw
1104 * @param Revision $revision
1106 function updateIfNewerOn( &$dbw, $revision ) {
1107 $fname = 'Article::updateIfNewerOn';
1108 wfProfileIn( $fname );
1110 $row = $dbw->selectRow(
1111 array( 'revision', 'page' ),
1112 array( 'rev_id', 'rev_timestamp' ),
1114 'page_id' => $this->getId(),
1115 'page_latest=rev_id' ),
1118 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1119 wfProfileOut( $fname );
1122 $prev = $row->rev_id
;
1124 # No or missing previous revision; mark the page as new
1128 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1129 wfProfileOut( $fname );
1134 * Insert a new article into the database
1137 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1140 $fname = 'Article::insertNewArticle';
1141 wfProfileIn( $fname );
1143 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1144 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1145 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1146 wfProfileOut( $fname );
1150 $ns = $this->mTitle
->getNamespace();
1151 $ttl = $this->mTitle
->getDBkey();
1153 # If this is a comment, add the summary as headline
1154 if($comment && $summary!="") {
1155 $text="== {$summary} ==\n\n".$text;
1157 $text = $this->preSaveTransform( $text );
1160 # Set statistics members
1161 # We work out if it's countable after PST to avoid counter drift
1162 # when articles are created with {{subst:}}
1163 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1164 $this->mTotalAdjustment
= 1;
1166 /* Silently ignore minoredit if not allowed */
1167 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1168 $now = wfTimestampNow();
1170 $dbw =& wfGetDB( DB_MASTER
);
1172 # Add the page record; stake our claim on this title!
1173 $newid = $this->insertOn( $dbw );
1175 # Save the revision text...
1176 $revision = new Revision( array(
1178 'comment' => $summary,
1179 'minor_edit' => $isminor,
1182 $revisionId = $revision->insertOn( $dbw );
1184 $this->mTitle
->resetArticleID( $newid );
1186 # Update the page record with revision data
1187 $this->updateRevisionOn( $dbw, $revision, 0 );
1189 Article
::onArticleCreate( $this->mTitle
);
1191 require_once( 'RecentChange.php' );
1192 $rcid = RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1193 '', strlen( $text ), $revisionId );
1194 # Mark as patrolled if the user can and has the option set
1195 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1196 RecentChange
::markPatrolled( $rcid );
1201 if(!$this->mTitle
->userIsWatching()) $this->doWatch();
1203 if ( $this->mTitle
->userIsWatching() ) {
1208 # The talk page isn't in the regular link tables, so we need to update manually:
1209 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1210 $dbw->update( 'page',
1211 array( 'page_touched' => $dbw->timestamp($now) ),
1212 array( 'page_namespace' => $talkns,
1213 'page_title' => $ttl ),
1216 # standard deferred updates
1217 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1219 $oldid = 0; # new article
1220 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1222 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1224 $watchthis, NULL ) );
1225 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1227 $watchthis, NULL ) );
1228 wfProfileOut( $fname );
1232 * @return string Complete article text, or null if error
1234 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1235 $fname = 'Article::replaceSection';
1236 wfProfileIn( $fname );
1238 if( $section == '' ) {
1239 // Whole-page edit; let the text through unmolested.
1241 if( is_null( $edittime ) ) {
1242 $rev = Revision
::newFromTitle( $this->mTitle
);
1244 $dbw =& wfGetDB( DB_MASTER
);
1245 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1247 if( is_null( $rev ) ) {
1248 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1249 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1252 $oldtext = $rev->getText();
1254 if($section=='new') {
1255 if($summary) $subject="== {$summary} ==\n\n";
1256 $text=$oldtext."\n\n".$subject.$text;
1259 $text = $wgParser->replaceSection( $oldtext, $section, $text );
1263 wfProfileOut( $fname );
1268 * Change an existing article. Puts the previous version back into the old table, updates RC
1269 * and all necessary caches, mostly via the deferred update array.
1271 * It is possible to call this function from a command-line script, but note that you should
1272 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1274 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1275 global $wgUser, $wgDBtransactions, $wgUseSquid;
1276 global $wgPostCommitUpdateList, $wgUseFileCache;
1278 $fname = 'Article::updateArticle';
1279 wfProfileIn( $fname );
1282 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1284 &$watchthis, &$sectionanchor ) ) ) {
1285 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1286 wfProfileOut( $fname );
1290 $isminor = $minor && $wgUser->isAllowed('minoredit');
1292 $text = $this->preSaveTransform( $text );
1293 $dbw =& wfGetDB( DB_MASTER
);
1294 $now = wfTimestampNow();
1296 # Update article, but only if changed.
1298 # It's important that we either rollback or complete, otherwise an attacker could
1299 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1300 # could conceivably have the same effect, especially if cur is locked for long periods.
1301 if( !$wgDBtransactions ) {
1302 $userAbort = ignore_user_abort( true );
1305 $oldtext = $this->getContent();
1306 $oldsize = strlen( $oldtext );
1307 $newsize = strlen( $text );
1311 if ( 0 != strcmp( $text, $oldtext ) ) {
1312 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1313 - (int)$this->isCountable( $oldtext );
1314 $this->mTotalAdjustment
= 0;
1315 $now = wfTimestampNow();
1317 $lastRevision = $dbw->selectField(
1318 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1320 $revision = new Revision( array(
1321 'page' => $this->getId(),
1322 'comment' => $summary,
1323 'minor_edit' => $isminor,
1327 $dbw->immediateCommit();
1329 $revisionId = $revision->insertOn( $dbw );
1332 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1335 /* Belated edit conflict! Run away!! */
1339 # Update recentchanges and purge cache and whatnot
1340 require_once( 'RecentChange.php' );
1341 $bot = (int)($wgUser->isBot() ||
$forceBot);
1342 $rcid = RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1343 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1346 # Mark as patrolled if the user can do so and has it set in their options
1347 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1348 RecentChange
::markPatrolled( $rcid );
1353 // Update caches outside the main transaction
1354 Article
::onArticleEdit( $this->mTitle
);
1357 // Keep the same revision ID, but do some updates on it
1358 $revisionId = $this->getRevIdFetched();
1361 if( !$wgDBtransactions ) {
1362 ignore_user_abort( $userAbort );
1367 if (!$this->mTitle
->userIsWatching()) {
1368 $dbw->immediateCommit();
1374 if ( $this->mTitle
->userIsWatching() ) {
1375 $dbw->immediateCommit();
1381 # standard deferred updates
1382 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1386 # Invalidate caches of all articles using this article as a template
1388 # Template namespace
1389 # Purge all articles linking here
1390 $titles = $this->mTitle
->getTemplateLinksTo();
1391 Title
::touchArray( $titles );
1392 if ( $wgUseSquid ) {
1393 foreach ( $titles as $title ) {
1394 $urls[] = $title->getInternalURL();
1399 if ( $wgUseSquid ) {
1400 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1401 $u = new SquidUpdate( $urls );
1402 array_push( $wgPostCommitUpdateList, $u );
1406 if ( $wgUseFileCache ) {
1407 $cm = new CacheManager($this->mTitle
);
1408 @unlink
($cm->fileCacheName());
1411 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1413 wfRunHooks( 'ArticleSaveComplete',
1414 array( &$this, &$wgUser, $text,
1416 $watchthis, $sectionanchor ) );
1417 wfProfileOut( $fname );
1422 * After we've either updated or inserted the article, update
1423 * the link tables and redirect to the new page.
1424 * @todo FIXME some function arguments never used
1426 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1429 $fname = 'Article::showArticle';
1430 wfProfileIn( $fname );
1432 # Output the redirect
1433 if( $this->isRedirect( $text ) )
1437 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1439 wfProfileOut( $fname );
1443 * Mark this particular edit as patrolled
1445 function markpatrolled() {
1446 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
1447 $wgOut->setRobotpolicy( 'noindex,follow' );
1449 # Check RC patrol config. option
1450 if( !$wgUseRCPatrol ) {
1451 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1456 if( !$wgUser->isAllowed( 'patrol' ) ) {
1457 $wgOut->permissionRequired( 'patrol' );
1461 $rcid = $wgRequest->getVal( 'rcid' );
1462 if ( !is_null ( $rcid ) ) {
1463 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
1464 require_once( 'RecentChange.php' );
1465 RecentChange
::markPatrolled( $rcid );
1466 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1467 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1468 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1470 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1471 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1474 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1479 * User-interface handler for the "watch" action
1484 global $wgUser, $wgOut;
1486 if ( $wgUser->isAnon() ) {
1487 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1490 if ( wfReadOnly() ) {
1491 $wgOut->readOnlyPage();
1495 if( $this->doWatch() ) {
1496 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1497 $wgOut->setRobotpolicy( 'noindex,follow' );
1499 $link = $this->mTitle
->getPrefixedText();
1500 $text = wfMsg( 'addedwatchtext', $link );
1501 $wgOut->addWikiText( $text );
1504 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1508 * Add this page to $wgUser's watchlist
1509 * @return bool true on successful watch operation
1511 function doWatch() {
1513 if( $wgUser->isAnon() ) {
1517 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1518 $wgUser->addWatch( $this->mTitle
);
1519 $wgUser->saveSettings();
1521 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1528 * User interface handler for the "unwatch" action.
1530 function unwatch() {
1532 global $wgUser, $wgOut;
1534 if ( $wgUser->isAnon() ) {
1535 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1538 if ( wfReadOnly() ) {
1539 $wgOut->readOnlyPage();
1543 if( $this->doUnwatch() ) {
1544 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1545 $wgOut->setRobotpolicy( 'noindex,follow' );
1547 $link = $this->mTitle
->getPrefixedText();
1548 $text = wfMsg( 'removedwatchtext', $link );
1549 $wgOut->addWikiText( $text );
1552 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1556 * Stop watching a page
1557 * @return bool true on successful unwatch
1559 function doUnwatch() {
1561 if( $wgUser->isAnon() ) {
1565 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1566 $wgUser->removeWatch( $this->mTitle
);
1567 $wgUser->saveSettings();
1569 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1576 * action=protect handler
1578 function protect() {
1579 require_once 'ProtectionForm.php';
1580 $form = new ProtectionForm( $this );
1585 * action=unprotect handler (alias)
1587 function unprotect() {
1592 * Update the article's restriction field, and leave a log entry.
1594 * @param array $limit set of restriction keys
1595 * @param string $reason
1596 * @return bool true on success
1598 function updateRestrictions( $limit = array(), $reason = '' ) {
1599 global $wgUser, $wgRestrictionTypes, $wgContLang;
1601 $id = $this->mTitle
->getArticleID();
1602 if( !$wgUser->isAllowed( 'protect' ) ||
wfReadOnly() ||
$id == 0 ) {
1606 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1607 # we expect a single selection, but the schema allows otherwise.
1609 foreach( $wgRestrictionTypes as $action )
1610 $current[$action] = implode( '', $this->mTitle
->getRestrictions( $action ) );
1612 $current = Article
::flattenRestrictions( $current );
1613 $updated = Article
::flattenRestrictions( $limit );
1615 $changed = ( $current != $updated );
1616 $protect = ( $updated != '' );
1618 # If nothing's changed, do nothing
1620 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1622 $dbw =& wfGetDB( DB_MASTER
);
1624 # Prepare a null revision to be added to the history
1625 $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ?
'protectedarticle' : 'unprotectedarticle', $this->mTitle
->getPrefixedText() ) );
1627 $comment .= ": $reason";
1629 $comment .= " [$updated]";
1630 $nullRevision = Revision
::newNullRevision( $dbw, $id, $comment, true );
1631 $nullRevId = $nullRevision->insertOn( $dbw );
1633 # Update page record
1634 $dbw->update( 'page',
1636 'page_touched' => $dbw->timestamp(),
1637 'page_restrictions' => $updated,
1638 'page_latest' => $nullRevId
1639 ), array( /* WHERE */
1641 ), 'Article::protect'
1643 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1645 # Update the protection log
1646 $log = new LogPage( 'protect' );
1648 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$updated]" ) );
1650 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1654 } # End "changed" check
1660 * Take an array of page restrictions and flatten it to a string
1661 * suitable for insertion into the page_restrictions field.
1662 * @param array $limit
1666 function flattenRestrictions( $limit ) {
1667 if( !is_array( $limit ) ) {
1668 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1672 foreach( $limit as $action => $restrictions ) {
1673 if( $restrictions != '' ) {
1674 $bits[] = "$action=$restrictions";
1677 return implode( ':', $bits );
1681 * UI entry point for page deletion
1684 global $wgUser, $wgOut, $wgRequest;
1685 $fname = 'Article::delete';
1686 $confirm = $wgRequest->wasPosted() &&
1687 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1688 $reason = $wgRequest->getText( 'wpReason' );
1690 # This code desperately needs to be totally rewritten
1693 if( $wgUser->isAllowed( 'delete' ) ) {
1694 if( $wgUser->isBlocked() ) {
1695 $wgOut->blockedPage();
1699 $wgOut->permissionRequired( 'delete' );
1703 if( wfReadOnly() ) {
1704 $wgOut->readOnlyPage();
1708 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1710 # Better double-check that it hasn't been deleted yet!
1711 $dbw =& wfGetDB( DB_MASTER
);
1712 $conds = $this->mTitle
->pageCond();
1713 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1714 if ( $latest === false ) {
1715 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1720 $this->doDelete( $reason );
1724 # determine whether this page has earlier revisions
1725 # and insert a warning if it does
1727 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1729 if( count( $authors ) > 1 && !$confirm ) {
1730 $skin=$wgUser->getSkin();
1731 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
1734 # If a single user is responsible for all revisions, find out who they are
1735 if ( count( $authors ) == $maxRevisions ) {
1736 // Query bailed out, too many revisions to find out if they're all the same
1737 $authorOfAll = false;
1739 $authorOfAll = reset( $authors );
1740 foreach ( $authors as $author ) {
1741 if ( $authorOfAll != $author ) {
1742 $authorOfAll = false;
1747 # Fetch article text
1748 $rev = Revision
::newFromTitle( $this->mTitle
);
1750 if( !is_null( $rev ) ) {
1751 # if this is a mini-text, we can paste part of it into the deletion reason
1752 $text = $rev->getText();
1754 #if this is empty, an earlier revision may contain "useful" text
1757 $prev = $rev->getPrevious();
1759 $text = $prev->getText();
1764 $length = strlen( $text );
1766 # this should not happen, since it is not possible to store an empty, new
1767 # page. Let's insert a standard text in case it does, though
1768 if( $length == 0 && $reason === '' ) {
1769 $reason = wfMsgForContent( 'exblank' );
1772 if( $length < 500 && $reason === '' ) {
1773 # comment field=255, let's grep the first 150 to have some user
1776 $text = $wgContLang->truncate( $text, 150, '...' );
1778 # let's strip out newlines
1779 $text = preg_replace( "/[\n\r]/", '', $text );
1782 if( $authorOfAll === false ) {
1783 $reason = wfMsgForContent( 'excontent', $text );
1785 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1788 $reason = wfMsgForContent( 'exbeforeblank', $text );
1793 return $this->confirmDelete( '', $reason );
1797 * Get the last N authors
1798 * @param int $num Number of revisions to get
1799 * @param string $revLatest The latest rev_id, selected from the master (optional)
1800 * @return array Array of authors, duplicates not removed
1802 function getLastNAuthors( $num, $revLatest = 0 ) {
1803 $fname = 'Article::getLastNAuthors';
1804 wfProfileIn( $fname );
1806 // First try the slave
1807 // If that doesn't have the latest revision, try the master
1809 $db =& wfGetDB( DB_SLAVE
);
1811 $res = $db->select( array( 'page', 'revision' ),
1812 array( 'rev_id', 'rev_user_text' ),
1814 'page_namespace' => $this->mTitle
->getNamespace(),
1815 'page_title' => $this->mTitle
->getDBkey(),
1816 'rev_page = page_id'
1817 ), $fname, $this->getSelectOptions( array(
1818 'ORDER BY' => 'rev_timestamp DESC',
1823 wfProfileOut( $fname );
1826 $row = $db->fetchObject( $res );
1827 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1828 $db =& wfGetDB( DB_MASTER
);
1833 } while ( $continue );
1835 $authors = array( $row->rev_user_text
);
1836 while ( $row = $db->fetchObject( $res ) ) {
1837 $authors[] = $row->rev_user_text
;
1839 wfProfileOut( $fname );
1844 * Output deletion confirmation dialog
1846 function confirmDelete( $par, $reason ) {
1847 global $wgOut, $wgUser;
1849 wfDebug( "Article::confirmDelete\n" );
1851 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1852 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1853 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1854 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1856 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1858 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1859 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1860 $token = htmlspecialchars( $wgUser->editToken() );
1863 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1867 <label for='wpReason'>{$delcom}:</label>
1870 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1876 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1880 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1883 $wgOut->returnToMain( false );
1888 * Perform a deletion and output success or failure messages
1890 function doDelete( $reason ) {
1891 global $wgOut, $wgUser;
1892 $fname = 'Article::doDelete';
1893 wfDebug( $fname."\n" );
1895 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1896 if ( $this->doDeleteArticle( $reason ) ) {
1897 $deleted = $this->mTitle
->getPrefixedText();
1899 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1900 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1902 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1903 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1905 $wgOut->addWikiText( $text );
1906 $wgOut->returnToMain( false );
1907 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1909 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1915 * Back-end article deletion
1916 * Deletes the article with database consistency, writes logs, purges caches
1919 function doDeleteArticle( $reason ) {
1920 global $wgUseSquid, $wgDeferredUpdateList;
1921 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1923 $fname = 'Article::doDeleteArticle';
1924 wfDebug( $fname."\n" );
1926 $dbw =& wfGetDB( DB_MASTER
);
1927 $ns = $this->mTitle
->getNamespace();
1928 $t = $this->mTitle
->getDBkey();
1929 $id = $this->mTitle
->getArticleID();
1931 if ( $t == '' ||
$id == 0 ) {
1935 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1936 array_push( $wgDeferredUpdateList, $u );
1938 $linksTo = $this->mTitle
->getLinksTo();
1941 if ( $wgUseSquid ) {
1943 $this->mTitle
->getInternalURL(),
1944 $this->mTitle
->getInternalURL( 'history' )
1947 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1948 array_push( $wgPostCommitUpdateList, $u );
1952 # Client and file cache invalidation
1953 Title
::touchArray( $linksTo );
1956 // For now, shunt the revision data into the archive table.
1957 // Text is *not* removed from the text table; bulk storage
1958 // is left intact to avoid breaking block-compression or
1959 // immutable storage schemes.
1961 // For backwards compatibility, note that some older archive
1962 // table entries will have ar_text and ar_flags fields still.
1964 // In the future, we may keep revisions and mark them with
1965 // the rev_deleted field, which is reserved for this purpose.
1966 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1968 'ar_namespace' => 'page_namespace',
1969 'ar_title' => 'page_title',
1970 'ar_comment' => 'rev_comment',
1971 'ar_user' => 'rev_user',
1972 'ar_user_text' => 'rev_user_text',
1973 'ar_timestamp' => 'rev_timestamp',
1974 'ar_minor_edit' => 'rev_minor_edit',
1975 'ar_rev_id' => 'rev_id',
1976 'ar_text_id' => 'rev_text_id',
1979 'page_id = rev_page'
1983 # Now that it's safely backed up, delete it
1984 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1985 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1987 if ($wgUseTrackbacks)
1988 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1990 # Clean up recentchanges entries...
1991 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1993 # Finally, clean up the link tables
1994 $t = $this->mTitle
->getPrefixedDBkey();
1996 Article
::onArticleDelete( $this->mTitle
);
1998 # Delete outgoing links
1999 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2000 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2001 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2002 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
2003 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
2004 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
2007 $log = new LogPage( 'delete' );
2008 $log->addEntry( 'delete', $this->mTitle
, $reason );
2010 # Clear the cached article id so the interface doesn't act like we exist
2011 $this->mTitle
->resetArticleID( 0 );
2012 $this->mTitle
->mArticleID
= 0;
2017 * Revert a modification
2019 function rollback() {
2020 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2021 $fname = 'Article::rollback';
2023 if( $wgUser->isAllowed( 'rollback' ) ) {
2024 if( $wgUser->isBlocked() ) {
2025 $wgOut->blockedPage();
2029 $wgOut->permissionRequired( 'rollback' );
2033 if ( wfReadOnly() ) {
2034 $wgOut->readOnlyPage( $this->getContent() );
2037 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2038 array( $this->mTitle
->getPrefixedText(),
2039 $wgRequest->getVal( 'from' ) ) ) ) {
2040 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2041 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2044 $dbw =& wfGetDB( DB_MASTER
);
2046 # Enhanced rollback, marks edits rc_bot=1
2047 $bot = $wgRequest->getBool( 'bot' );
2049 # Replace all this user's current edits with the next one down
2050 $tt = $this->mTitle
->getDBKey();
2051 $n = $this->mTitle
->getNamespace();
2053 # Get the last editor, lock table exclusively
2055 $current = Revision
::newFromTitle( $this->mTitle
);
2056 if( is_null( $current ) ) {
2057 # Something wrong... no page?
2059 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2063 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2064 if( $from != $current->getUserText() ) {
2065 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2066 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2067 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2068 htmlspecialchars( $from ),
2069 htmlspecialchars( $current->getUserText() ) ) );
2070 if( $current->getComment() != '') {
2072 wfMsg( 'editcomment',
2073 htmlspecialchars( $current->getComment() ) ) );
2078 # Get the last edit not by this guy
2079 $user = intval( $current->getUser() );
2080 $user_text = $dbw->addQuotes( $current->getUserText() );
2081 $s = $dbw->selectRow( 'revision',
2082 array( 'rev_id', 'rev_timestamp' ),
2084 'rev_page' => $current->getPage(),
2085 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2088 'USE INDEX' => 'page_timestamp',
2089 'ORDER BY' => 'rev_timestamp DESC' )
2091 if( $s === false ) {
2094 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2095 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2101 # Mark all reverted edits as bot
2104 if ( $wgUseRCPatrol ) {
2105 # Mark all reverted edits as patrolled
2106 $set['rc_patrolled'] = 1;
2110 $dbw->update( 'recentchanges', $set,
2112 'rc_cur_id' => $current->getPage(),
2113 'rc_user_text' => $current->getUserText(),
2114 "rc_timestamp > '{$s->rev_timestamp}'",
2119 # Get the edit summary
2120 $target = Revision
::newFromId( $s->rev_id
);
2121 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2122 $newComment = $wgRequest->getText( 'summary', $newComment );
2125 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2126 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2127 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2129 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2130 Article
::onArticleEdit( $this->mTitle
);
2133 $wgOut->returnToMain( false );
2138 * Do standard deferred updates after page view
2141 function viewUpdates() {
2142 global $wgDeferredUpdateList;
2144 if ( 0 != $this->getID() ) {
2145 global $wgDisableCounters;
2146 if( !$wgDisableCounters ) {
2147 Article
::incViewCount( $this->getID() );
2148 $u = new SiteStatsUpdate( 1, 0, 0 );
2149 array_push( $wgDeferredUpdateList, $u );
2153 # Update newtalk / watchlist notification status
2155 $wgUser->clearNotification( $this->mTitle
);
2159 * Do standard deferred updates after page edit.
2160 * Every 1000th edit, prune the recent changes table.
2162 * @param string $text
2164 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2165 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2167 $fname = 'Article::editUpdates';
2168 wfProfileIn( $fname );
2171 $options = new ParserOptions
;
2172 $options->setTidy(true);
2173 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2175 # Save it to the parser cache
2176 $parserCache =& ParserCache
::singleton();
2177 $parserCache->save( $poutput, $this, $wgUser );
2179 # Update the links tables
2180 $u = new LinksUpdate( $this->mTitle
, $poutput );
2183 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2185 if ( 0 == mt_rand( 0, 999 ) ) {
2186 # Periodically flush old entries from the recentchanges table.
2189 $dbw =& wfGetDB( DB_MASTER
);
2190 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2191 $recentchanges = $dbw->tableName( 'recentchanges' );
2192 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2193 $dbw->query( $sql );
2197 $id = $this->getID();
2198 $title = $this->mTitle
->getPrefixedDBkey();
2199 $shortTitle = $this->mTitle
->getDBkey();
2202 wfProfileOut( $fname );
2206 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2207 array_push( $wgDeferredUpdateList, $u );
2208 $u = new SearchUpdate( $id, $title, $text );
2209 array_push( $wgDeferredUpdateList, $u );
2211 # If this is another user's talk page, update newtalk
2213 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2214 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2215 $other = User
::newFromName( $shortTitle );
2216 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2217 // An anonymous user
2218 $other = new User();
2219 $other->setName( $shortTitle );
2222 $other->setNewtalk( true );
2227 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2228 $wgMessageCache->replace( $shortTitle, $text );
2231 wfProfileOut( $fname );
2235 * Generate the navigation links when browsing through an article revisions
2236 * It shows the information as:
2237 * Revision as of \<date\>; view current revision
2238 * \<- Previous version | Next Version -\>
2241 * @param string $oldid Revision ID of this article revision
2243 function setOldSubtitle( $oldid=0 ) {
2244 global $wgLang, $wgOut, $wgUser;
2246 $current = ( $oldid == $this->mLatest
);
2247 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2248 $sk = $wgUser->getSkin();
2250 ?
wfMsg( 'currentrevisionlink' )
2251 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2252 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2254 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2255 : wfMsg( 'previousrevision' );
2256 $nextlink = $current
2257 ?
wfMsg( 'nextrevision' )
2258 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2259 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2260 $wgOut->setSubtitle( $r );
2264 * This function is called right before saving the wikitext,
2265 * so we can do things like signatures and links-in-context.
2267 * @param string $text
2269 function preSaveTransform( $text ) {
2270 global $wgParser, $wgUser;
2271 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2274 /* Caching functions */
2277 * checkLastModified returns true if it has taken care of all
2278 * output to the client that is necessary for this request.
2279 * (that is, it has sent a cached version of the page)
2281 function tryFileCache() {
2282 static $called = false;
2284 wfDebug( " tryFileCache() -- called twice!?\n" );
2288 if($this->isFileCacheable()) {
2289 $touched = $this->mTouched
;
2290 $cache = new CacheManager( $this->mTitle
);
2291 if($cache->isFileCacheGood( $touched )) {
2292 wfDebug( " tryFileCache() - about to load\n" );
2293 $cache->loadFromFileCache();
2296 wfDebug( " tryFileCache() - starting buffer\n" );
2297 ob_start( array(&$cache, 'saveToFileCache' ) );
2300 wfDebug( " tryFileCache() - not cacheable\n" );
2305 * Check if the page can be cached
2308 function isFileCacheable() {
2309 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2310 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2312 return $wgUseFileCache
2313 and (!$wgShowIPinHeader)
2314 and ($this->getID() != 0)
2315 and ($wgUser->isAnon())
2316 and (!$wgUser->getNewtalk())
2317 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2318 and (empty( $action ) ||
$action == 'view')
2319 and (!isset($oldid))
2321 and (!isset($redirect))
2322 and (!isset($printable))
2323 and (!$this->mRedirectedFrom
);
2327 * Loads page_touched and returns a value indicating if it should be used
2330 function checkTouched() {
2331 $fname = 'Article::checkTouched';
2332 if( !$this->mDataLoaded
) {
2333 $this->loadPageData();
2335 return !$this->mIsRedirect
;
2339 * Get the page_touched field
2341 function getTouched() {
2342 # Ensure that page data has been loaded
2343 if( !$this->mDataLoaded
) {
2344 $this->loadPageData();
2346 return $this->mTouched
;
2350 * Get the page_latest field
2352 function getLatest() {
2353 if ( !$this->mDataLoaded
) {
2354 $this->loadPageData();
2356 return $this->mLatest
;
2360 * Edit an article without doing all that other stuff
2361 * The article must already exist; link tables etc
2362 * are not updated, caches are not flushed.
2364 * @param string $text text submitted
2365 * @param string $comment comment submitted
2366 * @param bool $minor whereas it's a minor modification
2368 function quickEdit( $text, $comment = '', $minor = 0 ) {
2369 $fname = 'Article::quickEdit';
2370 wfProfileIn( $fname );
2372 $dbw =& wfGetDB( DB_MASTER
);
2374 $revision = new Revision( array(
2375 'page' => $this->getId(),
2377 'comment' => $comment,
2378 'minor_edit' => $minor ?
1 : 0,
2380 # fixme : $revisionId never used
2381 $revisionId = $revision->insertOn( $dbw );
2382 $this->updateRevisionOn( $dbw, $revision );
2385 wfProfileOut( $fname );
2389 * Used to increment the view counter
2392 * @param integer $id article id
2394 function incViewCount( $id ) {
2395 $id = intval( $id );
2396 global $wgHitcounterUpdateFreq, $wgDBtype;
2398 $dbw =& wfGetDB( DB_MASTER
);
2399 $pageTable = $dbw->tableName( 'page' );
2400 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2401 $acchitsTable = $dbw->tableName( 'acchits' );
2403 if( $wgHitcounterUpdateFreq <= 1 ){ //
2404 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2408 # Not important enough to warrant an error page in case of failure
2409 $oldignore = $dbw->ignoreErrors( true );
2411 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2413 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2414 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2415 # Most of the time (or on SQL errors), skip row count check
2416 $dbw->ignoreErrors( $oldignore );
2420 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2421 $row = $dbw->fetchObject( $res );
2422 $rown = intval( $row->n
);
2423 if( $rown >= $wgHitcounterUpdateFreq ){
2424 wfProfileIn( 'Article::incViewCount-collect' );
2425 $old_user_abort = ignore_user_abort( true );
2427 if ($wgDBtype == 'mysql')
2428 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2429 $tabletype = $wgDBtype == 'mysql' ?
"ENGINE=HEAP " : '';
2430 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
2431 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2433 $dbw->query("DELETE FROM $hitcounterTable");
2434 if ($wgDBtype == 'mysql')
2435 $dbw->query('UNLOCK TABLES');
2436 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2437 'WHERE page_id = hc_id');
2438 $dbw->query("DROP TABLE $acchitsTable");
2440 ignore_user_abort( $old_user_abort );
2441 wfProfileOut( 'Article::incViewCount-collect' );
2443 $dbw->ignoreErrors( $oldignore );
2447 * The onArticle*() functions are supposed to be a kind of hooks
2448 * which should be called whenever any of the specified actions
2451 * This is a good place to put code to clear caches, for instance.
2453 * This is called on page move and undelete, as well as edit
2455 * @param $title_obj a title object
2458 function onArticleCreate($title_obj) {
2459 global $wgUseSquid, $wgPostCommitUpdateList;
2461 $title_obj->touchLinks();
2462 $titles = $title_obj->getLinksTo();
2465 if ( $wgUseSquid ) {
2466 $urls = $title_obj->getSquidURLs();
2467 foreach ( $titles as $linkTitle ) {
2468 $urls[] = $linkTitle->getInternalURL();
2470 $u = new SquidUpdate( $urls );
2471 array_push( $wgPostCommitUpdateList, $u );
2475 function onArticleDelete( $title ) {
2476 global $wgMessageCache;
2478 $title->touchLinks();
2480 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2481 $wgMessageCache->replace( $title->getDBkey(), false );
2486 * Purge caches on page update etc
2488 function onArticleEdit( $title ) {
2489 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2493 // Template namespace? Purge all articles linking here.
2494 // FIXME: When a templatelinks table arrives, use it for all includes.
2495 if ( $title->getNamespace() == NS_TEMPLATE
) {
2496 $titles = $title->getLinksTo();
2497 Title
::touchArray( $titles );
2498 if ( $wgUseSquid ) {
2499 foreach ( $titles as $link ) {
2500 $urls[] = $link->getInternalURL();
2506 if ( $wgUseSquid ) {
2507 $urls = array_merge( $urls, $title->getSquidURLs() );
2508 $u = new SquidUpdate( $urls );
2509 array_push( $wgPostCommitUpdateList, $u );
2513 if ( $wgUseFileCache ) {
2514 $cm = new CacheManager( $title );
2515 @unlink
( $cm->fileCacheName() );
2522 * Info about this page
2523 * Called for ?action=info when $wgAllowPageInfo is on.
2528 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2529 $fname = 'Article::info';
2531 if ( !$wgAllowPageInfo ) {
2532 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2536 $page = $this->mTitle
->getSubjectPage();
2538 $wgOut->setPagetitle( $page->getPrefixedText() );
2539 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2541 # first, see if the page exists at all.
2542 $exists = $page->getArticleId() != 0;
2544 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2545 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2547 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2550 $dbr =& wfGetDB( DB_SLAVE
);
2552 'wl_title' => $page->getDBkey(),
2553 'wl_namespace' => $page->getNamespace() );
2554 $numwatchers = $dbr->selectField(
2559 $this->getSelectOptions() );
2561 $pageInfo = $this->pageCountInfo( $page );
2562 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2564 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2565 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2567 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2569 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2571 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2573 $wgOut->addHTML( '</ul>' );
2579 * Return the total number of edits and number of unique editors
2580 * on a given page. If page does not exist, returns false.
2582 * @param Title $title
2586 function pageCountInfo( $title ) {
2587 $id = $title->getArticleId();
2592 $dbr =& wfGetDB( DB_SLAVE
);
2594 $rev_clause = array( 'rev_page' => $id );
2595 $fname = 'Article::pageCountInfo';
2597 $edits = $dbr->selectField(
2602 $this->getSelectOptions() );
2604 $authors = $dbr->selectField(
2606 'COUNT(DISTINCT rev_user_text)',
2609 $this->getSelectOptions() );
2611 return array( 'edits' => $edits, 'authors' => $authors );
2615 * Return a list of templates used by this article.
2616 * Uses the templatelinks table
2618 * @return array Array of Title objects
2620 function getUsedTemplates() {
2622 $id = $this->mTitle
->getArticleID();
2627 $dbr =& wfGetDB( DB_SLAVE
);
2628 $res = $dbr->select( array( 'templatelinks' ),
2629 array( 'tl_namespace', 'tl_title' ),
2630 array( 'tl_from' => $id ),
2631 'Article:getUsedTemplates' );
2632 if ( false !== $res ) {
2633 if ( $dbr->numRows( $res ) ) {
2634 while ( $row = $dbr->fetchObject( $res ) ) {
2635 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2639 $dbr->freeResult( $res );