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