4 if($wgUseTeX) include_once( "Math.php" );
7 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
8 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
9 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
10 var $mSubtitle, $mRedirect, $mAutonumber, $mHeadtext;
11 var $mLastModified, $mCategoryLinks;
13 var $mDTopen, $mLastSection; # Used for processing DL, PRE
14 var $mLanguageLinks, $mSupressQuickbar;
18 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
19 $this->mKeywords
= $this->mLinktags
= array();
20 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
21 $this->mLastSection
= $this->mRedirect
= $this->mLastModified
=
22 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
= "";
23 $this->mIsarticle
= $this->mPrintable
= true;
24 $this->mSupressQuickbar
= $this->mDTopen
= $this->mPrintable
= false;
25 $this->mLanguageLinks
= array();
26 $this->mCategoryLinks
= array() ;
27 $this->mAutonumber
= 0;
30 function addHeader( $name, $val ) { array_push( $this->mHeaders
, "$name: $val" ) ; }
31 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
32 function redirect( $url ) { $this->mRedirect
= $url; }
34 # To add an http-equiv meta tag, precede the name with "http:"
35 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
36 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
37 function addLink( $rel, $rev, $target ) { array_push( $this->mLinktags
, array( $rel, $rev, $target ) ); }
39 function checkLastModified ( $timestamp )
41 global $wgLang, $wgCachePages, $wgUser;
42 if( !$wgCachePages ) {
43 wfDebug( "CACHE DISABLED\n", false );
46 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
47 # IE 5.0 has probs with our caching
48 wfDebug( "-- bad client, not caching\n", false );
51 if( $wgUser->getOption( "nocache" ) ) {
52 wfDebug( "USER DISABLED CACHE\n", false );
56 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
57 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
59 if( $_SERVER["HTTP_IF_MODIFIED_SINCE"] != "" ) {
60 # IE sends sizes after the date for compressed pages:
61 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
62 # this breaks strtotime().
63 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
64 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
65 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
66 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
68 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
69 # Make sure you're in a place you can leave when you call us!
70 header( "HTTP/1.0 304 Not Modified" );
71 header( "Expires: Mon, 15 Jan 2001 00:00:00 GMT" ); # Cachers always validate the page!
72 header( "Cache-Control: private, must-revalidate, max-age=0" );
73 header( "Last-Modified: {$lastmod}" );
74 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
77 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
78 $this->mLastModified
= $lastmod;
81 wfDebug( "We're confused.\n", false );
82 $this->mLastModified
= $lastmod;
86 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
87 function setHTMLtitle( $name ) { $this->mHTMLtitle
= $name; }
88 function setPageTitle( $name ) { $this->mPagetitle
= $name; }
89 function getPageTitle() { return $this->mPagetitle
; }
90 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
91 function getSubtitle() { return $this->mSubtitle
; }
92 function setArticleFlag( $v ) { $this->mIsarticle
= $v; }
93 function isArticle() { return $this->mIsarticle
; }
94 function setPrintable() { $this->mPrintable
= true; }
95 function isPrintable() { return $this->mPrintable
; }
97 function getLanguageLinks() {
98 global $wgUseNewInterlanguage, $wgTitle, $wgLanguageCode;
99 global $wgDBconnection, $wgDBname, $wgDBintlname;
101 if ( ! $wgUseNewInterlanguage )
102 return $this->mLanguageLinks
;
104 mysql_select_db( $wgDBintlname, $wgDBconnection ) or die(
105 htmlspecialchars(mysql_error()) );
108 $sql = "SELECT * FROM ilinks WHERE lang_from=\"" .
109 "{$wgLanguageCode}\" AND title_from=\"" . $wgTitle->getDBkey() . "\"";
110 $res = mysql_query( $sql, $wgDBconnection );
112 while ( $q = mysql_fetch_object ( $res ) ) {
113 $list[] = $q->lang_to
. ":" . $q->title_to
;
115 mysql_free_result( $res );
116 mysql_select_db( $wgDBname, $wgDBconnection ) or die(
117 htmlspecialchars(mysql_error()) );
122 function supressQuickbar() { $this->mSupressQuickbar
= true; }
123 function isQuickbarSupressed() { return $this->mSupressQuickbar
; }
125 function addHTML( $text ) { $this->mBodytext
.= $text; }
126 function addHeadtext( $text ) { $this->mHeadtext
.= $text; }
127 function debug( $text ) { $this->mDebugtext
.= $text; }
129 # First pass--just handle <nowiki> sections, pass the rest off
130 # to doWikiPass2() which does all the real work.
133 function addWikiText( $text, $linestart = true )
136 wfProfileIn( "OutputPage::addWikiText" );
137 $unique = "3iyZiyA7iMwg5rhxP0Dcc9oTnj8qD1jm1Sfv4";
138 $unique2 = "4LIQ9nXtiYFPCSfitVwDw7EYwQlL4GeeQ7qSO";
139 $unique3 = "fPaA8gDfdLBqzj68Yjg9Hil3qEF8JGO0uszIp";
150 while ( "" != $text ) {
151 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
153 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) { $text = ""; }
155 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
157 $nwlist[$nwsecs] = wfEscapeHTMLTagsOnly($q[0]);
158 $stripped .= $unique;
164 while ( "" != $stripped ) {
165 $p = preg_split( "/<\\s*math\\s*>/i", $stripped, 2 );
167 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) { $stripped = ""; }
169 $q = preg_split( "/<\\/\\s*math\\s*>/i", $p[1], 2 );
171 $mathlist[$mathsecs] = renderMath($q[0]);
172 $stripped2 .= $unique2;
177 $stripped2 = $stripped;
180 while ( "" != $stripped2 ) {
181 $p = preg_split( "/<\\s*pre\\s*>/i", $stripped2, 2 );
183 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) { $stripped2 = ""; }
185 $q = preg_split( "/<\\/\\s*pre\\s*>/i", $p[1], 2 );
187 $prelist[$presecs] = "<pre>". wfEscapeHTMLTagsOnly($q[0]). "</pre>";
188 $stripped3 .= $unique3;
193 $text = $this->doWikiPass2( $stripped3, $linestart );
195 $specialChars = array("\\", "$");
196 $escapedChars = array("\\\\", "\\$");
197 for ( $i = 1; $i <= $presecs; ++
$i ) {
198 $text = preg_replace( "/{$unique3}/", str_replace( $specialChars,
199 $escapedChars, $prelist[$i] ), $text, 1 );
202 for ( $i = 1; $i <= $mathsecs; ++
$i ) {
203 $text = preg_replace( "/{$unique2}/", str_replace( $specialChars,
204 $escapedChars, $mathlist[$i] ), $text, 1 );
207 for ( $i = 1; $i <= $nwsecs; ++
$i ) {
208 $text = preg_replace( "/{$unique}/", str_replace( $specialChars,
209 $escapedChars, $nwlist[$i] ), $text, 1 );
211 $this->addHTML( $text );
215 function sendCacheControl() {
217 if( $this->mLastModified
!= "" ) {
218 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
219 header( "Cache-Control: private, must-revalidate, max-age=0" );
220 header( "Last-modified: {$this->mLastModified}" );
222 # We should put in Accept-Encoding, but IE chokes on anything but
223 # User-Agent in a Vary: header (at least through 6.0)
224 header( "Vary: User-Agent" );
227 wfDebug( "** no caching **\n", false );
228 header( "Cache-Control: no-cache" ); # Experimental - see below
229 header( "Pragma: no-cache" );
230 header( "Last-modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
232 header( "Expires: Mon, 15 Jan 2001 00:00:00 GMT" ); # Cachers always validate the page!
235 # Finally, all the text has been munged and accumulated into
236 # the object, let's actually output it:
240 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
241 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
242 $sk = $wgUser->getSkin();
244 $this->sendCacheControl();
246 header( "Content-type: text/html; charset={$wgOutputEncoding}" );
247 header( "Content-language: {$wgLanguageCode}" );
249 if ( "" != $this->mRedirect
) {
250 header( "Location: {$this->mRedirect}" );
254 $exp = time() +
$wgCookieExpiration;
255 foreach( $this->mCookies
as $name => $val ) {
256 setcookie( $name, $val, $exp, "/" );
259 $sk->outputPage( $this );
265 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
266 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
269 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
270 if ( false === $outs ) { $outs = $ins; }
275 function setEncodings()
277 global $HTTP_SERVER_VARS, $wgInputEncoding, $wgOutputEncoding;
278 global $wgUser, $wgLang;
280 $wgInputEncoding = strtolower( $wgInputEncoding );
281 $s = $HTTP_SERVER_VARS['HTTP_ACCEPT_CHARSET'];
283 if( $wgUser->getOption( 'altencoding' ) ) {
284 $wgLang->setAltEncoding();
289 $wgOutputEncoding = strtolower( $wgOutputEncoding );
292 $a = explode( ",", $s );
296 foreach ( $a as $s ) {
297 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
309 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
310 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
311 $wgOutputEncoding = strtolower( $bestset );
315 $wgOutputEncoding = $wgInputEncoding;
318 function reportTime()
320 global $wgRequestTime, $wgDebugLogFile, $HTTP_SERVER_VARS;
321 global $wgProfiling, $wgProfileStack, $wgUser;
323 list( $usec, $sec ) = explode( " ", microtime() );
324 $now = (float)$sec +
(float)$usec;
326 list( $usec, $sec ) = explode( " ", $wgRequestTime );
327 $start = (float)$sec +
(float)$usec;
328 $elapsed = $now - $start;
330 if ( "" != $wgDebugLogFile ) {
332 if( $wgProfiling and count( $wgProfileStack ) ) {
334 foreach( $wgProfileStack as $ile ) {
335 # "foo::bar 99 0.12345 1 0.23456 2"
336 if( preg_match( '/^(\S+)\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)/', $ile, $m ) ) {
337 $thisstart = (float)$m[3] +
(float)$m[4] - $start;
338 $thisend = (float)$m[5] +
(float)$m[6] - $start;
339 $thiselapsed = $thisend - $thisstart;
340 $thispercent = $thiselapsed / $elapsed * 100.0;
342 $prof .= sprintf( "\tat %04.3f in %04.3f (%2.1f%%) - %s %s\n",
343 $thisstart, $thiselapsed, $thispercent,
344 str_repeat( "*", $m[2] ), $m[1] );
345 $lasttime = $thistime;
346 #$prof .= "\t(^ $ile)\n";
348 $prof .= "\t?broken? $ile\n";
353 if( $forward = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'] )
354 $forward = " forwarded for $forward";
355 if( $client = $HTTP_SERVER_VARS['HTTP_CLIENT_IP'] )
356 $forward .= " client IP $client";
357 if( $from = $HTTP_SERVER_VARS['HTTP_FROM'] )
358 $forward .= " from $from";
360 $forward = "\t(proxied via {$HTTP_SERVER_VARS['REMOTE_ADDR']}{$forward})";
361 if($wgUser->getId() == 0)
363 $log = sprintf( "%s\t%04.3f\t%s\n",
364 gmdate( "YmdHis" ), $elapsed,
365 urldecode( $HTTP_SERVER_VARS['REQUEST_URI'] . $forward ) );
366 error_log( $log . $prof, 3, $wgDebugLogFile );
368 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
373 # Note: these arguments are keys into wfMsg(), not text!
375 function errorpage( $title, $msg )
379 $this->mDebugtext
.= "Original title: " .
380 $wgTitle->getPrefixedText() . "\n";
381 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
382 $this->setPageTitle( wfMsg( $title ) );
383 $this->setRobotpolicy( "noindex,nofollow" );
384 $this->setArticleFlag( false );
386 $this->mBodytext
= "";
387 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
388 $this->returnToMain( false );
394 function sysopRequired()
398 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
399 $this->setPageTitle( wfMsg( "sysoptitle" ) );
400 $this->setRobotpolicy( "noindex,nofollow" );
401 $this->setArticleFlag( false );
402 $this->mBodytext
= "";
404 $sk = $wgUser->getSkin();
405 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
406 $text = str_replace( "$1", $ap, wfMsg( "sysoptext" ) );
407 $this->addHTML( $text );
408 $this->returnToMain();
411 function developerRequired()
415 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
416 $this->setPageTitle( wfMsg( "developertitle" ) );
417 $this->setRobotpolicy( "noindex,nofollow" );
418 $this->setArticleFlag( false );
419 $this->mBodytext
= "";
421 $sk = $wgUser->getSkin();
422 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
423 $text = str_replace( "$1", $ap, wfMsg( "developertext" ) );
424 $this->addHTML( $text );
425 $this->returnToMain();
428 function databaseError( $fname )
430 global $wgUser, $wgCommandLineMode;
432 $this->setPageTitle( wfMsg( "databaseerror" ) );
433 $this->setRobotpolicy( "noindex,nofollow" );
434 $this->setArticleFlag( false );
436 if ( $wgCommandLineMode ) {
437 $msg = wfMsg( "dberrortextcl" );
439 $msg = wfMsg( "dberrortextcl" );
441 $msg = str_replace( "$1", htmlspecialchars( wfLastDBquery() ), $msg );
442 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
443 $msg = str_replace( "$3", wfLastErrno(), $msg );
444 $msg = str_replace( "$4", htmlspecialchars( wfLastError() ), $msg );
446 if ( $wgCommandLineMode ) {
450 $sk = $wgUser->getSkin();
451 $shlink = $sk->makeKnownLink( wfMsg( "searchhelppage" ),
452 wfMsg( "searchingwikipedia" ) );
453 $msg = str_replace( "$5", $shlink, $msg );
455 $this->mBodytext
= $msg;
460 function readOnlyPage( $source = "" )
462 global $wgUser, $wgReadOnlyFile;
464 $this->setPageTitle( wfMsg( "readonly" ) );
465 $this->setRobotpolicy( "noindex,nofollow" );
466 $this->setArticleFlag( false );
468 $reason = implode( "", file( $wgReadOnlyFile ) );
469 $text = str_replace( "$1", $reason, wfMsg( "readonlytext" ) );
472 $rows = $wgUser->getOption( "rows" );
473 $cols = $wgUser->getOption( "cols" );
474 $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
475 htmlspecialchars( $source ) . "\n</textarea>";
478 $this->addHTML( $text );
479 $this->returnToMain( false );
482 function fatalError( $message )
484 $this->setPageTitle( wfMsg( "internalerror" ) );
485 $this->setRobotpolicy( "noindex,nofollow" );
486 $this->setArticleFlag( false );
488 $this->mBodytext
= $message;
493 function unexpectedValueError( $name, $val )
495 $msg = str_replace( "$1", $name, wfMsg( "unexpected" ) );
496 $msg = str_replace( "$2", $val, $msg );
497 $this->fatalError( $msg );
500 function fileCopyError( $old, $new )
502 $msg = str_replace( "$1", $old, wfMsg( "filecopyerror" ) );
503 $msg = str_replace( "$2", $new, $msg );
504 $this->fatalError( $msg );
507 function fileRenameError( $old, $new )
509 $msg = str_replace( "$1", $old, wfMsg( "filerenameerror" ) );
510 $msg = str_replace( "$2", $new, $msg );
511 $this->fatalError( $msg );
514 function fileDeleteError( $name )
516 $msg = str_replace( "$1", $name, wfMsg( "filedeleteerror" ) );
517 $this->fatalError( $msg );
520 function fileNotFoundError( $name )
522 $msg = str_replace( "$1", $name, wfMsg( "filenotfound" ) );
523 $this->fatalError( $msg );
526 function returnToMain( $auto = true )
528 global $wgUser, $wgOut, $returnto;
530 $sk = $wgUser->getSkin();
531 if ( "" == $returnto ) {
532 $returnto = wfMsg( "mainpage" );
534 $link = $sk->makeKnownLink( $returnto, "" );
536 $r = str_replace( "$1", $link, wfMsg( "returnto" ) );
538 $wgOut->addMeta( "http:Refresh", "10;url=" .
539 wfLocalUrlE( wfUrlencode( $returnto ) ) );
541 $wgOut->addHTML( "\n<p>$r\n" );
545 function categoryMagic ()
547 global $wgTitle , $wgUseCategoryMagic ;
548 if ( !isset ( $wgUseCategoryMagic ) ||
!$wgUseCategoryMagic ) return ;
549 $id = $wgTitle->getArticleID() ;
550 $cat = ucfirst ( wfMsg ( "category" ) ) ;
551 $ti = $wgTitle->getText() ;
552 $ti = explode ( ":" , $ti , 2 ) ;
553 if ( $cat != $ti[0] ) return "" ;
554 $r = "<br break=all>\n" ;
556 $articles = array() ;
557 $parents = array () ;
558 $children = array() ;
562 $sk = $wgUser->getSkin() ;
563 $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
564 $res = wfQuery ( $sql ) ;
565 while ( $x = wfFetchObject ( $res ) )
568 # $t->newFromDBkey ( $x->l_from ) ;
569 # $t = $t->getText() ;
571 $y = explode ( ":" , $t , 2 ) ;
572 if ( count ( $y ) == 2 && $y[0] == $cat )
574 array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ;
576 else array_push ( $articles , $sk->makeLink ( $t ) ) ;
578 wfFreeResult ( $res ) ;
581 if ( count ( $children ) > 0 )
583 asort ( $children ) ;
584 $r .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
585 $r .= implode ( ", " , $children ) ;
589 if ( count ( $articles ) > 0 )
591 asort ( $articles ) ;
592 $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ;
593 $r .= "<h2>{$h}</h2>\n" ;
594 $r .= implode ( ", " , $articles ) ;
602 function doTableStuff ( $t )
604 $t = explode ( "\n" , $t ) ;
605 $td = array () ; # Is currently a td tag open?
606 $tr = array () ; # Is currently a tr tag open?
607 $ltd = array () ; # Was it TD or TH?
608 foreach ( $t AS $k => $x )
611 $fc = substr ( $x , 0 , 1 ) ;
612 if ( "{|" == substr ( $x , 0 , 2 ) )
614 $t[$k] = "<table " . substr ( $x , 3 ) . ">" ;
615 array_push ( $td , false ) ;
616 array_push ( $ltd , "" ) ;
617 array_push ( $tr , false ) ;
619 else if ( count ( $td ) == 0 ) { } # Don't do any of the following
620 else if ( "|}" == substr ( $x , 0 , 2 ) )
623 $l = array_pop ( $ltd ) ;
624 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
625 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
628 else if ( "|_" == substr ( $x , 0 , 2 ) ) # Caption
630 $z = trim ( substr ( $x , 2 ) ) ;
631 $t[$k] = "<caption>{$z}</caption>\n" ;
633 else if ( "|-" == substr ( $x , 0 , 2 ) ) # Allows for |---------------
636 $l = array_pop ( $ltd ) ;
637 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
638 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
640 array_push ( $tr , false ) ;
641 array_push ( $td , false ) ;
642 array_push ( $ltd , "" ) ;
644 else if ( "|" == $fc ||
"!" == $fc )
646 $after = substr ( $x , 1 ) ;
647 if ( $fc == "!" ) $after = str_replace ( "!!" , "||" , $after ) ;
648 $after = explode ( "||" , $after ) ;
650 foreach ( $after AS $theline )
653 if ( !array_pop ( $tr ) ) $z = "<tr>\n" ;
654 array_push ( $tr , true ) ;
656 $l = array_pop ( $ltd ) ;
657 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
658 if ( $fc == "|" ) $l = "TD" ;
659 else if ( $fc == "!" ) $l = "TH" ;
661 array_push ( $ltd , $l ) ;
662 $y = explode ( "|" , $theline , 2 ) ;
663 if ( count ( $y ) == 1 ) $y = "{$z}<{$l}>{$y[0]}" ;
664 else $y = $y = "{$z}<{$l} {$y[0]}>{$y[1]}" ;
666 array_push ( $td , true ) ;
672 # Well, OK, it's actually about 14 passes. But since all the
673 # hard lifting is done inside PHP's regex code, it probably
674 # wouldn't speed things up much to add a real parser.
676 function doWikiPass2( $text, $linestart )
678 global $wgUser, $wgLang, $wgUseDynamicDates;
679 wfProfileIn( "OutputPage::doWikiPass2" );
681 $text = $this->removeHTMLtags( $text );
682 $text = $this->replaceVariables( $text );
684 $text = preg_replace( "/(^|\n)-----*/", "\\1<hr>", $text );
685 $text = str_replace ( "<HR>", "<hr>", $text );
687 $text = $this->doAllQuotes( $text );
688 $text = $this->doHeadings( $text );
689 $text = $this->doBlockLevels( $text, $linestart );
691 if($wgUseDynamicDates) {
692 $text = $wgLang->replaceDates( $text );
695 $text = $this->replaceExternalLinks( $text );
696 $text = $this->replaceInternalLinks ( $text );
697 $text = $this->doTableStuff ( $text ) ;
699 $text = $this->magicISBN( $text );
700 $text = $this->magicRFC( $text );
701 $text = $this->formatHeadings( $text );
703 $sk = $wgUser->getSkin();
704 $text = $sk->transformContent( $text );
705 $text .= $this->categoryMagic () ;
711 /* private */ function doAllQuotes( $text )
714 $lines = explode( "\r\n", $text );
715 foreach ( $lines as $line ) {
716 $outtext .= $this->doQuotes ( "", $line, "" ) . "\r\n";
721 /* private */ function doQuotes( $pre, $text, $mode )
723 if ( preg_match( "/^(.*)''(.*)$/sU", $text, $m ) ) {
724 $m1_strong = ($m[1] == "") ?
"" : "<strong>{$m[1]}</strong>";
725 $m1_em = ($m[1] == "") ?
"" : "<em>{$m[1]}</em>";
726 if ( substr ($m[2], 0, 1) == "'" ) {
727 $m[2] = substr ($m[2], 1);
729 return $this->doQuotes ( $m[1], $m[2], ($m[1] == "") ?
"both" : "emstrong" );
730 } else if ($mode == "strong") {
731 return $m1_strong . $this->doQuotes ( "", $m[2], "" );
732 } else if (($mode == "emstrong") ||
($mode == "both")) {
733 return $this->doQuotes ( "", $pre.$m1_strong.$m[2], "em" );
734 } else if ($mode == "strongem") {
735 return "<strong>{$pre}{$m1_em}</strong>" . $this->doQuotes ( "", $m[2], "em" );
737 return $m[1] . $this->doQuotes ( "", $m[2], "strong" );
740 if ($mode == "strong") {
741 return $this->doQuotes ( $m[1], $m[2], ($m[1] == "") ?
"both" : "strongem" );
742 } else if ($mode == "em") {
743 return $m1_em . $this->doQuotes ( "", $m[2], "" );
744 } else if ($mode == "emstrong") {
745 return "<em>{$pre}{$m1_strong}</em>" . $this->doQuotes ( "", $m[2], "strong" );
746 } else if (($mode == "strongem") ||
($mode == "both")) {
747 return $this->doQuotes ( "", $pre.$m1_em.$m[2], "strong" );
749 return $m[1] . $this->doQuotes ( "", $m[2], "em" );
753 $text_strong = ($text == "") ?
"" : "<strong>{$text}</strong>";
754 $text_em = ($text == "") ?
"" : "<em>{$text}</em>";
757 } else if ($mode == "em") {
758 return $pre . $text_em;
759 } else if ($mode == "strong") {
760 return $pre . $text_strong;
761 } else if ($mode == "strongem") {
762 return (($pre == "") && ($text == "")) ?
"" : "<strong>{$pre}{$text_em}</strong>";
764 return (($pre == "") && ($text == "")) ?
"" : "<em>{$pre}{$text_strong}</em>";
769 /* private */ function doHeadings( $text )
771 for ( $i = 6; $i >= 1; --$i ) {
772 $h = substr( "======", 0, $i );
773 $text = preg_replace( "/^{$h}([^=]+){$h}(\\s|$)/m",
774 "<h{$i}>\\1</h{$i}>\\2", $text );
779 # Note: we have to do external links before the internal ones,
780 # and otherwise take great care in the order of things here, so
781 # that we don't end up interpreting some URLs twice.
783 /* private */ function replaceExternalLinks( $text )
785 wfProfileIn( "OutputPage::replaceExternalLinks" );
786 $text = $this->subReplaceExternalLinks( $text, "http", true );
787 $text = $this->subReplaceExternalLinks( $text, "https", true );
788 $text = $this->subReplaceExternalLinks( $text, "ftp", false );
789 $text = $this->subReplaceExternalLinks( $text, "gopher", false );
790 $text = $this->subReplaceExternalLinks( $text, "news", false );
791 $text = $this->subReplaceExternalLinks( $text, "mailto", false );
796 /* private */ function subReplaceExternalLinks( $s, $protocol, $autonumber )
798 global $wgUser, $printable;
799 global $wgAllowExternalImages;
802 $unique = "4jzAfzB8hNvf4sqyO9Edd8pSmk9rE2in0Tgw3";
803 $uc = "A-Za-z0-9_\\/~%\\-+&*#?!=()@\\x80-\\xFF";
805 # this is the list of separators that should be ignored if they
806 # are the last character of an URL but that should be included
807 # if they occur within the URL, e.g. "go to www.foo.com, where .."
808 # in this case, the last comma should not become part of the URL,
809 # but in "www.foo.com/123,2342,32.htm" it should.
811 $fnc = "A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF";
812 $images = "gif|png|jpg|jpeg";
814 # PLEASE NOTE: The curly braces { } are not part of the regex,
815 # they are interpreted as part of the string (used to tell PHP
816 # that the content of the string should be inserted there).
817 $e1 = "/(^|[^\\[])({$protocol}:)([{$uc}{$sep}]+)\\/([{$fnc}]+)\\." .
818 "((?i){$images})([^{$uc}]|$)/";
820 $e2 = "/(^|[^\\[])({$protocol}:)(([".$uc."]|[".$sep."][".$uc."])+)([^". $uc . $sep. "]|[".$sep."]|$)/";
821 $sk = $wgUser->getSkin();
823 if ( $autonumber and $wgAllowExternalImages) { # Use img tags only for HTTP urls
824 $s = preg_replace( $e1, "\\1" . $sk->makeImage( "{$unique}:\\3" .
825 "/\\4.\\5", "\\4.\\5" ) . "\\6", $s );
827 $s = preg_replace( $e2, "\\1" . "<a href=\"{$unique}:\\3\"" .
828 $sk->getExternalLinkAttributes( "{$unique}:\\3", wfEscapeHTML(
829 "{$unique}:\\3" ) ) . ">" . wfEscapeHTML( "{$unique}:\\3" ) .
831 $s = str_replace( $unique, $protocol, $s );
833 $a = explode( "[{$protocol}:", " " . $s );
834 $s = array_shift( $a );
835 $s = substr( $s, 1 );
837 $e1 = "/^([{$uc}"."{$sep}]+)](.*)\$/sD";
838 $e2 = "/^([{$uc}"."{$sep}]+)\\s+([^\\]]+)](.*)\$/sD";
840 foreach ( $a as $line ) {
841 if ( preg_match( $e1, $line, $m ) ) {
842 $link = "{$protocol}:{$m[1]}";
844 if ( $autonumber ) { $text = "[" . ++
$this->mAutonumber
. "]"; }
845 else { $text = wfEscapeHTML( $link ); }
846 } else if ( preg_match( $e2, $line, $m ) ) {
847 $link = "{$protocol}:{$m[1]}";
851 $s .= "[{$protocol}:" . $line;
854 if ( $printable == "yes") $paren = " (<i>" . htmlspecialchars ( $link ) . "</i>)";
856 $la = $sk->getExternalLinkAttributes( $link, $text );
857 $s .= "<a href='{$link}'{$la}>{$text}</a>{$paren}{$trail}";
863 /* private */ function replaceInternalLinks( $s )
865 global $wgTitle, $wgUser, $wgLang;
866 global $wgLinkCache, $wgInterwikiMagic, $wgUseCategoryMagic;
867 global $wgNamespacesWithSubpages, $wgLanguageCode;
868 wfProfileIn( $fname = "OutputPage::replaceInternalLinks" );
870 wfProfileIn( "$fname-setup" );
871 $tc = Title
::legalChars() . "#";
872 $sk = $wgUser->getSkin();
874 $a = explode( "[[", " " . $s );
875 $s = array_shift( $a );
876 $s = substr( $s, 1 );
878 $e1 = "/^([{$tc}]+)\\|([^]]+)]](.*)\$/sD";
879 $e2 = "/^([{$tc}]+)]](.*)\$/sD";
882 foreach ( $a as $line ) {
883 wfProfileIn( "$fname-loop" );
884 if ( preg_match( $e1, $line, $m ) ) { # page with alternate text
889 } else if ( preg_match( $e2, $line, $m ) ) { # page with normal text
895 else { # Invalid form; output directly
900 if(substr($m[1],0,1)=="/") { # subpage
901 if(substr($m[1],-1,1)=="/") { # / at end means we don't want the slash to be shown
902 $m[1]=substr($m[1],1,strlen($m[1])-2);
906 $noslash=substr($m[1],1);
908 if($wgNamespacesWithSubpages[$wgTitle->getNamespace()]) { # subpages allowed here
909 $link = $wgTitle->getPrefixedText(). "/" . trim($noslash);
912 } # this might be changed for ugliness reasons
914 $link = $noslash; # no subpage allowed, use standard link
916 } else { # no subpage
920 if ( preg_match( "/^((?:i|x|[a-z]{2,3})(?:-[a-z0-9]+)?|[A-Za-z\\x80-\\xff]+):(.*)\$/", $link, $m ) ) {
921 $pre = strtolower( $m[1] );
923 if ( $wgLang->getNsIndex( $pre ) ==
924 Namespace::getImage() ) {
925 $nt = Title
::newFromText( $suf );
926 $name = $nt->getDBkey();
927 if ( "" == $text ) { $text = $nt->GetText(); }
929 $wgLinkCache->addImageLink( $name );
930 $s .= $sk->makeImageLink( $name,
931 wfImageUrl( $name ), $text );
933 } else if ( "media" == $pre ) {
934 $nt = Title
::newFromText( $suf );
935 $name = $nt->getDBkey();
936 if ( "" == $text ) { $text = $nt->GetText(); }
938 $wgLinkCache->addImageLink( $name );
939 $s .= $sk->makeMediaLink( $name,
940 wfImageUrl( $name ), $text );
942 } else if ( isset($wgUseCategoryMagic) && $wgUseCategoryMagic && $pre == wfMsg ( "category" ) ) {
943 $l = $sk->makeLink ( $pre.":".ucfirst($m[2]) , ucfirst ( $m[2] ) ) ;
944 array_push ( $this->mCategoryLinks
, $l ) ;
947 $l = $wgLang->getLanguageName( $pre );
948 if ( "" == $l or !$wgInterwikiMagic or
949 Namespace::isTalk( $wgTitle->getNamespace() ) ) {
950 if ( "" == $text ) { $text = $link; }
951 $s .= $sk->makeLink( $link, $text, "", $trail );
952 } else if ( $pre != $wgLanguageCode ) {
953 array_push( $this->mLanguageLinks
, "$pre:$suf" );
957 # } else if ( 0 == strcmp( "##", substr( $link, 0, 2 ) ) ) {
958 # $link = substr( $link, 2 );
959 # $s .= "<a name=\"{$link}\">{$text}</a>{$trail}";
961 if ( "" == $text ) { $text = $link; }
962 $s .= $sk->makeLink( $link, $text, "", $trail );
970 # Some functions here used by doBlockLevels()
972 /* private */ function closeParagraph()
975 if ( 0 != strcmp( "p", $this->mLastSection
) &&
976 0 != strcmp( "", $this->mLastSection
) ) {
977 $result = "</" . $this->mLastSection
. ">";
979 $this->mLastSection
= "";
982 # getCommon() returns the length of the longest common substring
983 # of both arguments, starting at the beginning of both.
985 /* private */ function getCommon( $st1, $st2 )
987 $fl = strlen( $st1 );
988 $shorter = strlen( $st2 );
989 if ( $fl < $shorter ) { $shorter = $fl; }
991 for ( $i = 0; $i < $shorter; ++
$i ) {
992 if ( $st1{$i} != $st2{$i} ) { break; }
996 # These next three functions open, continue, and close the list
997 # element appropriate to the prefix character passed into them.
999 /* private */ function openList( $char )
1001 $result = $this->closeParagraph();
1003 if ( "*" == $char ) { $result .= "<ul><li>"; }
1004 else if ( "#" == $char ) { $result .= "<ol><li>"; }
1005 else if ( ":" == $char ) { $result .= "<dl><dd>"; }
1006 else if ( ";" == $char ) {
1007 $result .= "<dl><dt>";
1008 $this->mDTopen
= true;
1010 else { $result = "<!-- ERR 1 -->"; }
1015 /* private */ function nextItem( $char )
1017 if ( "*" == $char ||
"#" == $char ) { return "</li><li>"; }
1018 else if ( ":" == $char ||
";" == $char ) {
1020 if ( $this->mDTopen
) { $close = "</dt>"; }
1021 if ( ";" == $char ) {
1022 $this->mDTopen
= true;
1023 return $close . "<dt>";
1025 $this->mDTopen
= false;
1026 return $close . "<dd>";
1029 return "<!-- ERR 2 -->";
1032 /* private */function closeList( $char )
1034 if ( "*" == $char ) { return "</li></ul>"; }
1035 else if ( "#" == $char ) { return "</li></ol>"; }
1036 else if ( ":" == $char ) {
1037 if ( $this->mDTopen
) {
1038 $this->mDTopen
= false;
1039 return "</dt></dl>";
1041 return "</dd></dl>";
1044 return "<!-- ERR 3 -->";
1047 /* private */ function doBlockLevels( $text, $linestart )
1049 wfProfileIn( "OutputPage::doBlockLevels" );
1050 # Parsing through the text line by line. The main thing
1051 # happening here is handling of block-level elements p, pre,
1052 # and making lists from lines starting with * # : etc.
1054 $a = explode( "\n", $text );
1055 $text = $lastPref = "";
1056 $this->mDTopen
= $inBlockElem = false;
1058 if ( ! $linestart ) { $text .= array_shift( $a ); }
1059 foreach ( $a as $t ) {
1060 if ( "" != $text ) { $text .= "\n"; }
1063 $opl = strlen( $lastPref );
1064 $npl = strspn( $t, "*#:;" );
1065 $pref = substr( $t, 0, $npl );
1066 $pref2 = str_replace( ";", ":", $pref );
1067 $t = substr( $t, $npl );
1069 if ( 0 != $npl && 0 == strcmp( $lastPref, $pref2 ) ) {
1070 $text .= $this->nextItem( substr( $pref, -1 ) );
1072 if ( ";" == substr( $pref, -1 ) ) {
1073 $cpos = strpos( $t, ":" );
1074 if ( ! ( false === $cpos ) ) {
1075 $term = substr( $t, 0, $cpos );
1076 $text .= $term . $this->nextItem( ":" );
1077 $t = substr( $t, $cpos +
1 );
1080 } else if (0 != $npl ||
0 != $opl) {
1081 $cpl = $this->getCommon( $pref, $lastPref );
1083 while ( $cpl < $opl ) {
1084 $text .= $this->closeList( $lastPref{$opl-1} );
1087 if ( $npl <= $cpl && $cpl > 0 ) {
1088 $text .= $this->nextItem( $pref{$cpl-1} );
1090 while ( $npl > $cpl ) {
1091 $char = substr( $pref, $cpl, 1 );
1092 $text .= $this->openList( $char );
1094 if ( ";" == $char ) {
1095 $cpos = strpos( $t, ":" );
1096 if ( ! ( false === $cpos ) ) {
1097 $term = substr( $t, 0, $cpos );
1098 $text .= $term . $this->nextItem( ":" );
1099 $t = substr( $t, $cpos +
1 );
1106 if ( 0 == $npl ) { # No prefix--go to paragraph mode
1108 "/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6)/i", $t ) ) {
1109 $text .= $this->closeParagraph();
1110 $inBlockElem = true;
1112 if ( ! $inBlockElem ) {
1113 if ( " " == $t{0} ) {
1114 $newSection = "pre";
1115 # $t = wfEscapeHTML( $t );
1117 else { $newSection = "p"; }
1119 if ( 0 == strcmp( "", trim( $oLine ) ) ) {
1120 $text .= $this->closeParagraph();
1121 $text .= "<" . $newSection . ">";
1122 } else if ( 0 != strcmp( $this->mLastSection
,
1124 $text .= $this->closeParagraph();
1125 if ( 0 != strcmp( "p", $newSection ) ) {
1126 $text .= "<" . $newSection . ">";
1129 $this->mLastSection
= $newSection;
1131 if ( $inBlockElem &&
1132 preg_match( "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6)/i", $t ) ) {
1133 $inBlockElem = false;
1139 $text .= $this->closeList( $pref2{$npl-1} );
1142 if ( "" != $this->mLastSection
) {
1143 if ( "p" != $this->mLastSection
) {
1144 $text .= "</" . $this->mLastSection
. ">";
1146 $this->mLastSection
= "";
1152 /* private */ function replaceVariables( $text )
1155 wfProfileIn( "OutputPage:replaceVariables" );
1157 /* As with sigs, use server's local time --
1158 ensure this is appropriate for your audience! */
1160 $mw =& MagicWord
::get( MAG_CURRENTMONTH
);
1161 $text = $mw->replace( $v, $text );
1163 $v = $wgLang->getMonthName( date( "n" ) );
1164 $mw =& MagicWord
::get( MAG_CURRENTMONTHNAME
);
1165 $text = $mw->replace( $v, $text );
1167 $v = $wgLang->getMonthNameGen( date( "n" ) );
1168 $mw =& MagicWord
::get( MAG_CURRENTMONTHNAMEGEN
);
1169 $text = $mw->replace( $v, $text );
1172 $mw = MagicWord
::get( MAG_CURRENTDAY
);
1173 $text = $mw->replace( $v, $text );
1175 $v = $wgLang->getWeekdayName( date( "w" )+
1 );
1176 $mw =& MagicWord
::get( MAG_CURRENTDAYNAME
);
1177 $text = $mw->replace( $v, $text );
1180 $mw =& MagicWord
::get( MAG_CURRENTYEAR
);
1181 $text = $mw->replace( $v, $text );
1183 $v = $wgLang->time( wfTimestampNow(), false );
1184 $mw =& MagicWord
::get( MAG_CURRENTTIME
);
1185 $text = $mw->replace( $v, $text );
1187 $mw =& MagicWord
::get( MAG_NUMBEROFARTICLES
);
1188 if ( $mw->match( $text ) ) {
1189 $v = wfNumberOfArticles();
1190 $text = $mw->replace( $v, $text );
1196 /* private */ function removeHTMLtags( $text )
1198 wfProfileIn( "OutputPage::removeHTMLtags" );
1199 $htmlpairs = array( # Tags that must be closed
1200 "b", "i", "u", "font", "big", "small", "sub", "sup", "h1",
1201 "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
1202 "strike", "strong", "tt", "var", "div", "center",
1203 "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
1204 "ruby", "rt" , "rb" , "rp"
1206 $htmlsingle = array(
1207 "br", "p", "hr", "li", "dt", "dd"
1209 $htmlnest = array( # Tags that can be nested--??
1210 "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
1211 "dl", "font", "big", "small", "sub", "sup"
1213 $tabletags = array( # Can only appear inside table
1217 $htmlsingle = array_merge( $tabletags, $htmlsingle );
1218 $htmlelements = array_merge( $htmlsingle, $htmlpairs );
1220 $htmlattrs = array( # Allowed attributes--no scripting, etc.
1221 "title", "align", "lang", "dir", "width", "height",
1222 "bgcolor", "clear", /* BR */ "noshade", /* HR */
1223 "cite", /* BLOCKQUOTE, Q */ "size", "face", "color",
1224 /* FONT */ "type", "start", "value", "compact",
1225 /* For various lists, mostly deprecated but safe */
1226 "summary", "width", "border", "frame", "rules",
1227 "cellspacing", "cellpadding", "valign", "char",
1228 "charoff", "colgroup", "col", "span", "abbr", "axis",
1229 "headers", "scope", "rowspan", "colspan", /* Tables */
1230 "id", "class", "name", "style" /* For CSS */
1233 # Remove HTML comments
1234 $text = preg_replace( "/<!--.*-->/sU", "", $text );
1236 $bits = explode( "<", $text );
1237 $text = array_shift( $bits );
1238 $tagstack = array(); $tablestack = array();
1240 foreach ( $bits as $x ) {
1241 $prev = error_reporting( E_ALL
& ~
( E_NOTICE | E_WARNING
) );
1242 preg_match( "/^(\\/?)(\\w+)([^>]*)(\\/{0,1}>)([^<]*)$/",
1244 list( $qbar, $slash, $t, $params, $brace, $rest ) = $regs;
1245 error_reporting( $prev );
1248 if ( in_array( $t = strtolower( $t ), $htmlelements ) ) {
1252 if ( ! in_array( $t, $htmlsingle ) &&
1253 ( $ot = array_pop( $tagstack ) ) != $t ) {
1254 array_push( $tagstack, $ot );
1257 if ( $t == "table" ) {
1258 $tagstack = array_pop( $tablestack );
1263 # Keep track for later
1264 if ( in_array( $t, $tabletags ) &&
1265 ! in_array( "table", $tagstack ) ) {
1267 } else if ( in_array( $t, $tagstack ) &&
1268 ! in_array ( $t , $htmlnest ) ) {
1270 } else if ( ! in_array( $t, $htmlsingle ) ) {
1271 if ( $t == "table" ) {
1272 array_push( $tablestack, $tagstack );
1273 $tagstack = array();
1275 array_push( $tagstack, $t );
1277 # Strip non-approved attributes from the tag
1278 $newparams = preg_replace(
1279 "/(\\w+)(\\s*=\\s*([^\\s\">]+|\"[^\">]*\"))?/e",
1280 "(in_array(strtolower(\"\$1\"),\$htmlattrs)?(\"\$1\".((\"x\$3\" != \"x\")?\"=\$3\":'')):'')",
1284 $rest = str_replace( ">", ">", $rest );
1285 $text .= "<$slash$t$newparams$brace$rest";
1289 $text .= "<" . str_replace( ">", ">", $x);
1291 # Close off any remaining tags
1292 while ( $t = array_pop( $tagstack ) ) {
1294 if ( $t == "table" ) { $tagstack = array_pop( $tablestack ); }
1303 * This function accomplishes several tasks:
1304 * 1) Auto-number headings if that option is enabled
1305 * 2) Add an [edit] link to sections for logged in users who have enabled the option
1306 * 3) Add a Table of contents on the top for users who have enabled the option
1307 * 4) Auto-anchor headings
1309 * It loops through all headlines, collects the necessary data, then splits up the
1310 * string and re-inserts the newly formatted headlines.
1313 /* private */ function formatHeadings( $text )
1315 global $wgUser,$wgArticle,$wgTitle,$wpPreview;
1316 $nh=$wgUser->getOption( "numberheadings" );
1317 $st=$wgUser->getOption( "showtoc" );
1318 if(!$wgTitle->userCanEdit()) {
1322 $es=$wgUser->getID() && $wgUser->getOption( "editsection" );
1323 $esr=$wgUser->getID() && $wgUser->getOption( "editsectiononrightclick" );
1325 # if the string __NOTOC__ (not case-sensitive) occurs in the HTML, do not
1327 $mw =& MagicWord
::get( MAG_NOTOC
);
1328 $st = ! $mw->matchAndRemove( $text );
1330 # never add the TOC to the Main Page. This is an entry page that should not
1331 # be more than 1-2 screens large anyway
1332 if($wgTitle->getPrefixedText()==wfMsg("mainpage")) {$st=0;}
1334 # We need this to perform operations on the HTML
1335 $sk=$wgUser->getSkin();
1337 # Get all headlines for numbering them and adding funky stuff like [edit]
1339 preg_match_all("/<H([1-6])(.*?>)(.*?)<\/H[1-6]>/i",$text,$matches);
1344 # Ugh .. the TOC should have neat indentation levels which can be
1345 # passed to the skin functions. These are determined here
1346 foreach($matches[3] as $headline) {
1347 if($level) { $prevlevel=$level;}
1348 $level=$matches[1][$c];
1349 if(($nh||
$st) && $prevlevel && $level>$prevlevel) {
1351 $h[$level]=0; // reset when we enter a new level
1352 $toc.=$sk->tocIndent($level-$prevlevel);
1353 $toclevel+
=$level-$prevlevel;
1356 if(($nh||
$st) && $level<$prevlevel) {
1357 $h[$level+
1]=0; // reset when we step back a level
1358 $toc.=$sk->tocUnindent($prevlevel-$level);
1359 $toclevel-=$prevlevel-$level;
1362 $h[$level]++
; // count number of headlines for each level
1365 for($i=1;$i<=$level;$i++
) {
1367 if($dot) {$numbering.=".";}
1375 $canonized_headline=preg_replace("/<.*?>/","",$headline); // strip out HTML
1376 $tocline=$canonized_headline;
1377 $canonized_headline=str_replace('"',"",$canonized_headline);
1378 $canonized_headline=str_replace(" ","_",trim($canonized_headline));
1379 $refer[$c]=$canonized_headline;
1380 $refers[$canonized_headline]++
; // count how many in assoc. array so we can track dupes in anchors
1381 $refcount[$c]=$refers[$canonized_headline];
1383 $tocline=$numbering ." ". $tocline;
1385 $headline=$numbering . " " . $headline; // the two are different if the line contains a link
1388 $anchor=$canonized_headline;
1389 if($refcount[$c]>1) {$anchor.="_".$refcount[$c];}
1391 $toc.=$sk->tocLine($anchor,$tocline,$toclevel);
1393 if($es && !isset($wpPreview)) {
1394 $head[$c].=$sk->editSectionLink($c+
1);
1396 $head[$c].="<H".$level.$matches[2][$c]
1397 ."<a name=\"".$anchor."\">"
1401 if($esr && !isset($wpPreview)) {
1402 $head[$c]=$sk->editSectionScript($c+
1,$head[$c]);
1411 $toc.=$sk->tocUnindent($toclevel);
1412 $toc=$sk->tocTable($toc);
1415 // split up and insert constructed headlines
1417 $blocks=preg_split("/<H[1-6].*?>.*?<\/H[1-6]>/i",$text);
1421 foreach($blocks as $block) {
1422 if(($es) && !isset($wpPreview) && $c>0 && $i==0) {
1423 # This is the [edit] link that appears for the top block of text when
1424 # section editing is enabled
1425 $full.=$sk->editSectionLink(0);
1428 if($st && $toclines>3 && !$i) {
1429 # Let's add a top anchor just in case we want to link to the top of the page
1430 $full="<a name=\"top\"></a>".$full.$toc;
1439 /* private */ function magicISBN( $text )
1443 $a = split( "ISBN ", " $text" );
1444 if ( count ( $a ) < 2 ) return $text;
1445 $text = substr( array_shift( $a ), 1);
1446 $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1448 foreach ( $a as $x ) {
1449 $isbn = $blank = "" ;
1450 while ( " " == $x{0} ) {
1452 $x = substr( $x, 1 );
1454 while ( strstr( $valid, $x{0} ) != false ) {
1456 $x = substr( $x, 1 );
1458 $num = str_replace( "-", "", $isbn );
1459 $num = str_replace( " ", "", $num );
1462 $text .= "ISBN $blank$x";
1464 $text .= "<a href=\"" . wfLocalUrlE( $wgLang->specialPage(
1465 "Booksources"), "isbn={$num}" ) . "\" CLASS=\"internal\">ISBN $isbn</a>";
1472 /* private */ function magicRFC( $text )
1477 /* private */ function headElement()
1479 global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang;
1481 $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1483 if ( "" == $this->mHTMLtitle
) {
1484 $this->mHTMLtitle
= $this->mPagetitle
;
1486 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : "";
1487 $ret .= "<html lang=\"$wgLanguageCode\"$rtl><head><title>{$this->mHTMLtitle}</title>\n";
1488 array_push( $this->mMetatags
, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) );
1489 foreach ( $this->mMetatags
as $tag ) {
1490 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
1492 $tag[0] = substr( $tag[0], 5 );
1496 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\">\n";
1498 $p = $this->mRobotpolicy
;
1499 if ( "" == $p ) { $p = "index,follow"; }
1500 $ret .= "<meta name=\"robots\" content=\"$p\">\n";
1502 if ( count( $this->mKeywords
) > 0 ) {
1503 $ret .= "<meta name=\"keywords\" content=\"" .
1504 implode( ",", $this->mKeywords
) . "\">\n";
1506 foreach ( $this->mLinktags
as $tag ) {
1508 if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
1509 if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
1510 $ret .= "href=\"{$tag[2]}\">\n";
1512 $sk = $wgUser->getSkin();
1513 $ret .= $sk->getHeadScripts();
1514 $ret .= $sk->getUserStyles();
1516 $ret .= "</head>\n";