Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index 460fe51..cfbd062 100644 (file)
@@ -148,7 +148,7 @@ abstract class File implements IDBAccessObject {
        protected $isSafeFile;
 
        /** @var string Required Repository class type */
-       protected $repoClass = 'FileRepo';
+       protected $repoClass = FileRepo::class;
 
        /** @var array Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width */
        protected $tmpBucketedThumbCache = [];
@@ -250,7 +250,7 @@ abstract class File implements IDBAccessObject {
                $oldMime = $old->getMimeType();
                $n = strrpos( $new, '.' );
                $newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) : '' );
-               $mimeMagic = MimeMagic::singleton();
+               $mimeMagic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
 
                return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
        }
@@ -581,6 +581,25 @@ abstract class File implements IDBAccessObject {
                }
        }
 
+       /**
+        * Get the language code from the available languages for this file that matches the language
+        * requested by the user
+        *
+        * @param string $userPreferredLanguage
+        * @return string|null
+        */
+       public function getMatchedLanguage( $userPreferredLanguage ) {
+               $handler = $this->getHandler();
+               if ( $handler && method_exists( $handler, 'getMatchedLanguage' ) ) {
+                       return $handler->getMatchedLanguage(
+                               $userPreferredLanguage,
+                               $handler->getAvailableLanguages( $this )
+                       );
+               } else {
+                       return null;
+               }
+       }
+
        /**
         * In files that support multiple language, what is the default language
         * to use if none specified.
@@ -1147,7 +1166,7 @@ abstract class File implements IDBAccessObject {
                if ( !$thumb ) { // bad params?
                        $thumb = false;
                } elseif ( $thumb->isError() ) { // transform error
-                       /** @var $thumb MediaTransformError */
+                       /** @var MediaTransformError $thumb */
                        $this->lastError = $thumb->toText();
                        // Ignore errors if requested
                        if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
@@ -1282,11 +1301,10 @@ abstract class File implements IDBAccessObject {
                // Thumbnailing a very large file could result in network saturation if
                // everyone does it at once.
                if ( $this->getSize() >= 1e7 ) { // 10MB
-                       $that = $this;
                        $work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ),
                                [
-                                       'doWork' => function () use ( $that ) {
-                                               return $that->getLocalRefPath();
+                                       'doWork' => function () {
+                                               return $this->getLocalRefPath();
                                        }
                                ]
                        );
@@ -1446,7 +1464,9 @@ abstract class File implements IDBAccessObject {
                // Purge cache of all pages using this file
                $title = $this->getTitle();
                if ( $title ) {
-                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'imagelinks' ) );
+                       DeferredUpdates::addUpdate(
+                               new HTMLCacheUpdate( $title, 'imagelinks', 'file-purge' )
+                       );
                }
        }