Localisation updates for extension messages from Betawiki (2008-07-11 11:00 CEST)
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 6bd1fb8..56a313f 100644 (file)
@@ -176,12 +176,16 @@ function wfDebug( $text, $logonly = false ) {
        global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
        static $recursion = 0;
 
+       static $cache = array(); // Cache of unoutputted messages
+
        # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
        if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) {
                return;
        }
 
        if ( $wgDebugComments && !$logonly ) {
+               $cache[] = $text;
+
                if ( !isset( $wgOut ) ) {
                        return;
                }
@@ -193,7 +197,10 @@ function wfDebug( $text, $logonly = false ) {
                        $wgOut->_unstub();
                        $recursion--;
                }
-               $wgOut->debug( $text );
+
+               // add the message and possible cached ones to the output
+               array_map( array( $wgOut, 'debug' ), $cache );
+               $cache = array();
        }
        if ( '' != $wgDebugLogFile && !$wgProfileOnly ) {
                # Strip unprintables; they can switch terminal modes when binary data
@@ -445,7 +452,7 @@ function wfMsgWeirdKey ( $key ) {
  * @param string $key
  * @param bool $useDB
  * @param string $langcode Code of the language to get the message for, or
- *                         behaves as a content language switch if it is a 
+ *                         behaves as a content language switch if it is a
  *                         boolean.
  * @return string
  * @private
@@ -453,6 +460,8 @@ function wfMsgWeirdKey ( $key ) {
 function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) {
        global $wgParser, $wgContLang, $wgMessageCache, $wgLang;
 
+       wfRunHooks('NormalizeMessageKey', array(&$key, &$useDB, &$langCode, &$transform));
+       
        # If $wgMessageCache isn't initialised yet, try to return something sensible.
        if( is_object( $wgMessageCache ) ) {
                $message = $wgMessageCache->get( $key, $useDB, $langCode );
@@ -587,7 +596,8 @@ function wfMsgExt( $key, $options ) {
                $langCode = $options['language'];
                $validCodes = array_keys( Language::getLanguageNames() );
                if( !in_array($options['language'], $validCodes) ) {
-                       $langCode = false;
+                       # Fallback to en, instead of whatever interface language we might have
+                       $langCode = 'en';
                }
        } else {
                $forContent = false;
@@ -1724,22 +1734,28 @@ function wfMkdirParents( $fullDir, $mode = 0777 ) {
                        $currentDir = substr( $currentDir, 0, $p );
                }
        }
-       
+
        if ( count( $createList ) == 0 ) {
                # Directory specified already exists
                return true;
        } elseif ( $currentDir === false ) {
                # Went all the way back to root and it apparently doesn't exist
+               wfDebugLog( 'mkdir', "Root doesn't exist?\n" );
                return false;
        }
-       
        # Now go forward creating directories
        $createList = array_reverse( $createList );
+
+       # Is the parent directory writable?
+       if ( $currentDir === '' ) {
+               $currentDir = '/';
+       }
+       if ( !is_writable( $currentDir ) ) {
+               wfDebugLog( 'mkdir', "Not writable: $currentDir\n" );
+               return false;
+       }
+
        foreach ( $createList as $dir ) {
-               # Check first to avoid spamming with warnings
-               if ( !is_writable( $dir ) ) {
-                       return false;
-               }
                # use chmod to override the umask, as suggested by the PHP manual
                if ( !mkdir( $dir, $mode ) || !chmod( $dir, $mode ) ) {
                        wfDebugLog( 'mkdir', "Unable to create directory $dir\n" );
@@ -1793,15 +1809,12 @@ function wfPercent( $nr, $acc = 2, $round = true ) {
  * @param string $userid ID of the user
  * @param string $password Password of the user
  * @return string Hashed password
+ * @deprecated Use User::crypt() or User::oldCrypt() instead
  */
 function wfEncryptPassword( $userid, $password ) {
-       global $wgPasswordSalt;
-       $p = md5( $password);
-
-       if($wgPasswordSalt)
-               return md5( "{$userid}-{$p}" );
-       else
-               return $p;
+       wfDeprecated(__FUNCTION__);
+       # Just wrap around User::oldCrypt()
+       return User::oldCrypt($password, $userid);
 }
 
 /**
@@ -2283,12 +2296,20 @@ function wfCreateObject( $name, $p ){
 }
 
 /**
- * Aliases for modularized functions
+ * Alias for modularized function
+ * @deprecated Use Http::get() instead
  */
 function wfGetHTTP( $url, $timeout = 'default' ) {
+       wfDeprecated(__FUNCTION__);
        return Http::get( $url, $timeout );
 }
+
+/**
+ * Alias for modularized function
+ * @deprecated Use Http::isLocalURL() instead
+ */
 function wfIsLocalURL( $url ) {
+       wfDeprecated(__FUNCTION__);
        return Http::isLocalURL( $url );
 }
 
@@ -2296,7 +2317,7 @@ function wfHttpOnlySafe() {
        global $wgHttpOnlyBlacklist;
        if( !version_compare("5.2", PHP_VERSION, "<") )
                return false;
-       
+
        if( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
                foreach( $wgHttpOnlyBlacklist as $regex ) {
                        if( preg_match( $regex, $_SERVER['HTTP_USER_AGENT'] ) ) {
@@ -2304,7 +2325,7 @@ function wfHttpOnlySafe() {
                        }
                }
        }
-       
+
        return true;
 }
 
@@ -2443,9 +2464,9 @@ function wfSplitWikiID( $wiki ) {
  *
  * @param string $wiki The wiki ID, or false for the current wiki
  *
- * Note: multiple calls to wfGetDB(DB_SLAVE) during the course of one request 
- * will always return the same object, unless the underlying connection or load 
- * balancer is manually destroyed. 
+ * Note: multiple calls to wfGetDB(DB_SLAVE) during the course of one request
+ * will always return the same object, unless the underlying connection or load
+ * balancer is manually destroyed.
  */
 function &wfGetDB( $db = DB_LAST, $groups = array(), $wiki = false ) {
        return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki );
@@ -2544,6 +2565,10 @@ function wfLoadExtensionMessages( $extensionName, $langcode = false ) {
                $loaded[$extensionName] = array();
        }
 
+       if ( !isset($wgExtensionMessagesFiles[$extensionName]) ) {
+               throw new MWException( "Messages file for extensions $extensionName is not defined" );
+       }
+
        if( !$langcode && !array_key_exists( '*', $loaded[$extensionName] ) ) {
                # Just do en, content language and user language.
                $wgMessageCache->loadMessagesFile( $wgExtensionMessagesFiles[$extensionName], false );
@@ -2660,3 +2685,13 @@ function wfGenerateToken( $salt = '' ) {
 
        return md5( mt_rand( 0, 0x7fffffff ) . $salt );
 }
+
+/**
+ * Replace all invalid characters with -
+ * @param mixed $title Filename to process
+ */
+function wfStripIllegalFilenameChars( $name ) {
+       $name = wfBaseName( $name );
+       $name = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name );
+       return $name;
+}