MediaWiki REL1_34
HashLibrary.php
Go to the documentation of this file.
1<?php
2
4
5 public function register() {
6 $lib = [
7 'listAlgorithms' => [ $this, 'listAlgorithms' ],
8 'hashValue' => [ $this, 'hashValue' ],
9 ];
10
11 return $this->getEngine()->registerInterface( 'mw.hash.lua', $lib );
12 }
13
20 public function listAlgorithms() {
21 $algos = hash_algos();
22 $algos = array_combine( range( 1, count( $algos ) ), $algos );
23
24 return [ $algos ];
25 }
26
35 public function hashValue( $algo, $value ) {
36 if ( !in_array( $algo, hash_algos() ) ) {
37 throw new Scribunto_LuaError( "Unknown hashing algorithm: $algo" );
38 }
39
40 $hash = hash( $algo, $value );
41
42 return [ $hash ];
43 }
44
45}
hashValue( $algo, $value)
Hash a given value.
listAlgorithms()
Returns a list of known/ supported hash algorithms.
This class provides some basic services that Lua libraries will probably need.
getEngine()
Get the engine.