/
ujednoznacz.rb
44 lines (29 loc) · 972 Bytes
/
ujednoznacz.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coding: utf-8
require 'sunflower'
s = Sunflower.new.login
linki = s.make_list 'whatlinkshere', 'Vercors'
szczyty = s.make_list 'category-r', 'Kategoria:Szczyty Francji'
list = linki & szczyty
from = 'Vercors'
to = 'Vercors (masyw górski)'
puts "#{list.length} to do..."
s.summary = "ujednoznacznienie: [[#{from}]] -> [[#{to}]]"
slowly = true
list.each_with_index do |pagename, i|
p = Page.new pagename
simple = /\[\[#{Regexp.escape from}\]\]/
extended = /\[\[#{Regexp.escape from}\|([^\]]+)\]\]/
# cytuj = /(\|\s*autor link\s*=\s*)Józef Szymański(\s*[\|\}])/
p.text = p.text.gsub(simple, "[[#{to}|#{from}]]")
p.text = p.text.gsub(extended, "[[#{to}|\\1]]")
# p.text = p.text.gsub(cytuj, '\1Józef Szymański (historyk)\2')
if p.text != p.orig_text
p.save
puts "#{i+1} | #{pagename}: saved"
else
puts "#{i+1} | #{pagename}: no changes"
end
if slowly
slowly = !(gets.strip=='ok')
end
end