+ function getHashedDirectory() {
+ global $wgMakeDumpLinks, $wgInputEncoding;
+ $dbkey = $this->getDBkey();
+
+ # Split into characters
+ if ( $wgInputEncoding == 'UTF-8' ) {
+ preg_match_all( '/./us', $dbkey, $m );
+ } else {
+ preg_match_all( '/./s', $dbkey, $m );
+ }
+ $chars = $m[0];
+ $length = count( $chars );
+ $dir = '';
+
+ for ( $i = 0; $i < $wgMakeDumpLinks; $i++ ) {
+ if ( $i ) {
+ $dir .= '/';
+ }
+ if ( $i >= $length ) {
+ $dir .= '_';
+ } elseif ( ord( $chars[$i] ) > 32 ) {
+ $dir .= strtolower( $chars[$i] );
+ } else {
+ $dir .= sprintf( "%02X", ord( $chars[$i] ) );
+ }
+ }
+ return $dir;
+ }
+
+ function getHashedFilename() {
+ $dbkey = $this->getPrefixedDBkey();
+ $mainPage = Title::newMainPage();
+ if ( $mainPage->getPrefixedDBkey() == $dbkey ) {
+ return 'index.html';
+ }
+
+ $dir = $this->getHashedDirectory();
+
+ # Replace illegal charcters for Windows paths with underscores
+ $friendlyName = strtr( $dbkey, '/\\*?"<>|~', '_________' );
+
+ # Work out lower case form. We assume we're on a system with case-insensitive
+ # filenames, so unless the case is of a special form, we have to disambiguate
+ $lowerCase = $this->prefix( ucfirst( strtolower( $this->getDBkey() ) ) );
+
+ # Make it mostly unique
+ if ( $lowerCase != $friendlyName ) {
+ $friendlyName .= '_' . substr(md5( $dbkey ), 0, 4);
+ }
+ # Handle colon specially by replacing it with tilde
+ # Thus we reduce the number of paths with hashes appended
+ $friendlyName = str_replace( ':', '~', $friendlyName );
+ return "$dir/$friendlyName.html";