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();
94 } elseif( $rt->exists() ) {
95 // Internal redirects can be handled relatively gracefully.
96 // We may have to change to another Article subclass, though.
102 // No or invalid redirect
107 * get the title object of the article
109 function getTitle() {
110 return $this->mTitle
;
118 $this->mDataLoaded
= false;
119 $this->mContentLoaded
= false;
121 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
122 $this->mRedirectedFrom
= null; # Title object if set
124 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
125 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
126 $this->mTouched
= '19700101000000';
127 $this->mForUpdate
= false;
128 $this->mIsRedirect
= false;
129 $this->mRevIdFetched
= 0;
130 $this->mRedirectUrl
= false;
134 * Note that getContent/loadContent do not follow redirects anymore.
135 * If you need to fetch redirectable content easily, try
136 * the shortcut in Article::followContent()
138 * @fixme There are still side-effects in this!
139 * In general, you should use the Revision class, not Article,
140 * to fetch text for purposes other than page views.
142 * @return Return the text of this revision
144 function getContent() {
145 global $wgRequest, $wgUser, $wgOut;
147 # Get variables from query string :P
148 $action = $wgRequest->getText( 'action', 'view' );
149 $section = $wgRequest->getText( 'section' );
150 $preload = $wgRequest->getText( 'preload' );
152 $fname = 'Article::getContent';
153 wfProfileIn( $fname );
155 if ( 0 == $this->getID() ) {
156 if ( 'edit' == $action ) {
157 wfProfileOut( $fname );
159 # If requested, preload some text.
160 $text=$this->getPreloadedText($preload);
162 # We used to put MediaWiki:Newarticletext here if
163 # $text was empty at this point.
164 # This is now shown above the edit box instead.
167 wfProfileOut( $fname );
168 $wgOut->setRobotpolicy( 'noindex,nofollow' );
170 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
171 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
173 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
176 return "<div class='noarticletext'>$ret</div>";
178 $this->loadContent();
179 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
180 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
181 $wgUser->isIP($this->mTitle
->getText()) &&
184 wfProfileOut( $fname );
185 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
187 if($action=='edit') {
189 if($section=='new') {
190 wfProfileOut( $fname );
191 $text=$this->getPreloadedText($preload);
195 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
196 # comments to be stripped as well)
197 $rv=$this->getSection($this->mContent
,$section);
198 wfProfileOut( $fname );
202 wfProfileOut( $fname );
203 return $this->mContent
;
209 * Get the contents of a page from its title and remove includeonly tags
211 * TODO FIXME: This is only here because of the inputbox extension and
212 * should be moved there
216 * @param string The title of the page
217 * @return string The contents of the page
219 function getPreloadedText($preload) {
220 if ( $preload === '' )
223 $preloadTitle = Title
::newFromText( $preload );
224 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
225 $rev=Revision
::newFromTitle($preloadTitle);
226 if ( is_object( $rev ) ) {
227 $text = $rev->getText();
228 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
229 // its own mini-parser! -ævar
230 $text = preg_replace( '~</?includeonly>~', '', $text );
239 * This function returns the text of a section, specified by a number ($section).
240 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
241 * the first section before any such heading (section 0).
243 * If a section contains subsections, these are also returned.
245 * @param string $text text to look in
246 * @param integer $section section number
247 * @return string text of the requested section
249 function getSection($text,$section) {
251 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
252 # comments to be stripped as well)
254 $parser=new Parser();
255 $parser->mOutputType
=OT_WIKI
;
256 $parser->mOptions
= new ParserOptions();
257 $striptext=$parser->strip($text, $striparray, true);
259 # now that we can be sure that no pseudo-sections are in the source,
260 # split it up by section
263 '/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
265 PREG_SPLIT_DELIM_CAPTURE
);
269 $headline=$secs[$section*2-1];
270 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
273 # translate wiki heading into level
274 if(strpos($hlevel,'=')!==false) {
275 $hlevel=strlen($hlevel);
278 $rv=$headline. $secs[$section*2];
282 while(!empty($secs[$count*2-1]) && !$break) {
284 $subheadline=$secs[$count*2-1];
285 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
286 $subhlevel=$matches[1];
287 if(strpos($subhlevel,'=')!==false) {
288 $subhlevel=strlen($subhlevel);
290 if($subhlevel > $hlevel) {
291 $rv.=$subheadline.$secs[$count*2];
293 if($subhlevel <= $hlevel) {
300 # reinsert stripped tags
301 $rv=$parser->unstrip($rv,$striparray);
302 $rv=$parser->unstripNoWiki($rv,$striparray);
309 * @return int The oldid of the article that is to be shown, 0 for the
312 function getOldID() {
313 if ( is_null( $this->mOldId
) ) {
314 $this->mOldId
= $this->getOldIDFromRequest();
316 return $this->mOldId
;
320 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
322 * @return int The old id for the request
324 function getOldIDFromRequest() {
326 $this->mRedirectUrl
= false;
327 $oldid = $wgRequest->getVal( 'oldid' );
328 if ( isset( $oldid ) ) {
329 $oldid = intval( $oldid );
330 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
331 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
335 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
337 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
338 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
354 * Load the revision (including text) into this object
356 function loadContent() {
357 global $wgOut, $wgRequest;
359 if ( $this->mContentLoaded
) return;
362 $oldid = $this->getOldID();
364 $fname = 'Article::loadContent';
366 # Pre-fill content with error message so that if something
367 # fails we'll have something telling us what we intended.
369 $t = $this->mTitle
->getPrefixedText();
371 $this->mOldId
= $oldid;
372 $this->fetchContent( $oldid );
377 * Fetch a page record with the given conditions
378 * @param Database $dbr
379 * @param array $conditions
382 function pageData( &$dbr, $conditions ) {
395 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
396 $row = $dbr->selectRow( 'page',
399 'Article::pageData' );
400 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
405 * @param Database $dbr
406 * @param Title $title
408 function pageDataFromTitle( &$dbr, $title ) {
409 return $this->pageData( $dbr, array(
410 'page_namespace' => $title->getNamespace(),
411 'page_title' => $title->getDBkey() ) );
415 * @param Database $dbr
418 function pageDataFromId( &$dbr, $id ) {
419 return $this->pageData( $dbr, array( 'page_id' => $id ) );
423 * Set the general counter, title etc data loaded from
426 * @param object $data
429 function loadPageData( $data ) {
430 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
431 $this->mTitle
->mRestrictionsLoaded
= true;
433 $this->mCounter
= $data->page_counter
;
434 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
435 $this->mIsRedirect
= $data->page_is_redirect
;
436 $this->mLatest
= $data->page_latest
;
438 $this->mDataLoaded
= true;
442 * Get text of an article from database
443 * Does *NOT* follow redirects.
444 * @param int $oldid 0 for whatever the latest revision is
447 function fetchContent( $oldid = 0 ) {
448 if ( $this->mContentLoaded
) {
449 return $this->mContent
;
452 $dbr =& $this->getDB();
453 $fname = 'Article::fetchContent';
455 # Pre-fill content with error message so that if something
456 # fails we'll have something telling us what we intended.
457 $t = $this->mTitle
->getPrefixedText();
459 $t .= ',oldid='.$oldid;
461 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
464 $revision = Revision
::newFromId( $oldid );
465 if( is_null( $revision ) ) {
466 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
469 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
471 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
474 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
475 $this->loadPageData( $data );
477 if( !$this->mDataLoaded
) {
478 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
480 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
483 $this->loadPageData( $data );
485 $revision = Revision
::newFromId( $this->mLatest
);
486 if( is_null( $revision ) ) {
487 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
492 $this->mContent
= $revision->getText();
494 $this->mUser
= $revision->getUser();
495 $this->mUserText
= $revision->getUserText();
496 $this->mComment
= $revision->getComment();
497 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
499 $this->mRevIdFetched
= $revision->getID();
500 $this->mContentLoaded
= true;
501 $this->mRevision
=& $revision;
503 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
505 return $this->mContent
;
509 * Read/write accessor to select FOR UPDATE
513 function forUpdate( $x = NULL ) {
514 return wfSetVar( $this->mForUpdate
, $x );
518 * Get the database which should be used for reads
523 $ret =& wfGetDB( DB_MASTER
);
528 * Get options for all SELECT statements
530 * @param array $options an optional options array which'll be appended to
532 * @return array Options
534 function getSelectOptions( $options = '' ) {
535 if ( $this->mForUpdate
) {
536 if ( is_array( $options ) ) {
537 $options[] = 'FOR UPDATE';
539 $options = 'FOR UPDATE';
546 * @return int Page ID
549 if( $this->mTitle
) {
550 return $this->mTitle
->getArticleID();
557 * @return bool Whether or not the page exists in the database
560 return $this->getId() != 0;
564 * @return int The view count for the page
566 function getCount() {
567 if ( -1 == $this->mCounter
) {
568 $id = $this->getID();
569 $dbr =& wfGetDB( DB_SLAVE
);
570 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
571 'Article::getCount', $this->getSelectOptions() );
573 return $this->mCounter
;
577 * Determine whether a page would be suitable for being counted as an
578 * article in the site_stats table based on the title & its content
580 * @param string $text Text to analyze
583 function isCountable( $text ) {
584 global $wgUseCommaCount;
586 $token = $wgUseCommaCount ?
',' : '[[';
588 $this->mTitle
->getNamespace() == NS_MAIN
589 && ! $this->isRedirect( $text )
590 && in_string( $token, $text );
594 * Tests if the article text represents a redirect
596 * @param string $text
599 function isRedirect( $text = false ) {
600 if ( $text === false ) {
601 $this->loadContent();
602 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
604 $titleObj = Title
::newFromRedirect( $text );
606 return $titleObj !== NULL;
610 * Returns true if the currently-referenced revision is the current edit
611 * to this page (and it exists).
614 function isCurrent() {
615 return $this->exists() &&
616 isset( $this->mRevision
) &&
617 $this->mRevision
->isCurrent();
621 * Loads everything except the text
622 * This isn't necessary for all uses, so it's only done if needed.
625 function loadLastEdit() {
628 if ( -1 != $this->mUser
)
631 # New or non-existent articles have no user information
632 $id = $this->getID();
633 if ( 0 == $id ) return;
635 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
636 if( !is_null( $this->mLastRevision
) ) {
637 $this->mUser
= $this->mLastRevision
->getUser();
638 $this->mUserText
= $this->mLastRevision
->getUserText();
639 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
640 $this->mComment
= $this->mLastRevision
->getComment();
641 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
642 $this->mRevIdFetched
= $this->mLastRevision
->getID();
646 function getTimestamp() {
647 $this->loadLastEdit();
648 return wfTimestamp(TS_MW
, $this->mTimestamp
);
652 $this->loadLastEdit();
656 function getUserText() {
657 $this->loadLastEdit();
658 return $this->mUserText
;
661 function getComment() {
662 $this->loadLastEdit();
663 return $this->mComment
;
666 function getMinorEdit() {
667 $this->loadLastEdit();
668 return $this->mMinorEdit
;
671 function getRevIdFetched() {
672 $this->loadLastEdit();
673 return $this->mRevIdFetched
;
676 function getContributors($limit = 0, $offset = 0) {
677 $fname = 'Article::getContributors';
679 # XXX: this is expensive; cache this info somewhere.
681 $title = $this->mTitle
;
683 $dbr =& wfGetDB( DB_SLAVE
);
684 $revTable = $dbr->tableName( 'revision' );
685 $userTable = $dbr->tableName( 'user' );
686 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
687 $ns = $title->getNamespace();
688 $user = $this->getUser();
689 $pageId = $this->getId();
691 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
692 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
693 WHERE rev_page = $pageId
694 AND rev_user != $user
695 GROUP BY rev_user, rev_user_text, user_real_name
696 ORDER BY timestamp DESC";
698 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
699 $sql .= ' '. $this->getSelectOptions();
701 $res = $dbr->query($sql, $fname);
703 while ( $line = $dbr->fetchObject( $res ) ) {
704 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
707 $dbr->freeResult($res);
712 * This is the default action of the script: just view the page of
716 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
717 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
718 global $wgUseTrackbacks;
719 $sk = $wgUser->getSkin();
721 $fname = 'Article::view';
722 wfProfileIn( $fname );
723 $parserCache =& ParserCache
::singleton();
724 # Get variables from query string
725 $oldid = $this->getOldID();
727 # getOldID may want us to redirect somewhere else
728 if ( $this->mRedirectUrl
) {
729 $wgOut->redirect( $this->mRedirectUrl
);
730 wfProfileOut( $fname );
734 $diff = $wgRequest->getVal( 'diff' );
735 $rcid = $wgRequest->getVal( 'rcid' );
736 $rdfrom = $wgRequest->getVal( 'rdfrom' );
738 $wgOut->setArticleFlag( true );
739 $wgOut->setRobotpolicy( 'index,follow' );
740 # If we got diff and oldid in the query, we want to see a
741 # diff page instead of the article.
743 if ( !is_null( $diff ) ) {
744 require_once( 'DifferenceEngine.php' );
745 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
747 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
748 // DifferenceEngine directly fetched the revision:
749 $this->mRevIdFetched
= $de->mNewid
;
753 # Run view updates for current revision only
754 $this->viewUpdates();
756 wfProfileOut( $fname );
760 if ( empty( $oldid ) && $this->checkTouched() ) {
761 $wgOut->setETag($parserCache->getETag($this, $wgUser));
763 if( $wgOut->checkLastModified( $this->mTouched
) ){
764 wfProfileOut( $fname );
766 } else if ( $this->tryFileCache() ) {
767 # tell wgOut that output is taken care of
769 $this->viewUpdates();
770 wfProfileOut( $fname );
774 # Should the parser cache be used?
775 $pcache = $wgEnableParserCache &&
776 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
779 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
780 if ( $wgUser->getOption( 'stubthreshold' ) ) {
781 wfIncrStats( 'pcache_miss_stub' );
784 $wasRedirected = false;
785 if ( isset( $this->mRedirectedFrom
) ) {
786 // This is an internally redirected page view.
787 // We'll need a backlink to the source page for navigation.
788 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
789 $sk = $wgUser->getSkin();
790 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
791 $s = wfMsg( 'redirectedfrom', $redir );
792 $wgOut->setSubtitle( $s );
793 $wasRedirected = true;
795 } elseif ( !empty( $rdfrom ) ) {
796 // This is an externally redirected view, from some other wiki.
797 // If it was reported from a trusted site, supply a backlink.
798 global $wgRedirectSources;
799 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
800 $sk = $wgUser->getSkin();
801 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
802 $s = wfMsg( 'redirectedfrom', $redir );
803 $wgOut->setSubtitle( $s );
804 $wasRedirected = true;
810 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
814 if ( !$outputDone ) {
815 $text = $this->getContent();
816 if ( $text === false ) {
817 # Failed to load, replace text with error message
818 $t = $this->mTitle
->getPrefixedText();
820 $t .= ',oldid='.$oldid;
822 $text = wfMsg( 'missingarticle', $t );
825 # Another whitelist check in case oldid is altering the title
826 if ( !$this->mTitle
->userCanRead() ) {
827 $wgOut->loginToUse();
832 # We're looking at an old revision
834 if ( !empty( $oldid ) ) {
835 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
836 $wgOut->setRobotpolicy( 'noindex,follow' );
841 * @fixme: this hook doesn't work most of the time, as it doesn't
842 * trigger when the parser cache is used.
844 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
845 $wgOut->setRevisionId( $this->getRevIdFetched() );
846 # wrap user css and user js in pre and don't parse
847 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
849 $this->mTitle
->getNamespace() == NS_USER
&&
850 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
852 $wgOut->addWikiText( wfMsg('clearyourcache'));
853 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
854 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
856 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
857 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
858 if( !$wasRedirected ) {
859 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
861 $targetUrl = $rt->escapeLocalURL();
862 $titleText = htmlspecialchars( $rt->getPrefixedText() );
863 $link = $sk->makeLinkObj( $rt );
865 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
866 '<span class="redirectText">'.$link.'</span>' );
868 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
869 $wgOut->addParserOutputNoText( $parseout );
870 } else if ( $pcache ) {
871 # Display content and save to parser cache
872 $wgOut->addPrimaryWikiText( $text, $this );
874 # Display content, don't attempt to save to parser cache
876 # Don't show section-edit links on old revisions... this way lies madness.
877 if( !$this->isCurrent() ) {
878 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
880 $wgOut->addWikiText( $text );
882 if( !$this->isCurrent() ) {
883 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
887 /* title may have been set from the cache */
888 $t = $wgOut->getPageTitle();
890 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
893 # If we have been passed an &rcid= parameter, we want to give the user a
894 # chance to mark this new article as patrolled.
898 && $wgUser->isLoggedIn()
899 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
902 "<div class='patrollink'>" .
903 wfMsg ( 'markaspatrolledlink',
904 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
911 if ($wgUseTrackbacks)
912 $this->addTrackbacks();
914 $this->viewUpdates();
915 wfProfileOut( $fname );
918 function addTrackbacks() {
919 global $wgOut, $wgUser;
921 $dbr =& wfGetDB(DB_SLAVE
);
923 /* FROM */ 'trackbacks',
924 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
925 /* WHERE */ array('tb_page' => $this->getID())
928 if (!$dbr->numrows($tbs))
932 while ($o = $dbr->fetchObject($tbs)) {
934 if ($wgUser->isSysop()) {
935 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
936 . $o->tb_id
. "&token=" . $wgUser->editToken());
937 $rmvtxt = wfMsg('trackbackremove', $delurl);
939 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
946 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
949 function deletetrackback() {
950 global $wgUser, $wgRequest, $wgOut, $wgTitle;
952 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
953 $wgOut->addWikitext(wfMsg('sessionfailure'));
957 if ((!$wgUser->isAllowed('delete'))) {
958 $wgOut->sysopRequired();
963 $wgOut->readOnlyPage();
967 $db =& wfGetDB(DB_MASTER
);
968 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
969 $wgTitle->invalidateCache();
970 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
976 $wgOut->setArticleBodyOnly(true);
981 global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
983 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ||
! wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
984 // Invalidate the cache
985 $this->mTitle
->invalidateCache();
988 // Commit the transaction before the purge is sent
989 $dbw = wfGetDB( DB_MASTER
);
990 $dbw->immediateCommit();
993 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
998 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
999 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
1000 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
1001 $msg = str_replace( '$1',
1002 "<form method=\"post\" action=\"$action\">\n" .
1003 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
1004 "</form>\n", $msg );
1006 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
1007 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1008 $wgOut->addHTML( $msg );
1013 * Insert a new empty page record for this article.
1014 * This *must* be followed up by creating a revision
1015 * and running $this->updateToLatest( $rev_id );
1016 * or else the record will be left in a funky state.
1017 * Best if all done inside a transaction.
1019 * @param Database $dbw
1020 * @param string $restrictions
1021 * @return int The newly created page_id key
1024 function insertOn( &$dbw, $restrictions = '' ) {
1025 $fname = 'Article::insertOn';
1026 wfProfileIn( $fname );
1028 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1029 $dbw->insert( 'page', array(
1030 'page_id' => $page_id,
1031 'page_namespace' => $this->mTitle
->getNamespace(),
1032 'page_title' => $this->mTitle
->getDBkey(),
1033 'page_counter' => 0,
1034 'page_restrictions' => $restrictions,
1035 'page_is_redirect' => 0, # Will set this shortly...
1037 'page_random' => wfRandom(),
1038 'page_touched' => $dbw->timestamp(),
1039 'page_latest' => 0, # Fill this in shortly...
1040 'page_len' => 0, # Fill this in shortly...
1042 $newid = $dbw->insertId();
1044 $this->mTitle
->resetArticleId( $newid );
1046 wfProfileOut( $fname );
1051 * Update the page record to point to a newly saved revision.
1053 * @param Database $dbw
1054 * @param Revision $revision For ID number, and text used to set
1055 length and redirect status fields
1056 * @param int $lastRevision If given, will not overwrite the page field
1057 * when different from the currently set value.
1058 * Giving 0 indicates the new page flag should
1060 * @return bool true on success, false on failure
1063 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1064 $fname = 'Article::updateToRevision';
1065 wfProfileIn( $fname );
1067 $conditions = array( 'page_id' => $this->getId() );
1068 if( !is_null( $lastRevision ) ) {
1069 # An extra check against threads stepping on each other
1070 $conditions['page_latest'] = $lastRevision;
1073 $text = $revision->getText();
1074 $dbw->update( 'page',
1076 'page_latest' => $revision->getId(),
1077 'page_touched' => $dbw->timestamp(),
1078 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1079 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1080 'page_len' => strlen( $text ),
1085 wfProfileOut( $fname );
1086 return ( $dbw->affectedRows() != 0 );
1090 * If the given revision is newer than the currently set page_latest,
1091 * update the page record. Otherwise, do nothing.
1093 * @param Database $dbw
1094 * @param Revision $revision
1096 function updateIfNewerOn( &$dbw, $revision ) {
1097 $fname = 'Article::updateIfNewerOn';
1098 wfProfileIn( $fname );
1100 $row = $dbw->selectRow(
1101 array( 'revision', 'page' ),
1102 array( 'rev_id', 'rev_timestamp' ),
1104 'page_id' => $this->getId(),
1105 'page_latest=rev_id' ),
1108 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1109 wfProfileOut( $fname );
1112 $prev = $row->rev_id
;
1114 # No or missing previous revision; mark the page as new
1118 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1119 wfProfileOut( $fname );
1124 * Theoretically we could defer these whole insert and update
1125 * functions for after display, but that's taking a big leap
1126 * of faith, and we want to be able to report database
1127 * errors at some point.
1130 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1131 global $wgOut, $wgUser, $wgUseSquid;
1133 $fname = 'Article::insertNewArticle';
1134 wfProfileIn( $fname );
1136 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1137 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1138 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1139 wfProfileOut( $fname );
1143 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1144 $this->mTotalAdjustment
= 1;
1146 $ns = $this->mTitle
->getNamespace();
1147 $ttl = $this->mTitle
->getDBkey();
1149 # If this is a comment, add the summary as headline
1150 if($comment && $summary!="") {
1151 $text="== {$summary} ==\n\n".$text;
1153 $text = $this->preSaveTransform( $text );
1155 /* Silently ignore minoredit if not allowed */
1156 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1157 $now = wfTimestampNow();
1159 $dbw =& wfGetDB( DB_MASTER
);
1161 # Add the page record; stake our claim on this title!
1162 $newid = $this->insertOn( $dbw );
1164 # Save the revision text...
1165 $revision = new Revision( array(
1167 'comment' => $summary,
1168 'minor_edit' => $isminor,
1171 $revisionId = $revision->insertOn( $dbw );
1173 $this->mTitle
->resetArticleID( $newid );
1175 # Update the page record with revision data
1176 $this->updateRevisionOn( $dbw, $revision, 0 );
1178 Article
::onArticleCreate( $this->mTitle
);
1180 require_once( 'RecentChange.php' );
1181 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1182 '', strlen( $text ), $revisionId );
1186 if(!$this->mTitle
->userIsWatching()) $this->watch();
1188 if ( $this->mTitle
->userIsWatching() ) {
1193 # The talk page isn't in the regular link tables, so we need to update manually:
1194 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1195 $dbw->update( 'page',
1196 array( 'page_touched' => $dbw->timestamp($now) ),
1197 array( 'page_namespace' => $talkns,
1198 'page_title' => $ttl ),
1201 # standard deferred updates
1202 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1204 $oldid = 0; # new article
1205 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1207 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1209 $watchthis, NULL ) );
1210 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1212 $watchthis, NULL ) );
1213 wfProfileOut( $fname );
1216 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1217 $this->replaceSection( $section, $text, $summary, $edittime );
1221 * @return string Complete article text, or null if error
1223 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1224 $fname = 'Article::replaceSection';
1225 wfProfileIn( $fname );
1227 if ($section != '') {
1228 if( is_null( $edittime ) ) {
1229 $rev = Revision
::newFromTitle( $this->mTitle
);
1231 $dbw =& wfGetDB( DB_MASTER
);
1232 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1234 if( is_null( $rev ) ) {
1235 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1236 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1239 $oldtext = $rev->getText();
1241 if($section=='new') {
1242 if($summary) $subject="== {$summary} ==\n\n";
1243 $text=$oldtext."\n\n".$subject.$text;
1246 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1247 # comments to be stripped as well)
1248 $striparray=array();
1249 $parser=new Parser();
1250 $parser->mOutputType
=OT_WIKI
;
1251 $parser->mOptions
= new ParserOptions();
1252 $oldtext=$parser->strip($oldtext, $striparray, true);
1254 # now that we can be sure that no pseudo-sections are in the source,
1256 # Unfortunately we can't simply do a preg_replace because that might
1257 # replace the wrong section, so we have to use the section counter instead
1258 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
1259 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1260 $secs[$section*2]=$text."\n\n"; // replace with edited
1262 # section 0 is top (intro) section
1265 # headline of old section - we need to go through this section
1266 # to determine if there are any subsections that now need to
1267 # be erased, as the mother section has been replaced with
1268 # the text of all subsections.
1269 $headline=$secs[$section*2-1];
1270 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
1271 $hlevel=$matches[1];
1273 # determine headline level for wikimarkup headings
1274 if(strpos($hlevel,'=')!==false) {
1275 $hlevel=strlen($hlevel);
1278 $secs[$section*2-1]=''; // erase old headline
1281 while(!empty($secs[$count*2-1]) && !$break) {
1283 $subheadline=$secs[$count*2-1];
1285 '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
1286 $subhlevel=$matches[1];
1287 if(strpos($subhlevel,'=')!==false) {
1288 $subhlevel=strlen($subhlevel);
1290 if($subhlevel > $hlevel) {
1291 // erase old subsections
1292 $secs[$count*2-1]='';
1295 if($subhlevel <= $hlevel) {
1303 $text=join('',$secs);
1304 # reinsert the stuff that we stripped out earlier
1305 $text=$parser->unstrip($text,$striparray);
1306 $text=$parser->unstripNoWiki($text,$striparray);
1310 wfProfileOut( $fname );
1315 * Change an existing article. Puts the previous version back into the old table, updates RC
1316 * and all necessary caches, mostly via the deferred update array.
1318 * It is possible to call this function from a command-line script, but note that you should
1319 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1321 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1322 global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
1323 global $wgPostCommitUpdateList, $wgUseFileCache;
1325 $fname = 'Article::updateArticle';
1326 wfProfileIn( $fname );
1329 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1331 &$watchthis, &$sectionanchor ) ) ) {
1332 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1333 wfProfileOut( $fname );
1337 $isminor = $minor && $wgUser->isAllowed('minoredit');
1338 $redir = (int)$this->isRedirect( $text );
1340 $text = $this->preSaveTransform( $text );
1341 $dbw =& wfGetDB( DB_MASTER
);
1342 $now = wfTimestampNow();
1344 # Update article, but only if changed.
1346 # It's important that we either rollback or complete, otherwise an attacker could
1347 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1348 # could conceivably have the same effect, especially if cur is locked for long periods.
1349 if( !$wgDBtransactions ) {
1350 $userAbort = ignore_user_abort( true );
1353 $oldtext = $this->getContent();
1354 $oldsize = strlen( $oldtext );
1355 $newsize = strlen( $text );
1359 if ( 0 != strcmp( $text, $oldtext ) ) {
1360 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1361 - (int)$this->isCountable( $oldtext );
1362 $this->mTotalAdjustment
= 0;
1363 $now = wfTimestampNow();
1365 $lastRevision = $dbw->selectField(
1366 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1368 $revision = new Revision( array(
1369 'page' => $this->getId(),
1370 'comment' => $summary,
1371 'minor_edit' => $isminor,
1375 $dbw->immediateCommit();
1377 $revisionId = $revision->insertOn( $dbw );
1380 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1383 /* Belated edit conflict! Run away!! */
1387 # Update recentchanges and purge cache and whatnot
1388 require_once( 'RecentChange.php' );
1389 $bot = (int)($wgUser->isBot() ||
$forceBot);
1390 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1391 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1395 // Update caches outside the main transaction
1396 Article
::onArticleEdit( $this->mTitle
);
1399 // Keep the same revision ID, but do some updates on it
1400 $revisionId = $this->getRevIdFetched();
1403 if( !$wgDBtransactions ) {
1404 ignore_user_abort( $userAbort );
1409 if (!$this->mTitle
->userIsWatching()) {
1410 $dbw->immediateCommit();
1416 if ( $this->mTitle
->userIsWatching() ) {
1417 $dbw->immediateCommit();
1423 # standard deferred updates
1424 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1428 # Invalidate caches of all articles using this article as a template
1430 # Template namespace
1431 # Purge all articles linking here
1432 $titles = $this->mTitle
->getTemplateLinksTo();
1433 Title
::touchArray( $titles );
1434 if ( $wgUseSquid ) {
1435 foreach ( $titles as $title ) {
1436 $urls[] = $title->getInternalURL();
1441 if ( $wgUseSquid ) {
1442 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1443 $u = new SquidUpdate( $urls );
1444 array_push( $wgPostCommitUpdateList, $u );
1448 if ( $wgUseFileCache ) {
1449 $cm = new CacheManager($this->mTitle
);
1450 @unlink
($cm->fileCacheName());
1453 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1455 wfRunHooks( 'ArticleSaveComplete',
1456 array( &$this, &$wgUser, $text,
1458 $watchthis, $sectionanchor ) );
1459 wfProfileOut( $fname );
1464 * After we've either updated or inserted the article, update
1465 * the link tables and redirect to the new page.
1467 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1468 global $wgOut, $wgUser;
1469 global $wgUseEnotif;
1471 $fname = 'Article::showArticle';
1472 wfProfileIn( $fname );
1474 # Output the redirect
1475 if( $this->isRedirect( $text ) )
1479 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1481 wfProfileOut( $fname );
1485 * Mark this particular edit as patrolled
1487 function markpatrolled() {
1488 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1489 $wgOut->setRobotpolicy( 'noindex,follow' );
1491 # Check RC patrol config. option
1492 if( !$wgUseRCPatrol ) {
1493 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1498 if( $wgUser->isLoggedIn() ) {
1499 if( !$wgUser->isAllowed( 'patrol' ) ) {
1500 $wgOut->permissionRequired( 'patrol' );
1504 $wgOut->loginToUse();
1508 $rcid = $wgRequest->getVal( 'rcid' );
1509 if ( !is_null ( $rcid ) )
1511 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) ) ) {
1512 require_once( 'RecentChange.php' );
1513 RecentChange
::markPatrolled( $rcid );
1514 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) );
1515 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1516 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1518 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1519 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1523 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1528 * Add this page to $wgUser's watchlist
1533 global $wgUser, $wgOut;
1535 if ( $wgUser->isAnon() ) {
1536 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1539 if ( wfReadOnly() ) {
1540 $wgOut->readOnlyPage();
1544 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1546 $wgUser->addWatch( $this->mTitle
);
1547 $wgUser->saveSettings();
1549 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1551 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1552 $wgOut->setRobotpolicy( 'noindex,follow' );
1554 $link = $this->mTitle
->getPrefixedText();
1555 $text = wfMsg( 'addedwatchtext', $link );
1556 $wgOut->addWikiText( $text );
1559 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1563 * Stop watching a page
1566 function unwatch() {
1568 global $wgUser, $wgOut;
1570 if ( $wgUser->isAnon() ) {
1571 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1574 if ( wfReadOnly() ) {
1575 $wgOut->readOnlyPage();
1579 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1581 $wgUser->removeWatch( $this->mTitle
);
1582 $wgUser->saveSettings();
1584 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1586 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1587 $wgOut->setRobotpolicy( 'noindex,follow' );
1589 $link = $this->mTitle
->getPrefixedText();
1590 $text = wfMsg( 'removedwatchtext', $link );
1591 $wgOut->addWikiText( $text );
1594 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1598 * action=protect handler
1600 function protect() {
1601 require_once 'ProtectionForm.php';
1602 $form = new ProtectionForm( $this );
1607 * action=unprotect handler (alias)
1609 function unprotect() {
1614 * Update the article's restriction field, and leave a log entry.
1616 * @param array $limit set of restriction keys
1617 * @param string $reason
1618 * @return bool true on success
1620 function updateRestrictions( $limit = array(), $reason = '' ) {
1621 global $wgUser, $wgOut, $wgRequest;
1623 if ( !$wgUser->isAllowed( 'protect' ) ) {
1627 if( wfReadOnly() ) {
1631 $id = $this->mTitle
->getArticleID();
1636 $flat = Article
::flattenRestrictions( $limit );
1637 $protecting = ($flat != '');
1639 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser,
1640 $limit, $reason ) ) ) {
1642 $dbw =& wfGetDB( DB_MASTER
);
1643 $dbw->update( 'page',
1645 'page_touched' => $dbw->timestamp(),
1646 'page_restrictions' => $flat
1647 ), array( /* WHERE */
1649 ), 'Article::protect'
1652 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser,
1653 $limit, $reason ) );
1655 $log = new LogPage( 'protect' );
1657 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$flat]" ) );
1659 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1666 * Take an array of page restrictions and flatten it to a string
1667 * suitable for insertion into the page_restrictions field.
1668 * @param array $limit
1672 function flattenRestrictions( $limit ) {
1673 if( !is_array( $limit ) ) {
1674 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1677 foreach( $limit as $action => $restrictions ) {
1678 if( $restrictions != '' ) {
1679 $bits[] = "$action=$restrictions";
1682 return implode( ':', $bits );
1686 * UI entry point for page deletion
1689 global $wgUser, $wgOut, $wgRequest;
1690 $fname = 'Article::delete';
1691 $confirm = $wgRequest->wasPosted() &&
1692 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1693 $reason = $wgRequest->getText( 'wpReason' );
1695 # This code desperately needs to be totally rewritten
1698 if( $wgUser->isAllowed( 'delete' ) ) {
1699 if( $wgUser->isBlocked() ) {
1700 $wgOut->blockedPage();
1704 $wgOut->permissionRequired( 'delete' );
1708 if( wfReadOnly() ) {
1709 $wgOut->readOnlyPage();
1713 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1715 # Better double-check that it hasn't been deleted yet!
1716 $dbw =& wfGetDB( DB_MASTER
);
1717 $conds = $this->mTitle
->pageCond();
1718 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1719 if ( $latest === false ) {
1720 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1725 $this->doDelete( $reason );
1729 # determine whether this page has earlier revisions
1730 # and insert a warning if it does
1732 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1734 if( count( $authors ) > 1 && !$confirm ) {
1735 $skin=$wgUser->getSkin();
1736 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1737 $wgOut->addHTML( $skin->historyLink() .'</b>');
1740 # If a single user is responsible for all revisions, find out who they are
1741 if ( count( $authors ) == $maxRevisions ) {
1742 // Query bailed out, too many revisions to find out if they're all the same
1743 $authorOfAll = false;
1745 $authorOfAll = reset( $authors );
1746 foreach ( $authors as $author ) {
1747 if ( $authorOfAll != $author ) {
1748 $authorOfAll = false;
1753 # Fetch article text
1754 $rev = Revision
::newFromTitle( $this->mTitle
);
1756 if( !is_null( $rev ) ) {
1757 # if this is a mini-text, we can paste part of it into the deletion reason
1758 $text = $rev->getText();
1760 #if this is empty, an earlier revision may contain "useful" text
1763 $prev = $rev->getPrevious();
1765 $text = $prev->getText();
1770 $length = strlen( $text );
1772 # this should not happen, since it is not possible to store an empty, new
1773 # page. Let's insert a standard text in case it does, though
1774 if( $length == 0 && $reason === '' ) {
1775 $reason = wfMsgForContent( 'exblank' );
1778 if( $length < 500 && $reason === '' ) {
1779 # comment field=255, let's grep the first 150 to have some user
1782 $text = $wgContLang->truncate( $text, 150, '...' );
1784 # let's strip out newlines
1785 $text = preg_replace( "/[\n\r]/", '', $text );
1788 if( $authorOfAll === false ) {
1789 $reason = wfMsgForContent( 'excontent', $text );
1791 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1794 $reason = wfMsgForContent( 'exbeforeblank', $text );
1799 return $this->confirmDelete( '', $reason );
1803 * Get the last N authors
1804 * @param int $num Number of revisions to get
1805 * @param string $revLatest The latest rev_id, selected from the master (optional)
1806 * @return array Array of authors, duplicates not removed
1808 function getLastNAuthors( $num, $revLatest = 0 ) {
1809 $fname = 'Article::getLastNAuthors';
1810 wfProfileIn( $fname );
1812 // First try the slave
1813 // If that doesn't have the latest revision, try the master
1815 $db =& wfGetDB( DB_SLAVE
);
1817 $res = $db->select( array( 'page', 'revision' ),
1818 array( 'rev_id', 'rev_user_text' ),
1820 'page_namespace' => $this->mTitle
->getNamespace(),
1821 'page_title' => $this->mTitle
->getDBkey(),
1822 'rev_page = page_id'
1823 ), $fname, $this->getSelectOptions( array(
1824 'ORDER BY' => 'rev_timestamp DESC',
1829 wfProfileOut( $fname );
1832 $row = $db->fetchObject( $res );
1833 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1834 $db =& wfGetDB( DB_MASTER
);
1839 } while ( $continue );
1841 $authors = array( $row->rev_user_text
);
1842 while ( $row = $db->fetchObject( $res ) ) {
1843 $authors[] = $row->rev_user_text
;
1845 wfProfileOut( $fname );
1850 * Output deletion confirmation dialog
1852 function confirmDelete( $par, $reason ) {
1853 global $wgOut, $wgUser;
1855 wfDebug( "Article::confirmDelete\n" );
1857 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1858 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1859 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1860 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1862 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1864 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1865 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1866 $token = htmlspecialchars( $wgUser->editToken() );
1869 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1873 <label for='wpReason'>{$delcom}:</label>
1876 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1882 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1886 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1889 $wgOut->returnToMain( false );
1894 * Perform a deletion and output success or failure messages
1896 function doDelete( $reason ) {
1897 global $wgOut, $wgUser, $wgContLang;
1898 $fname = 'Article::doDelete';
1899 wfDebug( $fname."\n" );
1901 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1902 if ( $this->doDeleteArticle( $reason ) ) {
1903 $deleted = $this->mTitle
->getPrefixedText();
1905 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1906 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1908 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1909 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1911 $wgOut->addWikiText( $text );
1912 $wgOut->returnToMain( false );
1913 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1915 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1921 * Back-end article deletion
1922 * Deletes the article with database consistency, writes logs, purges caches
1925 function doDeleteArticle( $reason ) {
1926 global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
1927 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1929 $fname = 'Article::doDeleteArticle';
1930 wfDebug( $fname."\n" );
1932 $dbw =& wfGetDB( DB_MASTER
);
1933 $ns = $this->mTitle
->getNamespace();
1934 $t = $this->mTitle
->getDBkey();
1935 $id = $this->mTitle
->getArticleID();
1937 if ( $t == '' ||
$id == 0 ) {
1941 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1942 array_push( $wgDeferredUpdateList, $u );
1944 $linksTo = $this->mTitle
->getLinksTo();
1947 if ( $wgUseSquid ) {
1949 $this->mTitle
->getInternalURL(),
1950 $this->mTitle
->getInternalURL( 'history' )
1953 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1954 array_push( $wgPostCommitUpdateList, $u );
1958 # Client and file cache invalidation
1959 Title
::touchArray( $linksTo );
1962 // For now, shunt the revision data into the archive table.
1963 // Text is *not* removed from the text table; bulk storage
1964 // is left intact to avoid breaking block-compression or
1965 // immutable storage schemes.
1967 // For backwards compatibility, note that some older archive
1968 // table entries will have ar_text and ar_flags fields still.
1970 // In the future, we may keep revisions and mark them with
1971 // the rev_deleted field, which is reserved for this purpose.
1972 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1974 'ar_namespace' => 'page_namespace',
1975 'ar_title' => 'page_title',
1976 'ar_comment' => 'rev_comment',
1977 'ar_user' => 'rev_user',
1978 'ar_user_text' => 'rev_user_text',
1979 'ar_timestamp' => 'rev_timestamp',
1980 'ar_minor_edit' => 'rev_minor_edit',
1981 'ar_rev_id' => 'rev_id',
1982 'ar_text_id' => 'rev_text_id',
1985 'page_id = rev_page'
1989 # Now that it's safely backed up, delete it
1990 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1991 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1993 if ($wgUseTrackbacks)
1994 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1996 # Clean up recentchanges entries...
1997 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1999 # Finally, clean up the link tables
2000 $t = $this->mTitle
->getPrefixedDBkey();
2002 Article
::onArticleDelete( $this->mTitle
);
2004 # Delete outgoing links
2005 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2006 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2007 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2010 $log = new LogPage( 'delete' );
2011 $log->addEntry( 'delete', $this->mTitle
, $reason );
2013 # Clear the cached article id so the interface doesn't act like we exist
2014 $this->mTitle
->resetArticleID( 0 );
2015 $this->mTitle
->mArticleID
= 0;
2020 * Revert a modification
2022 function rollback() {
2023 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2024 $fname = 'Article::rollback';
2026 if( $wgUser->isAllowed( 'rollback' ) ) {
2027 if( $wgUser->isBlocked() ) {
2028 $wgOut->blockedPage();
2032 $wgOut->permissionRequired( 'rollback' );
2036 if ( wfReadOnly() ) {
2037 $wgOut->readOnlyPage( $this->getContent() );
2040 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2041 array( $this->mTitle
->getPrefixedText(),
2042 $wgRequest->getVal( 'from' ) ) ) ) {
2043 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2044 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2047 $dbw =& wfGetDB( DB_MASTER
);
2049 # Enhanced rollback, marks edits rc_bot=1
2050 $bot = $wgRequest->getBool( 'bot' );
2052 # Replace all this user's current edits with the next one down
2053 $tt = $this->mTitle
->getDBKey();
2054 $n = $this->mTitle
->getNamespace();
2056 # Get the last editor, lock table exclusively
2058 $current = Revision
::newFromTitle( $this->mTitle
);
2059 if( is_null( $current ) ) {
2060 # Something wrong... no page?
2062 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2066 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2067 if( $from != $current->getUserText() ) {
2068 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2069 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2070 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2071 htmlspecialchars( $from ),
2072 htmlspecialchars( $current->getUserText() ) ) );
2073 if( $current->getComment() != '') {
2075 wfMsg( 'editcomment',
2076 htmlspecialchars( $current->getComment() ) ) );
2081 # Get the last edit not by this guy
2082 $user = intval( $current->getUser() );
2083 $user_text = $dbw->addQuotes( $current->getUserText() );
2084 $s = $dbw->selectRow( 'revision',
2085 array( 'rev_id', 'rev_timestamp' ),
2087 'rev_page' => $current->getPage(),
2088 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2091 'USE INDEX' => 'page_timestamp',
2092 'ORDER BY' => 'rev_timestamp DESC' )
2094 if( $s === false ) {
2097 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2098 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2104 # Mark all reverted edits as bot
2107 if ( $wgUseRCPatrol ) {
2108 # Mark all reverted edits as patrolled
2109 $set['rc_patrolled'] = 1;
2113 $dbw->update( 'recentchanges', $set,
2115 'rc_cur_id' => $current->getPage(),
2116 'rc_user_text' => $current->getUserText(),
2117 "rc_timestamp > '{$s->rev_timestamp}'",
2122 # Get the edit summary
2123 $target = Revision
::newFromId( $s->rev_id
);
2124 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2125 $newComment = $wgRequest->getText( 'summary', $newComment );
2128 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2129 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2130 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2132 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2133 Article
::onArticleEdit( $this->mTitle
);
2136 $wgOut->returnToMain( false );
2141 * Do standard deferred updates after page view
2144 function viewUpdates() {
2145 global $wgDeferredUpdateList;
2147 if ( 0 != $this->getID() ) {
2148 global $wgDisableCounters;
2149 if( !$wgDisableCounters ) {
2150 Article
::incViewCount( $this->getID() );
2151 $u = new SiteStatsUpdate( 1, 0, 0 );
2152 array_push( $wgDeferredUpdateList, $u );
2156 # Update newtalk / watchlist notification status
2158 $wgUser->clearNotification( $this->mTitle
);
2162 * Do standard deferred updates after page edit.
2163 * Every 1000th edit, prune the recent changes table.
2165 * @param string $text
2167 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2168 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2170 $fname = 'Article::editUpdates';
2171 wfProfileIn( $fname );
2174 $options = new ParserOptions
;
2175 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2177 # Save it to the parser cache
2178 $parserCache =& ParserCache
::singleton();
2179 $parserCache->save( $poutput, $this, $wgUser );
2181 # Update the links tables
2182 $u = new LinksUpdate( $this->mTitle
, $poutput );
2185 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2187 if ( 0 == mt_rand( 0, 999 ) ) {
2188 # Periodically flush old entries from the recentchanges table.
2191 $dbw =& wfGetDB( DB_MASTER
);
2192 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2193 $recentchanges = $dbw->tableName( 'recentchanges' );
2194 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2195 $dbw->query( $sql );
2199 $id = $this->getID();
2200 $title = $this->mTitle
->getPrefixedDBkey();
2201 $shortTitle = $this->mTitle
->getDBkey();
2204 wfProfileOut( $fname );
2208 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2209 array_push( $wgDeferredUpdateList, $u );
2210 $u = new SearchUpdate( $id, $title, $text );
2211 array_push( $wgDeferredUpdateList, $u );
2213 # If this is another user's talk page, update newtalk
2215 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2216 $other = User
::newFromName( $shortTitle );
2217 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2218 // An anonymous user
2219 $other = new User();
2220 $other->setName( $shortTitle );
2223 $other->setNewtalk( true );
2227 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2228 $wgMessageCache->replace( $shortTitle, $text );
2231 wfProfileOut( $fname );
2235 * @todo document this function
2237 * @param string $oldid Revision ID of this article revision
2239 function setOldSubtitle( $oldid=0 ) {
2240 global $wgLang, $wgOut, $wgUser;
2242 $current = ( $oldid == $this->mLatest
);
2243 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2244 $sk = $wgUser->getSkin();
2246 ?
wfMsg( 'currentrevisionlink' )
2247 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2248 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2249 $nextlink = $current
2250 ?
wfMsg( 'nextrevision' )
2251 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2252 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2253 $wgOut->setSubtitle( $r );
2257 * This function is called right before saving the wikitext,
2258 * so we can do things like signatures and links-in-context.
2260 * @param string $text
2262 function preSaveTransform( $text ) {
2263 global $wgParser, $wgUser;
2264 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2267 /* Caching functions */
2270 * checkLastModified returns true if it has taken care of all
2271 * output to the client that is necessary for this request.
2272 * (that is, it has sent a cached version of the page)
2274 function tryFileCache() {
2275 static $called = false;
2277 wfDebug( " tryFileCache() -- called twice!?\n" );
2281 if($this->isFileCacheable()) {
2282 $touched = $this->mTouched
;
2283 $cache = new CacheManager( $this->mTitle
);
2284 if($cache->isFileCacheGood( $touched )) {
2286 wfDebug( " tryFileCache() - about to load\n" );
2287 $cache->loadFromFileCache();
2290 wfDebug( " tryFileCache() - starting buffer\n" );
2291 ob_start( array(&$cache, 'saveToFileCache' ) );
2294 wfDebug( " tryFileCache() - not cacheable\n" );
2299 * Check if the page can be cached
2302 function isFileCacheable() {
2303 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2304 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2306 return $wgUseFileCache
2307 and (!$wgShowIPinHeader)
2308 and ($this->getID() != 0)
2309 and ($wgUser->isAnon())
2310 and (!$wgUser->getNewtalk())
2311 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2312 and (empty( $action ) ||
$action == 'view')
2313 and (!isset($oldid))
2315 and (!isset($redirect))
2316 and (!isset($printable))
2317 and (!$this->mRedirectedFrom
);
2321 * Loads page_touched and returns a value indicating if it should be used
2324 function checkTouched() {
2325 $fname = 'Article::checkTouched';
2326 if( !$this->mDataLoaded
) {
2327 $dbr =& $this->getDB();
2328 $data = $this->pageDataFromId( $dbr, $this->getId() );
2330 $this->loadPageData( $data );
2333 return !$this->mIsRedirect
;
2337 * Get the page_touched field
2339 function getTouched() {
2340 # Ensure that page data has been loaded
2341 if( !$this->mDataLoaded
) {
2342 $dbr =& $this->getDB();
2343 $data = $this->pageDataFromId( $dbr, $this->getId() );
2345 $this->loadPageData( $data );
2348 return $this->mTouched
;
2352 * Edit an article without doing all that other stuff
2353 * The article must already exist; link tables etc
2354 * are not updated, caches are not flushed.
2356 * @param string $text text submitted
2357 * @param string $comment comment submitted
2358 * @param bool $minor whereas it's a minor modification
2360 function quickEdit( $text, $comment = '', $minor = 0 ) {
2361 $fname = 'Article::quickEdit';
2362 wfProfileIn( $fname );
2364 $dbw =& wfGetDB( DB_MASTER
);
2366 $revision = new Revision( array(
2367 'page' => $this->getId(),
2369 'comment' => $comment,
2370 'minor_edit' => $minor ?
1 : 0,
2372 $revisionId = $revision->insertOn( $dbw );
2373 $this->updateRevisionOn( $dbw, $revision );
2376 wfProfileOut( $fname );
2380 * Used to increment the view counter
2383 * @param integer $id article id
2385 function incViewCount( $id ) {
2386 $id = intval( $id );
2387 global $wgHitcounterUpdateFreq;
2389 $dbw =& wfGetDB( DB_MASTER
);
2390 $pageTable = $dbw->tableName( 'page' );
2391 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2392 $acchitsTable = $dbw->tableName( 'acchits' );
2394 if( $wgHitcounterUpdateFreq <= 1 ){ //
2395 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2399 # Not important enough to warrant an error page in case of failure
2400 $oldignore = $dbw->ignoreErrors( true );
2402 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2404 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2405 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2406 # Most of the time (or on SQL errors), skip row count check
2407 $dbw->ignoreErrors( $oldignore );
2411 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2412 $row = $dbw->fetchObject( $res );
2413 $rown = intval( $row->n
);
2414 if( $rown >= $wgHitcounterUpdateFreq ){
2415 wfProfileIn( 'Article::incViewCount-collect' );
2416 $old_user_abort = ignore_user_abort( true );
2418 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2419 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2420 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2422 $dbw->query("DELETE FROM $hitcounterTable");
2423 $dbw->query('UNLOCK TABLES');
2424 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2425 'WHERE page_id = hc_id');
2426 $dbw->query("DROP TABLE $acchitsTable");
2428 ignore_user_abort( $old_user_abort );
2429 wfProfileOut( 'Article::incViewCount-collect' );
2431 $dbw->ignoreErrors( $oldignore );
2435 * The onArticle*() functions are supposed to be a kind of hooks
2436 * which should be called whenever any of the specified actions
2439 * This is a good place to put code to clear caches, for instance.
2441 * This is called on page move and undelete, as well as edit
2443 * @param $title_obj a title object
2446 function onArticleCreate($title_obj) {
2447 global $wgUseSquid, $wgPostCommitUpdateList;
2449 $title_obj->touchLinks();
2450 $titles = $title_obj->getLinksTo();
2453 if ( $wgUseSquid ) {
2454 $urls = $title_obj->getSquidURLs();
2455 foreach ( $titles as $linkTitle ) {
2456 $urls[] = $linkTitle->getInternalURL();
2458 $u = new SquidUpdate( $urls );
2459 array_push( $wgPostCommitUpdateList, $u );
2463 function onArticleDelete( $title ) {
2464 global $wgMessageCache;
2466 $title->touchLinks();
2468 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2469 $wgMessageCache->replace( $title->getDBkey(), false );
2474 * Purge caches on page update etc
2476 function onArticleEdit( $title ) {
2477 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2481 // Template namespace? Purge all articles linking here.
2482 // FIXME: When a templatelinks table arrives, use it for all includes.
2483 if ( $title->getNamespace() == NS_TEMPLATE
) {
2484 $titles = $title->getLinksTo();
2485 Title
::touchArray( $titles );
2486 if ( $wgUseSquid ) {
2487 foreach ( $titles as $link ) {
2488 $urls[] = $link->getInternalURL();
2494 if ( $wgUseSquid ) {
2495 $urls = array_merge( $urls, $title->getSquidURLs() );
2496 $u = new SquidUpdate( $urls );
2497 array_push( $wgPostCommitUpdateList, $u );
2501 if ( $wgUseFileCache ) {
2502 $cm = new CacheManager( $title );
2503 @unlink
( $cm->fileCacheName() );
2510 * Info about this page
2511 * Called for ?action=info when $wgAllowPageInfo is on.
2516 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2517 $fname = 'Article::info';
2519 if ( !$wgAllowPageInfo ) {
2520 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2524 $page = $this->mTitle
->getSubjectPage();
2526 $wgOut->setPagetitle( $page->getPrefixedText() );
2527 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2529 # first, see if the page exists at all.
2530 $exists = $page->getArticleId() != 0;
2532 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2533 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2535 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2538 $dbr =& wfGetDB( DB_SLAVE
);
2540 'wl_title' => $page->getDBkey(),
2541 'wl_namespace' => $page->getNamespace() );
2542 $numwatchers = $dbr->selectField(
2547 $this->getSelectOptions() );
2549 $pageInfo = $this->pageCountInfo( $page );
2550 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2552 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2553 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2555 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2557 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2559 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2561 $wgOut->addHTML( '</ul>' );
2567 * Return the total number of edits and number of unique editors
2568 * on a given page. If page does not exist, returns false.
2570 * @param Title $title
2574 function pageCountInfo( $title ) {
2575 $id = $title->getArticleId();
2580 $dbr =& wfGetDB( DB_SLAVE
);
2582 $rev_clause = array( 'rev_page' => $id );
2583 $fname = 'Article::pageCountInfo';
2585 $edits = $dbr->selectField(
2590 $this->getSelectOptions() );
2592 $authors = $dbr->selectField(
2594 'COUNT(DISTINCT rev_user_text)',
2597 $this->getSelectOptions() );
2599 return array( 'edits' => $edits, 'authors' => $authors );
2603 * Return a list of templates used by this article.
2604 * Uses the templatelinks table
2606 * @return array Array of Title objects
2608 function getUsedTemplates() {
2610 $id = $this->mTitle
->getArticleID();
2612 $dbr =& wfGetDB( DB_SLAVE
);
2613 $res = $dbr->select( array( 'templatelinks' ),
2614 array( 'tl_namespace', 'tl_title' ),
2615 array( 'tl_from' => $id ),
2616 'Article:getUsedTemplates' );
2617 if ( false !== $res ) {
2618 if ( $dbr->numRows( $res ) ) {
2619 while ( $row = $dbr->fetchObject( $res ) ) {
2620 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2624 $dbr->freeResult( $res );