Prianka has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/201582

Change subject: Added cross-wiki Special:Import support in core.
......................................................................

Added cross-wiki Special:Import support in core.

Added pageimport feature in pywikibot-core/pywikibot/page.py so that it
may be directly used by core scripts transferbot.py / replicate_wiki.py.
Please guide me how the expected implementation may be done.

Bug:T66877
Change-Id: I2d65154c5f3c37257b9d720e7681645d48d59da4
---
M pywikibot/page.py
1 file changed, 65 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/82/201582/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 5607ace..69d5b0d 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3345,6 +3345,71 @@
         self.editEntity(data, **kwargs)
 
 
+class Importer(pywikibot.Page):
+
+    def __init__(self, site):
+        self.importsite = site
+        pywikibot.Page.__init__(self, site, 'Special:Import', None, 0)
+
+    def Import(self, target, project='w', crono='1', namespace='', 
prompt=True):
+        """Import the page from the wiki. Requires administrator status.
+        If prompt is True, asks the user if he wants to delete the page.
+
+        """
+        if project == 'w':
+            site = pywikibot.Site(fam='wikipedia')
+        elif project == 'b':
+            site = pywikibot.Site(fam='wikibooks')
+        elif project == 'wikt':
+            site = pywikibot.Site(fam='wiktionary')
+        elif project == 's':
+            site = pywikibot.Site(fam='wikisource')
+        elif project == 'q':
+            site = pywikibot.Site(fam='wikiquote')
+        else:
+            site = pywikibot.Site()
+        # Fixing the crono value...
+        if crono:
+            crono = '1'
+        else:
+            crono = '0'
+        # Fixing namespace's value.
+        if namespace == '0':
+            namespace == ''
+        answer = 'y'
+        if prompt:
+            answer = pywikibot.input_yn(u'Do you want to import %s?', 
default=False, automatic_quit=False)
+        if answer:
+            host = self.site.hostname()
+            address = self.site().path() + '?title=%s&action=submit' % 
self.urlname()
+            # You need to be a sysop for the import.
+            pywikibot.login.LoginManager(sysop=True, site=self.site())
+            # Getting the token.
+            token = self.site.tokens
+            # Defing the predata.
+            predata = {
+                'action': 'submit',
+                'source': 'interwiki',
+                # from what project do you want to import the page?
+                'interwiki': project,
+                # What is the page that you want to import?
+                'frompage': target,
+                # The entire history... or not?
+                'interwikiHistory': crono,
+                # What namespace do you want?
+                'namespace': '',
+            }
+            data = self.site.getUrl(address, data=predata, sysop=True)
+            if data:
+                pywikibot.output(u'Page imported, checking...')
+                if pywikibot.Page(self.importsite, target).exists():
+                    pywikibot.output(u'Import success!')
+                    return True
+                else:
+                    pywikibot.output(u'Import failed!')
+                    return False
+
+
 class ItemPage(WikibasePage):
 
     """Wikibase entity of type 'item'.

-- 
To view, visit https://gerrit.wikimedia.org/r/201582
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2d65154c5f3c37257b9d720e7681645d48d59da4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Prianka <priyankajayaswal...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to