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