Example #1
0
    def demote(self,
               title=False,
               dropchilds=False,
               force=False,
               reason=False,
               watch=False,
               unwatch=False):
        ''' Demote a category to a page

		newtitle - title of the page
		force - in case the page already exists, delete it
		'''
        if not self.exists:
            raise page.NoPage
        if title and title.startswith("Category:"):
            raise NotNonCategoryTitle
        if self.getAllMembers() and not dropchilds:
            raise NonEmptyCategory
        if not title:
            title = self.title.split("Category:")[1]
        page = page2.Page2(self.site, title=title)
        if page.exists and not force:
            raise page2.AlreadyExists
        page.edit(text=self.getWikiText())
        self.rewriteReferences(
            self.getBacklinks() + self.getAllMembers(titleonly=True), title)
        self.delete(reason=reason, watch=watch, unwatch=unwatch)
Example #2
0
	def demote(self, title=False, dropchilds=False, force=False, reason=False, watch=False, unwatch=False):
		''' Demote a category to a page

		newtitle - title of the page
		force - in case the page already exists, delete it
		'''
		if not self.exists:
			raise page.NoPage
		if title and title.startswith("Category:"):
			raise NotNonCategoryTitle		
		if self.getAllMembers() and not dropchilds:
			raise NonEmptyCategory
		if not title:
			title = self.title.split("Category:")[1]
		page = page2.Page2(self.site, title=title)
		if page.exists and not force:
			raise page2.AlreadyExists
		page.edit(text=self.getWikiText())	
		self.rewriteReferences(self.getBacklinks() + self.getAllMembers(titleonly=True), title)
		self.delete(reason=reason, watch=watch, unwatch=unwatch)
Example #3
0
#!/usr/bin/python 
# -*- coding: utf8 -*-
from wikitools import wiki                                                                                                                                                          
from wikitools import api                                                                                                                                                           
from wikitools import page
from wikitools import wikifile
# create a Wiki object                                                                                                                                                              
site = wiki.Wiki("http://mediawiki.loc/api.php")                                                                                                                                

site.login('Wikiadmin', 'gfhjkm', True)

page = page.Page(site=site, title='Test page')
page.edit(newtext='new text [[Категория:Лайя йога]] [[Категория:%s]]'%('книга тайны'));

file = wikifile.File(wiki=site, title='new file.pdf')
print file.upload(fileobj=open('pdf/t.pdf'), ignorewarnings=True, watch=True )

# define the params for the query                                                                                                                                                   
params = {'action':'query', 'titles':'Test page' }
# create the request object                                                                                                                                                         
request = api.APIRequest(site, params)                                                                                                                                              
# query the API                                                                                                                                                                     
result = request.query()  

print result
site = wiki.Wiki("https://wiki.london.hackspace.org.uk/w/api.php") 
# login - required for read-restricted wikis
login = site.login("biobot", pw)


#lbl01001 lbl02001 lbl03001 lbl04001 lbl04002 lbl04003 lbl04004 lbl04005 lbl04006 lbl04007 lbl04008 lbl05001 lbl06001 lbl07001 lbl07002 lbl07003 lbl07004 lbl07005 lbl08001 lbl08002 lbl08003
for content in ['lbl08001']:

  #this is the content, should have already been generated by Makefile
  pagetext = open("mwiki/"+content.lower()+".wiki").read()

  #get page from api.php
  page = page.Page(site, content.upper())

  # try an edit, this will fail with captcha
  myedit = page.edit(text=pagetext, bot=1, summary='Sync from github', answer="Hackney Road")

  print(repr(myedit))

  # this is the edit session token
  print(page.getToken('edit'))

  if myedit['edit']['result'] == 'Failure':
    id=myedit['edit']['captcha']['id']
    
    # provide the captcha text as query param "answer"
    params = {'action':'edit', 'title':content.upper(),'bot':1,'id':id,'answer':"Hackney Road",'text':pagetext,'token':page.getToken('edit')}
    request = api.APIRequest(site, params)
    # query the API
    result = request.query()
    print(result)
Example #5
0
site = wiki.Wiki("https://wiki.london.hackspace.org.uk/w/api.php")
# login - required for read-restricted wikis
login = site.login("biobot", pw)

#lbl01001 lbl02001 lbl03001 lbl04001 lbl04002 lbl04003 lbl04004 lbl04005 lbl04006 lbl04007 lbl04008 lbl05001 lbl06001 lbl07001 lbl07002 lbl07003 lbl07004 lbl07005 lbl08001 lbl08002 lbl08003
for content in ['lbl08001']:

    #this is the content, should have already been generated by Makefile
    pagetext = open("mwiki/" + content.lower() + ".wiki").read()

    #get page from api.php
    page = page.Page(site, content.upper())

    # try an edit, this will fail with captcha
    myedit = page.edit(text=pagetext,
                       bot=1,
                       summary='Sync from github',
                       answer="Hackney Road")

    print(repr(myedit))

    # this is the edit session token
    print(page.getToken('edit'))

    if myedit['edit']['result'] == 'Failure':
        id = myedit['edit']['captcha']['id']

        # provide the captcha text as query param "answer"
        params = {
            'action': 'edit',
            'title': content.upper(),
            'bot': 1,