def _wikipedia_Page_isRedirectPage(self): """ Returns whether the page is a redirect """ ret = toolserver.query(""" SELECT page_is_redirect FROM %s.page WHERE page_title=%%s AND page_namespace=%%s """ % (self.site().dbName()) , (self.titleWithoutNamespace(True), self.namespace()) ) return (len(ret) != 0 and ret[0]['page_is_redirect'] != 0)
def _wikipedia_Page_isRedirectPage(self): """ Returns whether the page is a redirect """ ret = toolserver.query( """ SELECT page_is_redirect FROM %s.page WHERE page_title=%%s AND page_namespace=%%s """ % (self.site().dbName()), (self.titleWithoutNamespace(True), self.namespace())) return (len(ret) != 0 and ret[0]['page_is_redirect'] != 0)
def _wikipedia_Page_isEmpty(self): """ True if the page has less than 4 characters, except for language links and category links, False otherwise. Categories from templates are counted! Can raise wikipedia.NoPage """ # retrieve page id and page length ret = toolserver.query("""SELECT page_id, page_len FROM %s.page WHERE page_title=%%s AND page_namespace=%%s""" % self.site().dbName() , (self.titleWithoutNamespace(True), self.namespace()) ) if (len(ret) == 0): raise wikipedia.NoPage('No such page %%s' % self.__repr__()) page_id = ret[0]['page_id'] length = ret[0]['page_len'] # remove length of langlink links ret = toolserver.query(""" SELECT COALESCE(SUM(LENGTH(ll_lang) + LENGTH(ll_title) + 5), 0) AS SUM FROM %s.langlinks WHERE ll_from=%%s GROUP BY ll_from """ % self.site().dbName() , page_id ) if (len(ret) > 0): length -= ret[0]['sum'] # remove length of category links ret = toolserver.query(""" SELECT COALESCE(SUM(LENGTH(cl_to) + LENGHT(cl_sortkey) + 5), 0) AS SUM FROM %s.categorylinks WHERE cl_from=%%s GROUP BY cl_from """ % self.site().dbName() , page_id ) if (len(ret) > 0): length -= ret[0]['sum'] return (length < 4)
def _wikipedia_Page_isEmpty(self): """ True if the page has less than 4 characters, except for language links and category links, False otherwise. Categories from templates are counted! Can raise wikipedia.NoPage """ # retrieve page id and page length ret = toolserver.query( """SELECT page_id, page_len FROM %s.page WHERE page_title=%%s AND page_namespace=%%s""" % self.site().dbName(), (self.titleWithoutNamespace(True), self.namespace())) if (len(ret) == 0): raise wikipedia.NoPage('No such page %%s' % self.__repr__()) page_id = ret[0]['page_id'] length = ret[0]['page_len'] # remove length of langlink links ret = toolserver.query( """ SELECT COALESCE(SUM(LENGTH(ll_lang) + LENGTH(ll_title) + 5), 0) AS SUM FROM %s.langlinks WHERE ll_from=%%s GROUP BY ll_from """ % self.site().dbName(), page_id) if (len(ret) > 0): length -= ret[0]['sum'] # remove length of category links ret = toolserver.query( """ SELECT COALESCE(SUM(LENGTH(cl_to) + LENGHT(cl_sortkey) + 5), 0) AS SUM FROM %s.categorylinks WHERE cl_from=%%s GROUP BY cl_from """ % self.site().dbName(), page_id) if (len(ret) > 0): length -= ret[0]['sum'] return (length < 4)
def _wikipedia_Page_latestRevision(self): """ Gets the latest revision from the database """ if not self._permalink: ret = toolserver.query(""" SELECT page_latest FROM %s.page WHERE page_title=%%s AND page_namespace=%%s """ % (self.site().dbName()) , (self.titleWithoutNamespace(True), self.namespace()) ) if (len(ret) == 0): raise wikipedia.NoPage('No revisions found for page %%s' % self.__repr__()) else: self._permalink = u'%i\n ' % ret[0]['page_latest'] return int(self._permalink)
def _wikipedia_Page_latestRevision(self): """ Gets the latest revision from the database """ if not self._permalink: ret = toolserver.query( """ SELECT page_latest FROM %s.page WHERE page_title=%%s AND page_namespace=%%s """ % (self.site().dbName()), (self.titleWithoutNamespace(True), self.namespace())) if (len(ret) == 0): raise wikipedia.NoPage('No revisions found for page %%s' % self.__repr__()) else: self._permalink = u'%i\n ' % ret[0]['page_latest'] return int(self._permalink)