X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=37379c83a837da8db2299d553d4a9c0dc2cafc56;hb=98fc03e686f9c0b74cd912a8a5f795fd84401b49;hp=4f5a53e4d411f396b86b80fd6a44c54f280c9214;hpb=9f9a988e0656b7f08a4cbf0ebf6c356bdd806aa6;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 4f5a53e4d4..37379c83a8 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -56,8 +56,8 @@ class OutputPage {
$lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
max( $timestamp, $wgUser->mTouched ) ) ) . " GMT";
- if( $_SERVER["HTTP_IF_MODIFIED_SINCE"] != "" ) {
- # IE sends sizes after the date for compressed pages:
+ if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
+ # IE sends sizes after the date like this:
# Wed, 20 Aug 2003 06:51:19 GMT; length=5202
# this breaks strtotime().
$modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
@@ -72,6 +72,7 @@ class OutputPage {
header( "Cache-Control: private, must-revalidate, max-age=0" );
header( "Last-Modified: {$lastmod}" );
wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
+ $this->reportTime(); # For profiling
exit;
} else {
wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
@@ -95,30 +96,10 @@ class OutputPage {
function isPrintable() { return $this->mPrintable; }
function getLanguageLinks() {
- global $wgUseNewInterlanguage, $wgTitle, $wgLanguageCode;
- global $wgDBconnection, $wgDBname, $wgDBintlname;
-
- if ( ! $wgUseNewInterlanguage )
- return $this->mLanguageLinks;
-
- mysql_select_db( $wgDBintlname, $wgDBconnection ) or die(
- htmlspecialchars(mysql_error()) );
-
- $list = array();
- $sql = "SELECT * FROM ilinks WHERE lang_from=\"" .
- "{$wgLanguageCode}\" AND title_from=\"" . $wgTitle->getDBkey() . "\"";
- $res = mysql_query( $sql, $wgDBconnection );
-
- while ( $q = mysql_fetch_object ( $res ) ) {
- $list[] = $q->lang_to . ":" . $q->title_to;
- }
- mysql_free_result( $res );
- mysql_select_db( $wgDBname, $wgDBconnection ) or die(
- htmlspecialchars(mysql_error()) );
-
- return $list;
+ global $wgTitle, $wgLanguageCode;
+ global $wgDBconnection, $wgDBname;
+ return $this->mLanguageLinks;
}
-
function supressQuickbar() { $this->mSupressQuickbar = true; }
function isQuickbarSupressed() { return $this->mSupressQuickbar; }
@@ -133,7 +114,8 @@ class OutputPage {
function addWikiText( $text, $linestart = true )
{
global $wgUseTeX;
- wfProfileIn( "OutputPage::addWikiText" );
+ $fname = "OutputPage::addWikiText";
+ wfProfileIn( $fname );
$unique = "3iyZiyA7iMwg5rhxP0Dcc9oTnj8qD1jm1Sfv4";
$unique2 = "4LIQ9nXtiYFPCSfitVwDw7EYwQlL4GeeQ7qSO";
$unique3 = "fPaA8gDfdLBqzj68Yjg9Hil3qEF8JGO0uszIp";
@@ -209,7 +191,7 @@ class OutputPage {
$escapedChars, $nwlist[$i] ), $text, 1 );
}
$this->addHTML( $text );
- wfProfileOut();
+ wfProfileOut( $fname );
}
function sendCacheControl() {
@@ -239,6 +221,10 @@ class OutputPage {
{
global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
+
+ $fname = "OutputPage::output";
+ wfProfileIn( $fname );
+
$sk = $wgUser->getSkin();
$this->sendCacheControl();
@@ -274,22 +260,26 @@ class OutputPage {
function setEncodings()
{
- global $HTTP_SERVER_VARS, $wgInputEncoding, $wgOutputEncoding;
+ global $wgInputEncoding, $wgOutputEncoding;
global $wgUser, $wgLang;
$wgInputEncoding = strtolower( $wgInputEncoding );
- $s = $HTTP_SERVER_VARS['HTTP_ACCEPT_CHARSET'];
if( $wgUser->getOption( 'altencoding' ) ) {
$wgLang->setAltEncoding();
return;
}
- if ( "" == $s ) {
+ if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
$wgOutputEncoding = strtolower( $wgOutputEncoding );
return;
}
- $a = explode( ",", $s );
+
+ /*
+ # This code is unused anyway!
+ # Commenting out. --bv 2003-11-15
+
+ $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
$best = 0.0;
$bestset = "*";
@@ -312,13 +302,14 @@ class OutputPage {
# Disable for now
#
+ */
$wgOutputEncoding = $wgInputEncoding;
}
function reportTime()
{
- global $wgRequestTime, $wgDebugLogFile, $HTTP_SERVER_VARS;
- global $wgProfiling, $wgProfileStack, $wgUser;
+ global $wgRequestTime, $wgDebugLogFile;
+ global $wgProfiling, $wgProfileStack, $wgProfileLimit, $wgUser;
list( $usec, $sec ) = explode( " ", microtime() );
$now = (float)$sec + (float)$usec;
@@ -328,41 +319,20 @@ class OutputPage {
$elapsed = $now - $start;
if ( "" != $wgDebugLogFile ) {
- $prof = "";
- if( $wgProfiling and count( $wgProfileStack ) ) {
- $lasttime = $start;
- foreach( $wgProfileStack as $ile ) {
- # "foo::bar 99 0.12345 1 0.23456 2"
- if( preg_match( '/^(\S+)\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)/', $ile, $m ) ) {
- $thisstart = (float)$m[3] + (float)$m[4] - $start;
- $thisend = (float)$m[5] + (float)$m[6] - $start;
- $thiselapsed = $thisend - $thisstart;
- $thispercent = $thiselapsed / $elapsed * 100.0;
-
- $prof .= sprintf( "\tat %04.3f in %04.3f (%2.1f%%) - %s %s\n",
- $thisstart, $thiselapsed, $thispercent,
- str_repeat( "*", $m[2] ), $m[1] );
- $lasttime = $thistime;
- #$prof .= "\t(^ $ile)\n";
- } else {
- $prof .= "\t?broken? $ile\n";
- }
- }
- }
-
- if( $forward = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'] )
- $forward = " forwarded for $forward";
- if( $client = $HTTP_SERVER_VARS['HTTP_CLIENT_IP'] )
- $forward .= " client IP $client";
- if( $from = $HTTP_SERVER_VARS['HTTP_FROM'] )
- $forward .= " from $from";
+ $prof = wfGetProfilingOutput( $start, $elapsed );
+ if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
+ $forward = " forwarded for " . $_SERVER['HTTP_X_FORWARDED_FOR'];
+ if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
+ $forward .= " client IP " . $_SERVER['HTTP_CLIENT_IP'];
+ if( !empty( $_SERVER['HTTP_FROM'] ) )
+ $forward .= " from " . $_SERVER['HTTP_FROM'];
if( $forward )
- $forward = "\t(proxied via {$HTTP_SERVER_VARS['REMOTE_ADDR']}{$forward})";
+ $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
if($wgUser->getId() == 0)
$forward .= " anon";
$log = sprintf( "%s\t%04.3f\t%s\n",
gmdate( "YmdHis" ), $elapsed,
- urldecode( $HTTP_SERVER_VARS['REQUEST_URI'] . $forward ) );
+ urldecode( $_SERVER['REQUEST_URI'] . $forward ) );
error_log( $log . $prof, 3, $wgDebugLogFile );
}
$com = sprintf( "",
@@ -403,8 +373,7 @@ class OutputPage {
$sk = $wgUser->getSkin();
$ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
- $text = str_replace( "$1", $ap, wfMsg( "sysoptext" ) );
- $this->addHTML( $text );
+ $this->addHTML( wfMsg( "sysoptext", $ap ) );
$this->returnToMain();
}
@@ -420,8 +389,7 @@ class OutputPage {
$sk = $wgUser->getSkin();
$ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
- $text = str_replace( "$1", $ap, wfMsg( "developertext" ) );
- $this->addHTML( $text );
+ $this->addHTML( wfMsg( "developertext", $ap ) );
$this->returnToMain();
}
@@ -436,7 +404,7 @@ class OutputPage {
if ( $wgCommandLineMode ) {
$msg = wfMsgNoDB( "dberrortextcl" );
} else {
- $msg = wfMsgNoDB( "dberrortextcl" );
+ $msg = wfMsgNoDB( "dberrortext" );
}
$msg = str_replace( "$1", htmlspecialchars( wfLastDBquery() ), $msg );
@@ -458,25 +426,30 @@ class OutputPage {
exit();
}
- function readOnlyPage( $source = "" )
+ function readOnlyPage( $source = "", $protected = false )
{
global $wgUser, $wgReadOnlyFile;
- $this->setPageTitle( wfMsg( "readonly" ) );
$this->setRobotpolicy( "noindex,nofollow" );
$this->setArticleFlag( false );
- $reason = implode( "", file( $wgReadOnlyFile ) );
- $text = str_replace( "$1", $reason, wfMsg( "readonlytext" ) );
+ if( $protected ) {
+ $this->setPageTitle( wfMsg( "viewsource" ) );
+ $this->addWikiText( wfMsg( "protectedtext" ) );
+ } else {
+ $this->setPageTitle( wfMsg( "readonly" ) );
+ $reason = file_get_contents( $wgReadOnlyFile );
+ $this->addHTML( wfMsg( "readonlytext", $reason ) );
+ }
if($source) {
$rows = $wgUser->getOption( "rows" );
$cols = $wgUser->getOption( "cols" );
$text .= "
\n";
+ $this->addHTML( $text );
}
- $this->addHTML( $text );
$this->returnToMain( false );
}
@@ -493,35 +466,27 @@ class OutputPage {
function unexpectedValueError( $name, $val )
{
- $msg = str_replace( "$1", $name, wfMsg( "unexpected" ) );
- $msg = str_replace( "$2", $val, $msg );
- $this->fatalError( $msg );
+ $this->fatalError( wfMsg( "unexpected", $name, $val ) );
}
function fileCopyError( $old, $new )
{
- $msg = str_replace( "$1", $old, wfMsg( "filecopyerror" ) );
- $msg = str_replace( "$2", $new, $msg );
- $this->fatalError( $msg );
+ $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
}
function fileRenameError( $old, $new )
{
- $msg = str_replace( "$1", $old, wfMsg( "filerenameerror" ) );
- $msg = str_replace( "$2", $new, $msg );
- $this->fatalError( $msg );
+ $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
}
function fileDeleteError( $name )
{
- $msg = str_replace( "$1", $name, wfMsg( "filedeleteerror" ) );
- $this->fatalError( $msg );
+ $this->fatalError( wfMsg( "filedeleteerror", $name ) );
}
function fileNotFoundError( $name )
{
- $msg = str_replace( "$1", $name, wfMsg( "filenotfound" ) );
- $this->fatalError( $msg );
+ $this->fatalError( wfMsg( "filenotfound", $name ) );
}
function returnToMain( $auto = true )
@@ -534,7 +499,7 @@ class OutputPage {
}
$link = $sk->makeKnownLink( $returnto, "" );
- $r = str_replace( "$1", $link, wfMsg( "returnto" ) );
+ $r = wfMsg( "returnto", $link );
if ( $auto ) {
$wgOut->addMeta( "http:Refresh", "10;url=" .
wfLocalUrlE( wfUrlencode( $returnto ) ) );
@@ -570,11 +535,11 @@ class OutputPage {
# $t = $t->getText() ;
$t = $x->l_from ;
$y = explode ( ":" , $t , 2 ) ;
- if ( count ( $y ) == 2 && $y[0] == $cat )
- {
+ if ( count ( $y ) == 2 && $y[0] == $cat ) {
array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ;
+ } else {
+ array_push ( $articles , $sk->makeLink ( $t ) ) ;
}
- else array_push ( $articles , $sk->makeLink ( $t ) ) ;
}
wfFreeResult ( $res ) ;
@@ -590,7 +555,7 @@ class OutputPage {
if ( count ( $articles ) > 0 )
{
asort ( $articles ) ;
- $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ;
+ $h = wfMsg( "category_header", $ti[1] );
$r .= "{$h}
\n" ;
$r .= implode ( ", " , $articles ) ;
}
@@ -734,7 +699,8 @@ $t[] = "" ;
function doWikiPass2( $text, $linestart )
{
global $wgUser, $wgLang, $wgUseDynamicDates;
- wfProfileIn( "OutputPage::doWikiPass2" );
+ $fname = "OutputPage::doWikiPass2";
+ wfProfileIn( $fname );
$text = $this->removeHTMLtags( $text );
$text = $this->replaceVariables( $text );
@@ -760,9 +726,9 @@ $t[] = "" ;
$sk = $wgUser->getSkin();
$text = $sk->transformContent( $text );
- $text .= $this->categoryMagic () ;
+ $text .= $this->categoryMagic () ;
- wfProfileOut();
+ wfProfileOut( $fname );
return $text;
}
@@ -840,14 +806,15 @@ $t[] = "" ;
/* private */ function replaceExternalLinks( $text )
{
- wfProfileIn( "OutputPage::replaceExternalLinks" );
+ $fname = "OutputPage::replaceExternalLinks";
+ wfProfileIn( $fname );
$text = $this->subReplaceExternalLinks( $text, "http", true );
$text = $this->subReplaceExternalLinks( $text, "https", true );
$text = $this->subReplaceExternalLinks( $text, "ftp", false );
$text = $this->subReplaceExternalLinks( $text, "gopher", false );
$text = $this->subReplaceExternalLinks( $text, "news", false );
$text = $this->subReplaceExternalLinks( $text, "mailto", false );
- wfProfileOut();
+ wfProfileOut( $fname );
return $text;
}
@@ -933,63 +900,67 @@ $t[] = "" ;
$s = array_shift( $a );
$s = substr( $s, 1 );
- $e1 = "/^([{$tc}]+)\\|([^]]+)]](.*)\$/sD";
- $e2 = "/^([{$tc}]+)]](.*)\$/sD";
- wfProfileOut();
+ $e1 = "/^([{$tc}]+)(?:\\|([^]]+))?]](.*)\$/sD";
+
+ # Special and Media are pseudo-namespaces; no pages actually exist in them
+ $image = Namespace::getImage();
+ $special = Namespace::getSpecial();
+ $media = Namespace::getMedia();
+ $nottalk = !Namespace::isTalk( $wgTitle->getNamespace() );
+ wfProfileOut( "$fname-setup" );
foreach ( $a as $line ) {
- wfProfileIn( "$fname-loop" );
- if ( preg_match( $e1, $line, $m ) ) { # page with alternate text
-
+ if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
$text = $m[2];
$trail = $m[3];
-
- } else if ( preg_match( $e2, $line, $m ) ) { # page with normal text
-
- $text = "";
- $trail = $m[2];
- }
-
- else { # Invalid form; output directly
+ } else { # Invalid form; output directly
$s .= "[[" . $line ;
- wfProfileOut();
continue;
}
- if(substr($m[1],0,1)=="/") { # subpage
+
+ /* Valid link forms:
+ Foobar -- normal
+ :Foobar -- override special treatment of prefix (images, language links)
+ /Foobar -- convert to CurrentPage/Foobar
+ /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
+ */
+ $c = substr($m[1],0,1);
+ $noforce = ($c != ":");
+ if( $c == "/" ) { # subpage
if(substr($m[1],-1,1)=="/") { # / at end means we don't want the slash to be shown
$m[1]=substr($m[1],1,strlen($m[1])-2);
$noslash=$m[1];
-
} else {
$noslash=substr($m[1],1);
}
if($wgNamespacesWithSubpages[$wgTitle->getNamespace()]) { # subpages allowed here
$link = $wgTitle->getPrefixedText(). "/" . trim($noslash);
- if(!$text) {
+ if(!$text) {
$text= $m[1];
} # this might be changed for ugliness reasons
} else {
$link = $noslash; # no subpage allowed, use standard link
}
- } else { # no subpage
- $link = $m[1];
+ } elseif( $noforce ) { # no subpage
+ $link = $m[1];
+ } else {
+ $link = substr( $m[1], 1 );
}
+ if( empty( $text ) )
+ $text = $link;
- if ( preg_match( "/^((?:i|x|[a-z]{2,3})(?:-[a-z0-9]+)?|[A-Za-z\\x80-\\xff]+):(.*)\$/", $link, $m ) ) {
- $pre = strtolower( $m[1] );
- $suf = trim($m[2]);
- if( empty( $suf ) ) {
- $s .= $trail;
- } else if ( $wgLang->getNsIndex( $pre ) ==
- Namespace::getImage() ) {
- $nt = Title::newFromText( $suf );
- $name = $nt->getDBkey();
- if ( "" == $text ) { $text = $nt->GetText(); }
-
- $wgLinkCache->addImageLink( $name );
- $s .= $sk->makeImageLink( $name,
- wfImageUrl( $name ), $text );
+ $nt = Title::newFromText( $link );
+ if( !$nt ) {
+ $s .= "[[" . $line;
+ continue;
+ }
+ $ns = $nt->getNamespace();
+ $iw = $nt->getInterWiki();
+ if( $noforce ) {
+ if( $iw && $wgInterwikiMagic && $nottalk && $wgLang->getLanguageName( $iw ) ) {
+ array_push( $this->mLanguageLinks, $nt->getPrefixedText() );
$s .= $trail;
+/* CHECK MERGE @@@
} else if ( "media" == $pre ) {
$nt = Title::newFromText( $suf );
$name = $nt->getDBkey();
@@ -999,31 +970,50 @@ $t[] = "" ;
$s .= $sk->makeMediaLink( $name,
wfImageUrl( $name ), $text );
$s .= $trail;
- } else if ( isset($wgUseCategoryMagic) && $wgUseCategoryMagic && $pre == wfMsg ( "category" ) ) {
- $l = $sk->makeLink ( $pre.":".ucfirst($m[2]) , ucfirst ( $m[2] ) ) ;
- array_push ( $this->mCategoryLinks , $l ) ;
- $s .= $trail ;
+ } else if ( isset($wgUseCategoryMagic) && $wgUseCategoryMagic && $pre == wfMsg ( "category" ) ) {
+ $l = $sk->makeLink ( $pre.":".ucfirst( $m[2] ), ucfirst ( $m[2] ) ) ;
+ array_push ( $this->mCategoryLinks , $l ) ;
+ $s .= $trail ;
} else {
$l = $wgLang->getLanguageName( $pre );
- if ( "" == $l or !$wgInterwikiMagic or
- Namespace::isTalk( $wgTitle->getNamespace() ) ) {
- if ( "" == $text ) { $text = $link; }
+ if ( "" == $l or !$wgInterwikiMagic or Namespace::isTalk( $wgTitle->getNamespace() ) ) {
+ if ( "" == $text ) {
+ $text = $link;
+ }
$s .= $sk->makeLink( $link, $text, "", $trail );
} else if ( $pre != $wgLanguageCode ) {
array_push( $this->mLanguageLinks, "$pre:$suf" );
$s .= $trail;
}
+*/
+ continue;
+ }
+ if( $ns == $image ) {
+ $s .= $sk->makeImageLinkObj( $nt, $text ) . $trail;
+ $wgLinkCache->addImageLinkObj( $nt );
+ continue;
}
+/* CHECK MERGE @@@
# } else if ( 0 == strcmp( "##", substr( $link, 0, 2 ) ) ) {
# $link = substr( $link, 2 );
# $s .= "{$text}{$trail}";
} else {
if ( "" == $text ) { $text = $link; }
+ # Hotspot:
$s .= $sk->makeLink( $link, $text, "", $trail );
+*/
}
- wfProfileOut();
+ if( $ns == $media ) {
+ $s .= $sk->makeMediaLinkObj( $nt, $text ) . $trail;
+ $wgLinkCache->addImageLinkObj( $nt );
+ continue;
+ } elseif( $ns == $special ) {
+ $s .= $sk->makeKnownLinkObj( $nt, $text, "", $trail );
+ continue;
+ }
+ $s .= $sk->makeLinkObj( $nt, $text, "", $trail );
}
- wfProfileOut();
+ wfProfileOut( $fname );
return $s;
}
@@ -1106,7 +1096,8 @@ $t[] = "" ;
/* private */ function doBlockLevels( $text, $linestart )
{
- wfProfileIn( "OutputPage::doBlockLevels" );
+ $fname = "OutputPage::doBlockLevels";
+ wfProfileIn( $fname );
# Parsing through the text line by line. The main thing
# happening here is handling of block-level elements p, pre,
# and making lists from lines starting with * # : etc.
@@ -1205,17 +1196,22 @@ $t[] = "" ;
}
$this->mLastSection = "";
}
- wfProfileOut();
+ wfProfileOut( $fname );
return $text;
}
/* private */ function replaceVariables( $text )
{
global $wgLang;
- wfProfileIn( "OutputPage:replaceVariables" );
+ $fname = "OutputPage::replaceVariables";
+ wfProfileIn( $fname );
+
+
+ # Basic variables
+ # See Language.php for the definition of each magic word
- /* As with sigs, use server's local time --
- ensure this is appropriate for your audience! */
+ # As with sigs, this uses the server's local time -- ensure
+ # this is appropriate for your audience!
$v = date( "m" );
$mw =& MagicWord::get( MAG_CURRENTMONTH );
$text = $mw->replace( $v, $text );
@@ -1250,20 +1246,23 @@ $t[] = "" ;
$text = $mw->replace( $v, $text );
}
- # The callbacks are in GlobalFunctions.php
+ # "Variables" with an additional parameter e.g. {{MSG:wikipedia}}
+ # The callbacks are at the bottom of this file
$mw =& MagicWord::get( MAG_MSG );
- $text = $mw->substituteCallback( $text, "replaceMsgVar" );
+ $text = $mw->substituteCallback( $text, "wfReplaceMsgVar" );
$mw =& MagicWord::get( MAG_MSGNW );
- $text = $mw->substituteCallback( $text, "replaceMsgVarNw" );
+ $text = $mw->substituteCallback( $text, "wfReplaceMsgnwVar" );
- wfProfileOut();
+ wfProfileOut( $fname );
return $text;
}
+ # Cleans up HTML, removes dangerous tags and attributes
/* private */ function removeHTMLtags( $text )
{
- wfProfileIn( "OutputPage::removeHTMLtags" );
+ $fname = "OutputPage::removeHTMLtags";
+ wfProfileIn( $fname );
$htmlpairs = array( # Tags that must be closed
"b", "i", "u", "font", "big", "small", "sub", "sup", "h1",
"h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
@@ -1350,7 +1349,7 @@ $t[] = "" ;
$text .= "$t>\n";
if ( $t == "table" ) { $tagstack = array_pop( $tablestack ); }
}
- wfProfileOut();
+ wfProfileOut( $fname );
return $text;
}
@@ -1439,6 +1438,7 @@ $t[] = "" ;
}
}
+ // The canonized header is a version of the header text safe to use for links
$canonized_headline=preg_replace("/<.*?>/","",$headline); // strip out HTML
$tocline=$canonized_headline;
@@ -1447,12 +1447,20 @@ $t[] = "" ;
$refer[$c]=$canonized_headline;
$refers[$canonized_headline]++; // count how many in assoc. array so we can track dupes in anchors
$refcount[$c]=$refers[$canonized_headline];
+
+ // Prepend the number to the heading text
+
if($nh||$st) {
$tocline=$numbering ." ". $tocline;
- if($nh) {
+
+ // Don't number the heading if it is the only one (looks silly)
+ if($nh && count($matches[3]) > 1) {
$headline=$numbering . " " . $headline; // the two are different if the line contains a link
- }
+ }
}
+
+ // Create the anchor for linking from the TOC to the section
+
$anchor=$canonized_headline;
if($refcount[$c]>1) {$anchor.="_".$refcount[$c];}
if($st) {
@@ -1461,14 +1469,21 @@ $t[] = "" ;
if($es && !isset($wpPreview)) {
$head[$c].=$sk->editSectionLink($c+1);
}
- $head[$c].=""
.$headline
.""
- ."";
+ ."";
+
+ // Add the edit section link
+
if($esr && !isset($wpPreview)) {
$head[$c]=$sk->editSectionScript($c+1,$head[$c]);
}
+
$numbering="";
$c++;
$dot=0;
@@ -1485,12 +1500,11 @@ $t[] = "" ;
$blocks=preg_split("/.*?<\/H[1-6]>/i",$text);
$i=0;
-
foreach($blocks as $block) {
if(($es) && !isset($wpPreview) && $c>0 && $i==0) {
# This is the [edit] link that appears for the top block of text when
# section editing is enabled
- $full.=$sk->editSectionLink(0);
+ $full.=$sk->editSectionLink(0);
}
$full.=$block;
if($st && $toclines>3 && !$i) {
@@ -1501,6 +1515,7 @@ $t[] = "" ;
$full.=$head[$i];
$i++;
}
+
return $full;
}
@@ -1511,30 +1526,30 @@ $t[] = "" ;
$a = split( "ISBN ", " $text" );
if ( count ( $a ) < 2 ) return $text;
$text = substr( array_shift( $a ), 1);
- $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
foreach ( $a as $x ) {
$isbn = $blank = "" ;
while ( " " == $x{0} ) {
- $blank .= " ";
- $x = substr( $x, 1 );
+ $blank .= " ";
+ $x = substr( $x, 1 );
}
- while ( strstr( $valid, $x{0} ) != false ) {
+ while ( strstr( $valid, $x{0} ) != false ) {
$isbn .= $x{0};
$x = substr( $x, 1 );
}
- $num = str_replace( "-", "", $isbn );
- $num = str_replace( " ", "", $num );
+ $num = str_replace( "-", "", $isbn );
+ $num = str_replace( " ", "", $num );
- if ( "" == $num ) {
+ if ( "" == $num ) {
$text .= "ISBN $blank$x";
- } else {
+ } else {
$text .= "specialPage(
- "Booksources"), "isbn={$num}" ) . "\" CLASS=\"internal\">ISBN $isbn";
+ "Booksources"), "isbn={$num}" ) . "\" class=\"internal\">ISBN $isbn";
$text .= $x;
}
}
- return $text;
+ return $text;
}
/* private */ function magicRFC( $text )
@@ -1586,4 +1601,22 @@ $t[] = "" ;
}
}
+# Regex callbacks, used in OutputPage::replaceVariables
+
+# Just get rid of the dangerous stuff
+# Necessary because replaceVariables is called after removeHTMLtags,
+# and message text can come from any user
+function wfReplaceMsgVar( $matches ) {
+ global $wgOut;
+ $text = $wgOut->removeHTMLtags( wfMsg( $matches[1] ) );
+ return $text;
+}
+
+# Effective
+# Not real because this is called after nowiki sections are processed
+function wfReplaceMsgnwVar( $matches ) {
+ $text = wfEscapeWikiText( wfMsg( $matches[1] ) );
+ return $text;
+}
+
?>