Minor tweaks to r74232, add a value for $botMax on calls for integer validation ...
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if ( !defined( 'MEDIAWIKI' ) ) {
3 die( 1 );
4 }
5
6 /**
7 * @todo document
8 */
9 class OutputPage {
10 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
11 var $mExtStyles = array();
12 var $mPagetitle = '', $mBodytext = '';
13
14 /**
15 * Holds the debug lines that will be outputted as comments in page source if
16 * $wgDebugComments is enabled. See also $wgShowDebug.
17 * TODO: make a getter method for this
18 */
19 public $mDebugtext = '';
20
21 var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
22 var $mSubtitle = '', $mRedirect = '', $mStatusCode;
23 var $mLastModified = '', $mETag = false;
24 var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array();
25
26 var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
27 var $mModules = array(), $mModuleScripts = array(), $mModuleStyles = array(), $mModuleMessages = array();
28 var $mResourceLoader;
29 var $mInlineMsg = array();
30
31 var $mTemplateIds = array();
32
33 var $mAllowUserJs;
34 var $mSuppressQuickbar = false;
35 var $mDoNothing = false;
36 var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
37 var $mIsArticleRelated = true;
38 protected $mParserOptions = null; // lazy initialised, use parserOptions()
39
40 var $mFeedLinks = array();
41
42 var $mEnableClientCache = true;
43 var $mArticleBodyOnly = false;
44
45 var $mNewSectionLink = false;
46 var $mHideNewSectionLink = false;
47 var $mNoGallery = false;
48 var $mPageTitleActionText = '';
49 var $mParseWarnings = array();
50 var $mSquidMaxage = 0;
51 var $mRevisionId = null;
52 protected $mTitle = null;
53
54 /**
55 * An array of stylesheet filenames (relative from skins path), with options
56 * for CSS media, IE conditions, and RTL/LTR direction.
57 * For internal use; add settings in the skin via $this->addStyle()
58 */
59 var $styles = array();
60
61 /**
62 * Whether to load jQuery core.
63 */
64 protected $mJQueryDone = false;
65
66 private $mIndexPolicy = 'index';
67 private $mFollowPolicy = 'follow';
68 private $mVaryHeader = array(
69 'Accept-Encoding' => array( 'list-contains=gzip' ),
70 'Cookie' => null
71 );
72
73 /**
74 * Constructor
75 * Initialise private variables
76 */
77 function __construct() {
78 global $wgAllowUserJs;
79 $this->mAllowUserJs = $wgAllowUserJs;
80 }
81
82 /**
83 * Redirect to $url rather than displaying the normal page
84 *
85 * @param $url String: URL
86 * @param $responsecode String: HTTP status code
87 */
88 public function redirect( $url, $responsecode = '302' ) {
89 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
90 $this->mRedirect = str_replace( "\n", '', $url );
91 $this->mRedirectCode = $responsecode;
92 }
93
94 /**
95 * Get the URL to redirect to, or an empty string if not redirect URL set
96 *
97 * @return String
98 */
99 public function getRedirect() {
100 return $this->mRedirect;
101 }
102
103 /**
104 * Set the HTTP status code to send with the output.
105 *
106 * @param $statusCode Integer
107 * @return nothing
108 */
109 public function setStatusCode( $statusCode ) {
110 $this->mStatusCode = $statusCode;
111 }
112
113 /**
114 * Add a new <meta> tag
115 * To add an http-equiv meta tag, precede the name with "http:"
116 *
117 * @param $name tag name
118 * @param $val tag value
119 */
120 function addMeta( $name, $val ) {
121 array_push( $this->mMetatags, array( $name, $val ) );
122 }
123
124 /**
125 * Add a keyword or a list of keywords in the page header
126 *
127 * @param $text String or array of strings
128 */
129 function addKeyword( $text ) {
130 if( is_array( $text ) ) {
131 $this->mKeywords = array_merge( $this->mKeywords, $text );
132 } else {
133 array_push( $this->mKeywords, $text );
134 }
135 }
136
137 /**
138 * Add a new \<link\> tag to the page header
139 *
140 * @param $linkarr Array: associative array of attributes.
141 */
142 function addLink( $linkarr ) {
143 array_push( $this->mLinktags, $linkarr );
144 }
145
146 /**
147 * Add a new \<link\> with "rel" attribute set to "meta"
148 *
149 * @param $linkarr Array: associative array mapping attribute names to their
150 * values, both keys and values will be escaped, and the
151 * "rel" attribute will be automatically added
152 */
153 function addMetadataLink( $linkarr ) {
154 # note: buggy CC software only reads first "meta" link
155 static $haveMeta = false;
156 $linkarr['rel'] = $haveMeta ? 'alternate meta' : 'meta';
157 $this->addLink( $linkarr );
158 $haveMeta = true;
159 }
160
161 /**
162 * Add raw HTML to the list of scripts (including \<script\> tag, etc.)
163 *
164 * @param $script String: raw HTML
165 */
166 function addScript( $script ) {
167 $this->mScripts .= $script . "\n";
168 }
169
170 /**
171 * Register and add a stylesheet from an extension directory.
172 *
173 * @param $url String path to sheet. Provide either a full url (beginning
174 * with 'http', etc) or a relative path from the document root
175 * (beginning with '/'). Otherwise it behaves identically to
176 * addStyle() and draws from the /skins folder.
177 */
178 public function addExtensionStyle( $url ) {
179 array_push( $this->mExtStyles, $url );
180 }
181
182 /**
183 * Get all links added by extensions
184 *
185 * @return Array
186 */
187 function getExtStyle() {
188 return $this->mExtStyles;
189 }
190
191 /**
192 * Add a JavaScript file out of skins/common, or a given relative path.
193 *
194 * @param $file String: filename in skins/common or complete on-server path
195 * (/foo/bar.js)
196 * @param $version String: style version of the file. Defaults to $wgStyleVersion
197 */
198 public function addScriptFile( $file, $version = null ) {
199 global $wgStylePath, $wgStyleVersion;
200 // See if $file parameter is an absolute URL or begins with a slash
201 if( substr( $file, 0, 1 ) == '/' || preg_match( '#^[a-z]*://#i', $file ) ) {
202 $path = $file;
203 } else {
204 $path = "{$wgStylePath}/common/{$file}";
205 }
206 if ( is_null( $version ) )
207 $version = $wgStyleVersion;
208 $this->addScript( Html::linkedScript( wfAppendQuery( $path, $version ) ) );
209 }
210
211 /**
212 * Add a self-contained script tag with the given contents
213 *
214 * @param $script String: JavaScript text, no <script> tags
215 */
216 public function addInlineScript( $script ) {
217 $this->mScripts .= Html::inlineScript( "\n$script\n" ) . "\n";
218 }
219
220 /**
221 * Get all registered JS and CSS tags for the header.
222 *
223 * @return String
224 */
225 function getScript() {
226 return $this->mScripts . $this->getHeadItems();
227 }
228
229 /**
230 * Get the list of modules to include on this page
231 *
232 * @return Array of module names
233 */
234 public function getModules() {
235 return $this->mModules;
236 }
237
238 /**
239 * Add one or more modules recognized by the resource loader. Modules added
240 * through this function will be loaded by the resource loader when the
241 * page loads.
242 *
243 * @param $modules Mixed: module name (string) or array of module names
244 */
245 public function addModules( $modules ) {
246 $this->mModules = array_merge( $this->mModules, (array)$modules );
247 }
248
249 /**
250 * Get the list of module JS to include on this page
251 * @return array of module names
252 */
253 public function getModuleScripts() {
254 return $this->mModuleScripts;
255 }
256
257 /**
258 * Add only JS of one or more modules recognized by the resource loader. Module
259 * scripts added through this function will be loaded by the resource loader when
260 * the page loads.
261 *
262 * @param $modules Mixed: module name (string) or array of module names
263 */
264 public function addModuleScripts( $modules ) {
265 $this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules );
266 }
267
268 /**
269 * Get the list of module CSS to include on this page
270 *
271 * @return Array of module names
272 */
273 public function getModuleStyles() {
274 return $this->mModuleStyles;
275 }
276
277 /**
278 * Add only CSS of one or more modules recognized by the resource loader. Module
279 * styles added through this function will be loaded by the resource loader when
280 * the page loads.
281 *
282 * @param $modules Mixed: module name (string) or array of module names
283 */
284 public function addModuleStyles( $modules ) {
285 $this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules );
286 }
287
288 /**
289 * Get the list of module messages to include on this page
290 *
291 * @return Array of module names
292 */
293 public function getModuleMessages() {
294 return $this->mModuleMessages;
295 }
296
297 /**
298 * Add only messages of one or more modules recognized by the resource loader.
299 * Module messages added through this function will be loaded by the resource
300 * loader when the page loads.
301 *
302 * @param $modules Mixed: module name (string) or array of module names
303 */
304 public function addModuleMessages( $modules ) {
305 $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules );
306 }
307
308 /**
309 * Get all header items in a string
310 *
311 * @return String
312 */
313 function getHeadItems() {
314 $s = '';
315 foreach ( $this->mHeadItems as $item ) {
316 $s .= $item;
317 }
318 return $s;
319 }
320
321 /**
322 * Add or replace an header item to the output
323 *
324 * @param $name String: item name
325 * @param $value String: raw HTML
326 */
327 public function addHeadItem( $name, $value ) {
328 $this->mHeadItems[$name] = $value;
329 }
330
331 /**
332 * Check if the header item $name is already set
333 *
334 * @param $name String: item name
335 * @return Boolean
336 */
337 public function hasHeadItem( $name ) {
338 return isset( $this->mHeadItems[$name] );
339 }
340
341 /**
342 * Set the value of the ETag HTTP header, only used if $wgUseETag is true
343 *
344 * @param $tag String: value of "ETag" header
345 */
346 function setETag( $tag ) {
347 $this->mETag = $tag;
348 }
349
350 /**
351 * Set whether the output should only contain the body of the article,
352 * without any skin, sidebar, etc.
353 * Used e.g. when calling with "action=render".
354 *
355 * @param $only Boolean: whether to output only the body of the article
356 */
357 public function setArticleBodyOnly( $only ) {
358 $this->mArticleBodyOnly = $only;
359 }
360
361 /**
362 * Return whether the output will contain only the body of the article
363 *
364 * @return Boolean
365 */
366 public function getArticleBodyOnly() {
367 return $this->mArticleBodyOnly;
368 }
369
370 /**
371 * checkLastModified tells the client to use the client-cached page if
372 * possible. If sucessful, the OutputPage is disabled so that
373 * any future call to OutputPage->output() have no effect.
374 *
375 * Side effect: sets mLastModified for Last-Modified header
376 *
377 * @return Boolean: true iff cache-ok headers was sent.
378 */
379 public function checkLastModified( $timestamp ) {
380 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
381
382 if ( !$timestamp || $timestamp == '19700101000000' ) {
383 wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
384 return false;
385 }
386 if( !$wgCachePages ) {
387 wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
388 return false;
389 }
390 if( $wgUser->getOption( 'nocache' ) ) {
391 wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false );
392 return false;
393 }
394
395 $timestamp = wfTimestamp( TS_MW, $timestamp );
396 $modifiedTimes = array(
397 'page' => $timestamp,
398 'user' => $wgUser->getTouched(),
399 'epoch' => $wgCacheEpoch
400 );
401 wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
402
403 $maxModified = max( $modifiedTimes );
404 $this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified );
405
406 if( empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
407 wfDebug( __METHOD__ . ": client did not send If-Modified-Since header\n", false );
408 return false;
409 }
410
411 # Make debug info
412 $info = '';
413 foreach ( $modifiedTimes as $name => $value ) {
414 if ( $info !== '' ) {
415 $info .= ', ';
416 }
417 $info .= "$name=" . wfTimestamp( TS_ISO_8601, $value );
418 }
419
420 # IE sends sizes after the date like this:
421 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
422 # this breaks strtotime().
423 $clientHeader = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
424
425 wfSuppressWarnings(); // E_STRICT system time bitching
426 $clientHeaderTime = strtotime( $clientHeader );
427 wfRestoreWarnings();
428 if ( !$clientHeaderTime ) {
429 wfDebug( __METHOD__ . ": unable to parse the client's If-Modified-Since header: $clientHeader\n" );
430 return false;
431 }
432 $clientHeaderTime = wfTimestamp( TS_MW, $clientHeaderTime );
433
434 wfDebug( __METHOD__ . ": client sent If-Modified-Since: " .
435 wfTimestamp( TS_ISO_8601, $clientHeaderTime ) . "\n", false );
436 wfDebug( __METHOD__ . ": effective Last-Modified: " .
437 wfTimestamp( TS_ISO_8601, $maxModified ) . "\n", false );
438 if( $clientHeaderTime < $maxModified ) {
439 wfDebug( __METHOD__ . ": STALE, $info\n", false );
440 return false;
441 }
442
443 # Not modified
444 # Give a 304 response code and disable body output
445 wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", false );
446 ini_set( 'zlib.output_compression', 0 );
447 $wgRequest->response()->header( "HTTP/1.1 304 Not Modified" );
448 $this->sendCacheControl();
449 $this->disable();
450
451 // Don't output a compressed blob when using ob_gzhandler;
452 // it's technically against HTTP spec and seems to confuse
453 // Firefox when the response gets split over two packets.
454 wfClearOutputBuffers();
455
456 return true;
457 }
458
459 /**
460 * Override the last modified timestamp
461 *
462 * @param $timestamp String: new timestamp, in a format readable by
463 * wfTimestamp()
464 */
465 public function setLastModified( $timestamp ) {
466 $this->mLastModified = wfTimestamp( TS_RFC2822, $timestamp );
467 }
468
469 /**
470 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
471 *
472 * @param $policy String: the literal string to output as the contents of
473 * the meta tag. Will be parsed according to the spec and output in
474 * standardized form.
475 * @return null
476 */
477 public function setRobotPolicy( $policy ) {
478 $policy = Article::formatRobotPolicy( $policy );
479
480 if( isset( $policy['index'] ) ) {
481 $this->setIndexPolicy( $policy['index'] );
482 }
483 if( isset( $policy['follow'] ) ) {
484 $this->setFollowPolicy( $policy['follow'] );
485 }
486 }
487
488 /**
489 * Set the index policy for the page, but leave the follow policy un-
490 * touched.
491 *
492 * @param $policy string Either 'index' or 'noindex'.
493 * @return null
494 */
495 public function setIndexPolicy( $policy ) {
496 $policy = trim( $policy );
497 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
498 $this->mIndexPolicy = $policy;
499 }
500 }
501
502 /**
503 * Set the follow policy for the page, but leave the index policy un-
504 * touched.
505 *
506 * @param $policy String: either 'follow' or 'nofollow'.
507 * @return null
508 */
509 public function setFollowPolicy( $policy ) {
510 $policy = trim( $policy );
511 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
512 $this->mFollowPolicy = $policy;
513 }
514 }
515
516 /**
517 * Set the new value of the "action text", this will be added to the
518 * "HTML title", separated from it with " - ".
519 *
520 * @param $text String: new value of the "action text"
521 */
522 public function setPageTitleActionText( $text ) {
523 $this->mPageTitleActionText = $text;
524 }
525
526 /**
527 * Get the value of the "action text"
528 *
529 * @return String
530 */
531 public function getPageTitleActionText() {
532 if ( isset( $this->mPageTitleActionText ) ) {
533 return $this->mPageTitleActionText;
534 }
535 }
536
537 /**
538 * "HTML title" means the contents of <title>.
539 * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
540 */
541 public function setHTMLTitle( $name ) {
542 $this->mHTMLtitle = $name;
543 }
544
545 /**
546 * Return the "HTML title", i.e. the content of the <title> tag.
547 *
548 * @return String
549 */
550 public function getHTMLTitle() {
551 return $this->mHTMLtitle;
552 }
553
554 /**
555 * "Page title" means the contents of \<h1\>. It is stored as a valid HTML fragment.
556 * This function allows good tags like \<sup\> in the \<h1\> tag, but not bad tags like \<script\>.
557 * This function automatically sets \<title\> to the same content as \<h1\> but with all tags removed.
558 * Bad tags that were escaped in \<h1\> will still be escaped in \<title\>, and good tags like \<i\> will be dropped entirely.
559 */
560 public function setPageTitle( $name ) {
561 # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
562 # but leave "<i>foobar</i>" alone
563 $nameWithTags = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $name ) );
564 $this->mPagetitle = $nameWithTags;
565
566 $taction = $this->getPageTitleActionText();
567 if( !empty( $taction ) ) {
568 $name .= ' - '.$taction;
569 }
570
571 # change "<i>foo&amp;bar</i>" to "foo&bar"
572 $this->setHTMLTitle( wfMsg( 'pagetitle', Sanitizer::stripAllTags( $nameWithTags ) ) );
573 }
574
575 /**
576 * Return the "page title", i.e. the content of the \<h1\> tag.
577 *
578 * @return String
579 */
580 public function getPageTitle() {
581 return $this->mPagetitle;
582 }
583
584 /**
585 * Set the Title object to use
586 *
587 * @param $t Title object
588 */
589 public function setTitle( $t ) {
590 $this->mTitle = $t;
591 }
592
593 /**
594 * Get the Title object used in this instance
595 *
596 * @return Title
597 */
598 public function getTitle() {
599 if ( $this->mTitle instanceof Title ) {
600 return $this->mTitle;
601 } else {
602 wfDebug( __METHOD__ . " called and \$mTitle is null. Return \$wgTitle for sanity\n" );
603 global $wgTitle;
604 return $wgTitle;
605 }
606 }
607
608 /**
609 * Replace the subtile with $str
610 *
611 * @param $str String: new value of the subtitle
612 */
613 public function setSubtitle( $str ) {
614 $this->mSubtitle = /*$this->parse(*/ $str /*)*/; // @bug 2514
615 }
616
617 /**
618 * Add $str to the subtitle
619 *
620 * @param $str String to add to the subtitle
621 */
622 public function appendSubtitle( $str ) {
623 $this->mSubtitle .= /*$this->parse(*/ $str /*)*/; // @bug 2514
624 }
625
626 /**
627 * Get the subtitle
628 *
629 * @return String
630 */
631 public function getSubtitle() {
632 return $this->mSubtitle;
633 }
634
635 /**
636 * Set the page as printable, i.e. it'll be displayed with with all
637 * print styles included
638 */
639 public function setPrintable() {
640 $this->mPrintable = true;
641 }
642
643 /**
644 * Return whether the page is "printable"
645 *
646 * @return Boolean
647 */
648 public function isPrintable() {
649 return $this->mPrintable;
650 }
651
652 /**
653 * Disable output completely, i.e. calling output() will have no effect
654 */
655 public function disable() {
656 $this->mDoNothing = true;
657 }
658
659 /**
660 * Return whether the output will be completely disabled
661 *
662 * @return Boolean
663 */
664 public function isDisabled() {
665 return $this->mDoNothing;
666 }
667
668 /**
669 * Show an "add new section" link?
670 *
671 * @return Boolean
672 */
673 public function showNewSectionLink() {
674 return $this->mNewSectionLink;
675 }
676
677 /**
678 * Forcibly hide the new section link?
679 *
680 * @return Boolean
681 */
682 public function forceHideNewSectionLink() {
683 return $this->mHideNewSectionLink;
684 }
685
686 /**
687 * Add or remove feed links in the page header
688 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
689 * for the new version
690 * @see addFeedLink()
691 *
692 * @param $show Boolean: true: add default feeds, false: remove all feeds
693 */
694 public function setSyndicated( $show = true ) {
695 if ( $show ) {
696 $this->setFeedAppendQuery( false );
697 } else {
698 $this->mFeedLinks = array();
699 }
700 }
701
702 /**
703 * Add default feeds to the page header
704 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
705 * for the new version
706 * @see addFeedLink()
707 *
708 * @param $val String: query to append to feed links or false to output
709 * default links
710 */
711 public function setFeedAppendQuery( $val ) {
712 global $wgAdvertisedFeedTypes;
713
714 $this->mFeedLinks = array();
715
716 foreach ( $wgAdvertisedFeedTypes as $type ) {
717 $query = "feed=$type";
718 if ( is_string( $val ) ) {
719 $query .= '&' . $val;
720 }
721 $this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query );
722 }
723 }
724
725 /**
726 * Add a feed link to the page header
727 *
728 * @param $format String: feed type, should be a key of $wgFeedClasses
729 * @param $href String: URL
730 */
731 public function addFeedLink( $format, $href ) {
732 global $wgAdvertisedFeedTypes;
733
734 if ( in_array( $format, $wgAdvertisedFeedTypes ) ) {
735 $this->mFeedLinks[$format] = $href;
736 }
737 }
738
739 /**
740 * Should we output feed links for this page?
741 * @return Boolean
742 */
743 public function isSyndicated() {
744 return count( $this->mFeedLinks ) > 0;
745 }
746
747 /**
748 * Return URLs for each supported syndication format for this page.
749 * @return array associating format keys with URLs
750 */
751 public function getSyndicationLinks() {
752 return $this->mFeedLinks;
753 }
754
755 /**
756 * Will currently always return null
757 *
758 * @return null
759 */
760 public function getFeedAppendQuery() {
761 return $this->mFeedLinksAppendQuery;
762 }
763
764 /**
765 * Set whether the displayed content is related to the source of the
766 * corresponding article on the wiki
767 * Setting true will cause the change "article related" toggle to true
768 *
769 * @param $v Boolean
770 */
771 public function setArticleFlag( $v ) {
772 $this->mIsarticle = $v;
773 if ( $v ) {
774 $this->mIsArticleRelated = $v;
775 }
776 }
777
778 /**
779 * Return whether the content displayed page is related to the source of
780 * the corresponding article on the wiki
781 *
782 * @return Boolean
783 */
784 public function isArticle() {
785 return $this->mIsarticle;
786 }
787
788 /**
789 * Set whether this page is related an article on the wiki
790 * Setting false will cause the change of "article flag" toggle to false
791 *
792 * @param $v Boolean
793 */
794 public function setArticleRelated( $v ) {
795 $this->mIsArticleRelated = $v;
796 if ( !$v ) {
797 $this->mIsarticle = false;
798 }
799 }
800
801 /**
802 * Return whether this page is related an article on the wiki
803 *
804 * @return Boolean
805 */
806 public function isArticleRelated() {
807 return $this->mIsArticleRelated;
808 }
809
810 /**
811 * Add new language links
812 *
813 * @param $newLinkArray Associative array mapping language code to the page
814 * name
815 */
816 public function addLanguageLinks( $newLinkArray ) {
817 $this->mLanguageLinks += $newLinkArray;
818 }
819
820 /**
821 * Reset the language links and add new language links
822 *
823 * @param $newLinkArray Associative array mapping language code to the page
824 * name
825 */
826 public function setLanguageLinks( $newLinkArray ) {
827 $this->mLanguageLinks = $newLinkArray;
828 }
829
830 /**
831 * Get the list of language links
832 *
833 * @return Associative array mapping language code to the page name
834 */
835 public function getLanguageLinks() {
836 return $this->mLanguageLinks;
837 }
838
839 /**
840 * Add an array of categories, with names in the keys
841 *
842 * @param $categories Associative array mapping category name to its sort key
843 */
844 public function addCategoryLinks( $categories ) {
845 global $wgUser, $wgContLang;
846
847 if ( !is_array( $categories ) || count( $categories ) == 0 ) {
848 return;
849 }
850
851 # Add the links to a LinkBatch
852 $arr = array( NS_CATEGORY => $categories );
853 $lb = new LinkBatch;
854 $lb->setArray( $arr );
855
856 # Fetch existence plus the hiddencat property
857 $dbr = wfGetDB( DB_SLAVE );
858 $pageTable = $dbr->tableName( 'page' );
859 $where = $lb->constructSet( 'page', $dbr );
860 $propsTable = $dbr->tableName( 'page_props' );
861 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest, pp_value
862 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
863 $res = $dbr->query( $sql, __METHOD__ );
864
865 # Add the results to the link cache
866 $lb->addResultToCache( LinkCache::singleton(), $res );
867
868 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
869 $categories = array_combine(
870 array_keys( $categories ),
871 array_fill( 0, count( $categories ), 'normal' )
872 );
873
874 # Mark hidden categories
875 foreach ( $res as $row ) {
876 if ( isset( $row->pp_value ) ) {
877 $categories[$row->page_title] = 'hidden';
878 }
879 }
880
881 # Add the remaining categories to the skin
882 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks ) ) ) {
883 $sk = $wgUser->getSkin();
884 foreach ( $categories as $category => $type ) {
885 $origcategory = $category;
886 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
887 $wgContLang->findVariantLink( $category, $title, true );
888 if ( $category != $origcategory ) {
889 if ( array_key_exists( $category, $categories ) ) {
890 continue;
891 }
892 }
893 $text = $wgContLang->convertHtml( $title->getText() );
894 $this->mCategories[] = $title->getText();
895 $this->mCategoryLinks[$type][] = $sk->link( $title, $text );
896 }
897 }
898 }
899
900 /**
901 * Reset the category links (but not the category list) and add $categories
902 *
903 * @param $categories Associative array mapping category name to its sort key
904 */
905 public function setCategoryLinks( $categories ) {
906 $this->mCategoryLinks = array();
907 $this->addCategoryLinks( $categories );
908 }
909
910 /**
911 * Get the list of category links, in a 2-D array with the following format:
912 * $arr[$type][] = $link, where $type is either "normal" or "hidden" (for
913 * hidden categories) and $link a HTML fragment with a link to the category
914 * page
915 *
916 * @return Array
917 */
918 public function getCategoryLinks() {
919 return $this->mCategoryLinks;
920 }
921
922 /**
923 * Get the list of category names this page belongs to
924 *
925 * @return Array of strings
926 */
927 public function getCategories() {
928 return $this->mCategories;
929 }
930
931 /**
932 * Suppress the quickbar from the output, only for skin supporting
933 * the quickbar
934 */
935 public function suppressQuickbar() {
936 $this->mSuppressQuickbar = true;
937 }
938
939 /**
940 * Return whether the quickbar should be suppressed from the output
941 *
942 * @return Boolean
943 */
944 public function isQuickbarSuppressed() {
945 return $this->mSuppressQuickbar;
946 }
947
948 /**
949 * Remove user JavaScript from scripts to load
950 */
951 public function disallowUserJs() {
952 $this->mAllowUserJs = false;
953 }
954
955 /**
956 * Return whether user JavaScript is allowed for this page
957 *
958 * @return Boolean
959 */
960 public function isUserJsAllowed() {
961 return $this->mAllowUserJs;
962 }
963
964 /**
965 * Prepend $text to the body HTML
966 *
967 * @param $text String: HTML
968 */
969 public function prependHTML( $text ) {
970 $this->mBodytext = $text . $this->mBodytext;
971 }
972
973 /**
974 * Append $text to the body HTML
975 *
976 * @param $text String: HTML
977 */
978 public function addHTML( $text ) {
979 $this->mBodytext .= $text;
980 }
981
982 /**
983 * Clear the body HTML
984 */
985 public function clearHTML() {
986 $this->mBodytext = '';
987 }
988
989 /**
990 * Get the body HTML
991 *
992 * @return String: HTML
993 */
994 public function getHTML() {
995 return $this->mBodytext;
996 }
997
998 /**
999 * Add $text to the debug output
1000 *
1001 * @param $text String: debug text
1002 */
1003 public function debug( $text ) {
1004 $this->mDebugtext .= $text;
1005 }
1006
1007 /**
1008 * @deprecated use parserOptions() instead
1009 */
1010 public function setParserOptions( $options ) {
1011 wfDeprecated( __METHOD__ );
1012 return $this->parserOptions( $options );
1013 }
1014
1015 /**
1016 * Get/set the ParserOptions object to use for wikitext parsing
1017 *
1018 * @param $options either the ParserOption to use or null to only get the
1019 * current ParserOption object
1020 * @return current ParserOption object
1021 */
1022 public function parserOptions( $options = null ) {
1023 if ( !$this->mParserOptions ) {
1024 $this->mParserOptions = new ParserOptions;
1025 }
1026 return wfSetVar( $this->mParserOptions, $options );
1027 }
1028
1029 /**
1030 * Set the revision ID which will be seen by the wiki text parser
1031 * for things such as embedded {{REVISIONID}} variable use.
1032 *
1033 * @param $revid Mixed: an positive integer, or null
1034 * @return Mixed: previous value
1035 */
1036 public function setRevisionId( $revid ) {
1037 $val = is_null( $revid ) ? null : intval( $revid );
1038 return wfSetVar( $this->mRevisionId, $val );
1039 }
1040
1041 /**
1042 * Get the current revision ID
1043 *
1044 * @return Integer
1045 */
1046 public function getRevisionId() {
1047 return $this->mRevisionId;
1048 }
1049
1050 /**
1051 * Convert wikitext to HTML and add it to the buffer
1052 * Default assumes that the current page title will be used.
1053 *
1054 * @param $text String
1055 * @param $linestart Boolean: is this the start of a line?
1056 */
1057 public function addWikiText( $text, $linestart = true ) {
1058 $title = $this->getTitle(); // Work arround E_STRICT
1059 $this->addWikiTextTitle( $text, $title, $linestart );
1060 }
1061
1062 /**
1063 * Add wikitext with a custom Title object
1064 *
1065 * @param $text String: wikitext
1066 * @param $title Title object
1067 * @param $linestart Boolean: is this the start of a line?
1068 */
1069 public function addWikiTextWithTitle( $text, &$title, $linestart = true ) {
1070 $this->addWikiTextTitle( $text, $title, $linestart );
1071 }
1072
1073 /**
1074 * Add wikitext with a custom Title object and
1075 *
1076 * @param $text String: wikitext
1077 * @param $title Title object
1078 * @param $linestart Boolean: is this the start of a line?
1079 */
1080 function addWikiTextTitleTidy( $text, &$title, $linestart = true ) {
1081 $this->addWikiTextTitle( $text, $title, $linestart, true );
1082 }
1083
1084 /**
1085 * Add wikitext with tidy enabled
1086 *
1087 * @param $text String: wikitext
1088 * @param $linestart Boolean: is this the start of a line?
1089 */
1090 public function addWikiTextTidy( $text, $linestart = true ) {
1091 $title = $this->getTitle();
1092 $this->addWikiTextTitleTidy( $text, $title, $linestart );
1093 }
1094
1095 /**
1096 * Add wikitext with a custom Title object
1097 *
1098 * @param $text String: wikitext
1099 * @param $title Title object
1100 * @param $linestart Boolean: is this the start of a line?
1101 * @param $tidy Boolean: whether to use tidy
1102 */
1103 public function addWikiTextTitle( $text, &$title, $linestart, $tidy = false ) {
1104 global $wgParser;
1105
1106 wfProfileIn( __METHOD__ );
1107
1108 wfIncrStats( 'pcache_not_possible' );
1109
1110 $popts = $this->parserOptions();
1111 $oldTidy = $popts->setTidy( $tidy );
1112
1113 $parserOutput = $wgParser->parse(
1114 $text, $title, $popts,
1115 $linestart, true, $this->mRevisionId
1116 );
1117
1118 $popts->setTidy( $oldTidy );
1119
1120 $this->addParserOutput( $parserOutput );
1121
1122 wfProfileOut( __METHOD__ );
1123 }
1124
1125 /**
1126 * Add wikitext to the buffer, assuming that this is the primary text for a page view
1127 * Saves the text into the parser cache if possible.
1128 *
1129 * @param $text String: wikitext
1130 * @param $article Article object
1131 * @param $cache Boolean
1132 * @deprecated Use Article::outputWikitext
1133 */
1134 public function addPrimaryWikiText( $text, $article, $cache = true ) {
1135 global $wgParser;
1136
1137 wfDeprecated( __METHOD__ );
1138
1139 $popts = $this->parserOptions();
1140 $popts->setTidy( true );
1141 $parserOutput = $wgParser->parse(
1142 $text, $article->mTitle,
1143 $popts, true, true, $this->mRevisionId
1144 );
1145 $popts->setTidy( false );
1146 if ( $cache && $article && $parserOutput->isCacheable() ) {
1147 $parserCache = ParserCache::singleton();
1148 $parserCache->save( $parserOutput, $article, $popts );
1149 }
1150
1151 $this->addParserOutput( $parserOutput );
1152 }
1153
1154 /**
1155 * @deprecated use addWikiTextTidy()
1156 */
1157 public function addSecondaryWikiText( $text, $linestart = true ) {
1158 wfDeprecated( __METHOD__ );
1159 $this->addWikiTextTitleTidy( $text, $this->getTitle(), $linestart );
1160 }
1161
1162 /**
1163 * Add a ParserOutput object, but without Html
1164 *
1165 * @param $parserOutput ParserOutput object
1166 */
1167 public function addParserOutputNoText( &$parserOutput ) {
1168 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
1169 $this->addCategoryLinks( $parserOutput->getCategories() );
1170 $this->mNewSectionLink = $parserOutput->getNewSection();
1171 $this->mHideNewSectionLink = $parserOutput->getHideNewSection();
1172
1173 $this->mParseWarnings = $parserOutput->getWarnings();
1174 if ( !$parserOutput->isCacheable() ) {
1175 $this->enableClientCache( false );
1176 }
1177 $this->mNoGallery = $parserOutput->getNoGallery();
1178 $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
1179 $this->addModules( $parserOutput->getModules() );
1180 // Versioning...
1181 foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
1182 if ( isset( $this->mTemplateIds[$ns] ) ) {
1183 $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
1184 } else {
1185 $this->mTemplateIds[$ns] = $dbks;
1186 }
1187 }
1188
1189 // Hooks registered in the object
1190 global $wgParserOutputHooks;
1191 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
1192 list( $hookName, $data ) = $hookInfo;
1193 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
1194 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
1195 }
1196 }
1197
1198 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
1199 }
1200
1201 /**
1202 * Add a ParserOutput object
1203 *
1204 * @param $parserOutput ParserOutput
1205 */
1206 function addParserOutput( &$parserOutput ) {
1207 $this->addParserOutputNoText( $parserOutput );
1208 $text = $parserOutput->getText();
1209 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
1210 $this->addHTML( $text );
1211 }
1212
1213
1214 /**
1215 * Add the output of a QuickTemplate to the output buffer
1216 *
1217 * @param $template QuickTemplate
1218 */
1219 public function addTemplate( &$template ) {
1220 ob_start();
1221 $template->execute();
1222 $this->addHTML( ob_get_contents() );
1223 ob_end_clean();
1224 }
1225
1226 /**
1227 * Parse wikitext and return the HTML.
1228 *
1229 * @param $text String
1230 * @param $linestart Boolean: is this the start of a line?
1231 * @param $interface Boolean: use interface language ($wgLang instead of
1232 * $wgContLang) while parsing language sensitive magic
1233 * words like GRAMMAR and PLURAL
1234 * @return String: HTML
1235 */
1236 public function parse( $text, $linestart = true, $interface = false ) {
1237 global $wgParser;
1238 if( is_null( $this->getTitle() ) ) {
1239 throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
1240 }
1241 $popts = $this->parserOptions();
1242 if ( $interface ) {
1243 $popts->setInterfaceMessage( true );
1244 }
1245 $parserOutput = $wgParser->parse(
1246 $text, $this->getTitle(), $popts,
1247 $linestart, true, $this->mRevisionId
1248 );
1249 if ( $interface ) {
1250 $popts->setInterfaceMessage( false );
1251 }
1252 return $parserOutput->getText();
1253 }
1254
1255 /**
1256 * Parse wikitext, strip paragraphs, and return the HTML.
1257 *
1258 * @param $text String
1259 * @param $linestart Boolean: is this the start of a line?
1260 * @param $interface Boolean: use interface language ($wgLang instead of
1261 * $wgContLang) while parsing language sensitive magic
1262 * words like GRAMMAR and PLURAL
1263 * @return String: HTML
1264 */
1265 public function parseInline( $text, $linestart = true, $interface = false ) {
1266 $parsed = $this->parse( $text, $linestart, $interface );
1267
1268 $m = array();
1269 if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
1270 $parsed = $m[1];
1271 }
1272
1273 return $parsed;
1274 }
1275
1276 /**
1277 * @deprecated
1278 *
1279 * @param $article Article
1280 * @return Boolean: true if successful, else false.
1281 */
1282 public function tryParserCache( &$article ) {
1283 wfDeprecated( __METHOD__ );
1284 $parserOutput = ParserCache::singleton()->get( $article, $article->getParserOptions() );
1285
1286 if ( $parserOutput !== false ) {
1287 $this->addParserOutput( $parserOutput );
1288 return true;
1289 } else {
1290 return false;
1291 }
1292 }
1293
1294 /**
1295 * Set the value of the "s-maxage" part of the "Cache-control" HTTP header
1296 *
1297 * @param $maxage Integer: maximum cache time on the Squid, in seconds.
1298 */
1299 public function setSquidMaxage( $maxage ) {
1300 $this->mSquidMaxage = $maxage;
1301 }
1302
1303 /**
1304 * Use enableClientCache(false) to force it to send nocache headers
1305 *
1306 * @param $state ??
1307 */
1308 public function enableClientCache( $state ) {
1309 return wfSetVar( $this->mEnableClientCache, $state );
1310 }
1311
1312 /**
1313 * Get the list of cookies that will influence on the cache
1314 *
1315 * @return Array
1316 */
1317 function getCacheVaryCookies() {
1318 global $wgCookiePrefix, $wgCacheVaryCookies;
1319 static $cookies;
1320 if ( $cookies === null ) {
1321 $cookies = array_merge(
1322 array(
1323 "{$wgCookiePrefix}Token",
1324 "{$wgCookiePrefix}LoggedOut",
1325 session_name()
1326 ),
1327 $wgCacheVaryCookies
1328 );
1329 wfRunHooks( 'GetCacheVaryCookies', array( $this, &$cookies ) );
1330 }
1331 return $cookies;
1332 }
1333
1334 /**
1335 * Return whether this page is not cacheable because "useskin" or "uselang"
1336 * URL parameters were passed.
1337 *
1338 * @return Boolean
1339 */
1340 function uncacheableBecauseRequestVars() {
1341 global $wgRequest;
1342 return $wgRequest->getText( 'useskin', false ) === false
1343 && $wgRequest->getText( 'uselang', false ) === false;
1344 }
1345
1346 /**
1347 * Check if the request has a cache-varying cookie header
1348 * If it does, it's very important that we don't allow public caching
1349 *
1350 * @return Boolean
1351 */
1352 function haveCacheVaryCookies() {
1353 global $wgRequest;
1354 $cookieHeader = $wgRequest->getHeader( 'cookie' );
1355 if ( $cookieHeader === false ) {
1356 return false;
1357 }
1358 $cvCookies = $this->getCacheVaryCookies();
1359 foreach ( $cvCookies as $cookieName ) {
1360 # Check for a simple string match, like the way squid does it
1361 if ( strpos( $cookieHeader, $cookieName ) !== false ) {
1362 wfDebug( __METHOD__ . ": found $cookieName\n" );
1363 return true;
1364 }
1365 }
1366 wfDebug( __METHOD__ . ": no cache-varying cookies found\n" );
1367 return false;
1368 }
1369
1370 /**
1371 * Add an HTTP header that will influence on the cache
1372 *
1373 * @param $header String: header name
1374 * @param $option either an Array or null
1375 */
1376 public function addVaryHeader( $header, $option = null ) {
1377 if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
1378 $this->mVaryHeader[$header] = $option;
1379 } elseif( is_array( $option ) ) {
1380 if( is_array( $this->mVaryHeader[$header] ) ) {
1381 $this->mVaryHeader[$header] = array_merge( $this->mVaryHeader[$header], $option );
1382 } else {
1383 $this->mVaryHeader[$header] = $option;
1384 }
1385 }
1386 $this->mVaryHeader[$header] = array_unique( $this->mVaryHeader[$header] );
1387 }
1388
1389 /**
1390 * Get a complete X-Vary-Options header
1391 *
1392 * @return String
1393 */
1394 public function getXVO() {
1395 $cvCookies = $this->getCacheVaryCookies();
1396
1397 $cookiesOption = array();
1398 foreach ( $cvCookies as $cookieName ) {
1399 $cookiesOption[] = 'string-contains=' . $cookieName;
1400 }
1401 $this->addVaryHeader( 'Cookie', $cookiesOption );
1402
1403 $headers = array();
1404 foreach( $this->mVaryHeader as $header => $option ) {
1405 $newheader = $header;
1406 if( is_array( $option ) ) {
1407 $newheader .= ';' . implode( ';', $option );
1408 }
1409 $headers[] = $newheader;
1410 }
1411 $xvo = 'X-Vary-Options: ' . implode( ',', $headers );
1412
1413 return $xvo;
1414 }
1415
1416 /**
1417 * bug 21672: Add Accept-Language to Vary and XVO headers
1418 * if there's no 'variant' parameter existed in GET.
1419 *
1420 * For example:
1421 * /w/index.php?title=Main_page should always be served; but
1422 * /w/index.php?title=Main_page&variant=zh-cn should never be served.
1423 */
1424 function addAcceptLanguage() {
1425 global $wgRequest, $wgContLang;
1426 if( !$wgRequest->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
1427 $variants = $wgContLang->getVariants();
1428 $aloption = array();
1429 foreach ( $variants as $variant ) {
1430 if( $variant === $wgContLang->getCode() ) {
1431 continue;
1432 } else {
1433 $aloption[] = "string-contains=$variant";
1434 }
1435 }
1436 $this->addVaryHeader( 'Accept-Language', $aloption );
1437 }
1438 }
1439
1440 /**
1441 * Send cache control HTTP headers
1442 */
1443 public function sendCacheControl() {
1444 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
1445
1446 $response = $wgRequest->response();
1447 if ( $wgUseETag && $this->mETag ) {
1448 $response->header( "ETag: $this->mETag" );
1449 }
1450
1451 $this->addAcceptLanguage();
1452
1453 # don't serve compressed data to clients who can't handle it
1454 # maintain different caches for logged-in users and non-logged in ones
1455 $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ) );
1456
1457 if ( $wgUseXVO ) {
1458 # Add an X-Vary-Options header for Squid with Wikimedia patches
1459 $response->header( $this->getXVO() );
1460 }
1461
1462 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache ) {
1463 if(
1464 $wgUseSquid && session_id() == '' && !$this->isPrintable() &&
1465 $this->mSquidMaxage != 0 && !$this->haveCacheVaryCookies()
1466 )
1467 {
1468 if ( $wgUseESI ) {
1469 # We'll purge the proxy cache explicitly, but require end user agents
1470 # to revalidate against the proxy on each visit.
1471 # Surrogate-Control controls our Squid, Cache-Control downstream caches
1472 wfDebug( __METHOD__ . ": proxy caching with ESI; {$this->mLastModified} **\n", false );
1473 # start with a shorter timeout for initial testing
1474 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
1475 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
1476 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
1477 } else {
1478 # We'll purge the proxy cache for anons explicitly, but require end user agents
1479 # to revalidate against the proxy on each visit.
1480 # IMPORTANT! The Squid needs to replace the Cache-Control header with
1481 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
1482 wfDebug( __METHOD__ . ": local proxy caching; {$this->mLastModified} **\n", false );
1483 # start with a shorter timeout for initial testing
1484 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
1485 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
1486 }
1487 } else {
1488 # We do want clients to cache if they can, but they *must* check for updates
1489 # on revisiting the page.
1490 wfDebug( __METHOD__ . ": private caching; {$this->mLastModified} **\n", false );
1491 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1492 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
1493 }
1494 if($this->mLastModified) {
1495 $response->header( "Last-Modified: {$this->mLastModified}" );
1496 }
1497 } else {
1498 wfDebug( __METHOD__ . ": no caching **\n", false );
1499
1500 # In general, the absence of a last modified header should be enough to prevent
1501 # the client from using its cache. We send a few other things just to make sure.
1502 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1503 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1504 $response->header( 'Pragma: no-cache' );
1505 }
1506 }
1507
1508 /**
1509 * Get the message associed with the HTTP response code $code
1510 *
1511 * @param $code Integer: status code
1512 * @return String or null: message or null if $code is not in the list of
1513 * messages
1514 */
1515 public static function getStatusMessage( $code ) {
1516 static $statusMessage = array(
1517 100 => 'Continue',
1518 101 => 'Switching Protocols',
1519 102 => 'Processing',
1520 200 => 'OK',
1521 201 => 'Created',
1522 202 => 'Accepted',
1523 203 => 'Non-Authoritative Information',
1524 204 => 'No Content',
1525 205 => 'Reset Content',
1526 206 => 'Partial Content',
1527 207 => 'Multi-Status',
1528 300 => 'Multiple Choices',
1529 301 => 'Moved Permanently',
1530 302 => 'Found',
1531 303 => 'See Other',
1532 304 => 'Not Modified',
1533 305 => 'Use Proxy',
1534 307 => 'Temporary Redirect',
1535 400 => 'Bad Request',
1536 401 => 'Unauthorized',
1537 402 => 'Payment Required',
1538 403 => 'Forbidden',
1539 404 => 'Not Found',
1540 405 => 'Method Not Allowed',
1541 406 => 'Not Acceptable',
1542 407 => 'Proxy Authentication Required',
1543 408 => 'Request Timeout',
1544 409 => 'Conflict',
1545 410 => 'Gone',
1546 411 => 'Length Required',
1547 412 => 'Precondition Failed',
1548 413 => 'Request Entity Too Large',
1549 414 => 'Request-URI Too Large',
1550 415 => 'Unsupported Media Type',
1551 416 => 'Request Range Not Satisfiable',
1552 417 => 'Expectation Failed',
1553 422 => 'Unprocessable Entity',
1554 423 => 'Locked',
1555 424 => 'Failed Dependency',
1556 500 => 'Internal Server Error',
1557 501 => 'Not Implemented',
1558 502 => 'Bad Gateway',
1559 503 => 'Service Unavailable',
1560 504 => 'Gateway Timeout',
1561 505 => 'HTTP Version Not Supported',
1562 507 => 'Insufficient Storage'
1563 );
1564 return isset( $statusMessage[$code] ) ? $statusMessage[$code] : null;
1565 }
1566
1567 /**
1568 * Finally, all the text has been munged and accumulated into
1569 * the object, let's actually output it:
1570 */
1571 public function output() {
1572 global $wgUser, $wgOutputEncoding, $wgRequest;
1573 global $wgLanguageCode, $wgDebugRedirects, $wgMimeType;
1574 global $wgUseAjax, $wgAjaxWatch;
1575 global $wgEnableMWSuggest, $wgUniversalEditButton;
1576 global $wgArticle;
1577
1578 if( $this->mDoNothing ) {
1579 return;
1580 }
1581 wfProfileIn( __METHOD__ );
1582 if ( $this->mRedirect != '' ) {
1583 # Standards require redirect URLs to be absolute
1584 $this->mRedirect = wfExpandUrl( $this->mRedirect );
1585 if( $this->mRedirectCode == '301' || $this->mRedirectCode == '303' ) {
1586 if( !$wgDebugRedirects ) {
1587 $message = self::getStatusMessage( $this->mRedirectCode );
1588 $wgRequest->response()->header( "HTTP/1.1 {$this->mRedirectCode} $message" );
1589 }
1590 $this->mLastModified = wfTimestamp( TS_RFC2822 );
1591 }
1592 $this->sendCacheControl();
1593
1594 $wgRequest->response()->header( "Content-Type: text/html; charset=utf-8" );
1595 if( $wgDebugRedirects ) {
1596 $url = htmlspecialchars( $this->mRedirect );
1597 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
1598 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
1599 print "</body>\n</html>\n";
1600 } else {
1601 $wgRequest->response()->header( 'Location: ' . $this->mRedirect );
1602 }
1603 wfProfileOut( __METHOD__ );
1604 return;
1605 } elseif ( $this->mStatusCode ) {
1606 $message = self::getStatusMessage( $this->mStatusCode );
1607 if ( $message ) {
1608 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $message );
1609 }
1610 }
1611
1612 $sk = $wgUser->getSkin();
1613
1614 // Add base resources
1615 $this->addModules( array( 'mediawiki.legacy.wikibits' ) );
1616
1617 // Add various resources if required
1618 if ( $wgUseAjax ) {
1619 $this->addModules( 'mediawiki.legacy.ajax' );
1620
1621 wfRunHooks( 'AjaxAddScript', array( &$this ) );
1622
1623 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
1624 $this->addModules( 'mediawiki.legacy.ajaxwatch' );
1625 }
1626
1627 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
1628 $this->addModules( 'mediawiki.legacy.mwsuggest' );
1629 }
1630 }
1631
1632 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
1633 $this->addModules( 'mediawiki.legacy.rightclickedit' );
1634 }
1635
1636 if( $wgUniversalEditButton ) {
1637 if( isset( $wgArticle ) && $this->getTitle() && $this->getTitle()->quickUserCan( 'edit' )
1638 && ( $this->getTitle()->exists() || $this->getTitle()->quickUserCan( 'create' ) ) ) {
1639 // Original UniversalEditButton
1640 $msg = wfMsg( 'edit' );
1641 $this->addLink( array(
1642 'rel' => 'alternate',
1643 'type' => 'application/x-wiki',
1644 'title' => $msg,
1645 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1646 ) );
1647 // Alternate edit link
1648 $this->addLink( array(
1649 'rel' => 'edit',
1650 'title' => $msg,
1651 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1652 ) );
1653 }
1654 }
1655
1656
1657 # Buffer output; final headers may depend on later processing
1658 ob_start();
1659
1660 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1661 $wgRequest->response()->header( 'Content-language: ' . $wgLanguageCode );
1662
1663 if ( $this->mArticleBodyOnly ) {
1664 $this->out( $this->mBodytext );
1665 } else {
1666 // Hook that allows last minute changes to the output page, e.g.
1667 // adding of CSS or Javascript by extensions.
1668 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
1669
1670 wfProfileIn( 'Output-skin' );
1671 $sk->outputPage( $this );
1672 wfProfileOut( 'Output-skin' );
1673 }
1674
1675 $this->sendCacheControl();
1676 ob_end_flush();
1677 wfProfileOut( __METHOD__ );
1678 }
1679
1680 /**
1681 * Actually output something with print(). Performs an iconv to the
1682 * output encoding, if needed.
1683 *
1684 * @param $ins String: the string to output
1685 */
1686 public function out( $ins ) {
1687 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
1688 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
1689 $outs = $ins;
1690 } else {
1691 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
1692 if ( false === $outs ) {
1693 $outs = $ins;
1694 }
1695 }
1696 print $outs;
1697 }
1698
1699 /**
1700 * @todo document
1701 */
1702 public static function setEncodings() {
1703 global $wgInputEncoding, $wgOutputEncoding;
1704
1705 $wgInputEncoding = strtolower( $wgInputEncoding );
1706
1707 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
1708 $wgOutputEncoding = strtolower( $wgOutputEncoding );
1709 return;
1710 }
1711 $wgOutputEncoding = $wgInputEncoding;
1712 }
1713
1714 /**
1715 * @deprecated use wfReportTime() instead.
1716 *
1717 * @return String
1718 */
1719 public function reportTime() {
1720 wfDeprecated( __METHOD__ );
1721 $time = wfReportTime();
1722 return $time;
1723 }
1724
1725 /**
1726 * Produce a "user is blocked" page.
1727 *
1728 * @param $return Boolean: whether to have a "return to $wgTitle" message or not.
1729 * @return nothing
1730 */
1731 function blockedPage( $return = true ) {
1732 global $wgUser, $wgContLang, $wgLang;
1733
1734 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
1735 $this->setRobotPolicy( 'noindex,nofollow' );
1736 $this->setArticleRelated( false );
1737
1738 $name = User::whoIs( $wgUser->blockedBy() );
1739 $reason = $wgUser->blockedFor();
1740 if( $reason == '' ) {
1741 $reason = wfMsg( 'blockednoreason' );
1742 }
1743 $blockTimestamp = $wgLang->timeanddate(
1744 wfTimestamp( TS_MW, $wgUser->mBlock->mTimestamp ), true
1745 );
1746 $ip = wfGetIP();
1747
1748 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
1749
1750 $blockid = $wgUser->mBlock->mId;
1751
1752 $blockExpiry = $wgUser->mBlock->mExpiry;
1753 if ( $blockExpiry == 'infinity' ) {
1754 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1755 // Search for localization in 'ipboptions'
1756 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1757 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1758 if ( strpos( $option, ':' ) === false ) {
1759 continue;
1760 }
1761 list( $show, $value ) = explode( ':', $option );
1762 if ( $value == 'infinite' || $value == 'indefinite' ) {
1763 $blockExpiry = $show;
1764 break;
1765 }
1766 }
1767 } else {
1768 $blockExpiry = $wgLang->timeanddate(
1769 wfTimestamp( TS_MW, $blockExpiry ),
1770 true
1771 );
1772 }
1773
1774 if ( $wgUser->mBlock->mAuto ) {
1775 $msg = 'autoblockedtext';
1776 } else {
1777 $msg = 'blockedtext';
1778 }
1779
1780 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1781 * This could be a username, an IP range, or a single IP. */
1782 $intended = $wgUser->mBlock->mAddress;
1783
1784 $this->addWikiMsg(
1785 $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
1786 $intended, $blockTimestamp
1787 );
1788
1789 # Don't auto-return to special pages
1790 if( $return ) {
1791 $return = $this->getTitle()->getNamespace() > -1 ? $this->getTitle() : null;
1792 $this->returnToMain( null, $return );
1793 }
1794 }
1795
1796 /**
1797 * Output a standard error page
1798 *
1799 * @param $title String: message key for page title
1800 * @param $msg String: message key for page text
1801 * @param $params Array: message parameters
1802 */
1803 public function showErrorPage( $title, $msg, $params = array() ) {
1804 if ( $this->getTitle() ) {
1805 $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1806 }
1807 $this->setPageTitle( wfMsg( $title ) );
1808 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1809 $this->setRobotPolicy( 'noindex,nofollow' );
1810 $this->setArticleRelated( false );
1811 $this->enableClientCache( false );
1812 $this->mRedirect = '';
1813 $this->mBodytext = '';
1814
1815 array_unshift( $params, 'parse' );
1816 array_unshift( $params, $msg );
1817 $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
1818
1819 $this->returnToMain();
1820 }
1821
1822 /**
1823 * Output a standard permission error page
1824 *
1825 * @param $errors Array: error message keys
1826 * @param $action String: action that was denied or null if unknown
1827 */
1828 public function showPermissionsErrorPage( $errors, $action = null ) {
1829 $this->mDebugtext .= 'Original title: ' .
1830 $this->getTitle()->getPrefixedText() . "\n";
1831 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1832 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1833 $this->setRobotPolicy( 'noindex,nofollow' );
1834 $this->setArticleRelated( false );
1835 $this->enableClientCache( false );
1836 $this->mRedirect = '';
1837 $this->mBodytext = '';
1838 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1839 }
1840
1841 /**
1842 * Display an error page indicating that a given version of MediaWiki is
1843 * required to use it
1844 *
1845 * @param $version Mixed: the version of MediaWiki needed to use the page
1846 */
1847 public function versionRequired( $version ) {
1848 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1849 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1850 $this->setRobotPolicy( 'noindex,nofollow' );
1851 $this->setArticleRelated( false );
1852 $this->mBodytext = '';
1853
1854 $this->addWikiMsg( 'versionrequiredtext', $version );
1855 $this->returnToMain();
1856 }
1857
1858 /**
1859 * Display an error page noting that a given permission bit is required.
1860 *
1861 * @param $permission String: key required
1862 */
1863 public function permissionRequired( $permission ) {
1864 global $wgLang;
1865
1866 $this->setPageTitle( wfMsg( 'badaccess' ) );
1867 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1868 $this->setRobotPolicy( 'noindex,nofollow' );
1869 $this->setArticleRelated( false );
1870 $this->mBodytext = '';
1871
1872 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
1873 User::getGroupsWithPermission( $permission ) );
1874 if( $groups ) {
1875 $this->addWikiMsg(
1876 'badaccess-groups',
1877 $wgLang->commaList( $groups ),
1878 count( $groups )
1879 );
1880 } else {
1881 $this->addWikiMsg( 'badaccess-group0' );
1882 }
1883 $this->returnToMain();
1884 }
1885
1886 /**
1887 * Produce the stock "please login to use the wiki" page
1888 */
1889 public function loginToUse() {
1890 global $wgUser;
1891
1892 if( $wgUser->isLoggedIn() ) {
1893 $this->permissionRequired( 'read' );
1894 return;
1895 }
1896
1897 $skin = $wgUser->getSkin();
1898
1899 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1900 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1901 $this->setRobotPolicy( 'noindex,nofollow' );
1902 $this->setArticleFlag( false );
1903
1904 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1905 $loginLink = $skin->link(
1906 $loginTitle,
1907 wfMsgHtml( 'loginreqlink' ),
1908 array(),
1909 array( 'returnto' => $this->getTitle()->getPrefixedText() ),
1910 array( 'known', 'noclasses' )
1911 );
1912 $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1913 $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . '-->' );
1914
1915 # Don't return to the main page if the user can't read it
1916 # otherwise we'll end up in a pointless loop
1917 $mainPage = Title::newMainPage();
1918 if( $mainPage->userCanRead() ) {
1919 $this->returnToMain( null, $mainPage );
1920 }
1921 }
1922
1923 /**
1924 * Format a list of error messages
1925 *
1926 * @param $errors An array of arrays returned by Title::getUserPermissionsErrors
1927 * @param $action String: action that was denied or null if unknown
1928 * @return String: the wikitext error-messages, formatted into a list.
1929 */
1930 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1931 if ( $action == null ) {
1932 $text = wfMsgNoTrans( 'permissionserrorstext', count( $errors ) ) . "\n\n";
1933 } else {
1934 $action_desc = wfMsgNoTrans( "action-$action" );
1935 $text = wfMsgNoTrans(
1936 'permissionserrorstext-withaction',
1937 count( $errors ),
1938 $action_desc
1939 ) . "\n\n";
1940 }
1941
1942 if ( count( $errors ) > 1 ) {
1943 $text .= '<ul class="permissions-errors">' . "\n";
1944
1945 foreach( $errors as $error ) {
1946 $text .= '<li>';
1947 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1948 $text .= "</li>\n";
1949 }
1950 $text .= '</ul>';
1951 } else {
1952 $text .= "<div class=\"permissions-errors\">\n" .
1953 call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) .
1954 "\n</div>";
1955 }
1956
1957 return $text;
1958 }
1959
1960 /**
1961 * Display a page stating that the Wiki is in read-only mode,
1962 * and optionally show the source of the page that the user
1963 * was trying to edit. Should only be called (for this
1964 * purpose) after wfReadOnly() has returned true.
1965 *
1966 * For historical reasons, this function is _also_ used to
1967 * show the error message when a user tries to edit a page
1968 * they are not allowed to edit. (Unless it's because they're
1969 * blocked, then we show blockedPage() instead.) In this
1970 * case, the second parameter should be set to true and a list
1971 * of reasons supplied as the third parameter.
1972 *
1973 * @todo Needs to be split into multiple functions.
1974 *
1975 * @param $source String: source code to show (or null).
1976 * @param $protected Boolean: is this a permissions error?
1977 * @param $reasons Array: list of reasons for this error, as returned by Title::getUserPermissionsErrors().
1978 * @param $action String: action that was denied or null if unknown
1979 */
1980 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1981 global $wgUser;
1982 $skin = $wgUser->getSkin();
1983
1984 $this->setRobotPolicy( 'noindex,nofollow' );
1985 $this->setArticleRelated( false );
1986
1987 // If no reason is given, just supply a default "I can't let you do
1988 // that, Dave" message. Should only occur if called by legacy code.
1989 if ( $protected && empty( $reasons ) ) {
1990 $reasons[] = array( 'badaccess-group0' );
1991 }
1992
1993 if ( !empty( $reasons ) ) {
1994 // Permissions error
1995 if( $source ) {
1996 $this->setPageTitle( wfMsg( 'viewsource' ) );
1997 $this->setSubtitle(
1998 wfMsg( 'viewsourcefor', $skin->linkKnown( $this->getTitle() ) )
1999 );
2000 } else {
2001 $this->setPageTitle( wfMsg( 'badaccess' ) );
2002 }
2003 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
2004 } else {
2005 // Wiki is read only
2006 $this->setPageTitle( wfMsg( 'readonly' ) );
2007 $reason = wfReadOnlyReason();
2008 $this->wrapWikiMsg( "<div class='mw-readonly-error'>\n$1\n</div>", array( 'readonlytext', $reason ) );
2009 }
2010
2011 // Show source, if supplied
2012 if( is_string( $source ) ) {
2013 $this->addWikiMsg( 'viewsourcetext' );
2014
2015 $params = array(
2016 'id' => 'wpTextbox1',
2017 'name' => 'wpTextbox1',
2018 'cols' => $wgUser->getOption( 'cols' ),
2019 'rows' => $wgUser->getOption( 'rows' ),
2020 'readonly' => 'readonly'
2021 );
2022 $this->addHTML( Html::element( 'textarea', $params, $source ) );
2023
2024 // Show templates used by this article
2025 $skin = $wgUser->getSkin();
2026 $article = new Article( $this->getTitle() );
2027 $this->addHTML( "<div class='templatesUsed'>
2028 {$skin->formatTemplates( $article->getUsedTemplates() )}
2029 </div>
2030 " );
2031 }
2032
2033 # If the title doesn't exist, it's fairly pointless to print a return
2034 # link to it. After all, you just tried editing it and couldn't, so
2035 # what's there to do there?
2036 if( $this->getTitle()->exists() ) {
2037 $this->returnToMain( null, $this->getTitle() );
2038 }
2039 }
2040
2041 /**
2042 * Adds JS-based password security checker
2043 * @param $passwordId String ID of input box containing password
2044 * @param $retypeId String ID of input box containing retyped password
2045 * @return none
2046 */
2047 public function addPasswordSecurity( $passwordId, $retypeId ) {
2048 $this->includeJQuery();
2049 $data = array(
2050 'password' => '#' . $passwordId,
2051 'retype' => '#' . $retypeId,
2052 'messages' => array(),
2053 );
2054 foreach ( array( 'password-strength', 'password-strength-bad', 'password-strength-mediocre',
2055 'password-strength-acceptable', 'password-strength-good', 'password-retype', 'password-retype-mismatch'
2056 ) as $message ) {
2057 $data['messages'][$message] = wfMsg( $message );
2058 }
2059 $this->addScript( Html::inlineScript( 'var passwordSecurity=' . FormatJson::encode( $data ) ) );
2060 $this->addModules( 'mediawiki.legacy.password' );
2061 }
2062
2063 /** @deprecated */
2064 public function errorpage( $title, $msg ) {
2065 wfDeprecated( __METHOD__ );
2066 throw new ErrorPageError( $title, $msg );
2067 }
2068
2069 /** @deprecated */
2070 public function databaseError( $fname, $sql, $error, $errno ) {
2071 throw new MWException( "OutputPage::databaseError is obsolete\n" );
2072 }
2073
2074 /** @deprecated */
2075 public function fatalError( $message ) {
2076 wfDeprecated( __METHOD__ );
2077 throw new FatalError( $message );
2078 }
2079
2080 /** @deprecated */
2081 public function unexpectedValueError( $name, $val ) {
2082 wfDeprecated( __METHOD__ );
2083 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
2084 }
2085
2086 /** @deprecated */
2087 public function fileCopyError( $old, $new ) {
2088 wfDeprecated( __METHOD__ );
2089 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
2090 }
2091
2092 /** @deprecated */
2093 public function fileRenameError( $old, $new ) {
2094 wfDeprecated( __METHOD__ );
2095 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
2096 }
2097
2098 /** @deprecated */
2099 public function fileDeleteError( $name ) {
2100 wfDeprecated( __METHOD__ );
2101 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
2102 }
2103
2104 /** @deprecated */
2105 public function fileNotFoundError( $name ) {
2106 wfDeprecated( __METHOD__ );
2107 throw new FatalError( wfMsg( 'filenotfound', $name ) );
2108 }
2109
2110 public function showFatalError( $message ) {
2111 $this->setPageTitle( wfMsg( 'internalerror' ) );
2112 $this->setRobotPolicy( 'noindex,nofollow' );
2113 $this->setArticleRelated( false );
2114 $this->enableClientCache( false );
2115 $this->mRedirect = '';
2116 $this->mBodytext = $message;
2117 }
2118
2119 public function showUnexpectedValueError( $name, $val ) {
2120 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
2121 }
2122
2123 public function showFileCopyError( $old, $new ) {
2124 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
2125 }
2126
2127 public function showFileRenameError( $old, $new ) {
2128 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
2129 }
2130
2131 public function showFileDeleteError( $name ) {
2132 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
2133 }
2134
2135 public function showFileNotFoundError( $name ) {
2136 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
2137 }
2138
2139 /**
2140 * Add a "return to" link pointing to a specified title
2141 *
2142 * @param $title Title to link
2143 * @param $query String: query string
2144 * @param $text String text of the link (input is not escaped)
2145 */
2146 public function addReturnTo( $title, $query = array(), $text = null ) {
2147 global $wgUser;
2148 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL() ) );
2149 $link = wfMsgHtml(
2150 'returnto',
2151 $wgUser->getSkin()->link( $title, $text, array(), $query )
2152 );
2153 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
2154 }
2155
2156 /**
2157 * Add a "return to" link pointing to a specified title,
2158 * or the title indicated in the request, or else the main page
2159 *
2160 * @param $unused No longer used
2161 * @param $returnto Title or String to return to
2162 * @param $returntoquery String: query string for the return to link
2163 */
2164 public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
2165 global $wgRequest;
2166
2167 if ( $returnto == null ) {
2168 $returnto = $wgRequest->getText( 'returnto' );
2169 }
2170
2171 if ( $returntoquery == null ) {
2172 $returntoquery = $wgRequest->getText( 'returntoquery' );
2173 }
2174
2175 if ( $returnto === '' ) {
2176 $returnto = Title::newMainPage();
2177 }
2178
2179 if ( is_object( $returnto ) ) {
2180 $titleObj = $returnto;
2181 } else {
2182 $titleObj = Title::newFromText( $returnto );
2183 }
2184 if ( !is_object( $titleObj ) ) {
2185 $titleObj = Title::newMainPage();
2186 }
2187
2188 $this->addReturnTo( $titleObj, $returntoquery );
2189 }
2190
2191 /**
2192 * @param $sk Skin The given Skin
2193 * @param $includeStyle Boolean: unused
2194 * @return String: The doctype, opening <html>, and head element.
2195 */
2196 public function headElement( Skin $sk, $includeStyle = true ) {
2197 global $wgOutputEncoding, $wgMimeType;
2198 global $wgUseTrackbacks, $wgHtml5;
2199 global $wgUser, $wgRequest, $wgLang;
2200
2201 if ( $sk->commonPrintStylesheet() ) {
2202 $this->addModuleStyles( 'mediawiki.legacy.wikiprintable' );
2203 }
2204 $sk->setupUserCss( $this );
2205
2206 $ret = Html::htmlHeader( array( 'lang' => wfUILang()->getCode() ) );
2207
2208 if ( $this->getHTMLTitle() == '' ) {
2209 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ) );
2210 }
2211
2212 $openHead = Html::openElement( 'head' );
2213 if ( $openHead ) {
2214 # Don't bother with the newline if $head == ''
2215 $ret .= "$openHead\n";
2216 }
2217
2218 if ( $wgHtml5 ) {
2219 # More succinct than <meta http-equiv=Content-Type>, has the
2220 # same effect
2221 $ret .= Html::element( 'meta', array( 'charset' => $wgOutputEncoding ) ) . "\n";
2222 } else {
2223 $this->addMeta( 'http:Content-Type', "$wgMimeType; charset=$wgOutputEncoding" );
2224 }
2225
2226 $ret .= Html::element( 'title', null, $this->getHTMLTitle() ) . "\n";
2227
2228 $ret .= implode( "\n", array(
2229 $this->getHeadLinks( $sk ),
2230 $this->buildCssLinks(),
2231 $this->getHeadItems(),
2232 ) );
2233 if ( $sk->usercss ) {
2234 $ret .= Html::inlineStyle( $sk->usercss );
2235 }
2236
2237 if ( $wgUseTrackbacks && $this->isArticleRelated() ) {
2238 $ret .= $this->getTitle()->trackbackRDF();
2239 }
2240
2241 $closeHead = Html::closeElement( 'head' );
2242 if ( $closeHead ) {
2243 $ret .= "$closeHead\n";
2244 }
2245
2246 $bodyAttrs = array();
2247
2248 # Crazy edit-on-double-click stuff
2249 $action = $wgRequest->getVal( 'action', 'view' );
2250
2251 if (
2252 $this->getTitle()->getNamespace() != NS_SPECIAL &&
2253 !in_array( $action, array( 'edit', 'submit' ) ) &&
2254 $wgUser->getOption( 'editondblclick' )
2255 )
2256 {
2257 $bodyAttrs['ondblclick'] = "document.location = '" . Xml::escapeJsString( $this->getTitle()->getEditURL() ) . "'";
2258 }
2259
2260 # Class bloat
2261 $dir = wfUILang()->getDir();
2262 $bodyAttrs['class'] = "mediawiki $dir";
2263
2264 if ( $wgLang->capitalizeAllNouns() ) {
2265 # A <body> class is probably not the best way to do this . . .
2266 $bodyAttrs['class'] .= ' capitalize-all-nouns';
2267 }
2268 $bodyAttrs['class'] .= ' ns-' . $this->getTitle()->getNamespace();
2269 if ( $this->getTitle()->getNamespace() == NS_SPECIAL ) {
2270 $bodyAttrs['class'] .= ' ns-special';
2271 } elseif ( $this->getTitle()->isTalkPage() ) {
2272 $bodyAttrs['class'] .= ' ns-talk';
2273 } else {
2274 $bodyAttrs['class'] .= ' ns-subject';
2275 }
2276 $bodyAttrs['class'] .= ' ' . Sanitizer::escapeClass( 'page-' . $this->getTitle()->getPrefixedText() );
2277 $bodyAttrs['class'] .= ' skin-' . Sanitizer::escapeClass( $wgUser->getSkin()->getSkinName() );
2278
2279 $sk->bodyAttributes( $this, $bodyAttrs ); // Allow skins to add body attributes they need
2280 wfRunHooks( 'OutputPageBodyAttrs', array( $this, $sk, &$bodyAttrs ) );
2281
2282 $ret .= Html::openElement( 'body', $bodyAttrs ) . "\n";
2283
2284 return $ret;
2285 }
2286
2287 // TODO: Document
2288 protected function makeResourceLoaderLink( $skin, $modules, $only, $useESI = false ) {
2289 global $wgUser, $wgLang, $wgRequest, $wgLoadScript, $wgResourceLoaderDebug, $wgResourceLoaderUseESI,
2290 $wgResourceLoaderInlinePrivateModules;
2291 // Lazy-load ResourceLoader
2292 if ( is_null( $this->mResourceLoader ) ) {
2293 $this->mResourceLoader = new ResourceLoader();
2294 }
2295 // TODO: Should this be a static function of ResourceLoader instead?
2296 // TODO: Divide off modules starting with "user", and add the user parameter to them
2297 $query = array(
2298 'lang' => $wgLang->getCode(),
2299 'debug' => $wgRequest->getFuzzyBool( 'debug', $wgResourceLoaderDebug ) ? 'true' : 'false',
2300 'skin' => $wgUser->getSkin()->getSkinName(),
2301 'only' => $only,
2302 );
2303 // Remove duplicate module requests
2304 $modules = array_unique( (array) $modules );
2305 // Sort module names so requests are more uniform
2306 sort( $modules );
2307 // Create keyed-by-group list of module objects from modules list
2308 $groups = array();
2309 foreach ( (array) $modules as $name ) {
2310 $module = $this->mResourceLoader->getModule( $name );
2311 $group = $module->getGroup();
2312 if ( !isset( $groups[$group] ) ) {
2313 $groups[$group] = array();
2314 }
2315 $groups[$group][$name] = $module;
2316 }
2317 $links = '';
2318 foreach ( $groups as $group => $modules ) {
2319 $query['modules'] = implode( '|', array_keys( $modules ) );
2320 // Special handling for user-specific groups
2321 if ( ( $group === 'user' || $group === 'private' ) && $wgUser->isLoggedIn() ) {
2322 $query['user'] = $wgUser->getName();
2323 }
2324 // Support inlining of private modules if configured as such
2325 if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) {
2326 $context = new ResourceLoaderContext( $this->mResourceLoader, new FauxRequest( $query ) );
2327 if ( $only == 'styles' ) {
2328 $links .= Html::inlineStyle(
2329 $this->mResourceLoader->makeModuleResponse( $context, $modules )
2330 );
2331 } else {
2332 $links .= Html::inlineScript(
2333 ResourceLoader::makeLoaderConditionalScript(
2334 $this->mResourceLoader->makeModuleResponse( $context, $modules )
2335 )
2336 );
2337 }
2338 continue;
2339 }
2340 // Special handling for user and site groups; because users might change their stuff on-wiki like site or
2341 // user pages, or user preferences; we need to find the highest timestamp of these user-changable modules so
2342 // we can ensure cache misses on change
2343 if ( $group === 'user' || $group === 'site' ) {
2344 // Create a fake request based on the one we are about to make so modules return correct times
2345 $context = new ResourceLoaderContext( $this->mResourceLoader, new FauxRequest( $query ) );
2346 // Get the maximum timestamp
2347 $timestamp = 1;
2348 foreach ( $modules as $module ) {
2349 $timestamp = max( $timestamp, $module->getModifiedTime( $context ) );
2350 }
2351 // Add a version parameter so cache will break when things change
2352 $query['version'] = wfTimestamp( TS_ISO_8601_BASIC, round( $timestamp, -2 ) );
2353 }
2354 // Make queries uniform in order
2355 ksort( $query );
2356
2357 $url = wfAppendQuery( $wgLoadScript, $query );
2358 if ( $useESI && $wgResourceLoaderUseESI ) {
2359 $esi = Xml::element( 'esi:include', array( 'src' => $url ) );
2360 if ( $only == 'styles' ) {
2361 $links .= Html::inlineStyle( $esi );
2362 } else {
2363 $links .= Html::inlineScript( $esi );
2364 }
2365 } else {
2366 // Automatically select style/script elements
2367 if ( $only === 'styles' ) {
2368 $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ) . "\n";
2369 } else {
2370 $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ) . "\n";
2371 }
2372 }
2373 }
2374 return $links;
2375 }
2376
2377 /**
2378 * Gets the global variables and mScripts; also adds userjs to the end if
2379 * enabled. Despite the name, these scripts are no longer put in the
2380 * <head> but at the bottom of the <body>
2381 *
2382 * @param $sk Skin object to use
2383 * @return String: HTML fragment
2384 */
2385 function getHeadScripts( Skin $sk ) {
2386 global $wgUser, $wgRequest, $wgUseSiteJs, $wgResourceLoaderDebug;
2387
2388 // Startup - this will immediately load jquery and mediawiki modules
2389 $scripts = $this->makeResourceLoaderLink( $sk, 'startup', 'scripts', true );
2390
2391 // Configuration -- This could be merged together with the load and go, but makeGlobalVariablesScript returns a
2392 // whole script tag -- grumble grumble...
2393 $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
2394
2395 // Script and Messages "only"
2396 if ( $wgRequest->getFuzzyBool( 'debug', $wgResourceLoaderDebug ) ) {
2397 // Scripts
2398 foreach ( $this->getModuleScripts() as $name ) {
2399 $scripts .= $this->makeResourceLoaderLink( $sk, $name, 'scripts' );
2400 }
2401 // Messages
2402 foreach ( $this->getModuleMessages() as $name ) {
2403 $scripts .= $this->makeResourceLoaderLink( $sk, $name, 'messages' );
2404 }
2405 } else {
2406 // Scripts
2407 if ( count( $this->getModuleScripts() ) ) {
2408 $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts(), 'scripts' );
2409 }
2410 // Messages
2411 if ( count( $this->getModuleMessages() ) ) {
2412 $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' );
2413 }
2414 }
2415
2416 // Modules - let the client calculate dependencies and batch requests as it likes
2417 if ( $this->getModules() ) {
2418 $modules = FormatJson::encode( $this->getModules() );
2419 $scripts .= Html::inlineScript(
2420 "if ( window.mediaWiki ) { mediaWiki.loader.load( {$modules} ); mediaWiki.loader.go(); }"
2421 ) . "\n";
2422 }
2423
2424 // Add user JS if enabled - trying to load user.options as a bundle if possible
2425 $userOptionsAdded = false;
2426 if ( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
2427 $action = $wgRequest->getVal( 'action', 'view' );
2428 if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
2429 # XXX: additional security check/prompt?
2430 $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
2431 } else {
2432 $scripts .= $this->makeResourceLoaderLink( $sk, array( 'user', 'user.options' ), 'scripts' );
2433 $userOptionsAdded = true;
2434 }
2435 }
2436 if ( !$userOptionsAdded ) {
2437 $scripts .= $this->makeResourceLoaderLink( $sk, 'user.options', 'scripts' );
2438 }
2439 $scripts .= "\n" . $this->mScripts;
2440
2441 // Add site JS if enabled
2442 if ( $wgUseSiteJs ) {
2443 $scripts .= $this->makeResourceLoaderLink( $sk, 'site', 'scripts' );
2444 }
2445
2446 return $scripts;
2447 }
2448
2449 /**
2450 * Add default \<meta\> tags
2451 */
2452 protected function addDefaultMeta() {
2453 global $wgVersion, $wgHtml5;
2454
2455 static $called = false;
2456 if ( $called ) {
2457 # Don't run this twice
2458 return;
2459 }
2460 $called = true;
2461
2462 if ( !$wgHtml5 ) {
2463 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); // bug 15835
2464 }
2465 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
2466
2467 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
2468 if( $p !== 'index,follow' ) {
2469 // http://www.robotstxt.org/wc/meta-user.html
2470 // Only show if it's different from the default robots policy
2471 $this->addMeta( 'robots', $p );
2472 }
2473
2474 if ( count( $this->mKeywords ) > 0 ) {
2475 $strip = array(
2476 "/<.*?" . ">/" => '',
2477 "/_/" => ' '
2478 );
2479 $this->addMeta(
2480 'keywords',
2481 preg_replace(
2482 array_keys( $strip ),
2483 array_values( $strip ),
2484 implode( ',', $this->mKeywords )
2485 )
2486 );
2487 }
2488 }
2489
2490 /**
2491 * @return string HTML tag links to be put in the header.
2492 */
2493 public function getHeadLinks( $sk ) {
2494 global $wgFeed, $wgRequest, $wgResourceLoaderDebug;
2495
2496 // Ideally this should happen earlier, somewhere. :P
2497 $this->addDefaultMeta();
2498
2499 $tags = array();
2500
2501 foreach ( $this->mMetatags as $tag ) {
2502 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
2503 $a = 'http-equiv';
2504 $tag[0] = substr( $tag[0], 5 );
2505 } else {
2506 $a = 'name';
2507 }
2508 $tags[] = Html::element( 'meta',
2509 array(
2510 $a => $tag[0],
2511 'content' => $tag[1]
2512 )
2513 );
2514 }
2515 foreach ( $this->mLinktags as $tag ) {
2516 $tags[] = Html::element( 'link', $tag );
2517 }
2518
2519 if( $wgFeed ) {
2520 foreach( $this->getSyndicationLinks() as $format => $link ) {
2521 # Use the page name for the title (accessed through $wgTitle since
2522 # there's no other way). In principle, this could lead to issues
2523 # with having the same name for different feeds corresponding to
2524 # the same page, but we can't avoid that at this low a level.
2525
2526 $tags[] = $this->feedLink(
2527 $format,
2528 $link,
2529 # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
2530 wfMsg( "page-{$format}-feed", $this->getTitle()->getPrefixedText() )
2531 );
2532 }
2533
2534 # Recent changes feed should appear on every page (except recentchanges,
2535 # that would be redundant). Put it after the per-page feed to avoid
2536 # changing existing behavior. It's still available, probably via a
2537 # menu in your browser. Some sites might have a different feed they'd
2538 # like to promote instead of the RC feed (maybe like a "Recent New Articles"
2539 # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
2540 # If so, use it instead.
2541
2542 global $wgOverrideSiteFeed, $wgSitename, $wgAdvertisedFeedTypes;
2543 $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
2544
2545 if ( $wgOverrideSiteFeed ) {
2546 foreach ( $wgOverrideSiteFeed as $type => $feedUrl ) {
2547 $tags[] = $this->feedLink(
2548 $type,
2549 htmlspecialchars( $feedUrl ),
2550 wfMsg( "site-{$type}-feed", $wgSitename )
2551 );
2552 }
2553 } elseif ( $this->getTitle()->getPrefixedText() != $rctitle->getPrefixedText() ) {
2554 foreach ( $wgAdvertisedFeedTypes as $format ) {
2555 $tags[] = $this->feedLink(
2556 $format,
2557 $rctitle->getLocalURL( "feed={$format}" ),
2558 wfMsg( "site-{$format}-feed", $wgSitename ) # For grep: 'site-rss-feed', 'site-atom-feed'.
2559 );
2560 }
2561 }
2562 }
2563
2564 // Support individual script requests in debug mode
2565 if ( $wgRequest->getFuzzyBool( 'debug', $wgResourceLoaderDebug ) ) {
2566 foreach ( $this->getModuleStyles() as $name ) {
2567 $tags[] = $this->makeResourceLoaderLink( $sk, $name, 'styles' );
2568 }
2569 } else {
2570 if ( count( $this->getModuleStyles() ) ) {
2571 $tags[] = $this->makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles' );
2572 }
2573 }
2574
2575 return implode( "\n", $tags );
2576 }
2577
2578 /**
2579 * Generate a <link rel/> for a feed.
2580 *
2581 * @param $type String: feed type
2582 * @param $url String: URL to the feed
2583 * @param $text String: value of the "title" attribute
2584 * @return String: HTML fragment
2585 */
2586 private function feedLink( $type, $url, $text ) {
2587 return Html::element( 'link', array(
2588 'rel' => 'alternate',
2589 'type' => "application/$type+xml",
2590 'title' => $text,
2591 'href' => $url )
2592 );
2593 }
2594
2595 /**
2596 * Add a local or specified stylesheet, with the given media options.
2597 * Meant primarily for internal use...
2598 *
2599 * @param $style String: URL to the file
2600 * @param $media String: to specify a media type, 'screen', 'printable', 'handheld' or any.
2601 * @param $condition String: for IE conditional comments, specifying an IE version
2602 * @param $dir String: set to 'rtl' or 'ltr' for direction-specific sheets
2603 */
2604 public function addStyle( $style, $media = '', $condition = '', $dir = '' ) {
2605 $options = array();
2606 // Even though we expect the media type to be lowercase, but here we
2607 // force it to lowercase to be safe.
2608 if( $media ) {
2609 $options['media'] = $media;
2610 }
2611 if( $condition ) {
2612 $options['condition'] = $condition;
2613 }
2614 if( $dir ) {
2615 $options['dir'] = $dir;
2616 }
2617 $this->styles[$style] = $options;
2618 }
2619
2620 /**
2621 * Adds inline CSS styles
2622 * @param $style_css Mixed: inline CSS
2623 */
2624 public function addInlineStyle( $style_css ){
2625 $this->mScripts .= Html::inlineStyle( $style_css );
2626 }
2627
2628 /**
2629 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
2630 * These will be applied to various media & IE conditionals.
2631 */
2632 public function buildCssLinks() {
2633 return implode( "\n", $this->buildCssLinksArray() );
2634 }
2635
2636 public function buildCssLinksArray() {
2637 $links = array();
2638 foreach( $this->styles as $file => $options ) {
2639 $link = $this->styleLink( $file, $options );
2640 if( $link ) {
2641 $links[$file] = $link;
2642 }
2643 }
2644 return $links;
2645 }
2646
2647 /**
2648 * Generate \<link\> tags for stylesheets
2649 *
2650 * @param $style String: URL to the file
2651 * @param $options Array: option, can contain 'condition', 'dir', 'media'
2652 * keys
2653 * @return String: HTML fragment
2654 */
2655 protected function styleLink( $style, $options ) {
2656 if( isset( $options['dir'] ) ) {
2657 $siteDir = wfUILang()->getDir();
2658 if( $siteDir != $options['dir'] ) {
2659 return '';
2660 }
2661 }
2662
2663 if( isset( $options['media'] ) ) {
2664 $media = $this->transformCssMedia( $options['media'] );
2665 if( is_null( $media ) ) {
2666 return '';
2667 }
2668 } else {
2669 $media = 'all';
2670 }
2671
2672 if( substr( $style, 0, 1 ) == '/' ||
2673 substr( $style, 0, 5 ) == 'http:' ||
2674 substr( $style, 0, 6 ) == 'https:' ) {
2675 $url = $style;
2676 } else {
2677 global $wgStylePath, $wgStyleVersion;
2678 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
2679 }
2680
2681 $link = Html::linkedStyle( $url, $media );
2682
2683 if( isset( $options['condition'] ) ) {
2684 $condition = htmlspecialchars( $options['condition'] );
2685 $link = "<!--[if $condition]>$link<![endif]-->";
2686 }
2687 return $link;
2688 }
2689
2690 /**
2691 * Transform "media" attribute based on request parameters
2692 *
2693 * @param $media String: current value of the "media" attribute
2694 * @return String: modified value of the "media" attribute
2695 */
2696 function transformCssMedia( $media ) {
2697 global $wgRequest, $wgHandheldForIPhone;
2698
2699 // Switch in on-screen display for media testing
2700 $switches = array(
2701 'printable' => 'print',
2702 'handheld' => 'handheld',
2703 );
2704 foreach( $switches as $switch => $targetMedia ) {
2705 if( $wgRequest->getBool( $switch ) ) {
2706 if( $media == $targetMedia ) {
2707 $media = '';
2708 } elseif( $media == 'screen' ) {
2709 return null;
2710 }
2711 }
2712 }
2713
2714 // Expand longer media queries as iPhone doesn't grok 'handheld'
2715 if( $wgHandheldForIPhone ) {
2716 $mediaAliases = array(
2717 'screen' => 'screen and (min-device-width: 481px)',
2718 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
2719 );
2720
2721 if( isset( $mediaAliases[$media] ) ) {
2722 $media = $mediaAliases[$media];
2723 }
2724 }
2725
2726 return $media;
2727 }
2728
2729 /**
2730 * Turn off regular page output and return an error reponse
2731 * for when rate limiting has triggered.
2732 */
2733 public function rateLimited() {
2734 $this->setPageTitle( wfMsg( 'actionthrottled' ) );
2735 $this->setRobotPolicy( 'noindex,follow' );
2736 $this->setArticleRelated( false );
2737 $this->enableClientCache( false );
2738 $this->mRedirect = '';
2739 $this->clearHTML();
2740 $this->setStatusCode( 503 );
2741 $this->addWikiMsg( 'actionthrottledtext' );
2742
2743 $this->returnToMain( null, $this->getTitle() );
2744 }
2745
2746 /**
2747 * Show a warning about slave lag
2748 *
2749 * If the lag is higher than $wgSlaveLagCritical seconds,
2750 * then the warning is a bit more obvious. If the lag is
2751 * lower than $wgSlaveLagWarning, then no warning is shown.
2752 *
2753 * @param $lag Integer: slave lag
2754 */
2755 public function showLagWarning( $lag ) {
2756 global $wgSlaveLagWarning, $wgSlaveLagCritical, $wgLang;
2757 if( $lag >= $wgSlaveLagWarning ) {
2758 $message = $lag < $wgSlaveLagCritical
2759 ? 'lag-warn-normal'
2760 : 'lag-warn-high';
2761 $wrap = Html::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" );
2762 $this->wrapWikiMsg( "$wrap\n", array( $message, $wgLang->formatNum( $lag ) ) );
2763 }
2764 }
2765
2766 /**
2767 * Add a wikitext-formatted message to the output.
2768 * This is equivalent to:
2769 *
2770 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
2771 */
2772 public function addWikiMsg( /*...*/ ) {
2773 $args = func_get_args();
2774 $name = array_shift( $args );
2775 $this->addWikiMsgArray( $name, $args );
2776 }
2777
2778 /**
2779 * Add a wikitext-formatted message to the output.
2780 * Like addWikiMsg() except the parameters are taken as an array
2781 * instead of a variable argument list.
2782 *
2783 * $options is passed through to wfMsgExt(), see that function for details.
2784 */
2785 public function addWikiMsgArray( $name, $args, $options = array() ) {
2786 $options[] = 'parse';
2787 $text = wfMsgExt( $name, $options, $args );
2788 $this->addHTML( $text );
2789 }
2790
2791 /**
2792 * This function takes a number of message/argument specifications, wraps them in
2793 * some overall structure, and then parses the result and adds it to the output.
2794 *
2795 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
2796 * on. The subsequent arguments may either be strings, in which case they are the
2797 * message names, or arrays, in which case the first element is the message name,
2798 * and subsequent elements are the parameters to that message.
2799 *
2800 * The special named parameter 'options' in a message specification array is passed
2801 * through to the $options parameter of wfMsgExt().
2802 *
2803 * Don't use this for messages that are not in users interface language.
2804 *
2805 * For example:
2806 *
2807 * $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>", 'some-error' );
2808 *
2809 * Is equivalent to:
2810 *
2811 * $wgOut->addWikiText( "<div class='error'>\n" . wfMsgNoTrans( 'some-error' ) . "\n</div>" );
2812 *
2813 * The newline after opening div is needed in some wikitext. See bug 19226.
2814 */
2815 public function wrapWikiMsg( $wrap /*, ...*/ ) {
2816 $msgSpecs = func_get_args();
2817 array_shift( $msgSpecs );
2818 $msgSpecs = array_values( $msgSpecs );
2819 $s = $wrap;
2820 foreach ( $msgSpecs as $n => $spec ) {
2821 $options = array();
2822 if ( is_array( $spec ) ) {
2823 $args = $spec;
2824 $name = array_shift( $args );
2825 if ( isset( $args['options'] ) ) {
2826 $options = $args['options'];
2827 unset( $args['options'] );
2828 }
2829 } else {
2830 $args = array();
2831 $name = $spec;
2832 }
2833 $s = str_replace( '$' . ( $n + 1 ), wfMsgExt( $name, $options, $args ), $s );
2834 }
2835 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
2836 }
2837
2838 /**
2839 * Include jQuery core. Use this to avoid loading it multiple times
2840 * before we get a usable script loader.
2841 *
2842 * @param $modules Array: list of jQuery modules which should be loaded
2843 * @return Array: the list of modules which were not loaded.
2844 * @since 1.16
2845 * @deprecated No longer needed as of 1.17
2846 */
2847 public function includeJQuery( $modules = array() ) {
2848 return array();
2849 }
2850
2851 }