*/
function getSha1() {
if ( $this->sha1base36 ) {
- return wfBaseConvert( $this->sha1base36, 36, 16 );
+ return Wikimedia\base_convert( $this->sha1base36, 36, 16 );
}
return false;
}
* @return string
*/
public static function base36Sha1( $text ) {
- return wfBaseConvert( sha1( $text ), 16, 36, 31 );
+ return Wikimedia\base_convert( sha1( $text ), 16, 36, 31 );
}
/**
if ( !$this->validateSha1Hash( $sha1 ) ) {
$this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
}
- $sha1 = wfBaseConvert( $sha1, 16, 36, 31 );
+ $sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
} elseif ( isset( $params['sha1base36'] ) ) {
$sha1 = strtolower( $params['sha1base36'] );
if ( !$this->validateSha1Base36Hash( $sha1 ) ) {
}
if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_TEXT, $user ) ) {
if ( $row->ar_sha1 != '' ) {
- $rev['sha1'] = wfBaseConvert( $row->ar_sha1, 36, 16, 40 );
+ $rev['sha1'] = Wikimedia\base_convert( $row->ar_sha1, 36, 16, 40 );
} else {
$rev['sha1'] = '';
}
if ( !$this->validateSha1Hash( $sha1 ) ) {
$this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
}
- $sha1 = wfBaseConvert( $sha1, 16, 36, 31 );
+ $sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
} elseif ( $sha1base36Set ) {
$sha1 = strtolower( $params['sha1base36'] );
if ( !$this->validateSha1Base36Hash( $sha1 ) ) {
$file['user'] = $row->fa_user_text;
}
if ( $fld_sha1 ) {
- $file['sha1'] = wfBaseConvert( $row->fa_sha1, 36, 16, 40 );
+ $file['sha1'] = Wikimedia\base_convert( $row->fa_sha1, 36, 16, 40 );
}
if ( $fld_timestamp ) {
$file['timestamp'] = wfTimestamp( TS_ISO_8601, $row->fa_timestamp );
}
if ( $sha1 ) {
- $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );
+ $vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
}
if ( $meta ) {
}
if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
if ( $row->rev_sha1 !== '' ) {
- $vals['sha1'] = wfBaseConvert( $row->rev_sha1, 36, 16, 40 );
+ $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
} else {
$vals['sha1'] = '';
}
}
if ( $revision->userCan( Revision::DELETED_TEXT, $user ) ) {
if ( $revision->getSha1() != '' ) {
- $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
+ $vals['sha1'] = Wikimedia\base_convert( $revision->getSha1(), 36, 16, 40 );
} else {
$vals['sha1'] = '';
}
* @return string Integer
*/
private function bigintFromLockName( $lockName ) {
- return wfBaseConvert( substr( sha1( $lockName ), 0, 15 ), 16, 10 );
+ return Wikimedia\base_convert( substr( sha1( $lockName ), 0, 15 ), 16, 10 );
}
} // end DatabasePostgres class
$be = FileBackendGroup::singleton()->get( $backend );
if ( $be instanceof FileBackend ) {
// Get three random base 36 characters to act as shard directories
- $rand = wfBaseConvert( mt_rand( 0, 46655 ), 10, 36, 3 );
+ $rand = Wikimedia\base_convert( mt_rand( 0, 46655 ), 10, 36, 3 );
// Make sure ID is roughly lexicographically increasing for performance
$id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT );
// Segregate items by wiki ID for the sake of bookkeeping
MediaWiki\restoreWarnings();
if ( $this->sha1Base36 !== false ) {
- $this->sha1Base36 = wfBaseConvert( $this->sha1Base36, 16, 36, 31 );
+ $this->sha1Base36 = Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 );
}
return $this->sha1Base36;
if ( $digits > 0 ) {
$numShards = pow( $base, $digits );
for ( $index = 0; $index < $numShards; $index++ ) {
- $shards[] = '.' . wfBaseConvert( $index, 10, $base, $digits );
+ $shards[] = '.' . Wikimedia\base_convert( $index, 10, $base, $digits );
}
}
}
protected function getSourceSha1Base36() {
- return wfBaseConvert( sha1( $this->params['content'] ), 16, 36, 31 );
+ return Wikimedia\base_convert( sha1( $this->params['content'] ), 16, 36, 31 );
}
public function storagePathsChanged() {
$hash = sha1_file( $this->params['src'] );
MediaWiki\restoreWarnings();
if ( $hash !== false ) {
- $hash = wfBaseConvert( $hash, 16, 36, 31 );
+ $hash = Wikimedia\base_convert( $hash, 16, 36, 31 );
}
return $hash;
return $status;
}
- $sha1Hash = wfBaseConvert( sha1( $params['content'] ), 16, 36, 31 );
+ $sha1Hash = Wikimedia\base_convert( sha1( $params['content'] ), 16, 36, 31 );
$contentType = isset( $params['headers']['content-type'] )
? $params['headers']['content-type']
: $this->getContentType( $params['dst'], $params['content'], null );
return $status;
}
- $sha1Hash = wfBaseConvert( $sha1Hash, 16, 36, 31 );
+ $sha1Hash = Wikimedia\base_convert( $sha1Hash, 16, 36, 31 );
$contentType = isset( $params['headers']['content-type'] )
? $params['headers']['content-type']
: $this->getContentType( $params['dst'], null, $params['src'] );
for ( $i = 0; $i < 5; $i++ ) {
$s .= mt_rand( 0, 2147483647 );
}
- $s = wfBaseConvert( sha1( $s ), 16, 36, 31 );
+ $s = Wikimedia\base_convert( sha1( $s ), 16, 36, 31 );
- return substr( wfBaseConvert( wfTimestamp( TS_MW ), 10, 36, 9 ) . $s, 0, 31 );
+ return substr( Wikimedia\base_convert( wfTimestamp( TS_MW ), 10, 36, 9 ) . $s, 0, 31 );
}
/**
$db = $this->getConnection( $lockSrv ); // checked in isServerUp()
$bigints = array_unique( array_map(
function ( $key ) {
- return wfBaseConvert( substr( $key, 0, 15 ), 16, 10 );
+ return Wikimedia\base_convert( substr( $key, 0, 15 ), 16, 10 );
},
array_map( array( $this, 'sha1Base16Absolute' ), $paths )
) );
* @return string
*/
final protected function sha1Base36Absolute( $path ) {
- return wfBaseConvert( sha1( "{$this->domain}:{$path}" ), 16, 36, 31 );
+ return Wikimedia\base_convert( sha1( "{$this->domain}:{$path}" ), 16, 36, 31 );
}
/**
*/
function getSha1() {
return isset( $this->mInfo['sha1'] )
- ? wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 )
+ ? Wikimedia\base_convert( strval( $this->mInfo['sha1'] ), 16, 36, 31 )
: null;
}
// Additional job metadata
'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ),
'job_timestamp' => $dbw->timestamp(),
- 'job_sha1' => wfBaseConvert(
+ 'job_sha1' => Wikimedia\base_convert(
sha1( serialize( $job->getDeduplicationInfo() ) ),
16, 36, 31
),
// Additional job metadata
'uuid' => UIDGenerator::newRawUUIDv4( UIDGenerator::QUICK_RAND ),
'sha1' => $job->ignoreDuplicates()
- ? wfBaseConvert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 )
+ ? Wikimedia\base_convert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 )
: '',
'timestamp' => time() // UNIX timestamp
);
// Generate random hex chars
$hex = MWCryptRand::generateHex( $length );
// Convert from base 16 to base 32 to get a proper password like string
- return wfBaseConvert( $hex, 16, 32 );
+ return Wikimedia\base_convert( $hex, 16, 32 );
}
/**
// see: http://www.jwz.org/doc/mid.html
list( $usec, $sec ) = explode( ' ', microtime() );
$usec = substr( $usec, 2 );
- $key = wfBaseConvert( $sec . $usec, 10, 36 ) . '.' .
- wfBaseConvert( mt_rand(), 10, 36 ) . '.' .
+ $key = Wikimedia\base_convert( $sec . $usec, 10, 36 ) . '.' .
+ Wikimedia\base_convert( mt_rand(), 10, 36 ) . '.' .
$this->userId . '.' .
$extension;
}
}
if ( $n !== false ) {
- # Floating points can handle the conversion; faster than wfBaseConvert()
+ # Floating points can handle the conversion; faster than Wikimedia\base_convert()
$n = strtoupper( str_pad( base_convert( $n, 10, 16 ), 8, '0', STR_PAD_LEFT ) );
}
} else {
} else {
# Native 32 bit functions WONT work here!!!
# Convert to a padded binary number
- $network = wfBaseConvert( $network, 16, 2, 128 );
+ $network = Wikimedia\base_convert( $network, 16, 2, 128 );
# Truncate the last (128-$bits) bits and replace them with zeros
$network = str_pad( substr( $network, 0, $bits ), 128, 0, STR_PAD_RIGHT );
# Convert back to an integer
- $network = wfBaseConvert( $network, 2, 10 );
+ $network = Wikimedia\base_convert( $network, 2, 10 );
}
} else {
$network = false;
if ( $network === false ) {
$start = $end = false;
} else {
- $start = wfBaseConvert( $network, 10, 16, 32, false );
+ $start = Wikimedia\base_convert( $network, 10, 16, 32, false );
# Turn network to binary (again)
- $end = wfBaseConvert( $network, 10, 2, 128 );
+ $end = Wikimedia\base_convert( $network, 10, 2, 128 );
# Truncate the last (128-$bits) bits and replace them with ones
$end = str_pad( substr( $end, 0, $bits ), 128, 1, STR_PAD_RIGHT );
# Convert to hex
- $end = wfBaseConvert( $end, 2, 16, 32, false );
+ $end = Wikimedia\base_convert( $end, 2, 16, 32, false );
# see toHex() comment
$start = "v6-$start";
$end = "v6-$end";
}
file_put_contents( $this->nodeIdFile, $nodeId ); // cache
}
- $this->nodeId32 = wfBaseConvert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 );
- $this->nodeId48 = wfBaseConvert( $nodeId, 16, 2, 48 );
+ $this->nodeId32 = Wikimedia\base_convert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 );
+ $this->nodeId48 = Wikimedia\base_convert( $nodeId, 16, 2, 48 );
// If different processes run as different users, they may have different temp dirs.
// This is dealt with by initializing the clock sequence number and counters randomly.
$this->lockFile88 = wfTempDir() . '/mw-' . __CLASS__ . '-UID-88';
$gen = self::singleton();
$time = $gen->getTimestampAndDelay( 'lockFile88', 1, 1024 );
- return wfBaseConvert( $gen->getTimestampedID88( $time ), 2, $base );
+ return Wikimedia\base_convert( $gen->getTimestampedID88( $time ), 2, $base );
}
/**
$gen = self::singleton();
$time = $gen->getTimestampAndDelay( 'lockFile128', 16384, 1048576 );
- return wfBaseConvert( $gen->getTimestampedID128( $time ), 2, $base );
+ return Wikimedia\base_convert( $gen->getTimestampedID128( $time ), 2, $base );
}
/**
': sorry, this function doesn\'t work after the year 144680' );
}
- return substr( wfBaseConvert( $ts, 10, 2, 46 ), -46 );
+ return substr( Wikimedia\base_convert( $ts, 10, 2, 46 ), -46 );
}
/**
<?php
/**
- * Benchmark for wfBaseConvert
+ * Benchmark for Wikimedia\base_convert
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
require_once __DIR__ . '/Benchmarker.php';
/**
- * Maintenance script that benchmarks wfBaseConvert().
+ * Maintenance script that benchmarks Wikimedia\base_convert().
*
* @ingroup Benchmark
*/
class BenchWfBaseConvert extends Benchmarker {
public function __construct() {
parent::__construct();
- $this->mDescription = "Benchmark for wfBaseConvert.";
+ $this->mDescription = "Benchmark for Wikimedia\base_convert.";
$this->addOption( "inbase", "Input base", false, true );
$this->addOption( "outbase", "Output base", false, true );
$this->addOption( "length", "Size in digits to generate for input", false, true );
$this->bench( array(
array(
- 'function' => 'wfBaseConvert',
+ 'function' => 'Wikimedia\base_convert',
'args' => array( $number, $inbase, $outbase, 0, true, 'php' )
),
array(
- 'function' => 'wfBaseConvert',
+ 'function' => 'Wikimedia\base_convert',
'args' => array( $number, $inbase, $outbase, 0, true, 'bcmath' )
),
array(
- 'function' => 'wfBaseConvert',
+ 'function' => 'Wikimedia\base_convert',
'args' => array( $number, $inbase, $outbase, 0, true, 'gmp' )
),
) );
'media_type' => MEDIATYPE_BITMAP,
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '1', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '1', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20010115123500' ), $user );
'media_type' => MEDIATYPE_BITMAP,
'mime' => 'image/png',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '2', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '2', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20130225203040' ), $user );
'media_type' => MEDIATYPE_DRAWING,
'mime' => 'image/svg+xml',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20010115123500' ), $user );
'media_type' => MEDIATYPE_BITMAP,
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '3', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '3', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20010115123500' ), $user );
</OBJECT>
</BODY>
</DjVuXML>',
- 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20010115123600' ), $user );
}
$this->assertEquals( strlen( $fileBContents ),
$this->backend->getFileSize( array( 'src' => $fileC ) ),
"Correct file size of $fileC" );
- $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
+ $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ),
$this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
"Correct file SHA-1 of $fileC" );
}
$this->assertEquals( strlen( $fileBContents ),
$this->backend->getFileSize( array( 'src' => $fileC ) ),
"Correct file size of $fileC" );
- $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
+ $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ),
$this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
"Correct file SHA-1 of $fileC" );
}
$this->assertEquals( strlen( $fileBContents ),
$this->backend->getFileSize( array( 'src' => $fileA ) ),
"Correct file size of $fileA" );
- $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
+ $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ),
$this->backend->getFileSha1Base36( array( 'src' => $fileA ) ),
"Correct file SHA-1 of $fileA" );
}
'media_type' => MEDIATYPE_BITMAP,
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '1', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '1', 16, 36, 31 ),
'fileExists' => true ),
$this->db->timestamp( '20010115123500' ), $user
);
'media_type' => MEDIATYPE_BITMAP,
'mime' => 'image/png',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '2', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '2', 16, 36, 31 ),
'fileExists' => true ),
$this->db->timestamp( '20130225203040' ), $user
);
'media_type' => MEDIATYPE_BITMAP,
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '3', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '3', 16, 36, 31 ),
'fileExists' => true ),
$this->db->timestamp( '20010115123500' ), $user
);
'media_type' => MEDIATYPE_DRAWING,
'mime' => 'image/svg+xml',
'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20010115123500' ), $user );
}
</OBJECT>
</BODY>
</DjVuXML>',
- 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+ 'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20140115123600' ), $user );
}
$this->assertEquals( true, ctype_digit( $id ), "UID made of digit characters" );
$this->assertLessThanOrEqual( $digitlen, strlen( $id ),
"UID has the right number of digits" );
- $this->assertLessThanOrEqual( $bits, strlen( wfBaseConvert( $id, 10, 2 ) ),
+ $this->assertLessThanOrEqual( $bits, strlen( Wikimedia\base_convert( $id, 10, 2 ) ),
"UID has the right number of bits" );
$ids = array();
$this->assertSame( array_unique( $ids ), $ids, "All generated IDs are unique." );
foreach ( $ids as $id ) {
- $id_bin = wfBaseConvert( $id, 10, 2 );
- $lastId_bin = wfBaseConvert( $lastId, 10, 2 );
+ $id_bin = Wikimedia\base_convert( $id, 10, 2 );
+ $lastId_bin = Wikimedia\base_convert( $lastId, 10, 2 );
$this->assertGreaterThanOrEqual(
substr( $lastId_bin, 0, $tbits ),