8 * Class for viewing MediaWiki article and history.
10 * This maintains WikiPage functions for backwards compatibility.
12 * @TODO: move and rewrite code to an Action class
14 * See design.txt for an overview.
15 * Note: edit user interface and cache support functions have been
16 * moved to separate EditPage and HTMLFileCache classes.
18 * @internal documentation reviewed 15 Mar 2010
20 class Article
extends Page
{
36 * @var ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
41 var $mContentLoaded = false; // !<
47 var $mRedirectedFrom = null;
50 * @var mixed: boolean false or URL string
52 var $mRedirectUrl = false; // !<
53 var $mRevIdFetched = 0; // !<
58 var $mRevision = null;
68 * Constructor and clear the article
69 * @param $title Title Reference to a Title object.
70 * @param $oldId Integer revision ID, null to fetch from request, zero for current
72 public function __construct( Title
$title, $oldId = null ) {
73 $this->mOldId
= $oldId;
74 $this->mPage
= $this->newPage( $title );
81 protected function newPage( Title
$title ) {
82 return new WikiPage( $title );
86 * Constructor from a page id
87 * @param $id Int article ID to load
88 * @return Article|null
90 public static function newFromID( $id ) {
91 $t = Title
::newFromID( $id );
92 # @todo FIXME: Doesn't inherit right
93 return $t == null ?
null : new self( $t );
94 # return $t == null ? null : new static( $t ); // PHP 5.3
98 * Create an Article object of the appropriate class for the given page.
100 * @param $title Title
101 * @param $context IContextSource
102 * @return Article object
104 public static function newFromTitle( $title, IContextSource
$context ) {
105 if ( NS_MEDIA
== $title->getNamespace() ) {
106 // FIXME: where should this go?
107 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
111 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
113 switch( $title->getNamespace() ) {
115 $page = new ImagePage( $title );
118 $page = new CategoryPage( $title );
121 $page = new Article( $title );
124 $page->setContext( $context );
130 * Create an Article object of the appropriate class for the given page.
132 * @param $page WikiPage
133 * @param $context IContextSource
134 * @return Article object
136 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
137 $article = self
::newFromTitle( $page->getTitle(), $context );
138 $article->mPage
= $page; // override to keep process cached vars
143 * Tell the page view functions that this view was redirected
144 * from another page on the wiki.
145 * @param $from Title object.
147 public function setRedirectedFrom( Title
$from ) {
148 $this->mRedirectedFrom
= $from;
152 * Get the title object of the article
153 * @return Title object of this page
155 public function getTitle() {
156 return $this->mPage
->getTitle();
162 public function clear() {
163 $this->mContentLoaded
= false;
165 $this->mRedirectedFrom
= null; # Title object if set
166 $this->mRevIdFetched
= 0;
167 $this->mRedirectUrl
= false;
169 $this->mPage
->clear();
173 * Note that getContent/loadContent do not follow redirects anymore.
174 * If you need to fetch redirectable content easily, try
175 * the shortcut in Article::followRedirect()
177 * This function has side effects! Do not use this function if you
178 * only want the real revision text if any.
180 * @return Return the text of this revision
182 public function getContent() {
185 wfProfileIn( __METHOD__
);
187 if ( $this->mPage
->getID() === 0 ) {
188 # If this is a MediaWiki:x message, then load the messages
189 # and return the message value for x.
190 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
191 $text = $this->getTitle()->getDefaultMessageText();
192 if ( $text === false ) {
196 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
198 wfProfileOut( __METHOD__
);
202 $this->fetchContent();
203 wfProfileOut( __METHOD__
);
205 return $this->mContent
;
210 * @return int The oldid of the article that is to be shown, 0 for the
213 public function getOldID() {
214 if ( is_null( $this->mOldId
) ) {
215 $this->mOldId
= $this->getOldIDFromRequest();
218 return $this->mOldId
;
222 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
224 * @return int The old id for the request
226 public function getOldIDFromRequest() {
229 $this->mRedirectUrl
= false;
231 $oldid = $wgRequest->getIntOrNull( 'oldid' );
233 if ( $oldid === null ) {
237 if ( $oldid !== 0 ) {
238 # Load the given revision and check whether the page is another one.
239 # In that case, update this instance to reflect the change.
240 $this->mRevision
= Revision
::newFromId( $oldid );
241 if ( $this->mRevision
!== null ) {
242 // Revision title doesn't match the page title given?
243 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
244 $function = array( get_class( $this->mPage
), 'newFromID' );
245 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
250 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
251 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
255 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
257 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
258 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
268 * Load the revision (including text) into this object
270 * @deprecated in 1.19; use fetchContent()
272 function loadContent() {
273 $this->fetchContent();
277 * Get text of an article from database
278 * Does *NOT* follow redirects.
280 * @return mixed string containing article contents, or false if null
282 function fetchContent() {
283 if ( $this->mContentLoaded
) {
284 return $this->mContent
;
287 wfProfileIn( __METHOD__
);
289 $this->mContentLoaded
= true;
291 $oldid = $this->getOldID();
293 # Pre-fill content with error message so that if something
294 # fails we'll have something telling us what we intended.
295 $t = $this->getTitle()->getPrefixedText();
296 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
297 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
300 # $this->mRevision might already be fetched by getOldIDFromRequest()
301 if ( !$this->mRevision
) {
302 $this->mRevision
= Revision
::newFromId( $oldid );
303 if ( !$this->mRevision
) {
304 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
305 wfProfileOut( __METHOD__
);
310 if ( !$this->mPage
->getLatest() ) {
311 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
312 wfProfileOut( __METHOD__
);
316 $this->mRevision
= $this->mPage
->getRevision();
317 if ( !$this->mRevision
) {
318 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
319 wfProfileOut( __METHOD__
);
324 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
325 // We should instead work with the Revision object when we need it...
326 $this->mContent
= $this->mRevision
->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
327 $this->mRevIdFetched
= $this->mRevision
->getId();
329 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
331 wfProfileOut( __METHOD__
);
333 return $this->mContent
;
338 * @deprecated since 1.18
340 public function forUpdate() {
341 wfDeprecated( __METHOD__
);
345 * Returns true if the currently-referenced revision is the current edit
346 * to this page (and it exists).
349 public function isCurrent() {
350 # If no oldid, this is the current version.
351 if ( $this->getOldID() == 0 ) {
355 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
359 * Use this to fetch the rev ID used on page views
361 * @return int revision ID of last article revision
363 public function getRevIdFetched() {
364 if ( $this->mRevIdFetched
) {
365 return $this->mRevIdFetched
;
367 return $this->mPage
->getLatest();
372 * This is the default action of the index.php entry point: just view the
373 * page of the given title.
375 public function view() {
376 global $wgUser, $wgOut, $wgRequest, $wgParser;
377 global $wgUseFileCache, $wgUseETag;
379 wfProfileIn( __METHOD__
);
381 # Get variables from query string
382 # As side effect this will load the revision and update the title
383 # in a revision ID is passed in the request, so this should remain
384 # the first call of this method even if $oldid is used way below.
385 $oldid = $this->getOldID();
387 # Another whitelist check in case getOldID() is altering the title
388 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
389 if ( count( $permErrors ) ) {
390 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
391 wfProfileOut( __METHOD__
);
392 throw new PermissionsError( 'read', $permErrors );
395 # getOldID() may as well want us to redirect somewhere else
396 if ( $this->mRedirectUrl
) {
397 $wgOut->redirect( $this->mRedirectUrl
);
398 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
399 wfProfileOut( __METHOD__
);
404 # If we got diff in the query, we want to see a diff page instead of the article.
405 if ( $wgRequest->getCheck( 'diff' ) ) {
406 wfDebug( __METHOD__
. ": showing diff page\n" );
407 $this->showDiffPage();
408 wfProfileOut( __METHOD__
);
413 # Set page title (may be overridden by DISPLAYTITLE)
414 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
416 $wgOut->setArticleFlag( true );
417 # Allow frames by default
418 $wgOut->allowClickjacking();
420 $parserCache = ParserCache
::singleton();
422 $parserOptions = $this->getParserOptions();
423 # Render printable version, use printable version cache
424 if ( $wgOut->isPrintable() ) {
425 $parserOptions->setIsPrintable( true );
426 $parserOptions->setEditSection( false );
427 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
428 $parserOptions->setEditSection( false );
431 # Try client and file cache
432 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
434 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
437 # Is it client cached?
438 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
439 wfDebug( __METHOD__
. ": done 304\n" );
440 wfProfileOut( __METHOD__
);
444 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
445 wfDebug( __METHOD__
. ": done file cache\n" );
446 # tell wgOut that output is taken care of
448 $this->mPage
->viewUpdates();
449 wfProfileOut( __METHOD__
);
455 # Should the parser cache be used?
456 $useParserCache = $this->mPage
->isParserCacheUsed( $wgUser, $oldid );
457 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
458 if ( $wgUser->getStubThreshold() ) {
459 wfIncrStats( 'pcache_miss_stub' );
462 $this->showRedirectedFromHeader();
463 $this->showNamespaceHeader();
465 # Iterate through the possible ways of constructing the output text.
466 # Keep going until $outputDone is set, or we run out of things to do.
469 $this->mParserOutput
= false;
471 while ( !$outputDone && ++
$pass ) {
474 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
477 # Early abort if the page doesn't exist
478 if ( !$this->mPage
->exists() ) {
479 wfDebug( __METHOD__
. ": showing missing article\n" );
480 $this->showMissingArticle();
481 wfProfileOut( __METHOD__
);
485 # Try the parser cache
486 if ( $useParserCache ) {
487 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
489 if ( $this->mParserOutput
!== false ) {
491 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
492 $this->setOldSubtitle( $oldid );
494 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
496 $wgOut->addParserOutput( $this->mParserOutput
);
497 # Ensure that UI elements requiring revision ID have
498 # the correct version information.
499 $wgOut->setRevisionId( $this->mPage
->getLatest() );
501 # Preload timestamp to avoid a DB hit
502 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
503 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
509 # This will set $this->mRevision if needed
510 $this->fetchContent();
512 # Are we looking at an old revision
513 if ( $oldid && $this->mRevision
) {
514 $this->setOldSubtitle( $oldid );
516 if ( !$this->showDeletedRevisionHeader() ) {
517 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
518 wfProfileOut( __METHOD__
);
523 # Ensure that UI elements requiring revision ID have
524 # the correct version information.
525 $wgOut->setRevisionId( $this->getRevIdFetched() );
527 # Pages containing custom CSS or JavaScript get special treatment
528 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
529 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
530 $this->showCssOrJsPage();
532 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
533 # Allow extensions do their own custom view for certain pages
536 $text = $this->getContent();
537 $rt = Title
::newFromRedirectArray( $text );
539 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
540 # Viewing a redirect page (e.g. with parameter redirect=no)
541 $wgOut->addHTML( $this->viewRedirect( $rt ) );
542 # Parse just to get categories, displaytitle, etc.
543 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
544 $wgOut->addParserOutputNoText( $this->mParserOutput
);
550 # Run the parse, protected by a pool counter
551 wfDebug( __METHOD__
. ": doing uncached parse\n" );
553 $key = $parserCache->getKey( $this, $parserOptions );
554 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
556 if ( !$poolArticleView->execute() ) {
557 # Connection or timeout error
558 wfProfileOut( __METHOD__
);
564 # Should be unreachable, but just in case...
570 # Get the ParserOutput actually *displayed* here.
571 # Note that $this->mParserOutput is the *current* version output.
572 $pOutput = ( $outputDone instanceof ParserOutput
)
573 ?
$outputDone // object fetched by hook
574 : $this->mParserOutput
;
576 # Adjust title for main page & pages with displaytitle
578 $this->adjustDisplayTitle( $pOutput );
581 # For the main page, overwrite the <title> element with the con-
582 # tents of 'pagetitle-view-mainpage' instead of the default (if
584 # This message always exists because it is in the i18n files
585 if ( $this->getTitle()->isMainPage() ) {
586 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
587 if ( !$msg->isDisabled() ) {
588 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
592 # Check for any __NOINDEX__ tags on the page using $pOutput
593 $policy = $this->getRobotPolicy( 'view', $pOutput );
594 $wgOut->setIndexPolicy( $policy['index'] );
595 $wgOut->setFollowPolicy( $policy['follow'] );
597 $this->showViewFooter();
598 $this->mPage
->viewUpdates();
600 wfProfileOut( __METHOD__
);
604 * Adjust title for pages with displaytitle, -{T|}- or language conversion
605 * @param $pOutput ParserOutput
607 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
609 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
610 $titleText = $pOutput->getTitleText();
611 if ( strval( $titleText ) !== '' ) {
612 $wgOut->setPageTitle( $titleText );
617 * Show a diff page according to current request variables. For use within
618 * Article::view() only, other callers should use the DifferenceEngine class.
620 public function showDiffPage() {
621 global $wgRequest, $wgUser;
623 $diff = $wgRequest->getVal( 'diff' );
624 $rcid = $wgRequest->getVal( 'rcid' );
625 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
626 $purge = $wgRequest->getVal( 'action' ) == 'purge';
627 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
628 $oldid = $this->getOldID();
630 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
631 // DifferenceEngine directly fetched the revision:
632 $this->mRevIdFetched
= $de->mNewid
;
633 $de->showDiffPage( $diffOnly );
635 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
636 # Run view updates for current revision only
637 $this->mPage
->viewUpdates();
642 * Show a page view for a page formatted as CSS or JavaScript. To be called by
643 * Article::view() only.
645 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
648 protected function showCssOrJsPage() {
651 $dir = $this->getContext()->getLang()->getDir();
652 $lang = $this->getContext()->getLang()->getCode();
654 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
657 // Give hooks a chance to customise the output
658 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
659 // Wrap the whole lot in a <pre> and don't parse
661 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
662 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
663 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
664 $wgOut->addHTML( "\n</pre>\n" );
669 * Get the robot policy to be used for the current view
670 * @param $action String the action= GET parameter
671 * @param $pOutput ParserOutput
672 * @return Array the policy that should be set
673 * TODO: actions other than 'view'
675 public function getRobotPolicy( $action, $pOutput ) {
676 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
677 global $wgDefaultRobotPolicy, $wgRequest;
679 $ns = $this->getTitle()->getNamespace();
681 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
682 # Don't index user and user talk pages for blocked users (bug 11443)
683 if ( !$this->getTitle()->isSubpage() ) {
684 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
686 'index' => 'noindex',
687 'follow' => 'nofollow'
693 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
694 # Non-articles (special pages etc), and old revisions
696 'index' => 'noindex',
697 'follow' => 'nofollow'
699 } elseif ( $wgOut->isPrintable() ) {
700 # Discourage indexing of printable versions, but encourage following
702 'index' => 'noindex',
705 } elseif ( $wgRequest->getInt( 'curid' ) ) {
706 # For ?curid=x urls, disallow indexing
708 'index' => 'noindex',
713 # Otherwise, construct the policy based on the various config variables.
714 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
716 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
717 # Honour customised robot policies for this namespace
718 $policy = array_merge(
720 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
723 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
724 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
725 # a final sanity check that we have really got the parser output.
726 $policy = array_merge(
728 array( 'index' => $pOutput->getIndexPolicy() )
732 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
733 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
734 $policy = array_merge(
736 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
744 * Converts a String robot policy into an associative array, to allow
745 * merging of several policies using array_merge().
746 * @param $policy Mixed, returns empty array on null/false/'', transparent
747 * to already-converted arrays, converts String.
748 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
750 public static function formatRobotPolicy( $policy ) {
751 if ( is_array( $policy ) ) {
753 } elseif ( !$policy ) {
757 $policy = explode( ',', $policy );
758 $policy = array_map( 'trim', $policy );
761 foreach ( $policy as $var ) {
762 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
763 $arr['index'] = $var;
764 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
765 $arr['follow'] = $var;
773 * If this request is a redirect view, send "redirected from" subtitle to
774 * $wgOut. Returns true if the header was needed, false if this is not a
775 * redirect view. Handles both local and remote redirects.
779 public function showRedirectedFromHeader() {
780 global $wgOut, $wgRequest, $wgRedirectSources;
782 $rdfrom = $wgRequest->getVal( 'rdfrom' );
784 if ( isset( $this->mRedirectedFrom
) ) {
785 // This is an internally redirected page view.
786 // We'll need a backlink to the source page for navigation.
787 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
788 $redir = Linker
::linkKnown(
789 $this->mRedirectedFrom
,
792 array( 'redirect' => 'no' )
795 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
797 // Set the fragment if one was specified in the redirect
798 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
799 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
800 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
803 // Add a <link rel="canonical"> tag
804 $wgOut->addLink( array( 'rel' => 'canonical',
805 'href' => $this->getTitle()->getLocalURL() )
810 } elseif ( $rdfrom ) {
811 // This is an externally redirected view, from some other wiki.
812 // If it was reported from a trusted site, supply a backlink.
813 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
814 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
815 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
825 * Show a header specific to the namespace currently being viewed, like
826 * [[MediaWiki:Talkpagetext]]. For Article::view().
828 public function showNamespaceHeader() {
831 if ( $this->getTitle()->isTalkPage() ) {
832 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
833 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
839 * Show the footer section of an ordinary page view
841 public function showViewFooter() {
842 global $wgOut, $wgUseTrackbacks;
844 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
845 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
846 $wgOut->addWikiMsg( 'anontalkpagetext' );
849 # If we have been passed an &rcid= parameter, we want to give the user a
850 # chance to mark this new article as patrolled.
851 $this->showPatrolFooter();
854 if ( $wgUseTrackbacks ) {
855 $this->addTrackbacks();
858 wfRunHooks( 'ArticleViewFooter', array( $this ) );
863 * If patrol is possible, output a patrol UI box. This is called from the
864 * footer section of ordinary page views. If patrol is not possible or not
865 * desired, does nothing.
867 public function showPatrolFooter() {
868 global $wgOut, $wgRequest, $wgUser;
870 $rcid = $wgRequest->getVal( 'rcid' );
872 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
876 $token = $wgUser->editToken( $rcid );
877 $wgOut->preventClickjacking();
880 "<div class='patrollink'>" .
882 'markaspatrolledlink',
885 wfMsgHtml( 'markaspatrolledtext' ),
888 'action' => 'markpatrolled',
892 array( 'known', 'noclasses' )
900 * Show the error text for a missing article. For articles in the MediaWiki
901 * namespace, show the default message text. To be called from Article::view().
903 public function showMissingArticle() {
904 global $wgOut, $wgRequest, $wgUser;
906 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
907 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
908 $parts = explode( '/', $this->getTitle()->getText() );
909 $rootPart = $parts[0];
910 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
911 $ip = User
::isIP( $rootPart );
913 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
914 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
915 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
916 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
917 LogEventsList
::showLogExtract(
920 $user->getUserPage()->getPrefixedText(),
924 'showIfEmpty' => false,
926 'blocked-notice-logextract',
927 $user->getName() # Support GENDER in notice
934 wfRunHooks( 'ShowMissingArticle', array( $this ) );
936 # Show delete and move logs
937 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
939 'conds' => array( "log_action != 'revision'" ),
940 'showIfEmpty' => false,
941 'msgKey' => array( 'moveddeleted-notice' ) )
945 $oldid = $this->getOldID();
947 $text = wfMsgNoTrans( 'missing-article',
948 $this->getTitle()->getPrefixedText(),
949 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
950 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
951 // Use the default message text
952 $text = $this->getTitle()->getDefaultMessageText();
954 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
955 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
956 $errors = array_merge( $createErrors, $editErrors );
958 if ( !count( $errors ) ) {
959 $text = wfMsgNoTrans( 'noarticletext' );
961 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
964 $text = "<div class='noarticletext'>\n$text\n</div>";
966 if ( !$this->mPage
->hasViewableContent() ) {
967 // If there's no backing content, send a 404 Not Found
968 // for better machine handling of broken links.
969 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
972 $wgOut->addWikiText( $text );
976 * If the revision requested for view is deleted, check permissions.
977 * Send either an error message or a warning header to $wgOut.
979 * @return boolean true if the view is allowed, false if not.
981 public function showDeletedRevisionHeader() {
982 global $wgOut, $wgRequest;
984 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
989 // If the user is not allowed to see it...
990 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
991 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
992 'rev-deleted-text-permission' );
995 // If the user needs to confirm that they want to see it...
996 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
997 # Give explanation and add a link to view the revision...
998 $oldid = intval( $this->getOldID() );
999 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1000 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1001 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1002 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1003 array( $msg, $link ) );
1006 // We are allowed to see...
1008 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1009 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1010 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1017 * Generate the navigation links when browsing through an article revisions
1018 * It shows the information as:
1019 * Revision as of \<date\>; view current revision
1020 * \<- Previous version | Next Version -\>
1022 * @param $oldid String: revision ID of this article revision
1024 public function setOldSubtitle( $oldid = 0 ) {
1025 global $wgLang, $wgOut, $wgUser, $wgRequest;
1027 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1031 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1033 # Cascade unhide param in links for easy deletion browsing
1034 $extraParams = array();
1035 if ( $wgRequest->getVal( 'unhide' ) ) {
1036 $extraParams['unhide'] = 1;
1039 $revision = Revision
::newFromId( $oldid );
1040 $timestamp = $revision->getTimestamp();
1042 $current = ( $oldid == $this->mPage
->getLatest() );
1043 $td = $wgLang->timeanddate( $timestamp, true );
1044 $tddate = $wgLang->date( $timestamp, true );
1045 $tdtime = $wgLang->time( $timestamp, true );
1047 # Show user links if allowed to see them. If hidden, then show them only if requested...
1048 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1050 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1051 ?
'revision-info-current'
1054 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1055 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1056 $tdtime, $revision->getUser() )->parse() . "</div>" );
1059 ?
wfMsgHtml( 'currentrevisionlink' )
1062 wfMsgHtml( 'currentrevisionlink' ),
1065 array( 'known', 'noclasses' )
1068 ?
wfMsgHtml( 'diff' )
1071 wfMsgHtml( 'diff' ),
1077 array( 'known', 'noclasses' )
1079 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1083 wfMsgHtml( 'previousrevision' ),
1086 'direction' => 'prev',
1089 array( 'known', 'noclasses' )
1091 : wfMsgHtml( 'previousrevision' );
1095 wfMsgHtml( 'diff' ),
1101 array( 'known', 'noclasses' )
1103 : wfMsgHtml( 'diff' );
1104 $nextlink = $current
1105 ?
wfMsgHtml( 'nextrevision' )
1108 wfMsgHtml( 'nextrevision' ),
1111 'direction' => 'next',
1114 array( 'known', 'noclasses' )
1116 $nextdiff = $current
1117 ?
wfMsgHtml( 'diff' )
1120 wfMsgHtml( 'diff' ),
1126 array( 'known', 'noclasses' )
1131 // User can delete revisions or view deleted revisions...
1132 $canHide = $wgUser->isAllowed( 'deleterevision' );
1133 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1134 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1135 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1138 'type' => 'revision',
1139 'target' => $this->getTitle()->getPrefixedDbkey(),
1142 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1147 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1148 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1149 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1153 * Execute the uncached parse for action=view
1156 public function doViewParse() {
1159 $oldid = $this->getOldID();
1160 $parserOptions = $this->getParserOptions();
1162 # Render printable version, use printable version cache
1163 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1165 # Don't show section-edit links on old revisions... this way lies madness.
1166 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1167 $parserOptions->setEditSection( false );
1170 $useParserCache = $this->useParserCache( $oldid );
1171 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1177 * Try to fetch an expired entry from the parser cache. If it is present,
1178 * output it and return true. If it is not present, output nothing and
1179 * return false. This is used as a callback function for
1180 * PoolCounter::executeProtected().
1184 public function tryDirtyCache() {
1186 $parserCache = ParserCache
::singleton();
1187 $options = $this->getParserOptions();
1189 if ( $wgOut->isPrintable() ) {
1190 $options->setIsPrintable( true );
1191 $options->setEditSection( false );
1194 $output = $parserCache->getDirty( $this, $options );
1197 wfDebug( __METHOD__
. ": sending dirty output\n" );
1198 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1199 $wgOut->setSquidMaxage( 0 );
1200 $this->mParserOutput
= $output;
1201 $wgOut->addParserOutput( $output );
1202 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1206 wfDebugLog( 'dirty', "dirty missing\n" );
1207 wfDebug( __METHOD__
. ": no dirty cache\n" );
1216 * @param $target Title|Array of destination(s) to redirect
1217 * @param $appendSubtitle Boolean [optional]
1218 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1219 * @return string containing HMTL with redirect link
1221 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1222 global $wgOut, $wgStylePath;
1224 if ( !is_array( $target ) ) {
1225 $target = array( $target );
1228 $lang = $this->getTitle()->getPageLanguage();
1229 $imageDir = $lang->getDir();
1231 if ( $appendSubtitle ) {
1232 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1235 // the loop prepends the arrow image before the link, so the first case needs to be outside
1240 $title = array_shift( $target );
1242 if ( $forceKnown ) {
1243 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1245 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1248 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1249 $alt = $lang->isRTL() ?
'←' : '→';
1250 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1251 foreach ( $target as $rt ) {
1252 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1253 if ( $forceKnown ) {
1254 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1256 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1260 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1261 return '<div class="redirectMsg">' .
1262 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1263 '<span class="redirectText">' . $link . '</span></div>';
1267 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1269 public function addTrackbacks() {
1272 $dbr = wfGetDB( DB_SLAVE
);
1273 $tbs = $dbr->select( 'trackbacks',
1274 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1275 array( 'tb_page' => $this->mPage
->getID() )
1278 if ( !$dbr->numRows( $tbs ) ) {
1282 $wgOut->preventClickjacking();
1285 foreach ( $tbs as $o ) {
1288 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1289 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1290 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1291 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1295 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1303 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1307 * Handle action=render
1309 public function render() {
1312 $wgOut->setArticleBodyOnly( true );
1317 * action=protect handler
1319 public function protect() {
1320 $form = new ProtectionForm( $this );
1325 * action=unprotect handler (alias)
1327 public function unprotect() {
1332 * UI entry point for page deletion
1334 public function delete() {
1335 global $wgOut, $wgRequest, $wgLang;
1337 # This code desperately needs to be totally rewritten
1339 $title = $this->getTitle();
1340 $user = $this->getContext()->getUser();
1343 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1344 if ( count( $permission_errors ) ) {
1345 throw new PermissionsError( 'delete', $permission_errors );
1348 # Read-only check...
1349 if ( wfReadOnly() ) {
1350 throw new ReadOnlyError
;
1353 # Better double-check that it hasn't been deleted yet!
1354 $dbw = wfGetDB( DB_MASTER
);
1355 $conds = $title->pageCond();
1356 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1357 if ( $latest === false ) {
1358 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1359 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1360 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1362 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1363 LogEventsList
::showLogExtract(
1366 $title->getPrefixedText()
1372 # Hack for big sites
1373 $bigHistory = $this->mPage
->isBigDeletion();
1374 if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
1375 global $wgDeleteRevisionsLimit;
1377 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1378 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1379 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1384 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1385 $deleteReason = $wgRequest->getText( 'wpReason' );
1387 if ( $deleteReasonList == 'other' ) {
1388 $reason = $deleteReason;
1389 } elseif ( $deleteReason != '' ) {
1390 // Entry from drop down menu + additional comment
1391 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1393 $reason = $deleteReasonList;
1396 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1397 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1399 # Flag to hide all contents of the archived revisions
1400 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1402 $this->doDelete( $reason, $suppress );
1404 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1406 } elseif ( $title->userIsWatching() ) {
1413 // Generate deletion reason
1414 $hasHistory = false;
1416 $reason = $this->generateReason( $hasHistory );
1419 // If the page has a history, insert a warning
1420 if ( $hasHistory ) {
1421 $revisions = $this->mPage
->estimateRevisionCount();
1422 // @todo FIXME: i18n issue/patchwork message
1423 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1424 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1425 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1426 wfMsgHtml( 'history' ),
1427 array( 'rel' => 'archives' ),
1428 array( 'action' => 'history' ) ) .
1432 if ( $bigHistory ) {
1433 global $wgDeleteRevisionsLimit;
1434 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1435 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1439 return $this->confirmDelete( $reason );
1443 * Output deletion confirmation dialog
1444 * @todo FIXME: Move to another file?
1445 * @param $reason String: prefilled reason
1447 public function confirmDelete( $reason ) {
1450 wfDebug( "Article::confirmDelete\n" );
1452 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1453 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1454 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1455 $wgOut->addWikiMsg( 'confirmdeletetext' );
1457 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1459 $user = $this->getContext()->getUser();
1461 if ( $user->isAllowed( 'suppressrevision' ) ) {
1462 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1464 <td class='mw-input'><strong>" .
1465 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1466 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1472 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1474 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1475 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1476 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1477 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1478 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1479 "<tr id=\"wpDeleteReasonListRow\">
1480 <td class='mw-label'>" .
1481 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1483 <td class='mw-input'>" .
1484 Xml
::listDropDown( 'wpDeleteReasonList',
1485 wfMsgForContent( 'deletereason-dropdown' ),
1486 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1489 <tr id=\"wpDeleteReasonRow\">
1490 <td class='mw-label'>" .
1491 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1493 <td class='mw-input'>" .
1494 Html
::input( 'wpReason', $reason, 'text', array(
1496 'maxlength' => '255',
1504 # Disallow watching if user is not logged in
1505 if ( $user->isLoggedIn() ) {
1509 <td class='mw-input'>" .
1510 Xml
::checkLabel( wfMsg( 'watchthis' ),
1511 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1520 <td class='mw-submit'>" .
1521 Xml
::submitButton( wfMsg( 'deletepage' ),
1522 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1525 Xml
::closeElement( 'table' ) .
1526 Xml
::closeElement( 'fieldset' ) .
1527 Html
::hidden( 'wpEditToken', $user->editToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1528 Xml
::closeElement( 'form' );
1530 if ( $user->isAllowed( 'editinterface' ) ) {
1531 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1532 $link = Linker
::link(
1534 wfMsgHtml( 'delete-edit-reasonlist' ),
1536 array( 'action' => 'edit' )
1538 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1541 $wgOut->addHTML( $form );
1542 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1543 LogEventsList
::showLogExtract( $wgOut, 'delete',
1544 $this->getTitle()->getPrefixedText()
1549 * Perform a deletion and output success or failure messages
1551 * @param $suppress bool
1553 public function doDelete( $reason, $suppress = false ) {
1556 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1559 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
1560 $deleted = $this->getTitle()->getPrefixedText();
1562 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1563 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1565 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1567 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1568 $wgOut->returnToMain( false );
1570 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1571 if ( $error == '' ) {
1572 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1573 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1575 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1577 LogEventsList
::showLogExtract(
1580 $this->getTitle()->getPrefixedText()
1583 $wgOut->addHTML( $error );
1588 /* Caching functions */
1591 * checkLastModified returns true if it has taken care of all
1592 * output to the client that is necessary for this request.
1593 * (that is, it has sent a cached version of the page)
1595 * @return boolean true if cached version send, false otherwise
1597 protected function tryFileCache() {
1598 static $called = false;
1601 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1606 if ( $this->isFileCacheable() ) {
1607 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1608 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1609 wfDebug( "Article::tryFileCache(): about to load file\n" );
1610 $cache->loadFromFileCache( $this->getContext() );
1613 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1614 ob_start( array( &$cache, 'saveToFileCache' ) );
1617 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1624 * Check if the page can be cached
1627 public function isFileCacheable() {
1630 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1631 $cacheable = $this->mPage
->getID()
1632 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1633 // Extension may have reason to disable file caching on some pages.
1635 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1645 * Add the primary page-view wikitext to the output buffer
1646 * Saves the text into the parser cache if possible.
1647 * Updates templatelinks if it is out of date.
1649 * @param $text String
1650 * @param $cache Boolean
1651 * @param $parserOptions mixed ParserOptions object, or boolean false
1653 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1656 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1658 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1660 $wgOut->addParserOutput( $this->mParserOutput
);
1664 * Lightweight method to get the parser output for a page, checking the parser cache
1665 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1666 * consider, so it's not appropriate to use there.
1668 * @since 1.16 (r52326) for LiquidThreads
1670 * @param $oldid mixed integer Revision ID or null
1671 * @param $user User The relevant user
1672 * @return ParserOutput or false if the given revsion ID is not found
1674 public function getParserOutput( $oldid = null, User
$user = null ) {
1675 global $wgEnableParserCache, $wgUser;
1676 $user = is_null( $user ) ?
$wgUser : $user;
1678 wfProfileIn( __METHOD__
);
1679 // Should the parser cache be used?
1680 $useParserCache = $wgEnableParserCache &&
1681 $user->getStubThreshold() == 0 &&
1682 $this->mPage
->exists() &&
1685 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1687 if ( $user->getStubThreshold() ) {
1688 wfIncrStats( 'pcache_miss_stub' );
1691 if ( $useParserCache ) {
1692 $options = $this->mPage
->makeParserOptions( $user );
1693 $parserOutput = ParserCache
::singleton()->get( $this, $options );
1694 if ( $parserOutput !== false ) {
1695 wfProfileOut( __METHOD__
);
1696 return $parserOutput;
1700 // Cache miss; parse and output it.
1701 if ( $oldid === null ) {
1702 $text = $this->mPage
->getRawText();
1704 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1705 if ( $rev === null ) {
1706 wfProfileOut( __METHOD__
);
1709 $text = $rev->getText();
1712 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1713 wfProfileOut( __METHOD__
);
1718 * This does all the heavy lifting for outputWikitext, except it returns the parser
1719 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1720 * say, embedding thread pages within a discussion system (LiquidThreads)
1722 * @param $text string
1723 * @param $cache boolean
1724 * @param $parserOptions parsing options, defaults to false
1725 * @return ParserOutput
1727 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1728 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1730 if ( !$parserOptions ) {
1731 $parserOptions = $this->getParserOptions();
1735 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1736 $parserOptions, true, true, $this->getRevIdFetched() );
1741 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1742 $this->getTitle()->getPrefixedDBkey() ) );
1745 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1746 $parserCache = ParserCache
::singleton();
1747 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1750 // Make sure file cache is not used on uncacheable content.
1751 // Output that has magic words in it can still use the parser cache
1752 // (if enabled), though it will generally expire sooner.
1753 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1754 $wgUseFileCache = false;
1757 if ( $this->isCurrent() ) {
1758 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1761 return $this->mParserOutput
;
1765 * Get parser options suitable for rendering the primary article wikitext
1766 * @return ParserOptions|false
1768 public function getParserOptions() {
1770 if ( !$this->mParserOptions
) {
1771 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1773 // Clone to allow modifications of the return value without affecting cache
1774 return clone $this->mParserOptions
;
1778 * Sets the context this Article is executed in
1780 * @param $context IContextSource
1783 public function setContext( $context ) {
1784 $this->mContext
= $context;
1788 * Gets the context this Article is executed in
1790 * @return IContextSource
1793 public function getContext() {
1794 if ( $this->mContext
instanceof IContextSource
) {
1795 return $this->mContext
;
1797 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1798 return RequestContext
::getMain();
1803 * Removes trackback record for current article from trackbacks table
1804 * @deprecated since 1.18
1806 public function deletetrackback() {
1807 return Action
::factory( 'deletetrackback', $this )->show();
1811 * Info about this page
1812 * @deprecated since 1.19
1814 public function info() {
1815 Action
::factory( 'info', $this )->show();
1819 * Mark this particular edit/page as patrolled
1820 * @deprecated since 1.18
1822 public function markpatrolled() {
1823 Action
::factory( 'markpatrolled', $this )->show();
1827 * Handle action=purge
1828 * @deprecated since 1.19
1830 public function purge() {
1831 return Action
::factory( 'purge', $this )->show();
1835 * Handle action=revert
1836 * @deprecated since 1.19
1838 public function revert() {
1839 Action
::factory( 'revert', $this )->show();
1843 * Handle action=rollback
1844 * @deprecated since 1.19
1846 public function rollback() {
1847 Action
::factory( 'rollback', $this )->show();
1851 * User-interface handler for the "watch" action.
1852 * Requires Request to pass a token as of 1.18.
1853 * @deprecated since 1.18
1855 public function watch() {
1856 Action
::factory( 'watch', $this )->show();
1860 * Add this page to $wgUser's watchlist
1862 * This is safe to be called multiple times
1864 * @return bool true on successful watch operation
1865 * @deprecated since 1.18
1867 public function doWatch() {
1869 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1873 * User interface handler for the "unwatch" action.
1874 * Requires Request to pass a token as of 1.18.
1875 * @deprecated since 1.18
1877 public function unwatch() {
1878 Action
::factory( 'unwatch', $this )->show();
1882 * Stop watching a page
1883 * @return bool true on successful unwatch
1884 * @deprecated since 1.18
1886 public function doUnwatch() {
1888 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1892 * Output a redirect back to the article.
1893 * This is typically used after an edit.
1895 * @deprecated in 1.18; call $wgOut->redirect() directly
1896 * @param $noRedir Boolean: add redirect=no
1897 * @param $sectionAnchor String: section to redirect to, including "#"
1898 * @param $extraQuery String: extra query params
1900 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1901 wfDeprecated( __METHOD__
);
1905 $query = 'redirect=no';
1907 $query .= "&$extraQuery";
1909 $query = $extraQuery;
1912 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1916 * Use PHP's magic __get handler to handle accessing of
1917 * raw WikiPage fields for backwards compatibility.
1919 * @param $fname String Field name
1921 public function __get( $fname ) {
1922 if ( property_exists( $this->mPage
, $fname ) ) {
1923 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1924 return $this->mPage
->$fname;
1926 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1930 * Use PHP's magic __set handler to handle setting of
1931 * raw WikiPage fields for backwards compatibility.
1933 * @param $fname String Field name
1934 * @param $fvalue mixed New value
1936 public function __set( $fname, $fvalue ) {
1937 if ( property_exists( $this->mPage
, $fname ) ) {
1938 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1939 $this->mPage
->$fname = $fvalue;
1940 // Note: extensions may want to toss on new fields
1941 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1942 $this->mPage
->$fname = $fvalue;
1944 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1949 * Use PHP's magic __call handler to transform instance calls to
1950 * WikiPage functions for backwards compatibility.
1952 * @param $fname String Name of called method
1953 * @param $args Array Arguments to the method
1955 public function __call( $fname, $args ) {
1956 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1957 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1958 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1960 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1963 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1966 * @param $limit array
1967 * @param $reason string
1968 * @param $cascade int
1969 * @param $expiry array
1972 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1973 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1977 * @param $reason string
1978 * @param $suppress bool
1980 * @param $commit bool
1981 * @param $error string
1984 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1985 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1993 * @param $resultDetails
1997 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1999 $user = is_null( $user ) ?
$wgUser : $user;
2000 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2007 * @param $resultDetails
2008 * @param $guser User
2011 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2013 $guser = is_null( $guser ) ?
$wgUser : $guser;
2014 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2018 * @param $hasHistory bool
2021 public function generateReason( &$hasHistory ) {
2022 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2025 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2030 public static function selectFields() {
2031 return WikiPage
::selectFields();
2035 * @param $title Title
2037 public static function onArticleCreate( $title ) {
2038 WikiPage
::onArticleCreate( $title );
2042 * @param $title Title
2044 public static function onArticleDelete( $title ) {
2045 WikiPage
::onArticleDelete( $title );
2049 * @param $title Title
2051 public static function onArticleEdit( $title ) {
2052 WikiPage
::onArticleEdit( $title );
2061 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2062 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2067 class PoolWorkArticleView
extends PoolCounterWork
{
2074 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2075 parent
::__construct( 'ArticleView', $key );
2076 $this->mArticle
= $article;
2077 $this->cacheable
= $useParserCache;
2078 $this->parserOptions
= $parserOptions;
2085 return $this->mArticle
->doViewParse();
2091 function getCachedWork() {
2094 $parserCache = ParserCache
::singleton();
2095 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2097 if ( $this->mArticle
->mParserOutput
!== false ) {
2098 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2099 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2100 # Ensure that UI elements requiring revision ID have
2101 # the correct version information.
2102 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2111 function fallback() {
2112 return $this->mArticle
->tryDirtyCache();
2116 * @param $status Status
2118 function error( $status ) {
2121 $wgOut->clearHTML(); // for release() errors
2122 $wgOut->enableClientCache( false );
2123 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2125 $errortext = $status->getWikiText( false, 'view-pool-error' );
2126 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );