Mediawiki/Anonymous IP Hash: Difference between revisions
Antonizoon (talk | contribs) |
Antonizoon (talk | contribs) No edit summary |
||
Line 8: | Line 8: | ||
Here's the gist of my anon ID hack to MediaWiki. I can't really package it as an extension or anything because it involves hacking things that | Here's the gist of my anon ID hack to MediaWiki. I can't really package it as an extension or anything because it involves hacking things that | ||
apparently aren't supposed to be hacked, but it's not hard to do. - Halcy <!-- Note that this mod makes banning IPs quite hard. Maybe if there was a way to just not show the IP address to non-Admin users, and still store the IP in the database, that would be better. But on the flip side, tanasinn.info seems to be doing fine with it. --> | apparently aren't supposed to be hacked, but it's not hard to do. - Halcy <!-- Note that this mod makes banning IPs quite hard. Maybe if there was a way to just not show the IP address to non-Admin users, and still store the IP in the database, that would be better. But on the flip side, tanasinn.info seems to be doing fine with it. We also use captchas that reduce the threat of mass edit by anonymous robots. --> | ||
1. Add the following to your LocalSettings.php: | 1. Add the following to your LocalSettings.php: |
Revision as of 21:12, 9 December 2016
By default, MediaWiki displays IP Addresses of an anonymous editor in edit history. This obviously has a chilling effect on anonymous user participation.
However, this wiki hashes these IP addresses using a salted bcrypt function, and displays the first 8 characters as an anonymous ID (e.g. ID:D9erK127
). The IDs change daily.
These are inspired by 2channel's anonymous ID hashes, as seen periodically on 4chan's /b/.
Activating Anonymous IP Hash
Here's the gist of my anon ID hack to MediaWiki. I can't really package it as an extension or anything because it involves hacking things that apparently aren't supposed to be hacked, but it's not hard to do. - Halcy
1. Add the following to your LocalSettings.php:
// you can leave anon talk pages on, but you'll // likely end up with useless crud after IDs expire $wgDisableAnonTalk = true; function AnonUsername($IP) { $options = [ 'cost' => 12, // bcrypt computation cost is 12 instead of default 10 'salt' => 'PUT RANDOM SALT HERE', // bcrypt requires 22 chars max. change the salt monthly if possible. Static salts are needed for IDs to stay the same within a day or week. Note this may be deprecated by PHP 7.0... ]; // Expiry time for hashes: dmY = new ID per day, WY = per week. $key = $IP.'PUT RANDOM PADDING HERE'.gmdate('dmY'); // The RANDOM PADDING should be 49 characters (72 - 16 - 8), since for bcrypt, the key string can only be 72 characters return 'ID:'.substr(password_hash($key, PASSWORD_BCRYPT, $options), 'id'), 8, 8); // uses bcrypt level 10 }
The ID is a truncated hash, which, although it increases the risk of collisions, that may be a benefit rather than a liability when it comes to IPs.
2. In includes/user/User.php
, (Mediawiki 1.27.1: getName() Line 2109) find the line that says:
$this->mName = IP::sanitizeIP( $this->getRequest()->getIP() );
and change it to:
$this->mName = AnonUsername( $this->getRequest()->getIP() );
3. In includes/user/User.php
, (Mediawiki 1.27.1: getBlockedStatus() Line 1600) find the line that says:
: IP::sanitizeIP( $wgUser->getRequest()->getIP() );
and change it to:
: AnonUsername( $this->getRequest()->getIP() );
You will need to repeat this mod whenever you update MediaWiki, since obviously an update replaces the system files. And of course the lines may vary, but have generally been similar.
aa tags
On a slightly related note, I hacked an extension together for <aa> tags.
- Music:DQN-kun / >>6 is not a panda