X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FimportImages.inc;h=29a7fbcb596c07ed9d3c284ce9077679cfaeb3db;hb=01c9645b072f89f7fc38b2e6fb6f4df48da22090;hp=290f3c0794b548355ff04bb5660f2d3721de0987;hpb=54396bab19a878022ac3d43631a2d0d397b8984e;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/importImages.inc b/maintenance/importImages.inc index 290f3c0794..29a7fbcb59 100644 --- a/maintenance/importImages.inc +++ b/maintenance/importImages.inc @@ -6,6 +6,7 @@ * @file * @ingroup Maintenance * @author Rob Church + * @author Mij */ /** @@ -16,21 +17,22 @@ * @return mixed Array of filenames on success, or false on failure */ function findFiles( $dir, $exts ) { - if( is_dir( $dir ) ) { - if( $dhl = opendir( $dir ) ) { - while( ( $file = readdir( $dhl ) ) !== false ) { - if( is_file( $dir . '/' . $file ) ) { + if ( is_dir( $dir ) ) { + if ( $dhl = opendir( $dir ) ) { + $files = array(); + while ( ( $file = readdir( $dhl ) ) !== false ) { + if ( is_file( $dir . '/' . $file ) ) { list( /* $name */, $ext ) = splitFilename( $dir . '/' . $file ); - if( array_search( strtolower( $ext ), $exts ) !== false ) + if ( array_search( strtolower( $ext ), $exts ) !== false ) $files[] = $dir . '/' . $file; } } return $files; } else { - return false; + return array(); } } else { - return false; + return array(); } } @@ -85,4 +87,26 @@ function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) { } return false; -} \ No newline at end of file +} + +# FIXME: Access the api in a saner way and performing just one query (preferably batching files too). +function getFileCommentFromSourceWiki( $wiki_host, $file ) { + $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment'; + $body = Http::get( $url ); + if ( preg_match( '##', $body, $matches ) == 0 ) { + return false; + } + + return html_entity_decode( $matches[1] ); +} + +function getFileUserFromSourceWiki( $wiki_host, $file ) { + $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user'; + $body = Http::get( $url ); + if ( preg_match( '##', $body, $matches ) == 0 ) { + return false; + } + + return html_entity_decode( $matches[1] ); +} +