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