From mediawiki.org
MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Release status: unmaintained
Implementation Special page
Description Saves hashes of uploaded files to a page.
Author(s) Artūras Šlajus <x11@arturaz.net>
Latest version 1.0 (2010-02-13)
MediaWiki 1.15.1
PHP 5.2.6
Database changes No
License BSD 3-clause "Modified" License
Download Extension:UploadedFileHasher#Code

Check usage and version matrix.

The UploadedFileHasher extension saves hashes of uploaded files to a page (as JSON). It can be used to synchronize wiki content with local file system.

Example content[edit]





Download instructions[edit]

Please cut and paste the code found below and place it in $IP/extensions/UploadedFileHasher.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.


To install this extension, add the following to LocalSettings.php:




class UploadedFileHasher {
  const HASHES_PAGE = "FileHashes";

  static function uploadComplete($file) {
    $localFile = $file->mLocalFile;

    // Use 40 chars sha1 for other systems compatibility.
    $sha1 = sha1_file($localFile->getPath());
    return self::updateHash(

  static function updateHash($filename, $sha1) {
    $title = Title::newFromText(self::HASHES_PAGE);
    $article = new Article($title);
    $content = $article->getRawText();

    $hashes = (! empty($content)) ? json_decode($content, true) : array();
    $hashes[$filename] = $sha1;

    // Add spaces for manual viewing
    $content = str_replace("\",", "\",\n\n", json_encode($hashes));

    $flag = $article->exists() ? EDIT_UPDATE : EDIT_NEW;
    $status = $article->doEdit($content, '', $flag | EDIT_FORCE_BOT);
    return $status->ok;

function UploadedFileHasherUploadComplete($file) {
  return UploadedFileHasher::uploadComplete($file);

$wgHooks['UploadComplete'][] = 'UploadedFileHasherUploadComplete';