Page MenuHomePhabricator
Authored By
matmarex
Apr 9 2015, 3:16 PM
Size
1 KB
Referenced Files
None
Subscribers
None

find-gadgets-on-wikis.rb

# coding: utf-8
require 'sunflower'
require 'rest-client'
def dbname_to_url dbname
@data ||= begin
data = File.readlines('operations/mediawiki-config/wmf-config/InitialiseSettings.php')
.drop_while{|ln| ln.strip != "'wgServer' => array(" }.drop(1)
.take_while{|ln| ln[0] == "\t" || ln.strip == '' }
.select{|ln| ln.include? '=>' }
.map{|ln| ln.sub('//', '').sub(%r~(//|#).+~, '') } # strip comments and leading // in URLs
# meh
eval "{ #{data.join "\n"} }"
end
if @data[dbname]
@data[dbname]
else
family_dbname = @data.keys.find{|k| dbname.end_with? k } || 'default'
family_dbname_suffix = family_dbname == 'default' ? 'wiki' : family_dbname
@data[family_dbname].sub '$lang', dbname.sub(/#{family_dbname_suffix}$/, '').sub('_', '-')
end
end
list = File.read(ARGV[0]).force_encoding('utf-8')
list = list.split(/\r?\n/).select{|ln| ln =~ /^\w+\s+MediaWiki:.+$/ }
list = list.map{|ln| ln.split(/\s+/, 2) }
list.uniq!
list.sort!
$stdout.sync = true
list.select!{|(_, pagetitle)| pagetitle =~ /^MediaWiki:Gadget-/ }
list.each do |(dbname, pagetitle)|
s = Sunflower.new dbname_to_url dbname
page = s.page 'MediaWiki:Gadgets-definition'
name = pagetitle[/^MediaWiki:Gadget-(.+)\.js$/, 1]
if name and line = page.text.each_line.to_a.find{|ln| ln.include? name }
puts "#{dbname}#{line.include?('default') ? ' (DEFAULT)' : ''}"
puts "https://#{dbname_to_url dbname}/wiki/#{pagetitle.sub ' ', '_'}"
puts ""
end
sleep 3
end

File Metadata

Mime Type
text/x-ruby
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
107232
Default Alt Text
find-gadgets-on-wikis.rb (1 KB)

Event Timeline