TclScripts/Mediawiki

A tcl script for eggdrop and mediawiki.

by mutante 01:49, 25 October 2005 (CEST)

Features
Mediawiki.tcl


 * .title - SEARCHes for a string in page TITLE (Alias .find)
 * .content - SEARCHes for a string in the page CONTENT (Alias .full)
 * .display - SHOWs the CONTENT of a wiki page (currently first 120 chars)
 * .rc - SHOWs the last x CHANGES on the Wiki (Recent Changes)
 * .popular - SHOW the most POPULAR wiki pages (hit count)
 * .stats - SHOW the wiki STATISTICS
 * .ban  - ADD an IP BAN from the Wiki (for x days with reason 'spammer')
 * .unban - REMOVE an IP BAN from the Wiki.
 * .teach - Bonus Trigger: TEACH padma (infobot) about ;)
 * .help - SHOW this HELP message

Source

 * 1)      ____  ____
 * 2)  ___|___ \|___ /
 * 3) / __| __) | |_ \
 * 4) \__ \/ __/ ___) |
 * |___/_____|____/.org/wiki/
 * 1) mediawiki.tcl v0.5
 * 2) A Mediawiki <-> IRC - Eggdrop TCL script
 * 3) tested on mediawiki 1.4/1.5 and eggdrop 1.6.13/1.6.16
 * 4) Mediawiki: http://meta.wikimedia.org/wiki/Mediawiki | #mediawiki on Freenode
 * 5) Eggdrop: http://eggheads.org/ | http://egghelp.org/ | #egghelp on Efnet
 * 6) by mutante (http://s23.org/wiki/User:mutante) (mutante@s23.org) of
 * 7) the S23 Cabal (http://s23.org/wiki/) | #wiki,#bots on Efnet
 * 8) v0.23 pre-release by [Hyarion]'s request. 25.Okt.2005
 * 9) licensed under "Attribution-NonCommercial-ShareAlike 2.0"
 * 10) http://creativecommons.org/licenses/by-nc-sa/2.0/
 * 11) v.05 completely updated mysql queries due to mediawiki 1.5 upgrade
 * 1) v.05 completely updated mysql queries due to mediawiki 1.5 upgrade

set file /usr/lib/mysqltcl-3.02/libmysqltcl3.02
 * 1) this script uses "libmysqltcl" for the TCL<->Mysql connection
 * 2) you can get it from http://rufus.o-town.de/eggdrop/
 * 3) set file /usr/lib/mysqltcl-2.30/libmysqltcl2.30
 * 4) newer version of libmysqltcl since Debian etch stable

load ${file}[info sharedlibextension]


 * 1) config
 * 1) config

set myhost "localhost" set myuser "wikiuser" set mydb "wikidb" set mypass "xxxxxxx"
 * 1) MYSQL
 * 2) database host
 * 1) database user
 * 1) database name
 * 1) database password

set mywiki "S23-Wiki" set mybaseurl "http://s23.org/wiki"
 * 1) BASIC
 * 2) Name of your Wiki
 * 1) (All Your Base..) URL (the part before the wiki page name)


 * 1) MISC

set myrcnum "5" set myfindlimit "5" set myspamdays "5" set myotherbot "padma" set mypopnum "5" set mysetupdate "Feb,04 2005" set mydisplaychars "180"
 * 1) number of recent changes displayed on .rc
 * 1) max number of results shown on .find and .content
 * 1) number of days a spammer is blocked on .ban
 * 1) name of another (infobot) bot used on .teach
 * 1) number of popular pages displayed on .popular
 * 1) the date your wiki was setup ,used on .stats
 * 1) number of characters shown of a wikipage content on .display




 * 1) the (public) triggers

bind pub - .rc wikirc
 * 1) Recent changes

bind pub - .find findpage bind pub - .title findpage
 * 1) Search in titles

bind pub - .content findcontent bind pub - .full findcontent
 * 1) Search fulltext

bind pub - .popular popular
 * 1) Show popular pages

bind pub - .display display
 * 1) Display page content (first x chars)

bind pub - .teach teach
 * 1) Teach other (info)bot

bind pub - .stats wikistats
 * 1) Show Statistics

bind pub - .sysops sysops
 * 1) Show Sysops

bind pub - .quote quote bind pub - !orakel specialquote bind pub - .23c3quote specialquote
 * 1) Show discordian quote


 * 1) add / remove IP bans (only for users with +W flag)

bind pub W .ban ban bind pub W .unban unban

bind pub - !wikisearch wikisearch
 * 1) search for wikis in wikistats

bind pub - .help help
 * 1) help


 * 1) the procs

proc help {nick host hand chan args} { puthelp "privmsg $chan : Mediawiki.tcl script by S23/mutante. Here are the triggers, $nick" puthelp "privmsg $chan : .title - SEARCHes for a string in page TITLE (Alias .find)" puthelp "privmsg $chan : .content - SEARCHes for a string in the page CONTENT (Alias .full)" puthelp "privmsg $chan : .display - SHOWs the CONTENT of a wiki page (currently first $::mydisplaychars chars)" puthelp "privmsg $chan : .rc - SHOWs the last 5 CHANGES on the Wiki (Recent Changes)" puthelp "privmsg $chan : .popular - SHOW the most POPULAR wiki pages (hit count)" puthelp "privmsg $chan : .sysops - SHOW the wiki SYSOPS" puthelp "privmsg $chan : .stats - SHOW the wiki STATISTICS" puthelp "privmsg $chan : .ban  - ADD an IP BAN from the Wiki (for 5 days with reason 'spammer')" puthelp "privmsg $chan : .unban - REMOVE an IP BAN from the Wiki." puthelp "privmsg $chan : .teach - Bonus Trigger: TEACH padma (infobot) about ;)" puthelp "privmsg $chan : .quote - Display a random discordian quote." puthelp "privmsg $chan : .help - SHOW this HELP message" puthelp "privmsg $chan : (K)2006 The S23-Cabal - visit us on http://s23.org/wiki/" }

proc wikistats {nick host hand chan args} { set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb] mysqlsel $db {SELECT ss_total_views,ss_total_edits,ss_good_articles from site_stats} putquick "privmsg $chan :$::mywiki Site-Stats" mysqlmap $db {ss_total_views ss_total_edits ss_good_articles} { putquick "privmsg $chan :Total Views: $ss_total_views Total Edits: $ss_total_edits Good Articles: $ss_good_articles (since mediawiki setup on $::mysetupdate)" } mysqlendquery $db mysqlclose $db }

proc sysops {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]


 * 1) mysqlsel $db {SELECT user_name,user_email FROM user WHERE user_rights LIKE "%sysop%"}
 * 2) changes due to mediawiki 1.5 upgrade

set query "SELECT user_name,user_email from `user` LEFT JOIN `user_groups` ON user_id=ug_user WHERE ug_group = 'sysop' GROUP BY user_name"
 * 1) set query "select user_name,user_email from user_rights join user on user_id=ur_user where ur_rights!='' order by user_name"

mysqlsel $db $query puthelp "privmsg $chan :$::mywiki Sysops (alphabetical order)" mysqlmap $db {user_name user_email} { puthelp "privmsg $chan :$user_name - $user_email" } mysqlendquery $db mysqlclose $db }

proc wikisearch {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]

set query "select name,mainurl from mediawikis where name like '%$args%' or statsurl like '%args%' limit 5"

mysqlsel $db $query puthelp "privmsg $chan :$::mywiki Searching for a Wiki matching '$args'..." mysqlmap $db {name mainurl} { set name [string trim $name]

puthelp "privmsg $chan :Found '$name' ($mainurl)" } mysqlendquery $db mysqlclose $db }

proc quote {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]

set query "select quote from quotes order by rand limit 1"

mysqlsel $db $query puthelp "privmsg $chan :$::mywiki Random discordian quote:" mysqlmap $db {quote} { puthelp "privmsg $chan :$quote" } mysqlendquery $db mysqlclose $db }

proc specialquote {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]

set query "select quote from quotes order by rand limit 1"

mysqlsel $db $query mysqlmap $db {quote} {
 * 1) http::formatQuery quote "$quote"

puthelp "privmsg $chan :The Oracle says to $nick: '$quote'" } mysqlendquery $db mysqlclose $db }

proc display {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]
 * 1) set query "SELECT left(cur_text,120) as cur_sum FROM cur WHERE cur_title='$args'"
 * 2) changes due to mediawiki 1.5 upgrade

set query "select left(si_text,$::mydisplaychars) as si_sum from searchindex join page on page_id=si_page where page_title='$args'"

mysqlsel $db $query puthelp "privmsg $chan :$::mywiki - Displaying page '$args' (first $::mydisplaychars chars)" mysqlmap $db {si_sum} { puthelp "privmsg $chan :$si_sum ... continued on $::mybaseurl/$args" } mysqlendquery $db mysqlclose $db }

proc ban {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb] set query "INSERT into ipblocks (ipb_address,ipb_user,ipb_by,ipb_reason,ipb_timestamp,ipb_auto,ipb_expiry) values ('$args','0','74','spammer (banned via IRC)',NOW+0,'0',ADDDATE(NOW,INTERVAL 1 DAY)+0);" mysqlsel $db $query puthelp "privmsg $chan :Ok, $nick, blocked '$args' for $::myspamdays days with reason 'spammer'" mysqlendquery $db mysqlclose $db }

proc unban {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb] set query "DELETE from ipblocks WHERE ipb_address='$args';" mysqlsel $db $query puthelp "privmsg $chan :Ok, $nick, removed block on '$args'" mysqlendquery $db mysqlclose $db }

proc teach {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]
 * 1) set query "SELECT left(cur_text,120) as cur_sum FROM cur WHERE cur_title='$args'"
 * 2) changes due to mediawiki 1.5 upgrade

set query "select left(si_text,180) as si_sum from searchindex join page on page_id=si_page where page_title='$args'"

mysqlsel $db $query mysqlmap $db {si_sum} { puthelp "privmsg $chan :$::myotherbot, $args is $si_sum ... $::mybaseurl/$args" } mysqlendquery $db mysqlclose $db }

proc wikirc {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb] set query "select rc_id,rc_title,rc_comment,rc_user_text from recentchanges order by rc_id desc LIMIT 0,$::myrcnum" mysqlsel $db $query puthelp "privmsg $chan :$::mywiki - Last $::myrcnum changes" mysqlmap $db {rc_id rc_title rc_comment rc_user_text} { puthelp "privmsg $chan :#$rc_id '$rc_title' $rc_comment by $rc_user_text ($::mybaseurl/$rc_title)" } mysqlendquery $db mysqlclose $db }

proc findpage {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]


 * 1) set query "SELECT cur_title FROM cur WHERE cur_title LIKE '%$args%' LIMIT 0,$::myfindlimit"
 * 2) changes due to mediawiki 1.5 upgrade


 * 1) set query "select page_id,page_title,page_counter from page join revision on rev_id = page_id where page_title LIKE '%$args%' limit 0,$::myfindlimit"

set lsearchstring [string tolower $args] set query "select page_title from page where page_title like '%$args%' or page_title like '%$lsearchstring%' LIMIT 0,$::myfindlimit"

mysqlsel $db $query puthelp "privmsg $chan :$::mywiki - Searching for page titles containing '$args'" mysqlmap $db {page_title} { puthelp "privmsg $chan :Found page $page_title ($::mybaseurl/$page_title)" } mysqlendquery $db mysqlclose $db }
 * 1) puthelp "privmsg $chan :Query: $query"

proc findcontent {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb]


 * 1) set query "SELECT cur_title FROM cur WHERE cur_text LIKE '%$args%' LIMIT 0,$::myfindlimit"
 * 2) changes due to mediawiki 1.5 upgrade

set query "select page_title from searchindex join page on page_id=si_page where si_text LIKE '%$args%' LIMIT 0,$::myfindlimit"

mysqlsel $db $query puthelp "privmsg $chan :$::mywiki - Searching full text for pages containing $args" mysqlmap $db {page_title} { puthelp "privmsg $chan :Found page $page_title ($::mybaseurl/$page_title)" } mysqlendquery $db mysqlclose $db }
 * 1) puthelp "privmsg $chan :$query"

proc popular {nick host hand chan args} { global myhost,myuser,mypass,mydb set db [mysqlconnect -host $::myhost -user $::myuser -password $::mypass -db $::mydb] set query "select page_title,page_counter from page order by page_counter desc limit 1,$::mypopnum"
 * 1) set query "select cur_title,cur_counter from cur ORDER by cur_counter DESC LIMIT 1,$::mypopnum"
 * 2) changes due to mediawiki 1.5 upgrade

mysqlsel $db $query puthelp "privmsg $chan :$::mywiki Top $::mypopnum popular pages" mysqlmap $db {page_title page_counter} { puthelp "privmsg $chan :$page_title ($page_counter hits) - ($::mybaseurl/$page_title)" } mysqlendquery $db mysqlclose $db }

putlog "Mediawiki.tcl by S23 loaded. Fnord. http://s23.org/wiki/"
 * 1) fnord
 * 2) mutante@s23.org