3 * User interface for page actions.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 use MediaWiki\MediaWikiServices
;
23 use MediaWiki\Revision\MutableRevisionRecord
;
24 use MediaWiki\Revision\RevisionRecord
;
25 use MediaWiki\Revision\SlotRecord
;
28 * Class for viewing MediaWiki article and history.
30 * This maintains WikiPage functions for backwards compatibility.
32 * @todo Move and rewrite code to an Action class
34 * See design.txt for an overview.
35 * Note: edit user interface and cache support functions have been
36 * moved to separate EditPage and HTMLFileCache classes.
38 class Article
implements Page
{
40 * @var IContextSource|null The context this Article is executed in.
41 * If null, RequestContext::getMain() is used.
45 /** @var WikiPage|null The WikiPage object of this instance */
49 * @var ParserOptions|null ParserOptions object for $wgUser articles.
50 * Initialized by getParserOptions by calling $this->mPage->makeParserOptions().
52 public $mParserOptions;
55 * @var Content|null Content of the main slot of $this->mRevision.
56 * @note This variable is read only, setting it has no effect.
57 * Extensions that wish to override the output of Article::view should use a hook.
58 * @todo MCR: Remove in 1.33
59 * @deprecated since 1.32
62 public $mContentObject;
65 * @var bool Is the target revision loaded? Set by fetchRevisionRecord().
67 * @deprecated since 1.32. Whether content has been loaded should not be relevant to
68 * code outside this class.
70 public $mContentLoaded = false;
73 * @var int|null The oldid of the article that was requested to be shown,
74 * 0 for the current revision.
79 /** @var Title|null Title from which we were redirected here, if any. */
80 public $mRedirectedFrom = null;
82 /** @var string|bool URL to redirect to or false if none */
83 public $mRedirectUrl = false;
86 * @var int Revision ID of revision that was loaded.
88 * @deprecated since 1.32, use getRevIdFetched() instead.
90 public $mRevIdFetched = 0;
93 * @var Status|null represents the outcome of fetchRevisionRecord().
94 * $fetchResult->value is the RevisionRecord object, if the operation was successful.
96 * The information in $fetchResult is duplicated by the following deprecated public fields:
97 * $mRevIdFetched, $mContentLoaded. $mRevision (and $mContentObject) also typically duplicate
98 * information of the loaded revision, but may be overwritten by extensions or due to errors.
100 private $fetchResult = null;
103 * @var Revision|null Revision to be shown. Initialized by getOldIDFromRequest()
104 * or fetchContentObject(). Normally loaded from the database, but may be replaced
105 * by an extension, or be a fake representing an error message or some such.
106 * While the output of Article::view is typically based on this revision,
107 * it may be overwritten by error messages or replaced by extensions.
109 public $mRevision = null;
112 * @var ParserOutput|null|false The ParserOutput generated for viewing the page,
113 * initialized by view(). If no ParserOutput could be generated, this is set to false.
114 * @deprecated since 1.32
116 public $mParserOutput = null;
119 * @var bool Whether render() was called. With the way subclasses work
120 * here, there doesn't seem to be any other way to stop calling
121 * OutputPage::enableSectionEditLinks() and still have it work as it did before.
123 protected $viewIsRenderAction = false;
126 * Constructor and clear the article
127 * @param Title $title Reference to a Title object.
128 * @param int|null $oldId Revision ID, null to fetch from request, zero for current
130 public function __construct( Title
$title, $oldId = null ) {
131 $this->mOldId
= $oldId;
132 $this->mPage
= $this->newPage( $title );
136 * @param Title $title
139 protected function newPage( Title
$title ) {
140 return new WikiPage( $title );
144 * Constructor from a page id
145 * @param int $id Article ID to load
146 * @return Article|null
148 public static function newFromID( $id ) {
149 $t = Title
::newFromID( $id );
150 return $t == null ?
null : new static( $t );
154 * Create an Article object of the appropriate class for the given page.
156 * @param Title $title
157 * @param IContextSource $context
160 public static function newFromTitle( $title, IContextSource
$context ) {
161 if ( NS_MEDIA
== $title->getNamespace() ) {
162 // XXX: This should not be here, but where should it go?
163 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
167 Hooks
::run( 'ArticleFromTitle', [ &$title, &$page, $context ] );
169 switch ( $title->getNamespace() ) {
171 $page = new ImagePage( $title );
174 $page = new CategoryPage( $title );
177 $page = new Article( $title );
180 $page->setContext( $context );
186 * Create an Article object of the appropriate class for the given page.
188 * @param WikiPage $page
189 * @param IContextSource $context
192 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
193 $article = self
::newFromTitle( $page->getTitle(), $context );
194 $article->mPage
= $page; // override to keep process cached vars
199 * Get the page this view was redirected from
203 public function getRedirectedFrom() {
204 return $this->mRedirectedFrom
;
208 * Tell the page view functions that this view was redirected
209 * from another page on the wiki.
212 public function setRedirectedFrom( Title
$from ) {
213 $this->mRedirectedFrom
= $from;
217 * Get the title object of the article
219 * @return Title Title object of this page
221 public function getTitle() {
222 return $this->mPage
->getTitle();
226 * Get the WikiPage object of this instance
231 public function getPage() {
238 public function clear() {
239 $this->mContentLoaded
= false;
241 $this->mRedirectedFrom
= null; # Title object if set
242 $this->mRevIdFetched
= 0;
243 $this->mRedirectUrl
= false;
244 $this->mRevision
= null;
245 $this->mContentObject
= null;
246 $this->fetchResult
= null;
248 // TODO hard-deprecate direct access to public fields
250 $this->mPage
->clear();
254 * Returns a Content object representing the pages effective display content,
255 * not necessarily the revision's content!
257 * Note that getContent does not follow redirects anymore.
258 * If you need to fetch redirectable content easily, try
259 * the shortcut in WikiPage::getRedirectTarget()
261 * This function has side effects! Do not use this function if you
262 * only want the real revision text if any.
264 * @deprecated since 1.32, use getRevisionFetched() or fetchRevisionRecord() instead.
270 protected function getContentObject() {
271 if ( $this->mPage
->getId() === 0 ) {
272 $content = $this->getSubstituteContent();
274 $this->fetchContentObject();
275 $content = $this->mContentObject
;
282 * Returns Content object to use when the page does not exist.
286 private function getSubstituteContent() {
287 # If this is a MediaWiki:x message, then load the messages
288 # and return the message value for x.
289 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
290 $text = $this->getTitle()->getDefaultMessageText();
291 if ( $text === false ) {
295 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
297 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
298 $content = new MessageContent( $message, null );
305 * Returns ParserOutput to use when a page does not exist. In some cases, we still want to show
306 * "virtual" content, e.g. in the MediaWiki namespace, or in the File namespace for non-local
309 * @param ParserOptions $options
311 * @return ParserOutput
313 protected function getEmptyPageParserOutput( ParserOptions
$options ) {
314 $content = $this->getSubstituteContent();
316 return $content->getParserOutput( $this->getTitle(), 0, $options );
320 * @see getOldIDFromRequest()
321 * @see getRevIdFetched()
323 * @return int The oldid of the article that is was requested in the constructor or via the
324 * context's WebRequest.
326 public function getOldID() {
327 if ( is_null( $this->mOldId
) ) {
328 $this->mOldId
= $this->getOldIDFromRequest();
331 return $this->mOldId
;
335 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
337 * @return int The old id for the request
339 public function getOldIDFromRequest() {
340 $this->mRedirectUrl
= false;
342 $request = $this->getContext()->getRequest();
343 $oldid = $request->getIntOrNull( 'oldid' );
345 if ( $oldid === null ) {
349 if ( $oldid !== 0 ) {
350 # Load the given revision and check whether the page is another one.
351 # In that case, update this instance to reflect the change.
352 if ( $oldid === $this->mPage
->getLatest() ) {
353 $this->mRevision
= $this->mPage
->getRevision();
355 $this->mRevision
= Revision
::newFromId( $oldid );
356 if ( $this->mRevision
!== null ) {
357 // Revision title doesn't match the page title given?
358 if ( $this->mPage
->getId() != $this->mRevision
->getPage() ) {
359 $function = get_class( $this->mPage
) . '::newFromID';
360 $this->mPage
= $function( $this->mRevision
->getPage() );
366 if ( $request->getVal( 'direction' ) == 'next' ) {
367 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
370 $this->mRevision
= null;
372 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
374 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
375 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
378 $this->mRevision
= null;
382 $this->mRevIdFetched
= $this->mRevision ?
$this->mRevision
->getId() : 0;
388 * Get text content object
389 * Does *NOT* follow redirects.
390 * @todo When is this null?
391 * @deprecated since 1.32, use fetchRevisionRecord() instead.
393 * @note Code that wants to retrieve page content from the database should
394 * use WikiPage::getContent().
396 * @return Content|null|bool
400 protected function fetchContentObject() {
401 if ( !$this->mContentLoaded
) {
402 $this->fetchRevisionRecord();
405 return $this->mContentObject
;
409 * Fetches the revision to work on.
410 * The revision is typically loaded from the database, but may also be a fake representing
411 * an error message or content supplied by an extension. Refer to $this->fetchResult for
412 * the revision actually loaded from the database, and any errors encountered while doing
415 * @return RevisionRecord|null
417 protected function fetchRevisionRecord() {
418 if ( $this->fetchResult
) {
419 return $this->mRevision ?
$this->mRevision
->getRevisionRecord() : null;
422 $this->mContentLoaded
= true;
423 $this->mContentObject
= null;
425 $oldid = $this->getOldID();
427 // $this->mRevision might already be fetched by getOldIDFromRequest()
428 if ( !$this->mRevision
) {
430 $this->mRevision
= $this->mPage
->getRevision();
432 if ( !$this->mRevision
) {
433 wfDebug( __METHOD__
. " failed to find page data for title " .
434 $this->getTitle()->getPrefixedText() . "\n" );
436 // Just for sanity, output for this case is done by showMissingArticle().
437 $this->fetchResult
= Status
::newFatal( 'noarticletext' );
438 $this->applyContentOverride( $this->makeFetchErrorContent() );
442 $this->mRevision
= Revision
::newFromId( $oldid );
444 if ( !$this->mRevision
) {
445 wfDebug( __METHOD__
. " failed to load revision, rev_id $oldid\n" );
447 $this->fetchResult
= Status
::newFatal( 'missing-revision', $oldid );
448 $this->applyContentOverride( $this->makeFetchErrorContent() );
454 $this->mRevIdFetched
= $this->mRevision
->getId();
455 $this->fetchResult
= Status
::newGood( $this->mRevision
);
457 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $this->getContext()->getUser() ) ) {
458 wfDebug( __METHOD__
. " failed to retrieve content of revision " .
459 $this->mRevision
->getId() . "\n" );
461 // Just for sanity, output for this case is done by showDeletedRevisionHeader().
462 $this->fetchResult
= Status
::newFatal( 'rev-deleted-text-permission' );
463 $this->applyContentOverride( $this->makeFetchErrorContent() );
467 if ( Hooks
::isRegistered( 'ArticleAfterFetchContentObject' ) ) {
468 $contentObject = $this->mRevision
->getContent(
469 Revision
::FOR_THIS_USER
,
470 $this->getContext()->getUser()
473 $hookContentObject = $contentObject;
475 // Avoid PHP 7.1 warning of passing $this by reference
476 $articlePage = $this;
479 'ArticleAfterFetchContentObject',
480 [ &$articlePage, &$hookContentObject ],
484 if ( $hookContentObject !== $contentObject ) {
485 // A hook handler is trying to override the content
486 $this->applyContentOverride( $hookContentObject );
491 $this->mContentObject
= $this->mRevision
->getContent(
492 Revision
::FOR_THIS_USER
,
493 $this->getContext()->getUser()
496 return $this->mRevision
->getRevisionRecord();
500 * Returns a Content object representing any error in $this->fetchContent, or null
501 * if there is no such error.
503 * @return Content|null
505 private function makeFetchErrorContent() {
506 if ( !$this->fetchResult ||
$this->fetchResult
->isOK() ) {
510 return new MessageContent( $this->fetchResult
->getMessage() );
514 * Applies a content override by constructing a fake Revision object and assigning
515 * it to mRevision. The fake revision will not have a user, timestamp or summary set.
517 * This mechanism exists mainly to accommodate extensions that use the
518 * ArticleAfterFetchContentObject. Once that hook has been removed, there should no longer
519 * be a need for a fake revision object. fetchRevisionRecord() presently also uses this mechanism
520 * to report errors, but that could be changed to use $this->fetchResult instead.
522 * @param Content $override Content to be used instead of the actual page content,
523 * coming from an extension or representing an error message.
525 private function applyContentOverride( Content
$override ) {
526 // Construct a fake revision
527 $rev = new MutableRevisionRecord( $this->getTitle() );
528 $rev->setContent( SlotRecord
::MAIN
, $override );
530 $this->mRevision
= new Revision( $rev );
533 $this->mContentObject
= $override;
537 * Returns true if the currently-referenced revision is the current edit
538 * to this page (and it exists).
541 public function isCurrent() {
542 # If no oldid, this is the current version.
543 if ( $this->getOldID() == 0 ) {
547 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
551 * Get the fetched Revision object depending on request parameters or null
552 * on failure. The revision returned may be a fake representing an error message or
553 * wrapping content supplied by an extension. Refer to $this->fetchResult for the
554 * revision actually loaded from the database.
557 * @return Revision|null
559 public function getRevisionFetched() {
560 $this->fetchRevisionRecord();
562 if ( $this->fetchResult
->isOK() ) {
563 return $this->mRevision
;
568 * Use this to fetch the rev ID used on page views
570 * Before fetchRevisionRecord was called, this returns the page's latest revision,
571 * regardless of what getOldID() returns.
573 * @return int Revision ID of last article revision
575 public function getRevIdFetched() {
576 if ( $this->fetchResult
&& $this->fetchResult
->isOK() ) {
577 return $this->fetchResult
->value
->getId();
579 return $this->mPage
->getLatest();
584 * This is the default action of the index.php entry point: just view the
585 * page of the given title.
587 public function view() {
588 global $wgUseFileCache, $wgDebugToolbar;
590 # Get variables from query string
591 # As side effect this will load the revision and update the title
592 # in a revision ID is passed in the request, so this should remain
593 # the first call of this method even if $oldid is used way below.
594 $oldid = $this->getOldID();
596 $user = $this->getContext()->getUser();
597 # Another whitelist check in case getOldID() is altering the title
598 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
599 if ( count( $permErrors ) ) {
600 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
601 throw new PermissionsError( 'read', $permErrors );
604 $outputPage = $this->getContext()->getOutput();
605 # getOldID() may as well want us to redirect somewhere else
606 if ( $this->mRedirectUrl
) {
607 $outputPage->redirect( $this->mRedirectUrl
);
608 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
613 # If we got diff in the query, we want to see a diff page instead of the article.
614 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
615 wfDebug( __METHOD__
. ": showing diff page\n" );
616 $this->showDiffPage();
621 # Set page title (may be overridden by DISPLAYTITLE)
622 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
624 $outputPage->setArticleFlag( true );
625 # Allow frames by default
626 $outputPage->allowClickjacking();
628 $parserCache = MediaWikiServices
::getInstance()->getParserCache();
630 $parserOptions = $this->getParserOptions();
632 # Render printable version, use printable version cache
633 if ( $outputPage->isPrintable() ) {
634 $parserOptions->setIsPrintable( true );
635 $poOptions['enableSectionEditLinks'] = false;
636 } elseif ( $this->viewIsRenderAction
637 ||
!$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user )
639 $poOptions['enableSectionEditLinks'] = false;
642 # Try client and file cache
643 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
644 # Try to stream the output from file cache
645 if ( $wgUseFileCache && $this->tryFileCache() ) {
646 wfDebug( __METHOD__
. ": done file cache\n" );
647 # tell wgOut that output is taken care of
648 $outputPage->disable();
649 $this->mPage
->doViewUpdates( $user, $oldid );
655 # Should the parser cache be used?
656 $useParserCache = $this->mPage
->shouldCheckParserCache( $parserOptions, $oldid );
657 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
658 if ( $user->getStubThreshold() ) {
659 MediaWikiServices
::getInstance()->getStatsdDataFactory()->increment( 'pcache_miss_stub' );
662 $this->showRedirectedFromHeader();
663 $this->showNamespaceHeader();
665 # Iterate through the possible ways of constructing the output text.
666 # Keep going until $outputDone is set, or we run out of things to do.
669 $this->mParserOutput
= false;
671 while ( !$outputDone && ++
$pass ) {
674 // Avoid PHP 7.1 warning of passing $this by reference
675 $articlePage = $this;
676 Hooks
::run( 'ArticleViewHeader', [ &$articlePage, &$outputDone, &$useParserCache ] );
679 # Early abort if the page doesn't exist
680 if ( !$this->mPage
->exists() ) {
681 wfDebug( __METHOD__
. ": showing missing article\n" );
682 $this->showMissingArticle();
683 $this->mPage
->doViewUpdates( $user );
687 # Try the parser cache
688 if ( $useParserCache ) {
689 $this->mParserOutput
= $parserCache->get( $this->mPage
, $parserOptions );
691 if ( $this->mParserOutput
!== false ) {
693 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
694 $this->setOldSubtitle( $oldid );
696 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
698 $outputPage->addParserOutput( $this->mParserOutput
, $poOptions );
699 # Ensure that UI elements requiring revision ID have
700 # the correct version information.
701 $outputPage->setRevisionId( $this->mPage
->getLatest() );
702 # Preload timestamp to avoid a DB hit
703 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
704 if ( $cachedTimestamp !== null ) {
705 $outputPage->setRevisionTimestamp( $cachedTimestamp );
706 $this->mPage
->setTimestamp( $cachedTimestamp );
713 # Are we looking at an old revision
714 $rev = $this->fetchRevisionRecord();
715 if ( $oldid && $this->fetchResult
->isOK() ) {
716 $this->setOldSubtitle( $oldid );
718 if ( !$this->showDeletedRevisionHeader() ) {
719 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
724 # Ensure that UI elements requiring revision ID have
725 # the correct version information.
726 $outputPage->setRevisionId( $this->getRevIdFetched() );
727 # Preload timestamp to avoid a DB hit
728 $outputPage->setRevisionTimestamp( $this->mPage
->getTimestamp() );
730 # Pages containing custom CSS or JavaScript get special treatment
731 if ( $this->getTitle()->isSiteConfigPage() ||
$this->getTitle()->isUserConfigPage() ) {
732 $dir = $this->getContext()->getLanguage()->getDir();
733 $lang = $this->getContext()->getLanguage()->getHtmlCode();
735 $outputPage->wrapWikiMsg(
736 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
739 } elseif ( !Hooks
::run( 'ArticleRevisionViewCustom', [
746 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
747 // Allow extensions do their own custom view for certain pages
749 } elseif ( !Hooks
::run( 'ArticleContentViewCustom',
750 [ $this->fetchContentObject(), $this->getTitle(), $outputPage ], '1.32' )
752 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
753 // Allow extensions do their own custom view for certain pages
758 # Run the parse, protected by a pool counter
759 wfDebug( __METHOD__
. ": doing uncached parse\n" );
761 $rev = $this->fetchRevisionRecord();
765 $poolArticleView = new PoolWorkArticleView(
768 $this->getRevIdFetched(),
771 // permission checking was done earlier via showDeletedRevisionHeader()
774 $ok = $poolArticleView->execute();
775 $error = $poolArticleView->getError();
776 $this->mParserOutput
= $poolArticleView->getParserOutput() ?
: null;
778 # Don't cache a dirty ParserOutput object
779 if ( $poolArticleView->getIsDirty() ) {
780 $outputPage->setCdnMaxage( 0 );
781 $outputPage->addHTML( "<!-- parser cache is expired, " .
782 "sending anyway due to pool overload-->\n" );
790 $outputPage->clearHTML(); // for release() errors
791 $outputPage->enableClientCache( false );
792 $outputPage->setRobotPolicy( 'noindex,nofollow' );
794 $errortext = $error->getWikiText( false, 'view-pool-error' );
795 $outputPage->wrapWikiTextAsInterface( 'errorbox', $errortext );
797 # Connection or timeout error
801 if ( $this->mParserOutput
) {
802 $outputPage->addParserOutput( $this->mParserOutput
, $poOptions );
805 if ( $rev && $this->getRevisionRedirectTarget( $rev ) ) {
806 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
807 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
812 # Should be unreachable, but just in case...
818 // Get the ParserOutput actually *displayed* here.
819 // Note that $this->mParserOutput is the *current*/oldid version output.
820 // Note that the ArticleViewHeader hook is allowed to set $outputDone to a
821 // ParserOutput instance.
822 $pOutput = ( $outputDone instanceof ParserOutput
)
823 ?
$outputDone // object fetched by hook
824 : ( $this->mParserOutput ?
: null ); // ParserOutput or null, avoid false
826 # Adjust title for main page & pages with displaytitle
828 $this->adjustDisplayTitle( $pOutput );
831 # For the main page, overwrite the <title> element with the con-
832 # tents of 'pagetitle-view-mainpage' instead of the default (if
834 # This message always exists because it is in the i18n files
835 if ( $this->getTitle()->isMainPage() ) {
836 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
837 if ( !$msg->isDisabled() ) {
838 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
842 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
843 # This could use getTouched(), but that could be scary for major template edits.
844 $outputPage->adaptCdnTTL( $this->mPage
->getTimestamp(), IExpiringStore
::TTL_DAY
);
846 # Check for any __NOINDEX__ tags on the page using $pOutput
847 $policy = $this->getRobotPolicy( 'view', $pOutput ?
: null );
848 $outputPage->setIndexPolicy( $policy['index'] );
849 $outputPage->setFollowPolicy( $policy['follow'] ); // FIXME: test this
851 $this->showViewFooter();
852 $this->mPage
->doViewUpdates( $user, $oldid ); // FIXME: test this
854 # Load the postEdit module if the user just saved this revision
855 # See also EditPage::setPostEditCookie
856 $request = $this->getContext()->getRequest();
857 $cookieKey = EditPage
::POST_EDIT_COOKIE_KEY_PREFIX
. $this->getRevIdFetched();
858 $postEdit = $request->getCookie( $cookieKey );
860 # Clear the cookie. This also prevents caching of the response.
861 $request->response()->clearCookie( $cookieKey );
862 $outputPage->addJsConfigVars( 'wgPostEdit', $postEdit );
863 $outputPage->addModules( 'mediawiki.action.view.postEdit' ); // FIXME: test this
868 * @param RevisionRecord $revision
871 private function getRevisionRedirectTarget( RevisionRecord
$revision ) {
872 // TODO: find a *good* place for the code that determines the redirect target for
874 // NOTE: Use main slot content. Compare code in DerivedPageDataUpdater::revisionIsRedirect.
875 $content = $revision->getContent( SlotRecord
::MAIN
);
876 return $content ?
$content->getRedirectTarget() : null;
880 * Adjust title for pages with displaytitle, -{T|}- or language conversion
881 * @param ParserOutput $pOutput
883 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
884 $out = $this->getContext()->getOutput();
886 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
887 $titleText = $pOutput->getTitleText();
888 if ( strval( $titleText ) !== '' ) {
889 $out->setPageTitle( $titleText );
890 $out->setDisplayTitle( $titleText );
895 * Show a diff page according to current request variables. For use within
896 * Article::view() only, other callers should use the DifferenceEngine class.
898 protected function showDiffPage() {
899 $request = $this->getContext()->getRequest();
900 $user = $this->getContext()->getUser();
901 $diff = $request->getVal( 'diff' );
902 $rcid = $request->getVal( 'rcid' );
903 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
904 $purge = $request->getVal( 'action' ) == 'purge';
905 $unhide = $request->getInt( 'unhide' ) == 1;
906 $oldid = $this->getOldID();
908 $rev = $this->getRevisionFetched();
911 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
912 $msg = $this->getContext()->msg( 'difference-missing-revision' )
916 $this->getContext()->getOutput()->addHTML( $msg );
920 $contentHandler = $rev->getContentHandler();
921 $de = $contentHandler->createDifferenceEngine(
930 // DifferenceEngine directly fetched the revision:
931 $this->mRevIdFetched
= $de->getNewid();
932 $de->showDiffPage( $diffOnly );
934 // Run view updates for the newer revision being diffed (and shown
935 // below the diff if not $diffOnly).
936 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
937 // New can be false, convert it to 0 - this conveniently means the latest revision
938 $this->mPage
->doViewUpdates( $user, (int)$new );
942 * Get the robot policy to be used for the current view
943 * @param string $action The action= GET parameter
944 * @param ParserOutput|null $pOutput
945 * @return array The policy that should be set
946 * @todo actions other than 'view'
948 public function getRobotPolicy( $action, ParserOutput
$pOutput = null ) {
949 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
951 $ns = $this->getTitle()->getNamespace();
953 # Don't index user and user talk pages for blocked users (T13443)
954 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
955 $specificTarget = null;
957 $titleText = $this->getTitle()->getText();
958 if ( IP
::isValid( $titleText ) ) {
959 $vagueTarget = $titleText;
961 $specificTarget = $titleText;
963 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
965 'index' => 'noindex',
966 'follow' => 'nofollow'
971 if ( $this->mPage
->getId() === 0 ||
$this->getOldID() ) {
972 # Non-articles (special pages etc), and old revisions
974 'index' => 'noindex',
975 'follow' => 'nofollow'
977 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
978 # Discourage indexing of printable versions, but encourage following
980 'index' => 'noindex',
983 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
984 # For ?curid=x urls, disallow indexing
986 'index' => 'noindex',
991 # Otherwise, construct the policy based on the various config variables.
992 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
994 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
995 # Honour customised robot policies for this namespace
996 $policy = array_merge(
998 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
1001 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
1002 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1003 # a final sanity check that we have really got the parser output.
1004 $policy = array_merge(
1006 [ 'index' => $pOutput->getIndexPolicy() ]
1010 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
1011 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1012 $policy = array_merge(
1014 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
1022 * Converts a String robot policy into an associative array, to allow
1023 * merging of several policies using array_merge().
1024 * @param array|string $policy Returns empty array on null/false/'', transparent
1025 * to already-converted arrays, converts string.
1026 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
1028 public static function formatRobotPolicy( $policy ) {
1029 if ( is_array( $policy ) ) {
1031 } elseif ( !$policy ) {
1035 $policy = explode( ',', $policy );
1036 $policy = array_map( 'trim', $policy );
1039 foreach ( $policy as $var ) {
1040 if ( in_array( $var, [ 'index', 'noindex' ] ) ) {
1041 $arr['index'] = $var;
1042 } elseif ( in_array( $var, [ 'follow', 'nofollow' ] ) ) {
1043 $arr['follow'] = $var;
1051 * If this request is a redirect view, send "redirected from" subtitle to
1052 * the output. Returns true if the header was needed, false if this is not
1053 * a redirect view. Handles both local and remote redirects.
1057 public function showRedirectedFromHeader() {
1058 global $wgRedirectSources;
1060 $context = $this->getContext();
1061 $outputPage = $context->getOutput();
1062 $request = $context->getRequest();
1063 $rdfrom = $request->getVal( 'rdfrom' );
1065 // Construct a URL for the current page view, but with the target title
1066 $query = $request->getValues();
1067 unset( $query['rdfrom'] );
1068 unset( $query['title'] );
1069 if ( $this->getTitle()->isRedirect() ) {
1070 // Prevent double redirects
1071 $query['redirect'] = 'no';
1073 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
1075 if ( isset( $this->mRedirectedFrom
) ) {
1076 // Avoid PHP 7.1 warning of passing $this by reference
1077 $articlePage = $this;
1079 // This is an internally redirected page view.
1080 // We'll need a backlink to the source page for navigation.
1081 if ( Hooks
::run( 'ArticleViewRedirect', [ &$articlePage ] ) ) {
1082 $redir = Linker
::linkKnown(
1083 $this->mRedirectedFrom
,
1086 [ 'redirect' => 'no' ]
1089 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1090 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1093 // Add the script to update the displayed URL and
1094 // set the fragment if one was specified in the redirect
1095 $outputPage->addJsConfigVars( [
1096 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1098 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1100 // Add a <link rel="canonical"> tag
1101 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
1103 // Tell the output object that the user arrived at this article through a redirect
1104 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1108 } elseif ( $rdfrom ) {
1109 // This is an externally redirected view, from some other wiki.
1110 // If it was reported from a trusted site, supply a backlink.
1111 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1112 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1113 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1114 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1117 // Add the script to update the displayed URL
1118 $outputPage->addJsConfigVars( [
1119 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1121 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1131 * Show a header specific to the namespace currently being viewed, like
1132 * [[MediaWiki:Talkpagetext]]. For Article::view().
1134 public function showNamespaceHeader() {
1135 if ( $this->getTitle()->isTalkPage() ) {
1136 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1137 $this->getContext()->getOutput()->wrapWikiMsg(
1138 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1139 [ 'talkpageheader' ]
1146 * Show the footer section of an ordinary page view
1148 public function showViewFooter() {
1149 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1150 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1151 && IP
::isValid( $this->getTitle()->getText() )
1153 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1156 // Show a footer allowing the user to patrol the shown revision or page if possible
1157 $patrolFooterShown = $this->showPatrolFooter();
1159 Hooks
::run( 'ArticleViewFooter', [ $this, $patrolFooterShown ] );
1163 * If patrol is possible, output a patrol UI box. This is called from the
1164 * footer section of ordinary page views. If patrol is not possible or not
1165 * desired, does nothing.
1166 * Side effect: When the patrol link is build, this method will call
1167 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1171 public function showPatrolFooter() {
1172 global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol;
1174 // Allow hooks to decide whether to not output this at all
1175 if ( !Hooks
::run( 'ArticleShowPatrolFooter', [ $this ] ) ) {
1179 $outputPage = $this->getContext()->getOutput();
1180 $user = $this->getContext()->getUser();
1181 $title = $this->getTitle();
1184 if ( !$title->quickUserCan( 'patrol', $user )
1185 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol
1186 ||
( $wgUseFilePatrol && $title->inNamespace( NS_FILE
) ) )
1188 // Patrolling is disabled or the user isn't allowed to
1192 if ( $this->mRevision
1193 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1195 // The current revision is already older than what could be in the RC table
1196 // 6h tolerance because the RC might not be cleaned out regularly
1200 // Check for cached results
1201 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1202 $key = $cache->makeKey( 'unpatrollable-page', $title->getArticleID() );
1203 if ( $cache->get( $key ) ) {
1207 $dbr = wfGetDB( DB_REPLICA
);
1208 $oldestRevisionTimestamp = $dbr->selectField(
1210 'MIN( rev_timestamp )',
1211 [ 'rev_page' => $title->getArticleID() ],
1215 // New page patrol: Get the timestamp of the oldest revison which
1216 // the revision table holds for the given page. Then we look
1217 // whether it's within the RC lifespan and if it is, we try
1218 // to get the recentchanges row belonging to that entry
1219 // (with rc_new = 1).
1220 $recentPageCreation = false;
1221 if ( $oldestRevisionTimestamp
1222 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1224 // 6h tolerance because the RC might not be cleaned out regularly
1225 $recentPageCreation = true;
1226 $rc = RecentChange
::newFromConds(
1229 'rc_timestamp' => $oldestRevisionTimestamp,
1230 'rc_namespace' => $title->getNamespace(),
1231 'rc_cur_id' => $title->getArticleID()
1236 // Use generic patrol message for new pages
1237 $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
1241 // File patrol: Get the timestamp of the latest upload for this page,
1242 // check whether it is within the RC lifespan and if it is, we try
1243 // to get the recentchanges row belonging to that entry
1244 // (with rc_type = RC_LOG, rc_log_type = upload).
1245 $recentFileUpload = false;
1246 if ( ( !$rc ||
$rc->getAttribute( 'rc_patrolled' ) ) && $wgUseFilePatrol
1247 && $title->getNamespace() === NS_FILE
) {
1248 // Retrieve timestamp of most recent upload
1249 $newestUploadTimestamp = $dbr->selectField(
1251 'MAX( img_timestamp )',
1252 [ 'img_name' => $title->getDBkey() ],
1255 if ( $newestUploadTimestamp
1256 && RecentChange
::isInRCLifespan( $newestUploadTimestamp, 21600 )
1258 // 6h tolerance because the RC might not be cleaned out regularly
1259 $recentFileUpload = true;
1260 $rc = RecentChange
::newFromConds(
1262 'rc_type' => RC_LOG
,
1263 'rc_log_type' => 'upload',
1264 'rc_timestamp' => $newestUploadTimestamp,
1265 'rc_namespace' => NS_FILE
,
1266 'rc_cur_id' => $title->getArticleID()
1271 // Use patrol message specific to files
1272 $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
1277 if ( !$recentPageCreation && !$recentFileUpload ) {
1278 // Page creation and latest upload (for files) is too old to be in RC
1280 // We definitely can't patrol so cache the information
1281 // When a new file version is uploaded, the cache is cleared
1282 $cache->set( $key, '1' );
1288 // Don't cache: This can be hit if the page gets accessed very fast after
1289 // its creation / latest upload or in case we have high replica DB lag. In case
1290 // the revision is too old, we will already return above.
1294 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1295 // Patrolled RC entry around
1297 // Cache the information we gathered above in case we can't patrol
1298 // Don't cache in case we can patrol as this could change
1299 $cache->set( $key, '1' );
1304 if ( $rc->getPerformer()->equals( $user ) ) {
1305 // Don't show a patrol link for own creations/uploads. If the user could
1306 // patrol them, they already would be patrolled
1310 $outputPage->preventClickjacking();
1311 if ( $user->isAllowed( 'writeapi' ) ) {
1312 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1315 $link = Linker
::linkKnown(
1317 $markPatrolledMsg->escaped(),
1320 'action' => 'markpatrolled',
1321 'rcid' => $rc->getAttribute( 'rc_id' ),
1325 $outputPage->addHTML(
1326 "<div class='patrollink' data-mw='interface'>" .
1327 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1335 * Purge the cache used to check if it is worth showing the patrol footer
1336 * For example, it is done during re-uploads when file patrol is used.
1337 * @param int $articleID ID of the article to purge
1340 public static function purgePatrolFooterCache( $articleID ) {
1341 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1342 $cache->delete( $cache->makeKey( 'unpatrollable-page', $articleID ) );
1346 * Show the error text for a missing article. For articles in the MediaWiki
1347 * namespace, show the default message text. To be called from Article::view().
1349 public function showMissingArticle() {
1350 global $wgSend404Code;
1352 $outputPage = $this->getContext()->getOutput();
1353 // Whether the page is a root user page of an existing user (but not a subpage)
1354 $validUserPage = false;
1356 $title = $this->getTitle();
1358 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1359 if ( $title->getNamespace() == NS_USER
1360 ||
$title->getNamespace() == NS_USER_TALK
1362 $rootPart = explode( '/', $title->getText() )[0];
1363 $user = User
::newFromName( $rootPart, false /* allow IP users */ );
1364 $ip = User
::isIP( $rootPart );
1365 $block = Block
::newFromTarget( $user, $user );
1367 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1368 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1369 [ 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ] );
1371 !is_null( $block ) &&
1372 $block->getType() != Block
::TYPE_AUTO
&&
1373 ( $block->isSitewide() ||
$user->isBlockedFrom( $title ) )
1375 // Show log extract if the user is sitewide blocked or is partially
1376 // blocked and not allowed to edit their user page or user talk page
1377 LogEventsList
::showLogExtract(
1380 MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget(),
1384 'showIfEmpty' => false,
1386 'blocked-notice-logextract',
1387 $user->getName() # Support GENDER in notice
1391 $validUserPage = !$title->isSubpage();
1393 $validUserPage = !$title->isSubpage();
1397 Hooks
::run( 'ShowMissingArticle', [ $this ] );
1399 # Show delete and move logs if there were any such events.
1400 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1401 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1402 $cache = MediaWikiServices
::getInstance()->getMainObjectStash();
1403 $key = $cache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) );
1404 $loggedIn = $this->getContext()->getUser()->isLoggedIn();
1405 $sessionExists = $this->getContext()->getRequest()->getSession()->isPersistent();
1406 if ( $loggedIn ||
$cache->get( $key ) ||
$sessionExists ) {
1407 $logTypes = [ 'delete', 'move', 'protect' ];
1409 $dbr = wfGetDB( DB_REPLICA
);
1411 $conds = [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ];
1412 // Give extensions a chance to hide their (unrelated) log entries
1413 Hooks
::run( 'Article::MissingArticleConditions', [ &$conds, $logTypes ] );
1414 LogEventsList
::showLogExtract(
1422 'showIfEmpty' => false,
1423 'msgKey' => [ $loggedIn ||
$sessionExists
1424 ?
'moveddeleted-notice'
1425 : 'moveddeleted-notice-recent'
1431 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1432 // If there's no backing content, send a 404 Not Found
1433 // for better machine handling of broken links.
1434 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1437 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1438 $policy = $this->getRobotPolicy( 'view' );
1439 $outputPage->setIndexPolicy( $policy['index'] );
1440 $outputPage->setFollowPolicy( $policy['follow'] );
1442 $hookResult = Hooks
::run( 'BeforeDisplayNoArticleText', [ $this ] );
1444 if ( !$hookResult ) {
1448 # Show error message
1449 $oldid = $this->getOldID();
1450 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI
&& $title->hasSourceText() ) {
1451 // use fake Content object for system message
1452 $parserOptions = ParserOptions
::newCanonical( 'canonical' );
1453 $outputPage->addParserOutput( $this->getEmptyPageParserOutput( $parserOptions ) );
1456 $text = wfMessage( 'missing-revision', $oldid )->plain();
1457 } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
1458 && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
1460 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1461 $text = wfMessage( $message )->plain();
1463 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1466 $dir = $this->getContext()->getLanguage()->getDir();
1467 $lang = $this->getContext()->getLanguage()->getHtmlCode();
1468 $outputPage->addWikiTextAsInterface( Xml
::openElement( 'div', [
1469 'class' => "noarticletext mw-content-$dir",
1472 ] ) . "\n$text\n</div>" );
1477 * If the revision requested for view is deleted, check permissions.
1478 * Send either an error message or a warning header to the output.
1480 * @return bool True if the view is allowed, false if not.
1482 public function showDeletedRevisionHeader() {
1483 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1488 $outputPage = $this->getContext()->getOutput();
1489 $user = $this->getContext()->getUser();
1490 // If the user is not allowed to see it...
1491 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1492 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1493 'rev-deleted-text-permission' );
1496 // If the user needs to confirm that they want to see it...
1497 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1498 # Give explanation and add a link to view the revision...
1499 $oldid = intval( $this->getOldID() );
1500 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1501 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1502 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1503 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1507 // We are allowed to see...
1509 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1510 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1511 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1518 * Generate the navigation links when browsing through an article revisions
1519 * It shows the information as:
1520 * Revision as of \<date\>; view current revision
1521 * \<- Previous version | Next Version -\>
1523 * @param int $oldid Revision ID of this article revision
1525 public function setOldSubtitle( $oldid = 0 ) {
1526 // Avoid PHP 7.1 warning of passing $this by reference
1527 $articlePage = $this;
1529 if ( !Hooks
::run( 'DisplayOldSubtitle', [ &$articlePage, &$oldid ] ) ) {
1533 $context = $this->getContext();
1534 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1536 # Cascade unhide param in links for easy deletion browsing
1539 $extraParams['unhide'] = 1;
1542 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1543 $revision = $this->mRevision
;
1545 $revision = Revision
::newFromId( $oldid );
1548 $timestamp = $revision->getTimestamp();
1550 $current = ( $oldid == $this->mPage
->getLatest() );
1551 $language = $context->getLanguage();
1552 $user = $context->getUser();
1554 $td = $language->userTimeAndDate( $timestamp, $user );
1555 $tddate = $language->userDate( $timestamp, $user );
1556 $tdtime = $language->userTime( $timestamp, $user );
1558 # Show user links if allowed to see them. If hidden, then show them only if requested...
1559 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1561 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1562 ?
'revision-info-current'
1565 $outputPage = $context->getOutput();
1566 $revisionInfo = "<div id=\"mw-{$infomsg}\">" .
1567 $context->msg( $infomsg, $td )
1568 ->rawParams( $userlinks )
1569 ->params( $revision->getId(), $tddate, $tdtime, $revision->getUserText() )
1570 ->rawParams( Linker
::revComment( $revision, true, true ) )
1575 ?
$context->msg( 'currentrevisionlink' )->escaped()
1576 : Linker
::linkKnown(
1578 $context->msg( 'currentrevisionlink' )->escaped(),
1583 ?
$context->msg( 'diff' )->escaped()
1584 : Linker
::linkKnown(
1586 $context->msg( 'diff' )->escaped(),
1593 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1595 ? Linker
::linkKnown(
1597 $context->msg( 'previousrevision' )->escaped(),
1600 'direction' => 'prev',
1604 : $context->msg( 'previousrevision' )->escaped();
1606 ? Linker
::linkKnown(
1608 $context->msg( 'diff' )->escaped(),
1615 : $context->msg( 'diff' )->escaped();
1616 $nextlink = $current
1617 ?
$context->msg( 'nextrevision' )->escaped()
1618 : Linker
::linkKnown(
1620 $context->msg( 'nextrevision' )->escaped(),
1623 'direction' => 'next',
1627 $nextdiff = $current
1628 ?
$context->msg( 'diff' )->escaped()
1629 : Linker
::linkKnown(
1631 $context->msg( 'diff' )->escaped(),
1639 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1640 if ( $cdel !== '' ) {
1644 // the outer div is need for styling the revision info and nav in MobileFrontend
1645 $outputPage->addSubtitle( "<div class=\"mw-revision\">" . $revisionInfo .
1646 "<div id=\"mw-revision-nav\">" . $cdel .
1647 $context->msg( 'revision-nav' )->rawParams(
1648 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1649 )->escaped() . "</div></div>" );
1653 * Return the HTML for the top of a redirect page
1655 * Chances are you should just be using the ParserOutput from
1656 * WikitextContent::getParserOutput instead of calling this for redirects.
1658 * @param Title|array $target Destination(s) to redirect
1659 * @param bool $appendSubtitle [optional]
1660 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1661 * @return string Containing HTML with redirect link
1663 * @deprecated since 1.30
1665 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1666 $lang = $this->getTitle()->getPageLanguage();
1667 $out = $this->getContext()->getOutput();
1668 if ( $appendSubtitle ) {
1669 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1671 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1672 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1676 * Return the HTML for the top of a redirect page
1678 * Chances are you should just be using the ParserOutput from
1679 * WikitextContent::getParserOutput instead of calling this for redirects.
1682 * @param Language $lang
1683 * @param Title|array $target Destination(s) to redirect
1684 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1685 * @return string Containing HTML with redirect link
1687 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1688 if ( !is_array( $target ) ) {
1689 $target = [ $target ];
1692 $html = '<ul class="redirectText">';
1693 /** @var Title $title */
1694 foreach ( $target as $title ) {
1695 $html .= '<li>' . Linker
::link(
1697 htmlspecialchars( $title->getFullText() ),
1699 // Make sure wiki page redirects are not followed
1700 $title->isRedirect() ?
[ 'redirect' => 'no' ] : [],
1701 ( $forceKnown ?
[ 'known', 'noclasses' ] : [] )
1706 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1708 return '<div class="redirectMsg">' .
1709 '<p>' . $redirectToText . '</p>' .
1715 * Adds help link with an icon via page indicators.
1716 * Link target can be overridden by a local message containing a wikilink:
1717 * the message key is: 'namespace-' + namespace number + '-helppage'.
1718 * @param string $to Target MediaWiki.org page title or encoded URL.
1719 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1722 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1724 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1727 $out = $this->getContext()->getOutput();
1728 if ( !$msg->isDisabled() ) {
1729 $helpUrl = Skin
::makeUrl( $msg->plain() );
1730 $out->addHelpLink( $helpUrl, true );
1732 $out->addHelpLink( $to, $overrideBaseUrl );
1737 * Handle action=render
1739 public function render() {
1740 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1741 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1742 // We later set 'enableSectionEditLinks=false' based on this; also used by ImagePage
1743 $this->viewIsRenderAction
= true;
1748 * action=protect handler
1750 public function protect() {
1751 $form = new ProtectionForm( $this );
1756 * action=unprotect handler (alias)
1758 public function unprotect() {
1763 * UI entry point for page deletion
1765 public function delete() {
1766 # This code desperately needs to be totally rewritten
1768 $title = $this->getTitle();
1769 $context = $this->getContext();
1770 $user = $context->getUser();
1771 $request = $context->getRequest();
1774 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1775 if ( count( $permissionErrors ) ) {
1776 throw new PermissionsError( 'delete', $permissionErrors );
1779 # Read-only check...
1780 if ( wfReadOnly() ) {
1781 throw new ReadOnlyError
;
1784 # Better double-check that it hasn't been deleted yet!
1785 $this->mPage
->loadPageData(
1786 $request->wasPosted() ? WikiPage
::READ_LATEST
: WikiPage
::READ_NORMAL
1788 if ( !$this->mPage
->exists() ) {
1789 $deleteLogPage = new LogPage( 'delete' );
1790 $outputPage = $context->getOutput();
1791 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1792 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1793 [ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ]
1795 $outputPage->addHTML(
1796 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1798 LogEventsList
::showLogExtract(
1807 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1808 $deleteReason = $request->getText( 'wpReason' );
1810 if ( $deleteReasonList == 'other' ) {
1811 $reason = $deleteReason;
1812 } elseif ( $deleteReason != '' ) {
1813 // Entry from drop down menu + additional comment
1814 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1815 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1817 $reason = $deleteReasonList;
1820 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1821 [ 'delete', $this->getTitle()->getPrefixedText() ] )
1823 # Flag to hide all contents of the archived revisions
1824 $suppress = $request->getCheck( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1826 $this->doDelete( $reason, $suppress );
1828 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1833 // Generate deletion reason
1834 $hasHistory = false;
1837 $reason = $this->generateReason( $hasHistory );
1838 } catch ( Exception
$e ) {
1839 # if a page is horribly broken, we still want to be able to
1840 # delete it. So be lenient about errors here.
1841 wfDebug( "Error while building auto delete summary: $e" );
1846 // If the page has a history, insert a warning
1847 if ( $hasHistory ) {
1848 $title = $this->getTitle();
1850 // The following can use the real revision count as this is only being shown for users
1851 // that can delete this page.
1852 // This, as a side-effect, also makes sure that the following query isn't being run for
1853 // pages with a larger history, unless the user has the 'bigdelete' right
1854 // (and is about to delete this page).
1855 $dbr = wfGetDB( DB_REPLICA
);
1856 $revisions = $edits = (int)$dbr->selectField(
1859 [ 'rev_page' => $title->getArticleID() ],
1863 // @todo i18n issue/patchwork message
1864 $context->getOutput()->addHTML(
1865 '<strong class="mw-delete-warning-revisions">' .
1866 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1867 $context->msg( 'word-separator' )->escaped() . Linker
::linkKnown( $title,
1868 $context->msg( 'history' )->escaped(),
1870 [ 'action' => 'history' ] ) .
1874 if ( $title->isBigDeletion() ) {
1875 global $wgDeleteRevisionsLimit;
1876 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1878 'delete-warning-toobig',
1879 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1885 $this->confirmDelete( $reason );
1889 * Output deletion confirmation dialog
1890 * @todo Move to another file?
1891 * @param string $reason Prefilled reason
1893 public function confirmDelete( $reason ) {
1894 wfDebug( "Article::confirmDelete\n" );
1896 $title = $this->getTitle();
1897 $ctx = $this->getContext();
1898 $outputPage = $ctx->getOutput();
1899 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1900 $outputPage->addBacklinkSubtitle( $title );
1901 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1902 $outputPage->addModules( 'mediawiki.action.delete' );
1904 $backlinkCache = $title->getBacklinkCache();
1905 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1906 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1907 'deleting-backlinks-warning' );
1910 $subpageQueryLimit = 51;
1911 $subpages = $title->getSubpages( $subpageQueryLimit );
1912 $subpageCount = count( $subpages );
1913 if ( $subpageCount > 0 ) {
1914 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1915 [ 'deleting-subpages-warning', Message
::numParam( $subpageCount ) ] );
1917 $outputPage->addWikiMsg( 'confirmdeletetext' );
1919 Hooks
::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
1921 $user = $this->getContext()->getUser();
1922 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1924 $outputPage->enableOOUI();
1926 $options = Xml
::listDropDownOptions(
1927 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
1928 [ 'other' => $ctx->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
1930 $options = Xml
::listDropDownOptionsOoui( $options );
1932 $fields[] = new OOUI\
FieldLayout(
1933 new OOUI\
DropdownInputWidget( [
1934 'name' => 'wpDeleteReasonList',
1935 'inputId' => 'wpDeleteReasonList',
1937 'infusable' => true,
1939 'options' => $options
1942 'label' => $ctx->msg( 'deletecomment' )->text(),
1947 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
1948 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
1949 // Unicode codepoints.
1950 $fields[] = new OOUI\
FieldLayout(
1951 new OOUI\
TextInputWidget( [
1952 'name' => 'wpReason',
1953 'inputId' => 'wpReason',
1955 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
1956 'infusable' => true,
1958 'autofocus' => true,
1961 'label' => $ctx->msg( 'deleteotherreason' )->text(),
1966 if ( $user->isLoggedIn() ) {
1967 $fields[] = new OOUI\
FieldLayout(
1968 new OOUI\
CheckboxInputWidget( [
1969 'name' => 'wpWatch',
1970 'inputId' => 'wpWatch',
1972 'selected' => $checkWatch,
1975 'label' => $ctx->msg( 'watchthis' )->text(),
1976 'align' => 'inline',
1977 'infusable' => true,
1982 if ( $user->isAllowed( 'suppressrevision' ) ) {
1983 $fields[] = new OOUI\
FieldLayout(
1984 new OOUI\
CheckboxInputWidget( [
1985 'name' => 'wpSuppress',
1986 'inputId' => 'wpSuppress',
1990 'label' => $ctx->msg( 'revdelete-suppress' )->text(),
1991 'align' => 'inline',
1992 'infusable' => true,
1997 $fields[] = new OOUI\
FieldLayout(
1998 new OOUI\
ButtonInputWidget( [
1999 'name' => 'wpConfirmB',
2000 'inputId' => 'wpConfirmB',
2002 'value' => $ctx->msg( 'deletepage' )->text(),
2003 'label' => $ctx->msg( 'deletepage' )->text(),
2004 'flags' => [ 'primary', 'destructive' ],
2012 $fieldset = new OOUI\
FieldsetLayout( [
2013 'label' => $ctx->msg( 'delete-legend' )->text(),
2014 'id' => 'mw-delete-table',
2018 $form = new OOUI\
FormLayout( [
2020 'action' => $title->getLocalURL( 'action=delete' ),
2021 'id' => 'deleteconfirm',
2023 $form->appendContent(
2025 new OOUI\
HtmlSnippet(
2026 Html
::hidden( 'wpEditToken', $user->getEditToken( [ 'delete', $title->getPrefixedText() ] ) )
2030 $outputPage->addHTML(
2031 new OOUI\
PanelLayout( [
2032 'classes' => [ 'deletepage-wrapper' ],
2033 'expanded' => false,
2040 if ( $user->isAllowed( 'editinterface' ) ) {
2041 $link = Linker
::linkKnown(
2042 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
2043 wfMessage( 'delete-edit-reasonlist' )->escaped(),
2045 [ 'action' => 'edit' ]
2047 $outputPage->addHTML( '<p class="mw-delete-editreasons">' . $link . '</p>' );
2050 $deleteLogPage = new LogPage( 'delete' );
2051 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2052 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
2056 * Perform a deletion and output success or failure messages
2057 * @param string $reason
2058 * @param bool $suppress
2059 * @param bool $immediate false allows deleting over time via the job queue
2060 * @throws FatalError
2061 * @throws MWException
2063 public function doDelete( $reason, $suppress = false, $immediate = false ) {
2065 $context = $this->getContext();
2066 $outputPage = $context->getOutput();
2067 $user = $context->getUser();
2068 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user,
2069 [], 'delete', $immediate );
2071 if ( $status->isOK() ) {
2072 $deleted = $this->getTitle()->getPrefixedText();
2074 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
2075 $outputPage->setRobotPolicy( 'noindex,nofollow' );
2077 if ( $status->isGood() ) {
2078 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
2079 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
2080 Hooks
::run( 'ArticleDeleteAfterSuccess', [ $this->getTitle(), $outputPage ] );
2082 $outputPage->addWikiMsg( 'delete-scheduled', wfEscapeWikiText( $deleted ) );
2085 $outputPage->returnToMain( false );
2087 $outputPage->setPageTitle(
2088 wfMessage( 'cannotdelete-title',
2089 $this->getTitle()->getPrefixedText() )
2092 if ( $error == '' ) {
2093 $outputPage->wrapWikiTextAsInterface(
2094 'error mw-error-cannotdelete',
2095 $status->getWikiText()
2097 $deleteLogPage = new LogPage( 'delete' );
2098 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2100 LogEventsList
::showLogExtract(
2106 $outputPage->addHTML( $error );
2111 /* Caching functions */
2114 * checkLastModified returns true if it has taken care of all
2115 * output to the client that is necessary for this request.
2116 * (that is, it has sent a cached version of the page)
2118 * @return bool True if cached version send, false otherwise
2120 protected function tryFileCache() {
2121 static $called = false;
2124 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2129 if ( $this->isFileCacheable() ) {
2130 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
2131 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
2132 wfDebug( "Article::tryFileCache(): about to load file\n" );
2133 $cache->loadFromFileCache( $this->getContext() );
2136 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2137 ob_start( [ &$cache, 'saveToFileCache' ] );
2140 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2147 * Check if the page can be cached
2148 * @param int $mode One of the HTMLFileCache::MODE_* constants (since 1.28)
2151 public function isFileCacheable( $mode = HTMLFileCache
::MODE_NORMAL
) {
2154 if ( HTMLFileCache
::useFileCache( $this->getContext(), $mode ) ) {
2155 $cacheable = $this->mPage
->getId()
2156 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
2157 // Extension may have reason to disable file caching on some pages.
2159 // Avoid PHP 7.1 warning of passing $this by reference
2160 $articlePage = $this;
2161 $cacheable = Hooks
::run( 'IsFileCacheable', [ &$articlePage ] );
2171 * Lightweight method to get the parser output for a page, checking the parser cache
2172 * and so on. Doesn't consider most of the stuff that Article::view() is forced to
2173 * consider, so it's not appropriate to use there.
2175 * @since 1.16 (r52326) for LiquidThreads
2177 * @param int|null $oldid Revision ID or null
2178 * @param User|null $user The relevant user
2179 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
2181 public function getParserOutput( $oldid = null, User
$user = null ) {
2182 // XXX: bypasses mParserOptions and thus setParserOptions()
2184 if ( $user === null ) {
2185 $parserOptions = $this->getParserOptions();
2187 $parserOptions = $this->mPage
->makeParserOptions( $user );
2190 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
2194 * Override the ParserOptions used to render the primary article wikitext.
2196 * @param ParserOptions $options
2197 * @throws MWException If the parser options where already initialized.
2199 public function setParserOptions( ParserOptions
$options ) {
2200 if ( $this->mParserOptions
) {
2201 throw new MWException( "can't change parser options after they have already been set" );
2204 // clone, so if $options is modified later, it doesn't confuse the parser cache.
2205 $this->mParserOptions
= clone $options;
2209 * Get parser options suitable for rendering the primary article wikitext
2210 * @return ParserOptions
2212 public function getParserOptions() {
2213 if ( !$this->mParserOptions
) {
2214 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
2216 // Clone to allow modifications of the return value without affecting cache
2217 return clone $this->mParserOptions
;
2221 * Sets the context this Article is executed in
2223 * @param IContextSource $context
2226 public function setContext( $context ) {
2227 $this->mContext
= $context;
2231 * Gets the context this Article is executed in
2233 * @return IContextSource
2236 public function getContext() {
2237 if ( $this->mContext
instanceof IContextSource
) {
2238 return $this->mContext
;
2240 wfDebug( __METHOD__
. " called and \$mContext is null. " .
2241 "Return RequestContext::getMain(); for sanity\n" );
2242 return RequestContext
::getMain();
2247 * Use PHP's magic __get handler to handle accessing of
2248 * raw WikiPage fields for backwards compatibility.
2250 * @param string $fname Field name
2253 public function __get( $fname ) {
2254 if ( property_exists( $this->mPage
, $fname ) ) {
2255 # wfWarn( "Access to raw $fname field " . __CLASS__ );
2256 return $this->mPage
->$fname;
2258 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2262 * Use PHP's magic __set handler to handle setting of
2263 * raw WikiPage fields for backwards compatibility.
2265 * @param string $fname Field name
2266 * @param mixed $fvalue New value
2268 public function __set( $fname, $fvalue ) {
2269 if ( property_exists( $this->mPage
, $fname ) ) {
2270 # wfWarn( "Access to raw $fname field of " . __CLASS__ );
2271 $this->mPage
->$fname = $fvalue;
2272 // Note: extensions may want to toss on new fields
2273 } elseif ( !in_array( $fname, [ 'mContext', 'mPage' ] ) ) {
2274 $this->mPage
->$fname = $fvalue;
2276 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2281 * Call to WikiPage function for backwards compatibility.
2282 * @see WikiPage::checkFlags
2284 public function checkFlags( $flags ) {
2285 return $this->mPage
->checkFlags( $flags );
2289 * Call to WikiPage function for backwards compatibility.
2290 * @see WikiPage::checkTouched
2292 public function checkTouched() {
2293 return $this->mPage
->checkTouched();
2297 * Call to WikiPage function for backwards compatibility.
2298 * @see WikiPage::clearPreparedEdit
2300 public function clearPreparedEdit() {
2301 $this->mPage
->clearPreparedEdit();
2305 * Call to WikiPage function for backwards compatibility.
2306 * @see WikiPage::doDeleteArticleReal
2308 public function doDeleteArticleReal(
2309 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User
$user = null,
2310 $tags = [], $immediate = false
2312 return $this->mPage
->doDeleteArticleReal(
2313 $reason, $suppress, $u1, $u2, $error, $user, $tags, 'delete', $immediate
2318 * Call to WikiPage function for backwards compatibility.
2319 * @see WikiPage::doDeleteUpdates
2321 public function doDeleteUpdates(
2323 Content
$content = null,
2327 $this->mPage
->doDeleteUpdates( $id, $content, $revision, $user );
2331 * Call to WikiPage function for backwards compatibility.
2332 * @deprecated since 1.29. Use WikiPage::doEditContent() directly instead
2333 * @see WikiPage::doEditContent
2335 public function doEditContent( Content
$content, $summary, $flags = 0, $originalRevId = false,
2336 User
$user = null, $serialFormat = null
2338 wfDeprecated( __METHOD__
, '1.29' );
2339 return $this->mPage
->doEditContent( $content, $summary, $flags, $originalRevId,
2340 $user, $serialFormat
2345 * Call to WikiPage function for backwards compatibility.
2346 * @see WikiPage::doEditUpdates
2348 public function doEditUpdates( Revision
$revision, User
$user, array $options = [] ) {
2349 return $this->mPage
->doEditUpdates( $revision, $user, $options );
2353 * Call to WikiPage function for backwards compatibility.
2354 * @see WikiPage::doPurge
2355 * @note In 1.28 (and only 1.28), this took a $flags parameter that
2356 * controlled how much purging was done.
2358 public function doPurge() {
2359 return $this->mPage
->doPurge();
2363 * Call to WikiPage function for backwards compatibility.
2364 * @see WikiPage::doViewUpdates
2366 public function doViewUpdates( User
$user, $oldid = 0 ) {
2367 $this->mPage
->doViewUpdates( $user, $oldid );
2371 * Call to WikiPage function for backwards compatibility.
2372 * @see WikiPage::exists
2374 public function exists() {
2375 return $this->mPage
->exists();
2379 * Call to WikiPage function for backwards compatibility.
2380 * @see WikiPage::followRedirect
2382 public function followRedirect() {
2383 return $this->mPage
->followRedirect();
2387 * Call to WikiPage function for backwards compatibility.
2388 * @see ContentHandler::getActionOverrides
2390 public function getActionOverrides() {
2391 return $this->mPage
->getActionOverrides();
2395 * Call to WikiPage function for backwards compatibility.
2396 * @see WikiPage::getAutoDeleteReason
2398 public function getAutoDeleteReason( &$hasHistory ) {
2399 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2403 * Call to WikiPage function for backwards compatibility.
2404 * @see WikiPage::getCategories
2406 public function getCategories() {
2407 return $this->mPage
->getCategories();
2411 * Call to WikiPage function for backwards compatibility.
2412 * @see WikiPage::getComment
2414 public function getComment( $audience = Revision
::FOR_PUBLIC
, User
$user = null ) {
2415 return $this->mPage
->getComment( $audience, $user );
2419 * Call to WikiPage function for backwards compatibility.
2420 * @see WikiPage::getContentHandler
2422 public function getContentHandler() {
2423 return $this->mPage
->getContentHandler();
2427 * Call to WikiPage function for backwards compatibility.
2428 * @see WikiPage::getContentModel
2430 public function getContentModel() {
2431 return $this->mPage
->getContentModel();
2435 * Call to WikiPage function for backwards compatibility.
2436 * @see WikiPage::getContributors
2438 public function getContributors() {
2439 return $this->mPage
->getContributors();
2443 * Call to WikiPage function for backwards compatibility.
2444 * @see WikiPage::getCreator
2446 public function getCreator( $audience = Revision
::FOR_PUBLIC
, User
$user = null ) {
2447 return $this->mPage
->getCreator( $audience, $user );
2451 * Call to WikiPage function for backwards compatibility.
2452 * @see WikiPage::getDeletionUpdates
2454 public function getDeletionUpdates( Content
$content = null ) {
2455 return $this->mPage
->getDeletionUpdates( $content );
2459 * Call to WikiPage function for backwards compatibility.
2460 * @see WikiPage::getHiddenCategories
2462 public function getHiddenCategories() {
2463 return $this->mPage
->getHiddenCategories();
2467 * Call to WikiPage function for backwards compatibility.
2468 * @see WikiPage::getId
2470 public function getId() {
2471 return $this->mPage
->getId();
2475 * Call to WikiPage function for backwards compatibility.
2476 * @see WikiPage::getLatest
2478 public function getLatest() {
2479 return $this->mPage
->getLatest();
2483 * Call to WikiPage function for backwards compatibility.
2484 * @see WikiPage::getLinksTimestamp
2486 public function getLinksTimestamp() {
2487 return $this->mPage
->getLinksTimestamp();
2491 * Call to WikiPage function for backwards compatibility.
2492 * @see WikiPage::getMinorEdit
2494 public function getMinorEdit() {
2495 return $this->mPage
->getMinorEdit();
2499 * Call to WikiPage function for backwards compatibility.
2500 * @see WikiPage::getOldestRevision
2502 public function getOldestRevision() {
2503 return $this->mPage
->getOldestRevision();
2507 * Call to WikiPage function for backwards compatibility.
2508 * @see WikiPage::getRedirectTarget
2510 public function getRedirectTarget() {
2511 return $this->mPage
->getRedirectTarget();
2515 * Call to WikiPage function for backwards compatibility.
2516 * @see WikiPage::getRedirectURL
2518 public function getRedirectURL( $rt ) {
2519 return $this->mPage
->getRedirectURL( $rt );
2523 * Call to WikiPage function for backwards compatibility.
2524 * @see WikiPage::getRevision
2526 public function getRevision() {
2527 return $this->mPage
->getRevision();
2531 * Call to WikiPage function for backwards compatibility.
2532 * @see WikiPage::getTimestamp
2534 public function getTimestamp() {
2535 return $this->mPage
->getTimestamp();
2539 * Call to WikiPage function for backwards compatibility.
2540 * @see WikiPage::getTouched
2542 public function getTouched() {
2543 return $this->mPage
->getTouched();
2547 * Call to WikiPage function for backwards compatibility.
2548 * @see WikiPage::getUndoContent
2550 public function getUndoContent( Revision
$undo, Revision
$undoafter = null ) {
2551 return $this->mPage
->getUndoContent( $undo, $undoafter );
2555 * Call to WikiPage function for backwards compatibility.
2556 * @see WikiPage::getUser
2558 public function getUser( $audience = Revision
::FOR_PUBLIC
, User
$user = null ) {
2559 return $this->mPage
->getUser( $audience, $user );
2563 * Call to WikiPage function for backwards compatibility.
2564 * @see WikiPage::getUserText
2566 public function getUserText( $audience = Revision
::FOR_PUBLIC
, User
$user = null ) {
2567 return $this->mPage
->getUserText( $audience, $user );
2571 * Call to WikiPage function for backwards compatibility.
2572 * @see WikiPage::hasViewableContent
2574 public function hasViewableContent() {
2575 return $this->mPage
->hasViewableContent();
2579 * Call to WikiPage function for backwards compatibility.
2580 * @see WikiPage::insertOn
2582 public function insertOn( $dbw, $pageId = null ) {
2583 return $this->mPage
->insertOn( $dbw, $pageId );
2587 * Call to WikiPage function for backwards compatibility.
2588 * @see WikiPage::insertProtectNullRevision
2590 public function insertProtectNullRevision( $revCommentMsg, array $limit,
2591 array $expiry, $cascade, $reason, $user = null
2593 return $this->mPage
->insertProtectNullRevision( $revCommentMsg, $limit,
2594 $expiry, $cascade, $reason, $user
2599 * Call to WikiPage function for backwards compatibility.
2600 * @see WikiPage::insertRedirect
2602 public function insertRedirect() {
2603 return $this->mPage
->insertRedirect();
2607 * Call to WikiPage function for backwards compatibility.
2608 * @see WikiPage::insertRedirectEntry
2610 public function insertRedirectEntry( Title
$rt, $oldLatest = null ) {
2611 return $this->mPage
->insertRedirectEntry( $rt, $oldLatest );
2615 * Call to WikiPage function for backwards compatibility.
2616 * @see WikiPage::isCountable
2618 public function isCountable( $editInfo = false ) {
2619 return $this->mPage
->isCountable( $editInfo );
2623 * Call to WikiPage function for backwards compatibility.
2624 * @see WikiPage::isRedirect
2626 public function isRedirect() {
2627 return $this->mPage
->isRedirect();
2631 * Call to WikiPage function for backwards compatibility.
2632 * @see WikiPage::loadFromRow
2634 public function loadFromRow( $data, $from ) {
2635 return $this->mPage
->loadFromRow( $data, $from );
2639 * Call to WikiPage function for backwards compatibility.
2640 * @see WikiPage::loadPageData
2642 public function loadPageData( $from = 'fromdb' ) {
2643 $this->mPage
->loadPageData( $from );
2647 * Call to WikiPage function for backwards compatibility.
2648 * @see WikiPage::lockAndGetLatest
2650 public function lockAndGetLatest() {
2651 return $this->mPage
->lockAndGetLatest();
2655 * Call to WikiPage function for backwards compatibility.
2656 * @see WikiPage::makeParserOptions
2658 public function makeParserOptions( $context ) {
2659 return $this->mPage
->makeParserOptions( $context );
2663 * Call to WikiPage function for backwards compatibility.
2664 * @see WikiPage::pageDataFromId
2666 public function pageDataFromId( $dbr, $id, $options = [] ) {
2667 return $this->mPage
->pageDataFromId( $dbr, $id, $options );
2671 * Call to WikiPage function for backwards compatibility.
2672 * @see WikiPage::pageDataFromTitle
2674 public function pageDataFromTitle( $dbr, $title, $options = [] ) {
2675 return $this->mPage
->pageDataFromTitle( $dbr, $title, $options );
2679 * Call to WikiPage function for backwards compatibility.
2680 * @see WikiPage::prepareContentForEdit
2682 public function prepareContentForEdit(
2683 Content
$content, $revision = null, User
$user = null,
2684 $serialFormat = null, $useCache = true
2686 return $this->mPage
->prepareContentForEdit(
2687 $content, $revision, $user,
2688 $serialFormat, $useCache
2693 * Call to WikiPage function for backwards compatibility.
2694 * @see WikiPage::protectDescription
2696 public function protectDescription( array $limit, array $expiry ) {
2697 return $this->mPage
->protectDescription( $limit, $expiry );
2701 * Call to WikiPage function for backwards compatibility.
2702 * @see WikiPage::protectDescriptionLog
2704 public function protectDescriptionLog( array $limit, array $expiry ) {
2705 return $this->mPage
->protectDescriptionLog( $limit, $expiry );
2709 * Call to WikiPage function for backwards compatibility.
2710 * @see WikiPage::replaceSectionAtRev
2712 public function replaceSectionAtRev( $sectionId, Content
$sectionContent,
2713 $sectionTitle = '', $baseRevId = null
2715 return $this->mPage
->replaceSectionAtRev( $sectionId, $sectionContent,
2716 $sectionTitle, $baseRevId
2721 * Call to WikiPage function for backwards compatibility.
2722 * @see WikiPage::replaceSectionContent
2724 public function replaceSectionContent(
2725 $sectionId, Content
$sectionContent, $sectionTitle = '', $edittime = null
2727 return $this->mPage
->replaceSectionContent(
2728 $sectionId, $sectionContent, $sectionTitle, $edittime
2733 * Call to WikiPage function for backwards compatibility.
2734 * @see WikiPage::setTimestamp
2736 public function setTimestamp( $ts ) {
2737 return $this->mPage
->setTimestamp( $ts );
2741 * Call to WikiPage function for backwards compatibility.
2742 * @see WikiPage::shouldCheckParserCache
2744 public function shouldCheckParserCache( ParserOptions
$parserOptions, $oldId ) {
2745 return $this->mPage
->shouldCheckParserCache( $parserOptions, $oldId );
2749 * Call to WikiPage function for backwards compatibility.
2750 * @see WikiPage::supportsSections
2752 public function supportsSections() {
2753 return $this->mPage
->supportsSections();
2757 * Call to WikiPage function for backwards compatibility.
2758 * @see WikiPage::triggerOpportunisticLinksUpdate
2760 public function triggerOpportunisticLinksUpdate( ParserOutput
$parserOutput ) {
2761 return $this->mPage
->triggerOpportunisticLinksUpdate( $parserOutput );
2765 * Call to WikiPage function for backwards compatibility.
2766 * @see WikiPage::updateCategoryCounts
2768 public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
2769 return $this->mPage
->updateCategoryCounts( $added, $deleted, $id );
2773 * Call to WikiPage function for backwards compatibility.
2774 * @see WikiPage::updateIfNewerOn
2776 public function updateIfNewerOn( $dbw, $revision ) {
2777 return $this->mPage
->updateIfNewerOn( $dbw, $revision );
2781 * Call to WikiPage function for backwards compatibility.
2782 * @see WikiPage::updateRedirectOn
2784 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
2785 return $this->mPage
->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect );
2789 * Call to WikiPage function for backwards compatibility.
2790 * @see WikiPage::updateRevisionOn
2792 public function updateRevisionOn( $dbw, $revision, $lastRevision = null,
2793 $lastRevIsRedirect = null
2795 return $this->mPage
->updateRevisionOn( $dbw, $revision, $lastRevision,
2801 * @param array $limit
2802 * @param array $expiry
2803 * @param bool &$cascade
2804 * @param string $reason
2808 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2811 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2815 * @param array $limit
2816 * @param string $reason
2817 * @param int &$cascade
2818 * @param array $expiry
2821 public function updateRestrictions( $limit = [], $reason = '',
2822 &$cascade = 0, $expiry = []
2824 return $this->mPage
->doUpdateRestrictions(
2829 $this->getContext()->getUser()
2834 * @param string $reason
2835 * @param bool $suppress
2836 * @param int|null $u1 Unused
2837 * @param bool|null $u2 Unused
2838 * @param string &$error
2839 * @param bool $immediate false allows deleting over time via the job queue
2841 * @throws FatalError
2842 * @throws MWException
2844 public function doDeleteArticle(
2845 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', $immediate = false
2847 return $this->mPage
->doDeleteArticle( $reason, $suppress, $u1, $u2, $error,
2852 * @param string $fromP
2853 * @param string $summary
2854 * @param string $token
2856 * @param array &$resultDetails
2857 * @param User|null $user
2860 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2861 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2862 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2866 * @param string $fromP
2867 * @param string $summary
2869 * @param array &$resultDetails
2870 * @param User|null $guser
2873 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2874 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2875 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2879 * @param bool &$hasHistory
2882 public function generateReason( &$hasHistory ) {
2883 $title = $this->mPage
->getTitle();
2884 $handler = ContentHandler
::getForTitle( $title );
2885 return $handler->getAutoDeleteReason( $title, $hasHistory );