Merge "filebackend: improve internal use of FileBackend constants"
[lhc/web/wiklou.git] / includes / filerepo / LocalRepo.php
index bb65b0a..8e3355c 100644 (file)
@@ -180,7 +180,11 @@ class LocalRepo extends FileRepo {
         * @return string
         */
        public static function getHashFromKey( $key ) {
-               return strtok( $key, '.' );
+               $sha1 = strtok( $key, '.' );
+               if ( is_string( $sha1 ) && strlen( $sha1 ) === 32 && $sha1[0] === '0' ) {
+                       $sha1 = substr( $sha1, 1 );
+               }
+               return $sha1;
        }
 
        /**
@@ -209,20 +213,16 @@ class LocalRepo extends FileRepo {
 
                                $setOpts += Database::getCacheSetOptions( $dbr );
 
-                               if ( $title instanceof Title ) {
-                                       $row = $dbr->selectRow(
-                                               [ 'page', 'redirect' ],
-                                               [ 'rd_namespace', 'rd_title' ],
-                                               [
-                                                       'page_namespace' => $title->getNamespace(),
-                                                       'page_title' => $title->getDBkey(),
-                                                       'rd_from = page_id'
-                                               ],
-                                               $method
-                                       );
-                               } else {
-                                       $row = false;
-                               }
+                               $row = $dbr->selectRow(
+                                       [ 'page', 'redirect' ],
+                                       [ 'rd_namespace', 'rd_title' ],
+                                       [
+                                               'page_namespace' => $title->getNamespace(),
+                                               'page_title' => $title->getDBkey(),
+                                               'rd_from = page_id'
+                                       ],
+                                       $method
+                               );
 
                                return ( $row && $row->rd_namespace == NS_FILE )
                                        ? Title::makeTitle( $row->rd_namespace, $row->rd_title )->getDBkey()