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