8 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
10 if( defined( 'MEDIAWIKI' ) ) {
14 if($wgUseTeX) require_once( 'Math.php' );
16 define( 'RLH_FOR_UPDATE', 1 );
23 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
24 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
25 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
26 var $mSubtitle, $mRedirect;
27 var $mLastModified, $mCategoryLinks;
28 var $mScripts, $mLinkColours;
30 var $mSuppressQuickbar;
33 var $mContainsOldMagic, $mContainsNewMagic;
34 var $mIsArticleRelated;
36 var $mShowFeedLinks = false;
37 var $mEnableClientCache = true;
41 * Initialise private variables
43 function OutputPage() {
44 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
45 $this->mKeywords
= $this->mLinktags
= array();
46 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
47 $this->mRedirect
= $this->mLastModified
=
48 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
49 $this->mOnloadHandler
= '';
50 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
51 $this->mSuppressQuickbar
= $this->mPrintable
= false;
52 $this->mLanguageLinks
= array();
53 $this->mCategoryLinks
= array() ;
54 $this->mDoNothing
= false;
55 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
56 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
57 $this->mSquidMaxage
= 0;
61 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ) ; }
62 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
63 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
65 # To add an http-equiv meta tag, precede the name with "http:"
66 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
67 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
68 function addScript( $script ) { $this->mScripts
.= $script; }
69 function getScript() { return $this->mScripts
; }
71 function addLink( $linkarr ) {
72 # $linkarr should be an associative array of attributes. We'll escape on output.
73 array_push( $this->mLinktags
, $linkarr );
76 function addMetadataLink( $linkarr ) {
77 # note: buggy CC software only reads first "meta" link
78 static $haveMeta = false;
79 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
80 $this->addLink( $linkarr );
85 * checkLastModified tells the client to use the client-cached page if
86 * possible. If sucessful, the OutputPage is disabled so that
87 * any future call to OutputPage->output() have no effect. The method
88 * returns true iff cache-ok headers was sent.
90 function checkLastModified ( $timestamp ) {
91 global $wgLang, $wgCachePages, $wgUser;
92 $timestamp=wfTimestamp(TS_MW
,$timestamp);
93 if( !$wgCachePages ) {
94 wfDebug( "CACHE DISABLED\n", false );
97 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
98 # IE 5.0 has probs with our caching
99 wfDebug( "-- bad client, not caching\n", false );
102 if( $wgUser->getOption( 'nocache' ) ) {
103 wfDebug( "USER DISABLED CACHE\n", false );
107 $lastmod = gmdate( 'D, j M Y H:i:s', wfTimestamp(TS_UNIX
, max( $timestamp, $wgUser->mTouched
) ) ) . ' GMT';
109 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
110 # IE sends sizes after the date like this:
111 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
112 # this breaks strtotime().
113 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
114 $ismodsince = wfTimestamp( TS_MW
, strtotime( $modsince ) );
115 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
116 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
117 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
118 # Make sure you're in a place you can leave when you call us!
119 header( "HTTP/1.0 304 Not Modified" );
120 $this->mLastModified
= $lastmod;
121 $this->sendCacheControl();
122 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
126 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
127 $this->mLastModified
= $lastmod;
130 wfDebug( "We're confused.\n", false );
131 $this->mLastModified
= $lastmod;
135 function getPageTitleActionText () {
139 return wfMsg('edit');
141 return wfMsg('history_short');
143 return wfMsg('protect');
145 return wfMsg('unprotect');
147 return wfMsg('delete');
149 return wfMsg('watch');
151 return wfMsg('unwatch');
153 return wfMsg('preview');
155 return wfMsg('info_short');
161 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
162 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
163 function setPageTitle( $name ) {
165 $this->mPagetitle
= $name;
166 if(!empty($action)) {
167 $taction = $this->getPageTitleActionText();
168 if( !empty( $taction ) ) {
169 $name .= ' - '.$taction;
172 $this->setHTMLTitle( $name . ' - ' . wfMsg( 'wikititlesuffix' ) );
174 function getHTMLTitle() { return $this->mHTMLtitle
; }
175 function getPageTitle() { return $this->mPagetitle
; }
176 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
177 function getSubtitle() { return $this->mSubtitle
; }
178 function isArticle() { return $this->mIsarticle
; }
179 function setPrintable() { $this->mPrintable
= true; }
180 function isPrintable() { return $this->mPrintable
; }
181 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
182 function isSyndicated() { return $this->mShowFeedLinks
; }
183 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
184 function getOnloadHandler() { return $this->mOnloadHandler
; }
185 function disable() { $this->mDoNothing
= true; }
187 function setArticleRelated( $v ) {
188 $this->mIsArticleRelated
= $v;
190 $this->mIsarticle
= false;
193 function setArticleFlag( $v ) {
194 $this->mIsarticle
= $v;
196 $this->mIsArticleRelated
= $v;
200 function isArticleRelated() { return $this->mIsArticleRelated
; }
202 function getLanguageLinks() { return $this->mLanguageLinks
; }
203 function addLanguageLinks($newLinkArray) {
204 $this->mLanguageLinks +
= $newLinkArray;
206 function setLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks
= $newLinkArray;
210 function getCategoryLinks() {
211 return $this->mCategoryLinks
;
213 function addCategoryLinks($newLinkArray) {
214 $this->mCategoryLinks +
= $newLinkArray;
216 function setCategoryLinks($newLinkArray) {
217 $this->mCategoryLinks +
= $newLinkArray;
220 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
221 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
223 function addHTML( $text ) { $this->mBodytext
.= $text; }
224 function clearHTML() { $this->mBodytext
= ''; }
225 function debug( $text ) { $this->mDebugtext
.= $text; }
227 function setParserOptions( $options ) {
228 return wfSetVar( $this->mParserOptions
, $options );
232 * Convert wikitext to HTML and add it to the buffer
234 function addWikiText( $text, $linestart = true ) {
235 global $wgParser, $wgTitle, $wgUseTidy;
237 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
239 $text = Parser
::tidy($text);
241 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
242 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
243 $this->addHTML( $parserOutput->getText() );
247 * Add wikitext to the buffer, assuming that this is the primary text for a page view
248 * Saves the text into the parser cache if possible
250 function addPrimaryWikiText( $text, $cacheArticle ) {
251 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
253 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, true );
255 # Replace link holders
256 $text = $parserOutput->getText();
257 $this->replaceLinkHolders( $text );
259 $text = Parser
::tidy($text);
261 $parserOutput->setText( $text );
263 if ( $cacheArticle ) {
264 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
267 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
268 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
269 $this->addHTML( $text );
276 function tryParserCache( $article, $user ) {
277 global $wgParserCache;
278 $parserOutput = $wgParserCache->get( $article, $user );
279 if ( $parserOutput !== false ) {
280 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
281 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
282 $this->addHTML( $parserOutput->getText() );
290 * Set the maximum cache time on the Squid in seconds
293 function setSquidMaxage( $maxage ) {
294 $this->mSquidMaxage
= $maxage;
298 * Use enableClientCache(false) to force it to send nocache headers
301 function enableClientCache( $state ) {
302 return wfSetVar( $this->mEnableClientCache
, $state );
305 function sendCacheControl() {
306 global $wgUseSquid, $wgUseESI;
307 # FIXME: This header may cause trouble with some versions of Internet Explorer
308 header( 'Vary: Accept-Encoding, Cookie' );
309 if( $this->mEnableClientCache
) {
310 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
311 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
314 # We'll purge the proxy cache explicitly, but require end user agents
315 # to revalidate against the proxy on each visit.
316 # Surrogate-Control controls our Squid, Cache-Control downstream caches
317 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
318 # start with a shorter timeout for initial testing
319 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
320 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
321 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
323 # We'll purge the proxy cache for anons explicitly, but require end user agents
324 # to revalidate against the proxy on each visit.
325 # IMPORTANT! The Squid needs to replace the Cache-Control header with
326 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
327 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
328 # start with a shorter timeout for initial testing
329 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
330 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
333 # We do want clients to cache if they can, but they *must* check for updates
334 # on revisiting the page.
335 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
336 header( "Expires: -1" );
337 header( "Cache-Control: private, must-revalidate, max-age=0" );
339 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
341 wfDebug( "** no caching **\n", false );
343 # In general, the absence of a last modified header should be enough to prevent
344 # the client from using its cache. We send a few other things just to make sure.
345 header( 'Expires: -1' );
346 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
347 header( 'Pragma: no-cache' );
352 * Finally, all the text has been munged and accumulated into
353 * the object, let's actually output it:
356 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
357 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
358 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
359 if( $this->mDoNothing
){
362 $fname = 'OutputPage::output';
363 wfProfileIn( $fname );
365 $sk = $wgUser->getSkin();
367 if ( '' != $this->mRedirect
) {
368 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
369 # Standards require redirect URLs to be absolute
371 $this->mRedirect
= $wgServer . $this->mRedirect
;
373 if( $this->mRedirectCode
== '301') {
374 if( !$wgDebugRedirects ) {
375 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
377 $this->mLastModified
= gmdate( 'D, j M Y H:i:s' ) . ' GMT';
380 $this->sendCacheControl();
382 if( $wgDebugRedirects ) {
383 $url = htmlspecialchars( $this->mRedirect
);
384 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
385 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
386 print "</body>\n</html>\n";
388 header( 'Location: '.$this->mRedirect
);
390 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
395 $this->sendCacheControl();
396 # Perform link colouring
397 $this->transformBuffer();
398 $this->replaceLinkHolders( $this->mSubtitle
);
400 # Disable temporary placeholders, so that the skin produces HTML
401 $sk->postParseLinkColour( false );
403 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
404 header( 'Content-language: '.$wgContLanguageCode );
406 $exp = time() +
$wgCookieExpiration;
407 foreach( $this->mCookies
as $name => $val ) {
408 setcookie( $name, $val, $exp, '/' );
411 $sk->outputPage( $this );
415 function out( $ins ) {
416 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
417 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
420 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
421 if ( false === $outs ) { $outs = $ins; }
426 function setEncodings() {
427 global $wgInputEncoding, $wgOutputEncoding;
428 global $wgUser, $wgContLang;
430 $wgInputEncoding = strtolower( $wgInputEncoding );
432 if( $wgUser->getOption( 'altencoding' ) ) {
433 $wgContLang->setAltEncoding();
437 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
438 $wgOutputEncoding = strtolower( $wgOutputEncoding );
443 # This code is unused anyway!
444 # Commenting out. --bv 2003-11-15
446 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
450 foreach ( $a as $s ) {
451 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
463 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
464 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
465 $wgOutputEncoding = strtolower( $bestset );
470 $wgOutputEncoding = $wgInputEncoding;
474 * Returns a HTML comment with the elapsed time since request.
475 * This method has no side effects.
477 function reportTime() {
478 global $wgRequestTime;
481 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
482 $start = (float)$sec +
(float)$usec;
483 $elapsed = $now - $start;
485 # Use real server name if available, so we know which machine
486 # in a server farm generated the current page.
487 if ( function_exists( 'posix_uname' ) ) {
488 $uname = @posix_uname
();
492 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
493 $hostname = $uname['nodename'];
495 # This may be a virtual server.
496 $hostname = $_SERVER['SERVER_NAME'];
498 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
499 $hostname, $elapsed );
504 * Note: these arguments are keys into wfMsg(), not text!
506 function errorpage( $title, $msg ) {
509 $this->mDebugtext
.= 'Original title: ' .
510 $wgTitle->getPrefixedText() . "\n";
511 $this->setPageTitle( wfMsg( $title ) );
512 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
513 $this->setRobotpolicy( 'noindex,nofollow' );
514 $this->setArticleRelated( false );
515 $this->suppressQuickbar();
517 $this->enableClientCache( false );
518 $this->mRedirect
= '';
520 $this->mBodytext
= '';
521 $this->addHTML( '<p>' . wfMsg( $msg ) . "</p>\n" );
522 $this->returnToMain( false );
528 function sysopRequired() {
531 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
532 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
533 $this->setRobotpolicy( 'noindex,nofollow' );
534 $this->setArticleRelated( false );
535 $this->mBodytext
= '';
537 $sk = $wgUser->getSkin();
538 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
539 $this->addHTML( wfMsg( 'sysoptext', $ap ) );
540 $this->returnToMain();
543 function developerRequired() {
546 $this->setPageTitle( wfMsg( 'developertitle' ) );
547 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
548 $this->setRobotpolicy( 'noindex,nofollow' );
549 $this->setArticleRelated( false );
550 $this->mBodytext
= '';
552 $sk = $wgUser->getSkin();
553 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
554 $this->addHTML( wfMsg( 'developertext', $ap ) );
555 $this->returnToMain();
558 function loginToUse() {
559 global $wgUser, $wgTitle, $wgContLang;
561 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
562 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
563 $this->setRobotpolicy( 'noindex,nofollow' );
564 $this->setArticleFlag( false );
565 $this->mBodytext
= '';
566 $this->addWikiText( wfMsg( 'loginreqtext' ) );
568 # We put a comment in the .html file so a Sysop can diagnose the page the
570 $this->addHTML( "\n<!--" .
571 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
573 $wgTitle->getDBkey() . '-->' );
574 $this->returnToMain(); # Flip back to the main page after 10 seconds.
577 function databaseError( $fname, $sql, $error, $errno ) {
578 global $wgUser, $wgCommandLineMode;
580 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
581 $this->setRobotpolicy( 'noindex,nofollow' );
582 $this->setArticleRelated( false );
583 $this->enableClientCache( false );
584 $this->mRedirect
= '';
586 if ( $wgCommandLineMode ) {
587 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
588 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
590 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
591 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
594 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
598 $this->mBodytext
= $msg;
603 function readOnlyPage( $source = null, $protected = false ) {
604 global $wgUser, $wgReadOnlyFile;
606 $this->setRobotpolicy( 'noindex,nofollow' );
607 $this->setArticleRelated( false );
610 $this->setPageTitle( wfMsg( 'viewsource' ) );
611 $this->addWikiText( wfMsg( 'protectedtext' ) );
613 $this->setPageTitle( wfMsg( 'readonly' ) );
614 $reason = file_get_contents( $wgReadOnlyFile );
615 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
618 if( is_string( $source ) ) {
619 if( strcmp( $source, '' ) == 0 ) {
620 $source = wfMsg( 'noarticletext' );
622 $rows = $wgUser->getOption( 'rows' );
623 $cols = $wgUser->getOption( 'cols' );
624 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
625 htmlspecialchars( $source ) . "\n</textarea>";
626 $this->addHTML( $text );
629 $this->returnToMain( false );
632 function fatalError( $message ) {
633 $this->setPageTitle( wfMsg( "internalerror" ) );
634 $this->setRobotpolicy( "noindex,nofollow" );
635 $this->setArticleRelated( false );
636 $this->enableClientCache( false );
637 $this->mRedirect
= '';
639 $this->mBodytext
= $message;
644 function unexpectedValueError( $name, $val ) {
645 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
648 function fileCopyError( $old, $new ) {
649 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
652 function fileRenameError( $old, $new ) {
653 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
656 function fileDeleteError( $name ) {
657 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
660 function fileNotFoundError( $name ) {
661 $this->fatalError( wfMsg( 'filenotfound', $name ) );
665 * return from error messages or notes
666 * @param $auto automatically redirect the user after 10 seconds
667 * @param $returnto page title to return to. Default is Main Page.
669 function returnToMain( $auto = true, $returnto = NULL ) {
670 global $wgUser, $wgOut, $wgRequest;
672 if ( $returnto == NULL ) {
673 $returnto = $wgRequest->getText( 'returnto' );
676 $sk = $wgUser->getSkin();
677 if ( '' == $returnto ) {
678 $returnto = wfMsgForContent( 'mainpage' );
680 $link = $sk->makeKnownLink( $returnto, '' );
682 $r = wfMsg( 'returnto', $link );
684 $titleObj = Title
::newFromText( $returnto );
685 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
687 $wgOut->addHTML( "\n<p>$r</p>\n" );
691 * This function takes the existing and broken links for the page
692 * and uses the first 10 of them for META keywords
694 function addMetaTags () {
695 global $wgLinkCache , $wgOut ;
696 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
697 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
698 $a = array_merge ( $good , $bad ) ;
699 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
700 $a = implode ( ',' , $a ) ;
702 "/<.*?" . ">/" => '',
705 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
707 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
713 function headElement() {
714 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
715 global $wgUser, $wgContLang, $wgRequest;
717 $xml = ($wgMimeType == 'text/xml');
719 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
724 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
726 if ( "" == $this->mHTMLtitle
) {
727 $this->mHTMLtitle
= wfMsg( "pagetitle", $this->mPagetitle
);
730 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
734 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
735 $ret .= "<html $xmlbits lang=\"$wgContLanguageCode\" $rtl>\n";
736 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle
) . "</title>\n";
737 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
739 $ret .= $this->getHeadLinks();
741 if( $this->isPrintable() ) {
744 $media = "media='print'";
746 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
747 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
749 $sk = $wgUser->getSkin();
750 $ret .= $sk->getHeadScripts();
751 $ret .= $this->mScripts
;
752 $ret .= $sk->getUserStyles();
758 function getHeadLinks() {
759 global $wgRequest, $wgStylePath;
761 foreach ( $this->mMetatags
as $tag ) {
762 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
764 $tag[0] = substr( $tag[0], 5 );
768 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
770 $p = $this->mRobotpolicy
;
771 if ( '' == $p ) { $p = 'index,follow'; }
772 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
774 if ( count( $this->mKeywords
) > 0 ) {
776 "/<.*?" . ">/" => '',
779 $ret .= "<meta name=\"keywords\" content=\"" .
780 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
782 foreach ( $this->mLinktags
as $tag ) {
784 foreach( $tag as $attr => $val ) {
785 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
789 if( $this->isSyndicated() ) {
790 # FIXME: centralize the mime-type and name information in Feed.php
791 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
792 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
793 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
794 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
796 # FIXME: get these working
797 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
798 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
803 * Run any necessary pre-output transformations on the buffer text
805 function transformBuffer( $options = 0 ) {
806 $this->replaceLinkHolders( $this->mBodytext
, $options );
810 * Replace <!--LINK--> link placeholders with actual links, in the buffer
811 * Placeholders created in Skin::makeLinkObj()
812 * Returns an array of links found, indexed by PDBK:
816 * $options is a bit field, RLH_FOR_UPDATE to select for update
818 function replaceLinkHolders( &$text, $options = 0 ) {
819 global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck, $wgLinkHolders;
821 if ( $wgUseOldExistenceCheck ) {
825 $fname = 'OutputPage::replaceLinkHolders';
826 wfProfileIn( $fname );
831 #if ( !empty( $tmpLinks[0] ) ) { #TODO
832 if ( !empty( $wgLinkHolders['namespaces'] ) ) {
833 wfProfileIn( $fname.'-check' );
834 $dbr =& wfGetDB( DB_SLAVE
);
835 $cur = $dbr->tableName( 'cur' );
836 $sk = $wgUser->getSkin();
837 $threshold = $wgUser->getOption('stubthreshold');
840 asort( $wgLinkHolders['namespaces'] );
844 foreach ( $wgLinkHolders['namespaces'] as $key => $val ) {
846 $title = $wgLinkHolders['titles'][$key];
848 # Skip invalid entries.
849 # Result will be ugly, but prevents crash.
850 if ( is_null( $title ) ) {
853 $pdbk = $pdbks[$key] = $title->getPrefixedDBkey();
855 # Check if it's in the link cache already
856 if ( $wgLinkCache->getGoodLinkID( $pdbk ) ) {
858 } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
861 # Not in the link cache, add it to the query
862 if ( !isset( $current ) ) {
864 $query = "SELECT cur_id, cur_namespace, cur_title";
865 if ( $threshold > 0 ) {
866 $query .= ", LENGTH(cur_text) AS cur_len, cur_is_redirect";
868 $query .= " FROM $cur WHERE (cur_namespace=$val AND cur_title IN(";
869 } elseif ( $current != $val ) {
871 $query .= ")) OR (cur_namespace=$val AND cur_title IN(";
876 $query .= $dbr->addQuotes( $wgLinkHolders['dbkeys'][$key] );
881 if ( $options & RLH_FOR_UPDATE
) {
882 $query .= ' FOR UPDATE';
885 $res = $dbr->query( $query, $fname );
887 # Fetch data and form into an associative array
888 # non-existent = broken
891 while ( $s = $dbr->fetchObject($res) ) {
892 $title = Title
::makeTitle( $s->cur_namespace
, $s->cur_title
);
893 $pdbk = $title->getPrefixedDBkey();
894 $wgLinkCache->addGoodLink( $s->cur_id
, $pdbk );
896 if ( $threshold > 0 ) {
898 if ( $s->cur_is_redirect ||
$s->cur_namespace
!= 0 ||
$length < $threshold ) {
908 wfProfileOut( $fname.'-check' );
910 # Construct search and replace arrays
911 wfProfileIn( $fname.'-construct' );
912 global $outputReplace;
913 $outputReplace = array();
914 foreach ( $wgLinkHolders['namespaces'] as $key => $ns ) {
915 $pdbk = $pdbks[$key];
916 $searchkey = '<!--LINK '.$key.'-->';
917 $title = $wgLinkHolders['titles'][$key];
918 if ( empty( $colours[$pdbk] ) ) {
919 $wgLinkCache->addBadLink( $pdbk );
921 $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
922 $wgLinkHolders['texts'][$key],
923 $wgLinkHolders['queries'][$key] );
924 } elseif ( $colours[$pdbk] == 1 ) {
925 $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title,
926 $wgLinkHolders['texts'][$key],
927 $wgLinkHolders['queries'][$key] );
928 } elseif ( $colours[$pdbk] == 2 ) {
929 $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title,
930 $wgLinkHolders['texts'][$key],
931 $wgLinkHolders['queries'][$key] );
934 wfProfileOut( $fname.'-construct' );
937 wfProfileIn( $fname.'-replace' );
939 $text = preg_replace_callback(
940 '/(<!--LINK .*?-->)/',
941 "outputReplaceMatches",
943 wfProfileOut( $fname.'-replace' );
945 wfProfileIn( $fname.'-interwiki' );
946 global $wgInterwikiLinkHolders;
947 $outputReplace = $wgInterwikiLinkHolders;
948 $text = preg_replace_callback(
949 '/<!--IWLINK (.*?)-->/',
950 "outputReplaceMatches",
952 wfProfileOut( $fname.'-interwiki' );
954 wfProfileOut( $fname );
959 function &outputReplaceMatches($matches) {
960 global $outputReplace;
961 return $outputReplace[$matches[1]];