8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
17 * Class representing a MediaWiki article and history.
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
29 var $mContent, $mContentLoaded;
30 var $mUser, $mTimestamp, $mUserText;
31 var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
32 var $mMinorEdit, $mRedirectedFrom;
33 var $mTouched, $mFileCache, $mTitle;
42 * Constructor and clear the article
43 * @param mixed &$title
45 function Article( &$title ) {
46 $this->mTitle
=& $title;
51 * get the title object of the article
63 $this->mDataLoaded
= false;
64 $this->mContentLoaded
= false;
66 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
67 $this->mRedirectedFrom
= $this->mUserText
=
68 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
69 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
70 $this->mTouched
= '19700101000000';
71 $this->mForUpdate
= false;
72 $this->mIsRedirect
= false;
73 $this->mRevIdFetched
= 0;
77 * Note that getContent/loadContent may follow redirects if
78 * not told otherwise, and so may cause a change to mTitle.
81 * @return Return the text of this revision
83 function getContent( $noredir ) {
84 global $wgRequest, $wgUser, $wgOut;
86 # Get variables from query string :P
87 $action = $wgRequest->getText( 'action', 'view' );
88 $section = $wgRequest->getText( 'section' );
89 $preload = $wgRequest->getText( 'preload' );
91 $fname = 'Article::getContent';
92 wfProfileIn( $fname );
94 if ( 0 == $this->getID() ) {
95 if ( 'edit' == $action ) {
96 wfProfileOut( $fname );
98 # If requested, preload some text.
99 $text=$this->getPreloadedText($preload);
101 # We used to put MediaWiki:Newarticletext here if
102 # $text was empty at this point.
103 # This is now shown above the edit box instead.
106 wfProfileOut( $fname );
107 $wgOut->setRobotpolicy( 'noindex,nofollow' );
109 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
110 return "<div class='noarticletext'>$ret</div>";
112 $this->loadContent( $noredir );
113 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
114 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
115 $wgUser->isIP($this->mTitle
->getText()) &&
118 wfProfileOut( $fname );
119 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
121 if($action=='edit') {
123 if($section=='new') {
124 wfProfileOut( $fname );
125 $text=$this->getPreloadedText($preload);
129 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
130 # comments to be stripped as well)
131 $rv=$this->getSection($this->mContent
,$section);
132 wfProfileOut( $fname );
136 wfProfileOut( $fname );
137 return $this->mContent
;
143 This function accepts a title string as parameter
144 ($preload). If this string is non-empty, it attempts
145 to fetch the current revision text.
147 function getPreloadedText($preload) {
149 $preloadTitle=Title
::newFromText($preload);
150 if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
151 $rev=Revision
::newFromTitle($preloadTitle);
153 return $rev->getText();
161 * This function returns the text of a section, specified by a number ($section).
162 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
163 * the first section before any such heading (section 0).
165 * If a section contains subsections, these are also returned.
167 * @param string $text text to look in
168 * @param integer $section section number
169 * @return string text of the requested section
171 function getSection($text,$section) {
173 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
174 # comments to be stripped as well)
176 $parser=new Parser();
177 $parser->mOutputType
=OT_WIKI
;
178 $parser->mOptions
= new ParserOptions();
179 $striptext=$parser->strip($text, $striparray, true);
181 # now that we can be sure that no pseudo-sections are in the source,
182 # split it up by section
185 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
187 PREG_SPLIT_DELIM_CAPTURE
);
191 $headline=$secs[$section*2-1];
192 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
195 # translate wiki heading into level
196 if(strpos($hlevel,'=')!==false) {
197 $hlevel=strlen($hlevel);
200 $rv=$headline. $secs[$section*2];
204 while(!empty($secs[$count*2-1]) && !$break) {
206 $subheadline=$secs[$count*2-1];
207 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
208 $subhlevel=$matches[1];
209 if(strpos($subhlevel,'=')!==false) {
210 $subhlevel=strlen($subhlevel);
212 if($subhlevel > $hlevel) {
213 $rv.=$subheadline.$secs[$count*2];
215 if($subhlevel <= $hlevel) {
222 # reinsert stripped tags
223 $rv=$parser->unstrip($rv,$striparray);
224 $rv=$parser->unstripNoWiki($rv,$striparray);
231 * Return the oldid of the article that is to be shown.
232 * For requests with a "direction", this is not the oldid of the
235 function getOldID() {
236 global $wgRequest, $wgOut;
239 if ( isset( $lastid ) ) {
243 $oldid = $wgRequest->getVal( 'oldid' );
244 if ( isset( $oldid ) ) {
245 $oldid = intval( $oldid );
246 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
247 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
251 $wgOut->redirect( $this->mTitle
->getFullURL( 'redirect=no' ) );
253 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
254 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
263 return @$oldid; # "@" to be able to return "unset" without PHP complaining
268 * Load the revision (including cur_text) into this object
270 function loadContent( $noredir = false ) {
271 global $wgOut, $wgRequest;
273 if ( $this->mContentLoaded
) return;
276 $oldid = $this->getOldID();
277 $redirect = $wgRequest->getVal( 'redirect' );
279 $fname = 'Article::loadContent';
281 # Pre-fill content with error message so that if something
282 # fails we'll have something telling us what we intended.
284 $t = $this->mTitle
->getPrefixedText();
286 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no')
287 ||
$wgRequest->getCheck( 'rdfrom' );
288 $this->mOldId
= $oldid;
289 $this->fetchContent( $oldid, $noredir, true );
294 * Fetch a page record with the given conditions
295 * @param Database $dbr
296 * @param array $conditions
299 function pageData( &$dbr, $conditions ) {
300 return $dbr->selectRow( 'page',
314 'Article::pageData' );
317 function pageDataFromTitle( &$dbr, $title ) {
318 return $this->pageData( $dbr, array(
319 'page_namespace' => $title->getNamespace(),
320 'page_title' => $title->getDBkey() ) );
323 function pageDataFromId( &$dbr, $id ) {
324 return $this->pageData( $dbr, array(
325 'page_id' => intval( $id ) ) );
329 * Set the general counter, title etc data loaded from
332 * @param object $data
335 function loadPageData( $data ) {
336 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
337 $this->mTitle
->mRestrictionsLoaded
= true;
339 $this->mCounter
= $data->page_counter
;
340 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
341 $this->mIsRedirect
= $data->page_is_redirect
;
342 $this->mLatest
= $data->page_latest
;
344 $this->mDataLoaded
= true;
348 * Get text of an article from database
349 * @param int $oldid 0 for whatever the latest revision is
350 * @param bool $noredir Set to false to follow redirects
351 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
354 function fetchContent( $oldid = 0, $noredir = true, $globalTitle = false ) {
355 if ( $this->mContentLoaded
) {
356 return $this->mContent
;
358 $dbr =& $this->getDB();
359 $fname = 'Article::fetchContent';
361 # Pre-fill content with error message so that if something
362 # fails we'll have something telling us what we intended.
363 $t = $this->mTitle
->getPrefixedText();
365 $t .= ',oldid='.$oldid;
367 if( isset( $redirect ) ) {
368 $redirect = ($redirect == 'no') ?
'no' : 'yes';
369 $t .= ',redirect='.$redirect;
371 $this->mContent
= wfMsg( 'missingarticle', $t );
374 $revision = Revision
::newFromId( $oldid );
375 if( is_null( $revision ) ) {
376 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
379 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
381 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
384 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
385 $this->loadPageData( $data );
387 if( !$this->mDataLoaded
) {
388 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
390 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
393 $this->loadPageData( $data );
395 $revision = Revision
::newFromId( $this->mLatest
);
396 if( is_null( $revision ) ) {
397 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
402 # If we got a redirect, follow it (unless we've been told
403 # not to by either the function parameter or the query
404 if ( !$oldid && !$noredir ) {
405 $rt = Title
::newFromRedirect( $revision->getText() );
406 # process if title object is valid and not special:userlogout
407 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
408 # Gotta hand redirects to special pages differently:
409 # Fill the HTTP response "Location" header and ignore
410 # the rest of the page we're on.
411 global $wgDisableHardRedirects;
412 if( $globalTitle && !$wgDisableHardRedirects ) {
414 if ( $rt->getInterwiki() != '' && $rt->isLocal() ) {
415 $source = $this->mTitle
->getFullURL( 'redirect=no' );
416 $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ;
419 if ( $rt->getNamespace() == NS_SPECIAL
) {
420 $wgOut->redirect( $rt->getFullURL() );
424 $redirData = $this->pageDataFromTitle( $dbr, $rt );
426 $redirRev = Revision
::newFromId( $redirData->page_latest
);
427 if( !is_null( $redirRev ) ) {
428 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
431 $this->loadPageData( $data );
432 $revision = $redirRev;
438 # if the title's different from expected, update...
441 if( !$this->mTitle
->equals( $wgTitle ) ) {
442 $wgTitle = $this->mTitle
;
446 # Back to the business at hand...
447 $this->mContent
= $revision->getText();
449 $this->mUser
= $revision->getUser();
450 $this->mUserText
= $revision->getUserText();
451 $this->mComment
= $revision->getComment();
452 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
454 $this->mRevIdFetched
= $revision->getID();
455 $this->mContentLoaded
= true;
456 $this->mRevision
=& $revision;
458 return $this->mContent
;
462 * Gets the article text without using so many damn globals
463 * Returns false on error
465 * @param integer $oldid
467 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
468 return $this->fetchContent( $oldid, $noredir, false );
472 * Read/write accessor to select FOR UPDATE
474 function forUpdate( $x = NULL ) {
475 return wfSetVar( $this->mForUpdate
, $x );
479 * Get the database which should be used for reads
482 $ret =& wfGetDB( DB_MASTER
);
484 #if ( $this->mForUpdate ) {
485 $ret =& wfGetDB( DB_MASTER
);
487 # $ret =& wfGetDB( DB_SLAVE );
493 * Get options for all SELECT statements
494 * Can pass an option array, to which the class-wide options will be appended
496 function getSelectOptions( $options = '' ) {
497 if ( $this->mForUpdate
) {
498 if ( is_array( $options ) ) {
499 $options[] = 'FOR UPDATE';
501 $options = 'FOR UPDATE';
508 * Return the Article ID
511 if( $this->mTitle
) {
512 return $this->mTitle
->getArticleID();
519 * Returns true if this article exists in the database.
523 return $this->getId() != 0;
527 * Get the view count for this article
529 function getCount() {
530 if ( -1 == $this->mCounter
) {
531 $id = $this->getID();
532 $dbr =& $this->getDB();
533 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
534 'Article::getCount', $this->getSelectOptions() );
536 return $this->mCounter
;
540 * Would the given text make this article a "good" article (i.e.,
541 * suitable for including in the article count)?
542 * @param string $text Text to analyze
543 * @return integer 1 if it can be counted else 0
545 function isCountable( $text ) {
546 global $wgUseCommaCount;
548 if ( NS_MAIN
!= $this->mTitle
->getNamespace() ) { return 0; }
549 if ( $this->isRedirect( $text ) ) { return 0; }
550 $token = ($wgUseCommaCount ?
',' : '[[' );
551 if ( false === strstr( $text, $token ) ) { return 0; }
556 * Tests if the article text represents a redirect
558 function isRedirect( $text = false ) {
559 if ( $text === false ) {
560 $this->loadContent();
561 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
563 $titleObj = Title
::newFromRedirect( $text );
565 return $titleObj !== NULL;
569 * Returns true if the currently-referenced revision is the current edit
570 * to this page (and it exists).
573 function isCurrent() {
574 return $this->exists() &&
575 isset( $this->mRevision
) &&
576 $this->mRevision
->isCurrent();
580 * Loads everything except the text
581 * This isn't necessary for all uses, so it's only done if needed.
584 function loadLastEdit() {
587 if ( -1 != $this->mUser
)
590 # New or non-existent articles have no user information
591 $id = $this->getID();
592 if ( 0 == $id ) return;
594 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
595 if( !is_null( $this->mLastRevision
) ) {
596 $this->mUser
= $this->mLastRevision
->getUser();
597 $this->mUserText
= $this->mLastRevision
->getUserText();
598 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
599 $this->mComment
= $this->mLastRevision
->getComment();
600 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
604 function getTimestamp() {
605 $this->loadLastEdit();
606 return wfTimestamp(TS_MW
, $this->mTimestamp
);
610 $this->loadLastEdit();
614 function getUserText() {
615 $this->loadLastEdit();
616 return $this->mUserText
;
619 function getComment() {
620 $this->loadLastEdit();
621 return $this->mComment
;
624 function getMinorEdit() {
625 $this->loadLastEdit();
626 return $this->mMinorEdit
;
629 function getRevIdFetched() {
630 $this->loadLastEdit();
631 return $this->mRevIdFetched
;
634 function getContributors($limit = 0, $offset = 0) {
635 $fname = 'Article::getContributors';
637 # XXX: this is expensive; cache this info somewhere.
639 $title = $this->mTitle
;
641 $dbr =& $this->getDB();
642 $revTable = $dbr->tableName( 'revision' );
643 $userTable = $dbr->tableName( 'user' );
644 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
645 $ns = $title->getNamespace();
646 $user = $this->getUser();
647 $pageId = $this->getId();
649 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
650 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
651 WHERE rev_page = $pageId
652 AND rev_user != $user
653 GROUP BY rev_user, rev_user_text, user_real_name
654 ORDER BY timestamp DESC";
656 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
657 $sql .= ' '. $this->getSelectOptions();
659 $res = $dbr->query($sql, $fname);
661 while ( $line = $dbr->fetchObject( $res ) ) {
662 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
665 $dbr->freeResult($res);
670 * This is the default action of the script: just view the page of
674 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
675 global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
676 global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
677 $sk = $wgUser->getSkin();
679 $fname = 'Article::view';
680 wfProfileIn( $fname );
681 # Get variables from query string
682 $oldid = $this->getOldID();
683 $diff = $wgRequest->getVal( 'diff' );
684 $rcid = $wgRequest->getVal( 'rcid' );
685 $rdfrom = $wgRequest->getVal( 'rdfrom' );
687 $wgOut->setArticleFlag( true );
688 $wgOut->setRobotpolicy( 'index,follow' );
689 # If we got diff and oldid in the query, we want to see a
690 # diff page instead of the article.
692 if ( !is_null( $diff ) ) {
693 require_once( 'DifferenceEngine.php' );
694 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
696 $de = new DifferenceEngine( $oldid, $diff, $rcid );
697 // DifferenceEngine directly fetched the revision:
698 $this->mRevIdFetched
= $de->mNewid
;
702 # Run view updates for current revision only
703 $this->viewUpdates();
705 wfProfileOut( $fname );
709 if ( empty( $oldid ) && $this->checkTouched() ) {
710 $wgOut->setETag($wgParserCache->getETag($this, $wgUser));
712 if( $wgOut->checkLastModified( $this->mTouched
) ){
713 wfProfileOut( $fname );
715 } else if ( $this->tryFileCache() ) {
716 # tell wgOut that output is taken care of
718 $this->viewUpdates();
719 wfProfileOut( $fname );
723 # Should the parser cache be used?
724 $pcache = $wgEnableParserCache &&
725 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
728 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
732 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
736 if ( !$outputDone ) {
737 $text = $this->getContent( false ); # May change mTitle by following a redirect
739 # Another whitelist check in case oldid or redirects are altering the title
740 if ( !$this->mTitle
->userCanRead() ) {
741 $wgOut->loginToUse();
746 # We're looking at an old revision
748 if ( !empty( $oldid ) ) {
749 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
750 $wgOut->setRobotpolicy( 'noindex,follow' );
752 if ( '' != $this->mRedirectedFrom
) {
753 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
754 $sk = $wgUser->getSkin();
755 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '', 'redirect=no' );
756 $s = wfMsg( 'redirectedfrom', $redir );
757 $wgOut->setSubtitle( $s );
758 # Can't cache redirects
761 } elseif ( !empty( $rdfrom ) ) {
762 global $wgRedirectSources;
763 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
764 $sk = $wgUser->getSkin();
765 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
766 $s = wfMsg( 'redirectedfrom', $redir );
767 $wgOut->setSubtitle( $s );
771 # wrap user css and user js in pre and don't parse
772 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
774 $this->mTitle
->getNamespace() == NS_USER
&&
775 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
777 $wgOut->addWikiText( wfMsg('clearyourcache'));
778 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
779 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
781 $imageUrl = $wgStylePath.'/common/images/redirect.png';
782 $targetUrl = $rt->escapeLocalURL();
783 $titleText = htmlspecialchars( $rt->getPrefixedText() );
784 $link = $sk->makeLinkObj( $rt );
786 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
787 '<span class="redirectText">'.$link.'</span>' );
789 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
790 $catlinks = $parseout->getCategoryLinks();
791 $wgOut->addCategoryLinks($catlinks);
792 $skin = $wgUser->getSkin();
793 } else if ( $pcache ) {
794 # Display content and save to parser cache
795 $wgOut->addPrimaryWikiText( $text, $this );
797 # Display content, don't attempt to save to parser cache
799 # Don't show section-edit links on old revisions... this way lies madness.
800 if( !$this->isCurrent() ) {
801 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
803 $wgOut->addWikiText( $text );
805 if( !$this->isCurrent() ) {
806 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
810 /* title may have been set from the cache */
811 $t = $wgOut->getPageTitle();
813 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
816 # If we have been passed an &rcid= parameter, we want to give the user a
817 # chance to mark this new article as patrolled.
821 && $wgUser->isLoggedIn()
822 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
825 "<div class='patrollink'>" .
826 wfMsg ( 'markaspatrolledlink',
827 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
834 if ($wgUseTrackbacks)
835 $this->addTrackbacks();
837 # Put link titles into the link cache
838 $wgOut->transformBuffer();
840 # Add link titles as META keywords
841 $wgOut->addMetaTags() ;
843 $this->viewUpdates();
844 wfProfileOut( $fname );
847 function addTrackbacks() {
848 global $wgOut, $wgUser;
850 $dbr =& wfGetDB(DB_SLAVE
);
852 /* FROM */ 'trackbacks',
853 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
854 /* WHERE */ array('tb_page' => $this->getID())
857 if (!$dbr->numrows($tbs))
861 while ($o = $dbr->fetchObject($tbs)) {
863 if ($wgUser->isSysop()) {
864 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
865 . $o->tb_id
. "&token=" . $wgUser->editToken());
866 $rmvtxt = wfMsg('trackbackremove', $delurl);
868 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
875 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
878 function deletetrackback() {
879 global $wgUser, $wgRequest, $wgOut, $wgTitle;
881 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
882 $wgOut->addWikitext(wfMsg('sessionfailure'));
886 if ((!$wgUser->isAllowed('delete'))) {
887 $wgOut->sysopRequired();
892 $wgOut->readOnlyPage();
896 $db =& wfGetDB(DB_MASTER
);
897 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
898 $wgTitle->invalidateCache();
899 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
905 $wgOut->setArticleBodyOnly(true);
910 * Insert a new empty page record for this article.
911 * This *must* be followed up by creating a revision
912 * and running $this->updateToLatest( $rev_id );
913 * or else the record will be left in a funky state.
914 * Best if all done inside a transaction.
916 * @param Database $dbw
917 * @param string $restrictions
918 * @return int The newly created page_id key
921 function insertOn( &$dbw, $restrictions = '' ) {
922 $fname = 'Article::insertOn';
923 wfProfileIn( $fname );
925 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
926 $dbw->insert( 'page', array(
927 'page_id' => $page_id,
928 'page_namespace' => $this->mTitle
->getNamespace(),
929 'page_title' => $this->mTitle
->getDBkey(),
931 'page_restrictions' => $restrictions,
932 'page_is_redirect' => 0, # Will set this shortly...
934 'page_random' => wfRandom(),
935 'page_touched' => $dbw->timestamp(),
936 'page_latest' => 0, # Fill this in shortly...
938 $newid = $dbw->insertId();
940 $this->mTitle
->resetArticleId( $newid );
942 wfProfileOut( $fname );
947 * Update the page record to point to a newly saved revision.
949 * @param Database $dbw
950 * @param Revision $revision -- for ID number, and text used to set
951 length and redirect status fields
952 * @param int $lastRevision -- if given, will not overwrite the page field
953 * when different from the currently set value.
954 * Giving 0 indicates the new page flag should
956 * @return bool true on success, false on failure
959 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
960 $fname = 'Article::updateToRevision';
961 wfProfileIn( $fname );
963 $conditions = array( 'page_id' => $this->getId() );
964 if( !is_null( $lastRevision ) ) {
965 # An extra check against threads stepping on each other
966 $conditions['page_latest'] = $lastRevision;
969 $text = $revision->getText();
970 $dbw->update( 'page',
972 'page_latest' => $revision->getId(),
973 'page_touched' => $dbw->timestamp(),
974 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
975 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
976 'page_len' => strlen( $text ),
981 wfProfileOut( $fname );
982 return ( $dbw->affectedRows() != 0 );
986 * If the given revision is newer than the currently set page_latest,
987 * update the page record. Otherwise, do nothing.
989 * @param Database $dbw
990 * @param Revision $revision
992 function updateIfNewerOn( &$dbw, $revision ) {
993 $fname = 'Article::updateIfNewerOn';
994 wfProfileIn( $fname );
996 $row = $dbw->selectRow(
997 array( 'revision', 'page' ),
998 array( 'rev_id', 'rev_timestamp' ),
1000 'page_id' => $this->getId(),
1001 'page_latest=rev_id' ),
1004 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1005 wfProfileOut( $fname );
1008 $prev = $row->rev_id
;
1010 # No or missing previous revision; mark the page as new
1014 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1015 wfProfileOut( $fname );
1020 * Theoretically we could defer these whole insert and update
1021 * functions for after display, but that's taking a big leap
1022 * of faith, and we want to be able to report database
1023 * errors at some point.
1026 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1027 global $wgOut, $wgUser;
1028 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1030 $fname = 'Article::insertNewArticle';
1031 wfProfileIn( $fname );
1033 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1034 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1035 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1036 wfProfileOut( $fname );
1040 $this->mGoodAdjustment
= $this->isCountable( $text );
1041 $this->mTotalAdjustment
= 1;
1043 $ns = $this->mTitle
->getNamespace();
1044 $ttl = $this->mTitle
->getDBkey();
1046 # If this is a comment, add the summary as headline
1047 if($comment && $summary!="") {
1048 $text="== {$summary} ==\n\n".$text;
1050 $text = $this->preSaveTransform( $text );
1051 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1052 $now = wfTimestampNow();
1054 $dbw =& wfGetDB( DB_MASTER
);
1056 # Add the page record; stake our claim on this title!
1057 $newid = $this->insertOn( $dbw );
1059 # Save the revision text...
1060 $revision = new Revision( array(
1062 'comment' => $summary,
1063 'minor_edit' => $isminor,
1066 $revisionId = $revision->insertOn( $dbw );
1068 $this->mTitle
->resetArticleID( $newid );
1070 # Update the page record with revision data
1071 $this->updateRevisionOn( $dbw, $revision, 0 );
1073 Article
::onArticleCreate( $this->mTitle
);
1075 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1076 '', strlen( $text ), $revisionId );
1080 if(!$this->mTitle
->userIsWatching()) $this->watch();
1082 if ( $this->mTitle
->userIsWatching() ) {
1087 # The talk page isn't in the regular link tables, so we need to update manually:
1088 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1089 $dbw->update( 'page',
1090 array( 'page_touched' => $dbw->timestamp($now) ),
1091 array( 'page_namespace' => $talkns,
1092 'page_title' => $ttl ),
1095 # standard deferred updates
1096 $this->editUpdates( $text, $summary, $isminor, $now );
1098 $oldid = 0; # new article
1099 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1101 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1103 $watchthis, NULL ) );
1104 wfProfileOut( $fname );
1107 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1108 $this->replaceSection( $section, $text, $summary, $edittime );
1111 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1112 $fname = 'Article::replaceSection';
1113 wfProfileIn( $fname );
1115 if ($section != '') {
1116 if( is_null( $edittime ) ) {
1117 $rev = Revision
::newFromTitle( $this->mTitle
);
1119 $dbw =& wfGetDB( DB_MASTER
);
1120 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1122 $oldtext = $rev->getText();
1124 if($section=='new') {
1125 if($summary) $subject="== {$summary} ==\n\n";
1126 $text=$oldtext."\n\n".$subject.$text;
1129 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1130 # comments to be stripped as well)
1131 $striparray=array();
1132 $parser=new Parser();
1133 $parser->mOutputType
=OT_WIKI
;
1134 $parser->mOptions
= new ParserOptions();
1135 $oldtext=$parser->strip($oldtext, $striparray, true);
1137 # now that we can be sure that no pseudo-sections are in the source,
1139 # Unfortunately we can't simply do a preg_replace because that might
1140 # replace the wrong section, so we have to use the section counter instead
1141 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1142 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1143 $secs[$section*2]=$text."\n\n"; // replace with edited
1145 # section 0 is top (intro) section
1148 # headline of old section - we need to go through this section
1149 # to determine if there are any subsections that now need to
1150 # be erased, as the mother section has been replaced with
1151 # the text of all subsections.
1152 $headline=$secs[$section*2-1];
1153 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1154 $hlevel=$matches[1];
1156 # determine headline level for wikimarkup headings
1157 if(strpos($hlevel,'=')!==false) {
1158 $hlevel=strlen($hlevel);
1161 $secs[$section*2-1]=''; // erase old headline
1164 while(!empty($secs[$count*2-1]) && !$break) {
1166 $subheadline=$secs[$count*2-1];
1168 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1169 $subhlevel=$matches[1];
1170 if(strpos($subhlevel,'=')!==false) {
1171 $subhlevel=strlen($subhlevel);
1173 if($subhlevel > $hlevel) {
1174 // erase old subsections
1175 $secs[$count*2-1]='';
1178 if($subhlevel <= $hlevel) {
1186 $text=join('',$secs);
1187 # reinsert the stuff that we stripped out earlier
1188 $text=$parser->unstrip($text,$striparray);
1189 $text=$parser->unstripNoWiki($text,$striparray);
1193 wfProfileOut( $fname );
1198 * Change an existing article. Puts the previous version back into the old table, updates RC
1199 * and all necessary caches, mostly via the deferred update array.
1201 * It is possible to call this function from a command-line script, but note that you should
1202 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1204 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1205 global $wgOut, $wgUser;
1206 global $wgDBtransactions, $wgMwRedir;
1207 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
1209 $fname = 'Article::updateArticle';
1210 wfProfileIn( $fname );
1213 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1215 &$watchthis, &$sectionanchor ) ) ) {
1216 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1217 wfProfileOut( $fname );
1221 $isminor = ( $minor && $wgUser->isLoggedIn() );
1222 if ( $this->isRedirect( $text ) ) {
1223 # Remove all content but redirect
1224 # This could be done by reconstructing the redirect from a title given by
1225 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1227 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1229 $text = $m[1] . "\n";
1232 else { $redir = 0; }
1234 $text = $this->preSaveTransform( $text );
1235 $dbw =& wfGetDB( DB_MASTER
);
1236 $now = wfTimestampNow();
1238 # Update article, but only if changed.
1240 # It's important that we either rollback or complete, otherwise an attacker could
1241 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1242 # could conceivably have the same effect, especially if cur is locked for long periods.
1243 if( !$wgDBtransactions ) {
1244 $userAbort = ignore_user_abort( true );
1247 $oldtext = $this->getContent( true );
1248 $oldsize = strlen( $oldtext );
1249 $newsize = strlen( $text );
1252 if ( 0 != strcmp( $text, $oldtext ) ) {
1253 $this->mGoodAdjustment
= $this->isCountable( $text )
1254 - $this->isCountable( $oldtext );
1255 $this->mTotalAdjustment
= 0;
1256 $now = wfTimestampNow();
1258 $lastRevision = $dbw->selectField(
1259 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1261 $revision = new Revision( array(
1262 'page' => $this->getId(),
1263 'comment' => $summary,
1264 'minor_edit' => $isminor,
1268 $dbw->immediateCommit();
1270 $revisionId = $revision->insertOn( $dbw );
1273 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1276 /* Belated edit conflict! Run away!! */
1280 # Update recentchanges and purge cache and whatnot
1281 $bot = (int)($wgUser->isBot() ||
$forceBot);
1282 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1283 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1285 Article
::onArticleEdit( $this->mTitle
);
1290 if( !$wgDBtransactions ) {
1291 ignore_user_abort( $userAbort );
1296 if (!$this->mTitle
->userIsWatching()) {
1297 $dbw->immediateCommit();
1303 if ( $this->mTitle
->userIsWatching() ) {
1304 $dbw->immediateCommit();
1310 # standard deferred updates
1311 $this->editUpdates( $text, $summary, $minor, $now );
1315 # Template namespace
1316 # Purge all articles linking here
1317 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1318 $titles = $this->mTitle
->getLinksTo();
1319 Title
::touchArray( $titles );
1320 if ( $wgUseSquid ) {
1321 foreach ( $titles as $title ) {
1322 $urls[] = $title->getInternalURL();
1328 if ( $wgUseSquid ) {
1329 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1330 $u = new SquidUpdate( $urls );
1331 array_push( $wgPostCommitUpdateList, $u );
1335 if ( $wgUseFileCache ) {
1336 $cm = new CacheManager($this->mTitle
);
1337 @unlink
($cm->fileCacheName());
1340 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1342 wfRunHooks( 'ArticleSaveComplete',
1343 array( &$this, &$wgUser, $text,
1345 $watchthis, $sectionanchor ) );
1346 wfProfileOut( $fname );
1351 * After we've either updated or inserted the article, update
1352 * the link tables and redirect to the new page.
1354 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1355 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1356 global $wgUseEnotif;
1358 $fname = 'Article::showArticle';
1359 wfProfileIn( $fname );
1361 $wgLinkCache = new LinkCache();
1363 if ( !$wgUseDumbLinkUpdate ) {
1364 # Preload links to reduce lock time
1365 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1366 $wgLinkCache->preFill( $this->mTitle
);
1367 $wgLinkCache->clear();
1371 # Parse the text and replace links with placeholders
1372 $wgOut = new OutputPage();
1374 # Pass the current title along in case we're creating a wiki page
1375 # which is different than the currently displayed one (e.g. image
1376 # pages created on file uploads); otherwise, link updates will
1378 $wgOut->addWikiTextWithTitle( $text, $this->mTitle
);
1380 if ( !$wgUseDumbLinkUpdate ) {
1381 # Move the current links back to the second register
1382 $wgLinkCache->swapRegisters();
1384 # Get old version of link table to allow incremental link updates
1385 # Lock this data now since it is needed for an update
1386 $wgLinkCache->forUpdate( true );
1387 $wgLinkCache->preFill( $this->mTitle
);
1389 # Swap this old version back into its rightful place
1390 $wgLinkCache->swapRegisters();
1393 if( $this->isRedirect( $text ) )
1397 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1399 if ( $wgUseEnotif ) {
1400 # this would be better as an extension hook
1401 include_once( "UserMailer.php" );
1402 $wgEnotif = new EmailNotification ();
1403 $wgEnotif->notifyOnPageChange( $this->mTitle
, $now, $summary, $me2, $oldid );
1405 wfProfileOut( $fname );
1409 * Mark this particular edit as patrolled
1411 function markpatrolled() {
1412 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1413 $wgOut->setRobotpolicy( 'noindex,follow' );
1415 if ( !$wgUseRCPatrol )
1417 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1420 if ( $wgUser->isAnon() )
1422 $wgOut->loginToUse();
1425 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1427 $wgOut->sysopRequired();
1430 $rcid = $wgRequest->getVal( 'rcid' );
1431 if ( !is_null ( $rcid ) )
1433 RecentChange
::markPatrolled( $rcid );
1434 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1435 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1437 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1438 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1442 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1449 function validate() {
1450 global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
1452 if ( !$wgUseValidation ) # Are we using article validation at all?
1454 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
1458 $wgOut->setRobotpolicy( 'noindex,follow' );
1459 $revision = $wgRequest->getVal( 'revision' );
1461 include_once ( "SpecialValidate.php" ) ; # The "Validation" class
1463 $v = new Validation
;
1464 if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
1465 $t = $v->showList ( $this ) ;
1466 else if ( $wgRequest->getVal ( "mode" , "" ) == "details" )
1467 $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ;
1469 $t = $v->validatePageForm ( $this , $revision ) ;
1471 $wgOut->addHTML ( $t ) ;
1475 * Add this page to $wgUser's watchlist
1480 global $wgUser, $wgOut;
1482 if ( $wgUser->isAnon() ) {
1483 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1486 if ( wfReadOnly() ) {
1487 $wgOut->readOnlyPage();
1491 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1493 $wgUser->addWatch( $this->mTitle
);
1494 $wgUser->saveSettings();
1496 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1498 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1499 $wgOut->setRobotpolicy( 'noindex,follow' );
1501 $link = $this->mTitle
->getPrefixedText();
1502 $text = wfMsg( 'addedwatchtext', $link );
1503 $wgOut->addWikiText( $text );
1506 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1510 * Stop watching a page
1513 function unwatch() {
1515 global $wgUser, $wgOut;
1517 if ( $wgUser->isAnon() ) {
1518 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1521 if ( wfReadOnly() ) {
1522 $wgOut->readOnlyPage();
1526 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1528 $wgUser->removeWatch( $this->mTitle
);
1529 $wgUser->saveSettings();
1531 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1533 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1534 $wgOut->setRobotpolicy( 'noindex,follow' );
1536 $link = $this->mTitle
->getPrefixedText();
1537 $text = wfMsg( 'removedwatchtext', $link );
1538 $wgOut->addWikiText( $text );
1541 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1547 function protect( $limit = 'sysop' ) {
1548 global $wgUser, $wgOut, $wgRequest;
1550 if ( ! $wgUser->isAllowed('protect') ) {
1551 $wgOut->sysopRequired();
1554 if ( wfReadOnly() ) {
1555 $wgOut->readOnlyPage();
1558 $id = $this->mTitle
->getArticleID();
1560 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1564 $confirm = $wgRequest->wasPosted() &&
1565 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1566 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1567 $reason = $wgRequest->getText( 'wpReasonProtect' );
1570 $dbw =& wfGetDB( DB_MASTER
);
1571 $dbw->update( 'page',
1573 'page_touched' => $dbw->timestamp(),
1574 'page_restrictions' => (string)$limit
1575 ), array( /* WHERE */
1577 ), 'Article::protect'
1580 $restrictions = "move=" . $limit;
1582 $restrictions .= ":edit=" . $limit;
1584 if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
1586 $dbw =& wfGetDB( DB_MASTER
);
1587 $dbw->update( 'page',
1589 'page_touched' => $dbw->timestamp(),
1590 'page_restrictions' => $restrictions
1591 ), array( /* WHERE */
1593 ), 'Article::protect'
1596 wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
1598 $log = new LogPage( 'protect' );
1599 if ( $limit === '' ) {
1600 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1602 $log->addEntry( 'protect', $this->mTitle
, $reason );
1604 $wgOut->redirect( $this->mTitle
->getFullURL() );
1608 return $this->confirmProtect( '', '', $limit );
1613 * Output protection confirmation dialog
1615 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1616 global $wgOut, $wgUser;
1618 wfDebug( "Article::confirmProtect\n" );
1620 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1621 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1627 if ( $limit === '' ) {
1628 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1629 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1630 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1631 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1632 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1634 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1635 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1636 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1637 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1638 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1639 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1642 $confirm = htmlspecialchars( wfMsg( 'protectpage' ) );
1643 $token = htmlspecialchars( $wgUser->editToken() );
1646 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1650 <label for='wpReasonProtect'>{$protcom}:</label>
1653 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1656 if($moveonly != '') {
1660 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1663 <label for='wpMoveOnly'>{$moveonly}</label>
1671 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1675 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1678 $wgOut->returnToMain( false );
1682 * Unprotect the pages
1684 function unprotect() {
1685 return $this->protect( '' );
1689 * UI entry point for page deletion
1692 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1693 $fname = 'Article::delete';
1694 $confirm = $wgRequest->wasPosted() &&
1695 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1696 $reason = $wgRequest->getText( 'wpReason' );
1698 # This code desperately needs to be totally rewritten
1701 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1702 $wgOut->sysopRequired();
1705 if( wfReadOnly() ) {
1706 $wgOut->readOnlyPage();
1710 # Better double-check that it hasn't been deleted yet!
1711 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1712 if( !$this->mTitle
->exists() ) {
1713 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1718 $this->doDelete( $reason );
1722 # determine whether this page has earlier revisions
1723 # and insert a warning if it does
1724 # we select the text because it might be useful below
1725 $dbr =& $this->getDB();
1726 $ns = $this->mTitle
->getNamespace();
1727 $title = $this->mTitle
->getDBkey();
1728 $revisions = $dbr->select( array( 'page', 'revision' ),
1729 array( 'rev_id', 'rev_user_text' ),
1731 'page_namespace' => $ns,
1732 'page_title' => $title,
1733 'rev_page = page_id'
1734 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1737 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1738 $skin=$wgUser->getSkin();
1739 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1740 $wgOut->addHTML( $skin->historyLink() .'</b>');
1744 $rev = Revision
::newFromTitle( $this->mTitle
);
1746 # Fetch name(s) of contributors
1748 $all_same_user = true;
1749 while( $row = $dbr->fetchObject( $revisions ) ) {
1750 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1751 $all_same_user = false;
1753 $rev_name = $row->rev_user_text
;
1757 if( !is_null( $rev ) ) {
1758 # if this is a mini-text, we can paste part of it into the deletion reason
1759 $text = $rev->getText();
1761 #if this is empty, an earlier revision may contain "useful" text
1764 $prev = $rev->getPrevious();
1766 $text = $prev->getText();
1771 $length = strlen( $text );
1773 # this should not happen, since it is not possible to store an empty, new
1774 # page. Let's insert a standard text in case it does, though
1775 if( $length == 0 && $reason === '' ) {
1776 $reason = wfMsgForContent( 'exblank' );
1779 if( $length < 500 && $reason === '' ) {
1780 # comment field=255, let's grep the first 150 to have some user
1783 $text = $wgContLang->truncate( $text, 150, '...' );
1785 # let's strip out newlines
1786 $text = preg_replace( "/[\n\r]/", '', $text );
1789 if( !$all_same_user ) {
1790 $reason = wfMsgForContent( 'excontent', $text );
1792 $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
1795 $reason = wfMsgForContent( 'exbeforeblank', $text );
1800 return $this->confirmDelete( '', $reason );
1804 * Output deletion confirmation dialog
1806 function confirmDelete( $par, $reason ) {
1807 global $wgOut, $wgUser;
1809 wfDebug( "Article::confirmDelete\n" );
1811 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1812 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1813 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1814 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1816 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1818 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1819 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1820 $token = htmlspecialchars( $wgUser->editToken() );
1823 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1827 <label for='wpReason'>{$delcom}:</label>
1830 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1836 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1840 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1843 $wgOut->returnToMain( false );
1848 * Perform a deletion and output success or failure messages
1850 function doDelete( $reason ) {
1851 global $wgOut, $wgUser, $wgContLang;
1852 $fname = 'Article::doDelete';
1853 wfDebug( $fname."\n" );
1855 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1856 if ( $this->doDeleteArticle( $reason ) ) {
1857 $deleted = $this->mTitle
->getPrefixedText();
1859 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1860 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1862 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1863 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1865 $wgOut->addWikiText( $text );
1866 $wgOut->returnToMain( false );
1867 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1869 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1875 * Back-end article deletion
1876 * Deletes the article with database consistency, writes logs, purges caches
1879 function doDeleteArticle( $reason ) {
1881 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
1882 global $wgUseTrackbacks;
1884 $fname = 'Article::doDeleteArticle';
1885 wfDebug( $fname."\n" );
1887 $dbw =& wfGetDB( DB_MASTER
);
1888 $ns = $this->mTitle
->getNamespace();
1889 $t = $this->mTitle
->getDBkey();
1890 $id = $this->mTitle
->getArticleID();
1892 if ( $t == '' ||
$id == 0 ) {
1896 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1897 array_push( $wgDeferredUpdateList, $u );
1899 $linksTo = $this->mTitle
->getLinksTo();
1902 if ( $wgUseSquid ) {
1904 $this->mTitle
->getInternalURL(),
1905 $this->mTitle
->getInternalURL( 'history' )
1908 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1909 array_push( $wgPostCommitUpdateList, $u );
1913 # Client and file cache invalidation
1914 Title
::touchArray( $linksTo );
1917 // For now, shunt the revision data into the archive table.
1918 // Text is *not* removed from the text table; bulk storage
1919 // is left intact to avoid breaking block-compression or
1920 // immutable storage schemes.
1922 // For backwards compatibility, note that some older archive
1923 // table entries will have ar_text and ar_flags fields still.
1925 // In the future, we may keep revisions and mark them with
1926 // the rev_deleted field, which is reserved for this purpose.
1927 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1929 'ar_namespace' => 'page_namespace',
1930 'ar_title' => 'page_title',
1931 'ar_comment' => 'rev_comment',
1932 'ar_user' => 'rev_user',
1933 'ar_user_text' => 'rev_user_text',
1934 'ar_timestamp' => 'rev_timestamp',
1935 'ar_minor_edit' => 'rev_minor_edit',
1936 'ar_rev_id' => 'rev_id',
1937 'ar_text_id' => 'rev_text_id',
1940 'page_id = rev_page'
1944 # Now that it's safely backed up, delete it
1945 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1946 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1948 if ($wgUseTrackbacks)
1949 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1951 # Clean up recentchanges entries...
1952 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1954 # Finally, clean up the link tables
1955 $t = $this->mTitle
->getPrefixedDBkey();
1957 Article
::onArticleDelete( $this->mTitle
);
1959 # Delete outgoing links
1960 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1961 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1962 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1965 $log = new LogPage( 'delete' );
1966 $log->addEntry( 'delete', $this->mTitle
, $reason );
1968 # Clear the cached article id so the interface doesn't act like we exist
1969 $this->mTitle
->resetArticleID( 0 );
1970 $this->mTitle
->mArticleID
= 0;
1975 * Revert a modification
1977 function rollback() {
1978 global $wgUser, $wgOut, $wgRequest;
1979 $fname = 'Article::rollback';
1981 if ( ! $wgUser->isAllowed('rollback') ) {
1982 $wgOut->sysopRequired();
1985 if ( wfReadOnly() ) {
1986 $wgOut->readOnlyPage( $this->getContent( true ) );
1989 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
1990 array( $this->mTitle
->getPrefixedText(),
1991 $wgRequest->getVal( 'from' ) ) ) ) {
1992 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1993 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
1996 $dbw =& wfGetDB( DB_MASTER
);
1998 # Enhanced rollback, marks edits rc_bot=1
1999 $bot = $wgRequest->getBool( 'bot' );
2001 # Replace all this user's current edits with the next one down
2002 $tt = $this->mTitle
->getDBKey();
2003 $n = $this->mTitle
->getNamespace();
2005 # Get the last editor, lock table exclusively
2007 $current = Revision
::newFromTitle( $this->mTitle
);
2008 if( is_null( $current ) ) {
2009 # Something wrong... no page?
2011 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2015 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2016 if( $from != $current->getUserText() ) {
2017 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2018 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2019 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2020 htmlspecialchars( $from ),
2021 htmlspecialchars( $current->getUserText() ) ) );
2022 if( $current->getComment() != '') {
2024 wfMsg( 'editcomment',
2025 htmlspecialchars( $current->getComment() ) ) );
2030 # Get the last edit not by this guy
2031 $user = intval( $current->getUser() );
2032 $user_text = $dbw->addQuotes( $current->getUserText() );
2033 $s = $dbw->selectRow( 'revision',
2034 array( 'rev_id', 'rev_timestamp' ),
2036 'rev_page' => $current->getPage(),
2037 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2040 'USE INDEX' => 'page_timestamp',
2041 'ORDER BY' => 'rev_timestamp DESC' )
2043 if( $s === false ) {
2046 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2047 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2052 # Mark all reverted edits as bot
2053 $dbw->update( 'recentchanges',
2056 ), array( /* WHERE */
2057 'rc_cur_id' => $current->getPage(),
2058 'rc_user_text' => $current->getUserText(),
2059 "rc_timestamp > '{$s->rev_timestamp}'",
2065 $target = Revision
::newFromId( $s->rev_id
);
2066 $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2068 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2069 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2070 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
2072 $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle
->userIsWatching(), $bot );
2073 Article
::onArticleEdit( $this->mTitle
);
2076 $wgOut->returnToMain( false );
2081 * Do standard deferred updates after page view
2084 function viewUpdates() {
2085 global $wgDeferredUpdateList, $wgUseEnotif;
2087 if ( 0 != $this->getID() ) {
2088 global $wgDisableCounters;
2089 if( !$wgDisableCounters ) {
2090 Article
::incViewCount( $this->getID() );
2091 $u = new SiteStatsUpdate( 1, 0, 0 );
2092 array_push( $wgDeferredUpdateList, $u );
2096 # Update newtalk status if user is reading their own
2100 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
2101 $this->mTitle
->getText() == $wgUser->getName())
2103 if ( $wgUseEnotif ) {
2104 require_once( 'UserTalkUpdate.php' );
2105 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
2107 $wgUser->setNewtalk(0);
2108 $wgUser->saveNewtalk();
2110 } elseif ( $wgUseEnotif ) {
2111 $wgUser->clearNotification( $this->mTitle
);
2117 * Do standard deferred updates after page edit.
2118 * Every 1000th edit, prune the recent changes table.
2120 * @param string $text
2122 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2123 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
2124 global $wgMessageCache, $wgUser, $wgUseEnotif;
2127 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', &$this ) ) {
2129 if ( 0 == mt_rand( 0, 999 ) ) {
2130 # Periodically flush old entries from the recentchanges table.
2133 $dbw =& wfGetDB( DB_MASTER
);
2134 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2135 $recentchanges = $dbw->tableName( 'recentchanges' );
2136 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2137 $dbw->query( $sql );
2141 $id = $this->getID();
2142 $title = $this->mTitle
->getPrefixedDBkey();
2143 $shortTitle = $this->mTitle
->getDBkey();
2146 $u = new LinksUpdate( $id, $title );
2147 array_push( $wgDeferredUpdateList, $u );
2148 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2149 array_push( $wgDeferredUpdateList, $u );
2150 $u = new SearchUpdate( $id, $title, $text );
2151 array_push( $wgDeferredUpdateList, $u );
2153 # If this is another user's talk page, update newtalk
2155 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2156 if ( $wgUseEnotif ) {
2157 require_once( 'UserTalkUpdate.php' );
2158 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary,
2159 $minoredit, $timestamp_of_pagechange);
2161 $other = User
::newFromName( $shortTitle );
2162 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2163 // An anonymous user
2164 $other = new User();
2165 $other->setName( $shortTitle );
2168 $other->setNewtalk(1);
2169 $other->saveNewtalk();
2174 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2175 $wgMessageCache->replace( $shortTitle, $text );
2181 * @todo document this function
2183 * @param string $oldid Revision ID of this article revision
2185 function setOldSubtitle( $oldid=0 ) {
2186 global $wgLang, $wgOut, $wgUser;
2188 $current = ( $oldid == $this->mLatest
);
2189 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2190 $sk = $wgUser->getSkin();
2192 ?
wfMsg( 'currentrevisionlink' )
2193 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2194 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2195 $nextlink = $current
2196 ?
wfMsg( 'nextrevision' )
2197 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2198 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2199 $wgOut->setSubtitle( $r );
2203 * This function is called right before saving the wikitext,
2204 * so we can do things like signatures and links-in-context.
2206 * @param string $text
2208 function preSaveTransform( $text ) {
2209 global $wgParser, $wgUser;
2210 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2213 /* Caching functions */
2216 * checkLastModified returns true if it has taken care of all
2217 * output to the client that is necessary for this request.
2218 * (that is, it has sent a cached version of the page)
2220 function tryFileCache() {
2221 static $called = false;
2223 wfDebug( " tryFileCache() -- called twice!?\n" );
2227 if($this->isFileCacheable()) {
2228 $touched = $this->mTouched
;
2229 $cache = new CacheManager( $this->mTitle
);
2230 if($cache->isFileCacheGood( $touched )) {
2232 wfDebug( " tryFileCache() - about to load\n" );
2233 $cache->loadFromFileCache();
2236 wfDebug( " tryFileCache() - starting buffer\n" );
2237 ob_start( array(&$cache, 'saveToFileCache' ) );
2240 wfDebug( " tryFileCache() - not cacheable\n" );
2245 * Check if the page can be cached
2248 function isFileCacheable() {
2249 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2250 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2252 return $wgUseFileCache
2253 and (!$wgShowIPinHeader)
2254 and ($this->getID() != 0)
2255 and ($wgUser->isAnon())
2256 and (!$wgUser->getNewtalk())
2257 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2258 and (empty( $action ) ||
$action == 'view')
2259 and (!isset($oldid))
2261 and (!isset($redirect))
2262 and (!isset($printable))
2263 and (!$this->mRedirectedFrom
);
2267 * Loads cur_touched and returns a value indicating if it should be used
2270 function checkTouched() {
2271 $fname = 'Article::checkTouched';
2272 if( !$this->mDataLoaded
) {
2273 $dbr =& $this->getDB();
2274 $data = $this->pageDataFromId( $dbr, $this->getId() );
2276 $this->loadPageData( $data );
2279 return !$this->mIsRedirect
;
2283 * Edit an article without doing all that other stuff
2284 * The article must already exist; link tables etc
2285 * are not updated, caches are not flushed.
2287 * @param string $text text submitted
2288 * @param string $comment comment submitted
2289 * @param bool $minor whereas it's a minor modification
2291 function quickEdit( $text, $comment = '', $minor = 0 ) {
2292 $fname = 'Article::quickEdit';
2293 wfProfileIn( $fname );
2295 $dbw =& wfGetDB( DB_MASTER
);
2297 $revision = new Revision( array(
2298 'page' => $this->getId(),
2300 'comment' => $comment,
2301 'minor_edit' => $minor ?
1 : 0,
2303 $revisionId = $revision->insertOn( $dbw );
2304 $this->updateRevisionOn( $dbw, $revision );
2307 wfProfileOut( $fname );
2311 * Used to increment the view counter
2314 * @param integer $id article id
2316 function incViewCount( $id ) {
2317 $id = intval( $id );
2318 global $wgHitcounterUpdateFreq;
2320 $dbw =& wfGetDB( DB_MASTER
);
2321 $pageTable = $dbw->tableName( 'page' );
2322 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2323 $acchitsTable = $dbw->tableName( 'acchits' );
2325 if( $wgHitcounterUpdateFreq <= 1 ){ //
2326 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2330 # Not important enough to warrant an error page in case of failure
2331 $oldignore = $dbw->ignoreErrors( true );
2333 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2335 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2336 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2337 # Most of the time (or on SQL errors), skip row count check
2338 $dbw->ignoreErrors( $oldignore );
2342 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2343 $row = $dbw->fetchObject( $res );
2344 $rown = intval( $row->n
);
2345 if( $rown >= $wgHitcounterUpdateFreq ){
2346 wfProfileIn( 'Article::incViewCount-collect' );
2347 $old_user_abort = ignore_user_abort( true );
2349 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2350 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2351 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2353 $dbw->query("DELETE FROM $hitcounterTable");
2354 $dbw->query('UNLOCK TABLES');
2355 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2356 'WHERE page_id = hc_id');
2357 $dbw->query("DROP TABLE $acchitsTable");
2359 ignore_user_abort( $old_user_abort );
2360 wfProfileOut( 'Article::incViewCount-collect' );
2362 $dbw->ignoreErrors( $oldignore );
2366 * The onArticle*() functions are supposed to be a kind of hooks
2367 * which should be called whenever any of the specified actions
2370 * This is a good place to put code to clear caches, for instance.
2372 * This is called on page move and undelete, as well as edit
2374 * @param $title_obj a title object
2377 function onArticleCreate($title_obj) {
2378 global $wgUseSquid, $wgPostCommitUpdateList;
2380 $title_obj->touchLinks();
2381 $titles = $title_obj->getLinksTo();
2384 if ( $wgUseSquid ) {
2385 $urls = $title_obj->getSquidURLs();
2386 foreach ( $titles as $linkTitle ) {
2387 $urls[] = $linkTitle->getInternalURL();
2389 $u = new SquidUpdate( $urls );
2390 array_push( $wgPostCommitUpdateList, $u );
2394 function onArticleDelete( $title ) {
2395 global $wgMessageCache;
2397 $title->touchLinks();
2399 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2400 $wgMessageCache->replace( $title->getDBkey(), false );
2404 function onArticleEdit($title_obj) {
2405 // This would be an appropriate place to purge caches.
2406 // Why's this not in here now?
2412 * Info about this page
2413 * Called for ?action=info when $wgAllowPageInfo is on.
2418 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2419 $fname = 'Article::info';
2421 if ( !$wgAllowPageInfo ) {
2422 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2426 $page = $this->mTitle
->getSubjectPage();
2428 $wgOut->setPagetitle( $page->getPrefixedText() );
2429 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2431 # first, see if the page exists at all.
2432 $exists = $page->getArticleId() != 0;
2434 $wgOut->addHTML( wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2436 $dbr =& $this->getDB( DB_SLAVE
);
2438 'wl_title' => $page->getDBkey(),
2439 'wl_namespace' => $page->getNamespace() );
2440 $numwatchers = $dbr->selectField(
2445 $this->getSelectOptions() );
2447 $pageInfo = $this->pageCountInfo( $page );
2448 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2450 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2451 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2453 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2455 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2457 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2459 $wgOut->addHTML( '</ul>' );
2465 * Return the total number of edits and number of unique editors
2466 * on a given page. If page does not exist, returns false.
2468 * @param Title $title
2472 function pageCountInfo( $title ) {
2473 $id = $title->getArticleId();
2478 $dbr =& $this->getDB( DB_SLAVE
);
2480 $rev_clause = array( 'rev_page' => $id );
2481 $fname = 'Article::pageCountInfo';
2483 $edits = $dbr->selectField(
2488 $this->getSelectOptions() );
2490 $authors = $dbr->selectField(
2492 'COUNT(DISTINCT rev_user_text)',
2495 $this->getSelectOptions() );
2497 return array( 'edits' => $edits, 'authors' => $authors );
2501 * Return a list of templates used by this article.
2502 * Uses the links table to find the templates
2506 function getUsedTemplates() {
2508 $id = $this->mTitle
->getArticleID();
2510 $db =& wfGetDB( DB_SLAVE
);
2511 $res = $db->select( array( 'pagelinks' ),
2512 array( 'pl_title' ),
2515 'pl_namespace' => NS_TEMPLATE
),
2516 'Article:getUsedTemplates' );
2517 if ( false !== $res ) {
2518 if ( $db->numRows( $res ) ) {
2519 while ( $row = $db->fetchObject( $res ) ) {
2520 $result[] = $row->pl_title
;
2524 $db->freeResult( $res );