Index: trunk/pywikipedia/wikipedia.py |
— | — | @@ -1,4 +1,4 @@ |
2 | | -## -*- coding: utf-8 -*- |
| 2 | +## -*- coding: utf-8 -*- |
3 | 3 | """ |
4 | 4 | Library to get and put pages on a MediaWiki. |
5 | 5 | |
— | — | @@ -1030,13 +1030,13 @@ |
1031 | 1031 | yield Page(site, fileLink) |
1032 | 1032 | |
1033 | 1033 | def put_async(self, newtext, |
1034 | | - comment=None, watchArticle=None, minorEdit=True): |
| 1034 | + comment=None, watchArticle=None, minorEdit=True, force=False): |
1035 | 1035 | """Asynchronous version of put (takes the same arguments), which |
1036 | 1036 | places pages on a queue to be saved by a daemon thread. |
1037 | 1037 | """ |
1038 | | - page_put_queue.put((self, newtext, comment, watchArticle, minorEdit)) |
| 1038 | + page_put_queue.put((self, newtext, comment, watchArticle, minorEdit, force)) |
1039 | 1039 | |
1040 | | - def put(self, newtext, comment=None, watchArticle = None, minorEdit = True): |
| 1040 | + def put(self, newtext, comment=None, watchArticle = None, minorEdit = True, force=False): |
1041 | 1041 | """Replace the new page with the contents of the first argument. |
1042 | 1042 | The second argument is a string that is to be used as the |
1043 | 1043 | summary for the modification |
— | — | @@ -1051,6 +1051,11 @@ |
1052 | 1052 | #except NoPage: |
1053 | 1053 | # pass |
1054 | 1054 | |
| 1055 | + # Determine if we are allowed to edit |
| 1056 | + if not force: |
| 1057 | + if not self.botMayEdit(): |
| 1058 | + raise LockedPage(u'Not allowed to edit %s because of a restricting template' % self.aslink()) |
| 1059 | + |
1055 | 1060 | # If there is an unchecked edit restriction, we need to load the page |
1056 | 1061 | if self._editrestriction: |
1057 | 1062 | output(u'Page %s is semi-protected. Getting edit page to find out if we are allowed to edit.' % self.aslink()) |
— | — | @@ -4641,13 +4646,13 @@ |
4642 | 4647 | Daemon that takes pages from the queue and tries to save them on the wiki. |
4643 | 4648 | ''' |
4644 | 4649 | while True: |
4645 | | - page, newtext, comment, watchArticle, minorEdit = page_put_queue.get() |
| 4650 | + page, newtext, comment, watchArticle, minorEdit, force = page_put_queue.get() |
4646 | 4651 | if page is None: |
4647 | 4652 | # needed for compatibility with Python 2.3 and 2.4 |
4648 | 4653 | # in 2.5, we could use the Queue's task_done() and join() methods |
4649 | 4654 | return |
4650 | 4655 | try: |
4651 | | - page.put(newtext, comment, watchArticle, minorEdit) |
| 4656 | + page.put(newtext, comment, watchArticle, minorEdit, force) |
4652 | 4657 | except SpamfilterError, ex: |
4653 | 4658 | output(u"Saving page [[%s]] prevented by spam filter: %s" |
4654 | 4659 | % (page.title(), ex.url)) |
— | — | @@ -4683,7 +4688,7 @@ |
4684 | 4689 | remaining = datetime.timedelta(seconds=(page_put_queue.qsize()+1) * config.put_throttle) |
4685 | 4690 | output('Waiting for %i pages to be put. Estimated time remaining: %s' % (page_put_queue.qsize()+1, remaining)) |
4686 | 4691 | |
4687 | | - page_put_queue.put((None, None, None, None, None)) |
| 4692 | + page_put_queue.put((None, None, None, None, None, None)) |
4688 | 4693 | |
4689 | 4694 | while(_putthread.isAlive()): |
4690 | 4695 | try: |
— | — | @@ -4694,6 +4699,7 @@ |
4695 | 4700 | ['yes', 'no'], ['y', 'N'], 'N') |
4696 | 4701 | if answer in ['y', 'Y']: |
4697 | 4702 | return |
| 4703 | + get_throttle.drop() |
4698 | 4704 | |
4699 | 4705 | import atexit |
4700 | 4706 | atexit.register(_flush) |