Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 05c4655..1741958 100644 (file)
@@ -1037,9 +1037,18 @@ function wfLogDBError( $text, array $context = [] ) {
  * @param int $callerOffset How far up the call stack is the original
  *    caller. 2 = function that called the function that called
  *    wfDeprecated (Added in 1.20).
+ *
+ * @throws Exception If the MediaWiki version number is not a string or boolean.
  */
 function wfDeprecated( $function, $version = false, $component = false, $callerOffset = 2 ) {
-       MWDebug::deprecated( $function, $version, $component, $callerOffset + 1 );
+       if ( is_string( $version ) || is_bool( $version ) ) {
+               MWDebug::deprecated( $function, $version, $component, $callerOffset + 1 );
+       } else {
+               throw new Exception(
+                       "MediaWiki version must either be a string or a boolean. " .
+                       "Example valid version: '1.33'"
+               );
+       }
 }
 
 /**
@@ -2512,6 +2521,7 @@ function wfForeignMemcKey( $db, $prefix, ...$args ) {
  * @return string
  */
 function wfGlobalCacheKey( ...$args ) {
+       wfDeprecated( __METHOD__, '1.30' );
        return ObjectCache::getLocalClusterInstance()->makeGlobalKey( ...$args );
 }
 
@@ -2553,10 +2563,10 @@ function wfWikiID() {
  * @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection()
  *       on an injected instance of LoadBalancer.
  *
- * @return \Wikimedia\Rdbms\Database
+ * @return \Wikimedia\Rdbms\DBConnRef
  */
 function wfGetDB( $db, $groups = [], $wiki = false ) {
-       return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki );
+       return wfGetLB( $wiki )->getMaintenanceConnectionRef( $db, $groups, $wiki );
 }
 
 /**
@@ -2747,30 +2757,27 @@ function wfStripIllegalFilenameChars( $name ) {
 }
 
 /**
- * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit
+ * Raise PHP's memory limit (if needed).
  *
- * @return int Resulting value of the memory limit.
+ * @internal For use by Setup.php
  */
-function wfMemoryLimit() {
-       global $wgMemoryLimit;
-       $memlimit = wfShorthandToInteger( ini_get( 'memory_limit' ) );
-       if ( $memlimit != -1 ) {
-               $conflimit = wfShorthandToInteger( $wgMemoryLimit );
-               if ( $conflimit == -1 ) {
+function wfMemoryLimit( $newLimit ) {
+       $oldLimit = wfShorthandToInteger( ini_get( 'memory_limit' ) );
+       // If the INI config is already unlimited, there is nothing larger
+       if ( $oldLimit != -1 ) {
+               $newLimit = wfShorthandToInteger( $newLimit );
+               if ( $newLimit == -1 ) {
                        wfDebug( "Removing PHP's memory limit\n" );
                        Wikimedia\suppressWarnings();
-                       ini_set( 'memory_limit', $conflimit );
+                       ini_set( 'memory_limit', $newLimit );
                        Wikimedia\restoreWarnings();
-                       return $conflimit;
-               } elseif ( $conflimit > $memlimit ) {
-                       wfDebug( "Raising PHP's memory limit to $conflimit bytes\n" );
+               } elseif ( $newLimit > $oldLimit ) {
+                       wfDebug( "Raising PHP's memory limit to $newLimit bytes\n" );
                        Wikimedia\suppressWarnings();
-                       ini_set( 'memory_limit', $conflimit );
+                       ini_set( 'memory_limit', $newLimit );
                        Wikimedia\restoreWarnings();
-                       return $conflimit;
                }
        }
-       return $memlimit;
 }
 
 /**