Pywikibot/Use on non-WMF wikis: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
→‎family.py file: don't do this if you don't have to! generate_family_file.py exists for a reason
m Billinghurst moved page Pywikipediabot/Use on non-WMF wikis to Pywikibot/Use on non-WMF wikis: align to preferred name
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{MovedToMediaWiki|Manual:{{PAGENAME}}}}
{{Template:Bothelp}}

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 [http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/families/] which can be [[Using_the_python_wikipediabot#Download|downloaded]].

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

{{:Using the python wikipediabot/Overview}} {{green|#REQUIRED}}

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

Save the text file as <code>user-config.py</code>, in the main pywikipedia folder.

Add the following '''three''' required lines to <code>user-config.py</code>:

{| cellpadding=5
|'''Code'''
|'''Explanation'''
|-
|valign=top width=400px|
mylang = 'xx'
|valign=top|
xx is the code for the language code you are working on, "en" is English.<ref name="lan">If you want to work with more than one language, choose the most common one, as you can override configured value in command line by <tt>-lang</tt> parameter.</ref>
|-
|valign=top|
usernames['sitename']['en'] = u'ExampleBot'<ref name="uni">The 'u' in front of the username stands for Unicode. The 'u' is important if your username contains non-ASCII characters. If you are using ASCII characters only, you can remove the 'u' (if you have troubles loging in with your bot, otherwise you can leave the 'u' as is).</ref>
|valign=top|
Your <code>user-config.py</code> file needs to specify the bot's username.

In this example, the user is working on English sitename, and has created a bot account with the username "ExampleBot".

"Sitename" is the name of the your site you're working on (actually the name of the family.py file without the "family").
|-
|valign=top|
family = 'sitename'
|valign=top|
Sitename is the same name as the sitename in the above username line. (usernames[''''sitename'''<nowiki>'</nowiki>]['en'] = u'ExampleBot'.)

|}

Now save <code>user-config.py</code> again.

Your user-config.py should look something like this:

<pre>
mylang='en'
family = 'dead'
usernames['dead']['en']=u'bobtheperv'
console_encoding = 'utf-8'
</pre>

===family.py file===
If there is no family file for the wiki that you are going to use the bot on, then you need to create one. ''Before you attempt to create one using the instructions below'' execute <code>python generate_family_file.py</code>. If it succeeds, then you do not need to do any of this, a family file will have been created for you and you can login to your wiki. If it fails, then you will need to modify the [[Pywikipediabot/Use_on_non-Wikimedia_wikis#Examples|existing files below]], or create a new file, in a [[w:text editor|text editor]].

Save the file in the pywikipedia/families folder, with a name such as <code>mozilla_family.py</code>

Follow the sections below in order (each section makes the following section easier).

You must have the correct details as described in the sections below.

Potential problems:
* errors in the custom namespaces mean the family file won't work properly (though you'll get a warning when you login?)
* an error in specifying index.php will prevent you logging in;
* an error in specifying api.php seems likely to lead to problems, since the wiki is accessed via API.

The <code>README-family.txt</code> file in the families folder offers considerable documentation of the options available to family files. In fact, <code>README-family.txt</code> is a simple 'prototype' family file. You can just copy <code>README-family.txt</code> to sitename_family.py, then open up the sitename_family.py file in a text editor, and tweak it per the instructions below.

==== index.php ====
:''Note, several family files do not have this in the file, for example, battlestarwiki_family.py''

You must have a correct index.php path in family.py.
To check if you have the correct path for your index.php, test which address redirects to your wiki's homepage - probably one of these:
* wikidomainname.org/wiki/index.php
* wikidomainname.org/w/index.php
* wikidomainname.org/mw/index.php
* wikidomainname.org/index.php

(You may be able to guess from the address of a regular wiki page, but you need to check it - e.g. a wiki page may be wikidomainname.org/randompage but the correct path may be ''''w/index.php'''' - this occurs at [http://fr.ekopedia.org fr.ekopedia.org] for example.)

Near the end of your family.py file, you find something similar to this. Modify or remove the "/w" as necessary:

<pre>
def scriptpath(self, code):
return '/w/' #The path of index.php, look at your wiki address.
# This line may need to be changed to /wiki/ or /mw/,
# depending on the folder where your mediawiki program is located.</pre>

==== api.php ====
:''Note, several family files in the pywikipedia family folder do not have this in the file, for example, battlestarwiki_family.py''

<del>You must have a correct API.php path in family.py.</del><ins>''Previously this needed to be corrected but variables now allow it to find the path from the scrptpath added in the step above.''</ins>

The API.php file is found in the same place as index.php. Test this by navigating to for example:
: your.domain.org/wiki/api.php
or
: your.domain.org/w/api.php
or
: your.domain.org/mw/api.php
or
: your.domain.org/api.php

The correct address will give you an auto-generated MediaWiki API documentation page (the important thing is that it confirms you have the correct address).

The api is defined like this:
<pre>
def apipath(self, code):

return '%s/api.php' % self.scriptpath(code)</pre>

''There is nothing here that needs to be changed.''

==== Custom Namespaces ====
:''Note, several family files in the pywikipedia family folder do not have this in the file, for example, battlestarwiki_family.py''

'''<font color="red">Why do you need to add a custom namespace to a family file? Please explain</font>'''

Adding a custom namespace to a family file is not well documented in the <code>README-family.txt</code> file. The [[#Example: Uncyclopedia|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.

'''Finding the details you need''': Start with the api url (which you found above) and add this string to the end:
<nowiki>?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics</nowiki>

...so your address might look something like:

:<nowiki>http://your.domain.org/wiki/api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics</nowiki>

The resulting page will list the information about your namespaces that you need for the family file, including the numerical ID.<ref>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. But to get the exact list view the Wiki's Mediawiki API Result file.</ref>

{| class="wikitable collapsible collapsed"
!Example of Mediawiki API Result
|-
|
<pre>
You are looking at the HTML representation of the XML format.
HTML is good for debugging, but probably is not suitable for your application.
See complete documentation, or API help for more information.
<?xml version="1.0"?>
<api>
<query>
<general mainpage="Dead Wiki" base="http://dead-wiki.com/w/index.php?title=Dead_Wiki" sitename="Dead Wiki" generator="MediaWiki 1.16.0" phpversion="5.2.14" phpsapi="cgi-fcgi" dbtype="mysql" dbversion="5.0.91-log" case="first-letter" rights="" lang="en" fallback8bitEncoding="windows-1252" writeapi="" timezone="UTC" timeoffset="0" articlepath="/w/index.php?title=$1" scriptpath="/w" script="/w/index.php" variantarticlepath="" server="http://dead-wiki.com" wikiid="dea199999999999999-mw_" time="2010-11-19T08:49:37Z" />
<namespaces>
<ns id="-2" case="first-letter" canonical="Media" xml:space="preserve">Media</ns>
<ns id="-1" case="first-letter" canonical="Special" xml:space="preserve">Special</ns>
<ns id="0" case="first-letter" content="" xml:space="preserve" />
<ns id="1" case="first-letter" subpages="" canonical="Talk" xml:space="preserve">Talk</ns>
<ns id="2" case="first-letter" subpages="" canonical="User" xml:space="preserve">User</ns>
<ns id="3" case="first-letter" subpages="" canonical="User talk" xml:space="preserve">User talk</ns>
<ns id="4" case="first-letter" canonical="Project" xml:space="preserve">Dead Wiki</ns>
<ns id="5" case="first-letter" subpages="" canonical="Project talk" xml:space="preserve">Dead Wiki talk</ns>
<ns id="6" case="first-letter" canonical="File" xml:space="preserve">File</ns>
<ns id="7" case="first-letter" subpages="" canonical="File talk" xml:space="preserve">File talk</ns>
<ns id="8" case="first-letter" subpages="" canonical="MediaWiki" xml:space="preserve">MediaWiki</ns>
<ns id="9" case="first-letter" subpages="" canonical="MediaWiki talk" xml:space="preserve">MediaWiki talk</ns>
<ns id="10" case="first-letter" canonical="Template" xml:space="preserve">Template</ns>
<ns id="11" case="first-letter" subpages="" canonical="Template talk" xml:space="preserve">Template talk</ns>
<ns id="12" case="first-letter" canonical="Help" xml:space="preserve">Help</ns>
<ns id="13" case="first-letter" subpages="" canonical="Help talk" xml:space="preserve">Help talk</ns>
<ns id="14" case="first-letter" canonical="Category" xml:space="preserve">Category</ns>
<ns id="15" case="first-letter" subpages="" canonical="Category talk" xml:space="preserve">Category talk</ns>
</namespaces>
<namespacealiases>
<ns id="6" xml:space="preserve">Image</ns>
<ns id="7" xml:space="preserve">Image talk</ns>
</namespacealiases>
<statistics pages="1757" articles="620" views="150" edits="2606" images="0" users="1" activeusers="-1" admins="1" jobs="28184" />
</query>
</api>
</pre>
|}


<code>README-family.txt</code> explains two ways to list namespaces:

1. Changing a specific language's namespace:
<source lang="Python">self.namespaces[2]['en'] = u'Wikiuser'
self.namespaces[3]['en'] = u'Wikiuser talk'</source>


2. Changing an entire batch of languages at once:
<source lang="Python">self.namespaces[4] = {
'_default': [u'WIKINAME', self.namespaces[4]['_default']], # REQUIRED
'de': 'Name des wiki',
'es': 'Nombre del wiki',
'fr': 'Nom du wiki',
# ETC.
}</source>

When adding custom namespaces you '''must''' use the second style. The first method only works because <code>self.namespaces[2]['en']</code> already exists. With custom namespaces, they do not, so you must use the second style, including the curly braces, even if you only have one language. For example, suppose you have a News namespace, and your Wiki only operates in English:
<source lang="Python">self.namespaces[100] = { 'en': 'News' }
self.namespaces[101] = { 'en': 'News talk' }</source>

If you do not use this format, the family file '''will not work''', the resulting error message '''will not help''' - it will ask you to create a <code>user-config.py</code> file, even if that file already exists and works correctly.

==== Custom User Groups & Permissions ====

PyWikipedia assumes that the Wiki it is running on uses the standard, default user groups and that each group is assigned the usual permissions. This means that it may refuse to do things that its account would allow, and it may attempt to do things that its account is not allowed to do (these attempts will fail, so this is not a security issue).

The fact that it will attempt things it is not allowed to do is minor, but the inability to perform certain actions (e.g. deleting pages) without being in the "Sysop" group can be a sizable limitation. If the bot account has such permissions without being in the "Sysop" group (being part of some other, non-standard group), the only known work-around is the edit Wikipedia.py itself. This file controls most bot actions, and is found in the main folder PyWikipedia has been installed to.

In the _getUserData() function within Wikipedia.py, a pair of lines like this exists:
<source lang="Python"> if 'Sysop' in self._rights[index]:
self._rights[index].extend(['delete', 'undelete', 'block', 'protect', 'import', 'deletedhistory', 'unwatchedpages'])</source>
In version 2008-10-29T19:21:05.438703Z 6043, this is line 4705 and 4706, but that line number may be different, even very different, in other versions. Using the Find function of your text editor to find "<code>def _getUserData(</code>" (to find the function definition) is recommended.

In order to get the rights listed in the second line, the first line must be changed to recognize your custom user group (note: if your custom user-group has some, but not all of those rights, changing this will not give you those rights - it will simply let PyWikipedia attempt to exercise them if you direct it to. Doing so is strongly '''not''' recommended as the program's behavior in such a case is undefined). The exact name of the user group can be found by logging in manually as the bot, and viewing the HTML code of any Wiki page. Near the top, a line as follows should appear:
<source lang="JavaScript">var wgUserGroups = [ ... ]</source>
Where the ellipsis is replaced by a list of the groups that the bot is a member of. Choose the one that matches the custom user group that gives you the rights that you are attempting to exercise, and replace Sysop in the above code from Wikipedia.py with that name. This should activate those rights for PyWikipedia.

===Running the PyWikipedia Bot===

Refer to [[Using_the_python_wikipediabot#Use|Using the python wikipediabot]] on how to run the bot.

==Family File examples==
{{anchor|Examples}}
=== 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 <code>families/mozilla_family.py</code>. Hints for you to write your own family specification are underlined.

<source lang=python> # -*- coding: utf-8 -*-
import family
# The official Mozilla Wiki. #Put a short project description here.
class Family(family.Family):
def __init__(self):
family.Family.__init__(self)
self.name = 'mozilla' # Set the family name; this should be the same as in the filename.
self.langs = {
'en': 'wiki.mozilla.org', # Put the hostname here.
}

# Translation used on all wikis for the different namespaces.
# Most namespaces are inherited from family.Family.
# Check the family.py file (in main directory) to see the standard
# namespace translations for each known language.
# You only need to enter translations that differ from the default.
self.namespaces[4] = {
'_default': u'MozillaWiki', # Specify the project namespace here.
}
self.namespaces[5] = {
'_default': u'MozillaWiki talk', # Specify the talk page of the project namespace here.
}
def version(self, code):
return "1.4.2" # The MediaWiki version used. Not very important in most cases.
def scriptpath(self, code):
return '' # The relative path of index.php, api.php : look at your wiki address.
# This line may need to be changed to /wiki or /w,
# depending on the folder where your mediawiki program is located.
# Note: Do not _include_ index.php, etc.
</source>

=== Example: Starwars ===
This is the content of the Starwars wiki at wikia. The file is located at <code>families/starwars_family.py</code>.

[http://starwars.wikia.com/wiki/User:Sikon/Pywikipedia Here] explains how to configure the Pywikipedia bot to work at this site.

<source lang=python>import family
class Family(family.Family):
def __init__(self):
family.Family.__init__(self)
self.name = 'starwars'
self.langs = {
'en': None,
}
# Translation used on all wikis for the different namespaces.
# Most namespaces are inherited from family.Family.
# Check the family.py file (in main directory) to see the standard
# namespace translations for each known language.
# You only need to enter translations that differ from the default.
self.namespaces[4] = {
'_default': u'Wookieepedia', # Specify the project namespace here.
}
self.namespaces[5] = {
'_default': u'Wookieepedia talk', # Specify the talk page of the project namespace here.
}
# A few selected big languages for things that we do not want to loop over
# all languages. This is only needed by the titletranslate.py module, so
# if you carefully avoid the options, you could get away without these
# for another wiki family.
self.languages_by_size = ['en']
def hostname(self,code):
return 'starwars.wikia.com'
def path(self, code):
return '/index.php'
def version(self, code):
return "1.9" # Which version of MediaWiki is used?
</source>

=== 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.

<source lang="python">
# -*- coding: utf-8 -*-
import family
# The Memory Alpha family, a set of StarTrek wikis.
class Family(family.Family):
def __init__(self):
family.Family.__init__(self)
self.name = 'memoryalpha'
self.langs = { # All available languages are listed here.
'de': None, # Because the hostname is the same for all languages,
'en': None, # we don't specify it here, but below in the hostname()
'nl': None, # function.
'sv': None,
}
# Most namespaces are inherited from family.Family.
self.namespaces[4] = {
'_default': u'Memory Alpha', # All languages use the same project namespace name.
}
self.namespaces[5] = {
'_default': u'Memory Alpha talk',
'de': u'Memory Alpha Diskussion',
'nl': u'Overleg Memory Alpha',
'sv': u'Memory Alphadiskussion',
}
# A few selected big languages for things that we do not want to loop over
# all languages. This is only needed by the titletranslate.py module, so
# if you carefully avoid the options, you could get away without these
# for another wiki family.
self.biglangs = ['en', 'de'] # Not very important
def hostname(self,code):
return 'www.memory-alpha.org' # The same for all languages
def scriptpath(self, code):
return '/%s' % code # The language code is included in the path
def version(self, code):
return "1.4"
</source>

=== Example: Uncyclopedia ===
The various [[Uncyclopedia:Babel:Main_Page|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:Main_Page|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.''

<source lang="python">
# -*- coding: utf-8 -*-
import family
# The Uncyclopaedia family, a satirical set of encyclopaedia wikis. (May 2006)
#
# Save this file to families/uncyclopedia_family.py in your pywikibot installation
# The pywikipediabot itself is available for free download from sourceforge.net
#

class Family(family.Family):
def __init__(self):
family.Family.__init__(self)
self.name = 'uncyclopedia'
self.langs = {
'ar': 'beidipedia.wikia.com',
'ca': 'valenciclopedia.wikia.com',
'da': 'da.uncyclopedia.wikia.com',
'de': 'de.uncyclopedia.wikia.com',
'el': 'anegkyklopaideia.wikia.com',
'en': 'uncyclopedia.wikia.com',
'es': 'inciclopedia.wikia.com',
'fi': 'peelonet.zapto.org',
'fr': 'desencyclopedie.com',
'he': 'eincyclopedia.wikia.com',
'hu': 'hu.uncyclopedia.info',
'it': 'nonciclopedia.wikia.com',
'ja': 'ja.uncyclopedia.info',
'la': 'uncapaedia.wikia.com',
'no': 'ikkepedia.net',
'pl': 'nonsensopedia.wikia.com',
'pt': 'pt.uncyclopedia.info',
'ru': 'absurdopedia.net',
'sv': 'psyklopedin.hehu.se',
'zh': 'zh.uncyclopedia.wikia.com',
'zh-tw': 'zh.uncyclopedia.info',
}
# Most namespaces are inherited from family.Family.
self.namespaces[1] = {
'_default': u'Talk',
'ar': u'نقاش',
'ca': u'Discussió',
'da': u'Diskussion',
'de': u'Diskussion',
'el': u'Συζήτηση',
'en': u'Talk',
'es': u'Discusión',
'fi': u'Keskustelu',
'fr': u'Discuter',
'he': u'שיחה',
'it': u'Discussione',
'la': u'Disputatio',
'no': u'Diskusjon',
'pl': u'Dyskusja',
'pt': u'Discussão',
'ru': u'Обсуждение',
'sv': u'Diskussion',
'zh-tw': u'討論',
}

self.namespaces[2] = {
'_default': u'User',
'ar': u'مستخدم',
'ca': u'Usuari',
'da': u'Bruger',
'de': u'Benutzer',
'el': u'Χρήστης',
'en': u'User',
'es': u'Usuario',
'fi': u'Käyttäjä',
'fr': u'Utilisateur',
'he': u'משתמש',
'it': u'Utente',
'la': u'Usor',
'no': u'Bruker',
'pl': u'Użytkownik',
'pt': u'Usuário',
'ru': u'Участник',
'sv': u'Användare',
'zh-tw': u'用戶',
}

self.namespaces[3] = {
'_default': u'User talk',
'ar': u'نقاش المستخدم',
'ca': u'Usuari Discussió',
'da': u'Bruger diskussion',
'de': u'Benutzer Diskussion',
'el': u'Συζήτηση χρήστη',
'en': u'User talk',
'es': u'Usuario Discusión',
'fi': u'Keskustelu käyttäjästä',
'fr': u'Discussion Utilisateur',
'he': u'שיחת משתמש',
'it': u'Discussioni utente',
'la': u'Disputatio Usoris',
'no': u'Brukerdiskusjon',
'pl': u'Dyskusja użytkownika',
'pt': u'Usuário Discussão',
'ru': u'Обсуждение участника',
'sv': u'Användardiskussion',
'zh-tw': u'用戶討論',
}

self.namespaces[4] = {
'_default': u'Uncyclopedia',
'ar': u'ويكيبيديا',
'ca': u'Valenciclopèdia',
'da': u'Spademanns Leksikon',
'de': u'Uncyclopedia',
'el': u'Ανεγκυκλοπαίδεια',
'en': u'Uncyclopedia',
'es': u'Inciclopedia',
'fi': u'Hikipedia',
'fr': u'Désencyclopédie',
'he': u'איןציקלופדיה',
'it': u'Nonciclopedia',
'la': u'Uncapaedia',
'no': u'Wikipedia',
'pl': u'Nonsensopedia',
'pt': u'Desciclopédia',
'ru': u'Абсурдопедия',
'sv': u'Psykelopedia',
'zh': u'伪基百科',
'zh-tw': u'偽基百科',
}
self.namespaces[5] = {
'_default': u'Uncyclopedia talk',
'ar': u'نقاش ويكيبيديا',
'ca': u'Valenciclopèdia Discussió',
'da': u'Spademanns Leksikon diskussion',
'de': u'Uncyclopedia Diskussion',
'el': u'Ανεγκυκλοπαίδεια συζήτηση',
'en': u'Uncyclopedia talk',
'es': u'Inciclopedia Discusión',
'fi': u'Keskustelu Hikipediasta',
'fr': u'Discussion Désencyclopédie',
'he': u'שיחת איןציקלופדיה',
'it': u'Discussioni Nonciclopedia',
'la': u'Disputatio Uncapaediae',
'no': u'Wikipedia-diskusjon',
'pl': u'Dyskusja Nonsensopedia',
'pt': u'Desciclopédia Discussão',
'ru': u'Обсуждение Абсурдопедии',
'sv': u'Psykelopediadiskussion',
'zh': u'伪基百科 talk',
'zh-tw': u'偽基百科討論',
}

self.namespaces[6] = {
'_default': u'Image',
'ar': u'صورة',
'ca': u'Imatge',
'da': u'Billede',
'de': u'Bild',
'el': u'Εικόνα',
'es': u'Imagen',
'fi': u'Kuva',
'he': u'תמונה',
'it': u'Immagine',
'la': u'Imago',
'no': u'Bilde',
'pl': u'Grafika',
'pt': u'Imagem',
'ru': u'Изображение',
'sv': u'Bild',
'zh-tw': u'圖像',
}

self.namespaces[7] = {
'_default': u'Image talk',
'ar': u'نقاش الصورة',
'ca': u'Imatge Discussió',
'da': u'Billede diskussion',
'de': u'Bild Diskussion',
'el': u'Συζήτηση εικόνας',
'es': u'Imagen Discusión',
'fi': u'Keskustelu kuvasta',
'fr': u'Discussion Image',
'he': u'שיחת תמונה',
'it': u'Discussioni immagine',
'la': u'Disputatio Imaginis',
'no': u'Bildediskusjon',
'pl': u'Dyskusja grafiki',
'pt': u'Imagem Discussão',
'ru': u'Обсуждение изображения',
'sv': u'Bilddiskussion',
'zh-tw': u'圖像討論',
}

self.namespaces[8] = {
'_default': u'MediaWiki',
'ar': u'ميدياويكي',
'he': u'מדיה ויקי',
'zh-tw': u'媒體維基',
}

self.namespaces[9] = {
'_default': u'MediaWiki talk',
'ar': u'نقاش ميدياويكي',
'ca': u'MediaWiki Discussió',
'da': u'MediaWiki diskussion',
'de': u'MediaWiki Diskussion',
'es': u'MediaWiki Discusión',
'fr': u'Discussion MediaWiki',
'he': u'שיחת מדיה ויקי',
'it': u'Discussioni MediaWiki',
'la': u'Disputatio MediaWiki',
'no': u'MediaWiki-diskusjon',
'pl': u'Dyskusja MediaWiki',
'pt': u'MediaWiki Discussão',
'ru': u'Обсуждение MediaWiki',
'sv': u'MediaWiki diskussion',
'zh-tw': u'媒體維基討論',
}

#
# Custom namespace list for en: (and fi:)
#
self.namespaces[100] = {
'_default':u'Wilde',
'en':u'Wilde',
'fi':u'Hikiquote',
'pl':u'Cytaty',
}
self.namespaces[101] = {
'_default':u'Wilde talk',
'en':u'Wilde talk',
'fi':u'Hiktionary',
'pl':u'Dyskucja cytatów',
}
self.namespaces[102] = {
'_default':u'UnNews',
'en':u'UnNews',
'fi':u'Hikikirjasto',
'pl':u'NonNews',
}
self.namespaces[103] = {'_default':u'UnNews talk'}
self.namespaces[104] = {'_default':u'Undictionary'}
self.namespaces[105] = {'_default':u'Undictionary talk'}
self.namespaces[106] = {'_default':u'Game'}
self.namespaces[107] = {'_default':u'Game talk'}
self.namespaces[108] = {'_default':u'Babel'}
self.namespaces[109] = {'_default':u'Babel talk'}
self.namespaces[110] = {'_default':u'Forum'}
self.namespaces[111] = {'_default':u'Forum talk'}

# A few selected big languages for things that we do not want to loop over
# all languages. This is only needed by the titletranslate.py module, so
# if you carefully avoid the options, you could get away without these
# for another wiki family.
self.languages_by_size = ['en', 'pl', 'de', 'es', 'ru', 'fr']

def hostname(self,code):
return self.langs[code]

def scriptpath(self, code):
if code=='fi':
return '/hikipedia'
if code in ['hu', 'ja', 'pt', 'sv', 'zh-tw']:
return '/w'
if code=='no':
return ''
return '/wiki'

def version(self, code):
return "1.7"
</source>

== Notes ==

=== 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.

You could also try running login.py in 'very verbose' mode, ie: <code> python login.py -v -v </code> . This will dump a lot of information, including possibly the html code from the server, so you can see exactly what is going on. (this option does however run the risk of possibly revealing some security sensitive info so be careful...)

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

<source lang="python">
def scriptpath(self, code):
return '/wiki'
</source>

If this does not help, add a line like

<source lang="python">
authenticate['www.mywiki.com'] = ('botName','botPassword')
</source>

to your user-config.py file.

See the [[#Example: Mozilla wiki|mozilla configuration ]] for clues.

=== Bot doesn't want to stay logged in ===
If you are able to log in with <code>login.py</code>, but the bot doesn't seem to want to remember your credentials no matter what, try this workaround (from the comments of <strike>bug #[http://sourceforge.net/tracker/index.php?func=detail&aid=1985308&group_id=93107&atid=603138 1985308]</strike>):

Add the line
<source lang="python">
password_file = "secretsfile"
</source>
to your <code>user-config.py</code>, then add this line to <code>secretsfile</code>
<source lang="python">
("yourBot", "yourPassword")
</source>

I was not able to find this documented anywhere else (yet), so I'm not sure if this method can be used to supply passwords for more than one bot username on more than one wiki. This is '''not''' the same as the tip above, which seems to be for HTTP AUTH BASIC-protected wikis.

==== Possible issue with SVN pywikipedia, custom URL schemes, and/or MediaWiki in XAMPP ====
My particular difficulty with <code>login.py</code> (from SVN rev [http://svn.wikimedia.org/svnroot/pywikipedia/!svn/bc/9509/trunk/pywikipedia/ 9509], with Python 2.6.something and MW 1.17) is that it initially logs in just fine, but <code>login.py -test</code> immediately after says:

<pre>You are not logged in on <wiki>:<lang>.</pre>

when clearly I just did. There is nothing unusual in the output of <code>python login.py -v -v</code>. Yet none of the other bot scripts are able to use the credentials which should have been cached by <code>login.py</code>. Since I'm using it with non-Wikimedia wiki, using a custom (short) URL scheme, with the wiki running on Windows (XAMPP), and with all those strikes against it, I'm not about to call this a bug. But <code>login.py</code> certainly isn't remembering the login cookie as advertised. Annoying, because I was trying to loop through a thousand plus images with <code>upload.py</code> and being asked a password for each one. The workaround above ''works''.

=== 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 [[mw:Extension:Special page to work with the interwiki table|Special:Interwiki]] and [[mw:Extension:Simple namespaces|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 [[:mw:Manual:Short URL|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 :
<source lang="python">
def isPublic(self):
return False
</source>

Fixing '''Permission Denied''' problems
<pre>
Creating page [[Category:Help]] via API
Unknown Error. API Error code:permissiondenied
Information:Permission denied
</pre>
Your wiki may require users to be part of a particular group in order to edit pages. If so, login to your wiki as an administrator and use [[Special:UserRights]] to put your bot into the proper group(s) to avoid API permission problems.

=== 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:
<source lang="python">
authenticate['en.wikipedia.org'] = ('John','XXXXX') # where John is your login name, and XXXXX your password.
</source>


[[Category:Pywikipedia]]

==See also==
*[[Using the python wikipediabot]]

==References==

<references/>

Latest revision as of 12:11, 5 February 2014