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