From: Brion Vibber Date: Fri, 13 Jul 2007 18:08:41 +0000 (+0000) Subject: Add support for $suffix parameter on wfBasename() clone of basename(), for completene... X-Git-Tag: 1.31.0-rc.0~52101 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=ba17e8b8c54edb5e0b1a538d573a0cac05d793e4;p=lhc%2Fweb%2Fwiklou.git Add support for $suffix parameter on wfBasename() clone of basename(), for completeness' sake --- 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 '';