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();
150 public function clear() {
151 $this->mContentLoaded
= false;
153 $this->mRedirectedFrom
= null; # Title object if set
154 $this->mRevIdFetched
= 0;
155 $this->mRedirectUrl
= false;
157 $this->mPage
->clear();
161 * Note that getContent/loadContent do not follow redirects anymore.
162 * If you need to fetch redirectable content easily, try
163 * the shortcut in Article::followRedirect()
165 * This function has side effects! Do not use this function if you
166 * only want the real revision text if any.
168 * @return Return the text of this revision
170 public function getContent() {
173 wfProfileIn( __METHOD__
);
175 if ( $this->mPage
->getID() === 0 ) {
176 # If this is a MediaWiki:x message, then load the messages
177 # and return the message value for x.
178 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
179 $text = $this->getTitle()->getDefaultMessageText();
180 if ( $text === false ) {
184 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
186 wfProfileOut( __METHOD__
);
190 $this->loadContent();
191 wfProfileOut( __METHOD__
);
193 return $this->mContent
;
198 * @return int The oldid of the article that is to be shown, 0 for the
201 public function getOldID() {
202 if ( is_null( $this->mOldId
) ) {
203 $this->mOldId
= $this->getOldIDFromRequest();
206 return $this->mOldId
;
210 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
212 * @return int The old id for the request
214 public function getOldIDFromRequest() {
217 $this->mRedirectUrl
= false;
219 $oldid = $wgRequest->getVal( 'oldid' );
221 if ( isset( $oldid ) ) {
222 $oldid = intval( $oldid );
223 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
224 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
228 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
230 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
231 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
246 * Load the revision (including text) into this object
248 function loadContent() {
249 if ( $this->mContentLoaded
) {
253 wfProfileIn( __METHOD__
);
255 $this->fetchContent( $this->getOldID() );
257 wfProfileOut( __METHOD__
);
261 * Get text of an article from database
262 * Does *NOT* follow redirects.
264 * @param $oldid Int: 0 for whatever the latest revision is
265 * @return mixed string containing article contents, or false if null
267 function fetchContent( $oldid = 0 ) {
268 if ( $this->mContentLoaded
) {
269 return $this->mContent
;
272 # Pre-fill content with error message so that if something
273 # fails we'll have something telling us what we intended.
274 $t = $this->getTitle()->getPrefixedText();
275 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
276 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
279 $revision = Revision
::newFromId( $oldid );
281 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
284 // Revision title doesn't match the page title given?
285 if ( $this->mPage
->getID() != $revision->getPage() ) {
286 $function = array( get_class( $this->mPage
), 'newFromID' );
287 $this->mPage
= call_user_func( $function, $revision->getPage() );
288 if ( !$this->mPage
->getId() ) {
289 wfDebug( __METHOD__
. " failed to get page data linked to revision id $oldid\n" );
294 if ( !$this->mPage
->getLatest() ) {
295 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
299 $revision = $this->mPage
->getRevision();
301 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
306 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
307 // We should instead work with the Revision object when we need it...
308 $this->mContent
= $revision->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
310 $this->mRevIdFetched
= $revision->getId();
311 $this->mContentLoaded
= true;
312 $this->mRevision
=& $revision;
314 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
316 return $this->mContent
;
321 * @deprecated since 1.18
323 public function forUpdate() {
324 wfDeprecated( __METHOD__
);
328 * Returns true if the currently-referenced revision is the current edit
329 * to this page (and it exists).
332 public function isCurrent() {
333 # If no oldid, this is the current version.
334 if ( $this->getOldID() == 0 ) {
338 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
342 * Use this to fetch the rev ID used on page views
344 * @return int revision ID of last article revision
346 public function getRevIdFetched() {
347 if ( $this->mRevIdFetched
) {
348 return $this->mRevIdFetched
;
350 return $this->mPage
->getLatest();
355 * This is the default action of the index.php entry point: just view the
356 * page of the given title.
358 public function view() {
359 global $wgUser, $wgOut, $wgRequest, $wgParser;
360 global $wgUseFileCache, $wgUseETag;
362 wfProfileIn( __METHOD__
);
364 # Get variables from query string
365 $oldid = $this->getOldID();
367 # getOldID may want us to redirect somewhere else
368 if ( $this->mRedirectUrl
) {
369 $wgOut->redirect( $this->mRedirectUrl
);
370 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
371 wfProfileOut( __METHOD__
);
376 # Set page title (may be overridden by DISPLAYTITLE)
377 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
379 # If we got diff in the query, we want to see a diff page instead of the article.
380 if ( $wgRequest->getCheck( 'diff' ) ) {
381 wfDebug( __METHOD__
. ": showing diff page\n" );
382 $this->showDiffPage();
383 wfProfileOut( __METHOD__
);
388 $wgOut->setArticleFlag( true );
389 # Allow frames by default
390 $wgOut->allowClickjacking();
392 $parserCache = ParserCache
::singleton();
394 $parserOptions = $this->getParserOptions();
395 # Render printable version, use printable version cache
396 if ( $wgOut->isPrintable() ) {
397 $parserOptions->setIsPrintable( true );
398 $parserOptions->setEditSection( false );
399 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
400 $parserOptions->setEditSection( false );
403 # Try client and file cache
404 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
406 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
409 # Is it client cached?
410 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
411 wfDebug( __METHOD__
. ": done 304\n" );
412 wfProfileOut( __METHOD__
);
416 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
417 wfDebug( __METHOD__
. ": done file cache\n" );
418 # tell wgOut that output is taken care of
420 $this->mPage
->viewUpdates();
421 wfProfileOut( __METHOD__
);
427 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
428 $parserOptions->setEditSection( false );
431 # Should the parser cache be used?
432 $useParserCache = $this->useParserCache( $oldid );
433 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
434 if ( $wgUser->getStubThreshold() ) {
435 wfIncrStats( 'pcache_miss_stub' );
438 $wasRedirected = $this->showRedirectedFromHeader();
439 $this->showNamespaceHeader();
441 # Iterate through the possible ways of constructing the output text.
442 # Keep going until $outputDone is set, or we run out of things to do.
445 $this->mParserOutput
= false;
447 while ( !$outputDone && ++
$pass ) {
450 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
453 # Try the parser cache
454 if ( $useParserCache ) {
455 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
457 if ( $this->mParserOutput
!== false ) {
458 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
459 $wgOut->addParserOutput( $this->mParserOutput
);
460 # Ensure that UI elements requiring revision ID have
461 # the correct version information.
462 $wgOut->setRevisionId( $this->mPage
->getLatest() );
464 # Preload timestamp to avoid a DB hit
465 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
466 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
472 $text = $this->getContent();
473 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
474 wfDebug( __METHOD__
. ": showing missing article\n" );
475 $this->showMissingArticle();
476 wfProfileOut( __METHOD__
);
480 # Another whitelist check in case oldid is altering the title
481 if ( !$this->getTitle()->userCanRead() ) {
482 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
483 $wgOut->loginToUse();
486 wfProfileOut( __METHOD__
);
490 # Are we looking at an old revision
491 if ( $oldid && !is_null( $this->mRevision
) ) {
492 $this->setOldSubtitle( $oldid );
494 if ( !$this->showDeletedRevisionHeader() ) {
495 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
496 wfProfileOut( __METHOD__
);
500 # If this "old" version is the current, then try the parser cache...
501 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
502 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
503 if ( $this->mParserOutput
) {
504 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
505 $wgOut->addParserOutput( $this->mParserOutput
);
506 $wgOut->setRevisionId( $this->mPage
->getLatest() );
513 # Ensure that UI elements requiring revision ID have
514 # the correct version information.
515 $wgOut->setRevisionId( $this->getRevIdFetched() );
517 # Pages containing custom CSS or JavaScript get special treatment
518 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
519 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
520 $this->showCssOrJsPage();
522 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
523 # Allow extensions do their own custom view for certain pages
526 $rt = Title
::newFromRedirectArray( $text );
528 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
529 # Viewing a redirect page (e.g. with parameter redirect=no)
530 # Don't append the subtitle if this was an old revision
531 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
532 # Parse just to get categories, displaytitle, etc.
533 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
534 $wgOut->addParserOutputNoText( $this->mParserOutput
);
540 # Run the parse, protected by a pool counter
541 wfDebug( __METHOD__
. ": doing uncached parse\n" );
543 $key = $parserCache->getKey( $this, $parserOptions );
544 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
546 if ( !$poolArticleView->execute() ) {
547 # Connection or timeout error
548 wfProfileOut( __METHOD__
);
554 # Should be unreachable, but just in case...
560 # Get the ParserOutput actually *displayed* here.
561 # Note that $this->mParserOutput is the *current* version output.
562 $pOutput = ( $outputDone instanceof ParserOutput
)
563 ?
$outputDone // object fetched by hook
564 : $this->mParserOutput
;
566 # Adjust title for main page & pages with displaytitle
568 $this->adjustDisplayTitle( $pOutput );
571 # For the main page, overwrite the <title> element with the con-
572 # tents of 'pagetitle-view-mainpage' instead of the default (if
574 # This message always exists because it is in the i18n files
575 if ( $this->getTitle()->isMainPage() ) {
576 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
577 if ( !$msg->isDisabled() ) {
578 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
582 # Check for any __NOINDEX__ tags on the page using $pOutput
583 $policy = $this->getRobotPolicy( 'view', $pOutput );
584 $wgOut->setIndexPolicy( $policy['index'] );
585 $wgOut->setFollowPolicy( $policy['follow'] );
587 $this->showViewFooter();
588 $this->mPage
->viewUpdates();
590 wfProfileOut( __METHOD__
);
594 * Adjust title for pages with displaytitle, -{T|}- or language conversion
595 * @param $pOutput ParserOutput
597 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
599 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
600 $titleText = $pOutput->getTitleText();
601 if ( strval( $titleText ) !== '' ) {
602 $wgOut->setPageTitle( $titleText );
607 * Show a diff page according to current request variables. For use within
608 * Article::view() only, other callers should use the DifferenceEngine class.
610 public function showDiffPage() {
611 global $wgRequest, $wgUser;
613 $diff = $wgRequest->getVal( 'diff' );
614 $rcid = $wgRequest->getVal( 'rcid' );
615 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
616 $purge = $wgRequest->getVal( 'action' ) == 'purge';
617 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
618 $oldid = $this->getOldID();
620 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
621 // DifferenceEngine directly fetched the revision:
622 $this->mRevIdFetched
= $de->mNewid
;
623 $de->showDiffPage( $diffOnly );
625 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
626 # Run view updates for current revision only
627 $this->mPage
->viewUpdates();
632 * Show a page view for a page formatted as CSS or JavaScript. To be called by
633 * Article::view() only.
635 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
638 protected function showCssOrJsPage() {
641 $dir = $this->getContext()->getLang()->getDir();
642 $lang = $this->getContext()->getLang()->getCode();
644 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
647 // Give hooks a chance to customise the output
648 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
649 // Wrap the whole lot in a <pre> and don't parse
651 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
652 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
653 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
654 $wgOut->addHTML( "\n</pre>\n" );
659 * Get the robot policy to be used for the current view
660 * @param $action String the action= GET parameter
661 * @param $pOutput ParserOutput
662 * @return Array the policy that should be set
663 * TODO: actions other than 'view'
665 public function getRobotPolicy( $action, $pOutput ) {
666 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
667 global $wgDefaultRobotPolicy, $wgRequest;
669 $ns = $this->getTitle()->getNamespace();
671 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
672 # Don't index user and user talk pages for blocked users (bug 11443)
673 if ( !$this->getTitle()->isSubpage() ) {
674 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
676 'index' => 'noindex',
677 'follow' => 'nofollow'
683 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
684 # Non-articles (special pages etc), and old revisions
686 'index' => 'noindex',
687 'follow' => 'nofollow'
689 } elseif ( $wgOut->isPrintable() ) {
690 # Discourage indexing of printable versions, but encourage following
692 'index' => 'noindex',
695 } elseif ( $wgRequest->getInt( 'curid' ) ) {
696 # For ?curid=x urls, disallow indexing
698 'index' => 'noindex',
703 # Otherwise, construct the policy based on the various config variables.
704 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
706 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
707 # Honour customised robot policies for this namespace
708 $policy = array_merge(
710 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
713 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
714 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
715 # a final sanity check that we have really got the parser output.
716 $policy = array_merge(
718 array( 'index' => $pOutput->getIndexPolicy() )
722 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
723 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
724 $policy = array_merge(
726 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
734 * Converts a String robot policy into an associative array, to allow
735 * merging of several policies using array_merge().
736 * @param $policy Mixed, returns empty array on null/false/'', transparent
737 * to already-converted arrays, converts String.
738 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
740 public static function formatRobotPolicy( $policy ) {
741 if ( is_array( $policy ) ) {
743 } elseif ( !$policy ) {
747 $policy = explode( ',', $policy );
748 $policy = array_map( 'trim', $policy );
751 foreach ( $policy as $var ) {
752 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
753 $arr['index'] = $var;
754 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
755 $arr['follow'] = $var;
763 * If this request is a redirect view, send "redirected from" subtitle to
764 * $wgOut. Returns true if the header was needed, false if this is not a
765 * redirect view. Handles both local and remote redirects.
769 public function showRedirectedFromHeader() {
770 global $wgOut, $wgRequest, $wgRedirectSources;
772 $rdfrom = $wgRequest->getVal( 'rdfrom' );
774 if ( isset( $this->mRedirectedFrom
) ) {
775 // This is an internally redirected page view.
776 // We'll need a backlink to the source page for navigation.
777 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
778 $redir = Linker
::link(
779 $this->mRedirectedFrom
,
782 array( 'redirect' => 'no' ),
783 array( 'known', 'noclasses' )
786 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
787 $wgOut->setSubtitle( $s );
789 // Set the fragment if one was specified in the redirect
790 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
791 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
792 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
795 // Add a <link rel="canonical"> tag
796 $wgOut->addLink( array( 'rel' => 'canonical',
797 'href' => $this->getTitle()->getLocalURL() )
802 } elseif ( $rdfrom ) {
803 // This is an externally redirected view, from some other wiki.
804 // If it was reported from a trusted site, supply a backlink.
805 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
806 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
807 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
808 $wgOut->setSubtitle( $s );
818 * Show a header specific to the namespace currently being viewed, like
819 * [[MediaWiki:Talkpagetext]]. For Article::view().
821 public function showNamespaceHeader() {
824 if ( $this->getTitle()->isTalkPage() ) {
825 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
826 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
832 * Show the footer section of an ordinary page view
834 public function showViewFooter() {
835 global $wgOut, $wgUseTrackbacks;
837 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
838 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
839 $wgOut->addWikiMsg( 'anontalkpagetext' );
842 # If we have been passed an &rcid= parameter, we want to give the user a
843 # chance to mark this new article as patrolled.
844 $this->showPatrolFooter();
847 if ( $wgUseTrackbacks ) {
848 $this->addTrackbacks();
851 wfRunHooks( 'ArticleViewFooter', array( $this ) );
856 * If patrol is possible, output a patrol UI box. This is called from the
857 * footer section of ordinary page views. If patrol is not possible or not
858 * desired, does nothing.
860 public function showPatrolFooter() {
861 global $wgOut, $wgRequest, $wgUser;
863 $rcid = $wgRequest->getVal( 'rcid' );
865 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
869 $token = $wgUser->editToken( $rcid );
870 $wgOut->preventClickjacking();
873 "<div class='patrollink'>" .
875 'markaspatrolledlink',
878 wfMsgHtml( 'markaspatrolledtext' ),
881 'action' => 'markpatrolled',
885 array( 'known', 'noclasses' )
893 * Show the error text for a missing article. For articles in the MediaWiki
894 * namespace, show the default message text. To be called from Article::view().
896 public function showMissingArticle() {
897 global $wgOut, $wgRequest, $wgUser;
899 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
900 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
901 $parts = explode( '/', $this->getTitle()->getText() );
902 $rootPart = $parts[0];
903 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
904 $ip = User
::isIP( $rootPart );
906 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
907 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
908 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
909 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
910 LogEventsList
::showLogExtract(
913 $user->getUserPage()->getPrefixedText(),
917 'showIfEmpty' => false,
919 'blocked-notice-logextract',
920 $user->getName() # Support GENDER in notice
927 wfRunHooks( 'ShowMissingArticle', array( $this ) );
929 # Show delete and move logs
930 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
932 'conds' => array( "log_action != 'revision'" ),
933 'showIfEmpty' => false,
934 'msgKey' => array( 'moveddeleted-notice' ) )
938 $oldid = $this->getOldID();
940 $text = wfMsgNoTrans( 'missing-article',
941 $this->getTitle()->getPrefixedText(),
942 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
943 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
944 // Use the default message text
945 $text = $this->getTitle()->getDefaultMessageText();
947 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
948 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
949 $errors = array_merge( $createErrors, $editErrors );
951 if ( !count( $errors ) ) {
952 $text = wfMsgNoTrans( 'noarticletext' );
954 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
957 $text = "<div class='noarticletext'>\n$text\n</div>";
959 if ( !$this->mPage
->hasViewableContent() ) {
960 // If there's no backing content, send a 404 Not Found
961 // for better machine handling of broken links.
962 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
965 $wgOut->addWikiText( $text );
969 * If the revision requested for view is deleted, check permissions.
970 * Send either an error message or a warning header to $wgOut.
972 * @return boolean true if the view is allowed, false if not.
974 public function showDeletedRevisionHeader() {
975 global $wgOut, $wgRequest;
977 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
982 // If the user is not allowed to see it...
983 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
984 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
985 'rev-deleted-text-permission' );
988 // If the user needs to confirm that they want to see it...
989 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
990 # Give explanation and add a link to view the revision...
991 $oldid = intval( $this->getOldID() );
992 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
993 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
994 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
995 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
996 array( $msg, $link ) );
999 // We are allowed to see...
1001 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1002 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1003 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1010 * Execute the uncached parse for action=view
1013 public function doViewParse() {
1016 $oldid = $this->getOldID();
1017 $parserOptions = $this->getParserOptions();
1019 # Render printable version, use printable version cache
1020 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1022 # Don't show section-edit links on old revisions... this way lies madness.
1023 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1024 $parserOptions->setEditSection( false );
1027 $useParserCache = $this->useParserCache( $oldid );
1028 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1034 * Try to fetch an expired entry from the parser cache. If it is present,
1035 * output it and return true. If it is not present, output nothing and
1036 * return false. This is used as a callback function for
1037 * PoolCounter::executeProtected().
1041 public function tryDirtyCache() {
1043 $parserCache = ParserCache
::singleton();
1044 $options = $this->getParserOptions();
1046 if ( $wgOut->isPrintable() ) {
1047 $options->setIsPrintable( true );
1048 $options->setEditSection( false );
1051 $output = $parserCache->getDirty( $this, $options );
1054 wfDebug( __METHOD__
. ": sending dirty output\n" );
1055 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1056 $wgOut->setSquidMaxage( 0 );
1057 $this->mParserOutput
= $output;
1058 $wgOut->addParserOutput( $output );
1059 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1063 wfDebugLog( 'dirty', "dirty missing\n" );
1064 wfDebug( __METHOD__
. ": no dirty cache\n" );
1073 * @param $target Title|Array of destination(s) to redirect
1074 * @param $appendSubtitle Boolean [optional]
1075 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1076 * @return string containing HMTL with redirect link
1078 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1079 global $wgOut, $wgStylePath;
1081 if ( !is_array( $target ) ) {
1082 $target = array( $target );
1085 $lang = $this->getTitle()->getPageLanguage();
1086 $imageDir = $lang->getDir();
1088 if ( $appendSubtitle ) {
1089 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1092 // the loop prepends the arrow image before the link, so the first case needs to be outside
1097 $title = array_shift( $target );
1099 if ( $forceKnown ) {
1100 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1102 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1105 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1106 $alt = $lang->isRTL() ?
'←' : '→';
1107 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1108 foreach ( $target as $rt ) {
1109 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1110 if ( $forceKnown ) {
1111 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1113 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1117 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1118 return '<div class="redirectMsg">' .
1119 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1120 '<span class="redirectText">' . $link . '</span></div>';
1124 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1126 public function addTrackbacks() {
1129 $dbr = wfGetDB( DB_SLAVE
);
1130 $tbs = $dbr->select( 'trackbacks',
1131 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1132 array( 'tb_page' => $this->mPage
->getID() )
1135 if ( !$dbr->numRows( $tbs ) ) {
1139 $wgOut->preventClickjacking();
1142 foreach ( $tbs as $o ) {
1145 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1146 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1147 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1148 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1152 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1160 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1164 * Removes trackback record for current article from trackbacks table
1165 * @deprecated since 1.18
1167 public function deletetrackback() {
1168 return Action
::factory( 'deletetrackback', $this )->show();
1172 * Handle action=render
1175 public function render() {
1178 $wgOut->setArticleBodyOnly( true );
1183 * Handle action=purge
1185 public function purge() {
1186 return Action
::factory( 'purge', $this )->show();
1190 * Mark this particular edit/page as patrolled
1191 * @deprecated since 1.18
1193 public function markpatrolled() {
1194 Action
::factory( 'markpatrolled', $this )->show();
1198 * User-interface handler for the "watch" action.
1199 * Requires Request to pass a token as of 1.18.
1200 * @deprecated since 1.18
1202 public function watch() {
1203 Action
::factory( 'watch', $this )->show();
1207 * Add this page to $wgUser's watchlist
1209 * This is safe to be called multiple times
1211 * @return bool true on successful watch operation
1212 * @deprecated since 1.18
1214 public function doWatch() {
1216 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1220 * User interface handler for the "unwatch" action.
1221 * Requires Request to pass a token as of 1.18.
1222 * @deprecated since 1.18
1224 public function unwatch() {
1225 Action
::factory( 'unwatch', $this )->show();
1229 * Stop watching a page
1230 * @return bool true on successful unwatch
1231 * @deprecated since 1.18
1233 public function doUnwatch() {
1235 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1239 * action=protect handler
1241 public function protect() {
1242 $form = new ProtectionForm( $this );
1247 * action=unprotect handler (alias)
1249 public function unprotect() {
1254 * Info about this page
1255 * Called for ?action=info when $wgAllowPageInfo is on.
1257 public function info() {
1258 Action
::factory( 'info', $this )->show();
1262 * Overriden by ImagePage class, only present here to avoid a fatal error
1263 * Called for ?action=revert
1265 public function revert() {
1266 Action
::factory( 'revert', $this )->show();
1270 * User interface for rollback operations
1272 public function rollback() {
1273 Action
::factory( 'rollback', $this )->show();
1277 * Output a redirect back to the article.
1278 * This is typically used after an edit.
1280 * @deprecated in 1.18; call $wgOut->redirect() directly
1281 * @param $noRedir Boolean: add redirect=no
1282 * @param $sectionAnchor String: section to redirect to, including "#"
1283 * @param $extraQuery String: extra query params
1285 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1286 wfDeprecated( __METHOD__
);
1290 $query = 'redirect=no';
1292 $query .= "&$extraQuery";
1294 $query = $extraQuery;
1297 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1301 * UI entry point for page deletion
1303 public function delete() {
1304 global $wgOut, $wgRequest;
1306 $confirm = $wgRequest->wasPosted() &&
1307 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1309 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1310 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1312 $reason = $this->DeleteReasonList
;
1314 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1315 // Entry from drop down menu + additional comment
1316 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1317 } elseif ( $reason == 'other' ) {
1318 $reason = $this->DeleteReason
;
1321 # Flag to hide all contents of the archived revisions
1322 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1324 # This code desperately needs to be totally rewritten
1326 # Read-only check...
1327 if ( wfReadOnly() ) {
1328 $wgOut->readOnlyPage();
1334 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1336 if ( count( $permission_errors ) > 0 ) {
1337 $wgOut->showPermissionsErrorPage( $permission_errors );
1342 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1344 # Better double-check that it hasn't been deleted yet!
1345 $dbw = wfGetDB( DB_MASTER
);
1346 $conds = $this->getTitle()->pageCond();
1347 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1348 if ( $latest === false ) {
1349 $wgOut->showFatalError(
1352 array( 'class' => 'error mw-error-cannotdelete' ),
1353 wfMsgExt( 'cannotdelete', array( 'parse' ),
1354 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1357 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1358 LogEventsList
::showLogExtract(
1361 $this->getTitle()->getPrefixedText()
1367 # Hack for big sites
1368 $bigHistory = $this->mPage
->isBigDeletion();
1369 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1370 global $wgLang, $wgDeleteRevisionsLimit;
1372 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1373 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1379 $this->doDelete( $reason, $suppress );
1381 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1383 } elseif ( $this->getTitle()->userIsWatching() ) {
1390 // Generate deletion reason
1391 $hasHistory = false;
1393 $reason = $this->generateReason( $hasHistory );
1396 // If the page has a history, insert a warning
1397 if ( $hasHistory && !$confirm ) {
1400 $revisions = $this->mPage
->estimateRevisionCount();
1401 // @todo FIXME: i18n issue/patchwork message
1402 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1403 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1404 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1405 wfMsgHtml( 'history' ),
1406 array( 'rel' => 'archives' ),
1407 array( 'action' => 'history' ) ) .
1411 if ( $bigHistory ) {
1412 global $wgDeleteRevisionsLimit;
1413 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1414 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1418 return $this->confirmDelete( $reason );
1422 * Output deletion confirmation dialog
1423 * @todo FIXME: Move to another file?
1424 * @param $reason String: prefilled reason
1426 public function confirmDelete( $reason ) {
1429 wfDebug( "Article::confirmDelete\n" );
1431 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1432 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1433 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1434 $wgOut->addWikiMsg( 'confirmdeletetext' );
1436 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1438 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1439 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1441 <td class='mw-input'><strong>" .
1442 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1443 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1449 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1451 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1452 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1453 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1454 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1455 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1456 "<tr id=\"wpDeleteReasonListRow\">
1457 <td class='mw-label'>" .
1458 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1460 <td class='mw-input'>" .
1461 Xml
::listDropDown( 'wpDeleteReasonList',
1462 wfMsgForContent( 'deletereason-dropdown' ),
1463 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1466 <tr id=\"wpDeleteReasonRow\">
1467 <td class='mw-label'>" .
1468 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1470 <td class='mw-input'>" .
1471 Html
::input( 'wpReason', $reason, 'text', array(
1473 'maxlength' => '255',
1481 # Disallow watching if user is not logged in
1482 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1486 <td class='mw-input'>" .
1487 Xml
::checkLabel( wfMsg( 'watchthis' ),
1488 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1497 <td class='mw-submit'>" .
1498 Xml
::submitButton( wfMsg( 'deletepage' ),
1499 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1502 Xml
::closeElement( 'table' ) .
1503 Xml
::closeElement( 'fieldset' ) .
1504 Html
::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1505 Xml
::closeElement( 'form' );
1507 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1508 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1509 $link = Linker
::link(
1511 wfMsgHtml( 'delete-edit-reasonlist' ),
1513 array( 'action' => 'edit' )
1515 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1518 $wgOut->addHTML( $form );
1519 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1520 LogEventsList
::showLogExtract( $wgOut, 'delete',
1521 $this->getTitle()->getPrefixedText()
1526 * Perform a deletion and output success or failure messages
1528 * @param $suppress bool
1530 public function doDelete( $reason, $suppress = false ) {
1533 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1536 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1537 $deleted = $this->getTitle()->getPrefixedText();
1539 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1540 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1542 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1544 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1545 $wgOut->returnToMain( false );
1547 if ( $error == '' ) {
1548 $wgOut->showFatalError(
1551 array( 'class' => 'error mw-error-cannotdelete' ),
1552 wfMsgExt( 'cannotdelete', array( 'parse' ),
1553 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1557 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1559 LogEventsList
::showLogExtract(
1562 $this->getTitle()->getPrefixedText()
1565 $wgOut->showFatalError( $error );
1571 * Generate the navigation links when browsing through an article revisions
1572 * It shows the information as:
1573 * Revision as of \<date\>; view current revision
1574 * \<- Previous version | Next Version -\>
1576 * @param $oldid String: revision ID of this article revision
1578 public function setOldSubtitle( $oldid = 0 ) {
1579 global $wgLang, $wgOut, $wgUser, $wgRequest;
1581 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1585 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1587 # Cascade unhide param in links for easy deletion browsing
1588 $extraParams = array();
1589 if ( $wgRequest->getVal( 'unhide' ) ) {
1590 $extraParams['unhide'] = 1;
1593 $revision = Revision
::newFromId( $oldid );
1594 $timestamp = $revision->getTimestamp();
1596 $current = ( $oldid == $this->mPage
->getLatest() );
1597 $td = $wgLang->timeanddate( $timestamp, true );
1598 $tddate = $wgLang->date( $timestamp, true );
1599 $tdtime = $wgLang->time( $timestamp, true );
1602 ?
wfMsgHtml( 'currentrevisionlink' )
1605 wfMsgHtml( 'currentrevisionlink' ),
1608 array( 'known', 'noclasses' )
1611 ?
wfMsgHtml( 'diff' )
1614 wfMsgHtml( 'diff' ),
1620 array( 'known', 'noclasses' )
1622 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1626 wfMsgHtml( 'previousrevision' ),
1629 'direction' => 'prev',
1632 array( 'known', 'noclasses' )
1634 : wfMsgHtml( 'previousrevision' );
1638 wfMsgHtml( 'diff' ),
1644 array( 'known', 'noclasses' )
1646 : wfMsgHtml( 'diff' );
1647 $nextlink = $current
1648 ?
wfMsgHtml( 'nextrevision' )
1651 wfMsgHtml( 'nextrevision' ),
1654 'direction' => 'next',
1657 array( 'known', 'noclasses' )
1659 $nextdiff = $current
1660 ?
wfMsgHtml( 'diff' )
1663 wfMsgHtml( 'diff' ),
1669 array( 'known', 'noclasses' )
1674 // User can delete revisions or view deleted revisions...
1675 $canHide = $wgUser->isAllowed( 'deleterevision' );
1676 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1677 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1678 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1681 'type' => 'revision',
1682 'target' => $this->getTitle()->getPrefixedDbkey(),
1685 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1690 # Show user links if allowed to see them. If hidden, then show them only if requested...
1691 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1693 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1694 ?
'revision-info-current'
1697 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1700 array( 'parseinline', 'replaceafter' ),
1706 $revision->getUser()
1709 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1710 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1712 $wgOut->setSubtitle( $r );
1715 /* Caching functions */
1718 * checkLastModified returns true if it has taken care of all
1719 * output to the client that is necessary for this request.
1720 * (that is, it has sent a cached version of the page)
1722 * @return boolean true if cached version send, false otherwise
1724 protected function tryFileCache() {
1725 static $called = false;
1728 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1733 if ( $this->isFileCacheable() ) {
1734 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1735 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1736 wfDebug( "Article::tryFileCache(): about to load file\n" );
1737 $cache->loadFromFileCache( $this->getContext() );
1740 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1741 ob_start( array( &$cache, 'saveToFileCache' ) );
1744 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1751 * Check if the page can be cached
1754 public function isFileCacheable() {
1757 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1758 $cacheable = $this->mPage
->getID()
1759 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1760 // Extension may have reason to disable file caching on some pages.
1762 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1772 * Add the primary page-view wikitext to the output buffer
1773 * Saves the text into the parser cache if possible.
1774 * Updates templatelinks if it is out of date.
1776 * @param $text String
1777 * @param $cache Boolean
1778 * @param $parserOptions mixed ParserOptions object, or boolean false
1780 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1783 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1785 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1787 $wgOut->addParserOutput( $this->mParserOutput
);
1791 * Lightweight method to get the parser output for a page, checking the parser cache
1792 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1793 * consider, so it's not appropriate to use there.
1795 * @since 1.16 (r52326) for LiquidThreads
1797 * @param $oldid mixed integer Revision ID or null
1798 * @param $user User The relevant user
1799 * @return ParserOutput or false if the given revsion ID is not found
1801 public function getParserOutput( $oldid = null, User
$user = null ) {
1802 global $wgEnableParserCache, $wgUser;
1803 $user = is_null( $user ) ?
$wgUser : $user;
1805 wfProfileIn( __METHOD__
);
1806 // Should the parser cache be used?
1807 $useParserCache = $wgEnableParserCache &&
1808 $user->getStubThreshold() == 0 &&
1809 $this->mPage
->exists() &&
1812 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1814 if ( $user->getStubThreshold() ) {
1815 wfIncrStats( 'pcache_miss_stub' );
1818 if ( $useParserCache ) {
1819 $options = $this->mPage
->makeParserOptions( $user );
1820 $parserOutput = ParserCache
::singleton()->get( $this, $options );
1821 if ( $parserOutput !== false ) {
1822 wfProfileOut( __METHOD__
);
1823 return $parserOutput;
1827 // Cache miss; parse and output it.
1828 if ( $oldid === null ) {
1829 $text = $this->mPage
->getRawText();
1831 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1832 if ( $rev === null ) {
1833 wfProfileOut( __METHOD__
);
1836 $text = $rev->getText();
1839 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1840 wfProfileOut( __METHOD__
);
1845 * This does all the heavy lifting for outputWikitext, except it returns the parser
1846 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1847 * say, embedding thread pages within a discussion system (LiquidThreads)
1849 * @param $text string
1850 * @param $cache boolean
1851 * @param $parserOptions parsing options, defaults to false
1852 * @return ParserOutput
1854 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1855 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1857 if ( !$parserOptions ) {
1858 $parserOptions = $this->getParserOptions();
1862 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1863 $parserOptions, true, true, $this->getRevIdFetched() );
1868 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1869 $this->getTitle()->getPrefixedDBkey() ) );
1872 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1873 $parserCache = ParserCache
::singleton();
1874 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1877 // Make sure file cache is not used on uncacheable content.
1878 // Output that has magic words in it can still use the parser cache
1879 // (if enabled), though it will generally expire sooner.
1880 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1881 $wgUseFileCache = false;
1884 if ( $this->isCurrent() ) {
1885 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1888 return $this->mParserOutput
;
1892 * Get parser options suitable for rendering the primary article wikitext
1893 * @return ParserOptions|false
1895 public function getParserOptions() {
1897 if ( !$this->mParserOptions
) {
1898 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1900 // Clone to allow modifications of the return value without affecting cache
1901 return clone $this->mParserOptions
;
1905 * Sets the context this Article is executed in
1907 * @param $context IContextSource
1910 public function setContext( $context ) {
1911 $this->mContext
= $context;
1915 * Gets the context this Article is executed in
1917 * @return IContextSource
1920 public function getContext() {
1921 if ( $this->mContext
instanceof IContextSource
) {
1922 return $this->mContext
;
1924 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1925 return RequestContext
::getMain();
1930 * Use PHP's magic __get handler to handle accessing of
1931 * raw WikiPage fields for backwards compatibility.
1933 * @param $fname String Field name
1935 public function __get( $fname ) {
1936 if ( property_exists( $this->mPage
, $fname ) ) {
1937 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1938 return $this->mPage
->$fname;
1940 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1944 * Use PHP's magic __set handler to handle setting of
1945 * raw WikiPage fields for backwards compatibility.
1947 * @param $fname String Field name
1948 * @param $fvalue mixed New value
1950 public function __set( $fname, $fvalue ) {
1951 if ( property_exists( $this->mPage
, $fname ) ) {
1952 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1953 $this->mPage
->$fname = $fvalue;
1954 // Note: extensions may want to toss on new fields
1955 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1956 $this->mPage
->$fname = $fvalue;
1958 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1963 * Use PHP's magic __call handler to transform instance calls to
1964 * WikiPage functions for backwards compatibility.
1966 * @param $fname String Name of called method
1967 * @param $args Array Arguments to the method
1969 public function __call( $fname, $args ) {
1970 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1971 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1972 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1974 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1977 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1980 * @param $limit array
1981 * @param $reason string
1982 * @param $cascade int
1983 * @param $expiry array
1986 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1987 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1991 * @param $reason string
1992 * @param $suppress bool
1994 * @param $commit bool
1995 * @param $error string
1998 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1999 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2007 * @param $resultDetails
2011 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2013 $user = is_null( $user ) ?
$wgUser : $user;
2014 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2021 * @param $resultDetails
2022 * @param $guser User
2025 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2027 $guser = is_null( $guser ) ?
$wgUser : $guser;
2028 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2032 * @param $hasHistory bool
2035 public function generateReason( &$hasHistory ) {
2036 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2039 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2044 public static function selectFields() {
2045 return WikiPage
::selectFields();
2049 * @param $title Title
2051 public static function onArticleCreate( $title ) {
2052 WikiPage
::onArticleCreate( $title );
2056 * @param $title Title
2058 public static function onArticleDelete( $title ) {
2059 WikiPage
::onArticleDelete( $title );
2063 * @param $title Title
2065 public static function onArticleEdit( $title ) {
2066 WikiPage
::onArticleEdit( $title );
2075 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2076 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2081 class PoolWorkArticleView
extends PoolCounterWork
{
2088 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2089 parent
::__construct( 'ArticleView', $key );
2090 $this->mArticle
= $article;
2091 $this->cacheable
= $useParserCache;
2092 $this->parserOptions
= $parserOptions;
2099 return $this->mArticle
->doViewParse();
2105 function getCachedWork() {
2108 $parserCache = ParserCache
::singleton();
2109 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2111 if ( $this->mArticle
->mParserOutput
!== false ) {
2112 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2113 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2114 # Ensure that UI elements requiring revision ID have
2115 # the correct version information.
2116 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2125 function fallback() {
2126 return $this->mArticle
->tryDirtyCache();
2130 * @param $status Status
2132 function error( $status ) {
2135 $wgOut->clearHTML(); // for release() errors
2136 $wgOut->enableClientCache( false );
2137 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2139 $errortext = $status->getWikiText( false, 'view-pool-error' );
2140 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );