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(
812 false, 'view-pool-error', $this->getContext()->getLanguage()
814 $outputPage->wrapWikiTextAsInterface( 'errorbox', $errortext );
816 # Connection or timeout error
820 if ( $this->mParserOutput
) {
821 $outputPage->addParserOutput( $this->mParserOutput
, $poOptions );
824 if ( $rev && $this->getRevisionRedirectTarget( $rev ) ) {
825 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
826 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
831 # Should be unreachable, but just in case...
837 // Get the ParserOutput actually *displayed* here.
838 // Note that $this->mParserOutput is the *current*/oldid version output.
839 // Note that the ArticleViewHeader hook is allowed to set $outputDone to a
840 // ParserOutput instance.
841 $pOutput = ( $outputDone instanceof ParserOutput
)
842 ?
$outputDone // object fetched by hook
843 : ( $this->mParserOutput ?
: null ); // ParserOutput or null, avoid false
845 # Adjust title for main page & pages with displaytitle
847 $this->adjustDisplayTitle( $pOutput );
850 # For the main page, overwrite the <title> element with the con-
851 # tents of 'pagetitle-view-mainpage' instead of the default (if
853 # This message always exists because it is in the i18n files
854 if ( $this->getTitle()->isMainPage() ) {
855 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
856 if ( !$msg->isDisabled() ) {
857 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
861 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
862 # This could use getTouched(), but that could be scary for major template edits.
863 $outputPage->adaptCdnTTL( $this->mPage
->getTimestamp(), IExpiringStore
::TTL_DAY
);
865 # Check for any __NOINDEX__ tags on the page using $pOutput
866 $policy = $this->getRobotPolicy( 'view', $pOutput ?
: null );
867 $outputPage->setIndexPolicy( $policy['index'] );
868 $outputPage->setFollowPolicy( $policy['follow'] ); // FIXME: test this
870 $this->showViewFooter();
871 $this->mPage
->doViewUpdates( $user, $oldid ); // FIXME: test this
873 # Load the postEdit module if the user just saved this revision
874 # See also EditPage::setPostEditCookie
875 $request = $this->getContext()->getRequest();
876 $cookieKey = EditPage
::POST_EDIT_COOKIE_KEY_PREFIX
. $this->getRevIdFetched();
877 $postEdit = $request->getCookie( $cookieKey );
879 # Clear the cookie. This also prevents caching of the response.
880 $request->response()->clearCookie( $cookieKey );
881 $outputPage->addJsConfigVars( 'wgPostEdit', $postEdit );
882 $outputPage->addModules( 'mediawiki.action.view.postEdit' ); // FIXME: test this
887 * @param RevisionRecord $revision
890 private function getRevisionRedirectTarget( RevisionRecord
$revision ) {
891 // TODO: find a *good* place for the code that determines the redirect target for
893 // NOTE: Use main slot content. Compare code in DerivedPageDataUpdater::revisionIsRedirect.
894 $content = $revision->getContent( SlotRecord
::MAIN
);
895 return $content ?
$content->getRedirectTarget() : null;
899 * Adjust title for pages with displaytitle, -{T|}- or language conversion
900 * @param ParserOutput $pOutput
902 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
903 $out = $this->getContext()->getOutput();
905 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
906 $titleText = $pOutput->getTitleText();
907 if ( strval( $titleText ) !== '' ) {
908 $out->setPageTitle( $titleText );
909 $out->setDisplayTitle( $titleText );
914 * Show a diff page according to current request variables. For use within
915 * Article::view() only, other callers should use the DifferenceEngine class.
917 protected function showDiffPage() {
918 $request = $this->getContext()->getRequest();
919 $user = $this->getContext()->getUser();
920 $diff = $request->getVal( 'diff' );
921 $rcid = $request->getVal( 'rcid' );
922 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
923 $purge = $request->getVal( 'action' ) == 'purge';
924 $unhide = $request->getInt( 'unhide' ) == 1;
925 $oldid = $this->getOldID();
927 $rev = $this->getRevisionFetched();
930 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
931 $msg = $this->getContext()->msg( 'difference-missing-revision' )
935 $this->getContext()->getOutput()->addHTML( $msg );
939 $contentHandler = $rev->getContentHandler();
940 $de = $contentHandler->createDifferenceEngine(
949 // DifferenceEngine directly fetched the revision:
950 $this->mRevIdFetched
= $de->getNewid();
951 $de->showDiffPage( $diffOnly );
953 // Run view updates for the newer revision being diffed (and shown
954 // below the diff if not $diffOnly).
955 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
956 // New can be false, convert it to 0 - this conveniently means the latest revision
957 $this->mPage
->doViewUpdates( $user, (int)$new );
961 * Get the robot policy to be used for the current view
962 * @param string $action The action= GET parameter
963 * @param ParserOutput|null $pOutput
964 * @return array The policy that should be set
965 * @todo actions other than 'view'
967 public function getRobotPolicy( $action, ParserOutput
$pOutput = null ) {
968 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
970 $ns = $this->getTitle()->getNamespace();
972 # Don't index user and user talk pages for blocked users (T13443)
973 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
974 $specificTarget = null;
976 $titleText = $this->getTitle()->getText();
977 if ( IP
::isValid( $titleText ) ) {
978 $vagueTarget = $titleText;
980 $specificTarget = $titleText;
982 if ( DatabaseBlock
::newFromTarget( $specificTarget, $vagueTarget ) instanceof DatabaseBlock
) {
984 'index' => 'noindex',
985 'follow' => 'nofollow'
990 if ( $this->mPage
->getId() === 0 ||
$this->getOldID() ) {
991 # Non-articles (special pages etc), and old revisions
993 'index' => 'noindex',
994 'follow' => 'nofollow'
996 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
997 # Discourage indexing of printable versions, but encourage following
999 'index' => 'noindex',
1000 'follow' => 'follow'
1002 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
1003 # For ?curid=x urls, disallow indexing
1005 'index' => 'noindex',
1006 'follow' => 'follow'
1010 # Otherwise, construct the policy based on the various config variables.
1011 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
1013 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
1014 # Honour customised robot policies for this namespace
1015 $policy = array_merge(
1017 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
1020 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
1021 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1022 # a final sanity check that we have really got the parser output.
1023 $policy = array_merge(
1025 [ 'index' => $pOutput->getIndexPolicy() ]
1029 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
1030 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1031 $policy = array_merge(
1033 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
1041 * Converts a String robot policy into an associative array, to allow
1042 * merging of several policies using array_merge().
1043 * @param array|string $policy Returns empty array on null/false/'', transparent
1044 * to already-converted arrays, converts string.
1045 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
1047 public static function formatRobotPolicy( $policy ) {
1048 if ( is_array( $policy ) ) {
1050 } elseif ( !$policy ) {
1054 $policy = explode( ',', $policy );
1055 $policy = array_map( 'trim', $policy );
1058 foreach ( $policy as $var ) {
1059 if ( in_array( $var, [ 'index', 'noindex' ] ) ) {
1060 $arr['index'] = $var;
1061 } elseif ( in_array( $var, [ 'follow', 'nofollow' ] ) ) {
1062 $arr['follow'] = $var;
1070 * If this request is a redirect view, send "redirected from" subtitle to
1071 * the output. Returns true if the header was needed, false if this is not
1072 * a redirect view. Handles both local and remote redirects.
1076 public function showRedirectedFromHeader() {
1077 global $wgRedirectSources;
1079 $context = $this->getContext();
1080 $outputPage = $context->getOutput();
1081 $request = $context->getRequest();
1082 $rdfrom = $request->getVal( 'rdfrom' );
1084 // Construct a URL for the current page view, but with the target title
1085 $query = $request->getValues();
1086 unset( $query['rdfrom'] );
1087 unset( $query['title'] );
1088 if ( $this->getTitle()->isRedirect() ) {
1089 // Prevent double redirects
1090 $query['redirect'] = 'no';
1092 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
1094 if ( isset( $this->mRedirectedFrom
) ) {
1095 // Avoid PHP 7.1 warning of passing $this by reference
1096 $articlePage = $this;
1098 // This is an internally redirected page view.
1099 // We'll need a backlink to the source page for navigation.
1100 if ( Hooks
::run( 'ArticleViewRedirect', [ &$articlePage ] ) ) {
1101 $redir = Linker
::linkKnown(
1102 $this->mRedirectedFrom
,
1105 [ 'redirect' => 'no' ]
1108 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1109 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1112 // Add the script to update the displayed URL and
1113 // set the fragment if one was specified in the redirect
1114 $outputPage->addJsConfigVars( [
1115 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1117 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1119 // Add a <link rel="canonical"> tag
1120 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
1122 // Tell the output object that the user arrived at this article through a redirect
1123 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1127 } elseif ( $rdfrom ) {
1128 // This is an externally redirected view, from some other wiki.
1129 // If it was reported from a trusted site, supply a backlink.
1130 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1131 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1132 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1133 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1136 // Add the script to update the displayed URL
1137 $outputPage->addJsConfigVars( [
1138 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1140 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1150 * Show a header specific to the namespace currently being viewed, like
1151 * [[MediaWiki:Talkpagetext]]. For Article::view().
1153 public function showNamespaceHeader() {
1154 if ( $this->getTitle()->isTalkPage() && !wfMessage( 'talkpageheader' )->isDisabled() ) {
1155 $this->getContext()->getOutput()->wrapWikiMsg(
1156 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1157 [ 'talkpageheader' ]
1163 * Show the footer section of an ordinary page view
1165 public function showViewFooter() {
1166 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1167 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1168 && IP
::isValid( $this->getTitle()->getText() )
1170 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1173 // Show a footer allowing the user to patrol the shown revision or page if possible
1174 $patrolFooterShown = $this->showPatrolFooter();
1176 Hooks
::run( 'ArticleViewFooter', [ $this, $patrolFooterShown ] );
1180 * If patrol is possible, output a patrol UI box. This is called from the
1181 * footer section of ordinary page views. If patrol is not possible or not
1182 * desired, does nothing.
1183 * Side effect: When the patrol link is build, this method will call
1184 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1188 public function showPatrolFooter() {
1189 global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol;
1191 // Allow hooks to decide whether to not output this at all
1192 if ( !Hooks
::run( 'ArticleShowPatrolFooter', [ $this ] ) ) {
1196 $outputPage = $this->getContext()->getOutput();
1197 $user = $this->getContext()->getUser();
1198 $title = $this->getTitle();
1201 if ( !MediaWikiServices
::getInstance()->getPermissionManager()
1202 ->quickUserCan( 'patrol', $user, $title )
1203 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol
1204 ||
( $wgUseFilePatrol && $title->inNamespace( NS_FILE
) ) )
1206 // Patrolling is disabled or the user isn't allowed to
1210 if ( $this->mRevision
1211 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1213 // The current revision is already older than what could be in the RC table
1214 // 6h tolerance because the RC might not be cleaned out regularly
1218 // Check for cached results
1219 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1220 $key = $cache->makeKey( 'unpatrollable-page', $title->getArticleID() );
1221 if ( $cache->get( $key ) ) {
1225 $dbr = wfGetDB( DB_REPLICA
);
1226 $oldestRevisionTimestamp = $dbr->selectField(
1228 'MIN( rev_timestamp )',
1229 [ 'rev_page' => $title->getArticleID() ],
1233 // New page patrol: Get the timestamp of the oldest revison which
1234 // the revision table holds for the given page. Then we look
1235 // whether it's within the RC lifespan and if it is, we try
1236 // to get the recentchanges row belonging to that entry
1237 // (with rc_new = 1).
1238 $recentPageCreation = false;
1239 if ( $oldestRevisionTimestamp
1240 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1242 // 6h tolerance because the RC might not be cleaned out regularly
1243 $recentPageCreation = true;
1244 $rc = RecentChange
::newFromConds(
1247 'rc_timestamp' => $oldestRevisionTimestamp,
1248 'rc_namespace' => $title->getNamespace(),
1249 'rc_cur_id' => $title->getArticleID()
1254 // Use generic patrol message for new pages
1255 $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
1259 // File patrol: Get the timestamp of the latest upload for this page,
1260 // check whether it is within the RC lifespan and if it is, we try
1261 // to get the recentchanges row belonging to that entry
1262 // (with rc_type = RC_LOG, rc_log_type = upload).
1263 $recentFileUpload = false;
1264 if ( ( !$rc ||
$rc->getAttribute( 'rc_patrolled' ) ) && $wgUseFilePatrol
1265 && $title->getNamespace() === NS_FILE
) {
1266 // Retrieve timestamp of most recent upload
1267 $newestUploadTimestamp = $dbr->selectField(
1269 'MAX( img_timestamp )',
1270 [ 'img_name' => $title->getDBkey() ],
1273 if ( $newestUploadTimestamp
1274 && RecentChange
::isInRCLifespan( $newestUploadTimestamp, 21600 )
1276 // 6h tolerance because the RC might not be cleaned out regularly
1277 $recentFileUpload = true;
1278 $rc = RecentChange
::newFromConds(
1280 'rc_type' => RC_LOG
,
1281 'rc_log_type' => 'upload',
1282 'rc_timestamp' => $newestUploadTimestamp,
1283 'rc_namespace' => NS_FILE
,
1284 'rc_cur_id' => $title->getArticleID()
1289 // Use patrol message specific to files
1290 $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
1295 if ( !$recentPageCreation && !$recentFileUpload ) {
1296 // Page creation and latest upload (for files) is too old to be in RC
1298 // We definitely can't patrol so cache the information
1299 // When a new file version is uploaded, the cache is cleared
1300 $cache->set( $key, '1' );
1306 // Don't cache: This can be hit if the page gets accessed very fast after
1307 // its creation / latest upload or in case we have high replica DB lag. In case
1308 // the revision is too old, we will already return above.
1312 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1313 // Patrolled RC entry around
1315 // Cache the information we gathered above in case we can't patrol
1316 // Don't cache in case we can patrol as this could change
1317 $cache->set( $key, '1' );
1322 if ( $rc->getPerformer()->equals( $user ) ) {
1323 // Don't show a patrol link for own creations/uploads. If the user could
1324 // patrol them, they already would be patrolled
1328 $outputPage->preventClickjacking();
1329 if ( MediaWikiServices
::getInstance()
1330 ->getPermissionManager()
1331 ->userHasRight( $user, 'writeapi' )
1333 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1336 $link = Linker
::linkKnown(
1338 $markPatrolledMsg->escaped(),
1341 'action' => 'markpatrolled',
1342 'rcid' => $rc->getAttribute( 'rc_id' ),
1346 $outputPage->addHTML(
1347 "<div class='patrollink' data-mw='interface'>" .
1348 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1356 * Purge the cache used to check if it is worth showing the patrol footer
1357 * For example, it is done during re-uploads when file patrol is used.
1358 * @param int $articleID ID of the article to purge
1361 public static function purgePatrolFooterCache( $articleID ) {
1362 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1363 $cache->delete( $cache->makeKey( 'unpatrollable-page', $articleID ) );
1367 * Show the error text for a missing article. For articles in the MediaWiki
1368 * namespace, show the default message text. To be called from Article::view().
1370 public function showMissingArticle() {
1371 global $wgSend404Code;
1373 $outputPage = $this->getContext()->getOutput();
1374 // Whether the page is a root user page of an existing user (but not a subpage)
1375 $validUserPage = false;
1377 $title = $this->getTitle();
1379 $services = MediaWikiServices
::getInstance();
1381 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1382 if ( $title->getNamespace() == NS_USER
1383 ||
$title->getNamespace() == NS_USER_TALK
1385 $rootPart = explode( '/', $title->getText() )[0];
1386 $user = User
::newFromName( $rootPart, false /* allow IP users */ );
1387 $ip = User
::isIP( $rootPart );
1388 $block = DatabaseBlock
::newFromTarget( $user, $user );
1390 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1391 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1392 [ 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ] );
1394 !is_null( $block ) &&
1395 $block->getType() != DatabaseBlock
::TYPE_AUTO
&&
1396 ( $block->isSitewide() ||
$user->isBlockedFrom( $title ) )
1398 // Show log extract if the user is sitewide blocked or is partially
1399 // blocked and not allowed to edit their user page or user talk page
1400 LogEventsList
::showLogExtract(
1403 $services->getNamespaceInfo()->getCanonicalName( NS_USER
) . ':' .
1404 $block->getTarget(),
1408 'showIfEmpty' => false,
1410 'blocked-notice-logextract',
1411 $user->getName() # Support GENDER in notice
1415 $validUserPage = !$title->isSubpage();
1417 $validUserPage = !$title->isSubpage();
1421 Hooks
::run( 'ShowMissingArticle', [ $this ] );
1423 # Show delete and move logs if there were any such events.
1424 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1425 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1426 $dbCache = ObjectCache
::getInstance( 'db-replicated' );
1427 $key = $dbCache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) );
1428 $loggedIn = $this->getContext()->getUser()->isLoggedIn();
1429 $sessionExists = $this->getContext()->getRequest()->getSession()->isPersistent();
1430 if ( $loggedIn ||
$dbCache->get( $key ) ||
$sessionExists ) {
1431 $logTypes = [ 'delete', 'move', 'protect' ];
1433 $dbr = wfGetDB( DB_REPLICA
);
1435 $conds = [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ];
1436 // Give extensions a chance to hide their (unrelated) log entries
1437 Hooks
::run( 'Article::MissingArticleConditions', [ &$conds, $logTypes ] );
1438 LogEventsList
::showLogExtract(
1446 'showIfEmpty' => false,
1447 'msgKey' => [ $loggedIn ||
$sessionExists
1448 ?
'moveddeleted-notice'
1449 : 'moveddeleted-notice-recent'
1455 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1456 // If there's no backing content, send a 404 Not Found
1457 // for better machine handling of broken links.
1458 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1461 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1462 $policy = $this->getRobotPolicy( 'view' );
1463 $outputPage->setIndexPolicy( $policy['index'] );
1464 $outputPage->setFollowPolicy( $policy['follow'] );
1466 $hookResult = Hooks
::run( 'BeforeDisplayNoArticleText', [ $this ] );
1468 if ( !$hookResult ) {
1472 # Show error message
1473 $oldid = $this->getOldID();
1474 $pm = MediaWikiServices
::getInstance()->getPermissionManager();
1475 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI
&& $title->hasSourceText() ) {
1476 // use fake Content object for system message
1477 $parserOptions = ParserOptions
::newCanonical( 'canonical' );
1478 $outputPage->addParserOutput( $this->getEmptyPageParserOutput( $parserOptions ) );
1481 $text = wfMessage( 'missing-revision', $oldid )->plain();
1482 } elseif ( $pm->quickUserCan( 'create', $this->getContext()->getUser(), $title ) &&
1483 $pm->quickUserCan( 'edit', $this->getContext()->getUser(), $title )
1485 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1486 $text = wfMessage( $message )->plain();
1488 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1491 $dir = $this->getContext()->getLanguage()->getDir();
1492 $lang = $this->getContext()->getLanguage()->getHtmlCode();
1493 $outputPage->addWikiTextAsInterface( Xml
::openElement( 'div', [
1494 'class' => "noarticletext mw-content-$dir",
1497 ] ) . "\n$text\n</div>" );
1502 * If the revision requested for view is deleted, check permissions.
1503 * Send either an error message or a warning header to the output.
1505 * @return bool True if the view is allowed, false if not.
1507 public function showDeletedRevisionHeader() {
1508 if ( !$this->mRevision
->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
1513 $outputPage = $this->getContext()->getOutput();
1514 $user = $this->getContext()->getUser();
1515 // If the user is not allowed to see it...
1516 if ( !$this->mRevision
->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
1517 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1518 'rev-deleted-text-permission' );
1521 // If the user needs to confirm that they want to see it...
1522 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1523 # Give explanation and add a link to view the revision...
1524 $oldid = intval( $this->getOldID() );
1525 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1526 $msg = $this->mRevision
->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
1527 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1528 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1532 // We are allowed to see...
1534 $msg = $this->mRevision
->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
1535 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1536 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1543 * Generate the navigation links when browsing through an article revisions
1544 * It shows the information as:
1545 * Revision as of \<date\>; view current revision
1546 * \<- Previous version | Next Version -\>
1548 * @param int $oldid Revision ID of this article revision
1550 public function setOldSubtitle( $oldid = 0 ) {
1551 // Avoid PHP 7.1 warning of passing $this by reference
1552 $articlePage = $this;
1554 if ( !Hooks
::run( 'DisplayOldSubtitle', [ &$articlePage, &$oldid ] ) ) {
1558 $context = $this->getContext();
1559 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1561 # Cascade unhide param in links for easy deletion browsing
1564 $extraParams['unhide'] = 1;
1567 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1568 $revision = $this->mRevision
;
1570 $revision = Revision
::newFromId( $oldid );
1573 $timestamp = $revision->getTimestamp();
1575 $current = ( $oldid == $this->mPage
->getLatest() );
1576 $language = $context->getLanguage();
1577 $user = $context->getUser();
1579 $td = $language->userTimeAndDate( $timestamp, $user );
1580 $tddate = $language->userDate( $timestamp, $user );
1581 $tdtime = $language->userTime( $timestamp, $user );
1583 # Show user links if allowed to see them. If hidden, then show them only if requested...
1584 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1586 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1587 ?
'revision-info-current'
1590 $outputPage = $context->getOutput();
1591 $revisionInfo = "<div id=\"mw-{$infomsg}\">" .
1592 $context->msg( $infomsg, $td )
1593 ->rawParams( $userlinks )
1594 ->params( $revision->getId(), $tddate, $tdtime, $revision->getUserText() )
1595 ->rawParams( Linker
::revComment( $revision, true, true ) )
1600 ?
$context->msg( 'currentrevisionlink' )->escaped()
1601 : Linker
::linkKnown(
1603 $context->msg( 'currentrevisionlink' )->escaped(),
1608 ?
$context->msg( 'diff' )->escaped()
1609 : Linker
::linkKnown(
1611 $context->msg( 'diff' )->escaped(),
1618 $rl = MediaWikiServices
::getInstance()->getRevisionLookup();
1619 $prevExist = (bool)$rl->getPreviousRevision( $revision->getRevisionRecord() );
1620 $prevlink = $prevExist
1621 ? Linker
::linkKnown(
1623 $context->msg( 'previousrevision' )->escaped(),
1626 'direction' => 'prev',
1630 : $context->msg( 'previousrevision' )->escaped();
1631 $prevdiff = $prevExist
1632 ? Linker
::linkKnown(
1634 $context->msg( 'diff' )->escaped(),
1641 : $context->msg( 'diff' )->escaped();
1642 $nextlink = $current
1643 ?
$context->msg( 'nextrevision' )->escaped()
1644 : Linker
::linkKnown(
1646 $context->msg( 'nextrevision' )->escaped(),
1649 'direction' => 'next',
1653 $nextdiff = $current
1654 ?
$context->msg( 'diff' )->escaped()
1655 : Linker
::linkKnown(
1657 $context->msg( 'diff' )->escaped(),
1665 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1666 if ( $cdel !== '' ) {
1670 // the outer div is need for styling the revision info and nav in MobileFrontend
1671 $outputPage->addSubtitle( "<div class=\"mw-revision warningbox\">" . $revisionInfo .
1672 "<div id=\"mw-revision-nav\">" . $cdel .
1673 $context->msg( 'revision-nav' )->rawParams(
1674 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1675 )->escaped() . "</div></div>" );
1679 * Return the HTML for the top of a redirect page
1681 * Chances are you should just be using the ParserOutput from
1682 * WikitextContent::getParserOutput instead of calling this for redirects.
1684 * @param Title|array $target Destination(s) to redirect
1685 * @param bool $appendSubtitle [optional]
1686 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1687 * @return string Containing HTML with redirect link
1689 * @deprecated since 1.30
1691 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1692 $lang = $this->getTitle()->getPageLanguage();
1693 $out = $this->getContext()->getOutput();
1694 if ( $appendSubtitle ) {
1695 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1697 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1698 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1702 * Return the HTML for the top of a redirect page
1704 * Chances are you should just be using the ParserOutput from
1705 * WikitextContent::getParserOutput instead of calling this for redirects.
1708 * @param Language $lang
1709 * @param Title|array $target Destination(s) to redirect
1710 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1711 * @return string Containing HTML with redirect link
1713 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1714 if ( !is_array( $target ) ) {
1715 $target = [ $target ];
1718 $html = '<ul class="redirectText">';
1719 /** @var Title $title */
1720 foreach ( $target as $title ) {
1721 $html .= '<li>' . Linker
::link(
1723 htmlspecialchars( $title->getFullText() ),
1725 // Make sure wiki page redirects are not followed
1726 $title->isRedirect() ?
[ 'redirect' => 'no' ] : [],
1727 ( $forceKnown ?
[ 'known', 'noclasses' ] : [] )
1732 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1734 return '<div class="redirectMsg">' .
1735 '<p>' . $redirectToText . '</p>' .
1741 * Adds help link with an icon via page indicators.
1742 * Link target can be overridden by a local message containing a wikilink:
1743 * the message key is: 'namespace-' + namespace number + '-helppage'.
1744 * @param string $to Target MediaWiki.org page title or encoded URL.
1745 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1748 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1750 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1753 $out = $this->getContext()->getOutput();
1754 if ( !$msg->isDisabled() ) {
1755 $helpUrl = Skin
::makeUrl( $msg->plain() );
1756 $out->addHelpLink( $helpUrl, true );
1758 $out->addHelpLink( $to, $overrideBaseUrl );
1763 * Handle action=render
1765 public function render() {
1766 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1767 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1768 // We later set 'enableSectionEditLinks=false' based on this; also used by ImagePage
1769 $this->viewIsRenderAction
= true;
1774 * action=protect handler
1776 public function protect() {
1777 $form = new ProtectionForm( $this );
1782 * action=unprotect handler (alias)
1784 public function unprotect() {
1789 * UI entry point for page deletion
1791 public function delete() {
1792 # This code desperately needs to be totally rewritten
1794 $title = $this->getTitle();
1795 $context = $this->getContext();
1796 $user = $context->getUser();
1797 $request = $context->getRequest();
1800 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1801 if ( count( $permissionErrors ) ) {
1802 throw new PermissionsError( 'delete', $permissionErrors );
1805 # Read-only check...
1806 if ( wfReadOnly() ) {
1807 throw new ReadOnlyError
;
1810 # Better double-check that it hasn't been deleted yet!
1811 $this->mPage
->loadPageData(
1812 $request->wasPosted() ? WikiPage
::READ_LATEST
: WikiPage
::READ_NORMAL
1814 if ( !$this->mPage
->exists() ) {
1815 $deleteLogPage = new LogPage( 'delete' );
1816 $outputPage = $context->getOutput();
1817 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1818 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1819 [ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ]
1821 $outputPage->addHTML(
1822 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1824 LogEventsList
::showLogExtract(
1833 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1834 $deleteReason = $request->getText( 'wpReason' );
1836 if ( $deleteReasonList == 'other' ) {
1837 $reason = $deleteReason;
1838 } elseif ( $deleteReason != '' ) {
1839 // Entry from drop down menu + additional comment
1840 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1841 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1843 $reason = $deleteReasonList;
1846 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1847 [ 'delete', $this->getTitle()->getPrefixedText() ] )
1849 # Flag to hide all contents of the archived revisions
1851 $suppress = $request->getCheck( 'wpSuppress' ) && MediaWikiServices
::getInstance()
1852 ->getPermissionManager()
1853 ->userHasRight( $user, 'suppressrevision' );
1855 $this->doDelete( $reason, $suppress );
1857 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1862 // Generate deletion reason
1863 $hasHistory = false;
1866 $reason = $this->generateReason( $hasHistory );
1867 } catch ( Exception
$e ) {
1868 # if a page is horribly broken, we still want to be able to
1869 # delete it. So be lenient about errors here.
1870 wfDebug( "Error while building auto delete summary: $e" );
1875 // If the page has a history, insert a warning
1876 if ( $hasHistory ) {
1877 $title = $this->getTitle();
1879 // The following can use the real revision count as this is only being shown for users
1880 // that can delete this page.
1881 // This, as a side-effect, also makes sure that the following query isn't being run for
1882 // pages with a larger history, unless the user has the 'bigdelete' right
1883 // (and is about to delete this page).
1884 $dbr = wfGetDB( DB_REPLICA
);
1885 $revisions = $edits = (int)$dbr->selectField(
1888 [ 'rev_page' => $title->getArticleID() ],
1892 // @todo i18n issue/patchwork message
1893 $context->getOutput()->addHTML(
1894 '<strong class="mw-delete-warning-revisions">' .
1895 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1896 $context->msg( 'word-separator' )->escaped() . Linker
::linkKnown( $title,
1897 $context->msg( 'history' )->escaped(),
1899 [ 'action' => 'history' ] ) .
1903 if ( $title->isBigDeletion() ) {
1904 global $wgDeleteRevisionsLimit;
1905 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1907 'delete-warning-toobig',
1908 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1914 $this->confirmDelete( $reason );
1918 * Output deletion confirmation dialog
1919 * @todo Move to another file?
1920 * @param string $reason Prefilled reason
1922 public function confirmDelete( $reason ) {
1923 wfDebug( "Article::confirmDelete\n" );
1925 $title = $this->getTitle();
1926 $ctx = $this->getContext();
1927 $outputPage = $ctx->getOutput();
1928 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1929 $outputPage->addBacklinkSubtitle( $title );
1930 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1931 $outputPage->addModules( 'mediawiki.action.delete' );
1933 $backlinkCache = $title->getBacklinkCache();
1934 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1935 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1936 'deleting-backlinks-warning' );
1939 $subpageQueryLimit = 51;
1940 $subpages = $title->getSubpages( $subpageQueryLimit );
1941 $subpageCount = count( $subpages );
1942 if ( $subpageCount > 0 ) {
1943 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1944 [ 'deleting-subpages-warning', Message
::numParam( $subpageCount ) ] );
1946 $outputPage->addWikiMsg( 'confirmdeletetext' );
1948 Hooks
::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
1950 $user = $this->getContext()->getUser();
1951 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1953 $outputPage->enableOOUI();
1957 $options = Xml
::listDropDownOptions(
1958 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
1959 [ 'other' => $ctx->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
1961 $options = Xml
::listDropDownOptionsOoui( $options );
1963 $fields[] = new OOUI\
FieldLayout(
1964 new OOUI\
DropdownInputWidget( [
1965 'name' => 'wpDeleteReasonList',
1966 'inputId' => 'wpDeleteReasonList',
1968 'infusable' => true,
1970 'options' => $options
1973 'label' => $ctx->msg( 'deletecomment' )->text(),
1978 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
1979 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
1980 // Unicode codepoints.
1981 $fields[] = new OOUI\
FieldLayout(
1982 new OOUI\
TextInputWidget( [
1983 'name' => 'wpReason',
1984 'inputId' => 'wpReason',
1986 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
1987 'infusable' => true,
1989 'autofocus' => true,
1992 'label' => $ctx->msg( 'deleteotherreason' )->text(),
1997 if ( $user->isLoggedIn() ) {
1998 $fields[] = new OOUI\
FieldLayout(
1999 new OOUI\
CheckboxInputWidget( [
2000 'name' => 'wpWatch',
2001 'inputId' => 'wpWatch',
2003 'selected' => $checkWatch,
2006 'label' => $ctx->msg( 'watchthis' )->text(),
2007 'align' => 'inline',
2008 'infusable' => true,
2012 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
2013 if ( $permissionManager->userHasRight( $user, 'suppressrevision' ) ) {
2014 $fields[] = new OOUI\
FieldLayout(
2015 new OOUI\
CheckboxInputWidget( [
2016 'name' => 'wpSuppress',
2017 'inputId' => 'wpSuppress',
2021 'label' => $ctx->msg( 'revdelete-suppress' )->text(),
2022 'align' => 'inline',
2023 'infusable' => true,
2028 $fields[] = new OOUI\
FieldLayout(
2029 new OOUI\
ButtonInputWidget( [
2030 'name' => 'wpConfirmB',
2031 'inputId' => 'wpConfirmB',
2033 'value' => $ctx->msg( 'deletepage' )->text(),
2034 'label' => $ctx->msg( 'deletepage' )->text(),
2035 'flags' => [ 'primary', 'destructive' ],
2043 $fieldset = new OOUI\
FieldsetLayout( [
2044 'label' => $ctx->msg( 'delete-legend' )->text(),
2045 'id' => 'mw-delete-table',
2049 $form = new OOUI\
FormLayout( [
2051 'action' => $title->getLocalURL( 'action=delete' ),
2052 'id' => 'deleteconfirm',
2054 $form->appendContent(
2056 new OOUI\
HtmlSnippet(
2057 Html
::hidden( 'wpEditToken', $user->getEditToken( [ 'delete', $title->getPrefixedText() ] ) )
2061 $outputPage->addHTML(
2062 new OOUI\
PanelLayout( [
2063 'classes' => [ 'deletepage-wrapper' ],
2064 'expanded' => false,
2071 if ( $permissionManager->userHasRight( $user, 'editinterface' ) ) {
2072 $link = Linker
::linkKnown(
2073 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
2074 wfMessage( 'delete-edit-reasonlist' )->escaped(),
2076 [ 'action' => 'edit' ]
2078 $outputPage->addHTML( '<p class="mw-delete-editreasons">' . $link . '</p>' );
2081 $deleteLogPage = new LogPage( 'delete' );
2082 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2083 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
2087 * Perform a deletion and output success or failure messages
2088 * @param string $reason
2089 * @param bool $suppress
2090 * @param bool $immediate false allows deleting over time via the job queue
2091 * @throws FatalError
2092 * @throws MWException
2094 public function doDelete( $reason, $suppress = false, $immediate = false ) {
2096 $context = $this->getContext();
2097 $outputPage = $context->getOutput();
2098 $user = $context->getUser();
2099 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user,
2100 [], 'delete', $immediate );
2102 if ( $status->isOK() ) {
2103 $deleted = $this->getTitle()->getPrefixedText();
2105 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
2106 $outputPage->setRobotPolicy( 'noindex,nofollow' );
2108 if ( $status->isGood() ) {
2109 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
2110 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
2111 Hooks
::run( 'ArticleDeleteAfterSuccess', [ $this->getTitle(), $outputPage ] );
2113 $outputPage->addWikiMsg( 'delete-scheduled', wfEscapeWikiText( $deleted ) );
2116 $outputPage->returnToMain( false );
2118 $outputPage->setPageTitle(
2119 wfMessage( 'cannotdelete-title',
2120 $this->getTitle()->getPrefixedText() )
2123 if ( $error == '' ) {
2124 $outputPage->wrapWikiTextAsInterface(
2125 'error mw-error-cannotdelete',
2126 $status->getWikiText( false, false, $context->getLanguage() )
2128 $deleteLogPage = new LogPage( 'delete' );
2129 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2131 LogEventsList
::showLogExtract(
2137 $outputPage->addHTML( $error );
2142 /* Caching functions */
2145 * checkLastModified returns true if it has taken care of all
2146 * output to the client that is necessary for this request.
2147 * (that is, it has sent a cached version of the page)
2149 * @return bool True if cached version send, false otherwise
2151 protected function tryFileCache() {
2152 static $called = false;
2155 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2160 if ( $this->isFileCacheable() ) {
2161 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
2162 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
2163 wfDebug( "Article::tryFileCache(): about to load file\n" );
2164 $cache->loadFromFileCache( $this->getContext() );
2167 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2168 ob_start( [ &$cache, 'saveToFileCache' ] );
2171 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2178 * Check if the page can be cached
2179 * @param int $mode One of the HTMLFileCache::MODE_* constants (since 1.28)
2182 public function isFileCacheable( $mode = HTMLFileCache
::MODE_NORMAL
) {
2185 if ( HTMLFileCache
::useFileCache( $this->getContext(), $mode ) ) {
2186 $cacheable = $this->mPage
->getId()
2187 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
2188 // Extension may have reason to disable file caching on some pages.
2190 // Avoid PHP 7.1 warning of passing $this by reference
2191 $articlePage = $this;
2192 $cacheable = Hooks
::run( 'IsFileCacheable', [ &$articlePage ] );
2202 * Lightweight method to get the parser output for a page, checking the parser cache
2203 * and so on. Doesn't consider most of the stuff that Article::view() is forced to
2204 * consider, so it's not appropriate to use there.
2206 * @since 1.16 (r52326) for LiquidThreads
2208 * @param int|null $oldid Revision ID or null
2209 * @param User|null $user The relevant user
2210 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
2212 public function getParserOutput( $oldid = null, User
$user = null ) {
2213 // XXX: bypasses mParserOptions and thus setParserOptions()
2215 if ( $user === null ) {
2216 $parserOptions = $this->getParserOptions();
2218 $parserOptions = $this->mPage
->makeParserOptions( $user );
2221 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
2225 * Override the ParserOptions used to render the primary article wikitext.
2227 * @param ParserOptions $options
2228 * @throws MWException If the parser options where already initialized.
2230 public function setParserOptions( ParserOptions
$options ) {
2231 if ( $this->mParserOptions
) {
2232 throw new MWException( "can't change parser options after they have already been set" );
2235 // clone, so if $options is modified later, it doesn't confuse the parser cache.
2236 $this->mParserOptions
= clone $options;
2240 * Get parser options suitable for rendering the primary article wikitext
2241 * @return ParserOptions
2243 public function getParserOptions() {
2244 if ( !$this->mParserOptions
) {
2245 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
2247 // Clone to allow modifications of the return value without affecting cache
2248 return clone $this->mParserOptions
;
2252 * Sets the context this Article is executed in
2254 * @param IContextSource $context
2257 public function setContext( $context ) {
2258 $this->mContext
= $context;
2262 * Gets the context this Article is executed in
2264 * @return IContextSource
2267 public function getContext() {
2268 if ( $this->mContext
instanceof IContextSource
) {
2269 return $this->mContext
;
2271 wfDebug( __METHOD__
. " called and \$mContext is null. " .
2272 "Return RequestContext::getMain(); for sanity\n" );
2273 return RequestContext
::getMain();
2278 * Use PHP's magic __get handler to handle accessing of
2279 * raw WikiPage fields for backwards compatibility.
2281 * @param string $fname Field name
2284 public function __get( $fname ) {
2285 if ( property_exists( $this->mPage
, $fname ) ) {
2286 # wfWarn( "Access to raw $fname field " . __CLASS__ );
2287 return $this->mPage
->$fname;
2289 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2293 * Use PHP's magic __set handler to handle setting of
2294 * raw WikiPage fields for backwards compatibility.
2296 * @param string $fname Field name
2297 * @param mixed $fvalue New value
2299 public function __set( $fname, $fvalue ) {
2300 if ( property_exists( $this->mPage
, $fname ) ) {
2301 # wfWarn( "Access to raw $fname field of " . __CLASS__ );
2302 $this->mPage
->$fname = $fvalue;
2303 // Note: extensions may want to toss on new fields
2304 } elseif ( !in_array( $fname, [ 'mContext', 'mPage' ] ) ) {
2305 $this->mPage
->$fname = $fvalue;
2307 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2312 * Call to WikiPage function for backwards compatibility.
2313 * @see WikiPage::checkFlags
2315 public function checkFlags( $flags ) {
2316 return $this->mPage
->checkFlags( $flags );
2320 * Call to WikiPage function for backwards compatibility.
2321 * @see WikiPage::checkTouched
2323 public function checkTouched() {
2324 return $this->mPage
->checkTouched();
2328 * Call to WikiPage function for backwards compatibility.
2329 * @see WikiPage::clearPreparedEdit
2331 public function clearPreparedEdit() {
2332 $this->mPage
->clearPreparedEdit();
2336 * Call to WikiPage function for backwards compatibility.
2337 * @see WikiPage::doDeleteArticleReal
2339 public function doDeleteArticleReal(
2340 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User
$user = null,
2341 $tags = [], $immediate = false
2343 return $this->mPage
->doDeleteArticleReal(
2344 $reason, $suppress, $u1, $u2, $error, $user, $tags, 'delete', $immediate
2349 * Call to WikiPage function for backwards compatibility.
2350 * @see WikiPage::doDeleteUpdates
2352 public function doDeleteUpdates(
2354 Content
$content = null,
2358 $this->mPage
->doDeleteUpdates( $id, $content, $revision, $user );
2362 * Call to WikiPage function for backwards compatibility.
2363 * @deprecated since 1.29. Use WikiPage::doEditContent() directly instead
2364 * @see WikiPage::doEditContent
2366 public function doEditContent( Content
$content, $summary, $flags = 0, $originalRevId = false,
2367 User
$user = null, $serialFormat = null
2369 wfDeprecated( __METHOD__
, '1.29' );
2370 return $this->mPage
->doEditContent( $content, $summary, $flags, $originalRevId,
2371 $user, $serialFormat
2376 * Call to WikiPage function for backwards compatibility.
2377 * @see WikiPage::doEditUpdates
2379 public function doEditUpdates( Revision
$revision, User
$user, array $options = [] ) {
2380 return $this->mPage
->doEditUpdates( $revision, $user, $options );
2384 * Call to WikiPage function for backwards compatibility.
2385 * @see WikiPage::doPurge
2386 * @note In 1.28 (and only 1.28), this took a $flags parameter that
2387 * controlled how much purging was done.
2389 public function doPurge() {
2390 return $this->mPage
->doPurge();
2394 * Call to WikiPage function for backwards compatibility.
2395 * @see WikiPage::doViewUpdates
2397 public function doViewUpdates( User
$user, $oldid = 0 ) {
2398 $this->mPage
->doViewUpdates( $user, $oldid );
2402 * Call to WikiPage function for backwards compatibility.
2403 * @see WikiPage::exists
2405 public function exists() {
2406 return $this->mPage
->exists();
2410 * Call to WikiPage function for backwards compatibility.
2411 * @see WikiPage::followRedirect
2413 public function followRedirect() {
2414 return $this->mPage
->followRedirect();
2418 * Call to WikiPage function for backwards compatibility.
2419 * @see ContentHandler::getActionOverrides
2421 public function getActionOverrides() {
2422 return $this->mPage
->getActionOverrides();
2426 * Call to WikiPage function for backwards compatibility.
2427 * @see WikiPage::getAutoDeleteReason
2429 public function getAutoDeleteReason( &$hasHistory ) {
2430 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2434 * Call to WikiPage function for backwards compatibility.
2435 * @see WikiPage::getCategories
2437 public function getCategories() {
2438 return $this->mPage
->getCategories();
2442 * Call to WikiPage function for backwards compatibility.
2443 * @see WikiPage::getComment
2445 public function getComment( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2446 return $this->mPage
->getComment( $audience, $user );
2450 * Call to WikiPage function for backwards compatibility.
2451 * @see WikiPage::getContentHandler
2453 public function getContentHandler() {
2454 return $this->mPage
->getContentHandler();
2458 * Call to WikiPage function for backwards compatibility.
2459 * @see WikiPage::getContentModel
2461 public function getContentModel() {
2462 return $this->mPage
->getContentModel();
2466 * Call to WikiPage function for backwards compatibility.
2467 * @see WikiPage::getContributors
2469 public function getContributors() {
2470 return $this->mPage
->getContributors();
2474 * Call to WikiPage function for backwards compatibility.
2475 * @see WikiPage::getCreator
2477 public function getCreator( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2478 return $this->mPage
->getCreator( $audience, $user );
2482 * Call to WikiPage function for backwards compatibility.
2483 * @see WikiPage::getDeletionUpdates
2485 public function getDeletionUpdates( Content
$content = null ) {
2486 return $this->mPage
->getDeletionUpdates( $content );
2490 * Call to WikiPage function for backwards compatibility.
2491 * @see WikiPage::getHiddenCategories
2493 public function getHiddenCategories() {
2494 return $this->mPage
->getHiddenCategories();
2498 * Call to WikiPage function for backwards compatibility.
2499 * @see WikiPage::getId
2501 public function getId() {
2502 return $this->mPage
->getId();
2506 * Call to WikiPage function for backwards compatibility.
2507 * @see WikiPage::getLatest
2509 public function getLatest() {
2510 return $this->mPage
->getLatest();
2514 * Call to WikiPage function for backwards compatibility.
2515 * @see WikiPage::getLinksTimestamp
2517 public function getLinksTimestamp() {
2518 return $this->mPage
->getLinksTimestamp();
2522 * Call to WikiPage function for backwards compatibility.
2523 * @see WikiPage::getMinorEdit
2525 public function getMinorEdit() {
2526 return $this->mPage
->getMinorEdit();
2530 * Call to WikiPage function for backwards compatibility.
2531 * @see WikiPage::getOldestRevision
2533 public function getOldestRevision() {
2534 return $this->mPage
->getOldestRevision();
2538 * Call to WikiPage function for backwards compatibility.
2539 * @see WikiPage::getRedirectTarget
2541 public function getRedirectTarget() {
2542 return $this->mPage
->getRedirectTarget();
2546 * Call to WikiPage function for backwards compatibility.
2547 * @see WikiPage::getRedirectURL
2549 public function getRedirectURL( $rt ) {
2550 return $this->mPage
->getRedirectURL( $rt );
2554 * Call to WikiPage function for backwards compatibility.
2555 * @see WikiPage::getRevision
2557 public function getRevision() {
2558 return $this->mPage
->getRevision();
2562 * Call to WikiPage function for backwards compatibility.
2563 * @see WikiPage::getTimestamp
2565 public function getTimestamp() {
2566 return $this->mPage
->getTimestamp();
2570 * Call to WikiPage function for backwards compatibility.
2571 * @see WikiPage::getTouched
2573 public function getTouched() {
2574 return $this->mPage
->getTouched();
2578 * Call to WikiPage function for backwards compatibility.
2579 * @see WikiPage::getUndoContent
2581 public function getUndoContent( Revision
$undo, Revision
$undoafter = null ) {
2582 return $this->mPage
->getUndoContent( $undo, $undoafter );
2586 * Call to WikiPage function for backwards compatibility.
2587 * @see WikiPage::getUser
2589 public function getUser( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2590 return $this->mPage
->getUser( $audience, $user );
2594 * Call to WikiPage function for backwards compatibility.
2595 * @see WikiPage::getUserText
2597 public function getUserText( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2598 return $this->mPage
->getUserText( $audience, $user );
2602 * Call to WikiPage function for backwards compatibility.
2603 * @see WikiPage::hasViewableContent
2605 public function hasViewableContent() {
2606 return $this->mPage
->hasViewableContent();
2610 * Call to WikiPage function for backwards compatibility.
2611 * @see WikiPage::insertOn
2613 public function insertOn( $dbw, $pageId = null ) {
2614 return $this->mPage
->insertOn( $dbw, $pageId );
2618 * Call to WikiPage function for backwards compatibility.
2619 * @see WikiPage::insertProtectNullRevision
2621 public function insertProtectNullRevision( $revCommentMsg, array $limit,
2622 array $expiry, $cascade, $reason, $user = null
2624 return $this->mPage
->insertProtectNullRevision( $revCommentMsg, $limit,
2625 $expiry, $cascade, $reason, $user
2630 * Call to WikiPage function for backwards compatibility.
2631 * @see WikiPage::insertRedirect
2633 public function insertRedirect() {
2634 return $this->mPage
->insertRedirect();
2638 * Call to WikiPage function for backwards compatibility.
2639 * @see WikiPage::insertRedirectEntry
2641 public function insertRedirectEntry( Title
$rt, $oldLatest = null ) {
2642 return $this->mPage
->insertRedirectEntry( $rt, $oldLatest );
2646 * Call to WikiPage function for backwards compatibility.
2647 * @see WikiPage::isCountable
2649 public function isCountable( $editInfo = false ) {
2650 return $this->mPage
->isCountable( $editInfo );
2654 * Call to WikiPage function for backwards compatibility.
2655 * @see WikiPage::isRedirect
2657 public function isRedirect() {
2658 return $this->mPage
->isRedirect();
2662 * Call to WikiPage function for backwards compatibility.
2663 * @see WikiPage::loadFromRow
2665 public function loadFromRow( $data, $from ) {
2666 return $this->mPage
->loadFromRow( $data, $from );
2670 * Call to WikiPage function for backwards compatibility.
2671 * @see WikiPage::loadPageData
2673 public function loadPageData( $from = 'fromdb' ) {
2674 $this->mPage
->loadPageData( $from );
2678 * Call to WikiPage function for backwards compatibility.
2679 * @see WikiPage::lockAndGetLatest
2681 public function lockAndGetLatest() {
2682 return $this->mPage
->lockAndGetLatest();
2686 * Call to WikiPage function for backwards compatibility.
2687 * @see WikiPage::makeParserOptions
2689 public function makeParserOptions( $context ) {
2690 return $this->mPage
->makeParserOptions( $context );
2694 * Call to WikiPage function for backwards compatibility.
2695 * @see WikiPage::pageDataFromId
2697 public function pageDataFromId( $dbr, $id, $options = [] ) {
2698 return $this->mPage
->pageDataFromId( $dbr, $id, $options );
2702 * Call to WikiPage function for backwards compatibility.
2703 * @see WikiPage::pageDataFromTitle
2705 public function pageDataFromTitle( $dbr, $title, $options = [] ) {
2706 return $this->mPage
->pageDataFromTitle( $dbr, $title, $options );
2710 * Call to WikiPage function for backwards compatibility.
2711 * @see WikiPage::prepareContentForEdit
2713 public function prepareContentForEdit(
2714 Content
$content, $revision = null, User
$user = null,
2715 $serialFormat = null, $useCache = true
2717 return $this->mPage
->prepareContentForEdit(
2718 $content, $revision, $user,
2719 $serialFormat, $useCache
2724 * Call to WikiPage function for backwards compatibility.
2725 * @see WikiPage::protectDescription
2727 public function protectDescription( array $limit, array $expiry ) {
2728 return $this->mPage
->protectDescription( $limit, $expiry );
2732 * Call to WikiPage function for backwards compatibility.
2733 * @see WikiPage::protectDescriptionLog
2735 public function protectDescriptionLog( array $limit, array $expiry ) {
2736 return $this->mPage
->protectDescriptionLog( $limit, $expiry );
2740 * Call to WikiPage function for backwards compatibility.
2741 * @see WikiPage::replaceSectionAtRev
2743 public function replaceSectionAtRev( $sectionId, Content
$sectionContent,
2744 $sectionTitle = '', $baseRevId = null
2746 return $this->mPage
->replaceSectionAtRev( $sectionId, $sectionContent,
2747 $sectionTitle, $baseRevId
2752 * Call to WikiPage function for backwards compatibility.
2753 * @see WikiPage::replaceSectionContent
2755 public function replaceSectionContent(
2756 $sectionId, Content
$sectionContent, $sectionTitle = '', $edittime = null
2758 return $this->mPage
->replaceSectionContent(
2759 $sectionId, $sectionContent, $sectionTitle, $edittime
2764 * Call to WikiPage function for backwards compatibility.
2765 * @see WikiPage::setTimestamp
2767 public function setTimestamp( $ts ) {
2768 $this->mPage
->setTimestamp( $ts );
2772 * Call to WikiPage function for backwards compatibility.
2773 * @see WikiPage::shouldCheckParserCache
2775 public function shouldCheckParserCache( ParserOptions
$parserOptions, $oldId ) {
2776 return $this->mPage
->shouldCheckParserCache( $parserOptions, $oldId );
2780 * Call to WikiPage function for backwards compatibility.
2781 * @see WikiPage::supportsSections
2783 public function supportsSections() {
2784 return $this->mPage
->supportsSections();
2788 * Call to WikiPage function for backwards compatibility.
2789 * @see WikiPage::triggerOpportunisticLinksUpdate
2791 public function triggerOpportunisticLinksUpdate( ParserOutput
$parserOutput ) {
2792 return $this->mPage
->triggerOpportunisticLinksUpdate( $parserOutput );
2796 * Call to WikiPage function for backwards compatibility.
2797 * @see WikiPage::updateCategoryCounts
2799 public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
2800 return $this->mPage
->updateCategoryCounts( $added, $deleted, $id );
2804 * Call to WikiPage function for backwards compatibility.
2805 * @see WikiPage::updateIfNewerOn
2807 public function updateIfNewerOn( $dbw, $revision ) {
2808 return $this->mPage
->updateIfNewerOn( $dbw, $revision );
2812 * Call to WikiPage function for backwards compatibility.
2813 * @see WikiPage::updateRedirectOn
2815 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
2816 return $this->mPage
->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect );
2820 * Call to WikiPage function for backwards compatibility.
2821 * @see WikiPage::updateRevisionOn
2823 public function updateRevisionOn( $dbw, $revision, $lastRevision = null,
2824 $lastRevIsRedirect = null
2826 return $this->mPage
->updateRevisionOn( $dbw, $revision, $lastRevision,
2832 * @param array $limit
2833 * @param array $expiry
2834 * @param bool &$cascade
2835 * @param string $reason
2839 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2842 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2846 * @param array $limit
2847 * @param string $reason
2848 * @param int &$cascade
2849 * @param array $expiry
2852 public function updateRestrictions( $limit = [], $reason = '',
2853 &$cascade = 0, $expiry = []
2855 return $this->mPage
->doUpdateRestrictions(
2860 $this->getContext()->getUser()
2865 * @param string $reason
2866 * @param bool $suppress
2867 * @param int|null $u1 Unused
2868 * @param bool|null $u2 Unused
2869 * @param string &$error
2870 * @param bool $immediate false allows deleting over time via the job queue
2872 * @throws FatalError
2873 * @throws MWException
2875 public function doDeleteArticle(
2876 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', $immediate = false
2878 return $this->mPage
->doDeleteArticle( $reason, $suppress, $u1, $u2, $error,
2883 * @param string $fromP
2884 * @param string $summary
2885 * @param string $token
2887 * @param array &$resultDetails
2888 * @param User|null $user
2891 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2893 $user = $this->getContext()->getUser();
2896 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2900 * @param string $fromP
2901 * @param string $summary
2903 * @param array &$resultDetails
2904 * @param User|null $guser
2907 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2909 $guser = $this->getContext()->getUser();
2912 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2916 * @param bool &$hasHistory
2919 public function generateReason( &$hasHistory ) {
2920 $title = $this->mPage
->getTitle();
2921 $handler = ContentHandler
::getForTitle( $title );
2922 return $handler->getAutoDeleteReason( $title, $hasHistory );