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