8 * Class representing a MediaWiki article and history.
10 * See design.txt for an overview.
11 * Note: edit user interface and cache support functions have been
12 * moved to separate EditPage and HTMLFileCache classes.
22 var $mContentLoaded; //!<
25 var $mGoodAdjustment; //!<
29 var $mRedirectedFrom; //!<
30 var $mRedirectUrl; //!<
31 var $mRevIdFetched; //!<
35 var $mTotalAdjustment; //!<
42 * Constructor and clear the article
43 * @param $title Reference to a Title object.
44 * @param $oldId Integer revision ID, null to fetch from request, zero for current
46 function Article( &$title, $oldId = null ) {
47 $this->mTitle
=& $title;
48 $this->mOldId
= $oldId;
53 * Tell the page view functions that this view was redirected
54 * from another page on the wiki.
55 * @param $from Title object.
57 function setRedirectedFrom( $from ) {
58 $this->mRedirectedFrom
= $from;
62 * @return mixed false, Title of in-wiki target, or string with URL
64 function followRedirect() {
65 $text = $this->getContent();
66 $rt = Title
::newFromRedirect( $text );
68 # process if title object is valid and not special:userlogout
70 if( $rt->getInterwiki() != '' ) {
71 if( $rt->isLocal() ) {
72 // Offsite wikis need an HTTP redirect.
74 // This can be hard to reverse and may produce loops,
75 // so they may be disabled in the site configuration.
77 $source = $this->mTitle
->getFullURL( 'redirect=no' );
78 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
81 if( $rt->getNamespace() == NS_SPECIAL
) {
82 // Gotta hand redirects to special pages differently:
83 // Fill the HTTP response "Location" header and ignore
84 // the rest of the page we're on.
86 // This can be hard to reverse, so they may be disabled.
88 if( $rt->isSpecial( 'Userlogout' ) ) {
91 return $rt->getFullURL();
98 // No or invalid redirect
103 * get the title object of the article
105 function getTitle() {
106 return $this->mTitle
;
114 $this->mDataLoaded
= false;
115 $this->mContentLoaded
= false;
117 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
118 $this->mRedirectedFrom
= null; # Title object if set
120 $this->mTimestamp
= $this->mComment
= '';
121 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
122 $this->mTouched
= '19700101000000';
123 $this->mForUpdate
= false;
124 $this->mIsRedirect
= false;
125 $this->mRevIdFetched
= 0;
126 $this->mRedirectUrl
= false;
127 $this->mLatest
= 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 * @todo 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 wfProfileIn( __METHOD__
);
146 if ( 0 == $this->getID() ) {
147 wfProfileOut( __METHOD__
);
148 $wgOut->setRobotpolicy( 'noindex,nofollow' );
150 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
151 $ret = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
153 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
156 return "<div class='noarticletext'>$ret</div>";
158 $this->loadContent();
159 wfProfileOut( __METHOD__
);
160 return $this->mContent
;
165 * This function returns the text of a section, specified by a number ($section).
166 * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
167 * the first section before any such heading (section 0).
169 * If a section contains subsections, these are also returned.
171 * @param $text String: text to look in
172 * @param $section Integer: section number
173 * @return string text of the requested section
176 function getSection($text,$section) {
178 return $wgParser->getSection( $text, $section );
182 * @return int The oldid of the article that is to be shown, 0 for the
185 function getOldID() {
186 if ( is_null( $this->mOldId
) ) {
187 $this->mOldId
= $this->getOldIDFromRequest();
189 return $this->mOldId
;
193 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
195 * @return int The old id for the request
197 function getOldIDFromRequest() {
199 $this->mRedirectUrl
= false;
200 $oldid = $wgRequest->getVal( 'oldid' );
201 if ( isset( $oldid ) ) {
202 $oldid = intval( $oldid );
203 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
204 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
208 $this->mRedirectUrl
= $this->mTitle
->getFullURL( 'redirect=no' );
210 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
211 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
229 * Load the revision (including text) into this object
231 function loadContent() {
232 if ( $this->mContentLoaded
) return;
235 $oldid = $this->getOldID();
237 # Pre-fill content with error message so that if something
238 # fails we'll have something telling us what we intended.
240 $t = $this->mTitle
->getPrefixedText();
242 $this->mOldId
= $oldid;
243 $this->fetchContent( $oldid );
248 * Fetch a page record with the given conditions
249 * @param Database $dbr
250 * @param array $conditions
253 function pageData( &$dbr, $conditions ) {
266 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
267 $row = $dbr->selectRow( 'page',
270 'Article::pageData' );
271 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
276 * @param Database $dbr
277 * @param Title $title
279 function pageDataFromTitle( &$dbr, $title ) {
280 return $this->pageData( $dbr, array(
281 'page_namespace' => $title->getNamespace(),
282 'page_title' => $title->getDBkey() ) );
286 * @param Database $dbr
289 function pageDataFromId( &$dbr, $id ) {
290 return $this->pageData( $dbr, array( 'page_id' => $id ) );
294 * Set the general counter, title etc data loaded from
297 * @param object $data
300 function loadPageData( $data = 'fromdb' ) {
301 if ( $data === 'fromdb' ) {
302 $dbr =& $this->getDB();
303 $data = $this->pageDataFromId( $dbr, $this->getId() );
306 $lc =& LinkCache
::singleton();
308 $lc->addGoodLinkObj( $data->page_id
, $this->mTitle
);
310 $this->mTitle
->mArticleID
= $data->page_id
;
311 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
312 $this->mTitle
->mRestrictionsLoaded
= true;
314 $this->mCounter
= $data->page_counter
;
315 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
316 $this->mIsRedirect
= $data->page_is_redirect
;
317 $this->mLatest
= $data->page_latest
;
319 if ( is_object( $this->mTitle
) ) {
320 $lc->addBadLinkObj( $this->mTitle
);
322 $this->mTitle
->mArticleID
= 0;
325 $this->mDataLoaded
= true;
329 * Get text of an article from database
330 * Does *NOT* follow redirects.
331 * @param int $oldid 0 for whatever the latest revision is
334 function fetchContent( $oldid = 0 ) {
335 if ( $this->mContentLoaded
) {
336 return $this->mContent
;
339 $dbr =& $this->getDB();
341 # Pre-fill content with error message so that if something
342 # fails we'll have something telling us what we intended.
343 $t = $this->mTitle
->getPrefixedText();
345 $t .= ',oldid='.$oldid;
347 $this->mContent
= wfMsg( 'missingarticle', $t ) ;
350 $revision = Revision
::newFromId( $oldid );
351 if( is_null( $revision ) ) {
352 wfDebug( __METHOD__
." failed to retrieve specified revision, id $oldid\n" );
355 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
357 wfDebug( __METHOD__
." failed to get page data linked to revision id $oldid\n" );
360 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
361 $this->loadPageData( $data );
363 if( !$this->mDataLoaded
) {
364 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
366 wfDebug( __METHOD__
." failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
369 $this->loadPageData( $data );
371 $revision = Revision
::newFromId( $this->mLatest
);
372 if( is_null( $revision ) ) {
373 wfDebug( __METHOD__
." failed to retrieve current page, rev_id {$data->page_latest}\n" );
378 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
379 // We should instead work with the Revision object when we need it...
380 $this->mContent
= $revision->userCan( Revision
::DELETED_TEXT
) ?
$revision->getRawText() : "";
381 //$this->mContent = $revision->getText();
383 $this->mUser
= $revision->getUser();
384 $this->mUserText
= $revision->getUserText();
385 $this->mComment
= $revision->getComment();
386 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
388 $this->mRevIdFetched
= $revision->getID();
389 $this->mContentLoaded
= true;
390 $this->mRevision
=& $revision;
392 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ) ;
394 return $this->mContent
;
398 * Read/write accessor to select FOR UPDATE
400 * @param $x Mixed: FIXME
402 function forUpdate( $x = NULL ) {
403 return wfSetVar( $this->mForUpdate
, $x );
407 * Get the database which should be used for reads
412 $ret =& wfGetDB( DB_MASTER
);
417 * Get options for all SELECT statements
419 * @param $options Array: an optional options array which'll be appended to
421 * @return Array: options
423 function getSelectOptions( $options = '' ) {
424 if ( $this->mForUpdate
) {
425 if ( is_array( $options ) ) {
426 $options[] = 'FOR UPDATE';
428 $options = 'FOR UPDATE';
435 * @return int Page ID
438 if( $this->mTitle
) {
439 return $this->mTitle
->getArticleID();
446 * @return bool Whether or not the page exists in the database
449 return $this->getId() != 0;
453 * @return int The view count for the page
455 function getCount() {
456 if ( -1 == $this->mCounter
) {
457 $id = $this->getID();
461 $dbr =& wfGetDB( DB_SLAVE
);
462 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
463 'Article::getCount', $this->getSelectOptions() );
466 return $this->mCounter
;
470 * Determine whether a page would be suitable for being counted as an
471 * article in the site_stats table based on the title & its content
473 * @param $text String: text to analyze
476 function isCountable( $text ) {
477 global $wgUseCommaCount, $wgContentNamespaces;
479 $token = $wgUseCommaCount ?
',' : '[[';
481 array_search( $this->mTitle
->getNamespace(), $wgContentNamespaces ) !== false
482 && ! $this->isRedirect( $text )
483 && in_string( $token, $text );
487 * Tests if the article text represents a redirect
489 * @param $text String: FIXME
492 function isRedirect( $text = false ) {
493 if ( $text === false ) {
494 $this->loadContent();
495 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
497 $titleObj = Title
::newFromRedirect( $text );
499 return $titleObj !== NULL;
503 * Returns true if the currently-referenced revision is the current edit
504 * to this page (and it exists).
507 function isCurrent() {
508 return $this->exists() &&
509 isset( $this->mRevision
) &&
510 $this->mRevision
->isCurrent();
514 * Loads everything except the text
515 * This isn't necessary for all uses, so it's only done if needed.
518 function loadLastEdit() {
519 if ( -1 != $this->mUser
)
522 # New or non-existent articles have no user information
523 $id = $this->getID();
524 if ( 0 == $id ) return;
526 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
527 if( !is_null( $this->mLastRevision
) ) {
528 $this->mUser
= $this->mLastRevision
->getUser();
529 $this->mUserText
= $this->mLastRevision
->getUserText();
530 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
531 $this->mComment
= $this->mLastRevision
->getComment();
532 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
533 $this->mRevIdFetched
= $this->mLastRevision
->getID();
537 function getTimestamp() {
538 // Check if the field has been filled by ParserCache::get()
539 if ( !$this->mTimestamp
) {
540 $this->loadLastEdit();
542 return wfTimestamp(TS_MW
, $this->mTimestamp
);
546 $this->loadLastEdit();
550 function getUserText() {
551 $this->loadLastEdit();
552 return $this->mUserText
;
555 function getComment() {
556 $this->loadLastEdit();
557 return $this->mComment
;
560 function getMinorEdit() {
561 $this->loadLastEdit();
562 return $this->mMinorEdit
;
565 function getRevIdFetched() {
566 $this->loadLastEdit();
567 return $this->mRevIdFetched
;
571 * @todo Document, fixme $offset never used.
572 * @param $limit Integer: default 0.
573 * @param $offset Integer: default 0.
575 function getContributors($limit = 0, $offset = 0) {
576 # XXX: this is expensive; cache this info somewhere.
578 $title = $this->mTitle
;
580 $dbr =& wfGetDB( DB_SLAVE
);
581 $revTable = $dbr->tableName( 'revision' );
582 $userTable = $dbr->tableName( 'user' );
583 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
584 $ns = $title->getNamespace();
585 $user = $this->getUser();
586 $pageId = $this->getId();
588 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
589 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
590 WHERE rev_page = $pageId
591 AND rev_user != $user
592 GROUP BY rev_user, rev_user_text, user_real_name
593 ORDER BY timestamp DESC";
595 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
596 $sql .= ' '. $this->getSelectOptions();
598 $res = $dbr->query($sql, __METHOD__
);
600 while ( $line = $dbr->fetchObject( $res ) ) {
601 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
604 $dbr->freeResult($res);
609 * This is the default action of the script: just view the page of
613 global $wgUser, $wgOut, $wgRequest, $wgContLang;
614 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
615 global $wgUseTrackbacks, $wgNamespaceRobotPolicies;
617 wfProfileIn( __METHOD__
);
619 $parserCache =& ParserCache
::singleton();
620 $ns = $this->mTitle
->getNamespace(); # shortcut
622 # Get variables from query string
623 $oldid = $this->getOldID();
625 # getOldID may want us to redirect somewhere else
626 if ( $this->mRedirectUrl
) {
627 $wgOut->redirect( $this->mRedirectUrl
);
628 wfProfileOut( __METHOD__
);
632 $diff = $wgRequest->getVal( 'diff' );
633 $rcid = $wgRequest->getVal( 'rcid' );
634 $rdfrom = $wgRequest->getVal( 'rdfrom' );
636 $wgOut->setArticleFlag( true );
637 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
638 $policy = $wgNamespaceRobotPolicies[$ns];
640 $policy = 'index,follow';
642 $wgOut->setRobotpolicy( $policy );
644 # If we got diff and oldid in the query, we want to see a
645 # diff page instead of the article.
647 if ( !is_null( $diff ) ) {
648 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
650 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
651 // DifferenceEngine directly fetched the revision:
652 $this->mRevIdFetched
= $de->mNewid
;
655 // Needed to get the page's current revision
656 $this->loadPageData();
657 if( $diff == 0 ||
$diff == $this->mLatest
) {
658 # Run view updates for current revision only
659 $this->viewUpdates();
661 wfProfileOut( __METHOD__
);
665 if ( empty( $oldid ) && $this->checkTouched() ) {
666 $wgOut->setETag($parserCache->getETag($this, $wgUser));
668 if( $wgOut->checkLastModified( $this->mTouched
) ){
669 wfProfileOut( __METHOD__
);
671 } else if ( $this->tryFileCache() ) {
672 # tell wgOut that output is taken care of
674 $this->viewUpdates();
675 wfProfileOut( __METHOD__
);
680 # Should the parser cache be used?
681 $pcache = $wgEnableParserCache &&
682 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
685 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
686 if ( $wgUser->getOption( 'stubthreshold' ) ) {
687 wfIncrStats( 'pcache_miss_stub' );
690 $wasRedirected = false;
691 if ( isset( $this->mRedirectedFrom
) ) {
692 // This is an internally redirected page view.
693 // We'll need a backlink to the source page for navigation.
694 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
695 $redir = Linker
::makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
696 $s = wfMsg( 'redirectedfrom', $redir );
697 $wgOut->setSubtitle( $s );
698 $wasRedirected = true;
700 } elseif ( !empty( $rdfrom ) ) {
701 // This is an externally redirected view, from some other wiki.
702 // If it was reported from a trusted site, supply a backlink.
703 global $wgRedirectSources;
704 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
705 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
706 $s = wfMsg( 'redirectedfrom', $redir );
707 $wgOut->setSubtitle( $s );
708 $wasRedirected = true;
714 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
715 wfRunHooks( 'ArticleViewHeader', array( &$this ) );
719 if ( !$outputDone ) {
720 $text = $this->getContent();
721 if ( $text === false ) {
722 # Failed to load, replace text with error message
723 $t = $this->mTitle
->getPrefixedText();
725 $t .= ',oldid='.$oldid;
726 $text = wfMsg( 'missingarticle', $t );
728 $text = wfMsg( 'noarticletext', $t );
732 # Another whitelist check in case oldid is altering the title
733 if ( !$this->mTitle
->userCanRead() ) {
734 $wgOut->loginToUse();
739 # We're looking at an old revision
741 if ( !empty( $oldid ) ) {
742 $wgOut->setRobotpolicy( 'noindex,nofollow' );
743 if( is_null( $this->mRevision
) ) {
744 // FIXME: This would be a nice place to load the 'no such page' text.
746 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
747 if( $this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
748 if( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
749 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
750 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
753 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
754 // and we are allowed to see...
763 * @fixme: this hook doesn't work most of the time, as it doesn't
764 * trigger when the parser cache is used.
766 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
767 $wgOut->setRevisionId( $this->getRevIdFetched() );
768 # wrap user css and user js in pre and don't parse
769 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
772 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
774 $wgOut->addWikiText( wfMsg('clearyourcache'));
775 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
776 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
778 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
779 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
780 # Don't overwrite the subtitle if this was an old revision
781 if( !$wasRedirected && $this->isCurrent() ) {
782 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
784 $targetUrl = $rt->escapeLocalURL();
785 #Â fixme unused $titleText :
786 $titleText = htmlspecialchars( $rt->getPrefixedText() );
787 $link = Linker
::makeLinkObj( $rt );
789 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
790 '<span class="redirectText">'.$link.'</span>' );
792 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
793 $wgOut->addParserOutputNoText( $parseout );
794 } else if ( $pcache ) {
795 # Display content and save to parser cache
796 $wgOut->addPrimaryWikiText( $text, $this );
798 # Display content, don't attempt to save to parser cache
799 # Don't show section-edit links on old revisions... this way lies madness.
800 if( !$this->isCurrent() ) {
801 $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
803 # Display content and don't save to parser cache
804 $wgOut->addPrimaryWikiText( $text, $this, false );
806 if( !$this->isCurrent() ) {
807 $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
811 /* title may have been set from the cache */
812 $t = $wgOut->getPageTitle();
814 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
817 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
818 if( $ns == NS_USER_TALK
&&
819 User
::isIP( $this->mTitle
->getText() ) ) {
820 $wgOut->addWikiText( wfMsg('anontalkpagetext') );
823 # If we have been passed an &rcid= parameter, we want to give the user a
824 # chance to mark this new article as patrolled.
825 if ( $wgUseRCPatrol && !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
827 "<div class='patrollink'>" .
828 wfMsg ( 'markaspatrolledlink',
829 Linker
::makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
836 if ($wgUseTrackbacks)
837 $this->addTrackbacks();
839 $this->viewUpdates();
840 wfProfileOut( __METHOD__
);
843 function addTrackbacks() {
844 global $wgOut, $wgUser;
846 $dbr =& wfGetDB(DB_SLAVE
);
848 /* FROM */ 'trackbacks',
849 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
850 /* WHERE */ array('tb_page' => $this->getID())
853 if (!$dbr->numrows($tbs))
857 while ($o = $dbr->fetchObject($tbs)) {
859 if ($wgUser->isAllowed( 'trackback' )) {
860 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
861 . $o->tb_id
. "&token=" . $wgUser->editToken());
862 $rmvtxt = wfMsg('trackbackremove', $delurl);
864 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
871 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
874 function deletetrackback() {
875 global $wgUser, $wgRequest, $wgOut, $wgTitle;
877 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
878 $wgOut->addWikitext(wfMsg('sessionfailure'));
882 if ((!$wgUser->isAllowed('delete'))) {
883 $wgOut->permissionRequired( 'delete' );
888 $wgOut->readOnlyPage();
892 $db =& wfGetDB(DB_MASTER
);
893 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
894 $wgTitle->invalidateCache();
895 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
901 $wgOut->setArticleBodyOnly(true);
906 * Handle action=purge
909 global $wgUser, $wgRequest, $wgOut;
911 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
912 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
916 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
917 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
918 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
919 $msg = str_replace( '$1',
920 "<form method=\"post\" action=\"$action\">\n" .
921 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
924 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
925 $wgOut->setRobotpolicy( 'noindex,nofollow' );
926 $wgOut->addHTML( $msg );
931 * Perform the actions of a page purging
935 // Invalidate the cache
936 $this->mTitle
->invalidateCache();
939 // Commit the transaction before the purge is sent
940 $dbw = wfGetDB( DB_MASTER
);
941 $dbw->immediateCommit();
944 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
951 * Insert a new empty page record for this article.
952 * This *must* be followed up by creating a revision
953 * and running $this->updateToLatest( $rev_id );
954 * or else the record will be left in a funky state.
955 * Best if all done inside a transaction.
957 * @param Database $dbw
958 * @param string $restrictions
959 * @return int The newly created page_id key
962 function insertOn( &$dbw, $restrictions = '' ) {
963 wfProfileIn( __METHOD__
);
965 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
966 $dbw->insert( 'page', array(
967 'page_id' => $page_id,
968 'page_namespace' => $this->mTitle
->getNamespace(),
969 'page_title' => $this->mTitle
->getDBkey(),
971 'page_restrictions' => $restrictions,
972 'page_is_redirect' => 0, # Will set this shortly...
974 'page_random' => wfRandom(),
975 'page_touched' => $dbw->timestamp(),
976 'page_latest' => 0, # Fill this in shortly...
977 'page_len' => 0, # Fill this in shortly...
979 $newid = $dbw->insertId();
981 $this->mTitle
->resetArticleId( $newid );
983 wfProfileOut( __METHOD__
);
988 * Update the page record to point to a newly saved revision.
990 * @param Database $dbw
991 * @param Revision $revision For ID number, and text used to set
992 length and redirect status fields
993 * @param int $lastRevision If given, will not overwrite the page field
994 * when different from the currently set value.
995 * Giving 0 indicates the new page flag should
997 * @param bool $lastRevIsRedirect If given, will optimize adding and
998 * removing rows in redirect table.
999 * @return bool true on success, false on failure
1002 function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) {
1003 wfProfileIn( __METHOD__
);
1005 $text = $revision->getText();
1006 $rt = Title
::newFromRedirect( $text );
1008 $conditions = array( 'page_id' => $this->getId() );
1009 if( !is_null( $lastRevision ) ) {
1010 # An extra check against threads stepping on each other
1011 $conditions['page_latest'] = $lastRevision;
1014 $dbw->update( 'page',
1016 'page_latest' => $revision->getId(),
1017 'page_touched' => $dbw->timestamp(),
1018 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1019 'page_is_redirect' => $rt !== NULL ?
1 : 0,
1020 'page_len' => strlen( $text ),
1025 $result = $dbw->affectedRows() != 0;
1028 // FIXME: Should the result from updateRedirectOn() be returned instead?
1029 $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
1032 wfProfileOut( __METHOD__
);
1037 * Add row to the redirect table if this is a redirect, remove otherwise.
1039 * @param Database $dbw
1040 * @param $redirectTitle a title object pointing to the redirect target,
1041 * or NULL if this is not a redirect
1042 * @param bool $lastRevIsRedirect If given, will optimize adding and
1043 * removing rows in redirect table.
1044 * @return bool true on success, false on failure
1047 function updateRedirectOn( &$dbw, $redirectTitle, $lastRevIsRedirect = null ) {
1049 // Always update redirects (target link might have changed)
1050 // Update/Insert if we don't know if the last revision was a redirect or not
1051 // Delete if changing from redirect to non-redirect
1052 $isRedirect = !is_null($redirectTitle);
1053 if ($isRedirect ||
is_null($lastRevIsRedirect) ||
$lastRevIsRedirect !== $isRedirect) {
1055 wfProfileIn( __METHOD__
);
1059 // This title is a redirect, Add/Update row in the redirect table
1060 $set = array( /* SET */
1061 'rd_namespace' => $redirectTitle->getNamespace(),
1062 'rd_title' => $redirectTitle->getDBkey(),
1063 'rd_from' => $this->getId(),
1066 $dbw->replace( 'redirect', array( 'rd_from' ), $set, __METHOD__
);
1068 // This is not a redirect, remove row from redirect table
1069 $where = array( 'rd_from' => $this->getId() );
1070 $dbw->delete( 'redirect', $where, __METHOD__
);
1073 wfProfileOut( __METHOD__
);
1074 return ( $dbw->affectedRows() != 0 );
1081 * If the given revision is newer than the currently set page_latest,
1082 * update the page record. Otherwise, do nothing.
1084 * @param Database $dbw
1085 * @param Revision $revision
1087 function updateIfNewerOn( &$dbw, $revision ) {
1088 wfProfileIn( __METHOD__
);
1090 $row = $dbw->selectRow(
1091 array( 'revision', 'page' ),
1092 array( 'rev_id', 'rev_timestamp', 'page_is_redirect' ),
1094 'page_id' => $this->getId(),
1095 'page_latest=rev_id' ),
1098 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1099 wfProfileOut( __METHOD__
);
1102 $prev = $row->rev_id
;
1103 $lastRevIsRedirect = (bool)$row->page_is_redirect
;
1105 # No or missing previous revision; mark the page as new
1107 $lastRevIsRedirect = null;
1110 $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
1111 wfProfileOut( __METHOD__
);
1116 * @return string Complete article text, or null if error
1118 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1119 wfProfileIn( __METHOD__
);
1121 if( $section == '' ) {
1122 // Whole-page edit; let the text through unmolested.
1124 if( is_null( $edittime ) ) {
1125 $rev = Revision
::newFromTitle( $this->mTitle
);
1127 $dbw =& wfGetDB( DB_MASTER
);
1128 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1130 if( is_null( $rev ) ) {
1131 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1132 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1135 $oldtext = $rev->getText();
1137 if($section=='new') {
1138 if($summary) $subject="== {$summary} ==\n\n";
1139 $text=$oldtext."\n\n".$subject.$text;
1142 $text = $wgParser->replaceSection( $oldtext, $section, $text );
1146 wfProfileOut( __METHOD__
);
1151 * @deprecated use Article::doEdit()
1153 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1154 $flags = EDIT_NEW | EDIT_DEFER_UPDATES |
1155 ( $isminor ? EDIT_MINOR
: 0 ) |
1156 ( $suppressRC ? EDIT_SUPPRESS_RC
: 0 );
1158 # If this is a comment, add the summary as headline
1159 if ( $comment && $summary != "" ) {
1160 $text = "== {$summary} ==\n\n".$text;
1163 $this->doEdit( $text, $summary, $flags );
1165 $dbw =& wfGetDB( DB_MASTER
);
1167 if (!$this->mTitle
->userIsWatching()) {
1173 if ( $this->mTitle
->userIsWatching() ) {
1179 $this->doRedirect( $this->isRedirect( $text ) );
1183 * @deprecated use Article::doEdit()
1185 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1186 $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES |
1187 ( $minor ? EDIT_MINOR
: 0 ) |
1188 ( $forceBot ? EDIT_FORCE_BOT
: 0 );
1190 $good = $this->doEdit( $text, $summary, $flags );
1192 $dbw =& wfGetDB( DB_MASTER
);
1194 if (!$this->mTitle
->userIsWatching()) {
1200 if ( $this->mTitle
->userIsWatching() ) {
1207 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
1215 * Change an existing article or create a new article. Updates RC and all necessary caches,
1216 * optionally via the deferred update array.
1218 * $wgUser must be set before calling this function.
1220 * @param string $text New text
1221 * @param string $summary Edit summary
1222 * @param integer $flags bitfield:
1224 * Article is known or assumed to be non-existent, create a new one
1226 * Article is known or assumed to be pre-existing, update it
1228 * Mark this edit minor, if the user is allowed to do so
1230 * Do not log the change in recentchanges
1232 * Mark the edit a "bot" edit regardless of user rights
1233 * EDIT_DEFER_UPDATES
1234 * Defer some of the updates until the end of index.php
1236 * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
1237 * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If
1238 * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
1239 * to be thrown from the Database. These two conditions are also possible with auto-detection due
1240 * to MediaWiki's performance-optimised locking strategy.
1242 * @return bool success
1244 function doEdit( $text, $summary, $flags = 0 ) {
1245 global $wgUser, $wgDBtransactions;
1247 wfProfileIn( __METHOD__
);
1250 if ( !($flags & EDIT_NEW
) && !($flags & EDIT_UPDATE
) ) {
1251 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
1253 $flags |
= EDIT_UPDATE
;
1259 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1260 &$summary, $flags & EDIT_MINOR
,
1261 null, null, &$flags ) ) )
1263 wfDebug( __METHOD__
. ": ArticleSave hook aborted save!\n" );
1264 wfProfileOut( __METHOD__
);
1268 # Silently ignore EDIT_MINOR if not allowed
1269 $isminor = ( $flags & EDIT_MINOR
) && $wgUser->isAllowed('minoredit');
1270 $bot = $wgUser->isAllowed( 'bot' ) ||
( $flags & EDIT_FORCE_BOT
);
1272 # If no edit comment was given when creating a new page, and what's being
1273 # created is a redirect, be smart and fill in a neat auto-comment
1274 if( $summary == '' ) {
1275 $rt = Title
::newFromRedirect( $text );
1276 if( is_object( $rt ) )
1277 $summary = wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() );
1280 $text = $this->preSaveTransform( $text );
1282 $dbw =& wfGetDB( DB_MASTER
);
1283 $now = wfTimestampNow();
1285 if ( $flags & EDIT_UPDATE
) {
1286 # Update article, but only if changed.
1288 # Make sure the revision is either completely inserted or not inserted at all
1289 if( !$wgDBtransactions ) {
1290 $userAbort = ignore_user_abort( true );
1293 $oldtext = $this->getContent();
1294 $oldsize = strlen( $oldtext );
1295 $newsize = strlen( $text );
1299 if ( 0 != strcmp( $text, $oldtext ) ) {
1300 $this->mGoodAdjustment
= (int)$this->isCountable( $text )
1301 - (int)$this->isCountable( $oldtext );
1302 $this->mTotalAdjustment
= 0;
1304 $lastRevision = $dbw->selectField(
1305 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1307 if ( !$lastRevision ) {
1308 # Article gone missing
1309 wfDebug( __METHOD__
.": EDIT_UPDATE specified but article doesn't exist\n" );
1310 wfProfileOut( __METHOD__
);
1314 $revision = new Revision( array(
1315 'page' => $this->getId(),
1316 'comment' => $summary,
1317 'minor_edit' => $isminor,
1322 $revisionId = $revision->insertOn( $dbw );
1325 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1328 /* Belated edit conflict! Run away!! */
1332 # Update recentchanges
1333 if( !( $flags & EDIT_SUPPRESS_RC
) ) {
1334 $rcid = RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1335 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1338 # Mark as patrolled if the user can do so and has it set in their options
1339 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1340 RecentChange
::markPatrolled( $rcid );
1346 // Keep the same revision ID, but do some updates on it
1347 $revisionId = $this->getRevIdFetched();
1348 // Update page_touched, this is usually implicit in the page update
1349 // Other cache updates are done in onArticleEdit()
1350 $this->mTitle
->invalidateCache();
1353 if( !$wgDBtransactions ) {
1354 ignore_user_abort( $userAbort );
1358 # Invalidate cache of this article and all pages using this article
1359 # as a template. Partly deferred.
1360 Article
::onArticleEdit( $this->mTitle
);
1362 # Update links tables, site stats, etc.
1363 $changed = ( strcmp( $oldtext, $text ) != 0 );
1364 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
1367 # Create new article
1369 # Set statistics members
1370 # We work out if it's countable after PST to avoid counter drift
1371 # when articles are created with {{subst:}}
1372 $this->mGoodAdjustment
= (int)$this->isCountable( $text );
1373 $this->mTotalAdjustment
= 1;
1377 # Add the page record; stake our claim on this title!
1378 # This will fail with a database query exception if the article already exists
1379 $newid = $this->insertOn( $dbw );
1381 # Save the revision text...
1382 $revision = new Revision( array(
1384 'comment' => $summary,
1385 'minor_edit' => $isminor,
1388 $revisionId = $revision->insertOn( $dbw );
1390 $this->mTitle
->resetArticleID( $newid );
1392 # Update the page record with revision data
1393 $this->updateRevisionOn( $dbw, $revision, 0 );
1395 if( !( $flags & EDIT_SUPPRESS_RC
) ) {
1396 $rcid = RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, $bot,
1397 '', strlen( $text ), $revisionId );
1398 # Mark as patrolled if the user can and has the option set
1399 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1400 RecentChange
::markPatrolled( $rcid );
1405 # Update links, etc.
1406 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
1409 Article
::onArticleCreate( $this->mTitle
);
1411 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1412 $summary, $flags & EDIT_MINOR
,
1413 null, null, &$flags ) );
1416 if ( $good && !( $flags & EDIT_DEFER_UPDATES
) ) {
1420 wfRunHooks( 'ArticleSaveComplete',
1421 array( &$this, &$wgUser, $text,
1422 $summary, $flags & EDIT_MINOR
,
1423 null, null, &$flags ) );
1425 wfProfileOut( __METHOD__
);
1430 * @deprecated wrapper for doRedirect
1432 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1433 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
1437 * Output a redirect back to the article.
1438 * This is typically used after an edit.
1440 * @param boolean $noRedir Add redirect=no
1441 * @param string $sectionAnchor section to redirect to, including "#"
1443 function doRedirect( $noRedir = false, $sectionAnchor = '' ) {
1446 $query = 'redirect=no';
1450 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) . $sectionAnchor );
1454 * Mark this particular edit as patrolled
1456 function markpatrolled() {
1457 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
1458 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1460 # Check RC patrol config. option
1461 if( !$wgUseRCPatrol ) {
1462 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1467 if( !$wgUser->isAllowed( 'patrol' ) ) {
1468 $wgOut->permissionRequired( 'patrol' );
1472 $rcid = $wgRequest->getVal( 'rcid' );
1473 if ( !is_null ( $rcid ) ) {
1474 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
1475 RecentChange
::markPatrolled( $rcid );
1476 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1477 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1478 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1480 $rcTitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1481 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1484 $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1489 * User-interface handler for the "watch" action
1494 global $wgUser, $wgOut;
1496 if ( $wgUser->isAnon() ) {
1497 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1500 if ( wfReadOnly() ) {
1501 $wgOut->readOnlyPage();
1505 if( $this->doWatch() ) {
1506 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1507 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1509 $link = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1510 $text = wfMsg( 'addedwatchtext', $link );
1511 $wgOut->addWikiText( $text );
1514 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1518 * Add this page to $wgUser's watchlist
1519 * @return bool true on successful watch operation
1521 function doWatch() {
1523 if( $wgUser->isAnon() ) {
1527 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1528 $wgUser->addWatch( $this->mTitle
);
1530 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1537 * User interface handler for the "unwatch" action.
1539 function unwatch() {
1541 global $wgUser, $wgOut;
1543 if ( $wgUser->isAnon() ) {
1544 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1547 if ( wfReadOnly() ) {
1548 $wgOut->readOnlyPage();
1552 if( $this->doUnwatch() ) {
1553 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1554 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1556 $link = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1557 $text = wfMsg( 'removedwatchtext', $link );
1558 $wgOut->addWikiText( $text );
1561 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1565 * Stop watching a page
1566 * @return bool true on successful unwatch
1568 function doUnwatch() {
1570 if( $wgUser->isAnon() ) {
1574 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1575 $wgUser->removeWatch( $this->mTitle
);
1577 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1584 * action=protect handler
1586 function protect() {
1587 $form = new ProtectionForm( $this );
1592 * action=unprotect handler (alias)
1594 function unprotect() {
1599 * Update the article's restriction field, and leave a log entry.
1601 * @param array $limit set of restriction keys
1602 * @param string $reason
1603 * @return bool true on success
1605 function updateRestrictions( $limit = array(), $reason = '' ) {
1606 global $wgUser, $wgRestrictionTypes, $wgContLang;
1608 $id = $this->mTitle
->getArticleID();
1609 if( !$wgUser->isAllowed( 'protect' ) ||
wfReadOnly() ||
$id == 0 ) {
1613 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1614 # we expect a single selection, but the schema allows otherwise.
1616 foreach( $wgRestrictionTypes as $action )
1617 $current[$action] = implode( '', $this->mTitle
->getRestrictions( $action ) );
1619 $current = Article
::flattenRestrictions( $current );
1620 $updated = Article
::flattenRestrictions( $limit );
1622 $changed = ( $current != $updated );
1623 $protect = ( $updated != '' );
1625 # If nothing's changed, do nothing
1627 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1629 $dbw =& wfGetDB( DB_MASTER
);
1631 # Prepare a null revision to be added to the history
1632 $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ?
'protectedarticle' : 'unprotectedarticle', $this->mTitle
->getPrefixedText() ) );
1634 $comment .= ": $reason";
1636 $comment .= " [$updated]";
1637 $nullRevision = Revision
::newNullRevision( $dbw, $id, $comment, true );
1638 $nullRevId = $nullRevision->insertOn( $dbw );
1640 # Update page record
1641 $dbw->update( 'page',
1643 'page_touched' => $dbw->timestamp(),
1644 'page_restrictions' => $updated,
1645 'page_latest' => $nullRevId
1646 ), array( /* WHERE */
1648 ), 'Article::protect'
1650 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1652 # Update the protection log
1653 $log = new LogPage( 'protect' );
1655 $log->addEntry( 'protect', $this->mTitle
, trim( $reason . " [$updated]" ) );
1657 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1661 } # End "changed" check
1667 * Take an array of page restrictions and flatten it to a string
1668 * suitable for insertion into the page_restrictions field.
1669 * @param array $limit
1673 function flattenRestrictions( $limit ) {
1674 if( !is_array( $limit ) ) {
1675 throw new MWException( 'Article::flattenRestrictions given non-array restriction set' );
1679 foreach( $limit as $action => $restrictions ) {
1680 if( $restrictions != '' ) {
1681 $bits[] = "$action=$restrictions";
1684 return implode( ':', $bits );
1688 * UI entry point for page deletion
1691 global $wgUser, $wgOut, $wgRequest;
1692 $confirm = $wgRequest->wasPosted() &&
1693 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1694 $reason = $wgRequest->getText( 'wpReason' );
1696 # This code desperately needs to be totally rewritten
1699 if( $wgUser->isAllowed( 'delete' ) ) {
1700 if( $wgUser->isBlocked( !$confirm ) ) {
1701 $wgOut->blockedPage();
1705 $wgOut->permissionRequired( 'delete' );
1709 if( wfReadOnly() ) {
1710 $wgOut->readOnlyPage();
1714 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1716 # Better double-check that it hasn't been deleted yet!
1717 $dbw =& wfGetDB( DB_MASTER
);
1718 $conds = $this->mTitle
->pageCond();
1719 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1720 if ( $latest === false ) {
1721 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
1726 $this->doDelete( $reason );
1730 # determine whether this page has earlier revisions
1731 # and insert a warning if it does
1733 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1735 if( count( $authors ) > 1 && !$confirm ) {
1736 $skin=$wgUser->getSkin();
1737 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
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 wfProfileIn( __METHOD__
);
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 ), __METHOD__
, $this->getSelectOptions( array(
1823 'ORDER BY' => 'rev_timestamp DESC',
1828 wfProfileOut( __METHOD__
);
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( __METHOD__
);
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' id='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;
1897 wfDebug( __METHOD__
."\n" );
1899 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1900 if ( $this->doDeleteArticle( $reason ) ) {
1901 $deleted = wfEscapeWikiText( $this->mTitle
->getPrefixedText() );
1903 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1904 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1906 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1907 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1909 $wgOut->addWikiText( $text );
1910 $wgOut->returnToMain( false );
1911 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1913 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
1919 * Back-end article deletion
1920 * Deletes the article with database consistency, writes logs, purges caches
1923 function doDeleteArticle( $reason ) {
1924 global $wgUseSquid, $wgDeferredUpdateList;
1925 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1927 wfDebug( __METHOD__
."\n" );
1929 $dbw =& wfGetDB( DB_MASTER
);
1930 $ns = $this->mTitle
->getNamespace();
1931 $t = $this->mTitle
->getDBkey();
1932 $id = $this->mTitle
->getArticleID();
1934 if ( $t == '' ||
$id == 0 ) {
1938 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
1939 array_push( $wgDeferredUpdateList, $u );
1941 // For now, shunt the revision data into the archive table.
1942 // Text is *not* removed from the text table; bulk storage
1943 // is left intact to avoid breaking block-compression or
1944 // immutable storage schemes.
1946 // For backwards compatibility, note that some older archive
1947 // table entries will have ar_text and ar_flags fields still.
1949 // In the future, we may keep revisions and mark them with
1950 // the rev_deleted field, which is reserved for this purpose.
1951 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1953 'ar_namespace' => 'page_namespace',
1954 'ar_title' => 'page_title',
1955 'ar_comment' => 'rev_comment',
1956 'ar_user' => 'rev_user',
1957 'ar_user_text' => 'rev_user_text',
1958 'ar_timestamp' => 'rev_timestamp',
1959 'ar_minor_edit' => 'rev_minor_edit',
1960 'ar_rev_id' => 'rev_id',
1961 'ar_text_id' => 'rev_text_id',
1964 'page_id = rev_page'
1968 # Now that it's safely backed up, delete it
1969 $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__
);
1971 # If using cascading deletes, we can skip some explicit deletes
1972 if ( !$dbw->cascadingDeletes() ) {
1974 $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__
);
1976 if ($wgUseTrackbacks)
1977 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__
);
1979 # Delete outgoing links
1980 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1981 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1982 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1983 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
1984 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
1985 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
1986 $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
1989 # If using cleanup triggers, we can skip some manual deletes
1990 if ( !$dbw->cleanupTriggers() ) {
1992 # Clean up recentchanges entries...
1993 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__
);
1997 Article
::onArticleDelete( $this->mTitle
);
2000 $log = new LogPage( 'delete' );
2001 $log->addEntry( 'delete', $this->mTitle
, $reason );
2003 # Clear the cached article id so the interface doesn't act like we exist
2004 $this->mTitle
->resetArticleID( 0 );
2005 $this->mTitle
->mArticleID
= 0;
2010 * Revert a modification
2012 function rollback() {
2013 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2015 if( $wgUser->isAllowed( 'rollback' ) ) {
2016 if( $wgUser->isBlocked() ) {
2017 $wgOut->blockedPage();
2021 $wgOut->permissionRequired( 'rollback' );
2025 if ( wfReadOnly() ) {
2026 $wgOut->readOnlyPage( $this->getContent() );
2029 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2030 array( $this->mTitle
->getPrefixedText(),
2031 $wgRequest->getVal( 'from' ) ) ) ) {
2032 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2033 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2036 $dbw =& wfGetDB( DB_MASTER
);
2038 # Enhanced rollback, marks edits rc_bot=1
2039 $bot = $wgRequest->getBool( 'bot' );
2041 # Replace all this user's current edits with the next one down
2042 $tt = $this->mTitle
->getDBKey();
2043 $n = $this->mTitle
->getNamespace();
2045 # Get the last editor
2046 $current = Revision
::newFromTitle( $this->mTitle
);
2047 if( is_null( $current ) ) {
2048 # Something wrong... no page?
2049 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2053 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2054 if( $from != $current->getUserText() ) {
2055 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2056 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2057 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2058 htmlspecialchars( $from ),
2059 htmlspecialchars( $current->getUserText() ) ) );
2060 if( $current->getComment() != '') {
2062 wfMsg( 'editcomment',
2063 htmlspecialchars( $current->getComment() ) ) );
2068 # Get the last edit not by this guy
2069 $user = intval( $current->getUser() );
2070 $user_text = $dbw->addQuotes( $current->getUserText() );
2071 $s = $dbw->selectRow( 'revision',
2072 array( 'rev_id', 'rev_timestamp' ),
2074 'rev_page' => $current->getPage(),
2075 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2078 'USE INDEX' => 'page_timestamp',
2079 'ORDER BY' => 'rev_timestamp DESC' )
2081 if( $s === false ) {
2083 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2084 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2090 # Mark all reverted edits as bot
2093 if ( $wgUseRCPatrol ) {
2094 # Mark all reverted edits as patrolled
2095 $set['rc_patrolled'] = 1;
2099 $dbw->update( 'recentchanges', $set,
2101 'rc_cur_id' => $current->getPage(),
2102 'rc_user_text' => $current->getUserText(),
2103 "rc_timestamp > '{$s->rev_timestamp}'",
2108 # Get the edit summary
2109 $target = Revision
::newFromId( $s->rev_id
);
2110 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2111 $newComment = $wgRequest->getText( 'summary', $newComment );
2114 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2115 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2116 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2118 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2120 $wgOut->returnToMain( false );
2125 * Do standard deferred updates after page view
2128 function viewUpdates() {
2129 global $wgDeferredUpdateList;
2131 if ( 0 != $this->getID() ) {
2132 global $wgDisableCounters;
2133 if( !$wgDisableCounters ) {
2134 Article
::incViewCount( $this->getID() );
2135 $u = new SiteStatsUpdate( 1, 0, 0 );
2136 array_push( $wgDeferredUpdateList, $u );
2140 # Update newtalk / watchlist notification status
2142 $wgUser->clearNotification( $this->mTitle
);
2146 * Do standard deferred updates after page edit.
2147 * Update links tables, site stats, search index and message cache.
2148 * Every 1000th edit, prune the recent changes table.
2151 * @param $text New text of the article
2152 * @param $summary Edit summary
2153 * @param $minoredit Minor edit
2154 * @param $timestamp_of_pagechange Timestamp associated with the page change
2155 * @param $newid rev_id value of the new revision
2156 * @param $changed Whether or not the content actually changed
2158 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
2159 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2161 wfProfileIn( __METHOD__
);
2164 $options = new ParserOptions
;
2165 $options->setTidy(true);
2166 $poutput = $wgParser->parse( $text, $this->mTitle
, $options, true, true, $newid );
2168 # Save it to the parser cache
2169 $parserCache =& ParserCache
::singleton();
2170 $parserCache->save( $poutput, $this, $wgUser );
2172 # Update the links tables
2173 $u = new LinksUpdate( $this->mTitle
, $poutput );
2176 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2178 if ( 0 == mt_rand( 0, 999 ) ) {
2179 # Periodically flush old entries from the recentchanges table.
2182 $dbw =& wfGetDB( DB_MASTER
);
2183 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2184 $recentchanges = $dbw->tableName( 'recentchanges' );
2185 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2186 $dbw->query( $sql );
2190 $id = $this->getID();
2191 $title = $this->mTitle
->getPrefixedDBkey();
2192 $shortTitle = $this->mTitle
->getDBkey();
2195 wfProfileOut( __METHOD__
);
2199 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2200 array_push( $wgDeferredUpdateList, $u );
2201 $u = new SearchUpdate( $id, $title, $text );
2202 array_push( $wgDeferredUpdateList, $u );
2204 # If this is another user's talk page, update newtalk
2205 # Don't do this if $changed = false otherwise some idiot can null-edit a
2206 # load of user talk pages and piss people off, nor if it's a minor edit
2207 # by a properly-flagged bot.
2208 if( $this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getTitleKey() && $changed
2209 && !($minoredit && $wgUser->isAllowed('nominornewtalk') ) ) {
2210 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2211 $other = User
::newFromName( $shortTitle );
2212 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2213 // An anonymous user
2214 $other = new User();
2215 $other->setName( $shortTitle );
2218 $other->setNewtalk( true );
2223 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2224 $wgMessageCache->replace( $shortTitle, $text );
2227 wfProfileOut( __METHOD__
);
2231 * Perform article updates on a special page creation.
2233 * @param Revision $rev
2235 * @fixme This is a shitty interface function. Kill it and replace the
2236 * other shitty functions like editUpdates and such so it's not needed
2239 function createUpdates( $rev ) {
2240 $this->mGoodAdjustment
= $this->isCountable( $rev->getText() );
2241 $this->mTotalAdjustment
= 1;
2242 $this->editUpdates( $rev->getText(), $rev->getComment(),
2243 $rev->isMinor(), wfTimestamp(), $rev->getId(), true );
2247 * Generate the navigation links when browsing through an article revisions
2248 * It shows the information as:
2249 * Revision as of \<date\>; view current revision
2250 * \<- Previous version | Next Version -\>
2253 * @param string $oldid Revision ID of this article revision
2255 function setOldSubtitle( $oldid=0 ) {
2256 global $wgLang, $wgOut;
2258 if ( !wfRunHooks( 'DisplayOldSubtitle', array(&$this, &$oldid) ) ) {
2262 $revision = Revision
::newFromId( $oldid );
2264 $current = ( $oldid == $this->mLatest
);
2265 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2267 ?
wfMsg( 'currentrevisionlink' )
2268 : $lnk = Linker
::makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2269 $prev = $this->mTitle
->getPreviousRevisionID( $oldid ) ;
2271 ? Linker
::makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2272 : wfMsg( 'previousrevision' );
2274 ? Linker
::makeKnownLinkObj( $this->mTitle
, wfMsg( 'diff' ), 'diff=prev&oldid='.$oldid )
2276 $nextlink = $current
2277 ?
wfMsg( 'nextrevision' )
2278 : Linker
::makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2279 $nextdiff = $current
2281 : Linker
::makeKnownLinkObj( $this->mTitle
, wfMsg( 'diff' ), 'diff=next&oldid='.$oldid );
2283 $userlinks = Linker
::userLink( $revision->getUser(), $revision->getUserText() )
2284 . Linker
::userToolLinks( $revision->getUser(), $revision->getUserText() );
2286 $r = wfMsg( 'old-revision-navigation', $td, $lnk, $prevlink, $nextlink, $userlinks, $prevdiff, $nextdiff );
2287 $wgOut->setSubtitle( $r );
2291 * This function is called right before saving the wikitext,
2292 * so we can do things like signatures and links-in-context.
2294 * @param string $text
2296 function preSaveTransform( $text ) {
2297 global $wgParser, $wgUser;
2298 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2301 /* Caching functions */
2304 * checkLastModified returns true if it has taken care of all
2305 * output to the client that is necessary for this request.
2306 * (that is, it has sent a cached version of the page)
2308 function tryFileCache() {
2309 static $called = false;
2311 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2315 if($this->isFileCacheable()) {
2316 $touched = $this->mTouched
;
2317 $cache = new HTMLFileCache( $this->mTitle
);
2318 if($cache->isFileCacheGood( $touched )) {
2319 wfDebug( "Article::tryFileCache(): about to load file\n" );
2320 $cache->loadFromFileCache();
2323 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2324 ob_start( array(&$cache, 'saveToFileCache' ) );
2327 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2332 * Check if the page can be cached
2335 function isFileCacheable() {
2336 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2337 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2339 return $wgUseFileCache
2340 and (!$wgShowIPinHeader)
2341 and ($this->getID() != 0)
2342 and ($wgUser->isAnon())
2343 and (!$wgUser->getNewtalk())
2344 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2345 and (empty( $action ) ||
$action == 'view')
2346 and (!isset($oldid))
2348 and (!isset($redirect))
2349 and (!isset($printable))
2350 and (!$this->mRedirectedFrom
);
2354 * Loads page_touched and returns a value indicating if it should be used
2357 function checkTouched() {
2358 if( !$this->mDataLoaded
) {
2359 $this->loadPageData();
2361 return !$this->mIsRedirect
;
2365 * Get the page_touched field
2367 function getTouched() {
2368 # Ensure that page data has been loaded
2369 if( !$this->mDataLoaded
) {
2370 $this->loadPageData();
2372 return $this->mTouched
;
2376 * Get the page_latest field
2378 function getLatest() {
2379 if ( !$this->mDataLoaded
) {
2380 $this->loadPageData();
2382 return $this->mLatest
;
2386 * Edit an article without doing all that other stuff
2387 * The article must already exist; link tables etc
2388 * are not updated, caches are not flushed.
2390 * @param string $text text submitted
2391 * @param string $comment comment submitted
2392 * @param bool $minor whereas it's a minor modification
2394 function quickEdit( $text, $comment = '', $minor = 0 ) {
2395 wfProfileIn( __METHOD__
);
2397 $dbw =& wfGetDB( DB_MASTER
);
2399 $revision = new Revision( array(
2400 'page' => $this->getId(),
2402 'comment' => $comment,
2403 'minor_edit' => $minor ?
1 : 0,
2405 # fixme : $revisionId never used
2406 $revisionId = $revision->insertOn( $dbw );
2407 $this->updateRevisionOn( $dbw, $revision );
2410 wfProfileOut( __METHOD__
);
2414 * Used to increment the view counter
2417 * @param integer $id article id
2419 function incViewCount( $id ) {
2420 $id = intval( $id );
2421 global $wgHitcounterUpdateFreq, $wgDBtype;
2423 $dbw =& wfGetDB( DB_MASTER
);
2424 $pageTable = $dbw->tableName( 'page' );
2425 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2426 $acchitsTable = $dbw->tableName( 'acchits' );
2428 if( $wgHitcounterUpdateFreq <= 1 ){ //
2429 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2433 # Not important enough to warrant an error page in case of failure
2434 $oldignore = $dbw->ignoreErrors( true );
2436 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2438 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2439 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2440 # Most of the time (or on SQL errors), skip row count check
2441 $dbw->ignoreErrors( $oldignore );
2445 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2446 $row = $dbw->fetchObject( $res );
2447 $rown = intval( $row->n
);
2448 if( $rown >= $wgHitcounterUpdateFreq ){
2449 wfProfileIn( 'Article::incViewCount-collect' );
2450 $old_user_abort = ignore_user_abort( true );
2452 if ($wgDBtype == 'mysql')
2453 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2454 $tabletype = $wgDBtype == 'mysql' ?
"ENGINE=HEAP " : '';
2455 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
2456 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2458 $dbw->query("DELETE FROM $hitcounterTable");
2459 if ($wgDBtype == 'mysql')
2460 $dbw->query('UNLOCK TABLES');
2461 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2462 'WHERE page_id = hc_id');
2463 $dbw->query("DROP TABLE $acchitsTable");
2465 ignore_user_abort( $old_user_abort );
2466 wfProfileOut( 'Article::incViewCount-collect' );
2468 $dbw->ignoreErrors( $oldignore );
2472 * The onArticle*() functions are supposed to be a kind of hooks
2473 * which should be called whenever any of the specified actions
2476 * This is a good place to put code to clear caches, for instance.
2478 * This is called on page move and undelete, as well as edit
2480 * @param $title_obj a title object
2483 static function onArticleCreate($title) {
2484 # The talk page isn't in the regular link tables, so we need to update manually:
2485 if ( $title->isTalkPage() ) {
2486 $other = $title->getSubjectPage();
2488 $other = $title->getTalkPage();
2490 $other->invalidateCache();
2491 $other->purgeSquid();
2493 $title->touchLinks();
2494 $title->purgeSquid();
2497 static function onArticleDelete( $title ) {
2498 global $wgUseFileCache, $wgMessageCache;
2500 $title->touchLinks();
2501 $title->purgeSquid();
2504 if ( $wgUseFileCache ) {
2505 $cm = new HTMLFileCache( $title );
2506 @unlink
( $cm->fileCacheName() );
2509 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2510 $wgMessageCache->replace( $title->getDBkey(), false );
2515 * Purge caches on page update etc
2517 static function onArticleEdit( $title ) {
2518 global $wgDeferredUpdateList, $wgUseFileCache;
2522 // Invalidate caches of articles which include this page
2523 $update = new HTMLCacheUpdate( $title, 'templatelinks' );
2524 $wgDeferredUpdateList[] = $update;
2526 # Purge squid for this page only
2527 $title->purgeSquid();
2530 if ( $wgUseFileCache ) {
2531 $cm = new HTMLFileCache( $title );
2532 @unlink
( $cm->fileCacheName() );
2539 * Info about this page
2540 * Called for ?action=info when $wgAllowPageInfo is on.
2545 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2547 if ( !$wgAllowPageInfo ) {
2548 $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
2552 $page = $this->mTitle
->getSubjectPage();
2554 $wgOut->setPagetitle( $page->getPrefixedText() );
2555 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2557 # first, see if the page exists at all.
2558 $exists = $page->getArticleId() != 0;
2560 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2561 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle
->getText() ) );
2563 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2566 $dbr =& wfGetDB( DB_SLAVE
);
2568 'wl_title' => $page->getDBkey(),
2569 'wl_namespace' => $page->getNamespace() );
2570 $numwatchers = $dbr->selectField(
2575 $this->getSelectOptions() );
2577 $pageInfo = $this->pageCountInfo( $page );
2578 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2580 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2581 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2583 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2585 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2587 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2589 $wgOut->addHTML( '</ul>' );
2595 * Return the total number of edits and number of unique editors
2596 * on a given page. If page does not exist, returns false.
2598 * @param Title $title
2602 function pageCountInfo( $title ) {
2603 $id = $title->getArticleId();
2608 $dbr =& wfGetDB( DB_SLAVE
);
2610 $rev_clause = array( 'rev_page' => $id );
2612 $edits = $dbr->selectField(
2617 $this->getSelectOptions() );
2619 $authors = $dbr->selectField(
2621 'COUNT(DISTINCT rev_user_text)',
2624 $this->getSelectOptions() );
2626 return array( 'edits' => $edits, 'authors' => $authors );
2630 * Return a list of templates used by this article.
2631 * Uses the templatelinks table
2633 * @return array Array of Title objects
2635 function getUsedTemplates() {
2637 $id = $this->mTitle
->getArticleID();
2642 $dbr =& wfGetDB( DB_SLAVE
);
2643 $res = $dbr->select( array( 'templatelinks' ),
2644 array( 'tl_namespace', 'tl_title' ),
2645 array( 'tl_from' => $id ),
2646 'Article:getUsedTemplates' );
2647 if ( false !== $res ) {
2648 if ( $dbr->numRows( $res ) ) {
2649 while ( $row = $dbr->fetchObject( $res ) ) {
2650 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2654 $dbr->freeResult( $res );