wikidata_position_history 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f9b65df015932c64b9995789de132f401400b8641fe6da6d34529ee08a897f7
4
- data.tar.gz: 8eb66f80771e638a76e477db20e48c20cf10aa69843e20660c49a995e7040126
3
+ metadata.gz: 43d866e3ec1ab0f61a2d8d66d46757dff7ecfd66f4c39bb7a1f90125befb3586
4
+ data.tar.gz: 9ac67f8d608c4ce7cc746b4e035664cfed07c5501f117d075fb3ab11444a4a69
5
5
  SHA512:
6
- metadata.gz: 84464bf1eb62fad5dfe9287baa7988ed1e27024b3dce9ceefd1b2a74a79b7ea4fe472151c9b04bc10ed8bba846694553e929ce6f0bd316cff86aee4f09806ec4
7
- data.tar.gz: 1b8813db12384488d4719a6858fa31b3dd69b9692b2df9c62c4d861a7c46ab533715fc374bd5b7fd2441b07108257cd782369175318e89afdbb7f5cdea106945
6
+ metadata.gz: 24824e0ad6207a9a3c8b3e8a547a6eda2dc7e9ee5f6503995dd330c82ecb2bab11a4c4655c3fddd1d8c0235b13bc6d607010901147f305d736e46cdd959c1688
7
+ data.tar.gz: 257e34dc5e7855720b101d33d2bbf8404f1d4486270667653d1386e077ae4fbdc631b1edba4c7439f3c5f16b4cb80e6932c53d70c136577456d758fe55963b0d
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ # Unreleased
4
+
5
+ # [2.3.0] 2020-10-01
6
+
7
+ * Edits on Wikidata can now set a botflag if requested, based on the
8
+ `PHH_BOT` environemnt variable.
9
+
3
10
  # [2.2.0] 2020-09-18
4
11
 
5
12
  ## Enhancements
@@ -16,6 +16,18 @@ require 'date'
16
16
  require 'mediawiki/client'
17
17
  require 'mediawiki/page'
18
18
 
19
+ module MediaWiki
20
+ # mediawiki-page-replaceable_content does not provide a way to set a
21
+ # bot flag, so we need to monkey patch it. This should really be
22
+ # exposed somewhere in its interface.
23
+ class Client
24
+ def edit(hash)
25
+ hash['bot'] = ENV['PHH_BOT'] if ENV.key?('PHH_BOT')
26
+ wrapped_client.edit(hash)
27
+ end
28
+ end
29
+ end
30
+
19
31
  module WikidataPositionHistory
20
32
  # Rewrites a Wiki page
21
33
  class PageRewriter
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'report/abstract'
4
+ require_relative 'report/legislator'
5
+ require_relative 'report/mandate'
6
+ require_relative 'report/constituency'
7
+ require_relative 'report/position'
8
+
3
9
  module WikidataPositionHistory
4
10
  # A list made up of both direct and indirect claims, where we
5
11
  # can tell which came from which, when required
@@ -102,122 +108,32 @@ module WikidataPositionHistory
102
108
  end
103
109
  end
104
110
 
105
- # Construct the correct ReportConfig based on the position metadata
106
- class ReportConfigFactory
107
- def self.config(metadata)
108
- return ReportConfig::Constituency.new if metadata.constituency?
109
-
110
- ReportConfig::Position.new
111
- end
112
-
113
- private
114
-
115
- attr_reader :metadata
116
- end
117
-
118
- # Encapsulates the different configuration for each type of position
119
- module ReportConfig
120
- # Configuration for 'default' single-holder position
121
- class Position
122
- def mandates_query
123
- SPARQL::MandatesQuery
124
- end
125
-
126
- def biodata_query
127
- SPARQL::BioQuery
128
- end
129
- end
130
-
131
- # Configuration for representatives of a single-member constituency
132
- class Constituency
133
- def mandates_query
134
- SPARQL::ConstituencyMandatesQuery
135
- end
136
-
137
- def biodata_query
138
- SPARQL::ConstituencyBioQuery
139
- end
140
-
141
- def multimember_error_template
142
- "\n{{PositionHolderHistory/error_multimember}}\n"
143
- end
144
- end
145
- end
146
-
147
111
  # The entire wikitext generated for this report
148
112
  class Report
149
- def initialize(position_id, template_class = ReportTemplate)
113
+ def initialize(position_id)
150
114
  @position_id = position_id
151
115
  @template_class = template_class
152
116
  end
153
117
 
154
118
  attr_reader :position_id, :template_class
155
119
 
156
- def wikitext
157
- return legislator_template if metadata.legislator?
158
- return config.multimember_error_template if metadata.constituency? && (metadata.representative_count != 1)
159
- return no_items_output if mandates.empty?
160
-
161
- template_class.new(template_params).output
162
- end
163
-
164
- def template_params
165
- {
166
- metadata: metadata,
167
- table_rows: table_rows,
168
- sparql_url: sparql.wdqs_url,
169
- }
170
- end
171
-
172
- private
173
-
174
120
  def metadata
175
121
  @metadata ||= Metadata.new(SPARQL::PositionQuery.new(position_id).results_as(PositionRow))
176
122
  end
177
123
 
178
- def biodata
179
- @biodata ||= biodata_sparql.results_as(BioRow)
180
- end
181
-
182
- def biodata_for(officeholder)
183
- biodata.select { |bio| bio.person.id == officeholder.id }
184
- end
185
-
186
- def padded_mandates
187
- [nil, mandates, nil].flatten(1)
188
- end
189
-
190
- def config
191
- @config ||= ReportConfigFactory.config(metadata)
192
- end
193
-
194
- def sparql
195
- @sparql ||= config.mandates_query.new(position_id)
196
- end
197
-
198
- def biodata_sparql
199
- config.biodata_query.new(position_id)
200
- end
201
-
202
- def mandates
203
- @mandates ||= sparql.results_as(MandateRow)
204
- end
124
+ def report
125
+ return Report::Legislator.new(metadata) if metadata.legislator?
126
+ return Report::Constituency.new(metadata) if metadata.constituency?
205
127
 
206
- def no_items_output
207
- "\n{{PositionHolderHistory/error_no_holders|id=#{position_id}}}\n"
128
+ Report::Position.new(metadata)
208
129
  end
209
130
 
210
- def legislator_template
211
- "\n{{PositionHolderHistory/error_legislator|id=#{position_id}}}\n"
131
+ def template_params
132
+ report.template_params
212
133
  end
213
134
 
214
- def table_rows
215
- padded_mandates.each_cons(3).map do |later, current, earlier|
216
- {
217
- mandate: OutputRow::Mandate.new(later, current, earlier),
218
- bio: biodata_for(current.officeholder),
219
- }
220
- end
135
+ def wikitext
136
+ report.wikitext
221
137
  end
222
138
  end
223
139
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataPositionHistory
4
+ class Report
5
+ # Abstract base class for Reports
6
+ class Abstract
7
+ def initialize(metadata)
8
+ @metadata = metadata
9
+ end
10
+
11
+ protected
12
+
13
+ attr_reader :metadata
14
+
15
+ def position_id
16
+ metadata.position.id
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataPositionHistory
4
+ class Report
5
+ # Report of representatives for a single-member consttuency
6
+ class Constituency < Mandate
7
+ def wikitext
8
+ return multimember_error_template unless metadata.representative_count == 1
9
+
10
+ super
11
+ end
12
+
13
+ def mandates_query
14
+ SPARQL::ConstituencyMandatesQuery
15
+ end
16
+
17
+ def biodata_query
18
+ SPARQL::ConstituencyBioQuery
19
+ end
20
+
21
+ def multimember_error_template
22
+ "\n{{PositionHolderHistory/error_multimember}}\n"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataPositionHistory
4
+ class Report
5
+ # Report for a (presumed multi-member) legislative position
6
+ class Legislator < Abstract
7
+ def wikitext
8
+ "\n{{PositionHolderHistory/error_legislator|id=#{position_id}}}\n"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataPositionHistory
4
+ class Report
5
+ # base report where each row is one person holding an office for a period
6
+ class Mandate < Abstract
7
+ def wikitext
8
+ return no_items_output if mandates.empty?
9
+
10
+ ReportTemplate.new(template_params).output
11
+ end
12
+
13
+ def template_params
14
+ {
15
+ metadata: metadata,
16
+ table_rows: table_rows,
17
+ sparql_url: sparql.wdqs_url,
18
+ }
19
+ end
20
+
21
+ private
22
+
23
+ def biodata
24
+ @biodata ||= biodata_sparql.results_as(BioRow)
25
+ end
26
+
27
+ def biodata_for(officeholder)
28
+ biodata.select { |bio| bio.person.id == officeholder.id }
29
+ end
30
+
31
+ def padded_mandates
32
+ [nil, mandates, nil].flatten(1)
33
+ end
34
+
35
+ def sparql
36
+ @sparql ||= mandates_query.new(position_id)
37
+ end
38
+
39
+ def biodata_sparql
40
+ biodata_query.new(position_id)
41
+ end
42
+
43
+ def mandates
44
+ @mandates ||= sparql.results_as(MandateRow)
45
+ end
46
+
47
+ def no_items_output
48
+ "\n{{PositionHolderHistory/error_no_holders|id=#{position_id}}}\n"
49
+ end
50
+
51
+ def table_rows
52
+ padded_mandates.each_cons(3).map do |later, current, earlier|
53
+ {
54
+ mandate: OutputRow::Mandate.new(later, current, earlier),
55
+ bio: biodata_for(current.officeholder),
56
+ }
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataPositionHistory
4
+ class Report
5
+ # The default single-person-at-a-time position
6
+ class Position < Mandate
7
+ def mandates_query
8
+ SPARQL::MandatesQuery
9
+ end
10
+
11
+ def biodata_query
12
+ SPARQL::BioQuery
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WikidataPositionHistory
4
- VERSION = '2.2.0'
4
+ VERSION = '2.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikidata_position_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Bowden
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-09-18 00:00:00.000000000 Z
12
+ date: 2020-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mediawiki-replaceable-content
@@ -212,6 +212,11 @@ files:
212
212
  - lib/wikidata_position_history/checks.rb
213
213
  - lib/wikidata_position_history/output_row.rb
214
214
  - lib/wikidata_position_history/report.rb
215
+ - lib/wikidata_position_history/report/abstract.rb
216
+ - lib/wikidata_position_history/report/constituency.rb
217
+ - lib/wikidata_position_history/report/legislator.rb
218
+ - lib/wikidata_position_history/report/mandate.rb
219
+ - lib/wikidata_position_history/report/position.rb
215
220
  - lib/wikidata_position_history/template.rb
216
221
  - lib/wikidata_position_history/version.rb
217
222
  - wikidata_position_history.gemspec