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