Page MenuHomePhabricator
Authored By
matmarex
Aug 9 2021, 6:47 PM
Size
1 KB
Referenced Files
None
Subscribers
None

multiedit-T288275.rb

# coding: utf-8
require 'sunflower'
require 'io/console'
username = 'Matma Rex'
print 'Password: '
password = STDIN.noecho{ gets.strip }
print "\n"
items = {
'Q4592157' => 'MediaWiki:Discussiontools-emptystate-link-talkpages',
'Q4592334' => 'MediaWiki:Discussiontools-emptystate-link-userpage',
}
wikidata = Sunflower.new 'https://www.wikidata.org'
res = wikidata.API 'action=sitematrix&smlimit=5000&format=json&formatversion=2'
res_lang = res['sitematrix']
.select{|k, v| k =~ /^\d+$/ }
.values
.map{|a| a['site'] }
.flatten
res_site = res['sitematrix']['specials']
dbname_to_url = ( res_lang + res_site )
.reject{|a| a['private'] || a['closed'] }
.map{|a| [ a['dbname'], a['url'] ] }
.to_h
items.each do |qid, pagetitle|
resp = wikidata.API "action=wbgetentities&ids=#{qid}&props=sitelinks&format=json&formatversion=2"
sitelinks = resp['entities'][qid]['sitelinks']
# sitelinks.select!{|k, v| k == 'enwiki' }
sitelinks.each do |dbname, data|
puts ">> #{dbname} (#{dbname_to_url[dbname]}) #{pagetitle} #{data['title']}"
s = Sunflower.new dbname_to_url[dbname]
s.login username, password
page = s.page pagetitle
page.text = data['title']
s.summary = "Link to a local help page instead of mediawiki.org, based on [[wikidata:#{qid}]] ([[phab:T288275]])"
p page.save
end
end

File Metadata

Mime Type
text/x-ruby
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9149009
Default Alt Text
multiedit-T288275.rb (1 KB)

Event Timeline