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