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