Merge "Add way of including all stderr output when executing command"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 90d78ca..ba60fd8 100644 (file)
@@ -93,6 +93,18 @@ if ( !function_exists( 'mb_strrpos' ) ) {
                return Fallback::mb_strrpos( $haystack, $needle, $offset, $encoding );
        }
 }
+
+// gzdecode function only exists in PHP >= 5.4.0
+// http://php.net/gzdecode
+if ( !function_exists( 'gzdecode' ) ) {
+       /**
+        * @codeCoverageIgnore
+        * @return string
+        */
+       function gzdecode( $data ) {
+               return gzinflate( substr( $data, 10, -8 ) );
+       }
+}
 /// @endcond
 
 /**
@@ -106,12 +118,12 @@ function wfArrayDiff2( $a, $b ) {
 }
 
 /**
- * @param $a
- * @param $b
+ * @param $a array|string
+ * @param $b array|string
  * @return int
  */
 function wfArrayDiff2_cmp( $a, $b ) {
-       if ( !is_array( $a ) ) {
+       if ( is_string( $a ) && is_string( $b ) ) {
                return strcmp( $a, $b );
        } elseif ( count( $a ) !== count( $b ) ) {
                return count( $a ) < count( $b ) ? -1 : 1;
@@ -1691,10 +1703,12 @@ function wfEmptyMsg( $key ) {
  * Throw a debugging exception. This function previously once exited the process,
  * but now throws an exception instead, with similar results.
  *
+ * @deprecated since 1.22; just throw an MWException yourself
  * @param string $msg message shown when dying.
  * @throws MWException
  */
 function wfDebugDieBacktrace( $msg = '' ) {
+       wfDeprecated( __FUNCTION__, '1.22' );
        throw new MWException( $msg );
 }
 
@@ -2020,6 +2034,10 @@ function wfEscapeWikiText( $text ) {
                        "\n*" => "\n&#42;", "\r*" => "\r&#42;",
                        "\n:" => "\n&#58;", "\r:" => "\r&#58;",
                        "\n " => "\n&#32;", "\r " => "\r&#32;",
+                       "\n\n" => "\n&#10;", "\r\n" => "&#13;\n",
+                       "\n\r" => "\n&#13;", "\r\r" => "\r&#13;",
+                       "\n\t" => "\n&#9;", "\r\t" => "\r&#9;", // "\n\t\n" is treated like "\n\n"
+                       "\n----" => "\n&#45;---", "\r----" => "\r&#45;---",
                        '__' => '_&#95;', '://' => '&#58;//',
                );
 
@@ -2521,7 +2539,7 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) {
                wfDebug( "$caller: called wfMkdirParents($dir)\n" );
        }
 
-       if ( strval( $dir ) === '' || file_exists( $dir ) ) {
+       if ( strval( $dir ) === '' || ( file_exists( $dir ) && is_dir( $dir ) ) ) {
                return true;
        }
 
@@ -2537,6 +2555,11 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) {
        wfRestoreWarnings();
 
        if ( !$ok ) {
+               //directory may have been created on another request since we last checked
+               if ( is_dir( $dir ) ) {
+                       return true;
+               }
+
                // PHP doesn't report the path in its warning message, so add our own to aid in diagnosis.
                wfLogWarning( sprintf( "failed to mkdir \"%s\" mode 0%o", $dir, $mode ) );
        }