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