everypolitician / compare_with_wikidata

Library for diffing Wikidata and CSVs
MIT License
2 stars 0 forks source link

Rewrite a given MediaWiki page based on template parameters #11

Closed mhl closed 7 years ago

mhl commented 7 years ago

[This isn't quite ready yet; e.g. there are a few tests I'd like to add, and the prompt script hasn't been updated to use this. It's probably still worth getting comments on at this stage.]

One thing to consider is whether all this new code should be in a separate gem, since it's quite a generic way of rewriting MediaWiki pages based on template parameters, and not really specific to this application.

As an example of usage, You could do:

wiki_page = CompareWithWikidata::WikiPage.new(
  username: ENV['WIKI_USERNAME'],
  password: ENV['WIKI_PASSWORD'],
  title:   'User:Mhl20/test template'
)

class ExampleRewriter
  def rewrite(old_content:, parameters:)
    "Preserving the old content:\n#{old_content}\n" \
    "The animal parameter was: '#{parameters[:animal]}'"
  end
end

wiki_page.rewrite_and_put(ExampleRewriter.new)

This has been run twice on: https://www.wikidata.org/wiki/User:Mhl20/test_template for example.

tmtmtmtm commented 7 years ago

One thing to consider is whether all this new code should be in a separate gem, since it's quite a generic way of rewriting MediaWiki pages based on template parameters, and not really specific to this application.

I would be very much in favour of separating this out like that. (Even if not an entirely separate gem — though that would be my preference — I think it should at least live in a conceptually different class within this gem)

chrismytton commented 7 years ago

This code has now been moved out to the everypolitician/mediawiki-page-replaceable_content library.