d45b3322bd09f537fa50b68f41e2de69903dbf71
[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|false $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 $oldId Integer 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 $context IContextSource
152 * @return Article object
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 $page WikiPage
183 * @param $context IContextSource
184 * @return Article object
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 $from Title object.
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 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 in 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
294 * current revision
295 */
296 public function getOldID() {
297 if ( is_null( $this->mOldId ) ) {
298 $this->mOldId = $this->getOldIDFromRequest();
299 }
300
301 return $this->mOldId;
302 }
303
304 /**
305 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
306 *
307 * @return int The old id for the request
308 */
309 public function getOldIDFromRequest() {
310 $this->mRedirectUrl = false;
311
312 $request = $this->getContext()->getRequest();
313 $oldid = $request->getIntOrNull( 'oldid' );
314
315 if ( $oldid === null ) {
316 return 0;
317 }
318
319 if ( $oldid !== 0 ) {
320 # Load the given revision and check whether the page is another one.
321 # In that case, update this instance to reflect the change.
322 if ( $oldid === $this->mPage->getLatest() ) {
323 $this->mRevision = $this->mPage->getRevision();
324 } else {
325 $this->mRevision = Revision::newFromId( $oldid );
326 if ( $this->mRevision !== null ) {
327 // Revision title doesn't match the page title given?
328 if ( $this->mPage->getID() != $this->mRevision->getPage() ) {
329 $function = array( get_class( $this->mPage ), 'newFromID' );
330 $this->mPage = call_user_func( $function, $this->mRevision->getPage() );
331 }
332 }
333 }
334 }
335
336 if ( $request->getVal( 'direction' ) == 'next' ) {
337 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
338 if ( $nextid ) {
339 $oldid = $nextid;
340 $this->mRevision = null;
341 } else {
342 $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
343 }
344 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
345 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
346 if ( $previd ) {
347 $oldid = $previd;
348 $this->mRevision = null;
349 }
350 }
351
352 return $oldid;
353 }
354
355 /**
356 * Load the revision (including text) into this object
357 *
358 * @deprecated in 1.19; use fetchContent()
359 */
360 function loadContent() {
361 wfDeprecated( __METHOD__, '1.19' );
362 $this->fetchContent();
363 }
364
365 /**
366 * Get text of an article from database
367 * Does *NOT* follow redirects.
368 *
369 * @protected
370 * @note This is really internal functionality that should really NOT be
371 * used by other functions. For accessing article content, use the WikiPage
372 * class, especially WikiBase::getContent(). However, a lot of legacy code
373 * uses this method to retrieve page text from the database, so the function
374 * has to remain public for now.
375 *
376 * @return mixed string containing article contents, or false if null
377 * @deprecated in 1.21, use WikiPage::getContent() instead
378 */
379 function fetchContent() { #BC cruft!
380 ContentHandler::deprecated( __METHOD__, '1.21' );
381
382 if ( $this->mContentLoaded && $this->mContent ) {
383 return $this->mContent;
384 }
385
386 wfProfileIn( __METHOD__ );
387
388 $content = $this->fetchContentObject();
389
390 // @todo Get rid of mContent everywhere!
391 $this->mContent = ContentHandler::getContentText( $content );
392 ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
393
394 wfProfileOut( __METHOD__ );
395
396 return $this->mContent;
397 }
398
399 /**
400 * Get text content object
401 * Does *NOT* follow redirects.
402 * @todo When is this null?
403 *
404 * @note Code that wants to retrieve page content from the database should
405 * use WikiPage::getContent().
406 *
407 * @return Content|null|boolean false
408 *
409 * @since 1.21
410 */
411 protected function fetchContentObject() {
412 if ( $this->mContentLoaded ) {
413 return $this->mContentObject;
414 }
415
416 wfProfileIn( __METHOD__ );
417
418 $this->mContentLoaded = true;
419 $this->mContent = null;
420
421 $oldid = $this->getOldID();
422
423 # Pre-fill content with error message so that if something
424 # fails we'll have something telling us what we intended.
425 //XXX: this isn't page content but a UI message. horrible.
426 $this->mContentObject = new MessageContent( 'missing-revision', array( $oldid ), array() );
427
428 if ( $oldid ) {
429 # $this->mRevision might already be fetched by getOldIDFromRequest()
430 if ( !$this->mRevision ) {
431 $this->mRevision = Revision::newFromId( $oldid );
432 if ( !$this->mRevision ) {
433 wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
434 wfProfileOut( __METHOD__ );
435 return false;
436 }
437 }
438 } else {
439 if ( !$this->mPage->getLatest() ) {
440 wfDebug( __METHOD__ . " failed to find page data for title " .
441 $this->getTitle()->getPrefixedText() . "\n" );
442 wfProfileOut( __METHOD__ );
443 return false;
444 }
445
446 $this->mRevision = $this->mPage->getRevision();
447
448 if ( !$this->mRevision ) {
449 wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " .
450 $this->mPage->getLatest() . "\n" );
451 wfProfileOut( __METHOD__ );
452 return false;
453 }
454 }
455
456 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
457 // We should instead work with the Revision object when we need it...
458 // Loads if user is allowed
459 $this->mContentObject = $this->mRevision->getContent(
460 Revision::FOR_THIS_USER,
461 $this->getContext()->getUser()
462 );
463 $this->mRevIdFetched = $this->mRevision->getId();
464
465 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject ) );
466
467 wfProfileOut( __METHOD__ );
468
469 return $this->mContentObject;
470 }
471
472 /**
473 * Returns true if the currently-referenced revision is the current edit
474 * to this page (and it exists).
475 * @return bool
476 */
477 public function isCurrent() {
478 # If no oldid, this is the current version.
479 if ( $this->getOldID() == 0 ) {
480 return true;
481 }
482
483 return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
484 }
485
486 /**
487 * Get the fetched Revision object depending on request parameters or null
488 * on failure.
489 *
490 * @since 1.19
491 * @return Revision|null
492 */
493 public function getRevisionFetched() {
494 $this->fetchContentObject();
495
496 return $this->mRevision;
497 }
498
499 /**
500 * Use this to fetch the rev ID used on page views
501 *
502 * @return int revision ID of last article revision
503 */
504 public function getRevIdFetched() {
505 if ( $this->mRevIdFetched ) {
506 return $this->mRevIdFetched;
507 } else {
508 return $this->mPage->getLatest();
509 }
510 }
511
512 /**
513 * This is the default action of the index.php entry point: just view the
514 * page of the given title.
515 */
516 public function view() {
517 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
518
519 wfProfileIn( __METHOD__ );
520
521 # Get variables from query string
522 # As side effect this will load the revision and update the title
523 # in a revision ID is passed in the request, so this should remain
524 # the first call of this method even if $oldid is used way below.
525 $oldid = $this->getOldID();
526
527 $user = $this->getContext()->getUser();
528 # Another whitelist check in case getOldID() is altering the title
529 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
530 if ( count( $permErrors ) ) {
531 wfDebug( __METHOD__ . ": denied on secondary read check\n" );
532 wfProfileOut( __METHOD__ );
533 throw new PermissionsError( 'read', $permErrors );
534 }
535
536 $outputPage = $this->getContext()->getOutput();
537 # getOldID() may as well want us to redirect somewhere else
538 if ( $this->mRedirectUrl ) {
539 $outputPage->redirect( $this->mRedirectUrl );
540 wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
541 wfProfileOut( __METHOD__ );
542
543 return;
544 }
545
546 # If we got diff in the query, we want to see a diff page instead of the article.
547 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
548 wfDebug( __METHOD__ . ": showing diff page\n" );
549 $this->showDiffPage();
550 wfProfileOut( __METHOD__ );
551
552 return;
553 }
554
555 # Set page title (may be overridden by DISPLAYTITLE)
556 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
557
558 $outputPage->setArticleFlag( true );
559 # Allow frames by default
560 $outputPage->allowClickjacking();
561
562 $parserCache = ParserCache::singleton();
563
564 $parserOptions = $this->getParserOptions();
565 # Render printable version, use printable version cache
566 if ( $outputPage->isPrintable() ) {
567 $parserOptions->setIsPrintable( true );
568 $parserOptions->setEditSection( false );
569 } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user ) ) {
570 $parserOptions->setEditSection( false );
571 }
572
573 # Try client and file cache
574 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
575 if ( $wgUseETag ) {
576 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
577 }
578
579 # Is it client cached?
580 if ( $outputPage->checkLastModified( $this->mPage->getTouched() ) ) {
581 wfDebug( __METHOD__ . ": done 304\n" );
582 wfProfileOut( __METHOD__ );
583
584 return;
585 # Try file cache
586 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
587 wfDebug( __METHOD__ . ": done file cache\n" );
588 # tell wgOut that output is taken care of
589 $outputPage->disable();
590 $this->mPage->doViewUpdates( $user, $oldid );
591 wfProfileOut( __METHOD__ );
592
593 return;
594 }
595 }
596
597 # Should the parser cache be used?
598 $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid );
599 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
600 if ( $user->getStubThreshold() ) {
601 wfIncrStats( 'pcache_miss_stub' );
602 }
603
604 $this->showRedirectedFromHeader();
605 $this->showNamespaceHeader();
606
607 # Iterate through the possible ways of constructing the output text.
608 # Keep going until $outputDone is set, or we run out of things to do.
609 $pass = 0;
610 $outputDone = false;
611 $this->mParserOutput = false;
612
613 while ( !$outputDone && ++$pass ) {
614 switch ( $pass ) {
615 case 1:
616 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
617 break;
618 case 2:
619 # Early abort if the page doesn't exist
620 if ( !$this->mPage->exists() ) {
621 wfDebug( __METHOD__ . ": showing missing article\n" );
622 $this->showMissingArticle();
623 $this->mPage->doViewUpdates( $user );
624 wfProfileOut( __METHOD__ );
625 return;
626 }
627
628 # Try the parser cache
629 if ( $useParserCache ) {
630 $this->mParserOutput = $parserCache->get( $this, $parserOptions );
631
632 if ( $this->mParserOutput !== false ) {
633 if ( $oldid ) {
634 wfDebug( __METHOD__ . ": showing parser cache contents for current rev permalink\n" );
635 $this->setOldSubtitle( $oldid );
636 } else {
637 wfDebug( __METHOD__ . ": showing parser cache contents\n" );
638 }
639 $outputPage->addParserOutput( $this->mParserOutput );
640 # Ensure that UI elements requiring revision ID have
641 # the correct version information.
642 $outputPage->setRevisionId( $this->mPage->getLatest() );
643 # Preload timestamp to avoid a DB hit
644 $cachedTimestamp = $this->mParserOutput->getTimestamp();
645 if ( $cachedTimestamp !== null ) {
646 $outputPage->setRevisionTimestamp( $cachedTimestamp );
647 $this->mPage->setTimestamp( $cachedTimestamp );
648 }
649 $outputDone = true;
650 }
651 }
652 break;
653 case 3:
654 # This will set $this->mRevision if needed
655 $this->fetchContentObject();
656
657 # Are we looking at an old revision
658 if ( $oldid && $this->mRevision ) {
659 $this->setOldSubtitle( $oldid );
660
661 if ( !$this->showDeletedRevisionHeader() ) {
662 wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
663 wfProfileOut( __METHOD__ );
664 return;
665 }
666 }
667
668 # Ensure that UI elements requiring revision ID have
669 # the correct version information.
670 $outputPage->setRevisionId( $this->getRevIdFetched() );
671 # Preload timestamp to avoid a DB hit
672 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
673
674 # Pages containing custom CSS or JavaScript get special treatment
675 if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
676 wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
677 $this->showCssOrJsPage();
678 $outputDone = true;
679 } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
680 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
681
682 # Allow extensions do their own custom view for certain pages
683 $outputDone = true;
684 } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom',
685 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
686
687 # Allow extensions do their own custom view for certain pages
688 $outputDone = true;
689 }
690 break;
691 case 4:
692 # Run the parse, protected by a pool counter
693 wfDebug( __METHOD__ . ": doing uncached parse\n" );
694
695 $content = $this->getContentObject();
696 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
697 $this->getRevIdFetched(), $useParserCache, $content );
698
699 if ( !$poolArticleView->execute() ) {
700 $error = $poolArticleView->getError();
701 if ( $error ) {
702 $outputPage->clearHTML(); // for release() errors
703 $outputPage->enableClientCache( false );
704 $outputPage->setRobotPolicy( 'noindex,nofollow' );
705
706 $errortext = $error->getWikiText( false, 'view-pool-error' );
707 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
708 }
709 # Connection or timeout error
710 wfProfileOut( __METHOD__ );
711 return;
712 }
713
714 $this->mParserOutput = $poolArticleView->getParserOutput();
715 $outputPage->addParserOutput( $this->mParserOutput );
716 if ( $content->getRedirectTarget() ) {
717 $outputPage->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
718 }
719
720 # Don't cache a dirty ParserOutput object
721 if ( $poolArticleView->getIsDirty() ) {
722 $outputPage->setSquidMaxage( 0 );
723 $outputPage->addHTML( "<!-- parser cache is expired, " .
724 "sending anyway due to pool overload-->\n" );
725 }
726
727 $outputDone = true;
728 break;
729 # Should be unreachable, but just in case...
730 default:
731 break 2;
732 }
733 }
734
735 # Get the ParserOutput actually *displayed* here.
736 # Note that $this->mParserOutput is the *current* version output.
737 $pOutput = ( $outputDone instanceof ParserOutput )
738 ? $outputDone // object fetched by hook
739 : $this->mParserOutput;
740
741 # Adjust title for main page & pages with displaytitle
742 if ( $pOutput ) {
743 $this->adjustDisplayTitle( $pOutput );
744 }
745
746 # For the main page, overwrite the <title> element with the con-
747 # tents of 'pagetitle-view-mainpage' instead of the default (if
748 # that's not empty).
749 # This message always exists because it is in the i18n files
750 if ( $this->getTitle()->isMainPage() ) {
751 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
752 if ( !$msg->isDisabled() ) {
753 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
754 }
755 }
756
757 # Check for any __NOINDEX__ tags on the page using $pOutput
758 $policy = $this->getRobotPolicy( 'view', $pOutput );
759 $outputPage->setIndexPolicy( $policy['index'] );
760 $outputPage->setFollowPolicy( $policy['follow'] );
761
762 $this->showViewFooter();
763 $this->mPage->doViewUpdates( $user, $oldid );
764
765 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
766
767 wfProfileOut( __METHOD__ );
768 }
769
770 /**
771 * Adjust title for pages with displaytitle, -{T|}- or language conversion
772 * @param $pOutput ParserOutput
773 */
774 public function adjustDisplayTitle( ParserOutput $pOutput ) {
775 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
776 $titleText = $pOutput->getTitleText();
777 if ( strval( $titleText ) !== '' ) {
778 $this->getContext()->getOutput()->setPageTitle( $titleText );
779 }
780 }
781
782 /**
783 * Show a diff page according to current request variables. For use within
784 * Article::view() only, other callers should use the DifferenceEngine class.
785 *
786 * @todo Make protected
787 */
788 public function showDiffPage() {
789 $request = $this->getContext()->getRequest();
790 $user = $this->getContext()->getUser();
791 $diff = $request->getVal( 'diff' );
792 $rcid = $request->getVal( 'rcid' );
793 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
794 $purge = $request->getVal( 'action' ) == 'purge';
795 $unhide = $request->getInt( 'unhide' ) == 1;
796 $oldid = $this->getOldID();
797
798 $rev = $this->getRevisionFetched();
799
800 if ( !$rev ) {
801 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
802 $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
803 return;
804 }
805
806 $contentHandler = $rev->getContentHandler();
807 $de = $contentHandler->createDifferenceEngine(
808 $this->getContext(),
809 $oldid,
810 $diff,
811 $rcid,
812 $purge,
813 $unhide
814 );
815
816 // DifferenceEngine directly fetched the revision:
817 $this->mRevIdFetched = $de->mNewid;
818 $de->showDiffPage( $diffOnly );
819
820 // Run view updates for the newer revision being diffed (and shown
821 // below the diff if not $diffOnly).
822 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
823 // New can be false, convert it to 0 - this conveniently means the latest revision
824 $this->mPage->doViewUpdates( $user, (int)$new );
825 }
826
827 /**
828 * Show a page view for a page formatted as CSS or JavaScript. To be called by
829 * Article::view() only.
830 *
831 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
832 * page views.
833 *
834 * @param bool $showCacheHint whether to show a message telling the user
835 * to clear the browser cache (default: true).
836 */
837 protected function showCssOrJsPage( $showCacheHint = true ) {
838 $outputPage = $this->getContext()->getOutput();
839
840 if ( $showCacheHint ) {
841 $dir = $this->getContext()->getLanguage()->getDir();
842 $lang = $this->getContext()->getLanguage()->getCode();
843
844 $outputPage->wrapWikiMsg(
845 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
846 'clearyourcache'
847 );
848 }
849
850 $this->fetchContentObject();
851
852 if ( $this->mContentObject ) {
853 // Give hooks a chance to customise the output
854 if ( ContentHandler::runLegacyHooks(
855 'ShowRawCssJs',
856 array( $this->mContentObject, $this->getTitle(), $outputPage ) )
857 ) {
858 $po = $this->mContentObject->getParserOutput( $this->getTitle() );
859 $outputPage->addHTML( $po->getText() );
860 }
861 }
862 }
863
864 /**
865 * Get the robot policy to be used for the current view
866 * @param string $action the action= GET parameter
867 * @param $pOutput ParserOutput|null
868 * @return Array the policy that should be set
869 * TODO: actions other than 'view'
870 */
871 public function getRobotPolicy( $action, $pOutput = null ) {
872 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
873
874 $ns = $this->getTitle()->getNamespace();
875
876 # Don't index user and user talk pages for blocked users (bug 11443)
877 if ( ( $ns == NS_USER || $ns == NS_USER_TALK ) && !$this->getTitle()->isSubpage() ) {
878 $specificTarget = null;
879 $vagueTarget = null;
880 $titleText = $this->getTitle()->getText();
881 if ( IP::isValid( $titleText ) ) {
882 $vagueTarget = $titleText;
883 } else {
884 $specificTarget = $titleText;
885 }
886 if ( Block::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block ) {
887 return array(
888 'index' => 'noindex',
889 'follow' => 'nofollow'
890 );
891 }
892 }
893
894 if ( $this->mPage->getID() === 0 || $this->getOldID() ) {
895 # Non-articles (special pages etc), and old revisions
896 return array(
897 'index' => 'noindex',
898 'follow' => 'nofollow'
899 );
900 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
901 # Discourage indexing of printable versions, but encourage following
902 return array(
903 'index' => 'noindex',
904 'follow' => 'follow'
905 );
906 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
907 # For ?curid=x urls, disallow indexing
908 return array(
909 'index' => 'noindex',
910 'follow' => 'follow'
911 );
912 }
913
914 # Otherwise, construct the policy based on the various config variables.
915 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
916
917 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
918 # Honour customised robot policies for this namespace
919 $policy = array_merge(
920 $policy,
921 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
922 );
923 }
924 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
925 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
926 # a final sanity check that we have really got the parser output.
927 $policy = array_merge(
928 $policy,
929 array( 'index' => $pOutput->getIndexPolicy() )
930 );
931 }
932
933 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
934 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
935 $policy = array_merge(
936 $policy,
937 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
938 );
939 }
940
941 return $policy;
942 }
943
944 /**
945 * Converts a String robot policy into an associative array, to allow
946 * merging of several policies using array_merge().
947 * @param $policy Mixed, returns empty array on null/false/'', transparent
948 * to already-converted arrays, converts String.
949 * @return Array: 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
950 */
951 public static function formatRobotPolicy( $policy ) {
952 if ( is_array( $policy ) ) {
953 return $policy;
954 } elseif ( !$policy ) {
955 return array();
956 }
957
958 $policy = explode( ',', $policy );
959 $policy = array_map( 'trim', $policy );
960
961 $arr = array();
962 foreach ( $policy as $var ) {
963 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
964 $arr['index'] = $var;
965 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
966 $arr['follow'] = $var;
967 }
968 }
969
970 return $arr;
971 }
972
973 /**
974 * If this request is a redirect view, send "redirected from" subtitle to
975 * the output. Returns true if the header was needed, false if this is not
976 * a redirect view. Handles both local and remote redirects.
977 *
978 * @return boolean
979 */
980 public function showRedirectedFromHeader() {
981 global $wgRedirectSources;
982 $outputPage = $this->getContext()->getOutput();
983
984 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
985
986 if ( isset( $this->mRedirectedFrom ) ) {
987 // This is an internally redirected page view.
988 // We'll need a backlink to the source page for navigation.
989 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
990 $redir = Linker::linkKnown(
991 $this->mRedirectedFrom,
992 null,
993 array(),
994 array( 'redirect' => 'no' )
995 );
996
997 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
998
999 // Set the fragment if one was specified in the redirect
1000 if ( $this->getTitle()->hasFragment() ) {
1001 $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
1002 $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
1003 }
1004
1005 // Add a <link rel="canonical"> tag
1006 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
1007
1008 // Tell the output object that the user arrived at this article through a redirect
1009 $outputPage->setRedirectedFrom( $this->mRedirectedFrom );
1010
1011 return true;
1012 }
1013 } elseif ( $rdfrom ) {
1014 // This is an externally redirected view, from some other wiki.
1015 // If it was reported from a trusted site, supply a backlink.
1016 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1017 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
1018 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1019
1020 return true;
1021 }
1022 }
1023
1024 return false;
1025 }
1026
1027 /**
1028 * Show a header specific to the namespace currently being viewed, like
1029 * [[MediaWiki:Talkpagetext]]. For Article::view().
1030 */
1031 public function showNamespaceHeader() {
1032 if ( $this->getTitle()->isTalkPage() ) {
1033 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1034 $this->getContext()->getOutput()->wrapWikiMsg(
1035 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1036 array( 'talkpageheader' )
1037 );
1038 }
1039 }
1040 }
1041
1042 /**
1043 * Show the footer section of an ordinary page view
1044 */
1045 public function showViewFooter() {
1046 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1047 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1048 && IP::isValid( $this->getTitle()->getText() )
1049 ) {
1050 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1051 }
1052
1053 // Show a footer allowing the user to patrol the shown revision or page if possible
1054 $patrolFooterShown = $this->showPatrolFooter();
1055
1056 wfRunHooks( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1057 }
1058
1059 /**
1060 * If patrol is possible, output a patrol UI box. This is called from the
1061 * footer section of ordinary page views. If patrol is not possible or not
1062 * desired, does nothing.
1063 * Side effect: When the patrol link is build, this method will call
1064 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1065 *
1066 * @return bool
1067 */
1068 public function showPatrolFooter() {
1069 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1070
1071 $outputPage = $this->getContext()->getOutput();
1072 $user = $this->getContext()->getUser();
1073 $cache = wfGetMainCache();
1074 $rc = false;
1075
1076 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1077 || !( $wgUseRCPatrol || $wgUseNPPatrol )
1078 ) {
1079 // Patrolling is disabled or the user isn't allowed to
1080 return false;
1081 }
1082
1083 wfProfileIn( __METHOD__ );
1084
1085 // New page patrol: Get the timestamp of the oldest revison which
1086 // the revision table holds for the given page. Then we look
1087 // whether it's within the RC lifespan and if it is, we try
1088 // to get the recentchanges row belonging to that entry
1089 // (with rc_new = 1).
1090
1091 // Check for cached results
1092 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1093 wfProfileOut( __METHOD__ );
1094 return false;
1095 }
1096
1097 if ( $this->mRevision
1098 && !RecentChange::isInRCLifespan( $this->mRevision->getTimestamp(), 21600 )
1099 ) {
1100 // The current revision is already older than what could be in the RC table
1101 // 6h tolerance because the RC might not be cleaned out regularly
1102 wfProfileOut( __METHOD__ );
1103 return false;
1104 }
1105
1106 $dbr = wfGetDB( DB_SLAVE );
1107 $oldestRevisionTimestamp = $dbr->selectField(
1108 'revision',
1109 'MIN( rev_timestamp )',
1110 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1111 __METHOD__
1112 );
1113
1114 if ( $oldestRevisionTimestamp
1115 && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1116 ) {
1117 // 6h tolerance because the RC might not be cleaned out regularly
1118 $rc = RecentChange::newFromConds(
1119 array(
1120 'rc_new' => 1,
1121 'rc_timestamp' => $oldestRevisionTimestamp,
1122 'rc_namespace' => $this->getTitle()->getNamespace(),
1123 'rc_cur_id' => $this->getTitle()->getArticleID(),
1124 'rc_patrolled' => 0
1125 ),
1126 __METHOD__,
1127 array( 'USE INDEX' => 'new_name_timestamp' )
1128 );
1129 }
1130
1131 if ( !$rc ) {
1132 // No RC entry around
1133
1134 // Cache the information we gathered above in case we can't patrol
1135 // Don't cache in case we can patrol as this could change
1136 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1137
1138 wfProfileOut( __METHOD__ );
1139 return false;
1140 }
1141
1142 if ( $rc->getPerformer()->getName() == $user->getName() ) {
1143 // Don't show a patrol link for own creations. If the user could
1144 // patrol them, they already would be patrolled
1145 wfProfileOut( __METHOD__ );
1146 return false;
1147 }
1148
1149 $rcid = $rc->getAttribute( 'rc_id' );
1150
1151 $token = $user->getEditToken( $rcid );
1152
1153 $outputPage->preventClickjacking();
1154 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1155 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1156 }
1157
1158 $link = Linker::linkKnown(
1159 $this->getTitle(),
1160 wfMessage( 'markaspatrolledtext' )->escaped(),
1161 array(),
1162 array(
1163 'action' => 'markpatrolled',
1164 'rcid' => $rcid,
1165 'token' => $token,
1166 )
1167 );
1168
1169 $outputPage->addHTML(
1170 "<div class='patrollink'>" .
1171 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1172 '</div>'
1173 );
1174
1175 wfProfileOut( __METHOD__ );
1176 return true;
1177 }
1178
1179 /**
1180 * Show the error text for a missing article. For articles in the MediaWiki
1181 * namespace, show the default message text. To be called from Article::view().
1182 */
1183 public function showMissingArticle() {
1184 global $wgSend404Code;
1185 $outputPage = $this->getContext()->getOutput();
1186 // Whether the page is a root user page of an existing user (but not a subpage)
1187 $validUserPage = false;
1188
1189 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1190 if ( $this->getTitle()->getNamespace() == NS_USER
1191 || $this->getTitle()->getNamespace() == NS_USER_TALK
1192 ) {
1193 $parts = explode( '/', $this->getTitle()->getText() );
1194 $rootPart = $parts[0];
1195 $user = User::newFromName( $rootPart, false /* allow IP users*/ );
1196 $ip = User::isIP( $rootPart );
1197
1198 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1199 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1200 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1201 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1202 LogEventsList::showLogExtract(
1203 $outputPage,
1204 'block',
1205 $user->getUserPage(),
1206 '',
1207 array(
1208 'lim' => 1,
1209 'showIfEmpty' => false,
1210 'msgKey' => array(
1211 'blocked-notice-logextract',
1212 $user->getName() # Support GENDER in notice
1213 )
1214 )
1215 );
1216 $validUserPage = !$this->getTitle()->isSubpage();
1217 } else {
1218 $validUserPage = !$this->getTitle()->isSubpage();
1219 }
1220 }
1221
1222 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1223
1224 // Give extensions a chance to hide their (unrelated) log entries
1225 $logTypes = array( 'delete', 'move' );
1226 $conds = array( "log_action != 'revision'" );
1227 wfRunHooks( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1228
1229 # Show delete and move logs
1230 LogEventsList::showLogExtract( $outputPage, $logTypes, $this->getTitle(), '',
1231 array( 'lim' => 10,
1232 'conds' => $conds,
1233 'showIfEmpty' => false,
1234 'msgKey' => array( 'moveddeleted-notice' ) )
1235 );
1236
1237 if ( !$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1238 // If there's no backing content, send a 404 Not Found
1239 // for better machine handling of broken links.
1240 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1241 }
1242
1243 if ( $validUserPage ) {
1244 // Also apply the robot policy for nonexisting user pages (as those aren't served as 404)
1245 $policy = $this->getRobotPolicy( 'view' );
1246 $outputPage->setIndexPolicy( $policy['index'] );
1247 $outputPage->setFollowPolicy( $policy['follow'] );
1248 }
1249
1250 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1251
1252 if ( ! $hookResult ) {
1253 return;
1254 }
1255
1256 # Show error message
1257 $oldid = $this->getOldID();
1258 if ( $oldid ) {
1259 $text = wfMessage( 'missing-revision', $oldid )->plain();
1260 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI ) {
1261 // Use the default message text
1262 $text = $this->getTitle()->getDefaultMessageText();
1263 } elseif ( $this->getTitle()->quickUserCan( 'create', $this->getContext()->getUser() )
1264 && $this->getTitle()->quickUserCan( 'edit', $this->getContext()->getUser() )
1265 ) {
1266 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
1267 $text = wfMessage( $message )->plain();
1268 } else {
1269 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1270 }
1271 $text = "<div class='noarticletext'>\n$text\n</div>";
1272
1273 $outputPage->addWikiText( $text );
1274 }
1275
1276 /**
1277 * If the revision requested for view is deleted, check permissions.
1278 * Send either an error message or a warning header to the output.
1279 *
1280 * @return boolean true if the view is allowed, false if not.
1281 */
1282 public function showDeletedRevisionHeader() {
1283 if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1284 // Not deleted
1285 return true;
1286 }
1287
1288 $outputPage = $this->getContext()->getOutput();
1289 $user = $this->getContext()->getUser();
1290 // If the user is not allowed to see it...
1291 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT, $user ) ) {
1292 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1293 'rev-deleted-text-permission' );
1294
1295 return false;
1296 // If the user needs to confirm that they want to see it...
1297 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1298 # Give explanation and add a link to view the revision...
1299 $oldid = intval( $this->getOldID() );
1300 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1301 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1302 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1303 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1304 array( $msg, $link ) );
1305
1306 return false;
1307 // We are allowed to see...
1308 } else {
1309 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1310 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1311 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1312
1313 return true;
1314 }
1315 }
1316
1317 /**
1318 * Generate the navigation links when browsing through an article revisions
1319 * It shows the information as:
1320 * Revision as of \<date\>; view current revision
1321 * \<- Previous version | Next Version -\>
1322 *
1323 * @param int $oldid revision ID of this article revision
1324 */
1325 public function setOldSubtitle( $oldid = 0 ) {
1326 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1327 return;
1328 }
1329
1330 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1331
1332 # Cascade unhide param in links for easy deletion browsing
1333 $extraParams = array();
1334 if ( $unhide ) {
1335 $extraParams['unhide'] = 1;
1336 }
1337
1338 if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
1339 $revision = $this->mRevision;
1340 } else {
1341 $revision = Revision::newFromId( $oldid );
1342 }
1343
1344 $timestamp = $revision->getTimestamp();
1345
1346 $current = ( $oldid == $this->mPage->getLatest() );
1347 $language = $this->getContext()->getLanguage();
1348 $user = $this->getContext()->getUser();
1349
1350 $td = $language->userTimeAndDate( $timestamp, $user );
1351 $tddate = $language->userDate( $timestamp, $user );
1352 $tdtime = $language->userTime( $timestamp, $user );
1353
1354 # Show user links if allowed to see them. If hidden, then show them only if requested...
1355 $userlinks = Linker::revUserTools( $revision, !$unhide );
1356
1357 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1358 ? 'revision-info-current'
1359 : 'revision-info';
1360
1361 $outputPage = $this->getContext()->getOutput();
1362 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1363 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1364 $tdtime, $revision->getUser() )->parse() . "</div>" );
1365
1366 $lnk = $current
1367 ? wfMessage( 'currentrevisionlink' )->escaped()
1368 : Linker::linkKnown(
1369 $this->getTitle(),
1370 wfMessage( 'currentrevisionlink' )->escaped(),
1371 array(),
1372 $extraParams
1373 );
1374 $curdiff = $current
1375 ? wfMessage( 'diff' )->escaped()
1376 : Linker::linkKnown(
1377 $this->getTitle(),
1378 wfMessage( 'diff' )->escaped(),
1379 array(),
1380 array(
1381 'diff' => 'cur',
1382 'oldid' => $oldid
1383 ) + $extraParams
1384 );
1385 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1386 $prevlink = $prev
1387 ? Linker::linkKnown(
1388 $this->getTitle(),
1389 wfMessage( 'previousrevision' )->escaped(),
1390 array(),
1391 array(
1392 'direction' => 'prev',
1393 'oldid' => $oldid
1394 ) + $extraParams
1395 )
1396 : wfMessage( 'previousrevision' )->escaped();
1397 $prevdiff = $prev
1398 ? Linker::linkKnown(
1399 $this->getTitle(),
1400 wfMessage( 'diff' )->escaped(),
1401 array(),
1402 array(
1403 'diff' => 'prev',
1404 'oldid' => $oldid
1405 ) + $extraParams
1406 )
1407 : wfMessage( 'diff' )->escaped();
1408 $nextlink = $current
1409 ? wfMessage( 'nextrevision' )->escaped()
1410 : Linker::linkKnown(
1411 $this->getTitle(),
1412 wfMessage( 'nextrevision' )->escaped(),
1413 array(),
1414 array(
1415 'direction' => 'next',
1416 'oldid' => $oldid
1417 ) + $extraParams
1418 );
1419 $nextdiff = $current
1420 ? wfMessage( 'diff' )->escaped()
1421 : Linker::linkKnown(
1422 $this->getTitle(),
1423 wfMessage( 'diff' )->escaped(),
1424 array(),
1425 array(
1426 'diff' => 'next',
1427 'oldid' => $oldid
1428 ) + $extraParams
1429 );
1430
1431 $cdel = Linker::getRevDeleteLink( $user, $revision, $this->getTitle() );
1432 if ( $cdel !== '' ) {
1433 $cdel .= ' ';
1434 }
1435
1436 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1437 wfMessage( 'revision-nav' )->rawParams(
1438 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1439 )->escaped() . "</div>" );
1440 }
1441
1442 /**
1443 * Return the HTML for the top of a redirect page
1444 *
1445 * Chances are you should just be using the ParserOutput from
1446 * WikitextContent::getParserOutput instead of calling this for redirects.
1447 *
1448 * @param $target Title|Array of destination(s) to redirect
1449 * @param $appendSubtitle Boolean [optional]
1450 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1451 * @return string containing HMTL with redirect link
1452 */
1453 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1454 $lang = $this->getTitle()->getPageLanguage();
1455 if ( $appendSubtitle ) {
1456 $out = $this->getContext()->getOutput();
1457 $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
1458 }
1459 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1460 }
1461
1462 /**
1463 * Return the HTML for the top of a redirect page
1464 *
1465 * Chances are you should just be using the ParserOutput from
1466 * WikitextContent::getParserOutput instead of calling this for redirects.
1467 *
1468 * @since 1.23
1469 * @param Language $lang
1470 * @param Title|array $target destination(s) to redirect
1471 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1472 * @return string containing HMTL with redirect link
1473 */
1474 public static function getRedirectHeaderHtml( Language $lang, $target, $forceKnown = false ) {
1475 global $wgStylePath;
1476
1477 if ( !is_array( $target ) ) {
1478 $target = array( $target );
1479 }
1480
1481 $imageDir = $lang->getDir();
1482
1483 // the loop prepends the arrow image before the link, so the first case needs to be outside
1484
1485 /** @var $title Title */
1486 $title = array_shift( $target );
1487
1488 if ( $forceKnown ) {
1489 $link = Linker::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1490 } else {
1491 $link = Linker::link( $title, htmlspecialchars( $title->getFullText() ) );
1492 }
1493
1494 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1495 $alt = $lang->isRTL() ? '←' : '→';
1496
1497 // Automatically append redirect=no to each link, since most of them are
1498 // redirect pages themselves.
1499 /** @var Title $rt */
1500 foreach ( $target as $rt ) {
1501 $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1502 if ( $forceKnown ) {
1503 $link .= Linker::linkKnown(
1504 $rt,
1505 htmlspecialchars( $rt->getFullText(),
1506 array(),
1507 array( 'redirect' => 'no' )
1508 )
1509 );
1510 } else {
1511 $link .= Linker::link(
1512 $rt,
1513 htmlspecialchars( $rt->getFullText() ),
1514 array(),
1515 array( 'redirect' => 'no' )
1516 );
1517 }
1518 }
1519
1520 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1521 return '<div class="redirectMsg">' .
1522 Html::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1523 '<span class="redirectText">' . $link . '</span></div>';
1524 }
1525
1526 /**
1527 * Handle action=render
1528 */
1529 public function render() {
1530 $this->getContext()->getOutput()->setArticleBodyOnly( true );
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 boolean 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 $oldid mixed integer Revision ID or null
1885 * @param $user User The relevant user
1886 * @return 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 $context IContextSource
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 $fvalue mixed 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 $limit array
2042 * @param $expiry array
2043 * @param $cascade bool
2044 * @param $reason string
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 $limit array
2056 * @param $reason string
2057 * @param $cascade int
2058 * @param $expiry array
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 $reason string
2075 * @param $suppress bool
2076 * @param $id int
2077 * @param $commit bool
2078 * @param $error string
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 $fromP
2089 * @param $summary
2090 * @param $token
2091 * @param $bot
2092 * @param $resultDetails
2093 * @param $user 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 $fromP
2103 * @param $summary
2104 * @param $bot
2105 * @param $resultDetails
2106 * @param $guser User
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 $hasHistory bool
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 $oldtext
2156 * @param $newtext
2157 * @param $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 }