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