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; // !< #BC cruft
41 var $mContentObject; // !<
42 var $mContentLoaded = false; // !<
48 var $mRedirectedFrom = null;
51 * @var mixed: boolean false or URL string
53 var $mRedirectUrl = false; // !<
54 var $mRevIdFetched = 0; // !<
59 var $mRevision = null;
69 * Constructor and clear the article
70 * @param $title Title Reference to a Title object.
71 * @param $oldId Integer revision ID, null to fetch from request, zero for current
73 public function __construct( Title
$title, $oldId = null ) {
74 $this->mOldId
= $oldId;
75 $this->mPage
= $this->newPage( $title );
82 protected function newPage( Title
$title ) {
83 return new WikiPage( $title );
87 * Constructor from a page id
88 * @param $id Int article ID to load
89 * @return Article|null
91 public static function newFromID( $id ) {
92 $t = Title
::newFromID( $id );
93 # @todo FIXME: Doesn't inherit right
94 return $t == null ?
null : new self( $t );
95 # return $t == null ? null : new static( $t ); // PHP 5.3
99 * Create an Article object of the appropriate class for the given page.
101 * @param $title Title
102 * @param $context IContextSource
103 * @return Article object
105 public static function newFromTitle( $title, IContextSource
$context ) {
106 if ( NS_MEDIA
== $title->getNamespace() ) {
107 // FIXME: where should this go?
108 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
112 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
114 switch( $title->getNamespace() ) {
116 $page = new ImagePage( $title );
119 $page = new CategoryPage( $title );
122 $page = new Article( $title );
125 $page->setContext( $context );
131 * Create an Article object of the appropriate class for the given page.
133 * @param $page WikiPage
134 * @param $context IContextSource
135 * @return Article object
137 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
138 $article = self
::newFromTitle( $page->getTitle(), $context );
139 $article->mPage
= $page; // override to keep process cached vars
144 * Tell the page view functions that this view was redirected
145 * from another page on the wiki.
146 * @param $from Title object.
148 public function setRedirectedFrom( Title
$from ) {
149 $this->mRedirectedFrom
= $from;
153 * Get the title object of the article
155 * @return Title object of this page
157 public function getTitle() {
158 return $this->mPage
->getTitle();
162 * Get the WikiPage object of this instance
167 public function getPage() {
174 public function clear() {
175 $this->mContentLoaded
= false;
177 $this->mRedirectedFrom
= null; # Title object if set
178 $this->mRevIdFetched
= 0;
179 $this->mRedirectUrl
= false;
181 $this->mPage
->clear();
185 * Note that getContent/loadContent do not follow redirects anymore.
186 * If you need to fetch redirectable content easily, try
187 * the shortcut in WikiPage::getRedirectTarget()
189 * This function has side effects! Do not use this function if you
190 * only want the real revision text if any.
192 * @return Return the text of this revision
193 * @deprecated in 1.20; use getContentObject() instead
195 public function getContent() {
196 wfDeprecated( __METHOD__
, '1.20' );
197 $content = $this->getContentObject();
198 return ContentHandler
::getContentText( $content );
202 * Note that getContent/loadContent do not follow redirects anymore.
203 * If you need to fetch redirectable content easily, try
204 * the shortcut in WikiPage::getRedirectTarget()
206 * This function has side effects! Do not use this function if you
207 * only want the real revision text if any.
209 * @return Return the content of this revision
211 public function getContentObject() {
214 wfProfileIn( __METHOD__
);
216 if ( $this->mPage
->getID() === 0 ) {
217 # If this is a MediaWiki:x message, then load the messages
218 # and return the message value for x.
219 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
220 $text = $this->getTitle()->getDefaultMessageText();
221 if ( $text === false ) {
225 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
227 wfProfileOut( __METHOD__
);
229 return ContentHandler
::makeContent( $text, $this->getTitle() );
231 $this->fetchContentObject();
232 wfProfileOut( __METHOD__
);
234 return $this->mContentObject
;
239 * @return int The oldid of the article that is to be shown, 0 for the
242 public function getOldID() {
243 if ( is_null( $this->mOldId
) ) {
244 $this->mOldId
= $this->getOldIDFromRequest();
247 return $this->mOldId
;
251 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
253 * @return int The old id for the request
255 public function getOldIDFromRequest() {
258 $this->mRedirectUrl
= false;
260 $oldid = $wgRequest->getIntOrNull( 'oldid' );
262 if ( $oldid === null ) {
266 if ( $oldid !== 0 ) {
267 # Load the given revision and check whether the page is another one.
268 # In that case, update this instance to reflect the change.
269 $this->mRevision
= Revision
::newFromId( $oldid );
270 if ( $this->mRevision
!== null ) {
271 // Revision title doesn't match the page title given?
272 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
273 $function = array( get_class( $this->mPage
), 'newFromID' );
274 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
279 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
280 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
283 $this->mRevision
= null;
285 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
287 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
288 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
291 $this->mRevision
= null;
299 * Load the revision (including text) into this object
301 * @deprecated in 1.19; use fetchContent()
303 function loadContent() {
304 wfDeprecated( __METHOD__
, '1.19' );
305 $this->fetchContent();
309 * Get text of an article from database
310 * Does *NOT* follow redirects.
312 * @return mixed string containing article contents, or false if null
313 * @deprecated in 1.20, use getContentObject() instead
315 protected function fetchContent() { #BC cruft!
316 wfDeprecated( __METHOD__
, '1.20' );
318 if ( $this->mContentLoaded
&& $this->mContent
) {
319 return $this->mContent
;
322 wfProfileIn( __METHOD__
);
324 $content = $this->fetchContentObject();
326 $this->mContent
= ContentHandler
::getContentText( $content );
327 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft!
329 wfProfileOut( __METHOD__
);
331 return $this->mContent
;
336 * Get text content object
337 * Does *NOT* follow redirects.
339 * @return Content object containing article contents, or null
341 protected function fetchContentObject() {
342 if ( $this->mContentLoaded
) {
343 return $this->mContentObject
;
346 wfProfileIn( __METHOD__
);
348 $this->mContentLoaded
= true;
349 $this->mContent
= null;
351 $oldid = $this->getOldID();
353 # Pre-fill content with error message so that if something
354 # fails we'll have something telling us what we intended.
355 $t = $this->getTitle()->getPrefixedText();
356 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
357 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ;
360 # $this->mRevision might already be fetched by getOldIDFromRequest()
361 if ( !$this->mRevision
) {
362 $this->mRevision
= Revision
::newFromId( $oldid );
363 if ( !$this->mRevision
) {
364 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
365 wfProfileOut( __METHOD__
);
370 if ( !$this->mPage
->getLatest() ) {
371 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
372 wfProfileOut( __METHOD__
);
376 $this->mRevision
= $this->mPage
->getRevision();
377 if ( !$this->mRevision
) {
378 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
379 wfProfileOut( __METHOD__
);
384 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
385 // We should instead work with the Revision object when we need it...
386 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
387 $this->mRevIdFetched
= $this->mRevision
->getId();
389 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) ); #FIXME: register new hook
391 wfProfileOut( __METHOD__
);
393 return $this->mContentObject
;
398 * @deprecated since 1.18
400 public function forUpdate() {
401 wfDeprecated( __METHOD__
, '1.18' );
405 * Returns true if the currently-referenced revision is the current edit
406 * to this page (and it exists).
409 public function isCurrent() {
410 # If no oldid, this is the current version.
411 if ( $this->getOldID() == 0 ) {
415 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
419 * Get the fetched Revision object depending on request parameters or null
423 * @return Revision|null
425 public function getRevisionFetched() {
426 $this->fetchContentObject();
428 return $this->mRevision
;
432 * Use this to fetch the rev ID used on page views
434 * @return int revision ID of last article revision
436 public function getRevIdFetched() {
437 if ( $this->mRevIdFetched
) {
438 return $this->mRevIdFetched
;
440 return $this->mPage
->getLatest();
445 * This is the default action of the index.php entry point: just view the
446 * page of the given title.
448 public function view() {
449 global $wgUser, $wgOut, $wgRequest, $wgParser;
450 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
452 wfProfileIn( __METHOD__
);
454 # Get variables from query string
455 # As side effect this will load the revision and update the title
456 # in a revision ID is passed in the request, so this should remain
457 # the first call of this method even if $oldid is used way below.
458 $oldid = $this->getOldID();
460 # Another whitelist check in case getOldID() is altering the title
461 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
462 if ( count( $permErrors ) ) {
463 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
464 wfProfileOut( __METHOD__
);
465 throw new PermissionsError( 'read', $permErrors );
468 # getOldID() may as well want us to redirect somewhere else
469 if ( $this->mRedirectUrl
) {
470 $wgOut->redirect( $this->mRedirectUrl
);
471 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
472 wfProfileOut( __METHOD__
);
477 # If we got diff in the query, we want to see a diff page instead of the article.
478 if ( $wgRequest->getCheck( 'diff' ) ) {
479 wfDebug( __METHOD__
. ": showing diff page\n" );
480 $this->showDiffPage();
481 wfProfileOut( __METHOD__
);
486 # Set page title (may be overridden by DISPLAYTITLE)
487 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
489 $wgOut->setArticleFlag( true );
490 # Allow frames by default
491 $wgOut->allowClickjacking();
493 $parserCache = ParserCache
::singleton();
495 $parserOptions = $this->getParserOptions();
496 # Render printable version, use printable version cache
497 if ( $wgOut->isPrintable() ) {
498 $parserOptions->setIsPrintable( true );
499 $parserOptions->setEditSection( false );
500 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
501 $parserOptions->setEditSection( false );
504 # Try client and file cache
505 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
507 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
510 # Is it client cached?
511 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
512 wfDebug( __METHOD__
. ": done 304\n" );
513 wfProfileOut( __METHOD__
);
517 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
518 wfDebug( __METHOD__
. ": done file cache\n" );
519 # tell wgOut that output is taken care of
521 $this->mPage
->doViewUpdates( $wgUser );
522 wfProfileOut( __METHOD__
);
528 # Should the parser cache be used?
529 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
530 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
531 if ( $wgUser->getStubThreshold() ) {
532 wfIncrStats( 'pcache_miss_stub' );
535 $this->showRedirectedFromHeader();
536 $this->showNamespaceHeader();
538 # Iterate through the possible ways of constructing the output text.
539 # Keep going until $outputDone is set, or we run out of things to do.
542 $this->mParserOutput
= false;
544 while ( !$outputDone && ++
$pass ) {
547 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
550 # Early abort if the page doesn't exist
551 if ( !$this->mPage
->exists() ) {
552 wfDebug( __METHOD__
. ": showing missing article\n" );
553 $this->showMissingArticle();
554 wfProfileOut( __METHOD__
);
558 # Try the parser cache
559 if ( $useParserCache ) {
560 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
562 if ( $this->mParserOutput
!== false ) {
564 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
565 $this->setOldSubtitle( $oldid );
567 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
569 $wgOut->addParserOutput( $this->mParserOutput
);
570 # Ensure that UI elements requiring revision ID have
571 # the correct version information.
572 $wgOut->setRevisionId( $this->mPage
->getLatest() );
573 # Preload timestamp to avoid a DB hit
574 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
575 if ( $cachedTimestamp !== null ) {
576 $wgOut->setRevisionTimestamp( $cachedTimestamp );
577 $this->mPage
->setTimestamp( $cachedTimestamp );
584 # This will set $this->mRevision if needed
585 $this->fetchContentObject();
587 # Are we looking at an old revision
588 if ( $oldid && $this->mRevision
) {
589 $this->setOldSubtitle( $oldid );
591 if ( !$this->showDeletedRevisionHeader() ) {
592 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
593 wfProfileOut( __METHOD__
);
598 # Ensure that UI elements requiring revision ID have
599 # the correct version information.
600 $wgOut->setRevisionId( $this->getRevIdFetched() );
601 # Preload timestamp to avoid a DB hit
602 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
604 # Pages containing custom CSS or JavaScript get special treatment
605 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
606 #FIXME: use ContentHandler for specialized actions insetad.
607 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
608 $this->showCssOrJsPage();
610 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
611 # Allow extensions do their own custom view for certain pages
614 $content = $this->getContentObject();
615 $rt = $content->getRedirectChain();
617 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
618 # Viewing a redirect page (e.g. with parameter redirect=no)
619 $wgOut->addHTML( $this->viewRedirect( $rt ) );
620 # Parse just to get categories, displaytitle, etc.
621 $this->mParserOutput
= $content->getParserOutput( $parserOptions );
622 $wgOut->addParserOutputNoText( $this->mParserOutput
);
628 # Run the parse, protected by a pool counter
629 wfDebug( __METHOD__
. ": doing uncached parse\n" );
631 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
632 $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
634 if ( !$poolArticleView->execute() ) {
635 $error = $poolArticleView->getError();
637 $wgOut->clearHTML(); // for release() errors
638 $wgOut->enableClientCache( false );
639 $wgOut->setRobotPolicy( 'noindex,nofollow' );
641 $errortext = $error->getWikiText( false, 'view-pool-error' );
642 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
644 # Connection or timeout error
645 wfProfileOut( __METHOD__
);
649 $this->mParserOutput
= $poolArticleView->getParserOutput();
650 $wgOut->addParserOutput( $this->mParserOutput
);
652 # Don't cache a dirty ParserOutput object
653 if ( $poolArticleView->getIsDirty() ) {
654 $wgOut->setSquidMaxage( 0 );
655 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
660 # Should be unreachable, but just in case...
666 # Get the ParserOutput actually *displayed* here.
667 # Note that $this->mParserOutput is the *current* version output.
668 $pOutput = ( $outputDone instanceof ParserOutput
)
669 ?
$outputDone // object fetched by hook
670 : $this->mParserOutput
;
672 # Adjust title for main page & pages with displaytitle
674 $this->adjustDisplayTitle( $pOutput );
677 # For the main page, overwrite the <title> element with the con-
678 # tents of 'pagetitle-view-mainpage' instead of the default (if
680 # This message always exists because it is in the i18n files
681 if ( $this->getTitle()->isMainPage() ) {
682 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
683 if ( !$msg->isDisabled() ) {
684 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
688 # Check for any __NOINDEX__ tags on the page using $pOutput
689 $policy = $this->getRobotPolicy( 'view', $pOutput );
690 $wgOut->setIndexPolicy( $policy['index'] );
691 $wgOut->setFollowPolicy( $policy['follow'] );
693 $this->showViewFooter();
694 $this->mPage
->doViewUpdates( $wgUser );
696 wfProfileOut( __METHOD__
);
700 * Adjust title for pages with displaytitle, -{T|}- or language conversion
701 * @param $pOutput ParserOutput
703 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
705 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
706 $titleText = $pOutput->getTitleText();
707 if ( strval( $titleText ) !== '' ) {
708 $wgOut->setPageTitle( $titleText );
713 * Show a diff page according to current request variables. For use within
714 * Article::view() only, other callers should use the DifferenceEngine class.
716 public function showDiffPage() {
717 global $wgRequest, $wgUser;
719 $diff = $wgRequest->getVal( 'diff' );
720 $rcid = $wgRequest->getVal( 'rcid' );
721 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
722 $purge = $wgRequest->getVal( 'action' ) == 'purge';
723 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
724 $oldid = $this->getOldID();
726 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
727 // DifferenceEngine directly fetched the revision:
728 $this->mRevIdFetched
= $de->mNewid
;
729 $de->showDiffPage( $diffOnly );
731 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
732 # Run view updates for current revision only
733 $this->mPage
->doViewUpdates( $wgUser );
738 * Show a page view for a page formatted as CSS or JavaScript. To be called by
739 * Article::view() only.
741 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
744 protected function showCssOrJsPage() { #FIXME: move this to handler!
747 $dir = $this->getContext()->getLanguage()->getDir();
748 $lang = $this->getContext()->getLanguage()->getCode();
750 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
751 'clearyourcache' ); #FIXME: do this in handler
753 // Give hooks a chance to customise the output
754 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
755 $wgOut->addHTML( $this->mContentObject
->getHTML() );
760 * Get the robot policy to be used for the current view
761 * @param $action String the action= GET parameter
762 * @param $pOutput ParserOutput
763 * @return Array the policy that should be set
764 * TODO: actions other than 'view'
766 public function getRobotPolicy( $action, $pOutput ) {
767 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
768 global $wgDefaultRobotPolicy, $wgRequest;
770 $ns = $this->getTitle()->getNamespace();
772 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
773 # Don't index user and user talk pages for blocked users (bug 11443)
774 if ( !$this->getTitle()->isSubpage() ) {
775 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
777 'index' => 'noindex',
778 'follow' => 'nofollow'
784 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
785 # Non-articles (special pages etc), and old revisions
787 'index' => 'noindex',
788 'follow' => 'nofollow'
790 } elseif ( $wgOut->isPrintable() ) {
791 # Discourage indexing of printable versions, but encourage following
793 'index' => 'noindex',
796 } elseif ( $wgRequest->getInt( 'curid' ) ) {
797 # For ?curid=x urls, disallow indexing
799 'index' => 'noindex',
804 # Otherwise, construct the policy based on the various config variables.
805 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
807 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
808 # Honour customised robot policies for this namespace
809 $policy = array_merge(
811 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
814 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
815 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
816 # a final sanity check that we have really got the parser output.
817 $policy = array_merge(
819 array( 'index' => $pOutput->getIndexPolicy() )
823 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
824 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
825 $policy = array_merge(
827 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
835 * Converts a String robot policy into an associative array, to allow
836 * merging of several policies using array_merge().
837 * @param $policy Mixed, returns empty array on null/false/'', transparent
838 * to already-converted arrays, converts String.
839 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
841 public static function formatRobotPolicy( $policy ) {
842 if ( is_array( $policy ) ) {
844 } elseif ( !$policy ) {
848 $policy = explode( ',', $policy );
849 $policy = array_map( 'trim', $policy );
852 foreach ( $policy as $var ) {
853 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
854 $arr['index'] = $var;
855 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
856 $arr['follow'] = $var;
864 * If this request is a redirect view, send "redirected from" subtitle to
865 * $wgOut. Returns true if the header was needed, false if this is not a
866 * redirect view. Handles both local and remote redirects.
870 public function showRedirectedFromHeader() {
871 global $wgOut, $wgRequest, $wgRedirectSources;
873 $rdfrom = $wgRequest->getVal( 'rdfrom' );
875 if ( isset( $this->mRedirectedFrom
) ) {
876 // This is an internally redirected page view.
877 // We'll need a backlink to the source page for navigation.
878 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
879 $redir = Linker
::linkKnown(
880 $this->mRedirectedFrom
,
883 array( 'redirect' => 'no' )
886 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
888 // Set the fragment if one was specified in the redirect
889 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
890 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
891 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
894 // Add a <link rel="canonical"> tag
895 $wgOut->addLink( array( 'rel' => 'canonical',
896 'href' => $this->getTitle()->getLocalURL() )
899 // Tell $wgOut the user arrived at this article through a redirect
900 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
904 } elseif ( $rdfrom ) {
905 // This is an externally redirected view, from some other wiki.
906 // If it was reported from a trusted site, supply a backlink.
907 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
908 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
909 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
919 * Show a header specific to the namespace currently being viewed, like
920 * [[MediaWiki:Talkpagetext]]. For Article::view().
922 public function showNamespaceHeader() {
925 if ( $this->getTitle()->isTalkPage() ) {
926 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
927 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
933 * Show the footer section of an ordinary page view
935 public function showViewFooter() {
938 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
939 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
940 $wgOut->addWikiMsg( 'anontalkpagetext' );
943 # If we have been passed an &rcid= parameter, we want to give the user a
944 # chance to mark this new article as patrolled.
945 $this->showPatrolFooter();
947 wfRunHooks( 'ArticleViewFooter', array( $this ) );
952 * If patrol is possible, output a patrol UI box. This is called from the
953 * footer section of ordinary page views. If patrol is not possible or not
954 * desired, does nothing.
956 public function showPatrolFooter() {
957 global $wgOut, $wgRequest, $wgUser;
959 $rcid = $wgRequest->getVal( 'rcid' );
961 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
965 $token = $wgUser->getEditToken( $rcid );
966 $wgOut->preventClickjacking();
969 "<div class='patrollink'>" .
971 'markaspatrolledlink',
974 wfMsgHtml( 'markaspatrolledtext' ),
977 'action' => 'markpatrolled',
981 array( 'known', 'noclasses' )
989 * Show the error text for a missing article. For articles in the MediaWiki
990 * namespace, show the default message text. To be called from Article::view().
992 public function showMissingArticle() {
993 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
995 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
996 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
997 $parts = explode( '/', $this->getTitle()->getText() );
998 $rootPart = $parts[0];
999 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1000 $ip = User
::isIP( $rootPart );
1002 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1003 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1004 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1005 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1006 LogEventsList
::showLogExtract(
1009 $user->getUserPage()->getPrefixedText(),
1013 'showIfEmpty' => false,
1015 'blocked-notice-logextract',
1016 $user->getName() # Support GENDER in notice
1023 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1025 # Show delete and move logs
1026 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1028 'conds' => array( "log_action != 'revision'" ),
1029 'showIfEmpty' => false,
1030 'msgKey' => array( 'moveddeleted-notice' ) )
1033 # Show error message
1034 $oldid = $this->getOldID();
1036 $text = wfMsgNoTrans( 'missing-article',
1037 $this->getTitle()->getPrefixedText(),
1038 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1039 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1040 // Use the default message text
1041 $text = $this->getTitle()->getDefaultMessageText();
1043 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
1044 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
1045 $errors = array_merge( $createErrors, $editErrors );
1047 if ( !count( $errors ) ) {
1048 $text = wfMsgNoTrans( 'noarticletext' );
1050 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1053 $text = "<div class='noarticletext'>\n$text\n</div>";
1055 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1056 // If there's no backing content, send a 404 Not Found
1057 // for better machine handling of broken links.
1058 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1061 $wgOut->addWikiText( $text );
1065 * If the revision requested for view is deleted, check permissions.
1066 * Send either an error message or a warning header to $wgOut.
1068 * @return boolean true if the view is allowed, false if not.
1070 public function showDeletedRevisionHeader() {
1071 global $wgOut, $wgRequest;
1073 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1078 // If the user is not allowed to see it...
1079 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1080 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1081 'rev-deleted-text-permission' );
1084 // If the user needs to confirm that they want to see it...
1085 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1086 # Give explanation and add a link to view the revision...
1087 $oldid = intval( $this->getOldID() );
1088 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1089 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1090 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1091 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1092 array( $msg, $link ) );
1095 // We are allowed to see...
1097 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1098 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1099 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1106 * Generate the navigation links when browsing through an article revisions
1107 * It shows the information as:
1108 * Revision as of \<date\>; view current revision
1109 * \<- Previous version | Next Version -\>
1111 * @param $oldid String: revision ID of this article revision
1113 public function setOldSubtitle( $oldid = 0 ) {
1114 global $wgLang, $wgOut, $wgUser, $wgRequest;
1116 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1120 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1122 # Cascade unhide param in links for easy deletion browsing
1123 $extraParams = array();
1124 if ( $wgRequest->getVal( 'unhide' ) ) {
1125 $extraParams['unhide'] = 1;
1128 $revision = Revision
::newFromId( $oldid );
1129 $timestamp = $revision->getTimestamp();
1131 $current = ( $oldid == $this->mPage
->getLatest() );
1132 $td = $wgLang->timeanddate( $timestamp, true );
1133 $tddate = $wgLang->date( $timestamp, true );
1134 $tdtime = $wgLang->time( $timestamp, true );
1136 # Show user links if allowed to see them. If hidden, then show them only if requested...
1137 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1139 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1140 ?
'revision-info-current'
1143 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1144 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1145 $tdtime, $revision->getUser() )->parse() . "</div>" );
1148 ?
wfMsgHtml( 'currentrevisionlink' )
1151 wfMsgHtml( 'currentrevisionlink' ),
1154 array( 'known', 'noclasses' )
1157 ?
wfMsgHtml( 'diff' )
1160 wfMsgHtml( 'diff' ),
1166 array( 'known', 'noclasses' )
1168 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1172 wfMsgHtml( 'previousrevision' ),
1175 'direction' => 'prev',
1178 array( 'known', 'noclasses' )
1180 : wfMsgHtml( 'previousrevision' );
1184 wfMsgHtml( 'diff' ),
1190 array( 'known', 'noclasses' )
1192 : wfMsgHtml( 'diff' );
1193 $nextlink = $current
1194 ?
wfMsgHtml( 'nextrevision' )
1197 wfMsgHtml( 'nextrevision' ),
1200 'direction' => 'next',
1203 array( 'known', 'noclasses' )
1205 $nextdiff = $current
1206 ?
wfMsgHtml( 'diff' )
1209 wfMsgHtml( 'diff' ),
1215 array( 'known', 'noclasses' )
1218 $cdel = Linker
::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1219 if ( $cdel !== '' ) {
1223 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1224 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1225 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1231 * @param $target Title|Array of destination(s) to redirect
1232 * @param $appendSubtitle Boolean [optional]
1233 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1234 * @return string containing HMTL with redirect link
1236 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1237 global $wgOut, $wgStylePath;
1239 if ( !is_array( $target ) ) {
1240 $target = array( $target );
1243 $lang = $this->getTitle()->getPageLanguage();
1244 $imageDir = $lang->getDir();
1246 if ( $appendSubtitle ) {
1247 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1250 // the loop prepends the arrow image before the link, so the first case needs to be outside
1255 $title = array_shift( $target );
1257 if ( $forceKnown ) {
1258 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1260 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1263 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1264 $alt = $lang->isRTL() ?
'←' : '→';
1265 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1266 foreach ( $target as $rt ) {
1267 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1268 if ( $forceKnown ) {
1269 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1271 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1275 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1276 return '<div class="redirectMsg">' .
1277 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1278 '<span class="redirectText">' . $link . '</span></div>';
1282 * Handle action=render
1284 public function render() {
1287 $wgOut->setArticleBodyOnly( true );
1292 * action=protect handler
1294 public function protect() {
1295 $form = new ProtectionForm( $this );
1300 * action=unprotect handler (alias)
1302 public function unprotect() {
1307 * UI entry point for page deletion
1309 public function delete() {
1310 global $wgOut, $wgRequest, $wgLang;
1312 # This code desperately needs to be totally rewritten
1314 $title = $this->getTitle();
1315 $user = $this->getContext()->getUser();
1318 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1319 if ( count( $permission_errors ) ) {
1320 throw new PermissionsError( 'delete', $permission_errors );
1323 # Read-only check...
1324 if ( wfReadOnly() ) {
1325 throw new ReadOnlyError
;
1328 # Better double-check that it hasn't been deleted yet!
1329 $dbw = wfGetDB( DB_MASTER
);
1330 $conds = $title->pageCond();
1331 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1332 if ( $latest === false ) {
1333 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1334 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1335 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1337 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1338 LogEventsList
::showLogExtract(
1341 $title->getPrefixedText()
1347 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1348 $deleteReason = $wgRequest->getText( 'wpReason' );
1350 if ( $deleteReasonList == 'other' ) {
1351 $reason = $deleteReason;
1352 } elseif ( $deleteReason != '' ) {
1353 // Entry from drop down menu + additional comment
1354 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1356 $reason = $deleteReasonList;
1359 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1360 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1362 # Flag to hide all contents of the archived revisions
1363 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1365 $this->doDelete( $reason, $suppress );
1367 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1369 } elseif ( $title->userIsWatching() ) {
1376 // Generate deletion reason
1377 $hasHistory = false;
1379 $reason = $this->generateReason( $hasHistory );
1382 // If the page has a history, insert a warning
1383 if ( $hasHistory ) {
1384 $revisions = $this->mTitle
->estimateRevisionCount();
1385 // @todo FIXME: i18n issue/patchwork message
1386 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1387 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1388 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1389 wfMsgHtml( 'history' ),
1390 array( 'rel' => 'archives' ),
1391 array( 'action' => 'history' ) ) .
1395 if ( $this->mTitle
->isBigDeletion() ) {
1396 global $wgDeleteRevisionsLimit;
1397 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1398 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1402 return $this->confirmDelete( $reason );
1406 * Output deletion confirmation dialog
1407 * @todo FIXME: Move to another file?
1408 * @param $reason String: prefilled reason
1410 public function confirmDelete( $reason ) {
1413 wfDebug( "Article::confirmDelete\n" );
1415 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1416 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1417 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1418 $wgOut->addWikiMsg( 'confirmdeletetext' );
1420 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1422 $user = $this->getContext()->getUser();
1424 if ( $user->isAllowed( 'suppressrevision' ) ) {
1425 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1427 <td class='mw-input'><strong>" .
1428 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1429 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1435 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1437 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1438 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1439 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1440 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1441 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1442 "<tr id=\"wpDeleteReasonListRow\">
1443 <td class='mw-label'>" .
1444 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1446 <td class='mw-input'>" .
1447 Xml
::listDropDown( 'wpDeleteReasonList',
1448 wfMsgForContent( 'deletereason-dropdown' ),
1449 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1452 <tr id=\"wpDeleteReasonRow\">
1453 <td class='mw-label'>" .
1454 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1456 <td class='mw-input'>" .
1457 Html
::input( 'wpReason', $reason, 'text', array(
1459 'maxlength' => '255',
1467 # Disallow watching if user is not logged in
1468 if ( $user->isLoggedIn() ) {
1472 <td class='mw-input'>" .
1473 Xml
::checkLabel( wfMsg( 'watchthis' ),
1474 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1483 <td class='mw-submit'>" .
1484 Xml
::submitButton( wfMsg( 'deletepage' ),
1485 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1488 Xml
::closeElement( 'table' ) .
1489 Xml
::closeElement( 'fieldset' ) .
1490 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1491 Xml
::closeElement( 'form' );
1493 if ( $user->isAllowed( 'editinterface' ) ) {
1494 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1495 $link = Linker
::link(
1497 wfMsgHtml( 'delete-edit-reasonlist' ),
1499 array( 'action' => 'edit' )
1501 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1504 $wgOut->addHTML( $form );
1505 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1506 LogEventsList
::showLogExtract( $wgOut, 'delete',
1507 $this->getTitle()->getPrefixedText()
1512 * Perform a deletion and output success or failure messages
1514 * @param $suppress bool
1516 public function doDelete( $reason, $suppress = false ) {
1520 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1521 $deleted = $this->getTitle()->getPrefixedText();
1523 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1524 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1526 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1528 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1529 $wgOut->returnToMain( false );
1531 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1532 if ( $error == '' ) {
1533 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1534 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1536 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1538 LogEventsList
::showLogExtract(
1541 $this->getTitle()->getPrefixedText()
1544 $wgOut->addHTML( $error );
1549 /* Caching functions */
1552 * checkLastModified returns true if it has taken care of all
1553 * output to the client that is necessary for this request.
1554 * (that is, it has sent a cached version of the page)
1556 * @return boolean true if cached version send, false otherwise
1558 protected function tryFileCache() {
1559 static $called = false;
1562 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1567 if ( $this->isFileCacheable() ) {
1568 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1569 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1570 wfDebug( "Article::tryFileCache(): about to load file\n" );
1571 $cache->loadFromFileCache( $this->getContext() );
1574 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1575 ob_start( array( &$cache, 'saveToFileCache' ) );
1578 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1585 * Check if the page can be cached
1588 public function isFileCacheable() {
1591 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1592 $cacheable = $this->mPage
->getID()
1593 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1594 // Extension may have reason to disable file caching on some pages.
1596 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1606 * Lightweight method to get the parser output for a page, checking the parser cache
1607 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1608 * consider, so it's not appropriate to use there.
1610 * @since 1.16 (r52326) for LiquidThreads
1612 * @param $oldid mixed integer Revision ID or null
1613 * @param $user User The relevant user
1614 * @return ParserOutput or false if the given revsion ID is not found
1616 public function getParserOutput( $oldid = null, User
$user = null ) {
1619 $user = is_null( $user ) ?
$wgUser : $user;
1620 $parserOptions = $this->mPage
->makeParserOptions( $user );
1622 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1626 * Get parser options suitable for rendering the primary article wikitext
1627 * @return ParserOptions|false
1629 public function getParserOptions() {
1631 if ( !$this->mParserOptions
) {
1632 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1634 // Clone to allow modifications of the return value without affecting cache
1635 return clone $this->mParserOptions
;
1639 * Sets the context this Article is executed in
1641 * @param $context IContextSource
1644 public function setContext( $context ) {
1645 $this->mContext
= $context;
1649 * Gets the context this Article is executed in
1651 * @return IContextSource
1654 public function getContext() {
1655 if ( $this->mContext
instanceof IContextSource
) {
1656 return $this->mContext
;
1658 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1659 return RequestContext
::getMain();
1664 * Info about this page
1665 * @deprecated since 1.19
1667 public function info() {
1668 wfDeprecated( __METHOD__
, '1.19' );
1669 Action
::factory( 'info', $this )->show();
1673 * Mark this particular edit/page as patrolled
1674 * @deprecated since 1.18
1676 public function markpatrolled() {
1677 wfDeprecated( __METHOD__
, '1.18' );
1678 Action
::factory( 'markpatrolled', $this )->show();
1682 * Handle action=purge
1683 * @deprecated since 1.19
1685 public function purge() {
1686 return Action
::factory( 'purge', $this )->show();
1690 * Handle action=revert
1691 * @deprecated since 1.19
1693 public function revert() {
1694 wfDeprecated( __METHOD__
, '1.19' );
1695 Action
::factory( 'revert', $this )->show();
1699 * Handle action=rollback
1700 * @deprecated since 1.19
1702 public function rollback() {
1703 wfDeprecated( __METHOD__
, '1.19' );
1704 Action
::factory( 'rollback', $this )->show();
1708 * User-interface handler for the "watch" action.
1709 * Requires Request to pass a token as of 1.18.
1710 * @deprecated since 1.18
1712 public function watch() {
1713 wfDeprecated( __METHOD__
, '1.18' );
1714 Action
::factory( 'watch', $this )->show();
1718 * Add this page to $wgUser's watchlist
1720 * This is safe to be called multiple times
1722 * @return bool true on successful watch operation
1723 * @deprecated since 1.18
1725 public function doWatch() {
1727 wfDeprecated( __METHOD__
, '1.18' );
1728 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1732 * User interface handler for the "unwatch" action.
1733 * Requires Request to pass a token as of 1.18.
1734 * @deprecated since 1.18
1736 public function unwatch() {
1737 wfDeprecated( __METHOD__
, '1.18' );
1738 Action
::factory( 'unwatch', $this )->show();
1742 * Stop watching a page
1743 * @return bool true on successful unwatch
1744 * @deprecated since 1.18
1746 public function doUnwatch() {
1748 wfDeprecated( __METHOD__
, '1.18' );
1749 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1753 * Output a redirect back to the article.
1754 * This is typically used after an edit.
1756 * @deprecated in 1.18; call $wgOut->redirect() directly
1757 * @param $noRedir Boolean: add redirect=no
1758 * @param $sectionAnchor String: section to redirect to, including "#"
1759 * @param $extraQuery String: extra query params
1761 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1762 wfDeprecated( __METHOD__
, '1.18' );
1766 $query = 'redirect=no';
1768 $query .= "&$extraQuery";
1770 $query = $extraQuery;
1773 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1777 * Use PHP's magic __get handler to handle accessing of
1778 * raw WikiPage fields for backwards compatibility.
1780 * @param $fname String Field name
1782 public function __get( $fname ) {
1783 if ( property_exists( $this->mPage
, $fname ) ) {
1784 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1785 return $this->mPage
->$fname;
1787 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1791 * Use PHP's magic __set handler to handle setting of
1792 * raw WikiPage fields for backwards compatibility.
1794 * @param $fname String Field name
1795 * @param $fvalue mixed New value
1797 public function __set( $fname, $fvalue ) {
1798 if ( property_exists( $this->mPage
, $fname ) ) {
1799 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1800 $this->mPage
->$fname = $fvalue;
1801 // Note: extensions may want to toss on new fields
1802 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1803 $this->mPage
->$fname = $fvalue;
1805 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1810 * Use PHP's magic __call handler to transform instance calls to
1811 * WikiPage functions for backwards compatibility.
1813 * @param $fname String Name of called method
1814 * @param $args Array Arguments to the method
1816 public function __call( $fname, $args ) {
1817 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1818 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1819 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1821 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1824 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1827 * @param $limit array
1828 * @param $expiry array
1829 * @param $cascade bool
1830 * @param $reason string
1834 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1835 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1839 * @param $limit array
1840 * @param $reason string
1841 * @param $cascade int
1842 * @param $expiry array
1845 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1846 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1850 * @param $reason string
1851 * @param $suppress bool
1853 * @param $commit bool
1854 * @param $error string
1857 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1858 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1866 * @param $resultDetails
1870 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1872 $user = is_null( $user ) ?
$wgUser : $user;
1873 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1880 * @param $resultDetails
1881 * @param $guser User
1884 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1886 $guser = is_null( $guser ) ?
$wgUser : $guser;
1887 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1891 * @param $hasHistory bool
1894 public function generateReason( &$hasHistory ) {
1895 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1898 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1903 public static function selectFields() {
1904 return WikiPage
::selectFields();
1908 * @param $title Title
1910 public static function onArticleCreate( $title ) {
1911 WikiPage
::onArticleCreate( $title );
1915 * @param $title Title
1917 public static function onArticleDelete( $title ) {
1918 WikiPage
::onArticleDelete( $title );
1922 * @param $title Title
1924 public static function onArticleEdit( $title ) {
1925 WikiPage
::onArticleEdit( $title );
1934 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1935 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );