8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
17 * Class representing a MediaWiki article and history.
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
29 var $mContent, $mContentLoaded;
30 var $mUser, $mTimestamp, $mUserText;
31 var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
32 var $mMinorEdit, $mRedirectedFrom;
33 var $mTouched, $mFileCache, $mTitle;
43 * Constructor and clear the article
44 * @param Title &$title
45 * @param integer $oldId Revision ID, null to fetch from request, zero for current
47 function Article( &$title, $oldId = null ) {
48 $this->mTitle
=& $title;
49 $this->mOldId
= $oldId;
54 * Tell the page view functions that this view was redirected
55 * from another page on the wiki.
58 function setRedirectedFrom( $from ) {
59 $this->mRedirectedFrom
= $from;
63 * @return mixed false, Title of in-wiki target, or string with URL
65 function followRedirect() {
66 $text = $this->getContent();
67 $rt = Title
::newFromRedirect( $text );
69 # process if title object is valid and not special:userlogout
71 if( $rt->getInterwiki() != '' ) {
72 if( $rt->isLocal() ) {
73 // Offsite wikis need an HTTP redirect.
75 // This can be hard to reverse and may produce loops,
76 // so they may be disabled in the site configuration.
78 $source = $this->mTitle
->getFullURL( 'redirect=no' );
79 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
82 if( $rt->getNamespace() == NS_SPECIAL
) {
83 // Gotta hand redirects to special pages differently:
84 // Fill the HTTP response "Location" header and ignore
85 // the rest of the page we're on.
87 // This can be hard to reverse, so they may be disabled.
89 if( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) {
92 return $rt->getFullURL();
99 // No or invalid redirect
104 * get the title object of the article
106 function getTitle() {
107 return $this->mTitle
;
115 $this->mDataLoaded
= false;
116 $this->mContentLoaded
= false;
118 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
119 $this->mRedirectedFrom
= null; # Title object if set
121 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
122 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
123 $this->mTouched
= '19700101000000';
124 $this->mForUpdate
= false;
125 $this->mIsRedirect
= false;
126 $this->mRevIdFetched
= 0;
127 $this->mRedirectUrl
= false;
131 * Note that getContent/loadContent do not follow redirects anymore.
132 * If you need to fetch redirectable content easily, try
133 * the shortcut in Article::followContent()
135 * @fixme There are still side-effects in this!
136 * In general, you should use the Revision class, not Article,
137 * to fetch text for purposes other than page views.
139 * @return Return the text of this revision
141 function getContent() {
142 global $wgRequest, $wgUser, $wgOut;
144 # Get variables from query string :P
145 $action = $wgRequest->getText( 'action', 'view' );
146 $section = $wgRequest->getText( 'section' );
147 $preload = $wgRequest->getText( 'preload' );
149 $fname = 'Article::getContent';
150 wfProfileIn( $fname );
152 if ( 0 == $this->getID() ) {
153 if ( 'edit' == $action ) {
154 wfProfileOut( $fname );
156 # If requested, preload some text.
157 $text=$this->getPreloadedText($preload);
159 # We used to put MediaWiki:Newarticletext here if
160 # $text was empty at this point.
161 # This is now shown above the edit box instead.
164 wfProfileOut( $fname );
165 $wgOut->setRobotpolicy( 'noindex,nofollow' );
167 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
168 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
170 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
173 return "<div class='noarticletext'>$ret</div>";
175 $this->loadContent();
176 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
177 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
178 $wgUser->isIP($this->mTitle
->getText()) &&
181 wfProfileOut( $fname );
182 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
184 if($action=='edit') {
186 if($section=='new') {
187 wfProfileOut( $fname );
188 $text=$this->getPreloadedText($preload);
192 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
193 # comments to be stripped as well)
194 $rv=$this->getSection($this->mContent
,$section);
195 wfProfileOut( $fname );
199 wfProfileOut( $fname );
200 return $this->mContent
;
206 * Get the contents of a page from its title and remove includeonly tags
208 * @param string The title of the page
209 * @return string The contents of the page
211 function getPreloadedText($preload) {
212 if ( $preload === '' )
215 $preloadTitle = Title
::newFromText( $preload );
216 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
217 $rev=Revision
::newFromTitle($preloadTitle);
218 if ( is_object( $rev ) ) {
219 $text = $rev->getText();
220 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
221 // its own mini-parser! -ævar
222 $text = preg_replace( '~</?includeonly>~', '', $text );
231 * This function returns the text of a section, specified by a number ($section).
232 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
233 * the first section before any such heading (section 0).
235 * If a section contains subsections, these are also returned.
237 * @param string $text text to look in
238 * @param integer $section section number
239 * @return string text of the requested section
241 function getSection($text,$section) {
243 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
244 # comments to be stripped as well)
246 $parser=new Parser();
247 $parser->mOutputType
=OT_WIKI
;
248 $parser->mOptions
= new ParserOptions();
249 $striptext=$parser->strip($text, $striparray, true);
251 # now that we can be sure that no pseudo-sections are in the source,
252 # split it up by section
255 '/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
257 PREG_SPLIT_DELIM_CAPTURE
);
261 $headline=$secs[$section*2-1];
262 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
265 # translate wiki heading into level
266 if(strpos($hlevel,'=')!==false) {
267 $hlevel=strlen($hlevel);
270 $rv=$headline. $secs[$section*2];
274 while(!empty($secs[$count*2-1]) && !$break) {
276 $subheadline=$secs[$count*2-1];
277 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
278 $subhlevel=$matches[1];
279 if(strpos($subhlevel,'=')!==false) {
280 $subhlevel=strlen($subhlevel);
282 if($subhlevel > $hlevel) {
283 $rv.=$subheadline.$secs[$count*2];
285 if($subhlevel <= $hlevel) {
292 # reinsert stripped tags
293 $rv=$parser->unstrip($rv,$striparray);
294 $rv=$parser->unstripNoWiki($rv,$striparray);
301 * @return int The oldid of the article that is to be shown, 0 for the
304 function getOldID() {
305 if ( is_null( $this->mOldId
) ) {
306 $this->mOldId
= $this->getOldIDFromRequest();
308 return $this->mOldId
;
312 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
314 * @return int The old id for the request
316 function getOldIDFromRequest() {
318 $this->mRedirectUrl
= false;
319 $oldid = $wgRequest->getVal( 'oldid' );
320 if ( isset( $oldid ) ) {
321 $oldid = intval( $oldid );
322 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
323 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
327 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
329 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
330 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
346 * Load the revision (including text) into this object
348 function loadContent() {
349 if ( $this->mContentLoaded
) return;
352 $oldid = $this->getOldID();
354 $fname = 'Article::loadContent';
356 # Pre-fill content with error message so that if something
357 # fails we'll have something telling us what we intended.
359 $t = $this->mTitle
->getPrefixedText();
361 $this->mOldId
= $oldid;
362 $this->fetchContent( $oldid );
367 * Fetch a page record with the given conditions
368 * @param Database $dbr
369 * @param array $conditions
372 function pageData( &$dbr, $conditions ) {
385 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
386 $row = $dbr->selectRow( 'page',
389 'Article::pageData' );
390 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
395 * @param Database $dbr
396 * @param Title $title
398 function pageDataFromTitle( &$dbr, $title ) {
399 return $this->pageData( $dbr, array(
400 'page_namespace' => $title->getNamespace(),
401 'page_title' => $title->getDBkey() ) );
405 * @param Database $dbr
408 function pageDataFromId( &$dbr, $id ) {
409 return $this->pageData( $dbr, array( 'page_id' => $id ) );
413 * Set the general counter, title etc data loaded from
416 * @param object $data
419 function loadPageData( $data ) {
420 $this->mTitle
->mArticleID
= $data->page_id
;
421 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
422 $this->mTitle
->mRestrictionsLoaded
= true;
424 $this->mCounter
= $data->page_counter
;
425 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
426 $this->mIsRedirect
= $data->page_is_redirect
;
427 $this->mLatest
= $data->page_latest
;
429 $this->mDataLoaded
= true;
433 * Get text of an article from database
434 * Does *NOT* follow redirects.
435 * @param int $oldid 0 for whatever the latest revision is
438 function fetchContent( $oldid = 0 ) {
439 if ( $this->mContentLoaded
) {
440 return $this->mContent
;
443 $dbr =& $this->getDB();
444 $fname = 'Article::fetchContent';
446 # Pre-fill content with error message so that if something
447 # fails we'll have something telling us what we intended.
448 $t = $this->mTitle
->getPrefixedText();
450 $t .= ',oldid='.$oldid;
452 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
455 $revision = Revision
::newFromId( $oldid );
456 if( is_null( $revision ) ) {
457 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
460 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
462 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
465 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
466 $this->loadPageData( $data );
468 if( !$this->mDataLoaded
) {
469 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
471 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
474 $this->loadPageData( $data );
476 $revision = Revision
::newFromId( $this->mLatest
);
477 if( is_null( $revision ) ) {
478 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
483 $this->mContent
= $revision->getText();
485 $this->mUser
= $revision->getUser();
486 $this->mUserText
= $revision->getUserText();
487 $this->mComment
= $revision->getComment();
488 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
490 $this->mRevIdFetched
= $revision->getID();
491 $this->mContentLoaded
= true;
492 $this->mRevision
=& $revision;
494 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
496 return $this->mContent
;
500 * Read/write accessor to select FOR UPDATE
504 function forUpdate( $x = NULL ) {
505 return wfSetVar( $this->mForUpdate
, $x );
509 * Get the database which should be used for reads
514 $ret =& wfGetDB( DB_MASTER
);
519 * Get options for all SELECT statements
521 * @param array $options an optional options array which'll be appended to
523 * @return array Options
525 function getSelectOptions( $options = '' ) {
526 if ( $this->mForUpdate
) {
527 if ( is_array( $options ) ) {
528 $options[] = 'FOR UPDATE';
530 $options = 'FOR UPDATE';
537 * @return int Page ID
540 if( $this->mTitle
) {
541 return $this->mTitle
->getArticleID();
548 * @return bool Whether or not the page exists in the database
551 return $this->getId() != 0;
555 * @return int The view count for the page
557 function getCount() {
558 if ( -1 == $this->mCounter
) {
559 $id = $this->getID();
560 $dbr =& wfGetDB( DB_SLAVE
);
561 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
562 'Article::getCount', $this->getSelectOptions() );
564 return $this->mCounter
;
568 * Determine whether a page would be suitable for being counted as an
569 * article in the site_stats table based on the title & its content
571 * @param string $text Text to analyze
574 function isCountable( $text ) {
575 global $wgUseCommaCount;
577 $token = $wgUseCommaCount ?
',' : '[[';
579 $this->mTitle
->getNamespace() == NS_MAIN
580 && ! $this->isRedirect( $text )
581 && in_string( $token, $text );
585 * Tests if the article text represents a redirect
587 * @param string $text
590 function isRedirect( $text = false ) {
591 if ( $text === false ) {
592 $this->loadContent();
593 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
595 $titleObj = Title
::newFromRedirect( $text );
597 return $titleObj !== NULL;
601 * Returns true if the currently-referenced revision is the current edit
602 * to this page (and it exists).
605 function isCurrent() {
606 return $this->exists() &&
607 isset( $this->mRevision
) &&
608 $this->mRevision
->isCurrent();
612 * Loads everything except the text
613 * This isn't necessary for all uses, so it's only done if needed.
616 function loadLastEdit() {
617 if ( -1 != $this->mUser
)
620 # New or non-existent articles have no user information
621 $id = $this->getID();
622 if ( 0 == $id ) return;
624 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
625 if( !is_null( $this->mLastRevision
) ) {
626 $this->mUser
= $this->mLastRevision
->getUser();
627 $this->mUserText
= $this->mLastRevision
->getUserText();
628 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
629 $this->mComment
= $this->mLastRevision
->getComment();
630 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
631 $this->mRevIdFetched
= $this->mLastRevision
->getID();
635 function getTimestamp() {
636 $this->loadLastEdit();
637 return wfTimestamp(TS_MW
, $this->mTimestamp
);
641 $this->loadLastEdit();
645 function getUserText() {
646 $this->loadLastEdit();
647 return $this->mUserText
;
650 function getComment() {
651 $this->loadLastEdit();
652 return $this->mComment
;
655 function getMinorEdit() {
656 $this->loadLastEdit();
657 return $this->mMinorEdit
;
660 function getRevIdFetched() {
661 $this->loadLastEdit();
662 return $this->mRevIdFetched
;
665 function getContributors($limit = 0, $offset = 0) {
666 $fname = 'Article::getContributors';
668 # XXX: this is expensive; cache this info somewhere.
670 $title = $this->mTitle
;
672 $dbr =& wfGetDB( DB_SLAVE
);
673 $revTable = $dbr->tableName( 'revision' );
674 $userTable = $dbr->tableName( 'user' );
675 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
676 $ns = $title->getNamespace();
677 $user = $this->getUser();
678 $pageId = $this->getId();
680 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
681 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
682 WHERE rev_page = $pageId
683 AND rev_user != $user
684 GROUP BY rev_user, rev_user_text, user_real_name
685 ORDER BY timestamp DESC";
687 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
688 $sql .= ' '. $this->getSelectOptions();
690 $res = $dbr->query($sql, $fname);
692 while ( $line = $dbr->fetchObject( $res ) ) {
693 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
696 $dbr->freeResult($res);
701 * This is the default action of the script: just view the page of
705 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
706 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
707 global $wgUseTrackbacks;
708 $sk = $wgUser->getSkin();
710 $fname = 'Article::view';
711 wfProfileIn( $fname );
712 $parserCache =& ParserCache
::singleton();
713 # Get variables from query string
714 $oldid = $this->getOldID();
716 # getOldID may want us to redirect somewhere else
717 if ( $this->mRedirectUrl
) {
718 $wgOut->redirect( $this->mRedirectUrl
);
719 wfProfileOut( $fname );
723 $diff = $wgRequest->getVal( 'diff' );
724 $rcid = $wgRequest->getVal( 'rcid' );
725 $rdfrom = $wgRequest->getVal( 'rdfrom' );
727 $wgOut->setArticleFlag( true );
728 $wgOut->setRobotpolicy( 'index,follow' );
729 # If we got diff and oldid in the query, we want to see a
730 # diff page instead of the article.
732 if ( !is_null( $diff ) ) {
733 require_once( 'DifferenceEngine.php' );
734 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
736 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
737 // DifferenceEngine directly fetched the revision:
738 $this->mRevIdFetched
= $de->mNewid
;
742 # Run view updates for current revision only
743 $this->viewUpdates();
745 wfProfileOut( $fname );
749 if ( empty( $oldid ) && $this->checkTouched() ) {
750 $wgOut->setETag($parserCache->getETag($this, $wgUser));
752 if( $wgOut->checkLastModified( $this->mTouched
) ){
753 wfProfileOut( $fname );
755 } else if ( $this->tryFileCache() ) {
756 # tell wgOut that output is taken care of
758 $this->viewUpdates();
759 wfProfileOut( $fname );
763 # Should the parser cache be used?
764 $pcache = $wgEnableParserCache &&
765 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
768 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
769 if ( $wgUser->getOption( 'stubthreshold' ) ) {
770 wfIncrStats( 'pcache_miss_stub' );
773 $wasRedirected = false;
774 if ( isset( $this->mRedirectedFrom
) ) {
775 // This is an internally redirected page view.
776 // We'll need a backlink to the source page for navigation.
777 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
778 $sk = $wgUser->getSkin();
779 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
780 $s = wfMsg( 'redirectedfrom', $redir );
781 $wgOut->setSubtitle( $s );
782 $wasRedirected = true;
784 } elseif ( !empty( $rdfrom ) ) {
785 // This is an externally redirected view, from some other wiki.
786 // If it was reported from a trusted site, supply a backlink.
787 global $wgRedirectSources;
788 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
789 $sk = $wgUser->getSkin();
790 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
791 $s = wfMsg( 'redirectedfrom', $redir );
792 $wgOut->setSubtitle( $s );
793 $wasRedirected = true;
799 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
803 if ( !$outputDone ) {
804 $text = $this->getContent();
805 if ( $text === false ) {
806 # Failed to load, replace text with error message
807 $t = $this->mTitle
->getPrefixedText();
809 $t .= ',oldid='.$oldid;
810 $text = wfMsg( 'missingarticle', $t );
812 $text = wfMsg( 'noarticletext', $t );
816 # Another whitelist check in case oldid is altering the title
817 if ( !$this->mTitle
->userCanRead() ) {
818 $wgOut->loginToUse();
823 # We're looking at an old revision
825 if ( !empty( $oldid ) ) {
826 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
827 $wgOut->setRobotpolicy( 'noindex,follow' );
832 * @fixme: this hook doesn't work most of the time, as it doesn't
833 * trigger when the parser cache is used.
835 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
836 $wgOut->setRevisionId( $this->getRevIdFetched() );
837 # wrap user css and user js in pre and don't parse
838 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
840 $this->mTitle
->getNamespace() == NS_USER
&&
841 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
843 $wgOut->addWikiText( wfMsg('clearyourcache'));
844 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
845 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
847 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
848 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
849 if( !$wasRedirected ) {
850 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
852 $targetUrl = $rt->escapeLocalURL();
853 $titleText = htmlspecialchars( $rt->getPrefixedText() );
854 $link = $sk->makeLinkObj( $rt );
856 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
857 '<span class="redirectText">'.$link.'</span>' );
859 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
860 $wgOut->addParserOutputNoText( $parseout );
861 } else if ( $pcache ) {
862 # Display content and save to parser cache
863 $wgOut->addPrimaryWikiText( $text, $this );
865 # Display content, don't attempt to save to parser cache
867 # Don't show section-edit links on old revisions... this way lies madness.
868 if( !$this->isCurrent() ) {
869 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
871 # Display content and don't save to parser cache
872 $wgOut->addPrimaryWikiText( $text, $this, false );
874 if( !$this->isCurrent() ) {
875 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
879 /* title may have been set from the cache */
880 $t = $wgOut->getPageTitle();
882 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
885 # If we have been passed an &rcid= parameter, we want to give the user a
886 # chance to mark this new article as patrolled.
890 && $wgUser->isLoggedIn()
891 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
894 "<div class='patrollink'>" .
895 wfMsg ( 'markaspatrolledlink',
896 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
903 if ($wgUseTrackbacks)
904 $this->addTrackbacks();
906 $this->viewUpdates();
907 wfProfileOut( $fname );
910 function addTrackbacks() {
911 global $wgOut, $wgUser;
913 $dbr =& wfGetDB(DB_SLAVE
);
915 /* FROM */ 'trackbacks',
916 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
917 /* WHERE */ array('tb_page' => $this->getID())
920 if (!$dbr->numrows($tbs))
924 while ($o = $dbr->fetchObject($tbs)) {
926 if ($wgUser->isSysop()) {
927 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
928 . $o->tb_id
. "&token=" . $wgUser->editToken());
929 $rmvtxt = wfMsg('trackbackremove', $delurl);
931 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
938 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
941 function deletetrackback() {
942 global $wgUser, $wgRequest, $wgOut, $wgTitle;
944 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
945 $wgOut->addWikitext(wfMsg('sessionfailure'));
949 if ((!$wgUser->isAllowed('delete'))) {
950 $wgOut->sysopRequired();
955 $wgOut->readOnlyPage();
959 $db =& wfGetDB(DB_MASTER
);
960 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
961 $wgTitle->invalidateCache();
962 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
968 $wgOut->setArticleBodyOnly(true);
973 * Handle action=purge
976 global $wgUser, $wgRequest, $wgOut;
978 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
979 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
983 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
984 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
985 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
986 $msg = str_replace( '$1',
987 "<form method=\"post\" action=\"$action\">\n" .
988 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
991 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
992 $wgOut->setRobotpolicy( 'noindex,nofollow' );
993 $wgOut->addHTML( $msg );
998 * Perform the actions of a page purging
1000 function doPurge() {
1002 // Invalidate the cache
1003 $this->mTitle
->invalidateCache();
1005 if ( $wgUseSquid ) {
1006 // Commit the transaction before the purge is sent
1007 $dbw = wfGetDB( DB_MASTER
);
1008 $dbw->immediateCommit();
1011 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
1012 $update->doUpdate();
1018 * Insert a new empty page record for this article.
1019 * This *must* be followed up by creating a revision
1020 * and running $this->updateToLatest( $rev_id );
1021 * or else the record will be left in a funky state.
1022 * Best if all done inside a transaction.
1024 * @param Database $dbw
1025 * @param string $restrictions
1026 * @return int The newly created page_id key
1029 function insertOn( &$dbw, $restrictions = '' ) {
1030 $fname = 'Article::insertOn';
1031 wfProfileIn( $fname );
1033 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1034 $dbw->insert( 'page', array(
1035 'page_id' => $page_id,
1036 'page_namespace' => $this->mTitle
->getNamespace(),
1037 'page_title' => $this->mTitle
->getDBkey(),
1038 'page_counter' => 0,
1039 'page_restrictions' => $restrictions,
1040 'page_is_redirect' => 0, # Will set this shortly...
1042 'page_random' => wfRandom(),
1043 'page_touched' => $dbw->timestamp(),
1044 'page_latest' => 0, # Fill this in shortly...
1045 'page_len' => 0, # Fill this in shortly...
1047 $newid = $dbw->insertId();
1049 $this->mTitle
->resetArticleId( $newid );
1051 wfProfileOut( $fname );
1056 * Update the page record to point to a newly saved revision.
1058 * @param Database $dbw
1059 * @param Revision $revision For ID number, and text used to set
1060 length and redirect status fields
1061 * @param int $lastRevision If given, will not overwrite the page field
1062 * when different from the currently set value.
1063 * Giving 0 indicates the new page flag should
1065 * @return bool true on success, false on failure
1068 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1069 $fname = 'Article::updateToRevision';
1070 wfProfileIn( $fname );
1072 $conditions = array( 'page_id' => $this->getId() );
1073 if( !is_null( $lastRevision ) ) {
1074 # An extra check against threads stepping on each other
1075 $conditions['page_latest'] = $lastRevision;
1078 $text = $revision->getText();
1079 $dbw->update( 'page',
1081 'page_latest' => $revision->getId(),
1082 'page_touched' => $dbw->timestamp(),
1083 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1084 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1085 'page_len' => strlen( $text ),
1090 wfProfileOut( $fname );
1091 return ( $dbw->affectedRows() != 0 );
1095 * If the given revision is newer than the currently set page_latest,
1096 * update the page record. Otherwise, do nothing.
1098 * @param Database $dbw
1099 * @param Revision $revision
1101 function updateIfNewerOn( &$dbw, $revision ) {
1102 $fname = 'Article::updateIfNewerOn';
1103 wfProfileIn( $fname );
1105 $row = $dbw->selectRow(
1106 array( 'revision', 'page' ),
1107 array( 'rev_id', 'rev_timestamp' ),
1109 'page_id' => $this->getId(),
1110 'page_latest=rev_id' ),
1113 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1114 wfProfileOut( $fname );
1117 $prev = $row->rev_id
;
1119 # No or missing previous revision; mark the page as new
1123 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1124 wfProfileOut( $fname );
1129 * Insert a new article into the database
1132 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1135 $fname = 'Article::insertNewArticle';
1136 wfProfileIn( $fname );
1138 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1139 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1140 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1141 wfProfileOut( $fname );
1145 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1146 $this->mTotalAdjustment
= 1;
1148 $ns = $this->mTitle
->getNamespace();
1149 $ttl = $this->mTitle
->getDBkey();
1151 # If this is a comment, add the summary as headline
1152 if($comment && $summary!="") {
1153 $text="== {$summary} ==\n\n".$text;
1155 $text = $this->preSaveTransform( $text );
1157 /* Silently ignore minoredit if not allowed */
1158 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1159 $now = wfTimestampNow();
1161 $dbw =& wfGetDB( DB_MASTER
);
1163 # Add the page record; stake our claim on this title!
1164 $newid = $this->insertOn( $dbw );
1166 # Save the revision text...
1167 $revision = new Revision( array(
1169 'comment' => $summary,
1170 'minor_edit' => $isminor,
1173 $revisionId = $revision->insertOn( $dbw );
1175 $this->mTitle
->resetArticleID( $newid );
1177 # Update the page record with revision data
1178 $this->updateRevisionOn( $dbw, $revision, 0 );
1180 Article
::onArticleCreate( $this->mTitle
);
1182 require_once( 'RecentChange.php' );
1183 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1184 '', strlen( $text ), $revisionId );
1188 if(!$this->mTitle
->userIsWatching()) $this->watch();
1190 if ( $this->mTitle
->userIsWatching() ) {
1195 # The talk page isn't in the regular link tables, so we need to update manually:
1196 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1197 $dbw->update( 'page',
1198 array( 'page_touched' => $dbw->timestamp($now) ),
1199 array( 'page_namespace' => $talkns,
1200 'page_title' => $ttl ),
1203 # standard deferred updates
1204 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1206 $oldid = 0; # new article
1207 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1209 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1211 $watchthis, NULL ) );
1212 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1214 $watchthis, NULL ) );
1215 wfProfileOut( $fname );
1218 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1219 $this->replaceSection( $section, $text, $summary, $edittime );
1223 * @return string Complete article text, or null if error
1225 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1226 $fname = 'Article::replaceSection';
1227 wfProfileIn( $fname );
1229 if ($section != '') {
1230 if( is_null( $edittime ) ) {
1231 $rev = Revision
::newFromTitle( $this->mTitle
);
1233 $dbw =& wfGetDB( DB_MASTER
);
1234 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1236 if( is_null( $rev ) ) {
1237 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1238 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1241 $oldtext = $rev->getText();
1243 if($section=='new') {
1244 if($summary) $subject="== {$summary} ==\n\n";
1245 $text=$oldtext."\n\n".$subject.$text;
1248 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1249 # comments to be stripped as well)
1250 $striparray=array();
1251 $parser=new Parser();
1252 $parser->mOutputType
=OT_WIKI
;
1253 $parser->mOptions
= new ParserOptions();
1254 $oldtext=$parser->strip($oldtext, $striparray, true);
1256 # now that we can be sure that no pseudo-sections are in the source,
1258 # Unfortunately we can't simply do a preg_replace because that might
1259 # replace the wrong section, so we have to use the section counter instead
1260 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
1261 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1262 $secs[$section*2]=$text."\n\n"; // replace with edited
1264 # section 0 is top (intro) section
1267 # headline of old section - we need to go through this section
1268 # to determine if there are any subsections that now need to
1269 # be erased, as the mother section has been replaced with
1270 # the text of all subsections.
1271 $headline=$secs[$section*2-1];
1272 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
1273 $hlevel=$matches[1];
1275 # determine headline level for wikimarkup headings
1276 if(strpos($hlevel,'=')!==false) {
1277 $hlevel=strlen($hlevel);
1280 $secs[$section*2-1]=''; // erase old headline
1283 while(!empty($secs[$count*2-1]) && !$break) {
1285 $subheadline=$secs[$count*2-1];
1287 '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
1288 $subhlevel=$matches[1];
1289 if(strpos($subhlevel,'=')!==false) {
1290 $subhlevel=strlen($subhlevel);
1292 if($subhlevel > $hlevel) {
1293 // erase old subsections
1294 $secs[$count*2-1]='';
1297 if($subhlevel <= $hlevel) {
1305 $text=join('',$secs);
1306 # reinsert the stuff that we stripped out earlier
1307 $text=$parser->unstrip($text,$striparray);
1308 $text=$parser->unstripNoWiki($text,$striparray);
1312 wfProfileOut( $fname );
1317 * Change an existing article. Puts the previous version back into the old table, updates RC
1318 * and all necessary caches, mostly via the deferred update array.
1320 * It is possible to call this function from a command-line script, but note that you should
1321 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1323 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1324 global $wgUser, $wgDBtransactions, $wgUseSquid;
1325 global $wgPostCommitUpdateList, $wgUseFileCache;
1327 $fname = 'Article::updateArticle';
1328 wfProfileIn( $fname );
1331 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1333 &$watchthis, &$sectionanchor ) ) ) {
1334 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1335 wfProfileOut( $fname );
1339 $isminor = $minor && $wgUser->isAllowed('minoredit');
1340 $redir = (int)$this->isRedirect( $text );
1342 $text = $this->preSaveTransform( $text );
1343 $dbw =& wfGetDB( DB_MASTER
);
1344 $now = wfTimestampNow();
1346 # Update article, but only if changed.
1348 # It's important that we either rollback or complete, otherwise an attacker could
1349 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1350 # could conceivably have the same effect, especially if cur is locked for long periods.
1351 if( !$wgDBtransactions ) {
1352 $userAbort = ignore_user_abort( true );
1355 $oldtext = $this->getContent();
1356 $oldsize = strlen( $oldtext );
1357 $newsize = strlen( $text );
1361 if ( 0 != strcmp( $text, $oldtext ) ) {
1362 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1363 - (int)$this->isCountable( $oldtext );
1364 $this->mTotalAdjustment
= 0;
1365 $now = wfTimestampNow();
1367 $lastRevision = $dbw->selectField(
1368 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1370 $revision = new Revision( array(
1371 'page' => $this->getId(),
1372 'comment' => $summary,
1373 'minor_edit' => $isminor,
1377 $dbw->immediateCommit();
1379 $revisionId = $revision->insertOn( $dbw );
1382 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1385 /* Belated edit conflict! Run away!! */
1389 # Update recentchanges and purge cache and whatnot
1390 require_once( 'RecentChange.php' );
1391 $bot = (int)($wgUser->isBot() ||
$forceBot);
1392 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1393 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1397 // Update caches outside the main transaction
1398 Article
::onArticleEdit( $this->mTitle
);
1401 // Keep the same revision ID, but do some updates on it
1402 $revisionId = $this->getRevIdFetched();
1405 if( !$wgDBtransactions ) {
1406 ignore_user_abort( $userAbort );
1411 if (!$this->mTitle
->userIsWatching()) {
1412 $dbw->immediateCommit();
1418 if ( $this->mTitle
->userIsWatching() ) {
1419 $dbw->immediateCommit();
1425 # standard deferred updates
1426 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1430 # Invalidate caches of all articles using this article as a template
1432 # Template namespace
1433 # Purge all articles linking here
1434 $titles = $this->mTitle
->getTemplateLinksTo();
1435 Title
::touchArray( $titles );
1436 if ( $wgUseSquid ) {
1437 foreach ( $titles as $title ) {
1438 $urls[] = $title->getInternalURL();
1443 if ( $wgUseSquid ) {
1444 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1445 $u = new SquidUpdate( $urls );
1446 array_push( $wgPostCommitUpdateList, $u );
1450 if ( $wgUseFileCache ) {
1451 $cm = new CacheManager($this->mTitle
);
1452 @unlink
($cm->fileCacheName());
1455 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1457 wfRunHooks( 'ArticleSaveComplete',
1458 array( &$this, &$wgUser, $text,
1460 $watchthis, $sectionanchor ) );
1461 wfProfileOut( $fname );
1466 * After we've either updated or inserted the article, update
1467 * the link tables and redirect to the new page.
1469 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1472 $fname = 'Article::showArticle';
1473 wfProfileIn( $fname );
1475 # Output the redirect
1476 if( $this->isRedirect( $text ) )
1480 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1482 wfProfileOut( $fname );
1486 * Mark this particular edit as patrolled
1488 function markpatrolled() {
1489 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1490 $wgOut->setRobotpolicy( 'noindex,follow' );
1492 # Check RC patrol config. option
1493 if( !$wgUseRCPatrol ) {
1494 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1499 if( $wgUser->isLoggedIn() ) {
1500 if( !$wgUser->isAllowed( 'patrol' ) ) {
1501 $wgOut->permissionRequired( 'patrol' );
1505 $wgOut->loginToUse();
1509 $rcid = $wgRequest->getVal( 'rcid' );
1510 if ( !is_null ( $rcid ) )
1512 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) ) ) {
1513 require_once( 'RecentChange.php' );
1514 RecentChange
::markPatrolled( $rcid );
1515 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) );
1516 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1517 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1519 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1520 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1524 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1529 * Add this page to $wgUser's watchlist
1534 global $wgUser, $wgOut;
1536 if ( $wgUser->isAnon() ) {
1537 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1540 if ( wfReadOnly() ) {
1541 $wgOut->readOnlyPage();
1545 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1547 $wgUser->addWatch( $this->mTitle
);
1548 $wgUser->saveSettings();
1550 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1552 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1553 $wgOut->setRobotpolicy( 'noindex,follow' );
1555 $link = $this->mTitle
->getPrefixedText();
1556 $text = wfMsg( 'addedwatchtext', $link );
1557 $wgOut->addWikiText( $text );
1560 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1564 * Stop watching a page
1567 function unwatch() {
1569 global $wgUser, $wgOut;
1571 if ( $wgUser->isAnon() ) {
1572 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1575 if ( wfReadOnly() ) {
1576 $wgOut->readOnlyPage();
1580 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1582 $wgUser->removeWatch( $this->mTitle
);
1583 $wgUser->saveSettings();
1585 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1587 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1588 $wgOut->setRobotpolicy( 'noindex,follow' );
1590 $link = $this->mTitle
->getPrefixedText();
1591 $text = wfMsg( 'removedwatchtext', $link );
1592 $wgOut->addWikiText( $text );
1595 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1599 * action=protect handler
1601 function protect() {
1602 require_once 'ProtectionForm.php';
1603 $form = new ProtectionForm( $this );
1608 * action=unprotect handler (alias)
1610 function unprotect() {
1615 * Update the article's restriction field, and leave a log entry.
1617 * @param array $limit set of restriction keys
1618 * @param string $reason
1619 * @return bool true on success
1621 function updateRestrictions( $limit = array(), $reason = '' ) {
1624 if ( !$wgUser->isAllowed( 'protect' ) ) {
1628 if( wfReadOnly() ) {
1632 $id = $this->mTitle
->getArticleID();
1637 $flat = Article
::flattenRestrictions( $limit );
1638 $protecting = ($flat != '');
1640 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser,
1641 $limit, $reason ) ) ) {
1643 $dbw =& wfGetDB( DB_MASTER
);
1644 $dbw->update( 'page',
1646 'page_touched' => $dbw->timestamp(),
1647 'page_restrictions' => $flat
1648 ), array( /* WHERE */
1650 ), 'Article::protect'
1653 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser,
1654 $limit, $reason ) );
1656 $log = new LogPage( 'protect' );
1658 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$flat]" ) );
1660 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1667 * Take an array of page restrictions and flatten it to a string
1668 * suitable for insertion into the page_restrictions field.
1669 * @param array $limit
1673 function flattenRestrictions( $limit ) {
1674 if( !is_array( $limit ) ) {
1675 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1678 foreach( $limit as $action => $restrictions ) {
1679 if( $restrictions != '' ) {
1680 $bits[] = "$action=$restrictions";
1683 return implode( ':', $bits );
1687 * UI entry point for page deletion
1690 global $wgUser, $wgOut, $wgRequest;
1691 $fname = 'Article::delete';
1692 $confirm = $wgRequest->wasPosted() &&
1693 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1694 $reason = $wgRequest->getText( 'wpReason' );
1696 # This code desperately needs to be totally rewritten
1699 if( $wgUser->isAllowed( 'delete' ) ) {
1700 if( $wgUser->isBlocked() ) {
1701 $wgOut->blockedPage();
1705 $wgOut->permissionRequired( 'delete' );
1709 if( wfReadOnly() ) {
1710 $wgOut->readOnlyPage();
1714 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1716 # Better double-check that it hasn't been deleted yet!
1717 $dbw =& wfGetDB( DB_MASTER
);
1718 $conds = $this->mTitle
->pageCond();
1719 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1720 if ( $latest === false ) {
1721 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1726 $this->doDelete( $reason );
1730 # determine whether this page has earlier revisions
1731 # and insert a warning if it does
1733 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1735 if( count( $authors ) > 1 && !$confirm ) {
1736 $skin=$wgUser->getSkin();
1737 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1738 $wgOut->addHTML( $skin->historyLink() .'</b>');
1741 # If a single user is responsible for all revisions, find out who they are
1742 if ( count( $authors ) == $maxRevisions ) {
1743 // Query bailed out, too many revisions to find out if they're all the same
1744 $authorOfAll = false;
1746 $authorOfAll = reset( $authors );
1747 foreach ( $authors as $author ) {
1748 if ( $authorOfAll != $author ) {
1749 $authorOfAll = false;
1754 # Fetch article text
1755 $rev = Revision
::newFromTitle( $this->mTitle
);
1757 if( !is_null( $rev ) ) {
1758 # if this is a mini-text, we can paste part of it into the deletion reason
1759 $text = $rev->getText();
1761 #if this is empty, an earlier revision may contain "useful" text
1764 $prev = $rev->getPrevious();
1766 $text = $prev->getText();
1771 $length = strlen( $text );
1773 # this should not happen, since it is not possible to store an empty, new
1774 # page. Let's insert a standard text in case it does, though
1775 if( $length == 0 && $reason === '' ) {
1776 $reason = wfMsgForContent( 'exblank' );
1779 if( $length < 500 && $reason === '' ) {
1780 # comment field=255, let's grep the first 150 to have some user
1783 $text = $wgContLang->truncate( $text, 150, '...' );
1785 # let's strip out newlines
1786 $text = preg_replace( "/[\n\r]/", '', $text );
1789 if( $authorOfAll === false ) {
1790 $reason = wfMsgForContent( 'excontent', $text );
1792 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1795 $reason = wfMsgForContent( 'exbeforeblank', $text );
1800 return $this->confirmDelete( '', $reason );
1804 * Get the last N authors
1805 * @param int $num Number of revisions to get
1806 * @param string $revLatest The latest rev_id, selected from the master (optional)
1807 * @return array Array of authors, duplicates not removed
1809 function getLastNAuthors( $num, $revLatest = 0 ) {
1810 $fname = 'Article::getLastNAuthors';
1811 wfProfileIn( $fname );
1813 // First try the slave
1814 // If that doesn't have the latest revision, try the master
1816 $db =& wfGetDB( DB_SLAVE
);
1818 $res = $db->select( array( 'page', 'revision' ),
1819 array( 'rev_id', 'rev_user_text' ),
1821 'page_namespace' => $this->mTitle
->getNamespace(),
1822 'page_title' => $this->mTitle
->getDBkey(),
1823 'rev_page = page_id'
1824 ), $fname, $this->getSelectOptions( array(
1825 'ORDER BY' => 'rev_timestamp DESC',
1830 wfProfileOut( $fname );
1833 $row = $db->fetchObject( $res );
1834 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1835 $db =& wfGetDB( DB_MASTER
);
1840 } while ( $continue );
1842 $authors = array( $row->rev_user_text
);
1843 while ( $row = $db->fetchObject( $res ) ) {
1844 $authors[] = $row->rev_user_text
;
1846 wfProfileOut( $fname );
1851 * Output deletion confirmation dialog
1853 function confirmDelete( $par, $reason ) {
1854 global $wgOut, $wgUser;
1856 wfDebug( "Article::confirmDelete\n" );
1858 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1859 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1860 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1861 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1863 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1865 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1866 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1867 $token = htmlspecialchars( $wgUser->editToken() );
1870 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1874 <label for='wpReason'>{$delcom}:</label>
1877 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1883 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1887 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1890 $wgOut->returnToMain( false );
1895 * Perform a deletion and output success or failure messages
1897 function doDelete( $reason ) {
1898 global $wgOut, $wgUser;
1899 $fname = 'Article::doDelete';
1900 wfDebug( $fname."\n" );
1902 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1903 if ( $this->doDeleteArticle( $reason ) ) {
1904 $deleted = $this->mTitle
->getPrefixedText();
1906 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1907 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1909 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1910 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1912 $wgOut->addWikiText( $text );
1913 $wgOut->returnToMain( false );
1914 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1916 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1922 * Back-end article deletion
1923 * Deletes the article with database consistency, writes logs, purges caches
1926 function doDeleteArticle( $reason ) {
1927 global $wgUseSquid, $wgDeferredUpdateList;
1928 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1930 $fname = 'Article::doDeleteArticle';
1931 wfDebug( $fname."\n" );
1933 $dbw =& wfGetDB( DB_MASTER
);
1934 $ns = $this->mTitle
->getNamespace();
1935 $t = $this->mTitle
->getDBkey();
1936 $id = $this->mTitle
->getArticleID();
1938 if ( $t == '' ||
$id == 0 ) {
1942 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1943 array_push( $wgDeferredUpdateList, $u );
1945 $linksTo = $this->mTitle
->getLinksTo();
1948 if ( $wgUseSquid ) {
1950 $this->mTitle
->getInternalURL(),
1951 $this->mTitle
->getInternalURL( 'history' )
1954 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1955 array_push( $wgPostCommitUpdateList, $u );
1959 # Client and file cache invalidation
1960 Title
::touchArray( $linksTo );
1963 // For now, shunt the revision data into the archive table.
1964 // Text is *not* removed from the text table; bulk storage
1965 // is left intact to avoid breaking block-compression or
1966 // immutable storage schemes.
1968 // For backwards compatibility, note that some older archive
1969 // table entries will have ar_text and ar_flags fields still.
1971 // In the future, we may keep revisions and mark them with
1972 // the rev_deleted field, which is reserved for this purpose.
1973 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1975 'ar_namespace' => 'page_namespace',
1976 'ar_title' => 'page_title',
1977 'ar_comment' => 'rev_comment',
1978 'ar_user' => 'rev_user',
1979 'ar_user_text' => 'rev_user_text',
1980 'ar_timestamp' => 'rev_timestamp',
1981 'ar_minor_edit' => 'rev_minor_edit',
1982 'ar_rev_id' => 'rev_id',
1983 'ar_text_id' => 'rev_text_id',
1986 'page_id = rev_page'
1990 # Now that it's safely backed up, delete it
1991 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1992 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1994 if ($wgUseTrackbacks)
1995 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1997 # Clean up recentchanges entries...
1998 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
2000 # Finally, clean up the link tables
2001 $t = $this->mTitle
->getPrefixedDBkey();
2003 Article
::onArticleDelete( $this->mTitle
);
2005 # Delete outgoing links
2006 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2007 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2008 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2009 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
2010 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
2013 $log = new LogPage( 'delete' );
2014 $log->addEntry( 'delete', $this->mTitle
, $reason );
2016 # Clear the cached article id so the interface doesn't act like we exist
2017 $this->mTitle
->resetArticleID( 0 );
2018 $this->mTitle
->mArticleID
= 0;
2023 * Revert a modification
2025 function rollback() {
2026 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2027 $fname = 'Article::rollback';
2029 if( $wgUser->isAllowed( 'rollback' ) ) {
2030 if( $wgUser->isBlocked() ) {
2031 $wgOut->blockedPage();
2035 $wgOut->permissionRequired( 'rollback' );
2039 if ( wfReadOnly() ) {
2040 $wgOut->readOnlyPage( $this->getContent() );
2043 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2044 array( $this->mTitle
->getPrefixedText(),
2045 $wgRequest->getVal( 'from' ) ) ) ) {
2046 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2047 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2050 $dbw =& wfGetDB( DB_MASTER
);
2052 # Enhanced rollback, marks edits rc_bot=1
2053 $bot = $wgRequest->getBool( 'bot' );
2055 # Replace all this user's current edits with the next one down
2056 $tt = $this->mTitle
->getDBKey();
2057 $n = $this->mTitle
->getNamespace();
2059 # Get the last editor, lock table exclusively
2061 $current = Revision
::newFromTitle( $this->mTitle
);
2062 if( is_null( $current ) ) {
2063 # Something wrong... no page?
2065 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2069 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2070 if( $from != $current->getUserText() ) {
2071 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2072 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2073 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2074 htmlspecialchars( $from ),
2075 htmlspecialchars( $current->getUserText() ) ) );
2076 if( $current->getComment() != '') {
2078 wfMsg( 'editcomment',
2079 htmlspecialchars( $current->getComment() ) ) );
2084 # Get the last edit not by this guy
2085 $user = intval( $current->getUser() );
2086 $user_text = $dbw->addQuotes( $current->getUserText() );
2087 $s = $dbw->selectRow( 'revision',
2088 array( 'rev_id', 'rev_timestamp' ),
2090 'rev_page' => $current->getPage(),
2091 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2094 'USE INDEX' => 'page_timestamp',
2095 'ORDER BY' => 'rev_timestamp DESC' )
2097 if( $s === false ) {
2100 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2101 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2107 # Mark all reverted edits as bot
2110 if ( $wgUseRCPatrol ) {
2111 # Mark all reverted edits as patrolled
2112 $set['rc_patrolled'] = 1;
2116 $dbw->update( 'recentchanges', $set,
2118 'rc_cur_id' => $current->getPage(),
2119 'rc_user_text' => $current->getUserText(),
2120 "rc_timestamp > '{$s->rev_timestamp}'",
2125 # Get the edit summary
2126 $target = Revision
::newFromId( $s->rev_id
);
2127 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2128 $newComment = $wgRequest->getText( 'summary', $newComment );
2131 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2132 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2133 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2135 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2136 Article
::onArticleEdit( $this->mTitle
);
2139 $wgOut->returnToMain( false );
2144 * Do standard deferred updates after page view
2147 function viewUpdates() {
2148 global $wgDeferredUpdateList;
2150 if ( 0 != $this->getID() ) {
2151 global $wgDisableCounters;
2152 if( !$wgDisableCounters ) {
2153 Article
::incViewCount( $this->getID() );
2154 $u = new SiteStatsUpdate( 1, 0, 0 );
2155 array_push( $wgDeferredUpdateList, $u );
2159 # Update newtalk / watchlist notification status
2161 $wgUser->clearNotification( $this->mTitle
);
2165 * Do standard deferred updates after page edit.
2166 * Every 1000th edit, prune the recent changes table.
2168 * @param string $text
2170 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2171 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2173 $fname = 'Article::editUpdates';
2174 wfProfileIn( $fname );
2177 $options = new ParserOptions
;
2178 $options->setTidy(true);
2179 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2181 # Save it to the parser cache
2182 $parserCache =& ParserCache
::singleton();
2183 $parserCache->save( $poutput, $this, $wgUser );
2185 # Update the links tables
2186 $u = new LinksUpdate( $this->mTitle
, $poutput );
2189 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2191 if ( 0 == mt_rand( 0, 999 ) ) {
2192 # Periodically flush old entries from the recentchanges table.
2195 $dbw =& wfGetDB( DB_MASTER
);
2196 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2197 $recentchanges = $dbw->tableName( 'recentchanges' );
2198 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2199 $dbw->query( $sql );
2203 $id = $this->getID();
2204 $title = $this->mTitle
->getPrefixedDBkey();
2205 $shortTitle = $this->mTitle
->getDBkey();
2208 wfProfileOut( $fname );
2212 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2213 array_push( $wgDeferredUpdateList, $u );
2214 $u = new SearchUpdate( $id, $title, $text );
2215 array_push( $wgDeferredUpdateList, $u );
2217 # If this is another user's talk page, update newtalk
2219 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2220 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2221 $other = User
::newFromName( $shortTitle );
2222 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2223 // An anonymous user
2224 $other = new User();
2225 $other->setName( $shortTitle );
2228 $other->setNewtalk( true );
2233 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2234 $wgMessageCache->replace( $shortTitle, $text );
2237 wfProfileOut( $fname );
2241 * Generate the navigation links when browsing through an article revisions
2242 * It shows the information as:
2243 * Revision as of <date>; view current revision
2244 * <- Previous version | Next Version ->
2247 * @param string $oldid Revision ID of this article revision
2249 function setOldSubtitle( $oldid=0 ) {
2250 global $wgLang, $wgOut, $wgUser;
2252 $current = ( $oldid == $this->mLatest
);
2253 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2254 $sk = $wgUser->getSkin();
2256 ?
wfMsg( 'currentrevisionlink' )
2257 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2258 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2260 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2261 : wfMsg( 'previousrevision' );
2262 $nextlink = $current
2263 ?
wfMsg( 'nextrevision' )
2264 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2265 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2266 $wgOut->setSubtitle( $r );
2270 * This function is called right before saving the wikitext,
2271 * so we can do things like signatures and links-in-context.
2273 * @param string $text
2275 function preSaveTransform( $text ) {
2276 global $wgParser, $wgUser;
2277 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2280 /* Caching functions */
2283 * checkLastModified returns true if it has taken care of all
2284 * output to the client that is necessary for this request.
2285 * (that is, it has sent a cached version of the page)
2287 function tryFileCache() {
2288 static $called = false;
2290 wfDebug( " tryFileCache() -- called twice!?\n" );
2294 if($this->isFileCacheable()) {
2295 $touched = $this->mTouched
;
2296 $cache = new CacheManager( $this->mTitle
);
2297 if($cache->isFileCacheGood( $touched )) {
2298 wfDebug( " tryFileCache() - about to load\n" );
2299 $cache->loadFromFileCache();
2302 wfDebug( " tryFileCache() - starting buffer\n" );
2303 ob_start( array(&$cache, 'saveToFileCache' ) );
2306 wfDebug( " tryFileCache() - not cacheable\n" );
2311 * Check if the page can be cached
2314 function isFileCacheable() {
2315 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2316 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2318 return $wgUseFileCache
2319 and (!$wgShowIPinHeader)
2320 and ($this->getID() != 0)
2321 and ($wgUser->isAnon())
2322 and (!$wgUser->getNewtalk())
2323 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2324 and (empty( $action ) ||
$action == 'view')
2325 and (!isset($oldid))
2327 and (!isset($redirect))
2328 and (!isset($printable))
2329 and (!$this->mRedirectedFrom
);
2333 * Loads page_touched and returns a value indicating if it should be used
2336 function checkTouched() {
2337 $fname = 'Article::checkTouched';
2338 if( !$this->mDataLoaded
) {
2339 $dbr =& $this->getDB();
2340 $data = $this->pageDataFromId( $dbr, $this->getId() );
2342 $this->loadPageData( $data );
2345 return !$this->mIsRedirect
;
2349 * Get the page_touched field
2351 function getTouched() {
2352 # Ensure that page data has been loaded
2353 if( !$this->mDataLoaded
) {
2354 $dbr =& $this->getDB();
2355 $data = $this->pageDataFromId( $dbr, $this->getId() );
2357 $this->loadPageData( $data );
2360 return $this->mTouched
;
2364 * Edit an article without doing all that other stuff
2365 * The article must already exist; link tables etc
2366 * are not updated, caches are not flushed.
2368 * @param string $text text submitted
2369 * @param string $comment comment submitted
2370 * @param bool $minor whereas it's a minor modification
2372 function quickEdit( $text, $comment = '', $minor = 0 ) {
2373 $fname = 'Article::quickEdit';
2374 wfProfileIn( $fname );
2376 $dbw =& wfGetDB( DB_MASTER
);
2378 $revision = new Revision( array(
2379 'page' => $this->getId(),
2381 'comment' => $comment,
2382 'minor_edit' => $minor ?
1 : 0,
2384 $revisionId = $revision->insertOn( $dbw );
2385 $this->updateRevisionOn( $dbw, $revision );
2388 wfProfileOut( $fname );
2392 * Used to increment the view counter
2395 * @param integer $id article id
2397 function incViewCount( $id ) {
2398 $id = intval( $id );
2399 global $wgHitcounterUpdateFreq;
2401 $dbw =& wfGetDB( DB_MASTER
);
2402 $pageTable = $dbw->tableName( 'page' );
2403 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2404 $acchitsTable = $dbw->tableName( 'acchits' );
2406 if( $wgHitcounterUpdateFreq <= 1 ){ //
2407 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2411 # Not important enough to warrant an error page in case of failure
2412 $oldignore = $dbw->ignoreErrors( true );
2414 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2416 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2417 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2418 # Most of the time (or on SQL errors), skip row count check
2419 $dbw->ignoreErrors( $oldignore );
2423 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2424 $row = $dbw->fetchObject( $res );
2425 $rown = intval( $row->n
);
2426 if( $rown >= $wgHitcounterUpdateFreq ){
2427 wfProfileIn( 'Article::incViewCount-collect' );
2428 $old_user_abort = ignore_user_abort( true );
2430 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2431 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2432 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2434 $dbw->query("DELETE FROM $hitcounterTable");
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 );