filerepo: Use @method LocalRepo::newFile() to document the return type
[lhc/web/wiklou.git] / includes / filerepo / LocalRepo.php
index b3eae90..84c0a61 100644 (file)
@@ -32,6 +32,7 @@ use Wikimedia\Rdbms\IDatabase;
  * in the wiki's own database. This is the most commonly used repository class.
  *
  * @ingroup FileRepo
+ * @method LocalFile|null newFile( $title, $time = false )
  */
 class LocalRepo extends FileRepo {
        /** @var callable */
@@ -180,7 +181,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 +214,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()
@@ -405,7 +406,7 @@ class LocalRepo extends FileRepo {
         * @return array[] An Array of arrays or iterators of file objects and the hash as key
         */
        function findBySha1s( array $hashes ) {
-               if ( !count( $hashes ) ) {
+               if ( $hashes === [] ) {
                        return []; // empty parameter
                }