mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-12-04 20:58:13 +00:00
18d122b60d
This reverts commit 62e1fb0b5f
.
Reason for revert: caused several errors:
* unnamespaced HooksTest collides with core’s class of the same name
* Scribunto_LuaError renamed without class alias despite being used in Wikibase
Bug: T314464
Change-Id: I8b151327236bf86945e59823fba155497e4b3fc6
46 lines
896 B
PHP
46 lines
896 B
PHP
<?php
|
|
|
|
class Scribunto_LuaHashLibrary extends Scribunto_LuaLibraryBase {
|
|
|
|
public function register() {
|
|
$lib = [
|
|
'listAlgorithms' => [ $this, 'listAlgorithms' ],
|
|
'hashValue' => [ $this, 'hashValue' ],
|
|
];
|
|
|
|
return $this->getEngine()->registerInterface( 'mw.hash.lua', $lib );
|
|
}
|
|
|
|
/**
|
|
* Returns a list of known/ supported hash algorithms
|
|
*
|
|
* @internal
|
|
* @return string[][]
|
|
*/
|
|
public function listAlgorithms() {
|
|
$algos = hash_algos();
|
|
$algos = array_combine( range( 1, count( $algos ) ), $algos );
|
|
|
|
return [ $algos ];
|
|
}
|
|
|
|
/**
|
|
* Hash a given value.
|
|
*
|
|
* @internal
|
|
* @param string $algo
|
|
* @param string $value
|
|
* @return string[]
|
|
*/
|
|
public function hashValue( $algo, $value ) {
|
|
if ( !in_array( $algo, hash_algos() ) ) {
|
|
throw new Scribunto_LuaError( "Unknown hashing algorithm: $algo" );
|
|
}
|
|
|
|
$hash = hash( $algo, $value );
|
|
|
|
return [ $hash ];
|
|
}
|
|
|
|
}
|