User:Thegeneralbot/brokenlinkcode

From The Urban Dead Wiki
Jump to navigationJump to search
      generator = pagegenerators.LinkedPageGenerator(self.pagelink)
      for page in generator:
          try:
            links = page.get()
          except wikipedia.NoPage:
            #match pages in [[link|link]] format
            m = re.match(ur'\[\[\w+\|\w+\]\]', oldcontent)
            if m:
              value = m.group()
              txt = re.split('([\[\|\]]+)', value)
              newvalue = value 
              if txt[1]=='[[' and txt[3] == '|' and txt[5] == ']]':
                txt[2].replace('\s+', '_',)
                txt2 = array.array('u',txt[2])
                txt4 = array.array('u',txt[4])
                txt2addr, txt2len = txt2.buffer_info()
                txt4addr, txt4len = txt4.buffer_info()
                match = 0
                while match < txt2len:
                  match += 1
                  if match == txt2len:
                    newvalue = u'{{DelEx|' + txt2.tounicode() + u'|' + txt4.tounicode() + u'}}'
                    newvalue = txt[0] + newvalue + txt[6]
                print "replacing piped|redlink with:", newvalue
                newcontent = re.sub(ur'\[\[\w+\|\w+\]\]',newvalue,oldcontent)
              continue
            #match pages in [[link]] format
            msingle = re.match(ur'\[\[\w+\]\]', oldcontent)
            if msingle:
              value = msingle.group()
              txt = re.split('([\[\]]+)', value)
              newvalue = value 
              if txt[1]=='[[' and txt[3] == ']]':
                  txt4 = array.array('u',txt[2])
                  txt[2].replace('\s+', '_',)
                  txt2 = array.array('u',txt[2])
                  txt2addr, txt2len = txt2.buffer_info()
                  txt4addr, txt4len = txt4.buffer_info()
                  match = 0
                  while match < txt2len:
                      match += 1
                      if match == txt2len:
                              newvalue = u'{{DelEx|' + txt2.tounicode() + u'|' + txt4.tounicode() + u'}}'
                              newvalue = txt[0] + newvalue + txt[4]
                  print "replacing piped|redlink with:", newvalue
                  newcontent = re.sub(ur'\[\[\w+\]\]',newvalue,oldcontent)
              continue
            #is *supposed* to match makes in format [[a link]]
            mspace = re.match(ur'\[\[\w+\s+\w+\]\]', oldcontent)
            if mspace:
              value = mspace.group()
              txt = re.split('([\[\]]+)', value)
              newvalue = value 
              if txt[1]=='[[' and txt[3] == ']]':
                  txt4 = array.array('u',txt[2])
                  txt[2].replace('\s+', '_',)
                  txt2 = array.array('u',txt[2])
                  txt2addr, txt2len = txt2.buffer_info()
                  txt4addr, txt4len = txt4.buffer_info()
                  match = 0
                  while match < txt2len:
                      match += 1
                      if match == txt2len:
                              newvalue = u'{{DelEx|' + txt2.tounicode() + u'|' + txt4.tounicode() + u'}}'
                              newvalue = txt[0] + newvalue + txt[4]
                  print "replacing piped|redlink with:", newvalue
                  newcontent = re.sub(ur'\[\[\w+\s+\w+\]\]',newvalue,oldcontent)
              continue
            #s *supposed* to match pages in form [[a link|a link]]
            mspace = re.match(ur'\[\[\w+\s+\|\w+\s+\]\]', oldcontent)
            if mspace:
              value = mspace.group()
              txt = re.split('([\[\]]+)', value)
              newvalue = value 
              if txt[1]=='[[' and txt[3] == ']]':
                  txt4 = array.array('u',txt[2])
                  txt[2].replace('\s+', '_',)
                  txt2 = array.array('u',txt[2])
                  txt2addr, txt2len = txt2.buffer_info()
                  txt4addr, txt4len = txt4.buffer_info()
                  match = 0
                  while match < txt2len:
                      match += 1
                      if match == txt2len:
                              newvalue = u'{{DelEx|' + txt2.tounicode() + u'|' + txt4.tounicode() + u'}}'
                              newvalue = txt[0] + newvalue + txt[4]
                  print "replacing piped|redlink with:", newvalue
                  newcontent = re.sub(ur'\[\[\w+\s+\|\w+\s+\]\]',newvalue,oldcontent)
              continue