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