Mainframe98 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/381053 )

Change subject: Convert AntiBot to use extension registration
......................................................................

Convert AntiBot to use extension registration

Bug: T176872
Change-Id: I1b31e5bc214bf830e520cadeda0bf19cba3cf3e8
---
A AntiBot.class.php
M AntiBot.php
A AntiBotHooks.php
A extension.json
4 files changed, 133 insertions(+), 104 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AntiBot 
refs/changes/53/381053/1

diff --git a/AntiBot.class.php b/AntiBot.class.php
new file mode 100644
index 0000000..3680417
--- /dev/null
+++ b/AntiBot.class.php
@@ -0,0 +1,61 @@
+<?php
+
+class AntiBot {
+       static function getSecret( $name ) {
+               global $wgAntiBotSecret, $wgSecretKey;
+               $secret = $wgAntiBotSecret ? $wgAntiBotSecret : $wgSecretKey;
+               return substr( sha1( $secret . $name ), 0, 8 );
+       }
+
+       /**
+        * Plugins should call this function when they are triggered
+        */
+       static function trigger( $pluginName ) {
+               global $wgAntiBotPayloads, $wgAntiBotPayloadTypes;
+               $ret = 'quiet';
+               if ( isset( $wgAntiBotPayloads[$pluginName] ) ) {
+                       $payloadChain = $wgAntiBotPayloads[$pluginName];
+               } else {
+                       $payloadChain = $wgAntiBotPayloads['default'];
+               }
+
+               foreach ( $payloadChain as $payloadType ) {
+                       if ( !isset( $wgAntiBotPayloadTypes[$payloadType] ) ) {
+                               wfDebug( "Invalid payload type: $payloadType\n" 
);
+                               continue;
+                       }
+                       $ret = call_user_func( 
$wgAntiBotPayloadTypes[$payloadType], $pluginName );
+               }
+               return $ret;
+       }
+
+       static function log( $pluginName ) {
+               global $wgRequest;
+               $ip = $wgRequest->getIP();
+               $action = $wgRequest->getVal( 'action', '<no action>' );
+               $title = $wgRequest->getVal( 'title', '<no title>' );
+               $text = $wgRequest->getVal( 'wpTextbox1' );
+               if ( is_null( $text ) ) {
+                       $text = '<no text>';
+               } else {
+                       if ( strlen( $text ) > 60 ) {
+                               $text = '"' . substr( $text, 0, 60 ) . '..."';
+                       } else {
+                               $text = "\"$text\"";
+                       }
+               }
+               $action = str_replace( "\n", '', $action );
+               $title = str_replace( "\n", '', $title );
+               $text = str_replace( "\n", '', $text );
+
+               wfDebugLog( 'AntiBot', "$ip AntiBot plugin $pluginName hit: 
$action [[$title]] $text\n" );
+       }
+
+       static function quiet() {
+               return 'quiet';
+       }
+
+       static function fail() {
+               return 'fail';
+       }
+}
diff --git a/AntiBot.php b/AntiBot.php
index fe908a1..4fd059d 100644
--- a/AntiBot.php
+++ b/AntiBot.php
@@ -10,112 +10,19 @@
  *
  * To install, put this in LocalSettings.php:
  *
- * require_once( "$IP/extensions/AntiBot/AntiBot.php" );
+ * wfLoadExtension( "AntiBot" );
  *
  * And then copy the plugins you want into the active directory.
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       exit( 1 );
-}
-
-/** Configuration */
-
-/**
- * Persistent secret token used for setting form field names and what not
- * Change it periodically if they try to filter by any affected form field
- */
-$wgAntiBotSecret = '';
-
-/** Configure the payload sequence when each plugin is triggered */
-$wgAntiBotPayloads = array(
-       'default' => array( 'log', 'fail' ),
-);
-
-/** END CONFIGURATION */
-
-$wgExtensionCredits['antispam'][] = array(
-       'path' => __FILE__,
-       'name' => 'AntiBot',
-       'url' => 'https://www.mediawiki.org/wiki/Extension:AntiBot',
-       'author' => 'Tim Starling',
-       'descriptionmsg' => 'antibot-desc',
-       'license-label' => 'GPL-2.0+'
-);
-
-$wgMessagesDirs['AntiBot'] = __DIR__ . '/i18n';
-
-/**
- * A map of payload types to callbacks
- * This may be extended by plugins.
- */
-$wgAntiBotPayloadTypes = array(
-       'log' => array( 'AntiBot', 'log' ),
-       'quiet' => array( 'AntiBot', 'quiet' ),
-       'fail' => array( 'AntiBot', 'fail' ),
-);
-
-# Load plugins
-foreach ( glob( __DIR__ . '/active/*.php' ) as $file ) {
-       require( $file );
-}
-
-class AntiBot {
-       static function getSecret( $name ) {
-               global $wgAntiBotSecret, $wgSecretKey;
-               $secret = $wgAntiBotSecret ? $wgAntiBotSecret : $wgSecretKey;
-               return substr( sha1( $secret . $name ), 0, 8 );
-       }
-
-       /**
-        * Plugins should call this function when they are triggered
-        */
-       static function trigger( $pluginName ) {
-               global $wgAntiBotPayloads, $wgAntiBotPayloadTypes;
-               $ret = 'quiet';
-               if ( isset( $wgAntiBotPayloads[$pluginName] ) ) {
-                       $payloadChain = $wgAntiBotPayloads[$pluginName];
-               } else {
-                       $payloadChain = $wgAntiBotPayloads['default'];
-               }
-
-               foreach ( $payloadChain as $payloadType ) {
-                       if ( !isset( $wgAntiBotPayloadTypes[$payloadType] ) ) {
-                               wfDebug( "Invalid payload type: $payloadType\n" 
);
-                               continue;
-                       }
-                       $ret = call_user_func( 
$wgAntiBotPayloadTypes[$payloadType], $pluginName );
-               }
-               return $ret;
-       }
-
-       static function log( $pluginName ) {
-               global $wgRequest;
-               $ip = $wgRequest->getIP();
-               $action = $wgRequest->getVal( 'action', '<no action>' );
-               $title = $wgRequest->getVal( 'title', '<no title>' );
-               $text = $wgRequest->getVal( 'wpTextbox1' );
-               if ( is_null( $text ) ) {
-                       $text = '<no text>';
-               } else {
-                       if ( strlen( $text ) > 60 ) {
-                               $text = '"' . substr( $text, 0, 60 ) . '..."';
-                       } else {
-                               $text = "\"$text\"";
-                       }
-               }
-               $action = str_replace( "\n", '', $action );
-               $title = str_replace( "\n", '', $title );
-               $text = str_replace( "\n", '', $text );
-
-               wfDebugLog( 'AntiBot', "$ip AntiBot plugin $pluginName hit: 
$action [[$title]] $text\n" );
-       }
-
-       static function quiet() {
-               return 'quiet';
-       }
-
-       static function fail() {
-               return 'fail';
-       }
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'AntiBot' );
+       wfWarn(
+               'Deprecated PHP entry point used for AntiBot extension. ' .
+               'Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );
+       return;
+} else {
+       die( 'This version of the AntiBot extension requires MediaWiki 1.29+' );
 }
diff --git a/AntiBotHooks.php b/AntiBotHooks.php
new file mode 100644
index 0000000..d4f0138
--- /dev/null
+++ b/AntiBotHooks.php
@@ -0,0 +1,12 @@
+<?php
+
+class AntiBotHooks {
+       /**
+        * Load plugins
+        */
+       public static function onRegistration() {
+               foreach ( glob( __DIR__ . '/active/*.php' ) as $file ) {
+                       require( $file );
+               }
+       }
+}
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..9d3d65c
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,49 @@
+{
+       "name": "AntiBot",
+       "author": "Tim Starling",
+       "url": "https://www.mediawiki.org/wiki/Extension:AntiBot";,
+       "descriptionmsg": "antibot-desc",
+       "license-name": "GPL-2.0+",
+       "MessagesDirs": {
+               "AntiBot": [
+                       "i18n"
+               ]
+       },
+       "AutoloadClasses": {
+               "AntiBotHooks": "AntiBotHooks.php"
+       },
+       "callback": "AntiBotHooks::onRegistration",
+       "config": {
+               "AntiBotSecret": {
+                       "value": "",
+                       "description": "Persistent secret token used for 
setting form field names and what not. Change it periodically if they try to 
filter by any affected form field."
+               },
+               "AntiBotPayload": {
+                       "value": {
+                               "default": [
+                                       "log",
+                                       "fail"
+                               ]
+                       },
+                       "description": "Configure the payload sequence when 
each plugin is triggered."
+               },
+               "AntiBotPayloadTypes": {
+                       "value": {
+                               "log": [
+                                       "AntiBot",
+                                       "log"
+                               ],
+                               "quiet": [
+                                       "AntiBot",
+                                       "quiet"
+                               ],
+                               "fail": [
+                                       "AntiBot",
+                                       "fail"
+                               ]
+                       },
+                       "description": "A map of payload types to callbacks. 
This may be extended by plugins."
+               }
+       },
+       "manifest_version": 2
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/381053
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1b31e5bc214bf830e520cadeda0bf19cba3cf3e8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AntiBot
Gerrit-Branch: master
Gerrit-Owner: Mainframe98 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to