Add User::equals
[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 * @internal documentation reviewed 15 Mar 2010
35 */
36 class Article implements Page {
37 /** @var IContextSource The context this Article is executed in */
38 protected $mContext;
39
40 /** @var WikiPage The WikiPage object of this instance */
41 protected $mPage;
42
43 /** @var ParserOptions ParserOptions object for $wgUser articles */
44 public $mParserOptions;
45
46 /**
47 * @var string Text of the revision we are working on
48 * @todo BC cruft
49 */
50 public $mContent;
51
52 /**
53 * @var Content Content of the revision we are working on
54 * @since 1.21
55 */
56 public $mContentObject;
57
58 /** @var bool Is the content ($mContent) already loaded? */
59 public $mContentLoaded = false;
60
61 /** @var int|null The oldid of the article that is to be shown, 0 for the current revision */
62 public $mOldId;
63
64 /** @var Title Title from which we were redirected here */
65 public $mRedirectedFrom = null;
66
67 /** @var string|bool URL to redirect to or false if none */
68 public $mRedirectUrl = false;
69
70 /** @var int Revision ID of revision we are working on */
71 public $mRevIdFetched = 0;
72
73 /** @var Revision Revision we are working on */
74 public $mRevision = null;
75
76 /** @var ParserOutput */
77 public $mParserOutput;
78
79 /**
80 * Constructor and clear the article
81 * @param Title $title Reference to a Title object.
82 * @param int $oldId Revision ID, null to fetch from request, zero for current
83 */
84 public function __construct( Title $title, $oldId = null ) {
85 $this->mOldId = $oldId;
86 $this->mPage = $this->newPage( $title );
87 }
88
89 /**
90 * @param Title $title
91 * @return WikiPage
92 */
93 protected function newPage( Title $title ) {
94 return new WikiPage( $title );
95 }
96
97 /**
98 * Constructor from a page id
99 * @param int $id Article ID to load
100 * @return Article|null
101 */
102 public static function newFromID( $id ) {
103 $t = Title::newFromID( $id );
104 # @todo FIXME: Doesn't inherit right
105 return $t == null ? null : new self( $t );
106 # return $t == null ? null : new static( $t ); // PHP 5.3
107 }
108
109 /**
110 * Create an Article object of the appropriate class for the given page.
111 *
112 * @param Title $title
113 * @param IContextSource $context
114 * @return Article
115 */
116 public static function newFromTitle( $title, IContextSource $context ) {
117 if ( NS_MEDIA == $title->getNamespace() ) {
118 // FIXME: where should this go?
119 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
120 }
121
122 $page = null;
123 Hooks::run( 'ArticleFromTitle', array( &$title, &$page, $context ) );
124 if ( !$page ) {
125 switch ( $title->getNamespace() ) {
126 case NS_FILE:
127 $page = new ImagePage( $title );
128 break;
129 case NS_CATEGORY:
130 $page = new CategoryPage( $title );
131 break;
132 default:
133 $page = new Article( $title );
134 }
135 }
136 $page->setContext( $context );
137
138 return $page;
139 }
140
141 /**
142 * Create an Article object of the appropriate class for the given page.
143 *
144 * @param WikiPage $page
145 * @param IContextSource $context
146 * @return Article
147 */
148 public static function newFromWikiPage( WikiPage $page, IContextSource $context ) {
149 $article = self::newFromTitle( $page->getTitle(), $context );
150 $article->mPage = $page; // override to keep process cached vars
151 return $article;
152 }
153
154 /**
155 * Tell the page view functions that this view was redirected
156 * from another page on the wiki.
157 * @param Title $from
158 */
159 public function setRedirectedFrom( Title $from ) {
160 $this->mRedirectedFrom = $from;
161 }
162
163 /**
164 * Get the title object of the article
165 *
166 * @return Title Title object of this page
167 */
168 public function getTitle() {
169 return $this->mPage->getTitle();
170 }
171
172 /**
173 * Get the WikiPage object of this instance
174 *
175 * @since 1.19
176 * @return WikiPage
177 */
178 public function getPage() {
179 return $this->mPage;
180 }
181
182 /**
183 * Clear the object
184 */
185 public function clear() {
186 $this->mContentLoaded = false;
187
188 $this->mRedirectedFrom = null; # Title object if set
189 $this->mRevIdFetched = 0;
190 $this->mRedirectUrl = false;
191
192 $this->mPage->clear();
193 }
194
195 /**
196 * Note that getContent/loadContent do not follow redirects anymore.
197 * If you need to fetch redirectable content easily, try
198 * the shortcut in WikiPage::getRedirectTarget()
199 *
200 * This function has side effects! Do not use this function if you
201 * only want the real revision text if any.
202 *
203 * @deprecated since 1.21; use WikiPage::getContent() instead
204 *
205 * @return string Return the text of this revision
206 */
207 public function getContent() {
208 ContentHandler::deprecated( __METHOD__, '1.21' );
209 $content = $this->getContentObject();
210 return ContentHandler::getContentText( $content );
211 }
212
213 /**
214 * Returns a Content object representing the pages effective display content,
215 * not necessarily the revision's content!
216 *
217 * Note that getContent/loadContent do not follow redirects anymore.
218 * If you need to fetch redirectable content easily, try
219 * the shortcut in WikiPage::getRedirectTarget()
220 *
221 * This function has side effects! Do not use this function if you
222 * only want the real revision text if any.
223 *
224 * @return Content Return the content of this revision
225 *
226 * @since 1.21
227 */
228 protected function getContentObject() {
229
230 if ( $this->mPage->getID() === 0 ) {
231 # If this is a MediaWiki:x message, then load the messages
232 # and return the message value for x.
233 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
234 $text = $this->getTitle()->getDefaultMessageText();
235 if ( $text === false ) {
236 $text = '';
237 }
238
239 $content = ContentHandler::makeContent( $text, $this->getTitle() );
240 } else {
241 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
242 $content = new MessageContent( $message, null, 'parsemag' );
243 }
244 } else {
245 $this->fetchContentObject();
246 $content = $this->mContentObject;
247 }
248
249 return $content;
250 }
251
252 /**
253 * @return int The oldid of the article that is to be shown, 0 for the current revision
254 */
255 public function getOldID() {
256 if ( is_null( $this->mOldId ) ) {
257 $this->mOldId = $this->getOldIDFromRequest();
258 }
259
260 return $this->mOldId;
261 }
262
263 /**
264 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
265 *
266 * @return int The old id for the request
267 */
268 public function getOldIDFromRequest() {
269 $this->mRedirectUrl = false;
270
271 $request = $this->getContext()->getRequest();
272 $oldid = $request->getIntOrNull( 'oldid' );
273
274 if ( $oldid === null ) {
275 return 0;
276 }
277
278 if ( $oldid !== 0 ) {
279 # Load the given revision and check whether the page is another one.
280 # In that case, update this instance to reflect the change.
281 if ( $oldid === $this->mPage->getLatest() ) {
282 $this->mRevision = $this->mPage->getRevision();
283 } else {
284 $this->mRevision = Revision::newFromId( $oldid );
285 if ( $this->mRevision !== null ) {
286 // Revision title doesn't match the page title given?
287 if ( $this->mPage->getID() != $this->mRevision->getPage() ) {
288 $function = array( get_class( $this->mPage ), 'newFromID' );
289 $this->mPage = call_user_func( $function, $this->mRevision->getPage() );
290 }
291 }
292 }
293 }
294
295 if ( $request->getVal( 'direction' ) == 'next' ) {
296 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
297 if ( $nextid ) {
298 $oldid = $nextid;
299 $this->mRevision = null;
300 } else {
301 $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
302 }
303 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
304 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
305 if ( $previd ) {
306 $oldid = $previd;
307 $this->mRevision = null;
308 }
309 }
310
311 return $oldid;
312 }
313
314 /**
315 * Load the revision (including text) into this object
316 *
317 * @deprecated since 1.19; use fetchContent()
318 */
319 function loadContent() {
320 wfDeprecated( __METHOD__, '1.19' );
321 $this->fetchContent();
322 }
323
324 /**
325 * Get text of an article from database
326 * Does *NOT* follow redirects.
327 *
328 * @protected
329 * @note This is really internal functionality that should really NOT be
330 * used by other functions. For accessing article content, use the WikiPage
331 * class, especially WikiBase::getContent(). However, a lot of legacy code
332 * uses this method to retrieve page text from the database, so the function
333 * has to remain public for now.
334 *
335 * @return string|bool String containing article contents, or false if null
336 * @deprecated since 1.21, use WikiPage::getContent() instead
337 */
338 function fetchContent() { #BC cruft!
339 ContentHandler::deprecated( __METHOD__, '1.21' );
340
341 if ( $this->mContentLoaded && $this->mContent ) {
342 return $this->mContent;
343 }
344
345 $content = $this->fetchContentObject();
346
347 if ( !$content ) {
348 return false;
349 }
350
351 // @todo Get rid of mContent everywhere!
352 $this->mContent = ContentHandler::getContentText( $content );
353 ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
354
355 return $this->mContent;
356 }
357
358 /**
359 * Get text content object
360 * Does *NOT* follow redirects.
361 * @todo When is this null?
362 *
363 * @note Code that wants to retrieve page content from the database should
364 * use WikiPage::getContent().
365 *
366 * @return Content|null|bool
367 *
368 * @since 1.21
369 */
370 protected function fetchContentObject() {
371 if ( $this->mContentLoaded ) {
372 return $this->mContentObject;
373 }
374
375 $this->mContentLoaded = true;
376 $this->mContent = null;
377
378 $oldid = $this->getOldID();
379
380 # Pre-fill content with error message so that if something
381 # fails we'll have something telling us what we intended.
382 //XXX: this isn't page content but a UI message. horrible.
383 $this->mContentObject = new MessageContent( 'missing-revision', array( $oldid ), array() );
384
385 if ( $oldid ) {
386 # $this->mRevision might already be fetched by getOldIDFromRequest()
387 if ( !$this->mRevision ) {
388 $this->mRevision = Revision::newFromId( $oldid );
389 if ( !$this->mRevision ) {
390 wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
391 return false;
392 }
393 }
394 } else {
395 if ( !$this->mPage->getLatest() ) {
396 wfDebug( __METHOD__ . " failed to find page data for title " .
397 $this->getTitle()->getPrefixedText() . "\n" );
398 return false;
399 }
400
401 $this->mRevision = $this->mPage->getRevision();
402
403 if ( !$this->mRevision ) {
404 wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " .
405 $this->mPage->getLatest() . "\n" );
406 return false;
407 }
408 }
409
410 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
411 // We should instead work with the Revision object when we need it...
412 // Loads if user is allowed
413 $this->mContentObject = $this->mRevision->getContent(
414 Revision::FOR_THIS_USER,
415 $this->getContext()->getUser()
416 );
417 $this->mRevIdFetched = $this->mRevision->getId();
418
419 Hooks::run( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject ) );
420
421 return $this->mContentObject;
422 }
423
424 /**
425 * Returns true if the currently-referenced revision is the current edit
426 * to this page (and it exists).
427 * @return bool
428 */
429 public function isCurrent() {
430 # If no oldid, this is the current version.
431 if ( $this->getOldID() == 0 ) {
432 return true;
433 }
434
435 return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
436 }
437
438 /**
439 * Get the fetched Revision object depending on request parameters or null
440 * on failure.
441 *
442 * @since 1.19
443 * @return Revision|null
444 */
445 public function getRevisionFetched() {
446 $this->fetchContentObject();
447
448 return $this->mRevision;
449 }
450
451 /**
452 * Use this to fetch the rev ID used on page views
453 *
454 * @return int Revision ID of last article revision
455 */
456 public function getRevIdFetched() {
457 if ( $this->mRevIdFetched ) {
458 return $this->mRevIdFetched;
459 } else {
460 return $this->mPage->getLatest();
461 }
462 }
463
464 /**
465 * This is the default action of the index.php entry point: just view the
466 * page of the given title.
467 */
468 public function view() {
469 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar, $wgMaxRedirects;
470
471 # Get variables from query string
472 # As side effect this will load the revision and update the title
473 # in a revision ID is passed in the request, so this should remain
474 # the first call of this method even if $oldid is used way below.
475 $oldid = $this->getOldID();
476
477 $user = $this->getContext()->getUser();
478 # Another whitelist check in case getOldID() is altering the title
479 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
480 if ( count( $permErrors ) ) {
481 wfDebug( __METHOD__ . ": denied on secondary read check\n" );
482 throw new PermissionsError( 'read', $permErrors );
483 }
484
485 $outputPage = $this->getContext()->getOutput();
486 # getOldID() may as well want us to redirect somewhere else
487 if ( $this->mRedirectUrl ) {
488 $outputPage->redirect( $this->mRedirectUrl );
489 wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
490
491 return;
492 }
493
494 # If we got diff in the query, we want to see a diff page instead of the article.
495 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
496 wfDebug( __METHOD__ . ": showing diff page\n" );
497 $this->showDiffPage();
498
499 return;
500 }
501
502 # Set page title (may be overridden by DISPLAYTITLE)
503 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
504
505 $outputPage->setArticleFlag( true );
506 # Allow frames by default
507 $outputPage->allowClickjacking();
508
509 $parserCache = ParserCache::singleton();
510
511 $parserOptions = $this->getParserOptions();
512 # Render printable version, use printable version cache
513 if ( $outputPage->isPrintable() ) {
514 $parserOptions->setIsPrintable( true );
515 $parserOptions->setEditSection( false );
516 } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user ) ) {
517 $parserOptions->setEditSection( false );
518 }
519
520 # Try client and file cache
521 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
522 if ( $wgUseETag ) {
523 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
524 }
525
526 # Use the greatest of the page's timestamp or the timestamp of any
527 # redirect in the chain (bug 67849)
528 $timestamp = $this->mPage->getTouched();
529 if ( isset( $this->mRedirectedFrom ) ) {
530 $timestamp = max( $timestamp, $this->mRedirectedFrom->getTouched() );
531
532 # If there can be more than one redirect in the chain, we have
533 # to go through the whole chain too in case an intermediate
534 # redirect was changed.
535 if ( $wgMaxRedirects > 1 ) {
536 $titles = Revision::newFromTitle( $this->mRedirectedFrom )
537 ->getContent( Revision::FOR_THIS_USER, $user )
538 ->getRedirectChain();
539 $thisTitle = $this->getTitle();
540 foreach ( $titles as $title ) {
541 if ( Title::compare( $title, $thisTitle ) === 0 ) {
542 break;
543 }
544 $timestamp = max( $timestamp, $title->getTouched() );
545 }
546 }
547 }
548
549 # Is it client cached?
550 if ( $outputPage->checkLastModified( $timestamp ) ) {
551 wfDebug( __METHOD__ . ": done 304\n" );
552
553 return;
554 # Try file cache
555 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
556 wfDebug( __METHOD__ . ": done file cache\n" );
557 # tell wgOut that output is taken care of
558 $outputPage->disable();
559 $this->mPage->doViewUpdates( $user, $oldid );
560
561 return;
562 }
563 }
564
565 # Should the parser cache be used?
566 $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid );
567 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
568 if ( $user->getStubThreshold() ) {
569 wfIncrStats( 'pcache_miss_stub' );
570 }
571
572 $this->showRedirectedFromHeader();
573 $this->showNamespaceHeader();
574
575 # Iterate through the possible ways of constructing the output text.
576 # Keep going until $outputDone is set, or we run out of things to do.
577 $pass = 0;
578 $outputDone = false;
579 $this->mParserOutput = false;
580
581 while ( !$outputDone && ++$pass ) {
582 switch ( $pass ) {
583 case 1:
584 Hooks::run( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
585 break;
586 case 2:
587 # Early abort if the page doesn't exist
588 if ( !$this->mPage->exists() ) {
589 wfDebug( __METHOD__ . ": showing missing article\n" );
590 $this->showMissingArticle();
591 $this->mPage->doViewUpdates( $user );
592 return;
593 }
594
595 # Try the parser cache
596 if ( $useParserCache ) {
597 $this->mParserOutput = $parserCache->get( $this, $parserOptions );
598
599 if ( $this->mParserOutput !== false ) {
600 if ( $oldid ) {
601 wfDebug( __METHOD__ . ": showing parser cache contents for current rev permalink\n" );
602 $this->setOldSubtitle( $oldid );
603 } else {
604 wfDebug( __METHOD__ . ": showing parser cache contents\n" );
605 }
606 $outputPage->addParserOutput( $this->mParserOutput );
607 # Ensure that UI elements requiring revision ID have
608 # the correct version information.
609 $outputPage->setRevisionId( $this->mPage->getLatest() );
610 # Preload timestamp to avoid a DB hit
611 $cachedTimestamp = $this->mParserOutput->getTimestamp();
612 if ( $cachedTimestamp !== null ) {
613 $outputPage->setRevisionTimestamp( $cachedTimestamp );
614 $this->mPage->setTimestamp( $cachedTimestamp );
615 }
616 $outputDone = true;
617 }
618 }
619 break;
620 case 3:
621 # This will set $this->mRevision if needed
622 $this->fetchContentObject();
623
624 # Are we looking at an old revision
625 if ( $oldid && $this->mRevision ) {
626 $this->setOldSubtitle( $oldid );
627
628 if ( !$this->showDeletedRevisionHeader() ) {
629 wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
630 return;
631 }
632 }
633
634 # Ensure that UI elements requiring revision ID have
635 # the correct version information.
636 $outputPage->setRevisionId( $this->getRevIdFetched() );
637 # Preload timestamp to avoid a DB hit
638 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
639
640 # Pages containing custom CSS or JavaScript get special treatment
641 if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
642 wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
643 $this->showCssOrJsPage();
644 $outputDone = true;
645 } elseif ( !Hooks::run( 'ArticleContentViewCustom',
646 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
647
648 # Allow extensions do their own custom view for certain pages
649 $outputDone = true;
650 } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom',
651 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
652
653 # Allow extensions do their own custom view for certain pages
654 $outputDone = true;
655 }
656 break;
657 case 4:
658 # Run the parse, protected by a pool counter
659 wfDebug( __METHOD__ . ": doing uncached parse\n" );
660
661 $content = $this->getContentObject();
662 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
663 $this->getRevIdFetched(), $useParserCache, $content );
664
665 if ( !$poolArticleView->execute() ) {
666 $error = $poolArticleView->getError();
667 if ( $error ) {
668 $outputPage->clearHTML(); // for release() errors
669 $outputPage->enableClientCache( false );
670 $outputPage->setRobotPolicy( 'noindex,nofollow' );
671
672 $errortext = $error->getWikiText( false, 'view-pool-error' );
673 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
674 }
675 # Connection or timeout error
676 return;
677 }
678
679 $this->mParserOutput = $poolArticleView->getParserOutput();
680 $outputPage->addParserOutput( $this->mParserOutput );
681 if ( $content->getRedirectTarget() ) {
682 $outputPage->addSubtitle(
683 "<span id=\"redirectsub\">" . wfMessage( 'redirectpagesub' )->parse() . "</span>"
684 );
685 }
686
687 # Don't cache a dirty ParserOutput object
688 if ( $poolArticleView->getIsDirty() ) {
689 $outputPage->setSquidMaxage( 0 );
690 $outputPage->addHTML( "<!-- parser cache is expired, " .
691 "sending anyway due to pool overload-->\n" );
692 }
693
694 $outputDone = true;
695 break;
696 # Should be unreachable, but just in case...
697 default:
698 break 2;
699 }
700 }
701
702 # Get the ParserOutput actually *displayed* here.
703 # Note that $this->mParserOutput is the *current* version output.
704 $pOutput = ( $outputDone instanceof ParserOutput )
705 ? $outputDone // object fetched by hook
706 : $this->mParserOutput;
707
708 # Adjust title for main page & pages with displaytitle
709 if ( $pOutput ) {
710 $this->adjustDisplayTitle( $pOutput );
711 }
712
713 # For the main page, overwrite the <title> element with the con-
714 # tents of 'pagetitle-view-mainpage' instead of the default (if
715 # that's not empty).
716 # This message always exists because it is in the i18n files
717 if ( $this->getTitle()->isMainPage() ) {
718 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
719 if ( !$msg->isDisabled() ) {
720 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
721 }
722 }
723
724 # Check for any __NOINDEX__ tags on the page using $pOutput
725 $policy = $this->getRobotPolicy( 'view', $pOutput );
726 $outputPage->setIndexPolicy( $policy['index'] );
727 $outputPage->setFollowPolicy( $policy['follow'] );
728
729 $this->showViewFooter();
730 $this->mPage->doViewUpdates( $user, $oldid );
731
732 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
733
734 }
735
736 /**
737 * Adjust title for pages with displaytitle, -{T|}- or language conversion
738 * @param ParserOutput $pOutput
739 */
740 public function adjustDisplayTitle( ParserOutput $pOutput ) {
741 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
742 $titleText = $pOutput->getTitleText();
743 if ( strval( $titleText ) !== '' ) {
744 $this->getContext()->getOutput()->setPageTitle( $titleText );
745 }
746 }
747
748 /**
749 * Show a diff page according to current request variables. For use within
750 * Article::view() only, other callers should use the DifferenceEngine class.
751 *
752 * @todo Make protected
753 */
754 public function showDiffPage() {
755 $request = $this->getContext()->getRequest();
756 $user = $this->getContext()->getUser();
757 $diff = $request->getVal( 'diff' );
758 $rcid = $request->getVal( 'rcid' );
759 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
760 $purge = $request->getVal( 'action' ) == 'purge';
761 $unhide = $request->getInt( 'unhide' ) == 1;
762 $oldid = $this->getOldID();
763
764 $rev = $this->getRevisionFetched();
765
766 if ( !$rev ) {
767 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
768 $msg = $this->getContext()->msg( 'difference-missing-revision' )
769 ->params( $oldid )
770 ->numParams( 1 )
771 ->parseAsBlock();
772 $this->getContext()->getOutput()->addHtml( $msg );
773 return;
774 }
775
776 $contentHandler = $rev->getContentHandler();
777 $de = $contentHandler->createDifferenceEngine(
778 $this->getContext(),
779 $oldid,
780 $diff,
781 $rcid,
782 $purge,
783 $unhide
784 );
785
786 // DifferenceEngine directly fetched the revision:
787 $this->mRevIdFetched = $de->mNewid;
788 $de->showDiffPage( $diffOnly );
789
790 // Run view updates for the newer revision being diffed (and shown
791 // below the diff if not $diffOnly).
792 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
793 // New can be false, convert it to 0 - this conveniently means the latest revision
794 $this->mPage->doViewUpdates( $user, (int)$new );
795 }
796
797 /**
798 * Show a page view for a page formatted as CSS or JavaScript. To be called by
799 * Article::view() only.
800 *
801 * This exists mostly to serve the deprecated ShowRawCssJs hook (used to customize these views).
802 * It has been replaced by the ContentGetParserOutput hook, which lets you do the same but with
803 * more flexibility.
804 *
805 * @param bool $showCacheHint Whether to show a message telling the user
806 * to clear the browser cache (default: true).
807 */
808 protected function showCssOrJsPage( $showCacheHint = true ) {
809 $outputPage = $this->getContext()->getOutput();
810
811 if ( $showCacheHint ) {
812 $dir = $this->getContext()->getLanguage()->getDir();
813 $lang = $this->getContext()->getLanguage()->getHtmlCode();
814
815 $outputPage->wrapWikiMsg(
816 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
817 'clearyourcache'
818 );
819 }
820
821 $this->fetchContentObject();
822
823 if ( $this->mContentObject ) {
824 // Give hooks a chance to customise the output
825 if ( ContentHandler::runLegacyHooks(
826 'ShowRawCssJs',
827 array( $this->mContentObject, $this->getTitle(), $outputPage ) )
828 ) {
829 // If no legacy hooks ran, display the content of the parser output, including RL modules,
830 // but excluding metadata like categories and language links
831 $po = $this->mContentObject->getParserOutput( $this->getTitle() );
832 $outputPage->addParserOutputContent( $po );
833 }
834 }
835 }
836
837 /**
838 * Get the robot policy to be used for the current view
839 * @param string $action The action= GET parameter
840 * @param ParserOutput|null $pOutput
841 * @return array The policy that should be set
842 * @todo actions other than 'view'
843 */
844 public function getRobotPolicy( $action, $pOutput = null ) {
845 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
846
847 $ns = $this->getTitle()->getNamespace();
848
849 # Don't index user and user talk pages for blocked users (bug 11443)
850 if ( ( $ns == NS_USER || $ns == NS_USER_TALK ) && !$this->getTitle()->isSubpage() ) {
851 $specificTarget = null;
852 $vagueTarget = null;
853 $titleText = $this->getTitle()->getText();
854 if ( IP::isValid( $titleText ) ) {
855 $vagueTarget = $titleText;
856 } else {
857 $specificTarget = $titleText;
858 }
859 if ( Block::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block ) {
860 return array(
861 'index' => 'noindex',
862 'follow' => 'nofollow'
863 );
864 }
865 }
866
867 if ( $this->mPage->getID() === 0 || $this->getOldID() ) {
868 # Non-articles (special pages etc), and old revisions
869 return array(
870 'index' => 'noindex',
871 'follow' => 'nofollow'
872 );
873 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
874 # Discourage indexing of printable versions, but encourage following
875 return array(
876 'index' => 'noindex',
877 'follow' => 'follow'
878 );
879 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
880 # For ?curid=x urls, disallow indexing
881 return array(
882 'index' => 'noindex',
883 'follow' => 'follow'
884 );
885 }
886
887 # Otherwise, construct the policy based on the various config variables.
888 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
889
890 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
891 # Honour customised robot policies for this namespace
892 $policy = array_merge(
893 $policy,
894 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
895 );
896 }
897 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
898 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
899 # a final sanity check that we have really got the parser output.
900 $policy = array_merge(
901 $policy,
902 array( 'index' => $pOutput->getIndexPolicy() )
903 );
904 }
905
906 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
907 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
908 $policy = array_merge(
909 $policy,
910 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
911 );
912 }
913
914 return $policy;
915 }
916
917 /**
918 * Converts a String robot policy into an associative array, to allow
919 * merging of several policies using array_merge().
920 * @param array|string $policy Returns empty array on null/false/'', transparent
921 * to already-converted arrays, converts string.
922 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
923 */
924 public static function formatRobotPolicy( $policy ) {
925 if ( is_array( $policy ) ) {
926 return $policy;
927 } elseif ( !$policy ) {
928 return array();
929 }
930
931 $policy = explode( ',', $policy );
932 $policy = array_map( 'trim', $policy );
933
934 $arr = array();
935 foreach ( $policy as $var ) {
936 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
937 $arr['index'] = $var;
938 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
939 $arr['follow'] = $var;
940 }
941 }
942
943 return $arr;
944 }
945
946 /**
947 * If this request is a redirect view, send "redirected from" subtitle to
948 * the output. Returns true if the header was needed, false if this is not
949 * a redirect view. Handles both local and remote redirects.
950 *
951 * @return bool
952 */
953 public function showRedirectedFromHeader() {
954 global $wgRedirectSources;
955 $outputPage = $this->getContext()->getOutput();
956
957 $request = $this->getContext()->getRequest();
958 $rdfrom = $request->getVal( 'rdfrom' );
959
960 // Construct a URL for the current page view, but with the target title
961 $query = $request->getValues();
962 unset( $query['rdfrom'] );
963 unset( $query['title'] );
964 if ( $this->getTitle()->isRedirect() ) {
965 // Prevent double redirects
966 $query['redirect'] = 'no';
967 }
968 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
969
970 if ( isset( $this->mRedirectedFrom ) ) {
971 // This is an internally redirected page view.
972 // We'll need a backlink to the source page for navigation.
973 if ( Hooks::run( 'ArticleViewRedirect', array( &$this ) ) ) {
974 $redir = Linker::linkKnown(
975 $this->mRedirectedFrom,
976 null,
977 array(),
978 array( 'redirect' => 'no' )
979 );
980
981 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
982 wfMessage( 'redirectedfrom' )->rawParams( $redir )->parse()
983 . "</span>" );
984
985 // Add the script to update the displayed URL and
986 // set the fragment if one was specified in the redirect
987 $outputPage->addJsConfigVars( array(
988 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
989 ) );
990 $outputPage->addModules( 'mediawiki.action.view.redirect' );
991
992 // Add a <link rel="canonical"> tag
993 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
994
995 // Tell the output object that the user arrived at this article through a redirect
996 $outputPage->setRedirectedFrom( $this->mRedirectedFrom );
997
998 return true;
999 }
1000 } elseif ( $rdfrom ) {
1001 // This is an externally redirected view, from some other wiki.
1002 // If it was reported from a trusted site, supply a backlink.
1003 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1004 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
1005 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1006 wfMessage( 'redirectedfrom' )->rawParams( $redir )->parse()
1007 . "</span>" );
1008
1009 // Add the script to update the displayed URL
1010 $outputPage->addJsConfigVars( array(
1011 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1012 ) );
1013 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1014
1015 return true;
1016 }
1017 }
1018
1019 return false;
1020 }
1021
1022 /**
1023 * Show a header specific to the namespace currently being viewed, like
1024 * [[MediaWiki:Talkpagetext]]. For Article::view().
1025 */
1026 public function showNamespaceHeader() {
1027 if ( $this->getTitle()->isTalkPage() ) {
1028 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1029 $this->getContext()->getOutput()->wrapWikiMsg(
1030 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1031 array( 'talkpageheader' )
1032 );
1033 }
1034 }
1035 }
1036
1037 /**
1038 * Show the footer section of an ordinary page view
1039 */
1040 public function showViewFooter() {
1041 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1042 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1043 && IP::isValid( $this->getTitle()->getText() )
1044 ) {
1045 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1046 }
1047
1048 // Show a footer allowing the user to patrol the shown revision or page if possible
1049 $patrolFooterShown = $this->showPatrolFooter();
1050
1051 Hooks::run( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1052 }
1053
1054 /**
1055 * If patrol is possible, output a patrol UI box. This is called from the
1056 * footer section of ordinary page views. If patrol is not possible or not
1057 * desired, does nothing.
1058 * Side effect: When the patrol link is build, this method will call
1059 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1060 *
1061 * @return bool
1062 */
1063 public function showPatrolFooter() {
1064 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1065
1066 $outputPage = $this->getContext()->getOutput();
1067 $user = $this->getContext()->getUser();
1068 $cache = wfGetMainCache();
1069 $rc = false;
1070
1071 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1072 || !( $wgUseRCPatrol || $wgUseNPPatrol )
1073 ) {
1074 // Patrolling is disabled or the user isn't allowed to
1075 return false;
1076 }
1077
1078 // New page patrol: Get the timestamp of the oldest revison which
1079 // the revision table holds for the given page. Then we look
1080 // whether it's within the RC lifespan and if it is, we try
1081 // to get the recentchanges row belonging to that entry
1082 // (with rc_new = 1).
1083
1084 // Check for cached results
1085 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1086 return false;
1087 }
1088
1089 if ( $this->mRevision
1090 && !RecentChange::isInRCLifespan( $this->mRevision->getTimestamp(), 21600 )
1091 ) {
1092 // The current revision is already older than what could be in the RC table
1093 // 6h tolerance because the RC might not be cleaned out regularly
1094 return false;
1095 }
1096
1097 $dbr = wfGetDB( DB_SLAVE );
1098 $oldestRevisionTimestamp = $dbr->selectField(
1099 'revision',
1100 'MIN( rev_timestamp )',
1101 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1102 __METHOD__
1103 );
1104
1105 if ( $oldestRevisionTimestamp
1106 && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1107 ) {
1108 // 6h tolerance because the RC might not be cleaned out regularly
1109 $rc = RecentChange::newFromConds(
1110 array(
1111 'rc_new' => 1,
1112 'rc_timestamp' => $oldestRevisionTimestamp,
1113 'rc_namespace' => $this->getTitle()->getNamespace(),
1114 'rc_cur_id' => $this->getTitle()->getArticleID(),
1115 'rc_patrolled' => 0
1116 ),
1117 __METHOD__,
1118 array( 'USE INDEX' => 'new_name_timestamp' )
1119 );
1120 }
1121
1122 if ( !$rc ) {
1123 // No RC entry around
1124
1125 // Cache the information we gathered above in case we can't patrol
1126 // Don't cache in case we can patrol as this could change
1127 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1128
1129 return false;
1130 }
1131
1132 if ( $rc->getPerformer()->equals( $user ) ) {
1133 // Don't show a patrol link for own creations. If the user could
1134 // patrol them, they already would be patrolled
1135 return false;
1136 }
1137
1138 $rcid = $rc->getAttribute( 'rc_id' );
1139
1140 $token = $user->getEditToken( $rcid );
1141
1142 $outputPage->preventClickjacking();
1143 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1144 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1145 }
1146
1147 $link = Linker::linkKnown(
1148 $this->getTitle(),
1149 wfMessage( 'markaspatrolledtext' )->escaped(),
1150 array(),
1151 array(
1152 'action' => 'markpatrolled',
1153 'rcid' => $rcid,
1154 'token' => $token,
1155 )
1156 );
1157
1158 $outputPage->addHTML(
1159 "<div class='patrollink'>" .
1160 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1161 '</div>'
1162 );
1163
1164 return true;
1165 }
1166
1167 /**
1168 * Show the error text for a missing article. For articles in the MediaWiki
1169 * namespace, show the default message text. To be called from Article::view().
1170 */
1171 public function showMissingArticle() {
1172 global $wgSend404Code;
1173
1174 $outputPage = $this->getContext()->getOutput();
1175 // Whether the page is a root user page of an existing user (but not a subpage)
1176 $validUserPage = false;
1177
1178 $title = $this->getTitle();
1179
1180 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1181 if ( $title->getNamespace() == NS_USER
1182 || $title->getNamespace() == NS_USER_TALK
1183 ) {
1184 $parts = explode( '/', $title->getText() );
1185 $rootPart = $parts[0];
1186 $user = User::newFromName( $rootPart, false /* allow IP users*/ );
1187 $ip = User::isIP( $rootPart );
1188 $block = Block::newFromTarget( $user, $user );
1189
1190 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1191 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1192 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1193 } elseif ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) {
1194 # Show log extract if the user is currently blocked
1195 LogEventsList::showLogExtract(
1196 $outputPage,
1197 'block',
1198 MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
1199 '',
1200 array(
1201 'lim' => 1,
1202 'showIfEmpty' => false,
1203 'msgKey' => array(
1204 'blocked-notice-logextract',
1205 $user->getName() # Support GENDER in notice
1206 )
1207 )
1208 );
1209 $validUserPage = !$title->isSubpage();
1210 } else {
1211 $validUserPage = !$title->isSubpage();
1212 }
1213 }
1214
1215 Hooks::run( 'ShowMissingArticle', array( $this ) );
1216
1217 // Give extensions a chance to hide their (unrelated) log entries
1218 $logTypes = array( 'delete', 'move' );
1219 $conds = array( "log_action != 'revision'" );
1220 Hooks::run( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1221
1222 # Show delete and move logs
1223 LogEventsList::showLogExtract( $outputPage, $logTypes, $title, '',
1224 array( 'lim' => 10,
1225 'conds' => $conds,
1226 'showIfEmpty' => false,
1227 'msgKey' => array( 'moveddeleted-notice' ) )
1228 );
1229
1230 if ( !$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1231 // If there's no backing content, send a 404 Not Found
1232 // for better machine handling of broken links.
1233 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1234 }
1235
1236 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1237 $policy = $this->getRobotPolicy( 'view' );
1238 $outputPage->setIndexPolicy( $policy['index'] );
1239 $outputPage->setFollowPolicy( $policy['follow'] );
1240
1241 $hookResult = Hooks::run( 'BeforeDisplayNoArticleText', array( $this ) );
1242
1243 if ( !$hookResult ) {
1244 return;
1245 }
1246
1247 # Show error message
1248 $oldid = $this->getOldID();
1249 if ( $oldid ) {
1250 $text = wfMessage( 'missing-revision', $oldid )->plain();
1251 } elseif ( $title->getNamespace() === NS_MEDIAWIKI ) {
1252 // Use the default message text
1253 $text = $title->getDefaultMessageText();
1254 } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
1255 && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
1256 ) {
1257 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
1258 $text = wfMessage( $message )->plain();
1259 } else {
1260 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1261 }
1262 $text = "<div class='noarticletext'>\n$text\n</div>";
1263
1264 $outputPage->addWikiText( $text );
1265 }
1266
1267 /**
1268 * If the revision requested for view is deleted, check permissions.
1269 * Send either an error message or a warning header to the output.
1270 *
1271 * @return bool True if the view is allowed, false if not.
1272 */
1273 public function showDeletedRevisionHeader() {
1274 if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1275 // Not deleted
1276 return true;
1277 }
1278
1279 $outputPage = $this->getContext()->getOutput();
1280 $user = $this->getContext()->getUser();
1281 // If the user is not allowed to see it...
1282 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT, $user ) ) {
1283 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1284 'rev-deleted-text-permission' );
1285
1286 return false;
1287 // If the user needs to confirm that they want to see it...
1288 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1289 # Give explanation and add a link to view the revision...
1290 $oldid = intval( $this->getOldID() );
1291 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1292 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1293 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1294 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1295 array( $msg, $link ) );
1296
1297 return false;
1298 // We are allowed to see...
1299 } else {
1300 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1301 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1302 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1303
1304 return true;
1305 }
1306 }
1307
1308 /**
1309 * Generate the navigation links when browsing through an article revisions
1310 * It shows the information as:
1311 * Revision as of \<date\>; view current revision
1312 * \<- Previous version | Next Version -\>
1313 *
1314 * @param int $oldid Revision ID of this article revision
1315 */
1316 public function setOldSubtitle( $oldid = 0 ) {
1317 if ( !Hooks::run( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1318 return;
1319 }
1320
1321 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1322
1323 # Cascade unhide param in links for easy deletion browsing
1324 $extraParams = array();
1325 if ( $unhide ) {
1326 $extraParams['unhide'] = 1;
1327 }
1328
1329 if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
1330 $revision = $this->mRevision;
1331 } else {
1332 $revision = Revision::newFromId( $oldid );
1333 }
1334
1335 $timestamp = $revision->getTimestamp();
1336
1337 $current = ( $oldid == $this->mPage->getLatest() );
1338 $language = $this->getContext()->getLanguage();
1339 $user = $this->getContext()->getUser();
1340
1341 $td = $language->userTimeAndDate( $timestamp, $user );
1342 $tddate = $language->userDate( $timestamp, $user );
1343 $tdtime = $language->userTime( $timestamp, $user );
1344
1345 # Show user links if allowed to see them. If hidden, then show them only if requested...
1346 $userlinks = Linker::revUserTools( $revision, !$unhide );
1347
1348 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1349 ? 'revision-info-current'
1350 : 'revision-info';
1351
1352 $outputPage = $this->getContext()->getOutput();
1353 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" .
1354 wfMessage( $infomsg, $td )
1355 ->rawParams( $userlinks )
1356 ->params( $revision->getID(), $tddate, $tdtime, $revision->getUserText() )
1357 ->rawParams( Linker::revComment( $revision, true, true ) )
1358 ->parse() .
1359 "</div>"
1360 );
1361
1362 $lnk = $current
1363 ? wfMessage( 'currentrevisionlink' )->escaped()
1364 : Linker::linkKnown(
1365 $this->getTitle(),
1366 wfMessage( 'currentrevisionlink' )->escaped(),
1367 array(),
1368 $extraParams
1369 );
1370 $curdiff = $current
1371 ? wfMessage( 'diff' )->escaped()
1372 : Linker::linkKnown(
1373 $this->getTitle(),
1374 wfMessage( 'diff' )->escaped(),
1375 array(),
1376 array(
1377 'diff' => 'cur',
1378 'oldid' => $oldid
1379 ) + $extraParams
1380 );
1381 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1382 $prevlink = $prev
1383 ? Linker::linkKnown(
1384 $this->getTitle(),
1385 wfMessage( 'previousrevision' )->escaped(),
1386 array(),
1387 array(
1388 'direction' => 'prev',
1389 'oldid' => $oldid
1390 ) + $extraParams
1391 )
1392 : wfMessage( 'previousrevision' )->escaped();
1393 $prevdiff = $prev
1394 ? Linker::linkKnown(
1395 $this->getTitle(),
1396 wfMessage( 'diff' )->escaped(),
1397 array(),
1398 array(
1399 'diff' => 'prev',
1400 'oldid' => $oldid
1401 ) + $extraParams
1402 )
1403 : wfMessage( 'diff' )->escaped();
1404 $nextlink = $current
1405 ? wfMessage( 'nextrevision' )->escaped()
1406 : Linker::linkKnown(
1407 $this->getTitle(),
1408 wfMessage( 'nextrevision' )->escaped(),
1409 array(),
1410 array(
1411 'direction' => 'next',
1412 'oldid' => $oldid
1413 ) + $extraParams
1414 );
1415 $nextdiff = $current
1416 ? wfMessage( 'diff' )->escaped()
1417 : Linker::linkKnown(
1418 $this->getTitle(),
1419 wfMessage( 'diff' )->escaped(),
1420 array(),
1421 array(
1422 'diff' => 'next',
1423 'oldid' => $oldid
1424 ) + $extraParams
1425 );
1426
1427 $cdel = Linker::getRevDeleteLink( $user, $revision, $this->getTitle() );
1428 if ( $cdel !== '' ) {
1429 $cdel .= ' ';
1430 }
1431
1432 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1433 wfMessage( 'revision-nav' )->rawParams(
1434 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1435 )->escaped() . "</div>" );
1436 }
1437
1438 /**
1439 * Return the HTML for the top of a redirect page
1440 *
1441 * Chances are you should just be using the ParserOutput from
1442 * WikitextContent::getParserOutput instead of calling this for redirects.
1443 *
1444 * @param Title|array $target Destination(s) to redirect
1445 * @param bool $appendSubtitle [optional]
1446 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1447 * @return string Containing HTML with redirect link
1448 */
1449 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1450 $lang = $this->getTitle()->getPageLanguage();
1451 $out = $this->getContext()->getOutput();
1452 if ( $appendSubtitle ) {
1453 $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
1454 }
1455 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1456 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1457 }
1458
1459 /**
1460 * Return the HTML for the top of a redirect page
1461 *
1462 * Chances are you should just be using the ParserOutput from
1463 * WikitextContent::getParserOutput instead of calling this for redirects.
1464 *
1465 * @since 1.23
1466 * @param Language $lang
1467 * @param Title|array $target Destination(s) to redirect
1468 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1469 * @return string Containing HTML with redirect link
1470 */
1471 public static function getRedirectHeaderHtml( Language $lang, $target, $forceKnown = false ) {
1472 if ( !is_array( $target ) ) {
1473 $target = array( $target );
1474 }
1475
1476 $html = '<ul class="redirectText">';
1477 /** @var Title $title */
1478 foreach ( $target as $title ) {
1479 $html .= '<li>' . Linker::link(
1480 $title,
1481 htmlspecialchars( $title->getFullText() ),
1482 array(),
1483 // Automatically append redirect=no to each link, since most of them are
1484 // redirect pages themselves.
1485 array( 'redirect' => 'no' ),
1486 ( $forceKnown ? array( 'known', 'noclasses' ) : array() )
1487 ) . '</li>';
1488 }
1489
1490 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->text();
1491
1492 return '<div class="redirectMsg">' .
1493 '<p>' . $redirectToText . '</p>' .
1494 $html .
1495 '</div>';
1496 }
1497
1498 /**
1499 * Handle action=render
1500 */
1501 public function render() {
1502 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1503 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1504 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1505 $this->view();
1506 }
1507
1508 /**
1509 * action=protect handler
1510 */
1511 public function protect() {
1512 $form = new ProtectionForm( $this );
1513 $form->execute();
1514 }
1515
1516 /**
1517 * action=unprotect handler (alias)
1518 */
1519 public function unprotect() {
1520 $this->protect();
1521 }
1522
1523 /**
1524 * UI entry point for page deletion
1525 */
1526 public function delete() {
1527 # This code desperately needs to be totally rewritten
1528
1529 $title = $this->getTitle();
1530 $context = $this->getContext();
1531 $user = $context->getUser();
1532
1533 # Check permissions
1534 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1535 if ( count( $permissionErrors ) ) {
1536 throw new PermissionsError( 'delete', $permissionErrors );
1537 }
1538
1539 # Read-only check...
1540 if ( wfReadOnly() ) {
1541 throw new ReadOnlyError;
1542 }
1543
1544 # Better double-check that it hasn't been deleted yet!
1545 $this->mPage->loadPageData( 'fromdbmaster' );
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 array( '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 $request = $context->getRequest();
1566 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1567 $deleteReason = $request->getText( 'wpReason' );
1568
1569 if ( $deleteReasonList == 'other' ) {
1570 $reason = $deleteReason;
1571 } elseif ( $deleteReason != '' ) {
1572 // Entry from drop down menu + additional comment
1573 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1574 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1575 } else {
1576 $reason = $deleteReasonList;
1577 }
1578
1579 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1580 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1581 ) {
1582 # Flag to hide all contents of the archived revisions
1583 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1584
1585 $this->doDelete( $reason, $suppress );
1586
1587 WatchAction::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1588
1589 return;
1590 }
1591
1592 // Generate deletion reason
1593 $hasHistory = false;
1594 if ( !$reason ) {
1595 try {
1596 $reason = $this->generateReason( $hasHistory );
1597 } catch ( Exception $e ) {
1598 # if a page is horribly broken, we still want to be able to
1599 # delete it. So be lenient about errors here.
1600 wfDebug( "Error while building auto delete summary: $e" );
1601 $reason = '';
1602 }
1603 }
1604
1605 // If the page has a history, insert a warning
1606 if ( $hasHistory ) {
1607 $title = $this->getTitle();
1608
1609 // The following can use the real revision count as this is only being shown for users
1610 // that can delete this page.
1611 // This, as a side-effect, also makes sure that the following query isn't being run for
1612 // pages with a larger history, unless the user has the 'bigdelete' right
1613 // (and is about to delete this page).
1614 $dbr = wfGetDB( DB_SLAVE );
1615 $revisions = $edits = (int)$dbr->selectField(
1616 'revision',
1617 'COUNT(rev_page)',
1618 array( 'rev_page' => $title->getArticleID() ),
1619 __METHOD__
1620 );
1621
1622 // @todo FIXME: i18n issue/patchwork message
1623 $context->getOutput()->addHTML(
1624 '<strong class="mw-delete-warning-revisions">' .
1625 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1626 $context->msg( 'word-separator' )->escaped() . Linker::linkKnown( $title,
1627 $context->msg( 'history' )->escaped(),
1628 array( 'rel' => 'archives' ),
1629 array( 'action' => 'history' ) ) .
1630 '</strong>'
1631 );
1632
1633 if ( $title->isBigDeletion() ) {
1634 global $wgDeleteRevisionsLimit;
1635 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1636 array(
1637 'delete-warning-toobig',
1638 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1639 )
1640 );
1641 }
1642 }
1643
1644 $this->confirmDelete( $reason );
1645 }
1646
1647 /**
1648 * Output deletion confirmation dialog
1649 * @todo FIXME: Move to another file?
1650 * @param string $reason Prefilled reason
1651 */
1652 public function confirmDelete( $reason ) {
1653 wfDebug( "Article::confirmDelete\n" );
1654
1655 $title = $this->getTitle();
1656 $ctx = $this->getContext();
1657 $outputPage = $ctx->getOutput();
1658 $useMediaWikiUIEverywhere = $ctx->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1659 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1660 $outputPage->addBacklinkSubtitle( $title );
1661 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1662 $backlinkCache = $title->getBacklinkCache();
1663 if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
1664 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1665 'deleting-backlinks-warning' );
1666 }
1667 $outputPage->addWikiMsg( 'confirmdeletetext' );
1668
1669 Hooks::run( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1670
1671 $user = $this->getContext()->getUser();
1672
1673 if ( $user->isAllowed( 'suppressrevision' ) ) {
1674 $suppress = Html::openElement( 'div', array( 'id' => 'wpDeleteSuppressRow' ) ) .
1675 "<strong>" .
1676 Xml::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1677 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1678 "</strong>" .
1679 Html::closeElement( 'div' );
1680 } else {
1681 $suppress = '';
1682 }
1683 $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $title );
1684
1685 $form = Html::openElement( 'form', array( 'method' => 'post',
1686 'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1687 Html::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1688 Html::element( 'legend', null, wfMessage( 'delete-legend' )->text() ) .
1689 Html::openElement( 'div', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1690 Html::openElement( 'div', array( 'id' => 'wpDeleteReasonListRow' ) ) .
1691 Html::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1692 '&nbsp;' .
1693 Xml::listDropDown(
1694 'wpDeleteReasonList',
1695 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1696 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1697 '',
1698 'wpReasonDropDown',
1699 1
1700 ) .
1701 Html::closeElement( 'div' ) .
1702 Html::openElement( 'div', array( 'id' => 'wpDeleteReasonRow' ) ) .
1703 Html::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1704 '&nbsp;' .
1705 Html::input( 'wpReason', $reason, 'text', array(
1706 'size' => '60',
1707 'maxlength' => '255',
1708 'tabindex' => '2',
1709 'id' => 'wpReason',
1710 'class' => 'mw-ui-input-inline',
1711 'autofocus'
1712 ) ) .
1713 Html::closeElement( 'div' );
1714
1715 # Disallow watching if user is not logged in
1716 if ( $user->isLoggedIn() ) {
1717 $form .=
1718 Xml::checkLabel( wfMessage( 'watchthis' )->text(),
1719 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) );
1720 }
1721
1722 $form .=
1723 Html::openElement( 'div' ) .
1724 $suppress .
1725 Xml::submitButton( wfMessage( 'deletepage' )->text(),
1726 array(
1727 'name' => 'wpConfirmB',
1728 'id' => 'wpConfirmB',
1729 'tabindex' => '5',
1730 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button mw-ui-destructive' : '',
1731 )
1732 ) .
1733 Html::closeElement( 'div' ) .
1734 Html::closeElement( 'div' ) .
1735 Xml::closeElement( 'fieldset' ) .
1736 Html::hidden(
1737 'wpEditToken',
1738 $user->getEditToken( array( 'delete', $title->getPrefixedText() ) )
1739 ) .
1740 Xml::closeElement( 'form' );
1741
1742 if ( $user->isAllowed( 'editinterface' ) ) {
1743 $dropdownTitle = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
1744 $link = Linker::link(
1745 $dropdownTitle,
1746 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1747 array(),
1748 array( 'action' => 'edit' )
1749 );
1750 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1751 }
1752
1753 $outputPage->addHTML( $form );
1754
1755 $deleteLogPage = new LogPage( 'delete' );
1756 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1757 LogEventsList::showLogExtract( $outputPage, 'delete', $title );
1758 }
1759
1760 /**
1761 * Perform a deletion and output success or failure messages
1762 * @param string $reason
1763 * @param bool $suppress
1764 */
1765 public function doDelete( $reason, $suppress = false ) {
1766 $error = '';
1767 $outputPage = $this->getContext()->getOutput();
1768 $status = $this->mPage->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1769
1770 if ( $status->isGood() ) {
1771 $deleted = $this->getTitle()->getPrefixedText();
1772
1773 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1774 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1775
1776 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1777
1778 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1779
1780 Hooks::run( 'ArticleDeleteAfterSuccess', array( $this->getTitle(), $outputPage ) );
1781
1782 $outputPage->returnToMain( false );
1783 } else {
1784 $outputPage->setPageTitle(
1785 wfMessage( 'cannotdelete-title',
1786 $this->getTitle()->getPrefixedText() )
1787 );
1788
1789 if ( $error == '' ) {
1790 $outputPage->addWikiText(
1791 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1792 );
1793 $deleteLogPage = new LogPage( 'delete' );
1794 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1795
1796 LogEventsList::showLogExtract(
1797 $outputPage,
1798 'delete',
1799 $this->getTitle()
1800 );
1801 } else {
1802 $outputPage->addHTML( $error );
1803 }
1804 }
1805 }
1806
1807 /* Caching functions */
1808
1809 /**
1810 * checkLastModified returns true if it has taken care of all
1811 * output to the client that is necessary for this request.
1812 * (that is, it has sent a cached version of the page)
1813 *
1814 * @return bool True if cached version send, false otherwise
1815 */
1816 protected function tryFileCache() {
1817 static $called = false;
1818
1819 if ( $called ) {
1820 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1821 return false;
1822 }
1823
1824 $called = true;
1825 if ( $this->isFileCacheable() ) {
1826 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
1827 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1828 wfDebug( "Article::tryFileCache(): about to load file\n" );
1829 $cache->loadFromFileCache( $this->getContext() );
1830 return true;
1831 } else {
1832 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1833 ob_start( array( &$cache, 'saveToFileCache' ) );
1834 }
1835 } else {
1836 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1837 }
1838
1839 return false;
1840 }
1841
1842 /**
1843 * Check if the page can be cached
1844 * @return bool
1845 */
1846 public function isFileCacheable() {
1847 $cacheable = false;
1848
1849 if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
1850 $cacheable = $this->mPage->getID()
1851 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
1852 // Extension may have reason to disable file caching on some pages.
1853 if ( $cacheable ) {
1854 $cacheable = Hooks::run( 'IsFileCacheable', array( &$this ) );
1855 }
1856 }
1857
1858 return $cacheable;
1859 }
1860
1861 /**#@-*/
1862
1863 /**
1864 * Lightweight method to get the parser output for a page, checking the parser cache
1865 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1866 * consider, so it's not appropriate to use there.
1867 *
1868 * @since 1.16 (r52326) for LiquidThreads
1869 *
1870 * @param int|null $oldid Revision ID or null
1871 * @param User $user The relevant user
1872 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1873 */
1874 public function getParserOutput( $oldid = null, User $user = null ) {
1875 //XXX: bypasses mParserOptions and thus setParserOptions()
1876
1877 if ( $user === null ) {
1878 $parserOptions = $this->getParserOptions();
1879 } else {
1880 $parserOptions = $this->mPage->makeParserOptions( $user );
1881 }
1882
1883 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1884 }
1885
1886 /**
1887 * Override the ParserOptions used to render the primary article wikitext.
1888 *
1889 * @param ParserOptions $options
1890 * @throws MWException If the parser options where already initialized.
1891 */
1892 public function setParserOptions( ParserOptions $options ) {
1893 if ( $this->mParserOptions ) {
1894 throw new MWException( "can't change parser options after they have already been set" );
1895 }
1896
1897 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1898 $this->mParserOptions = clone $options;
1899 }
1900
1901 /**
1902 * Get parser options suitable for rendering the primary article wikitext
1903 * @return ParserOptions
1904 */
1905 public function getParserOptions() {
1906 if ( !$this->mParserOptions ) {
1907 $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
1908 }
1909 // Clone to allow modifications of the return value without affecting cache
1910 return clone $this->mParserOptions;
1911 }
1912
1913 /**
1914 * Sets the context this Article is executed in
1915 *
1916 * @param IContextSource $context
1917 * @since 1.18
1918 */
1919 public function setContext( $context ) {
1920 $this->mContext = $context;
1921 }
1922
1923 /**
1924 * Gets the context this Article is executed in
1925 *
1926 * @return IContextSource
1927 * @since 1.18
1928 */
1929 public function getContext() {
1930 if ( $this->mContext instanceof IContextSource ) {
1931 return $this->mContext;
1932 } else {
1933 wfDebug( __METHOD__ . " called and \$mContext is null. " .
1934 "Return RequestContext::getMain(); for sanity\n" );
1935 return RequestContext::getMain();
1936 }
1937 }
1938
1939 /**
1940 * Use PHP's magic __get handler to handle accessing of
1941 * raw WikiPage fields for backwards compatibility.
1942 *
1943 * @param string $fname Field name
1944 * @return mixed
1945 */
1946 public function __get( $fname ) {
1947 if ( property_exists( $this->mPage, $fname ) ) {
1948 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1949 return $this->mPage->$fname;
1950 }
1951 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
1952 }
1953
1954 /**
1955 * Use PHP's magic __set handler to handle setting of
1956 * raw WikiPage fields for backwards compatibility.
1957 *
1958 * @param string $fname Field name
1959 * @param mixed $fvalue New value
1960 */
1961 public function __set( $fname, $fvalue ) {
1962 if ( property_exists( $this->mPage, $fname ) ) {
1963 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1964 $this->mPage->$fname = $fvalue;
1965 // Note: extensions may want to toss on new fields
1966 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1967 $this->mPage->$fname = $fvalue;
1968 } else {
1969 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
1970 }
1971 }
1972
1973 /**
1974 * Use PHP's magic __call handler to transform instance calls to
1975 * WikiPage functions for backwards compatibility.
1976 *
1977 * @param string $fname Name of called method
1978 * @param array $args Arguments to the method
1979 * @return mixed
1980 */
1981 public function __call( $fname, $args ) {
1982 if ( is_callable( array( $this->mPage, $fname ) ) ) {
1983 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1984 return call_user_func_array( array( $this->mPage, $fname ), $args );
1985 }
1986 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR );
1987 }
1988
1989 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1990
1991 /**
1992 * @param array $limit
1993 * @param array $expiry
1994 * @param bool $cascade
1995 * @param string $reason
1996 * @param User $user
1997 * @return Status
1998 */
1999 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2000 $reason, User $user
2001 ) {
2002 return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2003 }
2004
2005 /**
2006 * @param array $limit
2007 * @param string $reason
2008 * @param int $cascade
2009 * @param array $expiry
2010 * @return bool
2011 */
2012 public function updateRestrictions( $limit = array(), $reason = '',
2013 &$cascade = 0, $expiry = array()
2014 ) {
2015 return $this->mPage->doUpdateRestrictions(
2016 $limit,
2017 $expiry,
2018 $cascade,
2019 $reason,
2020 $this->getContext()->getUser()
2021 );
2022 }
2023
2024 /**
2025 * @param string $reason
2026 * @param bool $suppress
2027 * @param int $id
2028 * @param bool $commit
2029 * @param string $error
2030 * @return bool
2031 */
2032 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2033 $commit = true, &$error = ''
2034 ) {
2035 return $this->mPage->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2036 }
2037
2038 /**
2039 * @param string $fromP
2040 * @param string $summary
2041 * @param string $token
2042 * @param bool $bot
2043 * @param array $resultDetails
2044 * @param User|null $user
2045 * @return array
2046 */
2047 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user = null ) {
2048 $user = is_null( $user ) ? $this->getContext()->getUser() : $user;
2049 return $this->mPage->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2050 }
2051
2052 /**
2053 * @param string $fromP
2054 * @param string $summary
2055 * @param bool $bot
2056 * @param array $resultDetails
2057 * @param User|null $guser
2058 * @return array
2059 */
2060 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser = null ) {
2061 $guser = is_null( $guser ) ? $this->getContext()->getUser() : $guser;
2062 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2063 }
2064
2065 /**
2066 * @param bool $hasHistory
2067 * @return mixed
2068 */
2069 public function generateReason( &$hasHistory ) {
2070 $title = $this->mPage->getTitle();
2071 $handler = ContentHandler::getForTitle( $title );
2072 return $handler->getAutoDeleteReason( $title, $hasHistory );
2073 }
2074
2075 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2076
2077 /**
2078 * @return array
2079 *
2080 * @deprecated since 1.24, use WikiPage::selectFields() instead
2081 */
2082 public static function selectFields() {
2083 wfDeprecated( __METHOD__, '1.24' );
2084 return WikiPage::selectFields();
2085 }
2086
2087 /**
2088 * @param Title $title
2089 *
2090 * @deprecated since 1.24, use WikiPage::onArticleCreate() instead
2091 */
2092 public static function onArticleCreate( $title ) {
2093 wfDeprecated( __METHOD__, '1.24' );
2094 WikiPage::onArticleCreate( $title );
2095 }
2096
2097 /**
2098 * @param Title $title
2099 *
2100 * @deprecated since 1.24, use WikiPage::onArticleDelete() instead
2101 */
2102 public static function onArticleDelete( $title ) {
2103 wfDeprecated( __METHOD__, '1.24' );
2104 WikiPage::onArticleDelete( $title );
2105 }
2106
2107 /**
2108 * @param Title $title
2109 *
2110 * @deprecated since 1.24, use WikiPage::onArticleEdit() instead
2111 */
2112 public static function onArticleEdit( $title ) {
2113 wfDeprecated( __METHOD__, '1.24' );
2114 WikiPage::onArticleEdit( $title );
2115 }
2116
2117 /**
2118 * @param string $oldtext
2119 * @param string $newtext
2120 * @param int $flags
2121 * @return string
2122 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2123 */
2124 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2125 return WikiPage::getAutosummary( $oldtext, $newtext, $flags );
2126 }
2127 // ******
2128 }