From c33904111ac3b886cd10ff1c3f1dbdcd7c277941 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 7 Jan 2015 16:38:38 +0100 Subject: Fetch source by use of Mediawiki::API (not wget + custom mediawiki-extract decoding). --- Makefile | 5 ++--- mediawiki-fetch | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100755 mediawiki-fetch diff --git a/Makefile b/Makefile index 29b20dd..774bd70 100644 --- a/Makefile +++ b/Makefile @@ -47,11 +47,10 @@ args_ebook = -V papersize=ebook -V fontsize=12pt -V classoption=oneside -V class all: $(flavors:%=$(stem)-%.pdf) download: - wget -O $(stem).raw '$(source_baseurl)w/index.php?title=$(source_basename)&action=edit' + ./mediawiki-fetch $(source_baseurl) $(source_basename) $(stem).raw $(stem).mw: $(stem).raw - ./mediawiki-extract $< $@ - ./mediawiki-trim $@ + ./mediawiki-trim $< $@ ./mediawiki-blockquote $@ ./mediawiki-uri-escape $@ ./mediawiki-matter $@ diff --git a/mediawiki-fetch b/mediawiki-fetch new file mode 100755 index 0000000..181c84e --- /dev/null +++ b/mediawiki-fetch @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +# fetch content of mediawiki page + +use warnings; +use strict; + +use feature qw(say); + +use Path::Tiny; +use MediaWiki::API; +use DateTime::Format::ISO8601; + +my $base_uri = shift; +my $page_title = shift; +my $outfile = shift; + +my $mw = MediaWiki::API->new( { api_url => $base_uri . 'w/api.php' } ); + +my $page = $mw->get_page( { title => $page_title } ) + || die $mw->{error}->{code} . ': ' . $mw->{error}->{details}; + +my $dt = DateTime::Format::ISO8601->parse_datetime( $page->{'timestamp'} ); + +path($outfile)->spew_utf8( $page->{'*'} ); +path($outfile)->touch( $dt->epoch ); + +say STDERR sprintf( 'Succesfully fetched %s (rev. %s)', + $page_title, + $page->{'revid'}); + +1; -- cgit v1.2.3