| @@ -117,6 +117,8 @@ Create :py:class:`earwigbot.wiki.Page <earwigbot.wiki.page.Page>` objects with | |||||
| :py:meth:`user.get_talkpage() <earwigbot.wiki.user.User.get_talkpage>`. They | :py:meth:`user.get_talkpage() <earwigbot.wiki.user.User.get_talkpage>`. They | ||||
| provide the following attributes: | provide the following attributes: | ||||
| - :py:attr:`~earwigbot.wiki.page.Page.site`: the page's corresponding | |||||
| :py:class:`~earwigbot.wiki.site.Site` object | |||||
| - :py:attr:`~earwigbot.wiki.page.Page.title`: the page's title, or pagename | - :py:attr:`~earwigbot.wiki.page.Page.title`: the page's title, or pagename | ||||
| - :py:attr:`~earwigbot.wiki.page.Page.exists`: whether the page exists | - :py:attr:`~earwigbot.wiki.page.Page.exists`: whether the page exists | ||||
| - :py:attr:`~earwigbot.wiki.page.Page.pageid`: an integer ID representing the | - :py:attr:`~earwigbot.wiki.page.Page.pageid`: an integer ID representing the | ||||
| @@ -70,16 +70,16 @@ class Command(BaseCommand): | |||||
| def get_page(self, title): | def get_page(self, title): | ||||
| page = self.site.get_page(title, follow_redirects=False) | page = self.site.get_page(title, follow_redirects=False) | ||||
| if page.exists()[0]: | |||||
| if page.exists[0]: | |||||
| return page | return page | ||||
| def report(self, page): | def report(self, page): | ||||
| url = page.url().replace("en.wikipedia.org/wiki", "enwp.org") | |||||
| short = self.statistics.get_short_title(page.title()) | |||||
| url = page.url.replace("en.wikipedia.org/wiki", "enwp.org") | |||||
| short = self.statistics.get_short_title(page.title) | |||||
| status = self.get_status(page) | status = self.get_status(page) | ||||
| user = self.site.get_user(page.creator()) | user = self.site.get_user(page.creator()) | ||||
| user_name = user.name() | user_name = user.name() | ||||
| user_url = user.get_talkpage().url() | |||||
| user_url = user.get_talkpage().url | |||||
| msg1 = "AfC submission report for \x0302{0}\x0301 ({1}):" | msg1 = "AfC submission report for \x0302{0}\x0301 ({1}):" | ||||
| msg2 = "Status: \x0303{0}\x0301" | msg2 = "Status: \x0303{0}\x0301" | ||||
| @@ -92,9 +92,9 @@ class Command(BaseCommand): | |||||
| self.say(self.data.chan, msg3.format(user_name, user_url)) | self.say(self.data.chan, msg3.format(user_name, user_url)) | ||||
| def get_status(self, page): | def get_status(self, page): | ||||
| if page.is_redirect(): | |||||
| if page.is_redirect: | |||||
| target = page.get_redirect_target() | target = page.get_redirect_target() | ||||
| if self.site.get_page(target).namespace() == wiki.NS_MAIN: | |||||
| if self.site.get_page(target).namespace == wiki.NS_MAIN: | |||||
| return "accepted" | return "accepted" | ||||
| return "redirect" | return "redirect" | ||||
| @@ -70,13 +70,13 @@ class Task(BaseTask): | |||||
| def process(self, page): | def process(self, page): | ||||
| """Detect copyvios in 'page' and add a note if any are found.""" | """Detect copyvios in 'page' and add a note if any are found.""" | ||||
| title = page.title() | |||||
| title = page.title | |||||
| if title in self.ignore_list: | if title in self.ignore_list: | ||||
| msg = "Skipping page in ignore list: [[{0}]]" | msg = "Skipping page in ignore list: [[{0}]]" | ||||
| self.logger.info(msg.format(title)) | self.logger.info(msg.format(title)) | ||||
| return | return | ||||
| pageid = page.pageid() | |||||
| pageid = page.pageid | |||||
| if self.has_been_processed(pageid): | if self.has_been_processed(pageid): | ||||
| msg = "Skipping check on already processed page [[{0}]]" | msg = "Skipping check on already processed page [[{0}]]" | ||||
| self.logger.info(msg.format(title)) | self.logger.info(msg.format(title)) | ||||
| @@ -143,7 +143,7 @@ class Task(BaseTask): | |||||
| This will only be called if "cache_results" == True in the task's | This will only be called if "cache_results" == True in the task's | ||||
| config, which is False by default. | config, which is False by default. | ||||
| """ | """ | ||||
| pageid = page.pageid() | |||||
| pageid = page.pageid | |||||
| hash = sha256(page.get()).hexdigest() | hash = sha256(page.get()).hexdigest() | ||||
| query1 = "SELECT 1 FROM cache WHERE cache_id = ?" | query1 = "SELECT 1 FROM cache WHERE cache_id = ?" | ||||
| query2 = "DELETE FROM cache WHERE cache_id = ?" | query2 = "DELETE FROM cache WHERE cache_id = ?" | ||||
| @@ -93,7 +93,7 @@ class Task(BaseTask): | |||||
| generator = self.backwards_cat_iterator() | generator = self.backwards_cat_iterator() | ||||
| for d in xrange(num_days): | for d in xrange(num_days): | ||||
| category = generator.next() | category = generator.next() | ||||
| date = category.title().split("/")[-1] | |||||
| date = category.title.split("/")[-1] | |||||
| self.update_date(date, category) | self.update_date(date, category) | ||||
| sleep(10) | sleep(10) | ||||
| self.logger.info("Update complete") | self.logger.info("Update complete") | ||||
| @@ -104,7 +104,7 @@ class Task(BaseTask): | |||||
| generator = self.backwards_cat_iterator() | generator = self.backwards_cat_iterator() | ||||
| for d in xrange(num_days): | for d in xrange(num_days): | ||||
| category = generator.next() | category = generator.next() | ||||
| date = category.title().split("/")[-1] | |||||
| date = category.title.split("/")[-1] | |||||
| data[date] = self.get_date_counts(date) | data[date] = self.get_date_counts(date) | ||||
| data = OrderedDict(reversed(data.items())) # Oldest to most recent | data = OrderedDict(reversed(data.items())) # Oldest to most recent | ||||
| @@ -123,7 +123,7 @@ class Task(BaseTask): | |||||
| current -= timedelta(1) # Subtract one day from date | current -= timedelta(1) # Subtract one day from date | ||||
| def update_date(self, date, category): | def update_date(self, date, category): | ||||
| msg = "Updating {0} ([[{1}]])".format(date, category.title()) | |||||
| msg = "Updating {0} ([[{1}]])".format(date, category.title) | |||||
| self.logger.debug(msg) | self.logger.debug(msg) | ||||
| q_select = "SELECT page_date, page_status FROM page WHERE page_id = ?" | q_select = "SELECT page_date, page_status FROM page WHERE page_id = ?" | ||||
| @@ -153,7 +153,7 @@ class Task(BaseTask): | |||||
| def get_status(self, title, pageid): | def get_status(self, title, pageid): | ||||
| page = self.site.get_page(title) | page = self.site.get_page(title) | ||||
| ns = page.namespace() | |||||
| ns = page.namespace | |||||
| if ns == wiki.NS_FILE_TALK: # Ignore accepted FFU requests | if ns == wiki.NS_FILE_TALK: # Ignore accepted FFU requests | ||||
| return self.STATUS_NONE | return self.STATUS_NONE | ||||
| @@ -161,7 +161,7 @@ class Task(BaseTask): | |||||
| if ns == wiki.NS_TALK: | if ns == wiki.NS_TALK: | ||||
| new_page = page.toggle_talk() | new_page = page.toggle_talk() | ||||
| sleep(2) | sleep(2) | ||||
| if new_page.is_redirect(): | |||||
| if new_page.is_redirect: | |||||
| return self.STATUS_NONE # Ignore accepted AFC/R requests | return self.STATUS_NONE # Ignore accepted AFC/R requests | ||||
| return self.STATUS_ACCEPT | return self.STATUS_ACCEPT | ||||
| @@ -129,7 +129,7 @@ class Task(BaseTask): | |||||
| "<!-- sig begin -->~~~ at ~~~~~<!-- sig end -->", | "<!-- sig begin -->~~~ at ~~~~~<!-- sig end -->", | ||||
| newtext) | newtext) | ||||
| page.edit(newtext, summary, minor=True, bot=True) | page.edit(newtext, summary, minor=True, bot=True) | ||||
| self.logger.info(u"Chart saved to [[{0}]]".format(page.title())) | |||||
| self.logger.info(u"Chart saved to [[{0}]]".format(page.title)) | |||||
| def compile_charts(self): | def compile_charts(self): | ||||
| """Compile and return all statistics information from our local db.""" | """Compile and return all statistics information from our local db.""" | ||||
| @@ -332,7 +332,7 @@ class Task(BaseTask): | |||||
| self.logger.error(msg) | self.logger.error(msg) | ||||
| return | return | ||||
| namespace = self.site.get_page(title).namespace() | |||||
| namespace = self.site.get_page(title).namespace | |||||
| status, chart = self.get_status_and_chart(content, namespace) | status, chart = self.get_status_and_chart(content, namespace) | ||||
| if chart == self.CHART_NONE: | if chart == self.CHART_NONE: | ||||
| msg = u"Could not find a status for [[{0}]]".format(title) | msg = u"Could not find a status for [[{0}]]".format(title) | ||||
| @@ -364,7 +364,7 @@ class Task(BaseTask): | |||||
| self.logger.error(msg) | self.logger.error(msg) | ||||
| return | return | ||||
| namespace = self.site.get_page(title).namespace() | |||||
| namespace = self.site.get_page(title).namespace | |||||
| status, chart = self.get_status_and_chart(content, namespace) | status, chart = self.get_status_and_chart(content, namespace) | ||||
| if chart == self.CHART_NONE: | if chart == self.CHART_NONE: | ||||
| self.untrack_page(cursor, pageid) | self.untrack_page(cursor, pageid) | ||||
| @@ -49,14 +49,14 @@ class Category(Page): | |||||
| def __str__(self): | def __str__(self): | ||||
| """Returns a nice string representation of the Category.""" | """Returns a nice string representation of the Category.""" | ||||
| return '<Category "{0}" of {1}>'.format(self.title(), str(self._site)) | |||||
| return '<Category "{0}" of {1}>'.format(self.title, str(self._site)) | |||||
| def _get_members_via_sql(self, limit): | def _get_members_via_sql(self, limit): | ||||
| """Return a list of tuples of (title, pageid) in the category.""" | """Return a list of tuples of (title, pageid) in the category.""" | ||||
| query = """SELECT page_title, page_namespace, page_id FROM page | query = """SELECT page_title, page_namespace, page_id FROM page | ||||
| JOIN categorylinks ON page_id = cl_from | JOIN categorylinks ON page_id = cl_from | ||||
| WHERE cl_to = ?""" | WHERE cl_to = ?""" | ||||
| title = self.title().replace(" ", "_").split(":", 1)[1] | |||||
| title = self.title.replace(" ", "_").split(":", 1)[1] | |||||
| if limit: | if limit: | ||||
| query += " LIMIT ?" | query += " LIMIT ?" | ||||
| @@ -41,6 +41,7 @@ class Page(CopyrightMixin): | |||||
| *Attributes:* | *Attributes:* | ||||
| - :py:attr:`site`: the page's corresponding Site object | |||||
| - :py:attr:`title`: the page's title, or pagename | - :py:attr:`title`: the page's title, or pagename | ||||
| - :py:attr:`exists`: whether the page exists | - :py:attr:`exists`: whether the page exists | ||||
| - :py:attr:`pageid`: an integer ID representing the page | - :py:attr:`pageid`: an integer ID representing the page | ||||
| @@ -128,9 +129,9 @@ class Page(CopyrightMixin): | |||||
| def __str__(self): | def __str__(self): | ||||
| """Returns a nice string representation of the Page.""" | """Returns a nice string representation of the Page.""" | ||||
| return '<Page "{0}" of {1}>'.format(self.title(), str(self._site)) | |||||
| return '<Page "{0}" of {1}>'.format(self.title, str(self._site)) | |||||
| def _force_validity(self): | |||||
| def _assert_validity(self): | |||||
| """Used to ensure that our page's title is valid. | """Used to ensure that our page's title is valid. | ||||
| If this method is called when our page is not valid (and after | If this method is called when our page is not valid (and after | ||||
| @@ -143,14 +144,14 @@ class Page(CopyrightMixin): | |||||
| e = "Page '{0}' is invalid.".format(self._title) | e = "Page '{0}' is invalid.".format(self._title) | ||||
| raise exceptions.InvalidPageError(e) | raise exceptions.InvalidPageError(e) | ||||
| def _force_existence(self): | |||||
| def _assert_existence(self): | |||||
| """Used to ensure that our page exists. | """Used to ensure that our page exists. | ||||
| If this method is called when our page doesn't exist (and after | If this method is called when our page doesn't exist (and after | ||||
| _load_attributes() has been called), PageNotFoundError will be raised. | _load_attributes() has been called), PageNotFoundError will be raised. | ||||
| It will also call _force_validity() beforehand. | |||||
| It will also call _assert_validity() beforehand. | |||||
| """ | """ | ||||
| self._force_validity() | |||||
| self._assert_validity() | |||||
| if self._exists == 2: | if self._exists == 2: | ||||
| e = "Page '{0}' does not exist.".format(self._title) | e = "Page '{0}' does not exist.".format(self._title) | ||||
| raise exceptions.PageNotFoundError(e) | raise exceptions.PageNotFoundError(e) | ||||
| @@ -267,7 +268,7 @@ class Page(CopyrightMixin): | |||||
| # self._load_attributes(). In that case, some of our attributes are | # self._load_attributes(). In that case, some of our attributes are | ||||
| # outdated, so force another self._load_attributes(): | # outdated, so force another self._load_attributes(): | ||||
| self._load_attributes() | self._load_attributes() | ||||
| self._force_existence() | |||||
| self._assert_existence() | |||||
| def _edit(self, params=None, text=None, summary=None, minor=None, bot=None, | def _edit(self, params=None, text=None, summary=None, minor=None, bot=None, | ||||
| force=None, section=None, captcha_id=None, captcha_word=None, | force=None, section=None, captcha_id=None, captcha_word=None, | ||||
| @@ -290,7 +291,7 @@ class Page(CopyrightMixin): | |||||
| raise exceptions.PermissionsError(e) | raise exceptions.PermissionsError(e) | ||||
| # Weed out invalid pages before we get too far: | # Weed out invalid pages before we get too far: | ||||
| self._force_validity() | |||||
| self._assert_validity() | |||||
| # Build our API query string: | # Build our API query string: | ||||
| if not params: | if not params: | ||||
| @@ -430,6 +431,11 @@ class Page(CopyrightMixin): | |||||
| raise exceptions.PermissionsError(e) | raise exceptions.PermissionsError(e) | ||||
| @property | @property | ||||
| def site(self): | |||||
| """The Page's corresponding Site object.""" | |||||
| return self._site | |||||
| @property | |||||
| def title(self): | def title(self): | ||||
| """The Page's title, or "pagename". | """The Page's title, or "pagename". | ||||
| @@ -474,7 +480,7 @@ class Page(CopyrightMixin): | |||||
| """ | """ | ||||
| if self._exists == 0: | if self._exists == 0: | ||||
| self._load() | self._load() | ||||
| self._force_existence() # Missing pages do not have IDs | |||||
| self._assert_existence() # Missing pages do not have IDs | |||||
| return self._pageid | return self._pageid | ||||
| @property | @property | ||||
| @@ -514,7 +520,7 @@ class Page(CopyrightMixin): | |||||
| """ | """ | ||||
| if self._exists == 0: | if self._exists == 0: | ||||
| self._load() | self._load() | ||||
| self._force_validity() # Invalid pages cannot be protected | |||||
| self._assert_validity() # Invalid pages cannot be protected | |||||
| return self._protection | return self._protection | ||||
| @property | @property | ||||
| @@ -608,7 +614,7 @@ class Page(CopyrightMixin): | |||||
| "intoken": "edit", "rvprop": "content|timestamp"} | "intoken": "edit", "rvprop": "content|timestamp"} | ||||
| result = self._site._api_query(params) | result = self._site._api_query(params) | ||||
| self._load_attributes(result=result) | self._load_attributes(result=result) | ||||
| self._force_existence() | |||||
| self._assert_existence() | |||||
| self._load_content(result=result) | self._load_content(result=result) | ||||
| # Follow redirects if we're told to: | # Follow redirects if we're told to: | ||||
| @@ -623,7 +629,7 @@ class Page(CopyrightMixin): | |||||
| # Make sure we're dealing with a real page here. This may be outdated | # Make sure we're dealing with a real page here. This may be outdated | ||||
| # if the page was deleted since we last called self._load_attributes(), | # if the page was deleted since we last called self._load_attributes(), | ||||
| # but self._load_content() can handle that: | # but self._load_content() can handle that: | ||||
| self._force_existence() | |||||
| self._assert_existence() | |||||
| if self._content is None: | if self._content is None: | ||||
| self._load_content() | self._load_content() | ||||
| @@ -662,10 +668,10 @@ class Page(CopyrightMixin): | |||||
| """ | """ | ||||
| if self._exists == 0: | if self._exists == 0: | ||||
| self._load() | self._load() | ||||
| self._force_existence() | |||||
| self._assert_existence() | |||||
| if not self._creator: | if not self._creator: | ||||
| self._load() | self._load() | ||||
| self._force_existence() | |||||
| self._assert_existence() | |||||
| return self._site.get_user(self._creator) | return self._site.get_user(self._creator) | ||||
| def edit(self, text, summary, minor=False, bot=True, force=False): | def edit(self, text, summary, minor=False, bot=True, force=False): | ||||