64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright(C) 2011 Clément Schreiner
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, version 3 of the License.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
from __future__ import with_statement
|
|
|
|
from weboob.tools.backend import BaseBackend
|
|
from weboob.capabilities.content import ICapContent, Content
|
|
from weboob.tools.value import ValuesDict, Value
|
|
|
|
|
|
from .browser import MediawikiBrowser
|
|
|
|
|
|
__all__ = ['MediawikiBackend']
|
|
|
|
class MediawikiBackend(BaseBackend, ICapContent):
|
|
NAME = 'mediawiki'
|
|
MAINTAINER = u'Clément Schreiner'
|
|
EMAIL = 'clemux@clemux.info'
|
|
VERSION = '0.7'
|
|
LICENSE = 'GPLv3'
|
|
DESCRIPTION = 'Mediawiki wiki software application'
|
|
CONFIG = ValuesDict(Value('url', label='URL of the Mediawiki website', default='http://en.wikipedia.org/'),
|
|
Value('apiurl', label='URL of the Mediawiki website\'s API', default='http://en.wikipedia.org/w/api.php'),
|
|
Value('username', label='Login', default=''),
|
|
Value('password', label='Password', default='', masked=True))
|
|
|
|
BROWSER = MediawikiBrowser
|
|
def create_default_browser(self):
|
|
return self.create_browser(self.config['url'], self.config['apiurl'], self.config['username'], self.config['password'])
|
|
|
|
def get_content(self, _id):
|
|
_id = _id.replace(' ', '_').encode('utf-8')
|
|
content = Content(_id)
|
|
page = _id
|
|
with self.browser:
|
|
data = self.browser.get_wiki_source(page)
|
|
|
|
content.content = data
|
|
return content
|
|
|
|
def iter_revisions(self, _id, max_results=10):
|
|
for rev in self.browser.iter_wiki_revisions(_id, max_results):
|
|
yield rev
|
|
|
|
def push_content(self, content, message=None, minor=False):
|
|
self.browser.set_wiki_source(content, message, minor)
|
|
|
|
def get_content_preview(self, content):
|
|
return self.browser.get_wiki_preview(content)
|