getCode(); if ( empty( $this->filePrefixRegex[$langCode] ) ) { $fileNamespaces = [ \MWNamespace::getCanonicalName( NS_FILE ), $contLang->getNamespaces()[NS_FILE] ]; $aliases = $contLang->getNamespaceAliases(); foreach ( $aliases as $alias => $namespaceId ) { if ( $namespaceId == NS_FILE ) $fileNamespaces [] = $alias; } $this->filePrefixRegex[$langCode] = '^(' . implode( '|', $fileNamespaces ) . '):'; } return $this->filePrefixRegex[$langCode]; } /** * @param $filename string * @param $contLang \Language * @return mixed */ public function sanitizeImageFileName( $filename, $contLang ) { // replace the MW square brackets and surrounding whitespace $trimmedFilename = trim( $filename, "\t\n\r[]" ); $filePrefixRegex = $this->getFilePrefixRegex( $contLang ); $unprefixedFilename = mb_ereg_replace( $filePrefixRegex, "", $trimmedFilename ); // strip $filenameParts = explode( '|', $unprefixedFilename ); if ( !empty( $filenameParts[0] ) ) { $filename = $filenameParts[0]; } return $filename; } }