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' );
108 return wfMsg( 'noarticletext' );
110 $this->loadContent( $noredir );
111 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
112 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
113 $wgUser->isIP($this->mTitle
->getText()) &&
116 wfProfileOut( $fname );
117 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
119 if($action=='edit') {
121 if($section=='new') {
122 wfProfileOut( $fname );
123 $text=$this->getPreloadedText($preload);
127 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
128 # comments to be stripped as well)
129 $rv=$this->getSection($this->mContent
,$section);
130 wfProfileOut( $fname );
134 wfProfileOut( $fname );
135 return $this->mContent
;
141 This function accepts a title string as parameter
142 ($preload). If this string is non-empty, it attempts
143 to fetch the current revision text.
145 function getPreloadedText($preload) {
147 $preloadTitle=Title
::newFromText($preload);
148 if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
149 $rev=Revision
::newFromTitle($preloadTitle);
151 return $rev->getText();
159 * This function returns the text of a section, specified by a number ($section).
160 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
161 * the first section before any such heading (section 0).
163 * If a section contains subsections, these are also returned.
165 * @param string $text text to look in
166 * @param integer $section section number
167 * @return string text of the requested section
169 function getSection($text,$section) {
171 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
172 # comments to be stripped as well)
174 $parser=new Parser();
175 $parser->mOutputType
=OT_WIKI
;
176 $striptext=$parser->strip($text, $striparray, true);
178 # now that we can be sure that no pseudo-sections are in the source,
179 # split it up by section
182 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
184 PREG_SPLIT_DELIM_CAPTURE
);
188 $headline=$secs[$section*2-1];
189 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
192 # translate wiki heading into level
193 if(strpos($hlevel,'=')!==false) {
194 $hlevel=strlen($hlevel);
197 $rv=$headline. $secs[$section*2];
201 while(!empty($secs[$count*2-1]) && !$break) {
203 $subheadline=$secs[$count*2-1];
204 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
205 $subhlevel=$matches[1];
206 if(strpos($subhlevel,'=')!==false) {
207 $subhlevel=strlen($subhlevel);
209 if($subhlevel > $hlevel) {
210 $rv.=$subheadline.$secs[$count*2];
212 if($subhlevel <= $hlevel) {
219 # reinsert stripped tags
220 $rv=$parser->unstrip($rv,$striparray);
221 $rv=$parser->unstripNoWiki($rv,$striparray);
228 * Return an array of the columns of the "cur"-table
230 function getContentFields() {
231 return $wgArticleContentFields = array(
232 'old_text','old_flags',
233 'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
234 'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
238 * Return the oldid of the article that is to be shown.
239 * For requests with a "direction", this is not the oldid of the
242 function getOldID() {
243 global $wgRequest, $wgOut;
246 if ( isset( $lastid ) ) {
250 $oldid = $wgRequest->getVal( 'oldid' );
251 if ( isset( $oldid ) ) {
252 $oldid = IntVal( $oldid );
253 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
254 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
258 $wgOut->redirect( $this->mTitle
->getFullURL( 'redirect=no' ) );
260 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
261 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
270 return @$oldid; # "@" to be able to return "unset" without PHP complaining
275 * Load the revision (including cur_text) into this object
277 function loadContent( $noredir = false ) {
278 global $wgOut, $wgRequest;
280 if ( $this->mContentLoaded
) return;
283 $oldid = $this->getOldID();
284 $redirect = $wgRequest->getVal( 'redirect' );
286 $fname = 'Article::loadContent';
288 # Pre-fill content with error message so that if something
289 # fails we'll have something telling us what we intended.
291 $t = $this->mTitle
->getPrefixedText();
293 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no')
294 ||
$wgRequest->getCheck( 'rdfrom' );
295 $this->mOldId
= $oldid;
296 $this->fetchContent( $oldid, $noredir, true );
301 * Fetch a page record with the given conditions
302 * @param Database $dbr
303 * @param array $conditions
306 function pageData( &$dbr, $conditions ) {
307 return $dbr->selectRow( 'page',
321 'Article::pageData' );
324 function pageDataFromTitle( &$dbr, $title ) {
325 return $this->pageData( $dbr, array(
326 'page_namespace' => $title->getNamespace(),
327 'page_title' => $title->getDBkey() ) );
330 function pageDataFromId( &$dbr, $id ) {
331 return $this->pageData( $dbr, array(
332 'page_id' => IntVal( $id ) ) );
336 * Set the general counter, title etc data loaded from
339 * @param object $data
342 function loadPageData( $data ) {
343 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
344 $this->mTitle
->mRestrictionsLoaded
= true;
346 $this->mCounter
= $data->page_counter
;
347 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
348 $this->mIsRedirect
= $data->page_is_redirect
;
349 $this->mLatest
= $data->page_latest
;
351 $this->mDataLoaded
= true;
355 * Get text of an article from database
356 * @param int $oldid 0 for whatever the latest revision is
357 * @param bool $noredir Set to false to follow redirects
358 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
361 function fetchContent( $oldid = 0, $noredir = true, $globalTitle = false ) {
362 if ( $this->mContentLoaded
) {
363 return $this->mContent
;
365 $dbr =& $this->getDB();
366 $fname = 'Article::fetchContent';
368 # Pre-fill content with error message so that if something
369 # fails we'll have something telling us what we intended.
370 $t = $this->mTitle
->getPrefixedText();
372 $t .= ',oldid='.$oldid;
374 if( isset( $redirect ) ) {
375 $redirect = ($redirect == 'no') ?
'no' : 'yes';
376 $t .= ',redirect='.$redirect;
378 $this->mContent
= wfMsg( 'missingarticle', $t );
381 $revision = Revision
::newFromId( $oldid );
382 if( is_null( $revision ) ) {
383 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
386 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
388 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
391 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
392 $this->loadPageData( $data );
394 if( !$this->mDataLoaded
) {
395 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
397 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
400 $this->loadPageData( $data );
402 $revision = Revision
::newFromId( $this->mLatest
);
403 if( is_null( $revision ) ) {
404 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
409 # If we got a redirect, follow it (unless we've been told
410 # not to by either the function parameter or the query
411 if ( !$oldid && !$noredir ) {
412 $rt = Title
::newFromRedirect( $revision->getText() );
413 # process if title object is valid and not special:userlogout
414 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
415 # Gotta hand redirects to special pages differently:
416 # Fill the HTTP response "Location" header and ignore
417 # the rest of the page we're on.
418 global $wgDisableHardRedirects;
419 if( $globalTitle && !$wgDisableHardRedirects ) {
421 if ( $rt->getInterwiki() != '' && $rt->isLocal() ) {
422 $source = $this->mTitle
->getFullURL( 'redirect=no' );
423 $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ;
426 if ( $rt->getNamespace() == NS_SPECIAL
) {
427 $wgOut->redirect( $rt->getFullURL() );
431 $redirData = $this->pageDataFromTitle( $dbr, $rt );
433 $redirRev = Revision
::newFromId( $redirData->page_latest
);
434 if( !is_null( $redirRev ) ) {
435 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
438 $this->loadPageData( $data );
439 $revision = $redirRev;
445 # if the title's different from expected, update...
448 if( !$this->mTitle
->equals( $wgTitle ) ) {
449 $wgTitle = $this->mTitle
;
453 # Back to the business at hand...
454 $this->mContent
= $revision->getText();
456 $this->mUser
= $revision->getUser();
457 $this->mUserText
= $revision->getUserText();
458 $this->mComment
= $revision->getComment();
459 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
461 $this->mRevIdFetched
= $revision->getID();
462 $this->mContentLoaded
= true;
463 $this->mRevision
=& $revision;
465 return $this->mContent
;
469 * Gets the article text without using so many damn globals
470 * Returns false on error
472 * @param integer $oldid
474 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
475 return $this->fetchContent( $oldid, $noredir, false );
479 * Read/write accessor to select FOR UPDATE
481 function forUpdate( $x = NULL ) {
482 return wfSetVar( $this->mForUpdate
, $x );
486 * Get the database which should be used for reads
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 $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, $wgLang;
680 global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
681 global $wgEnotif, $wgParser, $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( $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 if ( '' != $this->mRedirectedFrom
) {
758 $sk = $wgUser->getSkin();
759 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '',
761 $s = wfMsg( 'redirectedfrom', $redir );
762 $wgOut->setSubtitle( $s );
764 # Can't cache redirects
766 } elseif ( !empty( $rdfrom ) ) {
767 global $wgRedirectSources;
768 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
769 $sk = $wgUser->getSkin();
770 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
771 $s = wfMsg( 'redirectedfrom', $redir );
772 $wgOut->setSubtitle( $s );
776 # wrap user css and user js in pre and don't parse
777 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
779 $this->mTitle
->getNamespace() == NS_USER
&&
780 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
782 $wgOut->addWikiText( wfMsg('clearyourcache'));
783 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
784 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
786 $imageUrl = $wgStylePath.'/common/images/redirect.png';
787 $targetUrl = $rt->escapeLocalURL();
788 $titleText = htmlspecialchars( $rt->getPrefixedText() );
789 $link = $sk->makeLinkObj( $rt );
791 $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
792 '<span class="redirectText">'.$link.'</span>' );
794 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
795 $catlinks = $parseout->getCategoryLinks();
796 $wgOut->addCategoryLinks($catlinks);
797 $skin = $wgUser->getSkin();
798 } else if ( $pcache ) {
799 # Display content and save to parser cache
800 $wgOut->addPrimaryWikiText( $text, $this );
802 # Display content, don't attempt to save to parser cache
804 # Don't show section-edit links on old revisions... this way lies madness.
805 if( !$this->isCurrent() ) {
806 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
808 $wgOut->addWikiText( $text );
810 if( !$this->isCurrent() ) {
811 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
815 /* title may have been set from the cache */
816 $t = $wgOut->getPageTitle();
818 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
821 # If we have been passed an &rcid= parameter, we want to give the user a
822 # chance to mark this new article as patrolled.
826 && $wgUser->isLoggedIn()
827 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
830 "<div class='patrollink'>" .
831 wfMsg ( 'markaspatrolledlink',
832 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
839 if ($wgUseTrackbacks)
840 $this->addTrackbacks();
842 # Put link titles into the link cache
843 $wgOut->transformBuffer();
845 # Add link titles as META keywords
846 $wgOut->addMetaTags() ;
848 $this->viewUpdates();
849 wfProfileOut( $fname );
852 function addTrackbacks() {
853 global $wgOut, $wgUser;
855 $dbr = wfGetDB(DB_SLAVE
);
857 /* FROM */ 'trackbacks',
858 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
859 /* WHERE */ array('tb_page' => $this->getID())
862 if (!$dbr->numrows($tbs))
866 while ($o = $dbr->fetchObject($tbs)) {
868 if ($wgUser->isSysop()) {
869 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
870 . $o->tb_id
. "&token=" . $wgUser->editToken());
871 $rmvtxt = wfMsg('trackbackremove', $delurl);
873 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
880 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
883 function deletetrackback() {
884 global $wgUser, $wgRequest, $wgOut, $wgTitle;
886 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
887 $wgOut->addWikitext(wfMsg('sessionfailure'));
891 if ((!$wgUser->isAllowed('delete'))) {
892 $wgOut->sysopRequired();
897 $wgOut->readOnlyPage();
901 $db = wfGetDB(DB_MASTER
);
902 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
903 $wgTitle->invalidateCache();
904 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
910 $wgOut->setArticleBodyOnly(true);
915 * Insert a new empty page record for this article.
916 * This *must* be followed up by creating a revision
917 * and running $this->updateToLatest( $rev_id );
918 * or else the record will be left in a funky state.
919 * Best if all done inside a transaction.
921 * @param Database $dbw
922 * @param string $restrictions
923 * @return int The newly created page_id key
926 function insertOn( &$dbw, $restrictions = '' ) {
927 $fname = 'Article::insertOn';
928 wfProfileIn( $fname );
930 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
931 $dbw->insert( 'page', array(
932 'page_id' => $page_id,
933 'page_namespace' => $this->mTitle
->getNamespace(),
934 'page_title' => $this->mTitle
->getDBkey(),
936 'page_restrictions' => $restrictions,
937 'page_is_redirect' => 0, # Will set this shortly...
939 'page_random' => wfRandom(),
940 'page_touched' => $dbw->timestamp(),
941 'page_latest' => 0, # Fill this in shortly...
943 $newid = $dbw->insertId();
945 $this->mTitle
->resetArticleId( $newid );
947 wfProfileOut( $fname );
952 * Update the page record to point to a newly saved revision.
954 * @param Database $dbw
955 * @param Revision $revision -- for ID number, and text used to set
956 length and redirect status fields
957 * @param int $lastRevision -- if given, will not overwrite the page field
958 * when different from the currently set value.
959 * Giving 0 indicates the new page flag should
961 * @return bool true on success, false on failure
964 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
965 $fname = 'Article::updateToRevision';
966 wfProfileIn( $fname );
968 $conditions = array( 'page_id' => $this->getId() );
969 if( !is_null( $lastRevision ) ) {
970 # An extra check against threads stepping on each other
971 $conditions['page_latest'] = $lastRevision;
973 $text = $revision->getText();
974 $dbw->update( 'page',
976 'page_latest' => $revision->getId(),
977 'page_touched' => $dbw->timestamp(),
978 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
979 'page_is_redirect' => Article
::isRedirect( $text ),
980 'page_len' => strlen( $text ),
985 wfProfileOut( $fname );
986 return ( $dbw->affectedRows() != 0 );
990 * If the given revision is newer than the currently set page_latest,
991 * update the page record. Otherwise, do nothing.
993 * @param Database $dbw
994 * @param Revision $revision
996 function updateIfNewerOn( &$dbw, $revision ) {
997 $fname = 'Article::updateIfNewerOn';
998 wfProfileIn( $fname );
1000 $row = $dbw->selectRow(
1001 array( 'revision', 'page' ),
1002 array( 'rev_id', 'rev_timestamp' ),
1004 'page_id' => $this->getId(),
1005 'page_latest=rev_id' ),
1008 if( $row->rev_timestamp
>= $revision->getTimestamp() ) {
1009 wfProfileOut( $fname );
1012 $prev = $row->rev_id
;
1014 # No or missing previous revision; mark the page as new
1018 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1019 wfProfileOut( $fname );
1024 * Theoretically we could defer these whole insert and update
1025 * functions for after display, but that's taking a big leap
1026 * of faith, and we want to be able to report database
1027 * errors at some point.
1030 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1031 global $wgOut, $wgUser;
1032 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1034 $fname = 'Article::insertNewArticle';
1035 wfProfileIn( $fname );
1037 $this->mGoodAdjustment
= $this->isCountable( $text );
1038 $this->mTotalAdjustment
= 1;
1040 $ns = $this->mTitle
->getNamespace();
1041 $ttl = $this->mTitle
->getDBkey();
1043 # If this is a comment, add the summary as headline
1044 if($comment && $summary!="") {
1045 $text="== {$summary} ==\n\n".$text;
1047 $text = $this->preSaveTransform( $text );
1048 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1049 $now = wfTimestampNow();
1051 $dbw =& wfGetDB( DB_MASTER
);
1053 # Add the page record; stake our claim on this title!
1054 $newid = $this->insertOn( $dbw );
1056 # Save the revision text...
1057 $revision = new Revision( array(
1059 'comment' => $summary,
1060 'minor_edit' => $isminor,
1063 $revisionId = $revision->insertOn( $dbw );
1065 $this->mTitle
->resetArticleID( $newid );
1067 # Update the page record with revision data
1068 $this->updateRevisionOn( $dbw, $revision, 0 );
1070 Article
::onArticleCreate( $this->mTitle
);
1072 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1073 '', strlen( $text ), $revisionId );
1077 if(!$this->mTitle
->userIsWatching()) $this->watch();
1079 if ( $this->mTitle
->userIsWatching() ) {
1084 # The talk page isn't in the regular link tables, so we need to update manually:
1085 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1086 $dbw->update( 'page',
1087 array( 'page_touched' => $dbw->timestamp($now) ),
1088 array( 'page_namespace' => $talkns,
1089 'page_title' => $ttl ),
1092 # standard deferred updates
1093 $this->editUpdates( $text, $summary, $isminor, $now );
1095 $oldid = 0; # new article
1096 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1097 wfProfileOut( $fname );
1100 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1101 $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded';
1102 if ($section != '') {
1103 if( is_null( $edittime ) ) {
1104 $rev = Revision
::newFromTitle( $this->mTitle
);
1106 $dbw =& wfGetDB( DB_MASTER
);
1107 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1109 $oldtext = $rev->getText();
1111 if($section=='new') {
1112 if($summary) $subject="== {$summary} ==\n\n";
1113 $text=$oldtext."\n\n".$subject.$text;
1116 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1117 # comments to be stripped as well)
1118 $striparray=array();
1119 $parser=new Parser();
1120 $parser->mOutputType
=OT_WIKI
;
1121 $oldtext=$parser->strip($oldtext, $striparray, true);
1123 # now that we can be sure that no pseudo-sections are in the source,
1125 # Unfortunately we can't simply do a preg_replace because that might
1126 # replace the wrong section, so we have to use the section counter instead
1127 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1128 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1129 $secs[$section*2]=$text."\n\n"; // replace with edited
1131 # section 0 is top (intro) section
1134 # headline of old section - we need to go through this section
1135 # to determine if there are any subsections that now need to
1136 # be erased, as the mother section has been replaced with
1137 # the text of all subsections.
1138 $headline=$secs[$section*2-1];
1139 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1140 $hlevel=$matches[1];
1142 # determine headline level for wikimarkup headings
1143 if(strpos($hlevel,'=')!==false) {
1144 $hlevel=strlen($hlevel);
1147 $secs[$section*2-1]=''; // erase old headline
1150 while(!empty($secs[$count*2-1]) && !$break) {
1152 $subheadline=$secs[$count*2-1];
1154 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1155 $subhlevel=$matches[1];
1156 if(strpos($subhlevel,'=')!==false) {
1157 $subhlevel=strlen($subhlevel);
1159 if($subhlevel > $hlevel) {
1160 // erase old subsections
1161 $secs[$count*2-1]='';
1164 if($subhlevel <= $hlevel) {
1172 $text=join('',$secs);
1173 # reinsert the stuff that we stripped out earlier
1174 $text=$parser->unstrip($text,$striparray);
1175 $text=$parser->unstripNoWiki($text,$striparray);
1183 * Change an existing article. Puts the previous version back into the old table, updates RC
1184 * and all necessary caches, mostly via the deferred update array.
1186 * It is possible to call this function from a command-line script, but note that you should
1187 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1189 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1190 global $wgOut, $wgUser;
1191 global $wgDBtransactions, $wgMwRedir;
1192 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
1194 $fname = 'Article::updateArticle';
1195 wfProfileIn( $fname );
1198 $isminor = ( $minor && $wgUser->isLoggedIn() );
1199 if ( $this->isRedirect( $text ) ) {
1200 # Remove all content but redirect
1201 # This could be done by reconstructing the redirect from a title given by
1202 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1204 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1206 $text = $m[1] . "\n";
1209 else { $redir = 0; }
1211 $text = $this->preSaveTransform( $text );
1212 $dbw =& wfGetDB( DB_MASTER
);
1213 $now = wfTimestampNow();
1215 # Update article, but only if changed.
1217 # It's important that we either rollback or complete, otherwise an attacker could
1218 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1219 # could conceivably have the same effect, especially if cur is locked for long periods.
1220 if( !$wgDBtransactions ) {
1221 $userAbort = ignore_user_abort( true );
1224 $oldtext = $this->getContent( true );
1225 $oldsize = strlen( $oldtext );
1226 $newsize = strlen( $text );
1229 if ( 0 != strcmp( $text, $oldtext ) ) {
1230 $this->mGoodAdjustment
= $this->isCountable( $text )
1231 - $this->isCountable( $oldtext );
1232 $this->mTotalAdjustment
= 0;
1233 $now = wfTimestampNow();
1235 $lastRevision = $dbw->selectField(
1236 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1238 $revision = new Revision( array(
1239 'page' => $this->getId(),
1240 'comment' => $summary,
1241 'minor_edit' => $isminor,
1245 $dbw->immediateCommit();
1247 $revisionId = $revision->insertOn( $dbw );
1250 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1253 /* Belated edit conflict! Run away!! */
1257 # Update recentchanges and purge cache and whatnot
1258 $bot = (int)($wgUser->isBot() ||
$forceBot);
1259 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1260 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1262 Article
::onArticleEdit( $this->mTitle
);
1267 if( !$wgDBtransactions ) {
1268 ignore_user_abort( $userAbort );
1273 if (!$this->mTitle
->userIsWatching()) $this->watch();
1275 if ( $this->mTitle
->userIsWatching() ) {
1279 # standard deferred updates
1280 $this->editUpdates( $text, $summary, $minor, $now );
1284 # Template namespace
1285 # Purge all articles linking here
1286 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1287 $titles = $this->mTitle
->getLinksTo();
1288 Title
::touchArray( $titles );
1289 if ( $wgUseSquid ) {
1290 foreach ( $titles as $title ) {
1291 $urls[] = $title->getInternalURL();
1297 if ( $wgUseSquid ) {
1298 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1299 $u = new SquidUpdate( $urls );
1300 array_push( $wgPostCommitUpdateList, $u );
1304 if ( $wgUseFileCache ) {
1305 $cm = new CacheManager($this->mTitle
);
1306 @unlink
($cm->fileCacheName());
1309 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1311 wfProfileOut( $fname );
1316 * After we've either updated or inserted the article, update
1317 * the link tables and redirect to the new page.
1319 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1320 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1321 global $wgUseEnotif;
1323 $fname = 'Article::showArticle';
1324 wfProfileIn( $fname );
1326 $wgLinkCache = new LinkCache();
1328 if ( !$wgUseDumbLinkUpdate ) {
1329 # Preload links to reduce lock time
1330 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1331 $wgLinkCache->preFill( $this->mTitle
);
1332 $wgLinkCache->clear();
1336 # Parse the text and replace links with placeholders
1337 $wgOut = new OutputPage();
1339 # Pass the current title along in case we're creating a wiki page
1340 # which is different than the currently displayed one (e.g. image
1341 # pages created on file uploads); otherwise, link updates will
1343 $wgOut->addWikiTextWithTitle( $text, $this->mTitle
);
1345 if ( !$wgUseDumbLinkUpdate ) {
1346 # Move the current links back to the second register
1347 $wgLinkCache->swapRegisters();
1349 # Get old version of link table to allow incremental link updates
1350 # Lock this data now since it is needed for an update
1351 $wgLinkCache->forUpdate( true );
1352 $wgLinkCache->preFill( $this->mTitle
);
1354 # Swap this old version back into its rightful place
1355 $wgLinkCache->swapRegisters();
1358 if( $this->isRedirect( $text ) )
1362 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1364 if ( $wgUseEnotif ) {
1365 # this would be better as an extension hook
1366 include_once( "UserMailer.php" );
1367 $wgEnotif = new EmailNotification ();
1368 $wgEnotif->notifyOnPageChange( $this->mTitle
, $now, $summary, $me2, $oldid );
1370 wfProfileOut( $fname );
1374 * Mark this particular edit as patrolled
1376 function markpatrolled() {
1377 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1378 $wgOut->setRobotpolicy( 'noindex,follow' );
1380 if ( !$wgUseRCPatrol )
1382 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1385 if ( $wgUser->isAnon() )
1387 $wgOut->loginToUse();
1390 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1392 $wgOut->sysopRequired();
1395 $rcid = $wgRequest->getVal( 'rcid' );
1396 if ( !is_null ( $rcid ) )
1398 RecentChange
::markPatrolled( $rcid );
1399 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1400 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1402 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1403 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1407 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1414 function validate() {
1415 global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
1417 if ( !$wgUseValidation ) # Are we using article validation at all?
1419 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
1423 $wgOut->setRobotpolicy( 'noindex,follow' );
1424 $revision = $wgRequest->getVal( 'revision' );
1426 include_once ( "SpecialValidate.php" ) ; # The "Validation" class
1428 $v = new Validation
;
1429 if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
1430 $t = $v->showList ( $this ) ;
1431 else if ( $wgRequest->getVal ( "mode" , "" ) == "details" )
1432 $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ;
1434 $t = $v->validatePageForm ( $this , $revision ) ;
1436 $wgOut->addHTML ( $t ) ;
1440 * Add this page to $wgUser's watchlist
1445 global $wgUser, $wgOut;
1447 if ( $wgUser->isAnon() ) {
1448 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1451 if ( wfReadOnly() ) {
1452 $wgOut->readOnlyPage();
1456 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1458 $wgUser->addWatch( $this->mTitle
);
1459 $wgUser->saveSettings();
1461 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1463 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1464 $wgOut->setRobotpolicy( 'noindex,follow' );
1466 $link = $this->mTitle
->getPrefixedText();
1467 $text = wfMsg( 'addedwatchtext', $link );
1468 $wgOut->addWikiText( $text );
1471 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1475 * Stop watching a page
1478 function unwatch() {
1480 global $wgUser, $wgOut;
1482 if ( $wgUser->isAnon() ) {
1483 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1486 if ( wfReadOnly() ) {
1487 $wgOut->readOnlyPage();
1491 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1493 $wgUser->removeWatch( $this->mTitle
);
1494 $wgUser->saveSettings();
1496 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1498 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1499 $wgOut->setRobotpolicy( 'noindex,follow' );
1501 $link = $this->mTitle
->getPrefixedText();
1502 $text = wfMsg( 'removedwatchtext', $link );
1503 $wgOut->addWikiText( $text );
1506 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1512 function protect( $limit = 'sysop' ) {
1513 global $wgUser, $wgOut, $wgRequest;
1515 if ( ! $wgUser->isAllowed('protect') ) {
1516 $wgOut->sysopRequired();
1519 if ( wfReadOnly() ) {
1520 $wgOut->readOnlyPage();
1523 $id = $this->mTitle
->getArticleID();
1525 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1529 $confirm = $wgRequest->wasPosted() &&
1530 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1531 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1532 $reason = $wgRequest->getText( 'wpReasonProtect' );
1535 $dbw =& wfGetDB( DB_MASTER
);
1536 $dbw->update( 'page',
1538 'page_touched' => $dbw->timestamp(),
1539 'page_restrictions' => (string)$limit
1540 ), array( /* WHERE */
1542 ), 'Article::protect'
1545 $restrictions = "move=" . $limit;
1547 $restrictions .= ":edit=" . $limit;
1549 if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
1551 $dbw =& wfGetDB( DB_MASTER
);
1552 $dbw->update( 'page',
1554 'page_touched' => $dbw->timestamp(),
1555 'page_restrictions' => $restrictions
1556 ), array( /* WHERE */
1558 ), 'Article::protect'
1561 wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
1563 $log = new LogPage( 'protect' );
1564 if ( $limit === '' ) {
1565 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1567 $log->addEntry( 'protect', $this->mTitle
, $reason );
1569 $wgOut->redirect( $this->mTitle
->getFullURL() );
1573 return $this->confirmProtect( '', '', $limit );
1578 * Output protection confirmation dialog
1580 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1581 global $wgOut, $wgUser;
1583 wfDebug( "Article::confirmProtect\n" );
1585 $sub = $this->mTitle
->getPrefixedText();
1586 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1592 if ( $limit === '' ) {
1593 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1594 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1595 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1596 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1597 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1599 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1600 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1601 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1602 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1603 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1604 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1607 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1608 $token = htmlspecialchars( $wgUser->editToken() );
1611 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1615 <label for='wpReasonProtect'>{$protcom}:</label>
1618 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1621 if($moveonly != '') {
1625 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1628 <label for='wpMoveOnly'>{$moveonly}</label>
1636 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1640 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1643 $wgOut->returnToMain( false );
1647 * Unprotect the pages
1649 function unprotect() {
1650 return $this->protect( '' );
1654 * UI entry point for page deletion
1657 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1658 $fname = 'Article::delete';
1659 $confirm = $wgRequest->wasPosted() &&
1660 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1661 $reason = $wgRequest->getText( 'wpReason' );
1663 # This code desperately needs to be totally rewritten
1666 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1667 $wgOut->sysopRequired();
1670 if( wfReadOnly() ) {
1671 $wgOut->readOnlyPage();
1675 # Better double-check that it hasn't been deleted yet!
1676 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1677 if( !$this->mTitle
->exists() ) {
1678 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1683 $this->doDelete( $reason );
1687 # determine whether this page has earlier revisions
1688 # and insert a warning if it does
1689 # we select the text because it might be useful below
1690 $dbr =& $this->getDB();
1691 $ns = $this->mTitle
->getNamespace();
1692 $title = $this->mTitle
->getDBkey();
1693 $revisions = $dbr->select( array( 'page', 'revision' ),
1694 array( 'rev_id', 'rev_user_text' ),
1696 'page_namespace' => $ns,
1697 'page_title' => $title,
1698 'rev_page = page_id'
1699 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1702 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1703 $skin=$wgUser->getSkin();
1704 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1705 $wgOut->addHTML( $skin->historyLink() .'</b>');
1709 $rev =& Revision
::newFromTitle( $this->mTitle
);
1711 # Fetch name(s) of contributors
1713 $all_same_user = true;
1714 while( $row = $dbr->fetchObject( $revisions ) ) {
1715 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1716 $all_same_user = false;
1718 $rev_name = $row->rev_user_text
;
1722 if( !is_null( $rev ) ) {
1723 # if this is a mini-text, we can paste part of it into the deletion reason
1724 $text = $rev->getText();
1726 #if this is empty, an earlier revision may contain "useful" text
1729 $prev = $rev->getPrevious();
1731 $text = $prev->getText();
1736 $length = strlen( $text );
1738 # this should not happen, since it is not possible to store an empty, new
1739 # page. Let's insert a standard text in case it does, though
1740 if( $length == 0 && $reason === '' ) {
1741 $reason = wfMsgForContent( 'exblank' );
1744 if( $length < 500 && $reason === '' ) {
1745 # comment field=255, let's grep the first 150 to have some user
1748 $text = $wgContLang->truncate( $text, 150, '...' );
1750 # let's strip out newlines
1751 $text = preg_replace( "/[\n\r]/", '', $text );
1754 if( !$all_same_user ) {
1755 $reason = wfMsgForContent( 'excontent', $text );
1757 $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
1760 $reason = wfMsgForContent( 'exbeforeblank', $text );
1765 return $this->confirmDelete( '', $reason );
1769 * Output deletion confirmation dialog
1771 function confirmDelete( $par, $reason ) {
1772 global $wgOut, $wgUser;
1774 wfDebug( "Article::confirmDelete\n" );
1776 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1777 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1778 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1779 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1781 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1783 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1784 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1785 $token = htmlspecialchars( $wgUser->editToken() );
1788 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1792 <label for='wpReason'>{$delcom}:</label>
1795 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1801 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1805 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1808 $wgOut->returnToMain( false );
1813 * Perform a deletion and output success or failure messages
1815 function doDelete( $reason ) {
1816 global $wgOut, $wgUser, $wgContLang;
1817 $fname = 'Article::doDelete';
1818 wfDebug( $fname."\n" );
1820 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1821 if ( $this->doDeleteArticle( $reason ) ) {
1822 $deleted = $this->mTitle
->getPrefixedText();
1824 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1825 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1827 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1828 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1830 $wgOut->addWikiText( $text );
1831 $wgOut->returnToMain( false );
1832 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1834 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1840 * Back-end article deletion
1841 * Deletes the article with database consistency, writes logs, purges caches
1844 function doDeleteArticle( $reason ) {
1846 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
1847 global $wgUseTrackbacks;
1849 $fname = 'Article::doDeleteArticle';
1850 wfDebug( $fname."\n" );
1852 $dbw =& wfGetDB( DB_MASTER
);
1853 $ns = $this->mTitle
->getNamespace();
1854 $t = $this->mTitle
->getDBkey();
1855 $id = $this->mTitle
->getArticleID();
1857 if ( $t == '' ||
$id == 0 ) {
1861 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1862 array_push( $wgDeferredUpdateList, $u );
1864 $linksTo = $this->mTitle
->getLinksTo();
1867 if ( $wgUseSquid ) {
1869 $this->mTitle
->getInternalURL(),
1870 $this->mTitle
->getInternalURL( 'history' )
1873 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1874 array_push( $wgPostCommitUpdateList, $u );
1878 # Client and file cache invalidation
1879 Title
::touchArray( $linksTo );
1882 // For now, shunt the revision data into the archive table.
1883 // Text is *not* removed from the text table; bulk storage
1884 // is left intact to avoid breaking block-compression or
1885 // immutable storage schemes.
1887 // For backwards compatibility, note that some older archive
1888 // table entries will have ar_text and ar_flags fields still.
1890 // In the future, we may keep revisions and mark them with
1891 // the rev_deleted field, which is reserved for this purpose.
1892 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1894 'ar_namespace' => 'page_namespace',
1895 'ar_title' => 'page_title',
1896 'ar_comment' => 'rev_comment',
1897 'ar_user' => 'rev_user',
1898 'ar_user_text' => 'rev_user_text',
1899 'ar_timestamp' => 'rev_timestamp',
1900 'ar_minor_edit' => 'rev_minor_edit',
1901 'ar_rev_id' => 'rev_id',
1902 'ar_text_id' => 'rev_text_id',
1905 'page_id = rev_page'
1909 # Now that it's safely backed up, delete it
1910 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1911 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1913 if ($wgUseTrackbacks)
1914 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1916 # Clean up recentchanges entries...
1917 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1919 # Finally, clean up the link tables
1920 $t = $this->mTitle
->getPrefixedDBkey();
1922 Article
::onArticleDelete( $this->mTitle
);
1924 # Delete outgoing links
1925 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1926 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1927 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1930 $log = new LogPage( 'delete' );
1931 $log->addEntry( 'delete', $this->mTitle
, $reason );
1933 # Clear the cached article id so the interface doesn't act like we exist
1934 $this->mTitle
->resetArticleID( 0 );
1935 $this->mTitle
->mArticleID
= 0;
1940 * Revert a modification
1942 function rollback() {
1943 global $wgUser, $wgOut, $wgRequest;
1944 $fname = 'Article::rollback';
1946 if ( ! $wgUser->isAllowed('rollback') ) {
1947 $wgOut->sysopRequired();
1950 if ( wfReadOnly() ) {
1951 $wgOut->readOnlyPage( $this->getContent( true ) );
1954 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
1955 array( $this->mTitle
->getPrefixedText(),
1956 $wgRequest->getVal( 'from' ) ) ) ) {
1957 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1958 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
1961 $dbw =& wfGetDB( DB_MASTER
);
1963 # Enhanced rollback, marks edits rc_bot=1
1964 $bot = $wgRequest->getBool( 'bot' );
1966 # Replace all this user's current edits with the next one down
1967 $tt = $this->mTitle
->getDBKey();
1968 $n = $this->mTitle
->getNamespace();
1970 # Get the last editor, lock table exclusively
1972 $current = Revision
::newFromTitle( $this->mTitle
);
1973 if( is_null( $current ) ) {
1974 # Something wrong... no page?
1976 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1980 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1981 if( $from != $current->getUserText() ) {
1982 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1983 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1984 htmlspecialchars( $this->mTitle
->getPrefixedText()),
1985 htmlspecialchars( $from ),
1986 htmlspecialchars( $current->getUserText() ) ) );
1987 if( $current->getComment() != '') {
1989 wfMsg( 'editcomment',
1990 htmlspecialchars( $current->getComment() ) ) );
1995 # Get the last edit not by this guy
1996 $user = IntVal( $current->getUser() );
1997 $user_text = $dbw->addQuotes( $current->getUserText() );
1998 $s = $dbw->selectRow( 'revision',
1999 array( 'rev_id', 'rev_timestamp' ),
2001 'rev_page' => $current->getPage(),
2002 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2005 'USE INDEX' => 'page_timestamp',
2006 'ORDER BY' => 'rev_timestamp DESC' )
2008 if( $s === false ) {
2011 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2012 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2017 # Mark all reverted edits as bot
2018 $dbw->update( 'recentchanges',
2021 ), array( /* WHERE */
2022 'rc_cur_id' => $current->getPage(),
2023 'rc_user_text' => $current->getUserText(),
2024 "rc_timestamp > '{$s->rev_timestamp}'",
2030 $target = Revision
::newFromId( $s->rev_id
);
2031 $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2033 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2034 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2035 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
2037 $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle
->userIsWatching(), $bot );
2038 Article
::onArticleEdit( $this->mTitle
);
2041 $wgOut->returnToMain( false );
2046 * Do standard deferred updates after page view
2049 function viewUpdates() {
2050 global $wgDeferredUpdateList, $wgUseEnotif;
2052 if ( 0 != $this->getID() ) {
2053 global $wgDisableCounters;
2054 if( !$wgDisableCounters ) {
2055 Article
::incViewCount( $this->getID() );
2056 $u = new SiteStatsUpdate( 1, 0, 0 );
2057 array_push( $wgDeferredUpdateList, $u );
2061 # Update newtalk status if user is reading their own
2065 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
2066 $this->mTitle
->getText() == $wgUser->getName())
2068 if ( $wgUseEnotif ) {
2069 require_once( 'UserTalkUpdate.php' );
2070 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
2072 $wgUser->setNewtalk(0);
2073 $wgUser->saveNewtalk();
2075 } elseif ( $wgUseEnotif ) {
2076 $wgUser->clearNotification( $this->mTitle
);
2082 * Do standard deferred updates after page edit.
2083 * Every 1000th edit, prune the recent changes table.
2085 * @param string $text
2087 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2088 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
2089 global $wgMessageCache, $wgUser, $wgUseEnotif;
2092 if ( 0 == mt_rand( 0, 999 ) ) {
2093 # Periodically flush old entries from the recentchanges table.
2095 $dbw =& wfGetDB( DB_MASTER
);
2096 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2097 $recentchanges = $dbw->tableName( 'recentchanges' );
2098 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2099 //$dbw->query( $sql ); // HACK: disabled for now, slowness
2101 // re-enabled for commit of unrelated live changes -- TS
2102 $dbw->query( $sql );
2104 $id = $this->getID();
2105 $title = $this->mTitle
->getPrefixedDBkey();
2106 $shortTitle = $this->mTitle
->getDBkey();
2109 $u = new LinksUpdate( $id, $title );
2110 array_push( $wgDeferredUpdateList, $u );
2111 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2112 array_push( $wgDeferredUpdateList, $u );
2113 $u = new SearchUpdate( $id, $title, $text );
2114 array_push( $wgDeferredUpdateList, $u );
2116 # If this is another user's talk page, update newtalk
2118 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2119 if ( $wgUseEnotif ) {
2120 require_once( 'UserTalkUpdate.php' );
2121 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary,
2122 $minoredit, $timestamp_of_pagechange);
2124 $other = User
::newFromName( $shortTitle );
2125 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2126 // An anonymous user
2127 $other = new User();
2128 $other->setName( $shortTitle );
2131 $other->setNewtalk(1);
2132 $other->saveNewtalk();
2137 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2138 $wgMessageCache->replace( $shortTitle, $text );
2144 * @todo document this function
2146 * @param string $oldid Revision ID of this article revision
2148 function setOldSubtitle( $oldid=0 ) {
2149 global $wgLang, $wgOut, $wgUser;
2151 $current = ( $oldid == $this->mLatest
);
2152 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2153 $sk = $wgUser->getSkin();
2155 ?
wfMsg( 'currentrevisionlink' )
2156 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2157 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2158 $nextlink = $current
2159 ?
wfMsg( 'nextrevision' )
2160 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2161 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2162 $wgOut->setSubtitle( $r );
2166 * This function is called right before saving the wikitext,
2167 * so we can do things like signatures and links-in-context.
2169 * @param string $text
2171 function preSaveTransform( $text ) {
2172 global $wgParser, $wgUser;
2173 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2176 /* Caching functions */
2179 * checkLastModified returns true if it has taken care of all
2180 * output to the client that is necessary for this request.
2181 * (that is, it has sent a cached version of the page)
2183 function tryFileCache() {
2184 static $called = false;
2186 wfDebug( " tryFileCache() -- called twice!?\n" );
2190 if($this->isFileCacheable()) {
2191 $touched = $this->mTouched
;
2192 $cache = new CacheManager( $this->mTitle
);
2193 if($cache->isFileCacheGood( $touched )) {
2195 wfDebug( " tryFileCache() - about to load\n" );
2196 $cache->loadFromFileCache();
2199 wfDebug( " tryFileCache() - starting buffer\n" );
2200 ob_start( array(&$cache, 'saveToFileCache' ) );
2203 wfDebug( " tryFileCache() - not cacheable\n" );
2208 * Check if the page can be cached
2211 function isFileCacheable() {
2212 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2213 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2215 return $wgUseFileCache
2216 and (!$wgShowIPinHeader)
2217 and ($this->getID() != 0)
2218 and ($wgUser->isAnon())
2219 and (!$wgUser->getNewtalk())
2220 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2221 and (empty( $action ) ||
$action == 'view')
2222 and (!isset($oldid))
2224 and (!isset($redirect))
2225 and (!isset($printable))
2226 and (!$this->mRedirectedFrom
);
2230 * Loads cur_touched and returns a value indicating if it should be used
2233 function checkTouched() {
2234 $fname = 'Article::checkTouched';
2235 if( !$this->mDataLoaded
) {
2236 $dbr =& $this->getDB();
2237 $data = $this->pageDataFromId( $dbr, $this->getId() );
2239 $this->loadPageData( $data );
2242 return !$this->mIsRedirect
;
2246 * Edit an article without doing all that other stuff
2247 * The article must already exist; link tables etc
2248 * are not updated, caches are not flushed.
2250 * @param string $text text submitted
2251 * @param string $comment comment submitted
2252 * @param bool $minor whereas it's a minor modification
2254 function quickEdit( $text, $comment = '', $minor = 0 ) {
2255 $fname = 'Article::quickEdit';
2256 wfProfileIn( $fname );
2258 $dbw =& wfGetDB( DB_MASTER
);
2260 $revision = new Revision( array(
2261 'page' => $this->getId(),
2263 'comment' => $comment,
2264 'minor_edit' => $minor ?
1 : 0,
2266 $revisionId = $revision->insertOn( $dbw );
2267 $this->updateRevisionOn( $dbw, $revision );
2270 wfProfileOut( $fname );
2274 * Used to increment the view counter
2277 * @param integer $id article id
2279 function incViewCount( $id ) {
2280 $id = intval( $id );
2281 global $wgHitcounterUpdateFreq;
2283 $dbw =& wfGetDB( DB_MASTER
);
2284 $pageTable = $dbw->tableName( 'page' );
2285 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2286 $acchitsTable = $dbw->tableName( 'acchits' );
2288 if( $wgHitcounterUpdateFreq <= 1 ){ //
2289 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2293 # Not important enough to warrant an error page in case of failure
2294 $oldignore = $dbw->ignoreErrors( true );
2296 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2298 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2299 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2300 # Most of the time (or on SQL errors), skip row count check
2301 $dbw->ignoreErrors( $oldignore );
2305 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2306 $row = $dbw->fetchObject( $res );
2307 $rown = intval( $row->n
);
2308 if( $rown >= $wgHitcounterUpdateFreq ){
2309 wfProfileIn( 'Article::incViewCount-collect' );
2310 $old_user_abort = ignore_user_abort( true );
2312 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2313 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2314 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2316 $dbw->query("DELETE FROM $hitcounterTable");
2317 $dbw->query('UNLOCK TABLES');
2318 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2319 'WHERE page_id = hc_id');
2320 $dbw->query("DROP TABLE $acchitsTable");
2322 ignore_user_abort( $old_user_abort );
2323 wfProfileOut( 'Article::incViewCount-collect' );
2325 $dbw->ignoreErrors( $oldignore );
2329 * The onArticle*() functions are supposed to be a kind of hooks
2330 * which should be called whenever any of the specified actions
2333 * This is a good place to put code to clear caches, for instance.
2335 * This is called on page move and undelete, as well as edit
2337 * @param $title_obj a title object
2340 function onArticleCreate($title_obj) {
2341 global $wgUseSquid, $wgPostCommitUpdateList;
2343 $title_obj->touchLinks();
2344 $titles = $title_obj->getLinksTo();
2347 if ( $wgUseSquid ) {
2348 $urls = $title_obj->getSquidURLs();
2349 foreach ( $titles as $linkTitle ) {
2350 $urls[] = $linkTitle->getInternalURL();
2352 $u = new SquidUpdate( $urls );
2353 array_push( $wgPostCommitUpdateList, $u );
2357 function onArticleDelete($title_obj) {
2358 $title_obj->touchLinks();
2361 function onArticleEdit($title_obj) {
2362 // This would be an appropriate place to purge caches.
2363 // Why's this not in here now?
2369 * Info about this page
2370 * Called for ?action=info when $wgAllowPageInfo is on.
2375 global $wgLang, $wgOut, $wgAllowPageInfo;
2376 $fname = 'Article::info';
2378 if ( !$wgAllowPageInfo ) {
2379 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2383 $page = $this->mTitle
->getSubjectPage();
2385 $wgOut->setPagetitle( $page->getPrefixedText() );
2386 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2388 # first, see if the page exists at all.
2389 $exists = $page->getArticleId() != 0;
2391 $wgOut->addHTML( wfMsg('noarticletext') );
2393 $dbr =& $this->getDB( DB_SLAVE
);
2395 'wl_title' => $page->getDBkey(),
2396 'wl_namespace' => $page->getNamespace() );
2397 $numwatchers = $dbr->selectField(
2402 $this->getSelectOptions() );
2404 $pageInfo = $this->pageCountInfo( $page );
2405 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2407 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2408 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2410 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2412 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2414 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2416 $wgOut->addHTML( '</ul>' );
2422 * Return the total number of edits and number of unique editors
2423 * on a given page. If page does not exist, returns false.
2425 * @param Title $title
2429 function pageCountInfo( $title ) {
2430 $id = $title->getArticleId();
2435 $dbr =& $this->getDB( DB_SLAVE
);
2437 $rev_clause = array( 'rev_page' => $id );
2438 $fname = 'Article::pageCountInfo';
2440 $edits = $dbr->selectField(
2445 $this->getSelectOptions() );
2447 $authors = $dbr->selectField(
2449 'COUNT(DISTINCT rev_user_text)',
2452 $this->getSelectOptions() );
2454 return array( 'edits' => $edits, 'authors' => $authors );
2458 * Return a list of templates used by this article.
2459 * Uses the links table to find the templates
2463 function getUsedTemplates() {
2465 $id = $this->mTitle
->getArticleID();
2467 $db =& wfGetDB( DB_SLAVE
);
2468 $res = $db->select( array( 'pagelinks' ),
2469 array( 'pl_title' ),
2472 'pl_namespace' => NS_TEMPLATE
),
2473 'Article:getUsedTemplates' );
2474 if ( false !== $res ) {
2475 if ( $db->numRows( $res ) ) {
2476 while ( $row = $db->fetchObject( $res ) ) {
2477 $result[] = $row->pl_title
;
2481 $db->freeResult( $res );