Use eval "$4" instead of "$@", so that shell metacharacters such as "(" are understood
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index c89bac3..1ffde74 100644 (file)
@@ -22,7 +22,6 @@ $wgTotalViews = -1;
 $wgTotalEdits = -1;
 
 
-global $IP;
 require_once dirname(__FILE__) . '/LogPage.php';
 require_once dirname(__FILE__) . '/normal/UtfNormalUtil.php';
 require_once dirname(__FILE__) . '/XmlFunctions.php';
@@ -68,7 +67,7 @@ if ( !function_exists( 'mb_strlen' ) ) {
         * @param string $enc optional encoding; ignored
         * @return int
         */
-       function new_mb_strlen( $str, $enc="" ) {
+       function mb_strlen( $str, $enc="" ) {
                $counts = count_chars( $str );
                $total = 0;
 
@@ -240,7 +239,7 @@ function wfLogDBError( $text ) {
 function wfErrorLog( $text, $file ) {
        wfSuppressWarnings();
        $exists = file_exists( $file );
-       $size = filesize( $file );
+       $size = $exists ? filesize( $file ) : false;
        if ( !$exists || ( $size !== false && $size + strlen( $text ) < 0x7fffffff ) ) {
                error_log( $text, 3, $file );
        }
@@ -559,11 +558,11 @@ function wfMsgWikiHtml( $key ) {
  * Returns message in the requested format
  * @param string $key Key of the message
  * @param array $options Processing rules:
- *  <i>parse<i>: parses wikitext to html
- *  <i>parseinline<i>: parses wikitext to html and removes the surrounding p's added by parser or tidy
- *  <i>escape<i>: filters message trough htmlspecialchars
- *  <i>replaceafter<i>: parameters are substituted after parsing or escaping
- *  <i>parsemag<i>: transform the message using magic phrases
+ *  <i>parse</i>: parses wikitext to html
+ *  <i>parseinline</i>: parses wikitext to html and removes the surrounding p's added by parser or tidy
+ *  <i>escape</i>: filters message trough htmlspecialchars
+ *  <i>replaceafter</i>: parameters are substituted after parsing or escaping
+ *  <i>parsemag</i>: transform the message using magic phrases
  */
 function wfMsgExt( $key, $options ) {
        global $wgOut, $wgParser;
@@ -613,7 +612,7 @@ function wfMsgExt( $key, $options ) {
  * Just like exit() but makes a note of it.
  * Commits open transactions except if the error parameter is set
  *
- * @obsolete Please return control to the caller or throw an exception
+ * @deprecated Please return control to the caller or throw an exception
  */
 function wfAbruptExit( $error = false ){
        global $wgLoadBalancer;
@@ -643,7 +642,7 @@ function wfAbruptExit( $error = false ){
 }
 
 /**
- * @obsolete Please return control the caller or throw an exception
+ * @deprecated Please return control the caller or throw an exception
  */
 function wfErrorExit() {
        wfAbruptExit( true );
@@ -984,6 +983,26 @@ function wfArrayToCGI( $array1, $array2 = NULL )
        return $cgi;
 }
 
+/**
+ * Append a query string to an existing URL, which may or may not already
+ * have query string parameters already. If so, they will be combined.
+ *
+ * @param string $url
+ * @param string $query
+ * @return string
+ */
+function wfAppendQuery( $url, $query ) {
+       if( $query != '' ) {
+               if( false === strpos( $url, '?' ) ) {
+                       $url .= '?';
+               } else {
+                       $url .= '&';
+               }
+               $url .= $query;
+       }
+       return $url;
+}
+
 /**
  * This is obsolete, use SquidUpdate::purge()
  * @deprecated
@@ -1148,7 +1167,7 @@ function wfHttpError( $code, $label, $desc ) {
  * Note that some PHP configuration options may add output buffer
  * layers which cannot be removed; these are left in place.
  *
- * @parameter bool $resetGzipEncoding
+ * @param bool $resetGzipEncoding
  */
 function wfResetOutputBuffers( $resetGzipEncoding=true ) {
        if( $resetGzipEncoding ) {
@@ -1382,7 +1401,7 @@ define('TS_ISO_8601', 4);
 /**
  * An Exif timestamp (YYYY:MM:DD HH:MM:SS)
  *
- * @url http://exif.org/Exif2-2.PDF The Exif 2.2 spec, see page 28 for the
+ * @see http://exif.org/Exif2-2.PDF The Exif 2.2 spec, see page 28 for the
  *       DateTime tag and page 36 for the DateTimeOriginal and
  *       DateTimeDigitized tags.
  */
@@ -1801,14 +1820,14 @@ function wfShellExec( $cmd, &$retval=null ) {
        }
 
        if ( php_uname( 's' ) == 'Linux' ) {
-               $time = ini_get( 'max_execution_time' );
+               $time = intval( ini_get( 'max_execution_time' ) );
                $mem = intval( $wgMaxShellMemory );
                $filesize = intval( $wgMaxShellFileSize );
 
                if ( $time > 0 && $mem > 0 ) {
-                       $script = "$IP/bin/ulimit-tvf.sh";
+                       $script = "$IP/bin/ulimit4.sh";
                        if ( is_executable( $script ) ) {
-                               $cmd = escapeshellarg( $script ) . " $time $mem $filesize $cmd";
+                               $cmd = escapeshellarg( $script ) . " $time $mem $filesize " . escapeshellarg( $cmd );
                        }
                }
        } elseif ( php_uname( 's' ) == 'Windows NT' ) {
@@ -1933,20 +1952,45 @@ function wfRelativePath( $path, $from ) {
  * Make a URL index, appropriate for the el_index field of externallinks.
  */
 function wfMakeUrlIndex( $url ) {
-       wfSuppressWarnings();
+       global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php
        $bits = parse_url( $url );
+       wfSuppressWarnings();
        wfRestoreWarnings();
-       if ( !$bits || $bits['scheme'] !== 'http' ) {
+       if ( !$bits ) {
                return false;
        }
+       // most of the protocols are followed by ://, but mailto: and sometimes news: not, check for it
+       $delimiter = '';
+       if ( in_array( $bits['scheme'] . '://' , $wgUrlProtocols ) ) {
+               $delimiter = '://';
+       } elseif ( in_array( $bits['scheme'] .':' , $wgUrlProtocols ) ) {
+               $delimiter = ':';
+               // parse_url detects for news: and mailto: the host part of an url as path
+               // We have to correct this wrong detection
+               if ( isset ( $bits['path'] ) ) { 
+                       $bits['host'] = $bits['path'];
+                       $bits['path'] = '';
+               }
+       } else {
+               return false;
+       }
+
        // Reverse the labels in the hostname, convert to lower case
-       $reversedHost = strtolower( implode( '.', array_reverse( explode( '.', $bits['host'] ) ) ) );
+       // For emails reverse domainpart only
+       if ( $bits['scheme'] == 'mailto' ) {
+               $mailparts = explode( '@', $bits['host'] );
+               $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) );
+               $reversedHost = $domainpart . '@' . $mailparts[0];
+       } else {
+               $reversedHost = strtolower( implode( '.', array_reverse( explode( '.', $bits['host'] ) ) ) );
+       }
        // Add an extra dot to the end
        if ( substr( $reversedHost, -1, 1 ) !== '.' ) {
                $reversedHost .= '.';
        }
        // Reconstruct the pseudo-URL
-       $index = "http://$reversedHost";
+       $prot = $bits['scheme'];
+       $index = "$prot$delimiter$reversedHost";
        // Leave out user and password. Add the port, path, query and fragment
        if ( isset( $bits['port'] ) )      $index .= ':' . $bits['port'];
        if ( isset( $bits['path'] ) ) {
@@ -1994,6 +2038,7 @@ function wfExplodeMarkup( $separator, $text ) {
  * @param $sourceBase int 2-36
  * @param $destBase int 2-36
  * @param $pad int 1 or greater
+ * @param $lowercase bool
  * @return string or false on invalid input
  */
 function wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true ) {