Manual:Pywikibot/Use on third-party wikis

The pywikipedia bot may be used to do all kind of things that are important for the maintenance of a MediaWiki project. When this software is to be used outside of the Wikimedia projects, some configuration needs to be done.

Some non-Wikimedia projects, or families, are already supported. These can be found in the families folder which can be downloaded.

Using the existing files as examples, it should be easy to adapt the bot to your own project.

user-config.py file
Open a text file. (Notepad.exe is a text file editor)

Save the text file as, in the main pywikipedia folder.

Add the following three required lines to :

Now save  again.

family.py file
Modify the existing files, or create a new file, in a text editor.

Save the file in the pywikipedia/families folder, with a name such as

The  file in the families folder offers considerable documentation of the options available to family files.

Custom Namespaces
Adding a custom namespace to a family file is not well documented in the  file. The Uncyclopedia example below has some examples using custom namespaces, but the addition of these namespaces to your family file requires knowing the numerical ID of each namespace.

Typically these numerical IDs start at 100, and each even number is a content space and the following odd number is the talk space for that content space. However, to get the exact list, directing your browser to your Wiki's API.php file, and calling certain commands, is ideal.

The API.php file is found in the same place as index.php - so if your Wiki's URLs read like this: http://your.domain.org/wiki/index.php/[...] API.php can be found at this location: http://your.domain.org/wiki/api.php Further, if you use this URL: http://your.domain.org/wiki/api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics The resulting page will will list all of the relevant information about your Wiki, that you will need for writing the family file.

Also, note that  lists two ways to provide translations of namespaces - either changing a specific language's namespace like so: Or else changing an entire batch of languages in one go: When adding custom namespaces, you do not have a choice - you must use the second style. The first method only works because  already exists. With custom namespaces, they do not, so you must use the second style, with curly braces and everything, even if you only have one language. For example, suppose you have a News namespace, and your Wiki only operates in English:

If you do not use this format, the family file will not work - and more importantly, the resulting error message will not help - it will ask you to create a  file, even if that file already exists and works correctly.

Running the PyWikipedia Bot
Refer to Using the python wikipediabot on how to run the bot.

Example: Mozilla wiki
The Mozilla Foundation's wiki, wiki.mozilla.org, is a very simple example because it is only available in one language.

This is the contents of families/mozilla_family.py. Hints for you to write your own family specification are underlined.

Example: Memory Alpha
memoryalpha_family.py is the "family" definition of Memory Alpha, www.memory-alpha.org, a Star Trek wiki. This specification is a little bit more difficult because it has several languages.

Example: Uncyclopedia
The various Uncyclopedias are slightly more awkward as not all are hosted at the same domain or under the same name. Domain names and paths must be specified individually. Just over half are Wikia-hosted; exceptions include fi: hu: ja: ko: no: pt: sv: and zh-tw:. Many have their own registered domain names and many use custom namespaces.

The approaches which work for an Uncyclopædia or a Memory Alpha project typically can be adapted to other Wikia.

''Note: There have been subsequent updates and changes, see botwiki:python:uncyclopedia_family.py or uncyclopedia:es:usuario:Chixpy/uncyclopedia_family.py for more current versions of the Uncyclopedia interwiki bot configuration. There are also unresolved issues in which some interwiki languages are not available from all Uncyclopedia projects or point to incorrect/inconsistent destinations; proceed with caution.''

Language
For a single-language site, the language specified does not matter as long as it is consistent between the user-config.py and families/foo_family.py

Login failed. Wrong password?
Pywikipedia does not report anything more useful than success, failure, or host connection failure. If possible, try accessing the web server logs (apache uses access_log by default) and take a look at the URL strings.

Make sure your scriptpath, the relative path to your api.ph and index.php files, is defined appropriately for your wiki in your families file:

See the mozilla configuration for clues.

Mismatched interwiki configuration
In some projects (such as Uncyclopedia), each language operates as an independent wiki. This may mean that interwiki tables differ from one individual wiki to another within the same project. Interwiki.py is built on the assumption that, if outbound interlanguage links are available at all from a language, the list of available link-destination languages and the destination URL for each will match perfectly across all wikis in the project.

This leads to some potential pitfalls:
 * If one language is missing outbound language interwiki support entirely, one must avoid giving pywikipediabot an account on that wiki (in user-config.py) in order to ensure that interwiki.py leaves that one language wiki untouched.
 * If one language is using a valid but incomplete interwiki table, running interwiki.py on that language wiki will create broken links. Unlike the case where one language is missing project-wide, there is no clean and easy workaround.
 * If a language in a project has been forked (not just mirrored), the interwiki for each individual language pair will point to only one of the multiple forks. Verify the wiki your bot is looking at is the same one that is being linked from the wiki you're editing - otherwise the bot will delete some valid links as "page does not exist".

Customisation of namespaces
Some projects use non-standard extensions to provide Special:Interwiki and Special:Namespaces lists; where available, these lists should be checked against the configuration files to detect any additional namespace customisations.

Short URL rewrites
If your site uses short URL rewrites, you may have to add "/api.php" to the blacklists, Otherwise, your bot scripts will not be able to access api.php.

Check your rewrite conditions in your apache conf file, and make an appropriate addition.

Bot & private wikis
Some wikis require logging in into mediawiki before being able to view any wikipage. If you have any such site, add to your custom family file :

Bot & HTTP auth
Some sites will require password identication to access the HTML pages at the site. If you have any such site, add lines to your user-config.py of the following form: