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