(bug 5167) Add {{SUBPAGENAME}} variable
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index a3f5b4a..215212e 100644 (file)
@@ -223,7 +223,8 @@ function wfDebugLog( $logGroup, $text, $public = true ) {
        global $wgDebugLogGroups, $wgDBname;
        if( $text{strlen( $text ) - 1} != "\n" ) $text .= "\n";
        if( isset( $wgDebugLogGroups[$logGroup] ) ) {
-               @error_log( "$wgDBname: $text", 3, $wgDebugLogGroups[$logGroup] );
+               $time = wfTimestamp( TS_DB );
+               @error_log( "$time $wgDBname: $text", 3, $wgDebugLogGroups[$logGroup] );
        } else if ( $public === true ) {
                wfDebug( $text, true );
        }
@@ -405,11 +406,9 @@ function wfMsgNoDBForContent( $key ) {
  */
 function wfMsgReal( $key, $args, $useDB, $forContent=false, $transform = true ) {
        $fname = 'wfMsgReal';
-       wfProfileIn( $fname );
 
        $message = wfMsgGetKey( $key, $useDB, $forContent, $transform );
        $message = wfMsgReplaceArgs( $message, $args );
-       wfProfileOut( $fname );
        return $message;
 }
 
@@ -957,7 +956,28 @@ function wfEscapeShellArg( ) {
                }
 
                if ( wfIsWindows() ) {
-                       $retVal .= '"' . str_replace( '"','\"', $arg ) . '"';
+                       // Escaping for an MSVC-style command line parser
+                       // Ref: http://mailman.lyra.org/pipermail/scite-interest/2002-March/000436.html
+                       // Double the backslashes before any double quotes. Escape the double quotes.
+                       $tokens = preg_split( '/(\\\\*")/', $arg, -1, PREG_SPLIT_DELIM_CAPTURE );
+                       $arg = '';
+                       $delim = false;
+                       foreach ( $tokens as $token ) {
+                               if ( $delim ) {
+                                       $arg .= str_replace( '\\', '\\\\', substr( $token, 0, -1 ) ) . '\\"';
+                               } else {
+                                       $arg .= $token;
+                               }
+                               $delim = !$delim;
+                       }
+                       // Double the backslashes before the end of the string, because 
+                       // we will soon add a quote
+                       if ( preg_match( '/^(.*?)(\\\\+)$/', $arg, $m ) ) {
+                               $arg = $m[1] . str_replace( '\\', '\\\\', $m[2] );
+                       }
+
+                       // Add surrounding quotes
+                       $retVal .= '"' . $arg . '"';
                } else {
                        $retVal .= escapeshellarg( $arg );
                }
@@ -1389,6 +1409,28 @@ function wfGetCachedNotice( $name ) {
        return $notice;
 }
 
+function wfGetNamespaceNotice() {
+       global $wgTitle;
+       
+       # Paranoia
+       if ( !isset( $wgTitle ) || !is_object( $wgTitle ) )
+               return "";
+
+       $fname = 'wfGetNamespaceNotice';
+       wfProfileIn( $fname );
+       
+       $key = "namespacenotice-" . $wgTitle->getNsText();
+       $namespaceNotice = wfGetCachedNotice( $key );
+       if ( $namespaceNotice && substr ( $namespaceNotice , 0 ,7 ) != "<p>&lt;" ) {
+                $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . "</div>";
+       } else {
+               $namespaceNotice = "";
+       }
+
+       wfProfileOut( $fname );
+       return $namespaceNotice;
+}
+
 function wfGetSiteNotice() {
        global $wgUser, $wgSiteNotice;
        $fname = 'wfGetSiteNotice';
@@ -1406,7 +1448,7 @@ function wfGetSiteNotice() {
                        $siteNotice = $anonNotice;
                }
        }
-       
+
        wfProfileOut( $fname );
        return( $siteNotice );
 }
@@ -1483,7 +1525,7 @@ function &HTMLnamespaceselector($selected = '', $allnamespaces = null) {
                        $selected = intval( $selected );
                }
        }
-       $s = "<select name='namespace' class='namespaceselector'>\n\t";
+       $s = "<select id='namespace' name='namespace' class='namespaceselector'>\n\t";
        $arr = $wgContLang->getFormattedNamespaces();
        if( !is_null($allnamespaces) ) {
                $arr = array($allnamespaces => wfMsgHtml('namespacesall')) + $arr;
@@ -1580,6 +1622,19 @@ function wfMkdirParents( $fullDir, $mode ) {
  */
 function wfIncrStats( $key ) {
        global $wgDBname, $wgMemc;
+        /* LIVE HACK AVOID MEMCACHED ACCESSES DURING HIGH LOAD */
+        if ($wgDBname != 'enwiki' and $wgDBname != 'dewiki' and $wgDBname != 'commonswiki' and $wgDBname != 'testwiki')
+            return true;
+        static $socket;
+        if (!$socket) {
+            $socket=socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+            $statline="{$wgDBname} - 1 1 1 1 1 -total\n";
+            socket_sendto($socket,$statline,strlen($statline),0,"webster","3811");
+        }
+        $statline="{$wgDBname} - 1 1 1 1 1 {$key}\n";
+        socket_sendto($socket,$statline,strlen($statline),0,"webster","3811");
+        return true;
+
        $key = "$wgDBname:stats:$key";
        if ( is_null( $wgMemc->incr( $key ) ) ) {
                $wgMemc->add( $key, 1 );
@@ -1658,11 +1713,17 @@ function in_string( $needle, $str ) {
 function wfUrlProtocols() {
        global $wgUrlProtocols;
 
-       $protocols = array();
-       foreach ($wgUrlProtocols as $protocol)
-               $protocols[] = preg_quote( $protocol, '/' );
+       // Support old-style $wgUrlProtocols strings, for backwards compatibility 
+       // with LocalSettings files from 1.5
+       if ( is_array( $wgUrlProtocols ) ) {
+               $protocols = array();
+               foreach ($wgUrlProtocols as $protocol)
+                       $protocols[] = preg_quote( $protocol, '/' );
 
-       return implode( '|', $protocols );
+               return implode( '|', $protocols );
+       } else {
+               return $wgUrlProtocols;
+       }
 }
 
 /**
@@ -1730,6 +1791,10 @@ function wfShellExec( $cmd )
                                $cmd = escapeshellarg( $script ) . " $time $memKB $cmd";
                        }
                }
+       } elseif ( php_uname( 's' ) == 'Windows NT' ) {
+               # This is a hack to work around PHP's flawed invocation of cmd.exe
+               # http://news.php.net/php.internals/21796
+               $cmd = '"' . $cmd . '"';
        }
        return shell_exec( $cmd );
 }
@@ -1821,7 +1886,7 @@ function wfMakeUrlIndex( $url ) {
        // Reverse the labels in the hostname, convert to lower case
        $reversedHost = strtolower( implode( '.', array_reverse( explode( '.', $bits['host'] ) ) ) );
        // Add an extra dot to the end
-       if ( substr( $reversedHost, -1 ) !== '.' ) {
+       if ( substr( $reversedHost, -1, 1 ) !== '.' ) {
                $reversedHost .= '.';
        }
        // Reconstruct the pseudo-URL
@@ -1838,4 +1903,21 @@ function wfMakeUrlIndex( $url ) {
        return $index;
 }
 
+/**
+ * Do any deferred updates and clear the list
+ * TODO: This could be in Wiki.php if that class made any sense at all
+ */
+function wfDoUpdates()
+{
+       global $wgPostCommitUpdateList, $wgDeferredUpdateList;
+       foreach ( $wgDeferredUpdateList as $update ) { 
+               $update->doUpdate();
+       }
+       foreach ( $wgPostCommitUpdateList as $update ) {
+               $update->doUpdate();
+       }
+       $wgDeferredUpdateList = array();
+       $wgPostCommitUpdateList = array();
+}
+
 ?>