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