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 $this->showDiffPage();
375 wfProfileOut( __METHOD__
);
380 # Allow frames by default
381 $wgOut->allowClickjacking();
383 $parserCache = ParserCache
::singleton();
385 $parserOptions = $this->mPage
->getParserOptions();
386 # Render printable version, use printable version cache
387 if ( $wgOut->isPrintable() ) {
388 $parserOptions->setIsPrintable( true );
389 $parserOptions->setEditSection( false );
390 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
391 $parserOptions->setEditSection( false );
394 # Try client and file cache
395 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
397 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
400 # Is it client cached?
401 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
402 wfDebug( __METHOD__
. ": done 304\n" );
403 wfProfileOut( __METHOD__
);
407 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
408 wfDebug( __METHOD__
. ": done file cache\n" );
409 # tell wgOut that output is taken care of
411 $this->mPage
->viewUpdates();
412 wfProfileOut( __METHOD__
);
418 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
419 $parserOptions->setEditSection( false );
422 # Should the parser cache be used?
423 $useParserCache = $this->useParserCache( $oldid );
424 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
425 if ( $wgUser->getStubThreshold() ) {
426 wfIncrStats( 'pcache_miss_stub' );
429 $wasRedirected = $this->showRedirectedFromHeader();
430 $this->showNamespaceHeader();
432 # Iterate through the possible ways of constructing the output text.
433 # Keep going until $outputDone is set, or we run out of things to do.
436 $this->mParserOutput
= false;
438 while ( !$outputDone && ++
$pass ) {
441 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
444 # Try the parser cache
445 if ( $useParserCache ) {
446 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
448 if ( $this->mParserOutput
!== false ) {
449 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
450 $wgOut->addParserOutput( $this->mParserOutput
);
451 # Ensure that UI elements requiring revision ID have
452 # the correct version information.
453 $wgOut->setRevisionId( $this->mPage
->getLatest() );
455 # Preload timestamp to avoid a DB hit
456 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
457 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
463 $text = $this->getContent();
464 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
465 wfDebug( __METHOD__
. ": showing missing article\n" );
466 $this->showMissingArticle();
467 wfProfileOut( __METHOD__
);
471 # Another whitelist check in case oldid is altering the title
472 if ( !$this->getTitle()->userCanRead() ) {
473 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
474 $wgOut->loginToUse();
477 wfProfileOut( __METHOD__
);
481 # Are we looking at an old revision
482 if ( $oldid && !is_null( $this->mRevision
) ) {
483 $this->setOldSubtitle( $oldid );
485 if ( !$this->showDeletedRevisionHeader() ) {
486 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
487 wfProfileOut( __METHOD__
);
491 # If this "old" version is the current, then try the parser cache...
492 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
493 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
494 if ( $this->mParserOutput
) {
495 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
496 $wgOut->addParserOutput( $this->mParserOutput
);
497 $wgOut->setRevisionId( $this->mPage
->getLatest() );
504 # Ensure that UI elements requiring revision ID have
505 # the correct version information.
506 $wgOut->setRevisionId( $this->getRevIdFetched() );
508 # Pages containing custom CSS or JavaScript get special treatment
509 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
510 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
511 $this->showCssOrJsPage();
514 $rt = Title
::newFromRedirectArray( $text );
516 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
517 # Viewing a redirect page (e.g. with parameter redirect=no)
518 # Don't append the subtitle if this was an old revision
519 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
520 # Parse just to get categories, displaytitle, etc.
521 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
522 $wgOut->addParserOutputNoText( $this->mParserOutput
);
528 # Run the parse, protected by a pool counter
529 wfDebug( __METHOD__
. ": doing uncached parse\n" );
531 $key = $parserCache->getKey( $this, $parserOptions );
532 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
534 if ( !$poolArticleView->execute() ) {
535 # Connection or timeout error
536 wfProfileOut( __METHOD__
);
542 # Should be unreachable, but just in case...
548 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
549 if ( $this->mParserOutput
) {
550 $titleText = $this->mParserOutput
->getTitleText();
552 if ( strval( $titleText ) !== '' ) {
553 $wgOut->setPageTitle( $titleText );
557 # For the main page, overwrite the <title> element with the con-
558 # tents of 'pagetitle-view-mainpage' instead of the default (if
560 # This message always exists because it is in the i18n files
561 if ( $this->getTitle()->equals( Title
::newMainPage() ) ) {
562 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
563 if ( !$msg->isDisabled() ) {
564 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
568 # Now that we've filled $this->mParserOutput, we know whether
569 # there are any __NOINDEX__ tags on the page
570 $policy = $this->getRobotPolicy( 'view' );
571 $wgOut->setIndexPolicy( $policy['index'] );
572 $wgOut->setFollowPolicy( $policy['follow'] );
574 $this->showViewFooter();
575 $this->mPage
->viewUpdates();
576 wfProfileOut( __METHOD__
);
580 * Show a diff page according to current request variables. For use within
581 * Article::view() only, other callers should use the DifferenceEngine class.
583 public function showDiffPage() {
584 global $wgRequest, $wgUser;
586 $diff = $wgRequest->getVal( 'diff' );
587 $rcid = $wgRequest->getVal( 'rcid' );
588 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
589 $purge = $wgRequest->getVal( 'action' ) == 'purge';
590 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
591 $oldid = $this->getOldID();
593 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
594 // DifferenceEngine directly fetched the revision:
595 $this->mRevIdFetched
= $de->mNewid
;
596 $de->showDiffPage( $diffOnly );
598 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
599 # Run view updates for current revision only
600 $this->mPage
->viewUpdates();
605 * Show a page view for a page formatted as CSS or JavaScript. To be called by
606 * Article::view() only.
608 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
611 protected function showCssOrJsPage() {
612 global $wgOut, $wgLang;
614 $dir = $wgLang->getDir();
615 $lang = $wgLang->getCode();
617 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
620 // Give hooks a chance to customise the output
621 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
622 // Wrap the whole lot in a <pre> and don't parse
624 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
625 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
626 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
627 $wgOut->addHTML( "\n</pre>\n" );
632 * Get the robot policy to be used for the current view
633 * @param $action String the action= GET parameter
634 * @return Array the policy that should be set
635 * TODO: actions other than 'view'
637 public function getRobotPolicy( $action ) {
638 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
639 global $wgDefaultRobotPolicy, $wgRequest;
641 $ns = $this->getTitle()->getNamespace();
643 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
644 # Don't index user and user talk pages for blocked users (bug 11443)
645 if ( !$this->getTitle()->isSubpage() ) {
646 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
648 'index' => 'noindex',
649 'follow' => 'nofollow'
655 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
656 # Non-articles (special pages etc), and old revisions
658 'index' => 'noindex',
659 'follow' => 'nofollow'
661 } elseif ( $wgOut->isPrintable() ) {
662 # Discourage indexing of printable versions, but encourage following
664 'index' => 'noindex',
667 } elseif ( $wgRequest->getInt( 'curid' ) ) {
668 # For ?curid=x urls, disallow indexing
670 'index' => 'noindex',
675 # Otherwise, construct the policy based on the various config variables.
676 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
678 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
679 # Honour customised robot policies for this namespace
680 $policy = array_merge(
682 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
685 if ( $this->getTitle()->canUseNoindex() && is_object( $this->mParserOutput
) && $this->mParserOutput
->getIndexPolicy() ) {
686 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
687 # a final sanity check that we have really got the parser output.
688 $policy = array_merge(
690 array( 'index' => $this->mParserOutput
->getIndexPolicy() )
694 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
695 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
696 $policy = array_merge(
698 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
706 * Converts a String robot policy into an associative array, to allow
707 * merging of several policies using array_merge().
708 * @param $policy Mixed, returns empty array on null/false/'', transparent
709 * to already-converted arrays, converts String.
710 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
712 public static function formatRobotPolicy( $policy ) {
713 if ( is_array( $policy ) ) {
715 } elseif ( !$policy ) {
719 $policy = explode( ',', $policy );
720 $policy = array_map( 'trim', $policy );
723 foreach ( $policy as $var ) {
724 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
725 $arr['index'] = $var;
726 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
727 $arr['follow'] = $var;
735 * If this request is a redirect view, send "redirected from" subtitle to
736 * $wgOut. Returns true if the header was needed, false if this is not a
737 * redirect view. Handles both local and remote redirects.
741 public function showRedirectedFromHeader() {
742 global $wgOut, $wgRequest, $wgRedirectSources;
744 $rdfrom = $wgRequest->getVal( 'rdfrom' );
746 if ( isset( $this->mRedirectedFrom
) ) {
747 // This is an internally redirected page view.
748 // We'll need a backlink to the source page for navigation.
749 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
750 $redir = Linker
::link(
751 $this->mRedirectedFrom
,
754 array( 'redirect' => 'no' ),
755 array( 'known', 'noclasses' )
758 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
759 $wgOut->setSubtitle( $s );
761 // Set the fragment if one was specified in the redirect
762 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
763 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
764 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
767 // Add a <link rel="canonical"> tag
768 $wgOut->addLink( array( 'rel' => 'canonical',
769 'href' => $this->getTitle()->getLocalURL() )
774 } elseif ( $rdfrom ) {
775 // This is an externally redirected view, from some other wiki.
776 // If it was reported from a trusted site, supply a backlink.
777 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
778 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
779 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
780 $wgOut->setSubtitle( $s );
790 * Show a header specific to the namespace currently being viewed, like
791 * [[MediaWiki:Talkpagetext]]. For Article::view().
793 public function showNamespaceHeader() {
796 if ( $this->getTitle()->isTalkPage() ) {
797 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
798 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
804 * Show the footer section of an ordinary page view
806 public function showViewFooter() {
807 global $wgOut, $wgUseTrackbacks;
809 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
810 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
811 $wgOut->addWikiMsg( 'anontalkpagetext' );
814 # If we have been passed an &rcid= parameter, we want to give the user a
815 # chance to mark this new article as patrolled.
816 $this->showPatrolFooter();
819 if ( $wgUseTrackbacks ) {
820 $this->addTrackbacks();
823 wfRunHooks( 'ArticleViewFooter', array( $this ) );
828 * If patrol is possible, output a patrol UI box. This is called from the
829 * footer section of ordinary page views. If patrol is not possible or not
830 * desired, does nothing.
832 public function showPatrolFooter() {
833 global $wgOut, $wgRequest, $wgUser;
835 $rcid = $wgRequest->getVal( 'rcid' );
837 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
841 $token = $wgUser->editToken( $rcid );
842 $wgOut->preventClickjacking();
845 "<div class='patrollink'>" .
847 'markaspatrolledlink',
850 wfMsgHtml( 'markaspatrolledtext' ),
853 'action' => 'markpatrolled',
857 array( 'known', 'noclasses' )
865 * Show the error text for a missing article. For articles in the MediaWiki
866 * namespace, show the default message text. To be called from Article::view().
868 public function showMissingArticle() {
869 global $wgOut, $wgRequest, $wgUser;
871 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
872 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
873 $parts = explode( '/', $this->getTitle()->getText() );
874 $rootPart = $parts[0];
875 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
876 $ip = User
::isIP( $rootPart );
878 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
879 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
880 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
881 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
882 LogEventsList
::showLogExtract(
885 $user->getUserPage()->getPrefixedText(),
889 'showIfEmpty' => false,
891 'blocked-notice-logextract',
892 $user->getName() # Support GENDER in notice
899 wfRunHooks( 'ShowMissingArticle', array( $this ) );
901 # Show delete and move logs
902 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
904 'conds' => array( "log_action != 'revision'" ),
905 'showIfEmpty' => false,
906 'msgKey' => array( 'moveddeleted-notice' ) )
910 $oldid = $this->getOldID();
912 $text = wfMsgNoTrans( 'missing-article',
913 $this->getTitle()->getPrefixedText(),
914 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
915 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
916 // Use the default message text
917 $text = $this->getTitle()->getDefaultMessageText();
919 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
920 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
921 $errors = array_merge( $createErrors, $editErrors );
923 if ( !count( $errors ) ) {
924 $text = wfMsgNoTrans( 'noarticletext' );
926 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
929 $text = "<div class='noarticletext'>\n$text\n</div>";
931 if ( !$this->mPage
->hasViewableContent() ) {
932 // If there's no backing content, send a 404 Not Found
933 // for better machine handling of broken links.
934 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
937 $wgOut->addWikiText( $text );
941 * If the revision requested for view is deleted, check permissions.
942 * Send either an error message or a warning header to $wgOut.
944 * @return boolean true if the view is allowed, false if not.
946 public function showDeletedRevisionHeader() {
947 global $wgOut, $wgRequest;
949 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
954 // If the user is not allowed to see it...
955 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
956 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
957 'rev-deleted-text-permission' );
960 // If the user needs to confirm that they want to see it...
961 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
962 # Give explanation and add a link to view the revision...
963 $oldid = intval( $this->getOldID() );
964 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
965 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
966 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
967 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
968 array( $msg, $link ) );
971 // We are allowed to see...
973 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
974 'rev-suppressed-text-view' : 'rev-deleted-text-view';
975 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
982 * Execute the uncached parse for action=view
984 public function doViewParse() {
987 $oldid = $this->getOldID();
988 $parserOptions = $this->mPage
->getParserOptions();
990 # Render printable version, use printable version cache
991 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
993 # Don't show section-edit links on old revisions... this way lies madness.
994 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
995 $parserOptions->setEditSection( false );
998 $useParserCache = $this->useParserCache( $oldid );
999 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1005 * Try to fetch an expired entry from the parser cache. If it is present,
1006 * output it and return true. If it is not present, output nothing and
1007 * return false. This is used as a callback function for
1008 * PoolCounter::executeProtected().
1012 public function tryDirtyCache() {
1014 $parserCache = ParserCache
::singleton();
1015 $options = $this->mPage
->getParserOptions();
1017 if ( $wgOut->isPrintable() ) {
1018 $options->setIsPrintable( true );
1019 $options->setEditSection( false );
1022 $output = $parserCache->getDirty( $this, $options );
1025 wfDebug( __METHOD__
. ": sending dirty output\n" );
1026 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1027 $wgOut->setSquidMaxage( 0 );
1028 $this->mParserOutput
= $output;
1029 $wgOut->addParserOutput( $output );
1030 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1034 wfDebugLog( 'dirty', "dirty missing\n" );
1035 wfDebug( __METHOD__
. ": no dirty cache\n" );
1044 * @param $target Title|Array of destination(s) to redirect
1045 * @param $appendSubtitle Boolean [optional]
1046 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1047 * @return string containing HMTL with redirect link
1049 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1050 global $wgOut, $wgLang, $wgStylePath;
1052 if ( !is_array( $target ) ) {
1053 $target = array( $target );
1056 $imageDir = $wgLang->getDir();
1058 if ( $appendSubtitle ) {
1059 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1062 // the loop prepends the arrow image before the link, so the first case needs to be outside
1063 $title = array_shift( $target );
1065 if ( $forceKnown ) {
1066 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1068 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1071 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1072 $alt = $wgLang->isRTL() ?
'←' : '→';
1073 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1074 foreach ( $target as $rt ) {
1075 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1076 if ( $forceKnown ) {
1077 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1079 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1083 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1084 return '<div class="redirectMsg">' .
1085 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1086 '<span class="redirectText">' . $link . '</span></div>';
1090 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1092 public function addTrackbacks() {
1095 $dbr = wfGetDB( DB_SLAVE
);
1096 $tbs = $dbr->select( 'trackbacks',
1097 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1098 array( 'tb_page' => $this->mPage
->getID() )
1101 if ( !$dbr->numRows( $tbs ) ) {
1105 $wgOut->preventClickjacking();
1108 foreach ( $tbs as $o ) {
1111 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1112 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1113 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1114 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1118 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1126 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1130 * Removes trackback record for current article from trackbacks table
1131 * @deprecated since 1.19
1133 public function deletetrackback() {
1134 return Action
::factory( 'deletetrackback', $this )->show();
1138 * Handle action=render
1141 public function render() {
1144 $wgOut->setArticleBodyOnly( true );
1149 * Handle action=purge
1151 public function purge() {
1152 return Action
::factory( 'purge', $this )->show();
1156 * Mark this particular edit/page as patrolled
1157 * @deprecated since 1.19
1159 public function markpatrolled() {
1160 Action
::factory( 'markpatrolled', $this )->show();
1164 * User-interface handler for the "watch" action.
1165 * Requires Request to pass a token as of 1.19.
1166 * @deprecated since 1.18
1168 public function watch() {
1169 Action
::factory( 'watch', $this )->show();
1173 * Add this page to $wgUser's watchlist
1175 * This is safe to be called multiple times
1177 * @return bool true on successful watch operation
1178 * @deprecated since 1.18
1180 public function doWatch() {
1182 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1186 * User interface handler for the "unwatch" action.
1187 * Requires Request to pass a token as of 1.19.
1188 * @deprecated since 1.18
1190 public function unwatch() {
1191 Action
::factory( 'unwatch', $this )->show();
1195 * Stop watching a page
1196 * @return bool true on successful unwatch
1197 * @deprecated since 1.18
1199 public function doUnwatch() {
1201 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1205 * action=protect handler
1207 public function protect() {
1208 $form = new ProtectionForm( $this );
1213 * action=unprotect handler (alias)
1215 public function unprotect() {
1220 * Info about this page
1221 * Called for ?action=info when $wgAllowPageInfo is on.
1223 public function info() {
1224 Action
::factory( 'info', $this )->show();
1228 * Overriden by ImagePage class, only present here to avoid a fatal error
1229 * Called for ?action=revert
1231 public function revert() {
1232 Action
::factory( 'revert', $this )->show();
1236 * User interface for rollback operations
1238 public function rollback() {
1239 Action
::factory( 'rollback', $this )->show();
1243 * Output a redirect back to the article.
1244 * This is typically used after an edit.
1246 * @deprecated in 1.19; call $wgOut->redirect() directly
1247 * @param $noRedir Boolean: add redirect=no
1248 * @param $sectionAnchor String: section to redirect to, including "#"
1249 * @param $extraQuery String: extra query params
1251 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1252 wfDeprecated( __METHOD__
);
1256 $query = 'redirect=no';
1258 $query .= "&$extraQuery";
1260 $query = $extraQuery;
1263 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1267 * Auto-generates a deletion reason
1269 * @param &$hasHistory Boolean: whether the page has a history
1270 * @return mixed String containing deletion reason or empty string, or boolean false
1271 * if no revision occurred
1273 public function generateReason( &$hasHistory ) {
1276 $dbw = wfGetDB( DB_MASTER
);
1277 // Get the last revision
1278 $rev = Revision
::newFromTitle( $this->getTitle() );
1280 if ( is_null( $rev ) ) {
1284 // Get the article's contents
1285 $contents = $rev->getText();
1288 // If the page is blank, use the text from the previous revision,
1289 // which can only be blank if there's a move/import/protect dummy revision involved
1290 if ( $contents == '' ) {
1291 $prev = $rev->getPrevious();
1294 $contents = $prev->getText();
1299 // Find out if there was only one contributor
1300 // Only scan the last 20 revisions
1301 $res = $dbw->select( 'revision', 'rev_user_text',
1302 array( 'rev_page' => $this->mPage
->getID(), $dbw->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0' ),
1304 array( 'LIMIT' => 20 )
1307 if ( $res === false ) {
1308 // This page has no revisions, which is very weird
1312 $hasHistory = ( $res->numRows() > 1 );
1313 $row = $dbw->fetchObject( $res );
1315 if ( $row ) { // $row is false if the only contributor is hidden
1316 $onlyAuthor = $row->rev_user_text
;
1317 // Try to find a second contributor
1318 foreach ( $res as $row ) {
1319 if ( $row->rev_user_text
!= $onlyAuthor ) { // Bug 22999
1320 $onlyAuthor = false;
1325 $onlyAuthor = false;
1328 // Generate the summary with a '$1' placeholder
1330 // The current revision is blank and the one before is also
1331 // blank. It's just not our lucky day
1332 $reason = wfMsgForContent( 'exbeforeblank', '$1' );
1334 if ( $onlyAuthor ) {
1335 $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
1337 $reason = wfMsgForContent( 'excontent', '$1' );
1341 if ( $reason == '-' ) {
1342 // Allow these UI messages to be blanked out cleanly
1346 // Replace newlines with spaces to prevent uglyness
1347 $contents = preg_replace( "/[\n\r]/", ' ', $contents );
1348 // Calculate the maximum amount of chars to get
1349 // Max content length = max comment length - length of the comment (excl. $1)
1350 $maxLength = 255 - ( strlen( $reason ) - 2 );
1351 $contents = $wgContLang->truncate( $contents, $maxLength );
1352 // Remove possible unfinished links
1353 $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
1354 // Now replace the '$1' placeholder
1355 $reason = str_replace( '$1', $contents, $reason );
1362 * UI entry point for page deletion
1364 public function delete() {
1365 global $wgOut, $wgRequest;
1367 $confirm = $wgRequest->wasPosted() &&
1368 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1370 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1371 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1373 $reason = $this->DeleteReasonList
;
1375 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1376 // Entry from drop down menu + additional comment
1377 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1378 } elseif ( $reason == 'other' ) {
1379 $reason = $this->DeleteReason
;
1382 # Flag to hide all contents of the archived revisions
1383 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1385 # This code desperately needs to be totally rewritten
1387 # Read-only check...
1388 if ( wfReadOnly() ) {
1389 $wgOut->readOnlyPage();
1395 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1397 if ( count( $permission_errors ) > 0 ) {
1398 $wgOut->showPermissionsErrorPage( $permission_errors );
1403 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1405 # Better double-check that it hasn't been deleted yet!
1406 $dbw = wfGetDB( DB_MASTER
);
1407 $conds = $this->getTitle()->pageCond();
1408 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1409 if ( $latest === false ) {
1410 $wgOut->showFatalError(
1413 array( 'class' => 'error mw-error-cannotdelete' ),
1414 wfMsgExt( 'cannotdelete', array( 'parse' ),
1415 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1418 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1419 LogEventsList
::showLogExtract(
1422 $this->getTitle()->getPrefixedText()
1428 # Hack for big sites
1429 $bigHistory = $this->mPage
->isBigDeletion();
1430 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1431 global $wgLang, $wgDeleteRevisionsLimit;
1433 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1434 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1440 $this->doDelete( $reason, $suppress );
1442 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1444 } elseif ( $this->getTitle()->userIsWatching() ) {
1451 // Generate deletion reason
1452 $hasHistory = false;
1454 $reason = $this->generateReason( $hasHistory );
1457 // If the page has a history, insert a warning
1458 if ( $hasHistory && !$confirm ) {
1461 $revisions = $this->mPage
->estimateRevisionCount();
1462 // @todo FIXME: i18n issue/patchwork message
1463 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1464 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1465 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1466 wfMsgHtml( 'history' ),
1467 array( 'rel' => 'archives' ),
1468 array( 'action' => 'history' ) ) .
1472 if ( $bigHistory ) {
1473 global $wgDeleteRevisionsLimit;
1474 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1475 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1479 return $this->confirmDelete( $reason );
1483 * Output deletion confirmation dialog
1484 * @todo FIXME: Move to another file?
1485 * @param $reason String: prefilled reason
1487 public function confirmDelete( $reason ) {
1490 wfDebug( "Article::confirmDelete\n" );
1492 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1493 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1494 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1495 $wgOut->addWikiMsg( 'confirmdeletetext' );
1497 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1499 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1500 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1502 <td class='mw-input'><strong>" .
1503 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1504 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1510 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1512 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1513 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1514 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1515 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1516 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1517 "<tr id=\"wpDeleteReasonListRow\">
1518 <td class='mw-label'>" .
1519 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1521 <td class='mw-input'>" .
1522 Xml
::listDropDown( 'wpDeleteReasonList',
1523 wfMsgForContent( 'deletereason-dropdown' ),
1524 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1527 <tr id=\"wpDeleteReasonRow\">
1528 <td class='mw-label'>" .
1529 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1531 <td class='mw-input'>" .
1532 Html
::input( 'wpReason', $reason, 'text', array(
1534 'maxlength' => '255',
1542 # Disallow watching if user is not logged in
1543 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1547 <td class='mw-input'>" .
1548 Xml
::checkLabel( wfMsg( 'watchthis' ),
1549 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1558 <td class='mw-submit'>" .
1559 Xml
::submitButton( wfMsg( 'deletepage' ),
1560 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1563 Xml
::closeElement( 'table' ) .
1564 Xml
::closeElement( 'fieldset' ) .
1565 Html
::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1566 Xml
::closeElement( 'form' );
1568 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1569 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1570 $link = Linker
::link(
1572 wfMsgHtml( 'delete-edit-reasonlist' ),
1574 array( 'action' => 'edit' )
1576 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1579 $wgOut->addHTML( $form );
1580 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1581 LogEventsList
::showLogExtract( $wgOut, 'delete',
1582 $this->getTitle()->getPrefixedText()
1587 * Perform a deletion and output success or failure messages
1589 public function doDelete( $reason, $suppress = false ) {
1592 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1595 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1596 $deleted = $this->getTitle()->getPrefixedText();
1598 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1599 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1601 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1603 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1604 $wgOut->returnToMain( false );
1606 if ( $error == '' ) {
1607 $wgOut->showFatalError(
1610 array( 'class' => 'error mw-error-cannotdelete' ),
1611 wfMsgExt( 'cannotdelete', array( 'parse' ),
1612 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1616 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1618 LogEventsList
::showLogExtract(
1621 $this->getTitle()->getPrefixedText()
1624 $wgOut->showFatalError( $error );
1630 * Generate the navigation links when browsing through an article revisions
1631 * It shows the information as:
1632 * Revision as of \<date\>; view current revision
1633 * \<- Previous version | Next Version -\>
1635 * @param $oldid String: revision ID of this article revision
1637 public function setOldSubtitle( $oldid = 0 ) {
1638 global $wgLang, $wgOut, $wgUser, $wgRequest;
1640 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1644 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1646 # Cascade unhide param in links for easy deletion browsing
1647 $extraParams = array();
1648 if ( $wgRequest->getVal( 'unhide' ) ) {
1649 $extraParams['unhide'] = 1;
1652 $revision = Revision
::newFromId( $oldid );
1653 $timestamp = $revision->getTimestamp();
1655 $current = ( $oldid == $this->mPage
->getLatest() );
1656 $td = $wgLang->timeanddate( $timestamp, true );
1657 $tddate = $wgLang->date( $timestamp, true );
1658 $tdtime = $wgLang->time( $timestamp, true );
1661 ?
wfMsgHtml( 'currentrevisionlink' )
1664 wfMsgHtml( 'currentrevisionlink' ),
1667 array( 'known', 'noclasses' )
1670 ?
wfMsgHtml( 'diff' )
1673 wfMsgHtml( 'diff' ),
1679 array( 'known', 'noclasses' )
1681 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1685 wfMsgHtml( 'previousrevision' ),
1688 'direction' => 'prev',
1691 array( 'known', 'noclasses' )
1693 : wfMsgHtml( 'previousrevision' );
1697 wfMsgHtml( 'diff' ),
1703 array( 'known', 'noclasses' )
1705 : wfMsgHtml( 'diff' );
1706 $nextlink = $current
1707 ?
wfMsgHtml( 'nextrevision' )
1710 wfMsgHtml( 'nextrevision' ),
1713 'direction' => 'next',
1716 array( 'known', 'noclasses' )
1718 $nextdiff = $current
1719 ?
wfMsgHtml( 'diff' )
1722 wfMsgHtml( 'diff' ),
1728 array( 'known', 'noclasses' )
1733 // User can delete revisions or view deleted revisions...
1734 $canHide = $wgUser->isAllowed( 'deleterevision' );
1735 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1736 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1737 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1740 'type' => 'revision',
1741 'target' => $this->getTitle()->getPrefixedDbkey(),
1744 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1749 # Show user links if allowed to see them. If hidden, then show them only if requested...
1750 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1752 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1753 ?
'revision-info-current'
1756 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1759 array( 'parseinline', 'replaceafter' ),
1765 $revision->getUser()
1768 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1769 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1771 $wgOut->setSubtitle( $r );
1774 /* Caching functions */
1777 * checkLastModified returns true if it has taken care of all
1778 * output to the client that is necessary for this request.
1779 * (that is, it has sent a cached version of the page)
1781 * @return boolean true if cached version send, false otherwise
1783 protected function tryFileCache() {
1784 static $called = false;
1787 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1792 if ( $this->isFileCacheable() ) {
1793 $cache = new HTMLFileCache( $this->getTitle() );
1794 if ( $cache->isFileCacheGood( $this->mPage
->getTouched() ) ) {
1795 wfDebug( "Article::tryFileCache(): about to load file\n" );
1796 $cache->loadFromFileCache();
1799 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1800 ob_start( array( &$cache, 'saveToFileCache' ) );
1803 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1810 * Check if the page can be cached
1813 public function isFileCacheable() {
1816 if ( HTMLFileCache
::useFileCache() ) {
1817 $cacheable = $this->mPage
->getID() && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1818 // Extension may have reason to disable file caching on some pages.
1820 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1830 * Add the primary page-view wikitext to the output buffer
1831 * Saves the text into the parser cache if possible.
1832 * Updates templatelinks if it is out of date.
1834 * @param $text String
1835 * @param $cache Boolean
1836 * @param $parserOptions mixed ParserOptions object, or boolean false
1838 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1841 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1843 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1845 $wgOut->addParserOutput( $this->mParserOutput
);
1849 * Lightweight method to get the parser output for a page, checking the parser cache
1850 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1851 * consider, so it's not appropriate to use there.
1853 * @since 1.16 (r52326) for LiquidThreads
1855 * @param $oldid mixed integer Revision ID or null
1856 * @param $user User The relevant user
1857 * @return ParserOutput or false if the given revsion ID is not found
1859 public function getParserOutput( $oldid = null, User
$user = null ) {
1860 global $wgEnableParserCache, $wgUser;
1861 $user = is_null( $user ) ?
$wgUser : $user;
1863 // Should the parser cache be used?
1864 $useParserCache = $wgEnableParserCache &&
1865 $user->getStubThreshold() == 0 &&
1866 $this->mPage
->exists() &&
1869 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1871 if ( $user->getStubThreshold() ) {
1872 wfIncrStats( 'pcache_miss_stub' );
1875 if ( $useParserCache ) {
1876 $parserOutput = ParserCache
::singleton()->get( $this, $this->mPage
->getParserOptions() );
1877 if ( $parserOutput !== false ) {
1878 return $parserOutput;
1882 // Cache miss; parse and output it.
1883 if ( $oldid === null ) {
1884 $text = $this->mPage
->getRawText();
1886 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1887 if ( $rev === null ) {
1890 $text = $rev->getText();
1893 return $this->getOutputFromWikitext( $text, $useParserCache );
1897 * This does all the heavy lifting for outputWikitext, except it returns the parser
1898 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1899 * say, embedding thread pages within a discussion system (LiquidThreads)
1901 * @param $text string
1902 * @param $cache boolean
1903 * @param $parserOptions parsing options, defaults to false
1904 * @return ParserOutput
1906 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1907 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1909 if ( !$parserOptions ) {
1910 $parserOptions = $this->mPage
->getParserOptions();
1914 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1915 $parserOptions, true, true, $this->getRevIdFetched() );
1920 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1921 $this->getTitle()->getPrefixedDBkey() ) );
1924 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1925 $parserCache = ParserCache
::singleton();
1926 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1929 // Make sure file cache is not used on uncacheable content.
1930 // Output that has magic words in it can still use the parser cache
1931 // (if enabled), though it will generally expire sooner.
1932 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1933 $wgUseFileCache = false;
1936 if ( $this->isCurrent() ) {
1937 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1940 return $this->mParserOutput
;
1944 * Sets the context this Article is executed in
1946 * @param $context RequestContext
1949 public function setContext( $context ) {
1950 $this->mContext
= $context;
1954 * Gets the context this Article is executed in
1956 * @return RequestContext
1959 public function getContext() {
1960 if ( $this->mContext
instanceof RequestContext
) {
1961 return $this->mContext
;
1963 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1964 return RequestContext
::getMain();
1969 * Use PHP's magic __get handler to handle accessing of
1970 * raw WikiPage fields for backwards compatibility.
1972 * @param $fname String Field name
1974 public function __get( $fname ) {
1975 if ( property_exists( $this->mPage
, $fname ) ) {
1976 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1977 return $this->mPage
->$fname;
1979 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1983 * Use PHP's magic __set handler to handle setting of
1984 * raw WikiPage fields for backwards compatibility.
1986 * @param $fname String Field name
1987 * @param $fvalue mixed New value
1988 * @param $args Array Arguments to the method
1990 public function __set( $fname, $fvalue ) {
1991 if ( property_exists( $this->mPage
, $fname ) ) {
1992 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1993 $this->mPage
->$fname = $fvalue;
1994 // Note: extensions may want to toss on new fields
1995 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1996 $this->mPage
->$fname = $fvalue;
1998 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2003 * Use PHP's magic __call handler to transform instance calls to
2004 * WikiPage functions for backwards compatibility.
2006 * @param $fname String Name of called method
2007 * @param $args Array Arguments to the method
2009 public function __call( $fname, $args ) {
2010 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2011 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2012 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2014 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2017 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2018 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
2019 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
2022 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
2023 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2026 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2028 $user = is_null( $user ) ?
$wgUser : $user;
2029 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2032 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2034 $guser = is_null( $guser ) ?
$wgUser : $guser;
2035 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2038 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2039 public static function selectFields() {
2040 return WikiPage
::selectFields();
2043 public static function onArticleCreate( $title ) {
2044 return WikiPage
::onArticleCreate( $title );
2047 public static function onArticleDelete( $title ) {
2048 return WikiPage
::onArticleDelete( $title );
2051 public static function onArticleEdit( $title ) {
2052 return WikiPage
::onArticleEdit( $title );
2055 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2056 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2061 class PoolWorkArticleView
extends PoolCounterWork
{
2068 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2069 parent
::__construct( 'ArticleView', $key );
2070 $this->mArticle
= $article;
2071 $this->cacheable
= $useParserCache;
2072 $this->parserOptions
= $parserOptions;
2076 return $this->mArticle
->doViewParse();
2079 function getCachedWork() {
2082 $parserCache = ParserCache
::singleton();
2083 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2085 if ( $this->mArticle
->mParserOutput
!== false ) {
2086 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2087 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2088 # Ensure that UI elements requiring revision ID have
2089 # the correct version information.
2090 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2096 function fallback() {
2097 return $this->mArticle
->tryDirtyCache();
2101 * @param $status Status
2103 function error( $status ) {
2106 $wgOut->clearHTML(); // for release() errors
2107 $wgOut->enableClientCache( false );
2108 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2110 $errortext = $status->getWikiText( false, 'view-pool-error' );
2111 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );