8 * Class for viewing MediaWiki article and history.
10 * This maintains WikiPage functions for backwards compatibility.
12 * @TODO: move and rewrite code to an Action class
14 * See design.txt for an overview.
15 * Note: edit user interface and cache support functions have been
16 * moved to separate EditPage and HTMLFileCache classes.
18 * @internal documentation reviewed 15 Mar 2010
20 class Article
extends Page
{
36 * @var ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
41 var $mContentLoaded = false; // !<
47 var $mRedirectedFrom = null;
50 * @var mixed: boolean false or URL string
52 var $mRedirectUrl = false; // !<
53 var $mRevIdFetched = 0; // !<
58 var $mRevision = null;
68 * Constructor and clear the article
69 * @param $title Title Reference to a Title object.
70 * @param $oldId Integer revision ID, null to fetch from request, zero for current
72 public function __construct( Title
$title, $oldId = null ) {
73 $this->mOldId
= $oldId;
74 $this->mPage
= $this->newPage( $title );
81 protected function newPage( Title
$title ) {
82 return new WikiPage( $title );
86 * Constructor from a page id
87 * @param $id Int article ID to load
88 * @return Article|null
90 public static function newFromID( $id ) {
91 $t = Title
::newFromID( $id );
92 # @todo FIXME: Doesn't inherit right
93 return $t == null ?
null : new self( $t );
94 # return $t == null ? null : new static( $t ); // PHP 5.3
98 * Create an Article object of the appropriate class for the given page.
100 * @param $title Title
101 * @param $context IContextSource
102 * @return Article object
104 public static function newFromTitle( $title, IContextSource
$context ) {
105 if ( NS_MEDIA
== $title->getNamespace() ) {
106 // FIXME: where should this go?
107 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
111 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
113 switch( $title->getNamespace() ) {
115 $page = new ImagePage( $title );
118 $page = new CategoryPage( $title );
121 $page = new Article( $title );
124 $page->setContext( $context );
130 * Create an Article object of the appropriate class for the given page.
132 * @param $page WikiPage
133 * @param $context IContextSource
134 * @return Article object
136 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
137 $article = self
::newFromTitle( $page->getTitle(), $context );
138 $article->mPage
= $page; // override to keep process cached vars
143 * Tell the page view functions that this view was redirected
144 * from another page on the wiki.
145 * @param $from Title object.
147 public function setRedirectedFrom( Title
$from ) {
148 $this->mRedirectedFrom
= $from;
152 * Get the title object of the article
153 * @return Title object of this page
155 public function getTitle() {
156 return $this->mPage
->getTitle();
162 public function clear() {
163 $this->mContentLoaded
= false;
165 $this->mRedirectedFrom
= null; # Title object if set
166 $this->mRevIdFetched
= 0;
167 $this->mRedirectUrl
= false;
169 $this->mPage
->clear();
173 * Note that getContent/loadContent do not follow redirects anymore.
174 * If you need to fetch redirectable content easily, try
175 * the shortcut in Article::followRedirect()
177 * This function has side effects! Do not use this function if you
178 * only want the real revision text if any.
180 * @return Return the text of this revision
182 public function getContent() {
185 wfProfileIn( __METHOD__
);
187 if ( $this->mPage
->getID() === 0 ) {
188 # If this is a MediaWiki:x message, then load the messages
189 # and return the message value for x.
190 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
191 $text = $this->getTitle()->getDefaultMessageText();
192 if ( $text === false ) {
196 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
198 wfProfileOut( __METHOD__
);
202 $this->fetchContent();
203 wfProfileOut( __METHOD__
);
205 return $this->mContent
;
210 * @return int The oldid of the article that is to be shown, 0 for the
213 public function getOldID() {
214 if ( is_null( $this->mOldId
) ) {
215 $this->mOldId
= $this->getOldIDFromRequest();
218 return $this->mOldId
;
222 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
224 * @return int The old id for the request
226 public function getOldIDFromRequest() {
229 $this->mRedirectUrl
= false;
231 $oldid = $wgRequest->getIntOrNull( 'oldid' );
233 if ( $oldid === null ) {
237 if ( $oldid !== 0 ) {
238 # Load the given revision and check whether the page is another one.
239 # In that case, update this instance to reflect the change.
240 $this->mRevision
= Revision
::newFromId( $oldid );
241 if ( $this->mRevision
!== null ) {
242 // Revision title doesn't match the page title given?
243 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
244 $function = array( get_class( $this->mPage
), 'newFromID' );
245 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
250 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
251 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
255 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
257 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
258 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
268 * Load the revision (including text) into this object
270 * @deprecated in 1.19; use fetchContent()
272 function loadContent() {
273 wfDeprecated( __METHOD__
, '1.19' );
274 $this->fetchContent();
278 * Get text of an article from database
279 * Does *NOT* follow redirects.
281 * @return mixed string containing article contents, or false if null
283 function fetchContent() {
284 if ( $this->mContentLoaded
) {
285 return $this->mContent
;
288 wfProfileIn( __METHOD__
);
290 $this->mContentLoaded
= true;
292 $oldid = $this->getOldID();
294 # Pre-fill content with error message so that if something
295 # fails we'll have something telling us what we intended.
296 $t = $this->getTitle()->getPrefixedText();
297 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
298 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
301 # $this->mRevision might already be fetched by getOldIDFromRequest()
302 if ( !$this->mRevision
) {
303 $this->mRevision
= Revision
::newFromId( $oldid );
304 if ( !$this->mRevision
) {
305 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
306 wfProfileOut( __METHOD__
);
311 if ( !$this->mPage
->getLatest() ) {
312 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
313 wfProfileOut( __METHOD__
);
317 $this->mRevision
= $this->mPage
->getRevision();
318 if ( !$this->mRevision
) {
319 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
320 wfProfileOut( __METHOD__
);
325 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
326 // We should instead work with the Revision object when we need it...
327 $this->mContent
= $this->mRevision
->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
328 $this->mRevIdFetched
= $this->mRevision
->getId();
330 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
332 wfProfileOut( __METHOD__
);
334 return $this->mContent
;
339 * @deprecated since 1.18
341 public function forUpdate() {
342 wfDeprecated( __METHOD__
, '1.18' );
346 * Returns true if the currently-referenced revision is the current edit
347 * to this page (and it exists).
350 public function isCurrent() {
351 # If no oldid, this is the current version.
352 if ( $this->getOldID() == 0 ) {
356 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
360 * Get the fetched Revision object depending on request parameters or null
363 * @return Revision|null
365 public function getRevisionFetched() {
366 $this->fetchContent();
368 return $this->mRevision
;
372 * Use this to fetch the rev ID used on page views
374 * @return int revision ID of last article revision
376 public function getRevIdFetched() {
377 if ( $this->mRevIdFetched
) {
378 return $this->mRevIdFetched
;
380 return $this->mPage
->getLatest();
385 * This is the default action of the index.php entry point: just view the
386 * page of the given title.
388 public function view() {
389 global $wgUser, $wgOut, $wgRequest, $wgParser;
390 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
392 wfProfileIn( __METHOD__
);
394 # Get variables from query string
395 # As side effect this will load the revision and update the title
396 # in a revision ID is passed in the request, so this should remain
397 # the first call of this method even if $oldid is used way below.
398 $oldid = $this->getOldID();
400 # Another whitelist check in case getOldID() is altering the title
401 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
402 if ( count( $permErrors ) ) {
403 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
404 wfProfileOut( __METHOD__
);
405 throw new PermissionsError( 'read', $permErrors );
408 # getOldID() may as well want us to redirect somewhere else
409 if ( $this->mRedirectUrl
) {
410 $wgOut->redirect( $this->mRedirectUrl
);
411 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
412 wfProfileOut( __METHOD__
);
417 # If we got diff in the query, we want to see a diff page instead of the article.
418 if ( $wgRequest->getCheck( 'diff' ) ) {
419 wfDebug( __METHOD__
. ": showing diff page\n" );
420 $this->showDiffPage();
421 wfProfileOut( __METHOD__
);
426 # Set page title (may be overridden by DISPLAYTITLE)
427 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
429 $wgOut->setArticleFlag( true );
430 # Allow frames by default
431 $wgOut->allowClickjacking();
433 $parserCache = ParserCache
::singleton();
435 $parserOptions = $this->getParserOptions();
436 # Render printable version, use printable version cache
437 if ( $wgOut->isPrintable() ) {
438 $parserOptions->setIsPrintable( true );
439 $parserOptions->setEditSection( false );
440 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
441 $parserOptions->setEditSection( false );
444 # Try client and file cache
445 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
447 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
450 # Is it client cached?
451 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
452 wfDebug( __METHOD__
. ": done 304\n" );
453 wfProfileOut( __METHOD__
);
457 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
458 wfDebug( __METHOD__
. ": done file cache\n" );
459 # tell wgOut that output is taken care of
461 $this->mPage
->doViewUpdates( $this->getContext()->getUser() );
462 wfProfileOut( __METHOD__
);
468 # Should the parser cache be used?
469 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
470 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
471 if ( $wgUser->getStubThreshold() ) {
472 wfIncrStats( 'pcache_miss_stub' );
475 $this->showRedirectedFromHeader();
476 $this->showNamespaceHeader();
478 # Iterate through the possible ways of constructing the output text.
479 # Keep going until $outputDone is set, or we run out of things to do.
482 $this->mParserOutput
= false;
484 while ( !$outputDone && ++
$pass ) {
487 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
490 # Early abort if the page doesn't exist
491 if ( !$this->mPage
->exists() ) {
492 wfDebug( __METHOD__
. ": showing missing article\n" );
493 $this->showMissingArticle();
494 wfProfileOut( __METHOD__
);
498 # Try the parser cache
499 if ( $useParserCache ) {
500 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
502 if ( $this->mParserOutput
!== false ) {
504 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
505 $this->setOldSubtitle( $oldid );
507 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
509 $wgOut->addParserOutput( $this->mParserOutput
);
510 # Ensure that UI elements requiring revision ID have
511 # the correct version information.
512 $wgOut->setRevisionId( $this->mPage
->getLatest() );
513 # Preload timestamp to avoid a DB hit
514 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
515 if ( $cachedTimestamp !== null ) {
516 $wgOut->setRevisionTimestamp( $cachedTimestamp );
517 $this->mPage
->setTimestamp( $cachedTimestamp );
524 # This will set $this->mRevision if needed
525 $this->fetchContent();
527 # Are we looking at an old revision
528 if ( $oldid && $this->mRevision
) {
529 $this->setOldSubtitle( $oldid );
531 if ( !$this->showDeletedRevisionHeader() ) {
532 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
533 wfProfileOut( __METHOD__
);
538 # Ensure that UI elements requiring revision ID have
539 # the correct version information.
540 $wgOut->setRevisionId( $this->getRevIdFetched() );
541 # Preload timestamp to avoid a DB hit
542 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
544 # Pages containing custom CSS or JavaScript get special treatment
545 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
546 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
547 $this->showCssOrJsPage();
549 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
550 # Allow extensions do their own custom view for certain pages
553 $text = $this->getContent();
554 $rt = Title
::newFromRedirectArray( $text );
556 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
557 # Viewing a redirect page (e.g. with parameter redirect=no)
558 $wgOut->addHTML( $this->viewRedirect( $rt ) );
559 # Parse just to get categories, displaytitle, etc.
560 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
561 $wgOut->addParserOutputNoText( $this->mParserOutput
);
567 # Run the parse, protected by a pool counter
568 wfDebug( __METHOD__
. ": doing uncached parse\n" );
570 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
571 $this->getRevIdFetched(), $useParserCache, $this->getContent() );
573 if ( !$poolArticleView->execute() ) {
574 $error = $poolArticleView->getError();
576 $wgOut->clearHTML(); // for release() errors
577 $wgOut->enableClientCache( false );
578 $wgOut->setRobotPolicy( 'noindex,nofollow' );
580 $errortext = $error->getWikiText( false, 'view-pool-error' );
581 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
583 # Connection or timeout error
584 wfProfileOut( __METHOD__
);
588 $this->mParserOutput
= $poolArticleView->getParserOutput();
589 $wgOut->addParserOutput( $this->mParserOutput
);
591 # Don't cache a dirty ParserOutput object
592 if ( $poolArticleView->getIsDirty() ) {
593 $wgOut->setSquidMaxage( 0 );
594 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
599 # Should be unreachable, but just in case...
605 # Get the ParserOutput actually *displayed* here.
606 # Note that $this->mParserOutput is the *current* version output.
607 $pOutput = ( $outputDone instanceof ParserOutput
)
608 ?
$outputDone // object fetched by hook
609 : $this->mParserOutput
;
611 # Adjust title for main page & pages with displaytitle
613 $this->adjustDisplayTitle( $pOutput );
616 # For the main page, overwrite the <title> element with the con-
617 # tents of 'pagetitle-view-mainpage' instead of the default (if
619 # This message always exists because it is in the i18n files
620 if ( $this->getTitle()->isMainPage() ) {
621 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
622 if ( !$msg->isDisabled() ) {
623 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
627 # Check for any __NOINDEX__ tags on the page using $pOutput
628 $policy = $this->getRobotPolicy( 'view', $pOutput );
629 $wgOut->setIndexPolicy( $policy['index'] );
630 $wgOut->setFollowPolicy( $policy['follow'] );
632 $this->showViewFooter();
633 $this->mPage
->doViewUpdates( $this->getContext()->getUser() );
635 wfProfileOut( __METHOD__
);
639 * Adjust title for pages with displaytitle, -{T|}- or language conversion
640 * @param $pOutput ParserOutput
642 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
644 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
645 $titleText = $pOutput->getTitleText();
646 if ( strval( $titleText ) !== '' ) {
647 $wgOut->setPageTitle( $titleText );
652 * Show a diff page according to current request variables. For use within
653 * Article::view() only, other callers should use the DifferenceEngine class.
655 public function showDiffPage() {
656 global $wgRequest, $wgUser;
658 $diff = $wgRequest->getVal( 'diff' );
659 $rcid = $wgRequest->getVal( 'rcid' );
660 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
661 $purge = $wgRequest->getVal( 'action' ) == 'purge';
662 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
663 $oldid = $this->getOldID();
665 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
666 // DifferenceEngine directly fetched the revision:
667 $this->mRevIdFetched
= $de->mNewid
;
668 $de->showDiffPage( $diffOnly );
670 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
671 # Run view updates for current revision only
672 $this->mPage
->doViewUpdates( $this->getContext()->getUser() );
677 * Show a page view for a page formatted as CSS or JavaScript. To be called by
678 * Article::view() only.
680 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
683 protected function showCssOrJsPage() {
686 $dir = $this->getContext()->getLanguage()->getDir();
687 $lang = $this->getContext()->getLanguage()->getCode();
689 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
692 // Give hooks a chance to customise the output
693 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
694 // Wrap the whole lot in a <pre> and don't parse
696 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
697 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
698 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
699 $wgOut->addHTML( "\n</pre>\n" );
704 * Get the robot policy to be used for the current view
705 * @param $action String the action= GET parameter
706 * @param $pOutput ParserOutput
707 * @return Array the policy that should be set
708 * TODO: actions other than 'view'
710 public function getRobotPolicy( $action, $pOutput ) {
711 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
712 global $wgDefaultRobotPolicy, $wgRequest;
714 $ns = $this->getTitle()->getNamespace();
716 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
717 # Don't index user and user talk pages for blocked users (bug 11443)
718 if ( !$this->getTitle()->isSubpage() ) {
719 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
721 'index' => 'noindex',
722 'follow' => 'nofollow'
728 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
729 # Non-articles (special pages etc), and old revisions
731 'index' => 'noindex',
732 'follow' => 'nofollow'
734 } elseif ( $wgOut->isPrintable() ) {
735 # Discourage indexing of printable versions, but encourage following
737 'index' => 'noindex',
740 } elseif ( $wgRequest->getInt( 'curid' ) ) {
741 # For ?curid=x urls, disallow indexing
743 'index' => 'noindex',
748 # Otherwise, construct the policy based on the various config variables.
749 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
751 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
752 # Honour customised robot policies for this namespace
753 $policy = array_merge(
755 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
758 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
759 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
760 # a final sanity check that we have really got the parser output.
761 $policy = array_merge(
763 array( 'index' => $pOutput->getIndexPolicy() )
767 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
768 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
769 $policy = array_merge(
771 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
779 * Converts a String robot policy into an associative array, to allow
780 * merging of several policies using array_merge().
781 * @param $policy Mixed, returns empty array on null/false/'', transparent
782 * to already-converted arrays, converts String.
783 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
785 public static function formatRobotPolicy( $policy ) {
786 if ( is_array( $policy ) ) {
788 } elseif ( !$policy ) {
792 $policy = explode( ',', $policy );
793 $policy = array_map( 'trim', $policy );
796 foreach ( $policy as $var ) {
797 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
798 $arr['index'] = $var;
799 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
800 $arr['follow'] = $var;
808 * If this request is a redirect view, send "redirected from" subtitle to
809 * $wgOut. Returns true if the header was needed, false if this is not a
810 * redirect view. Handles both local and remote redirects.
814 public function showRedirectedFromHeader() {
815 global $wgOut, $wgRequest, $wgRedirectSources;
817 $rdfrom = $wgRequest->getVal( 'rdfrom' );
819 if ( isset( $this->mRedirectedFrom
) ) {
820 // This is an internally redirected page view.
821 // We'll need a backlink to the source page for navigation.
822 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
823 $redir = Linker
::linkKnown(
824 $this->mRedirectedFrom
,
827 array( 'redirect' => 'no' )
830 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
832 // Set the fragment if one was specified in the redirect
833 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
834 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
835 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
838 // Add a <link rel="canonical"> tag
839 $wgOut->addLink( array( 'rel' => 'canonical',
840 'href' => $this->getTitle()->getLocalURL() )
843 // Tell $wgOut the user arrived at this article through a redirect
844 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
848 } elseif ( $rdfrom ) {
849 // This is an externally redirected view, from some other wiki.
850 // If it was reported from a trusted site, supply a backlink.
851 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
852 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
853 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
863 * Show a header specific to the namespace currently being viewed, like
864 * [[MediaWiki:Talkpagetext]]. For Article::view().
866 public function showNamespaceHeader() {
869 if ( $this->getTitle()->isTalkPage() ) {
870 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
871 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
877 * Show the footer section of an ordinary page view
879 public function showViewFooter() {
882 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
883 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
884 $wgOut->addWikiMsg( 'anontalkpagetext' );
887 # If we have been passed an &rcid= parameter, we want to give the user a
888 # chance to mark this new article as patrolled.
889 $this->showPatrolFooter();
891 wfRunHooks( 'ArticleViewFooter', array( $this ) );
896 * If patrol is possible, output a patrol UI box. This is called from the
897 * footer section of ordinary page views. If patrol is not possible or not
898 * desired, does nothing.
900 public function showPatrolFooter() {
901 global $wgOut, $wgRequest, $wgUser;
903 $rcid = $wgRequest->getVal( 'rcid' );
905 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
909 $token = $wgUser->getEditToken( $rcid );
910 $wgOut->preventClickjacking();
913 "<div class='patrollink'>" .
915 'markaspatrolledlink',
918 wfMsgHtml( 'markaspatrolledtext' ),
921 'action' => 'markpatrolled',
925 array( 'known', 'noclasses' )
933 * Show the error text for a missing article. For articles in the MediaWiki
934 * namespace, show the default message text. To be called from Article::view().
936 public function showMissingArticle() {
937 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
939 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
940 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
941 $parts = explode( '/', $this->getTitle()->getText() );
942 $rootPart = $parts[0];
943 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
944 $ip = User
::isIP( $rootPart );
946 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
947 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
948 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
949 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
950 LogEventsList
::showLogExtract(
953 $user->getUserPage()->getPrefixedText(),
957 'showIfEmpty' => false,
959 'blocked-notice-logextract',
960 $user->getName() # Support GENDER in notice
967 wfRunHooks( 'ShowMissingArticle', array( $this ) );
969 # Show delete and move logs
970 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
972 'conds' => array( "log_action != 'revision'" ),
973 'showIfEmpty' => false,
974 'msgKey' => array( 'moveddeleted-notice' ) )
978 $oldid = $this->getOldID();
980 $text = wfMsgNoTrans( 'missing-article',
981 $this->getTitle()->getPrefixedText(),
982 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
983 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
984 // Use the default message text
985 $text = $this->getTitle()->getDefaultMessageText();
987 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
988 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
989 $errors = array_merge( $createErrors, $editErrors );
991 if ( !count( $errors ) ) {
992 $text = wfMsgNoTrans( 'noarticletext' );
994 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
997 $text = "<div class='noarticletext'>\n$text\n</div>";
999 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1000 // If there's no backing content, send a 404 Not Found
1001 // for better machine handling of broken links.
1002 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1005 $wgOut->addWikiText( $text );
1009 * If the revision requested for view is deleted, check permissions.
1010 * Send either an error message or a warning header to $wgOut.
1012 * @return boolean true if the view is allowed, false if not.
1014 public function showDeletedRevisionHeader() {
1015 global $wgOut, $wgRequest;
1017 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1022 // If the user is not allowed to see it...
1023 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1024 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1025 'rev-deleted-text-permission' );
1028 // If the user needs to confirm that they want to see it...
1029 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1030 # Give explanation and add a link to view the revision...
1031 $oldid = intval( $this->getOldID() );
1032 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1033 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1034 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1035 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1036 array( $msg, $link ) );
1039 // We are allowed to see...
1041 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1042 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1043 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1050 * Generate the navigation links when browsing through an article revisions
1051 * It shows the information as:
1052 * Revision as of \<date\>; view current revision
1053 * \<- Previous version | Next Version -\>
1055 * @param $oldid String: revision ID of this article revision
1057 public function setOldSubtitle( $oldid = 0 ) {
1058 global $wgLang, $wgOut, $wgUser, $wgRequest;
1060 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1064 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1066 # Cascade unhide param in links for easy deletion browsing
1067 $extraParams = array();
1068 if ( $wgRequest->getVal( 'unhide' ) ) {
1069 $extraParams['unhide'] = 1;
1072 $revision = Revision
::newFromId( $oldid );
1073 $timestamp = $revision->getTimestamp();
1075 $current = ( $oldid == $this->mPage
->getLatest() );
1076 $td = $wgLang->timeanddate( $timestamp, true );
1077 $tddate = $wgLang->date( $timestamp, true );
1078 $tdtime = $wgLang->time( $timestamp, true );
1080 # Show user links if allowed to see them. If hidden, then show them only if requested...
1081 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1083 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1084 ?
'revision-info-current'
1087 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1088 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1089 $tdtime, $revision->getUser() )->parse() . "</div>" );
1092 ?
wfMsgHtml( 'currentrevisionlink' )
1095 wfMsgHtml( 'currentrevisionlink' ),
1098 array( 'known', 'noclasses' )
1101 ?
wfMsgHtml( 'diff' )
1104 wfMsgHtml( 'diff' ),
1110 array( 'known', 'noclasses' )
1112 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1116 wfMsgHtml( 'previousrevision' ),
1119 'direction' => 'prev',
1122 array( 'known', 'noclasses' )
1124 : wfMsgHtml( 'previousrevision' );
1128 wfMsgHtml( 'diff' ),
1134 array( 'known', 'noclasses' )
1136 : wfMsgHtml( 'diff' );
1137 $nextlink = $current
1138 ?
wfMsgHtml( 'nextrevision' )
1141 wfMsgHtml( 'nextrevision' ),
1144 'direction' => 'next',
1147 array( 'known', 'noclasses' )
1149 $nextdiff = $current
1150 ?
wfMsgHtml( 'diff' )
1153 wfMsgHtml( 'diff' ),
1159 array( 'known', 'noclasses' )
1162 $cdel = Linker
::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1163 if ( $cdel !== '' ) {
1167 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1168 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1169 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1175 * @param $target Title|Array of destination(s) to redirect
1176 * @param $appendSubtitle Boolean [optional]
1177 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1178 * @return string containing HMTL with redirect link
1180 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1181 global $wgOut, $wgStylePath;
1183 if ( !is_array( $target ) ) {
1184 $target = array( $target );
1187 $lang = $this->getTitle()->getPageLanguage();
1188 $imageDir = $lang->getDir();
1190 if ( $appendSubtitle ) {
1191 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1194 // the loop prepends the arrow image before the link, so the first case needs to be outside
1199 $title = array_shift( $target );
1201 if ( $forceKnown ) {
1202 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1204 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1207 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1208 $alt = $lang->isRTL() ?
'←' : '→';
1209 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1210 foreach ( $target as $rt ) {
1211 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1212 if ( $forceKnown ) {
1213 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1215 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1219 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1220 return '<div class="redirectMsg">' .
1221 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1222 '<span class="redirectText">' . $link . '</span></div>';
1226 * Handle action=render
1228 public function render() {
1231 $wgOut->setArticleBodyOnly( true );
1236 * action=protect handler
1238 public function protect() {
1239 $form = new ProtectionForm( $this );
1244 * action=unprotect handler (alias)
1246 public function unprotect() {
1251 * UI entry point for page deletion
1253 public function delete() {
1254 global $wgOut, $wgRequest, $wgLang;
1256 # This code desperately needs to be totally rewritten
1258 $title = $this->getTitle();
1259 $user = $this->getContext()->getUser();
1262 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1263 if ( count( $permission_errors ) ) {
1264 throw new PermissionsError( 'delete', $permission_errors );
1267 # Read-only check...
1268 if ( wfReadOnly() ) {
1269 throw new ReadOnlyError
;
1272 # Better double-check that it hasn't been deleted yet!
1273 $dbw = wfGetDB( DB_MASTER
);
1274 $conds = $title->pageCond();
1275 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1276 if ( $latest === false ) {
1277 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1278 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1279 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1281 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1282 LogEventsList
::showLogExtract(
1285 $title->getPrefixedText()
1291 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1292 $deleteReason = $wgRequest->getText( 'wpReason' );
1294 if ( $deleteReasonList == 'other' ) {
1295 $reason = $deleteReason;
1296 } elseif ( $deleteReason != '' ) {
1297 // Entry from drop down menu + additional comment
1298 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1300 $reason = $deleteReasonList;
1303 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1304 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1306 # Flag to hide all contents of the archived revisions
1307 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1309 $this->doDelete( $reason, $suppress );
1311 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1313 } elseif ( $title->userIsWatching() ) {
1320 // Generate deletion reason
1321 $hasHistory = false;
1323 $reason = $this->generateReason( $hasHistory );
1326 // If the page has a history, insert a warning
1327 if ( $hasHistory ) {
1328 $revisions = $this->mTitle
->estimateRevisionCount();
1329 // @todo FIXME: i18n issue/patchwork message
1330 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1331 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1332 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1333 wfMsgHtml( 'history' ),
1334 array( 'rel' => 'archives' ),
1335 array( 'action' => 'history' ) ) .
1339 if ( $this->mTitle
->isBigDeletion() ) {
1340 global $wgDeleteRevisionsLimit;
1341 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1342 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1346 return $this->confirmDelete( $reason );
1350 * Output deletion confirmation dialog
1351 * @todo FIXME: Move to another file?
1352 * @param $reason String: prefilled reason
1354 public function confirmDelete( $reason ) {
1357 wfDebug( "Article::confirmDelete\n" );
1359 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1360 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1361 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1362 $wgOut->addWikiMsg( 'confirmdeletetext' );
1364 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1366 $user = $this->getContext()->getUser();
1368 if ( $user->isAllowed( 'suppressrevision' ) ) {
1369 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1371 <td class='mw-input'><strong>" .
1372 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1373 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1379 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1381 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1382 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1383 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1384 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1385 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1386 "<tr id=\"wpDeleteReasonListRow\">
1387 <td class='mw-label'>" .
1388 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1390 <td class='mw-input'>" .
1391 Xml
::listDropDown( 'wpDeleteReasonList',
1392 wfMsgForContent( 'deletereason-dropdown' ),
1393 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1396 <tr id=\"wpDeleteReasonRow\">
1397 <td class='mw-label'>" .
1398 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1400 <td class='mw-input'>" .
1401 Html
::input( 'wpReason', $reason, 'text', array(
1403 'maxlength' => '255',
1411 # Disallow watching if user is not logged in
1412 if ( $user->isLoggedIn() ) {
1416 <td class='mw-input'>" .
1417 Xml
::checkLabel( wfMsg( 'watchthis' ),
1418 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1427 <td class='mw-submit'>" .
1428 Xml
::submitButton( wfMsg( 'deletepage' ),
1429 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1432 Xml
::closeElement( 'table' ) .
1433 Xml
::closeElement( 'fieldset' ) .
1434 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1435 Xml
::closeElement( 'form' );
1437 if ( $user->isAllowed( 'editinterface' ) ) {
1438 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1439 $link = Linker
::link(
1441 wfMsgHtml( 'delete-edit-reasonlist' ),
1443 array( 'action' => 'edit' )
1445 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1448 $wgOut->addHTML( $form );
1449 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1450 LogEventsList
::showLogExtract( $wgOut, 'delete',
1451 $this->getTitle()->getPrefixedText()
1456 * Perform a deletion and output success or failure messages
1458 * @param $suppress bool
1460 public function doDelete( $reason, $suppress = false ) {
1463 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1466 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
1467 $deleted = $this->getTitle()->getPrefixedText();
1469 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1470 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1472 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1474 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1475 $wgOut->returnToMain( false );
1477 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1478 if ( $error == '' ) {
1479 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1480 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1482 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1484 LogEventsList
::showLogExtract(
1487 $this->getTitle()->getPrefixedText()
1490 $wgOut->addHTML( $error );
1495 /* Caching functions */
1498 * checkLastModified returns true if it has taken care of all
1499 * output to the client that is necessary for this request.
1500 * (that is, it has sent a cached version of the page)
1502 * @return boolean true if cached version send, false otherwise
1504 protected function tryFileCache() {
1505 static $called = false;
1508 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1513 if ( $this->isFileCacheable() ) {
1514 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1515 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1516 wfDebug( "Article::tryFileCache(): about to load file\n" );
1517 $cache->loadFromFileCache( $this->getContext() );
1520 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1521 ob_start( array( &$cache, 'saveToFileCache' ) );
1524 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1531 * Check if the page can be cached
1534 public function isFileCacheable() {
1537 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1538 $cacheable = $this->mPage
->getID()
1539 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1540 // Extension may have reason to disable file caching on some pages.
1542 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1552 * Lightweight method to get the parser output for a page, checking the parser cache
1553 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1554 * consider, so it's not appropriate to use there.
1556 * @since 1.16 (r52326) for LiquidThreads
1558 * @param $oldid mixed integer Revision ID or null
1559 * @param $user User The relevant user
1560 * @return ParserOutput or false if the given revsion ID is not found
1562 public function getParserOutput( $oldid = null, User
$user = null ) {
1565 $user = is_null( $user ) ?
$wgUser : $user;
1566 $parserOptions = $this->mPage
->makeParserOptions( $user );
1568 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1572 * Get parser options suitable for rendering the primary article wikitext
1573 * @return ParserOptions|false
1575 public function getParserOptions() {
1577 if ( !$this->mParserOptions
) {
1578 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1580 // Clone to allow modifications of the return value without affecting cache
1581 return clone $this->mParserOptions
;
1585 * Sets the context this Article is executed in
1587 * @param $context IContextSource
1590 public function setContext( $context ) {
1591 $this->mContext
= $context;
1595 * Gets the context this Article is executed in
1597 * @return IContextSource
1600 public function getContext() {
1601 if ( $this->mContext
instanceof IContextSource
) {
1602 return $this->mContext
;
1604 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1605 return RequestContext
::getMain();
1610 * Info about this page
1611 * @deprecated since 1.19
1613 public function info() {
1614 wfDeprecated( __METHOD__
, '1.19' );
1615 Action
::factory( 'info', $this )->show();
1619 * Mark this particular edit/page as patrolled
1620 * @deprecated since 1.18
1622 public function markpatrolled() {
1623 wfDeprecated( __METHOD__
, '1.18' );
1624 Action
::factory( 'markpatrolled', $this )->show();
1628 * Handle action=purge
1629 * @deprecated since 1.19
1631 public function purge() {
1632 return Action
::factory( 'purge', $this )->show();
1636 * Handle action=revert
1637 * @deprecated since 1.19
1639 public function revert() {
1640 wfDeprecated( __METHOD__
, '1.19' );
1641 Action
::factory( 'revert', $this )->show();
1645 * Handle action=rollback
1646 * @deprecated since 1.19
1648 public function rollback() {
1649 wfDeprecated( __METHOD__
, '1.19' );
1650 Action
::factory( 'rollback', $this )->show();
1654 * User-interface handler for the "watch" action.
1655 * Requires Request to pass a token as of 1.18.
1656 * @deprecated since 1.18
1658 public function watch() {
1659 wfDeprecated( __METHOD__
, '1.18' );
1660 Action
::factory( 'watch', $this )->show();
1664 * Add this page to $wgUser's watchlist
1666 * This is safe to be called multiple times
1668 * @return bool true on successful watch operation
1669 * @deprecated since 1.18
1671 public function doWatch() {
1673 wfDeprecated( __METHOD__
, '1.18' );
1674 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1678 * User interface handler for the "unwatch" action.
1679 * Requires Request to pass a token as of 1.18.
1680 * @deprecated since 1.18
1682 public function unwatch() {
1683 wfDeprecated( __METHOD__
, '1.18' );
1684 Action
::factory( 'unwatch', $this )->show();
1688 * Stop watching a page
1689 * @return bool true on successful unwatch
1690 * @deprecated since 1.18
1692 public function doUnwatch() {
1694 wfDeprecated( __METHOD__
, '1.18' );
1695 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1699 * Output a redirect back to the article.
1700 * This is typically used after an edit.
1702 * @deprecated in 1.18; call $wgOut->redirect() directly
1703 * @param $noRedir Boolean: add redirect=no
1704 * @param $sectionAnchor String: section to redirect to, including "#"
1705 * @param $extraQuery String: extra query params
1707 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1708 wfDeprecated( __METHOD__
, '1.18' );
1712 $query = 'redirect=no';
1714 $query .= "&$extraQuery";
1716 $query = $extraQuery;
1719 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1723 * Use PHP's magic __get handler to handle accessing of
1724 * raw WikiPage fields for backwards compatibility.
1726 * @param $fname String Field name
1728 public function __get( $fname ) {
1729 if ( property_exists( $this->mPage
, $fname ) ) {
1730 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1731 return $this->mPage
->$fname;
1733 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1737 * Use PHP's magic __set handler to handle setting of
1738 * raw WikiPage fields for backwards compatibility.
1740 * @param $fname String Field name
1741 * @param $fvalue mixed New value
1743 public function __set( $fname, $fvalue ) {
1744 if ( property_exists( $this->mPage
, $fname ) ) {
1745 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1746 $this->mPage
->$fname = $fvalue;
1747 // Note: extensions may want to toss on new fields
1748 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1749 $this->mPage
->$fname = $fvalue;
1751 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1756 * Use PHP's magic __call handler to transform instance calls to
1757 * WikiPage functions for backwards compatibility.
1759 * @param $fname String Name of called method
1760 * @param $args Array Arguments to the method
1762 public function __call( $fname, $args ) {
1763 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1764 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1765 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1767 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1770 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1773 * @param $limit array
1774 * @param $expiry array
1775 * @param $cascade bool
1776 * @param $reason string
1780 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1781 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1785 * @param $limit array
1786 * @param $reason string
1787 * @param $cascade int
1788 * @param $expiry array
1791 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1792 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1796 * @param $reason string
1797 * @param $suppress bool
1799 * @param $commit bool
1800 * @param $error string
1803 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1804 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1812 * @param $resultDetails
1816 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1818 $user = is_null( $user ) ?
$wgUser : $user;
1819 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1826 * @param $resultDetails
1827 * @param $guser User
1830 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1832 $guser = is_null( $guser ) ?
$wgUser : $guser;
1833 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1837 * @param $hasHistory bool
1840 public function generateReason( &$hasHistory ) {
1841 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1844 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1849 public static function selectFields() {
1850 return WikiPage
::selectFields();
1854 * @param $title Title
1856 public static function onArticleCreate( $title ) {
1857 WikiPage
::onArticleCreate( $title );
1861 * @param $title Title
1863 public static function onArticleDelete( $title ) {
1864 WikiPage
::onArticleDelete( $title );
1868 * @param $title Title
1870 public static function onArticleEdit( $title ) {
1871 WikiPage
::onArticleEdit( $title );
1880 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1881 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );