* Start of Burmese (my) translation by Hakka
[lhc/web/wiklou.git] / maintenance / importImages.inc.php
1 <?php
2
3 /**
4 * Support functions for the importImages script
5 *
6 * @addtogroup Maintenance
7 * @author Rob Church <robchur@gmail.com>
8 */
9
10 /**
11 * Search a directory for files with one of a set of extensions
12 *
13 * @param $dir Path to directory to search
14 * @param $exts Array of extensions to search for
15 * @return mixed Array of filenames on success, or false on failure
16 */
17 function findFiles( $dir, $exts ) {
18 if( is_dir( $dir ) ) {
19 if( $dhl = opendir( $dir ) ) {
20 while( ( $file = readdir( $dhl ) ) !== false ) {
21 if( is_file( $dir . '/' . $file ) ) {
22 list( /* $name */, $ext ) = splitFilename( $dir . '/' . $file );
23 if( array_search( strtolower( $ext ), $exts ) !== false )
24 $files[] = $dir . '/' . $file;
25 }
26 }
27 return $files;
28 } else {
29 return false;
30 }
31 } else {
32 return false;
33 }
34 }
35
36 /**
37 * Split a filename into filename and extension
38 *
39 * @param $filename Filename
40 * @return array
41 */
42 function splitFilename( $filename ) {
43 $parts = explode( '.', $filename );
44 $ext = $parts[ count( $parts ) - 1 ];
45 unset( $parts[ count( $parts ) - 1 ] );
46 $fname = implode( '.', $parts );
47 return array( $fname, $ext );
48 }
49
50 /**
51 * Given an image hash, check that the structure exists to save the image file
52 * and create it if it doesn't
53 *
54 * @param $hash Part of an image hash, e.g. /f/fd/
55 */
56 function makeHashPath( $hash ) {
57 global $wgUploadDirectory;
58 $parts = explode( '/', substr( $hash, 1, strlen( $hash ) - 2 ) );
59 if( !is_dir( $wgUploadDirectory . '/' . $parts[0] ) )
60 mkdir( $wgUploadDirectory . '/' . $parts[0] );
61 if( !is_dir( $wgUploadDirectory . '/' . $hash ) )
62 mkdir( $wgUploadDirectory . '/' . $hash );
63 }
64
65
66 ?>