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" );
288 if ( $this->mPage
->getID() != $revision->getPage() ) {
289 $data = $this->mPage
->pageDataFromId( wfGetDB( DB_SLAVE
), $revision->getPage() );
292 wfDebug( __METHOD__
. " failed to get page data linked to revision id $oldid\n" );
296 $title = Title
::makeTitle( $data->page_namespace
, $data->page_title
);
297 $this->mPage
= new WikiPage( $title );
298 $this->mPage
->loadPageData( $data );
301 if ( $this->mPage
->getLatest() === false ) {
302 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
306 $revision = $this->mPage
->getRevision();
307 if ( $revision === null ) {
308 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
313 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
314 // We should instead work with the Revision object when we need it...
315 $this->mContent
= $revision->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
317 $this->mRevIdFetched
= $revision->getId();
318 $this->mContentLoaded
= true;
319 $this->mRevision
=& $revision;
321 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
323 return $this->mContent
;
328 * @deprecated since 1.18
330 public function forUpdate() {
331 wfDeprecated( __METHOD__
);
335 * Returns true if the currently-referenced revision is the current edit
336 * to this page (and it exists).
339 public function isCurrent() {
340 # If no oldid, this is the current version.
341 if ( $this->getOldID() == 0 ) {
345 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
349 * Use this to fetch the rev ID used on page views
351 * @return int revision ID of last article revision
353 public function getRevIdFetched() {
354 if ( $this->mRevIdFetched
) {
355 return $this->mRevIdFetched
;
357 return $this->mPage
->getLatest();
362 * This is the default action of the index.php entry point: just view the
363 * page of the given title.
365 public function view() {
366 global $wgUser, $wgOut, $wgRequest, $wgParser;
367 global $wgUseFileCache, $wgUseETag;
369 wfProfileIn( __METHOD__
);
371 # Get variables from query string
372 $oldid = $this->getOldID();
374 # getOldID may want us to redirect somewhere else
375 if ( $this->mRedirectUrl
) {
376 $wgOut->redirect( $this->mRedirectUrl
);
377 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
378 wfProfileOut( __METHOD__
);
383 $wgOut->setArticleFlag( true );
384 # Set page title (may be overridden by DISPLAYTITLE)
385 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
387 # If we got diff in the query, we want to see a diff page instead of the article.
388 if ( $wgRequest->getCheck( 'diff' ) ) {
389 wfDebug( __METHOD__
. ": showing diff page\n" );
390 $this->showDiffPage();
391 wfProfileOut( __METHOD__
);
396 # Allow frames by default
397 $wgOut->allowClickjacking();
399 $parserCache = ParserCache
::singleton();
401 $parserOptions = $this->mPage
->getParserOptions();
402 # Render printable version, use printable version cache
403 if ( $wgOut->isPrintable() ) {
404 $parserOptions->setIsPrintable( true );
405 $parserOptions->setEditSection( false );
406 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
407 $parserOptions->setEditSection( false );
410 # Try client and file cache
411 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
413 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
416 # Is it client cached?
417 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
418 wfDebug( __METHOD__
. ": done 304\n" );
419 wfProfileOut( __METHOD__
);
423 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
424 wfDebug( __METHOD__
. ": done file cache\n" );
425 # tell wgOut that output is taken care of
427 $this->mPage
->viewUpdates();
428 wfProfileOut( __METHOD__
);
434 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
435 $parserOptions->setEditSection( false );
438 # Should the parser cache be used?
439 $useParserCache = $this->useParserCache( $oldid );
440 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
441 if ( $wgUser->getStubThreshold() ) {
442 wfIncrStats( 'pcache_miss_stub' );
445 $wasRedirected = $this->showRedirectedFromHeader();
446 $this->showNamespaceHeader();
448 # Iterate through the possible ways of constructing the output text.
449 # Keep going until $outputDone is set, or we run out of things to do.
452 $this->mParserOutput
= false;
454 while ( !$outputDone && ++
$pass ) {
457 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
460 # Try the parser cache
461 if ( $useParserCache ) {
462 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
464 if ( $this->mParserOutput
!== false ) {
465 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
466 $wgOut->addParserOutput( $this->mParserOutput
);
467 # Ensure that UI elements requiring revision ID have
468 # the correct version information.
469 $wgOut->setRevisionId( $this->mPage
->getLatest() );
471 # Preload timestamp to avoid a DB hit
472 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
473 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
479 $text = $this->getContent();
480 if ( $text === false ||
$this->mPage
->getID() == 0 ) {
481 wfDebug( __METHOD__
. ": showing missing article\n" );
482 $this->showMissingArticle();
483 wfProfileOut( __METHOD__
);
487 # Another whitelist check in case oldid is altering the title
488 if ( !$this->getTitle()->userCanRead() ) {
489 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
490 $wgOut->loginToUse();
493 wfProfileOut( __METHOD__
);
497 # Are we looking at an old revision
498 if ( $oldid && !is_null( $this->mRevision
) ) {
499 $this->setOldSubtitle( $oldid );
501 if ( !$this->showDeletedRevisionHeader() ) {
502 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
503 wfProfileOut( __METHOD__
);
507 # If this "old" version is the current, then try the parser cache...
508 if ( $oldid === $this->mPage
->getLatest() && $this->useParserCache( false ) ) {
509 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
510 if ( $this->mParserOutput
) {
511 wfDebug( __METHOD__
. ": showing parser cache for current rev permalink\n" );
512 $wgOut->addParserOutput( $this->mParserOutput
);
513 $wgOut->setRevisionId( $this->mPage
->getLatest() );
520 # Ensure that UI elements requiring revision ID have
521 # the correct version information.
522 $wgOut->setRevisionId( $this->getRevIdFetched() );
524 # Pages containing custom CSS or JavaScript get special treatment
525 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
526 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
527 $this->showCssOrJsPage();
530 $rt = Title
::newFromRedirectArray( $text );
532 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
533 # Viewing a redirect page (e.g. with parameter redirect=no)
534 # Don't append the subtitle if this was an old revision
535 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
536 # Parse just to get categories, displaytitle, etc.
537 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
538 $wgOut->addParserOutputNoText( $this->mParserOutput
);
544 # Run the parse, protected by a pool counter
545 wfDebug( __METHOD__
. ": doing uncached parse\n" );
547 $key = $parserCache->getKey( $this, $parserOptions );
548 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
550 if ( !$poolArticleView->execute() ) {
551 # Connection or timeout error
552 wfProfileOut( __METHOD__
);
558 # Should be unreachable, but just in case...
564 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
565 if ( $this->mParserOutput
) {
566 $titleText = $this->mParserOutput
->getTitleText();
568 if ( strval( $titleText ) !== '' ) {
569 $wgOut->setPageTitle( $titleText );
573 # For the main page, overwrite the <title> element with the con-
574 # tents of 'pagetitle-view-mainpage' instead of the default (if
576 # This message always exists because it is in the i18n files
577 if ( $this->getTitle()->equals( Title
::newMainPage() ) ) {
578 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
579 if ( !$msg->isDisabled() ) {
580 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
584 # Now that we've filled $this->mParserOutput, we know whether
585 # there are any __NOINDEX__ tags on the page
586 $policy = $this->getRobotPolicy( 'view' );
587 $wgOut->setIndexPolicy( $policy['index'] );
588 $wgOut->setFollowPolicy( $policy['follow'] );
590 $this->showViewFooter();
591 $this->mPage
->viewUpdates();
592 wfProfileOut( __METHOD__
);
596 * Show a diff page according to current request variables. For use within
597 * Article::view() only, other callers should use the DifferenceEngine class.
599 public function showDiffPage() {
600 global $wgRequest, $wgUser;
602 $diff = $wgRequest->getVal( 'diff' );
603 $rcid = $wgRequest->getVal( 'rcid' );
604 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
605 $purge = $wgRequest->getVal( 'action' ) == 'purge';
606 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
607 $oldid = $this->getOldID();
609 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
610 // DifferenceEngine directly fetched the revision:
611 $this->mRevIdFetched
= $de->mNewid
;
612 $de->showDiffPage( $diffOnly );
614 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
615 # Run view updates for current revision only
616 $this->mPage
->viewUpdates();
621 * Show a page view for a page formatted as CSS or JavaScript. To be called by
622 * Article::view() only.
624 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
627 protected function showCssOrJsPage() {
630 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache'>\n$1\n</div>", 'clearyourcache' );
632 // Give hooks a chance to customise the output
633 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
634 // Wrap the whole lot in a <pre> and don't parse
636 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
637 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
638 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
639 $wgOut->addHTML( "\n</pre>\n" );
644 * Get the robot policy to be used for the current view
645 * @param $action String the action= GET parameter
646 * @return Array the policy that should be set
647 * TODO: actions other than 'view'
649 public function getRobotPolicy( $action ) {
650 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
651 global $wgDefaultRobotPolicy, $wgRequest;
653 $ns = $this->getTitle()->getNamespace();
655 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
656 # Don't index user and user talk pages for blocked users (bug 11443)
657 if ( !$this->getTitle()->isSubpage() ) {
658 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
660 'index' => 'noindex',
661 'follow' => 'nofollow'
667 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
668 # Non-articles (special pages etc), and old revisions
670 'index' => 'noindex',
671 'follow' => 'nofollow'
673 } elseif ( $wgOut->isPrintable() ) {
674 # Discourage indexing of printable versions, but encourage following
676 'index' => 'noindex',
679 } elseif ( $wgRequest->getInt( 'curid' ) ) {
680 # For ?curid=x urls, disallow indexing
682 'index' => 'noindex',
687 # Otherwise, construct the policy based on the various config variables.
688 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
690 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
691 # Honour customised robot policies for this namespace
692 $policy = array_merge(
694 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
697 if ( $this->getTitle()->canUseNoindex() && is_object( $this->mParserOutput
) && $this->mParserOutput
->getIndexPolicy() ) {
698 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
699 # a final sanity check that we have really got the parser output.
700 $policy = array_merge(
702 array( 'index' => $this->mParserOutput
->getIndexPolicy() )
706 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
707 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
708 $policy = array_merge(
710 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
718 * Converts a String robot policy into an associative array, to allow
719 * merging of several policies using array_merge().
720 * @param $policy Mixed, returns empty array on null/false/'', transparent
721 * to already-converted arrays, converts String.
722 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
724 public static function formatRobotPolicy( $policy ) {
725 if ( is_array( $policy ) ) {
727 } elseif ( !$policy ) {
731 $policy = explode( ',', $policy );
732 $policy = array_map( 'trim', $policy );
735 foreach ( $policy as $var ) {
736 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
737 $arr['index'] = $var;
738 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
739 $arr['follow'] = $var;
747 * If this request is a redirect view, send "redirected from" subtitle to
748 * $wgOut. Returns true if the header was needed, false if this is not a
749 * redirect view. Handles both local and remote redirects.
753 public function showRedirectedFromHeader() {
754 global $wgOut, $wgRequest, $wgRedirectSources;
756 $rdfrom = $wgRequest->getVal( 'rdfrom' );
758 if ( isset( $this->mRedirectedFrom
) ) {
759 // This is an internally redirected page view.
760 // We'll need a backlink to the source page for navigation.
761 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
762 $redir = Linker
::link(
763 $this->mRedirectedFrom
,
766 array( 'redirect' => 'no' ),
767 array( 'known', 'noclasses' )
770 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
771 $wgOut->setSubtitle( $s );
773 // Set the fragment if one was specified in the redirect
774 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
775 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
776 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
779 // Add a <link rel="canonical"> tag
780 $wgOut->addLink( array( 'rel' => 'canonical',
781 'href' => $this->getTitle()->getLocalURL() )
786 } elseif ( $rdfrom ) {
787 // This is an externally redirected view, from some other wiki.
788 // If it was reported from a trusted site, supply a backlink.
789 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
790 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
791 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
792 $wgOut->setSubtitle( $s );
802 * Show a header specific to the namespace currently being viewed, like
803 * [[MediaWiki:Talkpagetext]]. For Article::view().
805 public function showNamespaceHeader() {
808 if ( $this->getTitle()->isTalkPage() ) {
809 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
810 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
816 * Show the footer section of an ordinary page view
818 public function showViewFooter() {
819 global $wgOut, $wgUseTrackbacks;
821 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
822 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
823 $wgOut->addWikiMsg( 'anontalkpagetext' );
826 # If we have been passed an &rcid= parameter, we want to give the user a
827 # chance to mark this new article as patrolled.
828 $this->showPatrolFooter();
831 if ( $wgUseTrackbacks ) {
832 $this->addTrackbacks();
835 wfRunHooks( 'ArticleViewFooter', array( $this ) );
840 * If patrol is possible, output a patrol UI box. This is called from the
841 * footer section of ordinary page views. If patrol is not possible or not
842 * desired, does nothing.
844 public function showPatrolFooter() {
845 global $wgOut, $wgRequest, $wgUser;
847 $rcid = $wgRequest->getVal( 'rcid' );
849 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
853 $token = $wgUser->editToken( $rcid );
854 $wgOut->preventClickjacking();
857 "<div class='patrollink'>" .
859 'markaspatrolledlink',
862 wfMsgHtml( 'markaspatrolledtext' ),
865 'action' => 'markpatrolled',
869 array( 'known', 'noclasses' )
877 * Show the error text for a missing article. For articles in the MediaWiki
878 * namespace, show the default message text. To be called from Article::view().
880 public function showMissingArticle() {
881 global $wgOut, $wgRequest, $wgUser;
883 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
884 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
885 $parts = explode( '/', $this->getTitle()->getText() );
886 $rootPart = $parts[0];
887 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
888 $ip = User
::isIP( $rootPart );
890 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
891 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
892 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
893 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
894 LogEventsList
::showLogExtract(
897 $user->getUserPage()->getPrefixedText(),
901 'showIfEmpty' => false,
903 'blocked-notice-logextract',
904 $user->getName() # Support GENDER in notice
911 wfRunHooks( 'ShowMissingArticle', array( $this ) );
913 # Show delete and move logs
914 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
916 'conds' => array( "log_action != 'revision'" ),
917 'showIfEmpty' => false,
918 'msgKey' => array( 'moveddeleted-notice' ) )
922 $oldid = $this->getOldID();
924 $text = wfMsgNoTrans( 'missing-article',
925 $this->getTitle()->getPrefixedText(),
926 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
927 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
928 // Use the default message text
929 $text = $this->getTitle()->getDefaultMessageText();
931 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
932 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
933 $errors = array_merge( $createErrors, $editErrors );
935 if ( !count( $errors ) ) {
936 $text = wfMsgNoTrans( 'noarticletext' );
938 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
941 $text = "<div class='noarticletext'>\n$text\n</div>";
943 if ( !$this->mPage
->hasViewableContent() ) {
944 // If there's no backing content, send a 404 Not Found
945 // for better machine handling of broken links.
946 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
949 $wgOut->addWikiText( $text );
953 * If the revision requested for view is deleted, check permissions.
954 * Send either an error message or a warning header to $wgOut.
956 * @return boolean true if the view is allowed, false if not.
958 public function showDeletedRevisionHeader() {
959 global $wgOut, $wgRequest;
961 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
966 // If the user is not allowed to see it...
967 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
968 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
969 'rev-deleted-text-permission' );
972 // If the user needs to confirm that they want to see it...
973 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
974 # Give explanation and add a link to view the revision...
975 $oldid = intval( $this->getOldID() );
976 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
977 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
978 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
979 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
980 array( $msg, $link ) );
983 // We are allowed to see...
985 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
986 'rev-suppressed-text-view' : 'rev-deleted-text-view';
987 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
994 * Execute the uncached parse for action=view
996 public function doViewParse() {
999 $oldid = $this->getOldID();
1000 $parserOptions = $this->mPage
->getParserOptions();
1002 # Render printable version, use printable version cache
1003 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1005 # Don't show section-edit links on old revisions... this way lies madness.
1006 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1007 $parserOptions->setEditSection( false );
1010 $useParserCache = $this->useParserCache( $oldid );
1011 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1017 * Try to fetch an expired entry from the parser cache. If it is present,
1018 * output it and return true. If it is not present, output nothing and
1019 * return false. This is used as a callback function for
1020 * PoolCounter::executeProtected().
1024 public function tryDirtyCache() {
1026 $parserCache = ParserCache
::singleton();
1027 $options = $this->mPage
->getParserOptions();
1029 if ( $wgOut->isPrintable() ) {
1030 $options->setIsPrintable( true );
1031 $options->setEditSection( false );
1034 $output = $parserCache->getDirty( $this, $options );
1037 wfDebug( __METHOD__
. ": sending dirty output\n" );
1038 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1039 $wgOut->setSquidMaxage( 0 );
1040 $this->mParserOutput
= $output;
1041 $wgOut->addParserOutput( $output );
1042 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1046 wfDebugLog( 'dirty', "dirty missing\n" );
1047 wfDebug( __METHOD__
. ": no dirty cache\n" );
1056 * @param $target Title|Array of destination(s) to redirect
1057 * @param $appendSubtitle Boolean [optional]
1058 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1059 * @return string containing HMTL with redirect link
1061 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1062 global $wgOut, $wgStylePath;
1064 if ( !is_array( $target ) ) {
1065 $target = array( $target );
1068 $imageDir = wfUILang()->getDir();
1070 if ( $appendSubtitle ) {
1071 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1074 // the loop prepends the arrow image before the link, so the first case needs to be outside
1075 $title = array_shift( $target );
1077 if ( $forceKnown ) {
1078 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1080 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1083 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1084 $alt = wfUILang()->isRTL() ?
'←' : '→';
1085 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1086 foreach ( $target as $rt ) {
1087 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1088 if ( $forceKnown ) {
1089 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1091 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1095 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1096 return '<div class="redirectMsg">' .
1097 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1098 '<span class="redirectText">' . $link . '</span></div>';
1102 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1104 public function addTrackbacks() {
1107 $dbr = wfGetDB( DB_SLAVE
);
1108 $tbs = $dbr->select( 'trackbacks',
1109 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1110 array( 'tb_page' => $this->mPage
->getID() )
1113 if ( !$dbr->numRows( $tbs ) ) {
1117 $wgOut->preventClickjacking();
1120 foreach ( $tbs as $o ) {
1123 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1124 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1125 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1126 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1130 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1138 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1142 * Removes trackback record for current article from trackbacks table
1143 * @deprecated since 1.19
1145 public function deletetrackback() {
1146 return Action
::factory( 'deletetrackback', $this )->show();
1150 * Handle action=render
1153 public function render() {
1156 $wgOut->setArticleBodyOnly( true );
1161 * Handle action=purge
1163 public function purge() {
1164 return Action
::factory( 'purge', $this )->show();
1168 * Mark this particular edit/page as patrolled
1169 * @deprecated since 1.19
1171 public function markpatrolled() {
1172 Action
::factory( 'markpatrolled', $this )->show();
1176 * User-interface handler for the "watch" action.
1177 * Requires Request to pass a token as of 1.19.
1178 * @deprecated since 1.18
1180 public function watch() {
1181 Action
::factory( 'watch', $this )->show();
1185 * Add this page to $wgUser's watchlist
1187 * This is safe to be called multiple times
1189 * @return bool true on successful watch operation
1190 * @deprecated since 1.18
1192 public function doWatch() {
1194 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1198 * User interface handler for the "unwatch" action.
1199 * Requires Request to pass a token as of 1.19.
1200 * @deprecated since 1.18
1202 public function unwatch() {
1203 Action
::factory( 'unwatch', $this )->show();
1207 * Stop watching a page
1208 * @return bool true on successful unwatch
1209 * @deprecated since 1.18
1211 public function doUnwatch() {
1213 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1217 * action=protect handler
1219 public function protect() {
1220 $form = new ProtectionForm( $this );
1225 * action=unprotect handler (alias)
1227 public function unprotect() {
1232 * Info about this page
1233 * Called for ?action=info when $wgAllowPageInfo is on.
1235 public function info() {
1236 Action
::factory( 'info', $this )->show();
1240 * Output a redirect back to the article.
1241 * This is typically used after an edit.
1243 * @deprecated in 1.19; call $wgOut->redirect() directly
1244 * @param $noRedir Boolean: add redirect=no
1245 * @param $sectionAnchor String: section to redirect to, including "#"
1246 * @param $extraQuery String: extra query params
1248 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1249 wfDeprecated( __METHOD__
);
1253 $query = 'redirect=no';
1255 $query .= "&$extraQuery";
1257 $query = $extraQuery;
1260 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1264 * Auto-generates a deletion reason
1266 * @param &$hasHistory Boolean: whether the page has a history
1267 * @return mixed String containing deletion reason or empty string, or boolean false
1268 * if no revision occurred
1270 public function generateReason( &$hasHistory ) {
1273 $dbw = wfGetDB( DB_MASTER
);
1274 // Get the last revision
1275 $rev = Revision
::newFromTitle( $this->getTitle() );
1277 if ( is_null( $rev ) ) {
1281 // Get the article's contents
1282 $contents = $rev->getText();
1285 // If the page is blank, use the text from the previous revision,
1286 // which can only be blank if there's a move/import/protect dummy revision involved
1287 if ( $contents == '' ) {
1288 $prev = $rev->getPrevious();
1291 $contents = $prev->getText();
1296 // Find out if there was only one contributor
1297 // Only scan the last 20 revisions
1298 $res = $dbw->select( 'revision', 'rev_user_text',
1299 array( 'rev_page' => $this->mPage
->getID(), $dbw->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0' ),
1301 array( 'LIMIT' => 20 )
1304 if ( $res === false ) {
1305 // This page has no revisions, which is very weird
1309 $hasHistory = ( $res->numRows() > 1 );
1310 $row = $dbw->fetchObject( $res );
1312 if ( $row ) { // $row is false if the only contributor is hidden
1313 $onlyAuthor = $row->rev_user_text
;
1314 // Try to find a second contributor
1315 foreach ( $res as $row ) {
1316 if ( $row->rev_user_text
!= $onlyAuthor ) { // Bug 22999
1317 $onlyAuthor = false;
1322 $onlyAuthor = false;
1325 // Generate the summary with a '$1' placeholder
1327 // The current revision is blank and the one before is also
1328 // blank. It's just not our lucky day
1329 $reason = wfMsgForContent( 'exbeforeblank', '$1' );
1331 if ( $onlyAuthor ) {
1332 $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
1334 $reason = wfMsgForContent( 'excontent', '$1' );
1338 if ( $reason == '-' ) {
1339 // Allow these UI messages to be blanked out cleanly
1343 // Replace newlines with spaces to prevent uglyness
1344 $contents = preg_replace( "/[\n\r]/", ' ', $contents );
1345 // Calculate the maximum amount of chars to get
1346 // Max content length = max comment length - length of the comment (excl. $1)
1347 $maxLength = 255 - ( strlen( $reason ) - 2 );
1348 $contents = $wgContLang->truncate( $contents, $maxLength );
1349 // Remove possible unfinished links
1350 $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
1351 // Now replace the '$1' placeholder
1352 $reason = str_replace( '$1', $contents, $reason );
1359 * UI entry point for page deletion
1361 public function delete() {
1362 global $wgOut, $wgRequest;
1364 $confirm = $wgRequest->wasPosted() &&
1365 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1367 $this->DeleteReasonList
= $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1368 $this->DeleteReason
= $wgRequest->getText( 'wpReason' );
1370 $reason = $this->DeleteReasonList
;
1372 if ( $reason != 'other' && $this->DeleteReason
!= '' ) {
1373 // Entry from drop down menu + additional comment
1374 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason
;
1375 } elseif ( $reason == 'other' ) {
1376 $reason = $this->DeleteReason
;
1379 # Flag to hide all contents of the archived revisions
1380 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1382 # This code desperately needs to be totally rewritten
1384 # Read-only check...
1385 if ( wfReadOnly() ) {
1386 $wgOut->readOnlyPage();
1392 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1394 if ( count( $permission_errors ) > 0 ) {
1395 $wgOut->showPermissionsErrorPage( $permission_errors );
1400 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1402 # Better double-check that it hasn't been deleted yet!
1403 $dbw = wfGetDB( DB_MASTER
);
1404 $conds = $this->getTitle()->pageCond();
1405 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1406 if ( $latest === false ) {
1407 $wgOut->showFatalError(
1410 array( 'class' => 'error mw-error-cannotdelete' ),
1411 wfMsgExt( 'cannotdelete', array( 'parse' ),
1412 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1415 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1416 LogEventsList
::showLogExtract(
1419 $this->getTitle()->getPrefixedText()
1425 # Hack for big sites
1426 $bigHistory = $this->mPage
->isBigDeletion();
1427 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1428 global $wgLang, $wgDeleteRevisionsLimit;
1430 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1431 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1437 $this->doDelete( $reason, $suppress );
1439 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1441 } elseif ( $this->getTitle()->userIsWatching() ) {
1448 // Generate deletion reason
1449 $hasHistory = false;
1451 $reason = $this->generateReason( $hasHistory );
1454 // If the page has a history, insert a warning
1455 if ( $hasHistory && !$confirm ) {
1458 $revisions = $this->mPage
->estimateRevisionCount();
1459 // @todo FIXME: i18n issue/patchwork message
1460 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1461 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1462 wfMsgHtml( 'word-separator' ) . Linker
::link( $this->getTitle(),
1463 wfMsgHtml( 'history' ),
1464 array( 'rel' => 'archives' ),
1465 array( 'action' => 'history' ) ) .
1469 if ( $bigHistory ) {
1470 global $wgDeleteRevisionsLimit;
1471 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1472 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1476 return $this->confirmDelete( $reason );
1480 * Output deletion confirmation dialog
1481 * @todo FIXME: Move to another file?
1482 * @param $reason String: prefilled reason
1484 public function confirmDelete( $reason ) {
1487 wfDebug( "Article::confirmDelete\n" );
1489 $deleteBackLink = Linker
::linkKnown( $this->getTitle() );
1490 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1491 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1492 $wgOut->addWikiMsg( 'confirmdeletetext' );
1494 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1496 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1497 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1499 <td class='mw-input'><strong>" .
1500 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1501 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1507 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1509 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1510 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1511 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1512 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1513 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1514 "<tr id=\"wpDeleteReasonListRow\">
1515 <td class='mw-label'>" .
1516 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1518 <td class='mw-input'>" .
1519 Xml
::listDropDown( 'wpDeleteReasonList',
1520 wfMsgForContent( 'deletereason-dropdown' ),
1521 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1524 <tr id=\"wpDeleteReasonRow\">
1525 <td class='mw-label'>" .
1526 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1528 <td class='mw-input'>" .
1529 Html
::input( 'wpReason', $reason, 'text', array(
1531 'maxlength' => '255',
1539 # Disallow watching if user is not logged in
1540 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1544 <td class='mw-input'>" .
1545 Xml
::checkLabel( wfMsg( 'watchthis' ),
1546 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1555 <td class='mw-submit'>" .
1556 Xml
::submitButton( wfMsg( 'deletepage' ),
1557 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1560 Xml
::closeElement( 'table' ) .
1561 Xml
::closeElement( 'fieldset' ) .
1562 Html
::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1563 Xml
::closeElement( 'form' );
1565 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1566 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1567 $link = Linker
::link(
1569 wfMsgHtml( 'delete-edit-reasonlist' ),
1571 array( 'action' => 'edit' )
1573 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1576 $wgOut->addHTML( $form );
1577 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1578 LogEventsList
::showLogExtract( $wgOut, 'delete',
1579 $this->getTitle()->getPrefixedText()
1584 * Perform a deletion and output success or failure messages
1586 public function doDelete( $reason, $suppress = false ) {
1589 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1592 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1593 $deleted = $this->getTitle()->getPrefixedText();
1595 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1596 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1598 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1600 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1601 $wgOut->returnToMain( false );
1603 if ( $error == '' ) {
1604 $wgOut->showFatalError(
1607 array( 'class' => 'error mw-error-cannotdelete' ),
1608 wfMsgExt( 'cannotdelete', array( 'parse' ),
1609 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1613 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1615 LogEventsList
::showLogExtract(
1618 $this->getTitle()->getPrefixedText()
1621 $wgOut->showFatalError( $error );
1627 * User interface for rollback operations
1629 public function rollback() {
1630 global $wgUser, $wgOut, $wgRequest;
1634 $result = $this->mPage
->doRollback(
1635 $wgRequest->getVal( 'from' ),
1636 $wgRequest->getText( 'summary' ),
1637 $wgRequest->getVal( 'token' ),
1638 $wgRequest->getBool( 'bot' ),
1642 if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
1643 $wgOut->rateLimited();
1647 if ( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' ||
$result[0][0] == 'cantrollback' ) ) {
1648 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
1649 $errArray = $result[0];
1650 $errMsg = array_shift( $errArray );
1651 $wgOut->addWikiMsgArray( $errMsg, $errArray );
1653 if ( isset( $details['current'] ) ) {
1654 $current = $details['current'];
1656 if ( $current->getComment() != '' ) {
1657 $wgOut->addWikiMsgArray( 'editcomment', array(
1658 Linker
::formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
1665 # Display permissions errors before read-only message -- there's no
1666 # point in misleading the user into thinking the inability to rollback
1667 # is only temporary.
1668 if ( !empty( $result ) && $result !== array( array( 'readonlytext' ) ) ) {
1669 # array_diff is completely broken for arrays of arrays, sigh.
1670 # Remove any 'readonlytext' error manually.
1672 foreach ( $result as $error ) {
1673 if ( $error != array( 'readonlytext' ) ) {
1677 $wgOut->showPermissionsErrorPage( $out );
1682 if ( $result == array( array( 'readonlytext' ) ) ) {
1683 $wgOut->readOnlyPage();
1688 $current = $details['current'];
1689 $target = $details['target'];
1690 $newId = $details['newid'];
1691 $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) );
1692 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1694 if ( $current->getUserText() === '' ) {
1695 $old = wfMsg( 'rev-deleted-user' );
1697 $old = Linker
::userLink( $current->getUser(), $current->getUserText() )
1698 . Linker
::userToolLinks( $current->getUser(), $current->getUserText() );
1701 $new = Linker
::userLink( $target->getUser(), $target->getUserText() )
1702 . Linker
::userToolLinks( $target->getUser(), $target->getUserText() );
1703 $wgOut->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
1704 $wgOut->returnToMain( false, $this->getTitle() );
1706 if ( !$wgRequest->getBool( 'hidediff', false ) && !$wgUser->getBoolOption( 'norollbackdiff', false ) ) {
1707 $de = new DifferenceEngine( $this->getTitle(), $current->getId(), $newId, false, true );
1708 $de->showDiff( '', '' );
1713 * Generate the navigation links when browsing through an article revisions
1714 * It shows the information as:
1715 * Revision as of \<date\>; view current revision
1716 * \<- Previous version | Next Version -\>
1718 * @param $oldid String: revision ID of this article revision
1720 public function setOldSubtitle( $oldid = 0 ) {
1721 global $wgLang, $wgOut, $wgUser, $wgRequest;
1723 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1727 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1729 # Cascade unhide param in links for easy deletion browsing
1730 $extraParams = array();
1731 if ( $wgRequest->getVal( 'unhide' ) ) {
1732 $extraParams['unhide'] = 1;
1735 $revision = Revision
::newFromId( $oldid );
1736 $timestamp = $revision->getTimestamp();
1738 $current = ( $oldid == $this->mPage
->getLatest() );
1739 $td = $wgLang->timeanddate( $timestamp, true );
1740 $tddate = $wgLang->date( $timestamp, true );
1741 $tdtime = $wgLang->time( $timestamp, true );
1744 ?
wfMsgHtml( 'currentrevisionlink' )
1747 wfMsgHtml( 'currentrevisionlink' ),
1750 array( 'known', 'noclasses' )
1753 ?
wfMsgHtml( 'diff' )
1756 wfMsgHtml( 'diff' ),
1762 array( 'known', 'noclasses' )
1764 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1768 wfMsgHtml( 'previousrevision' ),
1771 'direction' => 'prev',
1774 array( 'known', 'noclasses' )
1776 : wfMsgHtml( 'previousrevision' );
1780 wfMsgHtml( 'diff' ),
1786 array( 'known', 'noclasses' )
1788 : wfMsgHtml( 'diff' );
1789 $nextlink = $current
1790 ?
wfMsgHtml( 'nextrevision' )
1793 wfMsgHtml( 'nextrevision' ),
1796 'direction' => 'next',
1799 array( 'known', 'noclasses' )
1801 $nextdiff = $current
1802 ?
wfMsgHtml( 'diff' )
1805 wfMsgHtml( 'diff' ),
1811 array( 'known', 'noclasses' )
1816 // User can delete revisions or view deleted revisions...
1817 $canHide = $wgUser->isAllowed( 'deleterevision' );
1818 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1819 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1820 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1823 'type' => 'revision',
1824 'target' => $this->getTitle()->getPrefixedDbkey(),
1827 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1832 # Show user links if allowed to see them. If hidden, then show them only if requested...
1833 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1835 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1836 ?
'revision-info-current'
1839 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1842 array( 'parseinline', 'replaceafter' ),
1848 $revision->getUser()
1851 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1852 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1854 $wgOut->addHTML( $r );
1857 /* Caching functions */
1860 * checkLastModified returns true if it has taken care of all
1861 * output to the client that is necessary for this request.
1862 * (that is, it has sent a cached version of the page)
1864 * @return boolean true if cached version send, false otherwise
1866 protected function tryFileCache() {
1867 static $called = false;
1870 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1875 if ( $this->isFileCacheable() ) {
1876 $cache = new HTMLFileCache( $this->getTitle() );
1877 if ( $cache->isFileCacheGood( $this->mPage
->getTouched() ) ) {
1878 wfDebug( "Article::tryFileCache(): about to load file\n" );
1879 $cache->loadFromFileCache();
1882 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1883 ob_start( array( &$cache, 'saveToFileCache' ) );
1886 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1893 * Check if the page can be cached
1896 public function isFileCacheable() {
1899 if ( HTMLFileCache
::useFileCache() ) {
1900 $cacheable = $this->mPage
->getID() && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1901 // Extension may have reason to disable file caching on some pages.
1903 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1913 * Overriden by ImagePage class, only present here to avoid a fatal error
1914 * Called for ?action=revert
1916 public function revert() {
1918 $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
1922 * Add the primary page-view wikitext to the output buffer
1923 * Saves the text into the parser cache if possible.
1924 * Updates templatelinks if it is out of date.
1926 * @param $text String
1927 * @param $cache Boolean
1928 * @param $parserOptions mixed ParserOptions object, or boolean false
1930 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1933 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1934 $wgOut->addParserOutput( $this->mParserOutput
);
1938 * This does all the heavy lifting for outputWikitext, except it returns the parser
1939 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1940 * say, embedding thread pages within a discussion system (LiquidThreads)
1942 * @param $text string
1943 * @param $cache boolean
1944 * @param $parserOptions parsing options, defaults to false
1945 * @return string containing parsed output
1947 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1948 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1950 if ( !$parserOptions ) {
1951 $parserOptions = $this->mPage
->getParserOptions();
1955 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1956 $parserOptions, true, true, $this->getRevIdFetched() );
1961 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1962 $this->getTitle()->getPrefixedDBkey() ) );
1965 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1966 $parserCache = ParserCache
::singleton();
1967 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1970 // Make sure file cache is not used on uncacheable content.
1971 // Output that has magic words in it can still use the parser cache
1972 // (if enabled), though it will generally expire sooner.
1973 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1974 $wgUseFileCache = false;
1977 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1979 return $this->mParserOutput
;
1983 * Updates cascading protections
1985 * @param $parserOutput ParserOutput object, or boolean false
1987 protected function doCascadeProtectionUpdates( $parserOutput ) {
1988 if ( !$this->isCurrent() ||
wfReadOnly() ||
!$this->getTitle()->areRestrictionsCascading() ) {
1992 // templatelinks table may have become out of sync,
1993 // especially if using variable-based transclusions.
1994 // For paranoia, check if things have changed and if
1995 // so apply updates to the database. This will ensure
1996 // that cascaded protections apply as soon as the changes
1999 # Get templates from templatelinks
2000 $id = $this->getTitle()->getArticleID();
2002 $tlTemplates = array();
2004 $dbr = wfGetDB( DB_SLAVE
);
2005 $res = $dbr->select( array( 'templatelinks' ),
2006 array( 'tl_namespace', 'tl_title' ),
2007 array( 'tl_from' => $id ),
2011 foreach ( $res as $row ) {
2012 $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
2015 # Get templates from parser output.
2016 $poTemplates = array();
2017 foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
2018 foreach ( $templates as $dbk => $id ) {
2019 $poTemplates["$ns:$dbk"] = true;
2024 $templates_diff = array_diff_key( $poTemplates, $tlTemplates );
2026 if ( count( $templates_diff ) > 0 ) {
2027 # Whee, link updates time.
2028 $u = new LinksUpdate( $this->getTitle(), $parserOutput, false );
2034 * Sets the context this Article is executed in
2036 * @param $context RequestContext
2039 public function setContext( $context ) {
2040 $this->mContext
= $context;
2044 * Gets the context this Article is executed in
2046 * @return RequestContext
2049 public function getContext() {
2050 if ( $this->mContext
instanceof RequestContext
) {
2051 return $this->mContext
;
2053 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
2054 return RequestContext
::getMain();
2059 * Use PHP's magic __get handler to handle accessing of
2060 * raw WikiPage fields for backwards compatibility.
2062 * @param $fname String Field name
2064 public function __get( $fname ) {
2065 if ( property_exists( $this->mPage
, $fname ) ) {
2066 #wfWarn( "Access to raw $fname field " . __CLASS__ );
2067 return $this->mPage
->$fname;
2069 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2073 * Use PHP's magic __set handler to handle setting of
2074 * raw WikiPage fields for backwards compatibility.
2076 * @param $fname String Field name
2077 * @param $fvalue mixed New value
2078 * @param $args Array Arguments to the method
2080 public function __set( $fname, $fvalue ) {
2081 if ( property_exists( $this->mPage
, $fname ) ) {
2082 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
2083 $this->mPage
->$fname = $fvalue;
2084 // Note: extensions may want to toss on new fields
2085 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
2086 $this->mPage
->$fname = $fvalue;
2088 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2093 * Use PHP's magic __call handler to transform instance calls to
2094 * WikiPage functions for backwards compatibility.
2096 * @param $fname String Name of called method
2097 * @param $args Array Arguments to the method
2099 public function __call( $fname, $args ) {
2100 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2101 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2102 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2104 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2107 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2108 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
2109 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
2112 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
2113 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2116 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) {
2117 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails );
2120 public function commitRollback( $fromP, $summary, $bot, &$resultDetails ) {
2121 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails );
2124 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2125 public static function selectFields() {
2126 return WikiPage
::selectFields();
2129 public static function onArticleCreate( $title ) {
2130 return WikiPage
::onArticleCreate( $title );
2133 public static function onArticleDelete( $title ) {
2134 return WikiPage
::onArticleDelete( $title );
2137 public static function onArticleEdit( $title ) {
2138 return WikiPage
::onArticleEdit( $title );
2141 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2142 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2147 class PoolWorkArticleView
extends PoolCounterWork
{
2154 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2155 parent
::__construct( 'ArticleView', $key );
2156 $this->mArticle
= $article;
2157 $this->cacheable
= $useParserCache;
2158 $this->parserOptions
= $parserOptions;
2162 return $this->mArticle
->doViewParse();
2165 function getCachedWork() {
2168 $parserCache = ParserCache
::singleton();
2169 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2171 if ( $this->mArticle
->mParserOutput
!== false ) {
2172 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2173 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2174 # Ensure that UI elements requiring revision ID have
2175 # the correct version information.
2176 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2182 function fallback() {
2183 return $this->mArticle
->tryDirtyCache();
2187 * @param $status Status
2189 function error( $status ) {
2192 $wgOut->clearHTML(); // for release() errors
2193 $wgOut->enableClientCache( false );
2194 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2196 $errortext = $status->getWikiText( false, 'view-pool-error' );
2197 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );