7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 if( defined( 'MEDIAWIKI' ) ) {
13 if($wgUseTeX) require_once( 'Math.php' );
15 define( 'RLH_FOR_UPDATE', 1 );
21 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
22 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
23 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
24 var $mSubtitle, $mRedirect;
25 var $mLastModified, $mCategoryLinks;
26 var $mScripts, $mLinkColours;
28 var $mSuppressQuickbar;
31 var $mContainsOldMagic, $mContainsNewMagic;
32 var $mIsArticleRelated;
34 var $mShowFeedLinks = false;
35 var $mEnableClientCache = true;
39 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
40 $this->mKeywords
= $this->mLinktags
= array();
41 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
42 $this->mRedirect
= $this->mLastModified
=
43 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
44 $this->mOnloadHandler
= "";
45 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
46 $this->mSuppressQuickbar
= $this->mPrintable
= false;
47 $this->mLanguageLinks
= array();
48 $this->mCategoryLinks
= array() ;
49 $this->mDoNothing
= false;
50 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
51 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
52 $this->mSquidMaxage
= 0;
56 function addHeader( $name, $val ) { array_push( $this->mHeaders
, "$name: $val" ) ; }
57 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
58 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
60 # To add an http-equiv meta tag, precede the name with "http:"
61 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
62 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
63 function addScript( $script ) { $this->mScripts
.= $script; }
64 function getScript() { return $this->mScripts
; }
66 function addLink( $linkarr ) {
67 # $linkarr should be an associative array of attributes. We'll escape on output.
68 array_push( $this->mLinktags
, $linkarr );
71 function addMetadataLink( $linkarr ) {
72 # note: buggy CC software only reads first "meta" link
73 static $haveMeta = false;
74 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
75 $this->addLink( $linkarr );
80 * checkLastModified tells the client to use the client-cached page if
81 * possible. If sucessful, the OutputPage is disabled so that
82 * any future call to OutputPage->output() have no effect. The method
83 * returns true iff cache-ok headers was sent.
85 function checkLastModified ( $timestamp )
87 global $wgLang, $wgCachePages, $wgUser;
88 if( !$wgCachePages ) {
89 wfDebug( "CACHE DISABLED\n", false );
92 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
93 # IE 5.0 has probs with our caching
94 wfDebug( "-- bad client, not caching\n", false );
97 if( $wgUser->getOption( 'nocache' ) ) {
98 wfDebug( "USER DISABLED CACHE\n", false );
102 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
104 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
105 # IE sends sizes after the date like this:
106 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
107 # this breaks strtotime().
108 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
109 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
110 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
111 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
113 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
114 # Make sure you're in a place you can leave when you call us!
115 header( "HTTP/1.0 304 Not Modified" );
116 $this->mLastModified
= $lastmod;
117 $this->sendCacheControl();
118 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
122 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
123 $this->mLastModified
= $lastmod;
126 wfDebug( "We're confused.\n", false );
127 $this->mLastModified
= $lastmod;
131 function getPageTitleActionText () {
135 return wfMsg('edit');
137 return wfMsg('history_short');
139 return wfMsg('protect');
141 return wfMsg('unprotect');
143 return wfMsg('delete');
145 return wfMsg('watch');
147 return wfMsg('unwatch');
149 return wfMsg('preview');
151 return wfMsg('info_short');
156 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
157 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
158 function setPageTitle( $name ) {
160 $this->mPagetitle
= $name;
161 if(!empty($action)) {
162 $taction = $this->getPageTitleActionText();
163 if( !empty( $taction ) ) {
164 $name .= ' - '.$taction;
167 $this->setHTMLTitle( $name . ' - ' . wfMsg( 'wikititlesuffix' ) );
169 function getHTMLTitle() { return $this->mHTMLtitle
; }
170 function getPageTitle() { return $this->mPagetitle
; }
171 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
172 function getSubtitle() { return $this->mSubtitle
; }
173 function isArticle() { return $this->mIsarticle
; }
174 function setPrintable() { $this->mPrintable
= true; }
175 function isPrintable() { return $this->mPrintable
; }
176 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
177 function isSyndicated() { return $this->mShowFeedLinks
; }
178 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
179 function getOnloadHandler() { return $this->mOnloadHandler
; }
180 function disable() { $this->mDoNothing
= true; }
182 function setArticleRelated( $v )
184 $this->mIsArticleRelated
= $v;
186 $this->mIsarticle
= false;
189 function setArticleFlag( $v ) {
190 $this->mIsarticle
= $v;
192 $this->mIsArticleRelated
= $v;
196 function isArticleRelated()
198 return $this->mIsArticleRelated
;
201 function getLanguageLinks() {
202 return $this->mLanguageLinks
;
204 function addLanguageLinks($newLinkArray) {
205 $this->mLanguageLinks +
= $newLinkArray;
207 function setLanguageLinks($newLinkArray) {
208 $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 debug( $text ) { $this->mDebugtext
.= $text; }
226 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 )
236 global $wgParser, $wgTitle;
238 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
239 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
240 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
241 $this->addHTML( $parserOutput->getText() );
245 * Add wikitext to the buffer, assuming that this is the primary text for a page view
246 * Saves the text into the parser cache if possible
248 function addPrimaryWikiText( $text, $cacheArticle ) {
249 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
251 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, true );
253 # Replace link holders
254 $text = $parserOutput->getText();
255 $this->replaceLinkHolders( $text );
256 $parserOutput->setText( $text );
258 if ( $cacheArticle ) {
259 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
262 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
263 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
264 $this->addHTML( $text );
267 function tryParserCache( $article, $user ) {
268 global $wgParserCache;
269 $parserOutput = $wgParserCache->get( $article, $user );
270 if ( $parserOutput !== false ) {
271 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
272 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
273 $this->addHTML( $parserOutput->getText() );
281 * Set the maximum cache time on the Squid in seconds
283 function setSquidMaxage( $maxage ) {
284 $this->mSquidMaxage
= $maxage;
288 * Use enableClientCache(false) to force it to send nocache headers
290 function enableClientCache( $state ) {
291 return wfSetVar( $this->mEnableClientCache
, $state );
294 function sendCacheControl() {
295 global $wgUseSquid, $wgUseESI;
296 # FIXME: This header may cause trouble with some versions of Internet Explorer
297 header( 'Vary: Accept-Encoding, Cookie' );
298 if( $this->mEnableClientCache
) {
299 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
300 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
303 # We'll purge the proxy cache explicitly, but require end user agents
304 # to revalidate against the proxy on each visit.
305 # Surrogate-Control controls our Squid, Cache-Control downstream caches
306 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
307 # start with a shorter timeout for initial testing
308 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
309 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
310 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
312 # We'll purge the proxy cache for anons explicitly, but require end user agents
313 # to revalidate against the proxy on each visit.
314 # IMPORTANT! The Squid needs to replace the Cache-Control header with
315 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
316 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
317 # start with a shorter timeout for initial testing
318 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
319 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
322 # We do want clients to cache if they can, but they *must* check for updates
323 # on revisiting the page.
324 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
325 header( "Expires: -1" );
326 header( "Cache-Control: private, must-revalidate, max-age=0" );
328 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
330 wfDebug( "** no caching **\n", false );
332 # In general, the absence of a last modified header should be enough to prevent
333 # the client from using its cache. We send a few other things just to make sure.
334 header( 'Expires: -1' );
335 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
336 header( 'Pragma: no-cache' );
341 * Finally, all the text has been munged and accumulated into
342 * the object, let's actually output it:
346 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
347 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
348 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
349 if( $this->mDoNothing
){
352 $fname = 'OutputPage::output';
353 wfProfileIn( $fname );
355 $sk = $wgUser->getSkin();
357 if ( '' != $this->mRedirect
) {
358 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
359 # Standards require redirect URLs to be absolute
361 $this->mRedirect
= $wgServer . $this->mRedirect
;
363 if( $this->mRedirectCode
== '301') {
364 if( !$wgDebugRedirects ) {
365 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
367 $this->mLastModified
= gmdate( 'D, j M Y H:i:s' ) . ' GMT';
370 $this->sendCacheControl();
372 if( $wgDebugRedirects ) {
373 $url = htmlspecialchars( $this->mRedirect
);
374 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
375 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
376 print "</body>\n</html>\n";
378 header( 'Location: '.$this->mRedirect
);
380 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
385 $this->sendCacheControl();
386 # Perform link colouring
387 $this->transformBuffer();
389 # Disable temporary placeholders, so that the skin produces HTML
390 $sk->postParseLinkColour( false );
392 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
393 header( 'Content-language: '.$wgLanguageCode );
395 $exp = time() +
$wgCookieExpiration;
396 foreach( $this->mCookies
as $name => $val ) {
397 setcookie( $name, $val, $exp, '/' );
400 $sk->outputPage( $this );
404 function out( $ins ) {
405 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
406 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
409 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
410 if ( false === $outs ) { $outs = $ins; }
415 function setEncodings() {
416 global $wgInputEncoding, $wgOutputEncoding;
417 global $wgUser, $wgLang;
419 $wgInputEncoding = strtolower( $wgInputEncoding );
421 if( $wgUser->getOption( 'altencoding' ) ) {
422 $wgLang->setAltEncoding();
426 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
427 $wgOutputEncoding = strtolower( $wgOutputEncoding );
432 # This code is unused anyway!
433 # Commenting out. --bv 2003-11-15
435 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
439 foreach ( $a as $s ) {
440 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
452 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
453 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
454 $wgOutputEncoding = strtolower( $bestset );
459 $wgOutputEncoding = $wgInputEncoding;
463 * Returns a HTML comment with the elapsed time since request.
464 * This method has no side effects.
466 function reportTime() {
467 global $wgRequestTime;
470 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
471 $start = (float)$sec +
(float)$usec;
472 $elapsed = $now - $start;
474 # Use real server name if available, so we know which machine
475 # in a server farm generated the current page.
476 if ( function_exists( 'posix_uname' ) ) {
477 $uname = @posix_uname
();
481 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
482 $hostname = $uname['nodename'];
484 # This may be a virtual server.
485 $hostname = $_SERVER['SERVER_NAME'];
487 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
488 $hostname, $elapsed );
493 * Note: these arguments are keys into wfMsg(), not text!
495 function errorpage( $title, $msg ) {
498 $this->mDebugtext
.= 'Original title: ' .
499 $wgTitle->getPrefixedText() . "\n";
500 $this->setPageTitle( wfMsg( $title ) );
501 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
502 $this->setRobotpolicy( 'noindex,nofollow' );
503 $this->setArticleRelated( false );
504 $this->enableClientCache( false );
505 $this->mRedirect
= '';
507 $this->mBodytext
= '';
508 $this->addHTML( '<p>' . wfMsg( $msg ) . "</p>\n" );
509 $this->returnToMain( false );
515 function sysopRequired() {
518 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
519 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
520 $this->setRobotpolicy( 'noindex,nofollow' );
521 $this->setArticleRelated( false );
522 $this->mBodytext
= '';
524 $sk = $wgUser->getSkin();
525 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
526 $this->addHTML( wfMsg( 'sysoptext', $ap ) );
527 $this->returnToMain();
530 function developerRequired() {
533 $this->setPageTitle( wfMsg( 'developertitle' ) );
534 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
535 $this->setRobotpolicy( 'noindex,nofollow' );
536 $this->setArticleRelated( false );
537 $this->mBodytext
= '';
539 $sk = $wgUser->getSkin();
540 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
541 $this->addHTML( wfMsg( 'developertext', $ap ) );
542 $this->returnToMain();
545 function loginToUse() {
546 global $wgUser, $wgTitle, $wgLang;
548 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
549 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
550 $this->setRobotpolicy( 'noindex,nofollow' );
551 $this->setArticleFlag( false );
552 $this->mBodytext
= '';
553 $this->addWikiText( wfMsg( 'loginreqtext' ) );
555 # We put a comment in the .html file so a Sysop can diagnose the page the
557 $this->addHTML( "\n<!--" .
558 $wgLang->getNsText( $wgTitle->getNamespace() ) .
560 $wgTitle->getDBkey() . '-->' );
561 $this->returnToMain(); # Flip back to the main page after 10 seconds.
564 function databaseError( $fname, $sql, $error, $errno ) {
565 global $wgUser, $wgCommandLineMode;
567 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
568 $this->setRobotpolicy( 'noindex,nofollow' );
569 $this->setArticleRelated( false );
570 $this->enableClientCache( false );
571 $this->mRedirect
= '';
573 if ( $wgCommandLineMode ) {
574 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
575 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
577 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
578 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
581 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
585 $this->mBodytext
= $msg;
590 function readOnlyPage( $source = null, $protected = false ) {
591 global $wgUser, $wgReadOnlyFile;
593 $this->setRobotpolicy( 'noindex,nofollow' );
594 $this->setArticleRelated( false );
597 $this->setPageTitle( wfMsg( 'viewsource' ) );
598 $this->addWikiText( wfMsg( 'protectedtext' ) );
600 $this->setPageTitle( wfMsg( 'readonly' ) );
601 $reason = file_get_contents( $wgReadOnlyFile );
602 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
605 if( is_string( $source ) ) {
606 if( strcmp( $source, '' ) == 0 ) {
607 $source = wfMsg( 'noarticletext' );
609 $rows = $wgUser->getOption( 'rows' );
610 $cols = $wgUser->getOption( 'cols' );
611 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
612 htmlspecialchars( $source ) . "\n</textarea>";
613 $this->addHTML( $text );
616 $this->returnToMain( false );
619 function fatalError( $message ) {
620 $this->setPageTitle( wfMsg( "internalerror" ) );
621 $this->setRobotpolicy( "noindex,nofollow" );
622 $this->setArticleRelated( false );
623 $this->enableClientCache( false );
624 $this->mRedirect
= '';
626 $this->mBodytext
= $message;
631 function unexpectedValueError( $name, $val ) {
632 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
635 function fileCopyError( $old, $new ) {
636 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
639 function fileRenameError( $old, $new ) {
640 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
643 function fileDeleteError( $name ) {
644 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
647 function fileNotFoundError( $name ) {
648 $this->fatalError( wfMsg( 'filenotfound', $name ) );
652 * return from error messages or notes
653 * @param $auto automatically redirect the user after 10 seconds
654 * @param $returnto page title to return to. Default is Main Page.
656 function returnToMain( $auto = true, $returnto = NULL ) {
657 global $wgUser, $wgOut, $wgRequest;
659 if ( $returnto == NULL ) {
660 $returnto = $wgRequest->getText( 'returnto' );
663 $sk = $wgUser->getSkin();
664 if ( '' == $returnto ) {
665 $returnto = wfMsg( 'mainpage' );
667 $link = $sk->makeKnownLink( $returnto, '' );
669 $r = wfMsg( 'returnto', $link );
671 $titleObj = Title
::newFromText( $returnto );
672 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
674 $wgOut->addHTML( "\n<p>$r</p>\n" );
678 * This function takes the existing and broken links for the page
679 * and uses the first 10 of them for META keywords
681 function addMetaTags () {
682 global $wgLinkCache , $wgOut ;
683 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
684 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
685 $a = array_merge ( $good , $bad ) ;
686 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
687 $a = implode ( ',' , $a ) ;
689 "/<.*?" . ">/" => '',
692 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
694 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
700 function headElement() {
701 global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
702 global $wgUser, $wgLang, $wgRequest;
704 $xml = ($wgMimeType == 'text/xml');
706 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
711 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
713 if ( "" == $this->mHTMLtitle
) {
714 $this->mHTMLtitle
= wfMsg( "pagetitle", $this->mPagetitle
);
717 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
721 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : '';
722 $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
723 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle
) . "</title>\n";
724 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
726 $ret .= $this->getHeadLinks();
728 if( $this->isPrintable() ) {
731 $media = "media='print'";
733 $printsheet = htmlspecialchars( "$wgStylePath/wikiprintable.css" );
734 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
736 $sk = $wgUser->getSkin();
737 $ret .= $sk->getHeadScripts();
738 $ret .= $this->mScripts
;
739 $ret .= $sk->getUserStyles();
745 function getHeadLinks() {
746 global $wgRequest, $wgStylePath;
748 foreach ( $this->mMetatags
as $tag ) {
749 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
751 $tag[0] = substr( $tag[0], 5 );
755 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
757 $p = $this->mRobotpolicy
;
758 if ( '' == $p ) { $p = 'index,follow'; }
759 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
761 if ( count( $this->mKeywords
) > 0 ) {
763 "/<.*?" . ">/" => '',
766 $ret .= "<meta name=\"keywords\" content=\"" .
767 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
769 foreach ( $this->mLinktags
as $tag ) {
771 foreach( $tag as $attr => $val ) {
772 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
776 if( $this->isSyndicated() ) {
777 # FIXME: centralize the mime-type and name information in Feed.php
778 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
779 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
780 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
781 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
783 # FIXME: get these working
784 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
785 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
790 * Run any necessary pre-output transformations on the buffer text
792 function transformBuffer( $options = 0 ) {
793 $this->replaceLinkHolders( $this->mBodytext
, $options );
797 * Replace <!--LINK--> link placeholders with actual links, in the buffer
798 * Placeholders created in Skin::makeLinkObj()
799 * Returns an array of links found, indexed by PDBK:
803 * $options is a bit field, RLH_FOR_UPDATE to select for update
805 function replaceLinkHolders( &$text, $options = 0 ) {
806 global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck;
808 if ( $wgUseOldExistenceCheck ) {
812 $fname = 'OutputPage::replaceLinkHolders';
813 wfProfileIn( $fname );
819 # Get placeholders from body
820 wfProfileIn( $fname.'-match' );
821 preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $text, $tmpLinks );
822 wfProfileOut( $fname.'-match' );
824 if ( !empty( $tmpLinks[0] ) ) {
825 wfProfileIn( $fname.'-check' );
826 $dbr =& wfGetDB( DB_SLAVE
);
827 $cur = $dbr->tableName( 'cur' );
828 $sk = $wgUser->getSkin();
829 $threshold = $wgUser->getOption('stubthreshold');
831 $namespaces =& $tmpLinks[1];
832 $dbkeys =& $tmpLinks[2];
833 $queries =& $tmpLinks[3];
834 $texts =& $tmpLinks[4];
837 asort( $namespaces );
841 foreach ( $namespaces as $key => $val ) {
843 $dbk = $dbkeys[$key];
844 $title = $titles[$key] = Title
::makeTitleSafe( $val, $dbk );
846 # Skip invalid entries.
847 # Result will be ugly, but prevents crash.
848 if ( is_null( $title ) ) {
851 $pdbk = $pdbks[$key] = $title->getPrefixedDBkey();
853 # Check if it's in the link cache already
854 if ( $wgLinkCache->getGoodLinkID( $pdbk ) ) {
856 } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
859 # Not in the link cache, add it to the query
860 if ( !isset( $current ) ) {
862 $query = "SELECT cur_id, cur_namespace, cur_title";
863 if ( $threshold > 0 ) {
864 $query .= ", LENGTH(cur_text) AS cur_len, cur_is_redirect";
866 $query .= " FROM $cur WHERE (cur_namespace=$val AND cur_title IN(";
867 } elseif ( $current != $val ) {
869 $query .= ")) OR (cur_namespace=$val AND cur_title IN(";
874 $query .= $dbr->addQuotes( $dbkeys[$key] );
879 if ( $options & RLH_FOR_UPDATE
) {
880 $query .= ' FOR UPDATE';
883 $res = $dbr->query( $query, $fname );
885 # Fetch data and form into an associative array
886 # non-existent = broken
889 while ( $s = $dbr->fetchObject($res) ) {
890 $title = Title
::makeTitle( $s->cur_namespace
, $s->cur_title
);
891 $pdbk = $title->getPrefixedDBkey();
892 $wgLinkCache->addGoodLink( $s->cur_id
, $pdbk );
894 if ( $threshold > 0 ) {
896 if ( $s->cur_is_redirect ||
$s->cur_namespace
!= 0 ||
$length < $threshold ) {
906 wfProfileOut( $fname.'-check' );
908 # Construct search and replace arrays
909 wfProfileIn( $fname.'-construct' );
910 global $outputReplace;
911 $outputReplace = array();
912 foreach ( $namespaces as $key => $ns ) {
913 $pdbk = $pdbks[$key];
914 $searchkey = $tmpLinks[0][$key];
915 $title = $titles[$key];
916 if ( empty( $colours[$pdbk] ) ) {
917 $wgLinkCache->addBadLink( $pdbk );
919 $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title, $texts[$key], $queries[$key] );
920 } elseif ( $colours[$pdbk] == 1 ) {
921 $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title, $texts[$key], $queries[$key] );
922 } elseif ( $colours[$pdbk] == 2 ) {
923 $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title, $texts[$key], $queries[$key] );
926 wfProfileOut( $fname.'-construct' );
929 wfProfileIn( $fname.'-replace' );
931 $text = preg_replace_callback(
932 '/(<!--LINK .*? .*? .*? .*?-->)/',
933 "outputReplaceMatches",
935 wfProfileOut( $fname.'-replace' );
937 wfProfileOut( $fname );
942 function &outputReplaceMatches($matches) {
943 global $outputReplace;
944 return $outputReplace[$matches[1]];