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 this text redirects to
131 * @param $text string article content containing redirect info
132 * @return mixed false, Title of in-wiki target, or string with URL
133 * @deprecated since 1.17
135 public function followRedirectText( $text ) {
136 // recurse through to only get the final target
137 return $this->getRedirectURL( Title
::newFromRedirectRecurse( $text ) );
141 * Get the title object of the article
142 * @return Title object of this page
144 public function getTitle() {
145 return $this->mPage
->getTitle();
150 * @todo FIXME: Shouldn't this be public?
153 public function clear() {
154 $this->mContentLoaded
= false;
156 $this->mRedirectedFrom
= null; # Title object if set
157 $this->mRevIdFetched
= 0;
158 $this->mRedirectUrl
= false;
160 $this->mPage
->clear();
164 * Note that getContent/loadContent do not follow redirects anymore.
165 * If you need to fetch redirectable content easily, try
166 * the shortcut in Article::followRedirect()
168 * This function has side effects! Do not use this function if you
169 * only want the real revision text if any.
171 * @return Return the text of this revision
173 public function getContent() {
176 wfProfileIn( __METHOD__
);
178 if ( $this->mPage
->getID() === 0 ) {
179 # If this is a MediaWiki:x message, then load the messages
180 # and return the message value for x.
181 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
182 $text = $this->getTitle()->getDefaultMessageText();
183 if ( $text === false ) {
187 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
189 wfProfileOut( __METHOD__
);
193 $this->loadContent();
194 wfProfileOut( __METHOD__
);
196 return $this->mContent
;
201 * @return int The oldid of the article that is to be shown, 0 for the
204 public function getOldID() {
205 if ( is_null( $this->mOldId
) ) {
206 $this->mOldId
= $this->getOldIDFromRequest();
209 return $this->mOldId
;
213 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
215 * @return int The old id for the request
217 public function getOldIDFromRequest() {
220 $this->mRedirectUrl
= false;
222 $oldid = $wgRequest->getVal( 'oldid' );
224 if ( isset( $oldid ) ) {
225 $oldid = intval( $oldid );
226 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
227 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
231 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
233 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
234 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
249 * Load the revision (including text) into this object
251 function loadContent() {
252 if ( $this->mContentLoaded
) {
256 wfProfileIn( __METHOD__
);
258 $this->fetchContent( $this->getOldID() );
260 wfProfileOut( __METHOD__
);
264 * Get text of an article from database
265 * Does *NOT* follow redirects.
267 * @param $oldid Int: 0 for whatever the latest revision is
268 * @return mixed string containing article contents, or false if null
270 function fetchContent( $oldid = 0 ) {
271 if ( $this->mContentLoaded
) {
272 return $this->mContent
;
275 # Pre-fill content with error message so that if something
276 # fails we'll have something telling us what we intended.
277 $t = $this->getTitle()->getPrefixedText();
278 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
279 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
282 $revision = Revision
::newFromId( $oldid );
283 if ( $revision === null ) {
284 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
287 // Revision title doesn't match the page title given?
288 if ( $this->mPage
->getID() != $revision->getPage() ) {
289 $function = array( get_class( $this->mPage
), 'newFromID' );
290 $this->mPage
= call_user_func( $function, $revision->getPage() );
291 if ( !$this->mPage
->getId() ) {
292 wfDebug( __METHOD__
. " failed to get page data linked to revision id $oldid\n" );
297 if ( $this->mPage
->getLatest() === false ) {
298 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
302 $revision = $this->mPage
->getRevision();
303 if ( $revision === null ) {
304 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
309 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
310 // We should instead work with the Revision object when we need it...
311 $this->mContent
= $revision->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
313 $this->mRevIdFetched
= $revision->getId();
314 $this->mContentLoaded
= true;
315 $this->mRevision
=& $revision;
317 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
319 return $this->mContent
;
324 * @deprecated since 1.18
326 public function forUpdate() {
327 wfDeprecated( __METHOD__
);
331 * Returns true if the currently-referenced revision is the current edit
332 * to this page (and it exists).
335 public function isCurrent() {
336 # If no oldid, this is the current version.
337 if ( $this->getOldID() == 0 ) {
341 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
345 * Use this to fetch the rev ID used on page views
347 * @return int revision ID of last article revision
349 public function getRevIdFetched() {
350 if ( $this->mRevIdFetched
) {
351 return $this->mRevIdFetched
;
353 return $this->mPage
->getLatest();
358 * This is the default action of the index.php entry point: just view the
359 * page of the given title.
361 public function view() {
362 global $wgUser, $wgOut, $wgRequest, $wgParser;
363 global $wgUseFileCache, $wgUseETag;
365 wfProfileIn( __METHOD__
);
367 # Get variables from query string
368 $oldid = $this->getOldID();
370 # getOldID may want us to redirect somewhere else
371 if ( $this->mRedirectUrl
) {
372 $wgOut->redirect( $this->mRedirectUrl
);
373 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
374 wfProfileOut( __METHOD__
);
379 $wgOut->setArticleFlag( true );
380 # Set page title (may be overridden by DISPLAYTITLE)
381 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
383 # If we got diff in the query, we want to see a diff page instead of the article.
384 if ( $wgRequest->getCheck( 'diff' ) ) {
385 wfDebug( __METHOD__
. ": showing diff page\n" );
386 $this->showDiffPage();
387 wfProfileOut( __METHOD__
);
392 # Allow frames by default
393 $wgOut->allowClickjacking();
395 $parserCache = ParserCache
::singleton();
397 $parserOptions = $this->mPage
->getParserOptions();
398 # Render printable version, use printable version cache
399 if ( $wgOut->isPrintable() ) {
400 $parserOptions->setIsPrintable( true );
401 $parserOptions->setEditSection( false );
402 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
403 $parserOptions->setEditSection( false );
406 # Try client and file cache
407 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
409 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
412 # Is it client cached?
413 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
414 wfDebug( __METHOD__
. ": done 304\n" );
415 wfProfileOut( __METHOD__
);
419 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
420 wfDebug( __METHOD__
. ": done file cache\n" );
421 # tell wgOut that output is taken care of
423 $this->mPage
->viewUpdates();
424 wfProfileOut( __METHOD__
);
430 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
431 $parserOptions->setEditSection( false );
434 # Should the parser cache be used?
435 $useParserCache = $this->useParserCache( $oldid );
436 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
437 if ( $wgUser->getStubThreshold() ) {
438 wfIncrStats( 'pcache_miss_stub' );
441 $wasRedirected = $this->showRedirectedFromHeader();
442 $this->showNamespaceHeader();
444 # Iterate through the possible ways of constructing the output text.
445 # Keep going until $outputDone is set, or we run out of things to do.
448 $this->mParserOutput
= false;
450 while ( !$outputDone && ++
$pass ) {
453 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
456 # Try the parser cache
457 if ( $useParserCache ) {
458 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
460 if ( $this->mParserOutput
!== false ) {
461 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
462 $wgOut->addParserOutput( $this->mParserOutput
);
463 # Ensure that UI elements requiring revision ID have
464 # the correct version information.
465 $wgOut->setRevisionId( $this->mPage
->getLatest() );
467 # Preload timestamp to avoid a DB hit
468 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
469 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
475 $text = $this->getContent();
476 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
477 wfDebug( __METHOD__
. ": showing missing article\n" );
478 $this->showMissingArticle();
479 wfProfileOut( __METHOD__
);
483 # Another whitelist check in case oldid is altering the title
484 if ( !$this->getTitle()->userCanRead() ) {
485 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
486 $wgOut->loginToUse();
489 wfProfileOut( __METHOD__
);
493 # Are we looking at an old revision
494 if ( $oldid && !is_null( $this->mRevision
) ) {
495 $this->setOldSubtitle( $oldid );
497 if ( !$this->showDeletedRevisionHeader() ) {
498 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
499 wfProfileOut( __METHOD__
);
503 # If this "old" version is the current, then try the parser cache...
504 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
505 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
506 if ( $this->mParserOutput
) {
507 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
508 $wgOut->addParserOutput( $this->mParserOutput
);
509 $wgOut->setRevisionId( $this->mPage
->getLatest() );
516 # Ensure that UI elements requiring revision ID have
517 # the correct version information.
518 $wgOut->setRevisionId( $this->getRevIdFetched() );
520 # Pages containing custom CSS or JavaScript get special treatment
521 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
522 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
523 $this->showCssOrJsPage();
526 $rt = Title
::newFromRedirectArray( $text );
528 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
529 # Viewing a redirect page (e.g. with parameter redirect=no)
530 # Don't append the subtitle if this was an old revision
531 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
532 # Parse just to get categories, displaytitle, etc.
533 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
534 $wgOut->addParserOutputNoText( $this->mParserOutput
);
540 # Run the parse, protected by a pool counter
541 wfDebug( __METHOD__
. ": doing uncached parse\n" );
543 $key = $parserCache->getKey( $this, $parserOptions );
544 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
546 if ( !$poolArticleView->execute() ) {
547 # Connection or timeout error
548 wfProfileOut( __METHOD__
);
554 # Should be unreachable, but just in case...
560 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
561 if ( $this->mParserOutput
) {
562 $titleText = $this->mParserOutput
->getTitleText();
564 if ( strval( $titleText ) !== '' ) {
565 $wgOut->setPageTitle( $titleText );
569 # For the main page, overwrite the <title> element with the con-
570 # tents of 'pagetitle-view-mainpage' instead of the default (if
572 # This message always exists because it is in the i18n files
573 if ( $this->getTitle()->equals( Title
::newMainPage() ) ) {
574 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
575 if ( !$msg->isDisabled() ) {
576 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
580 # Now that we've filled $this->mParserOutput, we know whether
581 # there are any __NOINDEX__ tags on the page
582 $policy = $this->getRobotPolicy( 'view' );
583 $wgOut->setIndexPolicy( $policy['index'] );
584 $wgOut->setFollowPolicy( $policy['follow'] );
586 $this->showViewFooter();
587 $this->mPage
->viewUpdates();
588 wfProfileOut( __METHOD__
);
592 * Show a diff page according to current request variables. For use within
593 * Article::view() only, other callers should use the DifferenceEngine class.
595 public function showDiffPage() {
596 global $wgRequest, $wgUser;
598 $diff = $wgRequest->getVal( 'diff' );
599 $rcid = $wgRequest->getVal( 'rcid' );
600 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
601 $purge = $wgRequest->getVal( 'action' ) == 'purge';
602 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
603 $oldid = $this->getOldID();
605 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
606 // DifferenceEngine directly fetched the revision:
607 $this->mRevIdFetched
= $de->mNewid
;
608 $de->showDiffPage( $diffOnly );
610 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
611 # Run view updates for current revision only
612 $this->mPage
->viewUpdates();
617 * Show a page view for a page formatted as CSS or JavaScript. To be called by
618 * Article::view() only.
620 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
623 protected function showCssOrJsPage() {
626 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache'>\n$1\n</div>", 'clearyourcache' );
628 // Give hooks a chance to customise the output
629 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
630 // Wrap the whole lot in a <pre> and don't parse
632 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
633 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
634 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
635 $wgOut->addHTML( "\n</pre>\n" );
640 * Get the robot policy to be used for the current view
641 * @param $action String the action= GET parameter
642 * @return Array the policy that should be set
643 * TODO: actions other than 'view'
645 public function getRobotPolicy( $action ) {
646 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
647 global $wgDefaultRobotPolicy, $wgRequest;
649 $ns = $this->getTitle()->getNamespace();
651 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
652 # Don't index user and user talk pages for blocked users (bug 11443)
653 if ( !$this->getTitle()->isSubpage() ) {
654 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
656 'index' => 'noindex',
657 'follow' => 'nofollow'
663 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
664 # Non-articles (special pages etc), and old revisions
666 'index' => 'noindex',
667 'follow' => 'nofollow'
669 } elseif ( $wgOut->isPrintable() ) {
670 # Discourage indexing of printable versions, but encourage following
672 'index' => 'noindex',
675 } elseif ( $wgRequest->getInt( 'curid' ) ) {
676 # For ?curid=x urls, disallow indexing
678 'index' => 'noindex',
683 # Otherwise, construct the policy based on the various config variables.
684 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
686 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
687 # Honour customised robot policies for this namespace
688 $policy = array_merge(
690 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
693 if ( $this->getTitle()->canUseNoindex() && is_object( $this->mParserOutput
) && $this->mParserOutput
->getIndexPolicy() ) {
694 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
695 # a final sanity check that we have really got the parser output.
696 $policy = array_merge(
698 array( 'index' => $this->mParserOutput
->getIndexPolicy() )
702 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
703 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
704 $policy = array_merge(
706 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
714 * Converts a String robot policy into an associative array, to allow
715 * merging of several policies using array_merge().
716 * @param $policy Mixed, returns empty array on null/false/'', transparent
717 * to already-converted arrays, converts String.
718 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
720 public static function formatRobotPolicy( $policy ) {
721 if ( is_array( $policy ) ) {
723 } elseif ( !$policy ) {
727 $policy = explode( ',', $policy );
728 $policy = array_map( 'trim', $policy );
731 foreach ( $policy as $var ) {
732 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
733 $arr['index'] = $var;
734 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
735 $arr['follow'] = $var;
743 * If this request is a redirect view, send "redirected from" subtitle to
744 * $wgOut. Returns true if the header was needed, false if this is not a
745 * redirect view. Handles both local and remote redirects.
749 public function showRedirectedFromHeader() {
750 global $wgOut, $wgRequest, $wgRedirectSources;
752 $rdfrom = $wgRequest->getVal( 'rdfrom' );
754 if ( isset( $this->mRedirectedFrom
) ) {
755 // This is an internally redirected page view.
756 // We'll need a backlink to the source page for navigation.
757 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
758 $redir = Linker
::link(
759 $this->mRedirectedFrom
,
762 array( 'redirect' => 'no' ),
763 array( 'known', 'noclasses' )
766 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
767 $wgOut->setSubtitle( $s );
769 // Set the fragment if one was specified in the redirect
770 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
771 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
772 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
775 // Add a <link rel="canonical"> tag
776 $wgOut->addLink( array( 'rel' => 'canonical',
777 'href' => $this->getTitle()->getLocalURL() )
782 } elseif ( $rdfrom ) {
783 // This is an externally redirected view, from some other wiki.
784 // If it was reported from a trusted site, supply a backlink.
785 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
786 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
787 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
788 $wgOut->setSubtitle( $s );
798 * Show a header specific to the namespace currently being viewed, like
799 * [[MediaWiki:Talkpagetext]]. For Article::view().
801 public function showNamespaceHeader() {
804 if ( $this->getTitle()->isTalkPage() ) {
805 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
806 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
812 * Show the footer section of an ordinary page view
814 public function showViewFooter() {
815 global $wgOut, $wgUseTrackbacks;
817 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
818 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
819 $wgOut->addWikiMsg( 'anontalkpagetext' );
822 # If we have been passed an &rcid= parameter, we want to give the user a
823 # chance to mark this new article as patrolled.
824 $this->showPatrolFooter();
827 if ( $wgUseTrackbacks ) {
828 $this->addTrackbacks();
831 wfRunHooks( 'ArticleViewFooter', array( $this ) );
836 * If patrol is possible, output a patrol UI box. This is called from the
837 * footer section of ordinary page views. If patrol is not possible or not
838 * desired, does nothing.
840 public function showPatrolFooter() {
841 global $wgOut, $wgRequest, $wgUser;
843 $rcid = $wgRequest->getVal( 'rcid' );
845 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
849 $token = $wgUser->editToken( $rcid );
850 $wgOut->preventClickjacking();
853 "<div class='patrollink'>" .
855 'markaspatrolledlink',
858 wfMsgHtml( 'markaspatrolledtext' ),
861 'action' => 'markpatrolled',
865 array( 'known', 'noclasses' )
873 * Show the error text for a missing article. For articles in the MediaWiki
874 * namespace, show the default message text. To be called from Article::view().
876 public function showMissingArticle() {
877 global $wgOut, $wgRequest, $wgUser;
879 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
880 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
881 $parts = explode( '/', $this->getTitle()->getText() );
882 $rootPart = $parts[0];
883 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
884 $ip = User
::isIP( $rootPart );
886 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
887 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
888 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
889 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
890 LogEventsList
::showLogExtract(
893 $user->getUserPage()->getPrefixedText(),
897 'showIfEmpty' => false,
899 'blocked-notice-logextract',
900 $user->getName() # Support GENDER in notice
907 wfRunHooks( 'ShowMissingArticle', array( $this ) );
909 # Show delete and move logs
910 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
912 'conds' => array( "log_action != 'revision'" ),
913 'showIfEmpty' => false,
914 'msgKey' => array( 'moveddeleted-notice' ) )
918 $oldid = $this->getOldID();
920 $text = wfMsgNoTrans( 'missing-article',
921 $this->getTitle()->getPrefixedText(),
922 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
923 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
924 // Use the default message text
925 $text = $this->getTitle()->getDefaultMessageText();
927 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
928 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
929 $errors = array_merge( $createErrors, $editErrors );
931 if ( !count( $errors ) ) {
932 $text = wfMsgNoTrans( 'noarticletext' );
934 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
937 $text = "<div class='noarticletext'>\n$text\n</div>";
939 if ( !$this->mPage
->hasViewableContent() ) {
940 // If there's no backing content, send a 404 Not Found
941 // for better machine handling of broken links.
942 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
945 $wgOut->addWikiText( $text );
949 * If the revision requested for view is deleted, check permissions.
950 * Send either an error message or a warning header to $wgOut.
952 * @return boolean true if the view is allowed, false if not.
954 public function showDeletedRevisionHeader() {
955 global $wgOut, $wgRequest;
957 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
962 // If the user is not allowed to see it...
963 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
964 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
965 'rev-deleted-text-permission' );
968 // If the user needs to confirm that they want to see it...
969 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
970 # Give explanation and add a link to view the revision...
971 $oldid = intval( $this->getOldID() );
972 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
973 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
974 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
975 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
976 array( $msg, $link ) );
979 // We are allowed to see...
981 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
982 'rev-suppressed-text-view' : 'rev-deleted-text-view';
983 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
990 * Execute the uncached parse for action=view
992 public function doViewParse() {
995 $oldid = $this->getOldID();
996 $parserOptions = $this->mPage
->getParserOptions();
998 # Render printable version, use printable version cache
999 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1001 # Don't show section-edit links on old revisions... this way lies madness.
1002 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1003 $parserOptions->setEditSection( false );
1006 $useParserCache = $this->useParserCache( $oldid );
1007 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1013 * Try to fetch an expired entry from the parser cache. If it is present,
1014 * output it and return true. If it is not present, output nothing and
1015 * return false. This is used as a callback function for
1016 * PoolCounter::executeProtected().
1020 public function tryDirtyCache() {
1022 $parserCache = ParserCache
::singleton();
1023 $options = $this->mPage
->getParserOptions();
1025 if ( $wgOut->isPrintable() ) {
1026 $options->setIsPrintable( true );
1027 $options->setEditSection( false );
1030 $output = $parserCache->getDirty( $this, $options );
1033 wfDebug( __METHOD__
. ": sending dirty output\n" );
1034 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1035 $wgOut->setSquidMaxage( 0 );
1036 $this->mParserOutput
= $output;
1037 $wgOut->addParserOutput( $output );
1038 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1042 wfDebugLog( 'dirty', "dirty missing\n" );
1043 wfDebug( __METHOD__
. ": no dirty cache\n" );
1052 * @param $target Title|Array of destination(s) to redirect
1053 * @param $appendSubtitle Boolean [optional]
1054 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1055 * @return string containing HMTL with redirect link
1057 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1058 global $wgOut, $wgStylePath;
1060 if ( !is_array( $target ) ) {
1061 $target = array( $target );
1064 $imageDir = wfUILang()->getDir();
1066 if ( $appendSubtitle ) {
1067 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1070 // the loop prepends the arrow image before the link, so the first case needs to be outside
1071 $title = array_shift( $target );
1073 if ( $forceKnown ) {
1074 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1076 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1079 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1080 $alt = wfUILang()->isRTL() ?
'←' : '→';
1081 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1082 foreach ( $target as $rt ) {
1083 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1084 if ( $forceKnown ) {
1085 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1087 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1091 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1092 return '<div class="redirectMsg">' .
1093 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1094 '<span class="redirectText">' . $link . '</span></div>';
1098 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1100 public function addTrackbacks() {
1103 $dbr = wfGetDB( DB_SLAVE
);
1104 $tbs = $dbr->select( 'trackbacks',
1105 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1106 array( 'tb_page' => $this->mPage
->getID() )
1109 if ( !$dbr->numRows( $tbs ) ) {
1113 $wgOut->preventClickjacking();
1116 foreach ( $tbs as $o ) {
1119 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1120 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1121 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1122 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1126 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1134 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1138 * Removes trackback record for current article from trackbacks table
1139 * @deprecated since 1.19
1141 public function deletetrackback() {
1142 return Action
::factory( 'deletetrackback', $this )->show();
1146 * Handle action=render
1149 public function render() {
1152 $wgOut->setArticleBodyOnly( true );
1157 * Handle action=purge
1159 public function purge() {
1160 return Action
::factory( 'purge', $this )->show();
1164 * Mark this particular edit/page as patrolled
1165 * @deprecated since 1.19
1167 public function markpatrolled() {
1168 Action
::factory( 'markpatrolled', $this )->show();
1172 * User-interface handler for the "watch" action.
1173 * Requires Request to pass a token as of 1.19.
1174 * @deprecated since 1.18
1176 public function watch() {
1177 Action
::factory( 'watch', $this )->show();
1181 * Add this page to $wgUser's watchlist
1183 * This is safe to be called multiple times
1185 * @return bool true on successful watch operation
1186 * @deprecated since 1.18
1188 public function doWatch() {
1190 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1194 * User interface handler for the "unwatch" action.
1195 * Requires Request to pass a token as of 1.19.
1196 * @deprecated since 1.18
1198 public function unwatch() {
1199 Action
::factory( 'unwatch', $this )->show();
1203 * Stop watching a page
1204 * @return bool true on successful unwatch
1205 * @deprecated since 1.18
1207 public function doUnwatch() {
1209 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1213 * action=protect handler
1215 public function protect() {
1216 $form = new ProtectionForm( $this );
1221 * action=unprotect handler (alias)
1223 public function unprotect() {
1228 * Info about this page
1229 * Called for ?action=info when $wgAllowPageInfo is on.
1231 public function info() {
1232 Action
::factory( 'info', $this )->show();
1236 * Output a redirect back to the article.
1237 * This is typically used after an edit.
1239 * @deprecated in 1.19; call $wgOut->redirect() directly
1240 * @param $noRedir Boolean: add redirect=no
1241 * @param $sectionAnchor String: section to redirect to, including "#"
1242 * @param $extraQuery String: extra query params
1244 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1245 wfDeprecated( __METHOD__
);
1249 $query = 'redirect=no';
1251 $query .= "&$extraQuery";
1253 $query = $extraQuery;
1256 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1260 * Auto-generates a deletion reason
1262 * @param &$hasHistory Boolean: whether the page has a history
1263 * @return mixed String containing deletion reason or empty string, or boolean false
1264 * if no revision occurred
1266 public function generateReason( &$hasHistory ) {
1269 $dbw = wfGetDB( DB_MASTER
);
1270 // Get the last revision
1271 $rev = Revision
::newFromTitle( $this->getTitle() );
1273 if ( is_null( $rev ) ) {
1277 // Get the article's contents
1278 $contents = $rev->getText();
1281 // If the page is blank, use the text from the previous revision,
1282 // which can only be blank if there's a move/import/protect dummy revision involved
1283 if ( $contents == '' ) {
1284 $prev = $rev->getPrevious();
1287 $contents = $prev->getText();
1292 // Find out if there was only one contributor
1293 // Only scan the last 20 revisions
1294 $res = $dbw->select( 'revision', 'rev_user_text',
1295 array( 'rev_page' => $this->mPage
->getID(), $dbw->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0' ),
1297 array( 'LIMIT' => 20 )
1300 if ( $res === false ) {
1301 // This page has no revisions, which is very weird
1305 $hasHistory = ( $res->numRows() > 1 );
1306 $row = $dbw->fetchObject( $res );
1308 if ( $row ) { // $row is false if the only contributor is hidden
1309 $onlyAuthor = $row->rev_user_text
;
1310 // Try to find a second contributor
1311 foreach ( $res as $row ) {
1312 if ( $row->rev_user_text
!= $onlyAuthor ) { // Bug 22999
1313 $onlyAuthor = false;
1318 $onlyAuthor = false;
1321 // Generate the summary with a '$1' placeholder
1323 // The current revision is blank and the one before is also
1324 // blank. It's just not our lucky day
1325 $reason = wfMsgForContent( 'exbeforeblank', '$1' );
1327 if ( $onlyAuthor ) {
1328 $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
1330 $reason = wfMsgForContent( 'excontent', '$1' );
1334 if ( $reason == '-' ) {
1335 // Allow these UI messages to be blanked out cleanly
1339 // Replace newlines with spaces to prevent uglyness
1340 $contents = preg_replace( "/[\n\r]/", ' ', $contents );
1341 // Calculate the maximum amount of chars to get
1342 // Max content length = max comment length - length of the comment (excl. $1)
1343 $maxLength = 255 - ( strlen( $reason ) - 2 );
1344 $contents = $wgContLang->truncate( $contents, $maxLength );
1345 // Remove possible unfinished links
1346 $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
1347 // Now replace the '$1' placeholder
1348 $reason = str_replace( '$1', $contents, $reason );
1355 * UI entry point for page deletion
1357 public function delete() {
1358 global $wgOut, $wgRequest;
1360 $confirm = $wgRequest->wasPosted() &&
1361 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1363 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1364 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1366 $reason = $this->DeleteReasonList
;
1368 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1369 // Entry from drop down menu + additional comment
1370 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1371 } elseif ( $reason == 'other' ) {
1372 $reason = $this->DeleteReason
;
1375 # Flag to hide all contents of the archived revisions
1376 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1378 # This code desperately needs to be totally rewritten
1380 # Read-only check...
1381 if ( wfReadOnly() ) {
1382 $wgOut->readOnlyPage();
1388 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1390 if ( count( $permission_errors ) > 0 ) {
1391 $wgOut->showPermissionsErrorPage( $permission_errors );
1396 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1398 # Better double-check that it hasn't been deleted yet!
1399 $dbw = wfGetDB( DB_MASTER
);
1400 $conds = $this->getTitle()->pageCond();
1401 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1402 if ( $latest === false ) {
1403 $wgOut->showFatalError(
1406 array( 'class' => 'error mw-error-cannotdelete' ),
1407 wfMsgExt( 'cannotdelete', array( 'parse' ),
1408 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1411 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1412 LogEventsList
::showLogExtract(
1415 $this->getTitle()->getPrefixedText()
1421 # Hack for big sites
1422 $bigHistory = $this->mPage
->isBigDeletion();
1423 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1424 global $wgLang, $wgDeleteRevisionsLimit;
1426 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1427 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1433 $this->doDelete( $reason, $suppress );
1435 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1437 } elseif ( $this->getTitle()->userIsWatching() ) {
1444 // Generate deletion reason
1445 $hasHistory = false;
1447 $reason = $this->generateReason( $hasHistory );
1450 // If the page has a history, insert a warning
1451 if ( $hasHistory && !$confirm ) {
1454 $revisions = $this->mPage
->estimateRevisionCount();
1455 // @todo FIXME: i18n issue/patchwork message
1456 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1457 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1458 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1459 wfMsgHtml( 'history' ),
1460 array( 'rel' => 'archives' ),
1461 array( 'action' => 'history' ) ) .
1465 if ( $bigHistory ) {
1466 global $wgDeleteRevisionsLimit;
1467 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1468 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1472 return $this->confirmDelete( $reason );
1476 * Output deletion confirmation dialog
1477 * @todo FIXME: Move to another file?
1478 * @param $reason String: prefilled reason
1480 public function confirmDelete( $reason ) {
1483 wfDebug( "Article::confirmDelete\n" );
1485 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1486 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1487 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1488 $wgOut->addWikiMsg( 'confirmdeletetext' );
1490 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1492 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1493 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1495 <td class='mw-input'><strong>" .
1496 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1497 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1503 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1505 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1506 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1507 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1508 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1509 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1510 "<tr id=\"wpDeleteReasonListRow\">
1511 <td class='mw-label'>" .
1512 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1514 <td class='mw-input'>" .
1515 Xml
::listDropDown( 'wpDeleteReasonList',
1516 wfMsgForContent( 'deletereason-dropdown' ),
1517 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1520 <tr id=\"wpDeleteReasonRow\">
1521 <td class='mw-label'>" .
1522 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1524 <td class='mw-input'>" .
1525 Html
::input( 'wpReason', $reason, 'text', array(
1527 'maxlength' => '255',
1535 # Disallow watching if user is not logged in
1536 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1540 <td class='mw-input'>" .
1541 Xml
::checkLabel( wfMsg( 'watchthis' ),
1542 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1551 <td class='mw-submit'>" .
1552 Xml
::submitButton( wfMsg( 'deletepage' ),
1553 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1556 Xml
::closeElement( 'table' ) .
1557 Xml
::closeElement( 'fieldset' ) .
1558 Html
::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1559 Xml
::closeElement( 'form' );
1561 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1562 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1563 $link = Linker
::link(
1565 wfMsgHtml( 'delete-edit-reasonlist' ),
1567 array( 'action' => 'edit' )
1569 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1572 $wgOut->addHTML( $form );
1573 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1574 LogEventsList
::showLogExtract( $wgOut, 'delete',
1575 $this->getTitle()->getPrefixedText()
1580 * Perform a deletion and output success or failure messages
1582 public function doDelete( $reason, $suppress = false ) {
1585 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1588 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1589 $deleted = $this->getTitle()->getPrefixedText();
1591 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1592 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1594 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1596 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1597 $wgOut->returnToMain( false );
1599 if ( $error == '' ) {
1600 $wgOut->showFatalError(
1603 array( 'class' => 'error mw-error-cannotdelete' ),
1604 wfMsgExt( 'cannotdelete', array( 'parse' ),
1605 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1609 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1611 LogEventsList
::showLogExtract(
1614 $this->getTitle()->getPrefixedText()
1617 $wgOut->showFatalError( $error );
1623 * User interface for rollback operations
1625 public function rollback() {
1626 global $wgUser, $wgOut, $wgRequest;
1630 $result = $this->mPage
->doRollback(
1631 $wgRequest->getVal( 'from' ),
1632 $wgRequest->getText( 'summary' ),
1633 $wgRequest->getVal( 'token' ),
1634 $wgRequest->getBool( 'bot' ),
1638 if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
1639 $wgOut->rateLimited();
1643 if ( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' ||
$result[0][0] == 'cantrollback' ) ) {
1644 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1645 $errArray = $result[0];
1646 $errMsg = array_shift( $errArray );
1647 $wgOut->addWikiMsgArray( $errMsg, $errArray );
1649 if ( isset( $details['current'] ) ) {
1650 $current = $details['current'];
1652 if ( $current->getComment() != '' ) {
1653 $wgOut->addWikiMsgArray( 'editcomment', array(
1654 Linker
::formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
1661 # Display permissions errors before read-only message -- there's no
1662 # point in misleading the user into thinking the inability to rollback
1663 # is only temporary.
1664 if ( !empty( $result ) && $result !== array( array( 'readonlytext' ) ) ) {
1665 # array_diff is completely broken for arrays of arrays, sigh.
1666 # Remove any 'readonlytext' error manually.
1668 foreach ( $result as $error ) {
1669 if ( $error != array( 'readonlytext' ) ) {
1673 $wgOut->showPermissionsErrorPage( $out );
1678 if ( $result == array( array( 'readonlytext' ) ) ) {
1679 $wgOut->readOnlyPage();
1684 $current = $details['current'];
1685 $target = $details['target'];
1686 $newId = $details['newid'];
1687 $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) );
1688 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1690 if ( $current->getUserText() === '' ) {
1691 $old = wfMsg( 'rev-deleted-user' );
1693 $old = Linker
::userLink( $current->getUser(), $current->getUserText() )
1694 . Linker
::userToolLinks( $current->getUser(), $current->getUserText() );
1697 $new = Linker
::userLink( $target->getUser(), $target->getUserText() )
1698 . Linker
::userToolLinks( $target->getUser(), $target->getUserText() );
1699 $wgOut->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
1700 $wgOut->returnToMain( false, $this->getTitle() );
1702 if ( !$wgRequest->getBool( 'hidediff', false ) && !$wgUser->getBoolOption( 'norollbackdiff', false ) ) {
1703 $de = new DifferenceEngine( $this->getTitle(), $current->getId(), $newId, false, true );
1704 $de->showDiff( '', '' );
1709 * Generate the navigation links when browsing through an article revisions
1710 * It shows the information as:
1711 * Revision as of \<date\>; view current revision
1712 * \<- Previous version | Next Version -\>
1714 * @param $oldid String: revision ID of this article revision
1716 public function setOldSubtitle( $oldid = 0 ) {
1717 global $wgLang, $wgOut, $wgUser, $wgRequest;
1719 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1723 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1725 # Cascade unhide param in links for easy deletion browsing
1726 $extraParams = array();
1727 if ( $wgRequest->getVal( 'unhide' ) ) {
1728 $extraParams['unhide'] = 1;
1731 $revision = Revision
::newFromId( $oldid );
1732 $timestamp = $revision->getTimestamp();
1734 $current = ( $oldid == $this->mPage
->getLatest() );
1735 $td = $wgLang->timeanddate( $timestamp, true );
1736 $tddate = $wgLang->date( $timestamp, true );
1737 $tdtime = $wgLang->time( $timestamp, true );
1740 ?
wfMsgHtml( 'currentrevisionlink' )
1743 wfMsgHtml( 'currentrevisionlink' ),
1746 array( 'known', 'noclasses' )
1749 ?
wfMsgHtml( 'diff' )
1752 wfMsgHtml( 'diff' ),
1758 array( 'known', 'noclasses' )
1760 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1764 wfMsgHtml( 'previousrevision' ),
1767 'direction' => 'prev',
1770 array( 'known', 'noclasses' )
1772 : wfMsgHtml( 'previousrevision' );
1776 wfMsgHtml( 'diff' ),
1782 array( 'known', 'noclasses' )
1784 : wfMsgHtml( 'diff' );
1785 $nextlink = $current
1786 ?
wfMsgHtml( 'nextrevision' )
1789 wfMsgHtml( 'nextrevision' ),
1792 'direction' => 'next',
1795 array( 'known', 'noclasses' )
1797 $nextdiff = $current
1798 ?
wfMsgHtml( 'diff' )
1801 wfMsgHtml( 'diff' ),
1807 array( 'known', 'noclasses' )
1812 // User can delete revisions or view deleted revisions...
1813 $canHide = $wgUser->isAllowed( 'deleterevision' );
1814 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1815 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1816 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1819 'type' => 'revision',
1820 'target' => $this->getTitle()->getPrefixedDbkey(),
1823 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1828 # Show user links if allowed to see them. If hidden, then show them only if requested...
1829 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1831 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1832 ?
'revision-info-current'
1835 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1838 array( 'parseinline', 'replaceafter' ),
1844 $revision->getUser()
1847 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1848 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1850 $wgOut->addHTML( $r );
1853 /* Caching functions */
1856 * checkLastModified returns true if it has taken care of all
1857 * output to the client that is necessary for this request.
1858 * (that is, it has sent a cached version of the page)
1860 * @return boolean true if cached version send, false otherwise
1862 protected function tryFileCache() {
1863 static $called = false;
1866 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1871 if ( $this->isFileCacheable() ) {
1872 $cache = new HTMLFileCache( $this->getTitle() );
1873 if ( $cache->isFileCacheGood( $this->mPage
->getTouched() ) ) {
1874 wfDebug( "Article::tryFileCache(): about to load file\n" );
1875 $cache->loadFromFileCache();
1878 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1879 ob_start( array( &$cache, 'saveToFileCache' ) );
1882 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1889 * Check if the page can be cached
1892 public function isFileCacheable() {
1895 if ( HTMLFileCache
::useFileCache() ) {
1896 $cacheable = $this->mPage
->getID() && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1897 // Extension may have reason to disable file caching on some pages.
1899 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1909 * Overriden by ImagePage class, only present here to avoid a fatal error
1910 * Called for ?action=revert
1912 public function revert() {
1914 $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
1918 * Add the primary page-view wikitext to the output buffer
1919 * Saves the text into the parser cache if possible.
1920 * Updates templatelinks if it is out of date.
1922 * @param $text String
1923 * @param $cache Boolean
1924 * @param $parserOptions mixed ParserOptions object, or boolean false
1926 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1929 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1931 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1933 $wgOut->addParserOutput( $this->mParserOutput
);
1937 * Lightweight method to get the parser output for a page, checking the parser cache
1938 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1939 * consider, so it's not appropriate to use there.
1941 * @since 1.16 (r52326) for LiquidThreads
1943 * @param $oldid mixed integer Revision ID or null
1944 * @param $user User The relevant user
1945 * @return ParserOutput or false if the given revsion ID is not found
1947 public function getParserOutput( $oldid = null, User
$user = null ) {
1948 global $wgEnableParserCache, $wgUser;
1949 $user = is_null( $user ) ?
$wgUser : $user;
1951 // Should the parser cache be used?
1952 $useParserCache = $wgEnableParserCache &&
1953 $user->getStubThreshold() == 0 &&
1954 $this->mPage
->exists() &&
1957 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1959 if ( $user->getStubThreshold() ) {
1960 wfIncrStats( 'pcache_miss_stub' );
1963 if ( $useParserCache ) {
1964 $parserOutput = ParserCache
::singleton()->get( $this, $this->mPage
->getParserOptions() );
1965 if ( $parserOutput !== false ) {
1966 return $parserOutput;
1970 // Cache miss; parse and output it.
1971 if ( $oldid === null ) {
1972 $text = $this->mPage
->getRawText();
1974 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1975 if ( $rev === null ) {
1978 $text = $rev->getText();
1981 return $this->getOutputFromWikitext( $text, $useParserCache );
1985 * This does all the heavy lifting for outputWikitext, except it returns the parser
1986 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1987 * say, embedding thread pages within a discussion system (LiquidThreads)
1989 * @param $text string
1990 * @param $cache boolean
1991 * @param $parserOptions parsing options, defaults to false
1992 * @return string containing parsed output
1994 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1995 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1997 if ( !$parserOptions ) {
1998 $parserOptions = $this->mPage
->getParserOptions();
2002 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
2003 $parserOptions, true, true, $this->getRevIdFetched() );
2008 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
2009 $this->getTitle()->getPrefixedDBkey() ) );
2012 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
2013 $parserCache = ParserCache
::singleton();
2014 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
2017 // Make sure file cache is not used on uncacheable content.
2018 // Output that has magic words in it can still use the parser cache
2019 // (if enabled), though it will generally expire sooner.
2020 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
2021 $wgUseFileCache = false;
2024 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
2026 return $this->mParserOutput
;
2030 * Updates cascading protections
2032 * @param $parserOutput ParserOutput object, or boolean false
2034 protected function doCascadeProtectionUpdates( $parserOutput ) {
2035 if ( !$this->isCurrent() ||
wfReadOnly() ||
!$this->getTitle()->areRestrictionsCascading() ) {
2039 // templatelinks table may have become out of sync,
2040 // especially if using variable-based transclusions.
2041 // For paranoia, check if things have changed and if
2042 // so apply updates to the database. This will ensure
2043 // that cascaded protections apply as soon as the changes
2046 # Get templates from templatelinks
2047 $id = $this->getTitle()->getArticleID();
2049 $tlTemplates = array();
2051 $dbr = wfGetDB( DB_SLAVE
);
2052 $res = $dbr->select( array( 'templatelinks' ),
2053 array( 'tl_namespace', 'tl_title' ),
2054 array( 'tl_from' => $id ),
2058 foreach ( $res as $row ) {
2059 $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
2062 # Get templates from parser output.
2063 $poTemplates = array();
2064 foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
2065 foreach ( $templates as $dbk => $id ) {
2066 $poTemplates["$ns:$dbk"] = true;
2071 $templates_diff = array_diff_key( $poTemplates, $tlTemplates );
2073 if ( count( $templates_diff ) > 0 ) {
2074 # Whee, link updates time.
2075 $u = new LinksUpdate( $this->getTitle(), $parserOutput, false );
2081 * Sets the context this Article is executed in
2083 * @param $context RequestContext
2086 public function setContext( $context ) {
2087 $this->mContext
= $context;
2091 * Gets the context this Article is executed in
2093 * @return RequestContext
2096 public function getContext() {
2097 if ( $this->mContext
instanceof RequestContext
) {
2098 return $this->mContext
;
2100 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
2101 return RequestContext
::getMain();
2106 * Use PHP's magic __get handler to handle accessing of
2107 * raw WikiPage fields for backwards compatibility.
2109 * @param $fname String Field name
2111 public function __get( $fname ) {
2112 if ( property_exists( $this->mPage
, $fname ) ) {
2113 #wfWarn( "Access to raw $fname field " . __CLASS__ );
2114 return $this->mPage
->$fname;
2116 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2120 * Use PHP's magic __set handler to handle setting of
2121 * raw WikiPage fields for backwards compatibility.
2123 * @param $fname String Field name
2124 * @param $fvalue mixed New value
2125 * @param $args Array Arguments to the method
2127 public function __set( $fname, $fvalue ) {
2128 if ( property_exists( $this->mPage
, $fname ) ) {
2129 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
2130 $this->mPage
->$fname = $fvalue;
2131 // Note: extensions may want to toss on new fields
2132 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
2133 $this->mPage
->$fname = $fvalue;
2135 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2140 * Use PHP's magic __call handler to transform instance calls to
2141 * WikiPage functions for backwards compatibility.
2143 * @param $fname String Name of called method
2144 * @param $args Array Arguments to the method
2146 public function __call( $fname, $args ) {
2147 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2148 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2149 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2151 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2154 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2155 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
2156 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
2159 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
2160 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2163 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) {
2164 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails );
2167 public function commitRollback( $fromP, $summary, $bot, &$resultDetails ) {
2168 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails );
2171 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2172 public static function selectFields() {
2173 return WikiPage
::selectFields();
2176 public static function onArticleCreate( $title ) {
2177 return WikiPage
::onArticleCreate( $title );
2180 public static function onArticleDelete( $title ) {
2181 return WikiPage
::onArticleDelete( $title );
2184 public static function onArticleEdit( $title ) {
2185 return WikiPage
::onArticleEdit( $title );
2188 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2189 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2194 class PoolWorkArticleView
extends PoolCounterWork
{
2201 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2202 parent
::__construct( 'ArticleView', $key );
2203 $this->mArticle
= $article;
2204 $this->cacheable
= $useParserCache;
2205 $this->parserOptions
= $parserOptions;
2209 return $this->mArticle
->doViewParse();
2212 function getCachedWork() {
2215 $parserCache = ParserCache
::singleton();
2216 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2218 if ( $this->mArticle
->mParserOutput
!== false ) {
2219 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2220 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2221 # Ensure that UI elements requiring revision ID have
2222 # the correct version information.
2223 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2229 function fallback() {
2230 return $this->mArticle
->tryDirtyCache();
2234 * @param $status Status
2236 function error( $status ) {
2239 $wgOut->clearHTML(); // for release() errors
2240 $wgOut->enableClientCache( false );
2241 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2243 $errortext = $status->getWikiText( false, 'view-pool-error' );
2244 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );