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