66fbc2c700099961ba3d98837a67f4876eae677d
8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
17 * Class representing a MediaWiki article and history.
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
29 var $mContent, $mContentLoaded;
30 var $mUser, $mTimestamp, $mUserText;
31 var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
32 var $mMinorEdit, $mRedirectedFrom;
33 var $mTouched, $mFileCache, $mTitle;
43 * Constructor and clear the article
44 * @param Title &$title
45 * @param integer $oldId Revision ID, null to fetch from request, zero for current
47 function Article( &$title, $oldId = null ) {
48 $this->mTitle
=& $title;
49 $this->mOldId
= $oldId;
54 * Tell the page view functions that this view was redirected
55 * from another page on the wiki.
58 function setRedirectedFrom( $from ) {
59 $this->mRedirectedFrom
= $from;
63 * @return mixed false, Title of in-wiki target, or string with URL
65 function followRedirect() {
66 $text = $this->getContent();
67 $rt = Title
::newFromRedirect( $text );
69 # process if title object is valid and not special:userlogout
71 if( $rt->getInterwiki() != '' ) {
72 if( $rt->isLocal() ) {
73 // Offsite wikis need an HTTP redirect.
75 // This can be hard to reverse and may produce loops,
76 // so they may be disabled in the site configuration.
78 $source = $this->mTitle
->getFullURL( 'redirect=no' );
79 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
82 if( $rt->getNamespace() == NS_SPECIAL
) {
83 // Gotta hand redirects to special pages differently:
84 // Fill the HTTP response "Location" header and ignore
85 // the rest of the page we're on.
87 // This can be hard to reverse, so they may be disabled.
89 if( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) {
92 return $rt->getFullURL();
99 // No or invalid redirect
104 * get the title object of the article
106 function getTitle() {
107 return $this->mTitle
;
115 $this->mDataLoaded
= false;
116 $this->mContentLoaded
= false;
118 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
119 $this->mRedirectedFrom
= null; # Title object if set
121 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
122 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
123 $this->mTouched
= '19700101000000';
124 $this->mForUpdate
= false;
125 $this->mIsRedirect
= false;
126 $this->mRevIdFetched
= 0;
127 $this->mRedirectUrl
= false;
131 * Note that getContent/loadContent do not follow redirects anymore.
132 * If you need to fetch redirectable content easily, try
133 * the shortcut in Article::followContent()
135 * @fixme There are still side-effects in this!
136 * In general, you should use the Revision class, not Article,
137 * to fetch text for purposes other than page views.
139 * @return Return the text of this revision
141 function getContent() {
142 global $wgRequest, $wgUser, $wgOut;
144 # Get variables from query string :P
145 $action = $wgRequest->getText( 'action', 'view' );
146 $section = $wgRequest->getText( 'section' );
147 $preload = $wgRequest->getText( 'preload' );
149 $fname = 'Article::getContent';
150 wfProfileIn( $fname );
152 if ( 0 == $this->getID() ) {
153 if ( 'edit' == $action ) {
154 wfProfileOut( $fname );
156 # If requested, preload some text.
157 $text=$this->getPreloadedText($preload);
159 # We used to put MediaWiki:Newarticletext here if
160 # $text was empty at this point.
161 # This is now shown above the edit box instead.
164 wfProfileOut( $fname );
165 $wgOut->setRobotpolicy( 'noindex,nofollow' );
167 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
168 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
170 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
173 return "<div class='noarticletext'>$ret</div>";
175 $this->loadContent();
176 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
177 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
178 $wgUser->isIP($this->mTitle
->getText()) &&
181 wfProfileOut( $fname );
182 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
184 if($action=='edit') {
186 if($section=='new') {
187 wfProfileOut( $fname );
188 $text=$this->getPreloadedText($preload);
192 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
193 # comments to be stripped as well)
194 $rv=$this->getSection($this->mContent
,$section);
195 wfProfileOut( $fname );
199 wfProfileOut( $fname );
200 return $this->mContent
;
206 * Get the contents of a page from its title and remove includeonly tags
208 * TODO FIXME: This is only here because of the inputbox extension and
209 * should be moved there
213 * @param string The title of the page
214 * @return string The contents of the page
216 function getPreloadedText($preload) {
217 if ( $preload === '' )
220 $preloadTitle = Title
::newFromText( $preload );
221 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
222 $rev=Revision
::newFromTitle($preloadTitle);
223 if ( is_object( $rev ) ) {
224 $text = $rev->getText();
225 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
226 // its own mini-parser! -ævar
227 $text = preg_replace( '~</?includeonly>~', '', $text );
236 * This function returns the text of a section, specified by a number ($section).
237 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
238 * the first section before any such heading (section 0).
240 * If a section contains subsections, these are also returned.
242 * @param string $text text to look in
243 * @param integer $section section number
244 * @return string text of the requested section
246 function getSection($text,$section) {
248 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
249 # comments to be stripped as well)
251 $parser=new Parser();
252 $parser->mOutputType
=OT_WIKI
;
253 $parser->mOptions
= new ParserOptions();
254 $striptext=$parser->strip($text, $striparray, true);
256 # now that we can be sure that no pseudo-sections are in the source,
257 # split it up by section
260 '/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
262 PREG_SPLIT_DELIM_CAPTURE
);
266 $headline=$secs[$section*2-1];
267 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
270 # translate wiki heading into level
271 if(strpos($hlevel,'=')!==false) {
272 $hlevel=strlen($hlevel);
275 $rv=$headline. $secs[$section*2];
279 while(!empty($secs[$count*2-1]) && !$break) {
281 $subheadline=$secs[$count*2-1];
282 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
283 $subhlevel=$matches[1];
284 if(strpos($subhlevel,'=')!==false) {
285 $subhlevel=strlen($subhlevel);
287 if($subhlevel > $hlevel) {
288 $rv.=$subheadline.$secs[$count*2];
290 if($subhlevel <= $hlevel) {
297 # reinsert stripped tags
298 $rv=$parser->unstrip($rv,$striparray);
299 $rv=$parser->unstripNoWiki($rv,$striparray);
306 * @return int The oldid of the article that is to be shown, 0 for the
309 function getOldID() {
310 if ( is_null( $this->mOldId
) ) {
311 $this->mOldId
= $this->getOldIDFromRequest();
313 return $this->mOldId
;
317 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
319 * @return int The old id for the request
321 function getOldIDFromRequest() {
323 $this->mRedirectUrl
= false;
324 $oldid = $wgRequest->getVal( 'oldid' );
325 if ( isset( $oldid ) ) {
326 $oldid = intval( $oldid );
327 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
328 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
332 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
334 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
335 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
351 * Load the revision (including text) into this object
353 function loadContent() {
354 global $wgOut, $wgRequest;
356 if ( $this->mContentLoaded
) return;
359 $oldid = $this->getOldID();
361 $fname = 'Article::loadContent';
363 # Pre-fill content with error message so that if something
364 # fails we'll have something telling us what we intended.
366 $t = $this->mTitle
->getPrefixedText();
368 $this->mOldId
= $oldid;
369 $this->fetchContent( $oldid );
374 * Fetch a page record with the given conditions
375 * @param Database $dbr
376 * @param array $conditions
379 function pageData( &$dbr, $conditions ) {
392 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
393 $row = $dbr->selectRow( 'page',
396 'Article::pageData' );
397 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
402 * @param Database $dbr
403 * @param Title $title
405 function pageDataFromTitle( &$dbr, $title ) {
406 return $this->pageData( $dbr, array(
407 'page_namespace' => $title->getNamespace(),
408 'page_title' => $title->getDBkey() ) );
412 * @param Database $dbr
415 function pageDataFromId( &$dbr, $id ) {
416 return $this->pageData( $dbr, array( 'page_id' => $id ) );
420 * Set the general counter, title etc data loaded from
423 * @param object $data
426 function loadPageData( $data ) {
427 $this->mTitle
->mArticleID
= $data->page_id
;
428 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
429 $this->mTitle
->mRestrictionsLoaded
= true;
431 $this->mCounter
= $data->page_counter
;
432 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
433 $this->mIsRedirect
= $data->page_is_redirect
;
434 $this->mLatest
= $data->page_latest
;
436 $this->mDataLoaded
= true;
440 * Get text of an article from database
441 * Does *NOT* follow redirects.
442 * @param int $oldid 0 for whatever the latest revision is
445 function fetchContent( $oldid = 0 ) {
446 if ( $this->mContentLoaded
) {
447 return $this->mContent
;
450 $dbr =& $this->getDB();
451 $fname = 'Article::fetchContent';
453 # Pre-fill content with error message so that if something
454 # fails we'll have something telling us what we intended.
455 $t = $this->mTitle
->getPrefixedText();
457 $t .= ',oldid='.$oldid;
459 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
462 $revision = Revision
::newFromId( $oldid );
463 if( is_null( $revision ) ) {
464 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
467 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
469 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
472 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
473 $this->loadPageData( $data );
475 if( !$this->mDataLoaded
) {
476 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
478 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
481 $this->loadPageData( $data );
483 $revision = Revision
::newFromId( $this->mLatest
);
484 if( is_null( $revision ) ) {
485 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
490 $this->mContent
= $revision->getText();
492 $this->mUser
= $revision->getUser();
493 $this->mUserText
= $revision->getUserText();
494 $this->mComment
= $revision->getComment();
495 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
497 $this->mRevIdFetched
= $revision->getID();
498 $this->mContentLoaded
= true;
499 $this->mRevision
=& $revision;
501 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
503 return $this->mContent
;
507 * Read/write accessor to select FOR UPDATE
511 function forUpdate( $x = NULL ) {
512 return wfSetVar( $this->mForUpdate
, $x );
516 * Get the database which should be used for reads
521 $ret =& wfGetDB( DB_MASTER
);
526 * Get options for all SELECT statements
528 * @param array $options an optional options array which'll be appended to
530 * @return array Options
532 function getSelectOptions( $options = '' ) {
533 if ( $this->mForUpdate
) {
534 if ( is_array( $options ) ) {
535 $options[] = 'FOR UPDATE';
537 $options = 'FOR UPDATE';
544 * @return int Page ID
547 if( $this->mTitle
) {
548 return $this->mTitle
->getArticleID();
555 * @return bool Whether or not the page exists in the database
558 return $this->getId() != 0;
562 * @return int The view count for the page
564 function getCount() {
565 if ( -1 == $this->mCounter
) {
566 $id = $this->getID();
567 $dbr =& wfGetDB( DB_SLAVE
);
568 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
569 'Article::getCount', $this->getSelectOptions() );
571 return $this->mCounter
;
575 * Determine whether a page would be suitable for being counted as an
576 * article in the site_stats table based on the title & its content
578 * @param string $text Text to analyze
581 function isCountable( $text ) {
582 global $wgUseCommaCount;
584 $token = $wgUseCommaCount ?
',' : '[[';
586 $this->mTitle
->getNamespace() == NS_MAIN
587 && ! $this->isRedirect( $text )
588 && in_string( $token, $text );
592 * Tests if the article text represents a redirect
594 * @param string $text
597 function isRedirect( $text = false ) {
598 if ( $text === false ) {
599 $this->loadContent();
600 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
602 $titleObj = Title
::newFromRedirect( $text );
604 return $titleObj !== NULL;
608 * Returns true if the currently-referenced revision is the current edit
609 * to this page (and it exists).
612 function isCurrent() {
613 return $this->exists() &&
614 isset( $this->mRevision
) &&
615 $this->mRevision
->isCurrent();
619 * Loads everything except the text
620 * This isn't necessary for all uses, so it's only done if needed.
623 function loadLastEdit() {
626 if ( -1 != $this->mUser
)
629 # New or non-existent articles have no user information
630 $id = $this->getID();
631 if ( 0 == $id ) return;
633 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
634 if( !is_null( $this->mLastRevision
) ) {
635 $this->mUser
= $this->mLastRevision
->getUser();
636 $this->mUserText
= $this->mLastRevision
->getUserText();
637 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
638 $this->mComment
= $this->mLastRevision
->getComment();
639 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
640 $this->mRevIdFetched
= $this->mLastRevision
->getID();
644 function getTimestamp() {
645 $this->loadLastEdit();
646 return wfTimestamp(TS_MW
, $this->mTimestamp
);
650 $this->loadLastEdit();
654 function getUserText() {
655 $this->loadLastEdit();
656 return $this->mUserText
;
659 function getComment() {
660 $this->loadLastEdit();
661 return $this->mComment
;
664 function getMinorEdit() {
665 $this->loadLastEdit();
666 return $this->mMinorEdit
;
669 function getRevIdFetched() {
670 $this->loadLastEdit();
671 return $this->mRevIdFetched
;
674 function getContributors($limit = 0, $offset = 0) {
675 $fname = 'Article::getContributors';
677 # XXX: this is expensive; cache this info somewhere.
679 $title = $this->mTitle
;
681 $dbr =& wfGetDB( DB_SLAVE
);
682 $revTable = $dbr->tableName( 'revision' );
683 $userTable = $dbr->tableName( 'user' );
684 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
685 $ns = $title->getNamespace();
686 $user = $this->getUser();
687 $pageId = $this->getId();
689 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
690 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
691 WHERE rev_page = $pageId
692 AND rev_user != $user
693 GROUP BY rev_user, rev_user_text, user_real_name
694 ORDER BY timestamp DESC";
696 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
697 $sql .= ' '. $this->getSelectOptions();
699 $res = $dbr->query($sql, $fname);
701 while ( $line = $dbr->fetchObject( $res ) ) {
702 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
705 $dbr->freeResult($res);
710 * This is the default action of the script: just view the page of
714 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
715 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
716 global $wgUseTrackbacks;
717 $sk = $wgUser->getSkin();
719 $fname = 'Article::view';
720 wfProfileIn( $fname );
721 $parserCache =& ParserCache
::singleton();
722 # Get variables from query string
723 $oldid = $this->getOldID();
725 # getOldID may want us to redirect somewhere else
726 if ( $this->mRedirectUrl
) {
727 $wgOut->redirect( $this->mRedirectUrl
);
728 wfProfileOut( $fname );
732 $diff = $wgRequest->getVal( 'diff' );
733 $rcid = $wgRequest->getVal( 'rcid' );
734 $rdfrom = $wgRequest->getVal( 'rdfrom' );
736 $wgOut->setArticleFlag( true );
737 $wgOut->setRobotpolicy( 'index,follow' );
738 # If we got diff and oldid in the query, we want to see a
739 # diff page instead of the article.
741 if ( !is_null( $diff ) ) {
742 require_once( 'DifferenceEngine.php' );
743 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
745 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
746 // DifferenceEngine directly fetched the revision:
747 $this->mRevIdFetched
= $de->mNewid
;
751 # Run view updates for current revision only
752 $this->viewUpdates();
754 wfProfileOut( $fname );
758 if ( empty( $oldid ) && $this->checkTouched() ) {
759 $wgOut->setETag($parserCache->getETag($this, $wgUser));
761 if( $wgOut->checkLastModified( $this->mTouched
) ){
762 wfProfileOut( $fname );
764 } else if ( $this->tryFileCache() ) {
765 # tell wgOut that output is taken care of
767 $this->viewUpdates();
768 wfProfileOut( $fname );
772 # Should the parser cache be used?
773 $pcache = $wgEnableParserCache &&
774 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
777 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
778 if ( $wgUser->getOption( 'stubthreshold' ) ) {
779 wfIncrStats( 'pcache_miss_stub' );
782 $wasRedirected = false;
783 if ( isset( $this->mRedirectedFrom
) ) {
784 // This is an internally redirected page view.
785 // We'll need a backlink to the source page for navigation.
786 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
787 $sk = $wgUser->getSkin();
788 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
789 $s = wfMsg( 'redirectedfrom', $redir );
790 $wgOut->setSubtitle( $s );
791 $wasRedirected = true;
793 } elseif ( !empty( $rdfrom ) ) {
794 // This is an externally redirected view, from some other wiki.
795 // If it was reported from a trusted site, supply a backlink.
796 global $wgRedirectSources;
797 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
798 $sk = $wgUser->getSkin();
799 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
800 $s = wfMsg( 'redirectedfrom', $redir );
801 $wgOut->setSubtitle( $s );
802 $wasRedirected = true;
808 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
812 if ( !$outputDone ) {
813 $text = $this->getContent();
814 if ( $text === false ) {
815 # Failed to load, replace text with error message
816 $t = $this->mTitle
->getPrefixedText();
818 $t .= ',oldid='.$oldid;
820 $text = wfMsg( 'missingarticle', $t );
823 # Another whitelist check in case oldid is altering the title
824 if ( !$this->mTitle
->userCanRead() ) {
825 $wgOut->loginToUse();
830 # We're looking at an old revision
832 if ( !empty( $oldid ) ) {
833 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
834 $wgOut->setRobotpolicy( 'noindex,follow' );
839 * @fixme: this hook doesn't work most of the time, as it doesn't
840 * trigger when the parser cache is used.
842 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
843 $wgOut->setRevisionId( $this->getRevIdFetched() );
844 # wrap user css and user js in pre and don't parse
845 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
847 $this->mTitle
->getNamespace() == NS_USER
&&
848 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
850 $wgOut->addWikiText( wfMsg('clearyourcache'));
851 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
852 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
854 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
855 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
856 if( !$wasRedirected ) {
857 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
859 $targetUrl = $rt->escapeLocalURL();
860 $titleText = htmlspecialchars( $rt->getPrefixedText() );
861 $link = $sk->makeLinkObj( $rt );
863 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
864 '<span class="redirectText">'.$link.'</span>' );
866 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
867 $wgOut->addParserOutputNoText( $parseout );
868 } else if ( $pcache ) {
869 # Display content and save to parser cache
870 $wgOut->addPrimaryWikiText( $text, $this );
872 # Display content, don't attempt to save to parser cache
874 # Don't show section-edit links on old revisions... this way lies madness.
875 if( !$this->isCurrent() ) {
876 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
878 # Display content and don't save to parser cache
879 $wgOut->addPrimaryWikiText( $text, $this, false );
881 if( !$this->isCurrent() ) {
882 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
886 /* title may have been set from the cache */
887 $t = $wgOut->getPageTitle();
889 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
892 # If we have been passed an &rcid= parameter, we want to give the user a
893 # chance to mark this new article as patrolled.
897 && $wgUser->isLoggedIn()
898 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
901 "<div class='patrollink'>" .
902 wfMsg ( 'markaspatrolledlink',
903 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
910 if ($wgUseTrackbacks)
911 $this->addTrackbacks();
913 $this->viewUpdates();
914 wfProfileOut( $fname );
917 function addTrackbacks() {
918 global $wgOut, $wgUser;
920 $dbr =& wfGetDB(DB_SLAVE
);
922 /* FROM */ 'trackbacks',
923 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
924 /* WHERE */ array('tb_page' => $this->getID())
927 if (!$dbr->numrows($tbs))
931 while ($o = $dbr->fetchObject($tbs)) {
933 if ($wgUser->isSysop()) {
934 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
935 . $o->tb_id
. "&token=" . $wgUser->editToken());
936 $rmvtxt = wfMsg('trackbackremove', $delurl);
938 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
945 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
948 function deletetrackback() {
949 global $wgUser, $wgRequest, $wgOut, $wgTitle;
951 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
952 $wgOut->addWikitext(wfMsg('sessionfailure'));
956 if ((!$wgUser->isAllowed('delete'))) {
957 $wgOut->sysopRequired();
962 $wgOut->readOnlyPage();
966 $db =& wfGetDB(DB_MASTER
);
967 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
968 $wgTitle->invalidateCache();
969 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
975 $wgOut->setArticleBodyOnly(true);
980 global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
982 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ||
! wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
983 // Invalidate the cache
984 $this->mTitle
->invalidateCache();
987 // Commit the transaction before the purge is sent
988 $dbw = wfGetDB( DB_MASTER
);
989 $dbw->immediateCommit();
992 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
997 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
998 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
999 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
1000 $msg = str_replace( '$1',
1001 "<form method=\"post\" action=\"$action\">\n" .
1002 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
1003 "</form>\n", $msg );
1005 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
1006 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1007 $wgOut->addHTML( $msg );
1012 * Insert a new empty page record for this article.
1013 * This *must* be followed up by creating a revision
1014 * and running $this->updateToLatest( $rev_id );
1015 * or else the record will be left in a funky state.
1016 * Best if all done inside a transaction.
1018 * @param Database $dbw
1019 * @param string $restrictions
1020 * @return int The newly created page_id key
1023 function insertOn( &$dbw, $restrictions = '' ) {
1024 $fname = 'Article::insertOn';
1025 wfProfileIn( $fname );
1027 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1028 $dbw->insert( 'page', array(
1029 'page_id' => $page_id,
1030 'page_namespace' => $this->mTitle
->getNamespace(),
1031 'page_title' => $this->mTitle
->getDBkey(),
1032 'page_counter' => 0,
1033 'page_restrictions' => $restrictions,
1034 'page_is_redirect' => 0, # Will set this shortly...
1036 'page_random' => wfRandom(),
1037 'page_touched' => $dbw->timestamp(),
1038 'page_latest' => 0, # Fill this in shortly...
1039 'page_len' => 0, # Fill this in shortly...
1041 $newid = $dbw->insertId();
1043 $this->mTitle
->resetArticleId( $newid );
1045 wfProfileOut( $fname );
1050 * Update the page record to point to a newly saved revision.
1052 * @param Database $dbw
1053 * @param Revision $revision For ID number, and text used to set
1054 length and redirect status fields
1055 * @param int $lastRevision If given, will not overwrite the page field
1056 * when different from the currently set value.
1057 * Giving 0 indicates the new page flag should
1059 * @return bool true on success, false on failure
1062 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1063 $fname = 'Article::updateToRevision';
1064 wfProfileIn( $fname );
1066 $conditions = array( 'page_id' => $this->getId() );
1067 if( !is_null( $lastRevision ) ) {
1068 # An extra check against threads stepping on each other
1069 $conditions['page_latest'] = $lastRevision;
1072 $text = $revision->getText();
1073 $dbw->update( 'page',
1075 'page_latest' => $revision->getId(),
1076 'page_touched' => $dbw->timestamp(),
1077 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1078 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1079 'page_len' => strlen( $text ),
1084 wfProfileOut( $fname );
1085 return ( $dbw->affectedRows() != 0 );
1089 * If the given revision is newer than the currently set page_latest,
1090 * update the page record. Otherwise, do nothing.
1092 * @param Database $dbw
1093 * @param Revision $revision
1095 function updateIfNewerOn( &$dbw, $revision ) {
1096 $fname = 'Article::updateIfNewerOn';
1097 wfProfileIn( $fname );
1099 $row = $dbw->selectRow(
1100 array( 'revision', 'page' ),
1101 array( 'rev_id', 'rev_timestamp' ),
1103 'page_id' => $this->getId(),
1104 'page_latest=rev_id' ),
1107 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1108 wfProfileOut( $fname );
1111 $prev = $row->rev_id
;
1113 # No or missing previous revision; mark the page as new
1117 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1118 wfProfileOut( $fname );
1123 * Theoretically we could defer these whole insert and update
1124 * functions for after display, but that's taking a big leap
1125 * of faith, and we want to be able to report database
1126 * errors at some point.
1129 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1130 global $wgOut, $wgUser, $wgUseSquid;
1132 $fname = 'Article::insertNewArticle';
1133 wfProfileIn( $fname );
1135 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1136 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1137 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1138 wfProfileOut( $fname );
1142 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1143 $this->mTotalAdjustment
= 1;
1145 $ns = $this->mTitle
->getNamespace();
1146 $ttl = $this->mTitle
->getDBkey();
1148 # If this is a comment, add the summary as headline
1149 if($comment && $summary!="") {
1150 $text="== {$summary} ==\n\n".$text;
1152 $text = $this->preSaveTransform( $text );
1154 /* Silently ignore minoredit if not allowed */
1155 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1156 $now = wfTimestampNow();
1158 $dbw =& wfGetDB( DB_MASTER
);
1160 # Add the page record; stake our claim on this title!
1161 $newid = $this->insertOn( $dbw );
1163 # Save the revision text...
1164 $revision = new Revision( array(
1166 'comment' => $summary,
1167 'minor_edit' => $isminor,
1170 $revisionId = $revision->insertOn( $dbw );
1172 $this->mTitle
->resetArticleID( $newid );
1174 # Update the page record with revision data
1175 $this->updateRevisionOn( $dbw, $revision, 0 );
1177 Article
::onArticleCreate( $this->mTitle
);
1179 require_once( 'RecentChange.php' );
1180 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1181 '', strlen( $text ), $revisionId );
1185 if(!$this->mTitle
->userIsWatching()) $this->watch();
1187 if ( $this->mTitle
->userIsWatching() ) {
1192 # The talk page isn't in the regular link tables, so we need to update manually:
1193 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1194 $dbw->update( 'page',
1195 array( 'page_touched' => $dbw->timestamp($now) ),
1196 array( 'page_namespace' => $talkns,
1197 'page_title' => $ttl ),
1200 # standard deferred updates
1201 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1203 $oldid = 0; # new article
1204 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1206 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1208 $watchthis, NULL ) );
1209 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1211 $watchthis, NULL ) );
1212 wfProfileOut( $fname );
1215 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1216 $this->replaceSection( $section, $text, $summary, $edittime );
1220 * @return string Complete article text, or null if error
1222 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1223 $fname = 'Article::replaceSection';
1224 wfProfileIn( $fname );
1226 if ($section != '') {
1227 if( is_null( $edittime ) ) {
1228 $rev = Revision
::newFromTitle( $this->mTitle
);
1230 $dbw =& wfGetDB( DB_MASTER
);
1231 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1233 if( is_null( $rev ) ) {
1234 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1235 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1238 $oldtext = $rev->getText();
1240 if($section=='new') {
1241 if($summary) $subject="== {$summary} ==\n\n";
1242 $text=$oldtext."\n\n".$subject.$text;
1245 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1246 # comments to be stripped as well)
1247 $striparray=array();
1248 $parser=new Parser();
1249 $parser->mOutputType
=OT_WIKI
;
1250 $parser->mOptions
= new ParserOptions();
1251 $oldtext=$parser->strip($oldtext, $striparray, true);
1253 # now that we can be sure that no pseudo-sections are in the source,
1255 # Unfortunately we can't simply do a preg_replace because that might
1256 # replace the wrong section, so we have to use the section counter instead
1257 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
1258 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1259 $secs[$section*2]=$text."\n\n"; // replace with edited
1261 # section 0 is top (intro) section
1264 # headline of old section - we need to go through this section
1265 # to determine if there are any subsections that now need to
1266 # be erased, as the mother section has been replaced with
1267 # the text of all subsections.
1268 $headline=$secs[$section*2-1];
1269 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
1270 $hlevel=$matches[1];
1272 # determine headline level for wikimarkup headings
1273 if(strpos($hlevel,'=')!==false) {
1274 $hlevel=strlen($hlevel);
1277 $secs[$section*2-1]=''; // erase old headline
1280 while(!empty($secs[$count*2-1]) && !$break) {
1282 $subheadline=$secs[$count*2-1];
1284 '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
1285 $subhlevel=$matches[1];
1286 if(strpos($subhlevel,'=')!==false) {
1287 $subhlevel=strlen($subhlevel);
1289 if($subhlevel > $hlevel) {
1290 // erase old subsections
1291 $secs[$count*2-1]='';
1294 if($subhlevel <= $hlevel) {
1302 $text=join('',$secs);
1303 # reinsert the stuff that we stripped out earlier
1304 $text=$parser->unstrip($text,$striparray);
1305 $text=$parser->unstripNoWiki($text,$striparray);
1309 wfProfileOut( $fname );
1314 * Change an existing article. Puts the previous version back into the old table, updates RC
1315 * and all necessary caches, mostly via the deferred update array.
1317 * It is possible to call this function from a command-line script, but note that you should
1318 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1320 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1321 global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
1322 global $wgPostCommitUpdateList, $wgUseFileCache;
1324 $fname = 'Article::updateArticle';
1325 wfProfileIn( $fname );
1328 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1330 &$watchthis, &$sectionanchor ) ) ) {
1331 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1332 wfProfileOut( $fname );
1336 $isminor = $minor && $wgUser->isAllowed('minoredit');
1337 $redir = (int)$this->isRedirect( $text );
1339 $text = $this->preSaveTransform( $text );
1340 $dbw =& wfGetDB( DB_MASTER
);
1341 $now = wfTimestampNow();
1343 # Update article, but only if changed.
1345 # It's important that we either rollback or complete, otherwise an attacker could
1346 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1347 # could conceivably have the same effect, especially if cur is locked for long periods.
1348 if( !$wgDBtransactions ) {
1349 $userAbort = ignore_user_abort( true );
1352 $oldtext = $this->getContent();
1353 $oldsize = strlen( $oldtext );
1354 $newsize = strlen( $text );
1358 if ( 0 != strcmp( $text, $oldtext ) ) {
1359 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1360 - (int)$this->isCountable( $oldtext );
1361 $this->mTotalAdjustment
= 0;
1362 $now = wfTimestampNow();
1364 $lastRevision = $dbw->selectField(
1365 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1367 $revision = new Revision( array(
1368 'page' => $this->getId(),
1369 'comment' => $summary,
1370 'minor_edit' => $isminor,
1374 $dbw->immediateCommit();
1376 $revisionId = $revision->insertOn( $dbw );
1379 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1382 /* Belated edit conflict! Run away!! */
1386 # Update recentchanges and purge cache and whatnot
1387 require_once( 'RecentChange.php' );
1388 $bot = (int)($wgUser->isBot() ||
$forceBot);
1389 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1390 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1394 // Update caches outside the main transaction
1395 Article
::onArticleEdit( $this->mTitle
);
1398 // Keep the same revision ID, but do some updates on it
1399 $revisionId = $this->getRevIdFetched();
1402 if( !$wgDBtransactions ) {
1403 ignore_user_abort( $userAbort );
1408 if (!$this->mTitle
->userIsWatching()) {
1409 $dbw->immediateCommit();
1415 if ( $this->mTitle
->userIsWatching() ) {
1416 $dbw->immediateCommit();
1422 # standard deferred updates
1423 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1427 # Invalidate caches of all articles using this article as a template
1429 # Template namespace
1430 # Purge all articles linking here
1431 $titles = $this->mTitle
->getTemplateLinksTo();
1432 Title
::touchArray( $titles );
1433 if ( $wgUseSquid ) {
1434 foreach ( $titles as $title ) {
1435 $urls[] = $title->getInternalURL();
1440 if ( $wgUseSquid ) {
1441 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1442 $u = new SquidUpdate( $urls );
1443 array_push( $wgPostCommitUpdateList, $u );
1447 if ( $wgUseFileCache ) {
1448 $cm = new CacheManager($this->mTitle
);
1449 @unlink
($cm->fileCacheName());
1452 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1454 wfRunHooks( 'ArticleSaveComplete',
1455 array( &$this, &$wgUser, $text,
1457 $watchthis, $sectionanchor ) );
1458 wfProfileOut( $fname );
1463 * After we've either updated or inserted the article, update
1464 * the link tables and redirect to the new page.
1466 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1467 global $wgOut, $wgUser;
1468 global $wgUseEnotif;
1470 $fname = 'Article::showArticle';
1471 wfProfileIn( $fname );
1473 # Output the redirect
1474 if( $this->isRedirect( $text ) )
1478 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1480 wfProfileOut( $fname );
1484 * Mark this particular edit as patrolled
1486 function markpatrolled() {
1487 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1488 $wgOut->setRobotpolicy( 'noindex,follow' );
1490 # Check RC patrol config. option
1491 if( !$wgUseRCPatrol ) {
1492 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1497 if( $wgUser->isLoggedIn() ) {
1498 if( !$wgUser->isAllowed( 'patrol' ) ) {
1499 $wgOut->permissionRequired( 'patrol' );
1503 $wgOut->loginToUse();
1507 $rcid = $wgRequest->getVal( 'rcid' );
1508 if ( !is_null ( $rcid ) )
1510 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) ) ) {
1511 require_once( 'RecentChange.php' );
1512 RecentChange
::markPatrolled( $rcid );
1513 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, $wgOnlySysopsCanPatrol ) );
1514 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1515 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1517 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1518 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1522 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1527 * Add this page to $wgUser's watchlist
1532 global $wgUser, $wgOut;
1534 if ( $wgUser->isAnon() ) {
1535 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1538 if ( wfReadOnly() ) {
1539 $wgOut->readOnlyPage();
1543 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1545 $wgUser->addWatch( $this->mTitle
);
1546 $wgUser->saveSettings();
1548 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1550 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1551 $wgOut->setRobotpolicy( 'noindex,follow' );
1553 $link = $this->mTitle
->getPrefixedText();
1554 $text = wfMsg( 'addedwatchtext', $link );
1555 $wgOut->addWikiText( $text );
1558 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1562 * Stop watching a page
1565 function unwatch() {
1567 global $wgUser, $wgOut;
1569 if ( $wgUser->isAnon() ) {
1570 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1573 if ( wfReadOnly() ) {
1574 $wgOut->readOnlyPage();
1578 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1580 $wgUser->removeWatch( $this->mTitle
);
1581 $wgUser->saveSettings();
1583 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1585 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1586 $wgOut->setRobotpolicy( 'noindex,follow' );
1588 $link = $this->mTitle
->getPrefixedText();
1589 $text = wfMsg( 'removedwatchtext', $link );
1590 $wgOut->addWikiText( $text );
1593 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1597 * action=protect handler
1599 function protect() {
1600 require_once 'ProtectionForm.php';
1601 $form = new ProtectionForm( $this );
1606 * action=unprotect handler (alias)
1608 function unprotect() {
1613 * Update the article's restriction field, and leave a log entry.
1615 * @param array $limit set of restriction keys
1616 * @param string $reason
1617 * @return bool true on success
1619 function updateRestrictions( $limit = array(), $reason = '' ) {
1620 global $wgUser, $wgOut, $wgRequest;
1622 if ( !$wgUser->isAllowed( 'protect' ) ) {
1626 if( wfReadOnly() ) {
1630 $id = $this->mTitle
->getArticleID();
1635 $flat = Article
::flattenRestrictions( $limit );
1636 $protecting = ($flat != '');
1638 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser,
1639 $limit, $reason ) ) ) {
1641 $dbw =& wfGetDB( DB_MASTER
);
1642 $dbw->update( 'page',
1644 'page_touched' => $dbw->timestamp(),
1645 'page_restrictions' => $flat
1646 ), array( /* WHERE */
1648 ), 'Article::protect'
1651 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser,
1652 $limit, $reason ) );
1654 $log = new LogPage( 'protect' );
1656 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$flat]" ) );
1658 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1665 * Take an array of page restrictions and flatten it to a string
1666 * suitable for insertion into the page_restrictions field.
1667 * @param array $limit
1671 function flattenRestrictions( $limit ) {
1672 if( !is_array( $limit ) ) {
1673 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1676 foreach( $limit as $action => $restrictions ) {
1677 if( $restrictions != '' ) {
1678 $bits[] = "$action=$restrictions";
1681 return implode( ':', $bits );
1685 * UI entry point for page deletion
1688 global $wgUser, $wgOut, $wgRequest;
1689 $fname = 'Article::delete';
1690 $confirm = $wgRequest->wasPosted() &&
1691 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1692 $reason = $wgRequest->getText( 'wpReason' );
1694 # This code desperately needs to be totally rewritten
1697 if( $wgUser->isAllowed( 'delete' ) ) {
1698 if( $wgUser->isBlocked() ) {
1699 $wgOut->blockedPage();
1703 $wgOut->permissionRequired( 'delete' );
1707 if( wfReadOnly() ) {
1708 $wgOut->readOnlyPage();
1712 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1714 # Better double-check that it hasn't been deleted yet!
1715 $dbw =& wfGetDB( DB_MASTER
);
1716 $conds = $this->mTitle
->pageCond();
1717 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1718 if ( $latest === false ) {
1719 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1724 $this->doDelete( $reason );
1728 # determine whether this page has earlier revisions
1729 # and insert a warning if it does
1731 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1733 if( count( $authors ) > 1 && !$confirm ) {
1734 $skin=$wgUser->getSkin();
1735 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1736 $wgOut->addHTML( $skin->historyLink() .'</b>');
1739 # If a single user is responsible for all revisions, find out who they are
1740 if ( count( $authors ) == $maxRevisions ) {
1741 // Query bailed out, too many revisions to find out if they're all the same
1742 $authorOfAll = false;
1744 $authorOfAll = reset( $authors );
1745 foreach ( $authors as $author ) {
1746 if ( $authorOfAll != $author ) {
1747 $authorOfAll = false;
1752 # Fetch article text
1753 $rev = Revision
::newFromTitle( $this->mTitle
);
1755 if( !is_null( $rev ) ) {
1756 # if this is a mini-text, we can paste part of it into the deletion reason
1757 $text = $rev->getText();
1759 #if this is empty, an earlier revision may contain "useful" text
1762 $prev = $rev->getPrevious();
1764 $text = $prev->getText();
1769 $length = strlen( $text );
1771 # this should not happen, since it is not possible to store an empty, new
1772 # page. Let's insert a standard text in case it does, though
1773 if( $length == 0 && $reason === '' ) {
1774 $reason = wfMsgForContent( 'exblank' );
1777 if( $length < 500 && $reason === '' ) {
1778 # comment field=255, let's grep the first 150 to have some user
1781 $text = $wgContLang->truncate( $text, 150, '...' );
1783 # let's strip out newlines
1784 $text = preg_replace( "/[\n\r]/", '', $text );
1787 if( $authorOfAll === false ) {
1788 $reason = wfMsgForContent( 'excontent', $text );
1790 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1793 $reason = wfMsgForContent( 'exbeforeblank', $text );
1798 return $this->confirmDelete( '', $reason );
1802 * Get the last N authors
1803 * @param int $num Number of revisions to get
1804 * @param string $revLatest The latest rev_id, selected from the master (optional)
1805 * @return array Array of authors, duplicates not removed
1807 function getLastNAuthors( $num, $revLatest = 0 ) {
1808 $fname = 'Article::getLastNAuthors';
1809 wfProfileIn( $fname );
1811 // First try the slave
1812 // If that doesn't have the latest revision, try the master
1814 $db =& wfGetDB( DB_SLAVE
);
1816 $res = $db->select( array( 'page', 'revision' ),
1817 array( 'rev_id', 'rev_user_text' ),
1819 'page_namespace' => $this->mTitle
->getNamespace(),
1820 'page_title' => $this->mTitle
->getDBkey(),
1821 'rev_page = page_id'
1822 ), $fname, $this->getSelectOptions( array(
1823 'ORDER BY' => 'rev_timestamp DESC',
1828 wfProfileOut( $fname );
1831 $row = $db->fetchObject( $res );
1832 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1833 $db =& wfGetDB( DB_MASTER
);
1838 } while ( $continue );
1840 $authors = array( $row->rev_user_text
);
1841 while ( $row = $db->fetchObject( $res ) ) {
1842 $authors[] = $row->rev_user_text
;
1844 wfProfileOut( $fname );
1849 * Output deletion confirmation dialog
1851 function confirmDelete( $par, $reason ) {
1852 global $wgOut, $wgUser;
1854 wfDebug( "Article::confirmDelete\n" );
1856 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1857 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1858 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1859 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1861 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1863 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1864 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1865 $token = htmlspecialchars( $wgUser->editToken() );
1868 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1872 <label for='wpReason'>{$delcom}:</label>
1875 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1881 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1885 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1888 $wgOut->returnToMain( false );
1893 * Perform a deletion and output success or failure messages
1895 function doDelete( $reason ) {
1896 global $wgOut, $wgUser, $wgContLang;
1897 $fname = 'Article::doDelete';
1898 wfDebug( $fname."\n" );
1900 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1901 if ( $this->doDeleteArticle( $reason ) ) {
1902 $deleted = $this->mTitle
->getPrefixedText();
1904 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1905 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1907 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1908 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1910 $wgOut->addWikiText( $text );
1911 $wgOut->returnToMain( false );
1912 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1914 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1920 * Back-end article deletion
1921 * Deletes the article with database consistency, writes logs, purges caches
1924 function doDeleteArticle( $reason ) {
1925 global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
1926 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1928 $fname = 'Article::doDeleteArticle';
1929 wfDebug( $fname."\n" );
1931 $dbw =& wfGetDB( DB_MASTER
);
1932 $ns = $this->mTitle
->getNamespace();
1933 $t = $this->mTitle
->getDBkey();
1934 $id = $this->mTitle
->getArticleID();
1936 if ( $t == '' ||
$id == 0 ) {
1940 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1941 array_push( $wgDeferredUpdateList, $u );
1943 $linksTo = $this->mTitle
->getLinksTo();
1946 if ( $wgUseSquid ) {
1948 $this->mTitle
->getInternalURL(),
1949 $this->mTitle
->getInternalURL( 'history' )
1952 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1953 array_push( $wgPostCommitUpdateList, $u );
1957 # Client and file cache invalidation
1958 Title
::touchArray( $linksTo );
1961 // For now, shunt the revision data into the archive table.
1962 // Text is *not* removed from the text table; bulk storage
1963 // is left intact to avoid breaking block-compression or
1964 // immutable storage schemes.
1966 // For backwards compatibility, note that some older archive
1967 // table entries will have ar_text and ar_flags fields still.
1969 // In the future, we may keep revisions and mark them with
1970 // the rev_deleted field, which is reserved for this purpose.
1971 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1973 'ar_namespace' => 'page_namespace',
1974 'ar_title' => 'page_title',
1975 'ar_comment' => 'rev_comment',
1976 'ar_user' => 'rev_user',
1977 'ar_user_text' => 'rev_user_text',
1978 'ar_timestamp' => 'rev_timestamp',
1979 'ar_minor_edit' => 'rev_minor_edit',
1980 'ar_rev_id' => 'rev_id',
1981 'ar_text_id' => 'rev_text_id',
1984 'page_id = rev_page'
1988 # Now that it's safely backed up, delete it
1989 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1990 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1992 if ($wgUseTrackbacks)
1993 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1995 # Clean up recentchanges entries...
1996 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1998 # Finally, clean up the link tables
1999 $t = $this->mTitle
->getPrefixedDBkey();
2001 Article
::onArticleDelete( $this->mTitle
);
2003 # Delete outgoing links
2004 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2005 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2006 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2009 $log = new LogPage( 'delete' );
2010 $log->addEntry( 'delete', $this->mTitle
, $reason );
2012 # Clear the cached article id so the interface doesn't act like we exist
2013 $this->mTitle
->resetArticleID( 0 );
2014 $this->mTitle
->mArticleID
= 0;
2019 * Revert a modification
2021 function rollback() {
2022 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2023 $fname = 'Article::rollback';
2025 if( $wgUser->isAllowed( 'rollback' ) ) {
2026 if( $wgUser->isBlocked() ) {
2027 $wgOut->blockedPage();
2031 $wgOut->permissionRequired( 'rollback' );
2035 if ( wfReadOnly() ) {
2036 $wgOut->readOnlyPage( $this->getContent() );
2039 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2040 array( $this->mTitle
->getPrefixedText(),
2041 $wgRequest->getVal( 'from' ) ) ) ) {
2042 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2043 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2046 $dbw =& wfGetDB( DB_MASTER
);
2048 # Enhanced rollback, marks edits rc_bot=1
2049 $bot = $wgRequest->getBool( 'bot' );
2051 # Replace all this user's current edits with the next one down
2052 $tt = $this->mTitle
->getDBKey();
2053 $n = $this->mTitle
->getNamespace();
2055 # Get the last editor, lock table exclusively
2057 $current = Revision
::newFromTitle( $this->mTitle
);
2058 if( is_null( $current ) ) {
2059 # Something wrong... no page?
2061 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2065 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2066 if( $from != $current->getUserText() ) {
2067 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2068 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2069 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2070 htmlspecialchars( $from ),
2071 htmlspecialchars( $current->getUserText() ) ) );
2072 if( $current->getComment() != '') {
2074 wfMsg( 'editcomment',
2075 htmlspecialchars( $current->getComment() ) ) );
2080 # Get the last edit not by this guy
2081 $user = intval( $current->getUser() );
2082 $user_text = $dbw->addQuotes( $current->getUserText() );
2083 $s = $dbw->selectRow( 'revision',
2084 array( 'rev_id', 'rev_timestamp' ),
2086 'rev_page' => $current->getPage(),
2087 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2090 'USE INDEX' => 'page_timestamp',
2091 'ORDER BY' => 'rev_timestamp DESC' )
2093 if( $s === false ) {
2096 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2097 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2103 # Mark all reverted edits as bot
2106 if ( $wgUseRCPatrol ) {
2107 # Mark all reverted edits as patrolled
2108 $set['rc_patrolled'] = 1;
2112 $dbw->update( 'recentchanges', $set,
2114 'rc_cur_id' => $current->getPage(),
2115 'rc_user_text' => $current->getUserText(),
2116 "rc_timestamp > '{$s->rev_timestamp}'",
2121 # Get the edit summary
2122 $target = Revision
::newFromId( $s->rev_id
);
2123 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2124 $newComment = $wgRequest->getText( 'summary', $newComment );
2127 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2128 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2129 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2131 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2132 Article
::onArticleEdit( $this->mTitle
);
2135 $wgOut->returnToMain( false );
2140 * Do standard deferred updates after page view
2143 function viewUpdates() {
2144 global $wgDeferredUpdateList;
2146 if ( 0 != $this->getID() ) {
2147 global $wgDisableCounters;
2148 if( !$wgDisableCounters ) {
2149 Article
::incViewCount( $this->getID() );
2150 $u = new SiteStatsUpdate( 1, 0, 0 );
2151 array_push( $wgDeferredUpdateList, $u );
2155 # Update newtalk / watchlist notification status
2157 $wgUser->clearNotification( $this->mTitle
);
2161 * Do standard deferred updates after page edit.
2162 * Every 1000th edit, prune the recent changes table.
2164 * @param string $text
2166 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2167 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2169 $fname = 'Article::editUpdates';
2170 wfProfileIn( $fname );
2173 $options = new ParserOptions
;
2174 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2176 # Save it to the parser cache
2177 $parserCache =& ParserCache
::singleton();
2178 $parserCache->save( $poutput, $this, $wgUser );
2180 # Update the links tables
2181 $u = new LinksUpdate( $this->mTitle
, $poutput );
2184 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2186 if ( 0 == mt_rand( 0, 999 ) ) {
2187 # Periodically flush old entries from the recentchanges table.
2190 $dbw =& wfGetDB( DB_MASTER
);
2191 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2192 $recentchanges = $dbw->tableName( 'recentchanges' );
2193 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2194 $dbw->query( $sql );
2198 $id = $this->getID();
2199 $title = $this->mTitle
->getPrefixedDBkey();
2200 $shortTitle = $this->mTitle
->getDBkey();
2203 wfProfileOut( $fname );
2207 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2208 array_push( $wgDeferredUpdateList, $u );
2209 $u = new SearchUpdate( $id, $title, $text );
2210 array_push( $wgDeferredUpdateList, $u );
2212 # If this is another user's talk page, update newtalk
2214 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2215 $other = User
::newFromName( $shortTitle );
2216 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2217 // An anonymous user
2218 $other = new User();
2219 $other->setName( $shortTitle );
2222 $other->setNewtalk( true );
2226 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2227 $wgMessageCache->replace( $shortTitle, $text );
2230 wfProfileOut( $fname );
2234 * Generate the navigation links when browsing through an article revisions
2235 * It shows the information as:
2236 * Revision as of <date>; view current revision
2237 * <- Previous version | Next Version ->
2240 * @param string $oldid Revision ID of this article revision
2242 function setOldSubtitle( $oldid=0 ) {
2243 global $wgLang, $wgOut, $wgUser;
2245 $current = ( $oldid == $this->mLatest
);
2246 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2247 $sk = $wgUser->getSkin();
2249 ?
wfMsg( 'currentrevisionlink' )
2250 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2251 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2253 ?
$sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2254 : wfMsg( 'previousrevision' );
2255 $nextlink = $current
2256 ?
wfMsg( 'nextrevision' )
2257 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2258 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2259 $wgOut->setSubtitle( $r );
2263 * This function is called right before saving the wikitext,
2264 * so we can do things like signatures and links-in-context.
2266 * @param string $text
2268 function preSaveTransform( $text ) {
2269 global $wgParser, $wgUser;
2270 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2273 /* Caching functions */
2276 * checkLastModified returns true if it has taken care of all
2277 * output to the client that is necessary for this request.
2278 * (that is, it has sent a cached version of the page)
2280 function tryFileCache() {
2281 static $called = false;
2283 wfDebug( " tryFileCache() -- called twice!?\n" );
2287 if($this->isFileCacheable()) {
2288 $touched = $this->mTouched
;
2289 $cache = new CacheManager( $this->mTitle
);
2290 if($cache->isFileCacheGood( $touched )) {
2292 wfDebug( " tryFileCache() - about to load\n" );
2293 $cache->loadFromFileCache();
2296 wfDebug( " tryFileCache() - starting buffer\n" );
2297 ob_start( array(&$cache, 'saveToFileCache' ) );
2300 wfDebug( " tryFileCache() - not cacheable\n" );
2305 * Check if the page can be cached
2308 function isFileCacheable() {
2309 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2310 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2312 return $wgUseFileCache
2313 and (!$wgShowIPinHeader)
2314 and ($this->getID() != 0)
2315 and ($wgUser->isAnon())
2316 and (!$wgUser->getNewtalk())
2317 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2318 and (empty( $action ) ||
$action == 'view')
2319 and (!isset($oldid))
2321 and (!isset($redirect))
2322 and (!isset($printable))
2323 and (!$this->mRedirectedFrom
);
2327 * Loads page_touched and returns a value indicating if it should be used
2330 function checkTouched() {
2331 $fname = 'Article::checkTouched';
2332 if( !$this->mDataLoaded
) {
2333 $dbr =& $this->getDB();
2334 $data = $this->pageDataFromId( $dbr, $this->getId() );
2336 $this->loadPageData( $data );
2339 return !$this->mIsRedirect
;
2343 * Get the page_touched field
2345 function getTouched() {
2346 # Ensure that page data has been loaded
2347 if( !$this->mDataLoaded
) {
2348 $dbr =& $this->getDB();
2349 $data = $this->pageDataFromId( $dbr, $this->getId() );
2351 $this->loadPageData( $data );
2354 return $this->mTouched
;
2358 * Edit an article without doing all that other stuff
2359 * The article must already exist; link tables etc
2360 * are not updated, caches are not flushed.
2362 * @param string $text text submitted
2363 * @param string $comment comment submitted
2364 * @param bool $minor whereas it's a minor modification
2366 function quickEdit( $text, $comment = '', $minor = 0 ) {
2367 $fname = 'Article::quickEdit';
2368 wfProfileIn( $fname );
2370 $dbw =& wfGetDB( DB_MASTER
);
2372 $revision = new Revision( array(
2373 'page' => $this->getId(),
2375 'comment' => $comment,
2376 'minor_edit' => $minor ?
1 : 0,
2378 $revisionId = $revision->insertOn( $dbw );
2379 $this->updateRevisionOn( $dbw, $revision );
2382 wfProfileOut( $fname );
2386 * Used to increment the view counter
2389 * @param integer $id article id
2391 function incViewCount( $id ) {
2392 $id = intval( $id );
2393 global $wgHitcounterUpdateFreq;
2395 $dbw =& wfGetDB( DB_MASTER
);
2396 $pageTable = $dbw->tableName( 'page' );
2397 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2398 $acchitsTable = $dbw->tableName( 'acchits' );
2400 if( $wgHitcounterUpdateFreq <= 1 ){ //
2401 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2405 # Not important enough to warrant an error page in case of failure
2406 $oldignore = $dbw->ignoreErrors( true );
2408 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2410 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2411 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2412 # Most of the time (or on SQL errors), skip row count check
2413 $dbw->ignoreErrors( $oldignore );
2417 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2418 $row = $dbw->fetchObject( $res );
2419 $rown = intval( $row->n
);
2420 if( $rown >= $wgHitcounterUpdateFreq ){
2421 wfProfileIn( 'Article::incViewCount-collect' );
2422 $old_user_abort = ignore_user_abort( true );
2424 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2425 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2426 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2428 $dbw->query("DELETE FROM $hitcounterTable");
2429 $dbw->query('UNLOCK TABLES');
2430 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2431 'WHERE page_id = hc_id');
2432 $dbw->query("DROP TABLE $acchitsTable");
2434 ignore_user_abort( $old_user_abort );
2435 wfProfileOut( 'Article::incViewCount-collect' );
2437 $dbw->ignoreErrors( $oldignore );
2441 * The onArticle*() functions are supposed to be a kind of hooks
2442 * which should be called whenever any of the specified actions
2445 * This is a good place to put code to clear caches, for instance.
2447 * This is called on page move and undelete, as well as edit
2449 * @param $title_obj a title object
2452 function onArticleCreate($title_obj) {
2453 global $wgUseSquid, $wgPostCommitUpdateList;
2455 $title_obj->touchLinks();
2456 $titles = $title_obj->getLinksTo();
2459 if ( $wgUseSquid ) {
2460 $urls = $title_obj->getSquidURLs();
2461 foreach ( $titles as $linkTitle ) {
2462 $urls[] = $linkTitle->getInternalURL();
2464 $u = new SquidUpdate( $urls );
2465 array_push( $wgPostCommitUpdateList, $u );
2469 function onArticleDelete( $title ) {
2470 global $wgMessageCache;
2472 $title->touchLinks();
2474 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2475 $wgMessageCache->replace( $title->getDBkey(), false );
2480 * Purge caches on page update etc
2482 function onArticleEdit( $title ) {
2483 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2487 // Template namespace? Purge all articles linking here.
2488 // FIXME: When a templatelinks table arrives, use it for all includes.
2489 if ( $title->getNamespace() == NS_TEMPLATE
) {
2490 $titles = $title->getLinksTo();
2491 Title
::touchArray( $titles );
2492 if ( $wgUseSquid ) {
2493 foreach ( $titles as $link ) {
2494 $urls[] = $link->getInternalURL();
2500 if ( $wgUseSquid ) {
2501 $urls = array_merge( $urls, $title->getSquidURLs() );
2502 $u = new SquidUpdate( $urls );
2503 array_push( $wgPostCommitUpdateList, $u );
2507 if ( $wgUseFileCache ) {
2508 $cm = new CacheManager( $title );
2509 @unlink
( $cm->fileCacheName() );
2516 * Info about this page
2517 * Called for ?action=info when $wgAllowPageInfo is on.
2522 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2523 $fname = 'Article::info';
2525 if ( !$wgAllowPageInfo ) {
2526 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2530 $page = $this->mTitle
->getSubjectPage();
2532 $wgOut->setPagetitle( $page->getPrefixedText() );
2533 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2535 # first, see if the page exists at all.
2536 $exists = $page->getArticleId() != 0;
2538 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2539 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2541 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2544 $dbr =& wfGetDB( DB_SLAVE
);
2546 'wl_title' => $page->getDBkey(),
2547 'wl_namespace' => $page->getNamespace() );
2548 $numwatchers = $dbr->selectField(
2553 $this->getSelectOptions() );
2555 $pageInfo = $this->pageCountInfo( $page );
2556 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2558 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2559 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2561 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2563 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2565 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2567 $wgOut->addHTML( '</ul>' );
2573 * Return the total number of edits and number of unique editors
2574 * on a given page. If page does not exist, returns false.
2576 * @param Title $title
2580 function pageCountInfo( $title ) {
2581 $id = $title->getArticleId();
2586 $dbr =& wfGetDB( DB_SLAVE
);
2588 $rev_clause = array( 'rev_page' => $id );
2589 $fname = 'Article::pageCountInfo';
2591 $edits = $dbr->selectField(
2596 $this->getSelectOptions() );
2598 $authors = $dbr->selectField(
2600 'COUNT(DISTINCT rev_user_text)',
2603 $this->getSelectOptions() );
2605 return array( 'edits' => $edits, 'authors' => $authors );
2609 * Return a list of templates used by this article.
2610 * Uses the templatelinks table
2612 * @return array Array of Title objects
2614 function getUsedTemplates() {
2616 $id = $this->mTitle
->getArticleID();
2618 $dbr =& wfGetDB( DB_SLAVE
);
2619 $res = $dbr->select( array( 'templatelinks' ),
2620 array( 'tl_namespace', 'tl_title' ),
2621 array( 'tl_from' => $id ),
2622 'Article:getUsedTemplates' );
2623 if ( false !== $res ) {
2624 if ( $dbr->numRows( $res ) ) {
2625 while ( $row = $dbr->fetchObject( $res ) ) {
2626 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2630 $dbr->freeResult( $res );