MediaWiki
REL1_19
|
00001 <?php 00033 function findFiles( $dir, $exts ) { 00034 if ( is_dir( $dir ) ) { 00035 $dhl = opendir( $dir ); 00036 if ( $dhl ) { 00037 $files = array(); 00038 while ( ( $file = readdir( $dhl ) ) !== false ) { 00039 if ( is_file( $dir . '/' . $file ) ) { 00040 list( /* $name */, $ext ) = splitFilename( $dir . '/' . $file ); 00041 if ( array_search( strtolower( $ext ), $exts ) !== false ) 00042 $files[] = $dir . '/' . $file; 00043 } 00044 } 00045 return $files; 00046 } else { 00047 return array(); 00048 } 00049 } else { 00050 return array(); 00051 } 00052 } 00053 00060 function splitFilename( $filename ) { 00061 $parts = explode( '.', $filename ); 00062 $ext = $parts[ count( $parts ) - 1 ]; 00063 unset( $parts[ count( $parts ) - 1 ] ); 00064 $fname = implode( '.', $parts ); 00065 return array( $fname, $ext ); 00066 } 00067 00082 function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) { 00083 if ( strpos( $auxExtension, '.' ) !== 0 ) { 00084 $auxExtension = '.' . $auxExtension; 00085 } 00086 00087 $d = dirname( $file ); 00088 $n = basename( $file ); 00089 00090 while ( $maxStrip >= 0 ) { 00091 $f = $d . '/' . $n . $auxExtension; 00092 00093 if ( file_exists( $f ) ) { 00094 return $f; 00095 } 00096 00097 $idx = strrpos( $n, '.' ); 00098 if ( !$idx ) break; 00099 00100 $n = substr( $n, 0, $idx ); 00101 $maxStrip -= 1; 00102 } 00103 00104 return false; 00105 } 00106 00107 # FIXME: Access the api in a saner way and performing just one query (preferably batching files too). 00108 function getFileCommentFromSourceWiki( $wiki_host, $file ) { 00109 $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment'; 00110 $body = Http::get( $url ); 00111 if ( preg_match( '#<ii comment="([^"]*)" />#', $body, $matches ) == 0 ) { 00112 return false; 00113 } 00114 00115 return html_entity_decode( $matches[1] ); 00116 } 00117 00118 function getFileUserFromSourceWiki( $wiki_host, $file ) { 00119 $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user'; 00120 $body = Http::get( $url ); 00121 if ( preg_match( '#<ii user="([^"]*)" />#', $body, $matches ) == 0 ) { 00122 return false; 00123 } 00124 00125 return html_entity_decode( $matches[1] ); 00126 } 00127