8 * Class for viewing MediaWiki article and history.
10 * This maintains WikiPage functions for backwards compatibility.
12 * @TODO: move and rewrite code to an Action class
14 * See design.txt for an overview.
15 * Note: edit user interface and cache support functions have been
16 * moved to separate EditPage and HTMLFileCache classes.
18 * @internal documentation reviewed 15 Mar 2010
20 class Article
extends Page
{
36 var $mContentLoaded = false; // !<
42 var $mRedirectedFrom = null;
45 * @var mixed: boolean false or URL string
47 var $mRedirectUrl = false; // !<
48 var $mRevIdFetched = 0; // !<
53 var $mRevision = null;
63 * Constructor and clear the article
64 * @param $title Title Reference to a Title object.
65 * @param $oldId Integer revision ID, null to fetch from request, zero for current
67 public function __construct( Title
$title, $oldId = null ) {
68 $this->mOldId
= $oldId;
69 $this->mPage
= $this->newPage( $title );
72 protected function newPage( Title
$title ) {
73 return new WikiPage( $title );
77 * Constructor from a page id
78 * @param $id Int article ID to load
80 public static function newFromID( $id ) {
81 $t = Title
::newFromID( $id );
82 # @todo FIXME: Doesn't inherit right
83 return $t == null ?
null : new self( $t );
84 # return $t == null ? null : new static( $t ); // PHP 5.3
88 * Create an Article object of the appropriate class for the given page.
91 * @param $context RequestContext
92 * @return Article object
94 public static function newFromTitle( $title, RequestContext
$context ) {
95 if ( NS_MEDIA
== $title->getNamespace() ) {
96 // FIXME: where should this go?
97 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
101 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
103 switch( $title->getNamespace() ) {
105 $page = new ImagePage( $title );
108 $page = new CategoryPage( $title );
111 $page = new Article( $title );
114 $page->setContext( $context );
120 * Tell the page view functions that this view was redirected
121 * from another page on the wiki.
122 * @param $from Title object.
124 public function setRedirectedFrom( Title
$from ) {
125 $this->mRedirectedFrom
= $from;
129 * Get the title object of the article
130 * @return Title object of this page
132 public function getTitle() {
133 return $this->mPage
->getTitle();
138 * @todo FIXME: Shouldn't this be public?
141 public function clear() {
142 $this->mContentLoaded
= false;
144 $this->mRedirectedFrom
= null; # Title object if set
145 $this->mRevIdFetched
= 0;
146 $this->mRedirectUrl
= false;
148 $this->mPage
->clear();
152 * Note that getContent/loadContent do not follow redirects anymore.
153 * If you need to fetch redirectable content easily, try
154 * the shortcut in Article::followRedirect()
156 * This function has side effects! Do not use this function if you
157 * only want the real revision text if any.
159 * @return Return the text of this revision
161 public function getContent() {
164 wfProfileIn( __METHOD__
);
166 if ( $this->mPage
->getID() === 0 ) {
167 # If this is a MediaWiki:x message, then load the messages
168 # and return the message value for x.
169 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
170 $text = $this->getTitle()->getDefaultMessageText();
171 if ( $text === false ) {
175 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
177 wfProfileOut( __METHOD__
);
181 $this->loadContent();
182 wfProfileOut( __METHOD__
);
184 return $this->mContent
;
189 * @return int The oldid of the article that is to be shown, 0 for the
192 public function getOldID() {
193 if ( is_null( $this->mOldId
) ) {
194 $this->mOldId
= $this->getOldIDFromRequest();
197 return $this->mOldId
;
201 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
203 * @return int The old id for the request
205 public function getOldIDFromRequest() {
208 $this->mRedirectUrl
= false;
210 $oldid = $wgRequest->getVal( 'oldid' );
212 if ( isset( $oldid ) ) {
213 $oldid = intval( $oldid );
214 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
215 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
219 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
221 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
222 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
237 * Load the revision (including text) into this object
239 function loadContent() {
240 if ( $this->mContentLoaded
) {
244 wfProfileIn( __METHOD__
);
246 $this->fetchContent( $this->getOldID() );
248 wfProfileOut( __METHOD__
);
252 * Get text of an article from database
253 * Does *NOT* follow redirects.
255 * @param $oldid Int: 0 for whatever the latest revision is
256 * @return mixed string containing article contents, or false if null
258 function fetchContent( $oldid = 0 ) {
259 if ( $this->mContentLoaded
) {
260 return $this->mContent
;
263 # Pre-fill content with error message so that if something
264 # fails we'll have something telling us what we intended.
265 $t = $this->getTitle()->getPrefixedText();
266 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
267 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
270 $revision = Revision
::newFromId( $oldid );
272 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
275 // Revision title doesn't match the page title given?
276 if ( $this->mPage
->getID() != $revision->getPage() ) {
277 $function = array( get_class( $this->mPage
), 'newFromID' );
278 $this->mPage
= call_user_func( $function, $revision->getPage() );
279 if ( !$this->mPage
->getId() ) {
280 wfDebug( __METHOD__
. " failed to get page data linked to revision id $oldid\n" );
285 if ( !$this->mPage
->getLatest() ) {
286 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
290 $revision = $this->mPage
->getRevision();
292 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
297 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
298 // We should instead work with the Revision object when we need it...
299 $this->mContent
= $revision->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
301 $this->mRevIdFetched
= $revision->getId();
302 $this->mContentLoaded
= true;
303 $this->mRevision
=& $revision;
305 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
307 return $this->mContent
;
312 * @deprecated since 1.18
314 public function forUpdate() {
315 wfDeprecated( __METHOD__
);
319 * Returns true if the currently-referenced revision is the current edit
320 * to this page (and it exists).
323 public function isCurrent() {
324 # If no oldid, this is the current version.
325 if ( $this->getOldID() == 0 ) {
329 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
333 * Use this to fetch the rev ID used on page views
335 * @return int revision ID of last article revision
337 public function getRevIdFetched() {
338 if ( $this->mRevIdFetched
) {
339 return $this->mRevIdFetched
;
341 return $this->mPage
->getLatest();
346 * This is the default action of the index.php entry point: just view the
347 * page of the given title.
349 public function view() {
350 global $wgUser, $wgOut, $wgRequest, $wgParser;
351 global $wgUseFileCache, $wgUseETag;
353 wfProfileIn( __METHOD__
);
355 # Get variables from query string
356 $oldid = $this->getOldID();
358 # getOldID may want us to redirect somewhere else
359 if ( $this->mRedirectUrl
) {
360 $wgOut->redirect( $this->mRedirectUrl
);
361 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
362 wfProfileOut( __METHOD__
);
367 $wgOut->setArticleFlag( true );
368 # Set page title (may be overridden by DISPLAYTITLE)
369 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
371 # If we got diff in the query, we want to see a diff page instead of the article.
372 if ( $wgRequest->getCheck( 'diff' ) ) {
373 wfDebug( __METHOD__
. ": showing diff page\n" );
374 # Manually setting action=diff. Bug 25800
375 $wgRequest->setVal( 'action', 'historysubmit' );
376 $this->showDiffPage();
377 wfProfileOut( __METHOD__
);
382 # Allow frames by default
383 $wgOut->allowClickjacking();
385 $parserCache = ParserCache
::singleton();
387 $parserOptions = $this->mPage
->getParserOptions();
388 # Render printable version, use printable version cache
389 if ( $wgOut->isPrintable() ) {
390 $parserOptions->setIsPrintable( true );
391 $parserOptions->setEditSection( false );
392 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
393 $parserOptions->setEditSection( false );
396 # Try client and file cache
397 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
399 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
402 # Is it client cached?
403 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
404 wfDebug( __METHOD__
. ": done 304\n" );
405 wfProfileOut( __METHOD__
);
409 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
410 wfDebug( __METHOD__
. ": done file cache\n" );
411 # tell wgOut that output is taken care of
413 $this->mPage
->viewUpdates();
414 wfProfileOut( __METHOD__
);
420 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
421 $parserOptions->setEditSection( false );
424 # Should the parser cache be used?
425 $useParserCache = $this->useParserCache( $oldid );
426 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
427 if ( $wgUser->getStubThreshold() ) {
428 wfIncrStats( 'pcache_miss_stub' );
431 $wasRedirected = $this->showRedirectedFromHeader();
432 $this->showNamespaceHeader();
434 # Iterate through the possible ways of constructing the output text.
435 # Keep going until $outputDone is set, or we run out of things to do.
438 $this->mParserOutput
= false;
440 while ( !$outputDone && ++
$pass ) {
443 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
446 # Try the parser cache
447 if ( $useParserCache ) {
448 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
450 if ( $this->mParserOutput
!== false ) {
451 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
452 $wgOut->addParserOutput( $this->mParserOutput
);
453 # Ensure that UI elements requiring revision ID have
454 # the correct version information.
455 $wgOut->setRevisionId( $this->mPage
->getLatest() );
457 # Preload timestamp to avoid a DB hit
458 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
459 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
465 $text = $this->getContent();
466 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
467 wfDebug( __METHOD__
. ": showing missing article\n" );
468 $this->showMissingArticle();
469 wfProfileOut( __METHOD__
);
473 # Another whitelist check in case oldid is altering the title
474 if ( !$this->getTitle()->userCanRead() ) {
475 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
476 $wgOut->loginToUse();
479 wfProfileOut( __METHOD__
);
483 # Are we looking at an old revision
484 if ( $oldid && !is_null( $this->mRevision
) ) {
485 $this->setOldSubtitle( $oldid );
487 if ( !$this->showDeletedRevisionHeader() ) {
488 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
489 wfProfileOut( __METHOD__
);
493 # If this "old" version is the current, then try the parser cache...
494 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
495 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
496 if ( $this->mParserOutput
) {
497 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
498 $wgOut->addParserOutput( $this->mParserOutput
);
499 $wgOut->setRevisionId( $this->mPage
->getLatest() );
506 # Ensure that UI elements requiring revision ID have
507 # the correct version information.
508 $wgOut->setRevisionId( $this->getRevIdFetched() );
510 # Pages containing custom CSS or JavaScript get special treatment
511 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
512 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
513 $this->showCssOrJsPage();
516 $rt = Title
::newFromRedirectArray( $text );
518 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
519 # Viewing a redirect page (e.g. with parameter redirect=no)
520 # Don't append the subtitle if this was an old revision
521 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
522 # Parse just to get categories, displaytitle, etc.
523 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
524 $wgOut->addParserOutputNoText( $this->mParserOutput
);
530 # Run the parse, protected by a pool counter
531 wfDebug( __METHOD__
. ": doing uncached parse\n" );
533 $key = $parserCache->getKey( $this, $parserOptions );
534 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
536 if ( !$poolArticleView->execute() ) {
537 # Connection or timeout error
538 wfProfileOut( __METHOD__
);
544 # Should be unreachable, but just in case...
550 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
551 if ( $this->mParserOutput
) {
552 $titleText = $this->mParserOutput
->getTitleText();
554 if ( strval( $titleText ) !== '' ) {
555 $wgOut->setPageTitle( $titleText );
559 # For the main page, overwrite the <title> element with the con-
560 # tents of 'pagetitle-view-mainpage' instead of the default (if
562 # This message always exists because it is in the i18n files
563 if ( $this->getTitle()->equals( Title
::newMainPage() ) ) {
564 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
565 if ( !$msg->isDisabled() ) {
566 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
570 # Now that we've filled $this->mParserOutput, we know whether
571 # there are any __NOINDEX__ tags on the page
572 $policy = $this->getRobotPolicy( 'view' );
573 $wgOut->setIndexPolicy( $policy['index'] );
574 $wgOut->setFollowPolicy( $policy['follow'] );
576 $this->showViewFooter();
577 $this->mPage
->viewUpdates();
578 wfProfileOut( __METHOD__
);
582 * Show a diff page according to current request variables. For use within
583 * Article::view() only, other callers should use the DifferenceEngine class.
585 public function showDiffPage() {
586 global $wgRequest, $wgUser;
588 $diff = $wgRequest->getVal( 'diff' );
589 $rcid = $wgRequest->getVal( 'rcid' );
590 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
591 $purge = $wgRequest->getVal( 'action' ) == 'purge';
592 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
593 $oldid = $this->getOldID();
595 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
596 // DifferenceEngine directly fetched the revision:
597 $this->mRevIdFetched
= $de->mNewid
;
598 $de->showDiffPage( $diffOnly );
600 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
601 # Run view updates for current revision only
602 $this->mPage
->viewUpdates();
607 * Show a page view for a page formatted as CSS or JavaScript. To be called by
608 * Article::view() only.
610 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
613 protected function showCssOrJsPage() {
614 global $wgOut, $wgLang;
616 $dir = $wgLang->getDir();
617 $lang = $wgLang->getCode();
619 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
622 // Give hooks a chance to customise the output
623 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
624 // Wrap the whole lot in a <pre> and don't parse
626 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
627 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
628 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
629 $wgOut->addHTML( "\n</pre>\n" );
634 * Get the robot policy to be used for the current view
635 * @param $action String the action= GET parameter
636 * @return Array the policy that should be set
637 * TODO: actions other than 'view'
639 public function getRobotPolicy( $action ) {
640 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
641 global $wgDefaultRobotPolicy, $wgRequest;
643 $ns = $this->getTitle()->getNamespace();
645 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
646 # Don't index user and user talk pages for blocked users (bug 11443)
647 if ( !$this->getTitle()->isSubpage() ) {
648 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
650 'index' => 'noindex',
651 'follow' => 'nofollow'
657 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
658 # Non-articles (special pages etc), and old revisions
660 'index' => 'noindex',
661 'follow' => 'nofollow'
663 } elseif ( $wgOut->isPrintable() ) {
664 # Discourage indexing of printable versions, but encourage following
666 'index' => 'noindex',
669 } elseif ( $wgRequest->getInt( 'curid' ) ) {
670 # For ?curid=x urls, disallow indexing
672 'index' => 'noindex',
677 # Otherwise, construct the policy based on the various config variables.
678 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
680 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
681 # Honour customised robot policies for this namespace
682 $policy = array_merge(
684 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
687 if ( $this->getTitle()->canUseNoindex() && is_object( $this->mParserOutput
) && $this->mParserOutput
->getIndexPolicy() ) {
688 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
689 # a final sanity check that we have really got the parser output.
690 $policy = array_merge(
692 array( 'index' => $this->mParserOutput
->getIndexPolicy() )
696 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
697 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
698 $policy = array_merge(
700 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
708 * Converts a String robot policy into an associative array, to allow
709 * merging of several policies using array_merge().
710 * @param $policy Mixed, returns empty array on null/false/'', transparent
711 * to already-converted arrays, converts String.
712 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
714 public static function formatRobotPolicy( $policy ) {
715 if ( is_array( $policy ) ) {
717 } elseif ( !$policy ) {
721 $policy = explode( ',', $policy );
722 $policy = array_map( 'trim', $policy );
725 foreach ( $policy as $var ) {
726 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
727 $arr['index'] = $var;
728 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
729 $arr['follow'] = $var;
737 * If this request is a redirect view, send "redirected from" subtitle to
738 * $wgOut. Returns true if the header was needed, false if this is not a
739 * redirect view. Handles both local and remote redirects.
743 public function showRedirectedFromHeader() {
744 global $wgOut, $wgRequest, $wgRedirectSources;
746 $rdfrom = $wgRequest->getVal( 'rdfrom' );
748 if ( isset( $this->mRedirectedFrom
) ) {
749 // This is an internally redirected page view.
750 // We'll need a backlink to the source page for navigation.
751 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
752 $redir = Linker
::link(
753 $this->mRedirectedFrom
,
756 array( 'redirect' => 'no' ),
757 array( 'known', 'noclasses' )
760 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
761 $wgOut->setSubtitle( $s );
763 // Set the fragment if one was specified in the redirect
764 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
765 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
766 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
769 // Add a <link rel="canonical"> tag
770 $wgOut->addLink( array( 'rel' => 'canonical',
771 'href' => $this->getTitle()->getLocalURL() )
776 } elseif ( $rdfrom ) {
777 // This is an externally redirected view, from some other wiki.
778 // If it was reported from a trusted site, supply a backlink.
779 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
780 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
781 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
782 $wgOut->setSubtitle( $s );
792 * Show a header specific to the namespace currently being viewed, like
793 * [[MediaWiki:Talkpagetext]]. For Article::view().
795 public function showNamespaceHeader() {
798 if ( $this->getTitle()->isTalkPage() ) {
799 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
800 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
806 * Show the footer section of an ordinary page view
808 public function showViewFooter() {
809 global $wgOut, $wgUseTrackbacks;
811 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
812 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
813 $wgOut->addWikiMsg( 'anontalkpagetext' );
816 # If we have been passed an &rcid= parameter, we want to give the user a
817 # chance to mark this new article as patrolled.
818 $this->showPatrolFooter();
821 if ( $wgUseTrackbacks ) {
822 $this->addTrackbacks();
825 wfRunHooks( 'ArticleViewFooter', array( $this ) );
830 * If patrol is possible, output a patrol UI box. This is called from the
831 * footer section of ordinary page views. If patrol is not possible or not
832 * desired, does nothing.
834 public function showPatrolFooter() {
835 global $wgOut, $wgRequest, $wgUser;
837 $rcid = $wgRequest->getVal( 'rcid' );
839 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
843 $token = $wgUser->editToken( $rcid );
844 $wgOut->preventClickjacking();
847 "<div class='patrollink'>" .
849 'markaspatrolledlink',
852 wfMsgHtml( 'markaspatrolledtext' ),
855 'action' => 'markpatrolled',
859 array( 'known', 'noclasses' )
867 * Show the error text for a missing article. For articles in the MediaWiki
868 * namespace, show the default message text. To be called from Article::view().
870 public function showMissingArticle() {
871 global $wgOut, $wgRequest, $wgUser;
873 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
874 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
875 $parts = explode( '/', $this->getTitle()->getText() );
876 $rootPart = $parts[0];
877 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
878 $ip = User
::isIP( $rootPart );
880 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
881 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
882 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
883 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
884 LogEventsList
::showLogExtract(
887 $user->getUserPage()->getPrefixedText(),
891 'showIfEmpty' => false,
893 'blocked-notice-logextract',
894 $user->getName() # Support GENDER in notice
901 wfRunHooks( 'ShowMissingArticle', array( $this ) );
903 # Show delete and move logs
904 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
906 'conds' => array( "log_action != 'revision'" ),
907 'showIfEmpty' => false,
908 'msgKey' => array( 'moveddeleted-notice' ) )
912 $oldid = $this->getOldID();
914 $text = wfMsgNoTrans( 'missing-article',
915 $this->getTitle()->getPrefixedText(),
916 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
917 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
918 // Use the default message text
919 $text = $this->getTitle()->getDefaultMessageText();
921 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
922 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
923 $errors = array_merge( $createErrors, $editErrors );
925 if ( !count( $errors ) ) {
926 $text = wfMsgNoTrans( 'noarticletext' );
928 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
931 $text = "<div class='noarticletext'>\n$text\n</div>";
933 if ( !$this->mPage
->hasViewableContent() ) {
934 // If there's no backing content, send a 404 Not Found
935 // for better machine handling of broken links.
936 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
939 $wgOut->addWikiText( $text );
943 * If the revision requested for view is deleted, check permissions.
944 * Send either an error message or a warning header to $wgOut.
946 * @return boolean true if the view is allowed, false if not.
948 public function showDeletedRevisionHeader() {
949 global $wgOut, $wgRequest;
951 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
956 // If the user is not allowed to see it...
957 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
958 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
959 'rev-deleted-text-permission' );
962 // If the user needs to confirm that they want to see it...
963 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
964 # Give explanation and add a link to view the revision...
965 $oldid = intval( $this->getOldID() );
966 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
967 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
968 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
969 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
970 array( $msg, $link ) );
973 // We are allowed to see...
975 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
976 'rev-suppressed-text-view' : 'rev-deleted-text-view';
977 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
984 * Execute the uncached parse for action=view
986 public function doViewParse() {
989 $oldid = $this->getOldID();
990 $parserOptions = $this->mPage
->getParserOptions();
992 # Render printable version, use printable version cache
993 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
995 # Don't show section-edit links on old revisions... this way lies madness.
996 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
997 $parserOptions->setEditSection( false );
1000 $useParserCache = $this->useParserCache( $oldid );
1001 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1007 * Try to fetch an expired entry from the parser cache. If it is present,
1008 * output it and return true. If it is not present, output nothing and
1009 * return false. This is used as a callback function for
1010 * PoolCounter::executeProtected().
1014 public function tryDirtyCache() {
1016 $parserCache = ParserCache
::singleton();
1017 $options = $this->mPage
->getParserOptions();
1019 if ( $wgOut->isPrintable() ) {
1020 $options->setIsPrintable( true );
1021 $options->setEditSection( false );
1024 $output = $parserCache->getDirty( $this, $options );
1027 wfDebug( __METHOD__
. ": sending dirty output\n" );
1028 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1029 $wgOut->setSquidMaxage( 0 );
1030 $this->mParserOutput
= $output;
1031 $wgOut->addParserOutput( $output );
1032 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1036 wfDebugLog( 'dirty', "dirty missing\n" );
1037 wfDebug( __METHOD__
. ": no dirty cache\n" );
1046 * @param $target Title|Array of destination(s) to redirect
1047 * @param $appendSubtitle Boolean [optional]
1048 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1049 * @return string containing HMTL with redirect link
1051 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1052 global $wgOut, $wgLang, $wgStylePath;
1054 if ( !is_array( $target ) ) {
1055 $target = array( $target );
1058 $imageDir = $wgLang->getDir();
1060 if ( $appendSubtitle ) {
1061 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1064 // the loop prepends the arrow image before the link, so the first case needs to be outside
1065 $title = array_shift( $target );
1067 if ( $forceKnown ) {
1068 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1070 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1073 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1074 $alt = $wgLang->isRTL() ?
'←' : '→';
1075 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1076 foreach ( $target as $rt ) {
1077 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1078 if ( $forceKnown ) {
1079 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1081 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1085 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1086 return '<div class="redirectMsg">' .
1087 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1088 '<span class="redirectText">' . $link . '</span></div>';
1092 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1094 public function addTrackbacks() {
1097 $dbr = wfGetDB( DB_SLAVE
);
1098 $tbs = $dbr->select( 'trackbacks',
1099 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1100 array( 'tb_page' => $this->mPage
->getID() )
1103 if ( !$dbr->numRows( $tbs ) ) {
1107 $wgOut->preventClickjacking();
1110 foreach ( $tbs as $o ) {
1113 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1114 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1115 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1116 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1120 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1128 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1132 * Removes trackback record for current article from trackbacks table
1133 * @deprecated since 1.19
1135 public function deletetrackback() {
1136 return Action
::factory( 'deletetrackback', $this )->show();
1140 * Handle action=render
1143 public function render() {
1146 $wgOut->setArticleBodyOnly( true );
1151 * Handle action=purge
1153 public function purge() {
1154 return Action
::factory( 'purge', $this )->show();
1158 * Mark this particular edit/page as patrolled
1159 * @deprecated since 1.19
1161 public function markpatrolled() {
1162 Action
::factory( 'markpatrolled', $this )->show();
1166 * User-interface handler for the "watch" action.
1167 * Requires Request to pass a token as of 1.19.
1168 * @deprecated since 1.18
1170 public function watch() {
1171 Action
::factory( 'watch', $this )->show();
1175 * Add this page to $wgUser's watchlist
1177 * This is safe to be called multiple times
1179 * @return bool true on successful watch operation
1180 * @deprecated since 1.18
1182 public function doWatch() {
1184 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1188 * User interface handler for the "unwatch" action.
1189 * Requires Request to pass a token as of 1.19.
1190 * @deprecated since 1.18
1192 public function unwatch() {
1193 Action
::factory( 'unwatch', $this )->show();
1197 * Stop watching a page
1198 * @return bool true on successful unwatch
1199 * @deprecated since 1.18
1201 public function doUnwatch() {
1203 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1207 * action=protect handler
1209 public function protect() {
1210 $form = new ProtectionForm( $this );
1215 * action=unprotect handler (alias)
1217 public function unprotect() {
1222 * Info about this page
1223 * Called for ?action=info when $wgAllowPageInfo is on.
1225 public function info() {
1226 Action
::factory( 'info', $this )->show();
1230 * Overriden by ImagePage class, only present here to avoid a fatal error
1231 * Called for ?action=revert
1233 public function revert() {
1234 Action
::factory( 'revert', $this )->show();
1238 * User interface for rollback operations
1240 public function rollback() {
1241 Action
::factory( 'rollback', $this )->show();
1245 * Output a redirect back to the article.
1246 * This is typically used after an edit.
1248 * @deprecated in 1.19; call $wgOut->redirect() directly
1249 * @param $noRedir Boolean: add redirect=no
1250 * @param $sectionAnchor String: section to redirect to, including "#"
1251 * @param $extraQuery String: extra query params
1253 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1254 wfDeprecated( __METHOD__
);
1258 $query = 'redirect=no';
1260 $query .= "&$extraQuery";
1262 $query = $extraQuery;
1265 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1269 * Auto-generates a deletion reason
1271 * @param &$hasHistory Boolean: whether the page has a history
1272 * @return mixed String containing deletion reason or empty string, or boolean false
1273 * if no revision occurred
1275 public function generateReason( &$hasHistory ) {
1278 $dbw = wfGetDB( DB_MASTER
);
1279 // Get the last revision
1280 $rev = Revision
::newFromTitle( $this->getTitle() );
1282 if ( is_null( $rev ) ) {
1286 // Get the article's contents
1287 $contents = $rev->getText();
1290 // If the page is blank, use the text from the previous revision,
1291 // which can only be blank if there's a move/import/protect dummy revision involved
1292 if ( $contents == '' ) {
1293 $prev = $rev->getPrevious();
1296 $contents = $prev->getText();
1301 // Find out if there was only one contributor
1302 // Only scan the last 20 revisions
1303 $res = $dbw->select( 'revision', 'rev_user_text',
1304 array( 'rev_page' => $this->mPage
->getID(), $dbw->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0' ),
1306 array( 'LIMIT' => 20 )
1309 if ( $res === false ) {
1310 // This page has no revisions, which is very weird
1314 $hasHistory = ( $res->numRows() > 1 );
1315 $row = $dbw->fetchObject( $res );
1317 if ( $row ) { // $row is false if the only contributor is hidden
1318 $onlyAuthor = $row->rev_user_text
;
1319 // Try to find a second contributor
1320 foreach ( $res as $row ) {
1321 if ( $row->rev_user_text
!= $onlyAuthor ) { // Bug 22999
1322 $onlyAuthor = false;
1327 $onlyAuthor = false;
1330 // Generate the summary with a '$1' placeholder
1332 // The current revision is blank and the one before is also
1333 // blank. It's just not our lucky day
1334 $reason = wfMsgForContent( 'exbeforeblank', '$1' );
1336 if ( $onlyAuthor ) {
1337 $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
1339 $reason = wfMsgForContent( 'excontent', '$1' );
1343 if ( $reason == '-' ) {
1344 // Allow these UI messages to be blanked out cleanly
1348 // Replace newlines with spaces to prevent uglyness
1349 $contents = preg_replace( "/[\n\r]/", ' ', $contents );
1350 // Calculate the maximum amount of chars to get
1351 // Max content length = max comment length - length of the comment (excl. $1)
1352 $maxLength = 255 - ( strlen( $reason ) - 2 );
1353 $contents = $wgContLang->truncate( $contents, $maxLength );
1354 // Remove possible unfinished links
1355 $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
1356 // Now replace the '$1' placeholder
1357 $reason = str_replace( '$1', $contents, $reason );
1364 * UI entry point for page deletion
1366 public function delete() {
1367 global $wgOut, $wgRequest;
1369 $confirm = $wgRequest->wasPosted() &&
1370 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1372 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1373 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1375 $reason = $this->DeleteReasonList
;
1377 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1378 // Entry from drop down menu + additional comment
1379 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1380 } elseif ( $reason == 'other' ) {
1381 $reason = $this->DeleteReason
;
1384 # Flag to hide all contents of the archived revisions
1385 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1387 # This code desperately needs to be totally rewritten
1389 # Read-only check...
1390 if ( wfReadOnly() ) {
1391 $wgOut->readOnlyPage();
1397 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1399 if ( count( $permission_errors ) > 0 ) {
1400 $wgOut->showPermissionsErrorPage( $permission_errors );
1405 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1407 # Better double-check that it hasn't been deleted yet!
1408 $dbw = wfGetDB( DB_MASTER
);
1409 $conds = $this->getTitle()->pageCond();
1410 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1411 if ( $latest === false ) {
1412 $wgOut->showFatalError(
1415 array( 'class' => 'error mw-error-cannotdelete' ),
1416 wfMsgExt( 'cannotdelete', array( 'parse' ),
1417 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1420 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1421 LogEventsList
::showLogExtract(
1424 $this->getTitle()->getPrefixedText()
1430 # Hack for big sites
1431 $bigHistory = $this->mPage
->isBigDeletion();
1432 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1433 global $wgLang, $wgDeleteRevisionsLimit;
1435 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1436 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1442 $this->doDelete( $reason, $suppress );
1444 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1446 } elseif ( $this->getTitle()->userIsWatching() ) {
1453 // Generate deletion reason
1454 $hasHistory = false;
1456 $reason = $this->generateReason( $hasHistory );
1459 // If the page has a history, insert a warning
1460 if ( $hasHistory && !$confirm ) {
1463 $revisions = $this->mPage
->estimateRevisionCount();
1464 // @todo FIXME: i18n issue/patchwork message
1465 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1466 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1467 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1468 wfMsgHtml( 'history' ),
1469 array( 'rel' => 'archives' ),
1470 array( 'action' => 'history' ) ) .
1474 if ( $bigHistory ) {
1475 global $wgDeleteRevisionsLimit;
1476 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1477 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1481 return $this->confirmDelete( $reason );
1485 * Output deletion confirmation dialog
1486 * @todo FIXME: Move to another file?
1487 * @param $reason String: prefilled reason
1489 public function confirmDelete( $reason ) {
1492 wfDebug( "Article::confirmDelete\n" );
1494 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1495 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1496 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1497 $wgOut->addWikiMsg( 'confirmdeletetext' );
1499 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1501 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1502 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1504 <td class='mw-input'><strong>" .
1505 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1506 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1512 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1514 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1515 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1516 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1517 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1518 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1519 "<tr id=\"wpDeleteReasonListRow\">
1520 <td class='mw-label'>" .
1521 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1523 <td class='mw-input'>" .
1524 Xml
::listDropDown( 'wpDeleteReasonList',
1525 wfMsgForContent( 'deletereason-dropdown' ),
1526 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1529 <tr id=\"wpDeleteReasonRow\">
1530 <td class='mw-label'>" .
1531 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1533 <td class='mw-input'>" .
1534 Html
::input( 'wpReason', $reason, 'text', array(
1536 'maxlength' => '255',
1544 # Disallow watching if user is not logged in
1545 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1549 <td class='mw-input'>" .
1550 Xml
::checkLabel( wfMsg( 'watchthis' ),
1551 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1560 <td class='mw-submit'>" .
1561 Xml
::submitButton( wfMsg( 'deletepage' ),
1562 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1565 Xml
::closeElement( 'table' ) .
1566 Xml
::closeElement( 'fieldset' ) .
1567 Html
::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1568 Xml
::closeElement( 'form' );
1570 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1571 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1572 $link = Linker
::link(
1574 wfMsgHtml( 'delete-edit-reasonlist' ),
1576 array( 'action' => 'edit' )
1578 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1581 $wgOut->addHTML( $form );
1582 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1583 LogEventsList
::showLogExtract( $wgOut, 'delete',
1584 $this->getTitle()->getPrefixedText()
1589 * Perform a deletion and output success or failure messages
1591 public function doDelete( $reason, $suppress = false ) {
1594 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1597 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1598 $deleted = $this->getTitle()->getPrefixedText();
1600 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1601 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1603 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1605 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1606 $wgOut->returnToMain( false );
1608 if ( $error == '' ) {
1609 $wgOut->showFatalError(
1612 array( 'class' => 'error mw-error-cannotdelete' ),
1613 wfMsgExt( 'cannotdelete', array( 'parse' ),
1614 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1618 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1620 LogEventsList
::showLogExtract(
1623 $this->getTitle()->getPrefixedText()
1626 $wgOut->showFatalError( $error );
1632 * Generate the navigation links when browsing through an article revisions
1633 * It shows the information as:
1634 * Revision as of \<date\>; view current revision
1635 * \<- Previous version | Next Version -\>
1637 * @param $oldid String: revision ID of this article revision
1639 public function setOldSubtitle( $oldid = 0 ) {
1640 global $wgLang, $wgOut, $wgUser, $wgRequest;
1642 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1646 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1648 # Cascade unhide param in links for easy deletion browsing
1649 $extraParams = array();
1650 if ( $wgRequest->getVal( 'unhide' ) ) {
1651 $extraParams['unhide'] = 1;
1654 $revision = Revision
::newFromId( $oldid );
1655 $timestamp = $revision->getTimestamp();
1657 $current = ( $oldid == $this->mPage
->getLatest() );
1658 $td = $wgLang->timeanddate( $timestamp, true );
1659 $tddate = $wgLang->date( $timestamp, true );
1660 $tdtime = $wgLang->time( $timestamp, true );
1663 ?
wfMsgHtml( 'currentrevisionlink' )
1666 wfMsgHtml( 'currentrevisionlink' ),
1669 array( 'known', 'noclasses' )
1672 ?
wfMsgHtml( 'diff' )
1675 wfMsgHtml( 'diff' ),
1681 array( 'known', 'noclasses' )
1683 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1687 wfMsgHtml( 'previousrevision' ),
1690 'direction' => 'prev',
1693 array( 'known', 'noclasses' )
1695 : wfMsgHtml( 'previousrevision' );
1699 wfMsgHtml( 'diff' ),
1705 array( 'known', 'noclasses' )
1707 : wfMsgHtml( 'diff' );
1708 $nextlink = $current
1709 ?
wfMsgHtml( 'nextrevision' )
1712 wfMsgHtml( 'nextrevision' ),
1715 'direction' => 'next',
1718 array( 'known', 'noclasses' )
1720 $nextdiff = $current
1721 ?
wfMsgHtml( 'diff' )
1724 wfMsgHtml( 'diff' ),
1730 array( 'known', 'noclasses' )
1735 // User can delete revisions or view deleted revisions...
1736 $canHide = $wgUser->isAllowed( 'deleterevision' );
1737 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1738 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1739 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1742 'type' => 'revision',
1743 'target' => $this->getTitle()->getPrefixedDbkey(),
1746 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1751 # Show user links if allowed to see them. If hidden, then show them only if requested...
1752 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1754 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1755 ?
'revision-info-current'
1758 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1761 array( 'parseinline', 'replaceafter' ),
1767 $revision->getUser()
1770 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1771 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1773 $wgOut->setSubtitle( $r );
1776 /* Caching functions */
1779 * checkLastModified returns true if it has taken care of all
1780 * output to the client that is necessary for this request.
1781 * (that is, it has sent a cached version of the page)
1783 * @return boolean true if cached version send, false otherwise
1785 protected function tryFileCache() {
1786 static $called = false;
1789 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1794 if ( $this->isFileCacheable() ) {
1795 $cache = new HTMLFileCache( $this->getTitle() );
1796 if ( $cache->isFileCacheGood( $this->mPage
->getTouched() ) ) {
1797 wfDebug( "Article::tryFileCache(): about to load file\n" );
1798 $cache->loadFromFileCache();
1801 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1802 ob_start( array( &$cache, 'saveToFileCache' ) );
1805 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1812 * Check if the page can be cached
1815 public function isFileCacheable() {
1818 if ( HTMLFileCache
::useFileCache() ) {
1819 $cacheable = $this->mPage
->getID() && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1820 // Extension may have reason to disable file caching on some pages.
1822 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1832 * Add the primary page-view wikitext to the output buffer
1833 * Saves the text into the parser cache if possible.
1834 * Updates templatelinks if it is out of date.
1836 * @param $text String
1837 * @param $cache Boolean
1838 * @param $parserOptions mixed ParserOptions object, or boolean false
1840 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1843 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1845 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1847 $wgOut->addParserOutput( $this->mParserOutput
);
1851 * Lightweight method to get the parser output for a page, checking the parser cache
1852 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1853 * consider, so it's not appropriate to use there.
1855 * @since 1.16 (r52326) for LiquidThreads
1857 * @param $oldid mixed integer Revision ID or null
1858 * @param $user User The relevant user
1859 * @return ParserOutput or false if the given revsion ID is not found
1861 public function getParserOutput( $oldid = null, User
$user = null ) {
1862 global $wgEnableParserCache, $wgUser;
1863 $user = is_null( $user ) ?
$wgUser : $user;
1865 // Should the parser cache be used?
1866 $useParserCache = $wgEnableParserCache &&
1867 $user->getStubThreshold() == 0 &&
1868 $this->mPage
->exists() &&
1871 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1873 if ( $user->getStubThreshold() ) {
1874 wfIncrStats( 'pcache_miss_stub' );
1877 if ( $useParserCache ) {
1878 $parserOutput = ParserCache
::singleton()->get( $this, $this->mPage
->getParserOptions() );
1879 if ( $parserOutput !== false ) {
1880 return $parserOutput;
1884 // Cache miss; parse and output it.
1885 if ( $oldid === null ) {
1886 $text = $this->mPage
->getRawText();
1888 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1889 if ( $rev === null ) {
1892 $text = $rev->getText();
1895 return $this->getOutputFromWikitext( $text, $useParserCache );
1899 * This does all the heavy lifting for outputWikitext, except it returns the parser
1900 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1901 * say, embedding thread pages within a discussion system (LiquidThreads)
1903 * @param $text string
1904 * @param $cache boolean
1905 * @param $parserOptions parsing options, defaults to false
1906 * @return ParserOutput
1908 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1909 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1911 if ( !$parserOptions ) {
1912 $parserOptions = $this->mPage
->getParserOptions();
1916 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1917 $parserOptions, true, true, $this->getRevIdFetched() );
1922 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1923 $this->getTitle()->getPrefixedDBkey() ) );
1926 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1927 $parserCache = ParserCache
::singleton();
1928 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1931 // Make sure file cache is not used on uncacheable content.
1932 // Output that has magic words in it can still use the parser cache
1933 // (if enabled), though it will generally expire sooner.
1934 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1935 $wgUseFileCache = false;
1938 if ( $this->isCurrent() ) {
1939 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1942 return $this->mParserOutput
;
1946 * Sets the context this Article is executed in
1948 * @param $context RequestContext
1951 public function setContext( $context ) {
1952 $this->mContext
= $context;
1956 * Gets the context this Article is executed in
1958 * @return RequestContext
1961 public function getContext() {
1962 if ( $this->mContext
instanceof RequestContext
) {
1963 return $this->mContext
;
1965 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1966 return RequestContext
::getMain();
1971 * Use PHP's magic __get handler to handle accessing of
1972 * raw WikiPage fields for backwards compatibility.
1974 * @param $fname String Field name
1976 public function __get( $fname ) {
1977 if ( property_exists( $this->mPage
, $fname ) ) {
1978 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1979 return $this->mPage
->$fname;
1981 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1985 * Use PHP's magic __set handler to handle setting of
1986 * raw WikiPage fields for backwards compatibility.
1988 * @param $fname String Field name
1989 * @param $fvalue mixed New value
1990 * @param $args Array Arguments to the method
1992 public function __set( $fname, $fvalue ) {
1993 if ( property_exists( $this->mPage
, $fname ) ) {
1994 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1995 $this->mPage
->$fname = $fvalue;
1996 // Note: extensions may want to toss on new fields
1997 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1998 $this->mPage
->$fname = $fvalue;
2000 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2005 * Use PHP's magic __call handler to transform instance calls to
2006 * WikiPage functions for backwards compatibility.
2008 * @param $fname String Name of called method
2009 * @param $args Array Arguments to the method
2011 public function __call( $fname, $args ) {
2012 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2013 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2014 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2016 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2019 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2020 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
2021 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
2024 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
2025 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2028 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2030 $user = is_null( $user ) ?
$wgUser : $user;
2031 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2034 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2036 $guser = is_null( $guser ) ?
$wgUser : $guser;
2037 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2040 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2041 public static function selectFields() {
2042 return WikiPage
::selectFields();
2045 public static function onArticleCreate( $title ) {
2046 return WikiPage
::onArticleCreate( $title );
2049 public static function onArticleDelete( $title ) {
2050 return WikiPage
::onArticleDelete( $title );
2053 public static function onArticleEdit( $title ) {
2054 return WikiPage
::onArticleEdit( $title );
2057 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2058 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2063 class PoolWorkArticleView
extends PoolCounterWork
{
2070 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2071 parent
::__construct( 'ArticleView', $key );
2072 $this->mArticle
= $article;
2073 $this->cacheable
= $useParserCache;
2074 $this->parserOptions
= $parserOptions;
2078 return $this->mArticle
->doViewParse();
2081 function getCachedWork() {
2084 $parserCache = ParserCache
::singleton();
2085 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2087 if ( $this->mArticle
->mParserOutput
!== false ) {
2088 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2089 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2090 # Ensure that UI elements requiring revision ID have
2091 # the correct version information.
2092 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2098 function fallback() {
2099 return $this->mArticle
->tryDirtyCache();
2103 * @param $status Status
2105 function error( $status ) {
2108 $wgOut->clearHTML(); // for release() errors
2109 $wgOut->enableClientCache( false );
2110 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2112 $errortext = $status->getWikiText( false, 'view-pool-error' );
2113 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );