Merge "New hook for filters on Special:Contributions form"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 2b018d9..1f9d14e 100644 (file)
@@ -1460,120 +1460,6 @@ function wfMessageFallback( /*...*/ ) {
        return call_user_func_array( 'Message::newFallbackSequence', $args );
 }
 
-/**
- * Get a message from anywhere, for the current user language.
- *
- * Use wfMsgForContent() instead if the message should NOT
- * change depending on the user preferences.
- *
- * @deprecated since 1.18
- *
- * @param string $key Lookup key for the message, usually
- *    defined in languages/Language.php
- *
- * Parameters to the message, which can be used to insert variable text into
- * it, can be passed to this function in the following formats:
- * - One per argument, starting at the second parameter
- * - As an array in the second parameter
- * These are not shown in the function definition.
- *
- * @return string
- */
-function wfMsg( $key ) {
-       wfDeprecated( __METHOD__, '1.21' );
-
-       $args = func_get_args();
-       array_shift( $args );
-       return wfMsgReal( $key, $args );
-}
-
-/**
- * Get a message from anywhere, for the current global language
- * set with $wgLanguageCode.
- *
- * Use this if the message should NOT change dependent on the
- * language set in the user's preferences. This is the case for
- * most text written into logs, as well as link targets (such as
- * the name of the copyright policy page). Link titles, on the
- * other hand, should be shown in the UI language.
- *
- * Note that MediaWiki allows users to change the user interface
- * language in their preferences, but a single installation
- * typically only contains content in one language.
- *
- * Be wary of this distinction: If you use wfMsg() where you should
- * use wfMsgForContent(), a user of the software may have to
- * customize potentially hundreds of messages in
- * order to, e.g., fix a link in every possible language.
- *
- * @deprecated since 1.18
- *
- * @param string $key Lookup key for the message, usually
- *     defined in languages/Language.php
- * @return string
- */
-function wfMsgForContent( $key ) {
-       wfDeprecated( __METHOD__, '1.21' );
-
-       global $wgForceUIMsgAsContentMsg;
-       $args = func_get_args();
-       array_shift( $args );
-       $forcontent = true;
-       if ( is_array( $wgForceUIMsgAsContentMsg )
-               && in_array( $key, $wgForceUIMsgAsContentMsg )
-       ) {
-               $forcontent = false;
-       }
-       return wfMsgReal( $key, $args, true, $forcontent );
-}
-
-/**
- * Really get a message
- *
- * @deprecated since 1.18
- *
- * @param string $key Key to get.
- * @param array $args
- * @param bool $useDB
- * @param string|bool $forContent Language code, or false for user lang, true for content lang.
- * @param bool $transform Whether or not to transform the message.
- * @return string The requested message.
- */
-function wfMsgReal( $key, $args, $useDB = true, $forContent = false, $transform = true ) {
-       wfDeprecated( __METHOD__, '1.21' );
-
-       $message = wfMsgGetKey( $key, $useDB, $forContent, $transform );
-       $message = wfMsgReplaceArgs( $message, $args );
-       return $message;
-}
-
-/**
- * Fetch a message string value, but don't replace any keys yet.
- *
- * @deprecated since 1.18
- *
- * @param string $key
- * @param bool $useDB
- * @param string|bool $langCode Code of the language to get the message for, or
- *   behaves as a content language switch if it is a boolean.
- * @param bool $transform Whether to parse magic words, etc.
- * @return string
- */
-function wfMsgGetKey( $key, $useDB = true, $langCode = false, $transform = true ) {
-       wfDeprecated( __METHOD__, '1.21' );
-
-       Hooks::run( 'NormalizeMessageKey', array( &$key, &$useDB, &$langCode, &$transform ) );
-
-       $cache = MessageCache::singleton();
-       $message = $cache->get( $key, $useDB, $langCode );
-       if ( $message === false ) {
-               $message = '<' . htmlspecialchars( $key ) . '>';
-       } elseif ( $transform ) {
-               $message = $cache->transform( $message );
-       }
-       return $message;
-}
-
 /**
  * Replace message parameter keys on the given formatted output.
  *
@@ -1588,7 +1474,7 @@ function wfMsgReplaceArgs( $message, $args ) {
        $message = str_replace( "\r", '', $message );
 
        // Replace arguments
-       if ( count( $args ) ) {
+       if ( is_array( $args ) && $args ) {
                if ( is_array( $args[0] ) ) {
                        $args = array_values( $args[0] );
                }
@@ -1602,143 +1488,6 @@ function wfMsgReplaceArgs( $message, $args ) {
        return $message;
 }
 
-/**
- * Return an HTML-escaped version of a message.
- * Parameter replacements, if any, are done *after* the HTML-escaping,
- * so parameters may contain HTML (eg links or form controls). Be sure
- * to pre-escape them if you really do want plaintext, or just wrap
- * the whole thing in htmlspecialchars().
- *
- * @deprecated since 1.18
- *
- * @param string $key
- * @param string $args,... Parameters
- * @return string
- */
-function wfMsgHtml( $key ) {
-       wfDeprecated( __METHOD__, '1.21' );
-
-       $args = func_get_args();
-       array_shift( $args );
-       return wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $key ) ), $args );
-}
-
-/**
- * Return an HTML version of message
- * Parameter replacements, if any, are done *after* parsing the wiki-text message,
- * so parameters may contain HTML (eg links or form controls). Be sure
- * to pre-escape them if you really do want plaintext, or just wrap
- * the whole thing in htmlspecialchars().
- *
- * @deprecated since 1.18
- *
- * @param string $key
- * @param string $args,... Parameters
- * @return string
- */
-function wfMsgWikiHtml( $key ) {
-       wfDeprecated( __METHOD__, '1.21' );
-
-       $args = func_get_args();
-       array_shift( $args );
-       return wfMsgReplaceArgs(
-               MessageCache::singleton()->parse( wfMsgGetKey( $key ), null,
-               /* can't be set to false */ true, /* interface */ true )->getText(),
-               $args );
-}
-
-/**
- * Returns message in the requested format
- *
- * @deprecated since 1.18
- *
- * @param string $key Key of the message
- * @param array $options Processing rules.
- *   Can take the following options:
- *     parse: parses wikitext to HTML
- *     parseinline: parses wikitext to HTML and removes the surrounding
- *       p's added by parser or tidy
- *     escape: filters message through htmlspecialchars
- *     escapenoentities: same, but allows entity references like   through
- *     replaceafter: parameters are substituted after parsing or escaping
- *     parsemag: transform the message using magic phrases
- *     content: fetch message for content language instead of interface
- *   Also can accept a single associative argument, of the form 'language' => 'xx':
- *     language: Language object or language code to fetch message for
- *       (overridden by content).
- * Behavior for conflicting options (e.g., parse+parseinline) is undefined.
- *
- * @return string
- */
-function wfMsgExt( $key, $options ) {
-       wfDeprecated( __METHOD__, '1.21' );
-
-       $args = func_get_args();
-       array_shift( $args );
-       array_shift( $args );
-       $options = (array)$options;
-       $validOptions = array( 'parse', 'parseinline', 'escape', 'escapenoentities', 'replaceafter',
-               'parsemag', 'content' );
-
-       foreach ( $options as $arrayKey => $option ) {
-               if ( !preg_match( '/^[0-9]+|language$/', $arrayKey ) ) {
-                       // An unknown index, neither numeric nor "language"
-                       wfWarn( "wfMsgExt called with incorrect parameter key $arrayKey", 1, E_USER_WARNING );
-               } elseif ( preg_match( '/^[0-9]+$/', $arrayKey ) && !in_array( $option, $validOptions ) ) {
-                       // A numeric index with unknown value
-                       wfWarn( "wfMsgExt called with incorrect parameter $option", 1, E_USER_WARNING );
-               }
-       }
-
-       if ( in_array( 'content', $options, true ) ) {
-               $forContent = true;
-               $langCode = true;
-               $langCodeObj = null;
-       } elseif ( array_key_exists( 'language', $options ) ) {
-               $forContent = false;
-               $langCode = wfGetLangObj( $options['language'] );
-               $langCodeObj = $langCode;
-       } else {
-               $forContent = false;
-               $langCode = false;
-               $langCodeObj = null;
-       }
-
-       $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false );
-
-       if ( !in_array( 'replaceafter', $options, true ) ) {
-               $string = wfMsgReplaceArgs( $string, $args );
-       }
-
-       $messageCache = MessageCache::singleton();
-       $parseInline = in_array( 'parseinline', $options, true );
-       if ( in_array( 'parse', $options, true ) || $parseInline ) {
-               $string = $messageCache->parse( $string, null, true, !$forContent, $langCodeObj );
-               if ( $string instanceof ParserOutput ) {
-                       $string = $string->getText();
-               }
-
-               if ( $parseInline ) {
-                       $string = Parser::stripOuterParagraph( $string );
-               }
-       } elseif ( in_array( 'parsemag', $options, true ) ) {
-               $string = $messageCache->transform( $string,
-                               !$forContent, $langCodeObj );
-       }
-
-       if ( in_array( 'escape', $options, true ) ) {
-               $string = htmlspecialchars( $string );
-       } elseif ( in_array( 'escapenoentities', $options, true ) ) {
-               $string = Sanitizer::escapeHtmlAllowEntities( $string );
-       }
-
-       if ( in_array( 'replaceafter', $options, true ) ) {
-               $string = wfMsgReplaceArgs( $string, $args );
-       }
-
-       return $string;
-}
-
 /**
  * Fetch server name for use in error reporting etc.
  * Use real server name if available, so we know which machine
@@ -2412,8 +2161,8 @@ function wfIsHHVM() {
 /**
  * Tries to get the system directory for temporary files. First
  * $wgTmpDirectory is checked, and then the TMPDIR, TMP, and TEMP
- * environment variables are then checked in sequence, and if none are
- * set try sys_get_temp_dir().
+ * environment variables are then checked in sequence, then
+ * sys_get_temp_dir(), then upload_tmp_dir from php.ini.
  *
  * NOTE: When possible, use instead the tmpfile() function to create
  * temporary files to avoid race conditions on file creation, etc.
@@ -2428,13 +2177,16 @@ function wfTempDir() {
        }
 
        $tmpDir = array_map( "getenv", array( 'TMPDIR', 'TMP', 'TEMP' ) );
+       $tmpDir[] = sys_get_temp_dir();
+       $tmpDir[] = ini_get( 'upload_tmp_dir' );
 
        foreach ( $tmpDir as $tmp ) {
                if ( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
        }
-       return sys_get_temp_dir();
+       throw new MWException( 'No writable temporary directory could be found. ' .
+               'Please set $wgTmpDirectory to a writable directory.' );
 }
 
 /**
@@ -3611,55 +3363,35 @@ function wfGetNull() {
  * @param string|bool $cluster Cluster name accepted by LBFactory. Default: false.
  * @param int|null $timeout Max wait time. Default: 1 day (cli), ~10 seconds (web)
  * @return bool Success (able to connect and no timeouts reached)
+ * @deprecated since 1.27 Use LBFactory::waitForReplication
  */
 function wfWaitForSlaves(
        $ifWritesSince = null, $wiki = false, $cluster = false, $timeout = null
 ) {
-       // B/C: first argument used to be "max seconds of lag"; ignore such values
-       $ifWritesSince = ( $ifWritesSince > 1e9 ) ? $ifWritesSince : null;
-
        if ( $timeout === null ) {
                $timeout = ( PHP_SAPI === 'cli' ) ? 86400 : 10;
        }
 
-       // Figure out which clusters need to be checked
-       /** @var LoadBalancer[] $lbs */
-       $lbs = array();
        if ( $cluster === '*' ) {
-               wfGetLBFactory()->forEachLB( function ( LoadBalancer $lb ) use ( &$lbs ) {
-                       $lbs[] = $lb;
-               } );
-       } elseif ( $cluster !== false ) {
-               $lbs[] = wfGetLBFactory()->getExternalLB( $cluster );
-       } else {
-               $lbs[] = wfGetLB( $wiki );
-       }
-
-       // Get all the master positions of applicable DBs right now.
-       // This can be faster since waiting on one cluster reduces the
-       // time needed to wait on the next clusters.
-       $masterPositions = array_fill( 0, count( $lbs ), false );
-       foreach ( $lbs as $i => $lb ) {
-               if ( $lb->getServerCount() <= 1 ) {
-                       // Bug 27975 - Don't try to wait for slaves if there are none
-                       // Prevents permission error when getting master position
-                       continue;
-               } elseif ( $ifWritesSince && $lb->lastMasterChangeTimestamp() < $ifWritesSince ) {
-                       continue; // no writes since the last wait
-               }
-               $masterPositions[$i] = $lb->getMasterPos();
+               $cluster = false;
+               $wiki = false;
+       } elseif ( $wiki === false ) {
+               $wiki = wfWikiID();
        }
 
-       $ok = true;
-       foreach ( $lbs as $i => $lb ) {
-               if ( $masterPositions[$i] ) {
-                       // The DBMS may not support getMasterPos() or the whole
-                       // load balancer might be fake (e.g. $wgAllDBsAreLocalhost).
-                       $ok = $lb->waitForAll( $masterPositions[$i], $timeout ) && $ok;
-               }
+       try {
+               wfGetLBFactory()->waitForReplication( array(
+                       'wiki' => $wiki,
+                       'cluster' => $cluster,
+                       'timeout' => $timeout,
+                       // B/C: first argument used to be "max seconds of lag"; ignore such values
+                       'ifWritesSince' => ( $ifWritesSince > 1e9 ) ? $ifWritesSince : null
+               ) );
+       } catch ( DBReplicationWaitError $e ) {
+               return false;
        }
 
-       return $ok;
+       return true;
 }
 
 /**