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
{
37 * @var ParserOptions: ParserOptions object for $wgUser articles
39 public $mParserOptions;
42 var $mContentLoaded = false; // !<
48 var $mRedirectedFrom = null;
51 * @var mixed: boolean false or URL string
53 var $mRedirectUrl = false; // !<
54 var $mRevIdFetched = 0; // !<
59 var $mRevision = null;
69 * Constructor and clear the article
70 * @param $title Title Reference to a Title object.
71 * @param $oldId Integer revision ID, null to fetch from request, zero for current
73 public function __construct( Title
$title, $oldId = null ) {
74 $this->mOldId
= $oldId;
75 $this->mPage
= $this->newPage( $title );
78 protected function newPage( Title
$title ) {
79 return new WikiPage( $title );
83 * Constructor from a page id
84 * @param $id Int article ID to load
86 public static function newFromID( $id ) {
87 $t = Title
::newFromID( $id );
88 # @todo FIXME: Doesn't inherit right
89 return $t == null ?
null : new self( $t );
90 # return $t == null ? null : new static( $t ); // PHP 5.3
94 * Create an Article object of the appropriate class for the given page.
97 * @param $context IContextSource
98 * @return Article object
100 public static function newFromTitle( $title, IContextSource
$context ) {
101 if ( NS_MEDIA
== $title->getNamespace() ) {
102 // FIXME: where should this go?
103 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
107 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
109 switch( $title->getNamespace() ) {
111 $page = new ImagePage( $title );
114 $page = new CategoryPage( $title );
117 $page = new Article( $title );
120 $page->setContext( $context );
126 * Tell the page view functions that this view was redirected
127 * from another page on the wiki.
128 * @param $from Title object.
130 public function setRedirectedFrom( Title
$from ) {
131 $this->mRedirectedFrom
= $from;
135 * Get the title object of the article
136 * @return Title object of this page
138 public function getTitle() {
139 return $this->mPage
->getTitle();
144 * @todo FIXME: Shouldn't this be public?
147 public function clear() {
148 $this->mContentLoaded
= false;
150 $this->mRedirectedFrom
= null; # Title object if set
151 $this->mRevIdFetched
= 0;
152 $this->mRedirectUrl
= false;
154 $this->mPage
->clear();
158 * Note that getContent/loadContent do not follow redirects anymore.
159 * If you need to fetch redirectable content easily, try
160 * the shortcut in Article::followRedirect()
162 * This function has side effects! Do not use this function if you
163 * only want the real revision text if any.
165 * @return Return the text of this revision
167 public function getContent() {
170 wfProfileIn( __METHOD__
);
172 if ( $this->mPage
->getID() === 0 ) {
173 # If this is a MediaWiki:x message, then load the messages
174 # and return the message value for x.
175 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
176 $text = $this->getTitle()->getDefaultMessageText();
177 if ( $text === false ) {
181 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
183 wfProfileOut( __METHOD__
);
187 $this->loadContent();
188 wfProfileOut( __METHOD__
);
190 return $this->mContent
;
195 * @return int The oldid of the article that is to be shown, 0 for the
198 public function getOldID() {
199 if ( is_null( $this->mOldId
) ) {
200 $this->mOldId
= $this->getOldIDFromRequest();
203 return $this->mOldId
;
207 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
209 * @return int The old id for the request
211 public function getOldIDFromRequest() {
214 $this->mRedirectUrl
= false;
216 $oldid = $wgRequest->getVal( 'oldid' );
218 if ( isset( $oldid ) ) {
219 $oldid = intval( $oldid );
220 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
221 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
225 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
227 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
228 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
243 * Load the revision (including text) into this object
245 function loadContent() {
246 if ( $this->mContentLoaded
) {
250 wfProfileIn( __METHOD__
);
252 $this->fetchContent( $this->getOldID() );
254 wfProfileOut( __METHOD__
);
258 * Get text of an article from database
259 * Does *NOT* follow redirects.
261 * @param $oldid Int: 0 for whatever the latest revision is
262 * @return mixed string containing article contents, or false if null
264 function fetchContent( $oldid = 0 ) {
265 if ( $this->mContentLoaded
) {
266 return $this->mContent
;
269 # Pre-fill content with error message so that if something
270 # fails we'll have something telling us what we intended.
271 $t = $this->getTitle()->getPrefixedText();
272 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
273 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
276 $revision = Revision
::newFromId( $oldid );
278 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
281 // Revision title doesn't match the page title given?
282 if ( $this->mPage
->getID() != $revision->getPage() ) {
283 $function = array( get_class( $this->mPage
), 'newFromID' );
284 $this->mPage
= call_user_func( $function, $revision->getPage() );
285 if ( !$this->mPage
->getId() ) {
286 wfDebug( __METHOD__
. " failed to get page data linked to revision id $oldid\n" );
291 if ( !$this->mPage
->getLatest() ) {
292 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
296 $revision = $this->mPage
->getRevision();
298 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
303 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
304 // We should instead work with the Revision object when we need it...
305 $this->mContent
= $revision->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
307 $this->mRevIdFetched
= $revision->getId();
308 $this->mContentLoaded
= true;
309 $this->mRevision
=& $revision;
311 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
313 return $this->mContent
;
318 * @deprecated since 1.18
320 public function forUpdate() {
321 wfDeprecated( __METHOD__
);
325 * Returns true if the currently-referenced revision is the current edit
326 * to this page (and it exists).
329 public function isCurrent() {
330 # If no oldid, this is the current version.
331 if ( $this->getOldID() == 0 ) {
335 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
339 * Use this to fetch the rev ID used on page views
341 * @return int revision ID of last article revision
343 public function getRevIdFetched() {
344 if ( $this->mRevIdFetched
) {
345 return $this->mRevIdFetched
;
347 return $this->mPage
->getLatest();
352 * This is the default action of the index.php entry point: just view the
353 * page of the given title.
355 public function view() {
356 global $wgUser, $wgOut, $wgRequest, $wgParser;
357 global $wgUseFileCache, $wgUseETag;
359 wfProfileIn( __METHOD__
);
361 # Get variables from query string
362 $oldid = $this->getOldID();
364 # getOldID may want us to redirect somewhere else
365 if ( $this->mRedirectUrl
) {
366 $wgOut->redirect( $this->mRedirectUrl
);
367 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
368 wfProfileOut( __METHOD__
);
373 # Set page title (may be overridden by DISPLAYTITLE)
374 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
376 # If we got diff in the query, we want to see a diff page instead of the article.
377 if ( $wgRequest->getCheck( 'diff' ) ) {
378 wfDebug( __METHOD__
. ": showing diff page\n" );
379 $this->showDiffPage();
380 wfProfileOut( __METHOD__
);
385 $wgOut->setArticleFlag( true );
386 # Allow frames by default
387 $wgOut->allowClickjacking();
389 $parserCache = ParserCache
::singleton();
391 $parserOptions = $this->getParserOptions();
392 # Render printable version, use printable version cache
393 if ( $wgOut->isPrintable() ) {
394 $parserOptions->setIsPrintable( true );
395 $parserOptions->setEditSection( false );
396 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
397 $parserOptions->setEditSection( false );
400 # Try client and file cache
401 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
403 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
406 # Is it client cached?
407 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
408 wfDebug( __METHOD__
. ": done 304\n" );
409 wfProfileOut( __METHOD__
);
413 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
414 wfDebug( __METHOD__
. ": done file cache\n" );
415 # tell wgOut that output is taken care of
417 $this->mPage
->viewUpdates();
418 wfProfileOut( __METHOD__
);
424 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
425 $parserOptions->setEditSection( false );
428 # Should the parser cache be used?
429 $useParserCache = $this->useParserCache( $oldid );
430 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
431 if ( $wgUser->getStubThreshold() ) {
432 wfIncrStats( 'pcache_miss_stub' );
435 $wasRedirected = $this->showRedirectedFromHeader();
436 $this->showNamespaceHeader();
438 # Iterate through the possible ways of constructing the output text.
439 # Keep going until $outputDone is set, or we run out of things to do.
442 $this->mParserOutput
= false;
444 while ( !$outputDone && ++
$pass ) {
447 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
450 # Try the parser cache
451 if ( $useParserCache ) {
452 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
454 if ( $this->mParserOutput
!== false ) {
455 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
456 $wgOut->addParserOutput( $this->mParserOutput
);
457 # Ensure that UI elements requiring revision ID have
458 # the correct version information.
459 $wgOut->setRevisionId( $this->mPage
->getLatest() );
461 # Preload timestamp to avoid a DB hit
462 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
463 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
469 $text = $this->getContent();
470 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
471 wfDebug( __METHOD__
. ": showing missing article\n" );
472 $this->showMissingArticle();
473 wfProfileOut( __METHOD__
);
477 # Another whitelist check in case oldid is altering the title
478 if ( !$this->getTitle()->userCanRead() ) {
479 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
480 $wgOut->loginToUse();
483 wfProfileOut( __METHOD__
);
487 # Are we looking at an old revision
488 if ( $oldid && !is_null( $this->mRevision
) ) {
489 $this->setOldSubtitle( $oldid );
491 if ( !$this->showDeletedRevisionHeader() ) {
492 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
493 wfProfileOut( __METHOD__
);
497 # If this "old" version is the current, then try the parser cache...
498 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
499 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
500 if ( $this->mParserOutput
) {
501 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
502 $wgOut->addParserOutput( $this->mParserOutput
);
503 $wgOut->setRevisionId( $this->mPage
->getLatest() );
510 # Ensure that UI elements requiring revision ID have
511 # the correct version information.
512 $wgOut->setRevisionId( $this->getRevIdFetched() );
514 # Pages containing custom CSS or JavaScript get special treatment
515 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
516 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
517 $this->showCssOrJsPage();
519 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
520 # Allow extensions do their own custom view for certain pages
523 $rt = Title
::newFromRedirectArray( $text );
525 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
526 # Viewing a redirect page (e.g. with parameter redirect=no)
527 # Don't append the subtitle if this was an old revision
528 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
529 # Parse just to get categories, displaytitle, etc.
530 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
531 $wgOut->addParserOutputNoText( $this->mParserOutput
);
537 # Run the parse, protected by a pool counter
538 wfDebug( __METHOD__
. ": doing uncached parse\n" );
540 $key = $parserCache->getKey( $this, $parserOptions );
541 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
543 if ( !$poolArticleView->execute() ) {
544 # Connection or timeout error
545 wfProfileOut( __METHOD__
);
551 # Should be unreachable, but just in case...
557 # Get the ParserOutput actually *displayed* here.
558 # Note that $this->mParserOutput is the *current* version output.
559 $pOutput = ( $outputDone instanceof ParserOutput
)
560 ?
$outputDone // object fetched by hook
561 : $this->mParserOutput
;
563 # Adjust title for main page & pages with displaytitle
565 $this->adjustDisplayTitle( $pOutput );
568 # For the main page, overwrite the <title> element with the con-
569 # tents of 'pagetitle-view-mainpage' instead of the default (if
571 # This message always exists because it is in the i18n files
572 if ( $this->getTitle()->isMainPage() ) {
573 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
574 if ( !$msg->isDisabled() ) {
575 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
579 # Check for any __NOINDEX__ tags on the page using $pOutput
580 $policy = $this->getRobotPolicy( 'view', $pOutput );
581 $wgOut->setIndexPolicy( $policy['index'] );
582 $wgOut->setFollowPolicy( $policy['follow'] );
584 $this->showViewFooter();
585 $this->mPage
->viewUpdates();
587 wfProfileOut( __METHOD__
);
591 * Adjust title for pages with displaytitle, -{T|}- or language conversion
592 * @param $pOutput ParserOutput
594 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
596 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
597 $titleText = $pOutput->getTitleText();
598 if ( strval( $titleText ) !== '' ) {
599 $wgOut->setPageTitle( $titleText );
604 * Show a diff page according to current request variables. For use within
605 * Article::view() only, other callers should use the DifferenceEngine class.
607 public function showDiffPage() {
608 global $wgRequest, $wgUser;
610 $diff = $wgRequest->getVal( 'diff' );
611 $rcid = $wgRequest->getVal( 'rcid' );
612 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
613 $purge = $wgRequest->getVal( 'action' ) == 'purge';
614 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
615 $oldid = $this->getOldID();
617 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
618 // DifferenceEngine directly fetched the revision:
619 $this->mRevIdFetched
= $de->mNewid
;
620 $de->showDiffPage( $diffOnly );
622 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
623 # Run view updates for current revision only
624 $this->mPage
->viewUpdates();
629 * Show a page view for a page formatted as CSS or JavaScript. To be called by
630 * Article::view() only.
632 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
635 protected function showCssOrJsPage() {
638 $dir = $this->getContext()->getLang()->getDir();
639 $lang = $this->getContext()->getLang()->getCode();
641 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
644 // Give hooks a chance to customise the output
645 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
646 // Wrap the whole lot in a <pre> and don't parse
648 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
649 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
650 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
651 $wgOut->addHTML( "\n</pre>\n" );
656 * Get the robot policy to be used for the current view
657 * @param $action String the action= GET parameter
658 * @param $pOutput ParserOutput
659 * @return Array the policy that should be set
660 * TODO: actions other than 'view'
662 public function getRobotPolicy( $action, $pOutput ) {
663 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
664 global $wgDefaultRobotPolicy, $wgRequest;
666 $ns = $this->getTitle()->getNamespace();
668 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
669 # Don't index user and user talk pages for blocked users (bug 11443)
670 if ( !$this->getTitle()->isSubpage() ) {
671 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
673 'index' => 'noindex',
674 'follow' => 'nofollow'
680 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
681 # Non-articles (special pages etc), and old revisions
683 'index' => 'noindex',
684 'follow' => 'nofollow'
686 } elseif ( $wgOut->isPrintable() ) {
687 # Discourage indexing of printable versions, but encourage following
689 'index' => 'noindex',
692 } elseif ( $wgRequest->getInt( 'curid' ) ) {
693 # For ?curid=x urls, disallow indexing
695 'index' => 'noindex',
700 # Otherwise, construct the policy based on the various config variables.
701 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
703 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
704 # Honour customised robot policies for this namespace
705 $policy = array_merge(
707 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
710 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
711 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
712 # a final sanity check that we have really got the parser output.
713 $policy = array_merge(
715 array( 'index' => $pOutput->getIndexPolicy() )
719 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
720 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
721 $policy = array_merge(
723 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
731 * Converts a String robot policy into an associative array, to allow
732 * merging of several policies using array_merge().
733 * @param $policy Mixed, returns empty array on null/false/'', transparent
734 * to already-converted arrays, converts String.
735 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
737 public static function formatRobotPolicy( $policy ) {
738 if ( is_array( $policy ) ) {
740 } elseif ( !$policy ) {
744 $policy = explode( ',', $policy );
745 $policy = array_map( 'trim', $policy );
748 foreach ( $policy as $var ) {
749 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
750 $arr['index'] = $var;
751 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
752 $arr['follow'] = $var;
760 * If this request is a redirect view, send "redirected from" subtitle to
761 * $wgOut. Returns true if the header was needed, false if this is not a
762 * redirect view. Handles both local and remote redirects.
766 public function showRedirectedFromHeader() {
767 global $wgOut, $wgRequest, $wgRedirectSources;
769 $rdfrom = $wgRequest->getVal( 'rdfrom' );
771 if ( isset( $this->mRedirectedFrom
) ) {
772 // This is an internally redirected page view.
773 // We'll need a backlink to the source page for navigation.
774 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
775 $redir = Linker
::link(
776 $this->mRedirectedFrom
,
779 array( 'redirect' => 'no' ),
780 array( 'known', 'noclasses' )
783 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
784 $wgOut->setSubtitle( $s );
786 // Set the fragment if one was specified in the redirect
787 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
788 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
789 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
792 // Add a <link rel="canonical"> tag
793 $wgOut->addLink( array( 'rel' => 'canonical',
794 'href' => $this->getTitle()->getLocalURL() )
799 } elseif ( $rdfrom ) {
800 // This is an externally redirected view, from some other wiki.
801 // If it was reported from a trusted site, supply a backlink.
802 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
803 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
804 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
805 $wgOut->setSubtitle( $s );
815 * Show a header specific to the namespace currently being viewed, like
816 * [[MediaWiki:Talkpagetext]]. For Article::view().
818 public function showNamespaceHeader() {
821 if ( $this->getTitle()->isTalkPage() ) {
822 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
823 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
829 * Show the footer section of an ordinary page view
831 public function showViewFooter() {
832 global $wgOut, $wgUseTrackbacks;
834 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
835 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
836 $wgOut->addWikiMsg( 'anontalkpagetext' );
839 # If we have been passed an &rcid= parameter, we want to give the user a
840 # chance to mark this new article as patrolled.
841 $this->showPatrolFooter();
844 if ( $wgUseTrackbacks ) {
845 $this->addTrackbacks();
848 wfRunHooks( 'ArticleViewFooter', array( $this ) );
853 * If patrol is possible, output a patrol UI box. This is called from the
854 * footer section of ordinary page views. If patrol is not possible or not
855 * desired, does nothing.
857 public function showPatrolFooter() {
858 global $wgOut, $wgRequest, $wgUser;
860 $rcid = $wgRequest->getVal( 'rcid' );
862 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
866 $token = $wgUser->editToken( $rcid );
867 $wgOut->preventClickjacking();
870 "<div class='patrollink'>" .
872 'markaspatrolledlink',
875 wfMsgHtml( 'markaspatrolledtext' ),
878 'action' => 'markpatrolled',
882 array( 'known', 'noclasses' )
890 * Show the error text for a missing article. For articles in the MediaWiki
891 * namespace, show the default message text. To be called from Article::view().
893 public function showMissingArticle() {
894 global $wgOut, $wgRequest, $wgUser;
896 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
897 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
898 $parts = explode( '/', $this->getTitle()->getText() );
899 $rootPart = $parts[0];
900 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
901 $ip = User
::isIP( $rootPart );
903 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
904 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
905 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
906 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
907 LogEventsList
::showLogExtract(
910 $user->getUserPage()->getPrefixedText(),
914 'showIfEmpty' => false,
916 'blocked-notice-logextract',
917 $user->getName() # Support GENDER in notice
924 wfRunHooks( 'ShowMissingArticle', array( $this ) );
926 # Show delete and move logs
927 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
929 'conds' => array( "log_action != 'revision'" ),
930 'showIfEmpty' => false,
931 'msgKey' => array( 'moveddeleted-notice' ) )
935 $oldid = $this->getOldID();
937 $text = wfMsgNoTrans( 'missing-article',
938 $this->getTitle()->getPrefixedText(),
939 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
940 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
941 // Use the default message text
942 $text = $this->getTitle()->getDefaultMessageText();
944 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
945 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
946 $errors = array_merge( $createErrors, $editErrors );
948 if ( !count( $errors ) ) {
949 $text = wfMsgNoTrans( 'noarticletext' );
951 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
954 $text = "<div class='noarticletext'>\n$text\n</div>";
956 if ( !$this->mPage
->hasViewableContent() ) {
957 // If there's no backing content, send a 404 Not Found
958 // for better machine handling of broken links.
959 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
962 $wgOut->addWikiText( $text );
966 * If the revision requested for view is deleted, check permissions.
967 * Send either an error message or a warning header to $wgOut.
969 * @return boolean true if the view is allowed, false if not.
971 public function showDeletedRevisionHeader() {
972 global $wgOut, $wgRequest;
974 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
979 // If the user is not allowed to see it...
980 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
981 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
982 'rev-deleted-text-permission' );
985 // If the user needs to confirm that they want to see it...
986 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
987 # Give explanation and add a link to view the revision...
988 $oldid = intval( $this->getOldID() );
989 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
990 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
991 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
992 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
993 array( $msg, $link ) );
996 // We are allowed to see...
998 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
999 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1000 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1007 * Execute the uncached parse for action=view
1009 public function doViewParse() {
1012 $oldid = $this->getOldID();
1013 $parserOptions = $this->getParserOptions();
1015 # Render printable version, use printable version cache
1016 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1018 # Don't show section-edit links on old revisions... this way lies madness.
1019 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1020 $parserOptions->setEditSection( false );
1023 $useParserCache = $this->useParserCache( $oldid );
1024 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1030 * Try to fetch an expired entry from the parser cache. If it is present,
1031 * output it and return true. If it is not present, output nothing and
1032 * return false. This is used as a callback function for
1033 * PoolCounter::executeProtected().
1037 public function tryDirtyCache() {
1039 $parserCache = ParserCache
::singleton();
1040 $options = $this->getParserOptions();
1042 if ( $wgOut->isPrintable() ) {
1043 $options->setIsPrintable( true );
1044 $options->setEditSection( false );
1047 $output = $parserCache->getDirty( $this, $options );
1050 wfDebug( __METHOD__
. ": sending dirty output\n" );
1051 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1052 $wgOut->setSquidMaxage( 0 );
1053 $this->mParserOutput
= $output;
1054 $wgOut->addParserOutput( $output );
1055 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1059 wfDebugLog( 'dirty', "dirty missing\n" );
1060 wfDebug( __METHOD__
. ": no dirty cache\n" );
1069 * @param $target Title|Array of destination(s) to redirect
1070 * @param $appendSubtitle Boolean [optional]
1071 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1072 * @return string containing HMTL with redirect link
1074 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1075 global $wgOut, $wgStylePath;
1077 if ( !is_array( $target ) ) {
1078 $target = array( $target );
1081 $lang = $this->getTitle()->getPageLanguage();
1082 $imageDir = $lang->getDir();
1084 if ( $appendSubtitle ) {
1085 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1088 // the loop prepends the arrow image before the link, so the first case needs to be outside
1089 $title = array_shift( $target );
1091 if ( $forceKnown ) {
1092 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1094 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1097 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1098 $alt = $lang->isRTL() ?
'←' : '→';
1099 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1100 foreach ( $target as $rt ) {
1101 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1102 if ( $forceKnown ) {
1103 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1105 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1109 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1110 return '<div class="redirectMsg">' .
1111 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1112 '<span class="redirectText">' . $link . '</span></div>';
1116 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1118 public function addTrackbacks() {
1121 $dbr = wfGetDB( DB_SLAVE
);
1122 $tbs = $dbr->select( 'trackbacks',
1123 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1124 array( 'tb_page' => $this->mPage
->getID() )
1127 if ( !$dbr->numRows( $tbs ) ) {
1131 $wgOut->preventClickjacking();
1134 foreach ( $tbs as $o ) {
1137 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1138 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1139 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1140 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1144 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1152 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1156 * Removes trackback record for current article from trackbacks table
1157 * @deprecated since 1.18
1159 public function deletetrackback() {
1160 return Action
::factory( 'deletetrackback', $this )->show();
1164 * Handle action=render
1167 public function render() {
1170 $wgOut->setArticleBodyOnly( true );
1175 * Handle action=purge
1177 public function purge() {
1178 return Action
::factory( 'purge', $this )->show();
1182 * Mark this particular edit/page as patrolled
1183 * @deprecated since 1.18
1185 public function markpatrolled() {
1186 Action
::factory( 'markpatrolled', $this )->show();
1190 * User-interface handler for the "watch" action.
1191 * Requires Request to pass a token as of 1.18.
1192 * @deprecated since 1.18
1194 public function watch() {
1195 Action
::factory( 'watch', $this )->show();
1199 * Add this page to $wgUser's watchlist
1201 * This is safe to be called multiple times
1203 * @return bool true on successful watch operation
1204 * @deprecated since 1.18
1206 public function doWatch() {
1208 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1212 * User interface handler for the "unwatch" action.
1213 * Requires Request to pass a token as of 1.18.
1214 * @deprecated since 1.18
1216 public function unwatch() {
1217 Action
::factory( 'unwatch', $this )->show();
1221 * Stop watching a page
1222 * @return bool true on successful unwatch
1223 * @deprecated since 1.18
1225 public function doUnwatch() {
1227 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1231 * action=protect handler
1233 public function protect() {
1234 $form = new ProtectionForm( $this );
1239 * action=unprotect handler (alias)
1241 public function unprotect() {
1246 * Info about this page
1247 * Called for ?action=info when $wgAllowPageInfo is on.
1249 public function info() {
1250 Action
::factory( 'info', $this )->show();
1254 * Overriden by ImagePage class, only present here to avoid a fatal error
1255 * Called for ?action=revert
1257 public function revert() {
1258 Action
::factory( 'revert', $this )->show();
1262 * User interface for rollback operations
1264 public function rollback() {
1265 Action
::factory( 'rollback', $this )->show();
1269 * Output a redirect back to the article.
1270 * This is typically used after an edit.
1272 * @deprecated in 1.18; call $wgOut->redirect() directly
1273 * @param $noRedir Boolean: add redirect=no
1274 * @param $sectionAnchor String: section to redirect to, including "#"
1275 * @param $extraQuery String: extra query params
1277 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1278 wfDeprecated( __METHOD__
);
1282 $query = 'redirect=no';
1284 $query .= "&$extraQuery";
1286 $query = $extraQuery;
1289 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1293 * UI entry point for page deletion
1295 public function delete() {
1296 global $wgOut, $wgRequest;
1298 $confirm = $wgRequest->wasPosted() &&
1299 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1301 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1302 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1304 $reason = $this->DeleteReasonList
;
1306 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1307 // Entry from drop down menu + additional comment
1308 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1309 } elseif ( $reason == 'other' ) {
1310 $reason = $this->DeleteReason
;
1313 # Flag to hide all contents of the archived revisions
1314 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1316 # This code desperately needs to be totally rewritten
1318 # Read-only check...
1319 if ( wfReadOnly() ) {
1320 $wgOut->readOnlyPage();
1326 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1328 if ( count( $permission_errors ) > 0 ) {
1329 $wgOut->showPermissionsErrorPage( $permission_errors );
1334 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1336 # Better double-check that it hasn't been deleted yet!
1337 $dbw = wfGetDB( DB_MASTER
);
1338 $conds = $this->getTitle()->pageCond();
1339 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1340 if ( $latest === false ) {
1341 $wgOut->showFatalError(
1344 array( 'class' => 'error mw-error-cannotdelete' ),
1345 wfMsgExt( 'cannotdelete', array( 'parse' ),
1346 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1349 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1350 LogEventsList
::showLogExtract(
1353 $this->getTitle()->getPrefixedText()
1359 # Hack for big sites
1360 $bigHistory = $this->mPage
->isBigDeletion();
1361 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1362 global $wgLang, $wgDeleteRevisionsLimit;
1364 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1365 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1371 $this->doDelete( $reason, $suppress );
1373 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1375 } elseif ( $this->getTitle()->userIsWatching() ) {
1382 // Generate deletion reason
1383 $hasHistory = false;
1385 $reason = $this->generateReason( $hasHistory );
1388 // If the page has a history, insert a warning
1389 if ( $hasHistory && !$confirm ) {
1392 $revisions = $this->mPage
->estimateRevisionCount();
1393 // @todo FIXME: i18n issue/patchwork message
1394 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1395 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1396 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1397 wfMsgHtml( 'history' ),
1398 array( 'rel' => 'archives' ),
1399 array( 'action' => 'history' ) ) .
1403 if ( $bigHistory ) {
1404 global $wgDeleteRevisionsLimit;
1405 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1406 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1410 return $this->confirmDelete( $reason );
1414 * Output deletion confirmation dialog
1415 * @todo FIXME: Move to another file?
1416 * @param $reason String: prefilled reason
1418 public function confirmDelete( $reason ) {
1421 wfDebug( "Article::confirmDelete\n" );
1423 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1424 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1425 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1426 $wgOut->addWikiMsg( 'confirmdeletetext' );
1428 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1430 if ( $this->getContext()->getUser()->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 = $this->getContext()->getUser()->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 ( $this->getContext()->getUser()->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', $this->getContext()->getUser()->editToken() ) .
1497 Xml
::closeElement( 'form' );
1499 if ( $this->getContext()->getUser()->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 public function doDelete( $reason, $suppress = false ) {
1523 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1526 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1527 $deleted = $this->getTitle()->getPrefixedText();
1529 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1530 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1532 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1534 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1535 $wgOut->returnToMain( false );
1537 if ( $error == '' ) {
1538 $wgOut->showFatalError(
1541 array( 'class' => 'error mw-error-cannotdelete' ),
1542 wfMsgExt( 'cannotdelete', array( 'parse' ),
1543 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1547 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1549 LogEventsList
::showLogExtract(
1552 $this->getTitle()->getPrefixedText()
1555 $wgOut->showFatalError( $error );
1561 * Generate the navigation links when browsing through an article revisions
1562 * It shows the information as:
1563 * Revision as of \<date\>; view current revision
1564 * \<- Previous version | Next Version -\>
1566 * @param $oldid String: revision ID of this article revision
1568 public function setOldSubtitle( $oldid = 0 ) {
1569 global $wgLang, $wgOut, $wgUser, $wgRequest;
1571 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1575 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1577 # Cascade unhide param in links for easy deletion browsing
1578 $extraParams = array();
1579 if ( $wgRequest->getVal( 'unhide' ) ) {
1580 $extraParams['unhide'] = 1;
1583 $revision = Revision
::newFromId( $oldid );
1584 $timestamp = $revision->getTimestamp();
1586 $current = ( $oldid == $this->mPage
->getLatest() );
1587 $td = $wgLang->timeanddate( $timestamp, true );
1588 $tddate = $wgLang->date( $timestamp, true );
1589 $tdtime = $wgLang->time( $timestamp, true );
1592 ?
wfMsgHtml( 'currentrevisionlink' )
1595 wfMsgHtml( 'currentrevisionlink' ),
1598 array( 'known', 'noclasses' )
1601 ?
wfMsgHtml( 'diff' )
1604 wfMsgHtml( 'diff' ),
1610 array( 'known', 'noclasses' )
1612 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1616 wfMsgHtml( 'previousrevision' ),
1619 'direction' => 'prev',
1622 array( 'known', 'noclasses' )
1624 : wfMsgHtml( 'previousrevision' );
1628 wfMsgHtml( 'diff' ),
1634 array( 'known', 'noclasses' )
1636 : wfMsgHtml( 'diff' );
1637 $nextlink = $current
1638 ?
wfMsgHtml( 'nextrevision' )
1641 wfMsgHtml( 'nextrevision' ),
1644 'direction' => 'next',
1647 array( 'known', 'noclasses' )
1649 $nextdiff = $current
1650 ?
wfMsgHtml( 'diff' )
1653 wfMsgHtml( 'diff' ),
1659 array( 'known', 'noclasses' )
1664 // User can delete revisions or view deleted revisions...
1665 $canHide = $wgUser->isAllowed( 'deleterevision' );
1666 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1667 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1668 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1671 'type' => 'revision',
1672 'target' => $this->getTitle()->getPrefixedDbkey(),
1675 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1680 # Show user links if allowed to see them. If hidden, then show them only if requested...
1681 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1683 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1684 ?
'revision-info-current'
1687 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1690 array( 'parseinline', 'replaceafter' ),
1696 $revision->getUser()
1699 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1700 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1702 $wgOut->setSubtitle( $r );
1705 /* Caching functions */
1708 * checkLastModified returns true if it has taken care of all
1709 * output to the client that is necessary for this request.
1710 * (that is, it has sent a cached version of the page)
1712 * @return boolean true if cached version send, false otherwise
1714 protected function tryFileCache() {
1715 static $called = false;
1718 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1723 if ( $this->isFileCacheable() ) {
1724 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1725 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1726 wfDebug( "Article::tryFileCache(): about to load file\n" );
1727 $cache->loadFromFileCache( $this->getContext() );
1730 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1731 ob_start( array( &$cache, 'saveToFileCache' ) );
1734 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1741 * Check if the page can be cached
1744 public function isFileCacheable() {
1747 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1748 $cacheable = $this->mPage
->getID()
1749 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1750 // Extension may have reason to disable file caching on some pages.
1752 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1762 * Add the primary page-view wikitext to the output buffer
1763 * Saves the text into the parser cache if possible.
1764 * Updates templatelinks if it is out of date.
1766 * @param $text String
1767 * @param $cache Boolean
1768 * @param $parserOptions mixed ParserOptions object, or boolean false
1770 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1773 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1775 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1777 $wgOut->addParserOutput( $this->mParserOutput
);
1781 * Lightweight method to get the parser output for a page, checking the parser cache
1782 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1783 * consider, so it's not appropriate to use there.
1785 * @since 1.16 (r52326) for LiquidThreads
1787 * @param $oldid mixed integer Revision ID or null
1788 * @param $user User The relevant user
1789 * @return ParserOutput or false if the given revsion ID is not found
1791 public function getParserOutput( $oldid = null, User
$user = null ) {
1792 global $wgEnableParserCache, $wgUser;
1793 $user = is_null( $user ) ?
$wgUser : $user;
1795 wfProfileIn( __METHOD__
);
1796 // Should the parser cache be used?
1797 $useParserCache = $wgEnableParserCache &&
1798 $user->getStubThreshold() == 0 &&
1799 $this->mPage
->exists() &&
1802 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1804 if ( $user->getStubThreshold() ) {
1805 wfIncrStats( 'pcache_miss_stub' );
1808 if ( $useParserCache ) {
1809 $options = $this->mPage
->makeParserOptions( $user );
1810 $parserOutput = ParserCache
::singleton()->get( $this, $options );
1811 if ( $parserOutput !== false ) {
1812 wfProfileOut( __METHOD__
);
1813 return $parserOutput;
1817 // Cache miss; parse and output it.
1818 if ( $oldid === null ) {
1819 $text = $this->mPage
->getRawText();
1821 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1822 if ( $rev === null ) {
1823 wfProfileOut( __METHOD__
);
1826 $text = $rev->getText();
1829 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1830 wfProfileOut( __METHOD__
);
1835 * This does all the heavy lifting for outputWikitext, except it returns the parser
1836 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1837 * say, embedding thread pages within a discussion system (LiquidThreads)
1839 * @param $text string
1840 * @param $cache boolean
1841 * @param $parserOptions parsing options, defaults to false
1842 * @return ParserOutput
1844 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1845 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1847 if ( !$parserOptions ) {
1848 $parserOptions = $this->getParserOptions();
1852 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1853 $parserOptions, true, true, $this->getRevIdFetched() );
1858 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1859 $this->getTitle()->getPrefixedDBkey() ) );
1862 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1863 $parserCache = ParserCache
::singleton();
1864 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1867 // Make sure file cache is not used on uncacheable content.
1868 // Output that has magic words in it can still use the parser cache
1869 // (if enabled), though it will generally expire sooner.
1870 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1871 $wgUseFileCache = false;
1874 if ( $this->isCurrent() ) {
1875 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1878 return $this->mParserOutput
;
1882 * Get parser options suitable for rendering the primary article wikitext
1883 * @return mixed ParserOptions object or boolean false
1885 public function getParserOptions() {
1887 if ( !$this->mParserOptions
) {
1888 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1890 // Clone to allow modifications of the return value without affecting cache
1891 return clone $this->mParserOptions
;
1895 * Sets the context this Article is executed in
1897 * @param $context IContextSource
1900 public function setContext( $context ) {
1901 $this->mContext
= $context;
1905 * Gets the context this Article is executed in
1907 * @return IContextSource
1910 public function getContext() {
1911 if ( $this->mContext
instanceof IContextSource
) {
1912 return $this->mContext
;
1914 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1915 return RequestContext
::getMain();
1920 * Use PHP's magic __get handler to handle accessing of
1921 * raw WikiPage fields for backwards compatibility.
1923 * @param $fname String Field name
1925 public function __get( $fname ) {
1926 if ( property_exists( $this->mPage
, $fname ) ) {
1927 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1928 return $this->mPage
->$fname;
1930 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1934 * Use PHP's magic __set handler to handle setting of
1935 * raw WikiPage fields for backwards compatibility.
1937 * @param $fname String Field name
1938 * @param $fvalue mixed New value
1940 public function __set( $fname, $fvalue ) {
1941 if ( property_exists( $this->mPage
, $fname ) ) {
1942 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1943 $this->mPage
->$fname = $fvalue;
1944 // Note: extensions may want to toss on new fields
1945 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1946 $this->mPage
->$fname = $fvalue;
1948 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1953 * Use PHP's magic __call handler to transform instance calls to
1954 * WikiPage functions for backwards compatibility.
1956 * @param $fname String Name of called method
1957 * @param $args Array Arguments to the method
1959 public function __call( $fname, $args ) {
1960 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1961 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1962 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1964 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1967 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1968 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1969 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1972 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1973 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1976 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1978 $user = is_null( $user ) ?
$wgUser : $user;
1979 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1982 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1984 $guser = is_null( $guser ) ?
$wgUser : $guser;
1985 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1988 public function generateReason( &$hasHistory ) {
1989 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1992 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1993 public static function selectFields() {
1994 return WikiPage
::selectFields();
1997 public static function onArticleCreate( $title ) {
1998 return WikiPage
::onArticleCreate( $title );
2001 public static function onArticleDelete( $title ) {
2002 return WikiPage
::onArticleDelete( $title );
2005 public static function onArticleEdit( $title ) {
2006 return WikiPage
::onArticleEdit( $title );
2009 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2010 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2015 class PoolWorkArticleView
extends PoolCounterWork
{
2022 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2023 parent
::__construct( 'ArticleView', $key );
2024 $this->mArticle
= $article;
2025 $this->cacheable
= $useParserCache;
2026 $this->parserOptions
= $parserOptions;
2030 return $this->mArticle
->doViewParse();
2033 function getCachedWork() {
2036 $parserCache = ParserCache
::singleton();
2037 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2039 if ( $this->mArticle
->mParserOutput
!== false ) {
2040 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2041 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2042 # Ensure that UI elements requiring revision ID have
2043 # the correct version information.
2044 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2050 function fallback() {
2051 return $this->mArticle
->tryDirtyCache();
2055 * @param $status Status
2057 function error( $status ) {
2060 $wgOut->clearHTML(); // for release() errors
2061 $wgOut->enableClientCache( false );
2062 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2064 $errortext = $status->getWikiText( false, 'view-pool-error' );
2065 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );