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';
1036 $this->mGoodAdjustment
= $this->isCountable( $text );
1037 $this->mTotalAdjustment
= 1;
1039 $ns = $this->mTitle
->getNamespace();
1040 $ttl = $this->mTitle
->getDBkey();
1042 # If this is a comment, add the summary as headline
1043 if($comment && $summary!="") {
1044 $text="== {$summary} ==\n\n".$text;
1046 $text = $this->preSaveTransform( $text );
1047 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1048 $now = wfTimestampNow();
1050 $dbw =& wfGetDB( DB_MASTER
);
1052 # Add the page record; stake our claim on this title!
1053 $newid = $this->insertOn( $dbw );
1055 # Save the revision text...
1056 $revision = new Revision( array(
1058 'comment' => $summary,
1059 'minor_edit' => $isminor,
1062 $revisionId = $revision->insertOn( $dbw );
1064 $this->mTitle
->resetArticleID( $newid );
1066 # Update the page record with revision data
1067 $this->updateRevisionOn( $dbw, $revision, 0 );
1069 Article
::onArticleCreate( $this->mTitle
);
1071 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1072 '', strlen( $text ), $revisionId );
1076 if(!$this->mTitle
->userIsWatching()) $this->watch();
1078 if ( $this->mTitle
->userIsWatching() ) {
1083 # The talk page isn't in the regular link tables, so we need to update manually:
1084 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1085 $dbw->update( 'page',
1086 array( 'page_touched' => $dbw->timestamp($now) ),
1087 array( 'page_namespace' => $talkns,
1088 'page_title' => $ttl ),
1091 # standard deferred updates
1092 $this->editUpdates( $text, $summary, $isminor, $now );
1094 $oldid = 0; # new article
1095 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1098 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1099 $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded';
1100 if ($section != '') {
1101 if( is_null( $edittime ) ) {
1102 $rev = Revision
::newFromTitle( $this->mTitle
);
1104 $dbw =& wfGetDB( DB_MASTER
);
1105 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1107 $oldtext = $rev->getText();
1109 if($section=='new') {
1110 if($summary) $subject="== {$summary} ==\n\n";
1111 $text=$oldtext."\n\n".$subject.$text;
1114 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1115 # comments to be stripped as well)
1116 $striparray=array();
1117 $parser=new Parser();
1118 $parser->mOutputType
=OT_WIKI
;
1119 $oldtext=$parser->strip($oldtext, $striparray, true);
1121 # now that we can be sure that no pseudo-sections are in the source,
1123 # Unfortunately we can't simply do a preg_replace because that might
1124 # replace the wrong section, so we have to use the section counter instead
1125 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1126 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1127 $secs[$section*2]=$text."\n\n"; // replace with edited
1129 # section 0 is top (intro) section
1132 # headline of old section - we need to go through this section
1133 # to determine if there are any subsections that now need to
1134 # be erased, as the mother section has been replaced with
1135 # the text of all subsections.
1136 $headline=$secs[$section*2-1];
1137 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1138 $hlevel=$matches[1];
1140 # determine headline level for wikimarkup headings
1141 if(strpos($hlevel,'=')!==false) {
1142 $hlevel=strlen($hlevel);
1145 $secs[$section*2-1]=''; // erase old headline
1148 while(!empty($secs[$count*2-1]) && !$break) {
1150 $subheadline=$secs[$count*2-1];
1152 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1153 $subhlevel=$matches[1];
1154 if(strpos($subhlevel,'=')!==false) {
1155 $subhlevel=strlen($subhlevel);
1157 if($subhlevel > $hlevel) {
1158 // erase old subsections
1159 $secs[$count*2-1]='';
1162 if($subhlevel <= $hlevel) {
1170 $text=join('',$secs);
1171 # reinsert the stuff that we stripped out earlier
1172 $text=$parser->unstrip($text,$striparray);
1173 $text=$parser->unstripNoWiki($text,$striparray);
1181 * Change an existing article. Puts the previous version back into the old table, updates RC
1182 * and all necessary caches, mostly via the deferred update array.
1184 * It is possible to call this function from a command-line script, but note that you should
1185 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1187 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1188 global $wgOut, $wgUser;
1189 global $wgDBtransactions, $wgMwRedir;
1190 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
1192 $fname = 'Article::updateArticle';
1195 $isminor = ( $minor && $wgUser->isLoggedIn() );
1196 if ( $this->isRedirect( $text ) ) {
1197 # Remove all content but redirect
1198 # This could be done by reconstructing the redirect from a title given by
1199 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1201 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1203 $text = $m[1] . "\n";
1206 else { $redir = 0; }
1208 $text = $this->preSaveTransform( $text );
1209 $dbw =& wfGetDB( DB_MASTER
);
1210 $now = wfTimestampNow();
1212 # Update article, but only if changed.
1214 # It's important that we either rollback or complete, otherwise an attacker could
1215 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1216 # could conceivably have the same effect, especially if cur is locked for long periods.
1217 if( !$wgDBtransactions ) {
1218 $userAbort = ignore_user_abort( true );
1221 $oldtext = $this->getContent( true );
1222 $oldsize = strlen( $oldtext );
1223 $newsize = strlen( $text );
1226 if ( 0 != strcmp( $text, $oldtext ) ) {
1227 $this->mGoodAdjustment
= $this->isCountable( $text )
1228 - $this->isCountable( $oldtext );
1229 $this->mTotalAdjustment
= 0;
1230 $now = wfTimestampNow();
1232 $lastRevision = $dbw->selectField(
1233 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1235 $revision = new Revision( array(
1236 'page' => $this->getId(),
1237 'comment' => $summary,
1238 'minor_edit' => $isminor,
1241 $revisionId = $revision->insertOn( $dbw );
1244 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1247 /* Belated edit conflict! Run away!! */
1250 # Update recentchanges and purge cache and whatnot
1251 $bot = (int)($wgUser->isBot() ||
$forceBot);
1252 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1253 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1255 Article
::onArticleEdit( $this->mTitle
);
1259 if( !$wgDBtransactions ) {
1260 ignore_user_abort( $userAbort );
1265 if (!$this->mTitle
->userIsWatching()) $this->watch();
1267 if ( $this->mTitle
->userIsWatching() ) {
1271 # standard deferred updates
1272 $this->editUpdates( $text, $summary, $minor, $now );
1276 # Template namespace
1277 # Purge all articles linking here
1278 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1279 $titles = $this->mTitle
->getLinksTo();
1280 Title
::touchArray( $titles );
1281 if ( $wgUseSquid ) {
1282 foreach ( $titles as $title ) {
1283 $urls[] = $title->getInternalURL();
1289 if ( $wgUseSquid ) {
1290 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1291 $u = new SquidUpdate( $urls );
1292 array_push( $wgPostCommitUpdateList, $u );
1296 if ( $wgUseFileCache ) {
1297 $cm = new CacheManager($this->mTitle
);
1298 @unlink
($cm->fileCacheName());
1301 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1307 * After we've either updated or inserted the article, update
1308 * the link tables and redirect to the new page.
1310 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1311 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1312 global $wgUseEnotif;
1314 $wgLinkCache = new LinkCache();
1316 if ( !$wgUseDumbLinkUpdate ) {
1317 # Preload links to reduce lock time
1318 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1319 $wgLinkCache->preFill( $this->mTitle
);
1320 $wgLinkCache->clear();
1324 # Parse the text and replace links with placeholders
1325 $wgOut = new OutputPage();
1327 # Pass the current title along in case we're creating a wiki page
1328 # which is different than the currently displayed one (e.g. image
1329 # pages created on file uploads); otherwise, link updates will
1331 $wgOut->addWikiTextWithTitle( $text, $this->mTitle
);
1333 if ( !$wgUseDumbLinkUpdate ) {
1334 # Move the current links back to the second register
1335 $wgLinkCache->swapRegisters();
1337 # Get old version of link table to allow incremental link updates
1338 # Lock this data now since it is needed for an update
1339 $wgLinkCache->forUpdate( true );
1340 $wgLinkCache->preFill( $this->mTitle
);
1342 # Swap this old version back into its rightful place
1343 $wgLinkCache->swapRegisters();
1346 if( $this->isRedirect( $text ) )
1350 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1352 if ( $wgUseEnotif ) {
1353 # this would be better as an extension hook
1354 include_once( "UserMailer.php" );
1355 $wgEnotif = new EmailNotification ();
1356 $wgEnotif->notifyOnPageChange( $this->mTitle
, $now, $summary, $me2, $oldid );
1361 * Mark this particular edit as patrolled
1363 function markpatrolled() {
1364 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1365 $wgOut->setRobotpolicy( 'noindex,follow' );
1367 if ( !$wgUseRCPatrol )
1369 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1372 if ( $wgUser->isAnon() )
1374 $wgOut->loginToUse();
1377 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1379 $wgOut->sysopRequired();
1382 $rcid = $wgRequest->getVal( 'rcid' );
1383 if ( !is_null ( $rcid ) )
1385 RecentChange
::markPatrolled( $rcid );
1386 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1387 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1389 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1390 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1394 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1401 function validate() {
1402 global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
1404 if ( !$wgUseValidation ) # Are we using article validation at all?
1406 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
1410 $wgOut->setRobotpolicy( 'noindex,follow' );
1411 $revision = $wgRequest->getVal( 'revision' );
1413 include_once ( "SpecialValidate.php" ) ; # The "Validation" class
1415 $v = new Validation
;
1416 if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
1417 $t = $v->showList ( $this ) ;
1418 else if ( $wgRequest->getVal ( "mode" , "" ) == "details" )
1419 $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ;
1421 $t = $v->validatePageForm ( $this , $revision ) ;
1423 $wgOut->addHTML ( $t ) ;
1427 * Add this page to $wgUser's watchlist
1432 global $wgUser, $wgOut;
1434 if ( $wgUser->isAnon() ) {
1435 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1438 if ( wfReadOnly() ) {
1439 $wgOut->readOnlyPage();
1443 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1445 $wgUser->addWatch( $this->mTitle
);
1446 $wgUser->saveSettings();
1448 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1450 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1451 $wgOut->setRobotpolicy( 'noindex,follow' );
1453 $link = $this->mTitle
->getPrefixedText();
1454 $text = wfMsg( 'addedwatchtext', $link );
1455 $wgOut->addWikiText( $text );
1458 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1462 * Stop watching a page
1465 function unwatch() {
1467 global $wgUser, $wgOut;
1469 if ( $wgUser->isAnon() ) {
1470 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1473 if ( wfReadOnly() ) {
1474 $wgOut->readOnlyPage();
1478 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1480 $wgUser->removeWatch( $this->mTitle
);
1481 $wgUser->saveSettings();
1483 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1485 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1486 $wgOut->setRobotpolicy( 'noindex,follow' );
1488 $link = $this->mTitle
->getPrefixedText();
1489 $text = wfMsg( 'removedwatchtext', $link );
1490 $wgOut->addWikiText( $text );
1493 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1499 function protect( $limit = 'sysop' ) {
1500 global $wgUser, $wgOut, $wgRequest;
1502 if ( ! $wgUser->isAllowed('protect') ) {
1503 $wgOut->sysopRequired();
1506 if ( wfReadOnly() ) {
1507 $wgOut->readOnlyPage();
1510 $id = $this->mTitle
->getArticleID();
1512 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1516 $confirm = $wgRequest->wasPosted() &&
1517 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1518 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1519 $reason = $wgRequest->getText( 'wpReasonProtect' );
1522 $dbw =& wfGetDB( DB_MASTER
);
1523 $dbw->update( 'page',
1525 'page_touched' => $dbw->timestamp(),
1526 'page_restrictions' => (string)$limit
1527 ), array( /* WHERE */
1529 ), 'Article::protect'
1532 $restrictions = "move=" . $limit;
1534 $restrictions .= ":edit=" . $limit;
1536 if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
1538 $dbw =& wfGetDB( DB_MASTER
);
1539 $dbw->update( 'page',
1541 'page_touched' => $dbw->timestamp(),
1542 'page_restrictions' => $restrictions
1543 ), array( /* WHERE */
1545 ), 'Article::protect'
1548 wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
1550 $log = new LogPage( 'protect' );
1551 if ( $limit === '' ) {
1552 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1554 $log->addEntry( 'protect', $this->mTitle
, $reason );
1556 $wgOut->redirect( $this->mTitle
->getFullURL() );
1560 $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
1561 return $this->confirmProtect( '', $reason, $limit );
1566 * Output protection confirmation dialog
1568 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1569 global $wgOut, $wgUser;
1571 wfDebug( "Article::confirmProtect\n" );
1573 $sub = $this->mTitle
->getPrefixedText();
1574 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1580 if ( $limit === '' ) {
1581 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1582 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1583 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1584 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1585 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1587 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1588 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1589 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1590 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1591 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1592 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1595 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1596 $token = htmlspecialchars( $wgUser->editToken() );
1599 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1603 <label for='wpReasonProtect'>{$protcom}:</label>
1606 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1609 if($moveonly != '') {
1613 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1616 <label for='wpMoveOnly'>{$moveonly}</label>
1624 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1628 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1631 $wgOut->returnToMain( false );
1635 * Unprotect the pages
1637 function unprotect() {
1638 return $this->protect( '' );
1642 * UI entry point for page deletion
1645 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1646 $fname = 'Article::delete';
1647 $confirm = $wgRequest->wasPosted() &&
1648 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1649 $reason = $wgRequest->getText( 'wpReason' );
1651 # This code desperately needs to be totally rewritten
1654 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1655 $wgOut->sysopRequired();
1658 if( wfReadOnly() ) {
1659 $wgOut->readOnlyPage();
1663 # Better double-check that it hasn't been deleted yet!
1664 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1665 if( !$this->mTitle
->exists() ) {
1666 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1671 $this->doDelete( $reason );
1675 # determine whether this page has earlier revisions
1676 # and insert a warning if it does
1677 # we select the text because it might be useful below
1678 $dbr =& $this->getDB();
1679 $ns = $this->mTitle
->getNamespace();
1680 $title = $this->mTitle
->getDBkey();
1681 $revisions = $dbr->select( array( 'page', 'revision' ),
1682 array( 'rev_id', 'rev_user_text' ),
1684 'page_namespace' => $ns,
1685 'page_title' => $title,
1686 'rev_page = page_id'
1687 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1690 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1691 $skin=$wgUser->getSkin();
1692 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1693 $wgOut->addHTML( $skin->historyLink() .'</b>');
1697 $rev =& Revision
::newFromTitle( $this->mTitle
);
1699 # Fetch name(s) of contributors
1701 $all_same_user = true;
1702 while( $row = $dbr->fetchObject( $revisions ) ) {
1703 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1704 $all_same_user = false;
1706 $rev_name = $row->rev_user_text
;
1710 if( !is_null( $rev ) ) {
1711 # if this is a mini-text, we can paste part of it into the deletion reason
1712 $text = $rev->getText();
1714 #if this is empty, an earlier revision may contain "useful" text
1717 $prev = $rev->getPrevious();
1719 $text = $prev->getText();
1724 $length = strlen( $text );
1726 # this should not happen, since it is not possible to store an empty, new
1727 # page. Let's insert a standard text in case it does, though
1728 if( $length == 0 && $reason === '' ) {
1729 $reason = wfMsg( 'exblank' );
1732 if( $length < 500 && $reason === '' ) {
1733 # comment field=255, let's grep the first 150 to have some user
1736 $text = $wgContLang->truncate( $text, 150, '...' );
1738 # let's strip out newlines
1739 $text = preg_replace( "/[\n\r]/", '', $text );
1742 if( !$all_same_user ) {
1743 $reason = wfMsg( 'excontent', $text );
1745 $reason = wfMsg( 'excontentauthor', $text, $rev_name );
1748 $reason = wfMsg( 'exbeforeblank', $text );
1753 return $this->confirmDelete( '', $reason );
1757 * Output deletion confirmation dialog
1759 function confirmDelete( $par, $reason ) {
1760 global $wgOut, $wgUser;
1762 wfDebug( "Article::confirmDelete\n" );
1764 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1765 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1766 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1767 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1769 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1771 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1772 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1773 $token = htmlspecialchars( $wgUser->editToken() );
1776 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1780 <label for='wpReason'>{$delcom}:</label>
1783 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1789 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1793 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1796 $wgOut->returnToMain( false );
1801 * Perform a deletion and output success or failure messages
1803 function doDelete( $reason ) {
1804 global $wgOut, $wgUser, $wgContLang;
1805 $fname = 'Article::doDelete';
1806 wfDebug( $fname."\n" );
1808 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1809 if ( $this->doDeleteArticle( $reason ) ) {
1810 $deleted = $this->mTitle
->getPrefixedText();
1812 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1813 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1815 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1816 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1818 $wgOut->addWikiText( $text );
1819 $wgOut->returnToMain( false );
1820 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1822 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1828 * Back-end article deletion
1829 * Deletes the article with database consistency, writes logs, purges caches
1832 function doDeleteArticle( $reason ) {
1834 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
1835 global $wgUseTrackbacks;
1837 $fname = 'Article::doDeleteArticle';
1838 wfDebug( $fname."\n" );
1840 $dbw =& wfGetDB( DB_MASTER
);
1841 $ns = $this->mTitle
->getNamespace();
1842 $t = $this->mTitle
->getDBkey();
1843 $id = $this->mTitle
->getArticleID();
1845 if ( $t == '' ||
$id == 0 ) {
1849 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1850 array_push( $wgDeferredUpdateList, $u );
1852 $linksTo = $this->mTitle
->getLinksTo();
1855 if ( $wgUseSquid ) {
1857 $this->mTitle
->getInternalURL(),
1858 $this->mTitle
->getInternalURL( 'history' )
1861 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1862 array_push( $wgPostCommitUpdateList, $u );
1866 # Client and file cache invalidation
1867 Title
::touchArray( $linksTo );
1870 // For now, shunt the revision data into the archive table.
1871 // Text is *not* removed from the text table; bulk storage
1872 // is left intact to avoid breaking block-compression or
1873 // immutable storage schemes.
1875 // For backwards compatibility, note that some older archive
1876 // table entries will have ar_text and ar_flags fields still.
1878 // In the future, we may keep revisions and mark them with
1879 // the rev_deleted field, which is reserved for this purpose.
1880 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1882 'ar_namespace' => 'page_namespace',
1883 'ar_title' => 'page_title',
1884 'ar_comment' => 'rev_comment',
1885 'ar_user' => 'rev_user',
1886 'ar_user_text' => 'rev_user_text',
1887 'ar_timestamp' => 'rev_timestamp',
1888 'ar_minor_edit' => 'rev_minor_edit',
1889 'ar_rev_id' => 'rev_id',
1890 'ar_text_id' => 'rev_text_id',
1893 'page_id = rev_page'
1897 # Now that it's safely backed up, delete it
1898 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1899 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1901 if ($wgUseTrackbacks)
1902 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1904 # Clean up recentchanges entries...
1905 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1907 # Finally, clean up the link tables
1908 $t = $this->mTitle
->getPrefixedDBkey();
1910 Article
::onArticleDelete( $this->mTitle
);
1912 # Delete outgoing links
1913 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1914 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1915 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1918 $log = new LogPage( 'delete' );
1919 $log->addEntry( 'delete', $this->mTitle
, $reason );
1921 # Clear the cached article id so the interface doesn't act like we exist
1922 $this->mTitle
->resetArticleID( 0 );
1923 $this->mTitle
->mArticleID
= 0;
1928 * Revert a modification
1930 function rollback() {
1931 global $wgUser, $wgOut, $wgRequest;
1932 $fname = 'Article::rollback';
1934 if ( ! $wgUser->isAllowed('rollback') ) {
1935 $wgOut->sysopRequired();
1938 if ( wfReadOnly() ) {
1939 $wgOut->readOnlyPage( $this->getContent( true ) );
1942 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
1943 array( $this->mTitle
->getPrefixedText(),
1944 $wgRequest->getVal( 'from' ) ) ) ) {
1945 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1946 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
1949 $dbw =& wfGetDB( DB_MASTER
);
1951 # Enhanced rollback, marks edits rc_bot=1
1952 $bot = $wgRequest->getBool( 'bot' );
1954 # Replace all this user's current edits with the next one down
1955 $tt = $this->mTitle
->getDBKey();
1956 $n = $this->mTitle
->getNamespace();
1958 # Get the last editor, lock table exclusively
1960 $current = Revision
::newFromTitle( $this->mTitle
);
1961 if( is_null( $current ) ) {
1962 # Something wrong... no page?
1964 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1968 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1969 if( $from != $current->getUserText() ) {
1970 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1971 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1972 htmlspecialchars( $this->mTitle
->getPrefixedText()),
1973 htmlspecialchars( $from ),
1974 htmlspecialchars( $current->getUserText() ) ) );
1975 if( $current->getComment() != '') {
1977 wfMsg( 'editcomment',
1978 htmlspecialchars( $current->getComment() ) ) );
1983 # Get the last edit not by this guy
1984 $user = IntVal( $current->getUser() );
1985 $user_text = $dbw->addQuotes( $current->getUserText() );
1986 $s = $dbw->selectRow( 'revision',
1987 array( 'rev_id', 'rev_timestamp' ),
1989 'rev_page' => $current->getPage(),
1990 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
1993 'USE INDEX' => 'page_timestamp',
1994 'ORDER BY' => 'rev_timestamp DESC' )
1996 if( $s === false ) {
1999 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2000 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2005 # Mark all reverted edits as bot
2006 $dbw->update( 'recentchanges',
2009 ), array( /* WHERE */
2010 'rc_cur_id' => $current->getPage(),
2011 'rc_user_text' => $current->getUserText(),
2012 "rc_timestamp > '{$s->rev_timestamp}'",
2018 $target = Revision
::newFromId( $s->rev_id
);
2019 $newcomment = wfMsg( 'revertpage', $target->getUserText(), $from );
2021 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2022 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2023 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
2025 $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle
->userIsWatching(), $bot );
2026 Article
::onArticleEdit( $this->mTitle
);
2029 $wgOut->returnToMain( false );
2034 * Do standard deferred updates after page view
2037 function viewUpdates() {
2038 global $wgDeferredUpdateList, $wgUseEnotif;
2040 if ( 0 != $this->getID() ) {
2041 global $wgDisableCounters;
2042 if( !$wgDisableCounters ) {
2043 Article
::incViewCount( $this->getID() );
2044 $u = new SiteStatsUpdate( 1, 0, 0 );
2045 array_push( $wgDeferredUpdateList, $u );
2049 # Update newtalk status if user is reading their own
2053 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
2054 $this->mTitle
->getText() == $wgUser->getName())
2056 if ( $wgUseEnotif ) {
2057 require_once( 'UserTalkUpdate.php' );
2058 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
2060 $wgUser->setNewtalk(0);
2061 $wgUser->saveNewtalk();
2063 } elseif ( $wgUseEnotif ) {
2064 $wgUser->clearNotification( $this->mTitle
);
2070 * Do standard deferred updates after page edit.
2071 * Every 1000th edit, prune the recent changes table.
2073 * @param string $text
2075 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2076 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
2077 global $wgMessageCache, $wgUser, $wgUseEnotif;
2080 if ( 0 == mt_rand( 0, 999 ) ) {
2081 # Periodically flush old entries from the recentchanges table.
2083 $dbw =& wfGetDB( DB_MASTER
);
2084 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2085 $recentchanges = $dbw->tableName( 'recentchanges' );
2086 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2087 $dbw->query( $sql );
2089 $id = $this->getID();
2090 $title = $this->mTitle
->getPrefixedDBkey();
2091 $shortTitle = $this->mTitle
->getDBkey();
2094 $u = new LinksUpdate( $id, $title );
2095 array_push( $wgDeferredUpdateList, $u );
2096 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2097 array_push( $wgDeferredUpdateList, $u );
2098 $u = new SearchUpdate( $id, $title, $text );
2099 array_push( $wgDeferredUpdateList, $u );
2101 # If this is another user's talk page, update newtalk
2103 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2104 if ( $wgUseEnotif ) {
2105 require_once( 'UserTalkUpdate.php' );
2106 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary,
2107 $minoredit, $timestamp_of_pagechange);
2109 $other = User
::newFromName( $shortTitle );
2110 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2111 // An anonymous user
2112 $other = new User();
2113 $other->setName( $shortTitle );
2116 $other->setNewtalk(1);
2117 $other->saveNewtalk();
2122 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2123 $wgMessageCache->replace( $shortTitle, $text );
2129 * @todo document this function
2131 * @param string $oldid Revision ID of this article revision
2133 function setOldSubtitle( $oldid=0 ) {
2134 global $wgLang, $wgOut, $wgUser;
2136 $current = ( $oldid == $this->mLatest
);
2137 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2138 $sk = $wgUser->getSkin();
2140 ?
wfMsg( 'currentrevisionlink' )
2141 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2142 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2143 $nextlink = $current
2144 ?
wfMsg( 'nextrevision' )
2145 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2146 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2147 $wgOut->setSubtitle( $r );
2151 * This function is called right before saving the wikitext,
2152 * so we can do things like signatures and links-in-context.
2154 * @param string $text
2156 function preSaveTransform( $text ) {
2157 global $wgParser, $wgUser;
2158 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2161 /* Caching functions */
2164 * checkLastModified returns true if it has taken care of all
2165 * output to the client that is necessary for this request.
2166 * (that is, it has sent a cached version of the page)
2168 function tryFileCache() {
2169 static $called = false;
2171 wfDebug( " tryFileCache() -- called twice!?\n" );
2175 if($this->isFileCacheable()) {
2176 $touched = $this->mTouched
;
2177 $cache = new CacheManager( $this->mTitle
);
2178 if($cache->isFileCacheGood( $touched )) {
2180 wfDebug( " tryFileCache() - about to load\n" );
2181 $cache->loadFromFileCache();
2184 wfDebug( " tryFileCache() - starting buffer\n" );
2185 ob_start( array(&$cache, 'saveToFileCache' ) );
2188 wfDebug( " tryFileCache() - not cacheable\n" );
2193 * Check if the page can be cached
2196 function isFileCacheable() {
2197 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2198 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2200 return $wgUseFileCache
2201 and (!$wgShowIPinHeader)
2202 and ($this->getID() != 0)
2203 and ($wgUser->isAnon())
2204 and (!$wgUser->getNewtalk())
2205 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2206 and (empty( $action ) ||
$action == 'view')
2207 and (!isset($oldid))
2209 and (!isset($redirect))
2210 and (!isset($printable))
2211 and (!$this->mRedirectedFrom
);
2215 * Loads cur_touched and returns a value indicating if it should be used
2218 function checkTouched() {
2219 $fname = 'Article::checkTouched';
2220 if( !$this->mDataLoaded
) {
2221 $dbr =& $this->getDB();
2222 $data = $this->pageDataFromId( $dbr, $this->getId() );
2224 $this->loadPageData( $data );
2227 return !$this->mIsRedirect
;
2231 * Edit an article without doing all that other stuff
2232 * The article must already exist; link tables etc
2233 * are not updated, caches are not flushed.
2235 * @param string $text text submitted
2236 * @param string $comment comment submitted
2237 * @param bool $minor whereas it's a minor modification
2239 function quickEdit( $text, $comment = '', $minor = 0 ) {
2240 $fname = 'Article::quickEdit';
2241 wfProfileIn( $fname );
2243 $dbw =& wfGetDB( DB_MASTER
);
2245 $revision = new Revision( array(
2246 'page' => $this->getId(),
2248 'comment' => $comment,
2249 'minor_edit' => $minor ?
1 : 0,
2251 $revisionId = $revision->insertOn( $dbw );
2252 $this->updateRevisionOn( $dbw, $revision );
2255 wfProfileOut( $fname );
2259 * Used to increment the view counter
2262 * @param integer $id article id
2264 function incViewCount( $id ) {
2265 $id = intval( $id );
2266 global $wgHitcounterUpdateFreq;
2268 $dbw =& wfGetDB( DB_MASTER
);
2269 $pageTable = $dbw->tableName( 'page' );
2270 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2271 $acchitsTable = $dbw->tableName( 'acchits' );
2273 if( $wgHitcounterUpdateFreq <= 1 ){ //
2274 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2278 # Not important enough to warrant an error page in case of failure
2279 $oldignore = $dbw->ignoreErrors( true );
2281 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2283 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2284 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2285 # Most of the time (or on SQL errors), skip row count check
2286 $dbw->ignoreErrors( $oldignore );
2290 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2291 $row = $dbw->fetchObject( $res );
2292 $rown = intval( $row->n
);
2293 if( $rown >= $wgHitcounterUpdateFreq ){
2294 wfProfileIn( 'Article::incViewCount-collect' );
2295 $old_user_abort = ignore_user_abort( true );
2297 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2298 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2299 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2301 $dbw->query("DELETE FROM $hitcounterTable");
2302 $dbw->query('UNLOCK TABLES');
2303 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2304 'WHERE page_id = hc_id');
2305 $dbw->query("DROP TABLE $acchitsTable");
2307 ignore_user_abort( $old_user_abort );
2308 wfProfileOut( 'Article::incViewCount-collect' );
2310 $dbw->ignoreErrors( $oldignore );
2314 * The onArticle*() functions are supposed to be a kind of hooks
2315 * which should be called whenever any of the specified actions
2318 * This is a good place to put code to clear caches, for instance.
2320 * This is called on page move and undelete, as well as edit
2322 * @param $title_obj a title object
2325 function onArticleCreate($title_obj) {
2326 global $wgUseSquid, $wgPostCommitUpdateList;
2328 $title_obj->touchLinks();
2329 $titles = $title_obj->getLinksTo();
2332 if ( $wgUseSquid ) {
2333 $urls = $title_obj->getSquidURLs();
2334 foreach ( $titles as $linkTitle ) {
2335 $urls[] = $linkTitle->getInternalURL();
2337 $u = new SquidUpdate( $urls );
2338 array_push( $wgPostCommitUpdateList, $u );
2342 function onArticleDelete($title_obj) {
2343 $title_obj->touchLinks();
2346 function onArticleEdit($title_obj) {
2347 // This would be an appropriate place to purge caches.
2348 // Why's this not in here now?
2354 * Info about this page
2355 * Called for ?action=info when $wgAllowPageInfo is on.
2360 global $wgLang, $wgOut, $wgAllowPageInfo;
2361 $fname = 'Article::info';
2363 if ( !$wgAllowPageInfo ) {
2364 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2368 $page = $this->mTitle
->getSubjectPage();
2370 $wgOut->setPagetitle( $page->getPrefixedText() );
2371 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2373 # first, see if the page exists at all.
2374 $exists = $page->getArticleId() != 0;
2376 $wgOut->addHTML( wfMsg('noarticletext') );
2378 $dbr =& $this->getDB( DB_SLAVE
);
2380 'wl_title' => $page->getDBkey(),
2381 'wl_namespace' => $page->getNamespace() );
2382 $numwatchers = $dbr->selectField(
2387 $this->getSelectOptions() );
2389 $pageInfo = $this->pageCountInfo( $page );
2390 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2392 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2393 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2395 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2397 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2399 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2401 $wgOut->addHTML( '</ul>' );
2407 * Return the total number of edits and number of unique editors
2408 * on a given page. If page does not exist, returns false.
2410 * @param Title $title
2414 function pageCountInfo( $title ) {
2415 $id = $title->getArticleId();
2420 $dbr =& $this->getDB( DB_SLAVE
);
2422 $rev_clause = array( 'rev_page' => $id );
2423 $fname = 'Article::pageCountInfo';
2425 $edits = $dbr->selectField(
2430 $this->getSelectOptions() );
2432 $authors = $dbr->selectField(
2434 'COUNT(DISTINCT rev_user_text)',
2437 $this->getSelectOptions() );
2439 return array( 'edits' => $edits, 'authors' => $authors );
2443 * Return a list of templates used by this article.
2444 * Uses the links table to find the templates
2448 function getUsedTemplates() {
2450 $id = $this->mTitle
->getArticleID();
2452 $db =& wfGetDB( DB_SLAVE
);
2453 $res = $db->select( array( 'pagelinks' ),
2454 array( 'pl_title' ),
2457 'pl_namespace' => NS_TEMPLATE
),
2458 'Article:getUsedTemplates' );
2459 if ( false !== $res ) {
2460 if ( $db->numRows( $res ) ) {
2461 while ( $row = $db->fetchObject( $res ) ) {
2462 $result[] = $row->pl_title
;
2466 $db->freeResult( $res );