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->doWatch();
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 * User-interface handler for the "watch" action
1534 global $wgUser, $wgOut;
1536 if ( $wgUser->isAnon() ) {
1537 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1540 if ( wfReadOnly() ) {
1541 $wgOut->readOnlyPage();
1545 if( $this->doWatch() ) {
1546 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1547 $wgOut->setRobotpolicy( 'noindex,follow' );
1549 $link = $this->mTitle
->getPrefixedText();
1550 $text = wfMsg( 'addedwatchtext', $link );
1551 $wgOut->addWikiText( $text );
1554 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1558 * Add this page to $wgUser's watchlist
1559 * @return bool true on successful watch operation
1561 function doWatch() {
1563 if( $wgUser->isAnon() ) {
1567 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1568 $wgUser->addWatch( $this->mTitle
);
1569 $wgUser->saveSettings();
1571 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1578 * User interface handler for the "unwatch" action.
1580 function unwatch() {
1582 global $wgUser, $wgOut;
1584 if ( $wgUser->isAnon() ) {
1585 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1588 if ( wfReadOnly() ) {
1589 $wgOut->readOnlyPage();
1593 if( $this->doUnwatch() ) {
1594 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1595 $wgOut->setRobotpolicy( 'noindex,follow' );
1597 $link = $this->mTitle
->getPrefixedText();
1598 $text = wfMsg( 'removedwatchtext', $link );
1599 $wgOut->addWikiText( $text );
1602 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1606 * Stop watching a page
1607 * @return bool true on successful unwatch
1609 function doUnwatch() {
1611 if( $wgUser->isAnon() ) {
1615 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1616 $wgUser->removeWatch( $this->mTitle
);
1617 $wgUser->saveSettings();
1619 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1626 * action=protect handler
1628 function protect() {
1629 require_once 'ProtectionForm.php';
1630 $form = new ProtectionForm( $this );
1635 * action=unprotect handler (alias)
1637 function unprotect() {
1642 * Update the article's restriction field, and leave a log entry.
1644 * @param array $limit set of restriction keys
1645 * @param string $reason
1646 * @return bool true on success
1648 function updateRestrictions( $limit = array(), $reason = '' ) {
1651 if ( !$wgUser->isAllowed( 'protect' ) ) {
1655 if( wfReadOnly() ) {
1659 $id = $this->mTitle
->getArticleID();
1664 $flat = Article
::flattenRestrictions( $limit );
1665 $protecting = ($flat != '');
1667 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser,
1668 $limit, $reason ) ) ) {
1670 $dbw =& wfGetDB( DB_MASTER
);
1671 $dbw->update( 'page',
1673 'page_touched' => $dbw->timestamp(),
1674 'page_restrictions' => $flat
1675 ), array( /* WHERE */
1677 ), 'Article::protect'
1680 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser,
1681 $limit, $reason ) );
1683 $log = new LogPage( 'protect' );
1685 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$flat]" ) );
1687 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1694 * Take an array of page restrictions and flatten it to a string
1695 * suitable for insertion into the page_restrictions field.
1696 * @param array $limit
1700 function flattenRestrictions( $limit ) {
1701 if( !is_array( $limit ) ) {
1702 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1705 foreach( $limit as $action => $restrictions ) {
1706 if( $restrictions != '' ) {
1707 $bits[] = "$action=$restrictions";
1710 return implode( ':', $bits );
1714 * UI entry point for page deletion
1717 global $wgUser, $wgOut, $wgRequest;
1718 $fname = 'Article::delete';
1719 $confirm = $wgRequest->wasPosted() &&
1720 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1721 $reason = $wgRequest->getText( 'wpReason' );
1723 # This code desperately needs to be totally rewritten
1726 if( $wgUser->isAllowed( 'delete' ) ) {
1727 if( $wgUser->isBlocked() ) {
1728 $wgOut->blockedPage();
1732 $wgOut->permissionRequired( 'delete' );
1736 if( wfReadOnly() ) {
1737 $wgOut->readOnlyPage();
1741 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1743 # Better double-check that it hasn't been deleted yet!
1744 $dbw =& wfGetDB( DB_MASTER
);
1745 $conds = $this->mTitle
->pageCond();
1746 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1747 if ( $latest === false ) {
1748 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1753 $this->doDelete( $reason );
1757 # determine whether this page has earlier revisions
1758 # and insert a warning if it does
1760 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1762 if( count( $authors ) > 1 && !$confirm ) {
1763 $skin=$wgUser->getSkin();
1764 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1765 $wgOut->addHTML( $skin->historyLink() .'</b>');
1768 # If a single user is responsible for all revisions, find out who they are
1769 if ( count( $authors ) == $maxRevisions ) {
1770 // Query bailed out, too many revisions to find out if they're all the same
1771 $authorOfAll = false;
1773 $authorOfAll = reset( $authors );
1774 foreach ( $authors as $author ) {
1775 if ( $authorOfAll != $author ) {
1776 $authorOfAll = false;
1781 # Fetch article text
1782 $rev = Revision
::newFromTitle( $this->mTitle
);
1784 if( !is_null( $rev ) ) {
1785 # if this is a mini-text, we can paste part of it into the deletion reason
1786 $text = $rev->getText();
1788 #if this is empty, an earlier revision may contain "useful" text
1791 $prev = $rev->getPrevious();
1793 $text = $prev->getText();
1798 $length = strlen( $text );
1800 # this should not happen, since it is not possible to store an empty, new
1801 # page. Let's insert a standard text in case it does, though
1802 if( $length == 0 && $reason === '' ) {
1803 $reason = wfMsgForContent( 'exblank' );
1806 if( $length < 500 && $reason === '' ) {
1807 # comment field=255, let's grep the first 150 to have some user
1810 $text = $wgContLang->truncate( $text, 150, '...' );
1812 # let's strip out newlines
1813 $text = preg_replace( "/[\n\r]/", '', $text );
1816 if( $authorOfAll === false ) {
1817 $reason = wfMsgForContent( 'excontent', $text );
1819 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1822 $reason = wfMsgForContent( 'exbeforeblank', $text );
1827 return $this->confirmDelete( '', $reason );
1831 * Get the last N authors
1832 * @param int $num Number of revisions to get
1833 * @param string $revLatest The latest rev_id, selected from the master (optional)
1834 * @return array Array of authors, duplicates not removed
1836 function getLastNAuthors( $num, $revLatest = 0 ) {
1837 $fname = 'Article::getLastNAuthors';
1838 wfProfileIn( $fname );
1840 // First try the slave
1841 // If that doesn't have the latest revision, try the master
1843 $db =& wfGetDB( DB_SLAVE
);
1845 $res = $db->select( array( 'page', 'revision' ),
1846 array( 'rev_id', 'rev_user_text' ),
1848 'page_namespace' => $this->mTitle
->getNamespace(),
1849 'page_title' => $this->mTitle
->getDBkey(),
1850 'rev_page = page_id'
1851 ), $fname, $this->getSelectOptions( array(
1852 'ORDER BY' => 'rev_timestamp DESC',
1857 wfProfileOut( $fname );
1860 $row = $db->fetchObject( $res );
1861 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1862 $db =& wfGetDB( DB_MASTER
);
1867 } while ( $continue );
1869 $authors = array( $row->rev_user_text
);
1870 while ( $row = $db->fetchObject( $res ) ) {
1871 $authors[] = $row->rev_user_text
;
1873 wfProfileOut( $fname );
1878 * Output deletion confirmation dialog
1880 function confirmDelete( $par, $reason ) {
1881 global $wgOut, $wgUser;
1883 wfDebug( "Article::confirmDelete\n" );
1885 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1886 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1887 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1888 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1890 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1892 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1893 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1894 $token = htmlspecialchars( $wgUser->editToken() );
1897 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1901 <label for='wpReason'>{$delcom}:</label>
1904 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1910 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1914 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1917 $wgOut->returnToMain( false );
1922 * Perform a deletion and output success or failure messages
1924 function doDelete( $reason ) {
1925 global $wgOut, $wgUser;
1926 $fname = 'Article::doDelete';
1927 wfDebug( $fname."\n" );
1929 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1930 if ( $this->doDeleteArticle( $reason ) ) {
1931 $deleted = $this->mTitle
->getPrefixedText();
1933 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1934 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1936 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1937 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1939 $wgOut->addWikiText( $text );
1940 $wgOut->returnToMain( false );
1941 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1943 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1949 * Back-end article deletion
1950 * Deletes the article with database consistency, writes logs, purges caches
1953 function doDeleteArticle( $reason ) {
1954 global $wgUseSquid, $wgDeferredUpdateList;
1955 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1957 $fname = 'Article::doDeleteArticle';
1958 wfDebug( $fname."\n" );
1960 $dbw =& wfGetDB( DB_MASTER
);
1961 $ns = $this->mTitle
->getNamespace();
1962 $t = $this->mTitle
->getDBkey();
1963 $id = $this->mTitle
->getArticleID();
1965 if ( $t == '' ||
$id == 0 ) {
1969 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1970 array_push( $wgDeferredUpdateList, $u );
1972 $linksTo = $this->mTitle
->getLinksTo();
1975 if ( $wgUseSquid ) {
1977 $this->mTitle
->getInternalURL(),
1978 $this->mTitle
->getInternalURL( 'history' )
1981 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1982 array_push( $wgPostCommitUpdateList, $u );
1986 # Client and file cache invalidation
1987 Title
::touchArray( $linksTo );
1990 // For now, shunt the revision data into the archive table.
1991 // Text is *not* removed from the text table; bulk storage
1992 // is left intact to avoid breaking block-compression or
1993 // immutable storage schemes.
1995 // For backwards compatibility, note that some older archive
1996 // table entries will have ar_text and ar_flags fields still.
1998 // In the future, we may keep revisions and mark them with
1999 // the rev_deleted field, which is reserved for this purpose.
2000 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
2002 'ar_namespace' => 'page_namespace',
2003 'ar_title' => 'page_title',
2004 'ar_comment' => 'rev_comment',
2005 'ar_user' => 'rev_user',
2006 'ar_user_text' => 'rev_user_text',
2007 'ar_timestamp' => 'rev_timestamp',
2008 'ar_minor_edit' => 'rev_minor_edit',
2009 'ar_rev_id' => 'rev_id',
2010 'ar_text_id' => 'rev_text_id',
2013 'page_id = rev_page'
2017 # Now that it's safely backed up, delete it
2018 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
2019 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
2021 if ($wgUseTrackbacks)
2022 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
2024 # Clean up recentchanges entries...
2025 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
2027 # Finally, clean up the link tables
2028 $t = $this->mTitle
->getPrefixedDBkey();
2030 Article
::onArticleDelete( $this->mTitle
);
2032 # Delete outgoing links
2033 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2034 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2035 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2036 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
2037 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
2040 $log = new LogPage( 'delete' );
2041 $log->addEntry( 'delete', $this->mTitle
, $reason );
2043 # Clear the cached article id so the interface doesn't act like we exist
2044 $this->mTitle
->resetArticleID( 0 );
2045 $this->mTitle
->mArticleID
= 0;
2050 * Revert a modification
2052 function rollback() {
2053 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2054 $fname = 'Article::rollback';
2056 if( $wgUser->isAllowed( 'rollback' ) ) {
2057 if( $wgUser->isBlocked() ) {
2058 $wgOut->blockedPage();
2062 $wgOut->permissionRequired( 'rollback' );
2066 if ( wfReadOnly() ) {
2067 $wgOut->readOnlyPage( $this->getContent() );
2070 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2071 array( $this->mTitle
->getPrefixedText(),
2072 $wgRequest->getVal( 'from' ) ) ) ) {
2073 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2074 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2077 $dbw =& wfGetDB( DB_MASTER
);
2079 # Enhanced rollback, marks edits rc_bot=1
2080 $bot = $wgRequest->getBool( 'bot' );
2082 # Replace all this user's current edits with the next one down
2083 $tt = $this->mTitle
->getDBKey();
2084 $n = $this->mTitle
->getNamespace();
2086 # Get the last editor, lock table exclusively
2088 $current = Revision
::newFromTitle( $this->mTitle
);
2089 if( is_null( $current ) ) {
2090 # Something wrong... no page?
2092 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2096 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2097 if( $from != $current->getUserText() ) {
2098 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2099 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2100 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2101 htmlspecialchars( $from ),
2102 htmlspecialchars( $current->getUserText() ) ) );
2103 if( $current->getComment() != '') {
2105 wfMsg( 'editcomment',
2106 htmlspecialchars( $current->getComment() ) ) );
2111 # Get the last edit not by this guy
2112 $user = intval( $current->getUser() );
2113 $user_text = $dbw->addQuotes( $current->getUserText() );
2114 $s = $dbw->selectRow( 'revision',
2115 array( 'rev_id', 'rev_timestamp' ),
2117 'rev_page' => $current->getPage(),
2118 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2121 'USE INDEX' => 'page_timestamp',
2122 'ORDER BY' => 'rev_timestamp DESC' )
2124 if( $s === false ) {
2127 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2128 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2134 # Mark all reverted edits as bot
2137 if ( $wgUseRCPatrol ) {
2138 # Mark all reverted edits as patrolled
2139 $set['rc_patrolled'] = 1;
2143 $dbw->update( 'recentchanges', $set,
2145 'rc_cur_id' => $current->getPage(),
2146 'rc_user_text' => $current->getUserText(),
2147 "rc_timestamp > '{$s->rev_timestamp}'",
2152 # Get the edit summary
2153 $target = Revision
::newFromId( $s->rev_id
);
2154 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2155 $newComment = $wgRequest->getText( 'summary', $newComment );
2158 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2159 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2160 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2162 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2163 Article
::onArticleEdit( $this->mTitle
);
2166 $wgOut->returnToMain( false );
2171 * Do standard deferred updates after page view
2174 function viewUpdates() {
2175 global $wgDeferredUpdateList;
2177 if ( 0 != $this->getID() ) {
2178 global $wgDisableCounters;
2179 if( !$wgDisableCounters ) {
2180 Article
::incViewCount( $this->getID() );
2181 $u = new SiteStatsUpdate( 1, 0, 0 );
2182 array_push( $wgDeferredUpdateList, $u );
2186 # Update newtalk / watchlist notification status
2188 $wgUser->clearNotification( $this->mTitle
);
2192 * Do standard deferred updates after page edit.
2193 * Every 1000th edit, prune the recent changes table.
2195 * @param string $text
2197 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2198 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2200 $fname = 'Article::editUpdates';
2201 wfProfileIn( $fname );
2204 $options = new ParserOptions
;
2205 $options->setTidy(true);
2206 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2208 # Save it to the parser cache
2209 $parserCache =& ParserCache
::singleton();
2210 $parserCache->save( $poutput, $this, $wgUser );
2212 # Update the links tables
2213 $u = new LinksUpdate( $this->mTitle
, $poutput );
2216 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2218 if ( 0 == mt_rand( 0, 999 ) ) {
2219 # Periodically flush old entries from the recentchanges table.
2222 $dbw =& wfGetDB( DB_MASTER
);
2223 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2224 $recentchanges = $dbw->tableName( 'recentchanges' );
2225 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2226 $dbw->query( $sql );
2230 $id = $this->getID();
2231 $title = $this->mTitle
->getPrefixedDBkey();
2232 $shortTitle = $this->mTitle
->getDBkey();
2235 wfProfileOut( $fname );
2239 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2240 array_push( $wgDeferredUpdateList, $u );
2241 $u = new SearchUpdate( $id, $title, $text );
2242 array_push( $wgDeferredUpdateList, $u );
2244 # If this is another user's talk page, update newtalk
2246 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2247 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2248 $other = User
::newFromName( $shortTitle );
2249 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2250 // An anonymous user
2251 $other = new User();
2252 $other->setName( $shortTitle );
2255 $other->setNewtalk( true );
2260 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2261 $wgMessageCache->replace( $shortTitle, $text );
2264 wfProfileOut( $fname );
2268 * Generate the navigation links when browsing through an article revisions
2269 * It shows the information as:
2270 * Revision as of <date>; view current revision
2271 * <- Previous version | Next Version ->
2274 * @param string $oldid Revision ID of this article revision
2276 function setOldSubtitle( $oldid=0 ) {
2277 global $wgLang, $wgOut, $wgUser;
2279 $current = ( $oldid == $this->mLatest
);
2280 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2281 $sk = $wgUser->getSkin();
2283 ?
wfMsg( 'currentrevisionlink' )
2284 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2285 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2287 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2288 : wfMsg( 'previousrevision' );
2289 $nextlink = $current
2290 ?
wfMsg( 'nextrevision' )
2291 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2292 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2293 $wgOut->setSubtitle( $r );
2297 * This function is called right before saving the wikitext,
2298 * so we can do things like signatures and links-in-context.
2300 * @param string $text
2302 function preSaveTransform( $text ) {
2303 global $wgParser, $wgUser;
2304 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2307 /* Caching functions */
2310 * checkLastModified returns true if it has taken care of all
2311 * output to the client that is necessary for this request.
2312 * (that is, it has sent a cached version of the page)
2314 function tryFileCache() {
2315 static $called = false;
2317 wfDebug( " tryFileCache() -- called twice!?\n" );
2321 if($this->isFileCacheable()) {
2322 $touched = $this->mTouched
;
2323 $cache = new CacheManager( $this->mTitle
);
2324 if($cache->isFileCacheGood( $touched )) {
2325 wfDebug( " tryFileCache() - about to load\n" );
2326 $cache->loadFromFileCache();
2329 wfDebug( " tryFileCache() - starting buffer\n" );
2330 ob_start( array(&$cache, 'saveToFileCache' ) );
2333 wfDebug( " tryFileCache() - not cacheable\n" );
2338 * Check if the page can be cached
2341 function isFileCacheable() {
2342 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2343 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2345 return $wgUseFileCache
2346 and (!$wgShowIPinHeader)
2347 and ($this->getID() != 0)
2348 and ($wgUser->isAnon())
2349 and (!$wgUser->getNewtalk())
2350 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2351 and (empty( $action ) ||
$action == 'view')
2352 and (!isset($oldid))
2354 and (!isset($redirect))
2355 and (!isset($printable))
2356 and (!$this->mRedirectedFrom
);
2360 * Loads page_touched and returns a value indicating if it should be used
2363 function checkTouched() {
2364 $fname = 'Article::checkTouched';
2365 if( !$this->mDataLoaded
) {
2366 $dbr =& $this->getDB();
2367 $data = $this->pageDataFromId( $dbr, $this->getId() );
2369 $this->loadPageData( $data );
2372 return !$this->mIsRedirect
;
2376 * Get the page_touched field
2378 function getTouched() {
2379 # Ensure that page data has been loaded
2380 if( !$this->mDataLoaded
) {
2381 $dbr =& $this->getDB();
2382 $data = $this->pageDataFromId( $dbr, $this->getId() );
2384 $this->loadPageData( $data );
2387 return $this->mTouched
;
2391 * Edit an article without doing all that other stuff
2392 * The article must already exist; link tables etc
2393 * are not updated, caches are not flushed.
2395 * @param string $text text submitted
2396 * @param string $comment comment submitted
2397 * @param bool $minor whereas it's a minor modification
2399 function quickEdit( $text, $comment = '', $minor = 0 ) {
2400 $fname = 'Article::quickEdit';
2401 wfProfileIn( $fname );
2403 $dbw =& wfGetDB( DB_MASTER
);
2405 $revision = new Revision( array(
2406 'page' => $this->getId(),
2408 'comment' => $comment,
2409 'minor_edit' => $minor ?
1 : 0,
2411 $revisionId = $revision->insertOn( $dbw );
2412 $this->updateRevisionOn( $dbw, $revision );
2415 wfProfileOut( $fname );
2419 * Used to increment the view counter
2422 * @param integer $id article id
2424 function incViewCount( $id ) {
2425 $id = intval( $id );
2426 global $wgHitcounterUpdateFreq;
2428 $dbw =& wfGetDB( DB_MASTER
);
2429 $pageTable = $dbw->tableName( 'page' );
2430 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2431 $acchitsTable = $dbw->tableName( 'acchits' );
2433 if( $wgHitcounterUpdateFreq <= 1 ){ //
2434 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2438 # Not important enough to warrant an error page in case of failure
2439 $oldignore = $dbw->ignoreErrors( true );
2441 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2443 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2444 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2445 # Most of the time (or on SQL errors), skip row count check
2446 $dbw->ignoreErrors( $oldignore );
2450 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2451 $row = $dbw->fetchObject( $res );
2452 $rown = intval( $row->n
);
2453 if( $rown >= $wgHitcounterUpdateFreq ){
2454 wfProfileIn( 'Article::incViewCount-collect' );
2455 $old_user_abort = ignore_user_abort( true );
2457 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2458 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2459 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2461 $dbw->query("DELETE FROM $hitcounterTable");
2462 $dbw->query('UNLOCK TABLES');
2463 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2464 'WHERE page_id = hc_id');
2465 $dbw->query("DROP TABLE $acchitsTable");
2467 ignore_user_abort( $old_user_abort );
2468 wfProfileOut( 'Article::incViewCount-collect' );
2470 $dbw->ignoreErrors( $oldignore );
2474 * The onArticle*() functions are supposed to be a kind of hooks
2475 * which should be called whenever any of the specified actions
2478 * This is a good place to put code to clear caches, for instance.
2480 * This is called on page move and undelete, as well as edit
2482 * @param $title_obj a title object
2485 function onArticleCreate($title_obj) {
2486 global $wgUseSquid, $wgPostCommitUpdateList;
2488 $title_obj->touchLinks();
2489 $titles = $title_obj->getLinksTo();
2492 if ( $wgUseSquid ) {
2493 $urls = $title_obj->getSquidURLs();
2494 foreach ( $titles as $linkTitle ) {
2495 $urls[] = $linkTitle->getInternalURL();
2497 $u = new SquidUpdate( $urls );
2498 array_push( $wgPostCommitUpdateList, $u );
2502 function onArticleDelete( $title ) {
2503 global $wgMessageCache;
2505 $title->touchLinks();
2507 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2508 $wgMessageCache->replace( $title->getDBkey(), false );
2513 * Purge caches on page update etc
2515 function onArticleEdit( $title ) {
2516 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2520 // Template namespace? Purge all articles linking here.
2521 // FIXME: When a templatelinks table arrives, use it for all includes.
2522 if ( $title->getNamespace() == NS_TEMPLATE
) {
2523 $titles = $title->getLinksTo();
2524 Title
::touchArray( $titles );
2525 if ( $wgUseSquid ) {
2526 foreach ( $titles as $link ) {
2527 $urls[] = $link->getInternalURL();
2533 if ( $wgUseSquid ) {
2534 $urls = array_merge( $urls, $title->getSquidURLs() );
2535 $u = new SquidUpdate( $urls );
2536 array_push( $wgPostCommitUpdateList, $u );
2540 if ( $wgUseFileCache ) {
2541 $cm = new CacheManager( $title );
2542 @unlink
( $cm->fileCacheName() );
2549 * Info about this page
2550 * Called for ?action=info when $wgAllowPageInfo is on.
2555 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2556 $fname = 'Article::info';
2558 if ( !$wgAllowPageInfo ) {
2559 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2563 $page = $this->mTitle
->getSubjectPage();
2565 $wgOut->setPagetitle( $page->getPrefixedText() );
2566 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2568 # first, see if the page exists at all.
2569 $exists = $page->getArticleId() != 0;
2571 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2572 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2574 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2577 $dbr =& wfGetDB( DB_SLAVE
);
2579 'wl_title' => $page->getDBkey(),
2580 'wl_namespace' => $page->getNamespace() );
2581 $numwatchers = $dbr->selectField(
2586 $this->getSelectOptions() );
2588 $pageInfo = $this->pageCountInfo( $page );
2589 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2591 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2592 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2594 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2596 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2598 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2600 $wgOut->addHTML( '</ul>' );
2606 * Return the total number of edits and number of unique editors
2607 * on a given page. If page does not exist, returns false.
2609 * @param Title $title
2613 function pageCountInfo( $title ) {
2614 $id = $title->getArticleId();
2619 $dbr =& wfGetDB( DB_SLAVE
);
2621 $rev_clause = array( 'rev_page' => $id );
2622 $fname = 'Article::pageCountInfo';
2624 $edits = $dbr->selectField(
2629 $this->getSelectOptions() );
2631 $authors = $dbr->selectField(
2633 'COUNT(DISTINCT rev_user_text)',
2636 $this->getSelectOptions() );
2638 return array( 'edits' => $edits, 'authors' => $authors );
2642 * Return a list of templates used by this article.
2643 * Uses the templatelinks table
2645 * @return array Array of Title objects
2647 function getUsedTemplates() {
2649 $id = $this->mTitle
->getArticleID();
2654 $dbr =& wfGetDB( DB_SLAVE
);
2655 $res = $dbr->select( array( 'templatelinks' ),
2656 array( 'tl_namespace', 'tl_title' ),
2657 array( 'tl_from' => $id ),
2658 'Article:getUsedTemplates' );
2659 if ( false !== $res ) {
2660 if ( $dbr->numRows( $res ) ) {
2661 while ( $row = $dbr->fetchObject( $res ) ) {
2662 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2666 $dbr->freeResult( $res );