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, $wgContLang;
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 $imageDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
782 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
783 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
784 $targetUrl = $rt->escapeLocalURL();
785 $titleText = htmlspecialchars( $rt->getPrefixedText() );
786 $link = $sk->makeLinkObj( $rt );
788 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
789 '<span class="redirectText">'.$link.'</span>' );
791 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
792 $catlinks = $parseout->getCategoryLinks();
793 $wgOut->addCategoryLinks($catlinks);
794 $skin = $wgUser->getSkin();
795 } else if ( $pcache ) {
796 # Display content and save to parser cache
797 $wgOut->addPrimaryWikiText( $text, $this );
799 # Display content, don't attempt to save to parser cache
801 # Don't show section-edit links on old revisions... this way lies madness.
802 if( !$this->isCurrent() ) {
803 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
805 $wgOut->addWikiText( $text );
807 if( !$this->isCurrent() ) {
808 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
812 /* title may have been set from the cache */
813 $t = $wgOut->getPageTitle();
815 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
818 # If we have been passed an &rcid= parameter, we want to give the user a
819 # chance to mark this new article as patrolled.
823 && $wgUser->isLoggedIn()
824 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
827 "<div class='patrollink'>" .
828 wfMsg ( 'markaspatrolledlink',
829 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
836 if ($wgUseTrackbacks)
837 $this->addTrackbacks();
839 # Put link titles into the link cache
840 $wgOut->transformBuffer();
842 # Add link titles as META keywords
843 $wgOut->addMetaTags() ;
845 $this->viewUpdates();
846 wfProfileOut( $fname );
849 function addTrackbacks() {
850 global $wgOut, $wgUser;
852 $dbr =& wfGetDB(DB_SLAVE
);
854 /* FROM */ 'trackbacks',
855 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
856 /* WHERE */ array('tb_page' => $this->getID())
859 if (!$dbr->numrows($tbs))
863 while ($o = $dbr->fetchObject($tbs)) {
865 if ($wgUser->isSysop()) {
866 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
867 . $o->tb_id
. "&token=" . $wgUser->editToken());
868 $rmvtxt = wfMsg('trackbackremove', $delurl);
870 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
877 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
880 function deletetrackback() {
881 global $wgUser, $wgRequest, $wgOut, $wgTitle;
883 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
884 $wgOut->addWikitext(wfMsg('sessionfailure'));
888 if ((!$wgUser->isAllowed('delete'))) {
889 $wgOut->sysopRequired();
894 $wgOut->readOnlyPage();
898 $db =& wfGetDB(DB_MASTER
);
899 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
900 $wgTitle->invalidateCache();
901 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
907 $wgOut->setArticleBodyOnly(true);
912 * Insert a new empty page record for this article.
913 * This *must* be followed up by creating a revision
914 * and running $this->updateToLatest( $rev_id );
915 * or else the record will be left in a funky state.
916 * Best if all done inside a transaction.
918 * @param Database $dbw
919 * @param string $restrictions
920 * @return int The newly created page_id key
923 function insertOn( &$dbw, $restrictions = '' ) {
924 $fname = 'Article::insertOn';
925 wfProfileIn( $fname );
927 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
928 $dbw->insert( 'page', array(
929 'page_id' => $page_id,
930 'page_namespace' => $this->mTitle
->getNamespace(),
931 'page_title' => $this->mTitle
->getDBkey(),
933 'page_restrictions' => $restrictions,
934 'page_is_redirect' => 0, # Will set this shortly...
936 'page_random' => wfRandom(),
937 'page_touched' => $dbw->timestamp(),
938 'page_latest' => 0, # Fill this in shortly...
939 'page_len' => 0, # Fill this in shortly...
941 $newid = $dbw->insertId();
943 $this->mTitle
->resetArticleId( $newid );
945 wfProfileOut( $fname );
950 * Update the page record to point to a newly saved revision.
952 * @param Database $dbw
953 * @param Revision $revision -- for ID number, and text used to set
954 length and redirect status fields
955 * @param int $lastRevision -- if given, will not overwrite the page field
956 * when different from the currently set value.
957 * Giving 0 indicates the new page flag should
959 * @return bool true on success, false on failure
962 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
963 $fname = 'Article::updateToRevision';
964 wfProfileIn( $fname );
966 $conditions = array( 'page_id' => $this->getId() );
967 if( !is_null( $lastRevision ) ) {
968 # An extra check against threads stepping on each other
969 $conditions['page_latest'] = $lastRevision;
972 $text = $revision->getText();
973 $dbw->update( 'page',
975 'page_latest' => $revision->getId(),
976 'page_touched' => $dbw->timestamp(),
977 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
978 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
979 'page_len' => strlen( $text ),
984 wfProfileOut( $fname );
985 return ( $dbw->affectedRows() != 0 );
989 * If the given revision is newer than the currently set page_latest,
990 * update the page record. Otherwise, do nothing.
992 * @param Database $dbw
993 * @param Revision $revision
995 function updateIfNewerOn( &$dbw, $revision ) {
996 $fname = 'Article::updateIfNewerOn';
997 wfProfileIn( $fname );
999 $row = $dbw->selectRow(
1000 array( 'revision', 'page' ),
1001 array( 'rev_id', 'rev_timestamp' ),
1003 'page_id' => $this->getId(),
1004 'page_latest=rev_id' ),
1007 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1008 wfProfileOut( $fname );
1011 $prev = $row->rev_id
;
1013 # No or missing previous revision; mark the page as new
1017 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1018 wfProfileOut( $fname );
1023 * Theoretically we could defer these whole insert and update
1024 * functions for after display, but that's taking a big leap
1025 * of faith, and we want to be able to report database
1026 * errors at some point.
1029 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1030 global $wgOut, $wgUser;
1031 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1033 $fname = 'Article::insertNewArticle';
1034 wfProfileIn( $fname );
1036 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1037 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1038 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1039 wfProfileOut( $fname );
1043 $this->mGoodAdjustment
= $this->isCountable( $text );
1044 $this->mTotalAdjustment
= 1;
1046 $ns = $this->mTitle
->getNamespace();
1047 $ttl = $this->mTitle
->getDBkey();
1049 # If this is a comment, add the summary as headline
1050 if($comment && $summary!="") {
1051 $text="== {$summary} ==\n\n".$text;
1053 $text = $this->preSaveTransform( $text );
1054 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1055 $now = wfTimestampNow();
1057 $dbw =& wfGetDB( DB_MASTER
);
1059 # Add the page record; stake our claim on this title!
1060 $newid = $this->insertOn( $dbw );
1062 # Save the revision text...
1063 $revision = new Revision( array(
1065 'comment' => $summary,
1066 'minor_edit' => $isminor,
1069 $revisionId = $revision->insertOn( $dbw );
1071 $this->mTitle
->resetArticleID( $newid );
1073 # Update the page record with revision data
1074 $this->updateRevisionOn( $dbw, $revision, 0 );
1076 Article
::onArticleCreate( $this->mTitle
);
1078 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1079 '', strlen( $text ), $revisionId );
1083 if(!$this->mTitle
->userIsWatching()) $this->watch();
1085 if ( $this->mTitle
->userIsWatching() ) {
1090 # The talk page isn't in the regular link tables, so we need to update manually:
1091 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1092 $dbw->update( 'page',
1093 array( 'page_touched' => $dbw->timestamp($now) ),
1094 array( 'page_namespace' => $talkns,
1095 'page_title' => $ttl ),
1098 # standard deferred updates
1099 $this->editUpdates( $text, $summary, $isminor, $now );
1101 $oldid = 0; # new article
1102 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1104 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1106 $watchthis, NULL ) );
1107 wfProfileOut( $fname );
1110 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1111 $this->replaceSection( $section, $text, $summary, $edittime );
1115 * @return string Complete article text, or null if error
1117 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1118 $fname = 'Article::replaceSection';
1119 wfProfileIn( $fname );
1121 if ($section != '') {
1122 if( is_null( $edittime ) ) {
1123 $rev = Revision
::newFromTitle( $this->mTitle
);
1125 $dbw =& wfGetDB( DB_MASTER
);
1126 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1128 if( is_null( $rev ) ) {
1129 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1130 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1133 $oldtext = $rev->getText();
1135 if($section=='new') {
1136 if($summary) $subject="== {$summary} ==\n\n";
1137 $text=$oldtext."\n\n".$subject.$text;
1140 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1141 # comments to be stripped as well)
1142 $striparray=array();
1143 $parser=new Parser();
1144 $parser->mOutputType
=OT_WIKI
;
1145 $parser->mOptions
= new ParserOptions();
1146 $oldtext=$parser->strip($oldtext, $striparray, true);
1148 # now that we can be sure that no pseudo-sections are in the source,
1150 # Unfortunately we can't simply do a preg_replace because that might
1151 # replace the wrong section, so we have to use the section counter instead
1152 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1153 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1154 $secs[$section*2]=$text."\n\n"; // replace with edited
1156 # section 0 is top (intro) section
1159 # headline of old section - we need to go through this section
1160 # to determine if there are any subsections that now need to
1161 # be erased, as the mother section has been replaced with
1162 # the text of all subsections.
1163 $headline=$secs[$section*2-1];
1164 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1165 $hlevel=$matches[1];
1167 # determine headline level for wikimarkup headings
1168 if(strpos($hlevel,'=')!==false) {
1169 $hlevel=strlen($hlevel);
1172 $secs[$section*2-1]=''; // erase old headline
1175 while(!empty($secs[$count*2-1]) && !$break) {
1177 $subheadline=$secs[$count*2-1];
1179 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1180 $subhlevel=$matches[1];
1181 if(strpos($subhlevel,'=')!==false) {
1182 $subhlevel=strlen($subhlevel);
1184 if($subhlevel > $hlevel) {
1185 // erase old subsections
1186 $secs[$count*2-1]='';
1189 if($subhlevel <= $hlevel) {
1197 $text=join('',$secs);
1198 # reinsert the stuff that we stripped out earlier
1199 $text=$parser->unstrip($text,$striparray);
1200 $text=$parser->unstripNoWiki($text,$striparray);
1204 wfProfileOut( $fname );
1209 * Change an existing article. Puts the previous version back into the old table, updates RC
1210 * and all necessary caches, mostly via the deferred update array.
1212 * It is possible to call this function from a command-line script, but note that you should
1213 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1215 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1216 global $wgOut, $wgUser;
1217 global $wgDBtransactions, $wgMwRedir;
1218 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
1220 $fname = 'Article::updateArticle';
1221 wfProfileIn( $fname );
1224 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1226 &$watchthis, &$sectionanchor ) ) ) {
1227 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1228 wfProfileOut( $fname );
1232 $isminor = ( $minor && $wgUser->isLoggedIn() );
1233 if ( $this->isRedirect( $text ) ) {
1234 # Remove all content but redirect
1235 # This could be done by reconstructing the redirect from a title given by
1236 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1238 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1240 $text = $m[1] . "\n";
1243 else { $redir = 0; }
1245 $text = $this->preSaveTransform( $text );
1246 $dbw =& wfGetDB( DB_MASTER
);
1247 $now = wfTimestampNow();
1249 # Update article, but only if changed.
1251 # It's important that we either rollback or complete, otherwise an attacker could
1252 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1253 # could conceivably have the same effect, especially if cur is locked for long periods.
1254 if( !$wgDBtransactions ) {
1255 $userAbort = ignore_user_abort( true );
1258 $oldtext = $this->getContent( true );
1259 $oldsize = strlen( $oldtext );
1260 $newsize = strlen( $text );
1263 if ( 0 != strcmp( $text, $oldtext ) ) {
1264 $this->mGoodAdjustment
= $this->isCountable( $text )
1265 - $this->isCountable( $oldtext );
1266 $this->mTotalAdjustment
= 0;
1267 $now = wfTimestampNow();
1269 $lastRevision = $dbw->selectField(
1270 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1272 $revision = new Revision( array(
1273 'page' => $this->getId(),
1274 'comment' => $summary,
1275 'minor_edit' => $isminor,
1279 $dbw->immediateCommit();
1281 $revisionId = $revision->insertOn( $dbw );
1284 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1287 /* Belated edit conflict! Run away!! */
1291 # Update recentchanges and purge cache and whatnot
1292 $bot = (int)($wgUser->isBot() ||
$forceBot);
1293 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1294 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1296 Article
::onArticleEdit( $this->mTitle
);
1301 if( !$wgDBtransactions ) {
1302 ignore_user_abort( $userAbort );
1307 if (!$this->mTitle
->userIsWatching()) {
1308 $dbw->immediateCommit();
1314 if ( $this->mTitle
->userIsWatching() ) {
1315 $dbw->immediateCommit();
1321 # standard deferred updates
1322 $this->editUpdates( $text, $summary, $minor, $now );
1326 # Template namespace
1327 # Purge all articles linking here
1328 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1329 $titles = $this->mTitle
->getLinksTo();
1330 Title
::touchArray( $titles );
1331 if ( $wgUseSquid ) {
1332 foreach ( $titles as $title ) {
1333 $urls[] = $title->getInternalURL();
1339 if ( $wgUseSquid ) {
1340 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1341 $u = new SquidUpdate( $urls );
1342 array_push( $wgPostCommitUpdateList, $u );
1346 if ( $wgUseFileCache ) {
1347 $cm = new CacheManager($this->mTitle
);
1348 @unlink
($cm->fileCacheName());
1351 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1353 wfRunHooks( 'ArticleSaveComplete',
1354 array( &$this, &$wgUser, $text,
1356 $watchthis, $sectionanchor ) );
1357 wfProfileOut( $fname );
1362 * After we've either updated or inserted the article, update
1363 * the link tables and redirect to the new page.
1365 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1366 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1367 global $wgUseEnotif;
1369 $fname = 'Article::showArticle';
1370 wfProfileIn( $fname );
1372 $wgLinkCache = new LinkCache();
1374 if ( !$wgUseDumbLinkUpdate ) {
1375 # Preload links to reduce lock time
1376 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1377 $wgLinkCache->preFill( $this->mTitle
);
1378 $wgLinkCache->clear();
1382 # Parse the text and replace links with placeholders
1383 $wgOut = new OutputPage();
1385 # Pass the current title along in case we're creating a wiki page
1386 # which is different than the currently displayed one (e.g. image
1387 # pages created on file uploads); otherwise, link updates will
1389 $wgOut->addWikiTextWithTitle( $text, $this->mTitle
);
1391 if ( !$wgUseDumbLinkUpdate ) {
1392 # Move the current links back to the second register
1393 $wgLinkCache->swapRegisters();
1395 # Get old version of link table to allow incremental link updates
1396 # Lock this data now since it is needed for an update
1397 $wgLinkCache->forUpdate( true );
1398 $wgLinkCache->preFill( $this->mTitle
);
1400 # Swap this old version back into its rightful place
1401 $wgLinkCache->swapRegisters();
1404 if( $this->isRedirect( $text ) )
1408 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1410 if ( $wgUseEnotif ) {
1411 # this would be better as an extension hook
1412 include_once( "UserMailer.php" );
1413 $wgEnotif = new EmailNotification ();
1414 $wgEnotif->notifyOnPageChange( $this->mTitle
, $now, $summary, $me2, $oldid );
1416 wfProfileOut( $fname );
1420 * Mark this particular edit as patrolled
1422 function markpatrolled() {
1423 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1424 $wgOut->setRobotpolicy( 'noindex,follow' );
1426 if ( !$wgUseRCPatrol )
1428 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1431 if ( $wgUser->isAnon() )
1433 $wgOut->loginToUse();
1436 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1438 $wgOut->sysopRequired();
1441 $rcid = $wgRequest->getVal( 'rcid' );
1442 if ( !is_null ( $rcid ) )
1444 RecentChange
::markPatrolled( $rcid );
1445 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1446 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1448 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1449 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1453 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1460 function validate() {
1461 global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
1463 if ( !$wgUseValidation ) # Are we using article validation at all?
1465 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
1469 $wgOut->setRobotpolicy( 'noindex,follow' );
1470 $revision = $wgRequest->getVal( 'revision' );
1472 include_once ( "SpecialValidate.php" ) ; # The "Validation" class
1474 $v = new Validation
;
1475 if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
1476 $t = $v->showList ( $this ) ;
1477 else if ( $wgRequest->getVal ( "mode" , "" ) == "details" )
1478 $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ;
1480 $t = $v->validatePageForm ( $this , $revision ) ;
1482 $wgOut->addHTML ( $t ) ;
1486 * Add this page to $wgUser's watchlist
1491 global $wgUser, $wgOut;
1493 if ( $wgUser->isAnon() ) {
1494 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1497 if ( wfReadOnly() ) {
1498 $wgOut->readOnlyPage();
1502 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1504 $wgUser->addWatch( $this->mTitle
);
1505 $wgUser->saveSettings();
1507 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1509 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1510 $wgOut->setRobotpolicy( 'noindex,follow' );
1512 $link = $this->mTitle
->getPrefixedText();
1513 $text = wfMsg( 'addedwatchtext', $link );
1514 $wgOut->addWikiText( $text );
1517 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1521 * Stop watching a page
1524 function unwatch() {
1526 global $wgUser, $wgOut;
1528 if ( $wgUser->isAnon() ) {
1529 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1532 if ( wfReadOnly() ) {
1533 $wgOut->readOnlyPage();
1537 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1539 $wgUser->removeWatch( $this->mTitle
);
1540 $wgUser->saveSettings();
1542 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1544 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1545 $wgOut->setRobotpolicy( 'noindex,follow' );
1547 $link = $this->mTitle
->getPrefixedText();
1548 $text = wfMsg( 'removedwatchtext', $link );
1549 $wgOut->addWikiText( $text );
1552 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1558 function protect( $limit = 'sysop' ) {
1559 global $wgUser, $wgOut, $wgRequest;
1561 if ( ! $wgUser->isAllowed('protect') ) {
1562 $wgOut->sysopRequired();
1565 if ( wfReadOnly() ) {
1566 $wgOut->readOnlyPage();
1569 $id = $this->mTitle
->getArticleID();
1571 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1575 $confirm = $wgRequest->wasPosted() &&
1576 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1577 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1578 $reason = $wgRequest->getText( 'wpReasonProtect' );
1581 $dbw =& wfGetDB( DB_MASTER
);
1582 $dbw->update( 'page',
1584 'page_touched' => $dbw->timestamp(),
1585 'page_restrictions' => (string)$limit
1586 ), array( /* WHERE */
1588 ), 'Article::protect'
1591 $restrictions = "move=" . $limit;
1593 $restrictions .= ":edit=" . $limit;
1595 if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
1597 $dbw =& wfGetDB( DB_MASTER
);
1598 $dbw->update( 'page',
1600 'page_touched' => $dbw->timestamp(),
1601 'page_restrictions' => $restrictions
1602 ), array( /* WHERE */
1604 ), 'Article::protect'
1607 wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
1609 $log = new LogPage( 'protect' );
1610 if ( $limit === '' ) {
1611 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1613 $log->addEntry( 'protect', $this->mTitle
, $reason );
1615 $wgOut->redirect( $this->mTitle
->getFullURL() );
1619 return $this->confirmProtect( '', '', $limit );
1624 * Output protection confirmation dialog
1626 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1627 global $wgOut, $wgUser;
1629 wfDebug( "Article::confirmProtect\n" );
1631 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1632 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1638 if ( $limit === '' ) {
1639 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1640 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1641 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1642 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1643 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1645 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1646 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1647 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1648 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1649 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1650 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1653 $confirm = htmlspecialchars( wfMsg( 'protectpage' ) );
1654 $token = htmlspecialchars( $wgUser->editToken() );
1657 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1661 <label for='wpReasonProtect'>{$protcom}:</label>
1664 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1667 if($moveonly != '') {
1671 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1674 <label for='wpMoveOnly'>{$moveonly}</label>
1682 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1686 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1689 $wgOut->returnToMain( false );
1693 * Unprotect the pages
1695 function unprotect() {
1696 return $this->protect( '' );
1700 * UI entry point for page deletion
1703 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1704 $fname = 'Article::delete';
1705 $confirm = $wgRequest->wasPosted() &&
1706 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1707 $reason = $wgRequest->getText( 'wpReason' );
1709 # This code desperately needs to be totally rewritten
1712 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1713 $wgOut->sysopRequired();
1716 if( wfReadOnly() ) {
1717 $wgOut->readOnlyPage();
1721 # Better double-check that it hasn't been deleted yet!
1722 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1723 if( !$this->mTitle
->exists() ) {
1724 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1729 $this->doDelete( $reason );
1733 # determine whether this page has earlier revisions
1734 # and insert a warning if it does
1735 # we select the text because it might be useful below
1736 $dbr =& $this->getDB();
1737 $ns = $this->mTitle
->getNamespace();
1738 $title = $this->mTitle
->getDBkey();
1739 $revisions = $dbr->select( array( 'page', 'revision' ),
1740 array( 'rev_id', 'rev_user_text' ),
1742 'page_namespace' => $ns,
1743 'page_title' => $title,
1744 'rev_page = page_id'
1745 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1748 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1749 $skin=$wgUser->getSkin();
1750 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1751 $wgOut->addHTML( $skin->historyLink() .'</b>');
1755 $rev = Revision
::newFromTitle( $this->mTitle
);
1757 # Fetch name(s) of contributors
1759 $all_same_user = true;
1760 while( $row = $dbr->fetchObject( $revisions ) ) {
1761 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1762 $all_same_user = false;
1764 $rev_name = $row->rev_user_text
;
1768 if( !is_null( $rev ) ) {
1769 # if this is a mini-text, we can paste part of it into the deletion reason
1770 $text = $rev->getText();
1772 #if this is empty, an earlier revision may contain "useful" text
1775 $prev = $rev->getPrevious();
1777 $text = $prev->getText();
1782 $length = strlen( $text );
1784 # this should not happen, since it is not possible to store an empty, new
1785 # page. Let's insert a standard text in case it does, though
1786 if( $length == 0 && $reason === '' ) {
1787 $reason = wfMsgForContent( 'exblank' );
1790 if( $length < 500 && $reason === '' ) {
1791 # comment field=255, let's grep the first 150 to have some user
1794 $text = $wgContLang->truncate( $text, 150, '...' );
1796 # let's strip out newlines
1797 $text = preg_replace( "/[\n\r]/", '', $text );
1800 if( !$all_same_user ) {
1801 $reason = wfMsgForContent( 'excontent', $text );
1803 $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
1806 $reason = wfMsgForContent( 'exbeforeblank', $text );
1811 return $this->confirmDelete( '', $reason );
1815 * Output deletion confirmation dialog
1817 function confirmDelete( $par, $reason ) {
1818 global $wgOut, $wgUser;
1820 wfDebug( "Article::confirmDelete\n" );
1822 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1823 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1824 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1825 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1827 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1829 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1830 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1831 $token = htmlspecialchars( $wgUser->editToken() );
1834 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1838 <label for='wpReason'>{$delcom}:</label>
1841 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1847 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1851 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1854 $wgOut->returnToMain( false );
1859 * Perform a deletion and output success or failure messages
1861 function doDelete( $reason ) {
1862 global $wgOut, $wgUser, $wgContLang;
1863 $fname = 'Article::doDelete';
1864 wfDebug( $fname."\n" );
1866 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1867 if ( $this->doDeleteArticle( $reason ) ) {
1868 $deleted = $this->mTitle
->getPrefixedText();
1870 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1871 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1873 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1874 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1876 $wgOut->addWikiText( $text );
1877 $wgOut->returnToMain( false );
1878 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1880 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1886 * Back-end article deletion
1887 * Deletes the article with database consistency, writes logs, purges caches
1890 function doDeleteArticle( $reason ) {
1892 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
1893 global $wgUseTrackbacks;
1895 $fname = 'Article::doDeleteArticle';
1896 wfDebug( $fname."\n" );
1898 $dbw =& wfGetDB( DB_MASTER
);
1899 $ns = $this->mTitle
->getNamespace();
1900 $t = $this->mTitle
->getDBkey();
1901 $id = $this->mTitle
->getArticleID();
1903 if ( $t == '' ||
$id == 0 ) {
1907 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1908 array_push( $wgDeferredUpdateList, $u );
1910 $linksTo = $this->mTitle
->getLinksTo();
1913 if ( $wgUseSquid ) {
1915 $this->mTitle
->getInternalURL(),
1916 $this->mTitle
->getInternalURL( 'history' )
1919 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1920 array_push( $wgPostCommitUpdateList, $u );
1924 # Client and file cache invalidation
1925 Title
::touchArray( $linksTo );
1928 // For now, shunt the revision data into the archive table.
1929 // Text is *not* removed from the text table; bulk storage
1930 // is left intact to avoid breaking block-compression or
1931 // immutable storage schemes.
1933 // For backwards compatibility, note that some older archive
1934 // table entries will have ar_text and ar_flags fields still.
1936 // In the future, we may keep revisions and mark them with
1937 // the rev_deleted field, which is reserved for this purpose.
1938 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1940 'ar_namespace' => 'page_namespace',
1941 'ar_title' => 'page_title',
1942 'ar_comment' => 'rev_comment',
1943 'ar_user' => 'rev_user',
1944 'ar_user_text' => 'rev_user_text',
1945 'ar_timestamp' => 'rev_timestamp',
1946 'ar_minor_edit' => 'rev_minor_edit',
1947 'ar_rev_id' => 'rev_id',
1948 'ar_text_id' => 'rev_text_id',
1951 'page_id = rev_page'
1955 # Now that it's safely backed up, delete it
1956 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1957 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1959 if ($wgUseTrackbacks)
1960 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1962 # Clean up recentchanges entries...
1963 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1965 # Finally, clean up the link tables
1966 $t = $this->mTitle
->getPrefixedDBkey();
1968 Article
::onArticleDelete( $this->mTitle
);
1970 # Delete outgoing links
1971 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1972 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1973 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1976 $log = new LogPage( 'delete' );
1977 $log->addEntry( 'delete', $this->mTitle
, $reason );
1979 # Clear the cached article id so the interface doesn't act like we exist
1980 $this->mTitle
->resetArticleID( 0 );
1981 $this->mTitle
->mArticleID
= 0;
1986 * Revert a modification
1988 function rollback() {
1989 global $wgUser, $wgOut, $wgRequest;
1990 $fname = 'Article::rollback';
1992 if ( ! $wgUser->isAllowed('rollback') ) {
1993 $wgOut->sysopRequired();
1996 if ( wfReadOnly() ) {
1997 $wgOut->readOnlyPage( $this->getContent( true ) );
2000 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2001 array( $this->mTitle
->getPrefixedText(),
2002 $wgRequest->getVal( 'from' ) ) ) ) {
2003 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2004 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2007 $dbw =& wfGetDB( DB_MASTER
);
2009 # Enhanced rollback, marks edits rc_bot=1
2010 $bot = $wgRequest->getBool( 'bot' );
2012 # Replace all this user's current edits with the next one down
2013 $tt = $this->mTitle
->getDBKey();
2014 $n = $this->mTitle
->getNamespace();
2016 # Get the last editor, lock table exclusively
2018 $current = Revision
::newFromTitle( $this->mTitle
);
2019 if( is_null( $current ) ) {
2020 # Something wrong... no page?
2022 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2026 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2027 if( $from != $current->getUserText() ) {
2028 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2029 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2030 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2031 htmlspecialchars( $from ),
2032 htmlspecialchars( $current->getUserText() ) ) );
2033 if( $current->getComment() != '') {
2035 wfMsg( 'editcomment',
2036 htmlspecialchars( $current->getComment() ) ) );
2041 # Get the last edit not by this guy
2042 $user = intval( $current->getUser() );
2043 $user_text = $dbw->addQuotes( $current->getUserText() );
2044 $s = $dbw->selectRow( 'revision',
2045 array( 'rev_id', 'rev_timestamp' ),
2047 'rev_page' => $current->getPage(),
2048 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2051 'USE INDEX' => 'page_timestamp',
2052 'ORDER BY' => 'rev_timestamp DESC' )
2054 if( $s === false ) {
2057 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2058 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2063 # Mark all reverted edits as bot
2064 $dbw->update( 'recentchanges',
2067 ), array( /* WHERE */
2068 'rc_cur_id' => $current->getPage(),
2069 'rc_user_text' => $current->getUserText(),
2070 "rc_timestamp > '{$s->rev_timestamp}'",
2076 $target = Revision
::newFromId( $s->rev_id
);
2077 $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2079 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2080 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2081 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
2083 $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle
->userIsWatching(), $bot );
2084 Article
::onArticleEdit( $this->mTitle
);
2087 $wgOut->returnToMain( false );
2092 * Do standard deferred updates after page view
2095 function viewUpdates() {
2096 global $wgDeferredUpdateList, $wgUseEnotif;
2098 if ( 0 != $this->getID() ) {
2099 global $wgDisableCounters;
2100 if( !$wgDisableCounters ) {
2101 Article
::incViewCount( $this->getID() );
2102 $u = new SiteStatsUpdate( 1, 0, 0 );
2103 array_push( $wgDeferredUpdateList, $u );
2107 # Update newtalk status if user is reading their own
2111 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
2112 $this->mTitle
->getText() == $wgUser->getName())
2114 if ( $wgUseEnotif ) {
2115 require_once( 'UserTalkUpdate.php' );
2116 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
2118 $wgUser->setNewtalk(0);
2119 $wgUser->saveNewtalk();
2121 } elseif ( $wgUseEnotif ) {
2122 $wgUser->clearNotification( $this->mTitle
);
2128 * Do standard deferred updates after page edit.
2129 * Every 1000th edit, prune the recent changes table.
2131 * @param string $text
2133 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2134 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
2135 global $wgMessageCache, $wgUser, $wgUseEnotif;
2138 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', &$this ) ) {
2140 if ( 0 == mt_rand( 0, 999 ) ) {
2141 # Periodically flush old entries from the recentchanges table.
2144 $dbw =& wfGetDB( DB_MASTER
);
2145 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2146 $recentchanges = $dbw->tableName( 'recentchanges' );
2147 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2148 $dbw->query( $sql );
2152 $id = $this->getID();
2153 $title = $this->mTitle
->getPrefixedDBkey();
2154 $shortTitle = $this->mTitle
->getDBkey();
2157 $u = new LinksUpdate( $id, $title );
2158 array_push( $wgDeferredUpdateList, $u );
2159 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2160 array_push( $wgDeferredUpdateList, $u );
2161 $u = new SearchUpdate( $id, $title, $text );
2162 array_push( $wgDeferredUpdateList, $u );
2164 # If this is another user's talk page, update newtalk
2166 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2167 if ( $wgUseEnotif ) {
2168 require_once( 'UserTalkUpdate.php' );
2169 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary,
2170 $minoredit, $timestamp_of_pagechange);
2172 $other = User
::newFromName( $shortTitle );
2173 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2174 // An anonymous user
2175 $other = new User();
2176 $other->setName( $shortTitle );
2179 $other->setNewtalk(1);
2180 $other->saveNewtalk();
2185 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2186 $wgMessageCache->replace( $shortTitle, $text );
2192 * @todo document this function
2194 * @param string $oldid Revision ID of this article revision
2196 function setOldSubtitle( $oldid=0 ) {
2197 global $wgLang, $wgOut, $wgUser;
2199 $current = ( $oldid == $this->mLatest
);
2200 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2201 $sk = $wgUser->getSkin();
2203 ?
wfMsg( 'currentrevisionlink' )
2204 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2205 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2206 $nextlink = $current
2207 ?
wfMsg( 'nextrevision' )
2208 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2209 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2210 $wgOut->setSubtitle( $r );
2214 * This function is called right before saving the wikitext,
2215 * so we can do things like signatures and links-in-context.
2217 * @param string $text
2219 function preSaveTransform( $text ) {
2220 global $wgParser, $wgUser;
2221 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2224 /* Caching functions */
2227 * checkLastModified returns true if it has taken care of all
2228 * output to the client that is necessary for this request.
2229 * (that is, it has sent a cached version of the page)
2231 function tryFileCache() {
2232 static $called = false;
2234 wfDebug( " tryFileCache() -- called twice!?\n" );
2238 if($this->isFileCacheable()) {
2239 $touched = $this->mTouched
;
2240 $cache = new CacheManager( $this->mTitle
);
2241 if($cache->isFileCacheGood( $touched )) {
2243 wfDebug( " tryFileCache() - about to load\n" );
2244 $cache->loadFromFileCache();
2247 wfDebug( " tryFileCache() - starting buffer\n" );
2248 ob_start( array(&$cache, 'saveToFileCache' ) );
2251 wfDebug( " tryFileCache() - not cacheable\n" );
2256 * Check if the page can be cached
2259 function isFileCacheable() {
2260 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2261 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2263 return $wgUseFileCache
2264 and (!$wgShowIPinHeader)
2265 and ($this->getID() != 0)
2266 and ($wgUser->isAnon())
2267 and (!$wgUser->getNewtalk())
2268 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2269 and (empty( $action ) ||
$action == 'view')
2270 and (!isset($oldid))
2272 and (!isset($redirect))
2273 and (!isset($printable))
2274 and (!$this->mRedirectedFrom
);
2278 * Loads cur_touched and returns a value indicating if it should be used
2281 function checkTouched() {
2282 $fname = 'Article::checkTouched';
2283 if( !$this->mDataLoaded
) {
2284 $dbr =& $this->getDB();
2285 $data = $this->pageDataFromId( $dbr, $this->getId() );
2287 $this->loadPageData( $data );
2290 return !$this->mIsRedirect
;
2294 * Edit an article without doing all that other stuff
2295 * The article must already exist; link tables etc
2296 * are not updated, caches are not flushed.
2298 * @param string $text text submitted
2299 * @param string $comment comment submitted
2300 * @param bool $minor whereas it's a minor modification
2302 function quickEdit( $text, $comment = '', $minor = 0 ) {
2303 $fname = 'Article::quickEdit';
2304 wfProfileIn( $fname );
2306 $dbw =& wfGetDB( DB_MASTER
);
2308 $revision = new Revision( array(
2309 'page' => $this->getId(),
2311 'comment' => $comment,
2312 'minor_edit' => $minor ?
1 : 0,
2314 $revisionId = $revision->insertOn( $dbw );
2315 $this->updateRevisionOn( $dbw, $revision );
2318 wfProfileOut( $fname );
2322 * Used to increment the view counter
2325 * @param integer $id article id
2327 function incViewCount( $id ) {
2328 $id = intval( $id );
2329 global $wgHitcounterUpdateFreq;
2331 $dbw =& wfGetDB( DB_MASTER
);
2332 $pageTable = $dbw->tableName( 'page' );
2333 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2334 $acchitsTable = $dbw->tableName( 'acchits' );
2336 if( $wgHitcounterUpdateFreq <= 1 ){ //
2337 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2341 # Not important enough to warrant an error page in case of failure
2342 $oldignore = $dbw->ignoreErrors( true );
2344 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2346 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2347 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2348 # Most of the time (or on SQL errors), skip row count check
2349 $dbw->ignoreErrors( $oldignore );
2353 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2354 $row = $dbw->fetchObject( $res );
2355 $rown = intval( $row->n
);
2356 if( $rown >= $wgHitcounterUpdateFreq ){
2357 wfProfileIn( 'Article::incViewCount-collect' );
2358 $old_user_abort = ignore_user_abort( true );
2360 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2361 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2362 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2364 $dbw->query("DELETE FROM $hitcounterTable");
2365 $dbw->query('UNLOCK TABLES');
2366 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2367 'WHERE page_id = hc_id');
2368 $dbw->query("DROP TABLE $acchitsTable");
2370 ignore_user_abort( $old_user_abort );
2371 wfProfileOut( 'Article::incViewCount-collect' );
2373 $dbw->ignoreErrors( $oldignore );
2377 * The onArticle*() functions are supposed to be a kind of hooks
2378 * which should be called whenever any of the specified actions
2381 * This is a good place to put code to clear caches, for instance.
2383 * This is called on page move and undelete, as well as edit
2385 * @param $title_obj a title object
2388 function onArticleCreate($title_obj) {
2389 global $wgUseSquid, $wgPostCommitUpdateList;
2391 $title_obj->touchLinks();
2392 $titles = $title_obj->getLinksTo();
2395 if ( $wgUseSquid ) {
2396 $urls = $title_obj->getSquidURLs();
2397 foreach ( $titles as $linkTitle ) {
2398 $urls[] = $linkTitle->getInternalURL();
2400 $u = new SquidUpdate( $urls );
2401 array_push( $wgPostCommitUpdateList, $u );
2405 function onArticleDelete( $title ) {
2406 global $wgMessageCache;
2408 $title->touchLinks();
2410 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2411 $wgMessageCache->replace( $title->getDBkey(), false );
2415 function onArticleEdit($title_obj) {
2416 // This would be an appropriate place to purge caches.
2417 // Why's this not in here now?
2423 * Info about this page
2424 * Called for ?action=info when $wgAllowPageInfo is on.
2429 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2430 $fname = 'Article::info';
2432 if ( !$wgAllowPageInfo ) {
2433 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2437 $page = $this->mTitle
->getSubjectPage();
2439 $wgOut->setPagetitle( $page->getPrefixedText() );
2440 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2442 # first, see if the page exists at all.
2443 $exists = $page->getArticleId() != 0;
2445 $wgOut->addHTML( wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2447 $dbr =& $this->getDB( DB_SLAVE
);
2449 'wl_title' => $page->getDBkey(),
2450 'wl_namespace' => $page->getNamespace() );
2451 $numwatchers = $dbr->selectField(
2456 $this->getSelectOptions() );
2458 $pageInfo = $this->pageCountInfo( $page );
2459 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2461 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2462 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2464 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2466 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2468 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2470 $wgOut->addHTML( '</ul>' );
2476 * Return the total number of edits and number of unique editors
2477 * on a given page. If page does not exist, returns false.
2479 * @param Title $title
2483 function pageCountInfo( $title ) {
2484 $id = $title->getArticleId();
2489 $dbr =& $this->getDB( DB_SLAVE
);
2491 $rev_clause = array( 'rev_page' => $id );
2492 $fname = 'Article::pageCountInfo';
2494 $edits = $dbr->selectField(
2499 $this->getSelectOptions() );
2501 $authors = $dbr->selectField(
2503 'COUNT(DISTINCT rev_user_text)',
2506 $this->getSelectOptions() );
2508 return array( 'edits' => $edits, 'authors' => $authors );
2512 * Return a list of templates used by this article.
2513 * Uses the links table to find the templates
2517 function getUsedTemplates() {
2519 $id = $this->mTitle
->getArticleID();
2521 $db =& wfGetDB( DB_SLAVE
);
2522 $res = $db->select( array( 'pagelinks' ),
2523 array( 'pl_title' ),
2526 'pl_namespace' => NS_TEMPLATE
),
2527 'Article:getUsedTemplates' );
2528 if ( false !== $res ) {
2529 if ( $db->numRows( $res ) ) {
2530 while ( $row = $db->fetchObject( $res ) ) {
2531 $result[] = $row->pl_title
;
2535 $db->freeResult( $res );