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();
390 $this->replaceLinkHolders( $this->mSubtitle
);
392 # Disable temporary placeholders, so that the skin produces HTML
393 $sk->postParseLinkColour( false );
395 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
396 header( 'Content-language: '.$wgLanguageCode );
398 $exp = time() +
$wgCookieExpiration;
399 foreach( $this->mCookies
as $name => $val ) {
400 setcookie( $name, $val, $exp, '/' );
403 $sk->outputPage( $this );
407 function out( $ins ) {
408 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
409 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
412 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
413 if ( false === $outs ) { $outs = $ins; }
418 function setEncodings() {
419 global $wgInputEncoding, $wgOutputEncoding;
420 global $wgUser, $wgLang;
422 $wgInputEncoding = strtolower( $wgInputEncoding );
424 if( $wgUser->getOption( 'altencoding' ) ) {
425 $wgLang->setAltEncoding();
429 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
430 $wgOutputEncoding = strtolower( $wgOutputEncoding );
435 # This code is unused anyway!
436 # Commenting out. --bv 2003-11-15
438 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
442 foreach ( $a as $s ) {
443 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
455 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
456 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
457 $wgOutputEncoding = strtolower( $bestset );
462 $wgOutputEncoding = $wgInputEncoding;
466 * Returns a HTML comment with the elapsed time since request.
467 * This method has no side effects.
469 function reportTime() {
470 global $wgRequestTime;
473 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
474 $start = (float)$sec +
(float)$usec;
475 $elapsed = $now - $start;
477 # Use real server name if available, so we know which machine
478 # in a server farm generated the current page.
479 if ( function_exists( 'posix_uname' ) ) {
480 $uname = @posix_uname
();
484 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
485 $hostname = $uname['nodename'];
487 # This may be a virtual server.
488 $hostname = $_SERVER['SERVER_NAME'];
490 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
491 $hostname, $elapsed );
496 * Note: these arguments are keys into wfMsg(), not text!
498 function errorpage( $title, $msg ) {
501 $this->mDebugtext
.= 'Original title: ' .
502 $wgTitle->getPrefixedText() . "\n";
503 $this->setPageTitle( wfMsg( $title ) );
504 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
505 $this->setRobotpolicy( 'noindex,nofollow' );
506 $this->setArticleRelated( false );
507 $this->enableClientCache( false );
508 $this->mRedirect
= '';
510 $this->mBodytext
= '';
511 $this->addHTML( '<p>' . wfMsg( $msg ) . "</p>\n" );
512 $this->returnToMain( false );
518 function sysopRequired() {
521 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
522 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
523 $this->setRobotpolicy( 'noindex,nofollow' );
524 $this->setArticleRelated( false );
525 $this->mBodytext
= '';
527 $sk = $wgUser->getSkin();
528 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
529 $this->addHTML( wfMsg( 'sysoptext', $ap ) );
530 $this->returnToMain();
533 function developerRequired() {
536 $this->setPageTitle( wfMsg( 'developertitle' ) );
537 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
538 $this->setRobotpolicy( 'noindex,nofollow' );
539 $this->setArticleRelated( false );
540 $this->mBodytext
= '';
542 $sk = $wgUser->getSkin();
543 $ap = $sk->makeKnownLink( wfMsg( 'administrators' ), '' );
544 $this->addHTML( wfMsg( 'developertext', $ap ) );
545 $this->returnToMain();
548 function loginToUse() {
549 global $wgUser, $wgTitle, $wgLang;
551 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
552 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
553 $this->setRobotpolicy( 'noindex,nofollow' );
554 $this->setArticleFlag( false );
555 $this->mBodytext
= '';
556 $this->addWikiText( wfMsg( 'loginreqtext' ) );
558 # We put a comment in the .html file so a Sysop can diagnose the page the
560 $this->addHTML( "\n<!--" .
561 $wgLang->getNsText( $wgTitle->getNamespace() ) .
563 $wgTitle->getDBkey() . '-->' );
564 $this->returnToMain(); # Flip back to the main page after 10 seconds.
567 function databaseError( $fname, $sql, $error, $errno ) {
568 global $wgUser, $wgCommandLineMode;
570 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
571 $this->setRobotpolicy( 'noindex,nofollow' );
572 $this->setArticleRelated( false );
573 $this->enableClientCache( false );
574 $this->mRedirect
= '';
576 if ( $wgCommandLineMode ) {
577 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
578 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
580 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
581 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
584 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
588 $this->mBodytext
= $msg;
593 function readOnlyPage( $source = null, $protected = false ) {
594 global $wgUser, $wgReadOnlyFile;
596 $this->setRobotpolicy( 'noindex,nofollow' );
597 $this->setArticleRelated( false );
600 $this->setPageTitle( wfMsg( 'viewsource' ) );
601 $this->addWikiText( wfMsg( 'protectedtext' ) );
603 $this->setPageTitle( wfMsg( 'readonly' ) );
604 $reason = file_get_contents( $wgReadOnlyFile );
605 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
608 if( is_string( $source ) ) {
609 if( strcmp( $source, '' ) == 0 ) {
610 $source = wfMsg( 'noarticletext' );
612 $rows = $wgUser->getOption( 'rows' );
613 $cols = $wgUser->getOption( 'cols' );
614 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
615 htmlspecialchars( $source ) . "\n</textarea>";
616 $this->addHTML( $text );
619 $this->returnToMain( false );
622 function fatalError( $message ) {
623 $this->setPageTitle( wfMsg( "internalerror" ) );
624 $this->setRobotpolicy( "noindex,nofollow" );
625 $this->setArticleRelated( false );
626 $this->enableClientCache( false );
627 $this->mRedirect
= '';
629 $this->mBodytext
= $message;
634 function unexpectedValueError( $name, $val ) {
635 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
638 function fileCopyError( $old, $new ) {
639 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
642 function fileRenameError( $old, $new ) {
643 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
646 function fileDeleteError( $name ) {
647 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
650 function fileNotFoundError( $name ) {
651 $this->fatalError( wfMsg( 'filenotfound', $name ) );
655 * return from error messages or notes
656 * @param $auto automatically redirect the user after 10 seconds
657 * @param $returnto page title to return to. Default is Main Page.
659 function returnToMain( $auto = true, $returnto = NULL ) {
660 global $wgUser, $wgOut, $wgRequest;
662 if ( $returnto == NULL ) {
663 $returnto = $wgRequest->getText( 'returnto' );
666 $sk = $wgUser->getSkin();
667 if ( '' == $returnto ) {
668 $returnto = wfMsg( 'mainpage' );
670 $link = $sk->makeKnownLink( $returnto, '' );
672 $r = wfMsg( 'returnto', $link );
674 $titleObj = Title
::newFromText( $returnto );
675 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
677 $wgOut->addHTML( "\n<p>$r</p>\n" );
681 * This function takes the existing and broken links for the page
682 * and uses the first 10 of them for META keywords
684 function addMetaTags () {
685 global $wgLinkCache , $wgOut ;
686 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
687 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
688 $a = array_merge ( $good , $bad ) ;
689 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
690 $a = implode ( ',' , $a ) ;
692 "/<.*?" . ">/" => '',
695 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
697 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
703 function headElement() {
704 global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
705 global $wgUser, $wgLang, $wgRequest;
707 $xml = ($wgMimeType == 'text/xml');
709 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
714 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
716 if ( "" == $this->mHTMLtitle
) {
717 $this->mHTMLtitle
= wfMsg( "pagetitle", $this->mPagetitle
);
720 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
724 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : '';
725 $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
726 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle
) . "</title>\n";
727 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
729 $ret .= $this->getHeadLinks();
731 if( $this->isPrintable() ) {
734 $media = "media='print'";
736 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
737 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
739 $sk = $wgUser->getSkin();
740 $ret .= $sk->getHeadScripts();
741 $ret .= $this->mScripts
;
742 $ret .= $sk->getUserStyles();
748 function getHeadLinks() {
749 global $wgRequest, $wgStylePath;
751 foreach ( $this->mMetatags
as $tag ) {
752 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
754 $tag[0] = substr( $tag[0], 5 );
758 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
760 $p = $this->mRobotpolicy
;
761 if ( '' == $p ) { $p = 'index,follow'; }
762 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
764 if ( count( $this->mKeywords
) > 0 ) {
766 "/<.*?" . ">/" => '',
769 $ret .= "<meta name=\"keywords\" content=\"" .
770 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
772 foreach ( $this->mLinktags
as $tag ) {
774 foreach( $tag as $attr => $val ) {
775 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
779 if( $this->isSyndicated() ) {
780 # FIXME: centralize the mime-type and name information in Feed.php
781 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
782 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
783 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
784 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
786 # FIXME: get these working
787 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
788 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
793 * Run any necessary pre-output transformations on the buffer text
795 function transformBuffer( $options = 0 ) {
796 $this->replaceLinkHolders( $this->mBodytext
, $options );
800 * Replace <!--LINK--> link placeholders with actual links, in the buffer
801 * Placeholders created in Skin::makeLinkObj()
802 * Returns an array of links found, indexed by PDBK:
806 * $options is a bit field, RLH_FOR_UPDATE to select for update
808 function replaceLinkHolders( &$text, $options = 0 ) {
809 global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck;
811 if ( $wgUseOldExistenceCheck ) {
815 $fname = 'OutputPage::replaceLinkHolders';
816 wfProfileIn( $fname );
822 # Get placeholders from body
823 wfProfileIn( $fname.'-match' );
824 preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $text, $tmpLinks );
825 wfProfileOut( $fname.'-match' );
827 if ( !empty( $tmpLinks[0] ) ) {
828 wfProfileIn( $fname.'-check' );
829 $dbr =& wfGetDB( DB_SLAVE
);
830 $cur = $dbr->tableName( 'cur' );
831 $sk = $wgUser->getSkin();
832 $threshold = $wgUser->getOption('stubthreshold');
834 $namespaces =& $tmpLinks[1];
835 $dbkeys =& $tmpLinks[2];
836 $queries =& $tmpLinks[3];
837 $texts =& $tmpLinks[4];
840 asort( $namespaces );
844 foreach ( $namespaces as $key => $val ) {
846 $dbk = $dbkeys[$key];
847 $title = $titles[$key] = Title
::makeTitleSafe( $val, $dbk );
849 # Skip invalid entries.
850 # Result will be ugly, but prevents crash.
851 if ( is_null( $title ) ) {
854 $pdbk = $pdbks[$key] = $title->getPrefixedDBkey();
856 # Check if it's in the link cache already
857 if ( $wgLinkCache->getGoodLinkID( $pdbk ) ) {
859 } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
862 # Not in the link cache, add it to the query
863 if ( !isset( $current ) ) {
865 $query = "SELECT cur_id, cur_namespace, cur_title";
866 if ( $threshold > 0 ) {
867 $query .= ", LENGTH(cur_text) AS cur_len, cur_is_redirect";
869 $query .= " FROM $cur WHERE (cur_namespace=$val AND cur_title IN(";
870 } elseif ( $current != $val ) {
872 $query .= ")) OR (cur_namespace=$val AND cur_title IN(";
877 $query .= $dbr->addQuotes( $dbkeys[$key] );
882 if ( $options & RLH_FOR_UPDATE
) {
883 $query .= ' FOR UPDATE';
886 $res = $dbr->query( $query, $fname );
888 # Fetch data and form into an associative array
889 # non-existent = broken
892 while ( $s = $dbr->fetchObject($res) ) {
893 $title = Title
::makeTitle( $s->cur_namespace
, $s->cur_title
);
894 $pdbk = $title->getPrefixedDBkey();
895 $wgLinkCache->addGoodLink( $s->cur_id
, $pdbk );
897 if ( $threshold > 0 ) {
899 if ( $s->cur_is_redirect ||
$s->cur_namespace
!= 0 ||
$length < $threshold ) {
909 wfProfileOut( $fname.'-check' );
911 # Construct search and replace arrays
912 wfProfileIn( $fname.'-construct' );
913 global $outputReplace;
914 $outputReplace = array();
915 foreach ( $namespaces as $key => $ns ) {
916 $pdbk = $pdbks[$key];
917 $searchkey = $tmpLinks[0][$key];
918 $title = $titles[$key];
919 if ( empty( $colours[$pdbk] ) ) {
920 $wgLinkCache->addBadLink( $pdbk );
922 $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title, $texts[$key], $queries[$key] );
923 } elseif ( $colours[$pdbk] == 1 ) {
924 $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title, $texts[$key], $queries[$key] );
925 } elseif ( $colours[$pdbk] == 2 ) {
926 $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title, $texts[$key], $queries[$key] );
929 wfProfileOut( $fname.'-construct' );
932 wfProfileIn( $fname.'-replace' );
934 $text = preg_replace_callback(
935 '/(<!--LINK .*? .*? .*? .*?-->)/',
936 "outputReplaceMatches",
938 wfProfileOut( $fname.'-replace' );
940 wfProfileOut( $fname );
945 function &outputReplaceMatches($matches) {
946 global $outputReplace;
947 return $outputReplace[$matches[1]];