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 * get the title object of the article
65 $this->mDataLoaded
= false;
66 $this->mContentLoaded
= false;
68 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
69 $this->mRedirectedFrom
= $this->mUserText
=
70 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
71 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
72 $this->mTouched
= '19700101000000';
73 $this->mForUpdate
= false;
74 $this->mIsRedirect
= false;
75 $this->mRevIdFetched
= 0;
76 $this->mRedirectUrl
= false;
80 * Note that getContent/loadContent may follow redirects if
81 * not told otherwise, and so may cause a change to mTitle.
84 * @return Return the text of this revision
86 function getContent( $noredir ) {
87 global $wgRequest, $wgUser, $wgOut;
89 # Get variables from query string :P
90 $action = $wgRequest->getText( 'action', 'view' );
91 $section = $wgRequest->getText( 'section' );
92 $preload = $wgRequest->getText( 'preload' );
94 $fname = 'Article::getContent';
95 wfProfileIn( $fname );
97 if ( 0 == $this->getID() ) {
98 if ( 'edit' == $action ) {
99 wfProfileOut( $fname );
101 # If requested, preload some text.
102 $text=$this->getPreloadedText($preload);
104 # We used to put MediaWiki:Newarticletext here if
105 # $text was empty at this point.
106 # This is now shown above the edit box instead.
109 wfProfileOut( $fname );
110 $wgOut->setRobotpolicy( 'noindex,nofollow' );
112 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
113 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
115 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
118 return "<div class='noarticletext'>$ret</div>";
120 $this->loadContent( $noredir );
121 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
122 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
123 $wgUser->isIP($this->mTitle
->getText()) &&
126 wfProfileOut( $fname );
127 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
129 if($action=='edit') {
131 if($section=='new') {
132 wfProfileOut( $fname );
133 $text=$this->getPreloadedText($preload);
137 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
138 # comments to be stripped as well)
139 $rv=$this->getSection($this->mContent
,$section);
140 wfProfileOut( $fname );
144 wfProfileOut( $fname );
145 return $this->mContent
;
151 * Get the contents of a page from its title and remove includeonly tags
153 * TODO FIXME: This is only here because of the inputbox extension and
154 * should be moved there
158 * @param string The title of the page
159 * @return string The contents of the page
161 function getPreloadedText($preload) {
162 if ( $preload === '' )
165 $preloadTitle = Title
::newFromText( $preload );
166 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
167 $rev=Revision
::newFromTitle($preloadTitle);
168 if ( is_object( $rev ) ) {
169 $text = $rev->getText();
170 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
171 // its own mini-parser! -ævar
172 $text = preg_replace( '~</?includeonly>~', '', $text );
181 * This function returns the text of a section, specified by a number ($section).
182 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
183 * the first section before any such heading (section 0).
185 * If a section contains subsections, these are also returned.
187 * @param string $text text to look in
188 * @param integer $section section number
189 * @return string text of the requested section
191 function getSection($text,$section) {
193 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
194 # comments to be stripped as well)
196 $parser=new Parser();
197 $parser->mOutputType
=OT_WIKI
;
198 $parser->mOptions
= new ParserOptions();
199 $striptext=$parser->strip($text, $striparray, true);
201 # now that we can be sure that no pseudo-sections are in the source,
202 # split it up by section
205 '/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
207 PREG_SPLIT_DELIM_CAPTURE
);
211 $headline=$secs[$section*2-1];
212 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
215 # translate wiki heading into level
216 if(strpos($hlevel,'=')!==false) {
217 $hlevel=strlen($hlevel);
220 $rv=$headline. $secs[$section*2];
224 while(!empty($secs[$count*2-1]) && !$break) {
226 $subheadline=$secs[$count*2-1];
227 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
228 $subhlevel=$matches[1];
229 if(strpos($subhlevel,'=')!==false) {
230 $subhlevel=strlen($subhlevel);
232 if($subhlevel > $hlevel) {
233 $rv.=$subheadline.$secs[$count*2];
235 if($subhlevel <= $hlevel) {
242 # reinsert stripped tags
243 $rv=$parser->unstrip($rv,$striparray);
244 $rv=$parser->unstripNoWiki($rv,$striparray);
251 * @return int The oldid of the article that is to be shown, 0 for the
254 function getOldID() {
255 if ( is_null( $this->mOldId
) ) {
256 $this->mOldId
= $this->getOldIDFromRequest();
258 return $this->mOldId
;
262 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
264 * @return int The old id for the request
266 function getOldIDFromRequest() {
268 $this->mRedirectUrl
= false;
269 $oldid = $wgRequest->getVal( 'oldid' );
270 if ( isset( $oldid ) ) {
271 $oldid = intval( $oldid );
272 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
273 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
277 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
279 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
280 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
296 * Load the revision (including text) into this object
298 function loadContent( $noredir = false ) {
299 global $wgOut, $wgRequest;
301 if ( $this->mContentLoaded
) return;
304 $oldid = $this->getOldID();
305 $redirect = $wgRequest->getVal( 'redirect' );
307 $fname = 'Article::loadContent';
309 # Pre-fill content with error message so that if something
310 # fails we'll have something telling us what we intended.
312 $t = $this->mTitle
->getPrefixedText();
314 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no')
315 ||
$wgRequest->getCheck( 'rdfrom' );
316 $this->mOldId
= $oldid;
317 $this->fetchContent( $oldid, $noredir, true );
322 * Fetch a page record with the given conditions
323 * @param Database $dbr
324 * @param array $conditions
327 function pageData( &$dbr, $conditions ) {
340 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
341 $row = $dbr->selectRow( 'page',
344 'Article::pageData' );
345 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
350 * @param Database $dbr
351 * @param Title $title
353 function pageDataFromTitle( &$dbr, $title ) {
354 return $this->pageData( $dbr, array(
355 'page_namespace' => $title->getNamespace(),
356 'page_title' => $title->getDBkey() ) );
360 * @param Database $dbr
363 function pageDataFromId( &$dbr, $id ) {
364 return $this->pageData( $dbr, array( 'page_id' => $id ) );
368 * Set the general counter, title etc data loaded from
371 * @param object $data
374 function loadPageData( $data ) {
375 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
376 $this->mTitle
->mRestrictionsLoaded
= true;
378 $this->mCounter
= $data->page_counter
;
379 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
380 $this->mIsRedirect
= $data->page_is_redirect
;
381 $this->mLatest
= $data->page_latest
;
383 $this->mDataLoaded
= true;
387 * Get text of an article from database
388 * @param int $oldid 0 for whatever the latest revision is
389 * @param bool $noredir Set to false to follow redirects
390 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
393 function fetchContent( $oldid = 0, $noredir = true, $globalTitle = false ) {
394 if ( $this->mContentLoaded
) {
395 return $this->mContent
;
398 $dbr =& $this->getDB();
399 $fname = 'Article::fetchContent';
401 # Pre-fill content with error message so that if something
402 # fails we'll have something telling us what we intended.
403 $t = $this->mTitle
->getPrefixedText();
405 $t .= ',oldid='.$oldid;
407 if( isset( $redirect ) ) {
408 $redirect = ($redirect == 'no') ?
'no' : 'yes';
409 $t .= ',redirect='.$redirect;
411 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
414 $revision = Revision
::newFromId( $oldid );
415 if( is_null( $revision ) ) {
416 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
419 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
421 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
424 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
425 $this->loadPageData( $data );
427 if( !$this->mDataLoaded
) {
428 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
430 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
433 $this->loadPageData( $data );
435 $revision = Revision
::newFromId( $this->mLatest
);
436 if( is_null( $revision ) ) {
437 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
442 # If we got a redirect, follow it (unless we've been told
443 # not to by either the function parameter or the query
444 if ( !$oldid && !$noredir ) {
445 $rt = Title
::newFromRedirect( $revision->getText() );
446 # process if title object is valid and not special:userlogout
447 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
448 # Gotta hand redirects to special pages differently:
449 # Fill the HTTP response "Location" header and ignore
450 # the rest of the page we're on.
451 global $wgDisableHardRedirects;
452 if( $globalTitle && !$wgDisableHardRedirects ) {
454 if ( $rt->getInterwiki() != '' && $rt->isLocal() ) {
455 $source = $this->mTitle
->getFullURL( 'redirect=no' );
456 $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ;
459 if ( $rt->getNamespace() == NS_SPECIAL
) {
460 $wgOut->redirect( $rt->getFullURL() );
464 if( $rt->getInterwiki() == '' ) {
465 $redirData = $this->pageDataFromTitle( $dbr, $rt );
467 $redirRev = Revision
::newFromId( $redirData->page_latest
);
468 if( !is_null( $redirRev ) ) {
469 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
472 $this->loadPageData( $data );
473 $revision = $redirRev;
480 # if the title's different from expected, update...
483 if( !$this->mTitle
->equals( $wgTitle ) ) {
484 $wgTitle = $this->mTitle
;
488 # Back to the business at hand...
489 $this->mContent
= $revision->getText();
491 $this->mUser
= $revision->getUser();
492 $this->mUserText
= $revision->getUserText();
493 $this->mComment
= $revision->getComment();
494 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
496 $this->mRevIdFetched
= $revision->getID();
497 $this->mContentLoaded
= true;
498 $this->mRevision
=& $revision;
500 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
502 return $this->mContent
;
506 * Gets the article text without using so many damn globals
508 * Used by maintenance/importLogs.php
511 * @param bool $noredir Whether to follow redirects
512 * @return mixed the content (string) or false on error
514 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
515 return $this->fetchContent( $oldid, $noredir, false );
519 * Read/write accessor to select FOR UPDATE
523 function forUpdate( $x = NULL ) {
524 return wfSetVar( $this->mForUpdate
, $x );
528 * Get the database which should be used for reads
533 $ret =& wfGetDB( DB_MASTER
);
538 * Get options for all SELECT statements
540 * @param array $options an optional options array which'll be appended to
542 * @return array Options
544 function getSelectOptions( $options = '' ) {
545 if ( $this->mForUpdate
) {
546 if ( is_array( $options ) ) {
547 $options[] = 'FOR UPDATE';
549 $options = 'FOR UPDATE';
556 * @return int Page ID
559 if( $this->mTitle
) {
560 return $this->mTitle
->getArticleID();
567 * @return bool Whether or not the page exists in the database
570 return $this->getId() != 0;
574 * @return int The view count for the page
576 function getCount() {
577 if ( -1 == $this->mCounter
) {
578 $id = $this->getID();
579 $dbr =& wfGetDB( DB_SLAVE
);
580 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
581 'Article::getCount', $this->getSelectOptions() );
583 return $this->mCounter
;
587 * Determine whether a page would be suitable for being counted as an
588 * article in the site_stats table based on the title & its content
590 * @param string $text Text to analyze
593 function isCountable( $text ) {
594 global $wgUseCommaCount;
596 $token = $wgUseCommaCount ?
',' : '[[';
598 $this->mTitle
->getNamespace() == NS_MAIN
599 && ! $this->isRedirect( $text )
600 && in_string( $token, $text );
604 * Tests if the article text represents a redirect
606 * @param string $text
609 function isRedirect( $text = false ) {
610 if ( $text === false ) {
611 $this->loadContent();
612 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
614 $titleObj = Title
::newFromRedirect( $text );
616 return $titleObj !== NULL;
620 * Returns true if the currently-referenced revision is the current edit
621 * to this page (and it exists).
624 function isCurrent() {
625 return $this->exists() &&
626 isset( $this->mRevision
) &&
627 $this->mRevision
->isCurrent();
631 * Loads everything except the text
632 * This isn't necessary for all uses, so it's only done if needed.
635 function loadLastEdit() {
638 if ( -1 != $this->mUser
)
641 # New or non-existent articles have no user information
642 $id = $this->getID();
643 if ( 0 == $id ) return;
645 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
646 if( !is_null( $this->mLastRevision
) ) {
647 $this->mUser
= $this->mLastRevision
->getUser();
648 $this->mUserText
= $this->mLastRevision
->getUserText();
649 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
650 $this->mComment
= $this->mLastRevision
->getComment();
651 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
652 $this->mRevIdFetched
= $this->mLastRevision
->getID();
656 function getTimestamp() {
657 $this->loadLastEdit();
658 return wfTimestamp(TS_MW
, $this->mTimestamp
);
662 $this->loadLastEdit();
666 function getUserText() {
667 $this->loadLastEdit();
668 return $this->mUserText
;
671 function getComment() {
672 $this->loadLastEdit();
673 return $this->mComment
;
676 function getMinorEdit() {
677 $this->loadLastEdit();
678 return $this->mMinorEdit
;
681 function getRevIdFetched() {
682 $this->loadLastEdit();
683 return $this->mRevIdFetched
;
686 function getContributors($limit = 0, $offset = 0) {
687 $fname = 'Article::getContributors';
689 # XXX: this is expensive; cache this info somewhere.
691 $title = $this->mTitle
;
693 $dbr =& wfGetDB( DB_SLAVE
);
694 $revTable = $dbr->tableName( 'revision' );
695 $userTable = $dbr->tableName( 'user' );
696 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
697 $ns = $title->getNamespace();
698 $user = $this->getUser();
699 $pageId = $this->getId();
701 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
702 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
703 WHERE rev_page = $pageId
704 AND rev_user != $user
705 GROUP BY rev_user, rev_user_text, user_real_name
706 ORDER BY timestamp DESC";
708 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
709 $sql .= ' '. $this->getSelectOptions();
711 $res = $dbr->query($sql, $fname);
713 while ( $line = $dbr->fetchObject( $res ) ) {
714 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
717 $dbr->freeResult($res);
722 * This is the default action of the script: just view the page of
726 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
727 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
728 global $wgUseTrackbacks;
729 $sk = $wgUser->getSkin();
731 $fname = 'Article::view';
732 wfProfileIn( $fname );
733 $parserCache =& ParserCache
::singleton();
734 # Get variables from query string
735 $oldid = $this->getOldID();
737 # getOldID may want us to redirect somewhere else
738 if ( $this->mRedirectUrl
) {
739 $wgOut->redirect( $this->mRedirectUrl
);
740 wfProfileOut( $fname );
744 $diff = $wgRequest->getVal( 'diff' );
745 $rcid = $wgRequest->getVal( 'rcid' );
746 $rdfrom = $wgRequest->getVal( 'rdfrom' );
748 $wgOut->setArticleFlag( true );
749 $wgOut->setRobotpolicy( 'index,follow' );
750 # If we got diff and oldid in the query, we want to see a
751 # diff page instead of the article.
753 if ( !is_null( $diff ) ) {
754 require_once( 'DifferenceEngine.php' );
755 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
757 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
758 // DifferenceEngine directly fetched the revision:
759 $this->mRevIdFetched
= $de->mNewid
;
763 # Run view updates for current revision only
764 $this->viewUpdates();
766 wfProfileOut( $fname );
770 if ( empty( $oldid ) && $this->checkTouched() ) {
771 $wgOut->setETag($parserCache->getETag($this, $wgUser));
773 if( $wgOut->checkLastModified( $this->mTouched
) ){
774 wfProfileOut( $fname );
776 } else if ( $this->tryFileCache() ) {
777 # tell wgOut that output is taken care of
779 $this->viewUpdates();
780 wfProfileOut( $fname );
784 # Should the parser cache be used?
785 $pcache = $wgEnableParserCache &&
786 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
789 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
790 if ( $wgUser->getOption( 'stubthreshold' ) ) {
791 wfIncrStats( 'pcache_miss_stub' );
796 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
800 if ( !$outputDone ) {
801 $text = $this->getContent( false ); # May change mTitle by following a redirect
802 if ( $text === false ) {
803 # Failed to load, replace text with error message
804 $t = $this->mTitle
->getPrefixedText();
806 $t .= ',oldid='.$oldid;
808 if( isset( $redirect ) ) {
809 $redirect = ($redirect == 'no') ?
'no' : 'yes';
810 $t .= ',redirect='.$redirect;
812 $text = wfMsg( 'missingarticle', $t );
815 # Another whitelist check in case oldid or redirects are altering the title
816 if ( !$this->mTitle
->userCanRead() ) {
817 $wgOut->loginToUse();
822 # We're looking at an old revision
824 if ( !empty( $oldid ) ) {
825 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
826 $wgOut->setRobotpolicy( 'noindex,follow' );
828 $wasRedirected = false;
829 if ( '' != $this->mRedirectedFrom
) {
830 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
831 $sk = $wgUser->getSkin();
832 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '', 'redirect=no' );
833 $s = wfMsg( 'redirectedfrom', $redir );
834 $wgOut->setSubtitle( $s );
836 // Check the parser cache again, for the target page
838 if( $wgOut->tryParserCache( $this, $wgUser ) ) {
842 $wasRedirected = true;
844 } elseif ( !empty( $rdfrom ) ) {
845 global $wgRedirectSources;
846 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
847 $sk = $wgUser->getSkin();
848 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
849 $s = wfMsg( 'redirectedfrom', $redir );
850 $wgOut->setSubtitle( $s );
851 $wasRedirected = true;
857 * @fixme: this hook doesn't work most of the time, as it doesn't
858 * trigger when the parser cache is used.
860 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
861 $wgOut->setRevisionId( $this->getRevIdFetched() );
862 # wrap user css and user js in pre and don't parse
863 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
865 $this->mTitle
->getNamespace() == NS_USER
&&
866 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
868 $wgOut->addWikiText( wfMsg('clearyourcache'));
869 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
870 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
872 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
873 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
874 if( !$wasRedirected ) {
875 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
877 $targetUrl = $rt->escapeLocalURL();
878 $titleText = htmlspecialchars( $rt->getPrefixedText() );
879 $link = $sk->makeLinkObj( $rt );
881 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
882 '<span class="redirectText">'.$link.'</span>' );
884 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
885 $wgOut->addParserOutputNoText( $parseout );
886 } else if ( $pcache ) {
887 # Display content and save to parser cache
888 $wgOut->addPrimaryWikiText( $text, $this );
890 # Display content, don't attempt to save to parser cache
892 # Don't show section-edit links on old revisions... this way lies madness.
893 if( !$this->isCurrent() ) {
894 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
896 $wgOut->addWikiText( $text );
898 if( !$this->isCurrent() ) {
899 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
903 /* title may have been set from the cache */
904 $t = $wgOut->getPageTitle();
906 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
909 # If we have been passed an &rcid= parameter, we want to give the user a
910 # chance to mark this new article as patrolled.
914 && $wgUser->isLoggedIn()
915 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
918 "<div class='patrollink'>" .
919 wfMsg ( 'markaspatrolledlink',
920 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
927 if ($wgUseTrackbacks)
928 $this->addTrackbacks();
930 $this->viewUpdates();
931 wfProfileOut( $fname );
934 function addTrackbacks() {
935 global $wgOut, $wgUser;
937 $dbr =& wfGetDB(DB_SLAVE
);
939 /* FROM */ 'trackbacks',
940 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
941 /* WHERE */ array('tb_page' => $this->getID())
944 if (!$dbr->numrows($tbs))
948 while ($o = $dbr->fetchObject($tbs)) {
950 if ($wgUser->isSysop()) {
951 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
952 . $o->tb_id
. "&token=" . $wgUser->editToken());
953 $rmvtxt = wfMsg('trackbackremove', $delurl);
955 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
962 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
965 function deletetrackback() {
966 global $wgUser, $wgRequest, $wgOut, $wgTitle;
968 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
969 $wgOut->addWikitext(wfMsg('sessionfailure'));
973 if ((!$wgUser->isAllowed('delete'))) {
974 $wgOut->sysopRequired();
979 $wgOut->readOnlyPage();
983 $db =& wfGetDB(DB_MASTER
);
984 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
985 $wgTitle->invalidateCache();
986 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
992 $wgOut->setArticleBodyOnly(true);
997 global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
999 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ||
! wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
1000 // Invalidate the cache
1001 $this->mTitle
->invalidateCache();
1003 if ( $wgUseSquid ) {
1004 // Commit the transaction before the purge is sent
1005 $dbw = wfGetDB( DB_MASTER
);
1006 $dbw->immediateCommit();
1009 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
1010 $update->doUpdate();
1014 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
1015 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
1016 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
1017 $msg = str_replace( '$1',
1018 "<form method=\"post\" action=\"$action\">\n" .
1019 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
1020 "</form>\n", $msg );
1022 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
1023 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1024 $wgOut->addHTML( $msg );
1029 * Insert a new empty page record for this article.
1030 * This *must* be followed up by creating a revision
1031 * and running $this->updateToLatest( $rev_id );
1032 * or else the record will be left in a funky state.
1033 * Best if all done inside a transaction.
1035 * @param Database $dbw
1036 * @param string $restrictions
1037 * @return int The newly created page_id key
1040 function insertOn( &$dbw, $restrictions = '' ) {
1041 $fname = 'Article::insertOn';
1042 wfProfileIn( $fname );
1044 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1045 $dbw->insert( 'page', array(
1046 'page_id' => $page_id,
1047 'page_namespace' => $this->mTitle
->getNamespace(),
1048 'page_title' => $this->mTitle
->getDBkey(),
1049 'page_counter' => 0,
1050 'page_restrictions' => $restrictions,
1051 'page_is_redirect' => 0, # Will set this shortly...
1053 'page_random' => wfRandom(),
1054 'page_touched' => $dbw->timestamp(),
1055 'page_latest' => 0, # Fill this in shortly...
1056 'page_len' => 0, # Fill this in shortly...
1058 $newid = $dbw->insertId();
1060 $this->mTitle
->resetArticleId( $newid );
1062 wfProfileOut( $fname );
1067 * Update the page record to point to a newly saved revision.
1069 * @param Database $dbw
1070 * @param Revision $revision For ID number, and text used to set
1071 length and redirect status fields
1072 * @param int $lastRevision If given, will not overwrite the page field
1073 * when different from the currently set value.
1074 * Giving 0 indicates the new page flag should
1076 * @return bool true on success, false on failure
1079 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1080 $fname = 'Article::updateToRevision';
1081 wfProfileIn( $fname );
1083 $conditions = array( 'page_id' => $this->getId() );
1084 if( !is_null( $lastRevision ) ) {
1085 # An extra check against threads stepping on each other
1086 $conditions['page_latest'] = $lastRevision;
1089 $text = $revision->getText();
1090 $dbw->update( 'page',
1092 'page_latest' => $revision->getId(),
1093 'page_touched' => $dbw->timestamp(),
1094 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1095 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1096 'page_len' => strlen( $text ),
1101 wfProfileOut( $fname );
1102 return ( $dbw->affectedRows() != 0 );
1106 * If the given revision is newer than the currently set page_latest,
1107 * update the page record. Otherwise, do nothing.
1109 * @param Database $dbw
1110 * @param Revision $revision
1112 function updateIfNewerOn( &$dbw, $revision ) {
1113 $fname = 'Article::updateIfNewerOn';
1114 wfProfileIn( $fname );
1116 $row = $dbw->selectRow(
1117 array( 'revision', 'page' ),
1118 array( 'rev_id', 'rev_timestamp' ),
1120 'page_id' => $this->getId(),
1121 'page_latest=rev_id' ),
1124 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1125 wfProfileOut( $fname );
1128 $prev = $row->rev_id
;
1130 # No or missing previous revision; mark the page as new
1134 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1135 wfProfileOut( $fname );
1140 * Theoretically we could defer these whole insert and update
1141 * functions for after display, but that's taking a big leap
1142 * of faith, and we want to be able to report database
1143 * errors at some point.
1146 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1147 global $wgOut, $wgUser, $wgUseSquid;
1149 $fname = 'Article::insertNewArticle';
1150 wfProfileIn( $fname );
1152 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1153 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1154 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1155 wfProfileOut( $fname );
1159 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1160 $this->mTotalAdjustment
= 1;
1162 $ns = $this->mTitle
->getNamespace();
1163 $ttl = $this->mTitle
->getDBkey();
1165 # If this is a comment, add the summary as headline
1166 if($comment && $summary!="") {
1167 $text="== {$summary} ==\n\n".$text;
1169 $text = $this->preSaveTransform( $text );
1171 /* Silently ignore minoredit if not allowed */
1172 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1173 $now = wfTimestampNow();
1175 $dbw =& wfGetDB( DB_MASTER
);
1177 # Add the page record; stake our claim on this title!
1178 $newid = $this->insertOn( $dbw );
1180 # Save the revision text...
1181 $revision = new Revision( array(
1183 'comment' => $summary,
1184 'minor_edit' => $isminor,
1187 $revisionId = $revision->insertOn( $dbw );
1189 $this->mTitle
->resetArticleID( $newid );
1191 # Update the page record with revision data
1192 $this->updateRevisionOn( $dbw, $revision, 0 );
1194 Article
::onArticleCreate( $this->mTitle
);
1196 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1197 '', strlen( $text ), $revisionId );
1201 if(!$this->mTitle
->userIsWatching()) $this->watch();
1203 if ( $this->mTitle
->userIsWatching() ) {
1208 # The talk page isn't in the regular link tables, so we need to update manually:
1209 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1210 $dbw->update( 'page',
1211 array( 'page_touched' => $dbw->timestamp($now) ),
1212 array( 'page_namespace' => $talkns,
1213 'page_title' => $ttl ),
1216 # standard deferred updates
1217 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1219 $oldid = 0; # new article
1220 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1222 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1224 $watchthis, NULL ) );
1225 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1227 $watchthis, NULL ) );
1228 wfProfileOut( $fname );
1231 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1232 $this->replaceSection( $section, $text, $summary, $edittime );
1236 * @return string Complete article text, or null if error
1238 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1239 $fname = 'Article::replaceSection';
1240 wfProfileIn( $fname );
1242 if ($section != '') {
1243 if( is_null( $edittime ) ) {
1244 $rev = Revision
::newFromTitle( $this->mTitle
);
1246 $dbw =& wfGetDB( DB_MASTER
);
1247 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1249 if( is_null( $rev ) ) {
1250 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1251 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1254 $oldtext = $rev->getText();
1256 if($section=='new') {
1257 if($summary) $subject="== {$summary} ==\n\n";
1258 $text=$oldtext."\n\n".$subject.$text;
1261 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1262 # comments to be stripped as well)
1263 $striparray=array();
1264 $parser=new Parser();
1265 $parser->mOutputType
=OT_WIKI
;
1266 $parser->mOptions
= new ParserOptions();
1267 $oldtext=$parser->strip($oldtext, $striparray, true);
1269 # now that we can be sure that no pseudo-sections are in the source,
1271 # Unfortunately we can't simply do a preg_replace because that might
1272 # replace the wrong section, so we have to use the section counter instead
1273 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
1274 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1275 $secs[$section*2]=$text."\n\n"; // replace with edited
1277 # section 0 is top (intro) section
1280 # headline of old section - we need to go through this section
1281 # to determine if there are any subsections that now need to
1282 # be erased, as the mother section has been replaced with
1283 # the text of all subsections.
1284 $headline=$secs[$section*2-1];
1285 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
1286 $hlevel=$matches[1];
1288 # determine headline level for wikimarkup headings
1289 if(strpos($hlevel,'=')!==false) {
1290 $hlevel=strlen($hlevel);
1293 $secs[$section*2-1]=''; // erase old headline
1296 while(!empty($secs[$count*2-1]) && !$break) {
1298 $subheadline=$secs[$count*2-1];
1300 '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
1301 $subhlevel=$matches[1];
1302 if(strpos($subhlevel,'=')!==false) {
1303 $subhlevel=strlen($subhlevel);
1305 if($subhlevel > $hlevel) {
1306 // erase old subsections
1307 $secs[$count*2-1]='';
1310 if($subhlevel <= $hlevel) {
1318 $text=join('',$secs);
1319 # reinsert the stuff that we stripped out earlier
1320 $text=$parser->unstrip($text,$striparray);
1321 $text=$parser->unstripNoWiki($text,$striparray);
1325 wfProfileOut( $fname );
1330 * Change an existing article. Puts the previous version back into the old table, updates RC
1331 * and all necessary caches, mostly via the deferred update array.
1333 * It is possible to call this function from a command-line script, but note that you should
1334 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1336 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1337 global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
1338 global $wgPostCommitUpdateList, $wgUseFileCache;
1340 $fname = 'Article::updateArticle';
1341 wfProfileIn( $fname );
1344 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1346 &$watchthis, &$sectionanchor ) ) ) {
1347 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1348 wfProfileOut( $fname );
1352 $isminor = $minor && $wgUser->isAllowed('minoredit');
1353 $redir = (int)$this->isRedirect( $text );
1355 $text = $this->preSaveTransform( $text );
1356 $dbw =& wfGetDB( DB_MASTER
);
1357 $now = wfTimestampNow();
1359 # Update article, but only if changed.
1361 # It's important that we either rollback or complete, otherwise an attacker could
1362 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1363 # could conceivably have the same effect, especially if cur is locked for long periods.
1364 if( !$wgDBtransactions ) {
1365 $userAbort = ignore_user_abort( true );
1368 $oldtext = $this->getContent( true );
1369 $oldsize = strlen( $oldtext );
1370 $newsize = strlen( $text );
1374 if ( 0 != strcmp( $text, $oldtext ) ) {
1375 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1376 - (int)$this->isCountable( $oldtext );
1377 $this->mTotalAdjustment
= 0;
1378 $now = wfTimestampNow();
1380 $lastRevision = $dbw->selectField(
1381 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1383 $revision = new Revision( array(
1384 'page' => $this->getId(),
1385 'comment' => $summary,
1386 'minor_edit' => $isminor,
1390 $dbw->immediateCommit();
1392 $revisionId = $revision->insertOn( $dbw );
1395 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1398 /* Belated edit conflict! Run away!! */
1402 # Update recentchanges and purge cache and whatnot
1403 $bot = (int)($wgUser->isBot() ||
$forceBot);
1404 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1405 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1409 // Update caches outside the main transaction
1410 Article
::onArticleEdit( $this->mTitle
);
1413 // Keep the same revision ID, but do some updates on it
1414 $revisionId = $this->getRevIdFetched();
1417 if( !$wgDBtransactions ) {
1418 ignore_user_abort( $userAbort );
1423 if (!$this->mTitle
->userIsWatching()) {
1424 $dbw->immediateCommit();
1430 if ( $this->mTitle
->userIsWatching() ) {
1431 $dbw->immediateCommit();
1437 # standard deferred updates
1438 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1442 # Invalidate caches of all articles using this article as a template
1444 # Template namespace
1445 # Purge all articles linking here
1446 $titles = $this->mTitle
->getTemplateLinksTo();
1447 Title
::touchArray( $titles );
1448 if ( $wgUseSquid ) {
1449 foreach ( $titles as $title ) {
1450 $urls[] = $title->getInternalURL();
1455 if ( $wgUseSquid ) {
1456 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1457 $u = new SquidUpdate( $urls );
1458 array_push( $wgPostCommitUpdateList, $u );
1462 if ( $wgUseFileCache ) {
1463 $cm = new CacheManager($this->mTitle
);
1464 @unlink
($cm->fileCacheName());
1467 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1469 wfRunHooks( 'ArticleSaveComplete',
1470 array( &$this, &$wgUser, $text,
1472 $watchthis, $sectionanchor ) );
1473 wfProfileOut( $fname );
1478 * After we've either updated or inserted the article, update
1479 * the link tables and redirect to the new page.
1481 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1482 global $wgOut, $wgUser;
1483 global $wgUseEnotif;
1485 $fname = 'Article::showArticle';
1486 wfProfileIn( $fname );
1488 # Output the redirect
1489 if( $this->isRedirect( $text ) )
1493 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1495 wfProfileOut( $fname );
1499 * Mark this particular edit as patrolled
1501 function markpatrolled() {
1502 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1503 $wgOut->setRobotpolicy( 'noindex,follow' );
1505 if ( !$wgUseRCPatrol )
1507 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1510 if ( $wgUser->isAnon() )
1512 $wgOut->loginToUse();
1515 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1517 $wgOut->sysopRequired();
1520 $rcid = $wgRequest->getVal( 'rcid' );
1521 if ( !is_null ( $rcid ) )
1523 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) ) ) {
1524 RecentChange
::markPatrolled( $rcid );
1525 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) );
1526 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1527 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1529 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1530 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1534 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1539 * Add this page to $wgUser's watchlist
1544 global $wgUser, $wgOut;
1546 if ( $wgUser->isAnon() ) {
1547 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1550 if ( wfReadOnly() ) {
1551 $wgOut->readOnlyPage();
1555 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1557 $wgUser->addWatch( $this->mTitle
);
1558 $wgUser->saveSettings();
1560 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1562 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1563 $wgOut->setRobotpolicy( 'noindex,follow' );
1565 $link = $this->mTitle
->getPrefixedText();
1566 $text = wfMsg( 'addedwatchtext', $link );
1567 $wgOut->addWikiText( $text );
1570 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1574 * Stop watching a page
1577 function unwatch() {
1579 global $wgUser, $wgOut;
1581 if ( $wgUser->isAnon() ) {
1582 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1585 if ( wfReadOnly() ) {
1586 $wgOut->readOnlyPage();
1590 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1592 $wgUser->removeWatch( $this->mTitle
);
1593 $wgUser->saveSettings();
1595 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1597 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1598 $wgOut->setRobotpolicy( 'noindex,follow' );
1600 $link = $this->mTitle
->getPrefixedText();
1601 $text = wfMsg( 'removedwatchtext', $link );
1602 $wgOut->addWikiText( $text );
1605 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1609 * action=protect handler
1611 function protect() {
1612 require_once 'ProtectionForm.php';
1613 $form = new ProtectionForm( $this );
1618 * action=unprotect handler (alias)
1620 function unprotect() {
1625 * Update the article's restriction field, and leave a log entry.
1627 * @param array $limit set of restriction keys
1628 * @param string $reason
1629 * @return bool true on success
1631 function updateRestrictions( $limit = array(), $reason = '' ) {
1632 global $wgUser, $wgOut, $wgRequest;
1634 if ( !$wgUser->isAllowed( 'protect' ) ) {
1638 if( wfReadOnly() ) {
1642 $id = $this->mTitle
->getArticleID();
1647 $flat = Article
::flattenRestrictions( $limit );
1648 $protecting = ($flat != '');
1650 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser,
1651 $limit, $reason ) ) ) {
1653 $dbw =& wfGetDB( DB_MASTER
);
1654 $dbw->update( 'page',
1656 'page_touched' => $dbw->timestamp(),
1657 'page_restrictions' => $flat
1658 ), array( /* WHERE */
1660 ), 'Article::protect'
1663 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser,
1664 $limit, $reason ) );
1666 $log = new LogPage( 'protect' );
1668 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$flat]" ) );
1670 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1677 * Take an array of page restrictions and flatten it to a string
1678 * suitable for insertion into the page_restrictions field.
1679 * @param array $limit
1683 function flattenRestrictions( $limit ) {
1684 if( !is_array( $limit ) ) {
1685 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1688 foreach( $limit as $action => $restrictions ) {
1689 if( $restrictions != '' ) {
1690 $bits[] = "$action=$restrictions";
1693 return implode( ':', $bits );
1697 * UI entry point for page deletion
1700 global $wgUser, $wgOut, $wgRequest;
1701 $fname = 'Article::delete';
1702 $confirm = $wgRequest->wasPosted() &&
1703 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1704 $reason = $wgRequest->getText( 'wpReason' );
1706 # This code desperately needs to be totally rewritten
1709 if( $wgUser->isAllowed( 'delete' ) ) {
1710 if( $wgUser->isBlocked() ) {
1711 $wgOut->blockedPage();
1715 $wgOut->sysopRequired();
1719 if( wfReadOnly() ) {
1720 $wgOut->readOnlyPage();
1724 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1726 # Better double-check that it hasn't been deleted yet!
1727 $dbw =& wfGetDB( DB_MASTER
);
1728 $conds = $this->mTitle
->pageCond();
1729 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1730 if ( $latest === false ) {
1731 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1736 $this->doDelete( $reason );
1740 # determine whether this page has earlier revisions
1741 # and insert a warning if it does
1743 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1745 if( count( $authors ) > 1 && !$confirm ) {
1746 $skin=$wgUser->getSkin();
1747 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1748 $wgOut->addHTML( $skin->historyLink() .'</b>');
1751 # If a single user is responsible for all revisions, find out who they are
1752 if ( count( $authors ) == $maxRevisions ) {
1753 // Query bailed out, too many revisions to find out if they're all the same
1754 $authorOfAll = false;
1756 $authorOfAll = reset( $authors );
1757 foreach ( $authors as $author ) {
1758 if ( $authorOfAll != $author ) {
1759 $authorOfAll = false;
1764 # Fetch article text
1765 $rev = Revision
::newFromTitle( $this->mTitle
);
1767 if( !is_null( $rev ) ) {
1768 # if this is a mini-text, we can paste part of it into the deletion reason
1769 $text = $rev->getText();
1771 #if this is empty, an earlier revision may contain "useful" text
1774 $prev = $rev->getPrevious();
1776 $text = $prev->getText();
1781 $length = strlen( $text );
1783 # this should not happen, since it is not possible to store an empty, new
1784 # page. Let's insert a standard text in case it does, though
1785 if( $length == 0 && $reason === '' ) {
1786 $reason = wfMsgForContent( 'exblank' );
1789 if( $length < 500 && $reason === '' ) {
1790 # comment field=255, let's grep the first 150 to have some user
1793 $text = $wgContLang->truncate( $text, 150, '...' );
1795 # let's strip out newlines
1796 $text = preg_replace( "/[\n\r]/", '', $text );
1799 if( $authorOfAll === false ) {
1800 $reason = wfMsgForContent( 'excontent', $text );
1802 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1805 $reason = wfMsgForContent( 'exbeforeblank', $text );
1810 return $this->confirmDelete( '', $reason );
1814 * Get the last N authors
1815 * @param int $num Number of revisions to get
1816 * @param string $revLatest The latest rev_id, selected from the master (optional)
1817 * @return array Array of authors, duplicates not removed
1819 function getLastNAuthors( $num, $revLatest = 0 ) {
1820 $fname = 'Article::getLastNAuthors';
1821 wfProfileIn( $fname );
1823 // First try the slave
1824 // If that doesn't have the latest revision, try the master
1826 $db =& wfGetDB( DB_SLAVE
);
1828 $res = $db->select( array( 'page', 'revision' ),
1829 array( 'rev_id', 'rev_user_text' ),
1831 'page_namespace' => $this->mTitle
->getNamespace(),
1832 'page_title' => $this->mTitle
->getDBkey(),
1833 'rev_page = page_id'
1834 ), $fname, $this->getSelectOptions( array(
1835 'ORDER BY' => 'rev_timestamp DESC',
1840 wfProfileOut( $fname );
1843 $row = $db->fetchObject( $res );
1844 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1845 $db =& wfGetDB( DB_MASTER
);
1850 } while ( $continue );
1852 $authors = array( $row->rev_user_text
);
1853 while ( $row = $db->fetchObject( $res ) ) {
1854 $authors[] = $row->rev_user_text
;
1856 wfProfileOut( $fname );
1861 * Output deletion confirmation dialog
1863 function confirmDelete( $par, $reason ) {
1864 global $wgOut, $wgUser;
1866 wfDebug( "Article::confirmDelete\n" );
1868 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1869 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1870 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1871 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1873 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1875 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1876 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1877 $token = htmlspecialchars( $wgUser->editToken() );
1880 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1884 <label for='wpReason'>{$delcom}:</label>
1887 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1893 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1897 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1900 $wgOut->returnToMain( false );
1905 * Perform a deletion and output success or failure messages
1907 function doDelete( $reason ) {
1908 global $wgOut, $wgUser, $wgContLang;
1909 $fname = 'Article::doDelete';
1910 wfDebug( $fname."\n" );
1912 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1913 if ( $this->doDeleteArticle( $reason ) ) {
1914 $deleted = $this->mTitle
->getPrefixedText();
1916 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1917 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1919 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1920 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1922 $wgOut->addWikiText( $text );
1923 $wgOut->returnToMain( false );
1924 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1926 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1932 * Back-end article deletion
1933 * Deletes the article with database consistency, writes logs, purges caches
1936 function doDeleteArticle( $reason ) {
1937 global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
1938 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1940 $fname = 'Article::doDeleteArticle';
1941 wfDebug( $fname."\n" );
1943 $dbw =& wfGetDB( DB_MASTER
);
1944 $ns = $this->mTitle
->getNamespace();
1945 $t = $this->mTitle
->getDBkey();
1946 $id = $this->mTitle
->getArticleID();
1948 if ( $t == '' ||
$id == 0 ) {
1952 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent( true ) ), -1 );
1953 array_push( $wgDeferredUpdateList, $u );
1955 $linksTo = $this->mTitle
->getLinksTo();
1958 if ( $wgUseSquid ) {
1960 $this->mTitle
->getInternalURL(),
1961 $this->mTitle
->getInternalURL( 'history' )
1964 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1965 array_push( $wgPostCommitUpdateList, $u );
1969 # Client and file cache invalidation
1970 Title
::touchArray( $linksTo );
1973 // For now, shunt the revision data into the archive table.
1974 // Text is *not* removed from the text table; bulk storage
1975 // is left intact to avoid breaking block-compression or
1976 // immutable storage schemes.
1978 // For backwards compatibility, note that some older archive
1979 // table entries will have ar_text and ar_flags fields still.
1981 // In the future, we may keep revisions and mark them with
1982 // the rev_deleted field, which is reserved for this purpose.
1983 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1985 'ar_namespace' => 'page_namespace',
1986 'ar_title' => 'page_title',
1987 'ar_comment' => 'rev_comment',
1988 'ar_user' => 'rev_user',
1989 'ar_user_text' => 'rev_user_text',
1990 'ar_timestamp' => 'rev_timestamp',
1991 'ar_minor_edit' => 'rev_minor_edit',
1992 'ar_rev_id' => 'rev_id',
1993 'ar_text_id' => 'rev_text_id',
1996 'page_id = rev_page'
2000 # Now that it's safely backed up, delete it
2001 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
2002 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
2004 if ($wgUseTrackbacks)
2005 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
2007 # Clean up recentchanges entries...
2008 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
2010 # Finally, clean up the link tables
2011 $t = $this->mTitle
->getPrefixedDBkey();
2013 Article
::onArticleDelete( $this->mTitle
);
2015 # Delete outgoing links
2016 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2017 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2018 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2021 $log = new LogPage( 'delete' );
2022 $log->addEntry( 'delete', $this->mTitle
, $reason );
2024 # Clear the cached article id so the interface doesn't act like we exist
2025 $this->mTitle
->resetArticleID( 0 );
2026 $this->mTitle
->mArticleID
= 0;
2031 * Revert a modification
2033 function rollback() {
2034 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2035 $fname = 'Article::rollback';
2037 if( $wgUser->isAllowed( 'rollback' ) ) {
2038 if( $wgUser->isBlocked() ) {
2039 $wgOut->blockedPage();
2043 $wgOut->sysopRequired();
2047 if ( wfReadOnly() ) {
2048 $wgOut->readOnlyPage( $this->getContent( true ) );
2051 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2052 array( $this->mTitle
->getPrefixedText(),
2053 $wgRequest->getVal( 'from' ) ) ) ) {
2054 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2055 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2058 $dbw =& wfGetDB( DB_MASTER
);
2060 # Enhanced rollback, marks edits rc_bot=1
2061 $bot = $wgRequest->getBool( 'bot' );
2063 # Replace all this user's current edits with the next one down
2064 $tt = $this->mTitle
->getDBKey();
2065 $n = $this->mTitle
->getNamespace();
2067 # Get the last editor, lock table exclusively
2069 $current = Revision
::newFromTitle( $this->mTitle
);
2070 if( is_null( $current ) ) {
2071 # Something wrong... no page?
2073 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2077 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2078 if( $from != $current->getUserText() ) {
2079 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2080 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2081 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2082 htmlspecialchars( $from ),
2083 htmlspecialchars( $current->getUserText() ) ) );
2084 if( $current->getComment() != '') {
2086 wfMsg( 'editcomment',
2087 htmlspecialchars( $current->getComment() ) ) );
2092 # Get the last edit not by this guy
2093 $user = intval( $current->getUser() );
2094 $user_text = $dbw->addQuotes( $current->getUserText() );
2095 $s = $dbw->selectRow( 'revision',
2096 array( 'rev_id', 'rev_timestamp' ),
2098 'rev_page' => $current->getPage(),
2099 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2102 'USE INDEX' => 'page_timestamp',
2103 'ORDER BY' => 'rev_timestamp DESC' )
2105 if( $s === false ) {
2108 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2109 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2115 # Mark all reverted edits as bot
2118 if ( $wgUseRCPatrol ) {
2119 # Mark all reverted edits as patrolled
2120 $set['rc_patrolled'] = 1;
2124 $dbw->update( 'recentchanges', $set,
2126 'rc_cur_id' => $current->getPage(),
2127 'rc_user_text' => $current->getUserText(),
2128 "rc_timestamp > '{$s->rev_timestamp}'",
2133 # Get the edit summary
2134 $target = Revision
::newFromId( $s->rev_id
);
2135 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2136 $newComment = $wgRequest->getText( 'summary', $newComment );
2139 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2140 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2141 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2143 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2144 Article
::onArticleEdit( $this->mTitle
);
2147 $wgOut->returnToMain( false );
2152 * Do standard deferred updates after page view
2155 function viewUpdates() {
2156 global $wgDeferredUpdateList;
2158 if ( 0 != $this->getID() ) {
2159 global $wgDisableCounters;
2160 if( !$wgDisableCounters ) {
2161 Article
::incViewCount( $this->getID() );
2162 $u = new SiteStatsUpdate( 1, 0, 0 );
2163 array_push( $wgDeferredUpdateList, $u );
2167 # Update newtalk / watchlist notification status
2169 $wgUser->clearNotification( $this->mTitle
);
2173 * Do standard deferred updates after page edit.
2174 * Every 1000th edit, prune the recent changes table.
2176 * @param string $text
2178 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2179 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2181 $fname = 'Article::editUpdates';
2182 wfProfileIn( $fname );
2185 $options = new ParserOptions
;
2186 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2188 # Save it to the parser cache
2189 $parserCache =& ParserCache
::singleton();
2190 $parserCache->save( $poutput, $this, $wgUser );
2192 # Update the links tables
2193 $u = new LinksUpdate( $this->mTitle
, $poutput );
2196 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2198 if ( 0 == mt_rand( 0, 999 ) ) {
2199 # Periodically flush old entries from the recentchanges table.
2202 $dbw =& wfGetDB( DB_MASTER
);
2203 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2204 $recentchanges = $dbw->tableName( 'recentchanges' );
2205 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2206 $dbw->query( $sql );
2210 $id = $this->getID();
2211 $title = $this->mTitle
->getPrefixedDBkey();
2212 $shortTitle = $this->mTitle
->getDBkey();
2215 wfProfileOut( $fname );
2219 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2220 array_push( $wgDeferredUpdateList, $u );
2221 $u = new SearchUpdate( $id, $title, $text );
2222 array_push( $wgDeferredUpdateList, $u );
2224 # If this is another user's talk page, update newtalk
2226 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2227 $other = User
::newFromName( $shortTitle );
2228 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2229 // An anonymous user
2230 $other = new User();
2231 $other->setName( $shortTitle );
2234 $other->setNewtalk( true );
2238 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2239 $wgMessageCache->replace( $shortTitle, $text );
2242 wfProfileOut( $fname );
2246 * @todo document this function
2248 * @param string $oldid Revision ID of this article revision
2250 function setOldSubtitle( $oldid=0 ) {
2251 global $wgLang, $wgOut, $wgUser;
2253 $current = ( $oldid == $this->mLatest
);
2254 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2255 $sk = $wgUser->getSkin();
2257 ?
wfMsg( 'currentrevisionlink' )
2258 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2259 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2260 $nextlink = $current
2261 ?
wfMsg( 'nextrevision' )
2262 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2263 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2264 $wgOut->setSubtitle( $r );
2268 * This function is called right before saving the wikitext,
2269 * so we can do things like signatures and links-in-context.
2271 * @param string $text
2273 function preSaveTransform( $text ) {
2274 global $wgParser, $wgUser;
2275 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2278 /* Caching functions */
2281 * checkLastModified returns true if it has taken care of all
2282 * output to the client that is necessary for this request.
2283 * (that is, it has sent a cached version of the page)
2285 function tryFileCache() {
2286 static $called = false;
2288 wfDebug( " tryFileCache() -- called twice!?\n" );
2292 if($this->isFileCacheable()) {
2293 $touched = $this->mTouched
;
2294 $cache = new CacheManager( $this->mTitle
);
2295 if($cache->isFileCacheGood( $touched )) {
2297 wfDebug( " tryFileCache() - about to load\n" );
2298 $cache->loadFromFileCache();
2301 wfDebug( " tryFileCache() - starting buffer\n" );
2302 ob_start( array(&$cache, 'saveToFileCache' ) );
2305 wfDebug( " tryFileCache() - not cacheable\n" );
2310 * Check if the page can be cached
2313 function isFileCacheable() {
2314 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2315 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2317 return $wgUseFileCache
2318 and (!$wgShowIPinHeader)
2319 and ($this->getID() != 0)
2320 and ($wgUser->isAnon())
2321 and (!$wgUser->getNewtalk())
2322 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2323 and (empty( $action ) ||
$action == 'view')
2324 and (!isset($oldid))
2326 and (!isset($redirect))
2327 and (!isset($printable))
2328 and (!$this->mRedirectedFrom
);
2332 * Loads page_touched and returns a value indicating if it should be used
2335 function checkTouched() {
2336 $fname = 'Article::checkTouched';
2337 if( !$this->mDataLoaded
) {
2338 $dbr =& $this->getDB();
2339 $data = $this->pageDataFromId( $dbr, $this->getId() );
2341 $this->loadPageData( $data );
2344 return !$this->mIsRedirect
;
2348 * Get the page_touched field
2350 function getTouched() {
2351 # Ensure that page data has been loaded
2352 if( !$this->mDataLoaded
) {
2353 $dbr =& $this->getDB();
2354 $data = $this->pageDataFromId( $dbr, $this->getId() );
2356 $this->loadPageData( $data );
2359 return $this->mTouched
;
2363 * Edit an article without doing all that other stuff
2364 * The article must already exist; link tables etc
2365 * are not updated, caches are not flushed.
2367 * @param string $text text submitted
2368 * @param string $comment comment submitted
2369 * @param bool $minor whereas it's a minor modification
2371 function quickEdit( $text, $comment = '', $minor = 0 ) {
2372 $fname = 'Article::quickEdit';
2373 wfProfileIn( $fname );
2375 $dbw =& wfGetDB( DB_MASTER
);
2377 $revision = new Revision( array(
2378 'page' => $this->getId(),
2380 'comment' => $comment,
2381 'minor_edit' => $minor ?
1 : 0,
2383 $revisionId = $revision->insertOn( $dbw );
2384 $this->updateRevisionOn( $dbw, $revision );
2387 wfProfileOut( $fname );
2391 * Used to increment the view counter
2394 * @param integer $id article id
2396 function incViewCount( $id ) {
2397 $id = intval( $id );
2398 global $wgHitcounterUpdateFreq;
2400 $dbw =& wfGetDB( DB_MASTER
);
2401 $pageTable = $dbw->tableName( 'page' );
2402 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2403 $acchitsTable = $dbw->tableName( 'acchits' );
2405 if( $wgHitcounterUpdateFreq <= 1 ){ //
2406 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2410 # Not important enough to warrant an error page in case of failure
2411 $oldignore = $dbw->ignoreErrors( true );
2413 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2415 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2416 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2417 # Most of the time (or on SQL errors), skip row count check
2418 $dbw->ignoreErrors( $oldignore );
2422 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2423 $row = $dbw->fetchObject( $res );
2424 $rown = intval( $row->n
);
2425 if( $rown >= $wgHitcounterUpdateFreq ){
2426 wfProfileIn( 'Article::incViewCount-collect' );
2427 $old_user_abort = ignore_user_abort( true );
2429 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2430 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2431 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2433 $dbw->query("DELETE FROM $hitcounterTable");
2434 $dbw->query('UNLOCK TABLES');
2435 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2436 'WHERE page_id = hc_id');
2437 $dbw->query("DROP TABLE $acchitsTable");
2439 ignore_user_abort( $old_user_abort );
2440 wfProfileOut( 'Article::incViewCount-collect' );
2442 $dbw->ignoreErrors( $oldignore );
2446 * The onArticle*() functions are supposed to be a kind of hooks
2447 * which should be called whenever any of the specified actions
2450 * This is a good place to put code to clear caches, for instance.
2452 * This is called on page move and undelete, as well as edit
2454 * @param $title_obj a title object
2457 function onArticleCreate($title_obj) {
2458 global $wgUseSquid, $wgPostCommitUpdateList;
2460 $title_obj->touchLinks();
2461 $titles = $title_obj->getLinksTo();
2464 if ( $wgUseSquid ) {
2465 $urls = $title_obj->getSquidURLs();
2466 foreach ( $titles as $linkTitle ) {
2467 $urls[] = $linkTitle->getInternalURL();
2469 $u = new SquidUpdate( $urls );
2470 array_push( $wgPostCommitUpdateList, $u );
2474 function onArticleDelete( $title ) {
2475 global $wgMessageCache;
2477 $title->touchLinks();
2479 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2480 $wgMessageCache->replace( $title->getDBkey(), false );
2485 * Purge caches on page update etc
2487 function onArticleEdit( $title ) {
2488 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2492 // Template namespace? Purge all articles linking here.
2493 // FIXME: When a templatelinks table arrives, use it for all includes.
2494 if ( $title->getNamespace() == NS_TEMPLATE
) {
2495 $titles = $title->getLinksTo();
2496 Title
::touchArray( $titles );
2497 if ( $wgUseSquid ) {
2498 foreach ( $titles as $link ) {
2499 $urls[] = $link->getInternalURL();
2505 if ( $wgUseSquid ) {
2506 $urls = array_merge( $urls, $title->getSquidURLs() );
2507 $u = new SquidUpdate( $urls );
2508 array_push( $wgPostCommitUpdateList, $u );
2512 if ( $wgUseFileCache ) {
2513 $cm = new CacheManager( $title );
2514 @unlink
( $cm->fileCacheName() );
2521 * Info about this page
2522 * Called for ?action=info when $wgAllowPageInfo is on.
2527 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2528 $fname = 'Article::info';
2530 if ( !$wgAllowPageInfo ) {
2531 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2535 $page = $this->mTitle
->getSubjectPage();
2537 $wgOut->setPagetitle( $page->getPrefixedText() );
2538 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2540 # first, see if the page exists at all.
2541 $exists = $page->getArticleId() != 0;
2543 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2544 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2546 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2549 $dbr =& wfGetDB( DB_SLAVE
);
2551 'wl_title' => $page->getDBkey(),
2552 'wl_namespace' => $page->getNamespace() );
2553 $numwatchers = $dbr->selectField(
2558 $this->getSelectOptions() );
2560 $pageInfo = $this->pageCountInfo( $page );
2561 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2563 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2564 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2566 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2568 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2570 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2572 $wgOut->addHTML( '</ul>' );
2578 * Return the total number of edits and number of unique editors
2579 * on a given page. If page does not exist, returns false.
2581 * @param Title $title
2585 function pageCountInfo( $title ) {
2586 $id = $title->getArticleId();
2591 $dbr =& wfGetDB( DB_SLAVE
);
2593 $rev_clause = array( 'rev_page' => $id );
2594 $fname = 'Article::pageCountInfo';
2596 $edits = $dbr->selectField(
2601 $this->getSelectOptions() );
2603 $authors = $dbr->selectField(
2605 'COUNT(DISTINCT rev_user_text)',
2608 $this->getSelectOptions() );
2610 return array( 'edits' => $edits, 'authors' => $authors );
2614 * Return a list of templates used by this article.
2615 * Uses the templatelinks table
2617 * @return array Array of Title objects
2619 function getUsedTemplates() {
2621 $id = $this->mTitle
->getArticleID();
2623 $dbr =& wfGetDB( DB_SLAVE
);
2624 $res = $dbr->select( array( 'templatelinks' ),
2625 array( 'tl_namespace', 'tl_title' ),
2626 array( 'tl_from' => $id ),
2627 'Article:getUsedTemplates' );
2628 if ( false !== $res ) {
2629 if ( $dbr->numRows( $res ) ) {
2630 while ( $row = $dbr->fetchObject( $res ) ) {
2631 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2635 $dbr->freeResult( $res );