-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
35 lines (27 loc) · 858 Bytes
/
app.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
require 'bundler/setup'
require_relative 'lib/load_environment_from_yaml'
require 'wikidata_position_history'
require 'sinatra'
get '/' do
redirect to('/position-holder-history')
end
get '/position-holder-history/?' do
mediawiki_site = params[:mediawiki_site]
page_title = params[:page_title]
return erb(:homepage) unless mediawiki_site && page_title
unless mediawiki_site =~ /^(www\.)?wikidata.org|[a-z]{2}.wikipedia.org$/
halt "Disallowed mediawiki_site"
end
rewriter = WikidataPositionHistory::PageRewriter.new(
mediawiki_site: mediawiki_site,
page_title: page_title
)
begin
rewriter.run!
rescue MediawikiApi::LoginError
halt "Please set WIKI_USERNAME and WIKI_PASSWORD environment variables"
rescue => e
halt "Error: #{e.message}"
end
redirect("https://#{mediawiki_site}/wiki/#{page_title}")
end