MediaWiki::DumpFile::Pages(3pm) | User Contributed Perl Documentation | MediaWiki::DumpFile::Pages(3pm) |
MediaWiki::DumpFile::Pages - Process an XML dump file of pages from a MediaWiki instance
use MediaWiki::DumpFile::Pages; #dump files up to version 0.5 are tested $input = 'file-name.xml'; #many supported compression formats $input = 'file-name.xml.bz2'; $input = 'file-name.xml.gz'; $input = \*FH; $pages = MediaWiki::DumpFile::Pages->new($input); #default values %opts = ( input => $input, fast_mode => 0, version_ignore => 1 ); #override configuration options passed to constructor $ENV{MEDIAWIKI_DUMPFILE_VERSION_IGNORE} = 0; $ENV{MEDIAWIKI_DUMPFILE_FAST_MODE} = 1; $pages = MediaWiki::DumpFile::Pages->new(%opts); $version = $pages->version; #version 0.3 and later dump files only $sitename = $pages->sitename; $base = $pages->base; $generator = $pages->generator; $case = $pages->case; %namespaces = $pages->namespaces; #all versions while(defined($page = $pages->next) { print 'Title: ', $page->title, "\n"; } $title = $page->title; $id = $page->id; $revision = $page->revision; @revisions = $page->revision; $text = $revision->text; $id = $revision->id; $timestamp = $revision->timestamp; $comment = $revision->comment; $contributor = $revision->contributor; #version 0.4 and later dump files only $bool = $revision->redirect; $username = $contributor->username; $id = $contributor->id; $ip = $contributor->ip; $username_or_ip = $contributor->astext; $username_or_ip = "$contributor";
This is the constructor for this package. If it is called with a single parameter it must be the input to use for parsing. The input is specified as either the location of a MediaWiki pages dump file or a reference to an already open file handle.
If more than one argument is passed to new it must be a hash of options. The keys are named
Returns the version of the dump file.
Returns the sitename from the MediaWiki instance. Requires a dump file of at least version 0.3.
Returns the URL used to access the MediaWiki instance. Requires a dump file of at least version 0.3.
Returns the version of MediaWiki that generated the dump file. Requires a dump file of at least version 0.3.
Returns the case sensitivity configuration of the MediaWiki instance. Requires a dump file of at least version 0.3.
Returns a hash where the key is the numerical namespace id and the value is the plain text namespace name. The main namespace has an id of 0 and an empty string value. Requires a dump file of at least version 0.3.
Accepts an optional boolean argument to control fast mode. If the argument is specified it forces fast mode on or off. Otherwise the mode is controlled by the fast_mode configuration option. See the section below on fast mode for more information.
It is safe to intermix calls between fast and normal mode in one parsing session.
In all modes undef is returned if there is no more data to parse.
In normal mode an instance of MediaWiki::DumpFile::Pages::Page is returned and the full API is available.
In fast mode an instance of MediaWiki::DumpFile::Pages::FastPage is returned; the only methods supported are title, text, and revision. This class can act as a stand-in for MediaWiki::DumpFile::Pages::Page except it will throw an error if any attempt is made to access any other part of the API.
Returns the size of the input file in bytes or if the input specified is a reference to a file handle it returns undef.
Returns the number of bytes of XML that have been successfully parsed.
Fast mode is a way to get increased parsing performance while dropping some of the features available in the parser. If you only require the titles and text from a page then fast mode will decrease the amount of time required just to parse the XML file; some times drastically.
When fast mode is used on a dump file that has more than one revision of a single article in it only the text of the first article in the dump file will be returned; the other revisions of the article will be silently skipped over.
This object represents a distinct Mediawiki page and is used to access the page data and metadata. The following methods are available:
This object represents a distinct revision of a page from the Mediawiki dump file. The standard dump files contain only the most specific revision of each page and the comprehensive dump files contain all revisions for each page. The following methods are available:
This object provides access to the contributor of a specific revision of a page. When used in a scalar context it will return the username of the editor if the editor was logged in or the IP address of the editor if the edit was anonymous.
While trying to build the XML::TreePuller object a fatal error occurred; the error message from the parser was included in the generated error output you saw. At the time of writing this document the error messages are not very helpful but for some reason the XML parser rejected the document; here's a list of things to check:
Something went wrong with the XML parser - the error from the parser was included in the generated error message. This happens when there is a severe error parsing the document such as a syntax error.
The dump files created by Mediawiki include a versioned XML schema. This software is tested with the most recent known schema versions and can be configured to enforce a specific tested schema. MediaWiki::DumpFile::Pages no longer enforces the versions by default but the software author using this library has indicated that it should. When this happens it dies with an error like the following:
E_UNTESTED_DUMP_VERSION Version 0.4 dump file "t/simpleenglish-wikipedia.xml" has not been tested with MediaWiki::DumpFile::Pages version 0.1.9; see the ERRORS section of the MediaWiki::DumpFile::Pages Perl module documentation for what to do at lib/MediaWiki/DumpFile/Pages.pm line 148.
If you encounter this condition you can do the following:
http://search.cpan.org/dist/MediaWiki-DumpFile/lib/MediaWiki/DumpFile/Pages.pm
will show the highest supported version dump files near the top of the SYNOPSIS.
http://rt.cpan.org/Public/Dist/Display.html?Name=mediawiki-dumpfile
and check for an open bug report relating to the version number changing.
MEDIAWIKI_DUMPFILE_VERSION_IGNORE=1 ./wikiscript.pl
This may work fine or it may fail in subtle ways silently - there is no way to know for sure with out studying the schema to see if the changes are backwards compatible.
Tyler Riddle, "<triddle at gmail.com>"
Please see MediaWiki::DumpFile for information on how to report bugs in this software.
Copyright 2009 "Tyler Riddle".
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
2022-06-15 | perl v5.34.0 |