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 if ( $request->getVal( 'direction' ) == 'next' ) {
367 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
370 $this->mRevision
= null;
372 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
374 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
375 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
378 $this->mRevision
= null;
382 $this->mRevIdFetched
= $this->mRevision ?
$this->mRevision
->getId() : 0;
388 * Get text content object
389 * Does *NOT* follow redirects.
390 * @todo When is this null?
391 * @deprecated since 1.32, use fetchRevisionRecord() instead.
393 * @note Code that wants to retrieve page content from the database should
394 * use WikiPage::getContent().
396 * @return Content|null|bool
400 protected function fetchContentObject() {
401 if ( !$this->mContentLoaded
) {
402 $this->fetchRevisionRecord();
405 return $this->mContentObject
;
409 * Fetches the revision to work on.
410 * The revision is typically loaded from the database, but may also be a fake representing
411 * an error message or content supplied by an extension. Refer to $this->fetchResult for
412 * the revision actually loaded from the database, and any errors encountered while doing
415 * @return RevisionRecord|null
417 protected function fetchRevisionRecord() {
418 if ( $this->fetchResult
) {
419 return $this->mRevision ?
$this->mRevision
->getRevisionRecord() : null;
422 $this->mContentLoaded
= true;
423 $this->mContentObject
= null;
425 $oldid = $this->getOldID();
427 // $this->mRevision might already be fetched by getOldIDFromRequest()
428 if ( !$this->mRevision
) {
430 $this->mRevision
= $this->mPage
->getRevision();
432 if ( !$this->mRevision
) {
433 wfDebug( __METHOD__
. " failed to find page data for title " .
434 $this->getTitle()->getPrefixedText() . "\n" );
436 // Just for sanity, output for this case is done by showMissingArticle().
437 $this->fetchResult
= Status
::newFatal( 'noarticletext' );
438 $this->applyContentOverride( $this->makeFetchErrorContent() );
442 $this->mRevision
= Revision
::newFromId( $oldid );
444 if ( !$this->mRevision
) {
445 wfDebug( __METHOD__
. " failed to load revision, rev_id $oldid\n" );
447 $this->fetchResult
= Status
::newFatal( 'missing-revision', $oldid );
448 $this->applyContentOverride( $this->makeFetchErrorContent() );
454 $this->mRevIdFetched
= $this->mRevision
->getId();
455 $this->fetchResult
= Status
::newGood( $this->mRevision
);
458 !$this->mRevision
->userCan( RevisionRecord
::DELETED_TEXT
, $this->getContext()->getUser() )
460 wfDebug( __METHOD__
. " failed to retrieve content of revision " .
461 $this->mRevision
->getId() . "\n" );
463 // Just for sanity, output for this case is done by showDeletedRevisionHeader().
464 $this->fetchResult
= Status
::newFatal( 'rev-deleted-text-permission' );
465 $this->applyContentOverride( $this->makeFetchErrorContent() );
469 if ( Hooks
::isRegistered( 'ArticleAfterFetchContentObject' ) ) {
470 $contentObject = $this->mRevision
->getContent(
471 RevisionRecord
::FOR_THIS_USER
,
472 $this->getContext()->getUser()
475 $hookContentObject = $contentObject;
477 // Avoid PHP 7.1 warning of passing $this by reference
478 $articlePage = $this;
481 'ArticleAfterFetchContentObject',
482 [ &$articlePage, &$hookContentObject ],
486 if ( $hookContentObject !== $contentObject ) {
487 // A hook handler is trying to override the content
488 $this->applyContentOverride( $hookContentObject );
493 $this->mContentObject
= $this->mRevision
->getContent(
494 RevisionRecord
::FOR_THIS_USER
,
495 $this->getContext()->getUser()
498 return $this->mRevision
->getRevisionRecord();
502 * Returns a Content object representing any error in $this->fetchContent, or null
503 * if there is no such error.
505 * @return Content|null
507 private function makeFetchErrorContent() {
508 if ( !$this->fetchResult ||
$this->fetchResult
->isOK() ) {
512 return new MessageContent( $this->fetchResult
->getMessage() );
516 * Applies a content override by constructing a fake Revision object and assigning
517 * it to mRevision. The fake revision will not have a user, timestamp or summary set.
519 * This mechanism exists mainly to accommodate extensions that use the
520 * ArticleAfterFetchContentObject. Once that hook has been removed, there should no longer
521 * be a need for a fake revision object. fetchRevisionRecord() presently also uses this mechanism
522 * to report errors, but that could be changed to use $this->fetchResult instead.
524 * @param Content $override Content to be used instead of the actual page content,
525 * coming from an extension or representing an error message.
527 private function applyContentOverride( Content
$override ) {
528 // Construct a fake revision
529 $rev = new MutableRevisionRecord( $this->getTitle() );
530 $rev->setContent( SlotRecord
::MAIN
, $override );
532 $this->mRevision
= new Revision( $rev );
535 $this->mContentObject
= $override;
539 * Returns true if the currently-referenced revision is the current edit
540 * to this page (and it exists).
543 public function isCurrent() {
544 # If no oldid, this is the current version.
545 if ( $this->getOldID() == 0 ) {
549 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
553 * Get the fetched Revision object depending on request parameters or null
554 * on failure. The revision returned may be a fake representing an error message or
555 * wrapping content supplied by an extension. Refer to $this->fetchResult for the
556 * revision actually loaded from the database.
559 * @return Revision|null
561 public function getRevisionFetched() {
562 $this->fetchRevisionRecord();
564 if ( $this->fetchResult
->isOK() ) {
565 return $this->mRevision
;
570 * Use this to fetch the rev ID used on page views
572 * Before fetchRevisionRecord was called, this returns the page's latest revision,
573 * regardless of what getOldID() returns.
575 * @return int Revision ID of last article revision
577 public function getRevIdFetched() {
578 if ( $this->fetchResult
&& $this->fetchResult
->isOK() ) {
579 return $this->fetchResult
->value
->getId();
581 return $this->mPage
->getLatest();
586 * This is the default action of the index.php entry point: just view the
587 * page of the given title.
589 public function view() {
590 global $wgUseFileCache;
592 # Get variables from query string
593 # As side effect this will load the revision and update the title
594 # in a revision ID is passed in the request, so this should remain
595 # the first call of this method even if $oldid is used way below.
596 $oldid = $this->getOldID();
598 $user = $this->getContext()->getUser();
599 # Another whitelist check in case getOldID() is altering the title
600 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
601 if ( count( $permErrors ) ) {
602 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
603 throw new PermissionsError( 'read', $permErrors );
606 $outputPage = $this->getContext()->getOutput();
607 # getOldID() may as well want us to redirect somewhere else
608 if ( $this->mRedirectUrl
) {
609 $outputPage->redirect( $this->mRedirectUrl
);
610 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
615 # If we got diff in the query, we want to see a diff page instead of the article.
616 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
617 wfDebug( __METHOD__
. ": showing diff page\n" );
618 $this->showDiffPage();
623 # Set page title (may be overridden by DISPLAYTITLE)
624 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
626 $outputPage->setArticleFlag( true );
627 # Allow frames by default
628 $outputPage->allowClickjacking();
630 $parserCache = MediaWikiServices
::getInstance()->getParserCache();
632 $parserOptions = $this->getParserOptions();
634 # Render printable version, use printable version cache
635 if ( $outputPage->isPrintable() ) {
636 $parserOptions->setIsPrintable( true );
637 $poOptions['enableSectionEditLinks'] = false;
638 } elseif ( $this->viewIsRenderAction ||
!$this->isCurrent() ||
639 !MediaWikiServices
::getInstance()->getPermissionManager()
640 ->quickUserCan( 'edit', $user, $this->getTitle() )
642 $poOptions['enableSectionEditLinks'] = false;
645 # Try client and file cache
646 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
647 # Try to stream the output from file cache
648 if ( $wgUseFileCache && $this->tryFileCache() ) {
649 wfDebug( __METHOD__
. ": done file cache\n" );
650 # tell wgOut that output is taken care of
651 $outputPage->disable();
652 $this->mPage
->doViewUpdates( $user, $oldid );
658 # Should the parser cache be used?
659 $useParserCache = $this->mPage
->shouldCheckParserCache( $parserOptions, $oldid );
660 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
661 if ( $user->getStubThreshold() ) {
662 MediaWikiServices
::getInstance()->getStatsdDataFactory()->increment( 'pcache_miss_stub' );
665 $this->showRedirectedFromHeader();
666 $this->showNamespaceHeader();
668 # Iterate through the possible ways of constructing the output text.
669 # Keep going until $outputDone is set, or we run out of things to do.
672 $this->mParserOutput
= false;
674 while ( !$outputDone && ++
$pass ) {
677 // Avoid PHP 7.1 warning of passing $this by reference
678 $articlePage = $this;
679 Hooks
::run( 'ArticleViewHeader', [ &$articlePage, &$outputDone, &$useParserCache ] );
682 # Early abort if the page doesn't exist
683 if ( !$this->mPage
->exists() ) {
684 wfDebug( __METHOD__
. ": showing missing article\n" );
685 $this->showMissingArticle();
686 $this->mPage
->doViewUpdates( $user );
690 # Try the parser cache
691 if ( $useParserCache ) {
692 $this->mParserOutput
= $parserCache->get( $this->mPage
, $parserOptions );
694 if ( $this->mParserOutput
!== false ) {
696 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
697 $this->setOldSubtitle( $oldid );
699 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
701 $outputPage->addParserOutput( $this->mParserOutput
, $poOptions );
702 # Ensure that UI elements requiring revision ID have
703 # the correct version information.
704 $outputPage->setRevisionId( $this->mPage
->getLatest() );
705 # Preload timestamp to avoid a DB hit
706 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
707 if ( $cachedTimestamp !== null ) {
708 $outputPage->setRevisionTimestamp( $cachedTimestamp );
709 $this->mPage
->setTimestamp( $cachedTimestamp );
716 # Are we looking at an old revision
717 $rev = $this->fetchRevisionRecord();
718 if ( $oldid && $this->fetchResult
->isOK() ) {
719 $this->setOldSubtitle( $oldid );
721 if ( !$this->showDeletedRevisionHeader() ) {
722 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
727 # Ensure that UI elements requiring revision ID have
728 # the correct version information.
729 $outputPage->setRevisionId( $this->getRevIdFetched() );
730 # Preload timestamp to avoid a DB hit
731 $outputPage->setRevisionTimestamp( $this->mPage
->getTimestamp() );
733 # Pages containing custom CSS or JavaScript get special treatment
734 if ( $this->getTitle()->isSiteConfigPage() ||
$this->getTitle()->isUserConfigPage() ) {
735 $dir = $this->getContext()->getLanguage()->getDir();
736 $lang = $this->getContext()->getLanguage()->getHtmlCode();
738 $outputPage->wrapWikiMsg(
739 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
742 } elseif ( !Hooks
::run( 'ArticleRevisionViewCustom', [
749 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
750 // Allow extensions do their own custom view for certain pages
752 } elseif ( !Hooks
::run( 'ArticleContentViewCustom',
753 [ $this->fetchContentObject(), $this->getTitle(), $outputPage ], '1.32' )
755 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
756 // Allow extensions do their own custom view for certain pages
761 # Run the parse, protected by a pool counter
762 wfDebug( __METHOD__
. ": doing uncached parse\n" );
764 $rev = $this->fetchRevisionRecord();
768 $poolArticleView = new PoolWorkArticleView(
771 $this->getRevIdFetched(),
774 // permission checking was done earlier via showDeletedRevisionHeader()
777 $ok = $poolArticleView->execute();
778 $error = $poolArticleView->getError();
779 $this->mParserOutput
= $poolArticleView->getParserOutput() ?
: null;
781 # Don't cache a dirty ParserOutput object
782 if ( $poolArticleView->getIsDirty() ) {
783 $outputPage->setCdnMaxage( 0 );
784 $outputPage->addHTML( "<!-- parser cache is expired, " .
785 "sending anyway due to pool overload-->\n" );
793 $outputPage->clearHTML(); // for release() errors
794 $outputPage->enableClientCache( false );
795 $outputPage->setRobotPolicy( 'noindex,nofollow' );
797 $errortext = $error->getWikiText( false, 'view-pool-error' );
798 $outputPage->wrapWikiTextAsInterface( 'errorbox', $errortext );
800 # Connection or timeout error
804 if ( $this->mParserOutput
) {
805 $outputPage->addParserOutput( $this->mParserOutput
, $poOptions );
808 if ( $rev && $this->getRevisionRedirectTarget( $rev ) ) {
809 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
810 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
815 # Should be unreachable, but just in case...
821 // Get the ParserOutput actually *displayed* here.
822 // Note that $this->mParserOutput is the *current*/oldid version output.
823 // Note that the ArticleViewHeader hook is allowed to set $outputDone to a
824 // ParserOutput instance.
825 $pOutput = ( $outputDone instanceof ParserOutput
)
826 ?
$outputDone // object fetched by hook
827 : ( $this->mParserOutput ?
: null ); // ParserOutput or null, avoid false
829 # Adjust title for main page & pages with displaytitle
831 $this->adjustDisplayTitle( $pOutput );
834 # For the main page, overwrite the <title> element with the con-
835 # tents of 'pagetitle-view-mainpage' instead of the default (if
837 # This message always exists because it is in the i18n files
838 if ( $this->getTitle()->isMainPage() ) {
839 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
840 if ( !$msg->isDisabled() ) {
841 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
845 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
846 # This could use getTouched(), but that could be scary for major template edits.
847 $outputPage->adaptCdnTTL( $this->mPage
->getTimestamp(), IExpiringStore
::TTL_DAY
);
849 # Check for any __NOINDEX__ tags on the page using $pOutput
850 $policy = $this->getRobotPolicy( 'view', $pOutput ?
: null );
851 $outputPage->setIndexPolicy( $policy['index'] );
852 $outputPage->setFollowPolicy( $policy['follow'] ); // FIXME: test this
854 $this->showViewFooter();
855 $this->mPage
->doViewUpdates( $user, $oldid ); // FIXME: test this
857 # Load the postEdit module if the user just saved this revision
858 # See also EditPage::setPostEditCookie
859 $request = $this->getContext()->getRequest();
860 $cookieKey = EditPage
::POST_EDIT_COOKIE_KEY_PREFIX
. $this->getRevIdFetched();
861 $postEdit = $request->getCookie( $cookieKey );
863 # Clear the cookie. This also prevents caching of the response.
864 $request->response()->clearCookie( $cookieKey );
865 $outputPage->addJsConfigVars( 'wgPostEdit', $postEdit );
866 $outputPage->addModules( 'mediawiki.action.view.postEdit' ); // FIXME: test this
871 * @param RevisionRecord $revision
874 private function getRevisionRedirectTarget( RevisionRecord
$revision ) {
875 // TODO: find a *good* place for the code that determines the redirect target for
877 // NOTE: Use main slot content. Compare code in DerivedPageDataUpdater::revisionIsRedirect.
878 $content = $revision->getContent( SlotRecord
::MAIN
);
879 return $content ?
$content->getRedirectTarget() : null;
883 * Adjust title for pages with displaytitle, -{T|}- or language conversion
884 * @param ParserOutput $pOutput
886 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
887 $out = $this->getContext()->getOutput();
889 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
890 $titleText = $pOutput->getTitleText();
891 if ( strval( $titleText ) !== '' ) {
892 $out->setPageTitle( $titleText );
893 $out->setDisplayTitle( $titleText );
898 * Show a diff page according to current request variables. For use within
899 * Article::view() only, other callers should use the DifferenceEngine class.
901 protected function showDiffPage() {
902 $request = $this->getContext()->getRequest();
903 $user = $this->getContext()->getUser();
904 $diff = $request->getVal( 'diff' );
905 $rcid = $request->getVal( 'rcid' );
906 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
907 $purge = $request->getVal( 'action' ) == 'purge';
908 $unhide = $request->getInt( 'unhide' ) == 1;
909 $oldid = $this->getOldID();
911 $rev = $this->getRevisionFetched();
914 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
915 $msg = $this->getContext()->msg( 'difference-missing-revision' )
919 $this->getContext()->getOutput()->addHTML( $msg );
923 $contentHandler = $rev->getContentHandler();
924 $de = $contentHandler->createDifferenceEngine(
933 // DifferenceEngine directly fetched the revision:
934 $this->mRevIdFetched
= $de->getNewid();
935 $de->showDiffPage( $diffOnly );
937 // Run view updates for the newer revision being diffed (and shown
938 // below the diff if not $diffOnly).
939 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
940 // New can be false, convert it to 0 - this conveniently means the latest revision
941 $this->mPage
->doViewUpdates( $user, (int)$new );
945 * Get the robot policy to be used for the current view
946 * @param string $action The action= GET parameter
947 * @param ParserOutput|null $pOutput
948 * @return array The policy that should be set
949 * @todo actions other than 'view'
951 public function getRobotPolicy( $action, ParserOutput
$pOutput = null ) {
952 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
954 $ns = $this->getTitle()->getNamespace();
956 # Don't index user and user talk pages for blocked users (T13443)
957 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
958 $specificTarget = null;
960 $titleText = $this->getTitle()->getText();
961 if ( IP
::isValid( $titleText ) ) {
962 $vagueTarget = $titleText;
964 $specificTarget = $titleText;
966 if ( DatabaseBlock
::newFromTarget( $specificTarget, $vagueTarget ) instanceof DatabaseBlock
) {
968 'index' => 'noindex',
969 'follow' => 'nofollow'
974 if ( $this->mPage
->getId() === 0 ||
$this->getOldID() ) {
975 # Non-articles (special pages etc), and old revisions
977 'index' => 'noindex',
978 'follow' => 'nofollow'
980 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
981 # Discourage indexing of printable versions, but encourage following
983 'index' => 'noindex',
986 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
987 # For ?curid=x urls, disallow indexing
989 'index' => 'noindex',
994 # Otherwise, construct the policy based on the various config variables.
995 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
997 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
998 # Honour customised robot policies for this namespace
999 $policy = array_merge(
1001 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
1004 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
1005 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1006 # a final sanity check that we have really got the parser output.
1007 $policy = array_merge(
1009 [ 'index' => $pOutput->getIndexPolicy() ]
1013 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
1014 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1015 $policy = array_merge(
1017 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
1025 * Converts a String robot policy into an associative array, to allow
1026 * merging of several policies using array_merge().
1027 * @param array|string $policy Returns empty array on null/false/'', transparent
1028 * to already-converted arrays, converts string.
1029 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
1031 public static function formatRobotPolicy( $policy ) {
1032 if ( is_array( $policy ) ) {
1034 } elseif ( !$policy ) {
1038 $policy = explode( ',', $policy );
1039 $policy = array_map( 'trim', $policy );
1042 foreach ( $policy as $var ) {
1043 if ( in_array( $var, [ 'index', 'noindex' ] ) ) {
1044 $arr['index'] = $var;
1045 } elseif ( in_array( $var, [ 'follow', 'nofollow' ] ) ) {
1046 $arr['follow'] = $var;
1054 * If this request is a redirect view, send "redirected from" subtitle to
1055 * the output. Returns true if the header was needed, false if this is not
1056 * a redirect view. Handles both local and remote redirects.
1060 public function showRedirectedFromHeader() {
1061 global $wgRedirectSources;
1063 $context = $this->getContext();
1064 $outputPage = $context->getOutput();
1065 $request = $context->getRequest();
1066 $rdfrom = $request->getVal( 'rdfrom' );
1068 // Construct a URL for the current page view, but with the target title
1069 $query = $request->getValues();
1070 unset( $query['rdfrom'] );
1071 unset( $query['title'] );
1072 if ( $this->getTitle()->isRedirect() ) {
1073 // Prevent double redirects
1074 $query['redirect'] = 'no';
1076 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
1078 if ( isset( $this->mRedirectedFrom
) ) {
1079 // Avoid PHP 7.1 warning of passing $this by reference
1080 $articlePage = $this;
1082 // This is an internally redirected page view.
1083 // We'll need a backlink to the source page for navigation.
1084 if ( Hooks
::run( 'ArticleViewRedirect', [ &$articlePage ] ) ) {
1085 $redir = Linker
::linkKnown(
1086 $this->mRedirectedFrom
,
1089 [ 'redirect' => 'no' ]
1092 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1093 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1096 // Add the script to update the displayed URL and
1097 // set the fragment if one was specified in the redirect
1098 $outputPage->addJsConfigVars( [
1099 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1101 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1103 // Add a <link rel="canonical"> tag
1104 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
1106 // Tell the output object that the user arrived at this article through a redirect
1107 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1111 } elseif ( $rdfrom ) {
1112 // This is an externally redirected view, from some other wiki.
1113 // If it was reported from a trusted site, supply a backlink.
1114 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1115 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1116 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1117 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1120 // Add the script to update the displayed URL
1121 $outputPage->addJsConfigVars( [
1122 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1124 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1134 * Show a header specific to the namespace currently being viewed, like
1135 * [[MediaWiki:Talkpagetext]]. For Article::view().
1137 public function showNamespaceHeader() {
1138 if ( $this->getTitle()->isTalkPage() && !wfMessage( 'talkpageheader' )->isDisabled() ) {
1139 $this->getContext()->getOutput()->wrapWikiMsg(
1140 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1141 [ 'talkpageheader' ]
1147 * Show the footer section of an ordinary page view
1149 public function showViewFooter() {
1150 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1151 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1152 && IP
::isValid( $this->getTitle()->getText() )
1154 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1157 // Show a footer allowing the user to patrol the shown revision or page if possible
1158 $patrolFooterShown = $this->showPatrolFooter();
1160 Hooks
::run( 'ArticleViewFooter', [ $this, $patrolFooterShown ] );
1164 * If patrol is possible, output a patrol UI box. This is called from the
1165 * footer section of ordinary page views. If patrol is not possible or not
1166 * desired, does nothing.
1167 * Side effect: When the patrol link is build, this method will call
1168 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1172 public function showPatrolFooter() {
1173 global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol;
1175 // Allow hooks to decide whether to not output this at all
1176 if ( !Hooks
::run( 'ArticleShowPatrolFooter', [ $this ] ) ) {
1180 $outputPage = $this->getContext()->getOutput();
1181 $user = $this->getContext()->getUser();
1182 $title = $this->getTitle();
1185 if ( !MediaWikiServices
::getInstance()->getPermissionManager()
1186 ->quickUserCan( 'patrol', $user, $title )
1187 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol
1188 ||
( $wgUseFilePatrol && $title->inNamespace( NS_FILE
) ) )
1190 // Patrolling is disabled or the user isn't allowed to
1194 if ( $this->mRevision
1195 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1197 // The current revision is already older than what could be in the RC table
1198 // 6h tolerance because the RC might not be cleaned out regularly
1202 // Check for cached results
1203 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1204 $key = $cache->makeKey( 'unpatrollable-page', $title->getArticleID() );
1205 if ( $cache->get( $key ) ) {
1209 $dbr = wfGetDB( DB_REPLICA
);
1210 $oldestRevisionTimestamp = $dbr->selectField(
1212 'MIN( rev_timestamp )',
1213 [ 'rev_page' => $title->getArticleID() ],
1217 // New page patrol: Get the timestamp of the oldest revison which
1218 // the revision table holds for the given page. Then we look
1219 // whether it's within the RC lifespan and if it is, we try
1220 // to get the recentchanges row belonging to that entry
1221 // (with rc_new = 1).
1222 $recentPageCreation = false;
1223 if ( $oldestRevisionTimestamp
1224 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1226 // 6h tolerance because the RC might not be cleaned out regularly
1227 $recentPageCreation = true;
1228 $rc = RecentChange
::newFromConds(
1231 'rc_timestamp' => $oldestRevisionTimestamp,
1232 'rc_namespace' => $title->getNamespace(),
1233 'rc_cur_id' => $title->getArticleID()
1238 // Use generic patrol message for new pages
1239 $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
1243 // File patrol: Get the timestamp of the latest upload for this page,
1244 // check whether it is within the RC lifespan and if it is, we try
1245 // to get the recentchanges row belonging to that entry
1246 // (with rc_type = RC_LOG, rc_log_type = upload).
1247 $recentFileUpload = false;
1248 if ( ( !$rc ||
$rc->getAttribute( 'rc_patrolled' ) ) && $wgUseFilePatrol
1249 && $title->getNamespace() === NS_FILE
) {
1250 // Retrieve timestamp of most recent upload
1251 $newestUploadTimestamp = $dbr->selectField(
1253 'MAX( img_timestamp )',
1254 [ 'img_name' => $title->getDBkey() ],
1257 if ( $newestUploadTimestamp
1258 && RecentChange
::isInRCLifespan( $newestUploadTimestamp, 21600 )
1260 // 6h tolerance because the RC might not be cleaned out regularly
1261 $recentFileUpload = true;
1262 $rc = RecentChange
::newFromConds(
1264 'rc_type' => RC_LOG
,
1265 'rc_log_type' => 'upload',
1266 'rc_timestamp' => $newestUploadTimestamp,
1267 'rc_namespace' => NS_FILE
,
1268 'rc_cur_id' => $title->getArticleID()
1273 // Use patrol message specific to files
1274 $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
1279 if ( !$recentPageCreation && !$recentFileUpload ) {
1280 // Page creation and latest upload (for files) is too old to be in RC
1282 // We definitely can't patrol so cache the information
1283 // When a new file version is uploaded, the cache is cleared
1284 $cache->set( $key, '1' );
1290 // Don't cache: This can be hit if the page gets accessed very fast after
1291 // its creation / latest upload or in case we have high replica DB lag. In case
1292 // the revision is too old, we will already return above.
1296 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1297 // Patrolled RC entry around
1299 // Cache the information we gathered above in case we can't patrol
1300 // Don't cache in case we can patrol as this could change
1301 $cache->set( $key, '1' );
1306 if ( $rc->getPerformer()->equals( $user ) ) {
1307 // Don't show a patrol link for own creations/uploads. If the user could
1308 // patrol them, they already would be patrolled
1312 $outputPage->preventClickjacking();
1313 if ( $user->isAllowed( 'writeapi' ) ) {
1314 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1317 $link = Linker
::linkKnown(
1319 $markPatrolledMsg->escaped(),
1322 'action' => 'markpatrolled',
1323 'rcid' => $rc->getAttribute( 'rc_id' ),
1327 $outputPage->addHTML(
1328 "<div class='patrollink' data-mw='interface'>" .
1329 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1337 * Purge the cache used to check if it is worth showing the patrol footer
1338 * For example, it is done during re-uploads when file patrol is used.
1339 * @param int $articleID ID of the article to purge
1342 public static function purgePatrolFooterCache( $articleID ) {
1343 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1344 $cache->delete( $cache->makeKey( 'unpatrollable-page', $articleID ) );
1348 * Show the error text for a missing article. For articles in the MediaWiki
1349 * namespace, show the default message text. To be called from Article::view().
1351 public function showMissingArticle() {
1352 global $wgSend404Code;
1354 $outputPage = $this->getContext()->getOutput();
1355 // Whether the page is a root user page of an existing user (but not a subpage)
1356 $validUserPage = false;
1358 $title = $this->getTitle();
1360 $services = MediaWikiServices
::getInstance();
1362 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1363 if ( $title->getNamespace() == NS_USER
1364 ||
$title->getNamespace() == NS_USER_TALK
1366 $rootPart = explode( '/', $title->getText() )[0];
1367 $user = User
::newFromName( $rootPart, false /* allow IP users */ );
1368 $ip = User
::isIP( $rootPart );
1369 $block = DatabaseBlock
::newFromTarget( $user, $user );
1371 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1372 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1373 [ 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ] );
1375 !is_null( $block ) &&
1376 $block->getType() != DatabaseBlock
::TYPE_AUTO
&&
1377 ( $block->isSitewide() ||
$user->isBlockedFrom( $title ) )
1379 // Show log extract if the user is sitewide blocked or is partially
1380 // blocked and not allowed to edit their user page or user talk page
1381 LogEventsList
::showLogExtract(
1384 $services->getNamespaceInfo()->getCanonicalName( NS_USER
) . ':' .
1385 $block->getTarget(),
1389 'showIfEmpty' => false,
1391 'blocked-notice-logextract',
1392 $user->getName() # Support GENDER in notice
1396 $validUserPage = !$title->isSubpage();
1398 $validUserPage = !$title->isSubpage();
1402 Hooks
::run( 'ShowMissingArticle', [ $this ] );
1404 # Show delete and move logs if there were any such events.
1405 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1406 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1407 $dbCache = ObjectCache
::getInstance( 'db-replicated' );
1408 $key = $dbCache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) );
1409 $loggedIn = $this->getContext()->getUser()->isLoggedIn();
1410 $sessionExists = $this->getContext()->getRequest()->getSession()->isPersistent();
1411 if ( $loggedIn ||
$dbCache->get( $key ) ||
$sessionExists ) {
1412 $logTypes = [ 'delete', 'move', 'protect' ];
1414 $dbr = wfGetDB( DB_REPLICA
);
1416 $conds = [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ];
1417 // Give extensions a chance to hide their (unrelated) log entries
1418 Hooks
::run( 'Article::MissingArticleConditions', [ &$conds, $logTypes ] );
1419 LogEventsList
::showLogExtract(
1427 'showIfEmpty' => false,
1428 'msgKey' => [ $loggedIn ||
$sessionExists
1429 ?
'moveddeleted-notice'
1430 : 'moveddeleted-notice-recent'
1436 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1437 // If there's no backing content, send a 404 Not Found
1438 // for better machine handling of broken links.
1439 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1442 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1443 $policy = $this->getRobotPolicy( 'view' );
1444 $outputPage->setIndexPolicy( $policy['index'] );
1445 $outputPage->setFollowPolicy( $policy['follow'] );
1447 $hookResult = Hooks
::run( 'BeforeDisplayNoArticleText', [ $this ] );
1449 if ( !$hookResult ) {
1453 # Show error message
1454 $oldid = $this->getOldID();
1455 $pm = MediaWikiServices
::getInstance()->getPermissionManager();
1456 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI
&& $title->hasSourceText() ) {
1457 // use fake Content object for system message
1458 $parserOptions = ParserOptions
::newCanonical( 'canonical' );
1459 $outputPage->addParserOutput( $this->getEmptyPageParserOutput( $parserOptions ) );
1462 $text = wfMessage( 'missing-revision', $oldid )->plain();
1463 } elseif ( $pm->quickUserCan( 'create', $this->getContext()->getUser(), $title ) &&
1464 $pm->quickUserCan( 'edit', $this->getContext()->getUser(), $title )
1466 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1467 $text = wfMessage( $message )->plain();
1469 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1472 $dir = $this->getContext()->getLanguage()->getDir();
1473 $lang = $this->getContext()->getLanguage()->getHtmlCode();
1474 $outputPage->addWikiTextAsInterface( Xml
::openElement( 'div', [
1475 'class' => "noarticletext mw-content-$dir",
1478 ] ) . "\n$text\n</div>" );
1483 * If the revision requested for view is deleted, check permissions.
1484 * Send either an error message or a warning header to the output.
1486 * @return bool True if the view is allowed, false if not.
1488 public function showDeletedRevisionHeader() {
1489 if ( !$this->mRevision
->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
1494 $outputPage = $this->getContext()->getOutput();
1495 $user = $this->getContext()->getUser();
1496 // If the user is not allowed to see it...
1497 if ( !$this->mRevision
->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
1498 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1499 'rev-deleted-text-permission' );
1502 // If the user needs to confirm that they want to see it...
1503 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1504 # Give explanation and add a link to view the revision...
1505 $oldid = intval( $this->getOldID() );
1506 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1507 $msg = $this->mRevision
->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
1508 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1509 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1513 // We are allowed to see...
1515 $msg = $this->mRevision
->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
1516 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1517 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1524 * Generate the navigation links when browsing through an article revisions
1525 * It shows the information as:
1526 * Revision as of \<date\>; view current revision
1527 * \<- Previous version | Next Version -\>
1529 * @param int $oldid Revision ID of this article revision
1531 public function setOldSubtitle( $oldid = 0 ) {
1532 // Avoid PHP 7.1 warning of passing $this by reference
1533 $articlePage = $this;
1535 if ( !Hooks
::run( 'DisplayOldSubtitle', [ &$articlePage, &$oldid ] ) ) {
1539 $context = $this->getContext();
1540 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1542 # Cascade unhide param in links for easy deletion browsing
1545 $extraParams['unhide'] = 1;
1548 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1549 $revision = $this->mRevision
;
1551 $revision = Revision
::newFromId( $oldid );
1554 $timestamp = $revision->getTimestamp();
1556 $current = ( $oldid == $this->mPage
->getLatest() );
1557 $language = $context->getLanguage();
1558 $user = $context->getUser();
1560 $td = $language->userTimeAndDate( $timestamp, $user );
1561 $tddate = $language->userDate( $timestamp, $user );
1562 $tdtime = $language->userTime( $timestamp, $user );
1564 # Show user links if allowed to see them. If hidden, then show them only if requested...
1565 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1567 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1568 ?
'revision-info-current'
1571 $outputPage = $context->getOutput();
1572 $revisionInfo = "<div id=\"mw-{$infomsg}\">" .
1573 $context->msg( $infomsg, $td )
1574 ->rawParams( $userlinks )
1575 ->params( $revision->getId(), $tddate, $tdtime, $revision->getUserText() )
1576 ->rawParams( Linker
::revComment( $revision, true, true ) )
1581 ?
$context->msg( 'currentrevisionlink' )->escaped()
1582 : Linker
::linkKnown(
1584 $context->msg( 'currentrevisionlink' )->escaped(),
1589 ?
$context->msg( 'diff' )->escaped()
1590 : Linker
::linkKnown(
1592 $context->msg( 'diff' )->escaped(),
1599 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1601 ? Linker
::linkKnown(
1603 $context->msg( 'previousrevision' )->escaped(),
1606 'direction' => 'prev',
1610 : $context->msg( 'previousrevision' )->escaped();
1612 ? Linker
::linkKnown(
1614 $context->msg( 'diff' )->escaped(),
1621 : $context->msg( 'diff' )->escaped();
1622 $nextlink = $current
1623 ?
$context->msg( 'nextrevision' )->escaped()
1624 : Linker
::linkKnown(
1626 $context->msg( 'nextrevision' )->escaped(),
1629 'direction' => 'next',
1633 $nextdiff = $current
1634 ?
$context->msg( 'diff' )->escaped()
1635 : Linker
::linkKnown(
1637 $context->msg( 'diff' )->escaped(),
1645 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1646 if ( $cdel !== '' ) {
1650 // the outer div is need for styling the revision info and nav in MobileFrontend
1651 $outputPage->addSubtitle( "<div class=\"mw-revision\">" . $revisionInfo .
1652 "<div id=\"mw-revision-nav\">" . $cdel .
1653 $context->msg( 'revision-nav' )->rawParams(
1654 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1655 )->escaped() . "</div></div>" );
1659 * Return the HTML for the top of a redirect page
1661 * Chances are you should just be using the ParserOutput from
1662 * WikitextContent::getParserOutput instead of calling this for redirects.
1664 * @param Title|array $target Destination(s) to redirect
1665 * @param bool $appendSubtitle [optional]
1666 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1667 * @return string Containing HTML with redirect link
1669 * @deprecated since 1.30
1671 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1672 $lang = $this->getTitle()->getPageLanguage();
1673 $out = $this->getContext()->getOutput();
1674 if ( $appendSubtitle ) {
1675 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1677 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1678 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1682 * Return the HTML for the top of a redirect page
1684 * Chances are you should just be using the ParserOutput from
1685 * WikitextContent::getParserOutput instead of calling this for redirects.
1688 * @param Language $lang
1689 * @param Title|array $target Destination(s) to redirect
1690 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1691 * @return string Containing HTML with redirect link
1693 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1694 if ( !is_array( $target ) ) {
1695 $target = [ $target ];
1698 $html = '<ul class="redirectText">';
1699 /** @var Title $title */
1700 foreach ( $target as $title ) {
1701 $html .= '<li>' . Linker
::link(
1703 htmlspecialchars( $title->getFullText() ),
1705 // Make sure wiki page redirects are not followed
1706 $title->isRedirect() ?
[ 'redirect' => 'no' ] : [],
1707 ( $forceKnown ?
[ 'known', 'noclasses' ] : [] )
1712 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1714 return '<div class="redirectMsg">' .
1715 '<p>' . $redirectToText . '</p>' .
1721 * Adds help link with an icon via page indicators.
1722 * Link target can be overridden by a local message containing a wikilink:
1723 * the message key is: 'namespace-' + namespace number + '-helppage'.
1724 * @param string $to Target MediaWiki.org page title or encoded URL.
1725 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1728 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1730 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1733 $out = $this->getContext()->getOutput();
1734 if ( !$msg->isDisabled() ) {
1735 $helpUrl = Skin
::makeUrl( $msg->plain() );
1736 $out->addHelpLink( $helpUrl, true );
1738 $out->addHelpLink( $to, $overrideBaseUrl );
1743 * Handle action=render
1745 public function render() {
1746 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1747 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1748 // We later set 'enableSectionEditLinks=false' based on this; also used by ImagePage
1749 $this->viewIsRenderAction
= true;
1754 * action=protect handler
1756 public function protect() {
1757 $form = new ProtectionForm( $this );
1762 * action=unprotect handler (alias)
1764 public function unprotect() {
1769 * UI entry point for page deletion
1771 public function delete() {
1772 # This code desperately needs to be totally rewritten
1774 $title = $this->getTitle();
1775 $context = $this->getContext();
1776 $user = $context->getUser();
1777 $request = $context->getRequest();
1780 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1781 if ( count( $permissionErrors ) ) {
1782 throw new PermissionsError( 'delete', $permissionErrors );
1785 # Read-only check...
1786 if ( wfReadOnly() ) {
1787 throw new ReadOnlyError
;
1790 # Better double-check that it hasn't been deleted yet!
1791 $this->mPage
->loadPageData(
1792 $request->wasPosted() ? WikiPage
::READ_LATEST
: WikiPage
::READ_NORMAL
1794 if ( !$this->mPage
->exists() ) {
1795 $deleteLogPage = new LogPage( 'delete' );
1796 $outputPage = $context->getOutput();
1797 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1798 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1799 [ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ]
1801 $outputPage->addHTML(
1802 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1804 LogEventsList
::showLogExtract(
1813 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1814 $deleteReason = $request->getText( 'wpReason' );
1816 if ( $deleteReasonList == 'other' ) {
1817 $reason = $deleteReason;
1818 } elseif ( $deleteReason != '' ) {
1819 // Entry from drop down menu + additional comment
1820 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1821 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1823 $reason = $deleteReasonList;
1826 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1827 [ 'delete', $this->getTitle()->getPrefixedText() ] )
1829 # Flag to hide all contents of the archived revisions
1830 $suppress = $request->getCheck( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1832 $this->doDelete( $reason, $suppress );
1834 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1839 // Generate deletion reason
1840 $hasHistory = false;
1843 $reason = $this->generateReason( $hasHistory );
1844 } catch ( Exception
$e ) {
1845 # if a page is horribly broken, we still want to be able to
1846 # delete it. So be lenient about errors here.
1847 wfDebug( "Error while building auto delete summary: $e" );
1852 // If the page has a history, insert a warning
1853 if ( $hasHistory ) {
1854 $title = $this->getTitle();
1856 // The following can use the real revision count as this is only being shown for users
1857 // that can delete this page.
1858 // This, as a side-effect, also makes sure that the following query isn't being run for
1859 // pages with a larger history, unless the user has the 'bigdelete' right
1860 // (and is about to delete this page).
1861 $dbr = wfGetDB( DB_REPLICA
);
1862 $revisions = $edits = (int)$dbr->selectField(
1865 [ 'rev_page' => $title->getArticleID() ],
1869 // @todo i18n issue/patchwork message
1870 $context->getOutput()->addHTML(
1871 '<strong class="mw-delete-warning-revisions">' .
1872 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1873 $context->msg( 'word-separator' )->escaped() . Linker
::linkKnown( $title,
1874 $context->msg( 'history' )->escaped(),
1876 [ 'action' => 'history' ] ) .
1880 if ( $title->isBigDeletion() ) {
1881 global $wgDeleteRevisionsLimit;
1882 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1884 'delete-warning-toobig',
1885 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1891 $this->confirmDelete( $reason );
1895 * Output deletion confirmation dialog
1896 * @todo Move to another file?
1897 * @param string $reason Prefilled reason
1899 public function confirmDelete( $reason ) {
1900 wfDebug( "Article::confirmDelete\n" );
1902 $title = $this->getTitle();
1903 $ctx = $this->getContext();
1904 $outputPage = $ctx->getOutput();
1905 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1906 $outputPage->addBacklinkSubtitle( $title );
1907 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1908 $outputPage->addModules( 'mediawiki.action.delete' );
1910 $backlinkCache = $title->getBacklinkCache();
1911 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1912 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1913 'deleting-backlinks-warning' );
1916 $subpageQueryLimit = 51;
1917 $subpages = $title->getSubpages( $subpageQueryLimit );
1918 $subpageCount = count( $subpages );
1919 if ( $subpageCount > 0 ) {
1920 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1921 [ 'deleting-subpages-warning', Message
::numParam( $subpageCount ) ] );
1923 $outputPage->addWikiMsg( 'confirmdeletetext' );
1925 Hooks
::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
1927 $user = $this->getContext()->getUser();
1928 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1930 $outputPage->enableOOUI();
1934 $options = Xml
::listDropDownOptions(
1935 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
1936 [ 'other' => $ctx->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
1938 $options = Xml
::listDropDownOptionsOoui( $options );
1940 $fields[] = new OOUI\
FieldLayout(
1941 new OOUI\
DropdownInputWidget( [
1942 'name' => 'wpDeleteReasonList',
1943 'inputId' => 'wpDeleteReasonList',
1945 'infusable' => true,
1947 'options' => $options
1950 'label' => $ctx->msg( 'deletecomment' )->text(),
1955 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
1956 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
1957 // Unicode codepoints.
1958 $fields[] = new OOUI\
FieldLayout(
1959 new OOUI\
TextInputWidget( [
1960 'name' => 'wpReason',
1961 'inputId' => 'wpReason',
1963 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
1964 'infusable' => true,
1966 'autofocus' => true,
1969 'label' => $ctx->msg( 'deleteotherreason' )->text(),
1974 if ( $user->isLoggedIn() ) {
1975 $fields[] = new OOUI\
FieldLayout(
1976 new OOUI\
CheckboxInputWidget( [
1977 'name' => 'wpWatch',
1978 'inputId' => 'wpWatch',
1980 'selected' => $checkWatch,
1983 'label' => $ctx->msg( 'watchthis' )->text(),
1984 'align' => 'inline',
1985 'infusable' => true,
1990 if ( $user->isAllowed( 'suppressrevision' ) ) {
1991 $fields[] = new OOUI\
FieldLayout(
1992 new OOUI\
CheckboxInputWidget( [
1993 'name' => 'wpSuppress',
1994 'inputId' => 'wpSuppress',
1998 'label' => $ctx->msg( 'revdelete-suppress' )->text(),
1999 'align' => 'inline',
2000 'infusable' => true,
2005 $fields[] = new OOUI\
FieldLayout(
2006 new OOUI\
ButtonInputWidget( [
2007 'name' => 'wpConfirmB',
2008 'inputId' => 'wpConfirmB',
2010 'value' => $ctx->msg( 'deletepage' )->text(),
2011 'label' => $ctx->msg( 'deletepage' )->text(),
2012 'flags' => [ 'primary', 'destructive' ],
2020 $fieldset = new OOUI\
FieldsetLayout( [
2021 'label' => $ctx->msg( 'delete-legend' )->text(),
2022 'id' => 'mw-delete-table',
2026 $form = new OOUI\
FormLayout( [
2028 'action' => $title->getLocalURL( 'action=delete' ),
2029 'id' => 'deleteconfirm',
2031 $form->appendContent(
2033 new OOUI\
HtmlSnippet(
2034 Html
::hidden( 'wpEditToken', $user->getEditToken( [ 'delete', $title->getPrefixedText() ] ) )
2038 $outputPage->addHTML(
2039 new OOUI\
PanelLayout( [
2040 'classes' => [ 'deletepage-wrapper' ],
2041 'expanded' => false,
2048 if ( $user->isAllowed( 'editinterface' ) ) {
2049 $link = Linker
::linkKnown(
2050 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
2051 wfMessage( 'delete-edit-reasonlist' )->escaped(),
2053 [ 'action' => 'edit' ]
2055 $outputPage->addHTML( '<p class="mw-delete-editreasons">' . $link . '</p>' );
2058 $deleteLogPage = new LogPage( 'delete' );
2059 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2060 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
2064 * Perform a deletion and output success or failure messages
2065 * @param string $reason
2066 * @param bool $suppress
2067 * @param bool $immediate false allows deleting over time via the job queue
2068 * @throws FatalError
2069 * @throws MWException
2071 public function doDelete( $reason, $suppress = false, $immediate = false ) {
2073 $context = $this->getContext();
2074 $outputPage = $context->getOutput();
2075 $user = $context->getUser();
2076 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user,
2077 [], 'delete', $immediate );
2079 if ( $status->isOK() ) {
2080 $deleted = $this->getTitle()->getPrefixedText();
2082 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
2083 $outputPage->setRobotPolicy( 'noindex,nofollow' );
2085 if ( $status->isGood() ) {
2086 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
2087 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
2088 Hooks
::run( 'ArticleDeleteAfterSuccess', [ $this->getTitle(), $outputPage ] );
2090 $outputPage->addWikiMsg( 'delete-scheduled', wfEscapeWikiText( $deleted ) );
2093 $outputPage->returnToMain( false );
2095 $outputPage->setPageTitle(
2096 wfMessage( 'cannotdelete-title',
2097 $this->getTitle()->getPrefixedText() )
2100 if ( $error == '' ) {
2101 $outputPage->wrapWikiTextAsInterface(
2102 'error mw-error-cannotdelete',
2103 $status->getWikiText()
2105 $deleteLogPage = new LogPage( 'delete' );
2106 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2108 LogEventsList
::showLogExtract(
2114 $outputPage->addHTML( $error );
2119 /* Caching functions */
2122 * checkLastModified returns true if it has taken care of all
2123 * output to the client that is necessary for this request.
2124 * (that is, it has sent a cached version of the page)
2126 * @return bool True if cached version send, false otherwise
2128 protected function tryFileCache() {
2129 static $called = false;
2132 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2137 if ( $this->isFileCacheable() ) {
2138 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
2139 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
2140 wfDebug( "Article::tryFileCache(): about to load file\n" );
2141 $cache->loadFromFileCache( $this->getContext() );
2144 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2145 ob_start( [ &$cache, 'saveToFileCache' ] );
2148 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2155 * Check if the page can be cached
2156 * @param int $mode One of the HTMLFileCache::MODE_* constants (since 1.28)
2159 public function isFileCacheable( $mode = HTMLFileCache
::MODE_NORMAL
) {
2162 if ( HTMLFileCache
::useFileCache( $this->getContext(), $mode ) ) {
2163 $cacheable = $this->mPage
->getId()
2164 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
2165 // Extension may have reason to disable file caching on some pages.
2167 // Avoid PHP 7.1 warning of passing $this by reference
2168 $articlePage = $this;
2169 $cacheable = Hooks
::run( 'IsFileCacheable', [ &$articlePage ] );
2179 * Lightweight method to get the parser output for a page, checking the parser cache
2180 * and so on. Doesn't consider most of the stuff that Article::view() is forced to
2181 * consider, so it's not appropriate to use there.
2183 * @since 1.16 (r52326) for LiquidThreads
2185 * @param int|null $oldid Revision ID or null
2186 * @param User|null $user The relevant user
2187 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
2189 public function getParserOutput( $oldid = null, User
$user = null ) {
2190 // XXX: bypasses mParserOptions and thus setParserOptions()
2192 if ( $user === null ) {
2193 $parserOptions = $this->getParserOptions();
2195 $parserOptions = $this->mPage
->makeParserOptions( $user );
2198 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
2202 * Override the ParserOptions used to render the primary article wikitext.
2204 * @param ParserOptions $options
2205 * @throws MWException If the parser options where already initialized.
2207 public function setParserOptions( ParserOptions
$options ) {
2208 if ( $this->mParserOptions
) {
2209 throw new MWException( "can't change parser options after they have already been set" );
2212 // clone, so if $options is modified later, it doesn't confuse the parser cache.
2213 $this->mParserOptions
= clone $options;
2217 * Get parser options suitable for rendering the primary article wikitext
2218 * @return ParserOptions
2220 public function getParserOptions() {
2221 if ( !$this->mParserOptions
) {
2222 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
2224 // Clone to allow modifications of the return value without affecting cache
2225 return clone $this->mParserOptions
;
2229 * Sets the context this Article is executed in
2231 * @param IContextSource $context
2234 public function setContext( $context ) {
2235 $this->mContext
= $context;
2239 * Gets the context this Article is executed in
2241 * @return IContextSource
2244 public function getContext() {
2245 if ( $this->mContext
instanceof IContextSource
) {
2246 return $this->mContext
;
2248 wfDebug( __METHOD__
. " called and \$mContext is null. " .
2249 "Return RequestContext::getMain(); for sanity\n" );
2250 return RequestContext
::getMain();
2255 * Use PHP's magic __get handler to handle accessing of
2256 * raw WikiPage fields for backwards compatibility.
2258 * @param string $fname Field name
2261 public function __get( $fname ) {
2262 if ( property_exists( $this->mPage
, $fname ) ) {
2263 # wfWarn( "Access to raw $fname field " . __CLASS__ );
2264 return $this->mPage
->$fname;
2266 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2270 * Use PHP's magic __set handler to handle setting of
2271 * raw WikiPage fields for backwards compatibility.
2273 * @param string $fname Field name
2274 * @param mixed $fvalue New value
2276 public function __set( $fname, $fvalue ) {
2277 if ( property_exists( $this->mPage
, $fname ) ) {
2278 # wfWarn( "Access to raw $fname field of " . __CLASS__ );
2279 $this->mPage
->$fname = $fvalue;
2280 // Note: extensions may want to toss on new fields
2281 } elseif ( !in_array( $fname, [ 'mContext', 'mPage' ] ) ) {
2282 $this->mPage
->$fname = $fvalue;
2284 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2289 * Call to WikiPage function for backwards compatibility.
2290 * @see WikiPage::checkFlags
2292 public function checkFlags( $flags ) {
2293 return $this->mPage
->checkFlags( $flags );
2297 * Call to WikiPage function for backwards compatibility.
2298 * @see WikiPage::checkTouched
2300 public function checkTouched() {
2301 return $this->mPage
->checkTouched();
2305 * Call to WikiPage function for backwards compatibility.
2306 * @see WikiPage::clearPreparedEdit
2308 public function clearPreparedEdit() {
2309 $this->mPage
->clearPreparedEdit();
2313 * Call to WikiPage function for backwards compatibility.
2314 * @see WikiPage::doDeleteArticleReal
2316 public function doDeleteArticleReal(
2317 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User
$user = null,
2318 $tags = [], $immediate = false
2320 return $this->mPage
->doDeleteArticleReal(
2321 $reason, $suppress, $u1, $u2, $error, $user, $tags, 'delete', $immediate
2326 * Call to WikiPage function for backwards compatibility.
2327 * @see WikiPage::doDeleteUpdates
2329 public function doDeleteUpdates(
2331 Content
$content = null,
2335 $this->mPage
->doDeleteUpdates( $id, $content, $revision, $user );
2339 * Call to WikiPage function for backwards compatibility.
2340 * @deprecated since 1.29. Use WikiPage::doEditContent() directly instead
2341 * @see WikiPage::doEditContent
2343 public function doEditContent( Content
$content, $summary, $flags = 0, $originalRevId = false,
2344 User
$user = null, $serialFormat = null
2346 wfDeprecated( __METHOD__
, '1.29' );
2347 return $this->mPage
->doEditContent( $content, $summary, $flags, $originalRevId,
2348 $user, $serialFormat
2353 * Call to WikiPage function for backwards compatibility.
2354 * @see WikiPage::doEditUpdates
2356 public function doEditUpdates( Revision
$revision, User
$user, array $options = [] ) {
2357 return $this->mPage
->doEditUpdates( $revision, $user, $options );
2361 * Call to WikiPage function for backwards compatibility.
2362 * @see WikiPage::doPurge
2363 * @note In 1.28 (and only 1.28), this took a $flags parameter that
2364 * controlled how much purging was done.
2366 public function doPurge() {
2367 return $this->mPage
->doPurge();
2371 * Call to WikiPage function for backwards compatibility.
2372 * @see WikiPage::doViewUpdates
2374 public function doViewUpdates( User
$user, $oldid = 0 ) {
2375 $this->mPage
->doViewUpdates( $user, $oldid );
2379 * Call to WikiPage function for backwards compatibility.
2380 * @see WikiPage::exists
2382 public function exists() {
2383 return $this->mPage
->exists();
2387 * Call to WikiPage function for backwards compatibility.
2388 * @see WikiPage::followRedirect
2390 public function followRedirect() {
2391 return $this->mPage
->followRedirect();
2395 * Call to WikiPage function for backwards compatibility.
2396 * @see ContentHandler::getActionOverrides
2398 public function getActionOverrides() {
2399 return $this->mPage
->getActionOverrides();
2403 * Call to WikiPage function for backwards compatibility.
2404 * @see WikiPage::getAutoDeleteReason
2406 public function getAutoDeleteReason( &$hasHistory ) {
2407 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2411 * Call to WikiPage function for backwards compatibility.
2412 * @see WikiPage::getCategories
2414 public function getCategories() {
2415 return $this->mPage
->getCategories();
2419 * Call to WikiPage function for backwards compatibility.
2420 * @see WikiPage::getComment
2422 public function getComment( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2423 return $this->mPage
->getComment( $audience, $user );
2427 * Call to WikiPage function for backwards compatibility.
2428 * @see WikiPage::getContentHandler
2430 public function getContentHandler() {
2431 return $this->mPage
->getContentHandler();
2435 * Call to WikiPage function for backwards compatibility.
2436 * @see WikiPage::getContentModel
2438 public function getContentModel() {
2439 return $this->mPage
->getContentModel();
2443 * Call to WikiPage function for backwards compatibility.
2444 * @see WikiPage::getContributors
2446 public function getContributors() {
2447 return $this->mPage
->getContributors();
2451 * Call to WikiPage function for backwards compatibility.
2452 * @see WikiPage::getCreator
2454 public function getCreator( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2455 return $this->mPage
->getCreator( $audience, $user );
2459 * Call to WikiPage function for backwards compatibility.
2460 * @see WikiPage::getDeletionUpdates
2462 public function getDeletionUpdates( Content
$content = null ) {
2463 return $this->mPage
->getDeletionUpdates( $content );
2467 * Call to WikiPage function for backwards compatibility.
2468 * @see WikiPage::getHiddenCategories
2470 public function getHiddenCategories() {
2471 return $this->mPage
->getHiddenCategories();
2475 * Call to WikiPage function for backwards compatibility.
2476 * @see WikiPage::getId
2478 public function getId() {
2479 return $this->mPage
->getId();
2483 * Call to WikiPage function for backwards compatibility.
2484 * @see WikiPage::getLatest
2486 public function getLatest() {
2487 return $this->mPage
->getLatest();
2491 * Call to WikiPage function for backwards compatibility.
2492 * @see WikiPage::getLinksTimestamp
2494 public function getLinksTimestamp() {
2495 return $this->mPage
->getLinksTimestamp();
2499 * Call to WikiPage function for backwards compatibility.
2500 * @see WikiPage::getMinorEdit
2502 public function getMinorEdit() {
2503 return $this->mPage
->getMinorEdit();
2507 * Call to WikiPage function for backwards compatibility.
2508 * @see WikiPage::getOldestRevision
2510 public function getOldestRevision() {
2511 return $this->mPage
->getOldestRevision();
2515 * Call to WikiPage function for backwards compatibility.
2516 * @see WikiPage::getRedirectTarget
2518 public function getRedirectTarget() {
2519 return $this->mPage
->getRedirectTarget();
2523 * Call to WikiPage function for backwards compatibility.
2524 * @see WikiPage::getRedirectURL
2526 public function getRedirectURL( $rt ) {
2527 return $this->mPage
->getRedirectURL( $rt );
2531 * Call to WikiPage function for backwards compatibility.
2532 * @see WikiPage::getRevision
2534 public function getRevision() {
2535 return $this->mPage
->getRevision();
2539 * Call to WikiPage function for backwards compatibility.
2540 * @see WikiPage::getTimestamp
2542 public function getTimestamp() {
2543 return $this->mPage
->getTimestamp();
2547 * Call to WikiPage function for backwards compatibility.
2548 * @see WikiPage::getTouched
2550 public function getTouched() {
2551 return $this->mPage
->getTouched();
2555 * Call to WikiPage function for backwards compatibility.
2556 * @see WikiPage::getUndoContent
2558 public function getUndoContent( Revision
$undo, Revision
$undoafter = null ) {
2559 return $this->mPage
->getUndoContent( $undo, $undoafter );
2563 * Call to WikiPage function for backwards compatibility.
2564 * @see WikiPage::getUser
2566 public function getUser( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2567 return $this->mPage
->getUser( $audience, $user );
2571 * Call to WikiPage function for backwards compatibility.
2572 * @see WikiPage::getUserText
2574 public function getUserText( $audience = RevisionRecord
::FOR_PUBLIC
, User
$user = null ) {
2575 return $this->mPage
->getUserText( $audience, $user );
2579 * Call to WikiPage function for backwards compatibility.
2580 * @see WikiPage::hasViewableContent
2582 public function hasViewableContent() {
2583 return $this->mPage
->hasViewableContent();
2587 * Call to WikiPage function for backwards compatibility.
2588 * @see WikiPage::insertOn
2590 public function insertOn( $dbw, $pageId = null ) {
2591 return $this->mPage
->insertOn( $dbw, $pageId );
2595 * Call to WikiPage function for backwards compatibility.
2596 * @see WikiPage::insertProtectNullRevision
2598 public function insertProtectNullRevision( $revCommentMsg, array $limit,
2599 array $expiry, $cascade, $reason, $user = null
2601 return $this->mPage
->insertProtectNullRevision( $revCommentMsg, $limit,
2602 $expiry, $cascade, $reason, $user
2607 * Call to WikiPage function for backwards compatibility.
2608 * @see WikiPage::insertRedirect
2610 public function insertRedirect() {
2611 return $this->mPage
->insertRedirect();
2615 * Call to WikiPage function for backwards compatibility.
2616 * @see WikiPage::insertRedirectEntry
2618 public function insertRedirectEntry( Title
$rt, $oldLatest = null ) {
2619 return $this->mPage
->insertRedirectEntry( $rt, $oldLatest );
2623 * Call to WikiPage function for backwards compatibility.
2624 * @see WikiPage::isCountable
2626 public function isCountable( $editInfo = false ) {
2627 return $this->mPage
->isCountable( $editInfo );
2631 * Call to WikiPage function for backwards compatibility.
2632 * @see WikiPage::isRedirect
2634 public function isRedirect() {
2635 return $this->mPage
->isRedirect();
2639 * Call to WikiPage function for backwards compatibility.
2640 * @see WikiPage::loadFromRow
2642 public function loadFromRow( $data, $from ) {
2643 return $this->mPage
->loadFromRow( $data, $from );
2647 * Call to WikiPage function for backwards compatibility.
2648 * @see WikiPage::loadPageData
2650 public function loadPageData( $from = 'fromdb' ) {
2651 $this->mPage
->loadPageData( $from );
2655 * Call to WikiPage function for backwards compatibility.
2656 * @see WikiPage::lockAndGetLatest
2658 public function lockAndGetLatest() {
2659 return $this->mPage
->lockAndGetLatest();
2663 * Call to WikiPage function for backwards compatibility.
2664 * @see WikiPage::makeParserOptions
2666 public function makeParserOptions( $context ) {
2667 return $this->mPage
->makeParserOptions( $context );
2671 * Call to WikiPage function for backwards compatibility.
2672 * @see WikiPage::pageDataFromId
2674 public function pageDataFromId( $dbr, $id, $options = [] ) {
2675 return $this->mPage
->pageDataFromId( $dbr, $id, $options );
2679 * Call to WikiPage function for backwards compatibility.
2680 * @see WikiPage::pageDataFromTitle
2682 public function pageDataFromTitle( $dbr, $title, $options = [] ) {
2683 return $this->mPage
->pageDataFromTitle( $dbr, $title, $options );
2687 * Call to WikiPage function for backwards compatibility.
2688 * @see WikiPage::prepareContentForEdit
2690 public function prepareContentForEdit(
2691 Content
$content, $revision = null, User
$user = null,
2692 $serialFormat = null, $useCache = true
2694 return $this->mPage
->prepareContentForEdit(
2695 $content, $revision, $user,
2696 $serialFormat, $useCache
2701 * Call to WikiPage function for backwards compatibility.
2702 * @see WikiPage::protectDescription
2704 public function protectDescription( array $limit, array $expiry ) {
2705 return $this->mPage
->protectDescription( $limit, $expiry );
2709 * Call to WikiPage function for backwards compatibility.
2710 * @see WikiPage::protectDescriptionLog
2712 public function protectDescriptionLog( array $limit, array $expiry ) {
2713 return $this->mPage
->protectDescriptionLog( $limit, $expiry );
2717 * Call to WikiPage function for backwards compatibility.
2718 * @see WikiPage::replaceSectionAtRev
2720 public function replaceSectionAtRev( $sectionId, Content
$sectionContent,
2721 $sectionTitle = '', $baseRevId = null
2723 return $this->mPage
->replaceSectionAtRev( $sectionId, $sectionContent,
2724 $sectionTitle, $baseRevId
2729 * Call to WikiPage function for backwards compatibility.
2730 * @see WikiPage::replaceSectionContent
2732 public function replaceSectionContent(
2733 $sectionId, Content
$sectionContent, $sectionTitle = '', $edittime = null
2735 return $this->mPage
->replaceSectionContent(
2736 $sectionId, $sectionContent, $sectionTitle, $edittime
2741 * Call to WikiPage function for backwards compatibility.
2742 * @see WikiPage::setTimestamp
2744 public function setTimestamp( $ts ) {
2745 $this->mPage
->setTimestamp( $ts );
2749 * Call to WikiPage function for backwards compatibility.
2750 * @see WikiPage::shouldCheckParserCache
2752 public function shouldCheckParserCache( ParserOptions
$parserOptions, $oldId ) {
2753 return $this->mPage
->shouldCheckParserCache( $parserOptions, $oldId );
2757 * Call to WikiPage function for backwards compatibility.
2758 * @see WikiPage::supportsSections
2760 public function supportsSections() {
2761 return $this->mPage
->supportsSections();
2765 * Call to WikiPage function for backwards compatibility.
2766 * @see WikiPage::triggerOpportunisticLinksUpdate
2768 public function triggerOpportunisticLinksUpdate( ParserOutput
$parserOutput ) {
2769 return $this->mPage
->triggerOpportunisticLinksUpdate( $parserOutput );
2773 * Call to WikiPage function for backwards compatibility.
2774 * @see WikiPage::updateCategoryCounts
2776 public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
2777 return $this->mPage
->updateCategoryCounts( $added, $deleted, $id );
2781 * Call to WikiPage function for backwards compatibility.
2782 * @see WikiPage::updateIfNewerOn
2784 public function updateIfNewerOn( $dbw, $revision ) {
2785 return $this->mPage
->updateIfNewerOn( $dbw, $revision );
2789 * Call to WikiPage function for backwards compatibility.
2790 * @see WikiPage::updateRedirectOn
2792 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
2793 return $this->mPage
->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect );
2797 * Call to WikiPage function for backwards compatibility.
2798 * @see WikiPage::updateRevisionOn
2800 public function updateRevisionOn( $dbw, $revision, $lastRevision = null,
2801 $lastRevIsRedirect = null
2803 return $this->mPage
->updateRevisionOn( $dbw, $revision, $lastRevision,
2809 * @param array $limit
2810 * @param array $expiry
2811 * @param bool &$cascade
2812 * @param string $reason
2816 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2819 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2823 * @param array $limit
2824 * @param string $reason
2825 * @param int &$cascade
2826 * @param array $expiry
2829 public function updateRestrictions( $limit = [], $reason = '',
2830 &$cascade = 0, $expiry = []
2832 return $this->mPage
->doUpdateRestrictions(
2837 $this->getContext()->getUser()
2842 * @param string $reason
2843 * @param bool $suppress
2844 * @param int|null $u1 Unused
2845 * @param bool|null $u2 Unused
2846 * @param string &$error
2847 * @param bool $immediate false allows deleting over time via the job queue
2849 * @throws FatalError
2850 * @throws MWException
2852 public function doDeleteArticle(
2853 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', $immediate = false
2855 return $this->mPage
->doDeleteArticle( $reason, $suppress, $u1, $u2, $error,
2860 * @param string $fromP
2861 * @param string $summary
2862 * @param string $token
2864 * @param array &$resultDetails
2865 * @param User|null $user
2868 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2870 $user = $this->getContext()->getUser();
2873 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2877 * @param string $fromP
2878 * @param string $summary
2880 * @param array &$resultDetails
2881 * @param User|null $guser
2884 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2886 $guser = $this->getContext()->getUser();
2889 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2893 * @param bool &$hasHistory
2896 public function generateReason( &$hasHistory ) {
2897 $title = $this->mPage
->getTitle();
2898 $handler = ContentHandler
::getForTitle( $title );
2899 return $handler->getAutoDeleteReason( $title, $hasHistory );