Lucas_Werkmeister_WMDE added a comment.
Well, I don’t think being able to reproduce those hashes externally was a
design goal for Wikibase… I’m not sure what else I can say about your question
that you couldn’t also get from looking at the code directly:
name=Reference.php
public function getHash() {
// For considering the reference snaks' property order without
actually manipulating the
// reference snaks's order, a new SnakList is generated. The
new SnakList is ordered
// by property and its hash is returned.
$orderedSnaks = new SnakList( $this->snaks );
$orderedSnaks->orderByProperty();
return $orderedSnaks->getHash();
}
name=SnakList.php
public function getHash() {
$hasher = new MapValueHasher();
return $hasher->hash( $this );
}
name=MapValueHasher.php
public function hash( $map ) {
if ( !is_array( $map ) && !( $map instanceof Traversable ) ) {
throw new InvalidArgumentException( '$map must be an
array or an instance of Traversable' );
}
$hashes = [];
foreach ( $map as $hashable ) {
$hashes[] = $hashable->getHash();
}
if ( !$this->isOrdered ) {
sort( $hashes );
}
return sha1( implode( '|', $hashes ) );
}
name=SnakObject.php
public function getHash() {
return sha1( serialize( $this ) );
}
The most important part for you is probably that the hash is based on the PHP
serialization of the snak (see the `serialize()` call in the last code
snippet), which means it will be pretty painful to reproduce faithfully.
If your goal is to verify EntitySchemas – do you really need to produce the
same hashes as Wikibase? Surely no EntitySchema depends on the specific value
of a value or reference hash (`prov:wasDerivedFrom [ wdref:0000~ ]`, reference
hash starts with four zeroes?), so I would hope that you could use some other
hashing method.
TASK DETAIL
https://phabricator.wikimedia.org/T283997
EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: Addshore, Lucas_Werkmeister_WMDE
Cc: Lucas_Werkmeister_WMDE, Aklapper, Andrawaag, Invadibot, maantietaja,
Akuckartz, Nandana, Lahi, Gq86, GoranSMilovanovic, QZanden, LawExplorer,
_jensen, rosalieper, Scott_WUaS, Wikidata-bugs, aude, Addshore, Mbch331
_______________________________________________
Wikidata-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]