r48046 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48045‎ | r48046 | r48047 >
Date:04:37, 5 March 2009
Author:werdna
Status:deferred
Tags:
Comment:
Add HoneypotIntegration extension to subversion.
Modified paths:
  • /trunk/extensions/HoneypotIntegration (added) (history)
  • /trunk/extensions/HoneypotIntegration/HoneypotIntegration.class.php (added) (history)
  • /trunk/extensions/HoneypotIntegration/HoneypotIntegration.i18n.php (added) (history)
  • /trunk/extensions/HoneypotIntegration/HoneypotIntegration.php (added) (history)

Diff [purge]

Index: trunk/extensions/HoneypotIntegration/HoneypotIntegration.php
@@ -0,0 +1,36 @@
 2+<?php
 3+
 4+if ( !defined('MEDIAWIKI') )
 5+ die( "This is a MediaWiki extension definition file; it is not a valid entry point." );
 6+
 7+/**#@+
 8+ * Provides integration with Project Honeypot for Wikimedia sites.
 9+ * Requires
 10+ * @addtogroup Extensions
 11+ *
 12+ *
 13+ * @author Andrew Garrett <andrew@werdn.us>
 14+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 15+ */
 16+
 17+$dir = dirname(__FILE__);
 18+$wgExtensionCredits['other'][] = array(
 19+ 'name' => 'HoneypotIntegration',
 20+ 'author' => 'Andrew Garrett',
 21+ 'svn-date' => '$LastChangedDate: 2009-03-05 13:43:05 +1100 (Thu, 05 Mar 2009) $',
 22+ 'svn-revision' => '$LastChangedRevision: 48042 $',
 23+ 'description' => 'Provides integration with Project Honeypot for Wikimedia sites',
 24+ 'descriptionmsg' => 'honeypot-desc',
 25+);
 26+
 27+$wgExtensionMessagesFiles['HoneypotIntegration'] = "$dir/Honeypot.i18n.php";
 28+$wgAutoloadClasses[ 'HoneypotIntegration' ] = "$dir/HoneypotIntegration.class.php";
 29+
 30+$wgHooks['AbuseFilter-filterAction'][] = 'HoneypotIntegration::onAbuseFilterFilterAction';
 31+$wgHooks['AbuseFilter-builder'][] = 'HoneypotIntegration::onAbuseFilterBuilder';
 32+$wgHooks['EditPage::showEditForm:fields'][] = 'HoneypotIntegration::onShowEditForm';
 33+
 34+$wgHoneypotURLs = array( 'http://www.google.com' );
 35+$wgHoneypotTemplates = array(
 36+ '<a href="honeypoturl"><!-- randomtext --></a>',
 37+);
\ No newline at end of file
Index: trunk/extensions/HoneypotIntegration/HoneypotIntegration.class.php
@@ -0,0 +1,64 @@
 2+<?php
 3+
 4+class HoneypotIntegration {
 5+ public static function onAbuseFilterFilterAction( &$vars, $title ) {
 6+ $vars->setVar( 'honeypot_list_count', self::listingCount() ? 1 : 0 );
 7+ return true;
 8+ }
 9+
 10+ public static function onAbuseFilterBuilder( &$builder ) {
 11+ wfLoadExtensionMessages( 'HoneypotIntegration' );
 12+ $builder['vars']['honeypot_list_count'] = 'honeypot-list-count';
 13+ return true;
 14+ }
 15+
 16+ public static function listingCount( $ip = null ) {
 17+ if ($ip === null)
 18+ $ip = wfGetIP();
 19+
 20+ // TODO IMPLEMENT
 21+ return 0;
 22+ }
 23+
 24+ public static function onShowEditForm( &$editPage, &$out ) {
 25+
 26+ // Spammers are more likely to fall for real text than for a random token.
 27+ // Extract a decent-sized string from the text
 28+ $editText = $editPage->textbox1;
 29+ $randomText = '';
 30+
 31+ if ( strlen($editText) > 10 ) {
 32+ // Start somewhere in the first quarter of the text,
 33+ // run for somewhere between a quarter and a half of the text, or 100-1000 bytes,
 34+ // whichever is shorter.
 35+ $start = rand( 0, strlen($editText)/4 );
 36+ $length = rand( min( strlen($editText)/4, 100 ), min( strlen($editText)/2, 1000 ) );
 37+ $randomText = substr( $editText, $start, $length );
 38+ }
 39+
 40+ $out->addHTML( self::generateHoneypotLink( $randomText ) );
 41+ return 1;
 42+ }
 43+
 44+ public static function generateHoneypotLink( $randomText = null ) {
 45+ global $wgHoneypotURLs, $wgHoneypotTemplates;
 46+
 47+ $index = rand( 0, count($wgHoneypotURLs)-1 );
 48+ $url = $wgHoneypotURLs[$index];
 49+ $index = rand( 0, count($wgHoneypotTemplates)-1 );
 50+ $template = $wgHoneypotTemplates[$index];
 51+
 52+ if (!$randomText)
 53+ $randomText = wfGenerateToken( );
 54+
 55+ // Variable replacement
 56+ $output = strtr( $template,
 57+ array(
 58+ 'honeypoturl' => $url,
 59+ 'randomtext' => htmlspecialchars($randomText)
 60+ )
 61+ );
 62+
 63+ return "$output\n";
 64+ }
 65+}
\ No newline at end of file
Index: trunk/extensions/HoneypotIntegration/HoneypotIntegration.i18n.php
@@ -0,0 +1,9 @@
 2+<?php
 3+
 4+$messages = array();
 5+
 6+$messages['en'] = array(
 7+ 'honeypot-desc' => 'Provides integration with Project Honeypot for Wikimedia sites',
 8+ 'abusefilter-edit-builder-vars-honeypot-list-count' =>
 9+ 'Number of recet events the IP address has triggered, according to Project Honeypot',
 10+);

Status & tagging log