Add support for $suffix parameter on wfBasename() clone of basename(), for completene...
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 13 Jul 2007 18:08:41 +0000 (18:08 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 13 Jul 2007 18:08:41 +0000 (18:08 +0000)
includes/GlobalFunctions.php

index f06cd47..81aa111 100644 (file)
@@ -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 '';