Changeset 35682
- Timestamp:
- 03/21/08 11:25:50 (4 months ago)
- Location:
- worst-offenders/trunk
- Files:
-
- 11 modified
-
classes/all_litmus.php (modified) (3 diffs)
-
classes/domain_litmus.php (modified) (2 diffs)
-
classes/email_litmus.php (modified) (3 diffs)
-
classes/ip_litmus.php (modified) (2 diffs)
-
classes/litmus.php (modified) (3 diffs)
-
classes/md5_litmus.php (modified) (2 diffs)
-
classes/multilink_litmus.php (modified) (3 diffs)
-
classes/name_length_litmus.php (modified) (3 diffs)
-
functions.php (modified) (7 diffs)
-
plugin.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
worst-offenders/trunk/classes/all_litmus.php
r35513 r35682 19 19 class AllLitmus extends Litmus { 20 20 21 function rollCall() {22 echo("<p>All Litmus</p>");23 }24 25 function addIndex() {26 }27 28 21 function getName() { 29 22 return "All"; … … 34 27 } 35 28 36 function addCount() {29 public static function getMatches() { 37 30 } 31 32 public static function tab() { 33 global $wo3_title, $keys; 38 34 39 function getMatches() {40 }41 42 public static function tab() {43 global $wo3_title;44 35 parent::tab( 45 36 self::getName(), 46 get_option( $keys['total_count'] ),37 wp_cache_get("current_count", $wo3_title), 47 38 self::isActive() 48 39 ); … … 72 63 } 73 64 } 65 74 66 } 75 67 } -
worst-offenders/trunk/classes/domain_litmus.php
r35135 r35682 9 9 */ 10 10 11 //drop function if exists test1;12 //create FUNCTION address (url TEXT)13 //RETURNS varchar(255)14 //CONTAINS SQL DETERMINISTIC15 //RETURN16 // SUBSTRING_INDEX(17 // TRIM(18 // LEADING "http://" FROM TRIM(url)19 // ),20 // "?",21 // 122 // );23 //SELECT address(" http://www.spoamtastic.com:80/blog/arse?123=456 ") AS subdomain;24 25 26 11 if (class_exists('Litmus')) { 12 add_action('wo3_prep', array('DomainLitmus', 'getCount')); 27 13 add_action('wo3_tabs', array('DomainLitmus', 'tab')); 28 14 add_action('wo3_content', array('DomainLitmus', 'content')); 29 add_action('wo3_total_count', array('DomainLitmus', 'addCount'));30 add_action('wo3_rollcall', array('DomainLitmus', 'rollCall'));31 15 add_action('wo3_add_index', array('DomainLitmus', 'addIndex')); 32 16 33 17 class DomainLitmus extends Litmus { 34 18 19 function getName() { 20 return "Domain"; 21 } 22 23 public static function getMatches() { 24 global $keys; 25 $lower_limit = get_option( $keys['ui_vis'] ); 26 return self::runCachedMatchesQuery( 27 self::getName(), 28 "select count(*) as num, address(comment_author_url) as comment_author_url_simplified, group_concat(comment_id separator ',') as comment_id_list from wp_comments where comment_approved='spam' and comment_author_url != '' group by comment_author_url_simplified having num >= $lower_limit order by num desc;" 29 ); 30 } 31 32 function content() { 33 if (DomainLitmus::isActive() || AllLitmus::isActive() ) { 34 $comments = DomainLitmus::getMatches(); 35 echo("<table>"); 36 foreach($comments as $comment) { 37 Litmus::wo3_show_row($comment->num, "comments from ".$comment->comment_author_url_simplified, $comment->comment_id_list); 38 } 39 echo("</table>"); 40 } 41 } 42 35 43 function addIndex() { 36 44 global $wpdb; … … 43 51 } 44 52 45 function rollCall() { 46 echo("<p>Domain</p>"); 53 54 //============================================ 55 // common class methods for litmus tests 56 // (there's got to be a better way to do this! 57 //============================================ 58 59 function getCount() { 60 global $wo3_title; 61 self::getMatches(); 62 return wp_cache_get(self::getName()."_count", $wo3_title); 47 63 } 48 49 function getName() { 50 return "Domain"; 51 } 52 53 54 function getCount() { 55 global $wpdb, $keys; 56 $lower_limit = get_option( $keys['ui_vis'] ); 57 $q = "select sum(x.num) from (select count(*) as num from wp_comments where comment_approved='spam' and address(comment_author_url) != '' group by address(comment_author_url) having num >= $lower_limit) as x;"; 58 $num = $wpdb->get_var($q); 59 if ($num == null) return "0"; 60 return $num; 61 } 62 63 64 function addCount() { 65 global $keys; 66 update_option( $keys['total_count'], DomainLitmus::getCount() + get_option( $keys['total_count'] ) ); 67 } 68 69 70 function getMatches() { 71 global $wpdb, $keys; 72 $lower_limit = get_option( $keys['ui_vis'] ); 73 $q= "select count(*) as num, address(comment_author_url) as comment_author_url_simplified, group_concat(comment_id separator ',') as comment_id_list from wp_comments where comment_approved='spam' and comment_author_url != '' group by comment_author_url_simplified having num >= $lower_limit order by num desc;"; 74 return $wpdb->get_results($q); 75 } 76 64 77 65 public static function tab() { 78 66 parent::tab(self::getName(), self::getCount(), self::isActive()); 79 67 } 80 81 68 82 69 function isActive() { 83 return ($_GET['tab'] == DomainLitmus::getName() ) && parent::isActive();70 return ($_GET['tab'] == self::getName() ) && parent::isActive(); 84 71 } 85 72 86 87 function content() {88 if (DomainLitmus::isActive() || AllLitmus::isActive() ) {89 $comments = DomainLitmus::getMatches();90 echo("<table>");91 foreach($comments as $comment) {92 Litmus::wo3_show_row($comment->num, "comments from ".$comment->comment_author_url_simplified, $comment->comment_id_list);93 }94 echo("</table>");95 }96 97 98 }99 73 100 74 } -
worst-offenders/trunk/classes/email_litmus.php
r35135 r35682 9 9 */ 10 10 11 //drop function if exists test1;12 //create FUNCTION address (url TEXT)13 //RETURNS varchar(255)14 //CONTAINS SQL DETERMINISTIC15 //RETURN16 // SUBSTRING_INDEX(17 // TRIM(18 // LEADING "http://" FROM TRIM(url)19 // ),20 // "?",21 // 122 // );23 //SELECT address(" http://www.spoamtastic.com:80/blog/arse?123=456 ") AS subdomain;24 25 26 11 if (class_exists('Litmus')) { 12 add_action('wo3_prep', array('EmailLitmus', 'getCount')); 27 13 add_action('wo3_tabs', array('EmailLitmus', 'tab')); 28 14 add_action('wo3_content', array('EmailLitmus', 'content')); 29 add_action('wo3_total_count', array('EmailLitmus', 'addCount'));30 add_action('wo3_rollcall', array('EmailLitmus', 'rollCall'));31 15 add_action('wo3_add_index', array('EmailLitmus', 'addIndex')); 32 16 33 17 class EmailLitmus extends Litmus { 34 35 function addIndex() {36 global $wpdb;37 echo("<p>Adding index and fucntion for URL addresses.</p>");38 $wpdb->query("ALTER TABLE 'wp_comments' ADD INDEX email_spotter'('comment_author_email');");39 }40 41 function rollCall() {42 echo("<p>Email</p>");43 }44 18 45 19 function getName() { … … 47 21 } 48 22 49 function getCount() {50 global $ wpdb, $keys;23 public static function getMatches() { 24 global $keys; 51 25 $lower_limit = get_option( $keys['ui_vis'] ); 52 $q = "select sum(x.num) from (select count(*) as num from wp_comments where comment_approved='spam' and comment_author_email != '' group by comment_author_email having num >= $lower_limit) as x;"; 53 $num = $wpdb->get_var($q); 54 if ($num == null) return "0"; 55 return $num; 56 } 57 58 function addCount() { 59 global $keys; 60 update_option( $keys['total_count'], EmailLitmus::getCount() + get_option( $keys['total_count'] ) ); 61 } 62 63 function getMatches() { 64 global $wpdb, $keys; 65 $lower_limit = get_option( $keys['ui_vis'] ); 66 $q= "select count(*) as num, comment_author_email, group_concat(comment_id separator ',') as comment_id_list from wp_comments where comment_approved='spam' and comment_author_email != '' group by comment_author_email having num >= $lower_limit order by num desc;"; 67 return $wpdb->get_results($q); 68 } 69 70 public static function tab() { 71 parent::tab(self::getName(), self::getCount(), self::isActive()); 72 } 73 74 75 function isActive() { 76 return ($_GET['tab'] == EmailLitmus::getName() ) && parent::isActive(); 26 return self::runCachedMatchesQuery( 27 self::getName(), 28 "select count(*) as num, comment_author_email, group_concat(comment_id separator ',') as comment_id_list from wp_comments where comment_approved='spam' and comment_author_email != '' group by comment_author_email having num >= $lower_limit order by num desc;" 29 ); 77 30 } 78 31 79 32 function content() { 80 81 33 if ( EmailLitmus::isActive() || AllLitmus::isActive() ) { 82 34 $comments = EmailLitmus::getMatches(); … … 87 39 echo("</table>"); 88 40 } 41 } 89 42 43 function addIndex() { 44 global $wpdb; 45 echo("<p>Adding index and fucntion for URL addresses.</p>"); 46 $wpdb->query("ALTER TABLE 'wp_comments' ADD INDEX email_spotter'('comment_author_email');"); 47 } 90 48 49 //============================================ 50 // common class methods for litmus tests 51 // (there's got to be a better way to do this! 52 //============================================ 53 54 function getCount() { 55 global $wo3_title; 56 self::getMatches(); 57 return wp_cache_get(self::getName()."_count", $wo3_title); 91 58 } 59 60 public static function tab() { 61 parent::tab(self::getName(), self::getCount(), self::isActive()); 62 } 63 64 function isActive() { 65 return ($_GET['tab'] == self::getName() ) && parent::isActive(); 66 } 67 92 68 93 69 } -
worst-offenders/trunk/classes/ip_litmus.php
r35135 r35682 9 9 */ 10 10 11 // very useful12 // ALTER TABLE `wpdb`.`wp_comments` ADD INDEX `ip_spotter`(`comment_author_IP`);13 14 // this one was less useful...15 // ALTER TABLE `wpdb`.`wp_comments` ADD INDEX `comment_approved_txt`(`comment_approved`);16 17 11 if (class_exists('Litmus')) { 12 add_action('wo3_prep', array('IPLitmus', 'getCount')); 18 13 add_action('wo3_tabs', array('IPLitmus', 'tab')); 19 14 add_action('wo3_content', array('IPLitmus', 'content')); 20 add_action('wo3_total_count', array('IPLitmus', 'addCount')); 21 add_action('wo3_rollcall', array('IPLitmus', 'rollCall')); 22 // add_action('wo3_add_index', array('IPLitmus', 'addIndex')); 15 add_action('wo3_add_index', array('IPLitmus', 'addIndex')); 23 16 24 17 class IPLitmus extends Litmus { 25 26 function addIndex() {27 // global $wpdb;28 // $q = "ALTER TABLE 'wp_comments' ADD INDEX 'ip_spotter'('comment_author_IP');";29 // $x = $wpdb->query($q);30 // echo("<p>Adding index for IP addresses: $x.</p>");31 }32 33 function rollCall() {34 echo("<p>IP Litmus</p>");35 }36 37 18 38 19 function getName() { 39 20 return "IP"; 40 21 } 41 42 43 function getCount() { 44 global $wpdb, $keys; 22 23 public static function getMatches() { 24 global $keys; 45 25 $lower_limit = get_option( $keys['ui_vis'] ); 46 $q = "select sum(x.num) from (select count(*) as num from wp_comments where comment_approved='spam' group by comment_author_ip having num >= $lower_limit) as x;";47 $num = $wpdb->get_var($q);48 if ($num == null) return "0";49 return $num;26 return self::runCachedMatchesQuery( 27 self::getName(), 28 "select comment_author_ip, count(comment_id) as num, group_concat(comment_ID separator ',') as comment_id_list from wp_comments where comment_approved='spam' group by comment_author_ip having num >= $lower_limit order by num;" 29 ); 50 30 } 51 31 52 53 function addCount() {54 global $keys;55 update_option( $keys['total_count'], IPLitmus::getCount() + get_option( $keys['total_count'] ) );56 }57 58 59 function getMatches() {60 global $wpdb, $keys;61 $lower_limit = get_option( $keys['ui_vis'] );62 $q =63 "select comment_author_ip, count(comment_id) as num, group_concat(comment_ID separator ',') as comment_id_list64 from wp_comments65 where comment_approved='spam'66 group by comment_author_ip67 having num >= $lower_limit68 order by num;";69 70 return $wpdb->get_results($q);71 }72 73 public static function tab() {74 parent::tab(self::getName(), self::getCount(), self::isActive());75 }76 77 function isActive() {78 return ($_GET['tab'] == IPLitmus::getName() ) && parent::isActive();79 }80 81 82 32 function content() { 83 84 33 if (IPLitmus::isActive() || AllLitmus::isActive()) { 85 34 $comments = IPLitmus::getMatches(); … … 90 39 echo("</table>"); 91 40 } 41 } 42 43 function addIndex() { 44 global $wpdb; 45 $q = "ALTER TABLE 'wp_comments' ADD INDEX 'ip_spotter'('comment_author_IP');"; 46 $x = $wpdb->query($q); 47 echo("<p>Adding index for IP addresses: $x.</p>"); 48 } 92 49 93 50 51 //============================================ 52 // common class methods for litmus tests 53 // (there's got to be a better way to do this! 54 //============================================ 55 56 function getCount() { 57 global $wo3_title; 58 self::getMatches(); 59 return wp_cache_get(self::getName()."_count", $wo3_title); 60 } 61 62 public static function tab() { 63 parent::tab(self::getName(), self::getCount(), self::isActive()); 64 } 65 66 function isActive() { 67 return ($_GET['tab'] == self::getName() ) && parent::isActive(); 94 68 } 95 69 -
worst-offenders/trunk/classes/litmus.php
r35135 r35682 2 2 3 3 abstract class Litmus { 4 5 var $classname = null;6 4 7 5 // Override this method to name your litmus test … … 11 9 // Override this method to count the current number of items matched by your litmus test 12 10 abstract function getCount(); 13 14 // Add any indexes required by this Litmus Test15 abstract function addIndex();16 11 17 // Override this method to add the result of getcount to $wo2_total_cpount 18 abstract function addCount() ; 19 20 // Override this method to retrieve matches to your litmus test 21 abstract function getMatches(); 12 abstract static function getMatches() ; 22 13 23 14 // This method should only be overridden if you want your tab to look different … … 28 19 } 29 20 21 public static function runCachedMatchesQuery($name, $q) { 22 global $wpdb, $wo3_title; 23 24 echo("\n<!-- Query is: $q -->\n"); 25 26 $result = wp_cache_get($name, $wo3_title); 27 if($result == false) { 28 $result= $wpdb->get_results($q); 29 echo("<!-- cache miss $name -->\n"); 30 echo("<!-- query gave ".sizeof($result)." results -->\n"); 31 wp_cache_add($name, $result, $wo3_title); 32 } else { 33 echo("<!-- cache hit $name -->\n"); 34 } 35 36 self::updateCount($name, $result); 37 38 return $result; 39 } 40 41 42 private static function updateCount($name, $results) { 43 global $wo3_title; 44 echo("<!-- updating count from ".sizeof($results)." results -->\n"); 45 $ids = array(); 46 foreach($results as $result) { 47 if (isset($result->comment_id_list)) { 48 $ids = array_merge($ids, explode(",",$result->comment_id_list)); 49 echo("<!-- its a list of ".sizeof($ids)." -->\n"); 50 } 51 if (isset($result->comment_id)) { 52 echo("<!-- its an id -->\n"); 53 $ids[] = $result->comment_id; 54 } 55 } 56 $ids = array_unique($ids); 57 wp_cache_set($name."_count", sizeof($ids), $wo3_title); 58 echo("<!-- ".sizeof($results)." results gave ".sizeof($ids)." distinct ids -->\n"); 59 60 $current_ids = wp_cache_get("current_ids", $wo3_title); 61 if ($current_ids == false) $current_ids = array(); 62 $current_ids = array_merge($current_ids, $ids); 63 $current_ids = array_unique($current_ids); 64 wp_cache_set("current_ids", $current_ids, $wo3_title); 65 wp_cache_set("current_count", sizeof($current_ids), $wo3_title); 66 echo("<!-- current_count is now ".sizeof($current_ids)." -->\n"); 67 68 } 30 69 31 70 function isActive() { -
worst-offenders/trunk/classes/md5_litmus.php
r35135 r35682 9 9 */ 10 10 11 // ALTER TABLE `wpdb`.`wp_comments` ENGINE = MyISAM ROW_FORMAT = DYNAMIC;12 // ALTER TABLE `wpdb`.`wp_comments` ADD FULLTEXT INDEX `content_fulltext`(`comment_content`);13 14 15 // SELECT16 // p.id,17 // COUNT(IF(MATCH (p.name) AGAINST ('the colour purple'),1,NULL) AS name_score18 //FROM19 // Product as p USE INDEX (name), ProductCategory as pc, Category as c20 //WHERE21 22 //CREATE FUNCTION wordcount2 ( a text, b VARCHAR(255) )23 // RETURNS INTEGER24 // CONTAINS SQL DETERMINISTIC25 //RETURN (CHAR_LENGTH(a)-CHAR_LENGTH(REPLACE(a, b, '')))/CHAR_LENGTH(b);26 27 //SELECT comment_id, wordcount2(comment_content, "http"), comment_content FROM wp_comments where //comment_approved="spam";28 29 30 31 11 if (class_exists('Litmus')) { 12 add_action('wo3_prep', array('MD5Litmus', 'getCount')); 32 13 add_action('wo3_tabs', array('MD5Litmus', 'tab')); 33 14 add_action('wo3_content', array('MD5Litmus', 'content')); 34 add_action('wo3_total_count', array('MD5Litmus', 'addCount'));35 add_action('wo3_rollcall', array('MD5Litmus', 'rollCall'));36 15 add_action('wo3_add_index', array('MD5Litmus', 'addIndex')); 37 16 38 17 class MD5Litmus extends Litmus { 18 19 function getName() { 20 return "MD5"; 21 } 22 23 public static function getMatches() { 24 global $keys; 25 $lower_limit = get_option( $keys['ui_vis'] ); 26 echo "\n<!-- ".self::getName().".getMatches() -->\n"; 27 return self::runCachedMatchesQuery( 28 self::getName(), 29 "SELECT count(*) num, MD5(comment_content) as comment_content_md5, group_concat(comment_id separator ',') as comment_id_list FROM wp_comments where comment_approved='spam' group by comment_content_md5 having num >= $lower_limit order by num desc;" 30 ); 31 } 32 33 function content() { 34 if (self::isActive() || AllLitmus::isActive()) { 35 $comments = self::getMatches(); 36 echo("<table>"); 37 if (!AllLitmus::isActive()) echo("<tr><th></th><th>Links</th><th>Message ID</th></tr>"); 38 foreach($comments as $comment) { 39 Litmus::wo3_show_row($comment->num, "messages match MD5(".$comment->comment_content_md5.")", $comment->comment_id_list); 40 } 41 echo("</table>"); 42 } else { 43 echo "\n<!-- ".self::getName()." is not active -->\n"; 44 } 45 } 39 46 40 47 function addIndex() { … … 51 58 echo("<p>Adding index for MD5s.</p>"); 52 59 } 60 61 62 //============================================ 63 // common class methods for litmus tests 64 // (there's got to be a better way to do this! 65 //============================================ 53 66 54 function rollCall() { 55 echo("<p>MD5 Litmus</p>"); 67 function getCount() { 68 global $wo3_title; 69 self::getMatches(); 70 return wp_cache_get(self::getName()."_count", $wo3_title); 56 71 } 57 58 function getName() { 59 return "MD5"; 60 } 61 62 function getCount() { 63 global $wpdb, $keys; 64 $lower_limit = get_option( $keys['ui_vis'] ); 65 $q="select sum(x.num) from (select count(*) as num from wp_comments where comment_approved='spam' group by md5(comment_content) having num >= $lower_limit) as x;"; 66 $num = $wpdb->get_var($q); 67 if ($num == null) return "0"; 68 return $num; 69 } 70 71 function addCount() { 72 global $keys; 73 update_option( $keys['total_count'], self::getCount() + get_option( $keys['total_count'] ) ); 74 } 75 76 function getMatches() { 77 global $wpdb, $keys; 78 $lower_limit = get_option( $keys['ui_vis'] ); 79 $q = "SELECT count(*) num, MD5(comment_content) as comment_content_md5, group_concat(comment_id separator ',') as comment_id_list FROM wp_comments where comment_approved='spam' group by comment_content_md5 having num >= $lower_limit order by num desc;"; 80 return $wpdb->get_results($q); 81 } 82 72 83 73 public static function tab() { 84 74 parent::tab(self::getName(), self::getCount(), self::isActive()); 85 75 } 86 76 87 77 function isActive() { 88 return $_GET['tab'] == self::getName() && parent::isActive();78 return ($_GET['tab'] == self::getName() ) && parent::isActive(); 89 79 } 90 80 91 92 function content() {93 94  
