f073b5a75c943b8e4feb77bc1edcd608df1050b2
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
153 * @return Title object of this page
155 public function getTitle() {
156 return $this->mPage
->getTitle();
162 public function clear() {
163 $this->mContentLoaded
= false;
165 $this->mRedirectedFrom
= null; # Title object if set
166 $this->mRevIdFetched
= 0;
167 $this->mRedirectUrl
= false;
169 $this->mPage
->clear();
173 * Note that getContent/loadContent do not follow redirects anymore.
174 * If you need to fetch redirectable content easily, try
175 * the shortcut in Article::followRedirect()
177 * This function has side effects! Do not use this function if you
178 * only want the real revision text if any.
180 * @return Return the text of this revision
182 public function getContent() {
185 wfProfileIn( __METHOD__
);
187 if ( $this->mPage
->getID() === 0 ) {
188 # If this is a MediaWiki:x message, then load the messages
189 # and return the message value for x.
190 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
191 $text = $this->getTitle()->getDefaultMessageText();
192 if ( $text === false ) {
196 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
198 wfProfileOut( __METHOD__
);
202 $this->fetchContent();
203 wfProfileOut( __METHOD__
);
205 return $this->mContent
;
210 * @return int The oldid of the article that is to be shown, 0 for the
213 public function getOldID() {
214 if ( is_null( $this->mOldId
) ) {
215 $this->mOldId
= $this->getOldIDFromRequest();
218 return $this->mOldId
;
222 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
224 * @return int The old id for the request
226 public function getOldIDFromRequest() {
229 $this->mRedirectUrl
= false;
231 $oldid = $wgRequest->getIntOrNull( 'oldid' );
233 if ( $oldid === null ) {
237 if ( $oldid !== 0 ) {
238 # Load the given revision and check whether the page is another one.
239 # In that case, update this instance to reflect the change.
240 $this->mRevision
= Revision
::newFromId( $oldid );
241 if ( $this->mRevision
!== null ) {
242 // Revision title doesn't match the page title given?
243 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
244 $function = array( get_class( $this->mPage
), 'newFromID' );
245 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
250 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
251 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
255 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
257 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
258 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
268 * Load the revision (including text) into this object
270 * @deprecated in 1.19; use fetchContent()
272 function loadContent() {
273 $this->fetchContent();
277 * Get text of an article from database
278 * Does *NOT* follow redirects.
280 * @return mixed string containing article contents, or false if null
282 function fetchContent() {
283 if ( $this->mContentLoaded
) {
284 return $this->mContent
;
287 wfProfileIn( __METHOD__
);
289 $this->mContentLoaded
= true;
291 $oldid = $this->getOldID();
293 # Pre-fill content with error message so that if something
294 # fails we'll have something telling us what we intended.
295 $t = $this->getTitle()->getPrefixedText();
296 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
297 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
300 # $this->mRevision might already be fetched by getOldIDFromRequest()
301 if ( !$this->mRevision
) {
302 $this->mRevision
= Revision
::newFromId( $oldid );
303 if ( !$this->mRevision
) {
304 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
305 wfProfileOut( __METHOD__
);
310 if ( !$this->mPage
->getLatest() ) {
311 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
312 wfProfileOut( __METHOD__
);
316 $this->mRevision
= $this->mPage
->getRevision();
317 if ( !$this->mRevision
) {
318 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
319 wfProfileOut( __METHOD__
);
324 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
325 // We should instead work with the Revision object when we need it...
326 $this->mContent
= $this->mRevision
->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
327 $this->mRevIdFetched
= $this->mRevision
->getId();
329 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
331 wfProfileOut( __METHOD__
);
333 return $this->mContent
;
338 * @deprecated since 1.18
340 public function forUpdate() {
341 wfDeprecated( __METHOD__
);
345 * Returns true if the currently-referenced revision is the current edit
346 * to this page (and it exists).
349 public function isCurrent() {
350 # If no oldid, this is the current version.
351 if ( $this->getOldID() == 0 ) {
355 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
359 * Use this to fetch the rev ID used on page views
361 * @return int revision ID of last article revision
363 public function getRevIdFetched() {
364 if ( $this->mRevIdFetched
) {
365 return $this->mRevIdFetched
;
367 return $this->mPage
->getLatest();
372 * This is the default action of the index.php entry point: just view the
373 * page of the given title.
375 public function view() {
376 global $wgUser, $wgOut, $wgRequest, $wgParser;
377 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
379 wfProfileIn( __METHOD__
);
381 # Get variables from query string
382 # As side effect this will load the revision and update the title
383 # in a revision ID is passed in the request, so this should remain
384 # the first call of this method even if $oldid is used way below.
385 $oldid = $this->getOldID();
387 # Another whitelist check in case getOldID() is altering the title
388 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
389 if ( count( $permErrors ) ) {
390 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
391 wfProfileOut( __METHOD__
);
392 throw new PermissionsError( 'read', $permErrors );
395 # getOldID() may as well want us to redirect somewhere else
396 if ( $this->mRedirectUrl
) {
397 $wgOut->redirect( $this->mRedirectUrl
);
398 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
399 wfProfileOut( __METHOD__
);
404 # If we got diff in the query, we want to see a diff page instead of the article.
405 if ( $wgRequest->getCheck( 'diff' ) ) {
406 wfDebug( __METHOD__
. ": showing diff page\n" );
407 $this->showDiffPage();
408 wfProfileOut( __METHOD__
);
413 # Set page title (may be overridden by DISPLAYTITLE)
414 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
416 $wgOut->setArticleFlag( true );
417 # Allow frames by default
418 $wgOut->allowClickjacking();
420 $parserCache = ParserCache
::singleton();
422 $parserOptions = $this->getParserOptions();
423 # Render printable version, use printable version cache
424 if ( $wgOut->isPrintable() ) {
425 $parserOptions->setIsPrintable( true );
426 $parserOptions->setEditSection( false );
427 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
428 $parserOptions->setEditSection( false );
431 # Try client and file cache
432 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
434 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
437 # Is it client cached?
438 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
439 wfDebug( __METHOD__
. ": done 304\n" );
440 wfProfileOut( __METHOD__
);
444 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
445 wfDebug( __METHOD__
. ": done file cache\n" );
446 # tell wgOut that output is taken care of
448 $this->mPage
->viewUpdates();
449 wfProfileOut( __METHOD__
);
455 # Should the parser cache be used?
456 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
457 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
458 if ( $wgUser->getStubThreshold() ) {
459 wfIncrStats( 'pcache_miss_stub' );
462 $this->showRedirectedFromHeader();
463 $this->showNamespaceHeader();
465 # Iterate through the possible ways of constructing the output text.
466 # Keep going until $outputDone is set, or we run out of things to do.
469 $this->mParserOutput
= false;
471 while ( !$outputDone && ++
$pass ) {
474 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
477 # Early abort if the page doesn't exist
478 if ( !$this->mPage
->exists() ) {
479 wfDebug( __METHOD__
. ": showing missing article\n" );
480 $this->showMissingArticle();
481 wfProfileOut( __METHOD__
);
485 # Try the parser cache
486 if ( $useParserCache ) {
487 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
489 if ( $this->mParserOutput
!== false ) {
491 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
492 $this->setOldSubtitle( $oldid );
494 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
496 $wgOut->addParserOutput( $this->mParserOutput
);
497 # Ensure that UI elements requiring revision ID have
498 # the correct version information.
499 $wgOut->setRevisionId( $this->mPage
->getLatest() );
500 # Preload timestamp to avoid a DB hit
501 $wgOut->setRevisionTimestamp( $this->mParserOutput
->getTimestamp() );
502 $this->mPage
->setTimestamp( $this->mParserOutput
->getTimestamp() );
508 # This will set $this->mRevision if needed
509 $this->fetchContent();
511 # Are we looking at an old revision
512 if ( $oldid && $this->mRevision
) {
513 $this->setOldSubtitle( $oldid );
515 if ( !$this->showDeletedRevisionHeader() ) {
516 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
517 wfProfileOut( __METHOD__
);
522 # Ensure that UI elements requiring revision ID have
523 # the correct version information.
524 $wgOut->setRevisionId( $this->getRevIdFetched() );
525 # Preload timestamp to avoid a DB hit
526 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
528 # Pages containing custom CSS or JavaScript get special treatment
529 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
530 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
531 $this->showCssOrJsPage();
533 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
534 # Allow extensions do their own custom view for certain pages
537 $text = $this->getContent();
538 $rt = Title
::newFromRedirectArray( $text );
540 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
541 # Viewing a redirect page (e.g. with parameter redirect=no)
542 $wgOut->addHTML( $this->viewRedirect( $rt ) );
543 # Parse just to get categories, displaytitle, etc.
544 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
545 $wgOut->addParserOutputNoText( $this->mParserOutput
);
551 # Run the parse, protected by a pool counter
552 wfDebug( __METHOD__
. ": doing uncached parse\n" );
554 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
555 $this->getRevIdFetched(), $useParserCache, $this->getContent() );
557 if ( !$poolArticleView->execute() ) {
558 $error = $poolArticleView->getError();
560 $wgOut->clearHTML(); // for release() errors
561 $wgOut->enableClientCache( false );
562 $wgOut->setRobotPolicy( 'noindex,nofollow' );
564 $errortext = $error->getWikiText( false, 'view-pool-error' );
565 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
567 # Connection or timeout error
568 wfProfileOut( __METHOD__
);
572 $this->mParserOutput
= $poolArticleView->getParserOutput();
573 $wgOut->addParserOutput( $this->mParserOutput
);
575 # Don't cache a dirty ParserOutput object
576 if ( $poolArticleView->getIsDirty() ) {
577 $wgOut->setSquidMaxage( 0 );
578 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
583 # Should be unreachable, but just in case...
589 # Get the ParserOutput actually *displayed* here.
590 # Note that $this->mParserOutput is the *current* version output.
591 $pOutput = ( $outputDone instanceof ParserOutput
)
592 ?
$outputDone // object fetched by hook
593 : $this->mParserOutput
;
595 # Adjust title for main page & pages with displaytitle
597 $this->adjustDisplayTitle( $pOutput );
600 # For the main page, overwrite the <title> element with the con-
601 # tents of 'pagetitle-view-mainpage' instead of the default (if
603 # This message always exists because it is in the i18n files
604 if ( $this->getTitle()->isMainPage() ) {
605 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
606 if ( !$msg->isDisabled() ) {
607 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
611 # Check for any __NOINDEX__ tags on the page using $pOutput
612 $policy = $this->getRobotPolicy( 'view', $pOutput );
613 $wgOut->setIndexPolicy( $policy['index'] );
614 $wgOut->setFollowPolicy( $policy['follow'] );
616 $this->showViewFooter();
617 $this->mPage
->viewUpdates();
619 wfProfileOut( __METHOD__
);
623 * Adjust title for pages with displaytitle, -{T|}- or language conversion
624 * @param $pOutput ParserOutput
626 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
628 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
629 $titleText = $pOutput->getTitleText();
630 if ( strval( $titleText ) !== '' ) {
631 $wgOut->setPageTitle( $titleText );
636 * Show a diff page according to current request variables. For use within
637 * Article::view() only, other callers should use the DifferenceEngine class.
639 public function showDiffPage() {
640 global $wgRequest, $wgUser;
642 $diff = $wgRequest->getVal( 'diff' );
643 $rcid = $wgRequest->getVal( 'rcid' );
644 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
645 $purge = $wgRequest->getVal( 'action' ) == 'purge';
646 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
647 $oldid = $this->getOldID();
649 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
650 // DifferenceEngine directly fetched the revision:
651 $this->mRevIdFetched
= $de->mNewid
;
652 $de->showDiffPage( $diffOnly );
654 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
655 # Run view updates for current revision only
656 $this->mPage
->viewUpdates();
661 * Show a page view for a page formatted as CSS or JavaScript. To be called by
662 * Article::view() only.
664 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
667 protected function showCssOrJsPage() {
670 $dir = $this->getContext()->getLanguage()->getDir();
671 $lang = $this->getContext()->getLanguage()->getCode();
673 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
676 // Give hooks a chance to customise the output
677 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
678 // Wrap the whole lot in a <pre> and don't parse
680 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
681 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
682 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
683 $wgOut->addHTML( "\n</pre>\n" );
688 * Get the robot policy to be used for the current view
689 * @param $action String the action= GET parameter
690 * @param $pOutput ParserOutput
691 * @return Array the policy that should be set
692 * TODO: actions other than 'view'
694 public function getRobotPolicy( $action, $pOutput ) {
695 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
696 global $wgDefaultRobotPolicy, $wgRequest;
698 $ns = $this->getTitle()->getNamespace();
700 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
701 # Don't index user and user talk pages for blocked users (bug 11443)
702 if ( !$this->getTitle()->isSubpage() ) {
703 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
705 'index' => 'noindex',
706 'follow' => 'nofollow'
712 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
713 # Non-articles (special pages etc), and old revisions
715 'index' => 'noindex',
716 'follow' => 'nofollow'
718 } elseif ( $wgOut->isPrintable() ) {
719 # Discourage indexing of printable versions, but encourage following
721 'index' => 'noindex',
724 } elseif ( $wgRequest->getInt( 'curid' ) ) {
725 # For ?curid=x urls, disallow indexing
727 'index' => 'noindex',
732 # Otherwise, construct the policy based on the various config variables.
733 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
735 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
736 # Honour customised robot policies for this namespace
737 $policy = array_merge(
739 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
742 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
743 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
744 # a final sanity check that we have really got the parser output.
745 $policy = array_merge(
747 array( 'index' => $pOutput->getIndexPolicy() )
751 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
752 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
753 $policy = array_merge(
755 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
763 * Converts a String robot policy into an associative array, to allow
764 * merging of several policies using array_merge().
765 * @param $policy Mixed, returns empty array on null/false/'', transparent
766 * to already-converted arrays, converts String.
767 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
769 public static function formatRobotPolicy( $policy ) {
770 if ( is_array( $policy ) ) {
772 } elseif ( !$policy ) {
776 $policy = explode( ',', $policy );
777 $policy = array_map( 'trim', $policy );
780 foreach ( $policy as $var ) {
781 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
782 $arr['index'] = $var;
783 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
784 $arr['follow'] = $var;
792 * If this request is a redirect view, send "redirected from" subtitle to
793 * $wgOut. Returns true if the header was needed, false if this is not a
794 * redirect view. Handles both local and remote redirects.
798 public function showRedirectedFromHeader() {
799 global $wgOut, $wgRequest, $wgRedirectSources;
801 $rdfrom = $wgRequest->getVal( 'rdfrom' );
803 if ( isset( $this->mRedirectedFrom
) ) {
804 // This is an internally redirected page view.
805 // We'll need a backlink to the source page for navigation.
806 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
807 $redir = Linker
::linkKnown(
808 $this->mRedirectedFrom
,
811 array( 'redirect' => 'no' )
814 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
816 // Set the fragment if one was specified in the redirect
817 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
818 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
819 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
822 // Add a <link rel="canonical"> tag
823 $wgOut->addLink( array( 'rel' => 'canonical',
824 'href' => $this->getTitle()->getLocalURL() )
827 // Tell $wgOut the user arrived at this article through a redirect
828 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
832 } elseif ( $rdfrom ) {
833 // This is an externally redirected view, from some other wiki.
834 // If it was reported from a trusted site, supply a backlink.
835 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
836 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
837 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
847 * Show a header specific to the namespace currently being viewed, like
848 * [[MediaWiki:Talkpagetext]]. For Article::view().
850 public function showNamespaceHeader() {
853 if ( $this->getTitle()->isTalkPage() ) {
854 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
855 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
861 * Show the footer section of an ordinary page view
863 public function showViewFooter() {
866 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
867 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
868 $wgOut->addWikiMsg( 'anontalkpagetext' );
871 # If we have been passed an &rcid= parameter, we want to give the user a
872 # chance to mark this new article as patrolled.
873 $this->showPatrolFooter();
875 wfRunHooks( 'ArticleViewFooter', array( $this ) );
880 * If patrol is possible, output a patrol UI box. This is called from the
881 * footer section of ordinary page views. If patrol is not possible or not
882 * desired, does nothing.
884 public function showPatrolFooter() {
885 global $wgOut, $wgRequest, $wgUser;
887 $rcid = $wgRequest->getVal( 'rcid' );
889 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
893 $token = $wgUser->getEditToken( $rcid );
894 $wgOut->preventClickjacking();
897 "<div class='patrollink'>" .
899 'markaspatrolledlink',
902 wfMsgHtml( 'markaspatrolledtext' ),
905 'action' => 'markpatrolled',
909 array( 'known', 'noclasses' )
917 * Show the error text for a missing article. For articles in the MediaWiki
918 * namespace, show the default message text. To be called from Article::view().
920 public function showMissingArticle() {
921 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
923 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
924 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
925 $parts = explode( '/', $this->getTitle()->getText() );
926 $rootPart = $parts[0];
927 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
928 $ip = User
::isIP( $rootPart );
930 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
931 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
932 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
933 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
934 LogEventsList
::showLogExtract(
937 $user->getUserPage()->getPrefixedText(),
941 'showIfEmpty' => false,
943 'blocked-notice-logextract',
944 $user->getName() # Support GENDER in notice
951 wfRunHooks( 'ShowMissingArticle', array( $this ) );
953 # Show delete and move logs
954 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
956 'conds' => array( "log_action != 'revision'" ),
957 'showIfEmpty' => false,
958 'msgKey' => array( 'moveddeleted-notice' ) )
962 $oldid = $this->getOldID();
964 $text = wfMsgNoTrans( 'missing-article',
965 $this->getTitle()->getPrefixedText(),
966 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
967 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
968 // Use the default message text
969 $text = $this->getTitle()->getDefaultMessageText();
971 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
972 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
973 $errors = array_merge( $createErrors, $editErrors );
975 if ( !count( $errors ) ) {
976 $text = wfMsgNoTrans( 'noarticletext' );
978 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
981 $text = "<div class='noarticletext'>\n$text\n</div>";
983 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
984 // If there's no backing content, send a 404 Not Found
985 // for better machine handling of broken links.
986 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
989 $wgOut->addWikiText( $text );
993 * If the revision requested for view is deleted, check permissions.
994 * Send either an error message or a warning header to $wgOut.
996 * @return boolean true if the view is allowed, false if not.
998 public function showDeletedRevisionHeader() {
999 global $wgOut, $wgRequest;
1001 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1006 // If the user is not allowed to see it...
1007 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1008 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1009 'rev-deleted-text-permission' );
1012 // If the user needs to confirm that they want to see it...
1013 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1014 # Give explanation and add a link to view the revision...
1015 $oldid = intval( $this->getOldID() );
1016 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1017 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1018 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1019 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1020 array( $msg, $link ) );
1023 // We are allowed to see...
1025 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1026 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1027 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1034 * Generate the navigation links when browsing through an article revisions
1035 * It shows the information as:
1036 * Revision as of \<date\>; view current revision
1037 * \<- Previous version | Next Version -\>
1039 * @param $oldid String: revision ID of this article revision
1041 public function setOldSubtitle( $oldid = 0 ) {
1042 global $wgLang, $wgOut, $wgUser, $wgRequest;
1044 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1048 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1050 # Cascade unhide param in links for easy deletion browsing
1051 $extraParams = array();
1052 if ( $wgRequest->getVal( 'unhide' ) ) {
1053 $extraParams['unhide'] = 1;
1056 $revision = Revision
::newFromId( $oldid );
1057 $timestamp = $revision->getTimestamp();
1059 $current = ( $oldid == $this->mPage
->getLatest() );
1060 $td = $wgLang->timeanddate( $timestamp, true );
1061 $tddate = $wgLang->date( $timestamp, true );
1062 $tdtime = $wgLang->time( $timestamp, true );
1064 # Show user links if allowed to see them. If hidden, then show them only if requested...
1065 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1067 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1068 ?
'revision-info-current'
1071 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1072 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1073 $tdtime, $revision->getUser() )->parse() . "</div>" );
1076 ?
wfMsgHtml( 'currentrevisionlink' )
1079 wfMsgHtml( 'currentrevisionlink' ),
1082 array( 'known', 'noclasses' )
1085 ?
wfMsgHtml( 'diff' )
1088 wfMsgHtml( 'diff' ),
1094 array( 'known', 'noclasses' )
1096 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1100 wfMsgHtml( 'previousrevision' ),
1103 'direction' => 'prev',
1106 array( 'known', 'noclasses' )
1108 : wfMsgHtml( 'previousrevision' );
1112 wfMsgHtml( 'diff' ),
1118 array( 'known', 'noclasses' )
1120 : wfMsgHtml( 'diff' );
1121 $nextlink = $current
1122 ?
wfMsgHtml( 'nextrevision' )
1125 wfMsgHtml( 'nextrevision' ),
1128 'direction' => 'next',
1131 array( 'known', 'noclasses' )
1133 $nextdiff = $current
1134 ?
wfMsgHtml( 'diff' )
1137 wfMsgHtml( 'diff' ),
1143 array( 'known', 'noclasses' )
1148 // User can delete revisions or view deleted revisions...
1149 $canHide = $wgUser->isAllowed( 'deleterevision' );
1150 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1151 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1152 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1155 'type' => 'revision',
1156 'target' => $this->getTitle()->getPrefixedDbkey(),
1159 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1164 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1165 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1166 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1172 * @param $target Title|Array of destination(s) to redirect
1173 * @param $appendSubtitle Boolean [optional]
1174 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1175 * @return string containing HMTL with redirect link
1177 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1178 global $wgOut, $wgStylePath;
1180 if ( !is_array( $target ) ) {
1181 $target = array( $target );
1184 $lang = $this->getTitle()->getPageLanguage();
1185 $imageDir = $lang->getDir();
1187 if ( $appendSubtitle ) {
1188 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1191 // the loop prepends the arrow image before the link, so the first case needs to be outside
1196 $title = array_shift( $target );
1198 if ( $forceKnown ) {
1199 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1201 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1204 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1205 $alt = $lang->isRTL() ?
'←' : '→';
1206 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1207 foreach ( $target as $rt ) {
1208 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1209 if ( $forceKnown ) {
1210 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1212 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1216 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1217 return '<div class="redirectMsg">' .
1218 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1219 '<span class="redirectText">' . $link . '</span></div>';
1223 * Handle action=render
1225 public function render() {
1228 $wgOut->setArticleBodyOnly( true );
1233 * action=protect handler
1235 public function protect() {
1236 $form = new ProtectionForm( $this );
1241 * action=unprotect handler (alias)
1243 public function unprotect() {
1248 * UI entry point for page deletion
1250 public function delete() {
1251 global $wgOut, $wgRequest, $wgLang;
1253 # This code desperately needs to be totally rewritten
1255 $title = $this->getTitle();
1256 $user = $this->getContext()->getUser();
1259 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1260 if ( count( $permission_errors ) ) {
1261 throw new PermissionsError( 'delete', $permission_errors );
1264 # Read-only check...
1265 if ( wfReadOnly() ) {
1266 throw new ReadOnlyError
;
1269 # Better double-check that it hasn't been deleted yet!
1270 $dbw = wfGetDB( DB_MASTER
);
1271 $conds = $title->pageCond();
1272 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1273 if ( $latest === false ) {
1274 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1275 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1276 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1278 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1279 LogEventsList
::showLogExtract(
1282 $title->getPrefixedText()
1288 # Hack for big sites
1289 $bigHistory = $this->mPage
->isBigDeletion();
1290 if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
1291 global $wgDeleteRevisionsLimit;
1293 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1294 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1295 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1300 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1301 $deleteReason = $wgRequest->getText( 'wpReason' );
1303 if ( $deleteReasonList == 'other' ) {
1304 $reason = $deleteReason;
1305 } elseif ( $deleteReason != '' ) {
1306 // Entry from drop down menu + additional comment
1307 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1309 $reason = $deleteReasonList;
1312 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1313 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1315 # Flag to hide all contents of the archived revisions
1316 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1318 $this->doDelete( $reason, $suppress );
1320 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1322 } elseif ( $title->userIsWatching() ) {
1329 // Generate deletion reason
1330 $hasHistory = false;
1332 $reason = $this->generateReason( $hasHistory );
1335 // If the page has a history, insert a warning
1336 if ( $hasHistory ) {
1337 $revisions = $this->mPage
->estimateRevisionCount();
1338 // @todo FIXME: i18n issue/patchwork message
1339 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1340 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1341 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1342 wfMsgHtml( 'history' ),
1343 array( 'rel' => 'archives' ),
1344 array( 'action' => 'history' ) ) .
1348 if ( $bigHistory ) {
1349 global $wgDeleteRevisionsLimit;
1350 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1351 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1355 return $this->confirmDelete( $reason );
1359 * Output deletion confirmation dialog
1360 * @todo FIXME: Move to another file?
1361 * @param $reason String: prefilled reason
1363 public function confirmDelete( $reason ) {
1366 wfDebug( "Article::confirmDelete\n" );
1368 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1369 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1370 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1371 $wgOut->addWikiMsg( 'confirmdeletetext' );
1373 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1375 $user = $this->getContext()->getUser();
1377 if ( $user->isAllowed( 'suppressrevision' ) ) {
1378 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1380 <td class='mw-input'><strong>" .
1381 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1382 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1388 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1390 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1391 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1392 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1393 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1394 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1395 "<tr id=\"wpDeleteReasonListRow\">
1396 <td class='mw-label'>" .
1397 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1399 <td class='mw-input'>" .
1400 Xml
::listDropDown( 'wpDeleteReasonList',
1401 wfMsgForContent( 'deletereason-dropdown' ),
1402 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1405 <tr id=\"wpDeleteReasonRow\">
1406 <td class='mw-label'>" .
1407 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1409 <td class='mw-input'>" .
1410 Html
::input( 'wpReason', $reason, 'text', array(
1412 'maxlength' => '255',
1420 # Disallow watching if user is not logged in
1421 if ( $user->isLoggedIn() ) {
1425 <td class='mw-input'>" .
1426 Xml
::checkLabel( wfMsg( 'watchthis' ),
1427 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1436 <td class='mw-submit'>" .
1437 Xml
::submitButton( wfMsg( 'deletepage' ),
1438 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1441 Xml
::closeElement( 'table' ) .
1442 Xml
::closeElement( 'fieldset' ) .
1443 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1444 Xml
::closeElement( 'form' );
1446 if ( $user->isAllowed( 'editinterface' ) ) {
1447 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1448 $link = Linker
::link(
1450 wfMsgHtml( 'delete-edit-reasonlist' ),
1452 array( 'action' => 'edit' )
1454 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1457 $wgOut->addHTML( $form );
1458 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1459 LogEventsList
::showLogExtract( $wgOut, 'delete',
1460 $this->getTitle()->getPrefixedText()
1465 * Perform a deletion and output success or failure messages
1467 * @param $suppress bool
1469 public function doDelete( $reason, $suppress = false ) {
1472 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1475 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
1476 $deleted = $this->getTitle()->getPrefixedText();
1478 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1479 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1481 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1483 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1484 $wgOut->returnToMain( false );
1486 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1487 if ( $error == '' ) {
1488 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1489 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1491 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1493 LogEventsList
::showLogExtract(
1496 $this->getTitle()->getPrefixedText()
1499 $wgOut->addHTML( $error );
1504 /* Caching functions */
1507 * checkLastModified returns true if it has taken care of all
1508 * output to the client that is necessary for this request.
1509 * (that is, it has sent a cached version of the page)
1511 * @return boolean true if cached version send, false otherwise
1513 protected function tryFileCache() {
1514 static $called = false;
1517 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1522 if ( $this->isFileCacheable() ) {
1523 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1524 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1525 wfDebug( "Article::tryFileCache(): about to load file\n" );
1526 $cache->loadFromFileCache( $this->getContext() );
1529 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1530 ob_start( array( &$cache, 'saveToFileCache' ) );
1533 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1540 * Check if the page can be cached
1543 public function isFileCacheable() {
1546 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1547 $cacheable = $this->mPage
->getID()
1548 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1549 // Extension may have reason to disable file caching on some pages.
1551 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1561 * Lightweight method to get the parser output for a page, checking the parser cache
1562 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1563 * consider, so it's not appropriate to use there.
1565 * @since 1.16 (r52326) for LiquidThreads
1567 * @param $oldid mixed integer Revision ID or null
1568 * @param $user User The relevant user
1569 * @return ParserOutput or false if the given revsion ID is not found
1571 public function getParserOutput( $oldid = null, User
$user = null ) {
1574 $user = is_null( $user ) ?
$wgUser : $user;
1575 $parserOptions = $this->mPage
->makeParserOptions( $user );
1577 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1581 * Get parser options suitable for rendering the primary article wikitext
1582 * @return ParserOptions|false
1584 public function getParserOptions() {
1586 if ( !$this->mParserOptions
) {
1587 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1589 // Clone to allow modifications of the return value without affecting cache
1590 return clone $this->mParserOptions
;
1594 * Sets the context this Article is executed in
1596 * @param $context IContextSource
1599 public function setContext( $context ) {
1600 $this->mContext
= $context;
1604 * Gets the context this Article is executed in
1606 * @return IContextSource
1609 public function getContext() {
1610 if ( $this->mContext
instanceof IContextSource
) {
1611 return $this->mContext
;
1613 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1614 return RequestContext
::getMain();
1619 * Info about this page
1620 * @deprecated since 1.19
1622 public function info() {
1623 Action
::factory( 'info', $this )->show();
1627 * Mark this particular edit/page as patrolled
1628 * @deprecated since 1.18
1630 public function markpatrolled() {
1631 Action
::factory( 'markpatrolled', $this )->show();
1635 * Handle action=purge
1636 * @deprecated since 1.19
1638 public function purge() {
1639 return Action
::factory( 'purge', $this )->show();
1643 * Handle action=revert
1644 * @deprecated since 1.19
1646 public function revert() {
1647 Action
::factory( 'revert', $this )->show();
1651 * Handle action=rollback
1652 * @deprecated since 1.19
1654 public function rollback() {
1655 Action
::factory( 'rollback', $this )->show();
1659 * User-interface handler for the "watch" action.
1660 * Requires Request to pass a token as of 1.18.
1661 * @deprecated since 1.18
1663 public function watch() {
1664 Action
::factory( 'watch', $this )->show();
1668 * Add this page to $wgUser's watchlist
1670 * This is safe to be called multiple times
1672 * @return bool true on successful watch operation
1673 * @deprecated since 1.18
1675 public function doWatch() {
1677 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1681 * User interface handler for the "unwatch" action.
1682 * Requires Request to pass a token as of 1.18.
1683 * @deprecated since 1.18
1685 public function unwatch() {
1686 Action
::factory( 'unwatch', $this )->show();
1690 * Stop watching a page
1691 * @return bool true on successful unwatch
1692 * @deprecated since 1.18
1694 public function doUnwatch() {
1696 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1700 * Output a redirect back to the article.
1701 * This is typically used after an edit.
1703 * @deprecated in 1.18; call $wgOut->redirect() directly
1704 * @param $noRedir Boolean: add redirect=no
1705 * @param $sectionAnchor String: section to redirect to, including "#"
1706 * @param $extraQuery String: extra query params
1708 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1709 wfDeprecated( __METHOD__
);
1713 $query = 'redirect=no';
1715 $query .= "&$extraQuery";
1717 $query = $extraQuery;
1720 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1724 * Use PHP's magic __get handler to handle accessing of
1725 * raw WikiPage fields for backwards compatibility.
1727 * @param $fname String Field name
1729 public function __get( $fname ) {
1730 if ( property_exists( $this->mPage
, $fname ) ) {
1731 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1732 return $this->mPage
->$fname;
1734 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1738 * Use PHP's magic __set handler to handle setting of
1739 * raw WikiPage fields for backwards compatibility.
1741 * @param $fname String Field name
1742 * @param $fvalue mixed New value
1744 public function __set( $fname, $fvalue ) {
1745 if ( property_exists( $this->mPage
, $fname ) ) {
1746 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1747 $this->mPage
->$fname = $fvalue;
1748 // Note: extensions may want to toss on new fields
1749 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1750 $this->mPage
->$fname = $fvalue;
1752 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1757 * Use PHP's magic __call handler to transform instance calls to
1758 * WikiPage functions for backwards compatibility.
1760 * @param $fname String Name of called method
1761 * @param $args Array Arguments to the method
1763 public function __call( $fname, $args ) {
1764 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1765 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1766 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1768 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1771 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1774 * @param $limit array
1775 * @param $reason string
1776 * @param $cascade int
1777 * @param $expiry array
1780 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1781 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1785 * @param $reason string
1786 * @param $suppress bool
1788 * @param $commit bool
1789 * @param $error string
1792 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1793 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1801 * @param $resultDetails
1805 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1807 $user = is_null( $user ) ?
$wgUser : $user;
1808 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1815 * @param $resultDetails
1816 * @param $guser User
1819 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1821 $guser = is_null( $guser ) ?
$wgUser : $guser;
1822 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1826 * @param $hasHistory bool
1829 public function generateReason( &$hasHistory ) {
1830 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1833 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1838 public static function selectFields() {
1839 return WikiPage
::selectFields();
1843 * @param $title Title
1845 public static function onArticleCreate( $title ) {
1846 WikiPage
::onArticleCreate( $title );
1850 * @param $title Title
1852 public static function onArticleDelete( $title ) {
1853 WikiPage
::onArticleDelete( $title );
1857 * @param $title Title
1859 public static function onArticleEdit( $title ) {
1860 WikiPage
::onArticleEdit( $title );
1869 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1870 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );