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
90 public static function newFromID( $id ) {
91 $t = Title
::newFromID( $id );
92 # @todo FIXME: Doesn't inherit right
93 return $t == null ?
null : new self( $t );
94 # return $t == null ? null : new static( $t ); // PHP 5.3
98 * Create an Article object of the appropriate class for the given page.
100 * @param $title Title
101 * @param $context IContextSource
102 * @return Article object
104 public static function newFromTitle( $title, IContextSource
$context ) {
105 if ( NS_MEDIA
== $title->getNamespace() ) {
106 // FIXME: where should this go?
107 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
111 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
113 switch( $title->getNamespace() ) {
115 $page = new ImagePage( $title );
118 $page = new CategoryPage( $title );
121 $page = new Article( $title );
124 $page->setContext( $context );
130 * Tell the page view functions that this view was redirected
131 * from another page on the wiki.
132 * @param $from Title object.
134 public function setRedirectedFrom( Title
$from ) {
135 $this->mRedirectedFrom
= $from;
139 * Get the title object of the article
140 * @return Title object of this page
142 public function getTitle() {
143 return $this->mPage
->getTitle();
148 * @todo FIXME: Shouldn't this be public?
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
1013 public function doViewParse() {
1016 $oldid = $this->getOldID();
1017 $parserOptions = $this->getParserOptions();
1019 # Render printable version, use printable version cache
1020 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1022 # Don't show section-edit links on old revisions... this way lies madness.
1023 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1024 $parserOptions->setEditSection( false );
1027 $useParserCache = $this->useParserCache( $oldid );
1028 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1034 * Try to fetch an expired entry from the parser cache. If it is present,
1035 * output it and return true. If it is not present, output nothing and
1036 * return false. This is used as a callback function for
1037 * PoolCounter::executeProtected().
1041 public function tryDirtyCache() {
1043 $parserCache = ParserCache
::singleton();
1044 $options = $this->getParserOptions();
1046 if ( $wgOut->isPrintable() ) {
1047 $options->setIsPrintable( true );
1048 $options->setEditSection( false );
1051 $output = $parserCache->getDirty( $this, $options );
1054 wfDebug( __METHOD__
. ": sending dirty output\n" );
1055 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1056 $wgOut->setSquidMaxage( 0 );
1057 $this->mParserOutput
= $output;
1058 $wgOut->addParserOutput( $output );
1059 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1063 wfDebugLog( 'dirty', "dirty missing\n" );
1064 wfDebug( __METHOD__
. ": no dirty cache\n" );
1073 * @param $target Title|Array of destination(s) to redirect
1074 * @param $appendSubtitle Boolean [optional]
1075 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1076 * @return string containing HMTL with redirect link
1078 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1079 global $wgOut, $wgStylePath;
1081 if ( !is_array( $target ) ) {
1082 $target = array( $target );
1085 $lang = $this->getTitle()->getPageLanguage();
1086 $imageDir = $lang->getDir();
1088 if ( $appendSubtitle ) {
1089 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1092 // the loop prepends the arrow image before the link, so the first case needs to be outside
1093 $title = array_shift( $target );
1095 if ( $forceKnown ) {
1096 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1098 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1101 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1102 $alt = $lang->isRTL() ?
'←' : '→';
1103 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1104 foreach ( $target as $rt ) {
1105 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1106 if ( $forceKnown ) {
1107 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1109 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1113 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1114 return '<div class="redirectMsg">' .
1115 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1116 '<span class="redirectText">' . $link . '</span></div>';
1120 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1122 public function addTrackbacks() {
1125 $dbr = wfGetDB( DB_SLAVE
);
1126 $tbs = $dbr->select( 'trackbacks',
1127 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1128 array( 'tb_page' => $this->mPage
->getID() )
1131 if ( !$dbr->numRows( $tbs ) ) {
1135 $wgOut->preventClickjacking();
1138 foreach ( $tbs as $o ) {
1141 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1142 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1143 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1144 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1148 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1156 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1160 * Removes trackback record for current article from trackbacks table
1161 * @deprecated since 1.18
1163 public function deletetrackback() {
1164 return Action
::factory( 'deletetrackback', $this )->show();
1168 * Handle action=render
1171 public function render() {
1174 $wgOut->setArticleBodyOnly( true );
1179 * Handle action=purge
1181 public function purge() {
1182 return Action
::factory( 'purge', $this )->show();
1186 * Mark this particular edit/page as patrolled
1187 * @deprecated since 1.18
1189 public function markpatrolled() {
1190 Action
::factory( 'markpatrolled', $this )->show();
1194 * User-interface handler for the "watch" action.
1195 * Requires Request to pass a token as of 1.18.
1196 * @deprecated since 1.18
1198 public function watch() {
1199 Action
::factory( 'watch', $this )->show();
1203 * Add this page to $wgUser's watchlist
1205 * This is safe to be called multiple times
1207 * @return bool true on successful watch operation
1208 * @deprecated since 1.18
1210 public function doWatch() {
1212 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1216 * User interface handler for the "unwatch" action.
1217 * Requires Request to pass a token as of 1.18.
1218 * @deprecated since 1.18
1220 public function unwatch() {
1221 Action
::factory( 'unwatch', $this )->show();
1225 * Stop watching a page
1226 * @return bool true on successful unwatch
1227 * @deprecated since 1.18
1229 public function doUnwatch() {
1231 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1235 * action=protect handler
1237 public function protect() {
1238 $form = new ProtectionForm( $this );
1243 * action=unprotect handler (alias)
1245 public function unprotect() {
1250 * Info about this page
1251 * Called for ?action=info when $wgAllowPageInfo is on.
1253 public function info() {
1254 Action
::factory( 'info', $this )->show();
1258 * Overriden by ImagePage class, only present here to avoid a fatal error
1259 * Called for ?action=revert
1261 public function revert() {
1262 Action
::factory( 'revert', $this )->show();
1266 * User interface for rollback operations
1268 public function rollback() {
1269 Action
::factory( 'rollback', $this )->show();
1273 * Output a redirect back to the article.
1274 * This is typically used after an edit.
1276 * @deprecated in 1.18; call $wgOut->redirect() directly
1277 * @param $noRedir Boolean: add redirect=no
1278 * @param $sectionAnchor String: section to redirect to, including "#"
1279 * @param $extraQuery String: extra query params
1281 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1282 wfDeprecated( __METHOD__
);
1286 $query = 'redirect=no';
1288 $query .= "&$extraQuery";
1290 $query = $extraQuery;
1293 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1297 * UI entry point for page deletion
1299 public function delete() {
1300 global $wgOut, $wgRequest;
1302 $confirm = $wgRequest->wasPosted() &&
1303 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1305 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1306 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1308 $reason = $this->DeleteReasonList
;
1310 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1311 // Entry from drop down menu + additional comment
1312 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1313 } elseif ( $reason == 'other' ) {
1314 $reason = $this->DeleteReason
;
1317 # Flag to hide all contents of the archived revisions
1318 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1320 # This code desperately needs to be totally rewritten
1322 # Read-only check...
1323 if ( wfReadOnly() ) {
1324 $wgOut->readOnlyPage();
1330 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1332 if ( count( $permission_errors ) > 0 ) {
1333 $wgOut->showPermissionsErrorPage( $permission_errors );
1338 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1340 # Better double-check that it hasn't been deleted yet!
1341 $dbw = wfGetDB( DB_MASTER
);
1342 $conds = $this->getTitle()->pageCond();
1343 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1344 if ( $latest === false ) {
1345 $wgOut->showFatalError(
1348 array( 'class' => 'error mw-error-cannotdelete' ),
1349 wfMsgExt( 'cannotdelete', array( 'parse' ),
1350 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1353 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1354 LogEventsList
::showLogExtract(
1357 $this->getTitle()->getPrefixedText()
1363 # Hack for big sites
1364 $bigHistory = $this->mPage
->isBigDeletion();
1365 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1366 global $wgLang, $wgDeleteRevisionsLimit;
1368 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1369 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1375 $this->doDelete( $reason, $suppress );
1377 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1379 } elseif ( $this->getTitle()->userIsWatching() ) {
1386 // Generate deletion reason
1387 $hasHistory = false;
1389 $reason = $this->generateReason( $hasHistory );
1392 // If the page has a history, insert a warning
1393 if ( $hasHistory && !$confirm ) {
1396 $revisions = $this->mPage
->estimateRevisionCount();
1397 // @todo FIXME: i18n issue/patchwork message
1398 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1399 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1400 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1401 wfMsgHtml( 'history' ),
1402 array( 'rel' => 'archives' ),
1403 array( 'action' => 'history' ) ) .
1407 if ( $bigHistory ) {
1408 global $wgDeleteRevisionsLimit;
1409 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1410 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1414 return $this->confirmDelete( $reason );
1418 * Output deletion confirmation dialog
1419 * @todo FIXME: Move to another file?
1420 * @param $reason String: prefilled reason
1422 public function confirmDelete( $reason ) {
1425 wfDebug( "Article::confirmDelete\n" );
1427 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1428 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1429 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1430 $wgOut->addWikiMsg( 'confirmdeletetext' );
1432 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1434 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1435 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1437 <td class='mw-input'><strong>" .
1438 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1439 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1445 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1447 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1448 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1449 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1450 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1451 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1452 "<tr id=\"wpDeleteReasonListRow\">
1453 <td class='mw-label'>" .
1454 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1456 <td class='mw-input'>" .
1457 Xml
::listDropDown( 'wpDeleteReasonList',
1458 wfMsgForContent( 'deletereason-dropdown' ),
1459 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1462 <tr id=\"wpDeleteReasonRow\">
1463 <td class='mw-label'>" .
1464 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1466 <td class='mw-input'>" .
1467 Html
::input( 'wpReason', $reason, 'text', array(
1469 'maxlength' => '255',
1477 # Disallow watching if user is not logged in
1478 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1482 <td class='mw-input'>" .
1483 Xml
::checkLabel( wfMsg( 'watchthis' ),
1484 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1493 <td class='mw-submit'>" .
1494 Xml
::submitButton( wfMsg( 'deletepage' ),
1495 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1498 Xml
::closeElement( 'table' ) .
1499 Xml
::closeElement( 'fieldset' ) .
1500 Html
::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1501 Xml
::closeElement( 'form' );
1503 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1504 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1505 $link = Linker
::link(
1507 wfMsgHtml( 'delete-edit-reasonlist' ),
1509 array( 'action' => 'edit' )
1511 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1514 $wgOut->addHTML( $form );
1515 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1516 LogEventsList
::showLogExtract( $wgOut, 'delete',
1517 $this->getTitle()->getPrefixedText()
1522 * Perform a deletion and output success or failure messages
1524 public function doDelete( $reason, $suppress = false ) {
1527 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1530 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1531 $deleted = $this->getTitle()->getPrefixedText();
1533 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1534 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1536 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1538 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1539 $wgOut->returnToMain( false );
1541 if ( $error == '' ) {
1542 $wgOut->showFatalError(
1545 array( 'class' => 'error mw-error-cannotdelete' ),
1546 wfMsgExt( 'cannotdelete', array( 'parse' ),
1547 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1551 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1553 LogEventsList
::showLogExtract(
1556 $this->getTitle()->getPrefixedText()
1559 $wgOut->showFatalError( $error );
1565 * Generate the navigation links when browsing through an article revisions
1566 * It shows the information as:
1567 * Revision as of \<date\>; view current revision
1568 * \<- Previous version | Next Version -\>
1570 * @param $oldid String: revision ID of this article revision
1572 public function setOldSubtitle( $oldid = 0 ) {
1573 global $wgLang, $wgOut, $wgUser, $wgRequest;
1575 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1579 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1581 # Cascade unhide param in links for easy deletion browsing
1582 $extraParams = array();
1583 if ( $wgRequest->getVal( 'unhide' ) ) {
1584 $extraParams['unhide'] = 1;
1587 $revision = Revision
::newFromId( $oldid );
1588 $timestamp = $revision->getTimestamp();
1590 $current = ( $oldid == $this->mPage
->getLatest() );
1591 $td = $wgLang->timeanddate( $timestamp, true );
1592 $tddate = $wgLang->date( $timestamp, true );
1593 $tdtime = $wgLang->time( $timestamp, true );
1596 ?
wfMsgHtml( 'currentrevisionlink' )
1599 wfMsgHtml( 'currentrevisionlink' ),
1602 array( 'known', 'noclasses' )
1605 ?
wfMsgHtml( 'diff' )
1608 wfMsgHtml( 'diff' ),
1614 array( 'known', 'noclasses' )
1616 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1620 wfMsgHtml( 'previousrevision' ),
1623 'direction' => 'prev',
1626 array( 'known', 'noclasses' )
1628 : wfMsgHtml( 'previousrevision' );
1632 wfMsgHtml( 'diff' ),
1638 array( 'known', 'noclasses' )
1640 : wfMsgHtml( 'diff' );
1641 $nextlink = $current
1642 ?
wfMsgHtml( 'nextrevision' )
1645 wfMsgHtml( 'nextrevision' ),
1648 'direction' => 'next',
1651 array( 'known', 'noclasses' )
1653 $nextdiff = $current
1654 ?
wfMsgHtml( 'diff' )
1657 wfMsgHtml( 'diff' ),
1663 array( 'known', 'noclasses' )
1668 // User can delete revisions or view deleted revisions...
1669 $canHide = $wgUser->isAllowed( 'deleterevision' );
1670 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1671 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1672 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1675 'type' => 'revision',
1676 'target' => $this->getTitle()->getPrefixedDbkey(),
1679 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1684 # Show user links if allowed to see them. If hidden, then show them only if requested...
1685 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1687 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1688 ?
'revision-info-current'
1691 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1694 array( 'parseinline', 'replaceafter' ),
1700 $revision->getUser()
1703 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1704 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1706 $wgOut->setSubtitle( $r );
1709 /* Caching functions */
1712 * checkLastModified returns true if it has taken care of all
1713 * output to the client that is necessary for this request.
1714 * (that is, it has sent a cached version of the page)
1716 * @return boolean true if cached version send, false otherwise
1718 protected function tryFileCache() {
1719 static $called = false;
1722 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1727 if ( $this->isFileCacheable() ) {
1728 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1729 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1730 wfDebug( "Article::tryFileCache(): about to load file\n" );
1731 $cache->loadFromFileCache( $this->getContext() );
1734 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1735 ob_start( array( &$cache, 'saveToFileCache' ) );
1738 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1745 * Check if the page can be cached
1748 public function isFileCacheable() {
1751 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1752 $cacheable = $this->mPage
->getID()
1753 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1754 // Extension may have reason to disable file caching on some pages.
1756 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1766 * Add the primary page-view wikitext to the output buffer
1767 * Saves the text into the parser cache if possible.
1768 * Updates templatelinks if it is out of date.
1770 * @param $text String
1771 * @param $cache Boolean
1772 * @param $parserOptions mixed ParserOptions object, or boolean false
1774 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1777 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1779 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1781 $wgOut->addParserOutput( $this->mParserOutput
);
1785 * Lightweight method to get the parser output for a page, checking the parser cache
1786 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1787 * consider, so it's not appropriate to use there.
1789 * @since 1.16 (r52326) for LiquidThreads
1791 * @param $oldid mixed integer Revision ID or null
1792 * @param $user User The relevant user
1793 * @return ParserOutput or false if the given revsion ID is not found
1795 public function getParserOutput( $oldid = null, User
$user = null ) {
1796 global $wgEnableParserCache, $wgUser;
1797 $user = is_null( $user ) ?
$wgUser : $user;
1799 wfProfileIn( __METHOD__
);
1800 // Should the parser cache be used?
1801 $useParserCache = $wgEnableParserCache &&
1802 $user->getStubThreshold() == 0 &&
1803 $this->mPage
->exists() &&
1806 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1808 if ( $user->getStubThreshold() ) {
1809 wfIncrStats( 'pcache_miss_stub' );
1812 if ( $useParserCache ) {
1813 $options = $this->mPage
->makeParserOptions( $user );
1814 $parserOutput = ParserCache
::singleton()->get( $this, $options );
1815 if ( $parserOutput !== false ) {
1816 wfProfileOut( __METHOD__
);
1817 return $parserOutput;
1821 // Cache miss; parse and output it.
1822 if ( $oldid === null ) {
1823 $text = $this->mPage
->getRawText();
1825 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1826 if ( $rev === null ) {
1827 wfProfileOut( __METHOD__
);
1830 $text = $rev->getText();
1833 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1834 wfProfileOut( __METHOD__
);
1839 * This does all the heavy lifting for outputWikitext, except it returns the parser
1840 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1841 * say, embedding thread pages within a discussion system (LiquidThreads)
1843 * @param $text string
1844 * @param $cache boolean
1845 * @param $parserOptions parsing options, defaults to false
1846 * @return ParserOutput
1848 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1849 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1851 if ( !$parserOptions ) {
1852 $parserOptions = $this->getParserOptions();
1856 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1857 $parserOptions, true, true, $this->getRevIdFetched() );
1862 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1863 $this->getTitle()->getPrefixedDBkey() ) );
1866 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1867 $parserCache = ParserCache
::singleton();
1868 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1871 // Make sure file cache is not used on uncacheable content.
1872 // Output that has magic words in it can still use the parser cache
1873 // (if enabled), though it will generally expire sooner.
1874 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1875 $wgUseFileCache = false;
1878 if ( $this->isCurrent() ) {
1879 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1882 return $this->mParserOutput
;
1886 * Get parser options suitable for rendering the primary article wikitext
1887 * @return mixed ParserOptions object or boolean false
1889 public function getParserOptions() {
1891 if ( !$this->mParserOptions
) {
1892 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1894 // Clone to allow modifications of the return value without affecting cache
1895 return clone $this->mParserOptions
;
1899 * Sets the context this Article is executed in
1901 * @param $context IContextSource
1904 public function setContext( $context ) {
1905 $this->mContext
= $context;
1909 * Gets the context this Article is executed in
1911 * @return IContextSource
1914 public function getContext() {
1915 if ( $this->mContext
instanceof IContextSource
) {
1916 return $this->mContext
;
1918 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1919 return RequestContext
::getMain();
1924 * Use PHP's magic __get handler to handle accessing of
1925 * raw WikiPage fields for backwards compatibility.
1927 * @param $fname String Field name
1929 public function __get( $fname ) {
1930 if ( property_exists( $this->mPage
, $fname ) ) {
1931 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1932 return $this->mPage
->$fname;
1934 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1938 * Use PHP's magic __set handler to handle setting of
1939 * raw WikiPage fields for backwards compatibility.
1941 * @param $fname String Field name
1942 * @param $fvalue mixed New value
1944 public function __set( $fname, $fvalue ) {
1945 if ( property_exists( $this->mPage
, $fname ) ) {
1946 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1947 $this->mPage
->$fname = $fvalue;
1948 // Note: extensions may want to toss on new fields
1949 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1950 $this->mPage
->$fname = $fvalue;
1952 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1957 * Use PHP's magic __call handler to transform instance calls to
1958 * WikiPage functions for backwards compatibility.
1960 * @param $fname String Name of called method
1961 * @param $args Array Arguments to the method
1963 public function __call( $fname, $args ) {
1964 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1965 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1966 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1968 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1971 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1972 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1973 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1976 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1977 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1980 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1982 $user = is_null( $user ) ?
$wgUser : $user;
1983 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1986 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1988 $guser = is_null( $guser ) ?
$wgUser : $guser;
1989 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1992 public function generateReason( &$hasHistory ) {
1993 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1996 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1997 public static function selectFields() {
1998 return WikiPage
::selectFields();
2001 public static function onArticleCreate( $title ) {
2002 return WikiPage
::onArticleCreate( $title );
2005 public static function onArticleDelete( $title ) {
2006 return WikiPage
::onArticleDelete( $title );
2009 public static function onArticleEdit( $title ) {
2010 return WikiPage
::onArticleEdit( $title );
2013 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2014 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2019 class PoolWorkArticleView
extends PoolCounterWork
{
2026 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2027 parent
::__construct( 'ArticleView', $key );
2028 $this->mArticle
= $article;
2029 $this->cacheable
= $useParserCache;
2030 $this->parserOptions
= $parserOptions;
2034 return $this->mArticle
->doViewParse();
2037 function getCachedWork() {
2040 $parserCache = ParserCache
::singleton();
2041 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2043 if ( $this->mArticle
->mParserOutput
!== false ) {
2044 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2045 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2046 # Ensure that UI elements requiring revision ID have
2047 # the correct version information.
2048 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2054 function fallback() {
2055 return $this->mArticle
->tryDirtyCache();
2059 * @param $status Status
2061 function error( $status ) {
2064 $wgOut->clearHTML(); // for release() errors
2065 $wgOut->enableClientCache( false );
2066 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2068 $errortext = $status->getWikiText( false, 'view-pool-error' );
2069 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );