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