ImportBibTeX.pl

From WhiteStar 02

Jump to: navigation, search

(MediaWiki capitalizes the page title, it should be "importBibTeX.pl")

Contents

[edit] Description

This script is designed for use with the BibTeX MediaWiki extension found at: http://gsc2.cemif.univ-evry.fr/index.php/Mediawiki_extensions#Bibtex_extension

It is essentially an utility to import a large number of references from a list of files onto a wiki for use with the above extension. It also has a few other interesting features which are useful in that context (namely, using BibTeX and MediaWiki together).

It has four modes of operation:

  • In check mode, the script will just verify the syntax of the given bib file(s), and check that there are no duplicate keys. Additional checks could be added (one I'm thinking about is replacing accented characters with the equivalent BibTeX code), but for now that's all it does. Syntax validation is done by the Text::BibTeX module.
  • In insert mode, the script will insert all references in the given list of files onto a wiki between <bibtex>...</bibtex> tags. If a reference with the given key already exists, it will be replaced, so the script can also be used to update the references when the bib file(s) are changed.
  • In delete mode, the script will delete all the pages for the references in the given list of files. This is useful when you change the key to many references - instead of deleting the pages manually, just keep a backup of the bib file, then use delete on the old file and insert on the new one. Non-existent pages will simply be skipped.
  • In test mode, the script will create a page (using the specified title) with all the references in the given list of files. This is so you can quickly check that all the references are correct and have the right information, rather than having to go to each page one by one.

[edit] Command-line examples

[edit] Check

./importBibTeX.pl check bibliography.bib

[edit] Import

./importBibTeX.pl import http://www.example.com/w username password bibliography.bib

[edit] Delete

./importBibTeX.pl delete http://www.example.com/w username password bibliography.bib

[edit] Test

./importBibTeX.pl test http://www.example.com/w username password BibTeX_References bibliography.bib

[edit] Known problems

[edit] Connection issues

If there is a connection problem, the script will just die with an error. This is to be expected, and there are no ill effects to just restarting the same command:

  • In insert mode, it will just reinsert everything, hopefully completing successfully this time.
  • In delete mode, it will just skip pages that were deleted the previous time and start deleting from where it left off.

The script could be made more robust by using a retry count. I currently have no time to implement this, especially since I have no problem restarting it and it normally completes correctly the second time. Also, this could be happening more often for me because of site-specific issues which users will not encounter unless something is wrong with their wiki server or setup. But if someone wants to implement this, be my guest, and please send back the improved script.

[edit] Prerequisites

The script is written in Perl. It should run on any version from 5.6 and up, but I have only tested it on my Fedora 6 machine with Perl 5.8.8.

[edit] Required modules

On my Fedora machine, WWW::Mechanize could be installed through yum from the fedora-extras repository:

yum install perl-WWW-Mechanize

but Text::BibTeX had to be installed though CPAN:

perl -MCPAN -e'install "Text::BibTeX";'

(note capitalization). If someone knows where Text::BibTeX can be found in a yum repository, please drop me a line, as I prefer updating everything through yum.

For other distros, check with your package manager, and as a last resort install through CPAN.

For Windows, both are available through ppm, the command should be (untested):

ppm install WWW::Mechanize Text::BibTeX

[edit] Download

Download the latest version of the script here: download

[edit] Version history

  • 0.1: Initial revision
download
  • 0.2: Modified to work with an updated version of the BibTeX extension, available here.
download

[edit] Copyright

Copyright (c) 2007 Jean-Sébastien Guay. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Note: that is the classic Perl idiom, and refers to dual-licensing under either the Artistic License or the GPL.

[edit] Contact

You can contact me at

jean-sebastien <dot> guay <at> polymtl <dot> ca

if you have improvements to make to the script. Note that I will probably not provide much support for such a simple script, it should be pretty easy to use and if it doesn't do what you want, just modify it yourself.

Personal tools