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