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 ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
41 var $mContentLoaded = false; // !<
47 var $mRedirectedFrom = null;
50 * @var mixed: boolean false or URL string
52 var $mRedirectUrl = false; // !<
53 var $mRevIdFetched = 0; // !<
58 var $mRevision = null;
68 * Constructor and clear the article
69 * @param $title Title Reference to a Title object.
70 * @param $oldId Integer revision ID, null to fetch from request, zero for current
72 public function __construct( Title
$title, $oldId = null ) {
73 $this->mOldId
= $oldId;
74 $this->mPage
= $this->newPage( $title );
81 protected function newPage( Title
$title ) {
82 return new WikiPage( $title );
86 * Constructor from a page id
87 * @param $id Int article ID to load
88 * @return Article|null
90 public static function newFromID( $id ) {
91 $t = Title
::newFromID( $id );
92 # @todo FIXME: Doesn't inherit right
93 return $t == null ?
null : new self( $t );
94 # return $t == null ? null : new static( $t ); // PHP 5.3
98 * Create an Article object of the appropriate class for the given page.
100 * @param $title Title
101 * @param $context IContextSource
102 * @return Article object
104 public static function newFromTitle( $title, IContextSource
$context ) {
105 if ( NS_MEDIA
== $title->getNamespace() ) {
106 // FIXME: where should this go?
107 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
111 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
113 switch( $title->getNamespace() ) {
115 $page = new ImagePage( $title );
118 $page = new CategoryPage( $title );
121 $page = new Article( $title );
124 $page->setContext( $context );
130 * Create an Article object of the appropriate class for the given page.
132 * @param $page WikiPage
133 * @param $context IContextSource
134 * @return Article object
136 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
137 $article = self
::newFromTitle( $page->getTitle(), $context );
138 $article->mPage
= $page; // override to keep process cached vars
143 * Tell the page view functions that this view was redirected
144 * from another page on the wiki.
145 * @param $from Title object.
147 public function setRedirectedFrom( Title
$from ) {
148 $this->mRedirectedFrom
= $from;
152 * Get the title object of the article
154 * @return Title object of this page
156 public function getTitle() {
157 return $this->mPage
->getTitle();
161 * Get the WikiPage object of this instance
166 public function getPage() {
173 public function clear() {
174 $this->mContentLoaded
= false;
176 $this->mRedirectedFrom
= null; # Title object if set
177 $this->mRevIdFetched
= 0;
178 $this->mRedirectUrl
= false;
180 $this->mPage
->clear();
184 * Note that getContent/loadContent do not follow redirects anymore.
185 * If you need to fetch redirectable content easily, try
186 * the shortcut in WikiPage::getRedirectTarget()
188 * This function has side effects! Do not use this function if you
189 * only want the real revision text if any.
191 * @return string Return the text of this revision
193 public function getContent() {
194 wfProfileIn( __METHOD__
);
196 if ( $this->mPage
->getID() === 0 ) {
197 # If this is a MediaWiki:x message, then load the messages
198 # and return the message value for x.
199 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
200 $text = $this->getTitle()->getDefaultMessageText();
201 if ( $text === false ) {
205 $text = wfMsgExt( $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
207 wfProfileOut( __METHOD__
);
211 $this->fetchContent();
212 wfProfileOut( __METHOD__
);
214 return $this->mContent
;
219 * @return int The oldid of the article that is to be shown, 0 for the
222 public function getOldID() {
223 if ( is_null( $this->mOldId
) ) {
224 $this->mOldId
= $this->getOldIDFromRequest();
227 return $this->mOldId
;
231 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
233 * @return int The old id for the request
235 public function getOldIDFromRequest() {
236 $this->mRedirectUrl
= false;
238 $request = $this->getContext()->getRequest();
239 $oldid = $request->getIntOrNull( 'oldid' );
241 if ( $oldid === null ) {
245 if ( $oldid !== 0 ) {
246 # Load the given revision and check whether the page is another one.
247 # In that case, update this instance to reflect the change.
248 if ( $oldid === $this->mPage
->getLatest() ) {
249 $this->mRevision
= $this->mPage
->getRevision();
251 $this->mRevision
= Revision
::newFromId( $oldid );
252 if ( $this->mRevision
!== null ) {
253 // Revision title doesn't match the page title given?
254 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
255 $function = array( get_class( $this->mPage
), 'newFromID' );
256 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
262 if ( $request->getVal( 'direction' ) == 'next' ) {
263 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
266 $this->mRevision
= null;
268 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
270 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
271 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
274 $this->mRevision
= null;
282 * Load the revision (including text) into this object
284 * @deprecated in 1.19; use fetchContent()
286 function loadContent() {
287 wfDeprecated( __METHOD__
, '1.19' );
288 $this->fetchContent();
292 * Get text of an article from database
293 * Does *NOT* follow redirects.
295 * @return mixed string containing article contents, or false if null
297 function fetchContent() {
298 if ( $this->mContentLoaded
) {
299 return $this->mContent
;
302 wfProfileIn( __METHOD__
);
304 $this->mContentLoaded
= true;
306 $oldid = $this->getOldID();
308 # Pre-fill content with error message so that if something
309 # fails we'll have something telling us what we intended.
310 $t = $this->getTitle()->getPrefixedText();
311 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
312 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
315 # $this->mRevision might already be fetched by getOldIDFromRequest()
316 if ( !$this->mRevision
) {
317 $this->mRevision
= Revision
::newFromId( $oldid );
318 if ( !$this->mRevision
) {
319 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
320 wfProfileOut( __METHOD__
);
325 if ( !$this->mPage
->getLatest() ) {
326 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
327 wfProfileOut( __METHOD__
);
331 $this->mRevision
= $this->mPage
->getRevision();
332 if ( !$this->mRevision
) {
333 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
334 wfProfileOut( __METHOD__
);
339 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
340 // We should instead work with the Revision object when we need it...
341 $this->mContent
= $this->mRevision
->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
342 $this->mRevIdFetched
= $this->mRevision
->getId();
344 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
346 wfProfileOut( __METHOD__
);
348 return $this->mContent
;
353 * @deprecated since 1.18
355 public function forUpdate() {
356 wfDeprecated( __METHOD__
, '1.18' );
360 * Returns true if the currently-referenced revision is the current edit
361 * to this page (and it exists).
364 public function isCurrent() {
365 # If no oldid, this is the current version.
366 if ( $this->getOldID() == 0 ) {
370 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
374 * Get the fetched Revision object depending on request parameters or null
378 * @return Revision|null
380 public function getRevisionFetched() {
381 $this->fetchContent();
383 return $this->mRevision
;
387 * Use this to fetch the rev ID used on page views
389 * @return int revision ID of last article revision
391 public function getRevIdFetched() {
392 if ( $this->mRevIdFetched
) {
393 return $this->mRevIdFetched
;
395 return $this->mPage
->getLatest();
400 * This is the default action of the index.php entry point: just view the
401 * page of the given title.
403 public function view() {
404 global $wgParser, $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
406 wfProfileIn( __METHOD__
);
408 # Get variables from query string
409 # As side effect this will load the revision and update the title
410 # in a revision ID is passed in the request, so this should remain
411 # the first call of this method even if $oldid is used way below.
412 $oldid = $this->getOldID();
414 $user = $this->getContext()->getUser();
415 # Another whitelist check in case getOldID() is altering the title
416 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
417 if ( count( $permErrors ) ) {
418 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
419 wfProfileOut( __METHOD__
);
420 throw new PermissionsError( 'read', $permErrors );
423 $outputPage = $this->getContext()->getOutput();
424 # getOldID() may as well want us to redirect somewhere else
425 if ( $this->mRedirectUrl
) {
426 $outputPage->redirect( $this->mRedirectUrl
);
427 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
428 wfProfileOut( __METHOD__
);
433 # If we got diff in the query, we want to see a diff page instead of the article.
434 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
435 wfDebug( __METHOD__
. ": showing diff page\n" );
436 $this->showDiffPage();
437 wfProfileOut( __METHOD__
);
442 # Set page title (may be overridden by DISPLAYTITLE)
443 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
445 $outputPage->setArticleFlag( true );
446 # Allow frames by default
447 $outputPage->allowClickjacking();
449 $parserCache = ParserCache
::singleton();
451 $parserOptions = $this->getParserOptions();
452 # Render printable version, use printable version cache
453 if ( $outputPage->isPrintable() ) {
454 $parserOptions->setIsPrintable( true );
455 $parserOptions->setEditSection( false );
456 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
457 $parserOptions->setEditSection( false );
460 # Try client and file cache
461 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
463 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
466 # Is it client cached?
467 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
468 wfDebug( __METHOD__
. ": done 304\n" );
469 wfProfileOut( __METHOD__
);
473 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
474 wfDebug( __METHOD__
. ": done file cache\n" );
475 # tell wgOut that output is taken care of
476 $outputPage->disable();
477 $this->mPage
->doViewUpdates( $user );
478 wfProfileOut( __METHOD__
);
484 # Should the parser cache be used?
485 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
486 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
487 if ( $user->getStubThreshold() ) {
488 wfIncrStats( 'pcache_miss_stub' );
491 $this->showRedirectedFromHeader();
492 $this->showNamespaceHeader();
494 # Iterate through the possible ways of constructing the output text.
495 # Keep going until $outputDone is set, or we run out of things to do.
498 $this->mParserOutput
= false;
500 while ( !$outputDone && ++
$pass ) {
503 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
506 # Early abort if the page doesn't exist
507 if ( !$this->mPage
->exists() ) {
508 wfDebug( __METHOD__
. ": showing missing article\n" );
509 $this->showMissingArticle();
510 wfProfileOut( __METHOD__
);
514 # Try the parser cache
515 if ( $useParserCache ) {
516 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
518 if ( $this->mParserOutput
!== false ) {
520 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
521 $this->setOldSubtitle( $oldid );
523 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
525 $outputPage->addParserOutput( $this->mParserOutput
);
526 # Ensure that UI elements requiring revision ID have
527 # the correct version information.
528 $outputPage->setRevisionId( $this->mPage
->getLatest() );
529 # Preload timestamp to avoid a DB hit
530 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
531 if ( $cachedTimestamp !== null ) {
532 $outputPage->setRevisionTimestamp( $cachedTimestamp );
533 $this->mPage
->setTimestamp( $cachedTimestamp );
540 # This will set $this->mRevision if needed
541 $this->fetchContent();
543 # Are we looking at an old revision
544 if ( $oldid && $this->mRevision
) {
545 $this->setOldSubtitle( $oldid );
547 if ( !$this->showDeletedRevisionHeader() ) {
548 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
549 wfProfileOut( __METHOD__
);
554 # Ensure that UI elements requiring revision ID have
555 # the correct version information.
556 $outputPage->setRevisionId( $this->getRevIdFetched() );
557 # Preload timestamp to avoid a DB hit
558 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
560 # Pages containing custom CSS or JavaScript get special treatment
561 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
562 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
563 $this->showCssOrJsPage();
565 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $outputPage ) ) ) {
566 # Allow extensions do their own custom view for certain pages
569 $text = $this->getContent();
570 $rt = Title
::newFromRedirectArray( $text );
572 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
573 # Viewing a redirect page (e.g. with parameter redirect=no)
574 $outputPage->addHTML( $this->viewRedirect( $rt ) );
575 # Parse just to get categories, displaytitle, etc.
576 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
577 $outputPage->addParserOutputNoText( $this->mParserOutput
);
583 # Run the parse, protected by a pool counter
584 wfDebug( __METHOD__
. ": doing uncached parse\n" );
586 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
587 $this->getRevIdFetched(), $useParserCache, $this->getContent() );
589 if ( !$poolArticleView->execute() ) {
590 $error = $poolArticleView->getError();
592 $outputPage->clearHTML(); // for release() errors
593 $outputPage->enableClientCache( false );
594 $outputPage->setRobotPolicy( 'noindex,nofollow' );
596 $errortext = $error->getWikiText( false, 'view-pool-error' );
597 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
599 # Connection or timeout error
600 wfProfileOut( __METHOD__
);
604 $this->mParserOutput
= $poolArticleView->getParserOutput();
605 $outputPage->addParserOutput( $this->mParserOutput
);
607 # Don't cache a dirty ParserOutput object
608 if ( $poolArticleView->getIsDirty() ) {
609 $outputPage->setSquidMaxage( 0 );
610 $outputPage->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
615 # Should be unreachable, but just in case...
621 # Get the ParserOutput actually *displayed* here.
622 # Note that $this->mParserOutput is the *current* version output.
623 $pOutput = ( $outputDone instanceof ParserOutput
)
624 ?
$outputDone // object fetched by hook
625 : $this->mParserOutput
;
627 # Adjust title for main page & pages with displaytitle
629 $this->adjustDisplayTitle( $pOutput );
632 # For the main page, overwrite the <title> element with the con-
633 # tents of 'pagetitle-view-mainpage' instead of the default (if
635 # This message always exists because it is in the i18n files
636 if ( $this->getTitle()->isMainPage() ) {
637 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
638 if ( !$msg->isDisabled() ) {
639 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
643 # Check for any __NOINDEX__ tags on the page using $pOutput
644 $policy = $this->getRobotPolicy( 'view', $pOutput );
645 $outputPage->setIndexPolicy( $policy['index'] );
646 $outputPage->setFollowPolicy( $policy['follow'] );
648 $this->showViewFooter();
649 $this->mPage
->doViewUpdates( $user );
651 wfProfileOut( __METHOD__
);
655 * Adjust title for pages with displaytitle, -{T|}- or language conversion
656 * @param $pOutput ParserOutput
658 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
659 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
660 $titleText = $pOutput->getTitleText();
661 if ( strval( $titleText ) !== '' ) {
662 $this->getContext()->getOutput()->setPageTitle( $titleText );
667 * Show a diff page according to current request variables. For use within
668 * Article::view() only, other callers should use the DifferenceEngine class.
670 public function showDiffPage() {
671 $request = $this->getContext()->getRequest();
672 $user = $this->getContext()->getUser();
673 $diff = $request->getVal( 'diff' );
674 $rcid = $request->getVal( 'rcid' );
675 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
676 $purge = $request->getVal( 'action' ) == 'purge';
677 $unhide = $request->getInt( 'unhide' ) == 1;
678 $oldid = $this->getOldID();
680 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
681 // DifferenceEngine directly fetched the revision:
682 $this->mRevIdFetched
= $de->mNewid
;
683 $de->showDiffPage( $diffOnly );
685 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
686 # Run view updates for current revision only
687 $this->mPage
->doViewUpdates( $user );
692 * Show a page view for a page formatted as CSS or JavaScript. To be called by
693 * Article::view() only.
695 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
698 protected function showCssOrJsPage() {
699 $dir = $this->getContext()->getLanguage()->getDir();
700 $lang = $this->getContext()->getLanguage()->getCode();
702 $outputPage = $this->getContext()->getOutput();
703 $outputPage->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
706 // Give hooks a chance to customise the output
707 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $outputPage ) ) ) {
708 // Wrap the whole lot in a <pre> and don't parse
710 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
711 $outputPage->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
712 $outputPage->addHTML( htmlspecialchars( $this->mContent
) );
713 $outputPage->addHTML( "\n</pre>\n" );
718 * Get the robot policy to be used for the current view
719 * @param $action String the action= GET parameter
720 * @param $pOutput ParserOutput
721 * @return Array the policy that should be set
722 * TODO: actions other than 'view'
724 public function getRobotPolicy( $action, $pOutput ) {
725 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
727 $ns = $this->getTitle()->getNamespace();
729 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
730 # Don't index user and user talk pages for blocked users (bug 11443)
731 if ( !$this->getTitle()->isSubpage() ) {
732 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
734 'index' => 'noindex',
735 'follow' => 'nofollow'
741 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
742 # Non-articles (special pages etc), and old revisions
744 'index' => 'noindex',
745 'follow' => 'nofollow'
747 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
748 # Discourage indexing of printable versions, but encourage following
750 'index' => 'noindex',
753 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
754 # For ?curid=x urls, disallow indexing
756 'index' => 'noindex',
761 # Otherwise, construct the policy based on the various config variables.
762 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
764 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
765 # Honour customised robot policies for this namespace
766 $policy = array_merge(
768 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
771 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
772 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
773 # a final sanity check that we have really got the parser output.
774 $policy = array_merge(
776 array( 'index' => $pOutput->getIndexPolicy() )
780 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
781 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
782 $policy = array_merge(
784 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
792 * Converts a String robot policy into an associative array, to allow
793 * merging of several policies using array_merge().
794 * @param $policy Mixed, returns empty array on null/false/'', transparent
795 * to already-converted arrays, converts String.
796 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
798 public static function formatRobotPolicy( $policy ) {
799 if ( is_array( $policy ) ) {
801 } elseif ( !$policy ) {
805 $policy = explode( ',', $policy );
806 $policy = array_map( 'trim', $policy );
809 foreach ( $policy as $var ) {
810 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
811 $arr['index'] = $var;
812 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
813 $arr['follow'] = $var;
821 * If this request is a redirect view, send "redirected from" subtitle to
822 * the output. Returns true if the header was needed, false if this is not
823 * a redirect view. Handles both local and remote redirects.
827 public function showRedirectedFromHeader() {
828 global $wgRedirectSources;
829 $outputPage = $this->getContext()->getOutput();
831 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
833 if ( isset( $this->mRedirectedFrom
) ) {
834 // This is an internally redirected page view.
835 // We'll need a backlink to the source page for navigation.
836 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
837 $redir = Linker
::linkKnown(
838 $this->mRedirectedFrom
,
841 array( 'redirect' => 'no' )
844 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
846 // Set the fragment if one was specified in the redirect
847 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
848 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
849 $outputPage->addInlineScript( "redirectToFragment(\"$fragment\");" );
852 // Add a <link rel="canonical"> tag
853 $outputPage->addLink( array( 'rel' => 'canonical',
854 'href' => $this->getTitle()->getLocalURL() )
857 // Tell the output object that the user arrived at this article through a redirect
858 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
862 } elseif ( $rdfrom ) {
863 // This is an externally redirected view, from some other wiki.
864 // If it was reported from a trusted site, supply a backlink.
865 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
866 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
867 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
877 * Show a header specific to the namespace currently being viewed, like
878 * [[MediaWiki:Talkpagetext]]. For Article::view().
880 public function showNamespaceHeader() {
881 if ( $this->getTitle()->isTalkPage() ) {
882 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
883 $this->getContext()->getOutput()->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
889 * Show the footer section of an ordinary page view
891 public function showViewFooter() {
892 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
893 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
894 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
897 # If we have been passed an &rcid= parameter, we want to give the user a
898 # chance to mark this new article as patrolled.
899 $this->showPatrolFooter();
901 wfRunHooks( 'ArticleViewFooter', array( $this ) );
906 * If patrol is possible, output a patrol UI box. This is called from the
907 * footer section of ordinary page views. If patrol is not possible or not
908 * desired, does nothing.
910 public function showPatrolFooter() {
911 $request = $this->getContext()->getRequest();
912 $outputPage = $this->getContext()->getOutput();
913 $user = $this->getContext()->getUser();
914 $rcid = $request->getVal( 'rcid' );
916 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
920 $token = $user->getEditToken( $rcid );
921 $outputPage->preventClickjacking();
923 $outputPage->addHTML(
924 "<div class='patrollink'>" .
926 'markaspatrolledlink',
929 wfMsgHtml( 'markaspatrolledtext' ),
932 'action' => 'markpatrolled',
936 array( 'known', 'noclasses' )
944 * Show the error text for a missing article. For articles in the MediaWiki
945 * namespace, show the default message text. To be called from Article::view().
947 public function showMissingArticle() {
948 global $wgSend404Code;
949 $outputPage = $this->getContext()->getOutput();
951 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
952 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
953 $parts = explode( '/', $this->getTitle()->getText() );
954 $rootPart = $parts[0];
955 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
956 $ip = User
::isIP( $rootPart );
958 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
959 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
960 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
961 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
962 LogEventsList
::showLogExtract(
965 $user->getUserPage()->getPrefixedText(),
969 'showIfEmpty' => false,
971 'blocked-notice-logextract',
972 $user->getName() # Support GENDER in notice
979 wfRunHooks( 'ShowMissingArticle', array( $this ) );
981 # Show delete and move logs
982 LogEventsList
::showLogExtract( $outputPage, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
984 'conds' => array( "log_action != 'revision'" ),
985 'showIfEmpty' => false,
986 'msgKey' => array( 'moveddeleted-notice' ) )
989 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
990 // If there's no backing content, send a 404 Not Found
991 // for better machine handling of broken links.
992 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
995 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
997 if ( ! $hookResult ) {
1001 # Show error message
1002 $oldid = $this->getOldID();
1004 $text = wfMsgNoTrans( 'missing-article',
1005 $this->getTitle()->getPrefixedText(),
1006 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1007 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1008 // Use the default message text
1009 $text = $this->getTitle()->getDefaultMessageText();
1011 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $this->getContext()->getUser() );
1012 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getContext()->getUser() );
1013 $errors = array_merge( $createErrors, $editErrors );
1015 if ( !count( $errors ) ) {
1016 $text = wfMsgNoTrans( 'noarticletext' );
1018 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1021 $text = "<div class='noarticletext'>\n$text\n</div>";
1023 $outputPage->addWikiText( $text );
1027 * If the revision requested for view is deleted, check permissions.
1028 * Send either an error message or a warning header to the output.
1030 * @return boolean true if the view is allowed, false if not.
1032 public function showDeletedRevisionHeader() {
1033 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1038 $outputPage = $this->getContext()->getOutput();
1039 // If the user is not allowed to see it...
1040 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1041 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1042 'rev-deleted-text-permission' );
1045 // If the user needs to confirm that they want to see it...
1046 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1047 # Give explanation and add a link to view the revision...
1048 $oldid = intval( $this->getOldID() );
1049 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1050 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1051 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1052 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1053 array( $msg, $link ) );
1056 // We are allowed to see...
1058 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1059 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1060 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1067 * Generate the navigation links when browsing through an article revisions
1068 * It shows the information as:
1069 * Revision as of \<date\>; view current revision
1070 * \<- Previous version | Next Version -\>
1072 * @param $oldid int: revision ID of this article revision
1074 public function setOldSubtitle( $oldid = 0 ) {
1075 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1079 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1081 # Cascade unhide param in links for easy deletion browsing
1082 $extraParams = array();
1084 $extraParams['unhide'] = 1;
1087 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1088 $revision = $this->mRevision
;
1090 $revision = Revision
::newFromId( $oldid );
1093 $timestamp = $revision->getTimestamp();
1095 $current = ( $oldid == $this->mPage
->getLatest() );
1096 $language = $this->getContext()->getLanguage();
1097 $td = $language->timeanddate( $timestamp, true );
1098 $tddate = $language->date( $timestamp, true );
1099 $tdtime = $language->time( $timestamp, true );
1101 # Show user links if allowed to see them. If hidden, then show them only if requested...
1102 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1104 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1105 ?
'revision-info-current'
1108 $outputPage = $this->getContext()->getOutput();
1109 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1110 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1111 $tdtime, $revision->getUser() )->parse() . "</div>" );
1114 ?
wfMsgHtml( 'currentrevisionlink' )
1117 wfMsgHtml( 'currentrevisionlink' ),
1120 array( 'known', 'noclasses' )
1123 ?
wfMsgHtml( 'diff' )
1126 wfMsgHtml( 'diff' ),
1132 array( 'known', 'noclasses' )
1134 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1138 wfMsgHtml( 'previousrevision' ),
1141 'direction' => 'prev',
1144 array( 'known', 'noclasses' )
1146 : wfMsgHtml( 'previousrevision' );
1150 wfMsgHtml( 'diff' ),
1156 array( 'known', 'noclasses' )
1158 : wfMsgHtml( 'diff' );
1159 $nextlink = $current
1160 ?
wfMsgHtml( 'nextrevision' )
1163 wfMsgHtml( 'nextrevision' ),
1166 'direction' => 'next',
1169 array( 'known', 'noclasses' )
1171 $nextdiff = $current
1172 ?
wfMsgHtml( 'diff' )
1175 wfMsgHtml( 'diff' ),
1181 array( 'known', 'noclasses' )
1184 $cdel = Linker
::getRevDeleteLink( $this->getContext()->getUser(), $revision, $this->getTitle() );
1185 if ( $cdel !== '' ) {
1189 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1190 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1191 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1197 * @param $target Title|Array of destination(s) to redirect
1198 * @param $appendSubtitle Boolean [optional]
1199 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1200 * @return string containing HMTL with redirect link
1202 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1203 global $wgStylePath;
1205 if ( !is_array( $target ) ) {
1206 $target = array( $target );
1209 $lang = $this->getTitle()->getPageLanguage();
1210 $imageDir = $lang->getDir();
1212 if ( $appendSubtitle ) {
1213 $this->getContext()->getOutput()->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1216 // the loop prepends the arrow image before the link, so the first case needs to be outside
1221 $title = array_shift( $target );
1223 if ( $forceKnown ) {
1224 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1226 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1229 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1230 $alt = $lang->isRTL() ?
'←' : '→';
1231 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1232 foreach ( $target as $rt ) {
1233 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1234 if ( $forceKnown ) {
1235 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1237 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1241 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1242 return '<div class="redirectMsg">' .
1243 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1244 '<span class="redirectText">' . $link . '</span></div>';
1248 * Handle action=render
1250 public function render() {
1251 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1256 * action=protect handler
1258 public function protect() {
1259 $form = new ProtectionForm( $this );
1264 * action=unprotect handler (alias)
1266 public function unprotect() {
1271 * UI entry point for page deletion
1273 public function delete() {
1274 # This code desperately needs to be totally rewritten
1276 $title = $this->getTitle();
1277 $user = $this->getContext()->getUser();
1280 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1281 if ( count( $permission_errors ) ) {
1282 throw new PermissionsError( 'delete', $permission_errors );
1285 # Read-only check...
1286 if ( wfReadOnly() ) {
1287 throw new ReadOnlyError
;
1290 # Better double-check that it hasn't been deleted yet!
1291 $dbw = wfGetDB( DB_MASTER
);
1292 $conds = $title->pageCond();
1293 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1294 if ( $latest === false ) {
1295 $outputPage = $this->getContext()->getOutput();
1296 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1297 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1298 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1300 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1301 LogEventsList
::showLogExtract(
1304 $title->getPrefixedText()
1310 $request = $this->getContext()->getRequest();
1311 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1312 $deleteReason = $request->getText( 'wpReason' );
1314 if ( $deleteReasonList == 'other' ) {
1315 $reason = $deleteReason;
1316 } elseif ( $deleteReason != '' ) {
1317 // Entry from drop down menu + additional comment
1318 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1320 $reason = $deleteReasonList;
1323 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1324 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1326 # Flag to hide all contents of the archived revisions
1327 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1329 $this->doDelete( $reason, $suppress );
1331 if ( $request->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1333 } elseif ( $title->userIsWatching() ) {
1340 // Generate deletion reason
1341 $hasHistory = false;
1343 $reason = $this->generateReason( $hasHistory );
1346 // If the page has a history, insert a warning
1347 if ( $hasHistory ) {
1348 $revisions = $this->mTitle
->estimateRevisionCount();
1349 // @todo FIXME: i18n issue/patchwork message
1350 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1351 wfMsgExt( 'historywarning', array( 'parseinline' ), $this->getContext()->getLanguage()->formatNum( $revisions ) ) .
1352 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1353 wfMsgHtml( 'history' ),
1354 array( 'rel' => 'archives' ),
1355 array( 'action' => 'history' ) ) .
1359 if ( $this->mTitle
->isBigDeletion() ) {
1360 global $wgDeleteRevisionsLimit;
1361 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1362 array( 'delete-warning-toobig', $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
1366 return $this->confirmDelete( $reason );
1370 * Output deletion confirmation dialog
1371 * @todo FIXME: Move to another file?
1372 * @param $reason String: prefilled reason
1374 public function confirmDelete( $reason ) {
1375 wfDebug( "Article::confirmDelete\n" );
1377 $outputPage = $this->getContext()->getOutput();
1378 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1379 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1380 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1381 $outputPage->addWikiMsg( 'confirmdeletetext' );
1383 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1385 $user = $this->getContext()->getUser();
1387 if ( $user->isAllowed( 'suppressrevision' ) ) {
1388 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1390 <td class='mw-input'><strong>" .
1391 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1392 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1398 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1400 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1401 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1402 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1403 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1404 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1405 "<tr id=\"wpDeleteReasonListRow\">
1406 <td class='mw-label'>" .
1407 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1409 <td class='mw-input'>" .
1410 Xml
::listDropDown( 'wpDeleteReasonList',
1411 wfMsgForContent( 'deletereason-dropdown' ),
1412 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1415 <tr id=\"wpDeleteReasonRow\">
1416 <td class='mw-label'>" .
1417 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1419 <td class='mw-input'>" .
1420 Html
::input( 'wpReason', $reason, 'text', array(
1422 'maxlength' => '255',
1430 # Disallow watching if user is not logged in
1431 if ( $user->isLoggedIn() ) {
1435 <td class='mw-input'>" .
1436 Xml
::checkLabel( wfMsg( 'watchthis' ),
1437 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1446 <td class='mw-submit'>" .
1447 Xml
::submitButton( wfMsg( 'deletepage' ),
1448 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1451 Xml
::closeElement( 'table' ) .
1452 Xml
::closeElement( 'fieldset' ) .
1453 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1454 Xml
::closeElement( 'form' );
1456 if ( $user->isAllowed( 'editinterface' ) ) {
1457 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1458 $link = Linker
::link(
1460 wfMsgHtml( 'delete-edit-reasonlist' ),
1462 array( 'action' => 'edit' )
1464 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1467 $outputPage->addHTML( $form );
1468 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1469 LogEventsList
::showLogExtract( $outputPage, 'delete',
1470 $this->getTitle()->getPrefixedText()
1475 * Perform a deletion and output success or failure messages
1477 * @param $suppress bool
1479 public function doDelete( $reason, $suppress = false ) {
1481 $outputPage = $this->getContext()->getOutput();
1482 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1483 $deleted = $this->getTitle()->getPrefixedText();
1485 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1486 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1488 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1490 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1491 $outputPage->returnToMain( false );
1493 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1494 if ( $error == '' ) {
1495 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1496 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1498 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1500 LogEventsList
::showLogExtract(
1503 $this->getTitle()->getPrefixedText()
1506 $outputPage->addHTML( $error );
1511 /* Caching functions */
1514 * checkLastModified returns true if it has taken care of all
1515 * output to the client that is necessary for this request.
1516 * (that is, it has sent a cached version of the page)
1518 * @return boolean true if cached version send, false otherwise
1520 protected function tryFileCache() {
1521 static $called = false;
1524 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1529 if ( $this->isFileCacheable() ) {
1530 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1531 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1532 wfDebug( "Article::tryFileCache(): about to load file\n" );
1533 $cache->loadFromFileCache( $this->getContext() );
1536 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1537 ob_start( array( &$cache, 'saveToFileCache' ) );
1540 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1547 * Check if the page can be cached
1550 public function isFileCacheable() {
1553 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1554 $cacheable = $this->mPage
->getID()
1555 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1556 // Extension may have reason to disable file caching on some pages.
1558 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1568 * Lightweight method to get the parser output for a page, checking the parser cache
1569 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1570 * consider, so it's not appropriate to use there.
1572 * @since 1.16 (r52326) for LiquidThreads
1574 * @param $oldid mixed integer Revision ID or null
1575 * @param $user User The relevant user
1576 * @return ParserOutput or false if the given revsion ID is not found
1578 public function getParserOutput( $oldid = null, User
$user = null ) {
1579 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1580 $parserOptions = $this->mPage
->makeParserOptions( $user );
1582 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1586 * Get parser options suitable for rendering the primary article wikitext
1587 * @return ParserOptions
1589 public function getParserOptions() {
1590 if ( !$this->mParserOptions
) {
1591 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext()->getUser() );
1593 // Clone to allow modifications of the return value without affecting cache
1594 return clone $this->mParserOptions
;
1598 * Sets the context this Article is executed in
1600 * @param $context IContextSource
1603 public function setContext( $context ) {
1604 $this->mContext
= $context;
1608 * Gets the context this Article is executed in
1610 * @return IContextSource
1613 public function getContext() {
1614 if ( $this->mContext
instanceof IContextSource
) {
1615 return $this->mContext
;
1617 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1618 return RequestContext
::getMain();
1623 * Info about this page
1624 * @deprecated since 1.19
1626 public function info() {
1627 wfDeprecated( __METHOD__
, '1.19' );
1628 Action
::factory( 'info', $this )->show();
1632 * Mark this particular edit/page as patrolled
1633 * @deprecated since 1.18
1635 public function markpatrolled() {
1636 wfDeprecated( __METHOD__
, '1.18' );
1637 Action
::factory( 'markpatrolled', $this )->show();
1641 * Handle action=purge
1642 * @deprecated since 1.19
1644 public function purge() {
1645 return Action
::factory( 'purge', $this )->show();
1649 * Handle action=revert
1650 * @deprecated since 1.19
1652 public function revert() {
1653 wfDeprecated( __METHOD__
, '1.19' );
1654 Action
::factory( 'revert', $this )->show();
1658 * Handle action=rollback
1659 * @deprecated since 1.19
1661 public function rollback() {
1662 wfDeprecated( __METHOD__
, '1.19' );
1663 Action
::factory( 'rollback', $this )->show();
1667 * User-interface handler for the "watch" action.
1668 * Requires Request to pass a token as of 1.18.
1669 * @deprecated since 1.18
1671 public function watch() {
1672 wfDeprecated( __METHOD__
, '1.18' );
1673 Action
::factory( 'watch', $this )->show();
1677 * Add this page to the current user's watchlist
1679 * This is safe to be called multiple times
1681 * @return bool true on successful watch operation
1682 * @deprecated since 1.18
1684 public function doWatch() {
1685 wfDeprecated( __METHOD__
, '1.18' );
1686 return WatchAction
::doWatch( $this->getTitle(), $this->getContext()->getUser() );
1690 * User interface handler for the "unwatch" action.
1691 * Requires Request to pass a token as of 1.18.
1692 * @deprecated since 1.18
1694 public function unwatch() {
1695 wfDeprecated( __METHOD__
, '1.18' );
1696 Action
::factory( 'unwatch', $this )->show();
1700 * Stop watching a page
1701 * @return bool true on successful unwatch
1702 * @deprecated since 1.18
1704 public function doUnwatch() {
1705 wfDeprecated( __METHOD__
, '1.18' );
1706 return WatchAction
::doUnwatch( $this->getTitle(), $this->getContext()->getUser() );
1710 * Output a redirect back to the article.
1711 * This is typically used after an edit.
1713 * @deprecated in 1.18; call OutputPage::redirect() directly
1714 * @param $noRedir Boolean: add redirect=no
1715 * @param $sectionAnchor String: section to redirect to, including "#"
1716 * @param $extraQuery String: extra query params
1718 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1719 wfDeprecated( __METHOD__
, '1.18' );
1721 $query = 'redirect=no';
1723 $query .= "&$extraQuery";
1725 $query = $extraQuery;
1728 $this->getContext()->getOutput()->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1732 * Use PHP's magic __get handler to handle accessing of
1733 * raw WikiPage fields for backwards compatibility.
1735 * @param $fname String Field name
1737 public function __get( $fname ) {
1738 if ( property_exists( $this->mPage
, $fname ) ) {
1739 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1740 return $this->mPage
->$fname;
1742 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1746 * Use PHP's magic __set handler to handle setting of
1747 * raw WikiPage fields for backwards compatibility.
1749 * @param $fname String Field name
1750 * @param $fvalue mixed New value
1752 public function __set( $fname, $fvalue ) {
1753 if ( property_exists( $this->mPage
, $fname ) ) {
1754 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1755 $this->mPage
->$fname = $fvalue;
1756 // Note: extensions may want to toss on new fields
1757 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1758 $this->mPage
->$fname = $fvalue;
1760 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1765 * Use PHP's magic __call handler to transform instance calls to
1766 * WikiPage functions for backwards compatibility.
1768 * @param $fname String Name of called method
1769 * @param $args Array Arguments to the method
1772 public function __call( $fname, $args ) {
1773 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1774 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1775 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1777 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1780 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1783 * @param $limit array
1784 * @param $expiry array
1785 * @param $cascade bool
1786 * @param $reason string
1790 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1791 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1795 * @param $limit array
1796 * @param $reason string
1797 * @param $cascade int
1798 * @param $expiry array
1801 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1802 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1806 * @param $reason string
1807 * @param $suppress bool
1809 * @param $commit bool
1810 * @param $error string
1813 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1814 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1822 * @param $resultDetails
1826 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1827 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1828 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1835 * @param $resultDetails
1836 * @param $guser User
1839 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1840 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
1841 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1845 * @param $hasHistory bool
1848 public function generateReason( &$hasHistory ) {
1849 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1852 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1857 public static function selectFields() {
1858 return WikiPage
::selectFields();
1862 * @param $title Title
1864 public static function onArticleCreate( $title ) {
1865 WikiPage
::onArticleCreate( $title );
1869 * @param $title Title
1871 public static function onArticleDelete( $title ) {
1872 WikiPage
::onArticleDelete( $title );
1876 * @param $title Title
1878 public static function onArticleEdit( $title ) {
1879 WikiPage
::onArticleEdit( $title );
1888 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1889 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );