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 * Tell the page view functions that this view was redirected
131 * from another page on the wiki.
132 * @param $from Title object.
134 public function setRedirectedFrom( Title
$from ) {
135 $this->mRedirectedFrom
= $from;
139 * Get the title object of the article
140 * @return Title object of this page
142 public function getTitle() {
143 return $this->mPage
->getTitle();
149 public function clear() {
150 $this->mContentLoaded
= false;
152 $this->mRedirectedFrom
= null; # Title object if set
153 $this->mRevIdFetched
= 0;
154 $this->mRedirectUrl
= false;
156 $this->mPage
->clear();
160 * Note that getContent/loadContent do not follow redirects anymore.
161 * If you need to fetch redirectable content easily, try
162 * the shortcut in Article::followRedirect()
164 * This function has side effects! Do not use this function if you
165 * only want the real revision text if any.
167 * @return Return the text of this revision
169 public function getContent() {
172 wfProfileIn( __METHOD__
);
174 if ( $this->mPage
->getID() === 0 ) {
175 # If this is a MediaWiki:x message, then load the messages
176 # and return the message value for x.
177 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
178 $text = $this->getTitle()->getDefaultMessageText();
179 if ( $text === false ) {
183 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
185 wfProfileOut( __METHOD__
);
189 $this->loadContent();
190 wfProfileOut( __METHOD__
);
192 return $this->mContent
;
197 * @return int The oldid of the article that is to be shown, 0 for the
200 public function getOldID() {
201 if ( is_null( $this->mOldId
) ) {
202 $this->mOldId
= $this->getOldIDFromRequest();
205 return $this->mOldId
;
209 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
211 * @return int The old id for the request
213 public function getOldIDFromRequest() {
216 $this->mRedirectUrl
= false;
218 $oldid = $wgRequest->getVal( 'oldid' );
220 if ( isset( $oldid ) ) {
221 $oldid = intval( $oldid );
222 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
223 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
227 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
229 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
230 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
245 * Load the revision (including text) into this object
247 function loadContent() {
248 if ( $this->mContentLoaded
) {
252 wfProfileIn( __METHOD__
);
254 $this->fetchContent( $this->getOldID() );
256 wfProfileOut( __METHOD__
);
260 * Get text of an article from database
261 * Does *NOT* follow redirects.
263 * @param $oldid Int: 0 for whatever the latest revision is
264 * @return mixed string containing article contents, or false if null
266 function fetchContent( $oldid = 0 ) {
267 if ( $this->mContentLoaded
) {
268 return $this->mContent
;
271 # Pre-fill content with error message so that if something
272 # fails we'll have something telling us what we intended.
273 $t = $this->getTitle()->getPrefixedText();
274 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
275 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
278 $revision = Revision
::newFromId( $oldid );
280 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
283 // Revision title doesn't match the page title given?
284 if ( $this->mPage
->getID() != $revision->getPage() ) {
285 $function = array( get_class( $this->mPage
), 'newFromID' );
286 $this->mPage
= call_user_func( $function, $revision->getPage() );
287 if ( !$this->mPage
->getId() ) {
288 wfDebug( __METHOD__
. " failed to get page data linked to revision id $oldid\n" );
293 if ( !$this->mPage
->getLatest() ) {
294 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
298 $revision = $this->mPage
->getRevision();
300 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
305 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
306 // We should instead work with the Revision object when we need it...
307 $this->mContent
= $revision->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
309 $this->mRevIdFetched
= $revision->getId();
310 $this->mContentLoaded
= true;
311 $this->mRevision
=& $revision;
313 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
315 return $this->mContent
;
320 * @deprecated since 1.18
322 public function forUpdate() {
323 wfDeprecated( __METHOD__
);
327 * Returns true if the currently-referenced revision is the current edit
328 * to this page (and it exists).
331 public function isCurrent() {
332 # If no oldid, this is the current version.
333 if ( $this->getOldID() == 0 ) {
337 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
341 * Use this to fetch the rev ID used on page views
343 * @return int revision ID of last article revision
345 public function getRevIdFetched() {
346 if ( $this->mRevIdFetched
) {
347 return $this->mRevIdFetched
;
349 return $this->mPage
->getLatest();
354 * This is the default action of the index.php entry point: just view the
355 * page of the given title.
357 public function view() {
358 global $wgUser, $wgOut, $wgRequest, $wgParser;
359 global $wgUseFileCache, $wgUseETag;
361 wfProfileIn( __METHOD__
);
363 # Get variables from query string
364 $oldid = $this->getOldID();
366 # getOldID may want us to redirect somewhere else
367 if ( $this->mRedirectUrl
) {
368 $wgOut->redirect( $this->mRedirectUrl
);
369 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
370 wfProfileOut( __METHOD__
);
375 # Set page title (may be overridden by DISPLAYTITLE)
376 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
378 # If we got diff in the query, we want to see a diff page instead of the article.
379 if ( $wgRequest->getCheck( 'diff' ) ) {
380 wfDebug( __METHOD__
. ": showing diff page\n" );
381 $this->showDiffPage();
382 wfProfileOut( __METHOD__
);
387 $wgOut->setArticleFlag( true );
388 # Allow frames by default
389 $wgOut->allowClickjacking();
391 $parserCache = ParserCache
::singleton();
393 $parserOptions = $this->getParserOptions();
394 # Render printable version, use printable version cache
395 if ( $wgOut->isPrintable() ) {
396 $parserOptions->setIsPrintable( true );
397 $parserOptions->setEditSection( false );
398 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
399 $parserOptions->setEditSection( false );
402 # Try client and file cache
403 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
405 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
408 # Is it client cached?
409 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
410 wfDebug( __METHOD__
. ": done 304\n" );
411 wfProfileOut( __METHOD__
);
415 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
416 wfDebug( __METHOD__
. ": done file cache\n" );
417 # tell wgOut that output is taken care of
419 $this->mPage
->viewUpdates();
420 wfProfileOut( __METHOD__
);
426 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
427 $parserOptions->setEditSection( false );
430 # Should the parser cache be used?
431 $useParserCache = $this->useParserCache( $oldid );
432 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
433 if ( $wgUser->getStubThreshold() ) {
434 wfIncrStats( 'pcache_miss_stub' );
437 $wasRedirected = $this->showRedirectedFromHeader();
438 $this->showNamespaceHeader();
440 # Iterate through the possible ways of constructing the output text.
441 # Keep going until $outputDone is set, or we run out of things to do.
444 $this->mParserOutput
= false;
446 while ( !$outputDone && ++
$pass ) {
449 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
452 # Try the parser cache
453 if ( $useParserCache ) {
454 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
456 if ( $this->mParserOutput
!== false ) {
457 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
458 $wgOut->addParserOutput( $this->mParserOutput
);
459 # Ensure that UI elements requiring revision ID have
460 # the correct version information.
461 $wgOut->setRevisionId( $this->mPage
->getLatest() );
463 # Preload timestamp to avoid a DB hit
464 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
465 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
471 $text = $this->getContent();
472 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
473 wfDebug( __METHOD__
. ": showing missing article\n" );
474 $this->showMissingArticle();
475 wfProfileOut( __METHOD__
);
479 # Another whitelist check in case oldid is altering the title
480 if ( !$this->getTitle()->userCanRead() ) {
481 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
482 $wgOut->loginToUse();
485 wfProfileOut( __METHOD__
);
489 # Are we looking at an old revision
490 if ( $oldid && !is_null( $this->mRevision
) ) {
491 $this->setOldSubtitle( $oldid );
493 if ( !$this->showDeletedRevisionHeader() ) {
494 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
495 wfProfileOut( __METHOD__
);
499 # If this "old" version is the current, then try the parser cache...
500 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
501 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
502 if ( $this->mParserOutput
) {
503 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
504 $wgOut->addParserOutput( $this->mParserOutput
);
505 $wgOut->setRevisionId( $this->mPage
->getLatest() );
512 # Ensure that UI elements requiring revision ID have
513 # the correct version information.
514 $wgOut->setRevisionId( $this->getRevIdFetched() );
516 # Pages containing custom CSS or JavaScript get special treatment
517 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
518 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
519 $this->showCssOrJsPage();
521 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
522 # Allow extensions do their own custom view for certain pages
525 $rt = Title
::newFromRedirectArray( $text );
527 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
528 # Viewing a redirect page (e.g. with parameter redirect=no)
529 # Don't append the subtitle if this was an old revision
530 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
531 # Parse just to get categories, displaytitle, etc.
532 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
533 $wgOut->addParserOutputNoText( $this->mParserOutput
);
539 # Run the parse, protected by a pool counter
540 wfDebug( __METHOD__
. ": doing uncached parse\n" );
542 $key = $parserCache->getKey( $this, $parserOptions );
543 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
545 if ( !$poolArticleView->execute() ) {
546 # Connection or timeout error
547 wfProfileOut( __METHOD__
);
553 # Should be unreachable, but just in case...
559 # Get the ParserOutput actually *displayed* here.
560 # Note that $this->mParserOutput is the *current* version output.
561 $pOutput = ( $outputDone instanceof ParserOutput
)
562 ?
$outputDone // object fetched by hook
563 : $this->mParserOutput
;
565 # Adjust title for main page & pages with displaytitle
567 $this->adjustDisplayTitle( $pOutput );
570 # For the main page, overwrite the <title> element with the con-
571 # tents of 'pagetitle-view-mainpage' instead of the default (if
573 # This message always exists because it is in the i18n files
574 if ( $this->getTitle()->isMainPage() ) {
575 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
576 if ( !$msg->isDisabled() ) {
577 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
581 # Check for any __NOINDEX__ tags on the page using $pOutput
582 $policy = $this->getRobotPolicy( 'view', $pOutput );
583 $wgOut->setIndexPolicy( $policy['index'] );
584 $wgOut->setFollowPolicy( $policy['follow'] );
586 $this->showViewFooter();
587 $this->mPage
->viewUpdates();
589 wfProfileOut( __METHOD__
);
593 * Adjust title for pages with displaytitle, -{T|}- or language conversion
594 * @param $pOutput ParserOutput
596 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
598 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
599 $titleText = $pOutput->getTitleText();
600 if ( strval( $titleText ) !== '' ) {
601 $wgOut->setPageTitle( $titleText );
606 * Show a diff page according to current request variables. For use within
607 * Article::view() only, other callers should use the DifferenceEngine class.
609 public function showDiffPage() {
610 global $wgRequest, $wgUser;
612 $diff = $wgRequest->getVal( 'diff' );
613 $rcid = $wgRequest->getVal( 'rcid' );
614 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
615 $purge = $wgRequest->getVal( 'action' ) == 'purge';
616 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
617 $oldid = $this->getOldID();
619 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
620 // DifferenceEngine directly fetched the revision:
621 $this->mRevIdFetched
= $de->mNewid
;
622 $de->showDiffPage( $diffOnly );
624 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
625 # Run view updates for current revision only
626 $this->mPage
->viewUpdates();
631 * Show a page view for a page formatted as CSS or JavaScript. To be called by
632 * Article::view() only.
634 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
637 protected function showCssOrJsPage() {
640 $dir = $this->getContext()->getLang()->getDir();
641 $lang = $this->getContext()->getLang()->getCode();
643 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
646 // Give hooks a chance to customise the output
647 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
648 // Wrap the whole lot in a <pre> and don't parse
650 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
651 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
652 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
653 $wgOut->addHTML( "\n</pre>\n" );
658 * Get the robot policy to be used for the current view
659 * @param $action String the action= GET parameter
660 * @param $pOutput ParserOutput
661 * @return Array the policy that should be set
662 * TODO: actions other than 'view'
664 public function getRobotPolicy( $action, $pOutput ) {
665 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
666 global $wgDefaultRobotPolicy, $wgRequest;
668 $ns = $this->getTitle()->getNamespace();
670 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
671 # Don't index user and user talk pages for blocked users (bug 11443)
672 if ( !$this->getTitle()->isSubpage() ) {
673 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
675 'index' => 'noindex',
676 'follow' => 'nofollow'
682 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
683 # Non-articles (special pages etc), and old revisions
685 'index' => 'noindex',
686 'follow' => 'nofollow'
688 } elseif ( $wgOut->isPrintable() ) {
689 # Discourage indexing of printable versions, but encourage following
691 'index' => 'noindex',
694 } elseif ( $wgRequest->getInt( 'curid' ) ) {
695 # For ?curid=x urls, disallow indexing
697 'index' => 'noindex',
702 # Otherwise, construct the policy based on the various config variables.
703 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
705 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
706 # Honour customised robot policies for this namespace
707 $policy = array_merge(
709 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
712 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
713 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
714 # a final sanity check that we have really got the parser output.
715 $policy = array_merge(
717 array( 'index' => $pOutput->getIndexPolicy() )
721 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
722 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
723 $policy = array_merge(
725 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
733 * Converts a String robot policy into an associative array, to allow
734 * merging of several policies using array_merge().
735 * @param $policy Mixed, returns empty array on null/false/'', transparent
736 * to already-converted arrays, converts String.
737 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
739 public static function formatRobotPolicy( $policy ) {
740 if ( is_array( $policy ) ) {
742 } elseif ( !$policy ) {
746 $policy = explode( ',', $policy );
747 $policy = array_map( 'trim', $policy );
750 foreach ( $policy as $var ) {
751 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
752 $arr['index'] = $var;
753 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
754 $arr['follow'] = $var;
762 * If this request is a redirect view, send "redirected from" subtitle to
763 * $wgOut. Returns true if the header was needed, false if this is not a
764 * redirect view. Handles both local and remote redirects.
768 public function showRedirectedFromHeader() {
769 global $wgOut, $wgRequest, $wgRedirectSources;
771 $rdfrom = $wgRequest->getVal( 'rdfrom' );
773 if ( isset( $this->mRedirectedFrom
) ) {
774 // This is an internally redirected page view.
775 // We'll need a backlink to the source page for navigation.
776 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
777 $redir = Linker
::link(
778 $this->mRedirectedFrom
,
781 array( 'redirect' => 'no' ),
782 array( 'known', 'noclasses' )
785 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
786 $wgOut->setSubtitle( $s );
788 // Set the fragment if one was specified in the redirect
789 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
790 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
791 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
794 // Add a <link rel="canonical"> tag
795 $wgOut->addLink( array( 'rel' => 'canonical',
796 'href' => $this->getTitle()->getLocalURL() )
801 } elseif ( $rdfrom ) {
802 // This is an externally redirected view, from some other wiki.
803 // If it was reported from a trusted site, supply a backlink.
804 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
805 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
806 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
807 $wgOut->setSubtitle( $s );
817 * Show a header specific to the namespace currently being viewed, like
818 * [[MediaWiki:Talkpagetext]]. For Article::view().
820 public function showNamespaceHeader() {
823 if ( $this->getTitle()->isTalkPage() ) {
824 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
825 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
831 * Show the footer section of an ordinary page view
833 public function showViewFooter() {
834 global $wgOut, $wgUseTrackbacks;
836 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
837 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
838 $wgOut->addWikiMsg( 'anontalkpagetext' );
841 # If we have been passed an &rcid= parameter, we want to give the user a
842 # chance to mark this new article as patrolled.
843 $this->showPatrolFooter();
846 if ( $wgUseTrackbacks ) {
847 $this->addTrackbacks();
850 wfRunHooks( 'ArticleViewFooter', array( $this ) );
855 * If patrol is possible, output a patrol UI box. This is called from the
856 * footer section of ordinary page views. If patrol is not possible or not
857 * desired, does nothing.
859 public function showPatrolFooter() {
860 global $wgOut, $wgRequest, $wgUser;
862 $rcid = $wgRequest->getVal( 'rcid' );
864 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
868 $token = $wgUser->editToken( $rcid );
869 $wgOut->preventClickjacking();
872 "<div class='patrollink'>" .
874 'markaspatrolledlink',
877 wfMsgHtml( 'markaspatrolledtext' ),
880 'action' => 'markpatrolled',
884 array( 'known', 'noclasses' )
892 * Show the error text for a missing article. For articles in the MediaWiki
893 * namespace, show the default message text. To be called from Article::view().
895 public function showMissingArticle() {
896 global $wgOut, $wgRequest, $wgUser;
898 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
899 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
900 $parts = explode( '/', $this->getTitle()->getText() );
901 $rootPart = $parts[0];
902 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
903 $ip = User
::isIP( $rootPart );
905 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
906 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
907 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
908 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
909 LogEventsList
::showLogExtract(
912 $user->getUserPage()->getPrefixedText(),
916 'showIfEmpty' => false,
918 'blocked-notice-logextract',
919 $user->getName() # Support GENDER in notice
926 wfRunHooks( 'ShowMissingArticle', array( $this ) );
928 # Show delete and move logs
929 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
931 'conds' => array( "log_action != 'revision'" ),
932 'showIfEmpty' => false,
933 'msgKey' => array( 'moveddeleted-notice' ) )
937 $oldid = $this->getOldID();
939 $text = wfMsgNoTrans( 'missing-article',
940 $this->getTitle()->getPrefixedText(),
941 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
942 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
943 // Use the default message text
944 $text = $this->getTitle()->getDefaultMessageText();
946 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
947 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
948 $errors = array_merge( $createErrors, $editErrors );
950 if ( !count( $errors ) ) {
951 $text = wfMsgNoTrans( 'noarticletext' );
953 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
956 $text = "<div class='noarticletext'>\n$text\n</div>";
958 if ( !$this->mPage
->hasViewableContent() ) {
959 // If there's no backing content, send a 404 Not Found
960 // for better machine handling of broken links.
961 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
964 $wgOut->addWikiText( $text );
968 * If the revision requested for view is deleted, check permissions.
969 * Send either an error message or a warning header to $wgOut.
971 * @return boolean true if the view is allowed, false if not.
973 public function showDeletedRevisionHeader() {
974 global $wgOut, $wgRequest;
976 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
981 // If the user is not allowed to see it...
982 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
983 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
984 'rev-deleted-text-permission' );
987 // If the user needs to confirm that they want to see it...
988 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
989 # Give explanation and add a link to view the revision...
990 $oldid = intval( $this->getOldID() );
991 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
992 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
993 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
994 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
995 array( $msg, $link ) );
998 // We are allowed to see...
1000 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1001 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1002 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1009 * Execute the uncached parse for action=view
1012 public function doViewParse() {
1015 $oldid = $this->getOldID();
1016 $parserOptions = $this->getParserOptions();
1018 # Render printable version, use printable version cache
1019 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1021 # Don't show section-edit links on old revisions... this way lies madness.
1022 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1023 $parserOptions->setEditSection( false );
1026 $useParserCache = $this->useParserCache( $oldid );
1027 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1033 * Try to fetch an expired entry from the parser cache. If it is present,
1034 * output it and return true. If it is not present, output nothing and
1035 * return false. This is used as a callback function for
1036 * PoolCounter::executeProtected().
1040 public function tryDirtyCache() {
1042 $parserCache = ParserCache
::singleton();
1043 $options = $this->getParserOptions();
1045 if ( $wgOut->isPrintable() ) {
1046 $options->setIsPrintable( true );
1047 $options->setEditSection( false );
1050 $output = $parserCache->getDirty( $this, $options );
1053 wfDebug( __METHOD__
. ": sending dirty output\n" );
1054 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1055 $wgOut->setSquidMaxage( 0 );
1056 $this->mParserOutput
= $output;
1057 $wgOut->addParserOutput( $output );
1058 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1062 wfDebugLog( 'dirty', "dirty missing\n" );
1063 wfDebug( __METHOD__
. ": no dirty cache\n" );
1072 * @param $target Title|Array of destination(s) to redirect
1073 * @param $appendSubtitle Boolean [optional]
1074 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1075 * @return string containing HMTL with redirect link
1077 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1078 global $wgOut, $wgStylePath;
1080 if ( !is_array( $target ) ) {
1081 $target = array( $target );
1084 $lang = $this->getTitle()->getPageLanguage();
1085 $imageDir = $lang->getDir();
1087 if ( $appendSubtitle ) {
1088 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1091 // the loop prepends the arrow image before the link, so the first case needs to be outside
1096 $title = array_shift( $target );
1098 if ( $forceKnown ) {
1099 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1101 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1104 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1105 $alt = $lang->isRTL() ?
'←' : '→';
1106 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1107 foreach ( $target as $rt ) {
1108 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1109 if ( $forceKnown ) {
1110 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1112 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1116 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1117 return '<div class="redirectMsg">' .
1118 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1119 '<span class="redirectText">' . $link . '</span></div>';
1123 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1125 public function addTrackbacks() {
1128 $dbr = wfGetDB( DB_SLAVE
);
1129 $tbs = $dbr->select( 'trackbacks',
1130 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1131 array( 'tb_page' => $this->mPage
->getID() )
1134 if ( !$dbr->numRows( $tbs ) ) {
1138 $wgOut->preventClickjacking();
1141 foreach ( $tbs as $o ) {
1144 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1145 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1146 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1147 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1151 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1159 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1163 * Removes trackback record for current article from trackbacks table
1164 * @deprecated since 1.18
1166 public function deletetrackback() {
1167 return Action
::factory( 'deletetrackback', $this )->show();
1171 * Handle action=render
1174 public function render() {
1177 $wgOut->setArticleBodyOnly( true );
1182 * Handle action=purge
1184 public function purge() {
1185 return Action
::factory( 'purge', $this )->show();
1189 * Mark this particular edit/page as patrolled
1190 * @deprecated since 1.18
1192 public function markpatrolled() {
1193 Action
::factory( 'markpatrolled', $this )->show();
1197 * User-interface handler for the "watch" action.
1198 * Requires Request to pass a token as of 1.18.
1199 * @deprecated since 1.18
1201 public function watch() {
1202 Action
::factory( 'watch', $this )->show();
1206 * Add this page to $wgUser's watchlist
1208 * This is safe to be called multiple times
1210 * @return bool true on successful watch operation
1211 * @deprecated since 1.18
1213 public function doWatch() {
1215 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1219 * User interface handler for the "unwatch" action.
1220 * Requires Request to pass a token as of 1.18.
1221 * @deprecated since 1.18
1223 public function unwatch() {
1224 Action
::factory( 'unwatch', $this )->show();
1228 * Stop watching a page
1229 * @return bool true on successful unwatch
1230 * @deprecated since 1.18
1232 public function doUnwatch() {
1234 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1238 * action=protect handler
1240 public function protect() {
1241 $form = new ProtectionForm( $this );
1246 * action=unprotect handler (alias)
1248 public function unprotect() {
1253 * Info about this page
1254 * Called for ?action=info when $wgAllowPageInfo is on.
1256 public function info() {
1257 Action
::factory( 'info', $this )->show();
1261 * Overriden by ImagePage class, only present here to avoid a fatal error
1262 * Called for ?action=revert
1264 public function revert() {
1265 Action
::factory( 'revert', $this )->show();
1269 * User interface for rollback operations
1271 public function rollback() {
1272 Action
::factory( 'rollback', $this )->show();
1276 * Output a redirect back to the article.
1277 * This is typically used after an edit.
1279 * @deprecated in 1.18; call $wgOut->redirect() directly
1280 * @param $noRedir Boolean: add redirect=no
1281 * @param $sectionAnchor String: section to redirect to, including "#"
1282 * @param $extraQuery String: extra query params
1284 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1285 wfDeprecated( __METHOD__
);
1289 $query = 'redirect=no';
1291 $query .= "&$extraQuery";
1293 $query = $extraQuery;
1296 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1300 * UI entry point for page deletion
1302 public function delete() {
1303 global $wgOut, $wgRequest, $wgLang;
1305 # This code desperately needs to be totally rewritten
1307 $title = $this->getTitle();
1308 $user = $this->getContext()->getUser();
1311 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1312 if ( count( $permission_errors ) ) {
1313 throw new PermissionsError( 'delete', $permission_errors );
1316 # Read-only check...
1317 if ( wfReadOnly() ) {
1318 throw new ReadOnlyError
;
1321 # Better double-check that it hasn't been deleted yet!
1322 $dbw = wfGetDB( DB_MASTER
);
1323 $conds = $title->pageCond();
1324 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1325 if ( $latest === false ) {
1326 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1327 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1328 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1330 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1331 LogEventsList
::showLogExtract(
1334 $title->getPrefixedText()
1340 # Hack for big sites
1341 $bigHistory = $this->mPage
->isBigDeletion();
1342 if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
1343 global $wgDeleteRevisionsLimit;
1345 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1346 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1347 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1352 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1353 $deleteReason = $wgRequest->getText( 'wpReason' );
1355 if ( $deleteReasonList == 'other' ) {
1356 $reason = $deleteReason;
1357 } elseif ( $deleteReason != '' ) {
1358 // Entry from drop down menu + additional comment
1359 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1361 $reason = $deleteReasonList;
1364 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1365 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1367 # Flag to hide all contents of the archived revisions
1368 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1370 $this->doDelete( $reason, $suppress );
1372 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1374 } elseif ( $title->userIsWatching() ) {
1381 // Generate deletion reason
1382 $hasHistory = false;
1384 $reason = $this->generateReason( $hasHistory );
1387 // If the page has a history, insert a warning
1388 if ( $hasHistory ) {
1389 $revisions = $this->mPage
->estimateRevisionCount();
1390 // @todo FIXME: i18n issue/patchwork message
1391 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1392 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1393 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1394 wfMsgHtml( 'history' ),
1395 array( 'rel' => 'archives' ),
1396 array( 'action' => 'history' ) ) .
1400 if ( $bigHistory ) {
1401 global $wgDeleteRevisionsLimit;
1402 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1403 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1407 return $this->confirmDelete( $reason );
1411 * Output deletion confirmation dialog
1412 * @todo FIXME: Move to another file?
1413 * @param $reason String: prefilled reason
1415 public function confirmDelete( $reason ) {
1418 wfDebug( "Article::confirmDelete\n" );
1420 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1421 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1422 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1423 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1424 $wgOut->addWikiMsg( 'confirmdeletetext' );
1426 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1428 $user = $this->getContext()->getUser();
1430 if ( $user->isAllowed( 'suppressrevision' ) ) {
1431 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1433 <td class='mw-input'><strong>" .
1434 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1435 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1441 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1443 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1444 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1445 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1446 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1447 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1448 "<tr id=\"wpDeleteReasonListRow\">
1449 <td class='mw-label'>" .
1450 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1452 <td class='mw-input'>" .
1453 Xml
::listDropDown( 'wpDeleteReasonList',
1454 wfMsgForContent( 'deletereason-dropdown' ),
1455 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1458 <tr id=\"wpDeleteReasonRow\">
1459 <td class='mw-label'>" .
1460 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1462 <td class='mw-input'>" .
1463 Html
::input( 'wpReason', $reason, 'text', array(
1465 'maxlength' => '255',
1473 # Disallow watching if user is not logged in
1474 if ( $user->isLoggedIn() ) {
1478 <td class='mw-input'>" .
1479 Xml
::checkLabel( wfMsg( 'watchthis' ),
1480 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1489 <td class='mw-submit'>" .
1490 Xml
::submitButton( wfMsg( 'deletepage' ),
1491 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1494 Xml
::closeElement( 'table' ) .
1495 Xml
::closeElement( 'fieldset' ) .
1496 Html
::hidden( 'wpEditToken', $user->editToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1497 Xml
::closeElement( 'form' );
1499 if ( $user->isAllowed( 'editinterface' ) ) {
1500 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1501 $link = Linker
::link(
1503 wfMsgHtml( 'delete-edit-reasonlist' ),
1505 array( 'action' => 'edit' )
1507 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1510 $wgOut->addHTML( $form );
1511 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1512 LogEventsList
::showLogExtract( $wgOut, 'delete',
1513 $this->getTitle()->getPrefixedText()
1518 * Perform a deletion and output success or failure messages
1520 * @param $suppress bool
1522 public function doDelete( $reason, $suppress = false ) {
1525 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1528 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
1529 $deleted = $this->getTitle()->getPrefixedText();
1531 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1532 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1534 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1536 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1537 $wgOut->returnToMain( false );
1539 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1540 if ( $error == '' ) {
1541 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1542 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1544 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1546 LogEventsList
::showLogExtract(
1549 $this->getTitle()->getPrefixedText()
1552 $wgOut->addHTML( $error );
1558 * Generate the navigation links when browsing through an article revisions
1559 * It shows the information as:
1560 * Revision as of \<date\>; view current revision
1561 * \<- Previous version | Next Version -\>
1563 * @param $oldid String: revision ID of this article revision
1565 public function setOldSubtitle( $oldid = 0 ) {
1566 global $wgLang, $wgOut, $wgUser, $wgRequest;
1568 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1572 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1574 # Cascade unhide param in links for easy deletion browsing
1575 $extraParams = array();
1576 if ( $wgRequest->getVal( 'unhide' ) ) {
1577 $extraParams['unhide'] = 1;
1580 $revision = Revision
::newFromId( $oldid );
1581 $timestamp = $revision->getTimestamp();
1583 $current = ( $oldid == $this->mPage
->getLatest() );
1584 $td = $wgLang->timeanddate( $timestamp, true );
1585 $tddate = $wgLang->date( $timestamp, true );
1586 $tdtime = $wgLang->time( $timestamp, true );
1589 ?
wfMsgHtml( 'currentrevisionlink' )
1592 wfMsgHtml( 'currentrevisionlink' ),
1595 array( 'known', 'noclasses' )
1598 ?
wfMsgHtml( 'diff' )
1601 wfMsgHtml( 'diff' ),
1607 array( 'known', 'noclasses' )
1609 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1613 wfMsgHtml( 'previousrevision' ),
1616 'direction' => 'prev',
1619 array( 'known', 'noclasses' )
1621 : wfMsgHtml( 'previousrevision' );
1625 wfMsgHtml( 'diff' ),
1631 array( 'known', 'noclasses' )
1633 : wfMsgHtml( 'diff' );
1634 $nextlink = $current
1635 ?
wfMsgHtml( 'nextrevision' )
1638 wfMsgHtml( 'nextrevision' ),
1641 'direction' => 'next',
1644 array( 'known', 'noclasses' )
1646 $nextdiff = $current
1647 ?
wfMsgHtml( 'diff' )
1650 wfMsgHtml( 'diff' ),
1656 array( 'known', 'noclasses' )
1661 // User can delete revisions or view deleted revisions...
1662 $canHide = $wgUser->isAllowed( 'deleterevision' );
1663 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1664 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1665 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1668 'type' => 'revision',
1669 'target' => $this->getTitle()->getPrefixedDbkey(),
1672 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1677 # Show user links if allowed to see them. If hidden, then show them only if requested...
1678 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1680 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1681 ?
'revision-info-current'
1684 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1687 array( 'parseinline', 'replaceafter' ),
1693 $revision->getUser()
1696 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1697 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1699 $wgOut->setSubtitle( $r );
1702 /* Caching functions */
1705 * checkLastModified returns true if it has taken care of all
1706 * output to the client that is necessary for this request.
1707 * (that is, it has sent a cached version of the page)
1709 * @return boolean true if cached version send, false otherwise
1711 protected function tryFileCache() {
1712 static $called = false;
1715 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1720 if ( $this->isFileCacheable() ) {
1721 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1722 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1723 wfDebug( "Article::tryFileCache(): about to load file\n" );
1724 $cache->loadFromFileCache( $this->getContext() );
1727 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1728 ob_start( array( &$cache, 'saveToFileCache' ) );
1731 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1738 * Check if the page can be cached
1741 public function isFileCacheable() {
1744 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1745 $cacheable = $this->mPage
->getID()
1746 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1747 // Extension may have reason to disable file caching on some pages.
1749 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1759 * Add the primary page-view wikitext to the output buffer
1760 * Saves the text into the parser cache if possible.
1761 * Updates templatelinks if it is out of date.
1763 * @param $text String
1764 * @param $cache Boolean
1765 * @param $parserOptions mixed ParserOptions object, or boolean false
1767 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1770 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1772 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1774 $wgOut->addParserOutput( $this->mParserOutput
);
1778 * Lightweight method to get the parser output for a page, checking the parser cache
1779 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1780 * consider, so it's not appropriate to use there.
1782 * @since 1.16 (r52326) for LiquidThreads
1784 * @param $oldid mixed integer Revision ID or null
1785 * @param $user User The relevant user
1786 * @return ParserOutput or false if the given revsion ID is not found
1788 public function getParserOutput( $oldid = null, User
$user = null ) {
1789 global $wgEnableParserCache, $wgUser;
1790 $user = is_null( $user ) ?
$wgUser : $user;
1792 wfProfileIn( __METHOD__
);
1793 // Should the parser cache be used?
1794 $useParserCache = $wgEnableParserCache &&
1795 $user->getStubThreshold() == 0 &&
1796 $this->mPage
->exists() &&
1799 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1801 if ( $user->getStubThreshold() ) {
1802 wfIncrStats( 'pcache_miss_stub' );
1805 if ( $useParserCache ) {
1806 $options = $this->mPage
->makeParserOptions( $user );
1807 $parserOutput = ParserCache
::singleton()->get( $this, $options );
1808 if ( $parserOutput !== false ) {
1809 wfProfileOut( __METHOD__
);
1810 return $parserOutput;
1814 // Cache miss; parse and output it.
1815 if ( $oldid === null ) {
1816 $text = $this->mPage
->getRawText();
1818 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1819 if ( $rev === null ) {
1820 wfProfileOut( __METHOD__
);
1823 $text = $rev->getText();
1826 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1827 wfProfileOut( __METHOD__
);
1832 * This does all the heavy lifting for outputWikitext, except it returns the parser
1833 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1834 * say, embedding thread pages within a discussion system (LiquidThreads)
1836 * @param $text string
1837 * @param $cache boolean
1838 * @param $parserOptions parsing options, defaults to false
1839 * @return ParserOutput
1841 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1842 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1844 if ( !$parserOptions ) {
1845 $parserOptions = $this->getParserOptions();
1849 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1850 $parserOptions, true, true, $this->getRevIdFetched() );
1855 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1856 $this->getTitle()->getPrefixedDBkey() ) );
1859 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1860 $parserCache = ParserCache
::singleton();
1861 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1864 // Make sure file cache is not used on uncacheable content.
1865 // Output that has magic words in it can still use the parser cache
1866 // (if enabled), though it will generally expire sooner.
1867 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1868 $wgUseFileCache = false;
1871 if ( $this->isCurrent() ) {
1872 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1875 return $this->mParserOutput
;
1879 * Get parser options suitable for rendering the primary article wikitext
1880 * @return ParserOptions|false
1882 public function getParserOptions() {
1884 if ( !$this->mParserOptions
) {
1885 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1887 // Clone to allow modifications of the return value without affecting cache
1888 return clone $this->mParserOptions
;
1892 * Sets the context this Article is executed in
1894 * @param $context IContextSource
1897 public function setContext( $context ) {
1898 $this->mContext
= $context;
1902 * Gets the context this Article is executed in
1904 * @return IContextSource
1907 public function getContext() {
1908 if ( $this->mContext
instanceof IContextSource
) {
1909 return $this->mContext
;
1911 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1912 return RequestContext
::getMain();
1917 * Use PHP's magic __get handler to handle accessing of
1918 * raw WikiPage fields for backwards compatibility.
1920 * @param $fname String Field name
1922 public function __get( $fname ) {
1923 if ( property_exists( $this->mPage
, $fname ) ) {
1924 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1925 return $this->mPage
->$fname;
1927 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1931 * Use PHP's magic __set handler to handle setting of
1932 * raw WikiPage fields for backwards compatibility.
1934 * @param $fname String Field name
1935 * @param $fvalue mixed New value
1937 public function __set( $fname, $fvalue ) {
1938 if ( property_exists( $this->mPage
, $fname ) ) {
1939 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1940 $this->mPage
->$fname = $fvalue;
1941 // Note: extensions may want to toss on new fields
1942 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1943 $this->mPage
->$fname = $fvalue;
1945 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1950 * Use PHP's magic __call handler to transform instance calls to
1951 * WikiPage functions for backwards compatibility.
1953 * @param $fname String Name of called method
1954 * @param $args Array Arguments to the method
1956 public function __call( $fname, $args ) {
1957 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1958 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1959 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1961 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1964 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1967 * @param $limit array
1968 * @param $reason string
1969 * @param $cascade int
1970 * @param $expiry array
1973 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1974 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1978 * @param $reason string
1979 * @param $suppress bool
1981 * @param $commit bool
1982 * @param $error string
1985 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1986 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1994 * @param $resultDetails
1998 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2000 $user = is_null( $user ) ?
$wgUser : $user;
2001 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2008 * @param $resultDetails
2009 * @param $guser User
2012 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2014 $guser = is_null( $guser ) ?
$wgUser : $guser;
2015 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2019 * @param $hasHistory bool
2022 public function generateReason( &$hasHistory ) {
2023 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2026 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2031 public static function selectFields() {
2032 return WikiPage
::selectFields();
2036 * @param $title Title
2038 public static function onArticleCreate( $title ) {
2039 WikiPage
::onArticleCreate( $title );
2043 * @param $title Title
2045 public static function onArticleDelete( $title ) {
2046 WikiPage
::onArticleDelete( $title );
2050 * @param $title Title
2052 public static function onArticleEdit( $title ) {
2053 WikiPage
::onArticleEdit( $title );
2062 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2063 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2068 class PoolWorkArticleView
extends PoolCounterWork
{
2075 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2076 parent
::__construct( 'ArticleView', $key );
2077 $this->mArticle
= $article;
2078 $this->cacheable
= $useParserCache;
2079 $this->parserOptions
= $parserOptions;
2086 return $this->mArticle
->doViewParse();
2092 function getCachedWork() {
2095 $parserCache = ParserCache
::singleton();
2096 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2098 if ( $this->mArticle
->mParserOutput
!== false ) {
2099 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2100 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2101 # Ensure that UI elements requiring revision ID have
2102 # the correct version information.
2103 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2112 function fallback() {
2113 return $this->mArticle
->tryDirtyCache();
2117 * @param $status Status
2119 function error( $status ) {
2122 $wgOut->clearHTML(); // for release() errors
2123 $wgOut->enableClientCache( false );
2124 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2126 $errortext = $status->getWikiText( false, 'view-pool-error' );
2127 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );