Merge "Update moment.js to 2.6.0"
[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 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
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 since 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 since 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->getContext()->getOutput()->enableSectionEditLinks( false );
1532 $this->view();
1533 }
1534
1535 /**
1536 * action=protect handler
1537 */
1538 public function protect() {
1539 $form = new ProtectionForm( $this );
1540 $form->execute();
1541 }
1542
1543 /**
1544 * action=unprotect handler (alias)
1545 */
1546 public function unprotect() {
1547 $this->protect();
1548 }
1549
1550 /**
1551 * UI entry point for page deletion
1552 */
1553 public function delete() {
1554 # This code desperately needs to be totally rewritten
1555
1556 $title = $this->getTitle();
1557 $user = $this->getContext()->getUser();
1558
1559 # Check permissions
1560 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1561 if ( count( $permission_errors ) ) {
1562 throw new PermissionsError( 'delete', $permission_errors );
1563 }
1564
1565 # Read-only check...
1566 if ( wfReadOnly() ) {
1567 throw new ReadOnlyError;
1568 }
1569
1570 # Better double-check that it hasn't been deleted yet!
1571 $this->mPage->loadPageData( 'fromdbmaster' );
1572 if ( !$this->mPage->exists() ) {
1573 $deleteLogPage = new LogPage( 'delete' );
1574 $outputPage = $this->getContext()->getOutput();
1575 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1576 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1577 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1578 );
1579 $outputPage->addHTML(
1580 Xml::element( 'h2', null, $deleteLogPage->getName()->text() )
1581 );
1582 LogEventsList::showLogExtract(
1583 $outputPage,
1584 'delete',
1585 $title
1586 );
1587
1588 return;
1589 }
1590
1591 $request = $this->getContext()->getRequest();
1592 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1593 $deleteReason = $request->getText( 'wpReason' );
1594
1595 if ( $deleteReasonList == 'other' ) {
1596 $reason = $deleteReason;
1597 } elseif ( $deleteReason != '' ) {
1598 // Entry from drop down menu + additional comment
1599 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1600 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1601 } else {
1602 $reason = $deleteReasonList;
1603 }
1604
1605 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1606 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1607 ) {
1608 # Flag to hide all contents of the archived revisions
1609 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1610
1611 $this->doDelete( $reason, $suppress );
1612
1613 WatchAction::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1614
1615 return;
1616 }
1617
1618 // Generate deletion reason
1619 $hasHistory = false;
1620 if ( !$reason ) {
1621 try {
1622 $reason = $this->generateReason( $hasHistory );
1623 } catch ( MWException $e ) {
1624 # if a page is horribly broken, we still want to be able to
1625 # delete it. So be lenient about errors here.
1626 wfDebug( "Error while building auto delete summary: $e" );
1627 $reason = '';
1628 }
1629 }
1630
1631 // If the page has a history, insert a warning
1632 if ( $hasHistory ) {
1633 $revisions = $this->mTitle->estimateRevisionCount();
1634 // @todo FIXME: i18n issue/patchwork message
1635 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1636 wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
1637 wfMessage( 'word-separator' )->plain() . Linker::linkKnown( $title,
1638 wfMessage( 'history' )->escaped(),
1639 array( 'rel' => 'archives' ),
1640 array( 'action' => 'history' ) ) .
1641 '</strong>'
1642 );
1643
1644 if ( $this->mTitle->isBigDeletion() ) {
1645 global $wgDeleteRevisionsLimit;
1646 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1647 array(
1648 'delete-warning-toobig',
1649 $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1650 )
1651 );
1652 }
1653 }
1654
1655 $this->confirmDelete( $reason );
1656 }
1657
1658 /**
1659 * Output deletion confirmation dialog
1660 * @todo FIXME: Move to another file?
1661 * @param string $reason prefilled reason
1662 */
1663 public function confirmDelete( $reason ) {
1664 wfDebug( "Article::confirmDelete\n" );
1665
1666 $outputPage = $this->getContext()->getOutput();
1667 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1668 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1669 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1670 $backlinkCache = $this->getTitle()->getBacklinkCache();
1671 if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
1672 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1673 'deleting-backlinks-warning' );
1674 }
1675 $outputPage->addWikiMsg( 'confirmdeletetext' );
1676
1677 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1678
1679 $user = $this->getContext()->getUser();
1680
1681 if ( $user->isAllowed( 'suppressrevision' ) ) {
1682 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1683 <td></td>
1684 <td class='mw-input'><strong>" .
1685 Xml::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1686 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1687 "</strong></td>
1688 </tr>";
1689 } else {
1690 $suppress = '';
1691 }
1692 $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $this->getTitle() );
1693
1694 $form = Xml::openElement( 'form', array( 'method' => 'post',
1695 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1696 Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1697 Xml::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
1698 Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1699 "<tr id=\"wpDeleteReasonListRow\">
1700 <td class='mw-label'>" .
1701 Xml::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1702 "</td>
1703 <td class='mw-input'>" .
1704 Xml::listDropDown(
1705 'wpDeleteReasonList',
1706 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1707 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1708 '',
1709 'wpReasonDropDown',
1710 1
1711 ) .
1712 "</td>
1713 </tr>
1714 <tr id=\"wpDeleteReasonRow\">
1715 <td class='mw-label'>" .
1716 Xml::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1717 "</td>
1718 <td class='mw-input'>" .
1719 Html::input( 'wpReason', $reason, 'text', array(
1720 'size' => '60',
1721 'maxlength' => '255',
1722 'tabindex' => '2',
1723 'id' => 'wpReason',
1724 'autofocus'
1725 ) ) .
1726 "</td>
1727 </tr>";
1728
1729 # Disallow watching if user is not logged in
1730 if ( $user->isLoggedIn() ) {
1731 $form .= "
1732 <tr>
1733 <td></td>
1734 <td class='mw-input'>" .
1735 Xml::checkLabel( wfMessage( 'watchthis' )->text(),
1736 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1737 "</td>
1738 </tr>";
1739 }
1740
1741 $form .= "
1742 $suppress
1743 <tr>
1744 <td></td>
1745 <td class='mw-submit'>" .
1746 Xml::submitButton( wfMessage( 'deletepage' )->text(),
1747 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1748 "</td>
1749 </tr>" .
1750 Xml::closeElement( 'table' ) .
1751 Xml::closeElement( 'fieldset' ) .
1752 Html::hidden(
1753 'wpEditToken',
1754 $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) )
1755 ) .
1756 Xml::closeElement( 'form' );
1757
1758 if ( $user->isAllowed( 'editinterface' ) ) {
1759 $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
1760 $link = Linker::link(
1761 $title,
1762 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1763 array(),
1764 array( 'action' => 'edit' )
1765 );
1766 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1767 }
1768
1769 $outputPage->addHTML( $form );
1770
1771 $deleteLogPage = new LogPage( 'delete' );
1772 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1773 LogEventsList::showLogExtract( $outputPage, 'delete',
1774 $this->getTitle()
1775 );
1776 }
1777
1778 /**
1779 * Perform a deletion and output success or failure messages
1780 * @param string $reason
1781 * @param bool $suppress
1782 */
1783 public function doDelete( $reason, $suppress = false ) {
1784 $error = '';
1785 $outputPage = $this->getContext()->getOutput();
1786 $status = $this->mPage->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1787
1788 if ( $status->isGood() ) {
1789 $deleted = $this->getTitle()->getPrefixedText();
1790
1791 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1792 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1793
1794 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1795
1796 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1797 $outputPage->returnToMain( false );
1798 } else {
1799 $outputPage->setPageTitle(
1800 wfMessage( 'cannotdelete-title',
1801 $this->getTitle()->getPrefixedText() )
1802 );
1803
1804 if ( $error == '' ) {
1805 $outputPage->addWikiText(
1806 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1807 );
1808 $deleteLogPage = new LogPage( 'delete' );
1809 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1810
1811 LogEventsList::showLogExtract(
1812 $outputPage,
1813 'delete',
1814 $this->getTitle()
1815 );
1816 } else {
1817 $outputPage->addHTML( $error );
1818 }
1819 }
1820 }
1821
1822 /* Caching functions */
1823
1824 /**
1825 * checkLastModified returns true if it has taken care of all
1826 * output to the client that is necessary for this request.
1827 * (that is, it has sent a cached version of the page)
1828 *
1829 * @return boolean true if cached version send, false otherwise
1830 */
1831 protected function tryFileCache() {
1832 static $called = false;
1833
1834 if ( $called ) {
1835 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1836 return false;
1837 }
1838
1839 $called = true;
1840 if ( $this->isFileCacheable() ) {
1841 $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'view' );
1842 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1843 wfDebug( "Article::tryFileCache(): about to load file\n" );
1844 $cache->loadFromFileCache( $this->getContext() );
1845 return true;
1846 } else {
1847 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1848 ob_start( array( &$cache, 'saveToFileCache' ) );
1849 }
1850 } else {
1851 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1852 }
1853
1854 return false;
1855 }
1856
1857 /**
1858 * Check if the page can be cached
1859 * @return bool
1860 */
1861 public function isFileCacheable() {
1862 $cacheable = false;
1863
1864 if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
1865 $cacheable = $this->mPage->getID()
1866 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
1867 // Extension may have reason to disable file caching on some pages.
1868 if ( $cacheable ) {
1869 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1870 }
1871 }
1872
1873 return $cacheable;
1874 }
1875
1876 /**#@-*/
1877
1878 /**
1879 * Lightweight method to get the parser output for a page, checking the parser cache
1880 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1881 * consider, so it's not appropriate to use there.
1882 *
1883 * @since 1.16 (r52326) for LiquidThreads
1884 *
1885 * @param $oldid mixed integer Revision ID or null
1886 * @param $user User The relevant user
1887 * @return ParserOutput or false if the given revision ID is not found
1888 */
1889 public function getParserOutput( $oldid = null, User $user = null ) {
1890 //XXX: bypasses mParserOptions and thus setParserOptions()
1891
1892 if ( $user === null ) {
1893 $parserOptions = $this->getParserOptions();
1894 } else {
1895 $parserOptions = $this->mPage->makeParserOptions( $user );
1896 }
1897
1898 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1899 }
1900
1901 /**
1902 * Override the ParserOptions used to render the primary article wikitext.
1903 *
1904 * @param ParserOptions $options
1905 * @throws MWException if the parser options where already initialized.
1906 */
1907 public function setParserOptions( ParserOptions $options ) {
1908 if ( $this->mParserOptions ) {
1909 throw new MWException( "can't change parser options after they have already been set" );
1910 }
1911
1912 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1913 $this->mParserOptions = clone $options;
1914 }
1915
1916 /**
1917 * Get parser options suitable for rendering the primary article wikitext
1918 * @return ParserOptions
1919 */
1920 public function getParserOptions() {
1921 if ( !$this->mParserOptions ) {
1922 $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
1923 }
1924 // Clone to allow modifications of the return value without affecting cache
1925 return clone $this->mParserOptions;
1926 }
1927
1928 /**
1929 * Sets the context this Article is executed in
1930 *
1931 * @param $context IContextSource
1932 * @since 1.18
1933 */
1934 public function setContext( $context ) {
1935 $this->mContext = $context;
1936 }
1937
1938 /**
1939 * Gets the context this Article is executed in
1940 *
1941 * @return IContextSource
1942 * @since 1.18
1943 */
1944 public function getContext() {
1945 if ( $this->mContext instanceof IContextSource ) {
1946 return $this->mContext;
1947 } else {
1948 wfDebug( __METHOD__ . " called and \$mContext is null. " .
1949 "Return RequestContext::getMain(); for sanity\n" );
1950 return RequestContext::getMain();
1951 }
1952 }
1953
1954 /**
1955 * Info about this page
1956 * @deprecated since 1.19
1957 */
1958 public function info() {
1959 wfDeprecated( __METHOD__, '1.19' );
1960 Action::factory( 'info', $this )->show();
1961 }
1962
1963 /**
1964 * Handle action=purge
1965 * @deprecated since 1.19
1966 * @return Action|bool|null false if the action is disabled, null if it is not recognised
1967 */
1968 public function purge() {
1969 return Action::factory( 'purge', $this )->show();
1970 }
1971
1972 /**
1973 * Handle action=revert
1974 * @deprecated since 1.19
1975 */
1976 public function revert() {
1977 wfDeprecated( __METHOD__, '1.19' );
1978 Action::factory( 'revert', $this )->show();
1979 }
1980
1981 /**
1982 * Handle action=rollback
1983 * @deprecated since 1.19
1984 */
1985 public function rollback() {
1986 wfDeprecated( __METHOD__, '1.19' );
1987 Action::factory( 'rollback', $this )->show();
1988 }
1989
1990 /**
1991 * Use PHP's magic __get handler to handle accessing of
1992 * raw WikiPage fields for backwards compatibility.
1993 *
1994 * @param string $fname Field name
1995 */
1996 public function __get( $fname ) {
1997 if ( property_exists( $this->mPage, $fname ) ) {
1998 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1999 return $this->mPage->$fname;
2000 }
2001 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
2002 }
2003
2004 /**
2005 * Use PHP's magic __set handler to handle setting of
2006 * raw WikiPage fields for backwards compatibility.
2007 *
2008 * @param string $fname Field name
2009 * @param $fvalue mixed New value
2010 */
2011 public function __set( $fname, $fvalue ) {
2012 if ( property_exists( $this->mPage, $fname ) ) {
2013 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
2014 $this->mPage->$fname = $fvalue;
2015 // Note: extensions may want to toss on new fields
2016 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
2017 $this->mPage->$fname = $fvalue;
2018 } else {
2019 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
2020 }
2021 }
2022
2023 /**
2024 * Use PHP's magic __call handler to transform instance calls to
2025 * WikiPage functions for backwards compatibility.
2026 *
2027 * @param string $fname Name of called method
2028 * @param array $args Arguments to the method
2029 * @return mixed
2030 */
2031 public function __call( $fname, $args ) {
2032 if ( is_callable( array( $this->mPage, $fname ) ) ) {
2033 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2034 return call_user_func_array( array( $this->mPage, $fname ), $args );
2035 }
2036 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR );
2037 }
2038
2039 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2040
2041 /**
2042 * @param $limit array
2043 * @param $expiry array
2044 * @param $cascade bool
2045 * @param $reason string
2046 * @param $user User
2047 * @return Status
2048 */
2049 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2050 $reason, User $user
2051 ) {
2052 return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2053 }
2054
2055 /**
2056 * @param $limit array
2057 * @param $reason string
2058 * @param $cascade int
2059 * @param $expiry array
2060 * @return bool
2061 */
2062 public function updateRestrictions( $limit = array(), $reason = '',
2063 &$cascade = 0, $expiry = array()
2064 ) {
2065 return $this->mPage->doUpdateRestrictions(
2066 $limit,
2067 $expiry,
2068 $cascade,
2069 $reason,
2070 $this->getContext()->getUser()
2071 );
2072 }
2073
2074 /**
2075 * @param $reason string
2076 * @param $suppress bool
2077 * @param $id int
2078 * @param $commit bool
2079 * @param $error string
2080 * @return bool
2081 */
2082 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2083 $commit = true, &$error = ''
2084 ) {
2085 return $this->mPage->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2086 }
2087
2088 /**
2089 * @param $fromP
2090 * @param $summary
2091 * @param $token
2092 * @param $bot
2093 * @param $resultDetails
2094 * @param $user User
2095 * @return array
2096 */
2097 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user = null ) {
2098 $user = is_null( $user ) ? $this->getContext()->getUser() : $user;
2099 return $this->mPage->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2100 }
2101
2102 /**
2103 * @param $fromP
2104 * @param $summary
2105 * @param $bot
2106 * @param $resultDetails
2107 * @param $guser User
2108 * @return array
2109 */
2110 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser = null ) {
2111 $guser = is_null( $guser ) ? $this->getContext()->getUser() : $guser;
2112 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2113 }
2114
2115 /**
2116 * @param $hasHistory bool
2117 * @return mixed
2118 */
2119 public function generateReason( &$hasHistory ) {
2120 $title = $this->mPage->getTitle();
2121 $handler = ContentHandler::getForTitle( $title );
2122 return $handler->getAutoDeleteReason( $title, $hasHistory );
2123 }
2124
2125 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2126
2127 /**
2128 * @return array
2129 */
2130 public static function selectFields() {
2131 return WikiPage::selectFields();
2132 }
2133
2134 /**
2135 * @param $title Title
2136 */
2137 public static function onArticleCreate( $title ) {
2138 WikiPage::onArticleCreate( $title );
2139 }
2140
2141 /**
2142 * @param $title Title
2143 */
2144 public static function onArticleDelete( $title ) {
2145 WikiPage::onArticleDelete( $title );
2146 }
2147
2148 /**
2149 * @param $title Title
2150 */
2151 public static function onArticleEdit( $title ) {
2152 WikiPage::onArticleEdit( $title );
2153 }
2154
2155 /**
2156 * @param $oldtext
2157 * @param $newtext
2158 * @param $flags
2159 * @return string
2160 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2161 */
2162 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2163 return WikiPage::getAutosummary( $oldtext, $newtext, $flags );
2164 }
2165 // ******
2166 }