From ba17e8b8c54edb5e0b1a538d573a0cac05d793e4 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 13 Jul 2007 18:08:41 +0000 Subject: [PATCH] Add support for $suffix parameter on wfBasename() clone of basename(), for completeness' sake --- includes/GlobalFunctions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index f06cd47c13..81aa1112d0 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1872,11 +1872,15 @@ function wfRegexReplacement( $string ) { * We'll consider it so always, as we don't want \s in our Unix paths either. * * @param string $path + * @param string $suffix to remove if present * @return string */ -function wfBaseName( $path ) { +function wfBaseName( $path, $suffix='' ) { + $encSuffix = ($suffix == '') + ? '' + : ( '(?:' . preg_quote( $suffix, '#' ) . ')?' ); $matches = array(); - if( preg_match( '#([^/\\\\]*)[/\\\\]*$#', $path, $matches ) ) { + if( preg_match( "#([^/\\\\]*?){$encSuffix}[/\\\\]*$#", $path, $matches ) ) { return $matches[1]; } else { return ''; -- 2.20.1