Merge "Add config for serving main Page from the domain root"
[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(
812 false, 'view-pool-error', $this->getContext()->getLanguage()
813 );
814 $outputPage->wrapWikiTextAsInterface( 'errorbox', $errortext );
815 }
816 # Connection or timeout error
817 return;
818 }
819
820 if ( $this->mParserOutput ) {
821 $outputPage->addParserOutput( $this->mParserOutput, $poOptions );
822 }
823
824 if ( $rev && $this->getRevisionRedirectTarget( $rev ) ) {
825 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
826 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
827 }
828
829 $outputDone = true;
830 break;
831 # Should be unreachable, but just in case...
832 default:
833 break 2;
834 }
835 }
836
837 // Get the ParserOutput actually *displayed* here.
838 // Note that $this->mParserOutput is the *current*/oldid version output.
839 // Note that the ArticleViewHeader hook is allowed to set $outputDone to a
840 // ParserOutput instance.
841 $pOutput = ( $outputDone instanceof ParserOutput )
842 ? $outputDone // object fetched by hook
843 : ( $this->mParserOutput ?: null ); // ParserOutput or null, avoid false
844
845 # Adjust title for main page & pages with displaytitle
846 if ( $pOutput ) {
847 $this->adjustDisplayTitle( $pOutput );
848 }
849
850 # For the main page, overwrite the <title> element with the con-
851 # tents of 'pagetitle-view-mainpage' instead of the default (if
852 # that's not empty).
853 # This message always exists because it is in the i18n files
854 if ( $this->getTitle()->isMainPage() ) {
855 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
856 if ( !$msg->isDisabled() ) {
857 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
858 }
859 }
860
861 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
862 # This could use getTouched(), but that could be scary for major template edits.
863 $outputPage->adaptCdnTTL( $this->mPage->getTimestamp(), IExpiringStore::TTL_DAY );
864
865 # Check for any __NOINDEX__ tags on the page using $pOutput
866 $policy = $this->getRobotPolicy( 'view', $pOutput ?: null );
867 $outputPage->setIndexPolicy( $policy['index'] );
868 $outputPage->setFollowPolicy( $policy['follow'] ); // FIXME: test this
869
870 $this->showViewFooter();
871 $this->mPage->doViewUpdates( $user, $oldid ); // FIXME: test this
872
873 # Load the postEdit module if the user just saved this revision
874 # See also EditPage::setPostEditCookie
875 $request = $this->getContext()->getRequest();
876 $cookieKey = EditPage::POST_EDIT_COOKIE_KEY_PREFIX . $this->getRevIdFetched();
877 $postEdit = $request->getCookie( $cookieKey );
878 if ( $postEdit ) {
879 # Clear the cookie. This also prevents caching of the response.
880 $request->response()->clearCookie( $cookieKey );
881 $outputPage->addJsConfigVars( 'wgPostEdit', $postEdit );
882 $outputPage->addModules( 'mediawiki.action.view.postEdit' ); // FIXME: test this
883 }
884 }
885
886 /**
887 * @param RevisionRecord $revision
888 * @return null|Title
889 */
890 private function getRevisionRedirectTarget( RevisionRecord $revision ) {
891 // TODO: find a *good* place for the code that determines the redirect target for
892 // a given revision!
893 // NOTE: Use main slot content. Compare code in DerivedPageDataUpdater::revisionIsRedirect.
894 $content = $revision->getContent( SlotRecord::MAIN );
895 return $content ? $content->getRedirectTarget() : null;
896 }
897
898 /**
899 * Adjust title for pages with displaytitle, -{T|}- or language conversion
900 * @param ParserOutput $pOutput
901 */
902 public function adjustDisplayTitle( ParserOutput $pOutput ) {
903 $out = $this->getContext()->getOutput();
904
905 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
906 $titleText = $pOutput->getTitleText();
907 if ( strval( $titleText ) !== '' ) {
908 $out->setPageTitle( $titleText );
909 $out->setDisplayTitle( $titleText );
910 }
911 }
912
913 /**
914 * Show a diff page according to current request variables. For use within
915 * Article::view() only, other callers should use the DifferenceEngine class.
916 */
917 protected function showDiffPage() {
918 $request = $this->getContext()->getRequest();
919 $user = $this->getContext()->getUser();
920 $diff = $request->getVal( 'diff' );
921 $rcid = $request->getVal( 'rcid' );
922 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
923 $purge = $request->getVal( 'action' ) == 'purge';
924 $unhide = $request->getInt( 'unhide' ) == 1;
925 $oldid = $this->getOldID();
926
927 $rev = $this->getRevisionFetched();
928
929 if ( !$rev ) {
930 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
931 $msg = $this->getContext()->msg( 'difference-missing-revision' )
932 ->params( $oldid )
933 ->numParams( 1 )
934 ->parseAsBlock();
935 $this->getContext()->getOutput()->addHTML( $msg );
936 return;
937 }
938
939 $contentHandler = $rev->getContentHandler();
940 $de = $contentHandler->createDifferenceEngine(
941 $this->getContext(),
942 $oldid,
943 $diff,
944 $rcid,
945 $purge,
946 $unhide
947 );
948
949 // DifferenceEngine directly fetched the revision:
950 $this->mRevIdFetched = $de->getNewid();
951 $de->showDiffPage( $diffOnly );
952
953 // Run view updates for the newer revision being diffed (and shown
954 // below the diff if not $diffOnly).
955 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
956 // New can be false, convert it to 0 - this conveniently means the latest revision
957 $this->mPage->doViewUpdates( $user, (int)$new );
958 }
959
960 /**
961 * Get the robot policy to be used for the current view
962 * @param string $action The action= GET parameter
963 * @param ParserOutput|null $pOutput
964 * @return array The policy that should be set
965 * @todo actions other than 'view'
966 */
967 public function getRobotPolicy( $action, ParserOutput $pOutput = null ) {
968 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
969
970 $ns = $this->getTitle()->getNamespace();
971
972 # Don't index user and user talk pages for blocked users (T13443)
973 if ( ( $ns == NS_USER || $ns == NS_USER_TALK ) && !$this->getTitle()->isSubpage() ) {
974 $specificTarget = null;
975 $vagueTarget = null;
976 $titleText = $this->getTitle()->getText();
977 if ( IP::isValid( $titleText ) ) {
978 $vagueTarget = $titleText;
979 } else {
980 $specificTarget = $titleText;
981 }
982 if ( DatabaseBlock::newFromTarget( $specificTarget, $vagueTarget ) instanceof DatabaseBlock ) {
983 return [
984 'index' => 'noindex',
985 'follow' => 'nofollow'
986 ];
987 }
988 }
989
990 if ( $this->mPage->getId() === 0 || $this->getOldID() ) {
991 # Non-articles (special pages etc), and old revisions
992 return [
993 'index' => 'noindex',
994 'follow' => 'nofollow'
995 ];
996 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
997 # Discourage indexing of printable versions, but encourage following
998 return [
999 'index' => 'noindex',
1000 'follow' => 'follow'
1001 ];
1002 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
1003 # For ?curid=x urls, disallow indexing
1004 return [
1005 'index' => 'noindex',
1006 'follow' => 'follow'
1007 ];
1008 }
1009
1010 # Otherwise, construct the policy based on the various config variables.
1011 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
1012
1013 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
1014 # Honour customised robot policies for this namespace
1015 $policy = array_merge(
1016 $policy,
1017 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
1018 );
1019 }
1020 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
1021 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1022 # a final sanity check that we have really got the parser output.
1023 $policy = array_merge(
1024 $policy,
1025 [ 'index' => $pOutput->getIndexPolicy() ]
1026 );
1027 }
1028
1029 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
1030 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1031 $policy = array_merge(
1032 $policy,
1033 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
1034 );
1035 }
1036
1037 return $policy;
1038 }
1039
1040 /**
1041 * Converts a String robot policy into an associative array, to allow
1042 * merging of several policies using array_merge().
1043 * @param array|string $policy Returns empty array on null/false/'', transparent
1044 * to already-converted arrays, converts string.
1045 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
1046 */
1047 public static function formatRobotPolicy( $policy ) {
1048 if ( is_array( $policy ) ) {
1049 return $policy;
1050 } elseif ( !$policy ) {
1051 return [];
1052 }
1053
1054 $policy = explode( ',', $policy );
1055 $policy = array_map( 'trim', $policy );
1056
1057 $arr = [];
1058 foreach ( $policy as $var ) {
1059 if ( in_array( $var, [ 'index', 'noindex' ] ) ) {
1060 $arr['index'] = $var;
1061 } elseif ( in_array( $var, [ 'follow', 'nofollow' ] ) ) {
1062 $arr['follow'] = $var;
1063 }
1064 }
1065
1066 return $arr;
1067 }
1068
1069 /**
1070 * If this request is a redirect view, send "redirected from" subtitle to
1071 * the output. Returns true if the header was needed, false if this is not
1072 * a redirect view. Handles both local and remote redirects.
1073 *
1074 * @return bool
1075 */
1076 public function showRedirectedFromHeader() {
1077 global $wgRedirectSources;
1078
1079 $context = $this->getContext();
1080 $outputPage = $context->getOutput();
1081 $request = $context->getRequest();
1082 $rdfrom = $request->getVal( 'rdfrom' );
1083
1084 // Construct a URL for the current page view, but with the target title
1085 $query = $request->getValues();
1086 unset( $query['rdfrom'] );
1087 unset( $query['title'] );
1088 if ( $this->getTitle()->isRedirect() ) {
1089 // Prevent double redirects
1090 $query['redirect'] = 'no';
1091 }
1092 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
1093
1094 if ( isset( $this->mRedirectedFrom ) ) {
1095 // Avoid PHP 7.1 warning of passing $this by reference
1096 $articlePage = $this;
1097
1098 // This is an internally redirected page view.
1099 // We'll need a backlink to the source page for navigation.
1100 if ( Hooks::run( 'ArticleViewRedirect', [ &$articlePage ] ) ) {
1101 $redir = Linker::linkKnown(
1102 $this->mRedirectedFrom,
1103 null,
1104 [],
1105 [ 'redirect' => 'no' ]
1106 );
1107
1108 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1109 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1110 . "</span>" );
1111
1112 // Add the script to update the displayed URL and
1113 // set the fragment if one was specified in the redirect
1114 $outputPage->addJsConfigVars( [
1115 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1116 ] );
1117 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1118
1119 // Add a <link rel="canonical"> tag
1120 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
1121
1122 // Tell the output object that the user arrived at this article through a redirect
1123 $outputPage->setRedirectedFrom( $this->mRedirectedFrom );
1124
1125 return true;
1126 }
1127 } elseif ( $rdfrom ) {
1128 // This is an externally redirected view, from some other wiki.
1129 // If it was reported from a trusted site, supply a backlink.
1130 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1131 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
1132 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1133 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1134 . "</span>" );
1135
1136 // Add the script to update the displayed URL
1137 $outputPage->addJsConfigVars( [
1138 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1139 ] );
1140 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1141
1142 return true;
1143 }
1144 }
1145
1146 return false;
1147 }
1148
1149 /**
1150 * Show a header specific to the namespace currently being viewed, like
1151 * [[MediaWiki:Talkpagetext]]. For Article::view().
1152 */
1153 public function showNamespaceHeader() {
1154 if ( $this->getTitle()->isTalkPage() && !wfMessage( 'talkpageheader' )->isDisabled() ) {
1155 $this->getContext()->getOutput()->wrapWikiMsg(
1156 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1157 [ 'talkpageheader' ]
1158 );
1159 }
1160 }
1161
1162 /**
1163 * Show the footer section of an ordinary page view
1164 */
1165 public function showViewFooter() {
1166 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1167 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1168 && IP::isValid( $this->getTitle()->getText() )
1169 ) {
1170 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1171 }
1172
1173 // Show a footer allowing the user to patrol the shown revision or page if possible
1174 $patrolFooterShown = $this->showPatrolFooter();
1175
1176 Hooks::run( 'ArticleViewFooter', [ $this, $patrolFooterShown ] );
1177 }
1178
1179 /**
1180 * If patrol is possible, output a patrol UI box. This is called from the
1181 * footer section of ordinary page views. If patrol is not possible or not
1182 * desired, does nothing.
1183 * Side effect: When the patrol link is build, this method will call
1184 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1185 *
1186 * @return bool
1187 */
1188 public function showPatrolFooter() {
1189 global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol;
1190
1191 // Allow hooks to decide whether to not output this at all
1192 if ( !Hooks::run( 'ArticleShowPatrolFooter', [ $this ] ) ) {
1193 return false;
1194 }
1195
1196 $outputPage = $this->getContext()->getOutput();
1197 $user = $this->getContext()->getUser();
1198 $title = $this->getTitle();
1199 $rc = false;
1200
1201 if ( !MediaWikiServices::getInstance()->getPermissionManager()
1202 ->quickUserCan( 'patrol', $user, $title )
1203 || !( $wgUseRCPatrol || $wgUseNPPatrol
1204 || ( $wgUseFilePatrol && $title->inNamespace( NS_FILE ) ) )
1205 ) {
1206 // Patrolling is disabled or the user isn't allowed to
1207 return false;
1208 }
1209
1210 if ( $this->mRevision
1211 && !RecentChange::isInRCLifespan( $this->mRevision->getTimestamp(), 21600 )
1212 ) {
1213 // The current revision is already older than what could be in the RC table
1214 // 6h tolerance because the RC might not be cleaned out regularly
1215 return false;
1216 }
1217
1218 // Check for cached results
1219 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1220 $key = $cache->makeKey( 'unpatrollable-page', $title->getArticleID() );
1221 if ( $cache->get( $key ) ) {
1222 return false;
1223 }
1224
1225 $dbr = wfGetDB( DB_REPLICA );
1226 $oldestRevisionTimestamp = $dbr->selectField(
1227 'revision',
1228 'MIN( rev_timestamp )',
1229 [ 'rev_page' => $title->getArticleID() ],
1230 __METHOD__
1231 );
1232
1233 // New page patrol: Get the timestamp of the oldest revison which
1234 // the revision table holds for the given page. Then we look
1235 // whether it's within the RC lifespan and if it is, we try
1236 // to get the recentchanges row belonging to that entry
1237 // (with rc_new = 1).
1238 $recentPageCreation = false;
1239 if ( $oldestRevisionTimestamp
1240 && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1241 ) {
1242 // 6h tolerance because the RC might not be cleaned out regularly
1243 $recentPageCreation = true;
1244 $rc = RecentChange::newFromConds(
1245 [
1246 'rc_new' => 1,
1247 'rc_timestamp' => $oldestRevisionTimestamp,
1248 'rc_namespace' => $title->getNamespace(),
1249 'rc_cur_id' => $title->getArticleID()
1250 ],
1251 __METHOD__
1252 );
1253 if ( $rc ) {
1254 // Use generic patrol message for new pages
1255 $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
1256 }
1257 }
1258
1259 // File patrol: Get the timestamp of the latest upload for this page,
1260 // check whether it is within the RC lifespan and if it is, we try
1261 // to get the recentchanges row belonging to that entry
1262 // (with rc_type = RC_LOG, rc_log_type = upload).
1263 $recentFileUpload = false;
1264 if ( ( !$rc || $rc->getAttribute( 'rc_patrolled' ) ) && $wgUseFilePatrol
1265 && $title->getNamespace() === NS_FILE ) {
1266 // Retrieve timestamp of most recent upload
1267 $newestUploadTimestamp = $dbr->selectField(
1268 'image',
1269 'MAX( img_timestamp )',
1270 [ 'img_name' => $title->getDBkey() ],
1271 __METHOD__
1272 );
1273 if ( $newestUploadTimestamp
1274 && RecentChange::isInRCLifespan( $newestUploadTimestamp, 21600 )
1275 ) {
1276 // 6h tolerance because the RC might not be cleaned out regularly
1277 $recentFileUpload = true;
1278 $rc = RecentChange::newFromConds(
1279 [
1280 'rc_type' => RC_LOG,
1281 'rc_log_type' => 'upload',
1282 'rc_timestamp' => $newestUploadTimestamp,
1283 'rc_namespace' => NS_FILE,
1284 'rc_cur_id' => $title->getArticleID()
1285 ],
1286 __METHOD__
1287 );
1288 if ( $rc ) {
1289 // Use patrol message specific to files
1290 $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
1291 }
1292 }
1293 }
1294
1295 if ( !$recentPageCreation && !$recentFileUpload ) {
1296 // Page creation and latest upload (for files) is too old to be in RC
1297
1298 // We definitely can't patrol so cache the information
1299 // When a new file version is uploaded, the cache is cleared
1300 $cache->set( $key, '1' );
1301
1302 return false;
1303 }
1304
1305 if ( !$rc ) {
1306 // Don't cache: This can be hit if the page gets accessed very fast after
1307 // its creation / latest upload or in case we have high replica DB lag. In case
1308 // the revision is too old, we will already return above.
1309 return false;
1310 }
1311
1312 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1313 // Patrolled RC entry around
1314
1315 // Cache the information we gathered above in case we can't patrol
1316 // Don't cache in case we can patrol as this could change
1317 $cache->set( $key, '1' );
1318
1319 return false;
1320 }
1321
1322 if ( $rc->getPerformer()->equals( $user ) ) {
1323 // Don't show a patrol link for own creations/uploads. If the user could
1324 // patrol them, they already would be patrolled
1325 return false;
1326 }
1327
1328 $outputPage->preventClickjacking();
1329 if ( MediaWikiServices::getInstance()
1330 ->getPermissionManager()
1331 ->userHasRight( $user, 'writeapi' )
1332 ) {
1333 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1334 }
1335
1336 $link = Linker::linkKnown(
1337 $title,
1338 $markPatrolledMsg->escaped(),
1339 [],
1340 [
1341 'action' => 'markpatrolled',
1342 'rcid' => $rc->getAttribute( 'rc_id' ),
1343 ]
1344 );
1345
1346 $outputPage->addHTML(
1347 "<div class='patrollink' data-mw='interface'>" .
1348 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1349 '</div>'
1350 );
1351
1352 return true;
1353 }
1354
1355 /**
1356 * Purge the cache used to check if it is worth showing the patrol footer
1357 * For example, it is done during re-uploads when file patrol is used.
1358 * @param int $articleID ID of the article to purge
1359 * @since 1.27
1360 */
1361 public static function purgePatrolFooterCache( $articleID ) {
1362 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1363 $cache->delete( $cache->makeKey( 'unpatrollable-page', $articleID ) );
1364 }
1365
1366 /**
1367 * Show the error text for a missing article. For articles in the MediaWiki
1368 * namespace, show the default message text. To be called from Article::view().
1369 */
1370 public function showMissingArticle() {
1371 global $wgSend404Code;
1372
1373 $outputPage = $this->getContext()->getOutput();
1374 // Whether the page is a root user page of an existing user (but not a subpage)
1375 $validUserPage = false;
1376
1377 $title = $this->getTitle();
1378
1379 $services = MediaWikiServices::getInstance();
1380
1381 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1382 if ( $title->getNamespace() == NS_USER
1383 || $title->getNamespace() == NS_USER_TALK
1384 ) {
1385 $rootPart = explode( '/', $title->getText() )[0];
1386 $user = User::newFromName( $rootPart, false /* allow IP users */ );
1387 $ip = User::isIP( $rootPart );
1388 $block = DatabaseBlock::newFromTarget( $user, $user );
1389
1390 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1391 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1392 [ 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ] );
1393 } elseif (
1394 !is_null( $block ) &&
1395 $block->getType() != DatabaseBlock::TYPE_AUTO &&
1396 ( $block->isSitewide() || $user->isBlockedFrom( $title ) )
1397 ) {
1398 // Show log extract if the user is sitewide blocked or is partially
1399 // blocked and not allowed to edit their user page or user talk page
1400 LogEventsList::showLogExtract(
1401 $outputPage,
1402 'block',
1403 $services->getNamespaceInfo()->getCanonicalName( NS_USER ) . ':' .
1404 $block->getTarget(),
1405 '',
1406 [
1407 'lim' => 1,
1408 'showIfEmpty' => false,
1409 'msgKey' => [
1410 'blocked-notice-logextract',
1411 $user->getName() # Support GENDER in notice
1412 ]
1413 ]
1414 );
1415 $validUserPage = !$title->isSubpage();
1416 } else {
1417 $validUserPage = !$title->isSubpage();
1418 }
1419 }
1420
1421 Hooks::run( 'ShowMissingArticle', [ $this ] );
1422
1423 # Show delete and move logs if there were any such events.
1424 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1425 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1426 $dbCache = ObjectCache::getInstance( 'db-replicated' );
1427 $key = $dbCache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) );
1428 $loggedIn = $this->getContext()->getUser()->isLoggedIn();
1429 $sessionExists = $this->getContext()->getRequest()->getSession()->isPersistent();
1430 if ( $loggedIn || $dbCache->get( $key ) || $sessionExists ) {
1431 $logTypes = [ 'delete', 'move', 'protect' ];
1432
1433 $dbr = wfGetDB( DB_REPLICA );
1434
1435 $conds = [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ];
1436 // Give extensions a chance to hide their (unrelated) log entries
1437 Hooks::run( 'Article::MissingArticleConditions', [ &$conds, $logTypes ] );
1438 LogEventsList::showLogExtract(
1439 $outputPage,
1440 $logTypes,
1441 $title,
1442 '',
1443 [
1444 'lim' => 10,
1445 'conds' => $conds,
1446 'showIfEmpty' => false,
1447 'msgKey' => [ $loggedIn || $sessionExists
1448 ? 'moveddeleted-notice'
1449 : 'moveddeleted-notice-recent'
1450 ]
1451 ]
1452 );
1453 }
1454
1455 if ( !$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1456 // If there's no backing content, send a 404 Not Found
1457 // for better machine handling of broken links.
1458 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1459 }
1460
1461 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1462 $policy = $this->getRobotPolicy( 'view' );
1463 $outputPage->setIndexPolicy( $policy['index'] );
1464 $outputPage->setFollowPolicy( $policy['follow'] );
1465
1466 $hookResult = Hooks::run( 'BeforeDisplayNoArticleText', [ $this ] );
1467
1468 if ( !$hookResult ) {
1469 return;
1470 }
1471
1472 # Show error message
1473 $oldid = $this->getOldID();
1474 $pm = MediaWikiServices::getInstance()->getPermissionManager();
1475 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI && $title->hasSourceText() ) {
1476 // use fake Content object for system message
1477 $parserOptions = ParserOptions::newCanonical( 'canonical' );
1478 $outputPage->addParserOutput( $this->getEmptyPageParserOutput( $parserOptions ) );
1479 } else {
1480 if ( $oldid ) {
1481 $text = wfMessage( 'missing-revision', $oldid )->plain();
1482 } elseif ( $pm->quickUserCan( 'create', $this->getContext()->getUser(), $title ) &&
1483 $pm->quickUserCan( 'edit', $this->getContext()->getUser(), $title )
1484 ) {
1485 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
1486 $text = wfMessage( $message )->plain();
1487 } else {
1488 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1489 }
1490
1491 $dir = $this->getContext()->getLanguage()->getDir();
1492 $lang = $this->getContext()->getLanguage()->getHtmlCode();
1493 $outputPage->addWikiTextAsInterface( Xml::openElement( 'div', [
1494 'class' => "noarticletext mw-content-$dir",
1495 'dir' => $dir,
1496 'lang' => $lang,
1497 ] ) . "\n$text\n</div>" );
1498 }
1499 }
1500
1501 /**
1502 * If the revision requested for view is deleted, check permissions.
1503 * Send either an error message or a warning header to the output.
1504 *
1505 * @return bool True if the view is allowed, false if not.
1506 */
1507 public function showDeletedRevisionHeader() {
1508 if ( !$this->mRevision->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
1509 // Not deleted
1510 return true;
1511 }
1512
1513 $outputPage = $this->getContext()->getOutput();
1514 $user = $this->getContext()->getUser();
1515 // If the user is not allowed to see it...
1516 if ( !$this->mRevision->userCan( RevisionRecord::DELETED_TEXT, $user ) ) {
1517 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1518 'rev-deleted-text-permission' );
1519
1520 return false;
1521 // If the user needs to confirm that they want to see it...
1522 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1523 # Give explanation and add a link to view the revision...
1524 $oldid = intval( $this->getOldID() );
1525 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1526 $msg = $this->mRevision->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ?
1527 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1528 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1529 [ $msg, $link ] );
1530
1531 return false;
1532 // We are allowed to see...
1533 } else {
1534 $msg = $this->mRevision->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ?
1535 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1536 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1537
1538 return true;
1539 }
1540 }
1541
1542 /**
1543 * Generate the navigation links when browsing through an article revisions
1544 * It shows the information as:
1545 * Revision as of \<date\>; view current revision
1546 * \<- Previous version | Next Version -\>
1547 *
1548 * @param int $oldid Revision ID of this article revision
1549 */
1550 public function setOldSubtitle( $oldid = 0 ) {
1551 // Avoid PHP 7.1 warning of passing $this by reference
1552 $articlePage = $this;
1553
1554 if ( !Hooks::run( 'DisplayOldSubtitle', [ &$articlePage, &$oldid ] ) ) {
1555 return;
1556 }
1557
1558 $context = $this->getContext();
1559 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1560
1561 # Cascade unhide param in links for easy deletion browsing
1562 $extraParams = [];
1563 if ( $unhide ) {
1564 $extraParams['unhide'] = 1;
1565 }
1566
1567 if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
1568 $revision = $this->mRevision;
1569 } else {
1570 $revision = Revision::newFromId( $oldid );
1571 }
1572
1573 $timestamp = $revision->getTimestamp();
1574
1575 $current = ( $oldid == $this->mPage->getLatest() );
1576 $language = $context->getLanguage();
1577 $user = $context->getUser();
1578
1579 $td = $language->userTimeAndDate( $timestamp, $user );
1580 $tddate = $language->userDate( $timestamp, $user );
1581 $tdtime = $language->userTime( $timestamp, $user );
1582
1583 # Show user links if allowed to see them. If hidden, then show them only if requested...
1584 $userlinks = Linker::revUserTools( $revision, !$unhide );
1585
1586 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1587 ? 'revision-info-current'
1588 : 'revision-info';
1589
1590 $outputPage = $context->getOutput();
1591 $revisionInfo = "<div id=\"mw-{$infomsg}\">" .
1592 $context->msg( $infomsg, $td )
1593 ->rawParams( $userlinks )
1594 ->params( $revision->getId(), $tddate, $tdtime, $revision->getUserText() )
1595 ->rawParams( Linker::revComment( $revision, true, true ) )
1596 ->parse() .
1597 "</div>";
1598
1599 $lnk = $current
1600 ? $context->msg( 'currentrevisionlink' )->escaped()
1601 : Linker::linkKnown(
1602 $this->getTitle(),
1603 $context->msg( 'currentrevisionlink' )->escaped(),
1604 [],
1605 $extraParams
1606 );
1607 $curdiff = $current
1608 ? $context->msg( 'diff' )->escaped()
1609 : Linker::linkKnown(
1610 $this->getTitle(),
1611 $context->msg( 'diff' )->escaped(),
1612 [],
1613 [
1614 'diff' => 'cur',
1615 'oldid' => $oldid
1616 ] + $extraParams
1617 );
1618 $rl = MediaWikiServices::getInstance()->getRevisionLookup();
1619 $prevExist = (bool)$rl->getPreviousRevision( $revision->getRevisionRecord() );
1620 $prevlink = $prevExist
1621 ? Linker::linkKnown(
1622 $this->getTitle(),
1623 $context->msg( 'previousrevision' )->escaped(),
1624 [],
1625 [
1626 'direction' => 'prev',
1627 'oldid' => $oldid
1628 ] + $extraParams
1629 )
1630 : $context->msg( 'previousrevision' )->escaped();
1631 $prevdiff = $prevExist
1632 ? Linker::linkKnown(
1633 $this->getTitle(),
1634 $context->msg( 'diff' )->escaped(),
1635 [],
1636 [
1637 'diff' => 'prev',
1638 'oldid' => $oldid
1639 ] + $extraParams
1640 )
1641 : $context->msg( 'diff' )->escaped();
1642 $nextlink = $current
1643 ? $context->msg( 'nextrevision' )->escaped()
1644 : Linker::linkKnown(
1645 $this->getTitle(),
1646 $context->msg( 'nextrevision' )->escaped(),
1647 [],
1648 [
1649 'direction' => 'next',
1650 'oldid' => $oldid
1651 ] + $extraParams
1652 );
1653 $nextdiff = $current
1654 ? $context->msg( 'diff' )->escaped()
1655 : Linker::linkKnown(
1656 $this->getTitle(),
1657 $context->msg( 'diff' )->escaped(),
1658 [],
1659 [
1660 'diff' => 'next',
1661 'oldid' => $oldid
1662 ] + $extraParams
1663 );
1664
1665 $cdel = Linker::getRevDeleteLink( $user, $revision, $this->getTitle() );
1666 if ( $cdel !== '' ) {
1667 $cdel .= ' ';
1668 }
1669
1670 // the outer div is need for styling the revision info and nav in MobileFrontend
1671 $outputPage->addSubtitle( "<div class=\"mw-revision\">" . $revisionInfo .
1672 "<div id=\"mw-revision-nav\">" . $cdel .
1673 $context->msg( 'revision-nav' )->rawParams(
1674 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1675 )->escaped() . "</div></div>" );
1676 }
1677
1678 /**
1679 * Return the HTML for the top of a redirect page
1680 *
1681 * Chances are you should just be using the ParserOutput from
1682 * WikitextContent::getParserOutput instead of calling this for redirects.
1683 *
1684 * @param Title|array $target Destination(s) to redirect
1685 * @param bool $appendSubtitle [optional]
1686 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1687 * @return string Containing HTML with redirect link
1688 *
1689 * @deprecated since 1.30
1690 */
1691 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1692 $lang = $this->getTitle()->getPageLanguage();
1693 $out = $this->getContext()->getOutput();
1694 if ( $appendSubtitle ) {
1695 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1696 }
1697 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1698 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1699 }
1700
1701 /**
1702 * Return the HTML for the top of a redirect page
1703 *
1704 * Chances are you should just be using the ParserOutput from
1705 * WikitextContent::getParserOutput instead of calling this for redirects.
1706 *
1707 * @since 1.23
1708 * @param Language $lang
1709 * @param Title|array $target Destination(s) to redirect
1710 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1711 * @return string Containing HTML with redirect link
1712 */
1713 public static function getRedirectHeaderHtml( Language $lang, $target, $forceKnown = false ) {
1714 if ( !is_array( $target ) ) {
1715 $target = [ $target ];
1716 }
1717
1718 $html = '<ul class="redirectText">';
1719 /** @var Title $title */
1720 foreach ( $target as $title ) {
1721 $html .= '<li>' . Linker::link(
1722 $title,
1723 htmlspecialchars( $title->getFullText() ),
1724 [],
1725 // Make sure wiki page redirects are not followed
1726 $title->isRedirect() ? [ 'redirect' => 'no' ] : [],
1727 ( $forceKnown ? [ 'known', 'noclasses' ] : [] )
1728 ) . '</li>';
1729 }
1730 $html .= '</ul>';
1731
1732 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1733
1734 return '<div class="redirectMsg">' .
1735 '<p>' . $redirectToText . '</p>' .
1736 $html .
1737 '</div>';
1738 }
1739
1740 /**
1741 * Adds help link with an icon via page indicators.
1742 * Link target can be overridden by a local message containing a wikilink:
1743 * the message key is: 'namespace-' + namespace number + '-helppage'.
1744 * @param string $to Target MediaWiki.org page title or encoded URL.
1745 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1746 * @since 1.25
1747 */
1748 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1749 $msg = wfMessage(
1750 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1751 );
1752
1753 $out = $this->getContext()->getOutput();
1754 if ( !$msg->isDisabled() ) {
1755 $helpUrl = Skin::makeUrl( $msg->plain() );
1756 $out->addHelpLink( $helpUrl, true );
1757 } else {
1758 $out->addHelpLink( $to, $overrideBaseUrl );
1759 }
1760 }
1761
1762 /**
1763 * Handle action=render
1764 */
1765 public function render() {
1766 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1767 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1768 // We later set 'enableSectionEditLinks=false' based on this; also used by ImagePage
1769 $this->viewIsRenderAction = true;
1770 $this->view();
1771 }
1772
1773 /**
1774 * action=protect handler
1775 */
1776 public function protect() {
1777 $form = new ProtectionForm( $this );
1778 $form->execute();
1779 }
1780
1781 /**
1782 * action=unprotect handler (alias)
1783 */
1784 public function unprotect() {
1785 $this->protect();
1786 }
1787
1788 /**
1789 * UI entry point for page deletion
1790 */
1791 public function delete() {
1792 # This code desperately needs to be totally rewritten
1793
1794 $title = $this->getTitle();
1795 $context = $this->getContext();
1796 $user = $context->getUser();
1797 $request = $context->getRequest();
1798
1799 # Check permissions
1800 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1801 if ( count( $permissionErrors ) ) {
1802 throw new PermissionsError( 'delete', $permissionErrors );
1803 }
1804
1805 # Read-only check...
1806 if ( wfReadOnly() ) {
1807 throw new ReadOnlyError;
1808 }
1809
1810 # Better double-check that it hasn't been deleted yet!
1811 $this->mPage->loadPageData(
1812 $request->wasPosted() ? WikiPage::READ_LATEST : WikiPage::READ_NORMAL
1813 );
1814 if ( !$this->mPage->exists() ) {
1815 $deleteLogPage = new LogPage( 'delete' );
1816 $outputPage = $context->getOutput();
1817 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1818 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1819 [ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ]
1820 );
1821 $outputPage->addHTML(
1822 Xml::element( 'h2', null, $deleteLogPage->getName()->text() )
1823 );
1824 LogEventsList::showLogExtract(
1825 $outputPage,
1826 'delete',
1827 $title
1828 );
1829
1830 return;
1831 }
1832
1833 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1834 $deleteReason = $request->getText( 'wpReason' );
1835
1836 if ( $deleteReasonList == 'other' ) {
1837 $reason = $deleteReason;
1838 } elseif ( $deleteReason != '' ) {
1839 // Entry from drop down menu + additional comment
1840 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1841 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1842 } else {
1843 $reason = $deleteReasonList;
1844 }
1845
1846 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1847 [ 'delete', $this->getTitle()->getPrefixedText() ] )
1848 ) {
1849 # Flag to hide all contents of the archived revisions
1850
1851 $suppress = $request->getCheck( 'wpSuppress' ) && MediaWikiServices::getInstance()
1852 ->getPermissionManager()
1853 ->userHasRight( $user, 'suppressrevision' );
1854
1855 $this->doDelete( $reason, $suppress );
1856
1857 WatchAction::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1858
1859 return;
1860 }
1861
1862 // Generate deletion reason
1863 $hasHistory = false;
1864 if ( !$reason ) {
1865 try {
1866 $reason = $this->generateReason( $hasHistory );
1867 } catch ( Exception $e ) {
1868 # if a page is horribly broken, we still want to be able to
1869 # delete it. So be lenient about errors here.
1870 wfDebug( "Error while building auto delete summary: $e" );
1871 $reason = '';
1872 }
1873 }
1874
1875 // If the page has a history, insert a warning
1876 if ( $hasHistory ) {
1877 $title = $this->getTitle();
1878
1879 // The following can use the real revision count as this is only being shown for users
1880 // that can delete this page.
1881 // This, as a side-effect, also makes sure that the following query isn't being run for
1882 // pages with a larger history, unless the user has the 'bigdelete' right
1883 // (and is about to delete this page).
1884 $dbr = wfGetDB( DB_REPLICA );
1885 $revisions = $edits = (int)$dbr->selectField(
1886 'revision',
1887 'COUNT(rev_page)',
1888 [ 'rev_page' => $title->getArticleID() ],
1889 __METHOD__
1890 );
1891
1892 // @todo i18n issue/patchwork message
1893 $context->getOutput()->addHTML(
1894 '<strong class="mw-delete-warning-revisions">' .
1895 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1896 $context->msg( 'word-separator' )->escaped() . Linker::linkKnown( $title,
1897 $context->msg( 'history' )->escaped(),
1898 [],
1899 [ 'action' => 'history' ] ) .
1900 '</strong>'
1901 );
1902
1903 if ( $title->isBigDeletion() ) {
1904 global $wgDeleteRevisionsLimit;
1905 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1906 [
1907 'delete-warning-toobig',
1908 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1909 ]
1910 );
1911 }
1912 }
1913
1914 $this->confirmDelete( $reason );
1915 }
1916
1917 /**
1918 * Output deletion confirmation dialog
1919 * @todo Move to another file?
1920 * @param string $reason Prefilled reason
1921 */
1922 public function confirmDelete( $reason ) {
1923 wfDebug( "Article::confirmDelete\n" );
1924
1925 $title = $this->getTitle();
1926 $ctx = $this->getContext();
1927 $outputPage = $ctx->getOutput();
1928 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1929 $outputPage->addBacklinkSubtitle( $title );
1930 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1931 $outputPage->addModules( 'mediawiki.action.delete' );
1932
1933 $backlinkCache = $title->getBacklinkCache();
1934 if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
1935 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1936 'deleting-backlinks-warning' );
1937 }
1938
1939 $subpageQueryLimit = 51;
1940 $subpages = $title->getSubpages( $subpageQueryLimit );
1941 $subpageCount = count( $subpages );
1942 if ( $subpageCount > 0 ) {
1943 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1944 [ 'deleting-subpages-warning', Message::numParam( $subpageCount ) ] );
1945 }
1946 $outputPage->addWikiMsg( 'confirmdeletetext' );
1947
1948 Hooks::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
1949
1950 $user = $this->getContext()->getUser();
1951 $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $title );
1952
1953 $outputPage->enableOOUI();
1954
1955 $fields = [];
1956
1957 $options = Xml::listDropDownOptions(
1958 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
1959 [ 'other' => $ctx->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
1960 );
1961 $options = Xml::listDropDownOptionsOoui( $options );
1962
1963 $fields[] = new OOUI\FieldLayout(
1964 new OOUI\DropdownInputWidget( [
1965 'name' => 'wpDeleteReasonList',
1966 'inputId' => 'wpDeleteReasonList',
1967 'tabIndex' => 1,
1968 'infusable' => true,
1969 'value' => '',
1970 'options' => $options
1971 ] ),
1972 [
1973 'label' => $ctx->msg( 'deletecomment' )->text(),
1974 'align' => 'top',
1975 ]
1976 );
1977
1978 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
1979 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
1980 // Unicode codepoints.
1981 $fields[] = new OOUI\FieldLayout(
1982 new OOUI\TextInputWidget( [
1983 'name' => 'wpReason',
1984 'inputId' => 'wpReason',
1985 'tabIndex' => 2,
1986 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
1987 'infusable' => true,
1988 'value' => $reason,
1989 'autofocus' => true,
1990 ] ),
1991 [
1992 'label' => $ctx->msg( 'deleteotherreason' )->text(),
1993 'align' => 'top',
1994 ]
1995 );
1996
1997 if ( $user->isLoggedIn() ) {
1998 $fields[] = new OOUI\FieldLayout(
1999 new OOUI\CheckboxInputWidget( [
2000 'name' => 'wpWatch',
2001 'inputId' => 'wpWatch',
2002 'tabIndex' => 3,
2003 'selected' => $checkWatch,
2004 ] ),
2005 [
2006 'label' => $ctx->msg( 'watchthis' )->text(),
2007 'align' => 'inline',
2008 'infusable' => true,
2009 ]
2010 );
2011 }
2012 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2013 if ( $permissionManager->userHasRight( $user, 'suppressrevision' ) ) {
2014 $fields[] = new OOUI\FieldLayout(
2015 new OOUI\CheckboxInputWidget( [
2016 'name' => 'wpSuppress',
2017 'inputId' => 'wpSuppress',
2018 'tabIndex' => 4,
2019 ] ),
2020 [
2021 'label' => $ctx->msg( 'revdelete-suppress' )->text(),
2022 'align' => 'inline',
2023 'infusable' => true,
2024 ]
2025 );
2026 }
2027
2028 $fields[] = new OOUI\FieldLayout(
2029 new OOUI\ButtonInputWidget( [
2030 'name' => 'wpConfirmB',
2031 'inputId' => 'wpConfirmB',
2032 'tabIndex' => 5,
2033 'value' => $ctx->msg( 'deletepage' )->text(),
2034 'label' => $ctx->msg( 'deletepage' )->text(),
2035 'flags' => [ 'primary', 'destructive' ],
2036 'type' => 'submit',
2037 ] ),
2038 [
2039 'align' => 'top',
2040 ]
2041 );
2042
2043 $fieldset = new OOUI\FieldsetLayout( [
2044 'label' => $ctx->msg( 'delete-legend' )->text(),
2045 'id' => 'mw-delete-table',
2046 'items' => $fields,
2047 ] );
2048
2049 $form = new OOUI\FormLayout( [
2050 'method' => 'post',
2051 'action' => $title->getLocalURL( 'action=delete' ),
2052 'id' => 'deleteconfirm',
2053 ] );
2054 $form->appendContent(
2055 $fieldset,
2056 new OOUI\HtmlSnippet(
2057 Html::hidden( 'wpEditToken', $user->getEditToken( [ 'delete', $title->getPrefixedText() ] ) )
2058 )
2059 );
2060
2061 $outputPage->addHTML(
2062 new OOUI\PanelLayout( [
2063 'classes' => [ 'deletepage-wrapper' ],
2064 'expanded' => false,
2065 'padded' => true,
2066 'framed' => true,
2067 'content' => $form,
2068 ] )
2069 );
2070
2071 if ( $permissionManager->userHasRight( $user, 'editinterface' ) ) {
2072 $link = Linker::linkKnown(
2073 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
2074 wfMessage( 'delete-edit-reasonlist' )->escaped(),
2075 [],
2076 [ 'action' => 'edit' ]
2077 );
2078 $outputPage->addHTML( '<p class="mw-delete-editreasons">' . $link . '</p>' );
2079 }
2080
2081 $deleteLogPage = new LogPage( 'delete' );
2082 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2083 LogEventsList::showLogExtract( $outputPage, 'delete', $title );
2084 }
2085
2086 /**
2087 * Perform a deletion and output success or failure messages
2088 * @param string $reason
2089 * @param bool $suppress
2090 * @param bool $immediate false allows deleting over time via the job queue
2091 * @throws FatalError
2092 * @throws MWException
2093 */
2094 public function doDelete( $reason, $suppress = false, $immediate = false ) {
2095 $error = '';
2096 $context = $this->getContext();
2097 $outputPage = $context->getOutput();
2098 $user = $context->getUser();
2099 $status = $this->mPage->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user,
2100 [], 'delete', $immediate );
2101
2102 if ( $status->isOK() ) {
2103 $deleted = $this->getTitle()->getPrefixedText();
2104
2105 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
2106 $outputPage->setRobotPolicy( 'noindex,nofollow' );
2107
2108 if ( $status->isGood() ) {
2109 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
2110 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
2111 Hooks::run( 'ArticleDeleteAfterSuccess', [ $this->getTitle(), $outputPage ] );
2112 } else {
2113 $outputPage->addWikiMsg( 'delete-scheduled', wfEscapeWikiText( $deleted ) );
2114 }
2115
2116 $outputPage->returnToMain( false );
2117 } else {
2118 $outputPage->setPageTitle(
2119 wfMessage( 'cannotdelete-title',
2120 $this->getTitle()->getPrefixedText() )
2121 );
2122
2123 if ( $error == '' ) {
2124 $outputPage->wrapWikiTextAsInterface(
2125 'error mw-error-cannotdelete',
2126 $status->getWikiText( false, false, $context->getLanguage() )
2127 );
2128 $deleteLogPage = new LogPage( 'delete' );
2129 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
2130
2131 LogEventsList::showLogExtract(
2132 $outputPage,
2133 'delete',
2134 $this->getTitle()
2135 );
2136 } else {
2137 $outputPage->addHTML( $error );
2138 }
2139 }
2140 }
2141
2142 /* Caching functions */
2143
2144 /**
2145 * checkLastModified returns true if it has taken care of all
2146 * output to the client that is necessary for this request.
2147 * (that is, it has sent a cached version of the page)
2148 *
2149 * @return bool True if cached version send, false otherwise
2150 */
2151 protected function tryFileCache() {
2152 static $called = false;
2153
2154 if ( $called ) {
2155 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2156 return false;
2157 }
2158
2159 $called = true;
2160 if ( $this->isFileCacheable() ) {
2161 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
2162 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
2163 wfDebug( "Article::tryFileCache(): about to load file\n" );
2164 $cache->loadFromFileCache( $this->getContext() );
2165 return true;
2166 } else {
2167 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2168 ob_start( [ &$cache, 'saveToFileCache' ] );
2169 }
2170 } else {
2171 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2172 }
2173
2174 return false;
2175 }
2176
2177 /**
2178 * Check if the page can be cached
2179 * @param int $mode One of the HTMLFileCache::MODE_* constants (since 1.28)
2180 * @return bool
2181 */
2182 public function isFileCacheable( $mode = HTMLFileCache::MODE_NORMAL ) {
2183 $cacheable = false;
2184
2185 if ( HTMLFileCache::useFileCache( $this->getContext(), $mode ) ) {
2186 $cacheable = $this->mPage->getId()
2187 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
2188 // Extension may have reason to disable file caching on some pages.
2189 if ( $cacheable ) {
2190 // Avoid PHP 7.1 warning of passing $this by reference
2191 $articlePage = $this;
2192 $cacheable = Hooks::run( 'IsFileCacheable', [ &$articlePage ] );
2193 }
2194 }
2195
2196 return $cacheable;
2197 }
2198
2199 /** #@- */
2200
2201 /**
2202 * Lightweight method to get the parser output for a page, checking the parser cache
2203 * and so on. Doesn't consider most of the stuff that Article::view() is forced to
2204 * consider, so it's not appropriate to use there.
2205 *
2206 * @since 1.16 (r52326) for LiquidThreads
2207 *
2208 * @param int|null $oldid Revision ID or null
2209 * @param User|null $user The relevant user
2210 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
2211 */
2212 public function getParserOutput( $oldid = null, User $user = null ) {
2213 // XXX: bypasses mParserOptions and thus setParserOptions()
2214
2215 if ( $user === null ) {
2216 $parserOptions = $this->getParserOptions();
2217 } else {
2218 $parserOptions = $this->mPage->makeParserOptions( $user );
2219 }
2220
2221 return $this->mPage->getParserOutput( $parserOptions, $oldid );
2222 }
2223
2224 /**
2225 * Override the ParserOptions used to render the primary article wikitext.
2226 *
2227 * @param ParserOptions $options
2228 * @throws MWException If the parser options where already initialized.
2229 */
2230 public function setParserOptions( ParserOptions $options ) {
2231 if ( $this->mParserOptions ) {
2232 throw new MWException( "can't change parser options after they have already been set" );
2233 }
2234
2235 // clone, so if $options is modified later, it doesn't confuse the parser cache.
2236 $this->mParserOptions = clone $options;
2237 }
2238
2239 /**
2240 * Get parser options suitable for rendering the primary article wikitext
2241 * @return ParserOptions
2242 */
2243 public function getParserOptions() {
2244 if ( !$this->mParserOptions ) {
2245 $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
2246 }
2247 // Clone to allow modifications of the return value without affecting cache
2248 return clone $this->mParserOptions;
2249 }
2250
2251 /**
2252 * Sets the context this Article is executed in
2253 *
2254 * @param IContextSource $context
2255 * @since 1.18
2256 */
2257 public function setContext( $context ) {
2258 $this->mContext = $context;
2259 }
2260
2261 /**
2262 * Gets the context this Article is executed in
2263 *
2264 * @return IContextSource
2265 * @since 1.18
2266 */
2267 public function getContext() {
2268 if ( $this->mContext instanceof IContextSource ) {
2269 return $this->mContext;
2270 } else {
2271 wfDebug( __METHOD__ . " called and \$mContext is null. " .
2272 "Return RequestContext::getMain(); for sanity\n" );
2273 return RequestContext::getMain();
2274 }
2275 }
2276
2277 /**
2278 * Use PHP's magic __get handler to handle accessing of
2279 * raw WikiPage fields for backwards compatibility.
2280 *
2281 * @param string $fname Field name
2282 * @return mixed
2283 */
2284 public function __get( $fname ) {
2285 if ( property_exists( $this->mPage, $fname ) ) {
2286 # wfWarn( "Access to raw $fname field " . __CLASS__ );
2287 return $this->mPage->$fname;
2288 }
2289 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
2290 }
2291
2292 /**
2293 * Use PHP's magic __set handler to handle setting of
2294 * raw WikiPage fields for backwards compatibility.
2295 *
2296 * @param string $fname Field name
2297 * @param mixed $fvalue New value
2298 */
2299 public function __set( $fname, $fvalue ) {
2300 if ( property_exists( $this->mPage, $fname ) ) {
2301 # wfWarn( "Access to raw $fname field of " . __CLASS__ );
2302 $this->mPage->$fname = $fvalue;
2303 // Note: extensions may want to toss on new fields
2304 } elseif ( !in_array( $fname, [ 'mContext', 'mPage' ] ) ) {
2305 $this->mPage->$fname = $fvalue;
2306 } else {
2307 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
2308 }
2309 }
2310
2311 /**
2312 * Call to WikiPage function for backwards compatibility.
2313 * @see WikiPage::checkFlags
2314 */
2315 public function checkFlags( $flags ) {
2316 return $this->mPage->checkFlags( $flags );
2317 }
2318
2319 /**
2320 * Call to WikiPage function for backwards compatibility.
2321 * @see WikiPage::checkTouched
2322 */
2323 public function checkTouched() {
2324 return $this->mPage->checkTouched();
2325 }
2326
2327 /**
2328 * Call to WikiPage function for backwards compatibility.
2329 * @see WikiPage::clearPreparedEdit
2330 */
2331 public function clearPreparedEdit() {
2332 $this->mPage->clearPreparedEdit();
2333 }
2334
2335 /**
2336 * Call to WikiPage function for backwards compatibility.
2337 * @see WikiPage::doDeleteArticleReal
2338 */
2339 public function doDeleteArticleReal(
2340 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null,
2341 $tags = [], $immediate = false
2342 ) {
2343 return $this->mPage->doDeleteArticleReal(
2344 $reason, $suppress, $u1, $u2, $error, $user, $tags, 'delete', $immediate
2345 );
2346 }
2347
2348 /**
2349 * Call to WikiPage function for backwards compatibility.
2350 * @see WikiPage::doDeleteUpdates
2351 */
2352 public function doDeleteUpdates(
2353 $id,
2354 Content $content = null,
2355 $revision = null,
2356 User $user = null
2357 ) {
2358 $this->mPage->doDeleteUpdates( $id, $content, $revision, $user );
2359 }
2360
2361 /**
2362 * Call to WikiPage function for backwards compatibility.
2363 * @deprecated since 1.29. Use WikiPage::doEditContent() directly instead
2364 * @see WikiPage::doEditContent
2365 */
2366 public function doEditContent( Content $content, $summary, $flags = 0, $originalRevId = false,
2367 User $user = null, $serialFormat = null
2368 ) {
2369 wfDeprecated( __METHOD__, '1.29' );
2370 return $this->mPage->doEditContent( $content, $summary, $flags, $originalRevId,
2371 $user, $serialFormat
2372 );
2373 }
2374
2375 /**
2376 * Call to WikiPage function for backwards compatibility.
2377 * @see WikiPage::doEditUpdates
2378 */
2379 public function doEditUpdates( Revision $revision, User $user, array $options = [] ) {
2380 return $this->mPage->doEditUpdates( $revision, $user, $options );
2381 }
2382
2383 /**
2384 * Call to WikiPage function for backwards compatibility.
2385 * @see WikiPage::doPurge
2386 * @note In 1.28 (and only 1.28), this took a $flags parameter that
2387 * controlled how much purging was done.
2388 */
2389 public function doPurge() {
2390 return $this->mPage->doPurge();
2391 }
2392
2393 /**
2394 * Call to WikiPage function for backwards compatibility.
2395 * @see WikiPage::doViewUpdates
2396 */
2397 public function doViewUpdates( User $user, $oldid = 0 ) {
2398 $this->mPage->doViewUpdates( $user, $oldid );
2399 }
2400
2401 /**
2402 * Call to WikiPage function for backwards compatibility.
2403 * @see WikiPage::exists
2404 */
2405 public function exists() {
2406 return $this->mPage->exists();
2407 }
2408
2409 /**
2410 * Call to WikiPage function for backwards compatibility.
2411 * @see WikiPage::followRedirect
2412 */
2413 public function followRedirect() {
2414 return $this->mPage->followRedirect();
2415 }
2416
2417 /**
2418 * Call to WikiPage function for backwards compatibility.
2419 * @see ContentHandler::getActionOverrides
2420 */
2421 public function getActionOverrides() {
2422 return $this->mPage->getActionOverrides();
2423 }
2424
2425 /**
2426 * Call to WikiPage function for backwards compatibility.
2427 * @see WikiPage::getAutoDeleteReason
2428 */
2429 public function getAutoDeleteReason( &$hasHistory ) {
2430 return $this->mPage->getAutoDeleteReason( $hasHistory );
2431 }
2432
2433 /**
2434 * Call to WikiPage function for backwards compatibility.
2435 * @see WikiPage::getCategories
2436 */
2437 public function getCategories() {
2438 return $this->mPage->getCategories();
2439 }
2440
2441 /**
2442 * Call to WikiPage function for backwards compatibility.
2443 * @see WikiPage::getComment
2444 */
2445 public function getComment( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
2446 return $this->mPage->getComment( $audience, $user );
2447 }
2448
2449 /**
2450 * Call to WikiPage function for backwards compatibility.
2451 * @see WikiPage::getContentHandler
2452 */
2453 public function getContentHandler() {
2454 return $this->mPage->getContentHandler();
2455 }
2456
2457 /**
2458 * Call to WikiPage function for backwards compatibility.
2459 * @see WikiPage::getContentModel
2460 */
2461 public function getContentModel() {
2462 return $this->mPage->getContentModel();
2463 }
2464
2465 /**
2466 * Call to WikiPage function for backwards compatibility.
2467 * @see WikiPage::getContributors
2468 */
2469 public function getContributors() {
2470 return $this->mPage->getContributors();
2471 }
2472
2473 /**
2474 * Call to WikiPage function for backwards compatibility.
2475 * @see WikiPage::getCreator
2476 */
2477 public function getCreator( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
2478 return $this->mPage->getCreator( $audience, $user );
2479 }
2480
2481 /**
2482 * Call to WikiPage function for backwards compatibility.
2483 * @see WikiPage::getDeletionUpdates
2484 */
2485 public function getDeletionUpdates( Content $content = null ) {
2486 return $this->mPage->getDeletionUpdates( $content );
2487 }
2488
2489 /**
2490 * Call to WikiPage function for backwards compatibility.
2491 * @see WikiPage::getHiddenCategories
2492 */
2493 public function getHiddenCategories() {
2494 return $this->mPage->getHiddenCategories();
2495 }
2496
2497 /**
2498 * Call to WikiPage function for backwards compatibility.
2499 * @see WikiPage::getId
2500 */
2501 public function getId() {
2502 return $this->mPage->getId();
2503 }
2504
2505 /**
2506 * Call to WikiPage function for backwards compatibility.
2507 * @see WikiPage::getLatest
2508 */
2509 public function getLatest() {
2510 return $this->mPage->getLatest();
2511 }
2512
2513 /**
2514 * Call to WikiPage function for backwards compatibility.
2515 * @see WikiPage::getLinksTimestamp
2516 */
2517 public function getLinksTimestamp() {
2518 return $this->mPage->getLinksTimestamp();
2519 }
2520
2521 /**
2522 * Call to WikiPage function for backwards compatibility.
2523 * @see WikiPage::getMinorEdit
2524 */
2525 public function getMinorEdit() {
2526 return $this->mPage->getMinorEdit();
2527 }
2528
2529 /**
2530 * Call to WikiPage function for backwards compatibility.
2531 * @see WikiPage::getOldestRevision
2532 */
2533 public function getOldestRevision() {
2534 return $this->mPage->getOldestRevision();
2535 }
2536
2537 /**
2538 * Call to WikiPage function for backwards compatibility.
2539 * @see WikiPage::getRedirectTarget
2540 */
2541 public function getRedirectTarget() {
2542 return $this->mPage->getRedirectTarget();
2543 }
2544
2545 /**
2546 * Call to WikiPage function for backwards compatibility.
2547 * @see WikiPage::getRedirectURL
2548 */
2549 public function getRedirectURL( $rt ) {
2550 return $this->mPage->getRedirectURL( $rt );
2551 }
2552
2553 /**
2554 * Call to WikiPage function for backwards compatibility.
2555 * @see WikiPage::getRevision
2556 */
2557 public function getRevision() {
2558 return $this->mPage->getRevision();
2559 }
2560
2561 /**
2562 * Call to WikiPage function for backwards compatibility.
2563 * @see WikiPage::getTimestamp
2564 */
2565 public function getTimestamp() {
2566 return $this->mPage->getTimestamp();
2567 }
2568
2569 /**
2570 * Call to WikiPage function for backwards compatibility.
2571 * @see WikiPage::getTouched
2572 */
2573 public function getTouched() {
2574 return $this->mPage->getTouched();
2575 }
2576
2577 /**
2578 * Call to WikiPage function for backwards compatibility.
2579 * @see WikiPage::getUndoContent
2580 */
2581 public function getUndoContent( Revision $undo, Revision $undoafter = null ) {
2582 return $this->mPage->getUndoContent( $undo, $undoafter );
2583 }
2584
2585 /**
2586 * Call to WikiPage function for backwards compatibility.
2587 * @see WikiPage::getUser
2588 */
2589 public function getUser( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
2590 return $this->mPage->getUser( $audience, $user );
2591 }
2592
2593 /**
2594 * Call to WikiPage function for backwards compatibility.
2595 * @see WikiPage::getUserText
2596 */
2597 public function getUserText( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
2598 return $this->mPage->getUserText( $audience, $user );
2599 }
2600
2601 /**
2602 * Call to WikiPage function for backwards compatibility.
2603 * @see WikiPage::hasViewableContent
2604 */
2605 public function hasViewableContent() {
2606 return $this->mPage->hasViewableContent();
2607 }
2608
2609 /**
2610 * Call to WikiPage function for backwards compatibility.
2611 * @see WikiPage::insertOn
2612 */
2613 public function insertOn( $dbw, $pageId = null ) {
2614 return $this->mPage->insertOn( $dbw, $pageId );
2615 }
2616
2617 /**
2618 * Call to WikiPage function for backwards compatibility.
2619 * @see WikiPage::insertProtectNullRevision
2620 */
2621 public function insertProtectNullRevision( $revCommentMsg, array $limit,
2622 array $expiry, $cascade, $reason, $user = null
2623 ) {
2624 return $this->mPage->insertProtectNullRevision( $revCommentMsg, $limit,
2625 $expiry, $cascade, $reason, $user
2626 );
2627 }
2628
2629 /**
2630 * Call to WikiPage function for backwards compatibility.
2631 * @see WikiPage::insertRedirect
2632 */
2633 public function insertRedirect() {
2634 return $this->mPage->insertRedirect();
2635 }
2636
2637 /**
2638 * Call to WikiPage function for backwards compatibility.
2639 * @see WikiPage::insertRedirectEntry
2640 */
2641 public function insertRedirectEntry( Title $rt, $oldLatest = null ) {
2642 return $this->mPage->insertRedirectEntry( $rt, $oldLatest );
2643 }
2644
2645 /**
2646 * Call to WikiPage function for backwards compatibility.
2647 * @see WikiPage::isCountable
2648 */
2649 public function isCountable( $editInfo = false ) {
2650 return $this->mPage->isCountable( $editInfo );
2651 }
2652
2653 /**
2654 * Call to WikiPage function for backwards compatibility.
2655 * @see WikiPage::isRedirect
2656 */
2657 public function isRedirect() {
2658 return $this->mPage->isRedirect();
2659 }
2660
2661 /**
2662 * Call to WikiPage function for backwards compatibility.
2663 * @see WikiPage::loadFromRow
2664 */
2665 public function loadFromRow( $data, $from ) {
2666 return $this->mPage->loadFromRow( $data, $from );
2667 }
2668
2669 /**
2670 * Call to WikiPage function for backwards compatibility.
2671 * @see WikiPage::loadPageData
2672 */
2673 public function loadPageData( $from = 'fromdb' ) {
2674 $this->mPage->loadPageData( $from );
2675 }
2676
2677 /**
2678 * Call to WikiPage function for backwards compatibility.
2679 * @see WikiPage::lockAndGetLatest
2680 */
2681 public function lockAndGetLatest() {
2682 return $this->mPage->lockAndGetLatest();
2683 }
2684
2685 /**
2686 * Call to WikiPage function for backwards compatibility.
2687 * @see WikiPage::makeParserOptions
2688 */
2689 public function makeParserOptions( $context ) {
2690 return $this->mPage->makeParserOptions( $context );
2691 }
2692
2693 /**
2694 * Call to WikiPage function for backwards compatibility.
2695 * @see WikiPage::pageDataFromId
2696 */
2697 public function pageDataFromId( $dbr, $id, $options = [] ) {
2698 return $this->mPage->pageDataFromId( $dbr, $id, $options );
2699 }
2700
2701 /**
2702 * Call to WikiPage function for backwards compatibility.
2703 * @see WikiPage::pageDataFromTitle
2704 */
2705 public function pageDataFromTitle( $dbr, $title, $options = [] ) {
2706 return $this->mPage->pageDataFromTitle( $dbr, $title, $options );
2707 }
2708
2709 /**
2710 * Call to WikiPage function for backwards compatibility.
2711 * @see WikiPage::prepareContentForEdit
2712 */
2713 public function prepareContentForEdit(
2714 Content $content, $revision = null, User $user = null,
2715 $serialFormat = null, $useCache = true
2716 ) {
2717 return $this->mPage->prepareContentForEdit(
2718 $content, $revision, $user,
2719 $serialFormat, $useCache
2720 );
2721 }
2722
2723 /**
2724 * Call to WikiPage function for backwards compatibility.
2725 * @see WikiPage::protectDescription
2726 */
2727 public function protectDescription( array $limit, array $expiry ) {
2728 return $this->mPage->protectDescription( $limit, $expiry );
2729 }
2730
2731 /**
2732 * Call to WikiPage function for backwards compatibility.
2733 * @see WikiPage::protectDescriptionLog
2734 */
2735 public function protectDescriptionLog( array $limit, array $expiry ) {
2736 return $this->mPage->protectDescriptionLog( $limit, $expiry );
2737 }
2738
2739 /**
2740 * Call to WikiPage function for backwards compatibility.
2741 * @see WikiPage::replaceSectionAtRev
2742 */
2743 public function replaceSectionAtRev( $sectionId, Content $sectionContent,
2744 $sectionTitle = '', $baseRevId = null
2745 ) {
2746 return $this->mPage->replaceSectionAtRev( $sectionId, $sectionContent,
2747 $sectionTitle, $baseRevId
2748 );
2749 }
2750
2751 /**
2752 * Call to WikiPage function for backwards compatibility.
2753 * @see WikiPage::replaceSectionContent
2754 */
2755 public function replaceSectionContent(
2756 $sectionId, Content $sectionContent, $sectionTitle = '', $edittime = null
2757 ) {
2758 return $this->mPage->replaceSectionContent(
2759 $sectionId, $sectionContent, $sectionTitle, $edittime
2760 );
2761 }
2762
2763 /**
2764 * Call to WikiPage function for backwards compatibility.
2765 * @see WikiPage::setTimestamp
2766 */
2767 public function setTimestamp( $ts ) {
2768 $this->mPage->setTimestamp( $ts );
2769 }
2770
2771 /**
2772 * Call to WikiPage function for backwards compatibility.
2773 * @see WikiPage::shouldCheckParserCache
2774 */
2775 public function shouldCheckParserCache( ParserOptions $parserOptions, $oldId ) {
2776 return $this->mPage->shouldCheckParserCache( $parserOptions, $oldId );
2777 }
2778
2779 /**
2780 * Call to WikiPage function for backwards compatibility.
2781 * @see WikiPage::supportsSections
2782 */
2783 public function supportsSections() {
2784 return $this->mPage->supportsSections();
2785 }
2786
2787 /**
2788 * Call to WikiPage function for backwards compatibility.
2789 * @see WikiPage::triggerOpportunisticLinksUpdate
2790 */
2791 public function triggerOpportunisticLinksUpdate( ParserOutput $parserOutput ) {
2792 return $this->mPage->triggerOpportunisticLinksUpdate( $parserOutput );
2793 }
2794
2795 /**
2796 * Call to WikiPage function for backwards compatibility.
2797 * @see WikiPage::updateCategoryCounts
2798 */
2799 public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
2800 return $this->mPage->updateCategoryCounts( $added, $deleted, $id );
2801 }
2802
2803 /**
2804 * Call to WikiPage function for backwards compatibility.
2805 * @see WikiPage::updateIfNewerOn
2806 */
2807 public function updateIfNewerOn( $dbw, $revision ) {
2808 return $this->mPage->updateIfNewerOn( $dbw, $revision );
2809 }
2810
2811 /**
2812 * Call to WikiPage function for backwards compatibility.
2813 * @see WikiPage::updateRedirectOn
2814 */
2815 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
2816 return $this->mPage->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect );
2817 }
2818
2819 /**
2820 * Call to WikiPage function for backwards compatibility.
2821 * @see WikiPage::updateRevisionOn
2822 */
2823 public function updateRevisionOn( $dbw, $revision, $lastRevision = null,
2824 $lastRevIsRedirect = null
2825 ) {
2826 return $this->mPage->updateRevisionOn( $dbw, $revision, $lastRevision,
2827 $lastRevIsRedirect
2828 );
2829 }
2830
2831 /**
2832 * @param array $limit
2833 * @param array $expiry
2834 * @param bool &$cascade
2835 * @param string $reason
2836 * @param User $user
2837 * @return Status
2838 */
2839 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2840 $reason, User $user
2841 ) {
2842 return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2843 }
2844
2845 /**
2846 * @param array $limit
2847 * @param string $reason
2848 * @param int &$cascade
2849 * @param array $expiry
2850 * @return bool
2851 */
2852 public function updateRestrictions( $limit = [], $reason = '',
2853 &$cascade = 0, $expiry = []
2854 ) {
2855 return $this->mPage->doUpdateRestrictions(
2856 $limit,
2857 $expiry,
2858 $cascade,
2859 $reason,
2860 $this->getContext()->getUser()
2861 );
2862 }
2863
2864 /**
2865 * @param string $reason
2866 * @param bool $suppress
2867 * @param int|null $u1 Unused
2868 * @param bool|null $u2 Unused
2869 * @param string &$error
2870 * @param bool $immediate false allows deleting over time via the job queue
2871 * @return bool
2872 * @throws FatalError
2873 * @throws MWException
2874 */
2875 public function doDeleteArticle(
2876 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', $immediate = false
2877 ) {
2878 return $this->mPage->doDeleteArticle( $reason, $suppress, $u1, $u2, $error,
2879 null, $immediate );
2880 }
2881
2882 /**
2883 * @param string $fromP
2884 * @param string $summary
2885 * @param string $token
2886 * @param bool $bot
2887 * @param array &$resultDetails
2888 * @param User|null $user
2889 * @return array
2890 */
2891 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user = null ) {
2892 if ( !$user ) {
2893 $user = $this->getContext()->getUser();
2894 }
2895
2896 return $this->mPage->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2897 }
2898
2899 /**
2900 * @param string $fromP
2901 * @param string $summary
2902 * @param bool $bot
2903 * @param array &$resultDetails
2904 * @param User|null $guser
2905 * @return array
2906 */
2907 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser = null ) {
2908 if ( !$guser ) {
2909 $guser = $this->getContext()->getUser();
2910 }
2911
2912 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2913 }
2914
2915 /**
2916 * @param bool &$hasHistory
2917 * @return mixed
2918 */
2919 public function generateReason( &$hasHistory ) {
2920 $title = $this->mPage->getTitle();
2921 $handler = ContentHandler::getForTitle( $title );
2922 return $handler->getAutoDeleteReason( $title, $hasHistory );
2923 }
2924
2925 // ******
2926 }