Make lines short to pass phpcs in 2 files under includes/
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 68e1635..6fbc11d 100644 (file)
@@ -171,6 +171,7 @@ if ( !function_exists( 'hash_equals' ) ) {
  *
  * @param string $ext Name of the extension to load
  * @param string|null $path Absolute path of where to find the extension.json file
+ * @since 1.25
  */
 function wfLoadExtension( $ext, $path = null ) {
        if ( !$path ) {
@@ -191,6 +192,7 @@ function wfLoadExtension( $ext, $path = null ) {
  *
  * @see wfLoadExtension
  * @param string[] $exts Array of extension names to load
+ * @since 1.25
  */
 function wfLoadExtensions( array $exts ) {
        global $wgExtensionDirectory;
@@ -206,6 +208,7 @@ function wfLoadExtensions( array $exts ) {
  * @see wfLoadExtension
  * @param string $skin Name of the extension to load
  * @param string|null $path Absolute path of where to find the skin.json file
+ * @since 1.25
  */
 function wfLoadSkin( $skin, $path = null ) {
        if ( !$path ) {
@@ -220,6 +223,7 @@ function wfLoadSkin( $skin, $path = null ) {
  *
  * @see wfLoadExtensions
  * @param string[] $skins Array of extension names to load
+ * @since 1.25
  */
 function wfLoadSkins( array $skins ) {
        global $wgStyleDirectory;
@@ -404,15 +408,14 @@ function wfRandomString( $length = 32 ) {
  * RFC 1738 says ~ is unsafe, however RFC 3986 considers it an unreserved
  * character which should not be encoded. More importantly, google chrome
  * always converts %7E back to ~, and converting it in this function can
- * cause a redirect loop (T105265). Similarly, encoding ' causes a
- * redirect loop on Opera 12 (T106793).
+ * cause a redirect loop (T105265).
  *
  * But + is not safe because it's used to indicate a space; &= are only safe in
- * paths and not in queries (and we don't distinguish here);
- * and urlencode() doesn't touch -_. to begin with.  Plus, although /
+ * paths and not in queries (and we don't distinguish here); ' seems kind of
+ * scary; and urlencode() doesn't touch -_. to begin with.  Plus, although /
  * is reserved, we don't care.  So the list we unescape is:
  *
- * ;:@$!*'(),/~
+ * ;:@$!*(),/~
  *
  * However, IIS7 redirects fail when the url contains a colon (Bug 22709),
  * so no fancy : for IIS7.
@@ -431,7 +434,7 @@ function wfUrlencode( $s ) {
        }
 
        if ( is_null( $needle ) ) {
-               $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%27', '%28', '%29', '%2C', '%2F', '%7E' );
+               $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%28', '%29', '%2C', '%2F', '%7E' );
                if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) ||
                        ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7' ) === false )
                ) {
@@ -442,7 +445,7 @@ function wfUrlencode( $s ) {
        $s = urlencode( $s );
        $s = str_ireplace(
                $needle,
-               array( ';', '@', '$', '!', '*', '\'', '(', ')', ',', '/', '~', ':' ),
+               array( ';', '@', '$', '!', '*', '(', ')', ',', '/', '~', ':' ),
                $s
        );
 
@@ -632,7 +635,7 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
        $bits = wfParseUrl( $url );
 
        // ensure proper port for HTTPS arrives in URL
-       // https://bugzilla.wikimedia.org/show_bug.cgi?id=65184
+       // https://phabricator.wikimedia.org/T67184
        if ( $defaultProto === PROTO_HTTPS && $wgHttpsPort != 443 ) {
                $bits['port'] = $wgHttpsPort;
        }
@@ -2180,14 +2183,24 @@ function wfResetOutputBuffers( $resetGzipEncoding = true ) {
                $wgDisableOutputCompression = true;
        }
        while ( $status = ob_get_status() ) {
-               if ( $status['type'] == 0 /* PHP_OUTPUT_HANDLER_INTERNAL */ ) {
-                       // Probably from zlib.output_compression or other
-                       // PHP-internal setting which can't be removed.
-                       //
+               if ( isset( $status['flags'] ) ) {
+                       $flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE;
+                       $deleteable = ( $status['flags'] & $flags ) === $flags;
+               } elseif ( isset( $status['del'] ) ) {
+                       $deleteable = $status['del'];
+               } else {
+                       // Guess that any PHP-internal setting can't be removed.
+                       $deleteable = $status['type'] !== 0; /* PHP_OUTPUT_HANDLER_INTERNAL */
+               }
+               if ( !$deleteable ) {
                        // Give up, and hope the result doesn't break
                        // output behavior.
                        break;
                }
+               if ( $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier' ) {
+                       // Unit testing barrier to prevent this function from breaking PHPUnit.
+                       break;
+               }
                if ( !ob_end_clean() ) {
                        // Could not remove output buffer handler; abort now
                        // to avoid getting in some kind of infinite loop.
@@ -2529,7 +2542,7 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) {
        MediaWiki\restoreWarnings();
 
        if ( !$ok ) {
-               //directory may have been created on another request since we last checked
+               // directory may have been created on another request since we last checked
                if ( is_dir( $dir ) ) {
                        return true;
                }
@@ -3203,6 +3216,7 @@ function wfUsePHP( $req_ver ) {
  *
  * @see perldoc -f use
  *
+ * @deprecated since 1.26, use the "requires' property of extension.json
  * @param string|int|float $req_ver The version to check, can be a string, an integer, or a float
  * @throws MWException
  */
@@ -3453,7 +3467,6 @@ function wfResetSessionID() {
                $_SESSION = $tmp;
        }
        $newSessionId = session_id();
-       Hooks::run( 'ResetSessionID', array( $oldSessionId, $newSessionId ) );
 }
 
 /**
@@ -4059,13 +4072,10 @@ function wfUnpack( $format, $data, $length = false ) {
  * @return bool
  */
 function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
-       static $badImageCache = null; // based on bad_image_list msg
-
-       # Handle redirects
-       $redirectTitle = RepoGroup::singleton()->checkRedirect( Title::makeTitle( NS_FILE, $name ) );
-       if ( $redirectTitle ) {
-               $name = $redirectTitle->getDBkey();
-       }
+       # Handle redirects; callers almost always hit wfFindFile() anyway,
+       # so just use that method because it has a fast process cache.
+       $file = wfFindFile( $name ); // get the final name
+       $name = $file ? $file->getTitle()->getDBkey() : $name;
 
        # Run the extension hook
        $bad = false;
@@ -4073,10 +4083,11 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
                return $bad;
        }
 
-       $cacheable = ( $blacklist === null );
-       if ( $cacheable && $badImageCache !== null ) {
-               $badImages = $badImageCache;
-       } else { // cache miss
+       $cache = ObjectCache::newAccelerator( 'hash' );
+       $key = wfMemcKey( 'bad-image-list', ( $blacklist === null ) ? 'default' : md5( $blacklist ) );
+       $badImages = $cache->get( $key );
+
+       if ( $badImages === false ) { // cache miss
                if ( $blacklist === null ) {
                        $blacklist = wfMessage( 'bad_image_list' )->inContentLanguage()->plain(); // site list
                }
@@ -4112,13 +4123,12 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
                                $badImages[$imageDBkey] = $exceptions;
                        }
                }
-               if ( $cacheable ) {
-                       $badImageCache = $badImages;
-               }
+               $cache->set( $key, $badImages, 60 );
        }
 
        $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false;
        $bad = isset( $badImages[$name] ) && !isset( $badImages[$name][$contextKey] );
+
        return $bad;
 }