Merge "GlobalFunctions: Document the usage of wfUrlencode( null )"
[lhc/web/wiklou.git] / includes / page / Article.php
1 <?php
2 /**
3 * User interface for page actions.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22 use MediaWiki\MediaWikiServices;
23 use MediaWiki\Revision\MutableRevisionRecord;
24 use MediaWiki\Revision\RevisionRecord;
25 use MediaWiki\Revision\SlotRecord;
26
27 /**
28 * Class for viewing MediaWiki article and history.
29 *
30 * This maintains WikiPage functions for backwards compatibility.
31 *
32 * @todo Move and rewrite code to an Action class
33 *
34 * Note: edit user interface and cache support functions have been
35 * moved to separate EditPage and HTMLFileCache classes.
36 */
37 class Article implements Page {
38 /**
39 * @var IContextSource|null The context this Article is executed in.
40 * If null, RequestContext::getMain() is used.
41 */
42 protected $mContext;
43
44 /** @var WikiPage|null The WikiPage object of this instance */
45 protected $mPage;
46
47 /**
48 * @var ParserOptions|null ParserOptions object for $wgUser articles.
49 * Initialized by getParserOptions by calling $this->mPage->makeParserOptions().
50 */
51 public $mParserOptions;
52
53 /**
54 * @var Content|null Content of the main slot of $this->mRevision.
55 * @note This variable is read only, setting it has no effect.
56 * Extensions that wish to override the output of Article::view should use a hook.
57 * @todo MCR: Remove in 1.33
58 * @deprecated since 1.32
59 * @since 1.21
60 */
61 public $mContentObject;
62
63 /**
64 * @var bool Is the target revision loaded? Set by fetchRevisionRecord().
65 *
66 * @deprecated since 1.32. Whether content has been loaded should not be relevant to
67 * code outside this class.
68 */
69 public $mContentLoaded = false;
70
71 /**
72 * @var int|null The oldid of the article that was requested to be shown,
73 * 0 for the current revision.
74 * @see $mRevIdFetched
75 */
76 public $mOldId;
77
78 /** @var Title|null Title from which we were redirected here, if any. */
79 public $mRedirectedFrom = null;
80
81 /** @var string|bool URL to redirect to or false if none */
82 public $mRedirectUrl = false;
83
84 /**
85 * @var int Revision ID of revision that was loaded.
86 * @see $mOldId
87 * @deprecated since 1.32, use getRevIdFetched() instead.
88 */
89 public $mRevIdFetched = 0;
90
91 /**
92 * @var Status|null represents the outcome of fetchRevisionRecord().
93 * $fetchResult->value is the RevisionRecord object, if the operation was successful.
94 *
95 * The information in $fetchResult is duplicated by the following deprecated public fields:
96 * $mRevIdFetched, $mContentLoaded. $mRevision (and $mContentObject) also typically duplicate
97 * information of the loaded revision, but may be overwritten by extensions or due to errors.
98 */
99 private $fetchResult = null;
100
101 /**
102 * @var Revision|null Revision to be shown. Initialized by getOldIDFromRequest()
103 * or fetchContentObject(). Normally loaded from the database, but may be replaced
104 * by an extension, or be a fake representing an error message or some such.
105 * While the output of Article::view is typically based on this revision,
106 * it may be overwritten by error messages or replaced by extensions.
107 */
108 public $mRevision = null;
109
110 /**
111 * @var ParserOutput|null|false The ParserOutput generated for viewing the page,
112 * initialized by view(). If no ParserOutput could be generated, this is set to false.
113 * @deprecated since 1.32
114 */
115 public $mParserOutput = null;
116
117 /**
118 * @var bool Whether render() was called. With the way subclasses work
119 * here, there doesn't seem to be any other way to stop calling
120 * OutputPage::enableSectionEditLinks() and still have it work as it did before.
121 */
122 protected $viewIsRenderAction = false;
123
124 /**
125 * Constructor and clear the article
126 * @param Title $title Reference to a Title object.
127 * @param int|null $oldId Revision ID, null to fetch from request, zero for current
128 */
129 public function __construct( Title $title, $oldId = null ) {
130 $this->mOldId = $oldId;
131 $this->mPage = $this->newPage( $title );
132 }
133
134 /**
135 * @param Title $title
136 * @return WikiPage
137 */
138 protected function newPage( Title $title ) {
139 return new WikiPage( $title );
140 }
141
142 /**
143 * Constructor from a page id
144 * @param int $id Article ID to load
145 * @return Article|null
146 */
147 public static function newFromID( $id ) {
148 $t = Title::newFromID( $id );
149 return $t == null ? null : new static( $t );
150 }
151
152 /**
153 * Create an Article object of the appropriate class for the given page.
154 *
155 * @param Title $title
156 * @param IContextSource $context
157 * @return Article
158 */
159 public static function newFromTitle( $title, IContextSource $context ) {
160 if ( NS_MEDIA == $title->getNamespace() ) {
161 // XXX: This should not be here, but where should it go?
162 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
163 }
164
165 $page = null;
166 Hooks::run( 'ArticleFromTitle', [ &$title, &$page, $context ] );
167 if ( !$page ) {
168 switch ( $title->getNamespace() ) {
169 case NS_FILE:
170 $page = new ImagePage( $title );
171 break;
172 case NS_CATEGORY:
173 $page = new CategoryPage( $title );
174 break;
175 default:
176 $page = new Article( $title );
177 }
178 }
179 $page->setContext( $context );
180
181 return $page;
182 }
183
184 /**
185 * Create an Article object of the appropriate class for the given page.
186 *
187 * @param WikiPage $page
188 * @param IContextSource $context
189 * @return Article
190 */
191 public static function newFromWikiPage( WikiPage $page, IContextSource $context ) {
192 $article = self::newFromTitle( $page->getTitle(), $context );
193 $article->mPage = $page; // override to keep process cached vars
194 return $article;
195 }
196
197 /**
198 * Get the page this view was redirected from
199 * @return Title|null
200 * @since 1.28
201 */
202 public function getRedirectedFrom() {
203 return $this->mRedirectedFrom;
204 }
205
206 /**
207 * Tell the page view functions that this view was redirected
208 * from another page on the wiki.
209 * @param Title $from
210 */
211 public function setRedirectedFrom( Title $from ) {
212 $this->mRedirectedFrom = $from;
213 }
214
215 /**
216 * Get the title object of the article
217 *
218 * @return Title Title object of this page
219 */
220 public function getTitle() {
221 return $this->mPage->getTitle();
222 }
223
224 /**
225 * Get the WikiPage object of this instance
226 *
227 * @since 1.19
228 * @return WikiPage
229 */
230 public function getPage() {
231 return $this->mPage;
232 }
233
234 /**
235 * Clear the object
236 */
237 public function clear() {
238 $this->mContentLoaded = false;
239
240 $this->mRedirectedFrom = null; # Title object if set
241 $this->mRevIdFetched = 0;
242 $this->mRedirectUrl = false;
243 $this->mRevision = null;
244 $this->mContentObject = null;
245 $this->fetchResult = null;
246
247 // TODO hard-deprecate direct access to public fields
248
249 $this->mPage->clear();
250 }
251
252 /**
253 * Returns a Content object representing the pages effective display content,
254 * not necessarily the revision's content!
255 *
256 * Note that getContent does not follow redirects anymore.
257 * If you need to fetch redirectable content easily, try
258 * the shortcut in WikiPage::getRedirectTarget()
259 *
260 * This function has side effects! Do not use this function if you
261 * only want the real revision text if any.
262 *
263 * @deprecated since 1.32, use getRevisionFetched() or fetchRevisionRecord() instead.
264 *
265 * @return Content
266 *
267 * @since 1.21
268 */
269 protected function getContentObject() {
270 if ( $this->mPage->getId() === 0 ) {
271 $content = $this->getSubstituteContent();
272 } else {
273 $this->fetchContentObject();
274 $content = $this->mContentObject;
275 }
276
277 return $content;
278 }
279
280 /**
281 * Returns Content object to use when the page does not exist.
282 *
283 * @return Content
284 */
285 private function getSubstituteContent() {
286 # If this is a MediaWiki:x message, then load the messages
287 # and return the message value for x.
288 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
289 $text = $this->getTitle()->getDefaultMessageText();
290 if ( $text === false ) {
291 $text = '';
292 }
293
294 $content = ContentHandler::makeContent( $text, $this->getTitle() );
295 } else {
296 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
297 $content = new MessageContent( $message, null );
298 }
299
300 return $content;
301 }
302
303 /**
304 * Returns ParserOutput to use when a page does not exist. In some cases, we still want to show
305 * "virtual" content, e.g. in the MediaWiki namespace, or in the File namespace for non-local
306 * files.
307 *
308 * @param ParserOptions $options
309 *
310 * @return ParserOutput
311 */
312 protected function getEmptyPageParserOutput( ParserOptions $options ) {
313 $content = $this->getSubstituteContent();
314
315 return $content->getParserOutput( $this->getTitle(), 0, $options );
316 }
317
318 /**
319 * @see getOldIDFromRequest()
320 * @see getRevIdFetched()
321 *
322 * @return int The oldid of the article that is was requested in the constructor or via the
323 * context's WebRequest.
324 */
325 public function getOldID() {
326 if ( is_null( $this->mOldId ) ) {
327 $this->mOldId = $this->getOldIDFromRequest();
328 }
329
330 return $this->mOldId;
331 }
332
333 /**
334 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
335 *
336 * @return int The old id for the request
337 */
338 public function getOldIDFromRequest() {
339 $this->mRedirectUrl = false;
340
341 $request = $this->getContext()->getRequest();
342 $oldid = $request->getIntOrNull( 'oldid' );
343
344 if ( $oldid === null ) {
345 return 0;
346 }
347
348 if ( $oldid !== 0 ) {
349 # Load the given revision and check whether the page is another one.
350 # In that case, update this instance to reflect the change.
351 if ( $oldid === $this->mPage->getLatest() ) {
352 $this->mRevision = $this->mPage->getRevision();
353 } else {
354 $this->mRevision = Revision::newFromId( $oldid );
355 if ( $this->mRevision !== null ) {
356 // Revision title doesn't match the page title given?
357 if ( $this->mPage->getId() != $this->mRevision->getPage() ) {
358 $function = get_class( $this->mPage ) . '::newFromID';
359 $this->mPage = $function( $this->mRevision->getPage() );
360 }
361 }
362 }
363 }
364
365 if ( $request->getVal( 'direction' ) == 'next' ) {
366 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
367 if ( $nextid ) {
368 $oldid = $nextid;
369 $this->mRevision = null;
370 } else {
371 $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
372 }
373 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
374 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
375 if ( $previd ) {
376 $oldid = $previd;
377 $this->mRevision = null;
378 }
379 }
380
381 $this->mRevIdFetched = $this->mRevision ? $this->mRevision->getId() : 0;
382
383 return $oldid;
384 }
385
386 /**
387 * Get text content object
388 * Does *NOT* follow redirects.
389 * @todo When is this null?
390 * @deprecated since 1.32, use fetchRevisionRecord() instead.
391 *
392 * @note Code that wants to retrieve page content from the database should
393 * use WikiPage::getContent().
394 *
395 * @return Content|null|bool
396 *
397 * @since 1.21
398 */
399 protected function fetchContentObject() {
400 if ( !$this->mContentLoaded ) {
401 $this->fetchRevisionRecord();
402 }
403
404 return $this->mContentObject;
405 }
406
407 /**
408 * Fetches the revision to work on.
409 * The revision is typically loaded from the database, but may also be a fake representing
410 * an error message or content supplied by an extension. Refer to $this->fetchResult for
411 * the revision actually loaded from the database, and any errors encountered while doing
412 * that.
413 *
414 * @return RevisionRecord|null
415 */
416 protected function fetchRevisionRecord() {
417 if ( $this->fetchResult ) {
418 return $this->mRevision ? $this->mRevision->getRevisionRecord() : null;
419 }
420
421 $this->mContentLoaded = true;
422 $this->mContentObject = null;
423
424 $oldid = $this->getOldID();
425
426 // $this->mRevision might already be fetched by getOldIDFromRequest()
427 if ( !$this->mRevision ) {
428 if ( !$oldid ) {
429 $this->mRevision = $this->mPage->getRevision();
430
431 if ( !$this->mRevision ) {
432 wfDebug( __METHOD__ . " failed to find page data for title " .
433 $this->getTitle()->getPrefixedText() . "\n" );
434
435 // Just for sanity, output for this case is done by showMissingArticle().
436 $this->fetchResult = Status::newFatal( 'noarticletext' );
437 $this->applyContentOverride( $this->makeFetchErrorContent() );
438 return null;
439 }
440 } else {
441 $this->mRevision = Revision::newFromId( $oldid );
442
443 if ( !$this->mRevision ) {
444 wfDebug( __METHOD__ . " failed to load revision, rev_id $oldid\n" );
445
446 $this->fetchResult = Status::newFatal( 'missing-revision', $oldid );
447 $this->applyContentOverride( $this->makeFetchErrorContent() );
448 return null;
449 }
450 }
451 }
452
453 $this->mRevIdFetched = $this->mRevision->getId();
454 $this->fetchResult = Status::newGood( $this->mRevision );
455
456 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT, $this->getContext()->getUser() ) ) {
457 wfDebug( __METHOD__ . " failed to retrieve content of revision " .
458 $this->mRevision->getId() . "\n" );
459
460 // Just for sanity, output for this case is done by showDeletedRevisionHeader().
461 $this->fetchResult = Status::newFatal( 'rev-deleted-text-permission' );
462 $this->applyContentOverride( $this->makeFetchErrorContent() );
463 return null;
464 }
465
466 if ( Hooks::isRegistered( 'ArticleAfterFetchContentObject' ) ) {
467 $contentObject = $this->mRevision->getContent(
468 Revision::FOR_THIS_USER,
469 $this->getContext()->getUser()
470 );
471
472 $hookContentObject = $contentObject;
473
474 // Avoid PHP 7.1 warning of passing $this by reference
475 $articlePage = $this;
476
477 Hooks::run(
478 'ArticleAfterFetchContentObject',
479 [ &$articlePage, &$hookContentObject ],
480 '1.32'
481 );
482
483 if ( $hookContentObject !== $contentObject ) {
484 // A hook handler is trying to override the content
485 $this->applyContentOverride( $hookContentObject );
486 }
487 }
488
489 // For B/C only
490 $this->mContentObject = $this->mRevision->getContent(
491 Revision::FOR_THIS_USER,
492 $this->getContext()->getUser()
493 );
494
495 return $this->mRevision->getRevisionRecord();
496 }
497
498 /**
499 * Returns a Content object representing any error in $this->fetchContent, or null
500 * if there is no such error.
501 *
502 * @return Content|null
503 */
504 private function makeFetchErrorContent() {
505 if ( !$this->fetchResult || $this->fetchResult->isOK() ) {
506 return null;
507 }
508
509 return new MessageContent( $this->fetchResult->getMessage() );
510 }
511
512 /**
513 * Applies a content override by constructing a fake Revision object and assigning
514 * it to mRevision. The fake revision will not have a user, timestamp or summary set.
515 *
516 * This mechanism exists mainly to accommodate extensions that use the
517 * ArticleAfterFetchContentObject. Once that hook has been removed, there should no longer
518 * be a need for a fake revision object. fetchRevisionRecord() presently also uses this mechanism
519 * to report errors, but that could be changed to use $this->fetchResult instead.
520 *
521 * @param Content $override Content to be used instead of the actual page content,
522 * coming from an extension or representing an error message.
523 */
524 private function applyContentOverride( Content $override ) {
525 // Construct a fake revision
526 $rev = new MutableRevisionRecord( $this->getTitle() );
527 $rev->setContent( SlotRecord::MAIN, $override );
528
529 $this->mRevision = new Revision( $rev );
530
531 // For B/C only
532 $this->mContentObject = $override;
533 }
534
535 /**
536 * Returns true if the currently-referenced revision is the current edit
537 * to this page (and it exists).
538 * @return bool
539 */
540 public function isCurrent() {
541 # If no oldid, this is the current version.
542 if ( $this->getOldID() == 0 ) {
543 return true;
544 }
545
546 return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
547 }
548
549 /**
550 * Get the fetched Revision object depending on request parameters or null
551 * on failure. The revision returned may be a fake representing an error message or
552 * wrapping content supplied by an extension. Refer to $this->fetchResult for the
553 * revision actually loaded from the database.
554 *
555 * @since 1.19
556 * @return Revision|null
557 */
558 public function getRevisionFetched() {
559 $this->fetchRevisionRecord();
560
561 if ( $this->fetchResult->isOK() ) {
562 return $this->mRevision;
563 }
564 }
565
566 /**
567 * Use this to fetch the rev ID used on page views
568 *
569 * Before fetchRevisionRecord was called, this returns the page's latest revision,
570 * regardless of what getOldID() returns.
571 *
572 * @return int Revision ID of last article revision
573 */
574 public function getRevIdFetched() {
575 if ( $this->fetchResult && $this->fetchResult->isOK() ) {
576 return $this->fetchResult->value->getId();
577 } else {
578 return $this->mPage->getLatest();
579 }
580 }
581
582 /**
583 * This is the default action of the index.php entry point: just view the
584 * page of the given title.
585 */
586 public function view() {
587 global $wgUseFileCache, $wgDebugToolbar;
588
589 # Get variables from query string
590 # As side effect this will load the revision and update the title
591 # in a revision ID is passed in the request, so this should remain
592 # the first call of this method even if $oldid is used way below.
593 $oldid = $this->getOldID();
594
595 $user = $this->getContext()->getUser();
596 # Another whitelist check in case getOldID() is altering the title
597 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
598 if ( count( $permErrors ) ) {
599 wfDebug( __METHOD__ . ": denied on secondary read check\n" );
600 throw new PermissionsError( 'read', $permErrors );
601 }
602
603 $outputPage = $this->getContext()->getOutput();
604 # getOldID() may as well want us to redirect somewhere else
605 if ( $this->mRedirectUrl ) {
606 $outputPage->redirect( $this->mRedirectUrl );
607 wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
608
609 return;
610 }
611
612 # If we got diff in the query, we want to see a diff page instead of the article.
613 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
614 wfDebug( __METHOD__ . ": showing diff page\n" );
615 $this->showDiffPage();
616
617 return;
618 }
619
620 # Set page title (may be overridden by DISPLAYTITLE)
621 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
622
623 $outputPage->setArticleFlag( true );
624 # Allow frames by default
625 $outputPage->allowClickjacking();
626
627 $parserCache = MediaWikiServices::getInstance()->getParserCache();
628
629 $parserOptions = $this->getParserOptions();
630 $poOptions = [];
631 # Render printable version, use printable version cache
632 if ( $outputPage->isPrintable() ) {
633 $parserOptions->setIsPrintable( true );
634 $poOptions['enableSectionEditLinks'] = false;
635 } elseif ( $this->viewIsRenderAction
636 || !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user )
637 ) {
638 $poOptions['enableSectionEditLinks'] = false;
639 }
640
641 # Try client and file cache
642 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
643 # Try to stream the output from file cache
644 if ( $wgUseFileCache && $this->tryFileCache() ) {
645 wfDebug( __METHOD__ . ": done file cache\n" );
646 # tell wgOut that output is taken care of
647 $outputPage->disable();
648 $this->mPage->doViewUpdates( $user, $oldid );
649
650 return;
651 }
652 }
653
654 # Should the parser cache be used?
655 $useParserCache = $this->mPage->shouldCheckParserCache( $parserOptions, $oldid );
656 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
657 if ( $user->getStubThreshold() ) {
658 MediaWikiServices::getInstance()->getStatsdDataFactory()->increment( 'pcache_miss_stub' );
659 }
660
661 $this->showRedirectedFromHeader();
662 $this->showNamespaceHeader();
663
664 # Iterate through the possible ways of constructing the output text.
665 # Keep going until $outputDone is set, or we run out of things to do.
666 $pass = 0;
667 $outputDone = false;
668 $this->mParserOutput = false;
669
670 while ( !$outputDone && ++$pass ) {
671 switch ( $pass ) {
672 case 1:
673 // Avoid PHP 7.1 warning of passing $this by reference
674 $articlePage = $this;
675 Hooks::run( 'ArticleViewHeader', [ &$articlePage, &$outputDone, &$useParserCache ] );
676 break;
677 case 2:
678 # Early abort if the page doesn't exist
679 if ( !$this->mPage->exists() ) {
680 wfDebug( __METHOD__ . ": showing missing article\n" );
681 $this->showMissingArticle();
682 $this->mPage->doViewUpdates( $user );
683 return;
684 }
685
686 # Try the parser cache
687 if ( $useParserCache ) {
688 $this->mParserOutput = $parserCache->get( $this->mPage, $parserOptions );
689
690 if ( $this->mParserOutput !== false ) {
691 if ( $oldid ) {
692 wfDebug( __METHOD__ . ": showing parser cache contents for current rev permalink\n" );
693 $this->setOldSubtitle( $oldid );
694 } else {
695 wfDebug( __METHOD__ . ": showing parser cache contents\n" );
696 }
697 $outputPage->addParserOutput( $this->mParserOutput, $poOptions );
698 # Ensure that UI elements requiring revision ID have
699 # the correct version information.
700 $outputPage->setRevisionId( $this->mPage->getLatest() );
701 # Preload timestamp to avoid a DB hit
702 $cachedTimestamp = $this->mParserOutput->getTimestamp();
703 if ( $cachedTimestamp !== null ) {
704 $outputPage->setRevisionTimestamp( $cachedTimestamp );
705 $this->mPage->setTimestamp( $cachedTimestamp );
706 }
707 $outputDone = true;
708 }
709 }
710 break;
711 case 3:
712 # Are we looking at an old revision
713 $rev = $this->fetchRevisionRecord();
714 if ( $oldid && $this->fetchResult->isOK() ) {
715 $this->setOldSubtitle( $oldid );
716
717 if ( !$this->showDeletedRevisionHeader() ) {
718 wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
719 return;
720 }
721 }
722
723 # Ensure that UI elements requiring revision ID have
724 # the correct version information.
725 $outputPage->setRevisionId( $this->getRevIdFetched() );
726 # Preload timestamp to avoid a DB hit
727 $outputPage->setRevisionTimestamp( $this->mPage->getTimestamp() );
728
729 # Pages containing custom CSS or JavaScript get special treatment
730 if ( $this->getTitle()->isSiteConfigPage() || $this->getTitle()->isUserConfigPage() ) {
731 $dir = $this->getContext()->getLanguage()->getDir();
732 $lang = $this->getContext()->getLanguage()->getHtmlCode();
733
734 $outputPage->wrapWikiMsg(
735 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
736 'clearyourcache'
737 );
738 } elseif ( !Hooks::run( 'ArticleRevisionViewCustom', [
739 $rev,
740 $this->getTitle(),
741 $oldid,
742 $outputPage,
743 ] )
744 ) {
745 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
746 // Allow extensions do their own custom view for certain pages
747 $outputDone = true;
748 } elseif ( !Hooks::run( 'ArticleContentViewCustom',
749 [ $this->fetchContentObject(), $this->getTitle(), $outputPage ], '1.32' )
750 ) {
751 // NOTE: sync with hooks called in DifferenceEngine::renderNewRevision()
752 // Allow extensions do their own custom view for certain pages
753 $outputDone = true;
754 }
755 break;
756 case 4:
757 # Run the parse, protected by a pool counter
758 wfDebug( __METHOD__ . ": doing uncached parse\n" );
759
760 $rev = $this->fetchRevisionRecord();
761 $error = null;
762
763 if ( $rev ) {
764 $poolArticleView = new PoolWorkArticleView(
765 $this->getPage(),
766 $parserOptions,
767 $this->getRevIdFetched(),
768 $useParserCache,
769 $rev,
770 // permission checking was done earlier via showDeletedRevisionHeader()
771 RevisionRecord::RAW
772 );
773 $ok = $poolArticleView->execute();
774 $error = $poolArticleView->getError();
775 $this->mParserOutput = $poolArticleView->getParserOutput() ?: null;
776
777 # Don't cache a dirty ParserOutput object
778 if ( $poolArticleView->getIsDirty() ) {
779 $outputPage->setCdnMaxage( 0 );
780 $outputPage->addHTML( "<!-- parser cache is expired, " .
781 "sending anyway due to pool overload-->\n" );
782 }
783 } else {
784 $ok = false;
785 }
786
787 if ( !$ok ) {
788 if ( $error ) {
789 $outputPage->clearHTML(); // for release() errors
790 $outputPage->enableClientCache( false );
791 $outputPage->setRobotPolicy( 'noindex,nofollow' );
792
793 $errortext = $error->getWikiText( false, 'view-pool-error' );
794 $outputPage->wrapWikiTextAsInterface( 'errorbox', $errortext );
795 }
796 # Connection or timeout error
797 return;
798 }
799
800 if ( $this->mParserOutput ) {
801 $outputPage->addParserOutput( $this->mParserOutput, $poOptions );
802 }
803
804 if ( $rev && $this->getRevisionRedirectTarget( $rev ) ) {
805 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
806 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
807 }
808
809 $outputDone = true;
810 break;
811 # Should be unreachable, but just in case...
812 default:
813 break 2;
814 }
815 }
816
817 // Get the ParserOutput actually *displayed* here.
818 // Note that $this->mParserOutput is the *current*/oldid version output.
819 // Note that the ArticleViewHeader hook is allowed to set $outputDone to a
820 // ParserOutput instance.
821 $pOutput = ( $outputDone instanceof ParserOutput )
822 ? $outputDone // object fetched by hook
823 : ( $this->mParserOutput ?: null ); // ParserOutput or null, avoid false
824
825 # Adjust title for main page & pages with displaytitle
826 if ( $pOutput ) {
827 $this->adjustDisplayTitle( $pOutput );
828 }
829
830 # For the main page, overwrite the <title> element with the con-
831 # tents of 'pagetitle-view-mainpage' instead of the default (if
832 # that's not empty).
833 # This message always exists because it is in the i18n files
834 if ( $this->getTitle()->isMainPage() ) {
835 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
836 if ( !$msg->isDisabled() ) {
837 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
838 }
839 }
840
841 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
842 # This could use getTouched(), but that could be scary for major template edits.
843 $outputPage->adaptCdnTTL( $this->mPage->getTimestamp(), IExpiringStore::TTL_DAY );
844
845 # Check for any __NOINDEX__ tags on the page using $pOutput
846 $policy = $this->getRobotPolicy( 'view', $pOutput ?: null );
847 $outputPage->setIndexPolicy( $policy['index'] );
848 $outputPage->setFollowPolicy( $policy['follow'] ); // FIXME: test this
849
850 $this->showViewFooter();
851 $this->mPage->doViewUpdates( $user, $oldid ); // FIXME: test this
852
853 # Load the postEdit module if the user just saved this revision
854 # See also EditPage::setPostEditCookie
855 $request = $this->getContext()->getRequest();
856 $cookieKey = EditPage::POST_EDIT_COOKIE_KEY_PREFIX . $this->getRevIdFetched();
857 $postEdit = $request->getCookie( $cookieKey );
858 if ( $postEdit ) {
859 # Clear the cookie. This also prevents caching of the response.
860 $request->response()->clearCookie( $cookieKey );
861 $outputPage->addJsConfigVars( 'wgPostEdit', $postEdit );
862 $outputPage->addModules( 'mediawiki.action.view.postEdit' ); // FIXME: test this
863 }
864 }
865
866 /**
867 * @param RevisionRecord $revision
868 * @return null|Title
869 */
870 private function getRevisionRedirectTarget( RevisionRecord $revision ) {
871 // TODO: find a *good* place for the code that determines the redirect target for
872 // a given revision!
873 // NOTE: Use main slot content. Compare code in DerivedPageDataUpdater::revisionIsRedirect.
874 $content = $revision->getContent( SlotRecord::MAIN );
875 return $content ? $content->getRedirectTarget() : null;
876 }
877
878 /**
879 * Adjust title for pages with displaytitle, -{T|}- or language conversion
880 * @param ParserOutput $pOutput
881 */
882 public function adjustDisplayTitle( ParserOutput $pOutput ) {
883 $out = $this->getContext()->getOutput();
884
885 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
886 $titleText = $pOutput->getTitleText();
887 if ( strval( $titleText ) !== '' ) {
888 $out->setPageTitle( $titleText );
889 $out->setDisplayTitle( $titleText );
890 }
891 }
892
893 /**
894 * Show a diff page according to current request variables. For use within
895 * Article::view() only, other callers should use the DifferenceEngine class.
896 */
897 protected function showDiffPage() {
898 $request = $this->getContext()->getRequest();
899 $user = $this->getContext()->getUser();
900 $diff = $request->getVal( 'diff' );
901 $rcid = $request->getVal( 'rcid' );
902 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
903 $purge = $request->getVal( 'action' ) == 'purge';
904 $unhide = $request->getInt( 'unhide' ) == 1;
905 $oldid = $this->getOldID();
906
907 $rev = $this->getRevisionFetched();
908
909 if ( !$rev ) {
910 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
911 $msg = $this->getContext()->msg( 'difference-missing-revision' )
912 ->params( $oldid )
913 ->numParams( 1 )
914 ->parseAsBlock();
915 $this->getContext()->getOutput()->addHTML( $msg );
916 return;
917 }
918
919 $contentHandler = $rev->getContentHandler();
920 $de = $contentHandler->createDifferenceEngine(
921 $this->getContext(),
922 $oldid,
923 $diff,
924 $rcid,
925 $purge,
926 $unhide
927 );
928
929 // DifferenceEngine directly fetched the revision:
930 $this->mRevIdFetched = $de->getNewid();
931 $de->showDiffPage( $diffOnly );
932
933 // Run view updates for the newer revision being diffed (and shown
934 // below the diff if not $diffOnly).
935 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
936 // New can be false, convert it to 0 - this conveniently means the latest revision
937 $this->mPage->doViewUpdates( $user, (int)$new );
938 }
939
940 /**
941 * Get the robot policy to be used for the current view
942 * @param string $action The action= GET parameter
943 * @param ParserOutput|null $pOutput
944 * @return array The policy that should be set
945 * @todo actions other than 'view'
946 */
947 public function getRobotPolicy( $action, ParserOutput $pOutput = null ) {
948 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
949
950 $ns = $this->getTitle()->getNamespace();
951
952 # Don't index user and user talk pages for blocked users (T13443)
953 if ( ( $ns == NS_USER || $ns == NS_USER_TALK ) && !$this->getTitle()->isSubpage() ) {
954 $specificTarget = null;
955 $vagueTarget = null;
956 $titleText = $this->getTitle()->getText();
957 if ( IP::isValid( $titleText ) ) {
958 $vagueTarget = $titleText;
959 } else {
960 $specificTarget = $titleText;
961 }
962 if ( Block::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block ) {
963 return [
964 'index' => 'noindex',
965 'follow' => 'nofollow'
966 ];
967 }
968 }
969
970 if ( $this->mPage->getId() === 0 || $this->getOldID() ) {
971 # Non-articles (special pages etc), and old revisions
972 return [
973 'index' => 'noindex',
974 'follow' => 'nofollow'
975 ];
976 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
977 # Discourage indexing of printable versions, but encourage following
978 return [
979 'index' => 'noindex',
980 'follow' => 'follow'
981 ];
982 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
983 # For ?curid=x urls, disallow indexing
984 return [
985 'index' => 'noindex',
986 'follow' => 'follow'
987 ];
988 }
989
990 # Otherwise, construct the policy based on the various config variables.
991 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
992
993 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
994 # Honour customised robot policies for this namespace
995 $policy = array_merge(
996 $policy,
997 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
998 );
999 }
1000 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
1001 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1002 # a final sanity check that we have really got the parser output.
1003 $policy = array_merge(
1004 $policy,
1005 [ 'index' => $pOutput->getIndexPolicy() ]
1006 );
1007 }
1008
1009 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
1010 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1011 $policy = array_merge(
1012 $policy,
1013 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
1014 );
1015 }
1016
1017 return $policy;
1018 }
1019
1020 /**
1021 * Converts a String robot policy into an associative array, to allow
1022 * merging of several policies using array_merge().
1023 * @param array|string $policy Returns empty array on null/false/'', transparent
1024 * to already-converted arrays, converts string.
1025 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
1026 */
1027 public static function formatRobotPolicy( $policy ) {
1028 if ( is_array( $policy ) ) {
1029 return $policy;
1030 } elseif ( !$policy ) {
1031 return [];
1032 }
1033
1034 $policy = explode( ',', $policy );
1035 $policy = array_map( 'trim', $policy );
1036
1037 $arr = [];
1038 foreach ( $policy as $var ) {
1039 if ( in_array( $var, [ 'index', 'noindex' ] ) ) {
1040 $arr['index'] = $var;
1041 } elseif ( in_array( $var, [ 'follow', 'nofollow' ] ) ) {
1042 $arr['follow'] = $var;
1043 }
1044 }
1045
1046 return $arr;
1047 }
1048
1049 /**
1050 * If this request is a redirect view, send "redirected from" subtitle to
1051 * the output. Returns true if the header was needed, false if this is not
1052 * a redirect view. Handles both local and remote redirects.
1053 *
1054 * @return bool
1055 */
1056 public function showRedirectedFromHeader() {
1057 global $wgRedirectSources;
1058
1059 $context = $this->getContext();
1060 $outputPage = $context->getOutput();
1061 $request = $context->getRequest();
1062 $rdfrom = $request->getVal( 'rdfrom' );
1063
1064 // Construct a URL for the current page view, but with the target title
1065 $query = $request->getValues();
1066 unset( $query['rdfrom'] );
1067 unset( $query['title'] );
1068 if ( $this->getTitle()->isRedirect() ) {
1069 // Prevent double redirects
1070 $query['redirect'] = 'no';
1071 }
1072 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
1073
1074 if ( isset( $this->mRedirectedFrom ) ) {
1075 // Avoid PHP 7.1 warning of passing $this by reference
1076 $articlePage = $this;
1077
1078 // This is an internally redirected page view.
1079 // We'll need a backlink to the source page for navigation.
1080 if ( Hooks::run( 'ArticleViewRedirect', [ &$articlePage ] ) ) {
1081 $redir = Linker::linkKnown(
1082 $this->mRedirectedFrom,
1083 null,
1084 [],
1085 [ 'redirect' => 'no' ]
1086 );
1087
1088 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1089 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1090 . "</span>" );
1091
1092 // Add the script to update the displayed URL and
1093 // set the fragment if one was specified in the redirect
1094 $outputPage->addJsConfigVars( [
1095 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1096 ] );
1097 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1098
1099 // Add a <link rel="canonical"> tag
1100 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
1101
1102 // Tell the output object that the user arrived at this article through a redirect
1103 $outputPage->setRedirectedFrom( $this->mRedirectedFrom );
1104
1105 return true;
1106 }
1107 } elseif ( $rdfrom ) {
1108 // This is an externally redirected view, from some other wiki.
1109 // If it was reported from a trusted site, supply a backlink.
1110 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1111 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
1112 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1113 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1114 . "</span>" );
1115
1116 // Add the script to update the displayed URL
1117 $outputPage->addJsConfigVars( [
1118 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1119 ] );
1120 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1121
1122 return true;
1123 }
1124 }
1125
1126 return false;
1127 }
1128
1129 /**
1130 * Show a header specific to the namespace currently being viewed, like
1131 * [[MediaWiki:Talkpagetext]]. For Article::view().
1132 */
1133 public function showNamespaceHeader() {
1134 if ( $this->getTitle()->isTalkPage() ) {
1135 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1136 $this->getContext()->getOutput()->wrapWikiMsg(
1137 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1138 [ 'talkpageheader' ]
1139 );
1140 }
1141 }
1142 }
1143
1144 /**
1145 * Show the footer section of an ordinary page view
1146 */
1147 public function showViewFooter() {
1148 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1149 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1150 && IP::isValid( $this->getTitle()->getText() )
1151 ) {
1152 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1153 }
1154
1155 // Show a footer allowing the user to patrol the shown revision or page if possible
1156 $patrolFooterShown = $this->showPatrolFooter();
1157
1158 Hooks::run( 'ArticleViewFooter', [ $this, $patrolFooterShown ] );
1159 }
1160
1161 /**
1162 * If patrol is possible, output a patrol UI box. This is called from the
1163 * footer section of ordinary page views. If patrol is not possible or not
1164 * desired, does nothing.
1165 * Side effect: When the patrol link is build, this method will call
1166 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1167 *
1168 * @return bool
1169 */
1170 public function showPatrolFooter() {
1171 global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol;
1172
1173 // Allow hooks to decide whether to not output this at all
1174 if ( !Hooks::run( 'ArticleShowPatrolFooter', [ $this ] ) ) {
1175 return false;
1176 }
1177
1178 $outputPage = $this->getContext()->getOutput();
1179 $user = $this->getContext()->getUser();
1180 $title = $this->getTitle();
1181 $rc = false;
1182
1183 if ( !$title->quickUserCan( 'patrol', $user )
1184 || !( $wgUseRCPatrol || $wgUseNPPatrol
1185 || ( $wgUseFilePatrol && $title->inNamespace( NS_FILE ) ) )
1186 ) {
1187 // Patrolling is disabled or the user isn't allowed to
1188 return false;
1189 }
1190
1191 if ( $this->mRevision
1192 && !RecentChange::isInRCLifespan( $this->mRevision->getTimestamp(), 21600 )
1193 ) {
1194 // The current revision is already older than what could be in the RC table
1195 // 6h tolerance because the RC might not be cleaned out regularly
1196 return false;
1197 }
1198
1199 // Check for cached results
1200 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1201 $key = $cache->makeKey( 'unpatrollable-page', $title->getArticleID() );
1202 if ( $cache->get( $key ) ) {
1203 return false;
1204 }
1205
1206 $dbr = wfGetDB( DB_REPLICA );
1207 $oldestRevisionTimestamp = $dbr->selectField(
1208 'revision',
1209 'MIN( rev_timestamp )',
1210 [ 'rev_page' => $title->getArticleID() ],
1211 __METHOD__
1212 );
1213
1214 // New page patrol: Get the timestamp of the oldest revison which
1215 // the revision table holds for the given page. Then we look
1216 // whether it's within the RC lifespan and if it is, we try
1217 // to get the recentchanges row belonging to that entry
1218 // (with rc_new = 1).
1219 $recentPageCreation = false;
1220 if ( $oldestRevisionTimestamp
1221 && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1222 ) {
1223 // 6h tolerance because the RC might not be cleaned out regularly
1224 $recentPageCreation = true;
1225 $rc = RecentChange::newFromConds(
1226 [
1227 'rc_new' => 1,
1228 'rc_timestamp' => $oldestRevisionTimestamp,
1229 'rc_namespace' => $title->getNamespace(),
1230 'rc_cur_id' => $title->getArticleID()
1231 ],
1232 __METHOD__
1233 );
1234 if ( $rc ) {
1235 // Use generic patrol message for new pages
1236 $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
1237 }
1238 }
1239
1240 // File patrol: Get the timestamp of the latest upload for this page,
1241 // check whether it is within the RC lifespan and if it is, we try
1242 // to get the recentchanges row belonging to that entry
1243 // (with rc_type = RC_LOG, rc_log_type = upload).
1244 $recentFileUpload = false;
1245 if ( ( !$rc || $rc->getAttribute( 'rc_patrolled' ) ) && $wgUseFilePatrol
1246 && $title->getNamespace() === NS_FILE ) {
1247 // Retrieve timestamp of most recent upload
1248 $newestUploadTimestamp = $dbr->selectField(
1249 'image',
1250 'MAX( img_timestamp )',
1251 [ 'img_name' => $title->getDBkey() ],
1252 __METHOD__
1253 );
1254 if ( $newestUploadTimestamp
1255 && RecentChange::isInRCLifespan( $newestUploadTimestamp, 21600 )
1256 ) {
1257 // 6h tolerance because the RC might not be cleaned out regularly
1258 $recentFileUpload = true;
1259 $rc = RecentChange::newFromConds(
1260 [
1261 'rc_type' => RC_LOG,
1262 'rc_log_type' => 'upload',
1263 'rc_timestamp' => $newestUploadTimestamp,
1264 'rc_namespace' => NS_FILE,
1265 'rc_cur_id' => $title->getArticleID()
1266 ],
1267 __METHOD__
1268 );
1269 if ( $rc ) {
1270 // Use patrol message specific to files
1271 $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
1272 }
1273 }
1274 }
1275
1276 if ( !$recentPageCreation && !$recentFileUpload ) {
1277 // Page creation and latest upload (for files) is too old to be in RC
1278
1279 // We definitely can't patrol so cache the information
1280 // When a new file version is uploaded, the cache is cleared
1281 $cache->set( $key, '1' );
1282
1283 return false;
1284 }
1285
1286 if ( !$rc ) {
1287 // Don't cache: This can be hit if the page gets accessed very fast after
1288 // its creation / latest upload or in case we have high replica DB lag. In case
1289 // the revision is too old, we will already return above.
1290 return false;
1291 }
1292
1293 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1294 // Patrolled RC entry around
1295
1296 // Cache the information we gathered above in case we can't patrol
1297 // Don't cache in case we can patrol as this could change
1298 $cache->set( $key, '1' );
1299
1300 return false;
1301 }
1302
1303 if ( $rc->getPerformer()->equals( $user ) ) {
1304 // Don't show a patrol link for own creations/uploads. If the user could
1305 // patrol them, they already would be patrolled
1306 return false;
1307 }
1308
1309 $outputPage->preventClickjacking();
1310 if ( $user->isAllowed( 'writeapi' ) ) {
1311 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1312 }
1313
1314 $link = Linker::linkKnown(
1315 $title,
1316 $markPatrolledMsg->escaped(),
1317 [],
1318 [
1319 'action' => 'markpatrolled',
1320 'rcid' => $rc->getAttribute( 'rc_id' ),
1321 ]
1322 );
1323
1324 $outputPage->addHTML(
1325 "<div class='patrollink' data-mw='interface'>" .
1326 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1327 '</div>'
1328 );
1329
1330 return true;
1331 }
1332
1333 /**
1334 * Purge the cache used to check if it is worth showing the patrol footer
1335 * For example, it is done during re-uploads when file patrol is used.
1336 * @param int $articleID ID of the article to purge
1337 * @since 1.27
1338 */
1339 public static function purgePatrolFooterCache( $articleID ) {
1340 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1341 $cache->delete( $cache->makeKey( 'unpatrollable-page', $articleID ) );
1342 }
1343
1344 /**
1345 * Show the error text for a missing article. For articles in the MediaWiki
1346 * namespace, show the default message text. To be called from Article::view().
1347 */
1348 public function showMissingArticle() {
1349 global $wgSend404Code;
1350
1351 $outputPage = $this->getContext()->getOutput();
1352 // Whether the page is a root user page of an existing user (but not a subpage)
1353 $validUserPage = false;
1354
1355 $title = $this->getTitle();
1356
1357 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1358 if ( $title->getNamespace() == NS_USER
1359 || $title->getNamespace() == NS_USER_TALK
1360 ) {
1361 $rootPart = explode( '/', $title->getText() )[0];
1362 $user = User::newFromName( $rootPart, false /* allow IP users */ );
1363 $ip = User::isIP( $rootPart );
1364 $block = Block::newFromTarget( $user, $user );
1365
1366 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1367 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1368 [ 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ] );
1369 } elseif (
1370 !is_null( $block ) &&
1371 $block->getType() != Block::TYPE_AUTO &&
1372 ( $block->isSitewide() || $user->isBlockedFrom( $title ) )
1373 ) {
1374 // Show log extract if the user is sitewide blocked or is partially
1375 // blocked and not allowed to edit their user page or user talk page
1376 LogEventsList::showLogExtract(
1377 $outputPage,
1378 'block',
1379 MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
1380 '',
1381 [
1382 'lim' => 1,
1383 'showIfEmpty' => false,
1384 'msgKey' => [
1385 'blocked-notice-logextract',
1386 $user->getName() # Support GENDER in notice
1387 ]
1388 ]
1389 );
1390 $validUserPage = !$title->isSubpage();
1391 } else {
1392 $validUserPage = !$title->isSubpage();
1393 }
1394 }
1395
1396 Hooks::run( 'ShowMissingArticle', [ $this ] );
1397
1398 # Show delete and move logs if there were any such events.
1399 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1400 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1401 $cache = MediaWikiServices::getInstance()->getMainObjectStash();
1402 $key = $cache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) );
1403 $loggedIn = $this->getContext()->getUser()->isLoggedIn();
1404 $sessionExists = $this->getContext()->getRequest()->getSession()->isPersistent();
1405 if ( $loggedIn || $cache->get( $key ) || $sessionExists ) {
1406 $logTypes = [ 'delete', 'move', 'protect' ];
1407
1408 $dbr = wfGetDB( DB_REPLICA );
1409
1410 $conds = [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ];
1411 // Give extensions a chance to hide their (unrelated) log entries
1412 Hooks::run( 'Article::MissingArticleConditions', [ &$conds, $logTypes ] );
1413 LogEventsList::showLogExtract(
1414 $outputPage,
1415 $logTypes,
1416 $title,
1417 '',
1418 [
1419 'lim' => 10,
1420 'conds' => $conds,
1421 'showIfEmpty' => false,
1422 'msgKey' => [ $loggedIn || $sessionExists
1423 ? 'moveddeleted-notice'
1424 : 'moveddeleted-notice-recent'
1425 ]
1426 ]
1427 );
1428 }
1429
1430 if ( !$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1431 // If there's no backing content, send a 404 Not Found
1432 // for better machine handling of broken links.
1433 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1434 }
1435
1436 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1437 $policy = $this->getRobotPolicy( 'view' );
1438 $outputPage->setIndexPolicy( $policy['index'] );
1439 $outputPage->setFollowPolicy( $policy['follow'] );
1440
1441 $hookResult = Hooks::run( 'BeforeDisplayNoArticleText', [ $this ] );
1442
1443 if ( !$hookResult ) {
1444 return;
1445 }
1446
1447 # Show error message
1448 $oldid = $this->getOldID();
1449 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI && $title->hasSourceText() ) {
1450 // use fake Content object for system message
1451 $parserOptions = ParserOptions::newCanonical( 'canonical' );
1452 $outputPage->addParserOutput( $this->getEmptyPageParserOutput( $parserOptions ) );
1453 } else {
1454 if ( $oldid ) {
1455 $text = wfMessage( 'missing-revision', $oldid )->plain();
1456 } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
1457 && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
1458 ) {
1459 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
1460 $text = wfMessage( $message )->plain();
1461 } else {
1462 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1463 }
1464
1465 $dir = $this->getContext()->getLanguage()->getDir();
1466 $lang = $this->getContext()->getLanguage()->getHtmlCode();
1467 $outputPage->addWikiTextAsInterface( Xml::openElement( 'div', [
1468 'class' => "noarticletext mw-content-$dir",
1469 'dir' => $dir,
1470 'lang' => $lang,
1471 ] ) . "\n$text\n</div>" );
1472 }
1473 }
1474
1475 /**
1476 * If the revision requested for view is deleted, check permissions.
1477 * Send either an error message or a warning header to the output.
1478 *
1479 * @return bool True if the view is allowed, false if not.
1480 */
1481 public function showDeletedRevisionHeader() {
1482 if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1483 // Not deleted
1484 return true;
1485 }
1486
1487 $outputPage = $this->getContext()->getOutput();
1488 $user = $this->getContext()->getUser();
1489 // If the user is not allowed to see it...
1490 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT, $user ) ) {
1491 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1492 'rev-deleted-text-permission' );
1493
1494 return false;
1495 // If the user needs to confirm that they want to see it...
1496 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1497 # Give explanation and add a link to view the revision...
1498 $oldid = intval( $this->getOldID() );
1499 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1500 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1501 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1502 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1503 [ $msg, $link ] );
1504
1505 return false;
1506 // We are allowed to see...
1507 } else {
1508 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1509 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1510 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1511
1512 return true;
1513 }
1514 }
1515
1516 /**
1517 * Generate the navigation links when browsing through an article revisions
1518 * It shows the information as:
1519 * Revision as of \<date\>; view current revision
1520 * \<- Previous version | Next Version -\>
1521 *
1522 * @param int $oldid Revision ID of this article revision
1523 */
1524 public function setOldSubtitle( $oldid = 0 ) {
1525 // Avoid PHP 7.1 warning of passing $this by reference
1526 $articlePage = $this;
1527
1528 if ( !Hooks::run( 'DisplayOldSubtitle', [ &$articlePage, &$oldid ] ) ) {
1529 return;
1530 }
1531
1532 $context = $this->getContext();
1533 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1534
1535 # Cascade unhide param in links for easy deletion browsing
1536 $extraParams = [];
1537 if ( $unhide ) {
1538 $extraParams['unhide'] = 1;
1539 }
1540
1541 if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
1542 $revision = $this->mRevision;
1543 } else {
1544 $revision = Revision::newFromId( $oldid );
1545 }
1546
1547 $timestamp = $revision->getTimestamp();
1548
1549 $current = ( $oldid == $this->mPage->getLatest() );
1550 $language = $context->getLanguage();
1551 $user = $context->getUser();
1552
1553 $td = $language->userTimeAndDate( $timestamp, $user );
1554 $tddate = $language->userDate( $timestamp, $user );
1555 $tdtime = $language->userTime( $timestamp, $user );
1556
1557 # Show user links if allowed to see them. If hidden, then show them only if requested...
1558 $userlinks = Linker::revUserTools( $revision, !$unhide );
1559
1560 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1561 ? 'revision-info-current'
1562 : 'revision-info';
1563
1564 $outputPage = $context->getOutput();
1565 $revisionInfo = "<div id=\"mw-{$infomsg}\">" .
1566 $context->msg( $infomsg, $td )
1567 ->rawParams( $userlinks )
1568 ->params( $revision->getId(), $tddate, $tdtime, $revision->getUserText() )
1569 ->rawParams( Linker::revComment( $revision, true, true ) )
1570 ->parse() .
1571 "</div>";
1572
1573 $lnk = $current
1574 ? $context->msg( 'currentrevisionlink' )->escaped()
1575 : Linker::linkKnown(
1576 $this->getTitle(),
1577 $context->msg( 'currentrevisionlink' )->escaped(),
1578 [],
1579 $extraParams
1580 );
1581 $curdiff = $current
1582 ? $context->msg( 'diff' )->escaped()
1583 : Linker::linkKnown(
1584 $this->getTitle(),
1585 $context->msg( 'diff' )->escaped(),
1586 [],
1587 [
1588 'diff' => 'cur',
1589 'oldid' => $oldid
1590 ] + $extraParams
1591 );
1592 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1593 $prevlink = $prev
1594 ? Linker::linkKnown(
1595 $this->getTitle(),
1596 $context->msg( 'previousrevision' )->escaped(),
1597 [],
1598 [
1599 'direction' => 'prev',
1600 'oldid' => $oldid
1601 ] + $extraParams
1602 )
1603 : $context->msg( 'previousrevision' )->escaped();
1604 $prevdiff = $prev
1605 ? Linker::linkKnown(
1606 $this->getTitle(),
1607 $context->msg( 'diff' )->escaped(),
1608 [],
1609 [
1610 'diff' => 'prev',
1611 'oldid' => $oldid
1612 ] + $extraParams
1613 )
1614 : $context->msg( 'diff' )->escaped();
1615 $nextlink = $current
1616 ? $context->msg( 'nextrevision' )->escaped()
1617 : Linker::linkKnown(
1618 $this->getTitle(),
1619 $context->msg( 'nextrevision' )->escaped(),
1620 [],
1621 [
1622 'direction' => 'next',
1623 'oldid' => $oldid
1624 ] + $extraParams
1625 );
1626 $nextdiff = $current
1627 ? $context->msg( 'diff' )->escaped()
1628 : Linker::linkKnown(
1629 $this->getTitle(),
1630 $context->msg( 'diff' )->escaped(),
1631 [],
1632 [
1633 'diff' => 'next',
1634 'oldid' => $oldid
1635 ] + $extraParams
1636 );
1637
1638 $cdel = Linker::getRevDeleteLink( $user, $revision, $this->getTitle() );
1639 if ( $cdel !== '' ) {
1640 $cdel .= ' ';
1641 }
1642
1643 // the outer div is need for styling the revision info and nav in MobileFrontend
1644 $outputPage->addSubtitle( "<div class=\"mw-revision\">" . $revisionInfo .
1645 "<div id=\"mw-revision-nav\">" . $cdel .
1646 $context->msg( 'revision-nav' )->rawParams(
1647 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1648 )->escaped() . "</div></div>" );
1649 }
1650
1651 /**
1652 * Return the HTML for the top of a redirect page
1653 *
1654 * Chances are you should just be using the ParserOutput from
1655 * WikitextContent::getParserOutput instead of calling this for redirects.
1656 *
1657 * @param Title|array $target Destination(s) to redirect
1658 * @param bool $appendSubtitle [optional]
1659 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1660 * @return string Containing HTML with redirect link
1661 *
1662 * @deprecated since 1.30
1663 */
1664 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1665 $lang = $this->getTitle()->getPageLanguage();
1666 $out = $this->getContext()->getOutput();
1667 if ( $appendSubtitle ) {
1668 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1669 }
1670 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1671 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1672 }
1673
1674 /**
1675 * Return the HTML for the top of a redirect page
1676 *
1677 * Chances are you should just be using the ParserOutput from
1678 * WikitextContent::getParserOutput instead of calling this for redirects.
1679 *
1680 * @since 1.23
1681 * @param Language $lang
1682 * @param Title|array $target Destination(s) to redirect
1683 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1684 * @return string Containing HTML with redirect link
1685 */
1686 public static function getRedirectHeaderHtml( Language $lang, $target, $forceKnown = false ) {
1687 if ( !is_array( $target ) ) {
1688 $target = [ $target ];
1689 }
1690
1691 $html = '<ul class="redirectText">';
1692 /** @var Title $title */
1693 foreach ( $target as $title ) {
1694 $html .= '<li>' . Linker::link(
1695 $title,
1696 htmlspecialchars( $title->getFullText() ),
1697 [],
1698 // Make sure wiki page redirects are not followed
1699 $title->isRedirect() ? [ 'redirect' => 'no' ] : [],
1700 ( $forceKnown ? [ 'known', 'noclasses' ] : [] )
1701 ) . '</li>';
1702 }
1703 $html .= '</ul>';
1704
1705 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1706
1707 return '<div class="redirectMsg">' .
1708 '<p>' . $redirectToText . '</p>' .
1709 $html .
1710 '</div>';
1711 }
1712
1713 /**
1714 * Adds help link with an icon via page indicators.
1715 * Link target can be overridden by a local message containing a wikilink:
1716 * the message key is: 'namespace-' + namespace number + '-helppage'.
1717 * @param string $to Target MediaWiki.org page title or encoded URL.
1718 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1719 * @since 1.25
1720 */
1721 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1722 $msg = wfMessage(
1723 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1724 );
1725
1726 $out = $this->getContext()->getOutput();
1727 if ( !$msg->isDisabled() ) {
1728 $helpUrl = Skin::makeUrl( $msg->plain() );
1729 $out->addHelpLink( $helpUrl, true );
1730 } else {
1731 $out->addHelpLink( $to, $overrideBaseUrl );
1732 }
1733 }
1734
1735 /**
1736 * Handle action=render
1737 */
1738 public function render() {
1739 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1740 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1741 // We later set 'enableSectionEditLinks=false' based on this; also used by ImagePage
1742 $this->viewIsRenderAction = true;
1743 $this->view();
1744 }
1745
1746 /**
1747 * action=protect handler
1748 */
1749 public function protect() {
1750 $form = new ProtectionForm( $this );
1751 $form->execute();
1752 }
1753
1754 /**
1755 * action=unprotect handler (alias)
1756 */
1757 public function unprotect() {
1758 $this->protect();
1759 }
1760
1761 /**
1762 * UI entry point for page deletion
1763 */
1764 public function delete() {
1765 # This code desperately needs to be totally rewritten
1766
1767 $title = $this->getTitle();
1768 $context = $this->getContext();
1769 $user = $context->getUser();
1770 $request = $context->getRequest();
1771
1772 # Check permissions
1773 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1774 if ( count( $permissionErrors ) ) {
1775 throw new PermissionsError( 'delete', $permissionErrors );
1776 }
1777
1778 # Read-only check...
1779 if ( wfReadOnly() ) {
1780 throw new ReadOnlyError;
1781 }
1782
1783 # Better double-check that it hasn't been deleted yet!
1784 $this->mPage->loadPageData(
1785 $request->wasPosted() ? WikiPage::READ_LATEST : WikiPage::READ_NORMAL
1786 );
1787 if ( !$this->mPage->exists() ) {
1788 $deleteLogPage = new LogPage( 'delete' );
1789 $outputPage = $context->getOutput();
1790 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1791 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1792 [ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ]
1793 );
1794 $outputPage->addHTML(
1795 Xml::element( 'h2', null, $deleteLogPage->getName()->text() )
1796 );
1797 LogEventsList::showLogExtract(
1798 $outputPage,
1799 'delete',
1800 $title
1801 );
1802
1803 return;
1804 }
1805
1806 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1807 $deleteReason = $request->getText( 'wpReason' );
1808
1809 if ( $deleteReasonList == 'other' ) {
1810 $reason = $deleteReason;
1811 } elseif ( $deleteReason != '' ) {
1812 // Entry from drop down menu + additional comment
1813 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1814 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1815 } else {
1816 $reason = $deleteReasonList;
1817 }
1818
1819 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1820 [ 'delete', $this->getTitle()->getPrefixedText() ] )
1821 ) {
1822 # Flag to hide all contents of the archived revisions
1823 $suppress = $request->getCheck( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1824
1825 $this->doDelete( $reason, $suppress );
1826
1827 WatchAction::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1828
1829 return;
1830 }
1831
1832 // Generate deletion reason
1833 $hasHistory = false;
1834 if ( !$reason ) {
1835 try {
1836 $reason = $this->generateReason( $hasHistory );
1837 } catch ( Exception $e ) {
1838 # if a page is horribly broken, we still want to be able to
1839 # delete it. So be lenient about errors here.
1840 wfDebug( "Error while building auto delete summary: $e" );
1841 $reason = '';
1842 }
1843 }
1844
1845 // If the page has a history, insert a warning
1846 if ( $hasHistory ) {
1847 $title = $this->getTitle();
1848
1849 // The following can use the real revision count as this is only being shown for users
1850 // that can delete this page.
1851 // This, as a side-effect, also makes sure that the following query isn't being run for
1852 // pages with a larger history, unless the user has the 'bigdelete' right
1853 // (and is about to delete this page).
1854 $dbr = wfGetDB( DB_REPLICA );
1855 $revisions = $edits = (int)$dbr->selectField(
1856 'revision',
1857 'COUNT(rev_page)',
1858 [ 'rev_page' => $title->getArticleID() ],
1859 __METHOD__
1860 );
1861
1862 // @todo i18n issue/patchwork message
1863 $context->getOutput()->addHTML(
1864 '<strong class="mw-delete-warning-revisions">' .
1865 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1866 $context->msg( 'word-separator' )->escaped() . Linker::linkKnown( $title,
1867 $context->msg( 'history' )->escaped(),
1868 [],
1869 [ 'action' => 'history' ] ) .
1870 '</strong>'
1871 );
1872
1873 if ( $title->isBigDeletion() ) {
1874 global $wgDeleteRevisionsLimit;
1875 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1876 [
1877 'delete-warning-toobig',
1878 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1879 ]
1880 );
1881 }
1882 }
1883
1884 $this->confirmDelete( $reason );
1885 }
1886
1887 /**
1888 * Output deletion confirmation dialog
1889 * @todo Move to another file?
1890 * @param string $reason Prefilled reason
1891 */
1892 public function confirmDelete( $reason ) {
1893 wfDebug( "Article::confirmDelete\n" );
1894
1895 $title = $this->getTitle();
1896 $ctx = $this->getContext();
1897 $outputPage = $ctx->getOutput();
1898 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1899 $outputPage->addBacklinkSubtitle( $title );
1900 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1901 $outputPage->addModules( 'mediawiki.action.delete' );
1902
1903 $backlinkCache = $title->getBacklinkCache();
1904 if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
1905 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1906 'deleting-backlinks-warning' );
1907 }
1908
1909 $subpageQueryLimit = 51;
1910 $subpages = $title->getSubpages( $subpageQueryLimit );
1911 $subpageCount = count( $subpages );
1912 if ( $subpageCount > 0 ) {
1913 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1914 [ 'deleting-subpages-warning', Message::numParam( $subpageCount ) ] );
1915 }
1916 $outputPage->addWikiMsg( 'confirmdeletetext' );
1917
1918 Hooks::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
1919
1920 $user = $this->getContext()->getUser();
1921 $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $title );
1922
1923 $outputPage->enableOOUI();
1924
1925 $options = Xml::listDropDownOptions(
1926 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
1927 [ 'other' => $ctx->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
1928 );
1929 $options = Xml::listDropDownOptionsOoui( $options );
1930
1931 $fields[] = new OOUI\FieldLayout(
1932 new OOUI\DropdownInputWidget( [
1933 'name' => 'wpDeleteReasonList',
1934 'inputId' => 'wpDeleteReasonList',
1935 'tabIndex' => 1,
1936 'infusable' => true,
1937 'value' => '',
1938 'options' => $options
1939 ] ),
1940 [
1941 'label' => $ctx->msg( 'deletecomment' )->text(),
1942 'align' => 'top',
1943 ]
1944 );
1945
1946 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
1947 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
1948 // Unicode codepoints.
1949 $fields[] = new OOUI\FieldLayout(
1950 new OOUI\TextInputWidget( [
1951 'name' => 'wpReason',
1952 'inputId' => 'wpReason',
1953 'tabIndex' => 2,
1954 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
1955 'infusable' => true,
1956 'value' => $reason,
1957 'autofocus' => true,
1958 ] ),
1959 [
1960 'label' => $ctx->msg( 'deleteotherreason' )->text(),
1961 'align' => 'top',
1962 ]
1963 );
1964
1965 if ( $user->isLoggedIn() ) {
1966 $fields[] = new OOUI\FieldLayout(
1967 new OOUI\CheckboxInputWidget( [
1968 'name' => 'wpWatch',
1969 'inputId' => 'wpWatch',
1970 'tabIndex' => 3,
1971 'selected' => $checkWatch,
1972 ] ),
1973 [
1974 'label' => $ctx->msg( 'watchthis' )->text(),
1975 'align' => 'inline',
1976 'infusable' => true,
1977 ]
1978 );
1979 }
1980
1981 if ( $user->isAllowed( 'suppressrevision' ) ) {
1982 $fields[] = new OOUI\FieldLayout(
1983 new OOUI\CheckboxInputWidget( [
1984 'name' => 'wpSuppress',
1985 'inputId' => 'wpSuppress',
1986 'tabIndex' => 4,
1987 ] ),
1988 [
1989 'label' => $ctx->msg( 'revdelete-suppress' )->text(),
1990 'align' => 'inline',
1991 'infusable' => true,
1992 ]
1993 );
1994 }
1995
1996 $fields[] = new OOUI\FieldLayout(
1997 new OOUI\ButtonInputWidget( [
1998 'name' => 'wpConfirmB',
1999 'inputId' => 'wpConfirmB',
2000 'tabIndex' => 5,
2001 'value' => $ctx->msg( 'deletepage' )->text(),
2002 'label' => $ctx->msg( 'deletepage' )->text(),
2003 'flags' => [ 'primary', 'destructive' ],
2004 'type' => 'submit',
2005 ] ),
2006 [
2007 'align' => 'top',
2008 ]
2009 );
2010
2011 $fieldset = new OOUI\FieldsetLayout( [
2012 'label' => $ctx->msg( 'delete-legend' )->text(),
2013 'id' => 'mw-delete-table',
2014 'items' => $fields,
2015 ] );
2016
2017 $form = new OOUI\FormLayout( [
2018 'method' => 'post',
2019 'action' => $title->getLocalURL( 'action=delete' ),
2020 'id' => 'deleteconfirm',
2021 ] );
2022 $form->appendContent(
2023 $fieldset,
2024 new OOUI\HtmlSnippet(
2025 Html::hidden( 'wpEditToken', $user->getEditToken( [ 'delete', $title->getPrefixedText() ] ) )
2026 )
2027 );
2028
2029 $outputPage->addHTML(
2030 new OOUI\PanelLayout( [
2031 'classes' => [ 'deletepage-wrapper' ],
2032 'expanded' => false,
2033 'padded' => true,
2034 'framed' => true,
2035 'content' => $form,
2036 ] )
2037 );
2038
2039 if ( $user->isAllowed( 'editinterface' ) ) {
2040 $link = Linker::linkKnown(
2041 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
2042 wfMessage( 'delete-edit-reasonlist' )->escaped(),
2043 [],
2044 [ 'action' => 'edit' ]
2045 );
2046 $outputPage->addHTML( '<p class="mw-delete-editreasons">' . $link . '</p>' );
2047 }
2048
2049 $deleteLogPage = new LogPage( 'delete' );
2050 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2051 LogEventsList::showLogExtract( $outputPage, 'delete', $title );
2052 }
2053
2054 /**
2055 * Perform a deletion and output success or failure messages
2056 * @param string $reason
2057 * @param bool $suppress
2058 * @param bool $immediate false allows deleting over time via the job queue
2059 * @throws FatalError
2060 * @throws MWException
2061 */
2062 public function doDelete( $reason, $suppress = false, $immediate = false ) {
2063 $error = '';
2064 $context = $this->getContext();
2065 $outputPage = $context->getOutput();
2066 $user = $context->getUser();
2067 $status = $this->mPage->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user,
2068 [], 'delete', $immediate );
2069
2070 if ( $status->isOK() ) {
2071 $deleted = $this->getTitle()->getPrefixedText();
2072
2073 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
2074 $outputPage->setRobotPolicy( 'noindex,nofollow' );
2075
2076 if ( $status->isGood() ) {
2077 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
2078 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
2079 Hooks::run( 'ArticleDeleteAfterSuccess', [ $this->getTitle(), $outputPage ] );
2080 } else {
2081 $outputPage->addWikiMsg( 'delete-scheduled', wfEscapeWikiText( $deleted ) );
2082 }
2083
2084 $outputPage->returnToMain( false );
2085 } else {
2086 $outputPage->setPageTitle(
2087 wfMessage( 'cannotdelete-title',
2088 $this->getTitle()->getPrefixedText() )
2089 );
2090
2091 if ( $error == '' ) {
2092 $outputPage->wrapWikiTextAsInterface(
2093 'error mw-error-cannotdelete',
2094 $status->getWikiText()
2095 );
2096 $deleteLogPage = new LogPage( 'delete' );
2097 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2098
2099 LogEventsList::showLogExtract(
2100 $outputPage,
2101 'delete',
2102 $this->getTitle()
2103 );
2104 } else {
2105 $outputPage->addHTML( $error );
2106 }
2107 }
2108 }
2109
2110 /* Caching functions */
2111
2112 /**
2113 * checkLastModified returns true if it has taken care of all
2114 * output to the client that is necessary for this request.
2115 * (that is, it has sent a cached version of the page)
2116 *
2117 * @return bool True if cached version send, false otherwise
2118 */
2119 protected function tryFileCache() {
2120 static $called = false;
2121
2122 if ( $called ) {
2123 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2124 return false;
2125 }
2126
2127 $called = true;
2128 if ( $this->isFileCacheable() ) {
2129 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
2130 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
2131 wfDebug( "Article::tryFileCache(): about to load file\n" );
2132 $cache->loadFromFileCache( $this->getContext() );
2133 return true;
2134 } else {
2135 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2136 ob_start( [ &$cache, 'saveToFileCache' ] );
2137 }
2138 } else {
2139 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2140 }
2141
2142 return false;
2143 }
2144
2145 /**
2146 * Check if the page can be cached
2147 * @param int $mode One of the HTMLFileCache::MODE_* constants (since 1.28)
2148 * @return bool
2149 */
2150 public function isFileCacheable( $mode = HTMLFileCache::MODE_NORMAL ) {
2151 $cacheable = false;
2152
2153 if ( HTMLFileCache::useFileCache( $this->getContext(), $mode ) ) {
2154 $cacheable = $this->mPage->getId()
2155 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
2156 // Extension may have reason to disable file caching on some pages.
2157 if ( $cacheable ) {
2158 // Avoid PHP 7.1 warning of passing $this by reference
2159 $articlePage = $this;
2160 $cacheable = Hooks::run( 'IsFileCacheable', [ &$articlePage ] );
2161 }
2162 }
2163
2164 return $cacheable;
2165 }
2166
2167 /**#@-*/
2168
2169 /**
2170 * Lightweight method to get the parser output for a page, checking the parser cache
2171 * and so on. Doesn't consider most of the stuff that Article::view() is forced to
2172 * consider, so it's not appropriate to use there.
2173 *
2174 * @since 1.16 (r52326) for LiquidThreads
2175 *
2176 * @param int|null $oldid Revision ID or null
2177 * @param User|null $user The relevant user
2178 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
2179 */
2180 public function getParserOutput( $oldid = null, User $user = null ) {
2181 // XXX: bypasses mParserOptions and thus setParserOptions()
2182
2183 if ( $user === null ) {
2184 $parserOptions = $this->getParserOptions();
2185 } else {
2186 $parserOptions = $this->mPage->makeParserOptions( $user );
2187 }
2188
2189 return $this->mPage->getParserOutput( $parserOptions, $oldid );
2190 }
2191
2192 /**
2193 * Override the ParserOptions used to render the primary article wikitext.
2194 *
2195 * @param ParserOptions $options
2196 * @throws MWException If the parser options where already initialized.
2197 */
2198 public function setParserOptions( ParserOptions $options ) {
2199 if ( $this->mParserOptions ) {
2200 throw new MWException( "can't change parser options after they have already been set" );
2201 }
2202
2203 // clone, so if $options is modified later, it doesn't confuse the parser cache.
2204 $this->mParserOptions = clone $options;
2205 }
2206
2207 /**
2208 * Get parser options suitable for rendering the primary article wikitext
2209 * @return ParserOptions
2210 */
2211 public function getParserOptions() {
2212 if ( !$this->mParserOptions ) {
2213 $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
2214 }
2215 // Clone to allow modifications of the return value without affecting cache
2216 return clone $this->mParserOptions;
2217 }
2218
2219 /**
2220 * Sets the context this Article is executed in
2221 *
2222 * @param IContextSource $context
2223 * @since 1.18
2224 */
2225 public function setContext( $context ) {
2226 $this->mContext = $context;
2227 }
2228
2229 /**
2230 * Gets the context this Article is executed in
2231 *
2232 * @return IContextSource
2233 * @since 1.18
2234 */
2235 public function getContext() {
2236 if ( $this->mContext instanceof IContextSource ) {
2237 return $this->mContext;
2238 } else {
2239 wfDebug( __METHOD__ . " called and \$mContext is null. " .
2240 "Return RequestContext::getMain(); for sanity\n" );
2241 return RequestContext::getMain();
2242 }
2243 }
2244
2245 /**
2246 * Use PHP's magic __get handler to handle accessing of
2247 * raw WikiPage fields for backwards compatibility.
2248 *
2249 * @param string $fname Field name
2250 * @return mixed
2251 */
2252 public function __get( $fname ) {
2253 if ( property_exists( $this->mPage, $fname ) ) {
2254 # wfWarn( "Access to raw $fname field " . __CLASS__ );
2255 return $this->mPage->$fname;
2256 }
2257 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
2258 }
2259
2260 /**
2261 * Use PHP's magic __set handler to handle setting of
2262 * raw WikiPage fields for backwards compatibility.
2263 *
2264 * @param string $fname Field name
2265 * @param mixed $fvalue New value
2266 */
2267 public function __set( $fname, $fvalue ) {
2268 if ( property_exists( $this->mPage, $fname ) ) {
2269 # wfWarn( "Access to raw $fname field of " . __CLASS__ );
2270 $this->mPage->$fname = $fvalue;
2271 // Note: extensions may want to toss on new fields
2272 } elseif ( !in_array( $fname, [ 'mContext', 'mPage' ] ) ) {
2273 $this->mPage->$fname = $fvalue;
2274 } else {
2275 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
2276 }
2277 }
2278
2279 /**
2280 * Call to WikiPage function for backwards compatibility.
2281 * @see WikiPage::checkFlags
2282 */
2283 public function checkFlags( $flags ) {
2284 return $this->mPage->checkFlags( $flags );
2285 }
2286
2287 /**
2288 * Call to WikiPage function for backwards compatibility.
2289 * @see WikiPage::checkTouched
2290 */
2291 public function checkTouched() {
2292 return $this->mPage->checkTouched();
2293 }
2294
2295 /**
2296 * Call to WikiPage function for backwards compatibility.
2297 * @see WikiPage::clearPreparedEdit
2298 */
2299 public function clearPreparedEdit() {
2300 $this->mPage->clearPreparedEdit();
2301 }
2302
2303 /**
2304 * Call to WikiPage function for backwards compatibility.
2305 * @see WikiPage::doDeleteArticleReal
2306 */
2307 public function doDeleteArticleReal(
2308 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null,
2309 $tags = [], $immediate = false
2310 ) {
2311 return $this->mPage->doDeleteArticleReal(
2312 $reason, $suppress, $u1, $u2, $error, $user, $tags, 'delete', $immediate
2313 );
2314 }
2315
2316 /**
2317 * Call to WikiPage function for backwards compatibility.
2318 * @see WikiPage::doDeleteUpdates
2319 */
2320 public function doDeleteUpdates(
2321 $id,
2322 Content $content = null,
2323 $revision = null,
2324 User $user = null
2325 ) {
2326 $this->mPage->doDeleteUpdates( $id, $content, $revision, $user );
2327 }
2328
2329 /**
2330 * Call to WikiPage function for backwards compatibility.
2331 * @deprecated since 1.29. Use WikiPage::doEditContent() directly instead
2332 * @see WikiPage::doEditContent
2333 */
2334 public function doEditContent( Content $content, $summary, $flags = 0, $originalRevId = false,
2335 User $user = null, $serialFormat = null
2336 ) {
2337 wfDeprecated( __METHOD__, '1.29' );
2338 return $this->mPage->doEditContent( $content, $summary, $flags, $originalRevId,
2339 $user, $serialFormat
2340 );
2341 }
2342
2343 /**
2344 * Call to WikiPage function for backwards compatibility.
2345 * @see WikiPage::doEditUpdates
2346 */
2347 public function doEditUpdates( Revision $revision, User $user, array $options = [] ) {
2348 return $this->mPage->doEditUpdates( $revision, $user, $options );
2349 }
2350
2351 /**
2352 * Call to WikiPage function for backwards compatibility.
2353 * @see WikiPage::doPurge
2354 * @note In 1.28 (and only 1.28), this took a $flags parameter that
2355 * controlled how much purging was done.
2356 */
2357 public function doPurge() {
2358 return $this->mPage->doPurge();
2359 }
2360
2361 /**
2362 * Call to WikiPage function for backwards compatibility.
2363 * @see WikiPage::doViewUpdates
2364 */
2365 public function doViewUpdates( User $user, $oldid = 0 ) {
2366 $this->mPage->doViewUpdates( $user, $oldid );
2367 }
2368
2369 /**
2370 * Call to WikiPage function for backwards compatibility.
2371 * @see WikiPage::exists
2372 */
2373 public function exists() {
2374 return $this->mPage->exists();
2375 }
2376
2377 /**
2378 * Call to WikiPage function for backwards compatibility.
2379 * @see WikiPage::followRedirect
2380 */
2381 public function followRedirect() {
2382 return $this->mPage->followRedirect();
2383 }
2384
2385 /**
2386 * Call to WikiPage function for backwards compatibility.
2387 * @see ContentHandler::getActionOverrides
2388 */
2389 public function getActionOverrides() {
2390 return $this->mPage->getActionOverrides();
2391 }
2392
2393 /**
2394 * Call to WikiPage function for backwards compatibility.
2395 * @see WikiPage::getAutoDeleteReason
2396 */
2397 public function getAutoDeleteReason( &$hasHistory ) {
2398 return $this->mPage->getAutoDeleteReason( $hasHistory );
2399 }
2400
2401 /**
2402 * Call to WikiPage function for backwards compatibility.
2403 * @see WikiPage::getCategories
2404 */
2405 public function getCategories() {
2406 return $this->mPage->getCategories();
2407 }
2408
2409 /**
2410 * Call to WikiPage function for backwards compatibility.
2411 * @see WikiPage::getComment
2412 */
2413 public function getComment( $audience = Revision::FOR_PUBLIC, User $user = null ) {
2414 return $this->mPage->getComment( $audience, $user );
2415 }
2416
2417 /**
2418 * Call to WikiPage function for backwards compatibility.
2419 * @see WikiPage::getContentHandler
2420 */
2421 public function getContentHandler() {
2422 return $this->mPage->getContentHandler();
2423 }
2424
2425 /**
2426 * Call to WikiPage function for backwards compatibility.
2427 * @see WikiPage::getContentModel
2428 */
2429 public function getContentModel() {
2430 return $this->mPage->getContentModel();
2431 }
2432
2433 /**
2434 * Call to WikiPage function for backwards compatibility.
2435 * @see WikiPage::getContributors
2436 */
2437 public function getContributors() {
2438 return $this->mPage->getContributors();
2439 }
2440
2441 /**
2442 * Call to WikiPage function for backwards compatibility.
2443 * @see WikiPage::getCreator
2444 */
2445 public function getCreator( $audience = Revision::FOR_PUBLIC, User $user = null ) {
2446 return $this->mPage->getCreator( $audience, $user );
2447 }
2448
2449 /**
2450 * Call to WikiPage function for backwards compatibility.
2451 * @see WikiPage::getDeletionUpdates
2452 */
2453 public function getDeletionUpdates( Content $content = null ) {
2454 return $this->mPage->getDeletionUpdates( $content );
2455 }
2456
2457 /**
2458 * Call to WikiPage function for backwards compatibility.
2459 * @see WikiPage::getHiddenCategories
2460 */
2461 public function getHiddenCategories() {
2462 return $this->mPage->getHiddenCategories();
2463 }
2464
2465 /**
2466 * Call to WikiPage function for backwards compatibility.
2467 * @see WikiPage::getId
2468 */
2469 public function getId() {
2470 return $this->mPage->getId();
2471 }
2472
2473 /**
2474 * Call to WikiPage function for backwards compatibility.
2475 * @see WikiPage::getLatest
2476 */
2477 public function getLatest() {
2478 return $this->mPage->getLatest();
2479 }
2480
2481 /**
2482 * Call to WikiPage function for backwards compatibility.
2483 * @see WikiPage::getLinksTimestamp
2484 */
2485 public function getLinksTimestamp() {
2486 return $this->mPage->getLinksTimestamp();
2487 }
2488
2489 /**
2490 * Call to WikiPage function for backwards compatibility.
2491 * @see WikiPage::getMinorEdit
2492 */
2493 public function getMinorEdit() {
2494 return $this->mPage->getMinorEdit();
2495 }
2496
2497 /**
2498 * Call to WikiPage function for backwards compatibility.
2499 * @see WikiPage::getOldestRevision
2500 */
2501 public function getOldestRevision() {
2502 return $this->mPage->getOldestRevision();
2503 }
2504
2505 /**
2506 * Call to WikiPage function for backwards compatibility.
2507 * @see WikiPage::getRedirectTarget
2508 */
2509 public function getRedirectTarget() {
2510 return $this->mPage->getRedirectTarget();
2511 }
2512
2513 /**
2514 * Call to WikiPage function for backwards compatibility.
2515 * @see WikiPage::getRedirectURL
2516 */
2517 public function getRedirectURL( $rt ) {
2518 return $this->mPage->getRedirectURL( $rt );
2519 }
2520
2521 /**
2522 * Call to WikiPage function for backwards compatibility.
2523 * @see WikiPage::getRevision
2524 */
2525 public function getRevision() {
2526 return $this->mPage->getRevision();
2527 }
2528
2529 /**
2530 * Call to WikiPage function for backwards compatibility.
2531 * @see WikiPage::getTimestamp
2532 */
2533 public function getTimestamp() {
2534 return $this->mPage->getTimestamp();
2535 }
2536
2537 /**
2538 * Call to WikiPage function for backwards compatibility.
2539 * @see WikiPage::getTouched
2540 */
2541 public function getTouched() {
2542 return $this->mPage->getTouched();
2543 }
2544
2545 /**
2546 * Call to WikiPage function for backwards compatibility.
2547 * @see WikiPage::getUndoContent
2548 */
2549 public function getUndoContent( Revision $undo, Revision $undoafter = null ) {
2550 return $this->mPage->getUndoContent( $undo, $undoafter );
2551 }
2552
2553 /**
2554 * Call to WikiPage function for backwards compatibility.
2555 * @see WikiPage::getUser
2556 */
2557 public function getUser( $audience = Revision::FOR_PUBLIC, User $user = null ) {
2558 return $this->mPage->getUser( $audience, $user );
2559 }
2560
2561 /**
2562 * Call to WikiPage function for backwards compatibility.
2563 * @see WikiPage::getUserText
2564 */
2565 public function getUserText( $audience = Revision::FOR_PUBLIC, User $user = null ) {
2566 return $this->mPage->getUserText( $audience, $user );
2567 }
2568
2569 /**
2570 * Call to WikiPage function for backwards compatibility.
2571 * @see WikiPage::hasViewableContent
2572 */
2573 public function hasViewableContent() {
2574 return $this->mPage->hasViewableContent();
2575 }
2576
2577 /**
2578 * Call to WikiPage function for backwards compatibility.
2579 * @see WikiPage::insertOn
2580 */
2581 public function insertOn( $dbw, $pageId = null ) {
2582 return $this->mPage->insertOn( $dbw, $pageId );
2583 }
2584
2585 /**
2586 * Call to WikiPage function for backwards compatibility.
2587 * @see WikiPage::insertProtectNullRevision
2588 */
2589 public function insertProtectNullRevision( $revCommentMsg, array $limit,
2590 array $expiry, $cascade, $reason, $user = null
2591 ) {
2592 return $this->mPage->insertProtectNullRevision( $revCommentMsg, $limit,
2593 $expiry, $cascade, $reason, $user
2594 );
2595 }
2596
2597 /**
2598 * Call to WikiPage function for backwards compatibility.
2599 * @see WikiPage::insertRedirect
2600 */
2601 public function insertRedirect() {
2602 return $this->mPage->insertRedirect();
2603 }
2604
2605 /**
2606 * Call to WikiPage function for backwards compatibility.
2607 * @see WikiPage::insertRedirectEntry
2608 */
2609 public function insertRedirectEntry( Title $rt, $oldLatest = null ) {
2610 return $this->mPage->insertRedirectEntry( $rt, $oldLatest );
2611 }
2612
2613 /**
2614 * Call to WikiPage function for backwards compatibility.
2615 * @see WikiPage::isCountable
2616 */
2617 public function isCountable( $editInfo = false ) {
2618 return $this->mPage->isCountable( $editInfo );
2619 }
2620
2621 /**
2622 * Call to WikiPage function for backwards compatibility.
2623 * @see WikiPage::isRedirect
2624 */
2625 public function isRedirect() {
2626 return $this->mPage->isRedirect();
2627 }
2628
2629 /**
2630 * Call to WikiPage function for backwards compatibility.
2631 * @see WikiPage::loadFromRow
2632 */
2633 public function loadFromRow( $data, $from ) {
2634 return $this->mPage->loadFromRow( $data, $from );
2635 }
2636
2637 /**
2638 * Call to WikiPage function for backwards compatibility.
2639 * @see WikiPage::loadPageData
2640 */
2641 public function loadPageData( $from = 'fromdb' ) {
2642 $this->mPage->loadPageData( $from );
2643 }
2644
2645 /**
2646 * Call to WikiPage function for backwards compatibility.
2647 * @see WikiPage::lockAndGetLatest
2648 */
2649 public function lockAndGetLatest() {
2650 return $this->mPage->lockAndGetLatest();
2651 }
2652
2653 /**
2654 * Call to WikiPage function for backwards compatibility.
2655 * @see WikiPage::makeParserOptions
2656 */
2657 public function makeParserOptions( $context ) {
2658 return $this->mPage->makeParserOptions( $context );
2659 }
2660
2661 /**
2662 * Call to WikiPage function for backwards compatibility.
2663 * @see WikiPage::pageDataFromId
2664 */
2665 public function pageDataFromId( $dbr, $id, $options = [] ) {
2666 return $this->mPage->pageDataFromId( $dbr, $id, $options );
2667 }
2668
2669 /**
2670 * Call to WikiPage function for backwards compatibility.
2671 * @see WikiPage::pageDataFromTitle
2672 */
2673 public function pageDataFromTitle( $dbr, $title, $options = [] ) {
2674 return $this->mPage->pageDataFromTitle( $dbr, $title, $options );
2675 }
2676
2677 /**
2678 * Call to WikiPage function for backwards compatibility.
2679 * @see WikiPage::prepareContentForEdit
2680 */
2681 public function prepareContentForEdit(
2682 Content $content, $revision = null, User $user = null,
2683 $serialFormat = null, $useCache = true
2684 ) {
2685 return $this->mPage->prepareContentForEdit(
2686 $content, $revision, $user,
2687 $serialFormat, $useCache
2688 );
2689 }
2690
2691 /**
2692 * Call to WikiPage function for backwards compatibility.
2693 * @see WikiPage::protectDescription
2694 */
2695 public function protectDescription( array $limit, array $expiry ) {
2696 return $this->mPage->protectDescription( $limit, $expiry );
2697 }
2698
2699 /**
2700 * Call to WikiPage function for backwards compatibility.
2701 * @see WikiPage::protectDescriptionLog
2702 */
2703 public function protectDescriptionLog( array $limit, array $expiry ) {
2704 return $this->mPage->protectDescriptionLog( $limit, $expiry );
2705 }
2706
2707 /**
2708 * Call to WikiPage function for backwards compatibility.
2709 * @see WikiPage::replaceSectionAtRev
2710 */
2711 public function replaceSectionAtRev( $sectionId, Content $sectionContent,
2712 $sectionTitle = '', $baseRevId = null
2713 ) {
2714 return $this->mPage->replaceSectionAtRev( $sectionId, $sectionContent,
2715 $sectionTitle, $baseRevId
2716 );
2717 }
2718
2719 /**
2720 * Call to WikiPage function for backwards compatibility.
2721 * @see WikiPage::replaceSectionContent
2722 */
2723 public function replaceSectionContent(
2724 $sectionId, Content $sectionContent, $sectionTitle = '', $edittime = null
2725 ) {
2726 return $this->mPage->replaceSectionContent(
2727 $sectionId, $sectionContent, $sectionTitle, $edittime
2728 );
2729 }
2730
2731 /**
2732 * Call to WikiPage function for backwards compatibility.
2733 * @see WikiPage::setTimestamp
2734 */
2735 public function setTimestamp( $ts ) {
2736 return $this->mPage->setTimestamp( $ts );
2737 }
2738
2739 /**
2740 * Call to WikiPage function for backwards compatibility.
2741 * @see WikiPage::shouldCheckParserCache
2742 */
2743 public function shouldCheckParserCache( ParserOptions $parserOptions, $oldId ) {
2744 return $this->mPage->shouldCheckParserCache( $parserOptions, $oldId );
2745 }
2746
2747 /**
2748 * Call to WikiPage function for backwards compatibility.
2749 * @see WikiPage::supportsSections
2750 */
2751 public function supportsSections() {
2752 return $this->mPage->supportsSections();
2753 }
2754
2755 /**
2756 * Call to WikiPage function for backwards compatibility.
2757 * @see WikiPage::triggerOpportunisticLinksUpdate
2758 */
2759 public function triggerOpportunisticLinksUpdate( ParserOutput $parserOutput ) {
2760 return $this->mPage->triggerOpportunisticLinksUpdate( $parserOutput );
2761 }
2762
2763 /**
2764 * Call to WikiPage function for backwards compatibility.
2765 * @see WikiPage::updateCategoryCounts
2766 */
2767 public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
2768 return $this->mPage->updateCategoryCounts( $added, $deleted, $id );
2769 }
2770
2771 /**
2772 * Call to WikiPage function for backwards compatibility.
2773 * @see WikiPage::updateIfNewerOn
2774 */
2775 public function updateIfNewerOn( $dbw, $revision ) {
2776 return $this->mPage->updateIfNewerOn( $dbw, $revision );
2777 }
2778
2779 /**
2780 * Call to WikiPage function for backwards compatibility.
2781 * @see WikiPage::updateRedirectOn
2782 */
2783 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
2784 return $this->mPage->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect );
2785 }
2786
2787 /**
2788 * Call to WikiPage function for backwards compatibility.
2789 * @see WikiPage::updateRevisionOn
2790 */
2791 public function updateRevisionOn( $dbw, $revision, $lastRevision = null,
2792 $lastRevIsRedirect = null
2793 ) {
2794 return $this->mPage->updateRevisionOn( $dbw, $revision, $lastRevision,
2795 $lastRevIsRedirect
2796 );
2797 }
2798
2799 /**
2800 * @param array $limit
2801 * @param array $expiry
2802 * @param bool &$cascade
2803 * @param string $reason
2804 * @param User $user
2805 * @return Status
2806 */
2807 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2808 $reason, User $user
2809 ) {
2810 return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2811 }
2812
2813 /**
2814 * @param array $limit
2815 * @param string $reason
2816 * @param int &$cascade
2817 * @param array $expiry
2818 * @return bool
2819 */
2820 public function updateRestrictions( $limit = [], $reason = '',
2821 &$cascade = 0, $expiry = []
2822 ) {
2823 return $this->mPage->doUpdateRestrictions(
2824 $limit,
2825 $expiry,
2826 $cascade,
2827 $reason,
2828 $this->getContext()->getUser()
2829 );
2830 }
2831
2832 /**
2833 * @param string $reason
2834 * @param bool $suppress
2835 * @param int|null $u1 Unused
2836 * @param bool|null $u2 Unused
2837 * @param string &$error
2838 * @param bool $immediate false allows deleting over time via the job queue
2839 * @return bool
2840 * @throws FatalError
2841 * @throws MWException
2842 */
2843 public function doDeleteArticle(
2844 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', $immediate = false
2845 ) {
2846 return $this->mPage->doDeleteArticle( $reason, $suppress, $u1, $u2, $error,
2847 null, $immediate );
2848 }
2849
2850 /**
2851 * @param string $fromP
2852 * @param string $summary
2853 * @param string $token
2854 * @param bool $bot
2855 * @param array &$resultDetails
2856 * @param User|null $user
2857 * @return array
2858 */
2859 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user = null ) {
2860 if ( !$user ) {
2861 $user = $this->getContext()->getUser();
2862 }
2863
2864 return $this->mPage->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2865 }
2866
2867 /**
2868 * @param string $fromP
2869 * @param string $summary
2870 * @param bool $bot
2871 * @param array &$resultDetails
2872 * @param User|null $guser
2873 * @return array
2874 */
2875 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser = null ) {
2876 if ( !$guser ) {
2877 $guser = $this->getContext()->getUser();
2878 }
2879
2880 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2881 }
2882
2883 /**
2884 * @param bool &$hasHistory
2885 * @return mixed
2886 */
2887 public function generateReason( &$hasHistory ) {
2888 $title = $this->mPage->getTitle();
2889 $handler = ContentHandler::getForTitle( $title );
2890 return $handler->getAutoDeleteReason( $title, $hasHistory );
2891 }
2892
2893 // ******
2894 }