* (bug 3170) Page Title failed to obey MediaWiki:Pagetitle
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
8 */
9 if( defined( 'MEDIAWIKI' ) ) {
10
11 # See design.txt
12
13 if($wgUseTeX) require_once( 'Math.php' );
14
15 /**
16 * @todo document
17 * @package MediaWiki
18 */
19 class OutputPage {
20 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
21 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
22 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
23 var $mSubtitle, $mRedirect;
24 var $mLastModified, $mETag, $mCategoryLinks;
25 var $mScripts, $mLinkColours;
26
27 var $mSuppressQuickbar;
28 var $mOnloadHandler;
29 var $mDoNothing;
30 var $mContainsOldMagic, $mContainsNewMagic;
31 var $mIsArticleRelated;
32 var $mParserOptions;
33 var $mShowFeedLinks = false;
34 var $mEnableClientCache = true;
35 var $mArticleBodyOnly = false;
36
37 /**
38 * Constructor
39 * Initialise private variables
40 */
41 function OutputPage() {
42 $this->mHeaders = $this->mCookies = $this->mMetatags =
43 $this->mKeywords = $this->mLinktags = array();
44 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
45 $this->mRedirect = $this->mLastModified =
46 $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
47 $this->mOnloadHandler = '';
48 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
49 $this->mSuppressQuickbar = $this->mPrintable = false;
50 $this->mLanguageLinks = array();
51 $this->mCategoryLinks = array() ;
52 $this->mDoNothing = false;
53 $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
54 $this->mParserOptions = ParserOptions::newFromUser( $temp = NULL );
55 $this->mSquidMaxage = 0;
56 $this->mScripts = '';
57 $this->mETag = false;
58 }
59
60 function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; }
61 function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); }
62 function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
63
64 # To add an http-equiv meta tag, precede the name with "http:"
65 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
66 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
67 function addScript( $script ) { $this->mScripts .= $script; }
68 function getScript() { return $this->mScripts; }
69
70 function setETag($tag) { $this->mETag = $tag; }
71 function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
72 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly; }
73
74 function addLink( $linkarr ) {
75 # $linkarr should be an associative array of attributes. We'll escape on output.
76 array_push( $this->mLinktags, $linkarr );
77 }
78
79 function addMetadataLink( $linkarr ) {
80 # note: buggy CC software only reads first "meta" link
81 static $haveMeta = false;
82 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
83 $this->addLink( $linkarr );
84 $haveMeta = true;
85 }
86
87 /**
88 * checkLastModified tells the client to use the client-cached page if
89 * possible. If sucessful, the OutputPage is disabled so that
90 * any future call to OutputPage->output() have no effect. The method
91 * returns true iff cache-ok headers was sent.
92 */
93 function checkLastModified ( $timestamp ) {
94 global $wgLang, $wgCachePages, $wgUser;
95 if ( !$timestamp || $timestamp == '19700101000000' ) {
96 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
97 return;
98 }
99 if( !$wgCachePages ) {
100 wfDebug( "CACHE DISABLED\n", false );
101 return;
102 }
103 if( $wgUser->getOption( 'nocache' ) ) {
104 wfDebug( "USER DISABLED CACHE\n", false );
105 return;
106 }
107
108 $timestamp=wfTimestamp(TS_MW,$timestamp);
109 $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched ) );
110
111 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
112 # IE sends sizes after the date like this:
113 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
114 # this breaks strtotime().
115 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
116 $modsinceTime = strtotime( $modsince );
117 $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 );
118 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
119 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
120 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
121 # Make sure you're in a place you can leave when you call us!
122 header( "HTTP/1.0 304 Not Modified" );
123 $this->mLastModified = $lastmod;
124 $this->sendCacheControl();
125 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
126 $this->disable();
127 @ob_end_clean(); // Don't output compressed blob
128 return true;
129 } else {
130 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
131 $this->mLastModified = $lastmod;
132 }
133 } else {
134 wfDebug( "client did not send If-Modified-Since header\n", false );
135 $this->mLastModified = $lastmod;
136 }
137 }
138
139 function getPageTitleActionText () {
140 global $action;
141 switch($action) {
142 case 'edit':
143 return wfMsg('edit');
144 case 'history':
145 return wfMsg('history_short');
146 case 'protect':
147 return wfMsg('protect');
148 case 'unprotect':
149 return wfMsg('unprotect');
150 case 'delete':
151 return wfMsg('delete');
152 case 'watch':
153 return wfMsg('watch');
154 case 'unwatch':
155 return wfMsg('unwatch');
156 case 'submit':
157 return wfMsg('preview');
158 case 'info':
159 return wfMsg('info_short');
160 default:
161 return '';
162 }
163 }
164
165 function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
166 function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
167 function setPageTitle( $name ) {
168 global $action, $wgContLang;
169 $name = $wgContLang->convert($name, true);
170 $this->mPagetitle = $name;
171 if(!empty($action)) {
172 $taction = $this->getPageTitleActionText();
173 if( !empty( $taction ) ) {
174 $name .= ' - '.$taction;
175 }
176 }
177
178 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
179 }
180 function getHTMLTitle() { return $this->mHTMLtitle; }
181 function getPageTitle() { return $this->mPagetitle; }
182 function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
183 function getSubtitle() { return $this->mSubtitle; }
184 function isArticle() { return $this->mIsarticle; }
185 function setPrintable() { $this->mPrintable = true; }
186 function isPrintable() { return $this->mPrintable; }
187 function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
188 function isSyndicated() { return $this->mShowFeedLinks; }
189 function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
190 function getOnloadHandler() { return $this->mOnloadHandler; }
191 function disable() { $this->mDoNothing = true; }
192
193 function setArticleRelated( $v ) {
194 $this->mIsArticleRelated = $v;
195 if ( !$v ) {
196 $this->mIsarticle = false;
197 }
198 }
199 function setArticleFlag( $v ) {
200 $this->mIsarticle = $v;
201 if ( $v ) {
202 $this->mIsArticleRelated = $v;
203 }
204 }
205
206 function isArticleRelated() { return $this->mIsArticleRelated; }
207
208 function getLanguageLinks() { return $this->mLanguageLinks; }
209 function addLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks += $newLinkArray;
211 }
212 function setLanguageLinks($newLinkArray) {
213 $this->mLanguageLinks = $newLinkArray;
214 }
215
216 function getCategoryLinks() {
217 return $this->mCategoryLinks;
218 }
219 function addCategoryLinks($newLinkArray) {
220 $this->mCategoryLinks += $newLinkArray;
221 }
222 function setCategoryLinks($newLinkArray) {
223 $this->mCategoryLinks += $newLinkArray;
224 }
225
226 function suppressQuickbar() { $this->mSuppressQuickbar = true; }
227 function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
228
229 function addHTML( $text ) { $this->mBodytext .= $text; }
230 function clearHTML() { $this->mBodytext = ''; }
231 function getHTML() { return $this->mBodytext; }
232 function debug( $text ) { $this->mDebugtext .= $text; }
233
234 function setParserOptions( $options ) {
235 return wfSetVar( $this->mParserOptions, $options );
236 }
237
238 /**
239 * Convert wikitext to HTML and add it to the buffer
240 * Default assumes that the current page title will
241 * be used.
242 */
243 function addWikiText( $text, $linestart = true ) {
244 global $wgTitle;
245 $this->addWikiTextTitle($text, $wgTitle, $linestart);
246 }
247
248 function addWikiTextWithTitle($text, &$title, $linestart = true) {
249 $this->addWikiTextTitle($text, $title, $linestart);
250 }
251
252 function addWikiTextTitle($text, &$title, $linestart) {
253 global $wgParser, $wgUseTidy;
254 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions, $linestart );
255 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
256 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
257 if ( $parserOutput->getCacheTime() == -1 ) {
258 $this->enableClientCache( false );
259 }
260 $this->addHTML( $parserOutput->getText() );
261 }
262
263 /**
264 * Add wikitext to the buffer, assuming that this is the primary text for a page view
265 * Saves the text into the parser cache if possible
266 */
267 function addPrimaryWikiText( $text, $cacheArticle ) {
268 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
269
270 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true );
271
272 $text = $parserOutput->getText();
273
274 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
275 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
276 }
277
278 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
279 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
280 if ( $parserOutput->getCacheTime() == -1 ) {
281 $this->enableClientCache( false );
282 }
283 $this->addHTML( $text );
284 }
285
286 /**
287 * Add the output of a QuickTemplate to the output buffer
288 * @param QuickTemplate $template
289 */
290 function addTemplate( &$template ) {
291 ob_start();
292 $template->execute();
293 $this->addHtml( ob_get_contents() );
294 ob_end_clean();
295 }
296
297 /**
298 * Parse wikitext and return the HTML. This is for special pages that add the text later
299 */
300 function parse( $text, $linestart = true ) {
301 global $wgParser, $wgTitle;
302 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
303 return $parserOutput->getText();
304 }
305
306 /**
307 * @param $article
308 * @param $user
309 *
310 * @return bool
311 */
312 function tryParserCache( $article, $user ) {
313 global $wgParserCache;
314 $parserOutput = $wgParserCache->get( $article, $user );
315 if ( $parserOutput !== false ) {
316 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
317 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
318 $this->addHTML( $parserOutput->getText() );
319 $t = $parserOutput->getTitleText();
320 if( !empty( $t ) ) {
321 $this->setPageTitle( $t );
322 }
323 return true;
324 } else {
325 return false;
326 }
327 }
328
329 /**
330 * Set the maximum cache time on the Squid in seconds
331 * @param $maxage
332 */
333 function setSquidMaxage( $maxage ) {
334 $this->mSquidMaxage = $maxage;
335 }
336
337 /**
338 * Use enableClientCache(false) to force it to send nocache headers
339 * @param $state
340 */
341 function enableClientCache( $state ) {
342 return wfSetVar( $this->mEnableClientCache, $state );
343 }
344
345 function uncacheableBecauseRequestvars() {
346 global $wgRequest;
347 return $wgRequest->getText('useskin', false) === false
348 && $wgRequest->getText('uselang', false) === false;
349 }
350
351 function sendCacheControl() {
352 global $wgUseSquid, $wgUseESI;
353
354 if ($this->mETag)
355 header("ETag: $this->mETag");
356
357 # don't serve compressed data to clients who can't handle it
358 # maintain different caches for logged-in users and non-logged in ones
359 header( 'Vary: Accept-Encoding, Cookie' );
360 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache ) {
361 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
362 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
363 {
364 if ( $wgUseESI ) {
365 # We'll purge the proxy cache explicitly, but require end user agents
366 # to revalidate against the proxy on each visit.
367 # Surrogate-Control controls our Squid, Cache-Control downstream caches
368 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
369 # start with a shorter timeout for initial testing
370 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
371 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
372 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
373 } else {
374 # We'll purge the proxy cache for anons explicitly, but require end user agents
375 # to revalidate against the proxy on each visit.
376 # IMPORTANT! The Squid needs to replace the Cache-Control header with
377 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
378 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
379 # start with a shorter timeout for initial testing
380 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
381 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
382 }
383 } else {
384 # We do want clients to cache if they can, but they *must* check for updates
385 # on revisiting the page.
386 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
387 header( "Expires: -1" );
388 header( "Cache-Control: private, must-revalidate, max-age=0" );
389 }
390 if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
391 } else {
392 wfDebug( "** no caching **\n", false );
393
394 # In general, the absence of a last modified header should be enough to prevent
395 # the client from using its cache. We send a few other things just to make sure.
396 header( 'Expires: -1' );
397 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
398 header( 'Pragma: no-cache' );
399 }
400 }
401
402 /**
403 * Finally, all the text has been munged and accumulated into
404 * the object, let's actually output it:
405 */
406 function output() {
407 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
408 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
409 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
410
411 if( $this->mDoNothing ){
412 return;
413 }
414 $fname = 'OutputPage::output';
415 wfProfileIn( $fname );
416 $sk = $wgUser->getSkin();
417
418 if ( '' != $this->mRedirect ) {
419 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
420 # Standards require redirect URLs to be absolute
421 global $wgServer;
422 $this->mRedirect = $wgServer . $this->mRedirect;
423 }
424 if( $this->mRedirectCode == '301') {
425 if( !$wgDebugRedirects ) {
426 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
427 }
428 $this->mLastModified = wfTimestamp( TS_RFC2822 );
429 }
430
431 $this->sendCacheControl();
432
433 if( $wgDebugRedirects ) {
434 $url = htmlspecialchars( $this->mRedirect );
435 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
436 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
437 print "</body>\n</html>\n";
438 } else {
439 header( 'Location: '.$this->mRedirect );
440 }
441 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
442 wfProfileOut( $fname );
443 return;
444 }
445
446
447 # Buffer output; final headers may depend on later processing
448 ob_start();
449
450 $this->transformBuffer();
451
452 # Disable temporary placeholders, so that the skin produces HTML
453 $sk->postParseLinkColour( false );
454
455 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
456 header( 'Content-language: '.$wgContLanguageCode );
457
458 $exp = time() + $wgCookieExpiration;
459 foreach( $this->mCookies as $name => $val ) {
460 setcookie( $name, $val, $exp, '/' );
461 }
462
463 if ($this->mArticleBodyOnly) {
464 $this->out($this->mBodytext);
465 } else {
466 wfProfileIn( 'Output-skin' );
467 $sk->outputPage( $this );
468 wfProfileOut( 'Output-skin' );
469 }
470
471 $this->sendCacheControl();
472 ob_end_flush();
473 wfProfileOut( $fname );
474 }
475
476 function out( $ins ) {
477 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
478 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
479 $outs = $ins;
480 } else {
481 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
482 if ( false === $outs ) { $outs = $ins; }
483 }
484 print $outs;
485 }
486
487 function setEncodings() {
488 global $wgInputEncoding, $wgOutputEncoding;
489 global $wgUser, $wgContLang;
490
491 $wgInputEncoding = strtolower( $wgInputEncoding );
492
493 if( $wgUser->getOption( 'altencoding' ) ) {
494 $wgContLang->setAltEncoding();
495 return;
496 }
497
498 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
499 $wgOutputEncoding = strtolower( $wgOutputEncoding );
500 return;
501 }
502 $wgOutputEncoding = $wgInputEncoding;
503 }
504
505 /**
506 * Returns a HTML comment with the elapsed time since request.
507 * This method has no side effects.
508 * @return string
509 */
510 function reportTime() {
511 global $wgRequestTime;
512
513 $now = wfTime();
514 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
515 $start = (float)$sec + (float)$usec;
516 $elapsed = $now - $start;
517
518 # Use real server name if available, so we know which machine
519 # in a server farm generated the current page.
520 if ( function_exists( 'posix_uname' ) ) {
521 $uname = @posix_uname();
522 } else {
523 $uname = false;
524 }
525 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
526 $hostname = $uname['nodename'];
527 } else {
528 # This may be a virtual server.
529 $hostname = $_SERVER['SERVER_NAME'];
530 }
531 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
532 $hostname, $elapsed );
533 return $com;
534 }
535
536 /**
537 * Note: these arguments are keys into wfMsg(), not text!
538 */
539 function errorpage( $title, $msg ) {
540 global $wgTitle;
541
542 $this->mDebugtext .= 'Original title: ' .
543 $wgTitle->getPrefixedText() . "\n";
544 $this->setPageTitle( wfMsg( $title ) );
545 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
546 $this->setRobotpolicy( 'noindex,nofollow' );
547 $this->setArticleRelated( false );
548 $this->enableClientCache( false );
549 $this->mRedirect = '';
550
551 $this->mBodytext = '';
552 $this->addWikiText( wfMsg( $msg ) );
553 $this->returnToMain( false );
554
555 $this->output();
556 wfErrorExit();
557 }
558
559 /**
560 * Display an error page indicating that a given version of MediaWiki is
561 * required to use it
562 *
563 * @param mixed $version The version of MediaWiki needed to use the page
564 */
565 function versionRequired( $version ) {
566 global $wgUser;
567
568 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
569 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
570 $this->setRobotpolicy( 'noindex,nofollow' );
571 $this->setArticleRelated( false );
572 $this->mBodytext = '';
573
574 $sk = $wgUser->getSkin();
575 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
576 $this->returnToMain();
577 }
578
579 /**
580 * Display an error page noting that a given permission bit is required.
581 * This should generally replace the sysopRequired, developerRequired etc.
582 * @param string $permission key required
583 */
584 function permissionRequired( $permission ) {
585 global $wgUser;
586
587 $this->setPageTitle( wfMsg( 'badaccess' ) );
588 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
589 $this->setRobotpolicy( 'noindex,nofollow' );
590 $this->setArticleRelated( false );
591 $this->mBodytext = '';
592
593 $sk = $wgUser->getSkin();
594 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
595 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
596 $this->returnToMain();
597 }
598
599 /**
600 * @deprecated
601 */
602 function sysopRequired() {
603 global $wgUser;
604
605 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
606 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
607 $this->setRobotpolicy( 'noindex,nofollow' );
608 $this->setArticleRelated( false );
609 $this->mBodytext = '';
610
611 $sk = $wgUser->getSkin();
612 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
613 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
614 $this->returnToMain();
615 }
616
617 /**
618 * @deprecated
619 */
620 function developerRequired() {
621 global $wgUser;
622
623 $this->setPageTitle( wfMsg( 'developertitle' ) );
624 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
625 $this->setRobotpolicy( 'noindex,nofollow' );
626 $this->setArticleRelated( false );
627 $this->mBodytext = '';
628
629 $sk = $wgUser->getSkin();
630 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
631 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
632 $this->returnToMain();
633 }
634
635 function loginToUse() {
636 global $wgUser, $wgTitle, $wgContLang;
637
638 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
639 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
640 $this->setRobotpolicy( 'noindex,nofollow' );
641 $this->setArticleFlag( false );
642 $this->mBodytext = '';
643 $loginpage = Title::makeTitle(NS_SPECIAL, 'Userlogin');
644 $sk = $wgUser->getSkin();
645 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
646 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
647 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
648
649 # We put a comment in the .html file so a Sysop can diagnose the page the
650 # user can't see.
651 $this->addHTML( "\n<!--" .
652 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
653 ':' .
654 $wgTitle->getDBkey() . '-->' );
655 $this->returnToMain(); # Flip back to the main page after 10 seconds.
656 }
657
658 function databaseError( $fname, $sql, $error, $errno ) {
659 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
660
661 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
662 $this->setRobotpolicy( 'noindex,nofollow' );
663 $this->setArticleRelated( false );
664 $this->enableClientCache( false );
665 $this->mRedirect = '';
666
667 if( !$wgShowSQLErrors ) {
668 $sql = wfMsg( 'sqlhidden' );
669 }
670
671 if ( $wgCommandLineMode ) {
672 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
673 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
674 } else {
675 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
676 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
677 }
678
679 if ( $wgCommandLineMode || !is_object( $wgUser )) {
680 print $msg."\n";
681 wfErrorExit();
682 }
683 $this->mBodytext = $msg;
684 $this->output();
685 wfErrorExit();
686 }
687
688 function readOnlyPage( $source = null, $protected = false ) {
689 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
690
691 $this->setRobotpolicy( 'noindex,nofollow' );
692 $this->setArticleRelated( false );
693
694 if( $protected ) {
695 $this->setPageTitle( wfMsg( 'viewsource' ) );
696 $this->addWikiText( wfMsg( 'protectedtext' ) );
697 } else {
698 $this->setPageTitle( wfMsg( 'readonly' ) );
699 if ( $wgReadOnly ) {
700 $reason = $wgReadOnly;
701 } else {
702 $reason = file_get_contents( $wgReadOnlyFile );
703 }
704 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
705 }
706
707 if( is_string( $source ) ) {
708 if( strcmp( $source, '' ) == 0 ) {
709 $source = wfMsg( 'noarticletext' );
710 }
711 $rows = $wgUser->getOption( 'rows' );
712 $cols = $wgUser->getOption( 'cols' );
713 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
714 htmlspecialchars( $source ) . "\n</textarea>";
715 $this->addHTML( $text );
716 }
717
718 $this->returnToMain( false );
719 }
720
721 function fatalError( $message ) {
722 $this->setPageTitle( wfMsg( "internalerror" ) );
723 $this->setRobotpolicy( "noindex,nofollow" );
724 $this->setArticleRelated( false );
725 $this->enableClientCache( false );
726 $this->mRedirect = '';
727
728 $this->mBodytext = $message;
729 $this->output();
730 wfErrorExit();
731 }
732
733 function unexpectedValueError( $name, $val ) {
734 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
735 }
736
737 function fileCopyError( $old, $new ) {
738 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
739 }
740
741 function fileRenameError( $old, $new ) {
742 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
743 }
744
745 function fileDeleteError( $name ) {
746 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
747 }
748
749 function fileNotFoundError( $name ) {
750 $this->fatalError( wfMsg( 'filenotfound', $name ) );
751 }
752
753 /**
754 * return from error messages or notes
755 * @param $auto automatically redirect the user after 10 seconds
756 * @param $returnto page title to return to. Default is Main Page.
757 */
758 function returnToMain( $auto = true, $returnto = NULL ) {
759 global $wgUser, $wgOut, $wgRequest;
760
761 if ( $returnto == NULL ) {
762 $returnto = $wgRequest->getText( 'returnto' );
763 }
764 $returnto = htmlspecialchars( $returnto );
765
766 $sk = $wgUser->getSkin();
767 if ( '' == $returnto ) {
768 $returnto = wfMsgForContent( 'mainpage' );
769 }
770 $link = $sk->makeKnownLink( $returnto, '' );
771
772 $r = wfMsg( 'returnto', $link );
773 if ( $auto ) {
774 $titleObj = Title::newFromText( $returnto );
775 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
776 }
777 $wgOut->addHTML( "\n<p>$r</p>\n" );
778 }
779
780 /**
781 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
782 * and uses the first 10 of them for META keywords
783 */
784 function addMetaTags () {
785 global $wgLinkCache , $wgOut ;
786 $categories = array_keys ( $wgLinkCache->mCategoryLinks ) ;
787 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
788 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
789 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
790 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
791 $a = implode ( ',' , $a ) ;
792 $strip = array(
793 "/<.*?>/" => '',
794 "/_/" => ' '
795 );
796 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
797
798 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
799 }
800
801 /**
802 * @private
803 * @return string
804 */
805 function headElement() {
806 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
807 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
808
809 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
810 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
811 } else {
812 $ret = '';
813 }
814
815 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
816
817 if ( '' == $this->getHTMLTitle() ) {
818 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
819 }
820
821 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
822 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
823 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
824 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
825
826 $ret .= $this->getHeadLinks();
827 global $wgStylePath;
828 if( $this->isPrintable() ) {
829 $media = '';
830 } else {
831 $media = "media='print'";
832 }
833 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
834 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
835
836 $sk = $wgUser->getSkin();
837 $ret .= $sk->getHeadScripts();
838 $ret .= $this->mScripts;
839 $ret .= $sk->getUserStyles();
840
841 if ($wgUseTrackbacks && $this->isArticleRelated())
842 $ret .= $wgTitle->trackbackRDF();
843
844 $ret .= "</head>\n";
845 return $ret;
846 }
847
848 function getHeadLinks() {
849 global $wgRequest, $wgStylePath;
850 $ret = '';
851 foreach ( $this->mMetatags as $tag ) {
852 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
853 $a = 'http-equiv';
854 $tag[0] = substr( $tag[0], 5 );
855 } else {
856 $a = 'name';
857 }
858 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
859 }
860 $p = $this->mRobotpolicy;
861 if ( '' == $p ) { $p = 'index,follow'; }
862 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
863
864 if ( count( $this->mKeywords ) > 0 ) {
865 $strip = array(
866 "/<.*?>/" => '',
867 "/_/" => ' '
868 );
869 $ret .= "<meta name=\"keywords\" content=\"" .
870 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
871 }
872 foreach ( $this->mLinktags as $tag ) {
873 $ret .= '<link';
874 foreach( $tag as $attr => $val ) {
875 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
876 }
877 $ret .= " />\n";
878 }
879 if( $this->isSyndicated() ) {
880 # FIXME: centralize the mime-type and name information in Feed.php
881 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
882 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
883 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
884 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
885 }
886
887 return $ret;
888 }
889
890 /**
891 * Run any necessary pre-output transformations on the buffer text
892 */
893 function transformBuffer( $options = 0 ) {
894 }
895
896
897 /**
898 * Turn off regular page output and return an error reponse
899 * for when rate limiting has triggered.
900 * @todo i18n
901 * @access public
902 */
903 function rateLimited() {
904 global $wgOut;
905 $wgOut->disable();
906 wfHttpError( 500, 'Internal Server Error',
907 'Sorry, the server has encountered an internal error. ' .
908 'Please wait a moment and hit "refresh" to submit the request again.' );
909 }
910
911 }
912
913 } // MediaWiki
914
915 ?>