From b9b85843572bf283f48285001e276ba7e61b63f6 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 22 Feb 2009 13:37:51 +0100 Subject: updated to MediaWiki 1.14.0 --- maintenance/importImages.inc.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'maintenance/importImages.inc.php') diff --git a/maintenance/importImages.inc.php b/maintenance/importImages.inc.php index 53895778..290f3c07 100644 --- a/maintenance/importImages.inc.php +++ b/maintenance/importImages.inc.php @@ -46,4 +46,43 @@ function splitFilename( $filename ) { unset( $parts[ count( $parts ) - 1 ] ); $fname = implode( '.', $parts ); return array( $fname, $ext ); +} + +/** + * Find an auxilliary file with the given extension, matching + * the give base file path. $maxStrip determines how many extensions + * may be stripped from the original file name before appending the + * new extension. For example, with $maxStrip = 1 (the default), + * file files acme.foo.bar.txt and acme.foo.txt would be auxilliary + * files for acme.foo.bar and the extension ".txt". With $maxStrip = 2, + * acme.txt would also be acceptable. + * + * @param $file base path + * @param $auxExtension the extension to be appended to the base path + * @param $maxStrip the maximum number of extensions to strip from the base path (default: 1) + * @return string or false + */ +function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) { + if ( strpos( $auxExtension, '.' ) !== 0 ) { + $auxExtension = '.' . $auxExtension; + } + + $d = dirname( $file ); + $n = basename( $file ); + + while ( $maxStrip >= 0 ) { + $f = $d . '/' . $n . $auxExtension; + + if ( file_exists( $f ) ) { + return $f; + } + + $idx = strrpos( $n, '.' ); + if ( !$idx ) break; + + $n = substr( $n, 0, $idx ); + $maxStrip -= 1; + } + + return false; } \ No newline at end of file -- cgit v1.2.3-54-g00ecf