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