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;
42 * Constructor and clear the article
43 * @param mixed &$title
45 function Article( &$title ) {
46 $this->mTitle
=& $title;
51 * get the title object of the article
63 $this->mDataLoaded
= false;
64 $this->mContentLoaded
= false;
66 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
67 $this->mRedirectedFrom
= $this->mUserText
=
68 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
69 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
70 $this->mTouched
= '19700101000000';
71 $this->mForUpdate
= false;
72 $this->mIsRedirect
= false;
73 $this->mRevIdFetched
= 0;
77 * Note that getContent/loadContent may follow redirects if
78 * not told otherwise, and so may cause a change to mTitle.
81 * @return Return the text of this revision
83 function getContent( $noredir ) {
84 global $wgRequest, $wgUser, $wgOut;
86 # Get variables from query string :P
87 $action = $wgRequest->getText( 'action', 'view' );
88 $section = $wgRequest->getText( 'section' );
89 $preload = $wgRequest->getText( 'preload' );
91 $fname = 'Article::getContent';
92 wfProfileIn( $fname );
94 if ( 0 == $this->getID() ) {
95 if ( 'edit' == $action ) {
96 wfProfileOut( $fname );
98 # If requested, preload some text.
99 $text=$this->getPreloadedText($preload);
101 # We used to put MediaWiki:Newarticletext here if
102 # $text was empty at this point.
103 # This is now shown above the edit box instead.
106 wfProfileOut( $fname );
107 $wgOut->setRobotpolicy( 'noindex,nofollow' );
109 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
110 return "<div class='noarticletext'>$ret</div>";
112 $this->loadContent( $noredir );
113 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
114 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
115 $wgUser->isIP($this->mTitle
->getText()) &&
118 wfProfileOut( $fname );
119 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
121 if($action=='edit') {
123 if($section=='new') {
124 wfProfileOut( $fname );
125 $text=$this->getPreloadedText($preload);
129 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
130 # comments to be stripped as well)
131 $rv=$this->getSection($this->mContent
,$section);
132 wfProfileOut( $fname );
136 wfProfileOut( $fname );
137 return $this->mContent
;
143 This function accepts a title string as parameter
144 ($preload). If this string is non-empty, it attempts
145 to fetch the current revision text. It respects
148 function getPreloadedText($preload) {
150 $preloadTitle=Title
::newFromText($preload);
151 if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
152 $rev=Revision
::newFromTitle($preloadTitle);
154 $text=$rev->getText();
155 $text=preg_replace('/<\/?includeonly>/i','',$text);
164 * This function returns the text of a section, specified by a number ($section).
165 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
166 * the first section before any such heading (section 0).
168 * If a section contains subsections, these are also returned.
170 * @param string $text text to look in
171 * @param integer $section section number
172 * @return string text of the requested section
174 function getSection($text,$section) {
176 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
177 # comments to be stripped as well)
179 $parser=new Parser();
180 $parser->mOutputType
=OT_WIKI
;
181 $parser->mOptions
= new ParserOptions();
182 $striptext=$parser->strip($text, $striparray, true);
184 # now that we can be sure that no pseudo-sections are in the source,
185 # split it up by section
188 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
190 PREG_SPLIT_DELIM_CAPTURE
);
194 $headline=$secs[$section*2-1];
195 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
198 # translate wiki heading into level
199 if(strpos($hlevel,'=')!==false) {
200 $hlevel=strlen($hlevel);
203 $rv=$headline. $secs[$section*2];
207 while(!empty($secs[$count*2-1]) && !$break) {
209 $subheadline=$secs[$count*2-1];
210 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
211 $subhlevel=$matches[1];
212 if(strpos($subhlevel,'=')!==false) {
213 $subhlevel=strlen($subhlevel);
215 if($subhlevel > $hlevel) {
216 $rv.=$subheadline.$secs[$count*2];
218 if($subhlevel <= $hlevel) {
225 # reinsert stripped tags
226 $rv=$parser->unstrip($rv,$striparray);
227 $rv=$parser->unstripNoWiki($rv,$striparray);
234 * Return the oldid of the article that is to be shown.
235 * For requests with a "direction", this is not the oldid of the
238 function getOldID() {
239 global $wgRequest, $wgOut;
242 if ( isset( $lastid ) ) {
246 $oldid = $wgRequest->getVal( 'oldid' );
247 if ( isset( $oldid ) ) {
248 $oldid = intval( $oldid );
249 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
250 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
254 $wgOut->redirect( $this->mTitle
->getFullURL( 'redirect=no' ) );
256 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
257 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
266 return @$oldid; # "@" to be able to return "unset" without PHP complaining
271 * Load the revision (including cur_text) into this object
273 function loadContent( $noredir = false ) {
274 global $wgOut, $wgRequest;
276 if ( $this->mContentLoaded
) return;
279 $oldid = $this->getOldID();
280 $redirect = $wgRequest->getVal( 'redirect' );
282 $fname = 'Article::loadContent';
284 # Pre-fill content with error message so that if something
285 # fails we'll have something telling us what we intended.
287 $t = $this->mTitle
->getPrefixedText();
289 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no')
290 ||
$wgRequest->getCheck( 'rdfrom' );
291 $this->mOldId
= $oldid;
292 $this->fetchContent( $oldid, $noredir, true );
297 * Fetch a page record with the given conditions
298 * @param Database $dbr
299 * @param array $conditions
302 function pageData( &$dbr, $conditions ) {
303 return $dbr->selectRow( 'page',
317 'Article::pageData' );
320 function pageDataFromTitle( &$dbr, $title ) {
321 return $this->pageData( $dbr, array(
322 'page_namespace' => $title->getNamespace(),
323 'page_title' => $title->getDBkey() ) );
326 function pageDataFromId( &$dbr, $id ) {
327 return $this->pageData( $dbr, array(
328 'page_id' => intval( $id ) ) );
332 * Set the general counter, title etc data loaded from
335 * @param object $data
338 function loadPageData( $data ) {
339 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
340 $this->mTitle
->mRestrictionsLoaded
= true;
342 $this->mCounter
= $data->page_counter
;
343 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
344 $this->mIsRedirect
= $data->page_is_redirect
;
345 $this->mLatest
= $data->page_latest
;
347 $this->mDataLoaded
= true;
351 * Get text of an article from database
352 * @param int $oldid 0 for whatever the latest revision is
353 * @param bool $noredir Set to false to follow redirects
354 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
357 function fetchContent( $oldid = 0, $noredir = true, $globalTitle = false ) {
358 if ( $this->mContentLoaded
) {
359 return $this->mContent
;
361 $dbr =& $this->getDB();
362 $fname = 'Article::fetchContent';
364 # Pre-fill content with error message so that if something
365 # fails we'll have something telling us what we intended.
366 $t = $this->mTitle
->getPrefixedText();
368 $t .= ',oldid='.$oldid;
370 if( isset( $redirect ) ) {
371 $redirect = ($redirect == 'no') ?
'no' : 'yes';
372 $t .= ',redirect='.$redirect;
374 $this->mContent
= wfMsg( 'missingarticle', $t );
377 $revision = Revision
::newFromId( $oldid );
378 if( is_null( $revision ) ) {
379 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
382 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
384 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
387 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
388 $this->loadPageData( $data );
390 if( !$this->mDataLoaded
) {
391 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
393 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
396 $this->loadPageData( $data );
398 $revision = Revision
::newFromId( $this->mLatest
);
399 if( is_null( $revision ) ) {
400 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
405 # If we got a redirect, follow it (unless we've been told
406 # not to by either the function parameter or the query
407 if ( !$oldid && !$noredir ) {
408 $rt = Title
::newFromRedirect( $revision->getText() );
409 # process if title object is valid and not special:userlogout
410 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
411 # Gotta hand redirects to special pages differently:
412 # Fill the HTTP response "Location" header and ignore
413 # the rest of the page we're on.
414 global $wgDisableHardRedirects;
415 if( $globalTitle && !$wgDisableHardRedirects ) {
417 if ( $rt->getInterwiki() != '' && $rt->isLocal() ) {
418 $source = $this->mTitle
->getFullURL( 'redirect=no' );
419 $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ;
422 if ( $rt->getNamespace() == NS_SPECIAL
) {
423 $wgOut->redirect( $rt->getFullURL() );
427 if( $rt->getInterwiki() == '' ) {
428 $redirData = $this->pageDataFromTitle( $dbr, $rt );
430 $redirRev = Revision
::newFromId( $redirData->page_latest
);
431 if( !is_null( $redirRev ) ) {
432 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
435 $this->loadPageData( $data );
436 $revision = $redirRev;
443 # if the title's different from expected, update...
446 if( !$this->mTitle
->equals( $wgTitle ) ) {
447 $wgTitle = $this->mTitle
;
451 # Back to the business at hand...
452 $this->mContent
= $revision->getText();
454 $this->mUser
= $revision->getUser();
455 $this->mUserText
= $revision->getUserText();
456 $this->mComment
= $revision->getComment();
457 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
459 $this->mRevIdFetched
= $revision->getID();
460 $this->mContentLoaded
= true;
461 $this->mRevision
=& $revision;
463 return $this->mContent
;
467 * Gets the article text without using so many damn globals
468 * Returns false on error
470 * @param integer $oldid
472 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
473 return $this->fetchContent( $oldid, $noredir, false );
477 * Read/write accessor to select FOR UPDATE
479 function forUpdate( $x = NULL ) {
480 return wfSetVar( $this->mForUpdate
, $x );
484 * Get the database which should be used for reads
487 $ret =& wfGetDB( DB_MASTER
);
489 #if ( $this->mForUpdate ) {
490 $ret =& wfGetDB( DB_MASTER
);
492 # $ret =& wfGetDB( DB_SLAVE );
498 * Get options for all SELECT statements
499 * Can pass an option array, to which the class-wide options will be appended
501 function getSelectOptions( $options = '' ) {
502 if ( $this->mForUpdate
) {
503 if ( is_array( $options ) ) {
504 $options[] = 'FOR UPDATE';
506 $options = 'FOR UPDATE';
513 * Return the Article ID
516 if( $this->mTitle
) {
517 return $this->mTitle
->getArticleID();
524 * Returns true if this article exists in the database.
528 return $this->getId() != 0;
532 * Get the view count for this article
534 function getCount() {
535 if ( -1 == $this->mCounter
) {
536 $id = $this->getID();
537 $dbr =& $this->getDB();
538 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
539 'Article::getCount', $this->getSelectOptions() );
541 return $this->mCounter
;
545 * Would the given text make this article a "good" article (i.e.,
546 * suitable for including in the article count)?
547 * @param string $text Text to analyze
548 * @return integer 1 if it can be counted else 0
550 function isCountable( $text ) {
551 global $wgUseCommaCount;
553 if ( NS_MAIN
!= $this->mTitle
->getNamespace() ) { return 0; }
554 if ( $this->isRedirect( $text ) ) { return 0; }
555 $token = ($wgUseCommaCount ?
',' : '[[' );
556 if ( false === strstr( $text, $token ) ) { return 0; }
561 * Tests if the article text represents a redirect
563 function isRedirect( $text = false ) {
564 if ( $text === false ) {
565 $this->loadContent();
566 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
568 $titleObj = Title
::newFromRedirect( $text );
570 return $titleObj !== NULL;
574 * Returns true if the currently-referenced revision is the current edit
575 * to this page (and it exists).
578 function isCurrent() {
579 return $this->exists() &&
580 isset( $this->mRevision
) &&
581 $this->mRevision
->isCurrent();
585 * Loads everything except the text
586 * This isn't necessary for all uses, so it's only done if needed.
589 function loadLastEdit() {
592 if ( -1 != $this->mUser
)
595 # New or non-existent articles have no user information
596 $id = $this->getID();
597 if ( 0 == $id ) return;
599 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
600 if( !is_null( $this->mLastRevision
) ) {
601 $this->mUser
= $this->mLastRevision
->getUser();
602 $this->mUserText
= $this->mLastRevision
->getUserText();
603 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
604 $this->mComment
= $this->mLastRevision
->getComment();
605 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
609 function getTimestamp() {
610 $this->loadLastEdit();
611 return wfTimestamp(TS_MW
, $this->mTimestamp
);
615 $this->loadLastEdit();
619 function getUserText() {
620 $this->loadLastEdit();
621 return $this->mUserText
;
624 function getComment() {
625 $this->loadLastEdit();
626 return $this->mComment
;
629 function getMinorEdit() {
630 $this->loadLastEdit();
631 return $this->mMinorEdit
;
634 function getRevIdFetched() {
635 $this->loadLastEdit();
636 return $this->mRevIdFetched
;
639 function getContributors($limit = 0, $offset = 0) {
640 $fname = 'Article::getContributors';
642 # XXX: this is expensive; cache this info somewhere.
644 $title = $this->mTitle
;
646 $dbr =& $this->getDB();
647 $revTable = $dbr->tableName( 'revision' );
648 $userTable = $dbr->tableName( 'user' );
649 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
650 $ns = $title->getNamespace();
651 $user = $this->getUser();
652 $pageId = $this->getId();
654 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
655 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
656 WHERE rev_page = $pageId
657 AND rev_user != $user
658 GROUP BY rev_user, rev_user_text, user_real_name
659 ORDER BY timestamp DESC";
661 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
662 $sql .= ' '. $this->getSelectOptions();
664 $res = $dbr->query($sql, $fname);
666 while ( $line = $dbr->fetchObject( $res ) ) {
667 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
670 $dbr->freeResult($res);
675 * This is the default action of the script: just view the page of
679 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
680 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
681 global $wgParserCache, $wgUseTrackbacks;
682 $sk = $wgUser->getSkin();
684 $fname = 'Article::view';
685 wfProfileIn( $fname );
686 # Get variables from query string
687 $oldid = $this->getOldID();
688 $diff = $wgRequest->getVal( 'diff' );
689 $rcid = $wgRequest->getVal( 'rcid' );
690 $rdfrom = $wgRequest->getVal( 'rdfrom' );
692 $wgOut->setArticleFlag( true );
693 $wgOut->setRobotpolicy( 'index,follow' );
694 # If we got diff and oldid in the query, we want to see a
695 # diff page instead of the article.
697 if ( !is_null( $diff ) ) {
698 require_once( 'DifferenceEngine.php' );
699 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
701 $de = new DifferenceEngine( $this->mTitle
, $oldid, $diff, $rcid );
702 // DifferenceEngine directly fetched the revision:
703 $this->mRevIdFetched
= $de->mNewid
;
707 # Run view updates for current revision only
708 $this->viewUpdates();
710 wfProfileOut( $fname );
714 if ( empty( $oldid ) && $this->checkTouched() ) {
715 $wgOut->setETag($wgParserCache->getETag($this, $wgUser));
717 if( $wgOut->checkLastModified( $this->mTouched
) ){
718 wfProfileOut( $fname );
720 } else if ( $this->tryFileCache() ) {
721 # tell wgOut that output is taken care of
723 $this->viewUpdates();
724 wfProfileOut( $fname );
728 # Should the parser cache be used?
729 $pcache = $wgEnableParserCache &&
730 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
733 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
737 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
741 if ( !$outputDone ) {
742 $text = $this->getContent( false ); # May change mTitle by following a redirect
744 # Another whitelist check in case oldid or redirects are altering the title
745 if ( !$this->mTitle
->userCanRead() ) {
746 $wgOut->loginToUse();
751 # We're looking at an old revision
753 if ( !empty( $oldid ) ) {
754 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
755 $wgOut->setRobotpolicy( 'noindex,follow' );
757 $wasRedirected = false;
758 if ( '' != $this->mRedirectedFrom
) {
759 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
760 $sk = $wgUser->getSkin();
761 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '', 'redirect=no' );
762 $s = wfMsg( 'redirectedfrom', $redir );
763 $wgOut->setSubtitle( $s );
765 // Check the parser cache again, for the target page
767 if( $wgOut->tryParserCache( $this, $wgUser ) ) {
771 $wasRedirected = true;
773 } elseif ( !empty( $rdfrom ) ) {
774 global $wgRedirectSources;
775 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
776 $sk = $wgUser->getSkin();
777 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
778 $s = wfMsg( 'redirectedfrom', $redir );
779 $wgOut->setSubtitle( $s );
780 $wasRedirected = true;
785 # wrap user css and user js in pre and don't parse
786 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
788 $this->mTitle
->getNamespace() == NS_USER
&&
789 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
791 $wgOut->addWikiText( wfMsg('clearyourcache'));
792 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
793 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
795 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
796 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
797 if( !$wasRedirected ) {
798 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
800 $targetUrl = $rt->escapeLocalURL();
801 $titleText = htmlspecialchars( $rt->getPrefixedText() );
802 $link = $sk->makeLinkObj( $rt );
804 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
805 '<span class="redirectText">'.$link.'</span>' );
807 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
808 $catlinks = $parseout->getCategoryLinks();
809 $wgOut->addCategoryLinks($catlinks);
810 $skin = $wgUser->getSkin();
811 } else if ( $pcache ) {
812 # Display content and save to parser cache
813 $wgOut->setRevisionId( $this->getRevIdFetched() );
814 $wgOut->addPrimaryWikiText( $text, $this );
816 # Display content, don't attempt to save to parser cache
818 # Don't show section-edit links on old revisions... this way lies madness.
819 if( !$this->isCurrent() ) {
820 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
822 $wgOut->setRevisionId( $this->getRevIdFetched() );
823 $wgOut->addWikiText( $text );
825 if( !$this->isCurrent() ) {
826 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
830 /* title may have been set from the cache */
831 $t = $wgOut->getPageTitle();
833 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
836 # If we have been passed an &rcid= parameter, we want to give the user a
837 # chance to mark this new article as patrolled.
841 && $wgUser->isLoggedIn()
842 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
845 "<div class='patrollink'>" .
846 wfMsg ( 'markaspatrolledlink',
847 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
854 if ($wgUseTrackbacks)
855 $this->addTrackbacks();
857 # Add link titles as META keywords
858 $wgOut->addMetaTags() ;
860 $this->viewUpdates();
861 wfProfileOut( $fname );
864 function addTrackbacks() {
865 global $wgOut, $wgUser;
867 $dbr =& wfGetDB(DB_SLAVE
);
869 /* FROM */ 'trackbacks',
870 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
871 /* WHERE */ array('tb_page' => $this->getID())
874 if (!$dbr->numrows($tbs))
878 while ($o = $dbr->fetchObject($tbs)) {
880 if ($wgUser->isSysop()) {
881 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
882 . $o->tb_id
. "&token=" . $wgUser->editToken());
883 $rmvtxt = wfMsg('trackbackremove', $delurl);
885 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
892 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
895 function deletetrackback() {
896 global $wgUser, $wgRequest, $wgOut, $wgTitle;
898 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
899 $wgOut->addWikitext(wfMsg('sessionfailure'));
903 if ((!$wgUser->isAllowed('delete'))) {
904 $wgOut->sysopRequired();
909 $wgOut->readOnlyPage();
913 $db =& wfGetDB(DB_MASTER
);
914 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
915 $wgTitle->invalidateCache();
916 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
922 $wgOut->setArticleBodyOnly(true);
927 global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
929 if ( $wgUser->isLoggedIn() ||
$wgRequest->wasPosted() ) {
930 // Invalidate the cache
931 $this->mTitle
->invalidateCache();
934 // Commit the transaction before the purge is sent
935 $dbw = wfGetDB( DB_MASTER
);
936 $dbw->immediateCommit();
939 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
944 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
945 $action = $this->mTitle
->escapeLocalURL( 'action=purge' );
946 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
947 $msg = str_replace( '$1',
948 "<form method=\"post\" action=\"$action\">\n" .
949 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
952 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
953 $wgOut->setRobotpolicy( 'noindex,nofollow' );
954 $wgOut->addHTML( $msg );
959 * Insert a new empty page record for this article.
960 * This *must* be followed up by creating a revision
961 * and running $this->updateToLatest( $rev_id );
962 * or else the record will be left in a funky state.
963 * Best if all done inside a transaction.
965 * @param Database $dbw
966 * @param string $restrictions
967 * @return int The newly created page_id key
970 function insertOn( &$dbw, $restrictions = '' ) {
971 $fname = 'Article::insertOn';
972 wfProfileIn( $fname );
974 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
975 $dbw->insert( 'page', array(
976 'page_id' => $page_id,
977 'page_namespace' => $this->mTitle
->getNamespace(),
978 'page_title' => $this->mTitle
->getDBkey(),
980 'page_restrictions' => $restrictions,
981 'page_is_redirect' => 0, # Will set this shortly...
983 'page_random' => wfRandom(),
984 'page_touched' => $dbw->timestamp(),
985 'page_latest' => 0, # Fill this in shortly...
986 'page_len' => 0, # Fill this in shortly...
988 $newid = $dbw->insertId();
990 $this->mTitle
->resetArticleId( $newid );
992 wfProfileOut( $fname );
997 * Update the page record to point to a newly saved revision.
999 * @param Database $dbw
1000 * @param Revision $revision -- for ID number, and text used to set
1001 length and redirect status fields
1002 * @param int $lastRevision -- if given, will not overwrite the page field
1003 * when different from the currently set value.
1004 * Giving 0 indicates the new page flag should
1006 * @return bool true on success, false on failure
1009 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1010 $fname = 'Article::updateToRevision';
1011 wfProfileIn( $fname );
1013 $conditions = array( 'page_id' => $this->getId() );
1014 if( !is_null( $lastRevision ) ) {
1015 # An extra check against threads stepping on each other
1016 $conditions['page_latest'] = $lastRevision;
1019 $text = $revision->getText();
1020 $dbw->update( 'page',
1022 'page_latest' => $revision->getId(),
1023 'page_touched' => $dbw->timestamp(),
1024 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
1025 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
1026 'page_len' => strlen( $text ),
1031 wfProfileOut( $fname );
1032 return ( $dbw->affectedRows() != 0 );
1036 * If the given revision is newer than the currently set page_latest,
1037 * update the page record. Otherwise, do nothing.
1039 * @param Database $dbw
1040 * @param Revision $revision
1042 function updateIfNewerOn( &$dbw, $revision ) {
1043 $fname = 'Article::updateIfNewerOn';
1044 wfProfileIn( $fname );
1046 $row = $dbw->selectRow(
1047 array( 'revision', 'page' ),
1048 array( 'rev_id', 'rev_timestamp' ),
1050 'page_id' => $this->getId(),
1051 'page_latest=rev_id' ),
1054 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1055 wfProfileOut( $fname );
1058 $prev = $row->rev_id
;
1060 # No or missing previous revision; mark the page as new
1064 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1065 wfProfileOut( $fname );
1070 * Theoretically we could defer these whole insert and update
1071 * functions for after display, but that's taking a big leap
1072 * of faith, and we want to be able to report database
1073 * errors at some point.
1076 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1077 global $wgOut, $wgUser, $wgUseSquid;
1079 $fname = 'Article::insertNewArticle';
1080 wfProfileIn( $fname );
1082 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1083 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1084 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1085 wfProfileOut( $fname );
1089 $this->mGoodAdjustment
= $this->isCountable( $text );
1090 $this->mTotalAdjustment
= 1;
1092 $ns = $this->mTitle
->getNamespace();
1093 $ttl = $this->mTitle
->getDBkey();
1095 # If this is a comment, add the summary as headline
1096 if($comment && $summary!="") {
1097 $text="== {$summary} ==\n\n".$text;
1099 $text = $this->preSaveTransform( $text );
1100 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1101 $now = wfTimestampNow();
1103 $dbw =& wfGetDB( DB_MASTER
);
1105 # Add the page record; stake our claim on this title!
1106 $newid = $this->insertOn( $dbw );
1108 # Save the revision text...
1109 $revision = new Revision( array(
1111 'comment' => $summary,
1112 'minor_edit' => $isminor,
1115 $revisionId = $revision->insertOn( $dbw );
1117 $this->mTitle
->resetArticleID( $newid );
1119 # Update the page record with revision data
1120 $this->updateRevisionOn( $dbw, $revision, 0 );
1122 Article
::onArticleCreate( $this->mTitle
);
1124 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1125 '', strlen( $text ), $revisionId );
1129 if(!$this->mTitle
->userIsWatching()) $this->watch();
1131 if ( $this->mTitle
->userIsWatching() ) {
1136 # The talk page isn't in the regular link tables, so we need to update manually:
1137 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1138 $dbw->update( 'page',
1139 array( 'page_touched' => $dbw->timestamp($now) ),
1140 array( 'page_namespace' => $talkns,
1141 'page_title' => $ttl ),
1144 # standard deferred updates
1145 $this->editUpdates( $text, $summary, $isminor, $now );
1147 $oldid = 0; # new article
1148 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid, $revisionId );
1150 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1152 $watchthis, NULL ) );
1153 wfProfileOut( $fname );
1156 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1157 $this->replaceSection( $section, $text, $summary, $edittime );
1161 * @return string Complete article text, or null if error
1163 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1164 $fname = 'Article::replaceSection';
1165 wfProfileIn( $fname );
1167 if ($section != '') {
1168 if( is_null( $edittime ) ) {
1169 $rev = Revision
::newFromTitle( $this->mTitle
);
1171 $dbw =& wfGetDB( DB_MASTER
);
1172 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1174 if( is_null( $rev ) ) {
1175 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1176 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1179 $oldtext = $rev->getText();
1181 if($section=='new') {
1182 if($summary) $subject="== {$summary} ==\n\n";
1183 $text=$oldtext."\n\n".$subject.$text;
1186 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1187 # comments to be stripped as well)
1188 $striparray=array();
1189 $parser=new Parser();
1190 $parser->mOutputType
=OT_WIKI
;
1191 $parser->mOptions
= new ParserOptions();
1192 $oldtext=$parser->strip($oldtext, $striparray, true);
1194 # now that we can be sure that no pseudo-sections are in the source,
1196 # Unfortunately we can't simply do a preg_replace because that might
1197 # replace the wrong section, so we have to use the section counter instead
1198 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1199 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1200 $secs[$section*2]=$text."\n\n"; // replace with edited
1202 # section 0 is top (intro) section
1205 # headline of old section - we need to go through this section
1206 # to determine if there are any subsections that now need to
1207 # be erased, as the mother section has been replaced with
1208 # the text of all subsections.
1209 $headline=$secs[$section*2-1];
1210 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1211 $hlevel=$matches[1];
1213 # determine headline level for wikimarkup headings
1214 if(strpos($hlevel,'=')!==false) {
1215 $hlevel=strlen($hlevel);
1218 $secs[$section*2-1]=''; // erase old headline
1221 while(!empty($secs[$count*2-1]) && !$break) {
1223 $subheadline=$secs[$count*2-1];
1225 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1226 $subhlevel=$matches[1];
1227 if(strpos($subhlevel,'=')!==false) {
1228 $subhlevel=strlen($subhlevel);
1230 if($subhlevel > $hlevel) {
1231 // erase old subsections
1232 $secs[$count*2-1]='';
1235 if($subhlevel <= $hlevel) {
1243 $text=join('',$secs);
1244 # reinsert the stuff that we stripped out earlier
1245 $text=$parser->unstrip($text,$striparray);
1246 $text=$parser->unstripNoWiki($text,$striparray);
1250 wfProfileOut( $fname );
1255 * Change an existing article. Puts the previous version back into the old table, updates RC
1256 * and all necessary caches, mostly via the deferred update array.
1258 * It is possible to call this function from a command-line script, but note that you should
1259 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1261 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1262 global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
1263 global $wgPostCommitUpdateList, $wgUseFileCache;
1265 $fname = 'Article::updateArticle';
1266 wfProfileIn( $fname );
1269 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1271 &$watchthis, &$sectionanchor ) ) ) {
1272 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1273 wfProfileOut( $fname );
1277 $isminor = ( $minor && $wgUser->isLoggedIn() );
1278 if ( $this->isRedirect( $text ) ) {
1279 # Remove all content but redirect
1280 # This could be done by reconstructing the redirect from a title given by
1281 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1283 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1285 $text = $m[1] . "\n";
1288 else { $redir = 0; }
1290 $text = $this->preSaveTransform( $text );
1291 $dbw =& wfGetDB( DB_MASTER
);
1292 $now = wfTimestampNow();
1294 # Update article, but only if changed.
1296 # It's important that we either rollback or complete, otherwise an attacker could
1297 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1298 # could conceivably have the same effect, especially if cur is locked for long periods.
1299 if( !$wgDBtransactions ) {
1300 $userAbort = ignore_user_abort( true );
1303 $oldtext = $this->getContent( true );
1304 $oldsize = strlen( $oldtext );
1305 $newsize = strlen( $text );
1308 if ( 0 != strcmp( $text, $oldtext ) ) {
1309 $this->mGoodAdjustment
= $this->isCountable( $text )
1310 - $this->isCountable( $oldtext );
1311 $this->mTotalAdjustment
= 0;
1312 $now = wfTimestampNow();
1314 $lastRevision = $dbw->selectField(
1315 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1317 $revision = new Revision( array(
1318 'page' => $this->getId(),
1319 'comment' => $summary,
1320 'minor_edit' => $isminor,
1324 $dbw->immediateCommit();
1326 $revisionId = $revision->insertOn( $dbw );
1329 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1332 /* Belated edit conflict! Run away!! */
1336 # Update recentchanges and purge cache and whatnot
1337 $bot = (int)($wgUser->isBot() ||
$forceBot);
1338 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1339 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1341 Article
::onArticleEdit( $this->mTitle
);
1346 if( !$wgDBtransactions ) {
1347 ignore_user_abort( $userAbort );
1352 if (!$this->mTitle
->userIsWatching()) {
1353 $dbw->immediateCommit();
1359 if ( $this->mTitle
->userIsWatching() ) {
1360 $dbw->immediateCommit();
1366 # standard deferred updates
1367 $this->editUpdates( $text, $summary, $minor, $now );
1371 # Template namespace
1372 # Purge all articles linking here
1373 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1374 $titles = $this->mTitle
->getLinksTo();
1375 Title
::touchArray( $titles );
1376 if ( $wgUseSquid ) {
1377 foreach ( $titles as $title ) {
1378 $urls[] = $title->getInternalURL();
1384 if ( $wgUseSquid ) {
1385 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1386 $u = new SquidUpdate( $urls );
1387 array_push( $wgPostCommitUpdateList, $u );
1391 if ( $wgUseFileCache ) {
1392 $cm = new CacheManager($this->mTitle
);
1393 @unlink
($cm->fileCacheName());
1396 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
1398 wfRunHooks( 'ArticleSaveComplete',
1399 array( &$this, &$wgUser, $text,
1401 $watchthis, $sectionanchor ) );
1402 wfProfileOut( $fname );
1407 * After we've either updated or inserted the article, update
1408 * the link tables and redirect to the new page.
1410 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
1411 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1412 global $wgUseEnotif;
1414 $fname = 'Article::showArticle';
1415 wfProfileIn( $fname );
1417 $wgLinkCache = new LinkCache();
1419 if ( !$wgUseDumbLinkUpdate ) {
1420 # Preload links to reduce lock time
1421 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1422 $wgLinkCache->preFill( $this->mTitle
);
1423 $wgLinkCache->clear();
1427 # Parse the text and save it to the parser cache
1428 $wgOut = new OutputPage();
1429 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
1430 $wgOut->setRevisionId( $newid );
1431 $wgOut->addPrimaryWikiText( $text, $this );
1433 if ( !$wgUseDumbLinkUpdate ) {
1434 # Move the current links back to the second register
1435 $wgLinkCache->swapRegisters();
1437 # Get old version of link table to allow incremental link updates
1438 # Lock this data now since it is needed for an update
1439 $wgLinkCache->forUpdate( true );
1440 $wgLinkCache->preFill( $this->mTitle
);
1442 # Swap this old version back into its rightful place
1443 $wgLinkCache->swapRegisters();
1446 if( $this->isRedirect( $text ) )
1450 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1452 if ( $wgUseEnotif ) {
1453 # this would be better as an extension hook
1454 include_once( "UserMailer.php" );
1455 $wgEnotif = new EmailNotification ();
1456 $wgEnotif->notifyOnPageChange( $this->mTitle
, $now, $summary, $me2, $oldid );
1458 wfProfileOut( $fname );
1462 * Mark this particular edit as patrolled
1464 function markpatrolled() {
1465 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1466 $wgOut->setRobotpolicy( 'noindex,follow' );
1468 if ( !$wgUseRCPatrol )
1470 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1473 if ( $wgUser->isAnon() )
1475 $wgOut->loginToUse();
1478 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1480 $wgOut->sysopRequired();
1483 $rcid = $wgRequest->getVal( 'rcid' );
1484 if ( !is_null ( $rcid ) )
1486 RecentChange
::markPatrolled( $rcid );
1487 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1488 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1490 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1491 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1495 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1502 function validate() {
1503 global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
1505 if ( !$wgUseValidation ) # Are we using article validation at all?
1507 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
1511 $wgOut->setRobotpolicy( 'noindex,follow' );
1512 $revision = $wgRequest->getVal( 'revision' );
1514 include_once ( "SpecialValidate.php" ) ; # The "Validation" class
1516 $v = new Validation
;
1517 if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
1518 $t = $v->showList ( $this ) ;
1519 else if ( $wgRequest->getVal ( "mode" , "" ) == "details" )
1520 $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ;
1522 $t = $v->validatePageForm ( $this , $revision ) ;
1524 $wgOut->addHTML ( $t ) ;
1528 * Add this page to $wgUser's watchlist
1533 global $wgUser, $wgOut;
1535 if ( $wgUser->isAnon() ) {
1536 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1539 if ( wfReadOnly() ) {
1540 $wgOut->readOnlyPage();
1544 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1546 $wgUser->addWatch( $this->mTitle
);
1547 $wgUser->saveSettings();
1549 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1551 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1552 $wgOut->setRobotpolicy( 'noindex,follow' );
1554 $link = $this->mTitle
->getPrefixedText();
1555 $text = wfMsg( 'addedwatchtext', $link );
1556 $wgOut->addWikiText( $text );
1559 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1563 * Stop watching a page
1566 function unwatch() {
1568 global $wgUser, $wgOut;
1570 if ( $wgUser->isAnon() ) {
1571 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1574 if ( wfReadOnly() ) {
1575 $wgOut->readOnlyPage();
1579 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1581 $wgUser->removeWatch( $this->mTitle
);
1582 $wgUser->saveSettings();
1584 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1586 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1587 $wgOut->setRobotpolicy( 'noindex,follow' );
1589 $link = $this->mTitle
->getPrefixedText();
1590 $text = wfMsg( 'removedwatchtext', $link );
1591 $wgOut->addWikiText( $text );
1594 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1600 function protect( $limit = 'sysop' ) {
1601 global $wgUser, $wgOut, $wgRequest;
1603 if ( ! $wgUser->isAllowed('protect') ) {
1604 $wgOut->sysopRequired();
1607 if ( wfReadOnly() ) {
1608 $wgOut->readOnlyPage();
1611 $id = $this->mTitle
->getArticleID();
1613 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1617 $confirm = $wgRequest->wasPosted() &&
1618 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1619 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1620 $reason = $wgRequest->getText( 'wpReasonProtect' );
1623 $dbw =& wfGetDB( DB_MASTER
);
1624 $dbw->update( 'page',
1626 'page_touched' => $dbw->timestamp(),
1627 'page_restrictions' => (string)$limit
1628 ), array( /* WHERE */
1630 ), 'Article::protect'
1633 $restrictions = "move=" . $limit;
1635 $restrictions .= ":edit=" . $limit;
1637 if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
1639 $dbw =& wfGetDB( DB_MASTER
);
1640 $dbw->update( 'page',
1642 'page_touched' => $dbw->timestamp(),
1643 'page_restrictions' => $restrictions
1644 ), array( /* WHERE */
1646 ), 'Article::protect'
1649 wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
1651 $log = new LogPage( 'protect' );
1652 if ( $limit === '' ) {
1653 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1655 $log->addEntry( 'protect', $this->mTitle
, $reason );
1657 $wgOut->redirect( $this->mTitle
->getFullURL() );
1661 return $this->confirmProtect( '', '', $limit );
1666 * Output protection confirmation dialog
1668 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1669 global $wgOut, $wgUser;
1671 wfDebug( "Article::confirmProtect\n" );
1673 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1674 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1680 if ( $limit === '' ) {
1681 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1682 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1683 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1684 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1685 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1687 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1688 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1689 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1690 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1691 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1692 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1695 $confirm = htmlspecialchars( wfMsg( 'protectpage' ) );
1696 $token = htmlspecialchars( $wgUser->editToken() );
1699 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1703 <label for='wpReasonProtect'>{$protcom}:</label>
1706 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1709 if($moveonly != '') {
1713 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1716 <label for='wpMoveOnly'>{$moveonly}</label>
1724 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1728 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1731 $wgOut->returnToMain( false );
1735 * Unprotect the pages
1737 function unprotect() {
1738 return $this->protect( '' );
1742 * UI entry point for page deletion
1745 global $wgUser, $wgOut, $wgRequest;
1746 $fname = 'Article::delete';
1747 $confirm = $wgRequest->wasPosted() &&
1748 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1749 $reason = $wgRequest->getText( 'wpReason' );
1751 # This code desperately needs to be totally rewritten
1754 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1755 $wgOut->sysopRequired();
1758 if( wfReadOnly() ) {
1759 $wgOut->readOnlyPage();
1763 # Better double-check that it hasn't been deleted yet!
1764 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1765 if( !$this->mTitle
->exists() ) {
1766 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1771 $this->doDelete( $reason );
1775 # determine whether this page has earlier revisions
1776 # and insert a warning if it does
1777 # we select the text because it might be useful below
1778 $dbr =& $this->getDB();
1779 $ns = $this->mTitle
->getNamespace();
1780 $title = $this->mTitle
->getDBkey();
1781 $revisions = $dbr->select( array( 'page', 'revision' ),
1782 array( 'rev_id', 'rev_user_text' ),
1784 'page_namespace' => $ns,
1785 'page_title' => $title,
1786 'rev_page = page_id'
1787 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1790 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1791 $skin=$wgUser->getSkin();
1792 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1793 $wgOut->addHTML( $skin->historyLink() .'</b>');
1797 $rev = Revision
::newFromTitle( $this->mTitle
);
1799 # Fetch name(s) of contributors
1801 $all_same_user = true;
1802 while( $row = $dbr->fetchObject( $revisions ) ) {
1803 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1804 $all_same_user = false;
1806 $rev_name = $row->rev_user_text
;
1810 if( !is_null( $rev ) ) {
1811 # if this is a mini-text, we can paste part of it into the deletion reason
1812 $text = $rev->getText();
1814 #if this is empty, an earlier revision may contain "useful" text
1817 $prev = $rev->getPrevious();
1819 $text = $prev->getText();
1824 $length = strlen( $text );
1826 # this should not happen, since it is not possible to store an empty, new
1827 # page. Let's insert a standard text in case it does, though
1828 if( $length == 0 && $reason === '' ) {
1829 $reason = wfMsgForContent( 'exblank' );
1832 if( $length < 500 && $reason === '' ) {
1833 # comment field=255, let's grep the first 150 to have some user
1836 $text = $wgContLang->truncate( $text, 150, '...' );
1838 # let's strip out newlines
1839 $text = preg_replace( "/[\n\r]/", '', $text );
1842 if( !$all_same_user ) {
1843 $reason = wfMsgForContent( 'excontent', $text );
1845 $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
1848 $reason = wfMsgForContent( 'exbeforeblank', $text );
1853 return $this->confirmDelete( '', $reason );
1857 * Output deletion confirmation dialog
1859 function confirmDelete( $par, $reason ) {
1860 global $wgOut, $wgUser;
1862 wfDebug( "Article::confirmDelete\n" );
1864 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1865 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1866 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1867 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1869 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1871 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1872 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1873 $token = htmlspecialchars( $wgUser->editToken() );
1876 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1880 <label for='wpReason'>{$delcom}:</label>
1883 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1889 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1893 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1896 $wgOut->returnToMain( false );
1901 * Perform a deletion and output success or failure messages
1903 function doDelete( $reason ) {
1904 global $wgOut, $wgUser, $wgContLang;
1905 $fname = 'Article::doDelete';
1906 wfDebug( $fname."\n" );
1908 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1909 if ( $this->doDeleteArticle( $reason ) ) {
1910 $deleted = $this->mTitle
->getPrefixedText();
1912 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1913 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1915 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1916 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1918 $wgOut->addWikiText( $text );
1919 $wgOut->returnToMain( false );
1920 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1922 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1928 * Back-end article deletion
1929 * Deletes the article with database consistency, writes logs, purges caches
1932 function doDeleteArticle( $reason ) {
1933 global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
1934 global $wgPostCommitUpdateList, $wgUseTrackbacks;
1936 $fname = 'Article::doDeleteArticle';
1937 wfDebug( $fname."\n" );
1939 $dbw =& wfGetDB( DB_MASTER
);
1940 $ns = $this->mTitle
->getNamespace();
1941 $t = $this->mTitle
->getDBkey();
1942 $id = $this->mTitle
->getArticleID();
1944 if ( $t == '' ||
$id == 0 ) {
1948 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1949 array_push( $wgDeferredUpdateList, $u );
1951 $linksTo = $this->mTitle
->getLinksTo();
1954 if ( $wgUseSquid ) {
1956 $this->mTitle
->getInternalURL(),
1957 $this->mTitle
->getInternalURL( 'history' )
1960 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1961 array_push( $wgPostCommitUpdateList, $u );
1965 # Client and file cache invalidation
1966 Title
::touchArray( $linksTo );
1969 // For now, shunt the revision data into the archive table.
1970 // Text is *not* removed from the text table; bulk storage
1971 // is left intact to avoid breaking block-compression or
1972 // immutable storage schemes.
1974 // For backwards compatibility, note that some older archive
1975 // table entries will have ar_text and ar_flags fields still.
1977 // In the future, we may keep revisions and mark them with
1978 // the rev_deleted field, which is reserved for this purpose.
1979 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1981 'ar_namespace' => 'page_namespace',
1982 'ar_title' => 'page_title',
1983 'ar_comment' => 'rev_comment',
1984 'ar_user' => 'rev_user',
1985 'ar_user_text' => 'rev_user_text',
1986 'ar_timestamp' => 'rev_timestamp',
1987 'ar_minor_edit' => 'rev_minor_edit',
1988 'ar_rev_id' => 'rev_id',
1989 'ar_text_id' => 'rev_text_id',
1992 'page_id = rev_page'
1996 # Now that it's safely backed up, delete it
1997 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1998 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
2000 if ($wgUseTrackbacks)
2001 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
2003 # Clean up recentchanges entries...
2004 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
2006 # Finally, clean up the link tables
2007 $t = $this->mTitle
->getPrefixedDBkey();
2009 Article
::onArticleDelete( $this->mTitle
);
2011 # Delete outgoing links
2012 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2013 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2014 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2017 $log = new LogPage( 'delete' );
2018 $log->addEntry( 'delete', $this->mTitle
, $reason );
2020 # Clear the cached article id so the interface doesn't act like we exist
2021 $this->mTitle
->resetArticleID( 0 );
2022 $this->mTitle
->mArticleID
= 0;
2027 * Revert a modification
2029 function rollback() {
2030 global $wgUser, $wgOut, $wgRequest;
2031 $fname = 'Article::rollback';
2033 if ( ! $wgUser->isAllowed('rollback') ) {
2034 $wgOut->sysopRequired();
2037 if ( wfReadOnly() ) {
2038 $wgOut->readOnlyPage( $this->getContent( true ) );
2041 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2042 array( $this->mTitle
->getPrefixedText(),
2043 $wgRequest->getVal( 'from' ) ) ) ) {
2044 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2045 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2048 $dbw =& wfGetDB( DB_MASTER
);
2050 # Enhanced rollback, marks edits rc_bot=1
2051 $bot = $wgRequest->getBool( 'bot' );
2053 # Replace all this user's current edits with the next one down
2054 $tt = $this->mTitle
->getDBKey();
2055 $n = $this->mTitle
->getNamespace();
2057 # Get the last editor, lock table exclusively
2059 $current = Revision
::newFromTitle( $this->mTitle
);
2060 if( is_null( $current ) ) {
2061 # Something wrong... no page?
2063 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2067 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2068 if( $from != $current->getUserText() ) {
2069 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2070 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2071 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2072 htmlspecialchars( $from ),
2073 htmlspecialchars( $current->getUserText() ) ) );
2074 if( $current->getComment() != '') {
2076 wfMsg( 'editcomment',
2077 htmlspecialchars( $current->getComment() ) ) );
2082 # Get the last edit not by this guy
2083 $user = intval( $current->getUser() );
2084 $user_text = $dbw->addQuotes( $current->getUserText() );
2085 $s = $dbw->selectRow( 'revision',
2086 array( 'rev_id', 'rev_timestamp' ),
2088 'rev_page' => $current->getPage(),
2089 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2092 'USE INDEX' => 'page_timestamp',
2093 'ORDER BY' => 'rev_timestamp DESC' )
2095 if( $s === false ) {
2098 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2099 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2104 # Mark all reverted edits as bot
2105 $dbw->update( 'recentchanges',
2108 ), array( /* WHERE */
2109 'rc_cur_id' => $current->getPage(),
2110 'rc_user_text' => $current->getUserText(),
2111 "rc_timestamp > '{$s->rev_timestamp}'",
2116 # Get the edit summary
2117 $target = Revision
::newFromId( $s->rev_id
);
2118 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2119 $newComment = $wgRequest->getText( 'summary', $newComment );
2122 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2123 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2124 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2126 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle
->userIsWatching(), $bot );
2127 Article
::onArticleEdit( $this->mTitle
);
2130 $wgOut->returnToMain( false );
2135 * Do standard deferred updates after page view
2138 function viewUpdates() {
2139 global $wgDeferredUpdateList, $wgUseEnotif;
2141 if ( 0 != $this->getID() ) {
2142 global $wgDisableCounters;
2143 if( !$wgDisableCounters ) {
2144 Article
::incViewCount( $this->getID() );
2145 $u = new SiteStatsUpdate( 1, 0, 0 );
2146 array_push( $wgDeferredUpdateList, $u );
2150 # Update newtalk status if user is reading their own
2154 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
2155 $this->mTitle
->getText() == $wgUser->getName())
2157 if ( $wgUseEnotif ) {
2158 require_once( 'UserTalkUpdate.php' );
2159 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
2161 $wgUser->setNewtalk(0);
2162 $wgUser->saveNewtalk();
2164 } elseif ( $wgUseEnotif ) {
2165 $wgUser->clearNotification( $this->mTitle
);
2171 * Do standard deferred updates after page edit.
2172 * Every 1000th edit, prune the recent changes table.
2174 * @param string $text
2176 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2177 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgUseEnotif;
2179 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2181 if ( 0 == mt_rand( 0, 999 ) ) {
2182 # Periodically flush old entries from the recentchanges table.
2185 $dbw =& wfGetDB( DB_MASTER
);
2186 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2187 $recentchanges = $dbw->tableName( 'recentchanges' );
2188 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2189 $dbw->query( $sql );
2193 $id = $this->getID();
2194 $title = $this->mTitle
->getPrefixedDBkey();
2195 $shortTitle = $this->mTitle
->getDBkey();
2198 $u = new LinksUpdate( $id, $title );
2199 array_push( $wgDeferredUpdateList, $u );
2200 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2201 array_push( $wgDeferredUpdateList, $u );
2202 $u = new SearchUpdate( $id, $title, $text );
2203 array_push( $wgDeferredUpdateList, $u );
2205 # If this is another user's talk page, update newtalk
2207 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2208 if ( $wgUseEnotif ) {
2209 require_once( 'UserTalkUpdate.php' );
2210 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary,
2211 $minoredit, $timestamp_of_pagechange);
2213 $other = User
::newFromName( $shortTitle );
2214 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2215 // An anonymous user
2216 $other = new User();
2217 $other->setName( $shortTitle );
2220 $other->setNewtalk(1);
2221 $other->saveNewtalk();
2226 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2227 $wgMessageCache->replace( $shortTitle, $text );
2233 * @todo document this function
2235 * @param string $oldid Revision ID of this article revision
2237 function setOldSubtitle( $oldid=0 ) {
2238 global $wgLang, $wgOut, $wgUser;
2240 $current = ( $oldid == $this->mLatest
);
2241 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2242 $sk = $wgUser->getSkin();
2244 ?
wfMsg( 'currentrevisionlink' )
2245 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2246 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2247 $nextlink = $current
2248 ?
wfMsg( 'nextrevision' )
2249 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2250 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2251 $wgOut->setSubtitle( $r );
2255 * This function is called right before saving the wikitext,
2256 * so we can do things like signatures and links-in-context.
2258 * @param string $text
2260 function preSaveTransform( $text ) {
2261 global $wgParser, $wgUser;
2262 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2265 /* Caching functions */
2268 * checkLastModified returns true if it has taken care of all
2269 * output to the client that is necessary for this request.
2270 * (that is, it has sent a cached version of the page)
2272 function tryFileCache() {
2273 static $called = false;
2275 wfDebug( " tryFileCache() -- called twice!?\n" );
2279 if($this->isFileCacheable()) {
2280 $touched = $this->mTouched
;
2281 $cache = new CacheManager( $this->mTitle
);
2282 if($cache->isFileCacheGood( $touched )) {
2284 wfDebug( " tryFileCache() - about to load\n" );
2285 $cache->loadFromFileCache();
2288 wfDebug( " tryFileCache() - starting buffer\n" );
2289 ob_start( array(&$cache, 'saveToFileCache' ) );
2292 wfDebug( " tryFileCache() - not cacheable\n" );
2297 * Check if the page can be cached
2300 function isFileCacheable() {
2301 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2302 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2304 return $wgUseFileCache
2305 and (!$wgShowIPinHeader)
2306 and ($this->getID() != 0)
2307 and ($wgUser->isAnon())
2308 and (!$wgUser->getNewtalk())
2309 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2310 and (empty( $action ) ||
$action == 'view')
2311 and (!isset($oldid))
2313 and (!isset($redirect))
2314 and (!isset($printable))
2315 and (!$this->mRedirectedFrom
);
2319 * Loads cur_touched and returns a value indicating if it should be used
2322 function checkTouched() {
2323 $fname = 'Article::checkTouched';
2324 if( !$this->mDataLoaded
) {
2325 $dbr =& $this->getDB();
2326 $data = $this->pageDataFromId( $dbr, $this->getId() );
2328 $this->loadPageData( $data );
2331 return !$this->mIsRedirect
;
2335 * Edit an article without doing all that other stuff
2336 * The article must already exist; link tables etc
2337 * are not updated, caches are not flushed.
2339 * @param string $text text submitted
2340 * @param string $comment comment submitted
2341 * @param bool $minor whereas it's a minor modification
2343 function quickEdit( $text, $comment = '', $minor = 0 ) {
2344 $fname = 'Article::quickEdit';
2345 wfProfileIn( $fname );
2347 $dbw =& wfGetDB( DB_MASTER
);
2349 $revision = new Revision( array(
2350 'page' => $this->getId(),
2352 'comment' => $comment,
2353 'minor_edit' => $minor ?
1 : 0,
2355 $revisionId = $revision->insertOn( $dbw );
2356 $this->updateRevisionOn( $dbw, $revision );
2359 wfProfileOut( $fname );
2363 * Used to increment the view counter
2366 * @param integer $id article id
2368 function incViewCount( $id ) {
2369 $id = intval( $id );
2370 global $wgHitcounterUpdateFreq;
2372 $dbw =& wfGetDB( DB_MASTER
);
2373 $pageTable = $dbw->tableName( 'page' );
2374 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2375 $acchitsTable = $dbw->tableName( 'acchits' );
2377 if( $wgHitcounterUpdateFreq <= 1 ){ //
2378 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2382 # Not important enough to warrant an error page in case of failure
2383 $oldignore = $dbw->ignoreErrors( true );
2385 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2387 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2388 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2389 # Most of the time (or on SQL errors), skip row count check
2390 $dbw->ignoreErrors( $oldignore );
2394 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2395 $row = $dbw->fetchObject( $res );
2396 $rown = intval( $row->n
);
2397 if( $rown >= $wgHitcounterUpdateFreq ){
2398 wfProfileIn( 'Article::incViewCount-collect' );
2399 $old_user_abort = ignore_user_abort( true );
2401 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2402 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2403 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2405 $dbw->query("DELETE FROM $hitcounterTable");
2406 $dbw->query('UNLOCK TABLES');
2407 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2408 'WHERE page_id = hc_id');
2409 $dbw->query("DROP TABLE $acchitsTable");
2411 ignore_user_abort( $old_user_abort );
2412 wfProfileOut( 'Article::incViewCount-collect' );
2414 $dbw->ignoreErrors( $oldignore );
2418 * The onArticle*() functions are supposed to be a kind of hooks
2419 * which should be called whenever any of the specified actions
2422 * This is a good place to put code to clear caches, for instance.
2424 * This is called on page move and undelete, as well as edit
2426 * @param $title_obj a title object
2429 function onArticleCreate($title_obj) {
2430 global $wgUseSquid, $wgPostCommitUpdateList;
2432 $title_obj->touchLinks();
2433 $titles = $title_obj->getLinksTo();
2436 if ( $wgUseSquid ) {
2437 $urls = $title_obj->getSquidURLs();
2438 foreach ( $titles as $linkTitle ) {
2439 $urls[] = $linkTitle->getInternalURL();
2441 $u = new SquidUpdate( $urls );
2442 array_push( $wgPostCommitUpdateList, $u );
2446 function onArticleDelete( $title ) {
2447 global $wgMessageCache;
2449 $title->touchLinks();
2451 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2452 $wgMessageCache->replace( $title->getDBkey(), false );
2456 function onArticleEdit($title_obj) {
2457 // This would be an appropriate place to purge caches.
2458 // Why's this not in here now?
2464 * Info about this page
2465 * Called for ?action=info when $wgAllowPageInfo is on.
2470 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2471 $fname = 'Article::info';
2473 if ( !$wgAllowPageInfo ) {
2474 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2478 $page = $this->mTitle
->getSubjectPage();
2480 $wgOut->setPagetitle( $page->getPrefixedText() );
2481 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2483 # first, see if the page exists at all.
2484 $exists = $page->getArticleId() != 0;
2486 $wgOut->addHTML( wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2488 $dbr =& $this->getDB( DB_SLAVE
);
2490 'wl_title' => $page->getDBkey(),
2491 'wl_namespace' => $page->getNamespace() );
2492 $numwatchers = $dbr->selectField(
2497 $this->getSelectOptions() );
2499 $pageInfo = $this->pageCountInfo( $page );
2500 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2502 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2503 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2505 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2507 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2509 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2511 $wgOut->addHTML( '</ul>' );
2517 * Return the total number of edits and number of unique editors
2518 * on a given page. If page does not exist, returns false.
2520 * @param Title $title
2524 function pageCountInfo( $title ) {
2525 $id = $title->getArticleId();
2530 $dbr =& $this->getDB( DB_SLAVE
);
2532 $rev_clause = array( 'rev_page' => $id );
2533 $fname = 'Article::pageCountInfo';
2535 $edits = $dbr->selectField(
2540 $this->getSelectOptions() );
2542 $authors = $dbr->selectField(
2544 'COUNT(DISTINCT rev_user_text)',
2547 $this->getSelectOptions() );
2549 return array( 'edits' => $edits, 'authors' => $authors );
2553 * Return a list of templates used by this article.
2554 * Uses the links table to find the templates
2558 function getUsedTemplates() {
2560 $id = $this->mTitle
->getArticleID();
2562 $db =& wfGetDB( DB_SLAVE
);
2563 $res = $db->select( array( 'pagelinks' ),
2564 array( 'pl_title' ),
2567 'pl_namespace' => NS_TEMPLATE
),
2568 'Article:getUsedTemplates' );
2569 if ( false !== $res ) {
2570 if ( $db->numRows( $res ) ) {
2571 while ( $row = $db->fetchObject( $res ) ) {
2572 $result[] = $row->pl_title
;
2576 $db->freeResult( $res );