Merge "Remove DELETE_SOURCE flag from FileRepo store()/storeBatch()"
[lhc/web/wiklou.git] / includes / media / DjVu.php
index 0d2ed29..9add138 100644 (file)
@@ -47,7 +47,7 @@ class DjVuHandler extends ImageHandler {
         * @param File $file
         * @return bool
         */
-       function mustRender( $file ) {
+       public function mustRender( $file ) {
                return true;
        }
 
@@ -64,14 +64,14 @@ class DjVuHandler extends ImageHandler {
         * @param File $file
         * @return bool
         */
-       function isMultiPage( $file ) {
+       public function isMultiPage( $file ) {
                return true;
        }
 
        /**
         * @return array
         */
-       function getParamMap() {
+       public function getParamMap() {
                return [
                        'img_width' => 'width',
                        'img_page' => 'page',
@@ -83,7 +83,7 @@ class DjVuHandler extends ImageHandler {
         * @param mixed $value
         * @return bool
         */
-       function validateParam( $name, $value ) {
+       public function validateParam( $name, $value ) {
                if ( $name === 'page' && trim( $value ) !== (string)intval( $value ) ) {
                        // Extra junk on the end of page, probably actually a caption
                        // e.g. [[File:Foo.djvu|thumb|Page 3 of the document shows foo]]
@@ -104,7 +104,7 @@ class DjVuHandler extends ImageHandler {
         * @param array $params
         * @return bool|string
         */
-       function makeParamString( $params ) {
+       public function makeParamString( $params ) {
                $page = isset( $params['page'] ) ? $params['page'] : 1;
                if ( !isset( $params['width'] ) ) {
                        return false;
@@ -117,7 +117,7 @@ class DjVuHandler extends ImageHandler {
         * @param string $str
         * @return array|bool
         */
-       function parseParamString( $str ) {
+       public function parseParamString( $str ) {
                $m = false;
                if ( preg_match( '/^page(\d+)-(\d+)px$/', $str, $m ) ) {
                        return [ 'width' => $m[2], 'page' => $m[1] ];
@@ -393,25 +393,24 @@ class DjVuHandler extends ImageHandler {
        }
 
        protected function getDimensionInfo( File $file ) {
-               $that = $this;
-
-               return ObjectCache::getMainWANInstance()->getWithSetCallback(
-                       wfMemcKey( 'file-djvu', 'dimensions', $file->getSha1() ),
-                       WANObjectCache::TTL_INDEFINITE,
-                       function () use ( $that, $file ) {
-                               $tree = $that->getMetaTree( $file );
+               $cache = ObjectCache::getMainWANInstance();
+               return $cache->getWithSetCallback(
+                       $cache->makeKey( 'file-djvu', 'dimensions', $file->getSha1() ),
+                       $cache::TTL_INDEFINITE,
+                       function () use ( $file ) {
+                               $tree = $this->getMetaTree( $file );
                                if ( !$tree ) {
                                        return false;
                                }
 
                                $dimsByPage = [];
                                $count = count( $tree->xpath( '//OBJECT' ) );
-                               for ( $i = 0; $i < $count; ++$i ) {
+                               for ( $i = 0; $i < $count; $i++ ) {
                                        $o = $tree->BODY[0]->OBJECT[$i];
                                        if ( $o ) {
                                                $dimsByPage[$i] = [
                                                        'width' => (int)$o['width'],
-                                                       'height' => (int)$o['height']
+                                                       'height' => (int)$o['height'],
                                                ];
                                        } else {
                                                $dimsByPage[$i] = false;
@@ -419,7 +418,8 @@ class DjVuHandler extends ImageHandler {
                                }
 
                                return [ 'pageCount' => $count, 'dimensionsByPage' => $dimsByPage ];
-                       }
+                       },
+                       [ 'pcTTL' => $cache::TTL_INDEFINITE ]
                );
        }