Removed JS2 work (has been moved to the js2-work branch). Has been lightly tested...
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 /**
6 * @todo document
7 */
8 class OutputPage {
9 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
10 var $mExtStyles = array();
11 var $mPagetitle = '', $mBodytext = '', $mDebugtext = '';
12 var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
13 var $mSubtitle = '', $mRedirect = '', $mStatusCode;
14 var $mLastModified = '', $mETag = false;
15 var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array();
16
17 var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
18 var $mInlineMsg = array();
19
20 var $mTemplateIds = array();
21
22 var $mAllowUserJs;
23 var $mSuppressQuickbar = false;
24 var $mOnloadHandler = '';
25 var $mDoNothing = false;
26 var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
27 var $mIsArticleRelated = true;
28 protected $mParserOptions = null; // lazy initialised, use parserOptions()
29
30 var $mFeedLinks = array();
31
32 var $mEnableClientCache = true;
33 var $mArticleBodyOnly = false;
34
35 var $mNewSectionLink = false;
36 var $mHideNewSectionLink = false;
37 var $mNoGallery = false;
38 var $mPageTitleActionText = '';
39 var $mParseWarnings = array();
40 var $mSquidMaxage = 0;
41 var $mRevisionId = null;
42 protected $mTitle = null;
43
44 /**
45 * An array of stylesheet filenames (relative from skins path), with options
46 * for CSS media, IE conditions, and RTL/LTR direction.
47 * For internal use; add settings in the skin via $this->addStyle()
48 */
49 var $styles = array();
50
51 private $mIndexPolicy = 'index';
52 private $mFollowPolicy = 'follow';
53
54 /**
55 * Constructor
56 * Initialise private variables
57 */
58 function __construct() {
59 global $wgAllowUserJs;
60 $this->mAllowUserJs = $wgAllowUserJs;
61 }
62
63 public function redirect( $url, $responsecode = '302' ) {
64 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
65 $this->mRedirect = str_replace( "\n", '', $url );
66 $this->mRedirectCode = $responsecode;
67 }
68
69 public function getRedirect() {
70 return $this->mRedirect;
71 }
72
73 /**
74 * Set the HTTP status code to send with the output.
75 *
76 * @param int $statusCode
77 * @return nothing
78 */
79 function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
80
81 /**
82 * Add a new <meta> tag
83 * To add an http-equiv meta tag, precede the name with "http:"
84 *
85 * @param $name tag name
86 * @param $val tag value
87 */
88 function addMeta( $name, $val ) {
89 array_push( $this->mMetatags, array( $name, $val ) );
90 }
91
92 function addKeyword( $text ) {
93 if( is_array( $text )) {
94 $this->mKeywords = array_merge( $this->mKeywords, $text );
95 } else {
96 array_push( $this->mKeywords, $text );
97 }
98 }
99 function addScript( $script ) {
100 $this->mScripts .= $script . "\n";
101 }
102
103 /**
104 * Register and add a stylesheet from an extension directory.
105 * @param $url String path to sheet. Provide either a full url (beginning
106 * with 'http', etc) or a relative path from the document root
107 * (beginning with '/'). Otherwise it behaves identically to
108 * addStyle() and draws from the /skins folder.
109 */
110 public function addExtensionStyle( $url ) {
111 array_push( $this->mExtStyles, $url );
112 }
113
114 /**
115 * Add a JavaScript file out of skins/common, or a given relative path.
116 * @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
117 */
118 function addScriptFile( $file ) {
119 global $wgStylePath, $wgStyleVersion, $wgJsMimeType;
120 if( substr( $file, 0, 1 ) == '/' ) {
121 $path = $file;
122 } else {
123 $path = "{$wgStylePath}/common/{$file}";
124 }
125 $this->addScript(
126 Xml::element( 'script',
127 array(
128 'type' => $wgJsMimeType,
129 'src' => "$path?$wgStyleVersion",
130 ),
131 '', false
132 )
133 );
134 }
135
136 /**
137 * Add a self-contained script tag with the given contents
138 * @param string $script JavaScript text, no <script> tags
139 */
140 function addInlineScript( $script ) {
141 $this->mScripts .= Html::inlineScript( "\n$script\n" ) . "\n";
142 }
143
144 /**
145 * Get all registered JS and CSS tags for the header.
146 */
147 function getScript() {
148 return $this->mScripts . $this->getHeadItems();
149 }
150
151 function getHeadItems() {
152 $s = '';
153 foreach ( $this->mHeadItems as $item ) {
154 $s .= $item;
155 }
156 return $s;
157 }
158
159 function addHeadItem( $name, $value ) {
160 $this->mHeadItems[$name] = $value;
161 }
162
163 function hasHeadItem( $name ) {
164 return isset( $this->mHeadItems[$name] );
165 }
166
167 function setETag($tag) { $this->mETag = $tag; }
168 function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
169 function getArticleBodyOnly() { return $this->mArticleBodyOnly; }
170
171 function addLink( $linkarr ) {
172 # $linkarr should be an associative array of attributes. We'll escape on output.
173 array_push( $this->mLinktags, $linkarr );
174 }
175
176 # Get all links added by extensions
177 function getExtStyle() {
178 return $this->mExtStyles;
179 }
180
181 function addMetadataLink( $linkarr ) {
182 # note: buggy CC software only reads first "meta" link
183 static $haveMeta = false;
184 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
185 $this->addLink( $linkarr );
186 $haveMeta = true;
187 }
188
189 /**
190 * checkLastModified tells the client to use the client-cached page if
191 * possible. If sucessful, the OutputPage is disabled so that
192 * any future call to OutputPage->output() have no effect.
193 *
194 * Side effect: sets mLastModified for Last-Modified header
195 *
196 * @return bool True iff cache-ok headers was sent.
197 */
198 function checkLastModified( $timestamp ) {
199 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
200
201 if ( !$timestamp || $timestamp == '19700101000000' ) {
202 wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
203 return false;
204 }
205 if( !$wgCachePages ) {
206 wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
207 return false;
208 }
209 if( $wgUser->getOption( 'nocache' ) ) {
210 wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false );
211 return false;
212 }
213
214 $timestamp = wfTimestamp( TS_MW, $timestamp );
215 $modifiedTimes = array(
216 'page' => $timestamp,
217 'user' => $wgUser->getTouched(),
218 'epoch' => $wgCacheEpoch
219 );
220 wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
221
222 $maxModified = max( $modifiedTimes );
223 $this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified );
224
225 if( empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
226 wfDebug( __METHOD__ . ": client did not send If-Modified-Since header\n", false );
227 return false;
228 }
229
230 # Make debug info
231 $info = '';
232 foreach ( $modifiedTimes as $name => $value ) {
233 if ( $info !== '' ) {
234 $info .= ', ';
235 }
236 $info .= "$name=" . wfTimestamp( TS_ISO_8601, $value );
237 }
238
239 # IE sends sizes after the date like this:
240 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
241 # this breaks strtotime().
242 $clientHeader = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
243
244 wfSuppressWarnings(); // E_STRICT system time bitching
245 $clientHeaderTime = strtotime( $clientHeader );
246 wfRestoreWarnings();
247 if ( !$clientHeaderTime ) {
248 wfDebug( __METHOD__ . ": unable to parse the client's If-Modified-Since header: $clientHeader\n" );
249 return false;
250 }
251 $clientHeaderTime = wfTimestamp( TS_MW, $clientHeaderTime );
252
253 wfDebug( __METHOD__ . ": client sent If-Modified-Since: " .
254 wfTimestamp( TS_ISO_8601, $clientHeaderTime ) . "\n", false );
255 wfDebug( __METHOD__ . ": effective Last-Modified: " .
256 wfTimestamp( TS_ISO_8601, $maxModified ) . "\n", false );
257 if( $clientHeaderTime < $maxModified ) {
258 wfDebug( __METHOD__ . ": STALE, $info\n", false );
259 return false;
260 }
261
262 # Not modified
263 # Give a 304 response code and disable body output
264 wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", false );
265 ini_set('zlib.output_compression', 0);
266 $wgRequest->response()->header( "HTTP/1.1 304 Not Modified" );
267 $this->sendCacheControl();
268 $this->disable();
269
270 // Don't output a compressed blob when using ob_gzhandler;
271 // it's technically against HTTP spec and seems to confuse
272 // Firefox when the response gets split over two packets.
273 wfClearOutputBuffers();
274
275 return true;
276 }
277
278 function setPageTitleActionText( $text ) {
279 $this->mPageTitleActionText = $text;
280 }
281
282 function getPageTitleActionText () {
283 if ( isset( $this->mPageTitleActionText ) ) {
284 return $this->mPageTitleActionText;
285 }
286 }
287
288 /**
289 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
290 *
291 * @param $policy string The literal string to output as the contents of
292 * the meta tag. Will be parsed according to the spec and output in
293 * standardized form.
294 * @return null
295 */
296 public function setRobotPolicy( $policy ) {
297 $policy = Article::formatRobotPolicy( $policy );
298
299 if( isset( $policy['index'] ) ){
300 $this->setIndexPolicy( $policy['index'] );
301 }
302 if( isset( $policy['follow'] ) ){
303 $this->setFollowPolicy( $policy['follow'] );
304 }
305 }
306
307 /**
308 * Set the index policy for the page, but leave the follow policy un-
309 * touched.
310 *
311 * @param $policy string Either 'index' or 'noindex'.
312 * @return null
313 */
314 public function setIndexPolicy( $policy ) {
315 $policy = trim( $policy );
316 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
317 $this->mIndexPolicy = $policy;
318 }
319 }
320
321 /**
322 * Set the follow policy for the page, but leave the index policy un-
323 * touched.
324 *
325 * @param $policy string Either 'follow' or 'nofollow'.
326 * @return null
327 */
328 public function setFollowPolicy( $policy ) {
329 $policy = trim( $policy );
330 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
331 $this->mFollowPolicy = $policy;
332 }
333 }
334
335 /**
336 * "HTML title" means the contents of <title>. It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
337 */
338 public function setHTMLTitle( $name ) {
339 $this->mHTMLtitle = $name;
340 }
341
342 /**
343 * "Page title" means the contents of <h1>. It is stored as a valid HTML fragment.
344 * This function allows good tags like <sup> in the <h1> tag, but not bad tags like <script>.
345 * This function automatically sets <title> to the same content as <h1> but with all tags removed.
346 * Bad tags that were escaped in <h1> will still be escaped in <title>, and good tags like <i> will be dropped entirely.
347 */
348 public function setPageTitle( $name ) {
349 global $wgContLang;
350 $name = $wgContLang->convert( $name, true );
351 # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
352 # but leave "<i>foobar</i>" alone
353 $nameWithTags = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $name ) );
354 $this->mPagetitle = $nameWithTags;
355
356 $taction = $this->getPageTitleActionText();
357 if( !empty( $taction ) ) {
358 $name .= ' - '.$taction;
359 }
360
361 # change "<i>foo&amp;bar</i>" to "foo&bar"
362 $this->setHTMLTitle( wfMsg( 'pagetitle', Sanitizer::stripAllTags( $nameWithTags ) ) );
363 }
364
365 public function setTitle( $t ) {
366 $this->mTitle = $t;
367 }
368
369 public function getTitle() {
370 if ( $this->mTitle instanceof Title ) {
371 return $this->mTitle;
372 }
373 else {
374 wfDebug( __METHOD__ . ' called and $mTitle is null. Return $wgTitle for sanity' );
375 global $wgTitle;
376 return $wgTitle;
377 }
378 }
379
380 public function getHTMLTitle() { return $this->mHTMLtitle; }
381 public function getPageTitle() { return $this->mPagetitle; }
382 public function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
383 public function appendSubtitle( $str ) { $this->mSubtitle .= /*$this->parse(*/$str/*)*/; } // @bug 2514
384 public function getSubtitle() { return $this->mSubtitle; }
385 public function isArticle() { return $this->mIsarticle; }
386 public function setPrintable() { $this->mPrintable = true; }
387 public function isPrintable() { return $this->mPrintable; }
388 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery; }
389 public function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
390 public function getOnloadHandler() { return $this->mOnloadHandler; }
391 public function disable() { $this->mDoNothing = true; }
392 public function isDisabled() { return $this->mDoNothing; }
393
394 public function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
395
396 public function setFeedAppendQuery( $val ) {
397 global $wgFeedClasses;
398
399 $this->mFeedLinks = array();
400
401 foreach( $wgFeedClasses as $type => $class ) {
402 $query = "feed=$type&".$val;
403 $this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query );
404 }
405 }
406
407 public function addFeedLink( $format, $href ) {
408 $this->mFeedLinks[$format] = $href;
409 }
410
411 public function isSyndicated() { return count($this->mFeedLinks); }
412
413 public function setArticleRelated( $v ) {
414 $this->mIsArticleRelated = $v;
415 if ( !$v ) {
416 $this->mIsarticle = false;
417 }
418 }
419 public function setArticleFlag( $v ) {
420 $this->mIsarticle = $v;
421 if ( $v ) {
422 $this->mIsArticleRelated = $v;
423 }
424 }
425
426 public function isArticleRelated() { return $this->mIsArticleRelated; }
427
428 public function getLanguageLinks() { return $this->mLanguageLinks; }
429 public function addLanguageLinks($newLinkArray) {
430 $this->mLanguageLinks += $newLinkArray;
431 }
432 public function setLanguageLinks($newLinkArray) {
433 $this->mLanguageLinks = $newLinkArray;
434 }
435
436 public function getCategoryLinks() {
437 return $this->mCategoryLinks;
438 }
439
440 public function getCategories() {
441 return $this->mCategories;
442 }
443
444 /**
445 * Add an array of categories, with names in the keys
446 */
447 public function addCategoryLinks( $categories ) {
448 global $wgUser, $wgContLang;
449
450 if ( !is_array( $categories ) || count( $categories ) == 0 ) {
451 return;
452 }
453
454 # Add the links to a LinkBatch
455 $arr = array( NS_CATEGORY => $categories );
456 $lb = new LinkBatch;
457 $lb->setArray( $arr );
458
459 # Fetch existence plus the hiddencat property
460 $dbr = wfGetDB( DB_SLAVE );
461 $pageTable = $dbr->tableName( 'page' );
462 $where = $lb->constructSet( 'page', $dbr );
463 $propsTable = $dbr->tableName( 'page_props' );
464 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value
465 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
466 $res = $dbr->query( $sql, __METHOD__ );
467
468 # Add the results to the link cache
469 $lb->addResultToCache( LinkCache::singleton(), $res );
470
471 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
472 $categories = array_combine( array_keys( $categories ),
473 array_fill( 0, count( $categories ), 'normal' ) );
474
475 # Mark hidden categories
476 foreach ( $res as $row ) {
477 if ( isset( $row->pp_value ) ) {
478 $categories[$row->page_title] = 'hidden';
479 }
480 }
481
482 # Add the remaining categories to the skin
483 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks ) ) ) {
484 $sk = $wgUser->getSkin();
485 foreach ( $categories as $category => $type ) {
486 $origcategory = $category;
487 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
488 $wgContLang->findVariantLink( $category, $title, true );
489 if ( $category != $origcategory )
490 if ( array_key_exists( $category, $categories ) )
491 continue;
492 $text = $wgContLang->convertHtml( $title->getText() );
493 $this->mCategories[] = $title->getText();
494 $this->mCategoryLinks[$type][] = $sk->link( $title, $text );
495 }
496 }
497 }
498
499 public function setCategoryLinks($categories) {
500 $this->mCategoryLinks = array();
501 $this->addCategoryLinks($categories);
502 }
503
504 public function suppressQuickbar() { $this->mSuppressQuickbar = true; }
505 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
506
507 public function disallowUserJs() { $this->mAllowUserJs = false; }
508 public function isUserJsAllowed() { return $this->mAllowUserJs; }
509
510 public function prependHTML( $text ) { $this->mBodytext = $text . $this->mBodytext; }
511 public function addHTML( $text ) { $this->mBodytext .= $text; }
512 public function clearHTML() { $this->mBodytext = ''; }
513 public function getHTML() { return $this->mBodytext; }
514 public function debug( $text ) { $this->mDebugtext .= $text; }
515
516 /* @deprecated */
517 public function setParserOptions( $options ) {
518 wfDeprecated( __METHOD__ );
519 return $this->parserOptions( $options );
520 }
521
522 public function parserOptions( $options = null ) {
523 if ( !$this->mParserOptions ) {
524 $this->mParserOptions = new ParserOptions;
525 }
526 return wfSetVar( $this->mParserOptions, $options );
527 }
528
529 /**
530 * Set the revision ID which will be seen by the wiki text parser
531 * for things such as embedded {{REVISIONID}} variable use.
532 * @param mixed $revid an integer, or NULL
533 * @return mixed previous value
534 */
535 public function setRevisionId( $revid ) {
536 $val = is_null( $revid ) ? null : intval( $revid );
537 return wfSetVar( $this->mRevisionId, $val );
538 }
539
540 public function getRevisionId() {
541 return $this->mRevisionId;
542 }
543
544 /**
545 * Convert wikitext to HTML and add it to the buffer
546 * Default assumes that the current page title will
547 * be used.
548 *
549 * @param string $text
550 * @param bool $linestart
551 */
552 public function addWikiText( $text, $linestart = true ) {
553 $title = $this->getTitle(); // Work arround E_STRICT
554 $this->addWikiTextTitle( $text, $title, $linestart );
555 }
556
557 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
558 $this->addWikiTextTitle($text, $title, $linestart);
559 }
560
561 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
562 $this->addWikiTextTitle( $text, $title, $linestart, true );
563 }
564
565 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
566 global $wgParser;
567
568 wfProfileIn( __METHOD__ );
569
570 wfIncrStats( 'pcache_not_possible' );
571
572 $popts = $this->parserOptions();
573 $oldTidy = $popts->setTidy( $tidy );
574
575 $parserOutput = $wgParser->parse( $text, $title, $popts,
576 $linestart, true, $this->mRevisionId );
577
578 $popts->setTidy( $oldTidy );
579
580 $this->addParserOutput( $parserOutput );
581
582 wfProfileOut( __METHOD__ );
583 }
584
585 /**
586 * @todo document
587 * @param ParserOutput object &$parserOutput
588 */
589 public function addParserOutputNoText( &$parserOutput ) {
590 global $wgExemptFromUserRobotsControl, $wgContentNamespaces;
591
592 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
593 $this->addCategoryLinks( $parserOutput->getCategories() );
594 $this->mNewSectionLink = $parserOutput->getNewSection();
595 $this->mHideNewSectionLink = $parserOutput->getHideNewSection();
596
597 $this->mParseWarnings = $parserOutput->getWarnings();
598 if ( $parserOutput->getCacheTime() == -1 ) {
599 $this->enableClientCache( false );
600 }
601 $this->mNoGallery = $parserOutput->getNoGallery();
602 $this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems );
603 // Versioning...
604 foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
605 if ( isset( $this->mTemplateIds[$ns] ) ) {
606 $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
607 } else {
608 $this->mTemplateIds[$ns] = $dbks;
609 }
610 }
611 // Page title
612 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
613 $this->setPageTitle( $dt );
614 else if ( ( $title = $parserOutput->getTitleText() ) != '' )
615 $this->setPageTitle( $title );
616
617 // Hooks registered in the object
618 global $wgParserOutputHooks;
619 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
620 list( $hookName, $data ) = $hookInfo;
621 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
622 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
623 }
624 }
625
626 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
627 }
628
629 /**
630 * @todo document
631 * @param ParserOutput &$parserOutput
632 */
633 function addParserOutput( &$parserOutput ) {
634 $this->addParserOutputNoText( $parserOutput );
635 $text = $parserOutput->getText();
636 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
637 $this->addHTML( $text );
638 }
639
640 /**
641 * Add wikitext to the buffer, assuming that this is the primary text for a page view
642 * Saves the text into the parser cache if possible.
643 *
644 * @param string $text
645 * @param Article $article
646 * @param bool $cache
647 * @deprecated Use Article::outputWikitext
648 */
649 public function addPrimaryWikiText( $text, $article, $cache = true ) {
650 global $wgParser;
651
652 wfDeprecated( __METHOD__ );
653
654 $popts = $this->parserOptions();
655 $popts->setTidy(true);
656 $parserOutput = $wgParser->parse( $text, $article->mTitle,
657 $popts, true, true, $this->mRevisionId );
658 $popts->setTidy(false);
659 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
660 $parserCache = ParserCache::singleton();
661 $parserCache->save( $parserOutput, $article, $popts);
662 }
663
664 $this->addParserOutput( $parserOutput );
665 }
666
667 /**
668 * @deprecated use addWikiTextTidy()
669 */
670 public function addSecondaryWikiText( $text, $linestart = true ) {
671 wfDeprecated( __METHOD__ );
672 $this->addWikiTextTitleTidy($text, $this->getTitle(), $linestart);
673 }
674
675 /**
676 * Add wikitext with tidy enabled
677 */
678 public function addWikiTextTidy( $text, $linestart = true ) {
679 $title = $this->getTitle();
680 $this->addWikiTextTitleTidy($text, $title, $linestart);
681 }
682
683
684 /**
685 * Add the output of a QuickTemplate to the output buffer
686 *
687 * @param QuickTemplate $template
688 */
689 public function addTemplate( &$template ) {
690 ob_start();
691 $template->execute();
692 $this->addHTML( ob_get_contents() );
693 ob_end_clean();
694 }
695
696 /**
697 * Parse wikitext and return the HTML.
698 *
699 * @param string $text
700 * @param bool $linestart Is this the start of a line?
701 * @param bool $interface ??
702 */
703 public function parse( $text, $linestart = true, $interface = false ) {
704 global $wgParser;
705 if( is_null( $this->getTitle() ) ) {
706 throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
707 }
708 $popts = $this->parserOptions();
709 if ( $interface) { $popts->setInterfaceMessage(true); }
710 $parserOutput = $wgParser->parse( $text, $this->getTitle(), $popts,
711 $linestart, true, $this->mRevisionId );
712 if ( $interface) { $popts->setInterfaceMessage(false); }
713 return $parserOutput->getText();
714 }
715
716 /** Parse wikitext, strip paragraphs, and return the HTML. */
717 public function parseInline( $text, $linestart = true, $interface = false ) {
718 $parsed = $this->parse( $text, $linestart, $interface );
719
720 $m = array();
721 if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
722 $parsed = $m[1];
723 }
724
725 return $parsed;
726 }
727
728 /**
729 * @param Article $article
730 * @param User $user
731 *
732 * @deprecated
733 *
734 * @return bool True if successful, else false.
735 */
736 public function tryParserCache( &$article ) {
737 wfDeprecated( __METHOD__ );
738 $parserOutput = ParserCache::singleton()->get( $article, $article->getParserOptions() );
739
740 if ($parserOutput !== false) {
741 $this->addParserOutput( $parserOutput );
742 return true;
743 } else {
744 return false;
745 }
746 }
747
748 /**
749 * @param int $maxage Maximum cache time on the Squid, in seconds.
750 */
751 public function setSquidMaxage( $maxage ) {
752 $this->mSquidMaxage = $maxage;
753 }
754
755 /**
756 * Use enableClientCache(false) to force it to send nocache headers
757 * @param $state ??
758 */
759 public function enableClientCache( $state ) {
760 return wfSetVar( $this->mEnableClientCache, $state );
761 }
762
763 function getCacheVaryCookies() {
764 global $wgCookiePrefix, $wgCacheVaryCookies;
765 static $cookies;
766 if ( $cookies === null ) {
767 $cookies = array_merge(
768 array(
769 "{$wgCookiePrefix}Token",
770 "{$wgCookiePrefix}LoggedOut",
771 session_name()
772 ),
773 $wgCacheVaryCookies
774 );
775 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
776 }
777 return $cookies;
778 }
779
780 function uncacheableBecauseRequestVars() {
781 global $wgRequest;
782 return $wgRequest->getText('useskin', false) === false
783 && $wgRequest->getText('uselang', false) === false;
784 }
785
786 /**
787 * Check if the request has a cache-varying cookie header
788 * If it does, it's very important that we don't allow public caching
789 */
790 function haveCacheVaryCookies() {
791 global $wgRequest;
792 $cookieHeader = $wgRequest->getHeader( 'cookie' );
793 if ( $cookieHeader === false ) {
794 return false;
795 }
796 $cvCookies = $this->getCacheVaryCookies();
797 foreach ( $cvCookies as $cookieName ) {
798 # Check for a simple string match, like the way squid does it
799 if ( strpos( $cookieHeader, $cookieName ) ) {
800 wfDebug( __METHOD__.": found $cookieName\n" );
801 return true;
802 }
803 }
804 wfDebug( __METHOD__.": no cache-varying cookies found\n" );
805 return false;
806 }
807
808 /** Get a complete X-Vary-Options header */
809 public function getXVO() {
810 $cvCookies = $this->getCacheVaryCookies();
811 $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;';
812 $first = true;
813 foreach ( $cvCookies as $cookieName ) {
814 if ( $first ) {
815 $first = false;
816 } else {
817 $xvo .= ';';
818 }
819 $xvo .= 'string-contains=' . $cookieName;
820 }
821 return $xvo;
822 }
823
824 public function sendCacheControl() {
825 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
826
827 $response = $wgRequest->response();
828 if ($wgUseETag && $this->mETag)
829 $response->header("ETag: $this->mETag");
830
831 # don't serve compressed data to clients who can't handle it
832 # maintain different caches for logged-in users and non-logged in ones
833 $response->header( 'Vary: Accept-Encoding, Cookie' );
834
835 if ( $wgUseXVO ) {
836 # Add an X-Vary-Options header for Squid with Wikimedia patches
837 $response->header( $this->getXVO() );
838 }
839
840 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache ) {
841 if( $wgUseSquid && session_id() == '' &&
842 ! $this->isPrintable() && $this->mSquidMaxage != 0 && !$this->haveCacheVaryCookies() )
843 {
844 if ( $wgUseESI ) {
845 # We'll purge the proxy cache explicitly, but require end user agents
846 # to revalidate against the proxy on each visit.
847 # Surrogate-Control controls our Squid, Cache-Control downstream caches
848 wfDebug( __METHOD__ . ": proxy caching with ESI; {$this->mLastModified} **\n", false );
849 # start with a shorter timeout for initial testing
850 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
851 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
852 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
853 } else {
854 # We'll purge the proxy cache for anons explicitly, but require end user agents
855 # to revalidate against the proxy on each visit.
856 # IMPORTANT! The Squid needs to replace the Cache-Control header with
857 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
858 wfDebug( __METHOD__ . ": local proxy caching; {$this->mLastModified} **\n", false );
859 # start with a shorter timeout for initial testing
860 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
861 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
862 }
863 } else {
864 # We do want clients to cache if they can, but they *must* check for updates
865 # on revisiting the page.
866 wfDebug( __METHOD__ . ": private caching; {$this->mLastModified} **\n", false );
867 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
868 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
869 }
870 if($this->mLastModified) {
871 $response->header( "Last-Modified: {$this->mLastModified}" );
872 }
873 } else {
874 wfDebug( __METHOD__ . ": no caching **\n", false );
875
876 # In general, the absence of a last modified header should be enough to prevent
877 # the client from using its cache. We send a few other things just to make sure.
878 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
879 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
880 $response->header( 'Pragma: no-cache' );
881 }
882 wfRunHooks('CacheHeadersAfterSet', array( $this ) );
883 }
884
885 /**
886 * Finally, all the text has been munged and accumulated into
887 * the object, let's actually output it:
888 */
889 public function output() {
890 global $wgUser, $wgOutputEncoding, $wgRequest;
891 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
892 global $wgUseAjax, $wgAjaxWatch;
893 global $wgEnableMWSuggest, $wgUniversalEditButton;
894 global $wgArticle;
895
896 if( $this->mDoNothing ){
897 return;
898 }
899 wfProfileIn( __METHOD__ );
900 if ( '' != $this->mRedirect ) {
901 # Standards require redirect URLs to be absolute
902 $this->mRedirect = wfExpandUrl( $this->mRedirect );
903 if( $this->mRedirectCode == '301') {
904 if( !$wgDebugRedirects ) {
905 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
906 }
907 $this->mLastModified = wfTimestamp( TS_RFC2822 );
908 }
909 $this->sendCacheControl();
910
911 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
912 if( $wgDebugRedirects ) {
913 $url = htmlspecialchars( $this->mRedirect );
914 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
915 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
916 print "</body>\n</html>\n";
917 } else {
918 $wgRequest->response()->header( 'Location: '.$this->mRedirect );
919 }
920 wfProfileOut( __METHOD__ );
921 return;
922 }
923 elseif ( $this->mStatusCode )
924 {
925 $statusMessage = array(
926 100 => 'Continue',
927 101 => 'Switching Protocols',
928 102 => 'Processing',
929 200 => 'OK',
930 201 => 'Created',
931 202 => 'Accepted',
932 203 => 'Non-Authoritative Information',
933 204 => 'No Content',
934 205 => 'Reset Content',
935 206 => 'Partial Content',
936 207 => 'Multi-Status',
937 300 => 'Multiple Choices',
938 301 => 'Moved Permanently',
939 302 => 'Found',
940 303 => 'See Other',
941 304 => 'Not Modified',
942 305 => 'Use Proxy',
943 307 => 'Temporary Redirect',
944 400 => 'Bad Request',
945 401 => 'Unauthorized',
946 402 => 'Payment Required',
947 403 => 'Forbidden',
948 404 => 'Not Found',
949 405 => 'Method Not Allowed',
950 406 => 'Not Acceptable',
951 407 => 'Proxy Authentication Required',
952 408 => 'Request Timeout',
953 409 => 'Conflict',
954 410 => 'Gone',
955 411 => 'Length Required',
956 412 => 'Precondition Failed',
957 413 => 'Request Entity Too Large',
958 414 => 'Request-URI Too Large',
959 415 => 'Unsupported Media Type',
960 416 => 'Request Range Not Satisfiable',
961 417 => 'Expectation Failed',
962 422 => 'Unprocessable Entity',
963 423 => 'Locked',
964 424 => 'Failed Dependency',
965 500 => 'Internal Server Error',
966 501 => 'Not Implemented',
967 502 => 'Bad Gateway',
968 503 => 'Service Unavailable',
969 504 => 'Gateway Timeout',
970 505 => 'HTTP Version Not Supported',
971 507 => 'Insufficient Storage'
972 );
973
974 if ( $statusMessage[$this->mStatusCode] )
975 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
976 }
977
978 $sk = $wgUser->getSkin();
979
980 if ( $wgUseAjax ) {
981 $this->addScriptFile( 'ajax.js' );
982
983 wfRunHooks( 'AjaxAddScript', array( &$this ) );
984
985 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
986 $this->addScriptFile( 'ajaxwatch.js' );
987 }
988
989 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
990 $this->addScriptFile( 'mwsuggest.js' );
991 }
992 }
993
994 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
995 $this->addScriptFile( 'rightclickedit.js' );
996 }
997
998 if( $wgUniversalEditButton ) {
999 if( isset( $wgArticle ) && $this->getTitle() && $this->getTitle()->quickUserCan( 'edit' )
1000 && ( $this->getTitle()->exists() || $this->getTitle()->quickUserCan( 'create' ) ) ) {
1001 // Original UniversalEditButton
1002 $msg = wfMsg('edit');
1003 $this->addLink( array(
1004 'rel' => 'alternate',
1005 'type' => 'application/x-wiki',
1006 'title' => $msg,
1007 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1008 ) );
1009 // Alternate edit link
1010 $this->addLink( array(
1011 'rel' => 'edit',
1012 'title' => $msg,
1013 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1014 ) );
1015 }
1016 }
1017
1018 # Buffer output; final headers may depend on later processing
1019 ob_start();
1020
1021 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1022 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
1023
1024 if ($this->mArticleBodyOnly) {
1025 $this->out($this->mBodytext);
1026 } else {
1027 // Hook that allows last minute changes to the output page, e.g.
1028 // adding of CSS or Javascript by extensions.
1029 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
1030
1031 wfProfileIn( 'Output-skin' );
1032 $sk->outputPage( $this );
1033 wfProfileOut( 'Output-skin' );
1034 }
1035
1036 $this->sendCacheControl();
1037 ob_end_flush();
1038 wfProfileOut( __METHOD__ );
1039 }
1040
1041 /**
1042 * Actually output something with print(). Performs an iconv to the
1043 * output encoding, if needed.
1044 * @param string $ins The string to output
1045 */
1046 public function out( $ins ) {
1047 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
1048 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
1049 $outs = $ins;
1050 } else {
1051 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
1052 if ( false === $outs ) { $outs = $ins; }
1053 }
1054 print $outs;
1055 }
1056
1057 /**
1058 * @todo document
1059 */
1060 public static function setEncodings() {
1061 global $wgInputEncoding, $wgOutputEncoding;
1062 global $wgContLang;
1063
1064 $wgInputEncoding = strtolower( $wgInputEncoding );
1065
1066 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
1067 $wgOutputEncoding = strtolower( $wgOutputEncoding );
1068 return;
1069 }
1070 $wgOutputEncoding = $wgInputEncoding;
1071 }
1072
1073 /**
1074 * Deprecated, use wfReportTime() instead.
1075 * @return string
1076 * @deprecated
1077 */
1078 public function reportTime() {
1079 wfDeprecated( __METHOD__ );
1080 $time = wfReportTime();
1081 return $time;
1082 }
1083
1084 /**
1085 * Produce a "user is blocked" page.
1086 *
1087 * @param bool $return Whether to have a "return to $wgTitle" message or not.
1088 * @return nothing
1089 */
1090 function blockedPage( $return = true ) {
1091 global $wgUser, $wgContLang, $wgLang;
1092
1093 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
1094 $this->setRobotPolicy( 'noindex,nofollow' );
1095 $this->setArticleRelated( false );
1096
1097 $name = User::whoIs( $wgUser->blockedBy() );
1098 $reason = $wgUser->blockedFor();
1099 if( $reason == '' ) {
1100 $reason = wfMsg( 'blockednoreason' );
1101 }
1102 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $wgUser->mBlock->mTimestamp ), true );
1103 $ip = wfGetIP();
1104
1105 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
1106
1107 $blockid = $wgUser->mBlock->mId;
1108
1109 $blockExpiry = $wgUser->mBlock->mExpiry;
1110 if ( $blockExpiry == 'infinity' ) {
1111 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1112 // Search for localization in 'ipboptions'
1113 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1114 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1115 if ( strpos( $option, ":" ) === false )
1116 continue;
1117 list( $show, $value ) = explode( ":", $option );
1118 if ( $value == 'infinite' || $value == 'indefinite' ) {
1119 $blockExpiry = $show;
1120 break;
1121 }
1122 }
1123 } else {
1124 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
1125 }
1126
1127 if ( $wgUser->mBlock->mAuto ) {
1128 $msg = 'autoblockedtext';
1129 } else {
1130 $msg = 'blockedtext';
1131 }
1132
1133 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1134 * This could be a username, an ip range, or a single ip. */
1135 $intended = $wgUser->mBlock->mAddress;
1136
1137 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
1138
1139 # Don't auto-return to special pages
1140 if( $return ) {
1141 $return = $this->getTitle()->getNamespace() > -1 ? $this->getTitle() : null;
1142 $this->returnToMain( null, $return );
1143 }
1144 }
1145
1146 /**
1147 * Output a standard error page
1148 *
1149 * @param string $title Message key for page title
1150 * @param string $msg Message key for page text
1151 * @param array $params Message parameters
1152 */
1153 public function showErrorPage( $title, $msg, $params = array() ) {
1154 if ( $this->getTitle() ) {
1155 $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1156 }
1157 $this->setPageTitle( wfMsg( $title ) );
1158 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1159 $this->setRobotPolicy( 'noindex,nofollow' );
1160 $this->setArticleRelated( false );
1161 $this->enableClientCache( false );
1162 $this->mRedirect = '';
1163 $this->mBodytext = '';
1164
1165 array_unshift( $params, 'parse' );
1166 array_unshift( $params, $msg );
1167 $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
1168
1169 $this->returnToMain();
1170 }
1171
1172 /**
1173 * Output a standard permission error page
1174 *
1175 * @param array $errors Error message keys
1176 */
1177 public function showPermissionsErrorPage( $errors, $action = null )
1178 {
1179 $this->mDebugtext .= 'Original title: ' .
1180 $this->getTitle()->getPrefixedText() . "\n";
1181 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1182 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1183 $this->setRobotPolicy( 'noindex,nofollow' );
1184 $this->setArticleRelated( false );
1185 $this->enableClientCache( false );
1186 $this->mRedirect = '';
1187 $this->mBodytext = '';
1188 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1189 }
1190
1191 /** @deprecated */
1192 public function errorpage( $title, $msg ) {
1193 wfDeprecated( __METHOD__ );
1194 throw new ErrorPageError( $title, $msg );
1195 }
1196
1197 /**
1198 * Display an error page indicating that a given version of MediaWiki is
1199 * required to use it
1200 *
1201 * @param mixed $version The version of MediaWiki needed to use the page
1202 */
1203 public function versionRequired( $version ) {
1204 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1205 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1206 $this->setRobotPolicy( 'noindex,nofollow' );
1207 $this->setArticleRelated( false );
1208 $this->mBodytext = '';
1209
1210 $this->addWikiMsg( 'versionrequiredtext', $version );
1211 $this->returnToMain();
1212 }
1213
1214 /**
1215 * Display an error page noting that a given permission bit is required.
1216 *
1217 * @param string $permission key required
1218 */
1219 public function permissionRequired( $permission ) {
1220 global $wgLang;
1221
1222 $this->setPageTitle( wfMsg( 'badaccess' ) );
1223 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1224 $this->setRobotPolicy( 'noindex,nofollow' );
1225 $this->setArticleRelated( false );
1226 $this->mBodytext = '';
1227
1228 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
1229 User::getGroupsWithPermission( $permission ) );
1230 if( $groups ) {
1231 $this->addWikiMsg( 'badaccess-groups',
1232 $wgLang->commaList( $groups ),
1233 count( $groups) );
1234 } else {
1235 $this->addWikiMsg( 'badaccess-group0' );
1236 }
1237 $this->returnToMain();
1238 }
1239
1240 /**
1241 * Use permissionRequired.
1242 * @deprecated
1243 */
1244 public function sysopRequired() {
1245 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1246 }
1247
1248 /**
1249 * Use permissionRequired.
1250 * @deprecated
1251 */
1252 public function developerRequired() {
1253 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1254 }
1255
1256 /**
1257 * Produce the stock "please login to use the wiki" page
1258 */
1259 public function loginToUse() {
1260 global $wgUser, $wgContLang;
1261
1262 if( $wgUser->isLoggedIn() ) {
1263 $this->permissionRequired( 'read' );
1264 return;
1265 }
1266
1267 $skin = $wgUser->getSkin();
1268
1269 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1270 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1271 $this->setRobotPolicy( 'noindex,nofollow' );
1272 $this->setArticleFlag( false );
1273
1274 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1275 $loginLink = $skin->link(
1276 $loginTitle,
1277 wfMsgHtml( 'loginreqlink' ),
1278 array(),
1279 array( 'returnto' => $this->getTitle()->getPrefixedText() ),
1280 array( 'known', 'noclasses' )
1281 );
1282 $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1283 $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . "-->" );
1284
1285 # Don't return to the main page if the user can't read it
1286 # otherwise we'll end up in a pointless loop
1287 $mainPage = Title::newMainPage();
1288 if( $mainPage->userCanRead() )
1289 $this->returnToMain( null, $mainPage );
1290 }
1291
1292 /** @deprecated */
1293 public function databaseError( $fname, $sql, $error, $errno ) {
1294 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1295 }
1296
1297 /**
1298 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1299 * @return string The wikitext error-messages, formatted into a list.
1300 */
1301 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1302 if ($action == null) {
1303 $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n";
1304 } else {
1305 global $wgLang;
1306 $action_desc = wfMsgNoTrans( "action-$action" );
1307 $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n";
1308 }
1309
1310 if (count( $errors ) > 1) {
1311 $text .= '<ul class="permissions-errors">' . "\n";
1312
1313 foreach( $errors as $error )
1314 {
1315 $text .= '<li>';
1316 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1317 $text .= "</li>\n";
1318 }
1319 $text .= '</ul>';
1320 } else {
1321 $text .= "<div class=\"permissions-errors\">\n" . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . "\n</div>";
1322 }
1323
1324 return $text;
1325 }
1326
1327 /**
1328 * Display a page stating that the Wiki is in read-only mode,
1329 * and optionally show the source of the page that the user
1330 * was trying to edit. Should only be called (for this
1331 * purpose) after wfReadOnly() has returned true.
1332 *
1333 * For historical reasons, this function is _also_ used to
1334 * show the error message when a user tries to edit a page
1335 * they are not allowed to edit. (Unless it's because they're
1336 * blocked, then we show blockedPage() instead.) In this
1337 * case, the second parameter should be set to true and a list
1338 * of reasons supplied as the third parameter.
1339 *
1340 * @todo Needs to be split into multiple functions.
1341 *
1342 * @param string $source Source code to show (or null).
1343 * @param bool $protected Is this a permissions error?
1344 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1345 */
1346 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1347 global $wgUser;
1348 $skin = $wgUser->getSkin();
1349
1350 $this->setRobotPolicy( 'noindex,nofollow' );
1351 $this->setArticleRelated( false );
1352
1353 // If no reason is given, just supply a default "I can't let you do
1354 // that, Dave" message. Should only occur if called by legacy code.
1355 if ( $protected && empty($reasons) ) {
1356 $reasons[] = array( 'badaccess-group0' );
1357 }
1358
1359 if ( !empty($reasons) ) {
1360 // Permissions error
1361 if( $source ) {
1362 $this->setPageTitle( wfMsg( 'viewsource' ) );
1363 $this->setSubtitle(
1364 wfMsg(
1365 'viewsourcefor',
1366 $skin->link(
1367 $this->getTitle(),
1368 null,
1369 array(),
1370 array(),
1371 array( 'known', 'noclasses' )
1372 )
1373 )
1374 );
1375 } else {
1376 $this->setPageTitle( wfMsg( 'badaccess' ) );
1377 }
1378 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
1379 } else {
1380 // Wiki is read only
1381 $this->setPageTitle( wfMsg( 'readonly' ) );
1382 $reason = wfReadOnlyReason();
1383 $this->wrapWikiMsg( '<div class="mw-readonly-error">$1</div>', array( 'readonlytext', $reason ) );
1384 }
1385
1386 // Show source, if supplied
1387 if( is_string( $source ) ) {
1388 $this->addWikiMsg( 'viewsourcetext' );
1389
1390 $params = array(
1391 'id' => 'wpTextbox1',
1392 'name' => 'wpTextbox1',
1393 'cols' => $wgUser->getOption( 'cols' ),
1394 'rows' => $wgUser->getOption( 'rows' ),
1395 'readonly' => 'readonly'
1396 );
1397 $this->addHTML( Html::element( 'textarea', $params, $source ) );
1398
1399 // Show templates used by this article
1400 $skin = $wgUser->getSkin();
1401 $article = new Article( $this->getTitle() );
1402 $this->addHTML( "<div class='templatesUsed'>
1403 {$skin->formatTemplates( $article->getUsedTemplates() )}
1404 </div>
1405 " );
1406 }
1407
1408 # If the title doesn't exist, it's fairly pointless to print a return
1409 # link to it. After all, you just tried editing it and couldn't, so
1410 # what's there to do there?
1411 if( $this->getTitle()->exists() ) {
1412 $this->returnToMain( null, $this->getTitle() );
1413 }
1414 }
1415
1416 /** @deprecated */
1417 public function fatalError( $message ) {
1418 wfDeprecated( __METHOD__ );
1419 throw new FatalError( $message );
1420 }
1421
1422 /** @deprecated */
1423 public function unexpectedValueError( $name, $val ) {
1424 wfDeprecated( __METHOD__ );
1425 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1426 }
1427
1428 /** @deprecated */
1429 public function fileCopyError( $old, $new ) {
1430 wfDeprecated( __METHOD__ );
1431 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1432 }
1433
1434 /** @deprecated */
1435 public function fileRenameError( $old, $new ) {
1436 wfDeprecated( __METHOD__ );
1437 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1438 }
1439
1440 /** @deprecated */
1441 public function fileDeleteError( $name ) {
1442 wfDeprecated( __METHOD__ );
1443 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1444 }
1445
1446 /** @deprecated */
1447 public function fileNotFoundError( $name ) {
1448 wfDeprecated( __METHOD__ );
1449 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1450 }
1451
1452 public function showFatalError( $message ) {
1453 $this->setPageTitle( wfMsg( "internalerror" ) );
1454 $this->setRobotPolicy( "noindex,nofollow" );
1455 $this->setArticleRelated( false );
1456 $this->enableClientCache( false );
1457 $this->mRedirect = '';
1458 $this->mBodytext = $message;
1459 }
1460
1461 public function showUnexpectedValueError( $name, $val ) {
1462 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1463 }
1464
1465 public function showFileCopyError( $old, $new ) {
1466 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1467 }
1468
1469 public function showFileRenameError( $old, $new ) {
1470 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1471 }
1472
1473 public function showFileDeleteError( $name ) {
1474 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1475 }
1476
1477 public function showFileNotFoundError( $name ) {
1478 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1479 }
1480
1481 /**
1482 * Add a "return to" link pointing to a specified title
1483 *
1484 * @param Title $title Title to link
1485 * @param string $query Query string
1486 */
1487 public function addReturnTo( $title, $query = array() ) {
1488 global $wgUser;
1489 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
1490 $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link(
1491 $title, null, array(), $query ) );
1492 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
1493 }
1494
1495 /**
1496 * Add a "return to" link pointing to a specified title,
1497 * or the title indicated in the request, or else the main page
1498 *
1499 * @param null $unused No longer used
1500 * @param Title $returnto Title to return to
1501 */
1502 public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
1503 global $wgRequest;
1504
1505 if ( $returnto == null ) {
1506 $returnto = $wgRequest->getText( 'returnto' );
1507 }
1508
1509 if ( $returntoquery == null ) {
1510 $returntoquery = $wgRequest->getText( 'returntoquery' );
1511 }
1512
1513 if ( '' === $returnto ) {
1514 $returnto = Title::newMainPage();
1515 }
1516
1517 if ( is_object( $returnto ) ) {
1518 $titleObj = $returnto;
1519 } else {
1520 $titleObj = Title::newFromText( $returnto );
1521 }
1522 if ( !is_object( $titleObj ) ) {
1523 $titleObj = Title::newMainPage();
1524 }
1525
1526 $this->addReturnTo( $titleObj, $returntoquery );
1527 }
1528
1529 /**
1530 * @return string The doctype, opening <html>, and head element.
1531 *
1532 * @param $sk Skin The given Skin
1533 */
1534 public function headElement( Skin $sk, $includeStyle = true ) {
1535 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1536 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
1537 global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5;
1538
1539 $this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" );
1540 if ( $sk->commonPrintStylesheet() ) {
1541 $this->addStyle( 'common/wikiprintable.css', 'print' );
1542 }
1543 $sk->setupUserCss( $this );
1544
1545 $ret = '';
1546
1547 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
1548 $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
1549 }
1550
1551 if ( '' == $this->getHTMLTitle() ) {
1552 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1553 }
1554
1555 $dir = $wgContLang->getDir();
1556
1557 if ( $wgHtml5 ) {
1558 $ret .= "<!DOCTYPE html>\n";
1559 $ret .= "<html lang=\"$wgContLanguageCode\" dir=\"$dir\" ";
1560 if ($wgHtml5Version) $ret .= " version=\"$wgHtml5Version\" ";
1561 $ret .= ">\n";
1562 } else {
1563 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
1564 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1565 foreach($wgXhtmlNamespaces as $tag => $ns) {
1566 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1567 }
1568 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
1569 }
1570
1571 $ret .= "<head>\n";
1572 $ret .= "<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1573 $ret .= implode( "\n", array(
1574 $this->getHeadLinks(),
1575 $this->buildCssLinks(),
1576 $this->getHeadScripts( $sk ),
1577 $this->getHeadItems(),
1578 ));
1579 if( $sk->usercss ){
1580 $ret .= Html::inlineStyle( $sk->usercss );
1581 }
1582
1583 if ($wgUseTrackbacks && $this->isArticleRelated())
1584 $ret .= $this->getTitle()->trackbackRDF();
1585
1586 $ret .= "</head>\n";
1587 return $ret;
1588 }
1589
1590 /*
1591 * gets the global variables and mScripts
1592 *
1593 * also adds userjs to the end if enabled:
1594 */
1595 function getHeadScripts( Skin $sk ) {
1596 global $wgUser, $wgRequest, $wgJsMimeType, $wgUseSiteJs;
1597 global $wgStylePath, $wgStyleVersion;
1598
1599 $scripts = Skin::makeGlobalVariablesScript( $sk->getSkinName() );
1600 $scripts .= Html::linkedScript( "{$wgStylePath}/common/wikibits.js?$wgStyleVersion" );
1601
1602 //add site JS if enabled:
1603 if( $wgUseSiteJs ) {
1604 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
1605 $this->addScriptFile( Skin::makeUrl( '-',
1606 "action=raw$jsCache&gen=js&useskin=" .
1607 urlencode( $sk->getSkinName() )
1608 )
1609 );
1610 }
1611
1612 //add user js if enabled:
1613 if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
1614 $action = $wgRequest->getVal( 'action', 'view' );
1615 if( $this->mTitle && $this->mTitle->isJsSubpage() and $sk->userCanPreview( $action ) ) {
1616 # XXX: additional security check/prompt?
1617 $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
1618 } else {
1619 $userpage = $wgUser->getUserPage();
1620 $userjs = Skin::makeUrl(
1621 $userpage->getPrefixedText() . '/' . $sk->getSkinName() . '.js',
1622 'action=raw&ctype=' . $wgJsMimeType );
1623 $this->addScriptFile( $userjs );
1624 }
1625 }
1626
1627 $scripts .= "\n" . $this->mScripts;
1628 return $scripts;
1629 }
1630
1631 protected function addDefaultMeta() {
1632 global $wgVersion, $wgHtml5;
1633
1634 static $called = false;
1635 if ( $called ) {
1636 # Don't run this twice
1637 return;
1638 }
1639 $called = true;
1640
1641 if ( !$wgHtml5 ) {
1642 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
1643 }
1644 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
1645
1646 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
1647 if( $p !== 'index,follow' ) {
1648 // http://www.robotstxt.org/wc/meta-user.html
1649 // Only show if it's different from the default robots policy
1650 $this->addMeta( 'robots', $p );
1651 }
1652
1653 if ( count( $this->mKeywords ) > 0 ) {
1654 $strip = array(
1655 "/<.*?" . ">/" => '',
1656 "/_/" => ' '
1657 );
1658 $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ) ) );
1659 }
1660 }
1661
1662 /**
1663 * @return string HTML tag links to be put in the header.
1664 */
1665 public function getHeadLinks() {
1666 global $wgRequest, $wgFeed;
1667
1668 // Ideally this should happen earlier, somewhere. :P
1669 $this->addDefaultMeta();
1670
1671 $tags = array();
1672
1673 foreach ( $this->mMetatags as $tag ) {
1674 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1675 $a = 'http-equiv';
1676 $tag[0] = substr( $tag[0], 5 );
1677 } else {
1678 $a = 'name';
1679 }
1680 $tags[] = Html::element( 'meta',
1681 array(
1682 $a => $tag[0],
1683 'content' => $tag[1] ) );
1684 }
1685 foreach ( $this->mLinktags as $tag ) {
1686 $tags[] = Html::element( 'link', $tag );
1687 }
1688
1689 if( $wgFeed ) {
1690 foreach( $this->getSyndicationLinks() as $format => $link ) {
1691 # Use the page name for the title (accessed through $wgTitle since
1692 # there's no other way). In principle, this could lead to issues
1693 # with having the same name for different feeds corresponding to
1694 # the same page, but we can't avoid that at this low a level.
1695
1696 $tags[] = $this->feedLink(
1697 $format,
1698 $link,
1699 wfMsg( "page-{$format}-feed", $this->getTitle()->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1700 }
1701
1702 # Recent changes feed should appear on every page (except recentchanges,
1703 # that would be redundant). Put it after the per-page feed to avoid
1704 # changing existing behavior. It's still available, probably via a
1705 # menu in your browser. Some sites might have a different feed they'd
1706 # like to promote instead of the RC feed (maybe like a "Recent New Articles"
1707 # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
1708 # If so, use it instead.
1709
1710 global $wgOverrideSiteFeed, $wgSitename, $wgFeedClasses;
1711 $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
1712
1713 if ( $wgOverrideSiteFeed ) {
1714 foreach ( $wgOverrideSiteFeed as $type => $feedUrl ) {
1715 $tags[] = $this->feedLink (
1716 $type,
1717 htmlspecialchars( $feedUrl ),
1718 wfMsg( "site-{$type}-feed", $wgSitename ) );
1719 }
1720 }
1721 else if ( $this->getTitle()->getPrefixedText() != $rctitle->getPrefixedText() ) {
1722 foreach( $wgFeedClasses as $format => $class ) {
1723 $tags[] = $this->feedLink(
1724 $format,
1725 $rctitle->getLocalURL( "feed={$format}" ),
1726 wfMsg( "site-{$format}-feed", $wgSitename ) ); # For grep: 'site-rss-feed', 'site-atom-feed'.
1727 }
1728 }
1729 }
1730
1731 return implode( "\n", $tags );
1732 }
1733
1734 /**
1735 * Return URLs for each supported syndication format for this page.
1736 * @return array associating format keys with URLs
1737 */
1738 public function getSyndicationLinks() {
1739 return $this->mFeedLinks;
1740 }
1741
1742 /**
1743 * Generate a <link rel/> for an RSS feed.
1744 */
1745 private function feedLink( $type, $url, $text ) {
1746 return Html::element( 'link', array(
1747 'rel' => 'alternate',
1748 'type' => "application/$type+xml",
1749 'title' => $text,
1750 'href' => $url ) );
1751 }
1752
1753 /**
1754 * Add a local or specified stylesheet, with the given media options.
1755 * Meant primarily for internal use...
1756 *
1757 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1758 * @param $conditional -- for IE conditional comments, specifying an IE version
1759 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1760 */
1761 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1762 $options = array();
1763 // Even though we expect the media type to be lowercase, but here we
1764 // force it to lowercase to be safe.
1765 if( $media )
1766 $options['media'] = $media;
1767 if( $condition )
1768 $options['condition'] = $condition;
1769 if( $dir )
1770 $options['dir'] = $dir;
1771 $this->styles[$style] = $options;
1772 }
1773
1774 /**
1775 * Adds inline CSS styles
1776 * @param $style_css Mixed: inline CSS
1777 */
1778 public function addInlineStyle( $style_css ){
1779 $this->mScripts .= Html::inlineStyle( $style_css );
1780 }
1781
1782 /**
1783 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1784 * These will be applied to various media & IE conditionals.
1785 */
1786 public function buildCssLinks() {
1787 $links = array();
1788 foreach( $this->styles as $file => $options ) {
1789 $link = $this->styleLink( $file, $options );
1790 if( $link )
1791 $links[] = $link;
1792 }
1793
1794 return implode( "\n", $links );
1795 }
1796
1797 protected function styleLink( $style, $options ) {
1798 global $wgRequest;
1799
1800 if( isset( $options['dir'] ) ) {
1801 global $wgContLang;
1802 $siteDir = $wgContLang->getDir();
1803 if( $siteDir != $options['dir'] )
1804 return '';
1805 }
1806
1807 if( isset( $options['media'] ) ) {
1808 $media = $this->transformCssMedia( $options['media'] );
1809 if( is_null( $media ) ) {
1810 return '';
1811 }
1812 } else {
1813 $media = 'all';
1814 }
1815
1816 if( substr( $style, 0, 1 ) == '/' ||
1817 substr( $style, 0, 5 ) == 'http:' ||
1818 substr( $style, 0, 6 ) == 'https:' ) {
1819 $url = $style;
1820 } else {
1821 global $wgStylePath, $wgStyleVersion;
1822 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1823 }
1824
1825 $link = Html::linkedStyle( $url, $media );
1826
1827 if( isset( $options['condition'] ) ) {
1828 $condition = htmlspecialchars( $options['condition'] );
1829 $link = "<!--[if $condition]>$link<![endif]-->";
1830 }
1831 return $link;
1832 }
1833
1834 function transformCssMedia( $media ) {
1835 global $wgRequest, $wgHandheldForIPhone;
1836
1837 // Switch in on-screen display for media testing
1838 $switches = array(
1839 'printable' => 'print',
1840 'handheld' => 'handheld',
1841 );
1842 foreach( $switches as $switch => $targetMedia ) {
1843 if( $wgRequest->getBool( $switch ) ) {
1844 if( $media == $targetMedia ) {
1845 $media = '';
1846 } elseif( $media == 'screen' ) {
1847 return null;
1848 }
1849 }
1850 }
1851
1852 // Expand longer media queries as iPhone doesn't grok 'handheld'
1853 if( $wgHandheldForIPhone ) {
1854 $mediaAliases = array(
1855 'screen' => 'screen and (min-device-width: 481px)',
1856 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1857 );
1858
1859 if( isset( $mediaAliases[$media] ) ) {
1860 $media = $mediaAliases[$media];
1861 }
1862 }
1863
1864 return $media;
1865 }
1866
1867 /**
1868 * Turn off regular page output and return an error reponse
1869 * for when rate limiting has triggered.
1870 */
1871 public function rateLimited() {
1872
1873 $this->setPageTitle(wfMsg('actionthrottled'));
1874 $this->setRobotPolicy( 'noindex,follow' );
1875 $this->setArticleRelated( false );
1876 $this->enableClientCache( false );
1877 $this->mRedirect = '';
1878 $this->clearHTML();
1879 $this->setStatusCode(503);
1880 $this->addWikiMsg( 'actionthrottledtext' );
1881
1882 $this->returnToMain( null, $this->getTitle() );
1883 }
1884
1885 /**
1886 * Show an "add new section" link?
1887 *
1888 * @return bool
1889 */
1890 public function showNewSectionLink() {
1891 return $this->mNewSectionLink;
1892 }
1893
1894 /**
1895 * Forcibly hide the new section link?
1896 *
1897 * @return bool
1898 */
1899 public function forceHideNewSectionLink() {
1900 return $this->mHideNewSectionLink;
1901 }
1902
1903 /**
1904 * Show a warning about slave lag
1905 *
1906 * If the lag is higher than $wgSlaveLagCritical seconds,
1907 * then the warning is a bit more obvious. If the lag is
1908 * lower than $wgSlaveLagWarning, then no warning is shown.
1909 *
1910 * @param int $lag Slave lag
1911 */
1912 public function showLagWarning( $lag ) {
1913 global $wgSlaveLagWarning, $wgSlaveLagCritical, $wgLang;
1914 if( $lag >= $wgSlaveLagWarning ) {
1915 $message = $lag < $wgSlaveLagCritical
1916 ? 'lag-warn-normal'
1917 : 'lag-warn-high';
1918 $wrap = Html::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" );
1919 $this->wrapWikiMsg( "$wrap\n", array( $message, $wgLang->formatNum( $lag ) ) );
1920 }
1921 }
1922
1923 /**
1924 * Add a wikitext-formatted message to the output.
1925 * This is equivalent to:
1926 *
1927 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
1928 */
1929 public function addWikiMsg( /*...*/ ) {
1930 $args = func_get_args();
1931 $name = array_shift( $args );
1932 $this->addWikiMsgArray( $name, $args );
1933 }
1934
1935 /**
1936 * Add a wikitext-formatted message to the output.
1937 * Like addWikiMsg() except the parameters are taken as an array
1938 * instead of a variable argument list.
1939 *
1940 * $options is passed through to wfMsgExt(), see that function for details.
1941 */
1942 public function addWikiMsgArray( $name, $args, $options = array() ) {
1943 $options[] = 'parse';
1944 $text = wfMsgExt( $name, $options, $args );
1945 $this->addHTML( $text );
1946 }
1947
1948 /**
1949 * This function takes a number of message/argument specifications, wraps them in
1950 * some overall structure, and then parses the result and adds it to the output.
1951 *
1952 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
1953 * on. The subsequent arguments may either be strings, in which case they are the
1954 * message names, or arrays, in which case the first element is the message name,
1955 * and subsequent elements are the parameters to that message.
1956 *
1957 * The special named parameter 'options' in a message specification array is passed
1958 * through to the $options parameter of wfMsgExt().
1959 *
1960 * Don't use this for messages that are not in users interface language.
1961 *
1962 * For example:
1963 *
1964 * $wgOut->wrapWikiMsg( '<div class="error">$1</div>', 'some-error' );
1965 *
1966 * Is equivalent to:
1967 *
1968 * $wgOut->addWikiText( '<div class="error">' . wfMsgNoTrans( 'some-error' ) . '</div>' );
1969 */
1970 public function wrapWikiMsg( $wrap /*, ...*/ ) {
1971 $msgSpecs = func_get_args();
1972 array_shift( $msgSpecs );
1973 $msgSpecs = array_values( $msgSpecs );
1974 $s = $wrap;
1975 foreach ( $msgSpecs as $n => $spec ) {
1976 $options = array();
1977 if ( is_array( $spec ) ) {
1978 $args = $spec;
1979 $name = array_shift( $args );
1980 if ( isset( $args['options'] ) ) {
1981 $options = $args['options'];
1982 unset( $args['options'] );
1983 }
1984 } else {
1985 $args = array();
1986 $name = $spec;
1987 }
1988 $s = str_replace( '$' . ( $n + 1 ), wfMsgExt( $name, $options, $args ), $s );
1989 }
1990 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
1991 }
1992 }