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 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
42 $this->mKeywords
= $this->mLinktags
= array();
43 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
44 $this->mRedirect
= $this->mLastModified
=
45 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
46 $this->mOnloadHandler
= "";
47 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
48 $this->mSuppressQuickbar
= $this->mPrintable
= false;
49 $this->mLanguageLinks
= array();
50 $this->mCategoryLinks
= array() ;
51 $this->mDoNothing
= false;
52 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
53 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
54 $this->mSquidMaxage
= 0;
58 function addHeader( $name, $val ) { array_push( $this->mHeaders
, "$name: $val" ) ; }
59 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
60 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
62 # To add an http-equiv meta tag, precede the name with "http:"
63 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
64 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
65 function addScript( $script ) { $this->mScripts
.= $script; }
66 function getScript() { return $this->mScripts
; }
68 function addLink( $linkarr ) {
69 # $linkarr should be an associative array of attributes. We'll escape on output.
70 array_push( $this->mLinktags
, $linkarr );
73 function addMetadataLink( $linkarr ) {
74 # note: buggy CC software only reads first "meta" link
75 static $haveMeta = false;
76 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
77 $this->addLink( $linkarr );
82 * checkLastModified tells the client to use the client-cached page if
83 * possible. If sucessful, the OutputPage is disabled so that
84 * any future call to OutputPage->output() have no effect. The method
85 * returns true iff cache-ok headers was sent.
87 function checkLastModified ( $timestamp )
89 global $wgLang, $wgCachePages, $wgUser;
90 $timestamp=wfTimestamp(TS_MW
,$timestamp);
91 if( !$wgCachePages ) {
92 wfDebug( "CACHE DISABLED\n", false );
95 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
96 # IE 5.0 has probs with our caching
97 wfDebug( "-- bad client, not caching\n", false );
100 if( $wgUser->getOption( 'nocache' ) ) {
101 wfDebug( "USER DISABLED CACHE\n", false );
105 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp(TS_UNIX
, max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
107 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
108 # IE sends sizes after the date like this:
109 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
110 # this breaks strtotime().
111 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
112 $ismodsince = wfTimestamp( TS_MW
, strtotime( $modsince ) );
113 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
114 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
115 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
116 # Make sure you're in a place you can leave when you call us!
117 header( "HTTP/1.0 304 Not Modified" );
118 $this->mLastModified
= $lastmod;
119 $this->sendCacheControl();
120 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
124 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
125 $this->mLastModified
= $lastmod;
128 wfDebug( "We're confused.\n", false );
129 $this->mLastModified
= $lastmod;
133 function getPageTitleActionText () {
137 return wfMsg('edit');
139 return wfMsg('history_short');
141 return wfMsg('protect');
143 return wfMsg('unprotect');
145 return wfMsg('delete');
147 return wfMsg('watch');
149 return wfMsg('unwatch');
151 return wfMsg('preview');
153 return wfMsg('info_short');
158 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
159 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
160 function setPageTitle( $name ) {
162 $this->mPagetitle
= $name;
163 if(!empty($action)) {
164 $taction = $this->getPageTitleActionText();
165 if( !empty( $taction ) ) {
166 $name .= ' - '.$taction;
169 $this->setHTMLTitle( $name . ' - ' . wfMsg( 'wikititlesuffix' ) );
171 function getHTMLTitle() { return $this->mHTMLtitle
; }
172 function getPageTitle() { return $this->mPagetitle
; }
173 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
174 function getSubtitle() { return $this->mSubtitle
; }
175 function isArticle() { return $this->mIsarticle
; }
176 function setPrintable() { $this->mPrintable
= true; }
177 function isPrintable() { return $this->mPrintable
; }
178 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
179 function isSyndicated() { return $this->mShowFeedLinks
; }
180 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
181 function getOnloadHandler() { return $this->mOnloadHandler
; }
182 function disable() { $this->mDoNothing
= true; }
184 function setArticleRelated( $v )
186 $this->mIsArticleRelated
= $v;
188 $this->mIsarticle
= false;
191 function setArticleFlag( $v ) {
192 $this->mIsarticle
= $v;
194 $this->mIsArticleRelated
= $v;
198 function isArticleRelated()
200 return $this->mIsArticleRelated
;
203 function getLanguageLinks() {
204 return $this->mLanguageLinks
;
206 function addLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks +
= $newLinkArray;
209 function setLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks
= $newLinkArray;
212 function getCategoryLinks() {
213 return $this->mCategoryLinks
;
215 function addCategoryLinks($newLinkArray) {
216 $this->mCategoryLinks +
= $newLinkArray;
218 function setCategoryLinks($newLinkArray) {
219 $this->mCategoryLinks +
= $newLinkArray;
222 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
223 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
225 function addHTML( $text ) { $this->mBodytext
.= $text; }
226 function debug( $text ) { $this->mDebugtext
.= $text; }
228 function setParserOptions( $options )
230 return wfSetVar( $this->mParserOptions
, $options );
234 * Convert wikitext to HTML and add it to the buffer
236 function addWikiText( $text, $linestart = true )
238 global $wgParser, $wgTitle;
240 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
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;
253 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, true );
255 # Replace link holders
256 $text = $parserOutput->getText();
257 $this->replaceLinkHolders( $text );
258 $parserOutput->setText( $text );
260 if ( $cacheArticle ) {
261 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
264 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
265 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
266 $this->addHTML( $text );
269 function tryParserCache( $article, $user ) {
270 global $wgParserCache;
271 $parserOutput = $wgParserCache->get( $article, $user );
272 if ( $parserOutput !== false ) {
273 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
274 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
275 $this->addHTML( $parserOutput->getText() );
283 * Set the maximum cache time on the Squid in seconds
285 function setSquidMaxage( $maxage ) {
286 $this->mSquidMaxage
= $maxage;
290 * Use enableClientCache(false) to force it to send nocache headers
292 function enableClientCache( $state ) {
293 return wfSetVar( $this->mEnableClientCache
, $state );
296 function sendCacheControl() {
297 global $wgUseSquid, $wgUseESI;
298 # FIXME: This header may cause trouble with some versions of Internet Explorer
299 header( 'Vary: Accept-Encoding, Cookie' );
300 if( $this->mEnableClientCache
) {
301 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
302 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
305 # We'll purge the proxy cache explicitly, but require end user agents
306 # to revalidate against the proxy on each visit.
307 # Surrogate-Control controls our Squid, Cache-Control downstream caches
308 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
309 # start with a shorter timeout for initial testing
310 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
311 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
312 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
314 # We'll purge the proxy cache for anons explicitly, but require end user agents
315 # to revalidate against the proxy on each visit.
316 # IMPORTANT! The Squid needs to replace the Cache-Control header with
317 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
318 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
319 # start with a shorter timeout for initial testing
320 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
321 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
324 # We do want clients to cache if they can, but they *must* check for updates
325 # on revisiting the page.
326 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
327 header( "Expires: -1" );
328 header( "Cache-Control: private, must-revalidate, max-age=0" );
330 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
332 wfDebug( "** no caching **\n", false );
334 # In general, the absence of a last modified header should be enough to prevent
335 # the client from using its cache. We send a few other things just to make sure.
336 header( 'Expires: -1' );
337 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
338 header( 'Pragma: no-cache' );
343 * Finally, all the text has been munged and accumulated into
344 * the object, let's actually output it:
348 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
349 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
350 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
351 if( $this->mDoNothing
){
354 $fname = 'OutputPage::output';
355 wfProfileIn( $fname );
357 $sk = $wgUser->getSkin();
359 if ( '' != $this->mRedirect
) {
360 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
361 # Standards require redirect URLs to be absolute
363 $this->mRedirect
= $wgServer . $this->mRedirect
;
365 if( $this->mRedirectCode
== '301') {
366 if( !$wgDebugRedirects ) {
367 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
369 $this->mLastModified
= gmdate( 'D, j M Y H:i:s' ) . ' GMT';
372 $this->sendCacheControl();
374 if( $wgDebugRedirects ) {
375 $url = htmlspecialchars( $this->mRedirect
);
376 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
377 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
378 print "</body>\n</html>\n";
380 header( 'Location: '.$this->mRedirect
);
382 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
387 $this->sendCacheControl();
388 # Perform link colouring
389 $this->transformBuffer();
391 # Disable temporary placeholders, so that the skin produces HTML
392 $sk->postParseLinkColour( false );
394 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
395 header( 'Content-language: '.$wgLanguageCode );
397 $exp = time() +
$wgCookieExpiration;
398 foreach( $this->mCookies
as $name => $val ) {
399 setcookie( $name, $val, $exp, '/' );
402 $sk->outputPage( $this );
406 function out( $ins ) {
407 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
408 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
411 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
412 if ( false === $outs ) { $outs = $ins; }
417 function setEncodings() {
418 global $wgInputEncoding, $wgOutputEncoding;
419 global $wgUser, $wgLang;
421 $wgInputEncoding = strtolower( $wgInputEncoding );
423 if( $wgUser->getOption( 'altencoding' ) ) {
424 $wgLang->setAltEncoding();
428 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
429 $wgOutputEncoding = strtolower( $wgOutputEncoding );
434 # This code is unused anyway!
435 # Commenting out. --bv 2003-11-15
437 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
441 foreach ( $a as $s ) {
442 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
454 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
455 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
456 $wgOutputEncoding = strtolower( $bestset );
461 $wgOutputEncoding = $wgInputEncoding;
465 * Returns a HTML comment with the elapsed time since request.
466 * This method has no side effects.
468 function reportTime() {
469 global $wgRequestTime;
472 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
473 $start = (float)$sec +
(float)$usec;
474 $elapsed = $now - $start;
476 # Use real server name if available, so we know which machine
477 # in a server farm generated the current page.
478 if ( function_exists( 'posix_uname' ) ) {
479 $uname = @posix_uname
();
483 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
484 $hostname = $uname['nodename'];
486 # This may be a virtual server.
487 $hostname = $_SERVER['SERVER_NAME'];
489 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
490 $hostname, $elapsed );
495 * Note: these arguments are keys into wfMsg(), not text!
497 function errorpage( $title, $msg ) {
500 $this->mDebugtext
.= 'Original title: ' .
501 $wgTitle->getPrefixedText() . "\n";
502 $this->setPageTitle( wfMsg( $title ) );
503 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
504 $this->setRobotpolicy( 'noindex,nofollow' );
505 $this->setArticleRelated( false );
506 $this->enableClientCache( false );
507 $this->mRedirect
= '';
509 $this->mBodytext
= '';
510 $this->addHTML( '<p>' . wfMsg( $msg ) . "</p>\n" );
511 $this->returnToMain( false );
517 function sysopRequired() {
520 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
521 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
522 $this->setRobotpolicy( 'noindex,nofollow' );
523 $this->setArticleRelated( false );
524 $this->mBodytext
= '';
526 $sk = $wgUser->getSkin();
527 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
528 $this->addHTML( wfMsg( 'sysoptext', $ap ) );
529 $this->returnToMain();
532 function developerRequired() {
535 $this->setPageTitle( wfMsg( 'developertitle' ) );
536 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
537 $this->setRobotpolicy( 'noindex,nofollow' );
538 $this->setArticleRelated( false );
539 $this->mBodytext
= '';
541 $sk = $wgUser->getSkin();
542 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
543 $this->addHTML( wfMsg( 'developertext', $ap ) );
544 $this->returnToMain();
547 function loginToUse() {
548 global $wgUser, $wgTitle, $wgLang;
550 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
551 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
552 $this->setRobotpolicy( 'noindex,nofollow' );
553 $this->setArticleFlag( false );
554 $this->mBodytext
= '';
555 $this->addWikiText( wfMsg( 'loginreqtext' ) );
557 # We put a comment in the .html file so a Sysop can diagnose the page the
559 $this->addHTML( "\n<!--" .
560 $wgLang->getNsText( $wgTitle->getNamespace() ) .
562 $wgTitle->getDBkey() . '-->' );
563 $this->returnToMain(); # Flip back to the main page after 10 seconds.
566 function databaseError( $fname, $sql, $error, $errno ) {
567 global $wgUser, $wgCommandLineMode;
569 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
570 $this->setRobotpolicy( 'noindex,nofollow' );
571 $this->setArticleRelated( false );
572 $this->enableClientCache( false );
573 $this->mRedirect
= '';
575 if ( $wgCommandLineMode ) {
576 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
577 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
579 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
580 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
583 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
587 $this->mBodytext
= $msg;
592 function readOnlyPage( $source = null, $protected = false ) {
593 global $wgUser, $wgReadOnlyFile;
595 $this->setRobotpolicy( 'noindex,nofollow' );
596 $this->setArticleRelated( false );
599 $this->setPageTitle( wfMsg( 'viewsource' ) );
600 $this->addWikiText( wfMsg( 'protectedtext' ) );
602 $this->setPageTitle( wfMsg( 'readonly' ) );
603 $reason = file_get_contents( $wgReadOnlyFile );
604 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
607 if( is_string( $source ) ) {
608 if( strcmp( $source, '' ) == 0 ) {
609 $source = wfMsg( 'noarticletext' );
611 $rows = $wgUser->getOption( 'rows' );
612 $cols = $wgUser->getOption( 'cols' );
613 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
614 htmlspecialchars( $source ) . "\n</textarea>";
615 $this->addHTML( $text );
618 $this->returnToMain( false );
621 function fatalError( $message ) {
622 $this->setPageTitle( wfMsg( "internalerror" ) );
623 $this->setRobotpolicy( "noindex,nofollow" );
624 $this->setArticleRelated( false );
625 $this->enableClientCache( false );
626 $this->mRedirect
= '';
628 $this->mBodytext
= $message;
633 function unexpectedValueError( $name, $val ) {
634 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
637 function fileCopyError( $old, $new ) {
638 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
641 function fileRenameError( $old, $new ) {
642 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
645 function fileDeleteError( $name ) {
646 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
649 function fileNotFoundError( $name ) {
650 $this->fatalError( wfMsg( 'filenotfound', $name ) );
654 * return from error messages or notes
655 * @param $auto automatically redirect the user after 10 seconds
656 * @param $returnto page title to return to. Default is Main Page.
658 function returnToMain( $auto = true, $returnto = NULL ) {
659 global $wgUser, $wgOut, $wgRequest;
661 if ( $returnto == NULL ) {
662 $returnto = $wgRequest->getText( 'returnto' );
665 $sk = $wgUser->getSkin();
666 if ( '' == $returnto ) {
667 $returnto = wfMsg( 'mainpage' );
669 $link = $sk->makeKnownLink( $returnto, '' );
671 $r = wfMsg( 'returnto', $link );
673 $titleObj = Title
::newFromText( $returnto );
674 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
676 $wgOut->addHTML( "\n<p>$r</p>\n" );
680 * This function takes the existing and broken links for the page
681 * and uses the first 10 of them for META keywords
683 function addMetaTags () {
684 global $wgLinkCache , $wgOut ;
685 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
686 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
687 $a = array_merge ( $good , $bad ) ;
688 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
689 $a = implode ( ',' , $a ) ;
691 "/<.*?" . ">/" => '',
694 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
696 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
702 function headElement() {
703 global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
704 global $wgUser, $wgLang, $wgRequest;
706 $xml = ($wgMimeType == 'text/xml');
708 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
713 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
715 if ( "" == $this->mHTMLtitle
) {
716 $this->mHTMLtitle
= wfMsg( "pagetitle", $this->mPagetitle
);
719 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
723 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : '';
724 $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
725 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle
) . "</title>\n";
726 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
728 $ret .= $this->getHeadLinks();
730 if( $this->isPrintable() ) {
733 $media = "media='print'";
735 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
736 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
738 $sk = $wgUser->getSkin();
739 $ret .= $sk->getHeadScripts();
740 $ret .= $this->mScripts
;
741 $ret .= $sk->getUserStyles();
747 function getHeadLinks() {
748 global $wgRequest, $wgStylePath;
750 foreach ( $this->mMetatags
as $tag ) {
751 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
753 $tag[0] = substr( $tag[0], 5 );
757 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
759 $p = $this->mRobotpolicy
;
760 if ( '' == $p ) { $p = 'index,follow'; }
761 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
763 if ( count( $this->mKeywords
) > 0 ) {
765 "/<.*?" . ">/" => '',
768 $ret .= "<meta name=\"keywords\" content=\"" .
769 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
771 foreach ( $this->mLinktags
as $tag ) {
773 foreach( $tag as $attr => $val ) {
774 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
778 if( $this->isSyndicated() ) {
779 # FIXME: centralize the mime-type and name information in Feed.php
780 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
781 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
782 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
783 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
785 # FIXME: get these working
786 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
787 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
792 * Run any necessary pre-output transformations on the buffer text
794 function transformBuffer( $options = 0 ) {
795 $this->replaceLinkHolders( $this->mBodytext
, $options );
799 * Replace <!--LINK--> link placeholders with actual links, in the buffer
800 * Placeholders created in Skin::makeLinkObj()
801 * Returns an array of links found, indexed by PDBK:
805 * $options is a bit field, RLH_FOR_UPDATE to select for update
807 function replaceLinkHolders( &$text, $options = 0 ) {
808 global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck;
810 if ( $wgUseOldExistenceCheck ) {
814 $fname = 'OutputPage::replaceLinkHolders';
815 wfProfileIn( $fname );
821 # Get placeholders from body
822 wfProfileIn( $fname.'-match' );
823 preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $text, $tmpLinks );
824 wfProfileOut( $fname.'-match' );
826 if ( !empty( $tmpLinks[0] ) ) {
827 wfProfileIn( $fname.'-check' );
828 $dbr =& wfGetDB( DB_SLAVE
);
829 $cur = $dbr->tableName( 'cur' );
830 $sk = $wgUser->getSkin();
831 $threshold = $wgUser->getOption('stubthreshold');
833 $namespaces =& $tmpLinks[1];
834 $dbkeys =& $tmpLinks[2];
835 $queries =& $tmpLinks[3];
836 $texts =& $tmpLinks[4];
839 asort( $namespaces );
843 foreach ( $namespaces as $key => $val ) {
845 $dbk = $dbkeys[$key];
846 $title = $titles[$key] = Title
::makeTitleSafe( $val, $dbk );
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( $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 ( $namespaces as $key => $ns ) {
915 $pdbk = $pdbks[$key];
916 $searchkey = $tmpLinks[0][$key];
917 $title = $titles[$key];
918 if ( empty( $colours[$pdbk] ) ) {
919 $wgLinkCache->addBadLink( $pdbk );
921 $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title, $texts[$key], $queries[$key] );
922 } elseif ( $colours[$pdbk] == 1 ) {
923 $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title, $texts[$key], $queries[$key] );
924 } elseif ( $colours[$pdbk] == 2 ) {
925 $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title, $texts[$key], $queries[$key] );
928 wfProfileOut( $fname.'-construct' );
931 wfProfileIn( $fname.'-replace' );
933 $text = preg_replace_callback(
934 '/(<!--LINK .*? .*? .*? .*?-->)/',
935 "outputReplaceMatches",
937 wfProfileOut( $fname.'-replace' );
939 wfProfileOut( $fname );
944 function &outputReplaceMatches($matches) {
945 global $outputReplace;
946 return $outputReplace[$matches[1]];