module MediaWiki::TestWiki::RakeHelper
Public Class Methods
configure(base, load_tasks = false, &block)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 52 def configure(base, load_tasks = false, &block) 53 Config.enhance(base, &block).tap { 54 require_relative 'rake_tasks' if load_tasks 55 } 56 end
extended(base)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 39 def extended(base) 40 keep = [:noop, :verbose] 41 42 base.define_singleton_method(:docker_system) { |*args, &block| 43 options = !args.last.is_a?(Hash) ? {} : 44 args.pop.keep_if { |k,| keep.include?(k) } 45 46 sh(*args << options, &block) 47 } 48 49 configure(base) unless base.respond_to?(:config) 50 end
Public Instance Methods
broken_version?(strict = false)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 202 def broken_version?(strict = false) 203 verified_version?(strict, config.broken_versions) 204 end
docker_tasks(name, image)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 60 def docker_tasks(name, image) 61 %w[start stop restart clean clobber].each { |task| 62 task(task) { send("docker_#{task}", name, image) } 63 } 64 65 task(:start) { puts "#{name}: #{docker_url(name)}" } 66 end
file_size(*args) { |self| ... }
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 68 def file_size(*args) 69 file_create(*args) { |t| File.write(t.name, '') }.instance_eval { 70 def needed?; !File.size?(name); end 71 yield self if block_given? 72 self 73 } 74 end
fix_config(file, host)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 76 def fix_config(file, host) 77 File.write(file, File.read(file).tap { |content| 78 content.sub!(/^\$wgServer\b/, '#\&') 79 content.gsub!(host, 'localhost') 80 }) 81 end
needed?()
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 70 def needed?; !File.size?(name); end
setup_broken(arg)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 83 def setup_broken(arg) 84 msg = <<-EOT 85 86 *** Manual configuration is broken for this MediaWiki version. *** 87 88 EOT 89 90 if arg.is_a?(LoadError) 91 abort msg << <<-EOT 92 However, automatic configuration is not available: #{arg}. 93 Please install the `mechanize' gem and try again. 94 EOT 95 elsif arg 96 wait msg << <<-EOT 97 Also, automatic configuration is not supported for this version either. 98 Please create a valid configuration file and press enter when finished: 99 #{arg} 100 EOT 101 else 102 abort msg << <<-EOT 103 However, you have requested to skip automatic configuration. 104 Please unset `NOMECHANIZE' and try again. 105 EOT 106 end 107 end
setup_manual(url, dir, cfg, err = nil, unk = nil)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 109 def setup_manual(url, dir, cfg, err = nil, unk = nil) 110 msg = <<-EOT 111 112 Visit #{url} and configure the wiki: 113 EOT 114 115 msg << <<-EOT if unk 116 117 NOTE: These configuration instructions have not been verified for 118 this version of MediaWiki -- please use your own judgement! 119 EOT 120 121 msg << <<-EOT 122 123 - Language 124 - Continue 125 126 - Welcome to MediaWiki! 127 - Continue 128 129 - Connect to database 130 - Database type: SQLite 131 - SQLite data directory: #{dir} 132 - Database name: #{config.database_name} 133 - Continue 134 135 - Name 136 - Name of wiki: #{config.sitename} 137 - Your username: #{config.username} 138 - Password: #{config.password} 139 - Password again: #{config.password} 140 - I'm bored already, just install the wiki. 141 - Continue 142 143 - Install (1) 144 - Continue 145 146 - Install (2) 147 - Continue 148 149 Save #{File.basename(cfg)} (replace existing file if already present): 150 #{cfg} 151 152 Close configuration window and press enter when finished. 153 EOT 154 155 msg << <<-EOT if err 156 157 NOTE: Install the `mechanize' gem to automate this process. (#{err}) 158 EOT 159 160 wait(msg) 161 end
setup_mechanize(url, dir, cfg)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 163 def setup_mechanize(url, dir, cfg) 164 agent = Mechanize.new 165 page = agent.get(url) 166 167 continue = lambda { |&block| 168 form = page.forms.first 169 block[form] if block 170 page = agent.submit(form) 171 } 172 173 2.times { continue.() } 174 175 continue.() { |form| 176 form.sqlite_wgSQLiteDataDir = dir 177 form.sqlite_wgDBname = config.database_name 178 form.radiobuttons_with(value: 'sqlite').first.check 179 } 180 181 continue.() { |form| 182 form.radiobuttons_with(value: 'skip').first.check 183 184 form.config_wgSitename = config.sitename 185 form.config__AdminName = config.username 186 187 form.config__AdminPassword = config.password 188 form.config__AdminPassword2 = config.password 189 } 190 191 2.times { continue.() } 192 193 page.link_with(text: Regexp.new( 194 Regexp.escape(File.basename(cfg)))).click.save!(cfg) 195 end
verified_version?(strict = false, list = config.verified_versions)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 197 def verified_version?(strict = false, list = config.verified_versions) 198 strict ? list.include?(config.version) : 199 list.grep(/\A#{Regexp.escape(config.version[/.*\./])}/).any? 200 end
Private Instance Methods
wait(msg)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb 208 def wait(msg) 209 puts(msg) 210 $stdin.gets 211 end