diff --git a/README.md b/README.md index 86f0257..3930b6d 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,11 @@ To start an export, you will need the URL of the mediawiki API (usually http://m yamdwe.py MEDIAWIKI_API_URL DOKUWIKI_ROOT_PATH -If you need to log in to to your Mediawiki install (either with a Mediawiki username, or via HTTP Basic Auth) then run `yamdwe.py -h` to view the command line options for authentication. +If you need to log in to to your Mediawiki install (either with a Mediawiki username and if you are in a domain with the domain-name, or via HTTP Basic Auth) then run `yamdwe.py -h` to view the command line options for authentication. + +Domain functionality is added through the "develop" branch of this [simplemediawiki fork](https://github.com/BlackLotus/python-simplemediawiki/tree/develop) and can be used through. + + yamdwe.py --wiki_domain WIKI_DOMAIN MEDIAWIKI_API_URL DOKUWIKI_ROOT_PATH If installation goes well it should print the names of pages and images as it is exporting, and finally print "Done". This process can be slow, and can load up the Mediawiki server for large wikis. diff --git a/mediawiki.py b/mediawiki.py index 136a5f0..6802e41 100644 --- a/mediawiki.py +++ b/mediawiki.py @@ -11,9 +11,12 @@ from pprint import pprint class Importer(object): - def __init__(self, api_url, http_user=None, http_pass="", wiki_user=None, wiki_pass="", verbose=False): + def __init__(self, api_url, http_user=None, http_pass="", wiki_user=None, wiki_pass="", wiki_domain=None, verbose=False): self.verbose = verbose - self.mw = simplemediawiki.MediaWiki(api_url,http_user=http_user,http_password=http_pass) + if wiki_domain: + self.mw = simplemediawiki.MediaWiki(api_url, http_user=http_user, http_password=http_pass, domain=wiki_domain) + else: + self.mw = simplemediawiki.MediaWiki(api_url, http_user=http_user, http_password=http_pass) # login if necessary if wiki_user is not None: print("Logging in as %s..." % wiki_user) diff --git a/yamdwe.py b/yamdwe.py index b644ab5..67ee685 100755 --- a/yamdwe.py +++ b/yamdwe.py @@ -15,6 +15,8 @@ import argparse, sys, codecs, locale, getpass, datetime from pprint import pprint import mediawiki, dokuwiki, wikicontent +# only needed to check for domain functionality +import simplemediawiki, inspect def main(): # the wikicontent code (that uses visitor module) tends to recurse quite deeply for complex pages @@ -38,7 +40,10 @@ def main(): if not args.mediawiki.endswith("api.php"): print("WARNING: Mediawiki URL does not end in 'api.php'... This has to be the URL of the Mediawiki API, not just the wiki. If you can't export anything, try adding '/api.php' to the wiki URL.") - importer = mediawiki.Importer(args.mediawiki, args.http_user, args.http_pass, args.wiki_user, args.wiki_pass, args.verbose) + if "domain" in inspect.getargspec(simplemediawiki.MediaWiki.__init__)[0]: + importer = mediawiki.Importer(args.mediawiki, args.http_user, args.http_pass, args.wiki_user, args.wiki_pass, args.wiki_domain, args.verbose) + else: + importer = mediawiki.Importer(args.mediawiki, args.http_user, args.http_pass, args.wiki_user, args.wiki_pass, args.verbose) exporter = dokuwiki.Exporter(args.dokuwiki) # Set the wikicontent's definition of File: and Image: prefixes (varies by language settings) @@ -51,6 +56,7 @@ def main(): # Add a shameless "exported by yamdwe" note to the front page of the wiki mainpage = importer.get_main_pagetitle() + for page in pages: if page["title"] == mainpage: latest = dict(page["revisions"][0]) @@ -84,6 +90,8 @@ def main(): arguments.add_argument('--http_pass', help="Password for HTTP basic auth (if --http_user is specified but not --http_pass, yamdwe will prompt for a password)") arguments.add_argument('--wiki_user', help="Mediawiki login username") arguments.add_argument('--wiki_pass', help="Mediawiki login password (if --wiki_user is specified but not --wiki_pass, yamdwe will prompt for a password)") +if "domain" in inspect.getargspec(simplemediawiki.MediaWiki.__init__)[0]: + arguments.add_argument('--wiki_domain', help="Mediawiki login domain (needs a non-standard simplemediawiki library)") arguments.add_argument('-v', '--verbose',help="Print verbose progress and error messages", action="store_true") arguments.add_argument('mediawiki', metavar='MEDIAWIKI_API_URL', help="URL of mediawiki's api.php file (something like http://mysite/wiki/api.php)") arguments.add_argument('dokuwiki', metavar='DOKUWIKI_ROOT', help="Root path to an existing dokuwiki installation to add the Mediawiki pages to (can be a brand new install.)")