2014-07-28 13:13:40 +00:00
|
|
|
def license(language_code, file_name)
|
2014-07-11 17:22:26 +00:00
|
|
|
require "date"
|
2014-07-08 20:02:08 +00:00
|
|
|
date = Date.today.to_s
|
|
|
|
"=={{int:filedesc}}==
|
|
|
|
{{Information
|
|
|
|
|description={{en|1=#{file_name}}}
|
|
|
|
|date=#{date}
|
|
|
|
|source=[[User:LanguageScreenshotBot|Automatically created by LanguageScreenshotBot]]
|
|
|
|
|author=[[User:LanguageScreenshotBot|Automatically created by LanguageScreenshotBot]]
|
|
|
|
|permission=
|
|
|
|
|other_versions=
|
|
|
|
|other_fields=
|
|
|
|
}}
|
|
|
|
|
|
|
|
=={{int:license-header}}==
|
|
|
|
{{Wikipedia-screenshot}}
|
|
|
|
|
2014-09-25 17:45:41 +00:00
|
|
|
[[Category:VisualEditor automatic screenshots/#{language_code}]]"
|
2014-07-08 20:02:08 +00:00
|
|
|
end
|
|
|
|
|
2014-11-20 18:55:18 +00:00
|
|
|
def upload_image(file_path, client)
|
2014-07-08 20:02:08 +00:00
|
|
|
language_code = ENV['LANGUAGE_SCREENSHOT_CODE']
|
|
|
|
file_name = File.basename(file_path, "")
|
2014-07-28 13:13:40 +00:00
|
|
|
file_license = license(language_code, file_name)
|
2014-07-08 20:02:08 +00:00
|
|
|
|
|
|
|
client.upload_image(file_name, file_path, file_license, true)
|
2014-07-22 13:24:24 +00:00
|
|
|
sleep 5 # Restriction in bot speed: https://commons.wikimedia.org/wiki/Commons:Bots#Bot_speed
|
2014-07-08 20:02:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def upload_images
|
|
|
|
screenshot_directory = ENV["LANGUAGE_SCREENSHOT_PATH"] || "./screenshots"
|
2014-07-22 13:45:56 +00:00
|
|
|
require 'mediawiki_api'
|
|
|
|
client = MediawikiApi::Client.new ENV["MEDIAWIKI_API_UPLOAD_URL"]
|
|
|
|
client.log_in ENV["MEDIAWIKI_USER"], ENV["MEDIAWIKI_PASSWORD"]
|
2014-07-11 17:22:26 +00:00
|
|
|
Dir["#{screenshot_directory}/*.png"].each do |file_path|
|
2014-07-08 20:02:08 +00:00
|
|
|
puts "Uploading #{file_path}"
|
2014-07-22 13:45:56 +00:00
|
|
|
upload_image file_path, client
|
2014-07-08 20:02:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-11 17:22:26 +00:00
|
|
|
ENV["MEDIAWIKI_PASSWORD"] = ENV[ENV["MEDIAWIKI_PASSWORD_VARIABLE"]] if ENV["MEDIAWIKI_PASSWORD_VARIABLE"]
|
|
|
|
upload_images
|