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 clearHTML() { $this->mBodytext
= ''; }
227 function debug( $text ) { $this->mDebugtext
.= $text; }
229 function setParserOptions( $options )
231 return wfSetVar( $this->mParserOptions
, $options );
235 * Convert wikitext to HTML and add it to the buffer
237 function addWikiText( $text, $linestart = true )
239 global $wgParser, $wgTitle;
241 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
242 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
243 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
244 $this->addHTML( $parserOutput->getText() );
248 * Add wikitext to the buffer, assuming that this is the primary text for a page view
249 * Saves the text into the parser cache if possible
251 function addPrimaryWikiText( $text, $cacheArticle ) {
252 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
254 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, true );
256 # Replace link holders
257 $text = $parserOutput->getText();
258 $this->replaceLinkHolders( $text );
259 $parserOutput->setText( $text );
261 if ( $cacheArticle ) {
262 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
265 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
266 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
267 $this->addHTML( $text );
270 function tryParserCache( $article, $user ) {
271 global $wgParserCache;
272 $parserOutput = $wgParserCache->get( $article, $user );
273 if ( $parserOutput !== false ) {
274 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
275 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
276 $this->addHTML( $parserOutput->getText() );
284 * Set the maximum cache time on the Squid in seconds
286 function setSquidMaxage( $maxage ) {
287 $this->mSquidMaxage
= $maxage;
291 * Use enableClientCache(false) to force it to send nocache headers
293 function enableClientCache( $state ) {
294 return wfSetVar( $this->mEnableClientCache
, $state );
297 function sendCacheControl() {
298 global $wgUseSquid, $wgUseESI;
299 # FIXME: This header may cause trouble with some versions of Internet Explorer
300 header( 'Vary: Accept-Encoding, Cookie' );
301 if( $this->mEnableClientCache
) {
302 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
303 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
306 # We'll purge the proxy cache explicitly, but require end user agents
307 # to revalidate against the proxy on each visit.
308 # Surrogate-Control controls our Squid, Cache-Control downstream caches
309 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
310 # start with a shorter timeout for initial testing
311 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
312 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
313 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
315 # We'll purge the proxy cache for anons explicitly, but require end user agents
316 # to revalidate against the proxy on each visit.
317 # IMPORTANT! The Squid needs to replace the Cache-Control header with
318 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
319 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
320 # start with a shorter timeout for initial testing
321 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
322 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
325 # We do want clients to cache if they can, but they *must* check for updates
326 # on revisiting the page.
327 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
328 header( "Expires: -1" );
329 header( "Cache-Control: private, must-revalidate, max-age=0" );
331 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
333 wfDebug( "** no caching **\n", false );
335 # In general, the absence of a last modified header should be enough to prevent
336 # the client from using its cache. We send a few other things just to make sure.
337 header( 'Expires: -1' );
338 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
339 header( 'Pragma: no-cache' );
344 * Finally, all the text has been munged and accumulated into
345 * the object, let's actually output it:
349 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
350 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
351 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
352 if( $this->mDoNothing
){
355 $fname = 'OutputPage::output';
356 wfProfileIn( $fname );
358 $sk = $wgUser->getSkin();
360 if ( '' != $this->mRedirect
) {
361 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
362 # Standards require redirect URLs to be absolute
364 $this->mRedirect
= $wgServer . $this->mRedirect
;
366 if( $this->mRedirectCode
== '301') {
367 if( !$wgDebugRedirects ) {
368 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
370 $this->mLastModified
= gmdate( 'D, j M Y H:i:s' ) . ' GMT';
373 $this->sendCacheControl();
375 if( $wgDebugRedirects ) {
376 $url = htmlspecialchars( $this->mRedirect
);
377 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
378 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
379 print "</body>\n</html>\n";
381 header( 'Location: '.$this->mRedirect
);
383 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
388 $this->sendCacheControl();
389 # Perform link colouring
390 $this->transformBuffer();
391 $this->replaceLinkHolders( $this->mSubtitle
);
393 # Disable temporary placeholders, so that the skin produces HTML
394 $sk->postParseLinkColour( false );
396 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
397 header( 'Content-language: '.$wgLanguageCode );
399 $exp = time() +
$wgCookieExpiration;
400 foreach( $this->mCookies
as $name => $val ) {
401 setcookie( $name, $val, $exp, '/' );
404 $sk->outputPage( $this );
408 function out( $ins ) {
409 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
410 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
413 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
414 if ( false === $outs ) { $outs = $ins; }
419 function setEncodings() {
420 global $wgInputEncoding, $wgOutputEncoding;
421 global $wgUser, $wgLang;
423 $wgInputEncoding = strtolower( $wgInputEncoding );
425 if( $wgUser->getOption( 'altencoding' ) ) {
426 $wgLang->setAltEncoding();
430 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
431 $wgOutputEncoding = strtolower( $wgOutputEncoding );
436 # This code is unused anyway!
437 # Commenting out. --bv 2003-11-15
439 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
443 foreach ( $a as $s ) {
444 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
456 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
457 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
458 $wgOutputEncoding = strtolower( $bestset );
463 $wgOutputEncoding = $wgInputEncoding;
467 * Returns a HTML comment with the elapsed time since request.
468 * This method has no side effects.
470 function reportTime() {
471 global $wgRequestTime;
474 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
475 $start = (float)$sec +
(float)$usec;
476 $elapsed = $now - $start;
478 # Use real server name if available, so we know which machine
479 # in a server farm generated the current page.
480 if ( function_exists( 'posix_uname' ) ) {
481 $uname = @posix_uname
();
485 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
486 $hostname = $uname['nodename'];
488 # This may be a virtual server.
489 $hostname = $_SERVER['SERVER_NAME'];
491 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
492 $hostname, $elapsed );
497 * Note: these arguments are keys into wfMsg(), not text!
499 function errorpage( $title, $msg ) {
502 $this->mDebugtext
.= 'Original title: ' .
503 $wgTitle->getPrefixedText() . "\n";
504 $this->setPageTitle( wfMsg( $title ) );
505 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
506 $this->setRobotpolicy( 'noindex,nofollow' );
507 $this->setArticleRelated( false );
508 $this->enableClientCache( false );
509 $this->mRedirect
= '';
511 $this->mBodytext
= '';
512 $this->addHTML( '<p>' . wfMsg( $msg ) . "</p>\n" );
513 $this->returnToMain( false );
519 function sysopRequired() {
522 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
523 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
524 $this->setRobotpolicy( 'noindex,nofollow' );
525 $this->setArticleRelated( false );
526 $this->mBodytext
= '';
528 $sk = $wgUser->getSkin();
529 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
530 $this->addHTML( wfMsg( 'sysoptext', $ap ) );
531 $this->returnToMain();
534 function developerRequired() {
537 $this->setPageTitle( wfMsg( 'developertitle' ) );
538 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
539 $this->setRobotpolicy( 'noindex,nofollow' );
540 $this->setArticleRelated( false );
541 $this->mBodytext
= '';
543 $sk = $wgUser->getSkin();
544 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
545 $this->addHTML( wfMsg( 'developertext', $ap ) );
546 $this->returnToMain();
549 function loginToUse() {
550 global $wgUser, $wgTitle, $wgLang;
552 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
553 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
554 $this->setRobotpolicy( 'noindex,nofollow' );
555 $this->setArticleFlag( false );
556 $this->mBodytext
= '';
557 $this->addWikiText( wfMsg( 'loginreqtext' ) );
559 # We put a comment in the .html file so a Sysop can diagnose the page the
561 $this->addHTML( "\n<!--" .
562 $wgLang->getNsText( $wgTitle->getNamespace() ) .
564 $wgTitle->getDBkey() . '-->' );
565 $this->returnToMain(); # Flip back to the main page after 10 seconds.
568 function databaseError( $fname, $sql, $error, $errno ) {
569 global $wgUser, $wgCommandLineMode;
571 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
572 $this->setRobotpolicy( 'noindex,nofollow' );
573 $this->setArticleRelated( false );
574 $this->enableClientCache( false );
575 $this->mRedirect
= '';
577 if ( $wgCommandLineMode ) {
578 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
579 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
581 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
582 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
585 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
589 $this->mBodytext
= $msg;
594 function readOnlyPage( $source = null, $protected = false ) {
595 global $wgUser, $wgReadOnlyFile;
597 $this->setRobotpolicy( 'noindex,nofollow' );
598 $this->setArticleRelated( false );
601 $this->setPageTitle( wfMsg( 'viewsource' ) );
602 $this->addWikiText( wfMsg( 'protectedtext' ) );
604 $this->setPageTitle( wfMsg( 'readonly' ) );
605 $reason = file_get_contents( $wgReadOnlyFile );
606 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
609 if( is_string( $source ) ) {
610 if( strcmp( $source, '' ) == 0 ) {
611 $source = wfMsg( 'noarticletext' );
613 $rows = $wgUser->getOption( 'rows' );
614 $cols = $wgUser->getOption( 'cols' );
615 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
616 htmlspecialchars( $source ) . "\n</textarea>";
617 $this->addHTML( $text );
620 $this->returnToMain( false );
623 function fatalError( $message ) {
624 $this->setPageTitle( wfMsg( "internalerror" ) );
625 $this->setRobotpolicy( "noindex,nofollow" );
626 $this->setArticleRelated( false );
627 $this->enableClientCache( false );
628 $this->mRedirect
= '';
630 $this->mBodytext
= $message;
635 function unexpectedValueError( $name, $val ) {
636 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
639 function fileCopyError( $old, $new ) {
640 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
643 function fileRenameError( $old, $new ) {
644 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
647 function fileDeleteError( $name ) {
648 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
651 function fileNotFoundError( $name ) {
652 $this->fatalError( wfMsg( 'filenotfound', $name ) );
656 * return from error messages or notes
657 * @param $auto automatically redirect the user after 10 seconds
658 * @param $returnto page title to return to. Default is Main Page.
660 function returnToMain( $auto = true, $returnto = NULL ) {
661 global $wgUser, $wgOut, $wgRequest;
663 if ( $returnto == NULL ) {
664 $returnto = $wgRequest->getText( 'returnto' );
667 $sk = $wgUser->getSkin();
668 if ( '' == $returnto ) {
669 $returnto = wfMsg( 'mainpage' );
671 $link = $sk->makeKnownLink( $returnto, '' );
673 $r = wfMsg( 'returnto', $link );
675 $titleObj = Title
::newFromText( $returnto );
676 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
678 $wgOut->addHTML( "\n<p>$r</p>\n" );
682 * This function takes the existing and broken links for the page
683 * and uses the first 10 of them for META keywords
685 function addMetaTags () {
686 global $wgLinkCache , $wgOut ;
687 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
688 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
689 $a = array_merge ( $good , $bad ) ;
690 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
691 $a = implode ( ',' , $a ) ;
693 "/<.*?" . ">/" => '',
696 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
698 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
704 function headElement() {
705 global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
706 global $wgUser, $wgLang, $wgRequest;
708 $xml = ($wgMimeType == 'text/xml');
710 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
715 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
717 if ( "" == $this->mHTMLtitle
) {
718 $this->mHTMLtitle
= wfMsg( "pagetitle", $this->mPagetitle
);
721 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
725 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : '';
726 $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
727 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle
) . "</title>\n";
728 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
730 $ret .= $this->getHeadLinks();
732 if( $this->isPrintable() ) {
735 $media = "media='print'";
737 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
738 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
740 $sk = $wgUser->getSkin();
741 $ret .= $sk->getHeadScripts();
742 $ret .= $this->mScripts
;
743 $ret .= $sk->getUserStyles();
749 function getHeadLinks() {
750 global $wgRequest, $wgStylePath;
752 foreach ( $this->mMetatags
as $tag ) {
753 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
755 $tag[0] = substr( $tag[0], 5 );
759 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
761 $p = $this->mRobotpolicy
;
762 if ( '' == $p ) { $p = 'index,follow'; }
763 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
765 if ( count( $this->mKeywords
) > 0 ) {
767 "/<.*?" . ">/" => '',
770 $ret .= "<meta name=\"keywords\" content=\"" .
771 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
773 foreach ( $this->mLinktags
as $tag ) {
775 foreach( $tag as $attr => $val ) {
776 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
780 if( $this->isSyndicated() ) {
781 # FIXME: centralize the mime-type and name information in Feed.php
782 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
783 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
784 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
785 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
787 # FIXME: get these working
788 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
789 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
794 * Run any necessary pre-output transformations on the buffer text
796 function transformBuffer( $options = 0 ) {
797 $this->replaceLinkHolders( $this->mBodytext
, $options );
801 * Replace <!--LINK--> link placeholders with actual links, in the buffer
802 * Placeholders created in Skin::makeLinkObj()
803 * Returns an array of links found, indexed by PDBK:
807 * $options is a bit field, RLH_FOR_UPDATE to select for update
809 function replaceLinkHolders( &$text, $options = 0 ) {
810 global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck;
812 if ( $wgUseOldExistenceCheck ) {
816 $fname = 'OutputPage::replaceLinkHolders';
817 wfProfileIn( $fname );
823 # Get placeholders from body
824 wfProfileIn( $fname.'-match' );
825 preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $text, $tmpLinks );
826 wfProfileOut( $fname.'-match' );
828 if ( !empty( $tmpLinks[0] ) ) {
829 wfProfileIn( $fname.'-check' );
830 $dbr =& wfGetDB( DB_SLAVE
);
831 $cur = $dbr->tableName( 'cur' );
832 $sk = $wgUser->getSkin();
833 $threshold = $wgUser->getOption('stubthreshold');
835 $namespaces =& $tmpLinks[1];
836 $dbkeys =& $tmpLinks[2];
837 $queries =& $tmpLinks[3];
838 $texts =& $tmpLinks[4];
841 asort( $namespaces );
845 foreach ( $namespaces as $key => $val ) {
847 $dbk = $dbkeys[$key];
848 $title = $titles[$key] = Title
::makeTitleSafe( $val, $dbk );
850 # Skip invalid entries.
851 # Result will be ugly, but prevents crash.
852 if ( is_null( $title ) ) {
855 $pdbk = $pdbks[$key] = $title->getPrefixedDBkey();
857 # Check if it's in the link cache already
858 if ( $wgLinkCache->getGoodLinkID( $pdbk ) ) {
860 } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
863 # Not in the link cache, add it to the query
864 if ( !isset( $current ) ) {
866 $query = "SELECT cur_id, cur_namespace, cur_title";
867 if ( $threshold > 0 ) {
868 $query .= ", LENGTH(cur_text) AS cur_len, cur_is_redirect";
870 $query .= " FROM $cur WHERE (cur_namespace=$val AND cur_title IN(";
871 } elseif ( $current != $val ) {
873 $query .= ")) OR (cur_namespace=$val AND cur_title IN(";
878 $query .= $dbr->addQuotes( $dbkeys[$key] );
883 if ( $options & RLH_FOR_UPDATE
) {
884 $query .= ' FOR UPDATE';
887 $res = $dbr->query( $query, $fname );
889 # Fetch data and form into an associative array
890 # non-existent = broken
893 while ( $s = $dbr->fetchObject($res) ) {
894 $title = Title
::makeTitle( $s->cur_namespace
, $s->cur_title
);
895 $pdbk = $title->getPrefixedDBkey();
896 $wgLinkCache->addGoodLink( $s->cur_id
, $pdbk );
898 if ( $threshold > 0 ) {
900 if ( $s->cur_is_redirect ||
$s->cur_namespace
!= 0 ||
$length < $threshold ) {
910 wfProfileOut( $fname.'-check' );
912 # Construct search and replace arrays
913 wfProfileIn( $fname.'-construct' );
914 global $outputReplace;
915 $outputReplace = array();
916 foreach ( $namespaces as $key => $ns ) {
917 $pdbk = $pdbks[$key];
918 $searchkey = $tmpLinks[0][$key];
919 $title = $titles[$key];
920 if ( empty( $colours[$pdbk] ) ) {
921 $wgLinkCache->addBadLink( $pdbk );
923 $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title, $texts[$key], $queries[$key] );
924 } elseif ( $colours[$pdbk] == 1 ) {
925 $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title, $texts[$key], $queries[$key] );
926 } elseif ( $colours[$pdbk] == 2 ) {
927 $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title, $texts[$key], $queries[$key] );
930 wfProfileOut( $fname.'-construct' );
933 wfProfileIn( $fname.'-replace' );
935 $text = preg_replace_callback(
936 '/(<!--LINK .*? .*? .*? .*?-->)/',
937 "outputReplaceMatches",
939 wfProfileOut( $fname.'-replace' );
941 wfProfileOut( $fname );
946 function &outputReplaceMatches($matches) {
947 global $outputReplace;
948 return $outputReplace[$matches[1]];