Exemple #1
0
    def add_points(self, rev, points, ptype, txt, pmax, include_zero=False):

        ab = rev.article().get_points(ptype)
        ab_raw = rev.article().get_points(ptype, ignore_max=True)
        pts = 0.0

        if pmax > 0.0 and self.iszero(ab - pmax):
            # we have reached max
            if points < 0.0 and ab_raw + points < pmax:
                pts = pmax - ab_raw - points
            rev.points.append([pts, ptype, txt, points])

        elif pmax > 0.0 and ab + points > pmax:
            # reaching max
            pts = pmax - ab
            rev.points.append([pts, ptype, txt + ' &gt; ' + _('max'), points])

        #elif not self.iszero(revpoints):
        else:
            if self.iszero(points) and not include_zero:
                return False
            pts = points
            rev.points.append([points, ptype, txt, points])
        if pts > 0.0:
            return True
Exemple #2
0
    def filter(self, articles):

        out = odict()
        for article_key, article in articles.iteritems():

            firstrevid = article.revisions.firstkey()
            firstrev = article.revisions[firstrevid]

            try:

                #if article.new == False and article.redirect == False:

                # Check if first revision is a stub
                t = self.has_template(firstrev.parenttext)
                if t:
                    logger.debug('Found template {{%s}} in [[%s]] @ %d',
                                 t, article_key, firstrevid)
                    out[article_key] = article

            except DanmicholoParseError as e:
                logger.warning(" >> DanmicholoParser failed to parse %s", article_key)
                parentid = firstrev.parentid
                args = {'article': article_key, 'prevrev': firstrev.parentid, 'rev': lastrev.revid, 'error': e.msg}
                article.site().errors.append(_('Could not analyze the article %(article)s because one of the revisions %(prevrev)d or %(rev)d could not be parsed: %(error)s') % args)

        logger.info(" - TemplateFilter: Articles reduced from %d to %d", len(articles), len(out))

        return out
Exemple #3
0
    def test(self, rev):

        words = rev.words
        revpoints = words * self.points
        if revpoints > 0.:
            self.add_points(rev, revpoints, 'word',
                            _('%(words).f words') % {'words': words},
                            self.maxpoints)
Exemple #4
0
    def test(self, rev):

        nlinks = self.get_linkcount(rev.text)
        nlinks_p = self.get_linkcount(rev.parenttext)
        links = nlinks - nlinks_p

        if links > 0:
            revpoints = links * self.points
            self.add_points(rev, revpoints, 'link', _('links') % {'links': links}, self.maxpoints)
Exemple #5
0
    def test(self, rev):

        r1 = self.has_ref_section(rev.parenttext)
        r2 = self.has_ref_section(rev.text)

        if not r1 and r2:
            if self.add_points(rev, self.points, 'refsection',
                               _('added reference section'),
                               self.maxpoints):
                self.totalrefsectionsadded += 1
Exemple #6
0
 def test(self, rev):
     if rev.redirect or rev.parentredirect:
         # skip redirects
         return
     pt = self.templatecount(rev.te_parenttext())
     ct = self.templatecount(rev.te_text())
     if ct < pt:
         rev.points.append([(pt - ct) * self.points, 'templateremoval',
                           _('removal of {{tl|%(template)s}}') % {'template': self.template}])
         self.total += (pt - ct)
Exemple #7
0
    def test(self, rev):
        abytes = 0
        thisrev = False
        passedlimit = False
        for r in rev.article().revisions.itervalues():
            if r.bytes > 0:
                abytes += r.bytes
            if passedlimit is False and abytes >= self.limit:
                passedlimit = True
                if r == rev:
                    thisrev = True

        if abytes >= self.limit and thisrev is True:
            rev.points.append([self.points, 'bytebonus', _('bonus %(bytes).f bytes') % {'bytes': self.limit}])
Exemple #8
0
    def test(self, rev):

        s1, r1 = self.get_sourcecount(rev.parenttext)
        s2, r2 = self.get_sourcecount(rev.text)

        #print rev.article().name,len(allref1), len(allref2)

        sources_added = s2 - s1
        refs_added = r2 - r1

        self.totalsources += sources_added

        if sources_added > 0 or refs_added > 0:
            p = 0.
            s = []
            if sources_added > 0:
                p += sources_added * self.sourcepoints
                s.append(_('references') % {'num': sources_added})
            if refs_added > 0:
                p += refs_added * self.refpoints
                s.append(_('reference pointers') % {'num': refs_added})
            txt = ', '.join(s)

            rev.points.append([p, 'ref', txt])
Exemple #9
0
    def filter(self, articles, debug=False):

        cats, parents = self.fetchcats(articles, debug=debug)

        out = odict()

        # loop over articles
        for article_key, article_cats in cats.iteritems():
            #if debug:
            #    print
            article = articles[article_key]
            lang = article_key.split(':')[0]
            if debug:
                logger.debug("CatFilter: %s", article.name)
                for l, ca in enumerate(article_cats):
                    logger.debug('CatFilter [%d] %s', l, ', '.join(ca))

            #print
            #print article_key
            #print article_cats
            #print
            catname = self.check_article_cats(article_cats)
            if catname:

                # Add category path to the article object, so we can check how the article matched
                article.cat_path = [catname]
                # print '[%s]' % (article_key)
                try:
                    i = 0
                    aname = article.site().key + ':' + article.name
                    while not catname == aname:
                        # print ' [%d] %s' % (i,catname)
                        if not parents[article_key][catname] == aname:
                            article.cat_path.append(parents[article_key][catname])
                        catname = parents[article_key][catname]
                        i += 1
                        if i > 50:
                            raise CategoryLoopError(article.cat_path)
                except CategoryLoopError as e:
                    article.errors.append(_('Encountered an infinite category loop: ')
                        + ' → '.join(['[[:%(catname)s|]]'
                        % {'catname': c} for c in e.catpath]))

                out[article_key] = article

        logger.info(" - CatFilter: Articles reduced from %d to %d", len(articles), len(out))
        return out
Exemple #10
0
    def test(self, rev):

        # First check all revisions
        awords = 0
        thisrev = False
        passedlimit = False
        for r in rev.article().revisions.itervalues():
            if r.words > 0:
                awords += r.words

            if passedlimit is False and awords >= self.limit:
                passedlimit = True
                if r == rev:
                    thisrev = True

        if awords >= self.limit and thisrev is True:
            rev.points.append([self.points, 'wordbonus',
                              _('bonus %(words)d words') % {'words': self.limit}])
Exemple #11
0
 def test(self, rev):
     if rev.new and rev.redirect:
         rev.points.append([self.points, 'redirect', _('redirect')])
Exemple #12
0
    def test(self, rev):
        if rev.new and not rev.redirect:
            rev.points.append([self.points, 'newpage', _('new page')])

        if rev.parentredirect and not rev.redirect:
            rev.points.append([self.points, 'newpage', _('new page')])
Exemple #13
0
    def test(self, rev):
        imgs0 = self.get_images(rev.parenttext)
        imgs1 = self.get_images(rev.text)
        imgs_added = set(imgs1).difference(set(imgs0))


        #own_imgs_added = []
        #others_imgs_added = []
        counters = {'ownwork': [], 'own': [], 'other': []}
        for filename in imgs_added:
            filename = urllib.unquote(filename)
            image = rev.article().site().images[filename]
            imageinfo = image.imageinfo
            if len(imageinfo) > 0:   # seems like image.exists only checks locally
                try:
                    uploader = imageinfo['user']
                except KeyError:
                    logger.error("Could not locate user for file '%s' in rev. %s ",
                                 filename, rev.revid)
                    continue

                logger.debug("File '%s' uploaded by '%s', revision made by '%s'",
                            filename, uploader, rev.username)
                if uploader == rev.username:
                    credit = ''
                    extrainfo = rev.article().site().api('query', prop='imageinfo', titles=u'File:{}'.format(filename), iiprop='extmetadata')
                    try:
                        for pageid, page  in extrainfo['query']['pages'].items():
                            credit = page['imageinfo'][0]['extmetadata']['Credit']['value']
                    except KeyError:
                        logger.debug("Could not read credit info for file '%s'", filename)

                    if 'int-own-work' in credit or 'Itse otettu valokuva' in credit:
                        logger.debug("File '%s' identified as own work.", filename)
                        counters['ownwork'].append(filename)
                    else:
                        logger.debug("File '%s' identified as own upload, but not own work.", filename)
                        counters['own'].append(filename)
                else:
                    logger.debug("File '%s' not identified as own upload or own work.", filename)
                    counters['other'].append(filename)
            else:
                logger.warning("File '%s' does not exist", filename)


        # If maxinitialcount is 0, only the first image counts.
        # If an user adds both an own image and an image by someone else,
        # we should make sure to credit the own image, not the other.
        # We therefore process the own images first.
        # imgs_added = own_imgs_added + others_imgs_added
        total_added = len(counters['own']) + len(counters['ownwork']) + len(counters['other'])
        self.totalimages += total_added
        revpoints = 0
        for n, img in enumerate(imgs_added):
            if len(imgs0) + n <= self.maxinitialcount:
                if img in counters['ownwork']:
                    revpoints += self.ownwork
                elif img in counters['own']:
                    revpoints += self.own
                else:
                    revpoints += self.points

        if revpoints > 0:
            self.add_points(rev, revpoints, 'image', _('images') % {'images': len(imgs_added)}, self.maxpoints)
Exemple #14
0
 def test(self, rev):
     revpoints = rev.bytes * self.points
     if revpoints > 0.:
         self.add_points(rev, revpoints, 'byte',
                         _('%(bytes).f bytes') % {'bytes': rev.bytes},
                         self.maxpoints, include_zero=True)
Exemple #15
0
 def test(self, rev):
     rev.points.append([self.points, 'contrib', _('contribution')])
Exemple #16
0
 def test(self, rev):
     if self.iszero(rev.article().get_points('quali')):
         rev.points.append([self.points, 'quali', _('qualified')])