Merge "Add CollationFa"
[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 return $t == null ? null : new static( $t );
103 }
104
105 /**
106 * Create an Article object of the appropriate class for the given page.
107 *
108 * @param Title $title
109 * @param IContextSource $context
110 * @return Article
111 */
112 public static function newFromTitle( $title, IContextSource $context ) {
113 if ( NS_MEDIA == $title->getNamespace() ) {
114 // FIXME: where should this go?
115 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
116 }
117
118 $page = null;
119 Hooks::run( 'ArticleFromTitle', [ &$title, &$page, $context ] );
120 if ( !$page ) {
121 switch ( $title->getNamespace() ) {
122 case NS_FILE:
123 $page = new ImagePage( $title );
124 break;
125 case NS_CATEGORY:
126 $page = new CategoryPage( $title );
127 break;
128 default:
129 $page = new Article( $title );
130 }
131 }
132 $page->setContext( $context );
133
134 return $page;
135 }
136
137 /**
138 * Create an Article object of the appropriate class for the given page.
139 *
140 * @param WikiPage $page
141 * @param IContextSource $context
142 * @return Article
143 */
144 public static function newFromWikiPage( WikiPage $page, IContextSource $context ) {
145 $article = self::newFromTitle( $page->getTitle(), $context );
146 $article->mPage = $page; // override to keep process cached vars
147 return $article;
148 }
149
150 /**
151 * Get the page this view was redirected from
152 * @return Title|null
153 * @since 1.28
154 */
155 public function getRedirectedFrom() {
156 return $this->mRedirectedFrom;
157 }
158
159 /**
160 * Tell the page view functions that this view was redirected
161 * from another page on the wiki.
162 * @param Title $from
163 */
164 public function setRedirectedFrom( Title $from ) {
165 $this->mRedirectedFrom = $from;
166 }
167
168 /**
169 * Get the title object of the article
170 *
171 * @return Title Title object of this page
172 */
173 public function getTitle() {
174 return $this->mPage->getTitle();
175 }
176
177 /**
178 * Get the WikiPage object of this instance
179 *
180 * @since 1.19
181 * @return WikiPage
182 */
183 public function getPage() {
184 return $this->mPage;
185 }
186
187 /**
188 * Clear the object
189 */
190 public function clear() {
191 $this->mContentLoaded = false;
192
193 $this->mRedirectedFrom = null; # Title object if set
194 $this->mRevIdFetched = 0;
195 $this->mRedirectUrl = false;
196
197 $this->mPage->clear();
198 }
199
200 /**
201 * Note that getContent does not follow redirects anymore.
202 * If you need to fetch redirectable content easily, try
203 * the shortcut in WikiPage::getRedirectTarget()
204 *
205 * This function has side effects! Do not use this function if you
206 * only want the real revision text if any.
207 *
208 * @deprecated since 1.21; use WikiPage::getContent() instead
209 *
210 * @return string Return the text of this revision
211 */
212 public function getContent() {
213 wfDeprecated( __METHOD__, '1.21' );
214 $content = $this->getContentObject();
215 return ContentHandler::getContentText( $content );
216 }
217
218 /**
219 * Returns a Content object representing the pages effective display content,
220 * not necessarily the revision's content!
221 *
222 * Note that getContent does not follow redirects anymore.
223 * If you need to fetch redirectable content easily, try
224 * the shortcut in WikiPage::getRedirectTarget()
225 *
226 * This function has side effects! Do not use this function if you
227 * only want the real revision text if any.
228 *
229 * @return Content Return the content of this revision
230 *
231 * @since 1.21
232 */
233 protected function getContentObject() {
234
235 if ( $this->mPage->getId() === 0 ) {
236 # If this is a MediaWiki:x message, then load the messages
237 # and return the message value for x.
238 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
239 $text = $this->getTitle()->getDefaultMessageText();
240 if ( $text === false ) {
241 $text = '';
242 }
243
244 $content = ContentHandler::makeContent( $text, $this->getTitle() );
245 } else {
246 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
247 $content = new MessageContent( $message, null, 'parsemag' );
248 }
249 } else {
250 $this->fetchContentObject();
251 $content = $this->mContentObject;
252 }
253
254 return $content;
255 }
256
257 /**
258 * @return int The oldid of the article that is to be shown, 0 for the current revision
259 */
260 public function getOldID() {
261 if ( is_null( $this->mOldId ) ) {
262 $this->mOldId = $this->getOldIDFromRequest();
263 }
264
265 return $this->mOldId;
266 }
267
268 /**
269 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
270 *
271 * @return int The old id for the request
272 */
273 public function getOldIDFromRequest() {
274 $this->mRedirectUrl = false;
275
276 $request = $this->getContext()->getRequest();
277 $oldid = $request->getIntOrNull( 'oldid' );
278
279 if ( $oldid === null ) {
280 return 0;
281 }
282
283 if ( $oldid !== 0 ) {
284 # Load the given revision and check whether the page is another one.
285 # In that case, update this instance to reflect the change.
286 if ( $oldid === $this->mPage->getLatest() ) {
287 $this->mRevision = $this->mPage->getRevision();
288 } else {
289 $this->mRevision = Revision::newFromId( $oldid );
290 if ( $this->mRevision !== null ) {
291 // Revision title doesn't match the page title given?
292 if ( $this->mPage->getId() != $this->mRevision->getPage() ) {
293 $function = [ get_class( $this->mPage ), 'newFromID' ];
294 $this->mPage = call_user_func( $function, $this->mRevision->getPage() );
295 }
296 }
297 }
298 }
299
300 if ( $request->getVal( 'direction' ) == 'next' ) {
301 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
302 if ( $nextid ) {
303 $oldid = $nextid;
304 $this->mRevision = null;
305 } else {
306 $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
307 }
308 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
309 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
310 if ( $previd ) {
311 $oldid = $previd;
312 $this->mRevision = null;
313 }
314 }
315
316 return $oldid;
317 }
318
319 /**
320 * Get text content object
321 * Does *NOT* follow redirects.
322 * @todo When is this null?
323 *
324 * @note Code that wants to retrieve page content from the database should
325 * use WikiPage::getContent().
326 *
327 * @return Content|null|bool
328 *
329 * @since 1.21
330 */
331 protected function fetchContentObject() {
332 if ( $this->mContentLoaded ) {
333 return $this->mContentObject;
334 }
335
336 $this->mContentLoaded = true;
337 $this->mContent = null;
338
339 $oldid = $this->getOldID();
340
341 # Pre-fill content with error message so that if something
342 # fails we'll have something telling us what we intended.
343 // XXX: this isn't page content but a UI message. horrible.
344 $this->mContentObject = new MessageContent( 'missing-revision', [ $oldid ] );
345
346 if ( $oldid ) {
347 # $this->mRevision might already be fetched by getOldIDFromRequest()
348 if ( !$this->mRevision ) {
349 $this->mRevision = Revision::newFromId( $oldid );
350 if ( !$this->mRevision ) {
351 wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
352 return false;
353 }
354 }
355 } else {
356 $oldid = $this->mPage->getLatest();
357 if ( !$oldid ) {
358 wfDebug( __METHOD__ . " failed to find page data for title " .
359 $this->getTitle()->getPrefixedText() . "\n" );
360 return false;
361 }
362
363 # Update error message with correct oldid
364 $this->mContentObject = new MessageContent( 'missing-revision', [ $oldid ] );
365
366 $this->mRevision = $this->mPage->getRevision();
367
368 if ( !$this->mRevision ) {
369 wfDebug( __METHOD__ . " failed to retrieve current page, rev_id $oldid\n" );
370 return false;
371 }
372 }
373
374 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
375 // We should instead work with the Revision object when we need it...
376 // Loads if user is allowed
377 $content = $this->mRevision->getContent(
378 Revision::FOR_THIS_USER,
379 $this->getContext()->getUser()
380 );
381
382 if ( !$content ) {
383 wfDebug( __METHOD__ . " failed to retrieve content of revision " .
384 $this->mRevision->getId() . "\n" );
385 return false;
386 }
387
388 $this->mContentObject = $content;
389 $this->mRevIdFetched = $this->mRevision->getId();
390
391 ContentHandler::runLegacyHooks(
392 'ArticleAfterFetchContentObject',
393 [ &$this, &$this->mContentObject ],
394 '1.21'
395 );
396
397 return $this->mContentObject;
398 }
399
400 /**
401 * Returns true if the currently-referenced revision is the current edit
402 * to this page (and it exists).
403 * @return bool
404 */
405 public function isCurrent() {
406 # If no oldid, this is the current version.
407 if ( $this->getOldID() == 0 ) {
408 return true;
409 }
410
411 return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
412 }
413
414 /**
415 * Get the fetched Revision object depending on request parameters or null
416 * on failure.
417 *
418 * @since 1.19
419 * @return Revision|null
420 */
421 public function getRevisionFetched() {
422 $this->fetchContentObject();
423
424 return $this->mRevision;
425 }
426
427 /**
428 * Use this to fetch the rev ID used on page views
429 *
430 * @return int Revision ID of last article revision
431 */
432 public function getRevIdFetched() {
433 if ( $this->mRevIdFetched ) {
434 return $this->mRevIdFetched;
435 } else {
436 return $this->mPage->getLatest();
437 }
438 }
439
440 /**
441 * This is the default action of the index.php entry point: just view the
442 * page of the given title.
443 */
444 public function view() {
445 global $wgUseFileCache, $wgDebugToolbar;
446
447 # Get variables from query string
448 # As side effect this will load the revision and update the title
449 # in a revision ID is passed in the request, so this should remain
450 # the first call of this method even if $oldid is used way below.
451 $oldid = $this->getOldID();
452
453 $user = $this->getContext()->getUser();
454 # Another whitelist check in case getOldID() is altering the title
455 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
456 if ( count( $permErrors ) ) {
457 wfDebug( __METHOD__ . ": denied on secondary read check\n" );
458 throw new PermissionsError( 'read', $permErrors );
459 }
460
461 $outputPage = $this->getContext()->getOutput();
462 # getOldID() may as well want us to redirect somewhere else
463 if ( $this->mRedirectUrl ) {
464 $outputPage->redirect( $this->mRedirectUrl );
465 wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
466
467 return;
468 }
469
470 # If we got diff in the query, we want to see a diff page instead of the article.
471 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
472 wfDebug( __METHOD__ . ": showing diff page\n" );
473 $this->showDiffPage();
474
475 return;
476 }
477
478 # Set page title (may be overridden by DISPLAYTITLE)
479 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
480
481 $outputPage->setArticleFlag( true );
482 # Allow frames by default
483 $outputPage->allowClickjacking();
484
485 $parserCache = ParserCache::singleton();
486
487 $parserOptions = $this->getParserOptions();
488 # Render printable version, use printable version cache
489 if ( $outputPage->isPrintable() ) {
490 $parserOptions->setIsPrintable( true );
491 $parserOptions->setEditSection( false );
492 } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user ) ) {
493 $parserOptions->setEditSection( false );
494 }
495
496 # Try client and file cache
497 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
498 # Try to stream the output from file cache
499 if ( $wgUseFileCache && $this->tryFileCache() ) {
500 wfDebug( __METHOD__ . ": done file cache\n" );
501 # tell wgOut that output is taken care of
502 $outputPage->disable();
503 $this->mPage->doViewUpdates( $user, $oldid );
504
505 return;
506 }
507 }
508
509 # Should the parser cache be used?
510 $useParserCache = $this->mPage->shouldCheckParserCache( $parserOptions, $oldid );
511 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
512 if ( $user->getStubThreshold() ) {
513 $this->getContext()->getStats()->increment( 'pcache_miss_stub' );
514 }
515
516 $this->showRedirectedFromHeader();
517 $this->showNamespaceHeader();
518
519 # Iterate through the possible ways of constructing the output text.
520 # Keep going until $outputDone is set, or we run out of things to do.
521 $pass = 0;
522 $outputDone = false;
523 $this->mParserOutput = false;
524
525 while ( !$outputDone && ++$pass ) {
526 switch ( $pass ) {
527 case 1:
528 Hooks::run( 'ArticleViewHeader', [ &$this, &$outputDone, &$useParserCache ] );
529 break;
530 case 2:
531 # Early abort if the page doesn't exist
532 if ( !$this->mPage->exists() ) {
533 wfDebug( __METHOD__ . ": showing missing article\n" );
534 $this->showMissingArticle();
535 $this->mPage->doViewUpdates( $user );
536 return;
537 }
538
539 # Try the parser cache
540 if ( $useParserCache ) {
541 $this->mParserOutput = $parserCache->get( $this->mPage, $parserOptions );
542
543 if ( $this->mParserOutput !== false ) {
544 if ( $oldid ) {
545 wfDebug( __METHOD__ . ": showing parser cache contents for current rev permalink\n" );
546 $this->setOldSubtitle( $oldid );
547 } else {
548 wfDebug( __METHOD__ . ": showing parser cache contents\n" );
549 }
550 $outputPage->addParserOutput( $this->mParserOutput );
551 # Ensure that UI elements requiring revision ID have
552 # the correct version information.
553 $outputPage->setRevisionId( $this->mPage->getLatest() );
554 # Preload timestamp to avoid a DB hit
555 $cachedTimestamp = $this->mParserOutput->getTimestamp();
556 if ( $cachedTimestamp !== null ) {
557 $outputPage->setRevisionTimestamp( $cachedTimestamp );
558 $this->mPage->setTimestamp( $cachedTimestamp );
559 }
560 $outputDone = true;
561 }
562 }
563 break;
564 case 3:
565 # This will set $this->mRevision if needed
566 $this->fetchContentObject();
567
568 # Are we looking at an old revision
569 if ( $oldid && $this->mRevision ) {
570 $this->setOldSubtitle( $oldid );
571
572 if ( !$this->showDeletedRevisionHeader() ) {
573 wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
574 return;
575 }
576 }
577
578 # Ensure that UI elements requiring revision ID have
579 # the correct version information.
580 $outputPage->setRevisionId( $this->getRevIdFetched() );
581 # Preload timestamp to avoid a DB hit
582 $outputPage->setRevisionTimestamp( $this->mPage->getTimestamp() );
583
584 if ( !Hooks::run( 'ArticleContentViewCustom',
585 [ $this->fetchContentObject(), $this->getTitle(), $outputPage ] ) ) {
586
587 # Allow extensions do their own custom view for certain pages
588 $outputDone = true;
589 }
590 break;
591 case 4:
592 # Run the parse, protected by a pool counter
593 wfDebug( __METHOD__ . ": doing uncached parse\n" );
594
595 $content = $this->getContentObject();
596 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
597 $this->getRevIdFetched(), $useParserCache, $content );
598
599 if ( !$poolArticleView->execute() ) {
600 $error = $poolArticleView->getError();
601 if ( $error ) {
602 $outputPage->clearHTML(); // for release() errors
603 $outputPage->enableClientCache( false );
604 $outputPage->setRobotPolicy( 'noindex,nofollow' );
605
606 $errortext = $error->getWikiText( false, 'view-pool-error' );
607 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
608 }
609 # Connection or timeout error
610 return;
611 }
612
613 $this->mParserOutput = $poolArticleView->getParserOutput();
614 $outputPage->addParserOutput( $this->mParserOutput );
615 if ( $content->getRedirectTarget() ) {
616 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
617 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
618 }
619
620 # Don't cache a dirty ParserOutput object
621 if ( $poolArticleView->getIsDirty() ) {
622 $outputPage->setCdnMaxage( 0 );
623 $outputPage->addHTML( "<!-- parser cache is expired, " .
624 "sending anyway due to pool overload-->\n" );
625 }
626
627 $outputDone = true;
628 break;
629 # Should be unreachable, but just in case...
630 default:
631 break 2;
632 }
633 }
634
635 # Get the ParserOutput actually *displayed* here.
636 # Note that $this->mParserOutput is the *current*/oldid version output.
637 $pOutput = ( $outputDone instanceof ParserOutput )
638 ? $outputDone // object fetched by hook
639 : $this->mParserOutput;
640
641 # Adjust title for main page & pages with displaytitle
642 if ( $pOutput ) {
643 $this->adjustDisplayTitle( $pOutput );
644 }
645
646 # For the main page, overwrite the <title> element with the con-
647 # tents of 'pagetitle-view-mainpage' instead of the default (if
648 # that's not empty).
649 # This message always exists because it is in the i18n files
650 if ( $this->getTitle()->isMainPage() ) {
651 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
652 if ( !$msg->isDisabled() ) {
653 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
654 }
655 }
656
657 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
658 # This could use getTouched(), but that could be scary for major template edits.
659 $outputPage->adaptCdnTTL( $this->mPage->getTimestamp(), IExpiringStore::TTL_DAY );
660
661 # Check for any __NOINDEX__ tags on the page using $pOutput
662 $policy = $this->getRobotPolicy( 'view', $pOutput );
663 $outputPage->setIndexPolicy( $policy['index'] );
664 $outputPage->setFollowPolicy( $policy['follow'] );
665
666 $this->showViewFooter();
667 $this->mPage->doViewUpdates( $user, $oldid );
668
669 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
670 }
671
672 /**
673 * Adjust title for pages with displaytitle, -{T|}- or language conversion
674 * @param ParserOutput $pOutput
675 */
676 public function adjustDisplayTitle( ParserOutput $pOutput ) {
677 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
678 $titleText = $pOutput->getTitleText();
679 if ( strval( $titleText ) !== '' ) {
680 $this->getContext()->getOutput()->setPageTitle( $titleText );
681 }
682 }
683
684 /**
685 * Show a diff page according to current request variables. For use within
686 * Article::view() only, other callers should use the DifferenceEngine class.
687 */
688 protected function showDiffPage() {
689 $request = $this->getContext()->getRequest();
690 $user = $this->getContext()->getUser();
691 $diff = $request->getVal( 'diff' );
692 $rcid = $request->getVal( 'rcid' );
693 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
694 $purge = $request->getVal( 'action' ) == 'purge';
695 $unhide = $request->getInt( 'unhide' ) == 1;
696 $oldid = $this->getOldID();
697
698 $rev = $this->getRevisionFetched();
699
700 if ( !$rev ) {
701 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
702 $msg = $this->getContext()->msg( 'difference-missing-revision' )
703 ->params( $oldid )
704 ->numParams( 1 )
705 ->parseAsBlock();
706 $this->getContext()->getOutput()->addHTML( $msg );
707 return;
708 }
709
710 $contentHandler = $rev->getContentHandler();
711 $de = $contentHandler->createDifferenceEngine(
712 $this->getContext(),
713 $oldid,
714 $diff,
715 $rcid,
716 $purge,
717 $unhide
718 );
719
720 // DifferenceEngine directly fetched the revision:
721 $this->mRevIdFetched = $de->mNewid;
722 $de->showDiffPage( $diffOnly );
723
724 // Run view updates for the newer revision being diffed (and shown
725 // below the diff if not $diffOnly).
726 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
727 // New can be false, convert it to 0 - this conveniently means the latest revision
728 $this->mPage->doViewUpdates( $user, (int)$new );
729 }
730
731 /**
732 * Get the robot policy to be used for the current view
733 * @param string $action The action= GET parameter
734 * @param ParserOutput|null $pOutput
735 * @return array The policy that should be set
736 * @todo actions other than 'view'
737 */
738 public function getRobotPolicy( $action, $pOutput = null ) {
739 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
740
741 $ns = $this->getTitle()->getNamespace();
742
743 # Don't index user and user talk pages for blocked users (bug 11443)
744 if ( ( $ns == NS_USER || $ns == NS_USER_TALK ) && !$this->getTitle()->isSubpage() ) {
745 $specificTarget = null;
746 $vagueTarget = null;
747 $titleText = $this->getTitle()->getText();
748 if ( IP::isValid( $titleText ) ) {
749 $vagueTarget = $titleText;
750 } else {
751 $specificTarget = $titleText;
752 }
753 if ( Block::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block ) {
754 return [
755 'index' => 'noindex',
756 'follow' => 'nofollow'
757 ];
758 }
759 }
760
761 if ( $this->mPage->getId() === 0 || $this->getOldID() ) {
762 # Non-articles (special pages etc), and old revisions
763 return [
764 'index' => 'noindex',
765 'follow' => 'nofollow'
766 ];
767 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
768 # Discourage indexing of printable versions, but encourage following
769 return [
770 'index' => 'noindex',
771 'follow' => 'follow'
772 ];
773 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
774 # For ?curid=x urls, disallow indexing
775 return [
776 'index' => 'noindex',
777 'follow' => 'follow'
778 ];
779 }
780
781 # Otherwise, construct the policy based on the various config variables.
782 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
783
784 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
785 # Honour customised robot policies for this namespace
786 $policy = array_merge(
787 $policy,
788 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
789 );
790 }
791 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
792 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
793 # a final sanity check that we have really got the parser output.
794 $policy = array_merge(
795 $policy,
796 [ 'index' => $pOutput->getIndexPolicy() ]
797 );
798 }
799
800 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
801 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
802 $policy = array_merge(
803 $policy,
804 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
805 );
806 }
807
808 return $policy;
809 }
810
811 /**
812 * Converts a String robot policy into an associative array, to allow
813 * merging of several policies using array_merge().
814 * @param array|string $policy Returns empty array on null/false/'', transparent
815 * to already-converted arrays, converts string.
816 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
817 */
818 public static function formatRobotPolicy( $policy ) {
819 if ( is_array( $policy ) ) {
820 return $policy;
821 } elseif ( !$policy ) {
822 return [];
823 }
824
825 $policy = explode( ',', $policy );
826 $policy = array_map( 'trim', $policy );
827
828 $arr = [];
829 foreach ( $policy as $var ) {
830 if ( in_array( $var, [ 'index', 'noindex' ] ) ) {
831 $arr['index'] = $var;
832 } elseif ( in_array( $var, [ 'follow', 'nofollow' ] ) ) {
833 $arr['follow'] = $var;
834 }
835 }
836
837 return $arr;
838 }
839
840 /**
841 * If this request is a redirect view, send "redirected from" subtitle to
842 * the output. Returns true if the header was needed, false if this is not
843 * a redirect view. Handles both local and remote redirects.
844 *
845 * @return bool
846 */
847 public function showRedirectedFromHeader() {
848 global $wgRedirectSources;
849
850 $context = $this->getContext();
851 $outputPage = $context->getOutput();
852 $request = $context->getRequest();
853 $rdfrom = $request->getVal( 'rdfrom' );
854
855 // Construct a URL for the current page view, but with the target title
856 $query = $request->getValues();
857 unset( $query['rdfrom'] );
858 unset( $query['title'] );
859 if ( $this->getTitle()->isRedirect() ) {
860 // Prevent double redirects
861 $query['redirect'] = 'no';
862 }
863 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
864
865 if ( isset( $this->mRedirectedFrom ) ) {
866 // This is an internally redirected page view.
867 // We'll need a backlink to the source page for navigation.
868 if ( Hooks::run( 'ArticleViewRedirect', [ &$this ] ) ) {
869 $redir = Linker::linkKnown(
870 $this->mRedirectedFrom,
871 null,
872 [],
873 [ 'redirect' => 'no' ]
874 );
875
876 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
877 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
878 . "</span>" );
879
880 // Add the script to update the displayed URL and
881 // set the fragment if one was specified in the redirect
882 $outputPage->addJsConfigVars( [
883 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
884 ] );
885 $outputPage->addModules( 'mediawiki.action.view.redirect' );
886
887 // Add a <link rel="canonical"> tag
888 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
889
890 // Tell the output object that the user arrived at this article through a redirect
891 $outputPage->setRedirectedFrom( $this->mRedirectedFrom );
892
893 return true;
894 }
895 } elseif ( $rdfrom ) {
896 // This is an externally redirected view, from some other wiki.
897 // If it was reported from a trusted site, supply a backlink.
898 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
899 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
900 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
901 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
902 . "</span>" );
903
904 // Add the script to update the displayed URL
905 $outputPage->addJsConfigVars( [
906 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
907 ] );
908 $outputPage->addModules( 'mediawiki.action.view.redirect' );
909
910 return true;
911 }
912 }
913
914 return false;
915 }
916
917 /**
918 * Show a header specific to the namespace currently being viewed, like
919 * [[MediaWiki:Talkpagetext]]. For Article::view().
920 */
921 public function showNamespaceHeader() {
922 if ( $this->getTitle()->isTalkPage() ) {
923 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
924 $this->getContext()->getOutput()->wrapWikiMsg(
925 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
926 [ 'talkpageheader' ]
927 );
928 }
929 }
930 }
931
932 /**
933 * Show the footer section of an ordinary page view
934 */
935 public function showViewFooter() {
936 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
937 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
938 && IP::isValid( $this->getTitle()->getText() )
939 ) {
940 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
941 }
942
943 // Show a footer allowing the user to patrol the shown revision or page if possible
944 $patrolFooterShown = $this->showPatrolFooter();
945
946 Hooks::run( 'ArticleViewFooter', [ $this, $patrolFooterShown ] );
947 }
948
949 /**
950 * If patrol is possible, output a patrol UI box. This is called from the
951 * footer section of ordinary page views. If patrol is not possible or not
952 * desired, does nothing.
953 * Side effect: When the patrol link is build, this method will call
954 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
955 *
956 * @return bool
957 */
958 public function showPatrolFooter() {
959 global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol, $wgEnableAPI, $wgEnableWriteAPI;
960
961 $outputPage = $this->getContext()->getOutput();
962 $user = $this->getContext()->getUser();
963 $title = $this->getTitle();
964 $rc = false;
965
966 if ( !$title->quickUserCan( 'patrol', $user )
967 || !( $wgUseRCPatrol || $wgUseNPPatrol
968 || ( $wgUseFilePatrol && $title->inNamespace( NS_FILE ) ) )
969 ) {
970 // Patrolling is disabled or the user isn't allowed to
971 return false;
972 }
973
974 if ( $this->mRevision
975 && !RecentChange::isInRCLifespan( $this->mRevision->getTimestamp(), 21600 )
976 ) {
977 // The current revision is already older than what could be in the RC table
978 // 6h tolerance because the RC might not be cleaned out regularly
979 return false;
980 }
981
982 // Check for cached results
983 $key = wfMemcKey( 'unpatrollable-page', $title->getArticleID() );
984 $cache = ObjectCache::getMainWANInstance();
985 if ( $cache->get( $key ) ) {
986 return false;
987 }
988
989 $dbr = wfGetDB( DB_REPLICA );
990 $oldestRevisionTimestamp = $dbr->selectField(
991 'revision',
992 'MIN( rev_timestamp )',
993 [ 'rev_page' => $title->getArticleID() ],
994 __METHOD__
995 );
996
997 // New page patrol: Get the timestamp of the oldest revison which
998 // the revision table holds for the given page. Then we look
999 // whether it's within the RC lifespan and if it is, we try
1000 // to get the recentchanges row belonging to that entry
1001 // (with rc_new = 1).
1002 $recentPageCreation = false;
1003 if ( $oldestRevisionTimestamp
1004 && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1005 ) {
1006 // 6h tolerance because the RC might not be cleaned out regularly
1007 $recentPageCreation = true;
1008 $rc = RecentChange::newFromConds(
1009 [
1010 'rc_new' => 1,
1011 'rc_timestamp' => $oldestRevisionTimestamp,
1012 'rc_namespace' => $title->getNamespace(),
1013 'rc_cur_id' => $title->getArticleID()
1014 ],
1015 __METHOD__
1016 );
1017 if ( $rc ) {
1018 // Use generic patrol message for new pages
1019 $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
1020 }
1021 }
1022
1023 // File patrol: Get the timestamp of the latest upload for this page,
1024 // check whether it is within the RC lifespan and if it is, we try
1025 // to get the recentchanges row belonging to that entry
1026 // (with rc_type = RC_LOG, rc_log_type = upload).
1027 $recentFileUpload = false;
1028 if ( ( !$rc || $rc->getAttribute( 'rc_patrolled' ) ) && $wgUseFilePatrol
1029 && $title->getNamespace() === NS_FILE ) {
1030 // Retrieve timestamp of most recent upload
1031 $newestUploadTimestamp = $dbr->selectField(
1032 'image',
1033 'MAX( img_timestamp )',
1034 [ 'img_name' => $title->getDBkey() ],
1035 __METHOD__
1036 );
1037 if ( $newestUploadTimestamp
1038 && RecentChange::isInRCLifespan( $newestUploadTimestamp, 21600 )
1039 ) {
1040 // 6h tolerance because the RC might not be cleaned out regularly
1041 $recentFileUpload = true;
1042 $rc = RecentChange::newFromConds(
1043 [
1044 'rc_type' => RC_LOG,
1045 'rc_log_type' => 'upload',
1046 'rc_timestamp' => $newestUploadTimestamp,
1047 'rc_namespace' => NS_FILE,
1048 'rc_cur_id' => $title->getArticleID()
1049 ],
1050 __METHOD__,
1051 [ 'USE INDEX' => 'rc_timestamp' ]
1052 );
1053 if ( $rc ) {
1054 // Use patrol message specific to files
1055 $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
1056 }
1057 }
1058 }
1059
1060 if ( !$recentPageCreation && !$recentFileUpload ) {
1061 // Page creation and latest upload (for files) is too old to be in RC
1062
1063 // We definitely can't patrol so cache the information
1064 // When a new file version is uploaded, the cache is cleared
1065 $cache->set( $key, '1' );
1066
1067 return false;
1068 }
1069
1070 if ( !$rc ) {
1071 // Don't cache: This can be hit if the page gets accessed very fast after
1072 // its creation / latest upload or in case we have high replica DB lag. In case
1073 // the revision is too old, we will already return above.
1074 return false;
1075 }
1076
1077 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1078 // Patrolled RC entry around
1079
1080 // Cache the information we gathered above in case we can't patrol
1081 // Don't cache in case we can patrol as this could change
1082 $cache->set( $key, '1' );
1083
1084 return false;
1085 }
1086
1087 if ( $rc->getPerformer()->equals( $user ) ) {
1088 // Don't show a patrol link for own creations/uploads. If the user could
1089 // patrol them, they already would be patrolled
1090 return false;
1091 }
1092
1093 $outputPage->preventClickjacking();
1094 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1095 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1096 }
1097
1098 $link = Linker::linkKnown(
1099 $title,
1100 $markPatrolledMsg->escaped(),
1101 [],
1102 [
1103 'action' => 'markpatrolled',
1104 'rcid' => $rc->getAttribute( 'rc_id' ),
1105 ]
1106 );
1107
1108 $outputPage->addHTML(
1109 "<div class='patrollink' data-mw='interface'>" .
1110 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1111 '</div>'
1112 );
1113
1114 return true;
1115 }
1116
1117 /**
1118 * Purge the cache used to check if it is worth showing the patrol footer
1119 * For example, it is done during re-uploads when file patrol is used.
1120 * @param int $articleID ID of the article to purge
1121 * @since 1.27
1122 */
1123 public static function purgePatrolFooterCache( $articleID ) {
1124 $cache = ObjectCache::getMainWANInstance();
1125 $cache->delete( wfMemcKey( 'unpatrollable-page', $articleID ) );
1126 }
1127
1128 /**
1129 * Show the error text for a missing article. For articles in the MediaWiki
1130 * namespace, show the default message text. To be called from Article::view().
1131 */
1132 public function showMissingArticle() {
1133 global $wgSend404Code;
1134
1135 $outputPage = $this->getContext()->getOutput();
1136 // Whether the page is a root user page of an existing user (but not a subpage)
1137 $validUserPage = false;
1138
1139 $title = $this->getTitle();
1140
1141 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1142 if ( $title->getNamespace() == NS_USER
1143 || $title->getNamespace() == NS_USER_TALK
1144 ) {
1145 $rootPart = explode( '/', $title->getText() )[0];
1146 $user = User::newFromName( $rootPart, false /* allow IP users*/ );
1147 $ip = User::isIP( $rootPart );
1148 $block = Block::newFromTarget( $user, $user );
1149
1150 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1151 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1152 [ 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ] );
1153 } elseif ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) {
1154 # Show log extract if the user is currently blocked
1155 LogEventsList::showLogExtract(
1156 $outputPage,
1157 'block',
1158 MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
1159 '',
1160 [
1161 'lim' => 1,
1162 'showIfEmpty' => false,
1163 'msgKey' => [
1164 'blocked-notice-logextract',
1165 $user->getName() # Support GENDER in notice
1166 ]
1167 ]
1168 );
1169 $validUserPage = !$title->isSubpage();
1170 } else {
1171 $validUserPage = !$title->isSubpage();
1172 }
1173 }
1174
1175 Hooks::run( 'ShowMissingArticle', [ $this ] );
1176
1177 # Show delete and move logs if there were any such events.
1178 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1179 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1180 $cache = ObjectCache::getMainStashInstance();
1181 $key = wfMemcKey( 'page-recent-delete', md5( $title->getPrefixedText() ) );
1182 $loggedIn = $this->getContext()->getUser()->isLoggedIn();
1183 if ( $loggedIn || $cache->get( $key ) ) {
1184 $logTypes = [ 'delete', 'move' ];
1185 $conds = [ "log_action != 'revision'" ];
1186 // Give extensions a chance to hide their (unrelated) log entries
1187 Hooks::run( 'Article::MissingArticleConditions', [ &$conds, $logTypes ] );
1188 LogEventsList::showLogExtract(
1189 $outputPage,
1190 $logTypes,
1191 $title,
1192 '',
1193 [
1194 'lim' => 10,
1195 'conds' => $conds,
1196 'showIfEmpty' => false,
1197 'msgKey' => [ $loggedIn
1198 ? 'moveddeleted-notice'
1199 : 'moveddeleted-notice-recent'
1200 ]
1201 ]
1202 );
1203 }
1204
1205 if ( !$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1206 // If there's no backing content, send a 404 Not Found
1207 // for better machine handling of broken links.
1208 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1209 }
1210
1211 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1212 $policy = $this->getRobotPolicy( 'view' );
1213 $outputPage->setIndexPolicy( $policy['index'] );
1214 $outputPage->setFollowPolicy( $policy['follow'] );
1215
1216 $hookResult = Hooks::run( 'BeforeDisplayNoArticleText', [ $this ] );
1217
1218 if ( !$hookResult ) {
1219 return;
1220 }
1221
1222 # Show error message
1223 $oldid = $this->getOldID();
1224 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI && $title->hasSourceText() ) {
1225 $outputPage->addParserOutput( $this->getContentObject()->getParserOutput( $title ) );
1226 } else {
1227 if ( $oldid ) {
1228 $text = wfMessage( 'missing-revision', $oldid )->plain();
1229 } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
1230 && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
1231 ) {
1232 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
1233 $text = wfMessage( $message )->plain();
1234 } else {
1235 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1236 }
1237
1238 $dir = $this->getContext()->getLanguage()->getDir();
1239 $lang = $this->getContext()->getLanguage()->getCode();
1240 $outputPage->addWikiText( Xml::openElement( 'div', [
1241 'class' => "noarticletext mw-content-$dir",
1242 'dir' => $dir,
1243 'lang' => $lang,
1244 ] ) . "\n$text\n</div>" );
1245 }
1246 }
1247
1248 /**
1249 * If the revision requested for view is deleted, check permissions.
1250 * Send either an error message or a warning header to the output.
1251 *
1252 * @return bool True if the view is allowed, false if not.
1253 */
1254 public function showDeletedRevisionHeader() {
1255 if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1256 // Not deleted
1257 return true;
1258 }
1259
1260 $outputPage = $this->getContext()->getOutput();
1261 $user = $this->getContext()->getUser();
1262 // If the user is not allowed to see it...
1263 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT, $user ) ) {
1264 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1265 'rev-deleted-text-permission' );
1266
1267 return false;
1268 // If the user needs to confirm that they want to see it...
1269 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1270 # Give explanation and add a link to view the revision...
1271 $oldid = intval( $this->getOldID() );
1272 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1273 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1274 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1275 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1276 [ $msg, $link ] );
1277
1278 return false;
1279 // We are allowed to see...
1280 } else {
1281 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1282 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1283 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1284
1285 return true;
1286 }
1287 }
1288
1289 /**
1290 * Generate the navigation links when browsing through an article revisions
1291 * It shows the information as:
1292 * Revision as of \<date\>; view current revision
1293 * \<- Previous version | Next Version -\>
1294 *
1295 * @param int $oldid Revision ID of this article revision
1296 */
1297 public function setOldSubtitle( $oldid = 0 ) {
1298 if ( !Hooks::run( 'DisplayOldSubtitle', [ &$this, &$oldid ] ) ) {
1299 return;
1300 }
1301
1302 $context = $this->getContext();
1303 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1304
1305 # Cascade unhide param in links for easy deletion browsing
1306 $extraParams = [];
1307 if ( $unhide ) {
1308 $extraParams['unhide'] = 1;
1309 }
1310
1311 if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
1312 $revision = $this->mRevision;
1313 } else {
1314 $revision = Revision::newFromId( $oldid );
1315 }
1316
1317 $timestamp = $revision->getTimestamp();
1318
1319 $current = ( $oldid == $this->mPage->getLatest() );
1320 $language = $context->getLanguage();
1321 $user = $context->getUser();
1322
1323 $td = $language->userTimeAndDate( $timestamp, $user );
1324 $tddate = $language->userDate( $timestamp, $user );
1325 $tdtime = $language->userTime( $timestamp, $user );
1326
1327 # Show user links if allowed to see them. If hidden, then show them only if requested...
1328 $userlinks = Linker::revUserTools( $revision, !$unhide );
1329
1330 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1331 ? 'revision-info-current'
1332 : 'revision-info';
1333
1334 $outputPage = $context->getOutput();
1335 $revisionInfo = "<div id=\"mw-{$infomsg}\">" .
1336 $context->msg( $infomsg, $td )
1337 ->rawParams( $userlinks )
1338 ->params( $revision->getId(), $tddate, $tdtime, $revision->getUserText() )
1339 ->rawParams( Linker::revComment( $revision, true, true ) )
1340 ->parse() .
1341 "</div>";
1342
1343 $lnk = $current
1344 ? $context->msg( 'currentrevisionlink' )->escaped()
1345 : Linker::linkKnown(
1346 $this->getTitle(),
1347 $context->msg( 'currentrevisionlink' )->escaped(),
1348 [],
1349 $extraParams
1350 );
1351 $curdiff = $current
1352 ? $context->msg( 'diff' )->escaped()
1353 : Linker::linkKnown(
1354 $this->getTitle(),
1355 $context->msg( 'diff' )->escaped(),
1356 [],
1357 [
1358 'diff' => 'cur',
1359 'oldid' => $oldid
1360 ] + $extraParams
1361 );
1362 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1363 $prevlink = $prev
1364 ? Linker::linkKnown(
1365 $this->getTitle(),
1366 $context->msg( 'previousrevision' )->escaped(),
1367 [],
1368 [
1369 'direction' => 'prev',
1370 'oldid' => $oldid
1371 ] + $extraParams
1372 )
1373 : $context->msg( 'previousrevision' )->escaped();
1374 $prevdiff = $prev
1375 ? Linker::linkKnown(
1376 $this->getTitle(),
1377 $context->msg( 'diff' )->escaped(),
1378 [],
1379 [
1380 'diff' => 'prev',
1381 'oldid' => $oldid
1382 ] + $extraParams
1383 )
1384 : $context->msg( 'diff' )->escaped();
1385 $nextlink = $current
1386 ? $context->msg( 'nextrevision' )->escaped()
1387 : Linker::linkKnown(
1388 $this->getTitle(),
1389 $context->msg( 'nextrevision' )->escaped(),
1390 [],
1391 [
1392 'direction' => 'next',
1393 'oldid' => $oldid
1394 ] + $extraParams
1395 );
1396 $nextdiff = $current
1397 ? $context->msg( 'diff' )->escaped()
1398 : Linker::linkKnown(
1399 $this->getTitle(),
1400 $context->msg( 'diff' )->escaped(),
1401 [],
1402 [
1403 'diff' => 'next',
1404 'oldid' => $oldid
1405 ] + $extraParams
1406 );
1407
1408 $cdel = Linker::getRevDeleteLink( $user, $revision, $this->getTitle() );
1409 if ( $cdel !== '' ) {
1410 $cdel .= ' ';
1411 }
1412
1413 // the outer div is need for styling the revision info and nav in MobileFrontend
1414 $outputPage->addSubtitle( "<div class=\"mw-revision\">" . $revisionInfo .
1415 "<div id=\"mw-revision-nav\">" . $cdel .
1416 $context->msg( 'revision-nav' )->rawParams(
1417 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1418 )->escaped() . "</div></div>" );
1419 }
1420
1421 /**
1422 * Return the HTML for the top of a redirect page
1423 *
1424 * Chances are you should just be using the ParserOutput from
1425 * WikitextContent::getParserOutput instead of calling this for redirects.
1426 *
1427 * @param Title|array $target Destination(s) to redirect
1428 * @param bool $appendSubtitle [optional]
1429 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1430 * @return string Containing HTML with redirect link
1431 */
1432 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1433 $lang = $this->getTitle()->getPageLanguage();
1434 $out = $this->getContext()->getOutput();
1435 if ( $appendSubtitle ) {
1436 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1437 }
1438 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1439 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1440 }
1441
1442 /**
1443 * Return the HTML for the top of a redirect page
1444 *
1445 * Chances are you should just be using the ParserOutput from
1446 * WikitextContent::getParserOutput instead of calling this for redirects.
1447 *
1448 * @since 1.23
1449 * @param Language $lang
1450 * @param Title|array $target Destination(s) to redirect
1451 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1452 * @return string Containing HTML with redirect link
1453 */
1454 public static function getRedirectHeaderHtml( Language $lang, $target, $forceKnown = false ) {
1455 if ( !is_array( $target ) ) {
1456 $target = [ $target ];
1457 }
1458
1459 $html = '<ul class="redirectText">';
1460 /** @var Title $title */
1461 foreach ( $target as $title ) {
1462 $html .= '<li>' . Linker::link(
1463 $title,
1464 htmlspecialchars( $title->getFullText() ),
1465 [],
1466 // Make sure wiki page redirects are not followed
1467 $title->isRedirect() ? [ 'redirect' => 'no' ] : [],
1468 ( $forceKnown ? [ 'known', 'noclasses' ] : [] )
1469 ) . '</li>';
1470 }
1471 $html .= '</ul>';
1472
1473 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1474
1475 return '<div class="redirectMsg">' .
1476 '<p>' . $redirectToText . '</p>' .
1477 $html .
1478 '</div>';
1479 }
1480
1481 /**
1482 * Adds help link with an icon via page indicators.
1483 * Link target can be overridden by a local message containing a wikilink:
1484 * the message key is: 'namespace-' + namespace number + '-helppage'.
1485 * @param string $to Target MediaWiki.org page title or encoded URL.
1486 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1487 * @since 1.25
1488 */
1489 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1490 $msg = wfMessage(
1491 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1492 );
1493
1494 $out = $this->getContext()->getOutput();
1495 if ( !$msg->isDisabled() ) {
1496 $helpUrl = Skin::makeUrl( $msg->plain() );
1497 $out->addHelpLink( $helpUrl, true );
1498 } else {
1499 $out->addHelpLink( $to, $overrideBaseUrl );
1500 }
1501 }
1502
1503 /**
1504 * Handle action=render
1505 */
1506 public function render() {
1507 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1508 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1509 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1510 $this->view();
1511 }
1512
1513 /**
1514 * action=protect handler
1515 */
1516 public function protect() {
1517 $form = new ProtectionForm( $this );
1518 $form->execute();
1519 }
1520
1521 /**
1522 * action=unprotect handler (alias)
1523 */
1524 public function unprotect() {
1525 $this->protect();
1526 }
1527
1528 /**
1529 * UI entry point for page deletion
1530 */
1531 public function delete() {
1532 # This code desperately needs to be totally rewritten
1533
1534 $title = $this->getTitle();
1535 $context = $this->getContext();
1536 $user = $context->getUser();
1537 $request = $context->getRequest();
1538
1539 # Check permissions
1540 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1541 if ( count( $permissionErrors ) ) {
1542 throw new PermissionsError( 'delete', $permissionErrors );
1543 }
1544
1545 # Read-only check...
1546 if ( wfReadOnly() ) {
1547 throw new ReadOnlyError;
1548 }
1549
1550 # Better double-check that it hasn't been deleted yet!
1551 $this->mPage->loadPageData(
1552 $request->wasPosted() ? WikiPage::READ_LATEST : WikiPage::READ_NORMAL
1553 );
1554 if ( !$this->mPage->exists() ) {
1555 $deleteLogPage = new LogPage( 'delete' );
1556 $outputPage = $context->getOutput();
1557 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1558 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1559 [ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ]
1560 );
1561 $outputPage->addHTML(
1562 Xml::element( 'h2', null, $deleteLogPage->getName()->text() )
1563 );
1564 LogEventsList::showLogExtract(
1565 $outputPage,
1566 'delete',
1567 $title
1568 );
1569
1570 return;
1571 }
1572
1573 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1574 $deleteReason = $request->getText( 'wpReason' );
1575
1576 if ( $deleteReasonList == 'other' ) {
1577 $reason = $deleteReason;
1578 } elseif ( $deleteReason != '' ) {
1579 // Entry from drop down menu + additional comment
1580 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1581 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1582 } else {
1583 $reason = $deleteReasonList;
1584 }
1585
1586 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1587 [ 'delete', $this->getTitle()->getPrefixedText() ] )
1588 ) {
1589 # Flag to hide all contents of the archived revisions
1590 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1591
1592 $this->doDelete( $reason, $suppress );
1593
1594 WatchAction::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1595
1596 return;
1597 }
1598
1599 // Generate deletion reason
1600 $hasHistory = false;
1601 if ( !$reason ) {
1602 try {
1603 $reason = $this->generateReason( $hasHistory );
1604 } catch ( Exception $e ) {
1605 # if a page is horribly broken, we still want to be able to
1606 # delete it. So be lenient about errors here.
1607 wfDebug( "Error while building auto delete summary: $e" );
1608 $reason = '';
1609 }
1610 }
1611
1612 // If the page has a history, insert a warning
1613 if ( $hasHistory ) {
1614 $title = $this->getTitle();
1615
1616 // The following can use the real revision count as this is only being shown for users
1617 // that can delete this page.
1618 // This, as a side-effect, also makes sure that the following query isn't being run for
1619 // pages with a larger history, unless the user has the 'bigdelete' right
1620 // (and is about to delete this page).
1621 $dbr = wfGetDB( DB_REPLICA );
1622 $revisions = $edits = (int)$dbr->selectField(
1623 'revision',
1624 'COUNT(rev_page)',
1625 [ 'rev_page' => $title->getArticleID() ],
1626 __METHOD__
1627 );
1628
1629 // @todo FIXME: i18n issue/patchwork message
1630 $context->getOutput()->addHTML(
1631 '<strong class="mw-delete-warning-revisions">' .
1632 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1633 $context->msg( 'word-separator' )->escaped() . Linker::linkKnown( $title,
1634 $context->msg( 'history' )->escaped(),
1635 [],
1636 [ 'action' => 'history' ] ) .
1637 '</strong>'
1638 );
1639
1640 if ( $title->isBigDeletion() ) {
1641 global $wgDeleteRevisionsLimit;
1642 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1643 [
1644 'delete-warning-toobig',
1645 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1646 ]
1647 );
1648 }
1649 }
1650
1651 $this->confirmDelete( $reason );
1652 }
1653
1654 /**
1655 * Output deletion confirmation dialog
1656 * @todo FIXME: Move to another file?
1657 * @param string $reason Prefilled reason
1658 */
1659 public function confirmDelete( $reason ) {
1660 wfDebug( "Article::confirmDelete\n" );
1661
1662 $title = $this->getTitle();
1663 $ctx = $this->getContext();
1664 $outputPage = $ctx->getOutput();
1665 $useMediaWikiUIEverywhere = $ctx->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1666 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1667 $outputPage->addBacklinkSubtitle( $title );
1668 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1669 $backlinkCache = $title->getBacklinkCache();
1670 if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
1671 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1672 'deleting-backlinks-warning' );
1673 }
1674 $outputPage->addWikiMsg( 'confirmdeletetext' );
1675
1676 Hooks::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
1677
1678 $user = $this->getContext()->getUser();
1679
1680 if ( $user->isAllowed( 'suppressrevision' ) ) {
1681 $suppress = Html::openElement( 'div', [ 'id' => 'wpDeleteSuppressRow' ] ) .
1682 Xml::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1683 'wpSuppress', 'wpSuppress', false, [ 'tabindex' => '4' ] ) .
1684 Html::closeElement( 'div' );
1685 } else {
1686 $suppress = '';
1687 }
1688 $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $title );
1689
1690 $form = Html::openElement( 'form', [ 'method' => 'post',
1691 'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ] ) .
1692 Html::openElement( 'fieldset', [ 'id' => 'mw-delete-table' ] ) .
1693 Html::element( 'legend', null, wfMessage( 'delete-legend' )->text() ) .
1694 Html::openElement( 'div', [ 'id' => 'mw-deleteconfirm-table' ] ) .
1695 Html::openElement( 'div', [ 'id' => 'wpDeleteReasonListRow' ] ) .
1696 Html::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1697 '&nbsp;' .
1698 Xml::listDropDown(
1699 'wpDeleteReasonList',
1700 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1701 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1702 '',
1703 'wpReasonDropDown',
1704 1
1705 ) .
1706 Html::closeElement( 'div' ) .
1707 Html::openElement( 'div', [ 'id' => 'wpDeleteReasonRow' ] ) .
1708 Html::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1709 '&nbsp;' .
1710 Html::input( 'wpReason', $reason, 'text', [
1711 'size' => '60',
1712 'maxlength' => '255',
1713 'tabindex' => '2',
1714 'id' => 'wpReason',
1715 'class' => 'mw-ui-input-inline',
1716 'autofocus'
1717 ] ) .
1718 Html::closeElement( 'div' );
1719
1720 # Disallow watching if user is not logged in
1721 if ( $user->isLoggedIn() ) {
1722 $form .=
1723 Xml::checkLabel( wfMessage( 'watchthis' )->text(),
1724 'wpWatch', 'wpWatch', $checkWatch, [ 'tabindex' => '3' ] );
1725 }
1726
1727 $form .=
1728 Html::openElement( 'div' ) .
1729 $suppress .
1730 Xml::submitButton( wfMessage( 'deletepage' )->text(),
1731 [
1732 'name' => 'wpConfirmB',
1733 'id' => 'wpConfirmB',
1734 'tabindex' => '5',
1735 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button mw-ui-destructive' : '',
1736 ]
1737 ) .
1738 Html::closeElement( 'div' ) .
1739 Html::closeElement( 'div' ) .
1740 Xml::closeElement( 'fieldset' ) .
1741 Html::hidden(
1742 'wpEditToken',
1743 $user->getEditToken( [ 'delete', $title->getPrefixedText() ] )
1744 ) .
1745 Xml::closeElement( 'form' );
1746
1747 if ( $user->isAllowed( 'editinterface' ) ) {
1748 $link = Linker::linkKnown(
1749 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
1750 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1751 [],
1752 [ 'action' => 'edit' ]
1753 );
1754 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1755 }
1756
1757 $outputPage->addHTML( $form );
1758
1759 $deleteLogPage = new LogPage( 'delete' );
1760 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1761 LogEventsList::showLogExtract( $outputPage, 'delete', $title );
1762 }
1763
1764 /**
1765 * Perform a deletion and output success or failure messages
1766 * @param string $reason
1767 * @param bool $suppress
1768 */
1769 public function doDelete( $reason, $suppress = false ) {
1770 $error = '';
1771 $context = $this->getContext();
1772 $outputPage = $context->getOutput();
1773 $user = $context->getUser();
1774 $status = $this->mPage->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user );
1775
1776 if ( $status->isGood() ) {
1777 $deleted = $this->getTitle()->getPrefixedText();
1778
1779 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1780 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1781
1782 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1783
1784 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1785
1786 Hooks::run( 'ArticleDeleteAfterSuccess', [ $this->getTitle(), $outputPage ] );
1787
1788 $outputPage->returnToMain( false );
1789 } else {
1790 $outputPage->setPageTitle(
1791 wfMessage( 'cannotdelete-title',
1792 $this->getTitle()->getPrefixedText() )
1793 );
1794
1795 if ( $error == '' ) {
1796 $outputPage->addWikiText(
1797 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1798 );
1799 $deleteLogPage = new LogPage( 'delete' );
1800 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1801
1802 LogEventsList::showLogExtract(
1803 $outputPage,
1804 'delete',
1805 $this->getTitle()
1806 );
1807 } else {
1808 $outputPage->addHTML( $error );
1809 }
1810 }
1811 }
1812
1813 /* Caching functions */
1814
1815 /**
1816 * checkLastModified returns true if it has taken care of all
1817 * output to the client that is necessary for this request.
1818 * (that is, it has sent a cached version of the page)
1819 *
1820 * @return bool True if cached version send, false otherwise
1821 */
1822 protected function tryFileCache() {
1823 static $called = false;
1824
1825 if ( $called ) {
1826 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1827 return false;
1828 }
1829
1830 $called = true;
1831 if ( $this->isFileCacheable() ) {
1832 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
1833 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1834 wfDebug( "Article::tryFileCache(): about to load file\n" );
1835 $cache->loadFromFileCache( $this->getContext() );
1836 return true;
1837 } else {
1838 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1839 ob_start( [ &$cache, 'saveToFileCache' ] );
1840 }
1841 } else {
1842 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1843 }
1844
1845 return false;
1846 }
1847
1848 /**
1849 * Check if the page can be cached
1850 * @param integer $mode One of the HTMLFileCache::MODE_* constants (since 1.28)
1851 * @return bool
1852 */
1853 public function isFileCacheable( $mode = HTMLFileCache::MODE_NORMAL ) {
1854 $cacheable = false;
1855
1856 if ( HTMLFileCache::useFileCache( $this->getContext(), $mode ) ) {
1857 $cacheable = $this->mPage->getId()
1858 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
1859 // Extension may have reason to disable file caching on some pages.
1860 if ( $cacheable ) {
1861 $cacheable = Hooks::run( 'IsFileCacheable', [ &$this ] );
1862 }
1863 }
1864
1865 return $cacheable;
1866 }
1867
1868 /**#@-*/
1869
1870 /**
1871 * Lightweight method to get the parser output for a page, checking the parser cache
1872 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1873 * consider, so it's not appropriate to use there.
1874 *
1875 * @since 1.16 (r52326) for LiquidThreads
1876 *
1877 * @param int|null $oldid Revision ID or null
1878 * @param User $user The relevant user
1879 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1880 */
1881 public function getParserOutput( $oldid = null, User $user = null ) {
1882 // XXX: bypasses mParserOptions and thus setParserOptions()
1883
1884 if ( $user === null ) {
1885 $parserOptions = $this->getParserOptions();
1886 } else {
1887 $parserOptions = $this->mPage->makeParserOptions( $user );
1888 }
1889
1890 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1891 }
1892
1893 /**
1894 * Override the ParserOptions used to render the primary article wikitext.
1895 *
1896 * @param ParserOptions $options
1897 * @throws MWException If the parser options where already initialized.
1898 */
1899 public function setParserOptions( ParserOptions $options ) {
1900 if ( $this->mParserOptions ) {
1901 throw new MWException( "can't change parser options after they have already been set" );
1902 }
1903
1904 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1905 $this->mParserOptions = clone $options;
1906 }
1907
1908 /**
1909 * Get parser options suitable for rendering the primary article wikitext
1910 * @return ParserOptions
1911 */
1912 public function getParserOptions() {
1913 if ( !$this->mParserOptions ) {
1914 $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
1915 }
1916 // Clone to allow modifications of the return value without affecting cache
1917 return clone $this->mParserOptions;
1918 }
1919
1920 /**
1921 * Sets the context this Article is executed in
1922 *
1923 * @param IContextSource $context
1924 * @since 1.18
1925 */
1926 public function setContext( $context ) {
1927 $this->mContext = $context;
1928 }
1929
1930 /**
1931 * Gets the context this Article is executed in
1932 *
1933 * @return IContextSource
1934 * @since 1.18
1935 */
1936 public function getContext() {
1937 if ( $this->mContext instanceof IContextSource ) {
1938 return $this->mContext;
1939 } else {
1940 wfDebug( __METHOD__ . " called and \$mContext is null. " .
1941 "Return RequestContext::getMain(); for sanity\n" );
1942 return RequestContext::getMain();
1943 }
1944 }
1945
1946 /**
1947 * Use PHP's magic __get handler to handle accessing of
1948 * raw WikiPage fields for backwards compatibility.
1949 *
1950 * @param string $fname Field name
1951 * @return mixed
1952 */
1953 public function __get( $fname ) {
1954 if ( property_exists( $this->mPage, $fname ) ) {
1955 # wfWarn( "Access to raw $fname field " . __CLASS__ );
1956 return $this->mPage->$fname;
1957 }
1958 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
1959 }
1960
1961 /**
1962 * Use PHP's magic __set handler to handle setting of
1963 * raw WikiPage fields for backwards compatibility.
1964 *
1965 * @param string $fname Field name
1966 * @param mixed $fvalue New value
1967 */
1968 public function __set( $fname, $fvalue ) {
1969 if ( property_exists( $this->mPage, $fname ) ) {
1970 # wfWarn( "Access to raw $fname field of " . __CLASS__ );
1971 $this->mPage->$fname = $fvalue;
1972 // Note: extensions may want to toss on new fields
1973 } elseif ( !in_array( $fname, [ 'mContext', 'mPage' ] ) ) {
1974 $this->mPage->$fname = $fvalue;
1975 } else {
1976 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
1977 }
1978 }
1979
1980 /**
1981 * Call to WikiPage function for backwards compatibility.
1982 * @see WikiPage::checkFlags
1983 */
1984 public function checkFlags( $flags ) {
1985 return $this->mPage->checkFlags( $flags );
1986 }
1987
1988 /**
1989 * Call to WikiPage function for backwards compatibility.
1990 * @see WikiPage::checkTouched
1991 */
1992 public function checkTouched() {
1993 return $this->mPage->checkTouched();
1994 }
1995
1996 /**
1997 * Call to WikiPage function for backwards compatibility.
1998 * @see WikiPage::clearPreparedEdit
1999 */
2000 public function clearPreparedEdit() {
2001 $this->mPage->clearPreparedEdit();
2002 }
2003
2004 /**
2005 * Call to WikiPage function for backwards compatibility.
2006 * @see WikiPage::doDeleteArticleReal
2007 */
2008 public function doDeleteArticleReal(
2009 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null,
2010 $tags = []
2011 ) {
2012 return $this->mPage->doDeleteArticleReal(
2013 $reason, $suppress, $u1, $u2, $error, $user, $tags
2014 );
2015 }
2016
2017 /**
2018 * Call to WikiPage function for backwards compatibility.
2019 * @see WikiPage::doDeleteUpdates
2020 */
2021 public function doDeleteUpdates( $id, Content $content = null ) {
2022 return $this->mPage->doDeleteUpdates( $id, $content );
2023 }
2024
2025 /**
2026 * Call to WikiPage function for backwards compatibility.
2027 * @see WikiPage::doEdit
2028 *
2029 * @deprecated since 1.21: use doEditContent() instead.
2030 */
2031 public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
2032 wfDeprecated( __METHOD__, '1.21' );
2033 return $this->mPage->doEdit( $text, $summary, $flags, $baseRevId, $user );
2034 }
2035
2036 /**
2037 * Call to WikiPage function for backwards compatibility.
2038 * @see WikiPage::doEditContent
2039 */
2040 public function doEditContent( Content $content, $summary, $flags = 0, $baseRevId = false,
2041 User $user = null, $serialFormat = null
2042 ) {
2043 return $this->mPage->doEditContent( $content, $summary, $flags, $baseRevId,
2044 $user, $serialFormat
2045 );
2046 }
2047
2048 /**
2049 * Call to WikiPage function for backwards compatibility.
2050 * @see WikiPage::doEditUpdates
2051 */
2052 public function doEditUpdates( Revision $revision, User $user, array $options = [] ) {
2053 return $this->mPage->doEditUpdates( $revision, $user, $options );
2054 }
2055
2056 /**
2057 * Call to WikiPage function for backwards compatibility.
2058 * @see WikiPage::doPurge
2059 */
2060 public function doPurge( $flags = WikiPage::PURGE_ALL ) {
2061 return $this->mPage->doPurge( $flags );
2062 }
2063
2064 /**
2065 * Call to WikiPage function for backwards compatibility.
2066 * @see WikiPage::getLastPurgeTimestamp
2067 */
2068 public function getLastPurgeTimestamp() {
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 }