Tweaked location of profiling in query() to split out the implicit BEGIN
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index a44e45b..be4ec3e 100644 (file)
@@ -130,14 +130,16 @@ function wfArrayDiff2_cmp( $a, $b ) {
 
 /**
  * Array lookup
- * Returns an array where the values in the first array are replaced by the
- * values in the second array with the corresponding keys
+ * Returns an array where the values in array $b are replaced by the
+ * values in array $a with the corresponding keys
  *
+ * @deprecated since 1.22; use array_intersect_key()
  * @param $a Array
  * @param $b Array
  * @return array
  */
 function wfArrayLookup( $a, $b ) {
+       wfDeprecated( __FUNCTION__, '1.22' );
        return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
 }
 
@@ -163,11 +165,13 @@ function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) {
  * Backwards array plus for people who haven't bothered to read the PHP manual
  * XXX: will not darn your socks for you.
  *
+ * @deprecated since 1.22; use array_replace()
  * @param $array1 Array
  * @param [$array2, [...]] Arrays
  * @return Array
  */
 function wfArrayMerge( $array1/* ... */ ) {
+       wfDeprecated( __FUNCTION__, '1.22' );
        $args = func_get_args();
        $args = array_reverse( $args, true );
        $out = array();
@@ -875,10 +879,10 @@ function wfMakeUrlIndexes( $url ) {
 function wfMatchesDomainList( $url, $domains ) {
        $bits = wfParseUrl( $url );
        if ( is_array( $bits ) && isset( $bits['host'] ) ) {
+               $host = '.' . $bits['host'];
                foreach ( (array)$domains as $domain ) {
-                       // FIXME: This gives false positives. http://nds-nl.wikipedia.org will match nl.wikipedia.org
-                       // We should use something that interprets dots instead
-                       if ( substr( $bits['host'], -strlen( $domain ) ) === $domain ) {
+                       $domain = '.' . $domain;
+                       if ( substr( $host, -strlen( $domain ) ) === $domain ) {
                                return true;
                        }
                }
@@ -1221,36 +1225,31 @@ function wfIncrStats( $key, $count = 1 ) {
 }
 
 /**
- * Check if the wiki read-only lock file is present. This can be used to lock
- * off editing functions, but doesn't guarantee that the database will not be
- * modified.
+ * Check whether the wiki is in read-only mode.
  *
  * @return bool
  */
 function wfReadOnly() {
-       global $wgReadOnlyFile, $wgReadOnly;
-
-       if ( !is_null( $wgReadOnly ) ) {
-               return (bool)$wgReadOnly;
-       }
-       if ( $wgReadOnlyFile == '' ) {
-               return false;
-       }
-       // Set $wgReadOnly for faster access next time
-       if ( is_file( $wgReadOnlyFile ) ) {
-               $wgReadOnly = file_get_contents( $wgReadOnlyFile );
-       } else {
-               $wgReadOnly = false;
-       }
-       return (bool)$wgReadOnly;
+       return wfReadOnlyReason() !== false;
 }
 
 /**
- * @return bool
+ * Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
+ *
+ * @return string|bool: String when in read-only mode; false otherwise
  */
 function wfReadOnlyReason() {
-       global $wgReadOnly;
-       wfReadOnly();
+       global $wgReadOnly, $wgReadOnlyFile;
+
+       if ( $wgReadOnly === null ) {
+               // Set $wgReadOnly for faster access next time
+               if ( is_file( $wgReadOnlyFile ) && filesize( $wgReadOnlyFile ) > 0 ) {
+                       $wgReadOnly = file_get_contents( $wgReadOnlyFile );
+               } else {
+                       $wgReadOnly = false;
+               }
+       }
+
        return $wgReadOnly;
 }
 
@@ -1347,7 +1346,7 @@ function wfMessage( $key /*...*/) {
  */
 function wfMessageFallback( /*...*/ ) {
        $args = func_get_args();
-       return MWFunction::callArray( 'Message::newFallbackSequence', $args );
+       return call_user_func_array( 'Message::newFallbackSequence', $args );
 }
 
 /**
@@ -2024,9 +2023,11 @@ function wfEscapeWikiText( $text ) {
 
 /**
  * Get the current unix timestamp with microseconds.  Useful for profiling
+ * @deprecated since 1.22; call microtime() directly
  * @return Float
  */
 function wfTime() {
+       wfDeprecated( __FUNCTION__, '1.22' );
        return microtime( true );
 }
 
@@ -3299,6 +3300,27 @@ function wfFixSessionID() {
        }
 }
 
+/**
+ * Reset the session_id
+ * @since 1.22
+ */
+function wfResetSessionID() {
+       global $wgCookieSecure;
+       $oldSessionId = session_id();
+       $cookieParams = session_get_cookie_params();
+       if ( wfCheckEntropy() && $wgCookieSecure == $cookieParams['secure'] ) {
+               session_regenerate_id( false );
+       } else {
+               $tmp = $_SESSION;
+               session_destroy();
+               wfSetupSession( MWCryptRand::generateHex( 32 ) );
+               $_SESSION = $tmp;
+       }
+       $newSessionId = session_id();
+       wfRunHooks( 'ResetSessionID', array( $oldSessionId, $newSessionId ) );
+}
+
+
 /**
  * Initialise php session
  *
@@ -3384,7 +3406,7 @@ function wfForeignMemcKey( $db, $prefix /*, ... */ ) {
        } else {
                $key = $db . ':' . implode( ':', $args );
        }
-       return $key;
+       return str_replace( ' ', '_', $key );
 }
 
 /**
@@ -3750,22 +3772,17 @@ function wfBCP47( $code ) {
        $codeSegment = explode( '-', $code );
        $codeBCP = array();
        foreach ( $codeSegment as $segNo => $seg ) {
-               if ( count( $codeSegment ) > 0 ) {
-                       // when previous segment is x, it is a private segment and should be lc
-                       if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
-                               $codeBCP[$segNo] = strtolower( $seg );
-                       // ISO 3166 country code
-                       } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
-                               $codeBCP[$segNo] = strtoupper( $seg );
-                       // ISO 15924 script code
-                       } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
-                               $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
-                       // Use lowercase for other cases
-                       } else {
-                               $codeBCP[$segNo] = strtolower( $seg );
-                       }
+               // when previous segment is x, it is a private segment and should be lc
+               if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
+                       $codeBCP[$segNo] = strtolower( $seg );
+               // ISO 3166 country code
+               } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
+                       $codeBCP[$segNo] = strtoupper( $seg );
+               // ISO 15924 script code
+               } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
+                       $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
+               // Use lowercase for other cases
                } else {
-               // Use lowercase for single segment
                        $codeBCP[$segNo] = strtolower( $seg );
                }
        }