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