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