<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: mediawiki code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 07 Sep 2008 04:51:05 GMT</pubDate>
    <description>DZone Snippets: mediawiki code</description>
    <item>
      <title>[Ruby] Script/bot to send MediaWiki Recent Changes over UDP to a Campfire room</title>
      <link>http://snippets.dzone.com/posts/show/5037</link>
      <description>Requires the Tinder gem, and PHP on the server running MediaWiki must be compiled with --enable-sockets. The computer running the bot will also have to be open to the web - it can't be behind a firewall.&lt;br /&gt;&lt;br /&gt;First, add this code to your MediaWiki LocalSettings.php, replacing the IP address with the IP of the server/computer running the bot, and the port to whatever you want to use (probably something above 40,000, but it's up to you):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$wgRC2UDPAddress = '69.178.6.244';&lt;br /&gt;$wgRC2UDPPort = '41895';&lt;br /&gt;$wgRC2UDPPrefix = "";&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now, you can run the bot! This is extremely hackish, because the retarded collective-mailing-list-coding system of the MediaWiki repos has somehow managed to code IRC color codes directly into their exported strings (at least with MediaWiki 1.2alpha, which is what I'm running right now).&lt;br /&gt;You'll need to replace the new tinder definition with your subdomain on Campfire, the username and password with ones for the bot account you've created on your campfire room, and the room name with the room you want the updates to be sent to.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'tinder'&lt;br /&gt;require 'socket'&lt;br /&gt;puts 'Dependencies loaded...'&lt;br /&gt;&lt;br /&gt;campfire = Tinder::Campfire.new 'subdomain'&lt;br /&gt;campfire.login 'email@domain.com', 'password'&lt;br /&gt;exit unless room = campfire.find_room_by_name('Case Sensitive Room Name')&lt;br /&gt;puts 'Campfire logged in...'&lt;br /&gt;&lt;br /&gt;server = UDPSocket.new&lt;br /&gt;exit unless server.bind('0.0.0.0', 41895)&lt;br /&gt;puts 'Socket listening...'&lt;br /&gt;&lt;br /&gt;loop do&lt;br /&gt;  msg = server.recv(2048).gsub(/\003[\d]{0,2}/,'').chomp&lt;br /&gt;  print "sending to room: #{msg.inspect}..."&lt;br /&gt;  exit unless room.speak msg.to_s&lt;br /&gt;  puts ' sent!'&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 26 Jan 2008 14:29:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5037</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>Converting Twiki formatting to MediaWiki</title>
      <link>http://snippets.dzone.com/posts/show/4999</link>
      <description>// It's not necessarily the cleanest, but it got the job done on an internal transfer we were doing. Your mileage may vary by quite a bit. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def convert_from_twiki_to_mediawiki(old_page_text)&lt;br /&gt;  new_page_text = ""&lt;br /&gt;  &lt;br /&gt;  # shifting the tables over&lt;br /&gt;  while (true)&lt;br /&gt;    if (old_page_text.index(/\n\|/).nil?)&lt;br /&gt;      new_page_text += old_page_text&lt;br /&gt;      break&lt;br /&gt;    end&lt;br /&gt;        &lt;br /&gt;    # table extraction&lt;br /&gt;    table_index = old_page_text.index("\n|")&lt;br /&gt;    first_chunk = old_page_text.slice!(0..table_index)&lt;br /&gt;    table_chunk = ""&lt;br /&gt;    old_page_text.each_line do |line|&lt;br /&gt;      if line[0..0] == '|'&lt;br /&gt;        table_chunk += line&lt;br /&gt;      else&lt;br /&gt;        break&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;    old_page_text.slice!(table_chunk)&lt;br /&gt;    &lt;br /&gt;    # table conversion&lt;br /&gt;    table_chunk.gsub!(/\|/, "||")&lt;br /&gt;    table_chunk.gsub!(/\|\|\s*$/, "\n|-")&lt;br /&gt;    table_chunk.gsub!(/^\|\|/, "|")&lt;br /&gt;    table_chunk.gsub!(/\|-\s*\Z/, "|}")&lt;br /&gt;    table_chunk.gsub!(/\A\|/, "{|class=\"wikitable sortable\"\n|")&lt;br /&gt;    &lt;br /&gt;    # process new table looking for headings&lt;br /&gt;    new_table_chunk = ""&lt;br /&gt;    table_chunk.each_line do |line|&lt;br /&gt;      if line.match(/\*\s.*\s\*/)&lt;br /&gt;        line.gsub!(/\|\|/, "!!")&lt;br /&gt;        line.gsub!(/^\|/, "!")&lt;br /&gt;        line.gsub!("*", '')&lt;br /&gt;      end&lt;br /&gt;      &lt;br /&gt;      new_table_chunk += line&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    new_page_text += first_chunk + new_table_chunk&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  # bold&lt;br /&gt;  new_page_text.gsub!(/(^|[\s\(])\*([^ ].*?[^ ])\*([\s\)\.\,\:\;\!\?]|$)/, "\\1'''\\2'''\\3")&lt;br /&gt;  # italic bold&lt;br /&gt;  new_page_text.gsub!(/(^|[\s\(])\_\_([^ ].*?[^ ])\_\_([\s\)\.\,\:\;\!\?]|$)/, "\\1''&lt;b&gt;\\2&lt;\/b&gt;''\\3") &lt;br /&gt;  # italic&lt;br /&gt;  new_page_text.gsub!(/(^|[\s\(])\_([^ ].*?[^ ])\_([\s\)\.\,\:\;\!\?]|$)/, "\\1''\\2''\\3")&lt;br /&gt;  # monospaced bold&lt;br /&gt;  new_page_text.gsub!(/(^|[\s\(])==([^ ].*?[^ ])==([\s\)\.\,\:\;\!\?]|$)/, "\\1'''&lt;tt&gt;\\2&lt;\/tt&gt;'''\\3")&lt;br /&gt;  # monospaced&lt;br /&gt;  new_page_text.gsub!(/(^|[\s\(])=([^ ].*?[^ ])=([\s\)\.\,\:\;\!\?]|$)/, "\\1&lt;tt&gt;\\2&lt;\/tt&gt;\\3")&lt;br /&gt;  # H6&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])---\+\+\+\+\+\+([^\n\r]*)/, "\\1======\\2 ======")&lt;br /&gt;  # H5&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])---\+\+\+\+\+([^\n\r]*)/, "\\1=====\\2 =====")&lt;br /&gt;  # H4&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])---\+\+\+\+([^\n\r]*)/, "\\1====\\2 ====")&lt;br /&gt;  # H3&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])---\+\+\+([^\n\r]*)/, "\\1===\\2 ===")&lt;br /&gt;  # H2&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])---\+\+([^\n\r]*)/, "\\1==\\2 ==")&lt;br /&gt;  # H1&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])---\+([^\n\r]*)/, "\\1=\\2 =")&lt;br /&gt;  # external link&lt;br /&gt;  new_page_text.gsub!(/\[\[(https?\:.*?)\]\[(.*?)\]\]/, "\[\\1 \\2\]")&lt;br /&gt;  # internal link [[WikiWord][WikiWord]]&lt;br /&gt;  new_page_text.gsub!(/\[\[([^\]]*)\]\]/, "\[\[\\1\|\\1\]\]")&lt;br /&gt;  # internal lnk [[WikiWord][label]]&lt;br /&gt;  new_page_text.gsub!(/\[\[([^\]]*)\]\[(.*?)\]\]/, "\[\[\\1\|\\2\]\]")&lt;br /&gt;  # level 1 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{3}\* /, "\\1*")&lt;br /&gt;  # level 2 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{6}\* /, "\\1**")&lt;br /&gt;  # level 3 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{9}\* /, "\\1***")&lt;br /&gt;  # level 4 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{12}\* /, "\\1****")&lt;br /&gt;  # level 5 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{15}\* /, "\\1*****")&lt;br /&gt;  # level 6 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{18}\* /, "\\1******")&lt;br /&gt;  # level 7 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{21}\* /, "\\1*******")&lt;br /&gt;  # level 8 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{24}\* /, "\\1********")&lt;br /&gt;  # level 9 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{27}\* /, "\\1*********")&lt;br /&gt;  # level 10 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{30}\* /, "\\1**********")&lt;br /&gt;  # level 1 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{3}[0-9]\.? /, "\\1#")&lt;br /&gt;  # level 2 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{6}[0-9]\.? /, "\\1##")&lt;br /&gt;  # level 3 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{9}[0-9]\.? /, "\\1###")&lt;br /&gt;  # level 4 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{12}[0-9]\.? /, "\\1####")&lt;br /&gt;  # level 5 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{15}[0-9]\.? /, "\\1#####")&lt;br /&gt;  # level 6 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{18}[0-9]\.? /, "\\1######")&lt;br /&gt;  # level 7 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{21}[0-9]\.? /, "\\1#######")&lt;br /&gt;  # level 8 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{24}[0-9]\.? /, "\\1########")&lt;br /&gt;  # level 9 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{27}[0-9]\.? /, "\\1#########")&lt;br /&gt;  # level 10 bullet&lt;br /&gt;  new_page_text.gsub!(/(^|[\n\r])[ ]{30}[0-9]\.? /, "\\1##########")&lt;br /&gt;    &lt;br /&gt;  &lt;br /&gt;  new_page_text&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 Jan 2008 23:26:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4999</guid>
      <author>sjml (Shane Liesegang)</author>
    </item>
  </channel>
</rss>
