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 );
82 protected function newPage( Title
$title ) {
83 return new WikiPage( $title );
87 * Constructor from a page id
88 * @param $id Int article ID to load
89 * @return Article|null
91 public static function newFromID( $id ) {
92 $t = Title
::newFromID( $id );
93 # @todo FIXME: Doesn't inherit right
94 return $t == null ?
null : new self( $t );
95 # return $t == null ? null : new static( $t ); // PHP 5.3
99 * Create an Article object of the appropriate class for the given page.
101 * @param $title Title
102 * @param $context IContextSource
103 * @return Article object
105 public static function newFromTitle( $title, IContextSource
$context ) {
106 if ( NS_MEDIA
== $title->getNamespace() ) {
107 // FIXME: where should this go?
108 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
112 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
114 switch( $title->getNamespace() ) {
116 $page = new ImagePage( $title );
119 $page = new CategoryPage( $title );
122 $page = new Article( $title );
125 $page->setContext( $context );
131 * Tell the page view functions that this view was redirected
132 * from another page on the wiki.
133 * @param $from Title object.
135 public function setRedirectedFrom( Title
$from ) {
136 $this->mRedirectedFrom
= $from;
140 * Get the title object of the article
141 * @return Title object of this page
143 public function getTitle() {
144 return $this->mPage
->getTitle();
151 public function clear() {
152 $this->mContentLoaded
= false;
154 $this->mRedirectedFrom
= null; # Title object if set
155 $this->mRevIdFetched
= 0;
156 $this->mRedirectUrl
= false;
158 $this->mPage
->clear();
162 * Note that getContent/loadContent do not follow redirects anymore.
163 * If you need to fetch redirectable content easily, try
164 * the shortcut in Article::followRedirect()
166 * This function has side effects! Do not use this function if you
167 * only want the real revision text if any.
169 * @return Return the text of this revision
171 public function getContent() {
174 wfProfileIn( __METHOD__
);
176 if ( $this->mPage
->getID() === 0 ) {
177 # If this is a MediaWiki:x message, then load the messages
178 # and return the message value for x.
179 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
180 $text = $this->getTitle()->getDefaultMessageText();
181 if ( $text === false ) {
185 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
187 wfProfileOut( __METHOD__
);
191 $this->loadContent();
192 wfProfileOut( __METHOD__
);
194 return $this->mContent
;
199 * @return int The oldid of the article that is to be shown, 0 for the
202 public function getOldID() {
203 if ( is_null( $this->mOldId
) ) {
204 $this->mOldId
= $this->getOldIDFromRequest();
207 return $this->mOldId
;
211 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
213 * @return int The old id for the request
215 public function getOldIDFromRequest() {
218 $this->mRedirectUrl
= false;
220 $oldid = $wgRequest->getVal( 'oldid' );
222 if ( isset( $oldid ) ) {
223 $oldid = intval( $oldid );
224 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
225 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
229 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
231 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
232 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
247 * Load the revision (including text) into this object
249 function loadContent() {
250 if ( $this->mContentLoaded
) {
254 wfProfileIn( __METHOD__
);
256 $this->fetchContent( $this->getOldID() );
258 wfProfileOut( __METHOD__
);
262 * Get text of an article from database
263 * Does *NOT* follow redirects.
265 * @param $oldid Int: 0 for whatever the latest revision is
266 * @return mixed string containing article contents, or false if null
268 function fetchContent( $oldid = 0 ) {
269 if ( $this->mContentLoaded
) {
270 return $this->mContent
;
273 # Pre-fill content with error message so that if something
274 # fails we'll have something telling us what we intended.
275 $t = $this->getTitle()->getPrefixedText();
276 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
277 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
280 $revision = Revision
::newFromId( $oldid );
282 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
285 // Revision title doesn't match the page title given?
286 if ( $this->mPage
->getID() != $revision->getPage() ) {
287 $function = array( get_class( $this->mPage
), 'newFromID' );
288 $this->mPage
= call_user_func( $function, $revision->getPage() );
289 if ( !$this->mPage
->getId() ) {
290 wfDebug( __METHOD__
. " failed to get page data linked to revision id $oldid\n" );
295 if ( !$this->mPage
->getLatest() ) {
296 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
300 $revision = $this->mPage
->getRevision();
302 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
307 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
308 // We should instead work with the Revision object when we need it...
309 $this->mContent
= $revision->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
311 $this->mRevIdFetched
= $revision->getId();
312 $this->mContentLoaded
= true;
313 $this->mRevision
=& $revision;
315 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
317 return $this->mContent
;
322 * @deprecated since 1.18
324 public function forUpdate() {
325 wfDeprecated( __METHOD__
);
329 * Returns true if the currently-referenced revision is the current edit
330 * to this page (and it exists).
333 public function isCurrent() {
334 # If no oldid, this is the current version.
335 if ( $this->getOldID() == 0 ) {
339 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
343 * Use this to fetch the rev ID used on page views
345 * @return int revision ID of last article revision
347 public function getRevIdFetched() {
348 if ( $this->mRevIdFetched
) {
349 return $this->mRevIdFetched
;
351 return $this->mPage
->getLatest();
356 * This is the default action of the index.php entry point: just view the
357 * page of the given title.
359 public function view() {
360 global $wgUser, $wgOut, $wgRequest, $wgParser;
361 global $wgUseFileCache, $wgUseETag;
363 wfProfileIn( __METHOD__
);
365 # Get variables from query string
366 $oldid = $this->getOldID();
368 # getOldID may want us to redirect somewhere else
369 if ( $this->mRedirectUrl
) {
370 $wgOut->redirect( $this->mRedirectUrl
);
371 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
372 wfProfileOut( __METHOD__
);
377 # Set page title (may be overridden by DISPLAYTITLE)
378 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
380 # If we got diff in the query, we want to see a diff page instead of the article.
381 if ( $wgRequest->getCheck( 'diff' ) ) {
382 wfDebug( __METHOD__
. ": showing diff page\n" );
383 $this->showDiffPage();
384 wfProfileOut( __METHOD__
);
389 $wgOut->setArticleFlag( true );
390 # Allow frames by default
391 $wgOut->allowClickjacking();
393 $parserCache = ParserCache
::singleton();
395 $parserOptions = $this->getParserOptions();
396 # Render printable version, use printable version cache
397 if ( $wgOut->isPrintable() ) {
398 $parserOptions->setIsPrintable( true );
399 $parserOptions->setEditSection( false );
400 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
401 $parserOptions->setEditSection( false );
404 # Try client and file cache
405 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
407 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
410 # Is it client cached?
411 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
412 wfDebug( __METHOD__
. ": done 304\n" );
413 wfProfileOut( __METHOD__
);
417 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
418 wfDebug( __METHOD__
. ": done file cache\n" );
419 # tell wgOut that output is taken care of
421 $this->mPage
->viewUpdates();
422 wfProfileOut( __METHOD__
);
428 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
429 $parserOptions->setEditSection( false );
432 # Should the parser cache be used?
433 $useParserCache = $this->useParserCache( $oldid );
434 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
435 if ( $wgUser->getStubThreshold() ) {
436 wfIncrStats( 'pcache_miss_stub' );
439 $wasRedirected = $this->showRedirectedFromHeader();
440 $this->showNamespaceHeader();
442 # Iterate through the possible ways of constructing the output text.
443 # Keep going until $outputDone is set, or we run out of things to do.
446 $this->mParserOutput
= false;
448 while ( !$outputDone && ++
$pass ) {
451 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
454 # Try the parser cache
455 if ( $useParserCache ) {
456 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
458 if ( $this->mParserOutput
!== false ) {
459 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
460 $wgOut->addParserOutput( $this->mParserOutput
);
461 # Ensure that UI elements requiring revision ID have
462 # the correct version information.
463 $wgOut->setRevisionId( $this->mPage
->getLatest() );
465 # Preload timestamp to avoid a DB hit
466 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
467 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
473 $text = $this->getContent();
474 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
475 wfDebug( __METHOD__
. ": showing missing article\n" );
476 $this->showMissingArticle();
477 wfProfileOut( __METHOD__
);
481 # Another whitelist check in case oldid is altering the title
482 if ( !$this->getTitle()->userCanRead() ) {
483 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
484 $wgOut->loginToUse();
487 wfProfileOut( __METHOD__
);
491 # Are we looking at an old revision
492 if ( $oldid && !is_null( $this->mRevision
) ) {
493 $this->setOldSubtitle( $oldid );
495 if ( !$this->showDeletedRevisionHeader() ) {
496 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
497 wfProfileOut( __METHOD__
);
501 # If this "old" version is the current, then try the parser cache...
502 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
503 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
504 if ( $this->mParserOutput
) {
505 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
506 $wgOut->addParserOutput( $this->mParserOutput
);
507 $wgOut->setRevisionId( $this->mPage
->getLatest() );
514 # Ensure that UI elements requiring revision ID have
515 # the correct version information.
516 $wgOut->setRevisionId( $this->getRevIdFetched() );
518 # Pages containing custom CSS or JavaScript get special treatment
519 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
520 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
521 $this->showCssOrJsPage();
523 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
524 # Allow extensions do their own custom view for certain pages
527 $rt = Title
::newFromRedirectArray( $text );
529 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
530 # Viewing a redirect page (e.g. with parameter redirect=no)
531 # Don't append the subtitle if this was an old revision
532 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
533 # Parse just to get categories, displaytitle, etc.
534 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
535 $wgOut->addParserOutputNoText( $this->mParserOutput
);
541 # Run the parse, protected by a pool counter
542 wfDebug( __METHOD__
. ": doing uncached parse\n" );
544 $key = $parserCache->getKey( $this, $parserOptions );
545 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
547 if ( !$poolArticleView->execute() ) {
548 # Connection or timeout error
549 wfProfileOut( __METHOD__
);
555 # Should be unreachable, but just in case...
561 # Get the ParserOutput actually *displayed* here.
562 # Note that $this->mParserOutput is the *current* version output.
563 $pOutput = ( $outputDone instanceof ParserOutput
)
564 ?
$outputDone // object fetched by hook
565 : $this->mParserOutput
;
567 # Adjust title for main page & pages with displaytitle
569 $this->adjustDisplayTitle( $pOutput );
572 # For the main page, overwrite the <title> element with the con-
573 # tents of 'pagetitle-view-mainpage' instead of the default (if
575 # This message always exists because it is in the i18n files
576 if ( $this->getTitle()->isMainPage() ) {
577 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
578 if ( !$msg->isDisabled() ) {
579 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
583 # Check for any __NOINDEX__ tags on the page using $pOutput
584 $policy = $this->getRobotPolicy( 'view', $pOutput );
585 $wgOut->setIndexPolicy( $policy['index'] );
586 $wgOut->setFollowPolicy( $policy['follow'] );
588 $this->showViewFooter();
589 $this->mPage
->viewUpdates();
591 wfProfileOut( __METHOD__
);
595 * Adjust title for pages with displaytitle, -{T|}- or language conversion
596 * @param $pOutput ParserOutput
598 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
600 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
601 $titleText = $pOutput->getTitleText();
602 if ( strval( $titleText ) !== '' ) {
603 $wgOut->setPageTitle( $titleText );
608 * Show a diff page according to current request variables. For use within
609 * Article::view() only, other callers should use the DifferenceEngine class.
611 public function showDiffPage() {
612 global $wgRequest, $wgUser;
614 $diff = $wgRequest->getVal( 'diff' );
615 $rcid = $wgRequest->getVal( 'rcid' );
616 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
617 $purge = $wgRequest->getVal( 'action' ) == 'purge';
618 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
619 $oldid = $this->getOldID();
621 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
622 // DifferenceEngine directly fetched the revision:
623 $this->mRevIdFetched
= $de->mNewid
;
624 $de->showDiffPage( $diffOnly );
626 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
627 # Run view updates for current revision only
628 $this->mPage
->viewUpdates();
633 * Show a page view for a page formatted as CSS or JavaScript. To be called by
634 * Article::view() only.
636 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
639 protected function showCssOrJsPage() {
642 $dir = $this->getContext()->getLang()->getDir();
643 $lang = $this->getContext()->getLang()->getCode();
645 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
648 // Give hooks a chance to customise the output
649 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
650 // Wrap the whole lot in a <pre> and don't parse
652 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
653 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
654 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
655 $wgOut->addHTML( "\n</pre>\n" );
660 * Get the robot policy to be used for the current view
661 * @param $action String the action= GET parameter
662 * @param $pOutput ParserOutput
663 * @return Array the policy that should be set
664 * TODO: actions other than 'view'
666 public function getRobotPolicy( $action, $pOutput ) {
667 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
668 global $wgDefaultRobotPolicy, $wgRequest;
670 $ns = $this->getTitle()->getNamespace();
672 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
673 # Don't index user and user talk pages for blocked users (bug 11443)
674 if ( !$this->getTitle()->isSubpage() ) {
675 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
677 'index' => 'noindex',
678 'follow' => 'nofollow'
684 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
685 # Non-articles (special pages etc), and old revisions
687 'index' => 'noindex',
688 'follow' => 'nofollow'
690 } elseif ( $wgOut->isPrintable() ) {
691 # Discourage indexing of printable versions, but encourage following
693 'index' => 'noindex',
696 } elseif ( $wgRequest->getInt( 'curid' ) ) {
697 # For ?curid=x urls, disallow indexing
699 'index' => 'noindex',
704 # Otherwise, construct the policy based on the various config variables.
705 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
707 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
708 # Honour customised robot policies for this namespace
709 $policy = array_merge(
711 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
714 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
715 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
716 # a final sanity check that we have really got the parser output.
717 $policy = array_merge(
719 array( 'index' => $pOutput->getIndexPolicy() )
723 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
724 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
725 $policy = array_merge(
727 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
735 * Converts a String robot policy into an associative array, to allow
736 * merging of several policies using array_merge().
737 * @param $policy Mixed, returns empty array on null/false/'', transparent
738 * to already-converted arrays, converts String.
739 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
741 public static function formatRobotPolicy( $policy ) {
742 if ( is_array( $policy ) ) {
744 } elseif ( !$policy ) {
748 $policy = explode( ',', $policy );
749 $policy = array_map( 'trim', $policy );
752 foreach ( $policy as $var ) {
753 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
754 $arr['index'] = $var;
755 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
756 $arr['follow'] = $var;
764 * If this request is a redirect view, send "redirected from" subtitle to
765 * $wgOut. Returns true if the header was needed, false if this is not a
766 * redirect view. Handles both local and remote redirects.
770 public function showRedirectedFromHeader() {
771 global $wgOut, $wgRequest, $wgRedirectSources;
773 $rdfrom = $wgRequest->getVal( 'rdfrom' );
775 if ( isset( $this->mRedirectedFrom
) ) {
776 // This is an internally redirected page view.
777 // We'll need a backlink to the source page for navigation.
778 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
779 $redir = Linker
::link(
780 $this->mRedirectedFrom
,
783 array( 'redirect' => 'no' ),
784 array( 'known', 'noclasses' )
787 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
788 $wgOut->setSubtitle( $s );
790 // Set the fragment if one was specified in the redirect
791 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
792 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
793 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
796 // Add a <link rel="canonical"> tag
797 $wgOut->addLink( array( 'rel' => 'canonical',
798 'href' => $this->getTitle()->getLocalURL() )
803 } elseif ( $rdfrom ) {
804 // This is an externally redirected view, from some other wiki.
805 // If it was reported from a trusted site, supply a backlink.
806 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
807 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
808 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
809 $wgOut->setSubtitle( $s );
819 * Show a header specific to the namespace currently being viewed, like
820 * [[MediaWiki:Talkpagetext]]. For Article::view().
822 public function showNamespaceHeader() {
825 if ( $this->getTitle()->isTalkPage() ) {
826 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
827 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
833 * Show the footer section of an ordinary page view
835 public function showViewFooter() {
836 global $wgOut, $wgUseTrackbacks;
838 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
839 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
840 $wgOut->addWikiMsg( 'anontalkpagetext' );
843 # If we have been passed an &rcid= parameter, we want to give the user a
844 # chance to mark this new article as patrolled.
845 $this->showPatrolFooter();
848 if ( $wgUseTrackbacks ) {
849 $this->addTrackbacks();
852 wfRunHooks( 'ArticleViewFooter', array( $this ) );
857 * If patrol is possible, output a patrol UI box. This is called from the
858 * footer section of ordinary page views. If patrol is not possible or not
859 * desired, does nothing.
861 public function showPatrolFooter() {
862 global $wgOut, $wgRequest, $wgUser;
864 $rcid = $wgRequest->getVal( 'rcid' );
866 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
870 $token = $wgUser->editToken( $rcid );
871 $wgOut->preventClickjacking();
874 "<div class='patrollink'>" .
876 'markaspatrolledlink',
879 wfMsgHtml( 'markaspatrolledtext' ),
882 'action' => 'markpatrolled',
886 array( 'known', 'noclasses' )
894 * Show the error text for a missing article. For articles in the MediaWiki
895 * namespace, show the default message text. To be called from Article::view().
897 public function showMissingArticle() {
898 global $wgOut, $wgRequest, $wgUser;
900 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
901 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
902 $parts = explode( '/', $this->getTitle()->getText() );
903 $rootPart = $parts[0];
904 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
905 $ip = User
::isIP( $rootPart );
907 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
908 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
909 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
910 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
911 LogEventsList
::showLogExtract(
914 $user->getUserPage()->getPrefixedText(),
918 'showIfEmpty' => false,
920 'blocked-notice-logextract',
921 $user->getName() # Support GENDER in notice
928 wfRunHooks( 'ShowMissingArticle', array( $this ) );
930 # Show delete and move logs
931 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
933 'conds' => array( "log_action != 'revision'" ),
934 'showIfEmpty' => false,
935 'msgKey' => array( 'moveddeleted-notice' ) )
939 $oldid = $this->getOldID();
941 $text = wfMsgNoTrans( 'missing-article',
942 $this->getTitle()->getPrefixedText(),
943 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
944 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
945 // Use the default message text
946 $text = $this->getTitle()->getDefaultMessageText();
948 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
949 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
950 $errors = array_merge( $createErrors, $editErrors );
952 if ( !count( $errors ) ) {
953 $text = wfMsgNoTrans( 'noarticletext' );
955 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
958 $text = "<div class='noarticletext'>\n$text\n</div>";
960 if ( !$this->mPage
->hasViewableContent() ) {
961 // If there's no backing content, send a 404 Not Found
962 // for better machine handling of broken links.
963 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
966 $wgOut->addWikiText( $text );
970 * If the revision requested for view is deleted, check permissions.
971 * Send either an error message or a warning header to $wgOut.
973 * @return boolean true if the view is allowed, false if not.
975 public function showDeletedRevisionHeader() {
976 global $wgOut, $wgRequest;
978 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
983 // If the user is not allowed to see it...
984 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
985 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
986 'rev-deleted-text-permission' );
989 // If the user needs to confirm that they want to see it...
990 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
991 # Give explanation and add a link to view the revision...
992 $oldid = intval( $this->getOldID() );
993 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
994 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
995 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
996 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
997 array( $msg, $link ) );
1000 // We are allowed to see...
1002 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1003 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1004 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1011 * Execute the uncached parse for action=view
1014 public function doViewParse() {
1017 $oldid = $this->getOldID();
1018 $parserOptions = $this->getParserOptions();
1020 # Render printable version, use printable version cache
1021 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1023 # Don't show section-edit links on old revisions... this way lies madness.
1024 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1025 $parserOptions->setEditSection( false );
1028 $useParserCache = $this->useParserCache( $oldid );
1029 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1035 * Try to fetch an expired entry from the parser cache. If it is present,
1036 * output it and return true. If it is not present, output nothing and
1037 * return false. This is used as a callback function for
1038 * PoolCounter::executeProtected().
1042 public function tryDirtyCache() {
1044 $parserCache = ParserCache
::singleton();
1045 $options = $this->getParserOptions();
1047 if ( $wgOut->isPrintable() ) {
1048 $options->setIsPrintable( true );
1049 $options->setEditSection( false );
1052 $output = $parserCache->getDirty( $this, $options );
1055 wfDebug( __METHOD__
. ": sending dirty output\n" );
1056 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1057 $wgOut->setSquidMaxage( 0 );
1058 $this->mParserOutput
= $output;
1059 $wgOut->addParserOutput( $output );
1060 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1064 wfDebugLog( 'dirty', "dirty missing\n" );
1065 wfDebug( __METHOD__
. ": no dirty cache\n" );
1074 * @param $target Title|Array of destination(s) to redirect
1075 * @param $appendSubtitle Boolean [optional]
1076 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1077 * @return string containing HMTL with redirect link
1079 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1080 global $wgOut, $wgStylePath;
1082 if ( !is_array( $target ) ) {
1083 $target = array( $target );
1086 $lang = $this->getTitle()->getPageLanguage();
1087 $imageDir = $lang->getDir();
1089 if ( $appendSubtitle ) {
1090 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1093 // the loop prepends the arrow image before the link, so the first case needs to be outside
1094 $title = array_shift( $target );
1096 if ( $forceKnown ) {
1097 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1099 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1102 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1103 $alt = $lang->isRTL() ?
'←' : '→';
1104 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1105 foreach ( $target as $rt ) {
1106 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1107 if ( $forceKnown ) {
1108 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1110 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1114 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1115 return '<div class="redirectMsg">' .
1116 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1117 '<span class="redirectText">' . $link . '</span></div>';
1121 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1123 public function addTrackbacks() {
1126 $dbr = wfGetDB( DB_SLAVE
);
1127 $tbs = $dbr->select( 'trackbacks',
1128 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1129 array( 'tb_page' => $this->mPage
->getID() )
1132 if ( !$dbr->numRows( $tbs ) ) {
1136 $wgOut->preventClickjacking();
1139 foreach ( $tbs as $o ) {
1142 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1143 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1144 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1145 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1149 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1157 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1161 * Removes trackback record for current article from trackbacks table
1162 * @deprecated since 1.18
1164 public function deletetrackback() {
1165 return Action
::factory( 'deletetrackback', $this )->show();
1169 * Handle action=render
1172 public function render() {
1175 $wgOut->setArticleBodyOnly( true );
1180 * Handle action=purge
1182 public function purge() {
1183 return Action
::factory( 'purge', $this )->show();
1187 * Mark this particular edit/page as patrolled
1188 * @deprecated since 1.18
1190 public function markpatrolled() {
1191 Action
::factory( 'markpatrolled', $this )->show();
1195 * User-interface handler for the "watch" action.
1196 * Requires Request to pass a token as of 1.18.
1197 * @deprecated since 1.18
1199 public function watch() {
1200 Action
::factory( 'watch', $this )->show();
1204 * Add this page to $wgUser's watchlist
1206 * This is safe to be called multiple times
1208 * @return bool true on successful watch operation
1209 * @deprecated since 1.18
1211 public function doWatch() {
1213 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1217 * User interface handler for the "unwatch" action.
1218 * Requires Request to pass a token as of 1.18.
1219 * @deprecated since 1.18
1221 public function unwatch() {
1222 Action
::factory( 'unwatch', $this )->show();
1226 * Stop watching a page
1227 * @return bool true on successful unwatch
1228 * @deprecated since 1.18
1230 public function doUnwatch() {
1232 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1236 * action=protect handler
1238 public function protect() {
1239 $form = new ProtectionForm( $this );
1244 * action=unprotect handler (alias)
1246 public function unprotect() {
1251 * Info about this page
1252 * Called for ?action=info when $wgAllowPageInfo is on.
1254 public function info() {
1255 Action
::factory( 'info', $this )->show();
1259 * Overriden by ImagePage class, only present here to avoid a fatal error
1260 * Called for ?action=revert
1262 public function revert() {
1263 Action
::factory( 'revert', $this )->show();
1267 * User interface for rollback operations
1269 public function rollback() {
1270 Action
::factory( 'rollback', $this )->show();
1274 * Output a redirect back to the article.
1275 * This is typically used after an edit.
1277 * @deprecated in 1.18; call $wgOut->redirect() directly
1278 * @param $noRedir Boolean: add redirect=no
1279 * @param $sectionAnchor String: section to redirect to, including "#"
1280 * @param $extraQuery String: extra query params
1282 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1283 wfDeprecated( __METHOD__
);
1287 $query = 'redirect=no';
1289 $query .= "&$extraQuery";
1291 $query = $extraQuery;
1294 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1298 * UI entry point for page deletion
1300 public function delete() {
1301 global $wgOut, $wgRequest;
1303 $confirm = $wgRequest->wasPosted() &&
1304 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1306 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1307 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1309 $reason = $this->DeleteReasonList
;
1311 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1312 // Entry from drop down menu + additional comment
1313 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1314 } elseif ( $reason == 'other' ) {
1315 $reason = $this->DeleteReason
;
1318 # Flag to hide all contents of the archived revisions
1319 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1321 # This code desperately needs to be totally rewritten
1323 # Read-only check...
1324 if ( wfReadOnly() ) {
1325 $wgOut->readOnlyPage();
1331 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1333 if ( count( $permission_errors ) > 0 ) {
1334 $wgOut->showPermissionsErrorPage( $permission_errors );
1339 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1341 # Better double-check that it hasn't been deleted yet!
1342 $dbw = wfGetDB( DB_MASTER
);
1343 $conds = $this->getTitle()->pageCond();
1344 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1345 if ( $latest === false ) {
1346 $wgOut->showFatalError(
1349 array( 'class' => 'error mw-error-cannotdelete' ),
1350 wfMsgExt( 'cannotdelete', array( 'parse' ),
1351 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1354 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1355 LogEventsList
::showLogExtract(
1358 $this->getTitle()->getPrefixedText()
1364 # Hack for big sites
1365 $bigHistory = $this->mPage
->isBigDeletion();
1366 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1367 global $wgLang, $wgDeleteRevisionsLimit;
1369 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1370 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1376 $this->doDelete( $reason, $suppress );
1378 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1380 } elseif ( $this->getTitle()->userIsWatching() ) {
1387 // Generate deletion reason
1388 $hasHistory = false;
1390 $reason = $this->generateReason( $hasHistory );
1393 // If the page has a history, insert a warning
1394 if ( $hasHistory && !$confirm ) {
1397 $revisions = $this->mPage
->estimateRevisionCount();
1398 // @todo FIXME: i18n issue/patchwork message
1399 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1400 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1401 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1402 wfMsgHtml( 'history' ),
1403 array( 'rel' => 'archives' ),
1404 array( 'action' => 'history' ) ) .
1408 if ( $bigHistory ) {
1409 global $wgDeleteRevisionsLimit;
1410 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1411 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1415 return $this->confirmDelete( $reason );
1419 * Output deletion confirmation dialog
1420 * @todo FIXME: Move to another file?
1421 * @param $reason String: prefilled reason
1423 public function confirmDelete( $reason ) {
1426 wfDebug( "Article::confirmDelete\n" );
1428 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1429 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1430 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1431 $wgOut->addWikiMsg( 'confirmdeletetext' );
1433 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1435 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1436 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1438 <td class='mw-input'><strong>" .
1439 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1440 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1446 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1448 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1449 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1450 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1451 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1452 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1453 "<tr id=\"wpDeleteReasonListRow\">
1454 <td class='mw-label'>" .
1455 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1457 <td class='mw-input'>" .
1458 Xml
::listDropDown( 'wpDeleteReasonList',
1459 wfMsgForContent( 'deletereason-dropdown' ),
1460 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1463 <tr id=\"wpDeleteReasonRow\">
1464 <td class='mw-label'>" .
1465 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1467 <td class='mw-input'>" .
1468 Html
::input( 'wpReason', $reason, 'text', array(
1470 'maxlength' => '255',
1478 # Disallow watching if user is not logged in
1479 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1483 <td class='mw-input'>" .
1484 Xml
::checkLabel( wfMsg( 'watchthis' ),
1485 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1494 <td class='mw-submit'>" .
1495 Xml
::submitButton( wfMsg( 'deletepage' ),
1496 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1499 Xml
::closeElement( 'table' ) .
1500 Xml
::closeElement( 'fieldset' ) .
1501 Html
::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1502 Xml
::closeElement( 'form' );
1504 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1505 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1506 $link = Linker
::link(
1508 wfMsgHtml( 'delete-edit-reasonlist' ),
1510 array( 'action' => 'edit' )
1512 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1515 $wgOut->addHTML( $form );
1516 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1517 LogEventsList
::showLogExtract( $wgOut, 'delete',
1518 $this->getTitle()->getPrefixedText()
1523 * Perform a deletion and output success or failure messages
1525 public function doDelete( $reason, $suppress = false ) {
1528 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1531 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1532 $deleted = $this->getTitle()->getPrefixedText();
1534 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1535 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1537 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1539 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1540 $wgOut->returnToMain( false );
1542 if ( $error == '' ) {
1543 $wgOut->showFatalError(
1546 array( 'class' => 'error mw-error-cannotdelete' ),
1547 wfMsgExt( 'cannotdelete', array( 'parse' ),
1548 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1552 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1554 LogEventsList
::showLogExtract(
1557 $this->getTitle()->getPrefixedText()
1560 $wgOut->showFatalError( $error );
1566 * Generate the navigation links when browsing through an article revisions
1567 * It shows the information as:
1568 * Revision as of \<date\>; view current revision
1569 * \<- Previous version | Next Version -\>
1571 * @param $oldid String: revision ID of this article revision
1573 public function setOldSubtitle( $oldid = 0 ) {
1574 global $wgLang, $wgOut, $wgUser, $wgRequest;
1576 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1580 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1582 # Cascade unhide param in links for easy deletion browsing
1583 $extraParams = array();
1584 if ( $wgRequest->getVal( 'unhide' ) ) {
1585 $extraParams['unhide'] = 1;
1588 $revision = Revision
::newFromId( $oldid );
1589 $timestamp = $revision->getTimestamp();
1591 $current = ( $oldid == $this->mPage
->getLatest() );
1592 $td = $wgLang->timeanddate( $timestamp, true );
1593 $tddate = $wgLang->date( $timestamp, true );
1594 $tdtime = $wgLang->time( $timestamp, true );
1597 ?
wfMsgHtml( 'currentrevisionlink' )
1600 wfMsgHtml( 'currentrevisionlink' ),
1603 array( 'known', 'noclasses' )
1606 ?
wfMsgHtml( 'diff' )
1609 wfMsgHtml( 'diff' ),
1615 array( 'known', 'noclasses' )
1617 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1621 wfMsgHtml( 'previousrevision' ),
1624 'direction' => 'prev',
1627 array( 'known', 'noclasses' )
1629 : wfMsgHtml( 'previousrevision' );
1633 wfMsgHtml( 'diff' ),
1639 array( 'known', 'noclasses' )
1641 : wfMsgHtml( 'diff' );
1642 $nextlink = $current
1643 ?
wfMsgHtml( 'nextrevision' )
1646 wfMsgHtml( 'nextrevision' ),
1649 'direction' => 'next',
1652 array( 'known', 'noclasses' )
1654 $nextdiff = $current
1655 ?
wfMsgHtml( 'diff' )
1658 wfMsgHtml( 'diff' ),
1664 array( 'known', 'noclasses' )
1669 // User can delete revisions or view deleted revisions...
1670 $canHide = $wgUser->isAllowed( 'deleterevision' );
1671 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1672 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1673 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1676 'type' => 'revision',
1677 'target' => $this->getTitle()->getPrefixedDbkey(),
1680 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1685 # Show user links if allowed to see them. If hidden, then show them only if requested...
1686 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1688 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1689 ?
'revision-info-current'
1692 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1695 array( 'parseinline', 'replaceafter' ),
1701 $revision->getUser()
1704 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1705 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1707 $wgOut->setSubtitle( $r );
1710 /* Caching functions */
1713 * checkLastModified returns true if it has taken care of all
1714 * output to the client that is necessary for this request.
1715 * (that is, it has sent a cached version of the page)
1717 * @return boolean true if cached version send, false otherwise
1719 protected function tryFileCache() {
1720 static $called = false;
1723 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1728 if ( $this->isFileCacheable() ) {
1729 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1730 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1731 wfDebug( "Article::tryFileCache(): about to load file\n" );
1732 $cache->loadFromFileCache( $this->getContext() );
1735 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1736 ob_start( array( &$cache, 'saveToFileCache' ) );
1739 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1746 * Check if the page can be cached
1749 public function isFileCacheable() {
1752 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1753 $cacheable = $this->mPage
->getID()
1754 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1755 // Extension may have reason to disable file caching on some pages.
1757 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1767 * Add the primary page-view wikitext to the output buffer
1768 * Saves the text into the parser cache if possible.
1769 * Updates templatelinks if it is out of date.
1771 * @param $text String
1772 * @param $cache Boolean
1773 * @param $parserOptions mixed ParserOptions object, or boolean false
1775 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1778 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1780 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1782 $wgOut->addParserOutput( $this->mParserOutput
);
1786 * Lightweight method to get the parser output for a page, checking the parser cache
1787 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1788 * consider, so it's not appropriate to use there.
1790 * @since 1.16 (r52326) for LiquidThreads
1792 * @param $oldid mixed integer Revision ID or null
1793 * @param $user User The relevant user
1794 * @return ParserOutput or false if the given revsion ID is not found
1796 public function getParserOutput( $oldid = null, User
$user = null ) {
1797 global $wgEnableParserCache, $wgUser;
1798 $user = is_null( $user ) ?
$wgUser : $user;
1800 wfProfileIn( __METHOD__
);
1801 // Should the parser cache be used?
1802 $useParserCache = $wgEnableParserCache &&
1803 $user->getStubThreshold() == 0 &&
1804 $this->mPage
->exists() &&
1807 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1809 if ( $user->getStubThreshold() ) {
1810 wfIncrStats( 'pcache_miss_stub' );
1813 if ( $useParserCache ) {
1814 $options = $this->mPage
->makeParserOptions( $user );
1815 $parserOutput = ParserCache
::singleton()->get( $this, $options );
1816 if ( $parserOutput !== false ) {
1817 wfProfileOut( __METHOD__
);
1818 return $parserOutput;
1822 // Cache miss; parse and output it.
1823 if ( $oldid === null ) {
1824 $text = $this->mPage
->getRawText();
1826 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1827 if ( $rev === null ) {
1828 wfProfileOut( __METHOD__
);
1831 $text = $rev->getText();
1834 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1835 wfProfileOut( __METHOD__
);
1840 * This does all the heavy lifting for outputWikitext, except it returns the parser
1841 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1842 * say, embedding thread pages within a discussion system (LiquidThreads)
1844 * @param $text string
1845 * @param $cache boolean
1846 * @param $parserOptions parsing options, defaults to false
1847 * @return ParserOutput
1849 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1850 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1852 if ( !$parserOptions ) {
1853 $parserOptions = $this->getParserOptions();
1857 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1858 $parserOptions, true, true, $this->getRevIdFetched() );
1863 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1864 $this->getTitle()->getPrefixedDBkey() ) );
1867 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1868 $parserCache = ParserCache
::singleton();
1869 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1872 // Make sure file cache is not used on uncacheable content.
1873 // Output that has magic words in it can still use the parser cache
1874 // (if enabled), though it will generally expire sooner.
1875 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1876 $wgUseFileCache = false;
1879 if ( $this->isCurrent() ) {
1880 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1883 return $this->mParserOutput
;
1887 * Get parser options suitable for rendering the primary article wikitext
1888 * @return ParserOptions|false
1890 public function getParserOptions() {
1892 if ( !$this->mParserOptions
) {
1893 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1895 // Clone to allow modifications of the return value without affecting cache
1896 return clone $this->mParserOptions
;
1900 * Sets the context this Article is executed in
1902 * @param $context IContextSource
1905 public function setContext( $context ) {
1906 $this->mContext
= $context;
1910 * Gets the context this Article is executed in
1912 * @return IContextSource
1915 public function getContext() {
1916 if ( $this->mContext
instanceof IContextSource
) {
1917 return $this->mContext
;
1919 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1920 return RequestContext
::getMain();
1925 * Use PHP's magic __get handler to handle accessing of
1926 * raw WikiPage fields for backwards compatibility.
1928 * @param $fname String Field name
1930 public function __get( $fname ) {
1931 if ( property_exists( $this->mPage
, $fname ) ) {
1932 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1933 return $this->mPage
->$fname;
1935 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1939 * Use PHP's magic __set handler to handle setting of
1940 * raw WikiPage fields for backwards compatibility.
1942 * @param $fname String Field name
1943 * @param $fvalue mixed New value
1945 public function __set( $fname, $fvalue ) {
1946 if ( property_exists( $this->mPage
, $fname ) ) {
1947 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1948 $this->mPage
->$fname = $fvalue;
1949 // Note: extensions may want to toss on new fields
1950 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1951 $this->mPage
->$fname = $fvalue;
1953 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1958 * Use PHP's magic __call handler to transform instance calls to
1959 * WikiPage functions for backwards compatibility.
1961 * @param $fname String Name of called method
1962 * @param $args Array Arguments to the method
1964 public function __call( $fname, $args ) {
1965 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1966 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1967 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1969 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1972 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1975 * @param $limit array
1976 * @param $reason string
1977 * @param $cascade int
1978 * @param $expiry array
1981 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1982 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1986 * @param $reason string
1987 * @param $suppress bool
1989 * @param $commit bool
1990 * @param $error string
1993 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1994 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2002 * @param $resultDetails
2006 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2008 $user = is_null( $user ) ?
$wgUser : $user;
2009 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2016 * @param $resultDetails
2017 * @param $guser User
2020 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2022 $guser = is_null( $guser ) ?
$wgUser : $guser;
2023 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2027 * @param $hasHistory bool
2030 public function generateReason( &$hasHistory ) {
2031 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2034 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2039 public static function selectFields() {
2040 return WikiPage
::selectFields();
2044 * @param $title Title
2046 public static function onArticleCreate( $title ) {
2047 return WikiPage
::onArticleCreate( $title );
2051 * @param $title Title
2053 public static function onArticleDelete( $title ) {
2054 return WikiPage
::onArticleDelete( $title );
2058 * @param $title Title
2060 public static function onArticleEdit( $title ) {
2061 return WikiPage
::onArticleEdit( $title );
2070 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2071 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2076 class PoolWorkArticleView
extends PoolCounterWork
{
2083 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2084 parent
::__construct( 'ArticleView', $key );
2085 $this->mArticle
= $article;
2086 $this->cacheable
= $useParserCache;
2087 $this->parserOptions
= $parserOptions;
2091 return $this->mArticle
->doViewParse();
2094 function getCachedWork() {
2097 $parserCache = ParserCache
::singleton();
2098 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2100 if ( $this->mArticle
->mParserOutput
!== false ) {
2101 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2102 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2103 # Ensure that UI elements requiring revision ID have
2104 # the correct version information.
2105 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2111 function fallback() {
2112 return $this->mArticle
->tryDirtyCache();
2116 * @param $status Status
2118 function error( $status ) {
2121 $wgOut->clearHTML(); // for release() errors
2122 $wgOut->enableClientCache( false );
2123 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2125 $errortext = $status->getWikiText( false, 'view-pool-error' );
2126 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );