Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Numinix MediaWiki Demo
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Manual/Importing XML dumps
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== On Ruby ==== <!--T:162--> </translate> <syntaxhighlight lang="ruby"> # -*- coding: utf-8 -*- # dumpxml2wiki.rb require 'rubygems' require 'nokogiri' # <translate nowrap><!--T:140--> This program <tvar name=1>dumpxml2wiki</tvar> reads MediaWiki xml files dumped by <tvar name=2>dumpBackup.php</tvar> on the current directory and transforms them into wiki files which can then be modified and uploaded again by <tvar name=3>pywikipediabot</tvar> using <tvar name=4>pagefromfile.py</tvar> on a MediaWiki family site.</translate> # <translate nowrap><!--T:143--> The text of each page is searched with xpath and its title is added on the first line as an html comment: this is required by <tvar name=1>pagefromfile.py</tvar>.</translate> # Dir.glob("*.xml").each do |filename| input = Nokogiri::XML(File.new(filename), nil, 'UTF-8') puts filename.to_s # prints the name of each .xml file File.open("out_" + filename + ".wiki", 'w') {|f| input.xpath("//xmlns:text").each {|n| pptitle = n.parent.parent.at_css "title" # searching for the title title = pptitle.content f.puts "\n<!--'''" << title.to_s << "'''-->" << n.content << "\n" } } end </syntaxhighlight> <translate> <!--T:39--> For example, here is an excerpt of a wiki file output by the command 'ruby dumpxml2wiki.rb' (two pages can then be uploaded by pagefromfile.py, a Template and a second page which is a redirect): </translate> <syntaxhighlight lang="html4strict"> <!--'''Template:Lang_translation_-pl'''--><includeonly>Tłumaczenie</includeonly> #REDIRECT[[badania demograficzne]]<!--'''ilościowa demografia'''--> <noinclude> [[Category:Termin wielojęzycznego słownika demograficznego (pierwsze wydanie)|ilościowa demografia]] [[Category:Termin wielojęzycznego słownika demograficznego (pierwsze wydanie) (redirect)]] [[Category:10]]</noinclude> </syntaxhighlight> <translate><!--T:40--> The program accesses each xml file, extracts the texts within <tvar name=1><nowiki><text> </text></nowiki></tvar> markups of each page, searches the corresponding title as a parent and enclosed it with the paired <nowiki><!--'''Title of the page'''--> </nowiki> commands used by 'pagefromfile' to create or update a page.</translate> <translate><!--T:70--> The name of the page is in an html comment and separated by three quotes on the same first start line.</translate> <translate><!--T:71--> Please notice that the name of the page can be written in Unicode.</translate> <translate><!--T:72--> Sometimes it is important that the page starts directly with the command, like for a <tvar name=2><nowiki>#REDIRECT</nowiki></tvar>; thus the comment giving the name of the page must be ''after'' the command but still on the first line.</translate> <translate> <!--T:41--> Please remark that the xml dump files produced by <tvar name=1>dumpBackup.php</tvar> are prefixed by a namespace: </translate> <syntaxhighlight lang="html4strict"><mediawiki xmlns="http://www.mediawiki.org/xml/export-0.4/"></syntaxhighlight> <translate> <!--T:42--> In order to access the text node using Nokogiri, you need to prefix your path with 'xmlns': </translate> <syntaxhighlight lang="html4strict">input.xpath("//xmlns:text")</syntaxhighlight> <translate> <!--T:12--> Nokogiri is an HTML, XML, SAX, & Reader parser with the ability to search documents via XPath or CSS3 selectors from the last generation of XML parsers using Ruby. <!--T:43--> Example of the use of 'pagefromfile' to upload the output wiki text file: </translate> <syntaxhighlight lang="bash"> python pagefromfile.py -file:out_filename.wiki -summary:"Reason for changes" -lang:pl -putthrottle:01 </syntaxhighlight> <translate>
Summary:
Please note that all contributions to Numinix MediaWiki Demo may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Project:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)