示例#1
0
 def run(self):
     hints, removeHints = self.warnfileReader.getHints()
     k = hints.keys()
     k.sort()
     print "Fixing... %i pages" % len(k)
     for page in k:
         old = {}
         try:
             for page2 in page.interwiki():
                 old[page2.site()] = page2
         except wikipedia.IsRedirectPage:
             wikipedia.output(u"%s is a redirect page; not changing" %
                              page.aslink())
             continue
         except wikipedia.NoPage:
             wikipedia.output(u"Page %s not found; skipping" %
                              page.aslink())
             continue
         new = {}
         new.update(old)
         if page in hints:
             for page2 in hints[page]:
                 site = page2.site()
                 new[site] = page2
         if page in removeHints:
             for page2 in removeHints[page]:
                 site = page2.site()
                 try:
                     del new[site]
                 except KeyError:
                     pass
         mods, adding, removing, modifying = interwiki.compareLanguages(
             old, new, insite=page.site())
         if mods:
             wikipedia.output(page.aslink() + mods)
             oldtext = page.get()
             newtext = wikipedia.replaceLanguageLinks(oldtext, new)
             if 1:
                 wikipedia.showDiff(oldtext, newtext)
                 try:
                     status, reason, data = page.put(newtext,
                                                     comment='warnfile ' +
                                                     mods)
                 except wikipedia.LockedPage:
                     wikipedia.output(u"Page is locked. Skipping.")
                     continue
                 except wikipedia.SpamfilterError, e:
                     wikipedia.output(
                         u'Cannot change %s because of blacklist entry %s' %
                         (page.title(), e.url))
                     continue
                 except wikipedia.Error:
                     wikipedia.output(u"Error while saving page.")
                     continue
                 if str(status) != '302':
                     print status, reason
示例#2
0
 def run(self):
     hints, removeHints = self.warnfileReader.getHints()
     k=hints.keys()
     k.sort()
     print "Fixing... %i pages" % len(k)
     for page in k:
         old={}
         try:
             for page2 in page.interwiki():
                 old[page2.site()] = page2
         except pywikibot.IsRedirectPage:
             pywikibot.output(u"%s is a redirect page; not changing"
                              % page.title(asLink=True))
             continue
         except pywikibot.NoPage:
             pywikibot.output(u"Page %s not found; skipping"
                              % page.title(asLink=True))
             continue
         new={}
         new.update(old)
         if page in hints:
             for page2 in hints[page]:
                 site = page2.site()
                 new[site] = page2
         if page in removeHints:
             for page2 in removeHints[page]:
                 site = page2.site()
                 try:
                     del new[site]
                 except KeyError:
                     pass
         mods, adding, removing, modifying = interwiki.compareLanguages(old,
                                                                        new,
                                                                        insite=page.site())
         if mods:
             pywikibot.output(page.title(asLink=True) + mods)
             oldtext = page.get()
             newtext = pywikibot.replaceLanguageLinks(oldtext, new)
             if 1:
                 pywikibot.showDiff(oldtext, newtext)
                 try:
                     status, reason, data = page.put(newtext,
                                                     comment='warnfile '+mods)
                 except pywikibot.LockedPage:
                     pywikibot.output(u"Page is locked. Skipping.")
                     continue
                 except pywikibot.SpamfilterError, e:
                     pywikibot.output(
                         u'Cannot change %s because of blacklist entry %s'
                         % (page.title(), e.url))
                     continue
                 except pywikibot.Error:
                     pywikibot.output(u"Error while saving page.")
                     continue
                 if str(status) != '302':
                     print status, reason
示例#3
0
    def run(self):
        hints, removeHints = self.warnfileReader.getHints()
        k = hints.keys()
        k.sort()
        print "Fixing... %i pages" % len(k)
        for page in k:
            old = {}
            try:
                for page2 in page.interwiki():
                    old[page2.site()] = page2
            except pywikibot.IsRedirectPage:
                pywikibot.output(u"%s is a redirect page; not changing" %
                                 page.title(asLink=True))
                continue
            except pywikibot.NoPage:
                pywikibot.output(u"Page %s not found; skipping" %
                                 page.title(asLink=True))
                continue
            new = {}
            new.update(old)
            if page in hints:
                for page2 in hints[page]:
                    site = page2.site()
                    new[site] = page2
            if page in removeHints:
                for page2 in removeHints[page]:
                    site = page2.site()
                    try:
                        del new[site]
                    except KeyError:
                        pass
            mods, mcomment, adding, removing, modifying = interwiki.compareLanguages(
                old, new, insite=page.site())
            if mods:
                pywikibot.output(page.title(asLink=True) + mods)
                oldtext = page.get()
                newtext = pywikibot.replaceLanguageLinks(oldtext, new)

                pywikibot.showDiff(oldtext, newtext)
                try:
                    #TODO: special warnfile comment needed like in previous releases?
                    status, reason, data = page.put(newtext, comment=mcomment)
                except pywikibot.LockedPage:
                    pywikibot.output(u"Page is locked. Skipping.")
                    continue
                except pywikibot.SpamfilterError, e:
                    pywikibot.output(
                        u'Cannot change %s because of blacklist entry %s' %
                        (page.title(), e.url))
                    continue
                if str(status) != '302':
                    print status, reason