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();
378 if ( !$this->mRevision
) {
379 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
380 wfProfileOut( __METHOD__
);
385 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
386 // We should instead work with the Revision object when we need it...
387 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
388 $this->mRevIdFetched
= $this->mRevision
->getId();
390 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) ); #FIXME: register new hook
392 wfProfileOut( __METHOD__
);
394 return $this->mContentObject
;
399 * @deprecated since 1.18
401 public function forUpdate() {
402 wfDeprecated( __METHOD__
, '1.18' );
406 * Returns true if the currently-referenced revision is the current edit
407 * to this page (and it exists).
410 public function isCurrent() {
411 # If no oldid, this is the current version.
412 if ( $this->getOldID() == 0 ) {
416 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
420 * Get the fetched Revision object depending on request parameters or null
424 * @return Revision|null
426 public function getRevisionFetched() {
427 $this->fetchContentObject();
429 return $this->mRevision
;
433 * Use this to fetch the rev ID used on page views
435 * @return int revision ID of last article revision
437 public function getRevIdFetched() {
438 if ( $this->mRevIdFetched
) {
439 return $this->mRevIdFetched
;
441 return $this->mPage
->getLatest();
446 * This is the default action of the index.php entry point: just view the
447 * page of the given title.
449 public function view() {
450 global $wgUser, $wgOut, $wgRequest, $wgParser;
451 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
453 wfProfileIn( __METHOD__
);
455 # Get variables from query string
456 # As side effect this will load the revision and update the title
457 # in a revision ID is passed in the request, so this should remain
458 # the first call of this method even if $oldid is used way below.
459 $oldid = $this->getOldID();
461 # Another whitelist check in case getOldID() is altering the title
462 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
463 if ( count( $permErrors ) ) {
464 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
465 wfProfileOut( __METHOD__
);
466 throw new PermissionsError( 'read', $permErrors );
469 # getOldID() may as well want us to redirect somewhere else
470 if ( $this->mRedirectUrl
) {
471 $wgOut->redirect( $this->mRedirectUrl
);
472 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
473 wfProfileOut( __METHOD__
);
478 # If we got diff in the query, we want to see a diff page instead of the article.
479 if ( $wgRequest->getCheck( 'diff' ) ) {
480 wfDebug( __METHOD__
. ": showing diff page\n" );
481 $this->showDiffPage();
482 wfProfileOut( __METHOD__
);
487 # Set page title (may be overridden by DISPLAYTITLE)
488 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
490 $wgOut->setArticleFlag( true );
491 # Allow frames by default
492 $wgOut->allowClickjacking();
494 $parserCache = ParserCache
::singleton();
496 $parserOptions = $this->getParserOptions();
497 # Render printable version, use printable version cache
498 if ( $wgOut->isPrintable() ) {
499 $parserOptions->setIsPrintable( true );
500 $parserOptions->setEditSection( false );
501 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
502 $parserOptions->setEditSection( false );
505 # Try client and file cache
506 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
508 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
511 # Is it client cached?
512 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
513 wfDebug( __METHOD__
. ": done 304\n" );
514 wfProfileOut( __METHOD__
);
518 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
519 wfDebug( __METHOD__
. ": done file cache\n" );
520 # tell wgOut that output is taken care of
522 $this->mPage
->doViewUpdates( $wgUser );
523 wfProfileOut( __METHOD__
);
529 # Should the parser cache be used?
530 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
531 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
532 if ( $wgUser->getStubThreshold() ) {
533 wfIncrStats( 'pcache_miss_stub' );
536 $this->showRedirectedFromHeader();
537 $this->showNamespaceHeader();
539 # Iterate through the possible ways of constructing the output text.
540 # Keep going until $outputDone is set, or we run out of things to do.
543 $this->mParserOutput
= false;
545 while ( !$outputDone && ++
$pass ) {
548 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
551 # Early abort if the page doesn't exist
552 if ( !$this->mPage
->exists() ) {
553 wfDebug( __METHOD__
. ": showing missing article\n" );
554 $this->showMissingArticle();
555 wfProfileOut( __METHOD__
);
559 # Try the parser cache
560 if ( $useParserCache ) {
561 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
563 if ( $this->mParserOutput
!== false ) {
565 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
566 $this->setOldSubtitle( $oldid );
568 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
570 $wgOut->addParserOutput( $this->mParserOutput
);
571 # Ensure that UI elements requiring revision ID have
572 # the correct version information.
573 $wgOut->setRevisionId( $this->mPage
->getLatest() );
574 # Preload timestamp to avoid a DB hit
575 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
576 if ( $cachedTimestamp !== null ) {
577 $wgOut->setRevisionTimestamp( $cachedTimestamp );
578 $this->mPage
->setTimestamp( $cachedTimestamp );
585 # This will set $this->mRevision if needed
586 $this->fetchContentObject();
588 # Are we looking at an old revision
589 if ( $oldid && $this->mRevision
) {
590 $this->setOldSubtitle( $oldid );
592 if ( !$this->showDeletedRevisionHeader() ) {
593 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
594 wfProfileOut( __METHOD__
);
599 # Ensure that UI elements requiring revision ID have
600 # the correct version information.
601 $wgOut->setRevisionId( $this->getRevIdFetched() );
602 # Preload timestamp to avoid a DB hit
603 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
605 # Pages containing custom CSS or JavaScript get special treatment
606 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
607 #FIXME: use ContentHandler for specialized actions insetad.
608 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
609 $this->showCssOrJsPage();
611 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
612 # Allow extensions do their own custom view for certain pages
615 $content = $this->getContentObject();
616 $rt = $content->getRedirectChain();
618 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
619 # Viewing a redirect page (e.g. with parameter redirect=no)
620 $wgOut->addHTML( $this->viewRedirect( $rt ) );
621 # Parse just to get categories, displaytitle, etc.
622 $this->mParserOutput
= $content->getParserOutput( $parserOptions );
623 $wgOut->addParserOutputNoText( $this->mParserOutput
);
629 # Run the parse, protected by a pool counter
630 wfDebug( __METHOD__
. ": doing uncached parse\n" );
632 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
633 $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
635 if ( !$poolArticleView->execute() ) {
636 $error = $poolArticleView->getError();
638 $wgOut->clearHTML(); // for release() errors
639 $wgOut->enableClientCache( false );
640 $wgOut->setRobotPolicy( 'noindex,nofollow' );
642 $errortext = $error->getWikiText( false, 'view-pool-error' );
643 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
645 # Connection or timeout error
646 wfProfileOut( __METHOD__
);
650 $this->mParserOutput
= $poolArticleView->getParserOutput();
651 $wgOut->addParserOutput( $this->mParserOutput
);
653 # Don't cache a dirty ParserOutput object
654 if ( $poolArticleView->getIsDirty() ) {
655 $wgOut->setSquidMaxage( 0 );
656 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
661 # Should be unreachable, but just in case...
667 # Get the ParserOutput actually *displayed* here.
668 # Note that $this->mParserOutput is the *current* version output.
669 $pOutput = ( $outputDone instanceof ParserOutput
)
670 ?
$outputDone // object fetched by hook
671 : $this->mParserOutput
;
673 # Adjust title for main page & pages with displaytitle
675 $this->adjustDisplayTitle( $pOutput );
678 # For the main page, overwrite the <title> element with the con-
679 # tents of 'pagetitle-view-mainpage' instead of the default (if
681 # This message always exists because it is in the i18n files
682 if ( $this->getTitle()->isMainPage() ) {
683 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
684 if ( !$msg->isDisabled() ) {
685 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
689 # Check for any __NOINDEX__ tags on the page using $pOutput
690 $policy = $this->getRobotPolicy( 'view', $pOutput );
691 $wgOut->setIndexPolicy( $policy['index'] );
692 $wgOut->setFollowPolicy( $policy['follow'] );
694 $this->showViewFooter();
695 $this->mPage
->doViewUpdates( $wgUser );
697 wfProfileOut( __METHOD__
);
701 * Adjust title for pages with displaytitle, -{T|}- or language conversion
702 * @param $pOutput ParserOutput
704 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
706 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
707 $titleText = $pOutput->getTitleText();
708 if ( strval( $titleText ) !== '' ) {
709 $wgOut->setPageTitle( $titleText );
714 * Show a diff page according to current request variables. For use within
715 * Article::view() only, other callers should use the DifferenceEngine class.
717 public function showDiffPage() {
718 global $wgRequest, $wgUser;
720 $diff = $wgRequest->getVal( 'diff' );
721 $rcid = $wgRequest->getVal( 'rcid' );
722 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
723 $purge = $wgRequest->getVal( 'action' ) == 'purge';
724 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
725 $oldid = $this->getOldID();
727 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
728 // DifferenceEngine directly fetched the revision:
729 $this->mRevIdFetched
= $de->mNewid
;
730 $de->showDiffPage( $diffOnly );
732 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
733 # Run view updates for current revision only
734 $this->mPage
->doViewUpdates( $wgUser );
739 * Show a page view for a page formatted as CSS or JavaScript. To be called by
740 * Article::view() only.
742 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
745 protected function showCssOrJsPage() { #FIXME: move this to handler!
748 $dir = $this->getContext()->getLanguage()->getDir();
749 $lang = $this->getContext()->getLanguage()->getCode();
751 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
752 'clearyourcache' ); #FIXME: do this in handler
754 // Give hooks a chance to customise the output
755 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
756 $wgOut->addHTML( $this->mContentObject
->getHTML() );
761 * Get the robot policy to be used for the current view
762 * @param $action String the action= GET parameter
763 * @param $pOutput ParserOutput
764 * @return Array the policy that should be set
765 * TODO: actions other than 'view'
767 public function getRobotPolicy( $action, $pOutput ) {
768 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
769 global $wgDefaultRobotPolicy, $wgRequest;
771 $ns = $this->getTitle()->getNamespace();
773 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
774 # Don't index user and user talk pages for blocked users (bug 11443)
775 if ( !$this->getTitle()->isSubpage() ) {
776 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
778 'index' => 'noindex',
779 'follow' => 'nofollow'
785 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
786 # Non-articles (special pages etc), and old revisions
788 'index' => 'noindex',
789 'follow' => 'nofollow'
791 } elseif ( $wgOut->isPrintable() ) {
792 # Discourage indexing of printable versions, but encourage following
794 'index' => 'noindex',
797 } elseif ( $wgRequest->getInt( 'curid' ) ) {
798 # For ?curid=x urls, disallow indexing
800 'index' => 'noindex',
805 # Otherwise, construct the policy based on the various config variables.
806 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
808 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
809 # Honour customised robot policies for this namespace
810 $policy = array_merge(
812 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
815 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
816 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
817 # a final sanity check that we have really got the parser output.
818 $policy = array_merge(
820 array( 'index' => $pOutput->getIndexPolicy() )
824 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
825 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
826 $policy = array_merge(
828 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
836 * Converts a String robot policy into an associative array, to allow
837 * merging of several policies using array_merge().
838 * @param $policy Mixed, returns empty array on null/false/'', transparent
839 * to already-converted arrays, converts String.
840 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
842 public static function formatRobotPolicy( $policy ) {
843 if ( is_array( $policy ) ) {
845 } elseif ( !$policy ) {
849 $policy = explode( ',', $policy );
850 $policy = array_map( 'trim', $policy );
853 foreach ( $policy as $var ) {
854 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
855 $arr['index'] = $var;
856 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
857 $arr['follow'] = $var;
865 * If this request is a redirect view, send "redirected from" subtitle to
866 * $wgOut. Returns true if the header was needed, false if this is not a
867 * redirect view. Handles both local and remote redirects.
871 public function showRedirectedFromHeader() {
872 global $wgOut, $wgRequest, $wgRedirectSources;
874 $rdfrom = $wgRequest->getVal( 'rdfrom' );
876 if ( isset( $this->mRedirectedFrom
) ) {
877 // This is an internally redirected page view.
878 // We'll need a backlink to the source page for navigation.
879 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
880 $redir = Linker
::linkKnown(
881 $this->mRedirectedFrom
,
884 array( 'redirect' => 'no' )
887 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
889 // Set the fragment if one was specified in the redirect
890 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
891 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
892 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
895 // Add a <link rel="canonical"> tag
896 $wgOut->addLink( array( 'rel' => 'canonical',
897 'href' => $this->getTitle()->getLocalURL() )
900 // Tell $wgOut the user arrived at this article through a redirect
901 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
905 } elseif ( $rdfrom ) {
906 // This is an externally redirected view, from some other wiki.
907 // If it was reported from a trusted site, supply a backlink.
908 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
909 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
910 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
920 * Show a header specific to the namespace currently being viewed, like
921 * [[MediaWiki:Talkpagetext]]. For Article::view().
923 public function showNamespaceHeader() {
926 if ( $this->getTitle()->isTalkPage() ) {
927 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
928 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
934 * Show the footer section of an ordinary page view
936 public function showViewFooter() {
939 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
940 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
941 $wgOut->addWikiMsg( 'anontalkpagetext' );
944 # If we have been passed an &rcid= parameter, we want to give the user a
945 # chance to mark this new article as patrolled.
946 $this->showPatrolFooter();
948 wfRunHooks( 'ArticleViewFooter', array( $this ) );
953 * If patrol is possible, output a patrol UI box. This is called from the
954 * footer section of ordinary page views. If patrol is not possible or not
955 * desired, does nothing.
957 public function showPatrolFooter() {
958 global $wgOut, $wgRequest, $wgUser;
960 $rcid = $wgRequest->getVal( 'rcid' );
962 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
966 $token = $wgUser->getEditToken( $rcid );
967 $wgOut->preventClickjacking();
970 "<div class='patrollink'>" .
972 'markaspatrolledlink',
975 wfMsgHtml( 'markaspatrolledtext' ),
978 'action' => 'markpatrolled',
982 array( 'known', 'noclasses' )
990 * Show the error text for a missing article. For articles in the MediaWiki
991 * namespace, show the default message text. To be called from Article::view().
993 public function showMissingArticle() {
994 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
996 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
997 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
998 $parts = explode( '/', $this->getTitle()->getText() );
999 $rootPart = $parts[0];
1000 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1001 $ip = User
::isIP( $rootPart );
1003 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1004 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1005 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1006 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1007 LogEventsList
::showLogExtract(
1010 $user->getUserPage()->getPrefixedText(),
1014 'showIfEmpty' => false,
1016 'blocked-notice-logextract',
1017 $user->getName() # Support GENDER in notice
1024 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1026 # Show delete and move logs
1027 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1029 'conds' => array( "log_action != 'revision'" ),
1030 'showIfEmpty' => false,
1031 'msgKey' => array( 'moveddeleted-notice' ) )
1034 # Show error message
1035 $oldid = $this->getOldID();
1037 $text = wfMsgNoTrans( 'missing-article',
1038 $this->getTitle()->getPrefixedText(),
1039 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1040 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1041 // Use the default message text
1042 $text = $this->getTitle()->getDefaultMessageText();
1044 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
1045 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
1046 $errors = array_merge( $createErrors, $editErrors );
1048 if ( !count( $errors ) ) {
1049 $text = wfMsgNoTrans( 'noarticletext' );
1051 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1054 $text = "<div class='noarticletext'>\n$text\n</div>";
1056 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1057 // If there's no backing content, send a 404 Not Found
1058 // for better machine handling of broken links.
1059 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1062 $wgOut->addWikiText( $text );
1066 * If the revision requested for view is deleted, check permissions.
1067 * Send either an error message or a warning header to $wgOut.
1069 * @return boolean true if the view is allowed, false if not.
1071 public function showDeletedRevisionHeader() {
1072 global $wgOut, $wgRequest;
1074 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1079 // If the user is not allowed to see it...
1080 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1081 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1082 'rev-deleted-text-permission' );
1085 // If the user needs to confirm that they want to see it...
1086 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1087 # Give explanation and add a link to view the revision...
1088 $oldid = intval( $this->getOldID() );
1089 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1090 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1091 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1092 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1093 array( $msg, $link ) );
1096 // We are allowed to see...
1098 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1099 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1100 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1107 * Generate the navigation links when browsing through an article revisions
1108 * It shows the information as:
1109 * Revision as of \<date\>; view current revision
1110 * \<- Previous version | Next Version -\>
1112 * @param $oldid String: revision ID of this article revision
1114 public function setOldSubtitle( $oldid = 0 ) {
1115 global $wgLang, $wgOut, $wgUser, $wgRequest;
1117 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1121 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1123 # Cascade unhide param in links for easy deletion browsing
1124 $extraParams = array();
1125 if ( $wgRequest->getVal( 'unhide' ) ) {
1126 $extraParams['unhide'] = 1;
1129 $revision = Revision
::newFromId( $oldid );
1130 $timestamp = $revision->getTimestamp();
1132 $current = ( $oldid == $this->mPage
->getLatest() );
1133 $td = $wgLang->timeanddate( $timestamp, true );
1134 $tddate = $wgLang->date( $timestamp, true );
1135 $tdtime = $wgLang->time( $timestamp, true );
1137 # Show user links if allowed to see them. If hidden, then show them only if requested...
1138 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1140 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1141 ?
'revision-info-current'
1144 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1145 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1146 $tdtime, $revision->getUser() )->parse() . "</div>" );
1149 ?
wfMsgHtml( 'currentrevisionlink' )
1152 wfMsgHtml( 'currentrevisionlink' ),
1155 array( 'known', 'noclasses' )
1158 ?
wfMsgHtml( 'diff' )
1161 wfMsgHtml( 'diff' ),
1167 array( 'known', 'noclasses' )
1169 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1173 wfMsgHtml( 'previousrevision' ),
1176 'direction' => 'prev',
1179 array( 'known', 'noclasses' )
1181 : wfMsgHtml( 'previousrevision' );
1185 wfMsgHtml( 'diff' ),
1191 array( 'known', 'noclasses' )
1193 : wfMsgHtml( 'diff' );
1194 $nextlink = $current
1195 ?
wfMsgHtml( 'nextrevision' )
1198 wfMsgHtml( 'nextrevision' ),
1201 'direction' => 'next',
1204 array( 'known', 'noclasses' )
1206 $nextdiff = $current
1207 ?
wfMsgHtml( 'diff' )
1210 wfMsgHtml( 'diff' ),
1216 array( 'known', 'noclasses' )
1219 $cdel = Linker
::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1220 if ( $cdel !== '' ) {
1224 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1225 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1226 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1232 * @param $target Title|Array of destination(s) to redirect
1233 * @param $appendSubtitle Boolean [optional]
1234 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1235 * @return string containing HMTL with redirect link
1237 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1238 global $wgOut, $wgStylePath;
1240 if ( !is_array( $target ) ) {
1241 $target = array( $target );
1244 $lang = $this->getTitle()->getPageLanguage();
1245 $imageDir = $lang->getDir();
1247 if ( $appendSubtitle ) {
1248 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1251 // the loop prepends the arrow image before the link, so the first case needs to be outside
1256 $title = array_shift( $target );
1258 if ( $forceKnown ) {
1259 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1261 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1264 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1265 $alt = $lang->isRTL() ?
'←' : '→';
1266 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1267 foreach ( $target as $rt ) {
1268 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1269 if ( $forceKnown ) {
1270 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1272 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1276 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1277 return '<div class="redirectMsg">' .
1278 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1279 '<span class="redirectText">' . $link . '</span></div>';
1283 * Handle action=render
1285 public function render() {
1288 $wgOut->setArticleBodyOnly( true );
1293 * action=protect handler
1295 public function protect() {
1296 $form = new ProtectionForm( $this );
1301 * action=unprotect handler (alias)
1303 public function unprotect() {
1308 * UI entry point for page deletion
1310 public function delete() {
1311 global $wgOut, $wgRequest, $wgLang;
1313 # This code desperately needs to be totally rewritten
1315 $title = $this->getTitle();
1316 $user = $this->getContext()->getUser();
1319 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1320 if ( count( $permission_errors ) ) {
1321 throw new PermissionsError( 'delete', $permission_errors );
1324 # Read-only check...
1325 if ( wfReadOnly() ) {
1326 throw new ReadOnlyError
;
1329 # Better double-check that it hasn't been deleted yet!
1330 $dbw = wfGetDB( DB_MASTER
);
1331 $conds = $title->pageCond();
1332 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1333 if ( $latest === false ) {
1334 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1335 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1336 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1338 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1339 LogEventsList
::showLogExtract(
1342 $title->getPrefixedText()
1348 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1349 $deleteReason = $wgRequest->getText( 'wpReason' );
1351 if ( $deleteReasonList == 'other' ) {
1352 $reason = $deleteReason;
1353 } elseif ( $deleteReason != '' ) {
1354 // Entry from drop down menu + additional comment
1355 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1357 $reason = $deleteReasonList;
1360 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1361 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1363 # Flag to hide all contents of the archived revisions
1364 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1366 $this->doDelete( $reason, $suppress );
1368 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1370 } elseif ( $title->userIsWatching() ) {
1377 // Generate deletion reason
1378 $hasHistory = false;
1380 $reason = $this->generateReason( $hasHistory );
1383 // If the page has a history, insert a warning
1384 if ( $hasHistory ) {
1385 $revisions = $this->mTitle
->estimateRevisionCount();
1386 // @todo FIXME: i18n issue/patchwork message
1387 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1388 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1389 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1390 wfMsgHtml( 'history' ),
1391 array( 'rel' => 'archives' ),
1392 array( 'action' => 'history' ) ) .
1396 if ( $this->mTitle
->isBigDeletion() ) {
1397 global $wgDeleteRevisionsLimit;
1398 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1399 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1403 return $this->confirmDelete( $reason );
1407 * Output deletion confirmation dialog
1408 * @todo FIXME: Move to another file?
1409 * @param $reason String: prefilled reason
1411 public function confirmDelete( $reason ) {
1414 wfDebug( "Article::confirmDelete\n" );
1416 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1417 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1418 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1419 $wgOut->addWikiMsg( 'confirmdeletetext' );
1421 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1423 $user = $this->getContext()->getUser();
1425 if ( $user->isAllowed( 'suppressrevision' ) ) {
1426 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1428 <td class='mw-input'><strong>" .
1429 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1430 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1436 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1438 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1439 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1440 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1441 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1442 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1443 "<tr id=\"wpDeleteReasonListRow\">
1444 <td class='mw-label'>" .
1445 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1447 <td class='mw-input'>" .
1448 Xml
::listDropDown( 'wpDeleteReasonList',
1449 wfMsgForContent( 'deletereason-dropdown' ),
1450 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1453 <tr id=\"wpDeleteReasonRow\">
1454 <td class='mw-label'>" .
1455 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1457 <td class='mw-input'>" .
1458 Html
::input( 'wpReason', $reason, 'text', array(
1460 'maxlength' => '255',
1468 # Disallow watching if user is not logged in
1469 if ( $user->isLoggedIn() ) {
1473 <td class='mw-input'>" .
1474 Xml
::checkLabel( wfMsg( 'watchthis' ),
1475 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1484 <td class='mw-submit'>" .
1485 Xml
::submitButton( wfMsg( 'deletepage' ),
1486 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1489 Xml
::closeElement( 'table' ) .
1490 Xml
::closeElement( 'fieldset' ) .
1491 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1492 Xml
::closeElement( 'form' );
1494 if ( $user->isAllowed( 'editinterface' ) ) {
1495 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1496 $link = Linker
::link(
1498 wfMsgHtml( 'delete-edit-reasonlist' ),
1500 array( 'action' => 'edit' )
1502 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1505 $wgOut->addHTML( $form );
1506 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1507 LogEventsList
::showLogExtract( $wgOut, 'delete',
1508 $this->getTitle()->getPrefixedText()
1513 * Perform a deletion and output success or failure messages
1515 * @param $suppress bool
1517 public function doDelete( $reason, $suppress = false ) {
1521 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1522 $deleted = $this->getTitle()->getPrefixedText();
1524 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1525 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1527 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1529 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1530 $wgOut->returnToMain( false );
1532 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1533 if ( $error == '' ) {
1534 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1535 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1537 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1539 LogEventsList
::showLogExtract(
1542 $this->getTitle()->getPrefixedText()
1545 $wgOut->addHTML( $error );
1550 /* Caching functions */
1553 * checkLastModified returns true if it has taken care of all
1554 * output to the client that is necessary for this request.
1555 * (that is, it has sent a cached version of the page)
1557 * @return boolean true if cached version send, false otherwise
1559 protected function tryFileCache() {
1560 static $called = false;
1563 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1568 if ( $this->isFileCacheable() ) {
1569 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1570 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1571 wfDebug( "Article::tryFileCache(): about to load file\n" );
1572 $cache->loadFromFileCache( $this->getContext() );
1575 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1576 ob_start( array( &$cache, 'saveToFileCache' ) );
1579 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1586 * Check if the page can be cached
1589 public function isFileCacheable() {
1592 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1593 $cacheable = $this->mPage
->getID()
1594 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1595 // Extension may have reason to disable file caching on some pages.
1597 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1607 * Lightweight method to get the parser output for a page, checking the parser cache
1608 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1609 * consider, so it's not appropriate to use there.
1611 * @since 1.16 (r52326) for LiquidThreads
1613 * @param $oldid mixed integer Revision ID or null
1614 * @param $user User The relevant user
1615 * @return ParserOutput or false if the given revsion ID is not found
1617 public function getParserOutput( $oldid = null, User
$user = null ) {
1620 $user = is_null( $user ) ?
$wgUser : $user;
1621 $parserOptions = $this->mPage
->makeParserOptions( $user );
1623 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1627 * Get parser options suitable for rendering the primary article wikitext
1628 * @return ParserOptions|false
1630 public function getParserOptions() {
1632 if ( !$this->mParserOptions
) {
1633 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1635 // Clone to allow modifications of the return value without affecting cache
1636 return clone $this->mParserOptions
;
1640 * Sets the context this Article is executed in
1642 * @param $context IContextSource
1645 public function setContext( $context ) {
1646 $this->mContext
= $context;
1650 * Gets the context this Article is executed in
1652 * @return IContextSource
1655 public function getContext() {
1656 if ( $this->mContext
instanceof IContextSource
) {
1657 return $this->mContext
;
1659 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1660 return RequestContext
::getMain();
1665 * Info about this page
1666 * @deprecated since 1.19
1668 public function info() {
1669 wfDeprecated( __METHOD__
, '1.19' );
1670 Action
::factory( 'info', $this )->show();
1674 * Mark this particular edit/page as patrolled
1675 * @deprecated since 1.18
1677 public function markpatrolled() {
1678 wfDeprecated( __METHOD__
, '1.18' );
1679 Action
::factory( 'markpatrolled', $this )->show();
1683 * Handle action=purge
1684 * @deprecated since 1.19
1686 public function purge() {
1687 return Action
::factory( 'purge', $this )->show();
1691 * Handle action=revert
1692 * @deprecated since 1.19
1694 public function revert() {
1695 wfDeprecated( __METHOD__
, '1.19' );
1696 Action
::factory( 'revert', $this )->show();
1700 * Handle action=rollback
1701 * @deprecated since 1.19
1703 public function rollback() {
1704 wfDeprecated( __METHOD__
, '1.19' );
1705 Action
::factory( 'rollback', $this )->show();
1709 * User-interface handler for the "watch" action.
1710 * Requires Request to pass a token as of 1.18.
1711 * @deprecated since 1.18
1713 public function watch() {
1714 wfDeprecated( __METHOD__
, '1.18' );
1715 Action
::factory( 'watch', $this )->show();
1719 * Add this page to $wgUser's watchlist
1721 * This is safe to be called multiple times
1723 * @return bool true on successful watch operation
1724 * @deprecated since 1.18
1726 public function doWatch() {
1728 wfDeprecated( __METHOD__
, '1.18' );
1729 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1733 * User interface handler for the "unwatch" action.
1734 * Requires Request to pass a token as of 1.18.
1735 * @deprecated since 1.18
1737 public function unwatch() {
1738 wfDeprecated( __METHOD__
, '1.18' );
1739 Action
::factory( 'unwatch', $this )->show();
1743 * Stop watching a page
1744 * @return bool true on successful unwatch
1745 * @deprecated since 1.18
1747 public function doUnwatch() {
1749 wfDeprecated( __METHOD__
, '1.18' );
1750 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1754 * Output a redirect back to the article.
1755 * This is typically used after an edit.
1757 * @deprecated in 1.18; call $wgOut->redirect() directly
1758 * @param $noRedir Boolean: add redirect=no
1759 * @param $sectionAnchor String: section to redirect to, including "#"
1760 * @param $extraQuery String: extra query params
1762 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1763 wfDeprecated( __METHOD__
, '1.18' );
1767 $query = 'redirect=no';
1769 $query .= "&$extraQuery";
1771 $query = $extraQuery;
1774 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1778 * Use PHP's magic __get handler to handle accessing of
1779 * raw WikiPage fields for backwards compatibility.
1781 * @param $fname String Field name
1783 public function __get( $fname ) {
1784 if ( property_exists( $this->mPage
, $fname ) ) {
1785 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1786 return $this->mPage
->$fname;
1788 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1792 * Use PHP's magic __set handler to handle setting of
1793 * raw WikiPage fields for backwards compatibility.
1795 * @param $fname String Field name
1796 * @param $fvalue mixed New value
1798 public function __set( $fname, $fvalue ) {
1799 if ( property_exists( $this->mPage
, $fname ) ) {
1800 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1801 $this->mPage
->$fname = $fvalue;
1802 // Note: extensions may want to toss on new fields
1803 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1804 $this->mPage
->$fname = $fvalue;
1806 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1811 * Use PHP's magic __call handler to transform instance calls to
1812 * WikiPage functions for backwards compatibility.
1814 * @param $fname String Name of called method
1815 * @param $args Array Arguments to the method
1817 public function __call( $fname, $args ) {
1818 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1819 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1820 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1822 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1825 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1828 * @param $limit array
1829 * @param $expiry array
1830 * @param $cascade bool
1831 * @param $reason string
1835 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1836 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1840 * @param $limit array
1841 * @param $reason string
1842 * @param $cascade int
1843 * @param $expiry array
1846 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1847 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1851 * @param $reason string
1852 * @param $suppress bool
1854 * @param $commit bool
1855 * @param $error string
1858 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1859 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1867 * @param $resultDetails
1871 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1873 $user = is_null( $user ) ?
$wgUser : $user;
1874 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1881 * @param $resultDetails
1882 * @param $guser User
1885 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1887 $guser = is_null( $guser ) ?
$wgUser : $guser;
1888 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1892 * @param $hasHistory bool
1895 public function generateReason( &$hasHistory ) {
1896 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1899 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1904 public static function selectFields() {
1905 return WikiPage
::selectFields();
1909 * @param $title Title
1911 public static function onArticleCreate( $title ) {
1912 WikiPage
::onArticleCreate( $title );
1916 * @param $title Title
1918 public static function onArticleDelete( $title ) {
1919 WikiPage
::onArticleDelete( $title );
1923 * @param $title Title
1925 public static function onArticleEdit( $title ) {
1926 WikiPage
::onArticleEdit( $title );
1935 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1936 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );