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