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\Block\DatabaseBlock
;
23 use MediaWiki\MediaWikiServices
;
24 use MediaWiki\Revision\MutableRevisionRecord
;
25 use MediaWiki\Revision\RevisionRecord
;
26 use MediaWiki\Revision\SlotRecord
;
29 * Class for viewing MediaWiki article and history.
31 * This maintains WikiPage functions for backwards compatibility.
33 * @todo Move and rewrite code to an Action class
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 $rl = MediaWikiServices
::getInstance()->getRevisionLookup();
367 $oldRev = $this->mRevision ?
$this->mRevision
->getRevisionRecord() : null;
368 if ( $request->getVal( 'direction' ) == 'next' ) {
371 $nextRev = $rl->getNextRevision( $oldRev );
373 $nextid = $nextRev->getId();
378 $this->mRevision
= null;
380 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
382 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
385 $prevRev = $rl->getPreviousRevision( $oldRev );
387 $previd = $prevRev->getId();
392 $this->mRevision
= null;
396 $this->mRevIdFetched
= $this->mRevision ?
$this->mRevision
->getId() : 0;
402 * Get text content object
403 * Does *NOT* follow redirects.
404 * @todo When is this null?
405 * @deprecated since 1.32, use fetchRevisionRecord() instead.
407 * @note Code that wants to retrieve page content from the database should
408 * use WikiPage::getContent().
410 * @return Content|null|bool
414 protected function fetchContentObject() {
415 if ( !$this->mContentLoaded
) {
416 $this->fetchRevisionRecord();
419 return $this->mContentObject
;
423 * Fetches the revision to work on.
424 * The revision is typically loaded from the database, but may also be a fake representing
425 * an error message or content supplied by an extension. Refer to $this->fetchResult for
426 * the revision actually loaded from the database, and any errors encountered while doing
429 * @return RevisionRecord|null
431 protected function fetchRevisionRecord() {
432 if ( $this->fetchResult
) {
433 return $this->mRevision ?
$this->mRevision
->getRevisionRecord() : null;
436 $this->mContentLoaded
= true;
437 $this->mContentObject
= null;
439 $oldid = $this->getOldID();
441 // $this->mRevision might already be fetched by getOldIDFromRequest()
442 if ( !$this->mRevision
) {
444 $this->mRevision
= $this->mPage
->getRevision();
446 if ( !$this->mRevision
) {
447 wfDebug( __METHOD__
. " failed to find page data for title " .
448 $this->getTitle()->getPrefixedText() . "\n" );
450 // Just for sanity, output for this case is done by showMissingArticle().
451 $this->fetchResult
= Status
::newFatal( 'noarticletext' );
452 $this->applyContentOverride( $this->makeFetchErrorContent() );
456 $this->mRevision
= Revision
::newFromId( $oldid );
458 if ( !$this->mRevision
) {
459 wfDebug( __METHOD__
. " failed to load revision, rev_id $oldid\n" );
461 $this->fetchResult
= Status
::newFatal( 'missing-revision', $oldid );
462 $this->applyContentOverride( $this->makeFetchErrorContent() );
468 $this->mRevIdFetched
= $this->mRevision
->getId();
469 $this->fetchResult
= Status
::newGood( $this->mRevision
);
472 !$this->mRevision
->userCan( RevisionRecord
::DELETED_TEXT
, $this->getContext()->getUser() )
474 wfDebug( __METHOD__
. " failed to retrieve content of revision " .
475 $this->mRevision
->getId() . "\n" );
477 // Just for sanity, output for this case is done by showDeletedRevisionHeader().
478 $this->fetchResult
= Status
::newFatal( 'rev-deleted-text-permission' );
479 $this->applyContentOverride( $this->makeFetchErrorContent() );
483 if ( Hooks
::isRegistered( 'ArticleAfterFetchContentObject' ) ) {
484 $contentObject = $this->mRevision
->getContent(
485 RevisionRecord
::FOR_THIS_USER
,
486 $this->getContext()->getUser()
489 $hookContentObject = $contentObject;
491 // Avoid PHP 7.1 warning of passing $this by reference
492 $articlePage = $this;
495 'ArticleAfterFetchContentObject',
496 [ &$articlePage, &$hookContentObject ],
500 if ( $hookContentObject !== $contentObject ) {
501 // A hook handler is trying to override the content
502 $this->applyContentOverride( $hookContentObject );
507 $this->mContentObject
= $this->mRevision
->getContent(
508 RevisionRecord
::FOR_THIS_USER
,
509 $this->getContext()->getUser()
512 return $this->mRevision
->getRevisionRecord();
516 * Returns a Content object representing any error in $this->fetchContent, or null
517 * if there is no such error.
519 * @return Content|null
521 private function makeFetchErrorContent() {
522 if ( !$this->fetchResult ||
$this->fetchResult
->isOK() ) {
526 return new MessageContent( $this->fetchResult
->getMessage() );
530 * Applies a content override by constructing a fake Revision object and assigning
531 * it to mRevision. The fake revision will not have a user, timestamp or summary set.
533 * This mechanism exists mainly to accommodate extensions that use the
534 * ArticleAfterFetchContentObject. Once that hook has been removed, there should no longer
535 * be a need for a fake revision object. fetchRevisionRecord() presently also uses this mechanism
536 * to report errors, but that could be changed to use $this->fetchResult instead.
538 * @param Content $override Content to be used instead of the actual page content,
539 * coming from an extension or representing an error message.
541 private function applyContentOverride( Content
$override ) {
542 // Construct a fake revision
543 $rev = new MutableRevisionRecord( $this->getTitle() );
544 $rev->setContent( SlotRecord
::MAIN
, $override );
546 $this->mRevision
= new Revision( $rev );
549 $this->mContentObject
= $override;
553 * Returns true if the currently-referenced revision is the current edit
554 * to this page (and it exists).
557 public function isCurrent() {
558 # If no oldid, this is the current version.
559 if ( $this->getOldID() == 0 ) {
563 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
567 * Get the fetched Revision object depending on request parameters or null
568 * on failure. The revision returned may be a fake representing an error message or
569 * wrapping content supplied by an extension. Refer to $this->fetchResult for the
570 * revision actually loaded from the database.
573 * @return Revision|null
575 public function getRevisionFetched() {
576 $this->fetchRevisionRecord();
578 if ( $this->fetchResult
->isOK() ) {
579 return $this->mRevision
;
584 * Use this to fetch the rev ID used on page views
586 * Before fetchRevisionRecord was called, this returns the page's latest revision,
587 * regardless of what getOldID() returns.
589 * @return int Revision ID of last article revision
591 public function getRevIdFetched() {
592 if ( $this->fetchResult
&& $this->fetchResult
->isOK() ) {
593 return $this->fetchResult
->value
->getId();
595 return $this->mPage
->getLatest();
600 * This is the default action of the index.php entry point: just view the
601 * page of the given title.
603 public function view() {
604 global $wgUseFileCache;
606 # Get variables from query string
607 # As side effect this will load the revision and update the title
608 # in a revision ID is passed in the request, so this should remain
609 # the first call of this method even if $oldid is used way below.
610 $oldid = $this->getOldID();
612 $user = $this->getContext()->getUser();
613 # Another whitelist check in case getOldID() is altering the title
614 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
615 if ( count( $permErrors ) ) {
616 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
617 throw new PermissionsError( 'read', $permErrors );
620 $outputPage = $this->getContext()->getOutput();
621 # getOldID() may as well want us to redirect somewhere else
622 if ( $this->mRedirectUrl
) {
623 $outputPage->redirect( $this->mRedirectUrl
);
624 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
629 # If we got diff in the query, we want to see a diff page instead of the article.
630 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
631 wfDebug( __METHOD__
. ": showing diff page\n" );
632 $this->showDiffPage();
637 # Set page title (may be overridden by DISPLAYTITLE)
638 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
640 $outputPage->setArticleFlag( true );
641 # Allow frames by default
642 $outputPage->allowClickjacking();
644 $parserCache = MediaWikiServices
::getInstance()->getParserCache();
646 $parserOptions = $this->getParserOptions();
648 # Render printable version, use printable version cache
649 if ( $outputPage->isPrintable() ) {
650 $parserOptions->setIsPrintable( true );
651 $poOptions['enableSectionEditLinks'] = false;
652 } elseif ( $this->viewIsRenderAction ||
!$this->isCurrent() ||
653 !MediaWikiServices
::getInstance()->getPermissionManager()
654 ->quickUserCan( 'edit', $user, $this->getTitle() )
656 $poOptions['enableSectionEditLinks'] = false;
659 # Try client and file cache
660 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
661 # Try to stream the output from file cache
662 if ( $wgUseFileCache && $this->tryFileCache() ) {
663 wfDebug( __METHOD__
. ": done file cache\n" );
664 # tell wgOut that output is taken care of
665 $outputPage->disable();
666 $this->mPage
->doViewUpdates( $user, $oldid );
672 # Should the parser cache be used?
673 $useParserCache = $this->mPage
->shouldCheckParserCache( $parserOptions, $oldid );
674 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
675 if ( $user->getStubThreshold() ) {
676 MediaWikiServices
::getInstance()->getStatsdDataFactory()->increment( 'pcache_miss_stub' );
679 $this->showRedirectedFromHeader();
680 $this->showNamespaceHeader();
682 # Iterate through the possible ways of constructing the output text.
683 # Keep going until $outputDone is set, or we run out of things to do.
686 $this->mParserOutput
= false;
688 while ( !$outputDone && ++
$pass ) {
691 // Avoid PHP 7.1 warning of passing $this by reference
692 $articlePage = $this;
693 Hooks
::run( 'ArticleViewHeader', [ &$articlePage, &$outputDone, &$useParserCache ] );
696 # Early abort if the page doesn't exist
697 if ( !$this->mPage
->exists() ) {
698 wfDebug( __METHOD__
. ": showing missing article\n" );
699 $this->showMissingArticle();
700 $this->mPage
->doViewUpdates( $user );
704 # Try the parser cache
705 if ( $useParserCache ) {
706 $this->mParserOutput
= $parserCache->get( $this->mPage
, $parserOptions );
708 if ( $this->mParserOutput
!== false ) {
710 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
711 $this->setOldSubtitle( $oldid );
713 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
715 $outputPage->addParserOutput( $this->mParserOutput
, $poOptions );
716 # Ensure that UI elements requiring revision ID have
717 # the correct version information.
718 $outputPage->setRevisionId( $this->mPage
->getLatest() );
719 # Preload timestamp to avoid a DB hit
720 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
721 if ( $cachedTimestamp !== null ) {
722 $outputPage->setRevisionTimestamp( $cachedTimestamp );
723 $this->mPage
->setTimestamp( $cachedTimestamp );
730 # Are we looking at an old revision
731 $rev = $this->fetchRevisionRecord();
732 if ( $oldid && $this->fetchResult
->isOK() ) {
733 $this->setOldSubtitle( $oldid );
735 if ( !$this->showDeletedRevisionHeader() ) {
736 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
741 # Ensure that UI elements requiring revision ID have
742 # the correct version information.
743 $outputPage->setRevisionId( $this->getRevIdFetched() );
744 # Preload timestamp to avoid a DB hit
745 $outputPage->setRevisionTimestamp( $this->mPage
->getTimestamp() );
747 # Pages containing custom CSS or JavaScript get special treatment
748 if ( $this->getTitle()->isSiteConfigPage() ||
$this->getTitle()->isUserConfigPage() ) {
749 $dir = $this->getContext()->getLanguage()->getDir();
750 $lang = $this->getContext()->getLanguage()->getHtmlCode();
752 $outputPage->wrapWikiMsg(
753 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
756 } elseif ( !Hooks
::run( 'ArticleRevisionViewCustom', [
763 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
764 // Allow extensions do their own custom view for certain pages
766 } elseif ( !Hooks
::run( 'ArticleContentViewCustom',
767 [ $this->fetchContentObject(), $this->getTitle(), $outputPage ], '1.32' )
769 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
770 // Allow extensions do their own custom view for certain pages
775 # Run the parse, protected by a pool counter
776 wfDebug( __METHOD__
. ": doing uncached parse\n" );
778 $rev = $this->fetchRevisionRecord();
782 $poolArticleView = new PoolWorkArticleView(
785 $this->getRevIdFetched(),
788 // permission checking was done earlier via showDeletedRevisionHeader()
791 $ok = $poolArticleView->execute();
792 $error = $poolArticleView->getError();
793 $this->mParserOutput
= $poolArticleView->getParserOutput() ?
: null;
795 # Don't cache a dirty ParserOutput object
796 if ( $poolArticleView->getIsDirty() ) {
797 $outputPage->setCdnMaxage( 0 );
798 $outputPage->addHTML( "<!-- parser cache is expired, " .
799 "sending anyway due to pool overload-->\n" );
807 $outputPage->clearHTML(); // for release() errors
808 $outputPage->enableClientCache( false );
809 $outputPage->setRobotPolicy( 'noindex,nofollow' );
811 $errortext = $error->getWikiText( false, 'view-pool-error' );
812 $outputPage->wrapWikiTextAsInterface( 'errorbox', $errortext );
814 # Connection or timeout error
818 if ( $this->mParserOutput
) {
819 $outputPage->addParserOutput( $this->mParserOutput
, $poOptions );
822 if ( $rev && $this->getRevisionRedirectTarget( $rev ) ) {
823 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
824 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
829 # Should be unreachable, but just in case...
835 // Get the ParserOutput actually *displayed* here.
836 // Note that $this->mParserOutput is the *current*/oldid version output.
837 // Note that the ArticleViewHeader hook is allowed to set $outputDone to a
838 // ParserOutput instance.
839 $pOutput = ( $outputDone instanceof ParserOutput
)
840 ?
$outputDone // object fetched by hook
841 : ( $this->mParserOutput ?
: null ); // ParserOutput or null, avoid false
843 # Adjust title for main page & pages with displaytitle
845 $this->adjustDisplayTitle( $pOutput );
848 # For the main page, overwrite the <title> element with the con-
849 # tents of 'pagetitle-view-mainpage' instead of the default (if
851 # This message always exists because it is in the i18n files
852 if ( $this->getTitle()->isMainPage() ) {
853 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
854 if ( !$msg->isDisabled() ) {
855 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
859 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
860 # This could use getTouched(), but that could be scary for major template edits.
861 $outputPage->adaptCdnTTL( $this->mPage
->getTimestamp(), IExpiringStore
::TTL_DAY
);
863 # Check for any __NOINDEX__ tags on the page using $pOutput
864 $policy = $this->getRobotPolicy( 'view', $pOutput ?
: null );
865 $outputPage->setIndexPolicy( $policy['index'] );
866 $outputPage->setFollowPolicy( $policy['follow'] ); // FIXME: test this
868 $this->showViewFooter();
869 $this->mPage
->doViewUpdates( $user, $oldid ); // FIXME: test this
871 # Load the postEdit module if the user just saved this revision
872 # See also EditPage::setPostEditCookie
873 $request = $this->getContext()->getRequest();
874 $cookieKey = EditPage
::POST_EDIT_COOKIE_KEY_PREFIX
. $this->getRevIdFetched();
875 $postEdit = $request->getCookie( $cookieKey );
877 # Clear the cookie. This also prevents caching of the response.
878 $request->response()->clearCookie( $cookieKey );
879 $outputPage->addJsConfigVars( 'wgPostEdit', $postEdit );
880 $outputPage->addModules( 'mediawiki.action.view.postEdit' ); // FIXME: test this
885 * @param RevisionRecord $revision
888 private function getRevisionRedirectTarget( RevisionRecord
$revision ) {
889 // TODO: find a *good* place for the code that determines the redirect target for
891 // NOTE: Use main slot content. Compare code in DerivedPageDataUpdater::revisionIsRedirect.
892 $content = $revision->getContent( SlotRecord
::MAIN
);
893 return $content ?
$content->getRedirectTarget() : null;
897 * Adjust title for pages with displaytitle, -{T|}- or language conversion
898 * @param ParserOutput $pOutput
900 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
901 $out = $this->getContext()->getOutput();
903 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
904 $titleText = $pOutput->getTitleText();
905 if ( strval( $titleText ) !== '' ) {
906 $out->setPageTitle( $titleText );
907 $out->setDisplayTitle( $titleText );
912 * Show a diff page according to current request variables. For use within
913 * Article::view() only, other callers should use the DifferenceEngine class.
915 protected function showDiffPage() {
916 $request = $this->getContext()->getRequest();
917 $user = $this->getContext()->getUser();
918 $diff = $request->getVal( 'diff' );
919 $rcid = $request->getVal( 'rcid' );
920 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
921 $purge = $request->getVal( 'action' ) == 'purge';
922 $unhide = $request->getInt( 'unhide' ) == 1;
923 $oldid = $this->getOldID();
925 $rev = $this->getRevisionFetched();
928 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
929 $msg = $this->getContext()->msg( 'difference-missing-revision' )
933 $this->getContext()->getOutput()->addHTML( $msg );
937 $contentHandler = $rev->getContentHandler();
938 $de = $contentHandler->createDifferenceEngine(
947 // DifferenceEngine directly fetched the revision:
948 $this->mRevIdFetched
= $de->getNewid();
949 $de->showDiffPage( $diffOnly );
951 // Run view updates for the newer revision being diffed (and shown
952 // below the diff if not $diffOnly).
953 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
954 // New can be false, convert it to 0 - this conveniently means the latest revision
955 $this->mPage
->doViewUpdates( $user, (int)$new );
959 * Get the robot policy to be used for the current view
960 * @param string $action The action= GET parameter
961 * @param ParserOutput|null $pOutput
962 * @return array The policy that should be set
963 * @todo actions other than 'view'
965 public function getRobotPolicy( $action, ParserOutput
$pOutput = null ) {
966 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
968 $ns = $this->getTitle()->getNamespace();
970 # Don't index user and user talk pages for blocked users (T13443)
971 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
972 $specificTarget = null;
974 $titleText = $this->getTitle()->getText();
975 if ( IP
::isValid( $titleText ) ) {
976 $vagueTarget = $titleText;
978 $specificTarget = $titleText;
980 if ( DatabaseBlock
::newFromTarget( $specificTarget, $vagueTarget ) instanceof DatabaseBlock
) {
982 'index' => 'noindex',
983 'follow' => 'nofollow'
988 if ( $this->mPage
->getId() === 0 ||
$this->getOldID() ) {
989 # Non-articles (special pages etc), and old revisions
991 'index' => 'noindex',
992 'follow' => 'nofollow'
994 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
995 # Discourage indexing of printable versions, but encourage following
997 'index' => 'noindex',
1000 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
1001 # For ?curid=x urls, disallow indexing
1003 'index' => 'noindex',
1004 'follow' => 'follow'
1008 # Otherwise, construct the policy based on the various config variables.
1009 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
1011 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
1012 # Honour customised robot policies for this namespace
1013 $policy = array_merge(
1015 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
1018 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
1019 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1020 # a final sanity check that we have really got the parser output.
1021 $policy = array_merge(
1023 [ 'index' => $pOutput->getIndexPolicy() ]
1027 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
1028 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1029 $policy = array_merge(
1031 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
1039 * Converts a String robot policy into an associative array, to allow
1040 * merging of several policies using array_merge().
1041 * @param array|string $policy Returns empty array on null/false/'', transparent
1042 * to already-converted arrays, converts string.
1043 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
1045 public static function formatRobotPolicy( $policy ) {
1046 if ( is_array( $policy ) ) {
1048 } elseif ( !$policy ) {
1052 $policy = explode( ',', $policy );
1053 $policy = array_map( 'trim', $policy );
1056 foreach ( $policy as $var ) {
1057 if ( in_array( $var, [ 'index', 'noindex' ] ) ) {
1058 $arr['index'] = $var;
1059 } elseif ( in_array( $var, [ 'follow', 'nofollow' ] ) ) {
1060 $arr['follow'] = $var;
1068 * If this request is a redirect view, send "redirected from" subtitle to
1069 * the output. Returns true if the header was needed, false if this is not
1070 * a redirect view. Handles both local and remote redirects.
1074 public function showRedirectedFromHeader() {
1075 global $wgRedirectSources;
1077 $context = $this->getContext();
1078 $outputPage = $context->getOutput();
1079 $request = $context->getRequest();
1080 $rdfrom = $request->getVal( 'rdfrom' );
1082 // Construct a URL for the current page view, but with the target title
1083 $query = $request->getValues();
1084 unset( $query['rdfrom'] );
1085 unset( $query['title'] );
1086 if ( $this->getTitle()->isRedirect() ) {
1087 // Prevent double redirects
1088 $query['redirect'] = 'no';
1090 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
1092 if ( isset( $this->mRedirectedFrom
) ) {
1093 // Avoid PHP 7.1 warning of passing $this by reference
1094 $articlePage = $this;
1096 // This is an internally redirected page view.
1097 // We'll need a backlink to the source page for navigation.
1098 if ( Hooks
::run( 'ArticleViewRedirect', [ &$articlePage ] ) ) {
1099 $redir = Linker
::linkKnown(
1100 $this->mRedirectedFrom
,
1103 [ 'redirect' => 'no' ]
1106 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1107 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1110 // Add the script to update the displayed URL and
1111 // set the fragment if one was specified in the redirect
1112 $outputPage->addJsConfigVars( [
1113 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1115 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1117 // Add a <link rel="canonical"> tag
1118 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
1120 // Tell the output object that the user arrived at this article through a redirect
1121 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1125 } elseif ( $rdfrom ) {
1126 // This is an externally redirected view, from some other wiki.
1127 // If it was reported from a trusted site, supply a backlink.
1128 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1129 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1130 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1131 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1134 // Add the script to update the displayed URL
1135 $outputPage->addJsConfigVars( [
1136 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1138 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1148 * Show a header specific to the namespace currently being viewed, like
1149 * [[MediaWiki:Talkpagetext]]. For Article::view().
1151 public function showNamespaceHeader() {
1152 if ( $this->getTitle()->isTalkPage() && !wfMessage( 'talkpageheader' )->isDisabled() ) {
1153 $this->getContext()->getOutput()->wrapWikiMsg(
1154 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1155 [ 'talkpageheader' ]
1161 * Show the footer section of an ordinary page view
1163 public function showViewFooter() {
1164 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1165 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1166 && IP
::isValid( $this->getTitle()->getText() )
1168 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1171 // Show a footer allowing the user to patrol the shown revision or page if possible
1172 $patrolFooterShown = $this->showPatrolFooter();
1174 Hooks
::run( 'ArticleViewFooter', [ $this, $patrolFooterShown ] );
1178 * If patrol is possible, output a patrol UI box. This is called from the
1179 * footer section of ordinary page views. If patrol is not possible or not
1180 * desired, does nothing.
1181 * Side effect: When the patrol link is build, this method will call
1182 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1186 public function showPatrolFooter() {
1187 global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol;
1189 // Allow hooks to decide whether to not output this at all
1190 if ( !Hooks
::run( 'ArticleShowPatrolFooter', [ $this ] ) ) {
1194 $outputPage = $this->getContext()->getOutput();
1195 $user = $this->getContext()->getUser();
1196 $title = $this->getTitle();
1199 if ( !MediaWikiServices
::getInstance()->getPermissionManager()
1200 ->quickUserCan( 'patrol', $user, $title )
1201 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol
1202 ||
( $wgUseFilePatrol && $title->inNamespace( NS_FILE
) ) )
1204 // Patrolling is disabled or the user isn't allowed to
1208 if ( $this->mRevision
1209 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1211 // The current revision is already older than what could be in the RC table
1212 // 6h tolerance because the RC might not be cleaned out regularly
1216 // Check for cached results
1217 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1218 $key = $cache->makeKey( 'unpatrollable-page', $title->getArticleID() );
1219 if ( $cache->get( $key ) ) {
1223 $dbr = wfGetDB( DB_REPLICA
);
1224 $oldestRevisionTimestamp = $dbr->selectField(
1226 'MIN( rev_timestamp )',
1227 [ 'rev_page' => $title->getArticleID() ],
1231 // New page patrol: Get the timestamp of the oldest revison which
1232 // the revision table holds for the given page. Then we look
1233 // whether it's within the RC lifespan and if it is, we try
1234 // to get the recentchanges row belonging to that entry
1235 // (with rc_new = 1).
1236 $recentPageCreation = false;
1237 if ( $oldestRevisionTimestamp
1238 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1240 // 6h tolerance because the RC might not be cleaned out regularly
1241 $recentPageCreation = true;
1242 $rc = RecentChange
::newFromConds(
1245 'rc_timestamp' => $oldestRevisionTimestamp,
1246 'rc_namespace' => $title->getNamespace(),
1247 'rc_cur_id' => $title->getArticleID()
1252 // Use generic patrol message for new pages
1253 $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
1257 // File patrol: Get the timestamp of the latest upload for this page,
1258 // check whether it is within the RC lifespan and if it is, we try
1259 // to get the recentchanges row belonging to that entry
1260 // (with rc_type = RC_LOG, rc_log_type = upload).
1261 $recentFileUpload = false;
1262 if ( ( !$rc ||
$rc->getAttribute( 'rc_patrolled' ) ) && $wgUseFilePatrol
1263 && $title->getNamespace() === NS_FILE
) {
1264 // Retrieve timestamp of most recent upload
1265 $newestUploadTimestamp = $dbr->selectField(
1267 'MAX( img_timestamp )',
1268 [ 'img_name' => $title->getDBkey() ],
1271 if ( $newestUploadTimestamp
1272 && RecentChange
::isInRCLifespan( $newestUploadTimestamp, 21600 )
1274 // 6h tolerance because the RC might not be cleaned out regularly
1275 $recentFileUpload = true;
1276 $rc = RecentChange
::newFromConds(
1278 'rc_type' => RC_LOG
,
1279 'rc_log_type' => 'upload',
1280 'rc_timestamp' => $newestUploadTimestamp,
1281 'rc_namespace' => NS_FILE
,
1282 'rc_cur_id' => $title->getArticleID()
1287 // Use patrol message specific to files
1288 $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
1293 if ( !$recentPageCreation && !$recentFileUpload ) {
1294 // Page creation and latest upload (for files) is too old to be in RC
1296 // We definitely can't patrol so cache the information
1297 // When a new file version is uploaded, the cache is cleared
1298 $cache->set( $key, '1' );
1304 // Don't cache: This can be hit if the page gets accessed very fast after
1305 // its creation / latest upload or in case we have high replica DB lag. In case
1306 // the revision is too old, we will already return above.
1310 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1311 // Patrolled RC entry around
1313 // Cache the information we gathered above in case we can't patrol
1314 // Don't cache in case we can patrol as this could change
1315 $cache->set( $key, '1' );
1320 if ( $rc->getPerformer()->equals( $user ) ) {
1321 // Don't show a patrol link for own creations/uploads. If the user could
1322 // patrol them, they already would be patrolled
1326 $outputPage->preventClickjacking();
1327 if ( MediaWikiServices
::getInstance()
1328 ->getPermissionManager()
1329 ->userHasRight( $user, 'writeapi' )
1331 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1334 $link = Linker
::linkKnown(
1336 $markPatrolledMsg->escaped(),
1339 'action' => 'markpatrolled',
1340 'rcid' => $rc->getAttribute( 'rc_id' ),
1344 $outputPage->addHTML(
1345 "<div class='patrollink' data-mw='interface'>" .
1346 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1354 * Purge the cache used to check if it is worth showing the patrol footer
1355 * For example, it is done during re-uploads when file patrol is used.
1356 * @param int $articleID ID of the article to purge
1359 public static function purgePatrolFooterCache( $articleID ) {
1360 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1361 $cache->delete( $cache->makeKey( 'unpatrollable-page', $articleID ) );
1365 * Show the error text for a missing article. For articles in the MediaWiki
1366 * namespace, show the default message text. To be called from Article::view().
1368 public function showMissingArticle() {
1369 global $wgSend404Code;
1371 $outputPage = $this->getContext()->getOutput();
1372 // Whether the page is a root user page of an existing user (but not a subpage)
1373 $validUserPage = false;
1375 $title = $this->getTitle();
1377 $services = MediaWikiServices
::getInstance();
1379 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1380 if ( $title->getNamespace() == NS_USER
1381 ||
$title->getNamespace() == NS_USER_TALK
1383 $rootPart = explode( '/', $title->getText() )[0];
1384 $user = User
::newFromName( $rootPart, false /* allow IP users */ );
1385 $ip = User
::isIP( $rootPart );
1386 $block = DatabaseBlock
::newFromTarget( $user, $user );
1388 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1389 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1390 [ 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ] );
1392 !is_null( $block ) &&
1393 $block->getType() != DatabaseBlock
::TYPE_AUTO
&&
1394 ( $block->isSitewide() ||
$user->isBlockedFrom( $title ) )
1396 // Show log extract if the user is sitewide blocked or is partially
1397 // blocked and not allowed to edit their user page or user talk page
1398 LogEventsList
::showLogExtract(
1401 $services->getNamespaceInfo()->getCanonicalName( NS_USER
) . ':' .
1402 $block->getTarget(),
1406 'showIfEmpty' => false,
1408 'blocked-notice-logextract',
1409 $user->getName() # Support GENDER in notice
1413 $validUserPage = !$title->isSubpage();
1415 $validUserPage = !$title->isSubpage();
1419 Hooks
::run( 'ShowMissingArticle', [ $this ] );
1421 # Show delete and move logs if there were any such events.
1422 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1423 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1424 $dbCache = ObjectCache
::getInstance( 'db-replicated' );
1425 $key = $dbCache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) );
1426 $loggedIn = $this->getContext()->getUser()->isLoggedIn();
1427 $sessionExists = $this->getContext()->getRequest()->getSession()->isPersistent();
1428 if ( $loggedIn ||
$dbCache->get( $key ) ||
$sessionExists ) {
1429 $logTypes = [ 'delete', 'move', 'protect' ];
1431 $dbr = wfGetDB( DB_REPLICA
);
1433 $conds = [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ];
1434 // Give extensions a chance to hide their (unrelated) log entries
1435 Hooks
::run( 'Article::MissingArticleConditions', [ &$conds, $logTypes ] );
1436 LogEventsList
::showLogExtract(
1444 'showIfEmpty' => false,
1445 'msgKey' => [ $loggedIn ||
$sessionExists
1446 ?
'moveddeleted-notice'
1447 : 'moveddeleted-notice-recent'
1453 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1454 // If there's no backing content, send a 404 Not Found
1455 // for better machine handling of broken links.
1456 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1459 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1460 $policy = $this->getRobotPolicy( 'view' );
1461 $outputPage->setIndexPolicy( $policy['index'] );
1462 $outputPage->setFollowPolicy( $policy['follow'] );
1464 $hookResult = Hooks
::run( 'BeforeDisplayNoArticleText', [ $this ] );
1466 if ( !$hookResult ) {
1470 # Show error message
1471 $oldid = $this->getOldID();
1472 $pm = MediaWikiServices
::getInstance()->getPermissionManager();
1473 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI
&& $title->hasSourceText() ) {
1474 // use fake Content object for system message
1475 $parserOptions = ParserOptions
::newCanonical( 'canonical' );
1476 $outputPage->addParserOutput( $this->getEmptyPageParserOutput( $parserOptions ) );
1479 $text = wfMessage( 'missing-revision', $oldid )->plain();
1480 } elseif ( $pm->quickUserCan( 'create', $this->getContext()->getUser(), $title ) &&
1481 $pm->quickUserCan( 'edit', $this->getContext()->getUser(), $title )
1483 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1484 $text = wfMessage( $message )->plain();
1486 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1489 $dir = $this->getContext()->getLanguage()->getDir();
1490 $lang = $this->getContext()->getLanguage()->getHtmlCode();
1491 $outputPage->addWikiTextAsInterface( Xml
::openElement( 'div', [
1492 'class' => "noarticletext mw-content-$dir",
1495 ] ) . "\n$text\n</div>" );
1500 * If the revision requested for view is deleted, check permissions.
1501 * Send either an error message or a warning header to the output.
1503 * @return bool True if the view is allowed, false if not.
1505 public function showDeletedRevisionHeader() {
1506 if ( !$this->mRevision
->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
1511 $outputPage = $this->getContext()->getOutput();
1512 $user = $this->getContext()->getUser();
1513 // If the user is not allowed to see it...
1514 if ( !$this->mRevision
->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
1515 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1516 'rev-deleted-text-permission' );
1519 // If the user needs to confirm that they want to see it...
1520 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1521 # Give explanation and add a link to view the revision...
1522 $oldid = intval( $this->getOldID() );
1523 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1524 $msg = $this->mRevision
->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
1525 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1526 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1530 // We are allowed to see...
1532 $msg = $this->mRevision
->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
1533 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1534 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1541 * Generate the navigation links when browsing through an article revisions
1542 * It shows the information as:
1543 * Revision as of \<date\>; view current revision
1544 * \<- Previous version | Next Version -\>
1546 * @param int $oldid Revision ID of this article revision
1548 public function setOldSubtitle( $oldid = 0 ) {
1549 // Avoid PHP 7.1 warning of passing $this by reference
1550 $articlePage = $this;
1552 if ( !Hooks
::run( 'DisplayOldSubtitle', [ &$articlePage, &$oldid ] ) ) {
1556 $context = $this->getContext();
1557 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1559 # Cascade unhide param in links for easy deletion browsing
1562 $extraParams['unhide'] = 1;
1565 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1566 $revision = $this->mRevision
;
1568 $revision = Revision
::newFromId( $oldid );
1571 $timestamp = $revision->getTimestamp();
1573 $current = ( $oldid == $this->mPage
->getLatest() );
1574 $language = $context->getLanguage();
1575 $user = $context->getUser();
1577 $td = $language->userTimeAndDate( $timestamp, $user );
1578 $tddate = $language->userDate( $timestamp, $user );
1579 $tdtime = $language->userTime( $timestamp, $user );
1581 # Show user links if allowed to see them. If hidden, then show them only if requested...
1582 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1584 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1585 ?
'revision-info-current'
1588 $outputPage = $context->getOutput();
1589 $revisionInfo = "<div id=\"mw-{$infomsg}\">" .
1590 $context->msg( $infomsg, $td )
1591 ->rawParams( $userlinks )
1592 ->params( $revision->getId(), $tddate, $tdtime, $revision->getUserText() )
1593 ->rawParams( Linker
::revComment( $revision, true, true ) )
1598 ?
$context->msg( 'currentrevisionlink' )->escaped()
1599 : Linker
::linkKnown(
1601 $context->msg( 'currentrevisionlink' )->escaped(),
1606 ?
$context->msg( 'diff' )->escaped()
1607 : Linker
::linkKnown(
1609 $context->msg( 'diff' )->escaped(),
1616 $rl = MediaWikiServices
::getInstance()->getRevisionLookup();
1617 $prevExist = (bool)$rl->getPreviousRevision( $revision->getRevisionRecord() );
1618 $prevlink = $prevExist
1619 ? Linker
::linkKnown(
1621 $context->msg( 'previousrevision' )->escaped(),
1624 'direction' => 'prev',
1628 : $context->msg( 'previousrevision' )->escaped();
1629 $prevdiff = $prevExist
1630 ? Linker
::linkKnown(
1632 $context->msg( 'diff' )->escaped(),
1639 : $context->msg( 'diff' )->escaped();
1640 $nextlink = $current
1641 ?
$context->msg( 'nextrevision' )->escaped()
1642 : Linker
::linkKnown(
1644 $context->msg( 'nextrevision' )->escaped(),
1647 'direction' => 'next',
1651 $nextdiff = $current
1652 ?
$context->msg( 'diff' )->escaped()
1653 : Linker
::linkKnown(
1655 $context->msg( 'diff' )->escaped(),
1663 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1664 if ( $cdel !== '' ) {
1668 // the outer div is need for styling the revision info and nav in MobileFrontend
1669 $outputPage->addSubtitle( "<div class=\"mw-revision\">" . $revisionInfo .
1670 "<div id=\"mw-revision-nav\">" . $cdel .
1671 $context->msg( 'revision-nav' )->rawParams(
1672 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1673 )->escaped() . "</div></div>" );
1677 * Return the HTML for the top of a redirect page
1679 * Chances are you should just be using the ParserOutput from
1680 * WikitextContent::getParserOutput instead of calling this for redirects.
1682 * @param Title|array $target Destination(s) to redirect
1683 * @param bool $appendSubtitle [optional]
1684 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1685 * @return string Containing HTML with redirect link
1687 * @deprecated since 1.30
1689 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1690 $lang = $this->getTitle()->getPageLanguage();
1691 $out = $this->getContext()->getOutput();
1692 if ( $appendSubtitle ) {
1693 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1695 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1696 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1700 * Return the HTML for the top of a redirect page
1702 * Chances are you should just be using the ParserOutput from
1703 * WikitextContent::getParserOutput instead of calling this for redirects.
1706 * @param Language $lang
1707 * @param Title|array $target Destination(s) to redirect
1708 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1709 * @return string Containing HTML with redirect link
1711 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1712 if ( !is_array( $target ) ) {
1713 $target = [ $target ];
1716 $html = '<ul class="redirectText">';
1717 /** @var Title $title */
1718 foreach ( $target as $title ) {
1719 $html .= '<li>' . Linker
::link(
1721 htmlspecialchars( $title->getFullText() ),
1723 // Make sure wiki page redirects are not followed
1724 $title->isRedirect() ?
[ 'redirect' => 'no' ] : [],
1725 ( $forceKnown ?
[ 'known', 'noclasses' ] : [] )
1730 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1732 return '<div class="redirectMsg">' .
1733 '<p>' . $redirectToText . '</p>' .
1739 * Adds help link with an icon via page indicators.
1740 * Link target can be overridden by a local message containing a wikilink:
1741 * the message key is: 'namespace-' + namespace number + '-helppage'.
1742 * @param string $to Target MediaWiki.org page title or encoded URL.
1743 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1746 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1748 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1751 $out = $this->getContext()->getOutput();
1752 if ( !$msg->isDisabled() ) {
1753 $helpUrl = Skin
::makeUrl( $msg->plain() );
1754 $out->addHelpLink( $helpUrl, true );
1756 $out->addHelpLink( $to, $overrideBaseUrl );
1761 * Handle action=render
1763 public function render() {
1764 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1765 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1766 // We later set 'enableSectionEditLinks=false' based on this; also used by ImagePage
1767 $this->viewIsRenderAction
= true;
1772 * action=protect handler
1774 public function protect() {
1775 $form = new ProtectionForm( $this );
1780 * action=unprotect handler (alias)
1782 public function unprotect() {
1787 * UI entry point for page deletion
1789 public function delete() {
1790 # This code desperately needs to be totally rewritten
1792 $title = $this->getTitle();
1793 $context = $this->getContext();
1794 $user = $context->getUser();
1795 $request = $context->getRequest();
1798 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1799 if ( count( $permissionErrors ) ) {
1800 throw new PermissionsError( 'delete', $permissionErrors );
1803 # Read-only check...
1804 if ( wfReadOnly() ) {
1805 throw new ReadOnlyError
;
1808 # Better double-check that it hasn't been deleted yet!
1809 $this->mPage
->loadPageData(
1810 $request->wasPosted() ? WikiPage
::READ_LATEST
: WikiPage
::READ_NORMAL
1812 if ( !$this->mPage
->exists() ) {
1813 $deleteLogPage = new LogPage( 'delete' );
1814 $outputPage = $context->getOutput();
1815 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1816 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1817 [ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ]
1819 $outputPage->addHTML(
1820 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1822 LogEventsList
::showLogExtract(
1831 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1832 $deleteReason = $request->getText( 'wpReason' );
1834 if ( $deleteReasonList == 'other' ) {
1835 $reason = $deleteReason;
1836 } elseif ( $deleteReason != '' ) {
1837 // Entry from drop down menu + additional comment
1838 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1839 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1841 $reason = $deleteReasonList;
1844 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1845 [ 'delete', $this->getTitle()->getPrefixedText() ] )
1847 # Flag to hide all contents of the archived revisions
1849 $suppress = $request->getCheck( 'wpSuppress' ) && MediaWikiServices
::getInstance()
1850 ->getPermissionManager()
1851 ->userHasRight( $user, 'suppressrevision' );
1853 $this->doDelete( $reason, $suppress );
1855 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1860 // Generate deletion reason
1861 $hasHistory = false;
1864 $reason = $this->generateReason( $hasHistory );
1865 } catch ( Exception
$e ) {
1866 # if a page is horribly broken, we still want to be able to
1867 # delete it. So be lenient about errors here.
1868 wfDebug( "Error while building auto delete summary: $e" );
1873 // If the page has a history, insert a warning
1874 if ( $hasHistory ) {
1875 $title = $this->getTitle();
1877 // The following can use the real revision count as this is only being shown for users
1878 // that can delete this page.
1879 // This, as a side-effect, also makes sure that the following query isn't being run for
1880 // pages with a larger history, unless the user has the 'bigdelete' right
1881 // (and is about to delete this page).
1882 $dbr = wfGetDB( DB_REPLICA
);
1883 $revisions = $edits = (int)$dbr->selectField(
1886 [ 'rev_page' => $title->getArticleID() ],
1890 // @todo i18n issue/patchwork message
1891 $context->getOutput()->addHTML(
1892 '<strong class="mw-delete-warning-revisions">' .
1893 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1894 $context->msg( 'word-separator' )->escaped() . Linker
::linkKnown( $title,
1895 $context->msg( 'history' )->escaped(),
1897 [ 'action' => 'history' ] ) .
1901 if ( $title->isBigDeletion() ) {
1902 global $wgDeleteRevisionsLimit;
1903 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1905 'delete-warning-toobig',
1906 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1912 $this->confirmDelete( $reason );
1916 * Output deletion confirmation dialog
1917 * @todo Move to another file?
1918 * @param string $reason Prefilled reason
1920 public function confirmDelete( $reason ) {
1921 wfDebug( "Article::confirmDelete\n" );
1923 $title = $this->getTitle();
1924 $ctx = $this->getContext();
1925 $outputPage = $ctx->getOutput();
1926 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1927 $outputPage->addBacklinkSubtitle( $title );
1928 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1929 $outputPage->addModules( 'mediawiki.action.delete' );
1931 $backlinkCache = $title->getBacklinkCache();
1932 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1933 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1934 'deleting-backlinks-warning' );
1937 $subpageQueryLimit = 51;
1938 $subpages = $title->getSubpages( $subpageQueryLimit );
1939 $subpageCount = count( $subpages );
1940 if ( $subpageCount > 0 ) {
1941 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1942 [ 'deleting-subpages-warning', Message
::numParam( $subpageCount ) ] );
1944 $outputPage->addWikiMsg( 'confirmdeletetext' );
1946 Hooks
::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
1948 $user = $this->getContext()->getUser();
1949 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1951 $outputPage->enableOOUI();
1955 $options = Xml
::listDropDownOptions(
1956 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
1957 [ 'other' => $ctx->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
1959 $options = Xml
::listDropDownOptionsOoui( $options );
1961 $fields[] = new OOUI\
FieldLayout(
1962 new OOUI\
DropdownInputWidget( [
1963 'name' => 'wpDeleteReasonList',
1964 'inputId' => 'wpDeleteReasonList',
1966 'infusable' => true,
1968 'options' => $options
1971 'label' => $ctx->msg( 'deletecomment' )->text(),
1976 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
1977 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
1978 // Unicode codepoints.
1979 $fields[] = new OOUI\
FieldLayout(
1980 new OOUI\
TextInputWidget( [
1981 'name' => 'wpReason',
1982 'inputId' => 'wpReason',
1984 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
1985 'infusable' => true,
1987 'autofocus' => true,
1990 'label' => $ctx->msg( 'deleteotherreason' )->text(),
1995 if ( $user->isLoggedIn() ) {
1996 $fields[] = new OOUI\
FieldLayout(
1997 new OOUI\
CheckboxInputWidget( [
1998 'name' => 'wpWatch',
1999 'inputId' => 'wpWatch',
2001 'selected' => $checkWatch,
2004 'label' => $ctx->msg( 'watchthis' )->text(),
2005 'align' => 'inline',
2006 'infusable' => true,
2010 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
2011 if ( $permissionManager->userHasRight( $user, 'suppressrevision' ) ) {
2012 $fields[] = new OOUI\
FieldLayout(
2013 new OOUI\
CheckboxInputWidget( [
2014 'name' => 'wpSuppress',
2015 'inputId' => 'wpSuppress',
2019 'label' => $ctx->msg( 'revdelete-suppress' )->text(),
2020 'align' => 'inline',
2021 'infusable' => true,
2026 $fields[] = new OOUI\
FieldLayout(
2027 new OOUI\
ButtonInputWidget( [
2028 'name' => 'wpConfirmB',
2029 'inputId' => 'wpConfirmB',
2031 'value' => $ctx->msg( 'deletepage' )->text(),
2032 'label' => $ctx->msg( 'deletepage' )->text(),
2033 'flags' => [ 'primary', 'destructive' ],
2041 $fieldset = new OOUI\
FieldsetLayout( [
2042 'label' => $ctx->msg( 'delete-legend' )->text(),
2043 'id' => 'mw-delete-table',
2047 $form = new OOUI\
FormLayout( [
2049 'action' => $title->getLocalURL( 'action=delete' ),
2050 'id' => 'deleteconfirm',
2052 $form->appendContent(
2054 new OOUI\
HtmlSnippet(
2055 Html
::hidden( 'wpEditToken', $user->getEditToken( [ 'delete', $title->getPrefixedText() ] ) )
2059 $outputPage->addHTML(
2060 new OOUI\
PanelLayout( [
2061 'classes' => [ 'deletepage-wrapper' ],
2062 'expanded' => false,
2069 if ( $permissionManager->userHasRight( $user, 'editinterface' ) ) {
2070 $link = Linker
::linkKnown(
2071 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
2072 wfMessage( 'delete-edit-reasonlist' )->escaped(),
2074 [ 'action' => 'edit' ]
2076 $outputPage->addHTML( '<p class="mw-delete-editreasons">' . $link . '</p>' );
2079 $deleteLogPage = new LogPage( 'delete' );
2080 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2081 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
2085 * Perform a deletion and output success or failure messages
2086 * @param string $reason
2087 * @param bool $suppress
2088 * @param bool $immediate false allows deleting over time via the job queue
2089 * @throws FatalError
2090 * @throws MWException
2092 public function doDelete( $reason, $suppress = false, $immediate = false ) {
2094 $context = $this->getContext();
2095 $outputPage = $context->getOutput();
2096 $user = $context->getUser();
2097 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user,
2098 [], 'delete', $immediate );
2100 if ( $status->isOK() ) {
2101 $deleted = $this->getTitle()->getPrefixedText();
2103 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
2104 $outputPage->setRobotPolicy( 'noindex,nofollow' );
2106 if ( $status->isGood() ) {
2107 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
2108 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
2109 Hooks
::run( 'ArticleDeleteAfterSuccess', [ $this->getTitle(), $outputPage ] );
2111 $outputPage->addWikiMsg( 'delete-scheduled', wfEscapeWikiText( $deleted ) );
2114 $outputPage->returnToMain( false );
2116 $outputPage->setPageTitle(
2117 wfMessage( 'cannotdelete-title',
2118 $this->getTitle()->getPrefixedText() )
2121 if ( $error == '' ) {
2122 $outputPage->wrapWikiTextAsInterface(
2123 'error mw-error-cannotdelete',
2124 $status->getWikiText()
2126 $deleteLogPage = new LogPage( 'delete' );
2127 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2129 LogEventsList
::showLogExtract(
2135 $outputPage->addHTML( $error );
2140 /* Caching functions */
2143 * checkLastModified returns true if it has taken care of all
2144 * output to the client that is necessary for this request.
2145 * (that is, it has sent a cached version of the page)
2147 * @return bool True if cached version send, false otherwise
2149 protected function tryFileCache() {
2150 static $called = false;
2153 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2158 if ( $this->isFileCacheable() ) {
2159 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
2160 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
2161 wfDebug( "Article::tryFileCache(): about to load file\n" );
2162 $cache->loadFromFileCache( $this->getContext() );
2165 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2166 ob_start( [ &$cache, 'saveToFileCache' ] );
2169 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2176 * Check if the page can be cached
2177 * @param int $mode One of the HTMLFileCache::MODE_* constants (since 1.28)
2180 public function isFileCacheable( $mode = HTMLFileCache
::MODE_NORMAL
) {
2183 if ( HTMLFileCache
::useFileCache( $this->getContext(), $mode ) ) {
2184 $cacheable = $this->mPage
->getId()
2185 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
2186 // Extension may have reason to disable file caching on some pages.
2188 // Avoid PHP 7.1 warning of passing $this by reference
2189 $articlePage = $this;
2190 $cacheable = Hooks
::run( 'IsFileCacheable', [ &$articlePage ] );
2200 * Lightweight method to get the parser output for a page, checking the parser cache
2201 * and so on. Doesn't consider most of the stuff that Article::view() is forced to
2202 * consider, so it's not appropriate to use there.
2204 * @since 1.16 (r52326) for LiquidThreads
2206 * @param int|null $oldid Revision ID or null
2207 * @param User|null $user The relevant user
2208 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
2210 public function getParserOutput( $oldid = null, User
$user = null ) {
2211 // XXX: bypasses mParserOptions and thus setParserOptions()
2213 if ( $user === null ) {
2214 $parserOptions = $this->getParserOptions();
2216 $parserOptions = $this->mPage
->makeParserOptions( $user );
2219 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
2223 * Override the ParserOptions used to render the primary article wikitext.
2225 * @param ParserOptions $options
2226 * @throws MWException If the parser options where already initialized.
2228 public function setParserOptions( ParserOptions
$options ) {
2229 if ( $this->mParserOptions
) {
2230 throw new MWException( "can't change parser options after they have already been set" );
2233 // clone, so if $options is modified later, it doesn't confuse the parser cache.
2234 $this->mParserOptions
= clone $options;
2238 * Get parser options suitable for rendering the primary article wikitext
2239 * @return ParserOptions
2241 public function getParserOptions() {
2242 if ( !$this->mParserOptions
) {
2243 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
2245 // Clone to allow modifications of the return value without affecting cache
2246 return clone $this->mParserOptions
;
2250 * Sets the context this Article is executed in
2252 * @param IContextSource $context
2255 public function setContext( $context ) {
2256 $this->mContext
= $context;
2260 * Gets the context this Article is executed in
2262 * @return IContextSource
2265 public function getContext() {
2266 if ( $this->mContext
instanceof IContextSource
) {
2267 return $this->mContext
;
2269 wfDebug( __METHOD__
. " called and \$mContext is null. " .
2270 "Return RequestContext::getMain(); for sanity\n" );
2271 return RequestContext
::getMain();
2276 * Use PHP's magic __get handler to handle accessing of
2277 * raw WikiPage fields for backwards compatibility.
2279 * @param string $fname Field name
2282 public function __get( $fname ) {
2283 if ( property_exists( $this->mPage
, $fname ) ) {
2284 # wfWarn( "Access to raw $fname field " . __CLASS__ );
2285 return $this->mPage
->$fname;
2287 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2291 * Use PHP's magic __set handler to handle setting of
2292 * raw WikiPage fields for backwards compatibility.
2294 * @param string $fname Field name
2295 * @param mixed $fvalue New value
2297 public function __set( $fname, $fvalue ) {
2298 if ( property_exists( $this->mPage
, $fname ) ) {
2299 # wfWarn( "Access to raw $fname field of " . __CLASS__ );
2300 $this->mPage
->$fname = $fvalue;
2301 // Note: extensions may want to toss on new fields
2302 } elseif ( !in_array( $fname, [ 'mContext', 'mPage' ] ) ) {
2303 $this->mPage
->$fname = $fvalue;
2305 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2310 * Call to WikiPage function for backwards compatibility.
2311 * @see WikiPage::checkFlags
2313 public function checkFlags( $flags ) {
2314 return $this->mPage
->checkFlags( $flags );
2318 * Call to WikiPage function for backwards compatibility.
2319 * @see WikiPage::checkTouched
2321 public function checkTouched() {
2322 return $this->mPage
->checkTouched();
2326 * Call to WikiPage function for backwards compatibility.
2327 * @see WikiPage::clearPreparedEdit
2329 public function clearPreparedEdit() {
2330 $this->mPage
->clearPreparedEdit();
2334 * Call to WikiPage function for backwards compatibility.
2335 * @see WikiPage::doDeleteArticleReal
2337 public function doDeleteArticleReal(
2338 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User
$user = null,
2339 $tags = [], $immediate = false
2341 return $this->mPage
->doDeleteArticleReal(
2342 $reason, $suppress, $u1, $u2, $error, $user, $tags, 'delete', $immediate
2347 * Call to WikiPage function for backwards compatibility.
2348 * @see WikiPage::doDeleteUpdates
2350 public function doDeleteUpdates(
2352 Content
$content = null,
2356 $this->mPage
->doDeleteUpdates( $id, $content, $revision, $user );
2360 * Call to WikiPage function for backwards compatibility.
2361 * @deprecated since 1.29. Use WikiPage::doEditContent() directly instead
2362 * @see WikiPage::doEditContent
2364 public function doEditContent( Content
$content, $summary, $flags = 0, $originalRevId = false,
2365 User
$user = null, $serialFormat = null
2367 wfDeprecated( __METHOD__
, '1.29' );
2368 return $this->mPage
->doEditContent( $content, $summary, $flags, $originalRevId,
2369 $user, $serialFormat
2374 * Call to WikiPage function for backwards compatibility.
2375 * @see WikiPage::doEditUpdates
2377 public function doEditUpdates( Revision
$revision, User
$user, array $options = [] ) {
2378 return $this->mPage
->doEditUpdates( $revision, $user, $options );
2382 * Call to WikiPage function for backwards compatibility.
2383 * @see WikiPage::doPurge
2384 * @note In 1.28 (and only 1.28), this took a $flags parameter that
2385 * controlled how much purging was done.
2387 public function doPurge() {
2388 return $this->mPage
->doPurge();
2392 * Call to WikiPage function for backwards compatibility.
2393 * @see WikiPage::doViewUpdates
2395 public function doViewUpdates( User
$user, $oldid = 0 ) {
2396 $this->mPage
->doViewUpdates( $user, $oldid );
2400 * Call to WikiPage function for backwards compatibility.
2401 * @see WikiPage::exists
2403 public function exists() {
2404 return $this->mPage
->exists();
2408 * Call to WikiPage function for backwards compatibility.
2409 * @see WikiPage::followRedirect
2411 public function followRedirect() {
2412 return $this->mPage
->followRedirect();
2416 * Call to WikiPage function for backwards compatibility.
2417 * @see ContentHandler::getActionOverrides
2419 public function getActionOverrides() {
2420 return $this->mPage
->getActionOverrides();
2424 * Call to WikiPage function for backwards compatibility.
2425 * @see WikiPage::getAutoDeleteReason
2427 public function getAutoDeleteReason( &$hasHistory ) {
2428 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2432 * Call to WikiPage function for backwards compatibility.
2433 * @see WikiPage::getCategories
2435 public function getCategories() {
2436 return $this->mPage
->getCategories();
2440 * Call to WikiPage function for backwards compatibility.
2441 * @see WikiPage::getComment
2443 public function getComment( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2444 return $this->mPage
->getComment( $audience, $user );
2448 * Call to WikiPage function for backwards compatibility.
2449 * @see WikiPage::getContentHandler
2451 public function getContentHandler() {
2452 return $this->mPage
->getContentHandler();
2456 * Call to WikiPage function for backwards compatibility.
2457 * @see WikiPage::getContentModel
2459 public function getContentModel() {
2460 return $this->mPage
->getContentModel();
2464 * Call to WikiPage function for backwards compatibility.
2465 * @see WikiPage::getContributors
2467 public function getContributors() {
2468 return $this->mPage
->getContributors();
2472 * Call to WikiPage function for backwards compatibility.
2473 * @see WikiPage::getCreator
2475 public function getCreator( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2476 return $this->mPage
->getCreator( $audience, $user );
2480 * Call to WikiPage function for backwards compatibility.
2481 * @see WikiPage::getDeletionUpdates
2483 public function getDeletionUpdates( Content
$content = null ) {
2484 return $this->mPage
->getDeletionUpdates( $content );
2488 * Call to WikiPage function for backwards compatibility.
2489 * @see WikiPage::getHiddenCategories
2491 public function getHiddenCategories() {
2492 return $this->mPage
->getHiddenCategories();
2496 * Call to WikiPage function for backwards compatibility.
2497 * @see WikiPage::getId
2499 public function getId() {
2500 return $this->mPage
->getId();
2504 * Call to WikiPage function for backwards compatibility.
2505 * @see WikiPage::getLatest
2507 public function getLatest() {
2508 return $this->mPage
->getLatest();
2512 * Call to WikiPage function for backwards compatibility.
2513 * @see WikiPage::getLinksTimestamp
2515 public function getLinksTimestamp() {
2516 return $this->mPage
->getLinksTimestamp();
2520 * Call to WikiPage function for backwards compatibility.
2521 * @see WikiPage::getMinorEdit
2523 public function getMinorEdit() {
2524 return $this->mPage
->getMinorEdit();
2528 * Call to WikiPage function for backwards compatibility.
2529 * @see WikiPage::getOldestRevision
2531 public function getOldestRevision() {
2532 return $this->mPage
->getOldestRevision();
2536 * Call to WikiPage function for backwards compatibility.
2537 * @see WikiPage::getRedirectTarget
2539 public function getRedirectTarget() {
2540 return $this->mPage
->getRedirectTarget();
2544 * Call to WikiPage function for backwards compatibility.
2545 * @see WikiPage::getRedirectURL
2547 public function getRedirectURL( $rt ) {
2548 return $this->mPage
->getRedirectURL( $rt );
2552 * Call to WikiPage function for backwards compatibility.
2553 * @see WikiPage::getRevision
2555 public function getRevision() {
2556 return $this->mPage
->getRevision();
2560 * Call to WikiPage function for backwards compatibility.
2561 * @see WikiPage::getTimestamp
2563 public function getTimestamp() {
2564 return $this->mPage
->getTimestamp();
2568 * Call to WikiPage function for backwards compatibility.
2569 * @see WikiPage::getTouched
2571 public function getTouched() {
2572 return $this->mPage
->getTouched();
2576 * Call to WikiPage function for backwards compatibility.
2577 * @see WikiPage::getUndoContent
2579 public function getUndoContent( Revision
$undo, Revision
$undoafter = null ) {
2580 return $this->mPage
->getUndoContent( $undo, $undoafter );
2584 * Call to WikiPage function for backwards compatibility.
2585 * @see WikiPage::getUser
2587 public function getUser( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2588 return $this->mPage
->getUser( $audience, $user );
2592 * Call to WikiPage function for backwards compatibility.
2593 * @see WikiPage::getUserText
2595 public function getUserText( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2596 return $this->mPage
->getUserText( $audience, $user );
2600 * Call to WikiPage function for backwards compatibility.
2601 * @see WikiPage::hasViewableContent
2603 public function hasViewableContent() {
2604 return $this->mPage
->hasViewableContent();
2608 * Call to WikiPage function for backwards compatibility.
2609 * @see WikiPage::insertOn
2611 public function insertOn( $dbw, $pageId = null ) {
2612 return $this->mPage
->insertOn( $dbw, $pageId );
2616 * Call to WikiPage function for backwards compatibility.
2617 * @see WikiPage::insertProtectNullRevision
2619 public function insertProtectNullRevision( $revCommentMsg, array $limit,
2620 array $expiry, $cascade, $reason, $user = null
2622 return $this->mPage
->insertProtectNullRevision( $revCommentMsg, $limit,
2623 $expiry, $cascade, $reason, $user
2628 * Call to WikiPage function for backwards compatibility.
2629 * @see WikiPage::insertRedirect
2631 public function insertRedirect() {
2632 return $this->mPage
->insertRedirect();
2636 * Call to WikiPage function for backwards compatibility.
2637 * @see WikiPage::insertRedirectEntry
2639 public function insertRedirectEntry( Title
$rt, $oldLatest = null ) {
2640 return $this->mPage
->insertRedirectEntry( $rt, $oldLatest );
2644 * Call to WikiPage function for backwards compatibility.
2645 * @see WikiPage::isCountable
2647 public function isCountable( $editInfo = false ) {
2648 return $this->mPage
->isCountable( $editInfo );
2652 * Call to WikiPage function for backwards compatibility.
2653 * @see WikiPage::isRedirect
2655 public function isRedirect() {
2656 return $this->mPage
->isRedirect();
2660 * Call to WikiPage function for backwards compatibility.
2661 * @see WikiPage::loadFromRow
2663 public function loadFromRow( $data, $from ) {
2664 return $this->mPage
->loadFromRow( $data, $from );
2668 * Call to WikiPage function for backwards compatibility.
2669 * @see WikiPage::loadPageData
2671 public function loadPageData( $from = 'fromdb' ) {
2672 $this->mPage
->loadPageData( $from );
2676 * Call to WikiPage function for backwards compatibility.
2677 * @see WikiPage::lockAndGetLatest
2679 public function lockAndGetLatest() {
2680 return $this->mPage
->lockAndGetLatest();
2684 * Call to WikiPage function for backwards compatibility.
2685 * @see WikiPage::makeParserOptions
2687 public function makeParserOptions( $context ) {
2688 return $this->mPage
->makeParserOptions( $context );
2692 * Call to WikiPage function for backwards compatibility.
2693 * @see WikiPage::pageDataFromId
2695 public function pageDataFromId( $dbr, $id, $options = [] ) {
2696 return $this->mPage
->pageDataFromId( $dbr, $id, $options );
2700 * Call to WikiPage function for backwards compatibility.
2701 * @see WikiPage::pageDataFromTitle
2703 public function pageDataFromTitle( $dbr, $title, $options = [] ) {
2704 return $this->mPage
->pageDataFromTitle( $dbr, $title, $options );
2708 * Call to WikiPage function for backwards compatibility.
2709 * @see WikiPage::prepareContentForEdit
2711 public function prepareContentForEdit(
2712 Content
$content, $revision = null, User
$user = null,
2713 $serialFormat = null, $useCache = true
2715 return $this->mPage
->prepareContentForEdit(
2716 $content, $revision, $user,
2717 $serialFormat, $useCache
2722 * Call to WikiPage function for backwards compatibility.
2723 * @see WikiPage::protectDescription
2725 public function protectDescription( array $limit, array $expiry ) {
2726 return $this->mPage
->protectDescription( $limit, $expiry );
2730 * Call to WikiPage function for backwards compatibility.
2731 * @see WikiPage::protectDescriptionLog
2733 public function protectDescriptionLog( array $limit, array $expiry ) {
2734 return $this->mPage
->protectDescriptionLog( $limit, $expiry );
2738 * Call to WikiPage function for backwards compatibility.
2739 * @see WikiPage::replaceSectionAtRev
2741 public function replaceSectionAtRev( $sectionId, Content
$sectionContent,
2742 $sectionTitle = '', $baseRevId = null
2744 return $this->mPage
->replaceSectionAtRev( $sectionId, $sectionContent,
2745 $sectionTitle, $baseRevId
2750 * Call to WikiPage function for backwards compatibility.
2751 * @see WikiPage::replaceSectionContent
2753 public function replaceSectionContent(
2754 $sectionId, Content
$sectionContent, $sectionTitle = '', $edittime = null
2756 return $this->mPage
->replaceSectionContent(
2757 $sectionId, $sectionContent, $sectionTitle, $edittime
2762 * Call to WikiPage function for backwards compatibility.
2763 * @see WikiPage::setTimestamp
2765 public function setTimestamp( $ts ) {
2766 $this->mPage
->setTimestamp( $ts );
2770 * Call to WikiPage function for backwards compatibility.
2771 * @see WikiPage::shouldCheckParserCache
2773 public function shouldCheckParserCache( ParserOptions
$parserOptions, $oldId ) {
2774 return $this->mPage
->shouldCheckParserCache( $parserOptions, $oldId );
2778 * Call to WikiPage function for backwards compatibility.
2779 * @see WikiPage::supportsSections
2781 public function supportsSections() {
2782 return $this->mPage
->supportsSections();
2786 * Call to WikiPage function for backwards compatibility.
2787 * @see WikiPage::triggerOpportunisticLinksUpdate
2789 public function triggerOpportunisticLinksUpdate( ParserOutput
$parserOutput ) {
2790 return $this->mPage
->triggerOpportunisticLinksUpdate( $parserOutput );
2794 * Call to WikiPage function for backwards compatibility.
2795 * @see WikiPage::updateCategoryCounts
2797 public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
2798 return $this->mPage
->updateCategoryCounts( $added, $deleted, $id );
2802 * Call to WikiPage function for backwards compatibility.
2803 * @see WikiPage::updateIfNewerOn
2805 public function updateIfNewerOn( $dbw, $revision ) {
2806 return $this->mPage
->updateIfNewerOn( $dbw, $revision );
2810 * Call to WikiPage function for backwards compatibility.
2811 * @see WikiPage::updateRedirectOn
2813 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
2814 return $this->mPage
->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect );
2818 * Call to WikiPage function for backwards compatibility.
2819 * @see WikiPage::updateRevisionOn
2821 public function updateRevisionOn( $dbw, $revision, $lastRevision = null,
2822 $lastRevIsRedirect = null
2824 return $this->mPage
->updateRevisionOn( $dbw, $revision, $lastRevision,
2830 * @param array $limit
2831 * @param array $expiry
2832 * @param bool &$cascade
2833 * @param string $reason
2837 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2840 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2844 * @param array $limit
2845 * @param string $reason
2846 * @param int &$cascade
2847 * @param array $expiry
2850 public function updateRestrictions( $limit = [], $reason = '',
2851 &$cascade = 0, $expiry = []
2853 return $this->mPage
->doUpdateRestrictions(
2858 $this->getContext()->getUser()
2863 * @param string $reason
2864 * @param bool $suppress
2865 * @param int|null $u1 Unused
2866 * @param bool|null $u2 Unused
2867 * @param string &$error
2868 * @param bool $immediate false allows deleting over time via the job queue
2870 * @throws FatalError
2871 * @throws MWException
2873 public function doDeleteArticle(
2874 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', $immediate = false
2876 return $this->mPage
->doDeleteArticle( $reason, $suppress, $u1, $u2, $error,
2881 * @param string $fromP
2882 * @param string $summary
2883 * @param string $token
2885 * @param array &$resultDetails
2886 * @param User|null $user
2889 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2891 $user = $this->getContext()->getUser();
2894 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2898 * @param string $fromP
2899 * @param string $summary
2901 * @param array &$resultDetails
2902 * @param User|null $guser
2905 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2907 $guser = $this->getContext()->getUser();
2910 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2914 * @param bool &$hasHistory
2917 public function generateReason( &$hasHistory ) {
2918 $title = $this->mPage
->getTitle();
2919 $handler = ContentHandler
::getForTitle( $title );
2920 return $handler->getAutoDeleteReason( $title, $hasHistory );