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;
40 var $mContent; // !< #FIXME: use Content object!
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 Return the text of this revision
193 public function getContent() {
196 wfProfileIn( __METHOD__
);
198 if ( $this->mPage
->getID() === 0 ) {
199 # If this is a MediaWiki:x message, then load the messages
200 # and return the message value for x.
201 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
202 $text = $this->getTitle()->getDefaultMessageText();
203 if ( $text === false ) {
207 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
209 wfProfileOut( __METHOD__
);
213 $this->fetchContent();
214 wfProfileOut( __METHOD__
);
216 return $this->mContent
;
221 * @return int The oldid of the article that is to be shown, 0 for the
224 public function getOldID() {
225 if ( is_null( $this->mOldId
) ) {
226 $this->mOldId
= $this->getOldIDFromRequest();
229 return $this->mOldId
;
233 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
235 * @return int The old id for the request
237 public function getOldIDFromRequest() {
240 $this->mRedirectUrl
= false;
242 $oldid = $wgRequest->getIntOrNull( 'oldid' );
244 if ( $oldid === null ) {
248 if ( $oldid !== 0 ) {
249 # Load the given revision and check whether the page is another one.
250 # In that case, update this instance to reflect the change.
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() );
261 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
262 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
265 $this->mRevision
= null;
267 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
269 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
270 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
273 $this->mRevision
= null;
281 * Load the revision (including text) into this object
283 * @deprecated in 1.19; use fetchContent()
285 function loadContent() {
286 wfDeprecated( __METHOD__
, '1.19' );
287 $this->fetchContent();
291 * Get text of an article from database
292 * Does *NOT* follow redirects.
294 * @return mixed string containing article contents, or false if null
296 function fetchContent() {
297 if ( $this->mContentLoaded
) {
298 return $this->mContent
;
301 wfProfileIn( __METHOD__
);
303 $this->mContentLoaded
= true;
305 $oldid = $this->getOldID();
307 # Pre-fill content with error message so that if something
308 # fails we'll have something telling us what we intended.
309 $t = $this->getTitle()->getPrefixedText();
310 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
311 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
314 # $this->mRevision might already be fetched by getOldIDFromRequest()
315 if ( !$this->mRevision
) {
316 $this->mRevision
= Revision
::newFromId( $oldid );
317 if ( !$this->mRevision
) {
318 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
319 wfProfileOut( __METHOD__
);
324 if ( !$this->mPage
->getLatest() ) {
325 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
326 wfProfileOut( __METHOD__
);
330 $this->mRevision
= $this->mPage
->getRevision();
331 if ( !$this->mRevision
) {
332 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
333 wfProfileOut( __METHOD__
);
338 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
339 // We should instead work with the Revision object when we need it...
340 $this->mContent
= $this->mRevision
->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
341 $this->mRevIdFetched
= $this->mRevision
->getId();
343 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
345 wfProfileOut( __METHOD__
);
347 return $this->mContent
;
352 * @deprecated since 1.18
354 public function forUpdate() {
355 wfDeprecated( __METHOD__
, '1.18' );
359 * Returns true if the currently-referenced revision is the current edit
360 * to this page (and it exists).
363 public function isCurrent() {
364 # If no oldid, this is the current version.
365 if ( $this->getOldID() == 0 ) {
369 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
373 * Get the fetched Revision object depending on request parameters or null
377 * @return Revision|null
379 public function getRevisionFetched() {
380 $this->fetchContent();
382 return $this->mRevision
;
386 * Use this to fetch the rev ID used on page views
388 * @return int revision ID of last article revision
390 public function getRevIdFetched() {
391 if ( $this->mRevIdFetched
) {
392 return $this->mRevIdFetched
;
394 return $this->mPage
->getLatest();
399 * This is the default action of the index.php entry point: just view the
400 * page of the given title.
402 public function view() {
403 global $wgUser, $wgOut, $wgRequest, $wgParser;
404 global $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 # Another whitelist check in case getOldID() is altering the title
415 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
416 if ( count( $permErrors ) ) {
417 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
418 wfProfileOut( __METHOD__
);
419 throw new PermissionsError( 'read', $permErrors );
422 # getOldID() may as well want us to redirect somewhere else
423 if ( $this->mRedirectUrl
) {
424 $wgOut->redirect( $this->mRedirectUrl
);
425 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
426 wfProfileOut( __METHOD__
);
431 # If we got diff in the query, we want to see a diff page instead of the article.
432 if ( $wgRequest->getCheck( 'diff' ) ) {
433 wfDebug( __METHOD__
. ": showing diff page\n" );
434 $this->showDiffPage();
435 wfProfileOut( __METHOD__
);
440 # Set page title (may be overridden by DISPLAYTITLE)
441 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
443 $wgOut->setArticleFlag( true );
444 # Allow frames by default
445 $wgOut->allowClickjacking();
447 $parserCache = ParserCache
::singleton();
449 $parserOptions = $this->getParserOptions();
450 # Render printable version, use printable version cache
451 if ( $wgOut->isPrintable() ) {
452 $parserOptions->setIsPrintable( true );
453 $parserOptions->setEditSection( false );
454 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
455 $parserOptions->setEditSection( false );
458 # Try client and file cache
459 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
461 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
464 # Is it client cached?
465 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
466 wfDebug( __METHOD__
. ": done 304\n" );
467 wfProfileOut( __METHOD__
);
471 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
472 wfDebug( __METHOD__
. ": done file cache\n" );
473 # tell wgOut that output is taken care of
475 $this->mPage
->doViewUpdates( $wgUser );
476 wfProfileOut( __METHOD__
);
482 # Should the parser cache be used?
483 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
484 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
485 if ( $wgUser->getStubThreshold() ) {
486 wfIncrStats( 'pcache_miss_stub' );
489 $this->showRedirectedFromHeader();
490 $this->showNamespaceHeader();
492 # Iterate through the possible ways of constructing the output text.
493 # Keep going until $outputDone is set, or we run out of things to do.
496 $this->mParserOutput
= false;
498 while ( !$outputDone && ++
$pass ) {
501 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
504 # Early abort if the page doesn't exist
505 if ( !$this->mPage
->exists() ) {
506 wfDebug( __METHOD__
. ": showing missing article\n" );
507 $this->showMissingArticle();
508 wfProfileOut( __METHOD__
);
512 # Try the parser cache
513 if ( $useParserCache ) {
514 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
516 if ( $this->mParserOutput
!== false ) {
518 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
519 $this->setOldSubtitle( $oldid );
521 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
523 $wgOut->addParserOutput( $this->mParserOutput
);
524 # Ensure that UI elements requiring revision ID have
525 # the correct version information.
526 $wgOut->setRevisionId( $this->mPage
->getLatest() );
527 # Preload timestamp to avoid a DB hit
528 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
529 if ( $cachedTimestamp !== null ) {
530 $wgOut->setRevisionTimestamp( $cachedTimestamp );
531 $this->mPage
->setTimestamp( $cachedTimestamp );
538 # This will set $this->mRevision if needed
539 $this->fetchContent();
541 # Are we looking at an old revision
542 if ( $oldid && $this->mRevision
) {
543 $this->setOldSubtitle( $oldid );
545 if ( !$this->showDeletedRevisionHeader() ) {
546 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
547 wfProfileOut( __METHOD__
);
552 # Ensure that UI elements requiring revision ID have
553 # the correct version information.
554 $wgOut->setRevisionId( $this->getRevIdFetched() );
555 # Preload timestamp to avoid a DB hit
556 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
558 # Pages containing custom CSS or JavaScript get special treatment
559 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
560 #FIXME: use Content object instead!
561 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
562 $this->showCssOrJsPage();
564 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
565 # Allow extensions do their own custom view for certain pages
568 $text = $this->getContent();
569 $rt = Title
::newFromRedirectArray( $text );
571 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
572 # Viewing a redirect page (e.g. with parameter redirect=no)
573 $wgOut->addHTML( $this->viewRedirect( $rt ) );
574 # Parse just to get categories, displaytitle, etc.
575 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
576 $wgOut->addParserOutputNoText( $this->mParserOutput
);
582 # Run the parse, protected by a pool counter
583 wfDebug( __METHOD__
. ": doing uncached parse\n" );
585 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
586 $this->getRevIdFetched(), $useParserCache, $this->getContent() );
588 if ( !$poolArticleView->execute() ) {
589 $error = $poolArticleView->getError();
591 $wgOut->clearHTML(); // for release() errors
592 $wgOut->enableClientCache( false );
593 $wgOut->setRobotPolicy( 'noindex,nofollow' );
595 $errortext = $error->getWikiText( false, 'view-pool-error' );
596 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
598 # Connection or timeout error
599 wfProfileOut( __METHOD__
);
603 $this->mParserOutput
= $poolArticleView->getParserOutput();
604 $wgOut->addParserOutput( $this->mParserOutput
);
606 # Don't cache a dirty ParserOutput object
607 if ( $poolArticleView->getIsDirty() ) {
608 $wgOut->setSquidMaxage( 0 );
609 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
614 # Should be unreachable, but just in case...
620 # Get the ParserOutput actually *displayed* here.
621 # Note that $this->mParserOutput is the *current* version output.
622 $pOutput = ( $outputDone instanceof ParserOutput
)
623 ?
$outputDone // object fetched by hook
624 : $this->mParserOutput
;
626 # Adjust title for main page & pages with displaytitle
628 $this->adjustDisplayTitle( $pOutput );
631 # For the main page, overwrite the <title> element with the con-
632 # tents of 'pagetitle-view-mainpage' instead of the default (if
634 # This message always exists because it is in the i18n files
635 if ( $this->getTitle()->isMainPage() ) {
636 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
637 if ( !$msg->isDisabled() ) {
638 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
642 # Check for any __NOINDEX__ tags on the page using $pOutput
643 $policy = $this->getRobotPolicy( 'view', $pOutput );
644 $wgOut->setIndexPolicy( $policy['index'] );
645 $wgOut->setFollowPolicy( $policy['follow'] );
647 $this->showViewFooter();
648 $this->mPage
->doViewUpdates( $wgUser );
650 wfProfileOut( __METHOD__
);
654 * Adjust title for pages with displaytitle, -{T|}- or language conversion
655 * @param $pOutput ParserOutput
657 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 $wgOut->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 global $wgRequest, $wgUser;
673 $diff = $wgRequest->getVal( 'diff' );
674 $rcid = $wgRequest->getVal( 'rcid' );
675 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
676 $purge = $wgRequest->getVal( 'action' ) == 'purge';
677 $unhide = $wgRequest->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( $wgUser );
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() { #FIXME: deprecate, keep for BC
701 $dir = $this->getContext()->getLanguage()->getDir();
702 $lang = $this->getContext()->getLanguage()->getCode();
704 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
705 'clearyourcache' ); #FIXME: get this from handler
707 // Give hooks a chance to customise the output
708 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
709 #FIXME: use content object instead
710 // Wrap the whole lot in a <pre> and don't parse
712 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
713 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
714 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
715 $wgOut->addHTML( "\n</pre>\n" );
720 * Get the robot policy to be used for the current view
721 * @param $action String the action= GET parameter
722 * @param $pOutput ParserOutput
723 * @return Array the policy that should be set
724 * TODO: actions other than 'view'
726 public function getRobotPolicy( $action, $pOutput ) {
727 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
728 global $wgDefaultRobotPolicy, $wgRequest;
730 $ns = $this->getTitle()->getNamespace();
732 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
733 # Don't index user and user talk pages for blocked users (bug 11443)
734 if ( !$this->getTitle()->isSubpage() ) {
735 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
737 'index' => 'noindex',
738 'follow' => 'nofollow'
744 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
745 # Non-articles (special pages etc), and old revisions
747 'index' => 'noindex',
748 'follow' => 'nofollow'
750 } elseif ( $wgOut->isPrintable() ) {
751 # Discourage indexing of printable versions, but encourage following
753 'index' => 'noindex',
756 } elseif ( $wgRequest->getInt( 'curid' ) ) {
757 # For ?curid=x urls, disallow indexing
759 'index' => 'noindex',
764 # Otherwise, construct the policy based on the various config variables.
765 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
767 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
768 # Honour customised robot policies for this namespace
769 $policy = array_merge(
771 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
774 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
775 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
776 # a final sanity check that we have really got the parser output.
777 $policy = array_merge(
779 array( 'index' => $pOutput->getIndexPolicy() )
783 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
784 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
785 $policy = array_merge(
787 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
795 * Converts a String robot policy into an associative array, to allow
796 * merging of several policies using array_merge().
797 * @param $policy Mixed, returns empty array on null/false/'', transparent
798 * to already-converted arrays, converts String.
799 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
801 public static function formatRobotPolicy( $policy ) {
802 if ( is_array( $policy ) ) {
804 } elseif ( !$policy ) {
808 $policy = explode( ',', $policy );
809 $policy = array_map( 'trim', $policy );
812 foreach ( $policy as $var ) {
813 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
814 $arr['index'] = $var;
815 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
816 $arr['follow'] = $var;
824 * If this request is a redirect view, send "redirected from" subtitle to
825 * $wgOut. Returns true if the header was needed, false if this is not a
826 * redirect view. Handles both local and remote redirects.
830 public function showRedirectedFromHeader() {
831 global $wgOut, $wgRequest, $wgRedirectSources;
833 $rdfrom = $wgRequest->getVal( 'rdfrom' );
835 if ( isset( $this->mRedirectedFrom
) ) {
836 // This is an internally redirected page view.
837 // We'll need a backlink to the source page for navigation.
838 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
839 $redir = Linker
::linkKnown(
840 $this->mRedirectedFrom
,
843 array( 'redirect' => 'no' )
846 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
848 // Set the fragment if one was specified in the redirect
849 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
850 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
851 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
854 // Add a <link rel="canonical"> tag
855 $wgOut->addLink( array( 'rel' => 'canonical',
856 'href' => $this->getTitle()->getLocalURL() )
859 // Tell $wgOut the user arrived at this article through a redirect
860 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
864 } elseif ( $rdfrom ) {
865 // This is an externally redirected view, from some other wiki.
866 // If it was reported from a trusted site, supply a backlink.
867 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
868 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
869 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
879 * Show a header specific to the namespace currently being viewed, like
880 * [[MediaWiki:Talkpagetext]]. For Article::view().
882 public function showNamespaceHeader() {
885 if ( $this->getTitle()->isTalkPage() ) {
886 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
887 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
893 * Show the footer section of an ordinary page view
895 public function showViewFooter() {
898 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
899 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
900 $wgOut->addWikiMsg( 'anontalkpagetext' );
903 # If we have been passed an &rcid= parameter, we want to give the user a
904 # chance to mark this new article as patrolled.
905 $this->showPatrolFooter();
907 wfRunHooks( 'ArticleViewFooter', array( $this ) );
912 * If patrol is possible, output a patrol UI box. This is called from the
913 * footer section of ordinary page views. If patrol is not possible or not
914 * desired, does nothing.
916 public function showPatrolFooter() {
917 global $wgOut, $wgRequest, $wgUser;
919 $rcid = $wgRequest->getVal( 'rcid' );
921 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
925 $token = $wgUser->getEditToken( $rcid );
926 $wgOut->preventClickjacking();
929 "<div class='patrollink'>" .
931 'markaspatrolledlink',
934 wfMsgHtml( 'markaspatrolledtext' ),
937 'action' => 'markpatrolled',
941 array( 'known', 'noclasses' )
949 * Show the error text for a missing article. For articles in the MediaWiki
950 * namespace, show the default message text. To be called from Article::view().
952 public function showMissingArticle() {
953 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
955 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
956 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
957 $parts = explode( '/', $this->getTitle()->getText() );
958 $rootPart = $parts[0];
959 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
960 $ip = User
::isIP( $rootPart );
962 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
963 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
964 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
965 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
966 LogEventsList
::showLogExtract(
969 $user->getUserPage()->getPrefixedText(),
973 'showIfEmpty' => false,
975 'blocked-notice-logextract',
976 $user->getName() # Support GENDER in notice
983 wfRunHooks( 'ShowMissingArticle', array( $this ) );
985 # Show delete and move logs
986 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
988 'conds' => array( "log_action != 'revision'" ),
989 'showIfEmpty' => false,
990 'msgKey' => array( 'moveddeleted-notice' ) )
994 $oldid = $this->getOldID();
996 $text = wfMsgNoTrans( 'missing-article',
997 $this->getTitle()->getPrefixedText(),
998 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
999 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1000 // Use the default message text
1001 $text = $this->getTitle()->getDefaultMessageText();
1003 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
1004 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
1005 $errors = array_merge( $createErrors, $editErrors );
1007 if ( !count( $errors ) ) {
1008 $text = wfMsgNoTrans( 'noarticletext' );
1010 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1013 $text = "<div class='noarticletext'>\n$text\n</div>";
1015 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1016 // If there's no backing content, send a 404 Not Found
1017 // for better machine handling of broken links.
1018 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1021 $wgOut->addWikiText( $text );
1025 * If the revision requested for view is deleted, check permissions.
1026 * Send either an error message or a warning header to $wgOut.
1028 * @return boolean true if the view is allowed, false if not.
1030 public function showDeletedRevisionHeader() {
1031 global $wgOut, $wgRequest;
1033 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1038 // If the user is not allowed to see it...
1039 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1040 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1041 'rev-deleted-text-permission' );
1044 // If the user needs to confirm that they want to see it...
1045 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1046 # Give explanation and add a link to view the revision...
1047 $oldid = intval( $this->getOldID() );
1048 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1049 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1050 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1051 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1052 array( $msg, $link ) );
1055 // We are allowed to see...
1057 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1058 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1059 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1066 * Generate the navigation links when browsing through an article revisions
1067 * It shows the information as:
1068 * Revision as of \<date\>; view current revision
1069 * \<- Previous version | Next Version -\>
1071 * @param $oldid String: revision ID of this article revision
1073 public function setOldSubtitle( $oldid = 0 ) {
1074 global $wgLang, $wgOut, $wgUser, $wgRequest;
1076 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1080 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1082 # Cascade unhide param in links for easy deletion browsing
1083 $extraParams = array();
1084 if ( $wgRequest->getVal( 'unhide' ) ) {
1085 $extraParams['unhide'] = 1;
1088 $revision = Revision
::newFromId( $oldid );
1089 $timestamp = $revision->getTimestamp();
1091 $current = ( $oldid == $this->mPage
->getLatest() );
1092 $td = $wgLang->timeanddate( $timestamp, true );
1093 $tddate = $wgLang->date( $timestamp, true );
1094 $tdtime = $wgLang->time( $timestamp, true );
1096 # Show user links if allowed to see them. If hidden, then show them only if requested...
1097 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1099 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1100 ?
'revision-info-current'
1103 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1104 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1105 $tdtime, $revision->getUser() )->parse() . "</div>" );
1108 ?
wfMsgHtml( 'currentrevisionlink' )
1111 wfMsgHtml( 'currentrevisionlink' ),
1114 array( 'known', 'noclasses' )
1117 ?
wfMsgHtml( 'diff' )
1120 wfMsgHtml( 'diff' ),
1126 array( 'known', 'noclasses' )
1128 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1132 wfMsgHtml( 'previousrevision' ),
1135 'direction' => 'prev',
1138 array( 'known', 'noclasses' )
1140 : wfMsgHtml( 'previousrevision' );
1144 wfMsgHtml( 'diff' ),
1150 array( 'known', 'noclasses' )
1152 : wfMsgHtml( 'diff' );
1153 $nextlink = $current
1154 ?
wfMsgHtml( 'nextrevision' )
1157 wfMsgHtml( 'nextrevision' ),
1160 'direction' => 'next',
1163 array( 'known', 'noclasses' )
1165 $nextdiff = $current
1166 ?
wfMsgHtml( 'diff' )
1169 wfMsgHtml( 'diff' ),
1175 array( 'known', 'noclasses' )
1178 $cdel = Linker
::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1179 if ( $cdel !== '' ) {
1183 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1184 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1185 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1191 * @param $target Title|Array of destination(s) to redirect
1192 * @param $appendSubtitle Boolean [optional]
1193 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1194 * @return string containing HMTL with redirect link
1196 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1197 global $wgOut, $wgStylePath;
1199 if ( !is_array( $target ) ) {
1200 $target = array( $target );
1203 $lang = $this->getTitle()->getPageLanguage();
1204 $imageDir = $lang->getDir();
1206 if ( $appendSubtitle ) {
1207 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1210 // the loop prepends the arrow image before the link, so the first case needs to be outside
1215 $title = array_shift( $target );
1217 if ( $forceKnown ) {
1218 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1220 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1223 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1224 $alt = $lang->isRTL() ?
'←' : '→';
1225 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1226 foreach ( $target as $rt ) {
1227 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1228 if ( $forceKnown ) {
1229 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1231 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1235 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1236 return '<div class="redirectMsg">' .
1237 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1238 '<span class="redirectText">' . $link . '</span></div>';
1242 * Handle action=render
1244 public function render() {
1247 $wgOut->setArticleBodyOnly( true );
1252 * action=protect handler
1254 public function protect() {
1255 $form = new ProtectionForm( $this );
1260 * action=unprotect handler (alias)
1262 public function unprotect() {
1267 * UI entry point for page deletion
1269 public function delete() {
1270 global $wgOut, $wgRequest, $wgLang;
1272 # This code desperately needs to be totally rewritten
1274 $title = $this->getTitle();
1275 $user = $this->getContext()->getUser();
1278 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1279 if ( count( $permission_errors ) ) {
1280 throw new PermissionsError( 'delete', $permission_errors );
1283 # Read-only check...
1284 if ( wfReadOnly() ) {
1285 throw new ReadOnlyError
;
1288 # Better double-check that it hasn't been deleted yet!
1289 $dbw = wfGetDB( DB_MASTER
);
1290 $conds = $title->pageCond();
1291 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1292 if ( $latest === false ) {
1293 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1294 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1295 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1297 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1298 LogEventsList
::showLogExtract(
1301 $title->getPrefixedText()
1307 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1308 $deleteReason = $wgRequest->getText( 'wpReason' );
1310 if ( $deleteReasonList == 'other' ) {
1311 $reason = $deleteReason;
1312 } elseif ( $deleteReason != '' ) {
1313 // Entry from drop down menu + additional comment
1314 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1316 $reason = $deleteReasonList;
1319 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1320 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1322 # Flag to hide all contents of the archived revisions
1323 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1325 $this->doDelete( $reason, $suppress );
1327 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1329 } elseif ( $title->userIsWatching() ) {
1336 // Generate deletion reason
1337 $hasHistory = false;
1339 $reason = $this->generateReason( $hasHistory );
1342 // If the page has a history, insert a warning
1343 if ( $hasHistory ) {
1344 $revisions = $this->mTitle
->estimateRevisionCount();
1345 // @todo FIXME: i18n issue/patchwork message
1346 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1347 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1348 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1349 wfMsgHtml( 'history' ),
1350 array( 'rel' => 'archives' ),
1351 array( 'action' => 'history' ) ) .
1355 if ( $this->mTitle
->isBigDeletion() ) {
1356 global $wgDeleteRevisionsLimit;
1357 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1358 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1362 return $this->confirmDelete( $reason );
1366 * Output deletion confirmation dialog
1367 * @todo FIXME: Move to another file?
1368 * @param $reason String: prefilled reason
1370 public function confirmDelete( $reason ) {
1373 wfDebug( "Article::confirmDelete\n" );
1375 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1376 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1377 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1378 $wgOut->addWikiMsg( 'confirmdeletetext' );
1380 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1382 $user = $this->getContext()->getUser();
1384 if ( $user->isAllowed( 'suppressrevision' ) ) {
1385 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1387 <td class='mw-input'><strong>" .
1388 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1389 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1395 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1397 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1398 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1399 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1400 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1401 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1402 "<tr id=\"wpDeleteReasonListRow\">
1403 <td class='mw-label'>" .
1404 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1406 <td class='mw-input'>" .
1407 Xml
::listDropDown( 'wpDeleteReasonList',
1408 wfMsgForContent( 'deletereason-dropdown' ),
1409 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1412 <tr id=\"wpDeleteReasonRow\">
1413 <td class='mw-label'>" .
1414 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1416 <td class='mw-input'>" .
1417 Html
::input( 'wpReason', $reason, 'text', array(
1419 'maxlength' => '255',
1427 # Disallow watching if user is not logged in
1428 if ( $user->isLoggedIn() ) {
1432 <td class='mw-input'>" .
1433 Xml
::checkLabel( wfMsg( 'watchthis' ),
1434 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1443 <td class='mw-submit'>" .
1444 Xml
::submitButton( wfMsg( 'deletepage' ),
1445 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1448 Xml
::closeElement( 'table' ) .
1449 Xml
::closeElement( 'fieldset' ) .
1450 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1451 Xml
::closeElement( 'form' );
1453 if ( $user->isAllowed( 'editinterface' ) ) {
1454 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1455 $link = Linker
::link(
1457 wfMsgHtml( 'delete-edit-reasonlist' ),
1459 array( 'action' => 'edit' )
1461 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1464 $wgOut->addHTML( $form );
1465 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1466 LogEventsList
::showLogExtract( $wgOut, 'delete',
1467 $this->getTitle()->getPrefixedText()
1472 * Perform a deletion and output success or failure messages
1474 * @param $suppress bool
1476 public function doDelete( $reason, $suppress = false ) {
1480 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1481 $deleted = $this->getTitle()->getPrefixedText();
1483 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1484 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1486 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1488 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1489 $wgOut->returnToMain( false );
1491 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1492 if ( $error == '' ) {
1493 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1494 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1496 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1498 LogEventsList
::showLogExtract(
1501 $this->getTitle()->getPrefixedText()
1504 $wgOut->addHTML( $error );
1509 /* Caching functions */
1512 * checkLastModified returns true if it has taken care of all
1513 * output to the client that is necessary for this request.
1514 * (that is, it has sent a cached version of the page)
1516 * @return boolean true if cached version send, false otherwise
1518 protected function tryFileCache() {
1519 static $called = false;
1522 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1527 if ( $this->isFileCacheable() ) {
1528 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1529 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1530 wfDebug( "Article::tryFileCache(): about to load file\n" );
1531 $cache->loadFromFileCache( $this->getContext() );
1534 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1535 ob_start( array( &$cache, 'saveToFileCache' ) );
1538 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1545 * Check if the page can be cached
1548 public function isFileCacheable() {
1551 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1552 $cacheable = $this->mPage
->getID()
1553 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1554 // Extension may have reason to disable file caching on some pages.
1556 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1566 * Lightweight method to get the parser output for a page, checking the parser cache
1567 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1568 * consider, so it's not appropriate to use there.
1570 * @since 1.16 (r52326) for LiquidThreads
1572 * @param $oldid mixed integer Revision ID or null
1573 * @param $user User The relevant user
1574 * @return ParserOutput or false if the given revsion ID is not found
1576 public function getParserOutput( $oldid = null, User
$user = null ) {
1579 $user = is_null( $user ) ?
$wgUser : $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|false
1589 public function getParserOptions() {
1591 if ( !$this->mParserOptions
) {
1592 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1594 // Clone to allow modifications of the return value without affecting cache
1595 return clone $this->mParserOptions
;
1599 * Sets the context this Article is executed in
1601 * @param $context IContextSource
1604 public function setContext( $context ) {
1605 $this->mContext
= $context;
1609 * Gets the context this Article is executed in
1611 * @return IContextSource
1614 public function getContext() {
1615 if ( $this->mContext
instanceof IContextSource
) {
1616 return $this->mContext
;
1618 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1619 return RequestContext
::getMain();
1624 * Info about this page
1625 * @deprecated since 1.19
1627 public function info() {
1628 wfDeprecated( __METHOD__
, '1.19' );
1629 Action
::factory( 'info', $this )->show();
1633 * Mark this particular edit/page as patrolled
1634 * @deprecated since 1.18
1636 public function markpatrolled() {
1637 wfDeprecated( __METHOD__
, '1.18' );
1638 Action
::factory( 'markpatrolled', $this )->show();
1642 * Handle action=purge
1643 * @deprecated since 1.19
1645 public function purge() {
1646 return Action
::factory( 'purge', $this )->show();
1650 * Handle action=revert
1651 * @deprecated since 1.19
1653 public function revert() {
1654 wfDeprecated( __METHOD__
, '1.19' );
1655 Action
::factory( 'revert', $this )->show();
1659 * Handle action=rollback
1660 * @deprecated since 1.19
1662 public function rollback() {
1663 wfDeprecated( __METHOD__
, '1.19' );
1664 Action
::factory( 'rollback', $this )->show();
1668 * User-interface handler for the "watch" action.
1669 * Requires Request to pass a token as of 1.18.
1670 * @deprecated since 1.18
1672 public function watch() {
1673 wfDeprecated( __METHOD__
, '1.18' );
1674 Action
::factory( 'watch', $this )->show();
1678 * Add this page to $wgUser's watchlist
1680 * This is safe to be called multiple times
1682 * @return bool true on successful watch operation
1683 * @deprecated since 1.18
1685 public function doWatch() {
1687 wfDeprecated( __METHOD__
, '1.18' );
1688 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1692 * User interface handler for the "unwatch" action.
1693 * Requires Request to pass a token as of 1.18.
1694 * @deprecated since 1.18
1696 public function unwatch() {
1697 wfDeprecated( __METHOD__
, '1.18' );
1698 Action
::factory( 'unwatch', $this )->show();
1702 * Stop watching a page
1703 * @return bool true on successful unwatch
1704 * @deprecated since 1.18
1706 public function doUnwatch() {
1708 wfDeprecated( __METHOD__
, '1.18' );
1709 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1713 * Output a redirect back to the article.
1714 * This is typically used after an edit.
1716 * @deprecated in 1.18; call $wgOut->redirect() directly
1717 * @param $noRedir Boolean: add redirect=no
1718 * @param $sectionAnchor String: section to redirect to, including "#"
1719 * @param $extraQuery String: extra query params
1721 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1722 wfDeprecated( __METHOD__
, '1.18' );
1726 $query = 'redirect=no';
1728 $query .= "&$extraQuery";
1730 $query = $extraQuery;
1733 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1737 * Use PHP's magic __get handler to handle accessing of
1738 * raw WikiPage fields for backwards compatibility.
1740 * @param $fname String Field name
1742 public function __get( $fname ) {
1743 if ( property_exists( $this->mPage
, $fname ) ) {
1744 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1745 return $this->mPage
->$fname;
1747 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1751 * Use PHP's magic __set handler to handle setting of
1752 * raw WikiPage fields for backwards compatibility.
1754 * @param $fname String Field name
1755 * @param $fvalue mixed New value
1757 public function __set( $fname, $fvalue ) {
1758 if ( property_exists( $this->mPage
, $fname ) ) {
1759 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1760 $this->mPage
->$fname = $fvalue;
1761 // Note: extensions may want to toss on new fields
1762 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1763 $this->mPage
->$fname = $fvalue;
1765 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1770 * Use PHP's magic __call handler to transform instance calls to
1771 * WikiPage functions for backwards compatibility.
1773 * @param $fname String Name of called method
1774 * @param $args Array Arguments to the method
1776 public function __call( $fname, $args ) {
1777 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1778 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1779 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1781 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1784 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1787 * @param $limit array
1788 * @param $expiry array
1789 * @param $cascade bool
1790 * @param $reason string
1794 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1795 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1799 * @param $limit array
1800 * @param $reason string
1801 * @param $cascade int
1802 * @param $expiry array
1805 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1806 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1810 * @param $reason string
1811 * @param $suppress bool
1813 * @param $commit bool
1814 * @param $error string
1817 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1818 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1826 * @param $resultDetails
1830 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1832 $user = is_null( $user ) ?
$wgUser : $user;
1833 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1840 * @param $resultDetails
1841 * @param $guser User
1844 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1846 $guser = is_null( $guser ) ?
$wgUser : $guser;
1847 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1851 * @param $hasHistory bool
1854 public function generateReason( &$hasHistory ) {
1855 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1858 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1863 public static function selectFields() {
1864 return WikiPage
::selectFields();
1868 * @param $title Title
1870 public static function onArticleCreate( $title ) {
1871 WikiPage
::onArticleCreate( $title );
1875 * @param $title Title
1877 public static function onArticleDelete( $title ) {
1878 WikiPage
::onArticleDelete( $title );
1882 * @param $title Title
1884 public static function onArticleEdit( $title ) {
1885 WikiPage
::onArticleEdit( $title );
1894 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1895 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );