media: Misc code clean up in DjVu.php
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 25 Mar 2016 00:18:09 +0000 (00:18 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 25 Mar 2016 00:19:18 +0000 (00:19 +0000)
* Use $cache->makeKey() instead of global.
* Access constants via $cache.
* Remove obsolete 'that = this' PHP 5.3 workaround.

Change-Id: I75505d3e3017fde185e43815d4e7acaba3fee69c

includes/media/DjVu.php

index cd249a8..9add138 100644 (file)
@@ -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;
@@ -420,7 +419,7 @@ class DjVuHandler extends ImageHandler {
 
                                return [ 'pageCount' => $count, 'dimensionsByPage' => $dimsByPage ];
                        },
-                       [ 'pcTTL' => WANObjectCache::TTL_INDEFINITE ]
+                       [ 'pcTTL' => $cache::TTL_INDEFINITE ]
                );
        }