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