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