[MediaWiki-commits] [Gerrit] mediawiki...Thanks[master]: [WIP] Proof-of-concept of logging on Thanks setting changes

2017-08-17 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372493 )

Change subject: [WIP] Proof-of-concept of logging on Thanks setting changes
..

[WIP] Proof-of-concept of logging on Thanks setting changes

TODO: Fill in

Bug: T120753
Change-Id: I695b81f1d0ad2e291472eebc92e63a346c918e36
---
M Thanks.hooks.php
M extension.json
M i18n/en.json
3 files changed, 10 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks 
refs/changes/93/372493/1

diff --git a/Thanks.hooks.php b/Thanks.hooks.php
index 4067dc5..daa0b05 100644
--- a/Thanks.hooks.php
+++ b/Thanks.hooks.php
@@ -171,9 +171,13 @@
public static function onBeforeCreateEchoEvent(
&$notifications, &$notificationCategories, &$icons
) {
+   global $wgThanksLoggingOnEnableDisableNotifications;
+   $tooltip = $wgThanksLoggingOnEnableDisableNotifications
+   ? 'echo-pref-tooltip-edit-thank-logged' : 
'echo-pref-tooltip-edit-thank';
+
$notificationCategories['edit-thank'] = [
'priority' => 3,
-   'tooltip' => 'echo-pref-tooltip-edit-thank',
+   'tooltip' => $tooltip,
];
 
$notifications['edit-thank'] = [
diff --git a/extension.json b/extension.json
index ada16a9..ea1e5f0 100644
--- a/extension.json
+++ b/extension.json
@@ -178,7 +178,8 @@
"config": {
"ThanksSendToBots": false,
"ThanksLogging": true,
-   "ThanksConfirmationRequired": true
+   "ThanksConfirmationRequired": true,
+   "ThanksLoggingOnEnableDisableNotifications": true
},
"manifest_version": 1
 }
diff --git a/i18n/en.json b/i18n/en.json
index 997b6e9..268fda1 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -29,6 +29,7 @@
"thanks-form-revid": "Revision ID for edit",
"echo-pref-subscription-edit-thank": "Thanks me for my edit",
"echo-pref-tooltip-edit-thank": "Notify me when someone thanks me for 
an edit I made.",
+   "echo-pref-tooltip-edit-thank-logged": "Notify me when someone thanks 
me for an edit I made. Changes to this preference are logged.",
"echo-category-title-edit-thank": "Thanks",
"notification-thanks-diff-link": "your edit",
"notification-header-edit-thank": "$1 {{GENDER:$2|thanked}} 
{{GENDER:$4|you}} for your edit on $3.",
@@ -37,6 +38,8 @@
"log-name-thanks": "Thanks log",
"log-description-thanks": "Below is a list of users thanked by other 
users.",
"logentry-thanks-thank": "$1 {{GENDER:$2|thanked}} {{GENDER:$4|$3}}",
+   "logentry-thanks-enabled": "$1 {{GENDER:$2|enabled}} notifications for 
thanks",
+   "logentry-thanks-disabled": "$1 {{GENDER:$2|disabled}} notifications 
for thanks",
"log-show-hide-thanks": "$1 thanks log",
"thanks-error-no-id-specified": "You must specify a revision ID to send 
thanks.",
"thanks-confirmation-special": "Do you want to publicly send thanks for 
this edit?",

-- 
To view, visit https://gerrit.wikimedia.org/r/372493
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I695b81f1d0ad2e291472eebc92e63a346c918e36
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Happy5214 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] pywikibot/core[master]: [WIP] Add ability to thank Flow posts

2017-06-29 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/362324 )

Change subject: [WIP] Add ability to thank Flow posts
..

[WIP] Add ability to thank Flow posts

I still need to write the tests for this code.

Change-Id: Ie629aaa46aa007a39e6d5dce6400504bf73e5980
---
M pywikibot/flow.py
M pywikibot/site.py
2 files changed, 24 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/24/362324/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 5f8a006..17f97e4 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -535,3 +535,7 @@
 """
 self.site.restore_post(self, reason)
 self._load()
+
+def thank(self):
+"""Thank the user who made this post."""
+self.site.thank_post(self)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index e2bc6cc..08b7b7a 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -6775,6 +6775,7 @@
 comparison = data['compare']['*']
 return comparison
 
+# Thanks API calls
 @need_extension('Thanks')
 def thank_revision(self, revid, source=None):
 """Corresponding method to the 'action=thank' API action.
@@ -6794,6 +6795,25 @@
 raise api.APIError('Thanking unsuccessful')
 return data
 
+@need_extension('Flow')
+@need_extension('Thanks')
+def thank_post(self, post):
+"""Corresponding method to the 'action=flowthank' API action.
+
+@param post: The post to be thanked for.
+@type post: Post
+@raise APIError: On thanking oneself or other API errors.
+@return: The API response.
+"""
+post_id = post.uuid
+token = self.tokens['csrf']
+req = self._simple_request(action='flowthank',
+   postid=post_id, token=token)
+data = req.submit()
+if data['result']['success'] != 1:
+raise api.APIError('Thanking unsuccessful')
+return data
+
 # Flow API calls
 @need_extension('Flow')
 def load_board(self, page):

-- 
To view, visit https://gerrit.wikimedia.org/r/362324
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie629aaa46aa007a39e6d5dce6400504bf73e5980
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Create superclass for log entries with user targets

2017-06-22 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361017 )

Change subject: Create superclass for log entries with user targets
..

Create superclass for log entries with user targets

This superclass will override the user() method so it returns a
User object instead of a Page object.

Change-Id: Iccce2364e67dc8e4975cea9b07c782d58a700b2f
---
M pywikibot/logentries.py
1 file changed, 16 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/17/361017/1

diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index 22cc434..80cf38c 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -129,6 +129,21 @@
 return self.data['comment']
 
 
+class UserTargetLogEntry(LogEntry):
+
+"""A log entry whose target is a user page."""
+
+def page(self):
+"""Return the target user.
+
+This returns a User object instead of the Page object returned by the
+superclass method.
+"""
+if not hasattr(self, '_page'):
+self._page = pywikibot.User(super(UserTargetLogEntry, self).page())
+return self._page
+
+
 class BlockEntry(LogEntry):
 
 """
@@ -361,21 +376,11 @@
 _expectedType = 'newusers'
 
 
-class ThanksEntry(LogEntry):
+class ThanksEntry(UserTargetLogEntry):
 
 """Thanks log entry."""
 
 _expectedType = 'thanks'
-
-def page(self):
-"""Return the target user.
-
-This returns a User object instead of the Page object returned by the
-superclass method.
-"""
-if not hasattr(self, '_page'):
-self._page = pywikibot.User(super(ThanksEntry, self).page())
-return self._page
 
 # TODO entries for 
merge,suppress,makebot,gblblock,renameuser,globalauth,gblrights ?
 

-- 
To view, visit https://gerrit.wikimedia.org/r/361017
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iccce2364e67dc8e4975cea9b07c782d58a700b2f
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] pywikibot/core[master]: [WIP] Add log entry code for thanks log

2017-06-15 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/359366 )

Change subject: [WIP] Add log entry code for thanks log
..

[WIP] Add log entry code for thanks log

Change-Id: Idb656b3920338d21e9a0d269c59d30597740a058
---
M pywikibot/logentries.py
1 file changed, 9 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/66/359366/1

diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index 310d826..cafa122 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -360,6 +360,13 @@
 
 _expectedType = 'newusers'
 
+
+class ThanksEntry(LogEntry):
+
+"""Thanks log entry."""
+
+_expectedType = 'thanks'
+
 # TODO entries for 
merge,suppress,makebot,gblblock,renameuser,globalauth,gblrights ?
 
 
@@ -380,7 +387,8 @@
 'move': MoveEntry,
 'import': ImportEntry,
 'patrol': PatrolEntry,
-'newusers': NewUsersEntry
+'newusers': NewUsersEntry,
+'thanks': ThanksEntry
 }
 
 def __init__(self, site, logtype=None):

-- 
To view, visit https://gerrit.wikimedia.org/r/359366
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb656b3920338d21e9a0d269c59d30597740a058
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] pywikibot/core[master]: [WIP] Add on to pywikibot support for thanking normal revisions

2017-06-08 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/357957 )

Change subject: [WIP] Add on to pywikibot support for thanking normal revisions
..

[WIP] Add on to pywikibot support for thanking normal revisions

This second commit:
 - Renames thankable to isThankable to match existing convention.

Bug: T135409
Change-Id: Ib3a35fea2442099fb685ddf0097e6c4003a69fd7
---
M pywikibot/page.py
M tests/thanks_tests.py
2 files changed, 3 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/57/357957/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 450da57..506 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3463,7 +3463,7 @@
)
 
 @property
-def thankable(self):
+def isThankable(self):
 """
 Determine if the user has thanks notifications enabled.
 
@@ -3474,7 +3474,7 @@
 
 @rtype: bool
 """
-return not self.isAnonymous()
+return not (self.isAnonymous() or 'bot' in self.groups())
 
 
 class WikibasePage(BasePage):
diff --git a/tests/thanks_tests.py b/tests/thanks_tests.py
index aeeb297..5c45bc4 100644
--- a/tests/thanks_tests.py
+++ b/tests/thanks_tests.py
@@ -35,7 +35,7 @@
 revid = i['revid']
 username = i['user']
 user = User(site, username)
-if user.thankable:
+if user.isThankable:
 can_thank = True
 break
 if not can_thank:

-- 
To view, visit https://gerrit.wikimedia.org/r/357957
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib3a35fea2442099fb685ddf0097e6c4003a69fd7
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Use new test topic for reply tests - change (pywikibot/core)

2015-11-26 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/255529

Change subject: Use new test topic for reply tests
..

Use new test topic for reply tests

The topic on the testwiki used to test replying has become too big.
The size of the topic is slowing down reply tests. This patch points
the reply tests to a new topic in order to speed them up.

Unless someone can purge the posts from the topic, patches such as
this one will be necessary periodically.

Change-Id: Icf84daa1ec0eb855370e10902b82cbb43ae7af43
---
M tests/flow_edit_tests.py
1 file changed, 5 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/29/255529/1

diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
index 5ae7a54..a794345 100644
--- a/tests/flow_edit_tests.py
+++ b/tests/flow_edit_tests.py
@@ -53,7 +53,7 @@
 """Test replying to "topic" (really the topic's root post)."""
 # Setup
 content = 'I am a reply to the topic. Replying works!'
-topic = Topic(self.site, 'Topic:Sl4ssgh123c3e1bh')
+topic = Topic(self.site, 'Topic:Stf56oxx0sd4dkj1')
 old_replies = topic.replies(force=True)[:]
 # Reply
 reply_post = topic.reply(content, 'wikitext')
@@ -71,7 +71,7 @@
 """Test replying to the topic's root post directly."""
 # Setup
 content = "I am a reply to the topic's root post. Replying still 
works!"
-topic = Topic(self.site, 'Topic:Sl4ssgh123c3e1bh')
+topic = Topic(self.site, 'Topic:Stf56oxx0sd4dkj1')
 topic_root = topic.root
 old_replies = topic_root.replies(force=True)[:]
 # Reply
@@ -90,8 +90,8 @@
 """Test replying to an ordinary post."""
 # Setup
 content = 'I am a nested reply to a regular post. Still going strong!'
-topic = Topic(self.site, 'Topic:Sl4ssgh123c3e1bh')
-root_post = Post(topic, 'smjnql768bl0h0kt')
+topic = Topic(self.site, 'Topic:Stf56oxx0sd4dkj1')
+root_post = Post(topic, 'stf5bamzx32rj1gt')
 old_replies = root_post.replies(force=True)[:]
 # Reply
 reply_post = root_post.reply(content, 'wikitext')
@@ -110,7 +110,7 @@
 # Setup
 first_content = 'I am a reply to the topic with my own replies. Great!'
 second_content = 'I am a nested reply. This conversation is getting 
pretty good!'
-topic = Topic(self.site, 'Topic:Sl4ssgh123c3e1bh')
+topic = Topic(self.site, 'Topic:Stf56oxx0sd4dkj1')
 topic_root = topic.root
 # First reply
 old_root_replies = topic_root.replies(force=True)[:]

-- 
To view, visit https://gerrit.wikimedia.org/r/255529
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf84daa1ec0eb855370e10902b82cbb43ae7af43
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] [WIP] Add Flow-specific revision support - change (pywikibot/core)

2015-11-16 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/253385

Change subject: [WIP] Add Flow-specific revision support
..

[WIP] Add Flow-specific revision support

This commit adds support for the Flow revision system.

Bug: T109309
Change-Id: Ifd003f061d63437c74f1f766d5c78bf69e83183a
---
M pywikibot/flow.py
1 file changed, 126 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/85/253385/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 9ccb5f5..8893724 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -221,7 +221,7 @@
 @property
 def is_locked(self):
 """Whether this topic is locked."""
-return self.root._current_revision['isLocked']
+return self.root._data['isLocked']
 
 @property
 def is_moderated(self):
@@ -377,12 +377,10 @@
 raise ValueError('Current revision of post'
  'not found in supplied data.')
 
-self._current_revision = data['revisions'][current_revision_id]
-if 'content' in self._current_revision:
-content = self._current_revision.pop('content')
-assert isinstance(content, dict)
-assert isinstance(content['content'], unicode)
-self._content[content['format']] = content['content']
+self._data = data['revisions'][current_revision_id]
+self._current_revision = FlowRevision.fromJSON(self.page,
+   current_revision_id,
+   data)
 
 def _load(self, format='wikitext', load_from_topic=False):
 """Load and cache the Post's data using the given content format."""
@@ -392,7 +390,7 @@
 data = self.site.load_post_current_revision(self.page, self.uuid,
 format)
 self._set_data(data)
-return self._current_revision
+return self._data
 
 @property
 def uuid(self):
@@ -446,7 +444,7 @@
 
 if format not in self._content or force:
 self._load(format)
-return self._content[format]
+return self._current_revision.get(format=format)
 
 def replies(self, format='wikitext', force=False):
 """Return this post's replies.
@@ -466,10 +464,10 @@
 
 # load_from_topic workaround due to T106733
 # (replies not returned by view-post)
-if not hasattr(self, '_current_revision') or force:
+if not hasattr(self, '_data') or force:
 self._load(format, load_from_topic=True)
 
-reply_uuids = self._current_revision['replies']
+reply_uuids = self._data['replies']
 self._replies = [Post(self.page, uuid) for uuid in reply_uuids]
 
 return self._replies
@@ -488,12 +486,12 @@
 if self.page.is_locked:
 raise LockedPage(self.page, 'Topic %s is locked.')
 
-reply_url = self._current_revision['actions']['reply']['url']
+reply_url = self._data['actions']['reply']['url']
 parsed_url = urlparse(reply_url)
 params = parse_qs(parsed_url.query)
 reply_to = params['topic_postId']
 if self.uuid == reply_to:
-del self._current_revision
+del self._data
 del self._replies
 data = self.site.reply_to_post(self.page, reply_to, content, format)
 post = Post(self.page, data['post-id'])
@@ -535,3 +533,118 @@
 """
 self.site.restore_post(self, reason)
 self._load()
+
+
+class FlowRevision(object):
+
+"""A revision of a Flow object."""
+
+def __init__(self, page, uuid):
+"""Constructor.
+
+@param page: Flow topic
+@type page: Topic
+@param uuid: UUID of a Flow revision
+@type uuid: unicode
+
+@raises TypeError: incorrect types of parameters
+"""
+if not isinstance(page, Topic):
+raise TypeError('Page must be a Topic object')
+if not page.exists():
+raise NoPage(page, 'Topic must exist: %s')
+if not isinstance(uuid, basestring):
+raise TypeError('Revision UUID must be a string')
+
+self._page = page
+self._uuid = uuid
+
+self._content = {}
+
+@classmethod
+def fromJSON(cls, page, uuid, data):
+"""
+Create a FlowRevision object using the data returned from the API call.
+
+@param page: A Flow topic
+@type page: Topic
+@param uuid: The UUID of the revision
+@type uuid: unicode
+@param data: The JSON data returned from the API
+@type data: dict
+
+@return: A FlowRevision object
+@raises TypeError: data is not a dict
+@raises ValueError: data is missing required entries
+"""
+revision = cls(page, uuid)
+

[MediaWiki-commits] [Gerrit] [WIP] Moderate Flow topics and posts - change (pywikibot/core)

2015-08-24 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/233482

Change subject: [WIP] Moderate Flow topics and posts
..

[WIP] Moderate Flow topics and posts

This change allows Pywikibot bots to moderate topics and posts using
Flow's moderation system.

Bug: T109308
Change-Id: I92f7c664d13f8397219a4045d782f4b1123610f5
---
M pywikibot/flow.py
M pywikibot/site.py
2 files changed, 121 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/82/233482/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index f9ba1fc..562fc1e 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -164,6 +164,10 @@
 self._data = self.site.load_topic(self, format)
 return self._data
 
+def _reload(self):
+Forcibly reload the topic's root post.
+self.root._load(load_from_topic=True)
+
 @classmethod
 def create_topic(cls, board, title, content, format='wikitext'):
 Create and return a Topic object for a new topic on a Board.
@@ -250,7 +254,7 @@
 @type reason: unicode
 
 self.site.lock_topic(self, True, reason)
-self.root._load(load_from_topic=True)
+self._reload()
 
 def unlock(self, reason='Reopened'):
 Unlock this topic.
@@ -259,7 +263,43 @@
 @type reason: unicode
 
 self.site.lock_topic(self, False, reason)
-self.root._load(load_from_topic=True)
+self._reload()
+
+def delete_mod(self, reason='Deleted'):
+Delete this topic through the Flow moderation system.
+
+@param reason: The reason for deleting this topic.
+@type reason: unicode
+
+self.site.delete_topic(self, reason)
+self._reload()
+
+def hide(self, reason='Hid'):
+Hide this topic.
+
+@param reason: The reason for hiding this topic.
+@type reason: unicode
+
+self.site.hide_topic(self, reason)
+self._reload()
+
+def suppress(self, reason='Suppressed'):
+Suppress this topic.
+
+@param reason: The reason for suppressing this topic.
+@type reason: unicode
+
+self.site.suppress_topic(self, reason)
+self._reload()
+
+def restore(self, reason='Restored'):
+Restore this topic.
+
+@param reason: The reason for restoring this topic.
+@type reason: unicode
+
+self.site.restore_topic(self, reason)
+self._reload()
 
 
 # Flow non-page-like objects
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3666f03..6084f8d 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -6006,7 +6006,7 @@
 data = req.submit()
 return data['flow']['reply']['committed']['topic']
 
-@must_be('user')
+@must_be('user', 'flow-lock')
 @need_extension('Flow')
 def lock_topic(self, page, lock, reason):
 Lock or unlock a Flow topic.
@@ -6029,6 +6029,84 @@
 data = req.submit()
 return data['flow']['lock-topic']['committed']['topic']
 
+@must_be('user')
+@need_extension('Flow')
+def moderate_topic(self, page, state, reason):
+Moderate a Flow topic.
+
+@param page: A Flow topic
+@type page: Topic
+@param state: The new moderation state
+@type state: str
+@param reason: The reason to moderate the topic
+@type reason: unicode
+@return: Metadata returned by the API
+@rtype: dict
+
+token = self.tokens['csrf']
+params = {'action': 'flow', 'page': page, 'token': token,
+  'submodule': 'moderate-topic', 'mtreason': reason,
+  'mtmoderationState': state}
+req = self._request(parameters=params, use_get=False)
+data = req.submit()
+return data['flow']['moderate-topic']['committed']['topic']
+
+@must_be('user', 'flow-delete')
+@need_extension('Flow')
+def delete_topic(self, page, reason):
+Delete a Flow topic.
+
+@param page: A Flow topic
+@type page: Topic
+@param reason: The reason to delete the topic
+@type reason: unicode
+@return: Metadata returned by the API
+@rtype: dict
+
+return self.moderate_topic(page, 'delete', reason)
+
+@must_be('user', 'flow-hide')
+@need_extension('Flow')
+def hide_topic(self, page, reason):
+Hide a Flow topic.
+
+@param page: A Flow topic
+@type page: Topic
+@param reason: The reason to hide the topic
+@type reason: unicode
+@return: Metadata returned by the API
+@rtype: dict
+
+return self.moderate_topic(page, 'hide', reason)
+
+@must_be('user', 'flow-suppress')
+@need_extension('Flow')
+def suppress_topic(self, page, reason):
+Suppress a Flow topic.
+
+@param page: A Flow topic
+ 

[MediaWiki-commits] [Gerrit] Add Flow modules to API docs - change (pywikibot/core)

2015-08-21 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/232923

Change subject: Add Flow modules to API docs
..

Add Flow modules to API docs

Bug: T109682
Change-Id: Ia91191349b4531e8fbdc0e661def276dc94d9abe
---
M docs/api_ref/pywikibot.rst
A docs/api_ref/tests/flow_edit_tests.rst
A docs/api_ref/tests/flow_tests.rst
M docs/api_ref/tests/index.rst
4 files changed, 44 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/23/232923/1

diff --git a/docs/api_ref/pywikibot.rst b/docs/api_ref/pywikibot.rst
index c18a64c..21c21b3 100644
--- a/docs/api_ref/pywikibot.rst
+++ b/docs/api_ref/pywikibot.rst
@@ -125,6 +125,14 @@
 :undoc-members:
 :show-inheritance:
 
+pywikibot.flow module
+--
+
+.. automodule:: pywikibot.flow
+:members:
+:undoc-members:
+:show-inheritance:
+
 pywikibot.i18n module
 -
 
diff --git a/docs/api_ref/tests/flow_edit_tests.rst 
b/docs/api_ref/tests/flow_edit_tests.rst
new file mode 100644
index 000..c81ed1c
--- /dev/null
+++ b/docs/api_ref/tests/flow_edit_tests.rst
@@ -0,0 +1,16 @@
+===
+flow_edit_tests
+===
+Tests in ``tests.flow_edit_tests``:
+
+---
+Available tests
+---
+.. autoclass:: tests.flow_edit_tests.TestFlowCreateTopic
+:members:
+.. autoclass:: tests.flow_edit_tests.TestFlowReply
+:members:
+.. autoclass:: tests.flow_edit_tests.TestFlowLockTopic
+:members:
+.. autoclass:: tests.flow_edit_tests.TestFlowEditFailure
+:members:
diff --git a/docs/api_ref/tests/flow_tests.rst 
b/docs/api_ref/tests/flow_tests.rst
new file mode 100644
index 000..124e266
--- /dev/null
+++ b/docs/api_ref/tests/flow_tests.rst
@@ -0,0 +1,18 @@
+==
+flow_tests
+==
+Tests in ``tests.flow_tests``:
+
+---
+Available tests
+---
+.. autoclass:: tests.flow_tests.TestBoardBasePageMethods
+:members:
+.. autoclass:: tests.flow_tests.TestTopicBasePageMethods
+:members:
+.. autoclass:: tests.flow_tests.TestLoadRevisionsCaching
+:members:
+.. autoclass:: tests.flow_tests.TestFlowLoading
+:members:
+.. autoclass:: tests.flow_tests.TestFlowFactoryErrors
+:members:
diff --git a/docs/api_ref/tests/index.rst b/docs/api_ref/tests/index.rst
index 15cd9b6..224328f 100644
--- a/docs/api_ref/tests/index.rst
+++ b/docs/api_ref/tests/index.rst
@@ -38,6 +38,8 @@
 wikibase_edit./wikibase_edit_tests
 upload./upload_tests
 oauth./oauth_tests
+flow./flow_tests
+flow_edit./flow_edit_tests
 
 
 Script tests

-- 
To view, visit https://gerrit.wikimedia.org/r/232923
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia91191349b4531e8fbdc0e661def276dc94d9abe
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] [POC] Enable Flow support in unusedfiles.py - change (pywikibot/core)

2015-08-20 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/232737

Change subject: [POC] Enable Flow support in unusedfiles.py
..

[POC] Enable Flow support in unusedfiles.py

This change adds Flow support to unusedfiles.py. The script now
creates a new Flow topic if the user talk page it is posting
to is a Flow board. Template definitions for the testwiki were
also added.

Change-Id: Ie0ba39c94b7804778c2becff866f0fbd27bed5ed
---
M scripts/unusedfiles.py
1 file changed, 22 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/37/232737/1

diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 30140aa..fb44b25 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -21,8 +21,12 @@
 __version__ = '$Id$'
 #
 
+import re
+
 import pywikibot
 from pywikibot import i18n, pagegenerators, Bot
+from pywikibot.flow import Board
+from pywikibot.page import FilePage
 
 comment = {
 'ar': u'صور للاستبعاد',
@@ -36,11 +40,14 @@
 template_to_the_image = {
 'it': u'{{immagine orfana}}',
 'fa': u'{{تصاویر بدون استفاده}}',
+'test': '{{User:Happy5214/Unused file notice (file)}}',
 }
 
 # This template message should use subst:
 template_to_the_user = {
-'fa': u'\n\n{{جا:اخطار به کاربر برای تصاویر بدون 
استفاده|%(title)s}}--',
+'fa': u'{{جا:اخطار به کاربر برای تصاویر بدون استفاده|%(title)s}}--',
+'it': u'{{Utente:Filbot/Immagine orfana}}',
+'test': '{{User:Happy5214/Unused file notice (user)|%(title)s}}',
 }
 
 
@@ -83,8 +90,12 @@
 uploader = image.getFileVersionHistory().pop(0)['user']
 user = pywikibot.User(image.site, uploader)
 usertalkpage = user.getUserTalkPage()
-msg2uploader = template_user % {'title': image.title()}
-self.append_text(usertalkpage, msg2uploader)
+template2uploader = template_user % {'title': image.title()}
+msg2uploader = self.site.expand_text(template2uploader)
+if usertalkpage.is_flow_page():
+self.post_to_flow_board(usertalkpage, msg2uploader)
+else:
+self.append_text(usertalkpage, '\n\n' + msg2uploader + ' 
')
 
 def append_text(self, page, apptext):
 Append apptext to the page.
@@ -102,6 +113,14 @@
 text += apptext
 self.userPut(page, oldtext, text, summary=self.summary)
 
+def post_to_flow_board(self, page, post):
+Post message as a Flow topic.
+board = Board(page)
+header, rest = post.split('\n', 1)
+title = header.strip('=')
+content = rest.lstrip()
+board.new_topic(title, content)
+
 
 def main(*args):
 

-- 
To view, visit https://gerrit.wikimedia.org/r/232737
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie0ba39c94b7804778c2becff866f0fbd27bed5ed
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] [WIP] Lock and unlock Flow topics - change (pywikibot/core)

2015-08-14 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/231747

Change subject: [WIP] Lock and unlock Flow topics
..

[WIP] Lock and unlock Flow topics

This patch will allow bots to lock and unlock Flow topics using the
API. Right now, this patch adds a property showing whether a topic
is locked, blocking replies to the topic if it is locked.

Bug: T108288
Change-Id: I4afb6c0fff6bf541a1a05aa2a5f9b0715e67541e
---
M pywikibot/flow.py
M tests/flow_edit_tests.py
2 files changed, 20 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/47/231747/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 1580edb..7e22057 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -11,7 +11,7 @@
 
 import logging
 
-from pywikibot.exceptions import NoPage, UnknownExtension
+from pywikibot.exceptions import NoPage, UnknownExtension, LockedPage
 from pywikibot.page import BasePage
 from pywikibot.tools import PY2
 
@@ -213,6 +213,11 @@
 self._root = Post.fromJSON(self, self.uuid, self._data)
 return self._root
 
+@property
+def is_locked(self):
+Whether this topic is locked.
+return self.root._current_revision['isLocked']
+
 def replies(self, format='wikitext', force=False):
 A list of replies to this topic's root post.
 
@@ -408,6 +413,9 @@
 @rtype: Post
 
 self._load()
+if self.page.is_locked:
+raise LockedPage(self.page, 'Topic %s is locked.')
+
 reply_url = self._current_revision['actions']['reply']['url']
 parsed_url = urlparse(reply_url)
 params = parse_qs(parsed_url.query)
diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
index 9844f5d..2c675e30 100644
--- a/tests/flow_edit_tests.py
+++ b/tests/flow_edit_tests.py
@@ -9,6 +9,7 @@
 
 __version__ = '$Id$'
 
+from pywikibot.exceptions import LockedPage
 from pywikibot.flow import Board, Topic, Post
 from pywikibot.tools import PY2
 
@@ -149,3 +150,13 @@
 self.assertListEqual(old_nested_replies, [])
 more_root_replies = topic_root.replies(force=True)
 self.assertEqual(len(more_root_replies), len(new_root_replies) + 1)
+
+def test_reply_to_locked_topic(self):
+Test replying to locked topic (should raise exception).
+# Setup
+content = 'I am a reply to a locked topic. This is not good!'
+topic = Topic(self.site, 'Topic:Smxnipjfs8umm1wt')
+# Reply (should raise a LockedPage exception)
+self.assertRaises(LockedPage, topic.reply, content, 'wikitext')
+topic_root = topic.root
+self.assertRaises(LockedPage, topic_root.reply, content, 'wikitext')

-- 
To view, visit https://gerrit.wikimedia.org/r/231747
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4afb6c0fff6bf541a1a05aa2a5f9b0715e67541e
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] [WIP] Reply to existing posts and topics in Flow - change (pywikibot/core)

2015-07-15 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/224802

Change subject: [WIP] Reply to existing posts and topics in Flow
..

[WIP] Reply to existing posts and topics in Flow

This patch adds code to reply to posts and topics, via their root posts.
It includes tests to post replies to topics and replies to those replies.
These tests currently fail because of an inconsistency in the Flow API and
a known issue in determing when to POST to the API. flow_edit_tests.py, a
new test module, was created in this change for Flow-related edit tests.

Bug: T105439
Change-Id: I96b123f98da847d1e9fcb87558fdb2ebde1a04cf
---
M pywikibot/flow.py
M pywikibot/site.py
A tests/flow_edit_tests.py
3 files changed, 159 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/02/224802/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 8bf2767..64eb145 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -139,9 +139,29 @@
 self._root = Post.fromJSON(self, self.uuid, self._data)
 return self._root
 
-def replies(self):
-A list of replies to this topic's root post.
-return self.root.replies()
+def replies(self, format='wikitext', force=False):
+A list of replies to this topic's root post.
+
+@param format: Content format to return contents in
+@type format: str ('wikitext', 'html', or 'fixed-html')
+@param force: Whether to reload from the API instead of using the cache
+@type force: bool
+@return The replies of this topic's root post
+@rtype: list of Posts
+
+return self.root.replies(format=format, force=force)
+
+def reply(self, content, format='wikitext'):
+A convenience method to reply to this topic's root post.
+
+@param content: The content of the new post
+@type content: unicode
+@param format: The format of the given content
+@type format: str ('wikitext' or 'html')
+@return: The new reply to this topic's root post
+@rtype: Post
+
+return self.root.reply(content, format)
 
 
 # Flow non-page-like objects
@@ -276,3 +296,19 @@
 self._replies = [Post(self.page, uuid) for uuid in reply_uuids]
 
 return self._replies
+
+def reply(self, content, format='wikitext'):
+Reply to this post.
+
+@param content: The content of the new post
+@type content: unicode
+@param format: The format of the given content
+@type format: str ('wikitext' or 'html')
+@return: The new reply post
+@rtype: Post
+
+data = self.site.reply_to_post(self.page, self.uuid, content, format)
+post = Post(self.page, data['post-id'])
+if hasattr(self, '_replies'):
+self._replies.append(post)
+return post
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 59ca823..db159b4 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -5815,6 +5815,28 @@
 data = req.submit()
 return data['flow']['view-post']['result']['topic']
 
+@need_extension('Flow')
+def reply_to_post(self, page, reply_to_uuid, content, format):
+Reply to a post on a Flow topic.
+
+@param page: A Flow topic
+@type page: Topic
+@param reply_to_uuid: The UUID of the Post to create a reply to
+@type reply_to_uuid: unicode
+@param content: The content of the reply
+@type content: unicode
+@param format: The content format used for the supplied content
+@type format: unicode (either 'wikitext' or 'html')
+@return: A dict representing the metadata returned by the API
+@rtype: dict
+
+token = self.tokens['csrf']
+req = self._simple_request(action='flow', page=page, token=token,
+   submodule='reply', repreplyTo=reply_to_uuid,
+   repcontent=content, repformat=format)
+data = req.submit()
+return data['flow']['reply']['committed']['topic']
+
 # aliases for backwards compatibility
 isBlocked = redirect_func(is_blocked, old_name='isBlocked',
   class_name='APISite')
diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
new file mode 100644
index 000..cc7f248
--- /dev/null
+++ b/tests/flow_edit_tests.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8  -*-
+Edit tests for the flow module.
+#
+# (C) Pywikibot team, 2015
+#
+# Distributed under the terms of the MIT license.
+#
+from __future__ import unicode_literals
+
+__version__ = '$Id$'
+
+import pywikibot
+import pywikibot.flow
+import pywikibot.tools
+
+from tests.aspects import (
+TestCase,
+)
+
+if not pywikibot.tools.PY2:
+unicode = str
+
+
+class TestFlowReply(TestCase):
+
+Test replying to existing posts.
+
+

[MediaWiki-commits] [Gerrit] [WIP] Create new topics on a Flow board - change (pywikibot/core)

2015-07-08 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/223525

Change subject: [WIP] Create new topics on a Flow board
..

[WIP] Create new topics on a Flow board

This patch adds functionality that allows bots to create new topics
on existing Flow boards.

Bug: T105129
Change-Id: I3b35082dde30f35df7663e265c89754c73f9ecb8
---
M pywikibot/flow.py
M pywikibot/site.py
M tests/flow_tests.py
3 files changed, 60 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/25/223525/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 061ad28..e58740f 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -104,6 +104,21 @@
 cont_args = _parse_url(data['links']['pagination'])
 data = self._load(**cont_args)
 
+def new_topic(self, title, content, format='wikitext'):
+Create and return a Topic object for a new topic on this Board.
+
+@param title: The title of the new topic
+@type title: unicode
+@param content: The content of the topic's initial post
+@type content: unicode
+@param format: The content format of the supplied content
+@type format: unicode (either 'wikitext' or 'html')
+@return: The new topic
+@rtype: Topic
+
+data = self.site.create_new_topic(self, title, content, format)
+return Topic(self.site, data['topic-page'])
+
 
 class Topic(FlowPage):
 
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 59ca823..ec30709 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -5815,6 +5815,28 @@
 data = req.submit()
 return data['flow']['view-post']['result']['topic']
 
+@need_extension('Flow')
+def create_new_topic(self, page, title, content, format='wikitext'):
+Create a new topic on a Flow board.
+
+@param page: A Flow board
+@type page: Board
+@param title: The title of the new topic
+@type title: unicode
+@param content: The content of the topic's initial post
+@type content: unicode
+@param format: The content format of the supplied content
+@type format: unicode (either 'wikitext' or 'html')
+@return: A dict representing the metadata of the new topic
+@rtype: dict
+
+token = self.tokens['csrf']
+req = self._simple_request(action='flow', page=page, token=token,
+   submodule='new-topic', nttopic=title,
+   ntcontent=content, ntformat=format)
+data = req.submit()
+return data['flow']['new-topic']['committed']['topiclist']
+
 # aliases for backwards compatibility
 isBlocked = redirect_func(is_blocked, old_name='isBlocked',
   class_name='APISite')
diff --git a/tests/flow_tests.py b/tests/flow_tests.py
index cacb104..dc01ea1 100644
--- a/tests/flow_tests.py
+++ b/tests/flow_tests.py
@@ -165,3 +165,26 @@
 if i == 10:
 break
 self.assertEqual(i, 10)
+
+class TestFlowCreateTopic(TestCase):
+
+Test the creation of Flow topics.
+
+family = 'wikipedia'
+code = 'test2'
+
+write = True
+
+def test_create_topic(self):
+Test creation of topic.
+site = self.get_site()
+board = pywikibot.flow.Board(site, 'Talk:Flow QA')
+topic = board.new_topic('Pywikibot test',
+'If you can read this, the Flow code in 
Pywikibot works!',
+'wikitext')
+first_post = topic.replies()[0]
+wikitext = first_post.get(format='wikitext')
+self.assertIn('wikitext', first_post._content)
+self.assertNotIn('html', first_post._content)
+self.assertIsInstance(wikitext, unicode)
+self.assertNotEqual(wikitext, '')

-- 
To view, visit https://gerrit.wikimedia.org/r/223525
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3b35082dde30f35df7663e265c89754c73f9ecb8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Expose post and topic history through the API - change (mediawiki...Flow)

2015-07-02 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/60

Change subject: Expose post and topic history through the API
..

Expose post and topic history through the API

This commit adds two new API submodules for accessing post and topic
histories. The calls return the relevant revisions. A modified clone
of the existing method rendering histories was used for this change.

Bug: T103032
Bug: T103034
Change-Id: Ib9b6a0fe53b6317d4bedfce2ebec0df709f96a86
---
M includes/Api/ApiFlow.php
A includes/Api/ApiFlowViewPostHistory.php
A includes/Api/ApiFlowViewTopicHistory.php
M includes/Block/Topic.php
4 files changed, 199 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/60/60/1

diff --git a/includes/Api/ApiFlow.php b/includes/Api/ApiFlow.php
index 7065351..fadb336 100644
--- a/includes/Api/ApiFlow.php
+++ b/includes/Api/ApiFlow.php
@@ -14,7 +14,7 @@
/** @var ApiModuleManager $moduleManager */
private $moduleManager;
 
-   private static $modules = array(
+   private static $alwaysEnabledModules = array(
// POST
'new-topic' = 'Flow\Api\ApiFlowNewTopic',
'edit-header' = 'Flow\Api\ApiFlowEditHeader',
@@ -35,16 +35,29 @@
// topiclist - we'll want to know topic-/post- or 
topiclist-view ;)
'view-topiclist' = 'Flow\Api\ApiFlowViewTopicList',
'view-post' = 'Flow\Api\ApiFlowViewPost',
+   'view-post-history' = 'Flow\Api\ApiFlowViewPostHistory',
'view-topic' = 'Flow\Api\ApiFlowViewTopic',
+   'view-topic-history' = 'Flow\Api\ApiFlowViewTopicHistory',
'view-header' = 'Flow\Api\ApiFlowViewHeader',
'view-topic-summary' = 'Flow\Api\ApiFlowViewTopicSummary',
-// 'search' = 'Flow\Api\ApiFlowSearch', // @todo: uncomment once 
we're ready to expose search
+   );
+
+   private static $searchModules = array(
+   'search' = 'Flow\Api\ApiFlowSearch',
);
 
public function __construct( $main, $action ) {
+   global $wgFlowSearchEnabled;
+
parent::__construct( $main, $action );
$this-moduleManager = new ApiModuleManager( $this );
-   $this-moduleManager-addModules( self::$modules, 'submodule' );
+
+   $enabledModules = self::$alwaysEnabledModules;
+   if ( $wgFlowSearchEnabled ) {
+   $enabledModules += self::$searchModules;
+   }
+
+   $this-moduleManager-addModules( $enabledModules, 'submodule' 
);
}
 
public function getModuleManager() {
diff --git a/includes/Api/ApiFlowViewPostHistory.php 
b/includes/Api/ApiFlowViewPostHistory.php
new file mode 100644
index 000..632d957
--- /dev/null
+++ b/includes/Api/ApiFlowViewPostHistory.php
@@ -0,0 +1,74 @@
+?php
+
+namespace Flow\Api;
+
+use ApiBase;
+
+class ApiFlowViewPostHistory extends ApiFlowBaseGet {
+   public function __construct( $api, $modName ) {
+   parent::__construct( $api, $modName, 'vph' );
+   }
+
+   /**
+* Taken from ext.flow.base.js
+*
+* @return array
+*/
+   protected function getBlockParams() {
+   return array( 'topic' = $this-extractRequestParams() );
+   }
+
+   protected function getAction() {
+   return 'view-post-history';
+   }
+
+   public function getAllowedParams() {
+   global $wgFlowContentFormat;
+
+   return array(
+   'postId' = array(
+   ApiBase::PARAM_REQUIRED = true,
+   ),
+   'format' = array(
+   ApiBase::PARAM_TYPE = array( 'html', 
'wikitext', 'fixed-html' ),
+   ApiBase::PARAM_DFLT = $wgFlowContentFormat,
+   ),
+   );
+   }
+
+   /**
+* @deprecated since MediaWiki core 1.25
+*/
+   public function getParamDescription() {
+   return array(
+   'postId' = 'Id of the post for which to view revision 
history',
+   'format' = 'Format to return the content in',
+   );
+   }
+
+   /**
+* @deprecated since MediaWiki core 1.25
+*/
+   public function getDescription() {
+   return 'View the revision history of a post';
+   }
+
+   /**
+* @deprecated since MediaWiki core 1.25
+*/
+   public function getExamples() {
+   return array(
+   
'api.php?action=flowsubmodule=view-post-historypage=Topic:S2tycnas4hcucw8wvphpostId=???vphformat=wikitext',
+   );
+   }
+
+   /**
+* @see 

[MediaWiki-commits] [Gerrit] Make inclusion of API action=flowthank conditional on Flow b... - change (mediawiki...Thanks)

2015-06-25 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/220978

Change subject: Make inclusion of API action=flowthank conditional on Flow 
being installed
..

Make inclusion of API action=flowthank conditional on Flow being installed

This patch will only enable the API module 'flowthank' if Flow is installed,
instead of checking whether Flow is installed when the module is invoked.

Bug: T85521
Change-Id: I0183188dd17f035f3c89e40a9cb1a21421071aca
---
M ApiFlowThank.php
M Thanks.hooks.php
M Thanks.php
3 files changed, 15 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks 
refs/changes/78/220978/1

diff --git a/ApiFlowThank.php b/ApiFlowThank.php
index 174c313..1fefc0e 100644
--- a/ApiFlowThank.php
+++ b/ApiFlowThank.php
@@ -17,7 +17,6 @@
 
 class ApiFlowThank extends ApiThank {
public function execute() {
-   $this-dieIfFlowNotInstalled();
$this-dieIfEchoNotInstalled();
 
$user = $this-getUser();
@@ -56,12 +55,6 @@
$topicTitleText,
$pageTitle
);
-   }
-
-   private function dieIfFlowNotInstalled() {
-   if ( !class_exists( 'FlowHooks' ) ) {
-   $this-dieUsage( 'Flow is not installed on this wiki', 
'flownotinstalled' );
-   }
}
 
private function userAlreadySentThanksForId( User $user, UUID $id ) {
diff --git a/Thanks.hooks.php b/Thanks.hooks.php
index 4119ade..ee73d77 100644
--- a/Thanks.hooks.php
+++ b/Thanks.hooks.php
@@ -299,4 +299,16 @@
}
return true;
}
+
+   /**
+* Initialize Thanks extension. Invoked from $wgExtensionFunctions.
+*/
+   public static function initThanksExtension() {
+   global $wgAPIModules;
+
+   // Load 'flowthank' API module only if Flow is installed
+   if ( class_exists( 'FlowHooks' ) ) {
+   $wgAPIModules['flowthank'] = 'ApiFlowThank';
+   }
+   }
 }
diff --git a/Thanks.php b/Thanks.php
index 014e556..f3a735e 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -56,8 +56,6 @@
 
 // Register APIs
 $wgAPIModules['thank'] = 'ApiRevThank';
-/** @todo This should be conditional on Flow being installed on the wiki */
-$wgAPIModules['flowthank'] = 'ApiFlowThank';
 
 // Register special page
 $wgSpecialPages['Thanks'] = 'SpecialThanks';
@@ -76,6 +74,9 @@
 $wgHooks['BeforePageDisplay'][] = 'ThanksHooks::onBeforePageDisplay';
 $wgHooks['ResourceLoaderTestModules'][] = 
'ThanksHooks::onResourceLoaderTestModules';
 
+// Extension initialization
+$wgExtensionFunctions[] = 'ThanksHooks::initThanksExtension';
+
 // Register modules
 $wgResourceModules['ext.thanks'] = array(
'scripts' = array(

-- 
To view, visit https://gerrit.wikimedia.org/r/220978
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0183188dd17f035f3c89e40a9cb1a21421071aca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Load Flow object content in Pywikibot - change (pywikibot/core)

2015-06-11 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/217717

Change subject: Load Flow object content in Pywikibot
..

Load Flow object content in Pywikibot

This change allows Pywikibot bots to load basic Flow content from
Flow-enabled wikis. This includes loading the contents of posts,
loading topics from boards, and loading replies to topics and posts.
Tests have been added to ensure that content is indeed loaded.

Bug: T101260
Change-Id: Ibd84d0763a7745da6410c194b8d5ddf9ba8b57de
---
M pywikibot/flow.py
M tests/flow_tests.py
2 files changed, 35 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/17/217717/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 946f228..eb1ea30 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -108,6 +108,19 @@
 
 self._page = page
 self._uuid = uuid
+
+self._content = {}
+
+def _load_data(self, format='wikitext'):
+Load the Post's data, saving the contents.
+data = self._site.view_post(self.page, self.uuid, format)
+self._content[format] = data['content']['content']
+return data
+
+def _load(self):
+Load and cache the Post's data using the default content format.
+if not hasattr(self, '_data'):
+self._data = self._load_data()
 
 @property
 def uuid(self):
@@ -135,3 +148,15 @@
 @rtype: FlowPage
 
 return self._page
+
+def get(self, format='wikitext'):
+Return the contents of the post in the given format.
+
+@param format: Content format to return contents in.
+@type format: unicode
+@return: The contents of the post in the given content format
+@rtype: unicode
+
+if format not in self._content:
+self._load_data(format)
+return self._content[format]
diff --git a/tests/flow_tests.py b/tests/flow_tests.py
index 575fcb6..4b1a9ca 100644
--- a/tests/flow_tests.py
+++ b/tests/flow_tests.py
@@ -73,3 +73,13 @@
 topic = pywikibot.flow.Topic(site, u'Topic:Sh6wgo5tu3qui1w2')
 post = pywikibot.flow.Post(topic, u'sh6wgoagna97q0ia')
 self.assertEqual(post.uuid, u'sh6wgoagna97q0ia')
+
+def test_post_contents(self):
+Test retrieval of Flow post contents.
+site = self.get_site()
+topic = pywikibot.flow.Topic(site, u'Topic:Sh6wgo5tu3qui1w2')
+post = pywikibot.flow.Post(site, topic, u'sh6wgoagna97q0ia')
+wikitext = post.get('wikitext')
+self.assertTrue(wikitext != u'')
+html = post.get('html')
+self.assertTrue(html != u'')

-- 
To view, visit https://gerrit.wikimedia.org/r/217717
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd84d0763a7745da6410c194b8d5ddf9ba8b57de
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Create classes (with UUIDs) for Flow boards, topics, and posts - change (pywikibot/core)

2015-06-02 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/215392

Change subject: Create classes (with UUIDs) for Flow boards, topics, and posts
..

Create classes (with UUIDs) for Flow boards, topics, and posts

This change will create four new classes representing Flow entities:

* FlowPage: a superclass for page-like Flow objects
* Board: Flow boards
* Topic: Flow topics
* Post: Flow posts

These classes implement UUID-related functionality, including properties
and private methods to load object data. This entails creating new API
hooks to perform calls for loading data from boards, topics, and posts.
Three tests have been added to test the proper working of this UUID
functionality.

Bug: T101146
Change-Id: I37691cd209b4ee9cc6aa03358bdc5d13fa9f1362
---
M pywikibot/page.py
M pywikibot/site.py
M tests/page_tests.py
3 files changed, 211 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/92/215392/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 90efda1..555f1a7 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -76,7 +76,7 @@
 reading from or writing to the wiki.  All other methods are delegated
 to the Site object.
 
-Will be subclassed by Page and WikibasePage.
+Will be subclassed by Page, WikibasePage, and FlowPage.
 
 
 
@@ -4333,6 +4333,168 @@
 'type': self.value_types.get(self.type, self.type)
 }
 
+class FlowPage(BasePage):
+
+
+The base page for the Flow extension.
+
+There should be no need to instantiate this directly.
+
+
+def __init__(self, site, title=u, **kwargs):
+Constructor.
+
+@param site: Flow-enabled site
+@type site: Site
+@param title: normalized title of the page
+@type title: unicode
+
+@raise TypeError: incorrect use of parameters
+@raise ValueError: use of non-Flow-enabled Site
+
+if not isinstance(site, pywikibot.site.BaseSite):
+raise TypeError(site must be a Site object)
+
+if not site.has_extension('Flow'):
+raise ValueError(site is not Flow-enabled)
+
+super(FlowPage, self).__init__(site, title, **kwargs)
+
+@property
+def uuid(self):
+Return the UUID of the page.
+
+@return: UUID of the page
+@rtype: unicode
+
+if not hasattr(self, '_uuid'):
+self._load_uuid()
+return self._uuid
+
+class Board(FlowPage):
+
+A Flow discussion board.
+
+def __init__(self, site, title=u, **kwargs):
+Constructor.
+
+@param site: Flow-enabled site
+@type site: Site
+@param title: normalized title of the page
+@type title: unicode
+
+@raise TypeError: incorrect use of parameters
+@raise ValueError: use of non-Flow-enabled Site
+
+super(Board, self).__init__(site, title, **kwargs)
+
+def _load(self):
+Load and cache the Board's data, derived from its topic list.
+if not hasattr(self, '_data'):
+self._data = self.site.topiclist(self)
+
+def _load_uuid(self):
+Load and save the UUID of the page.
+
+The UUID of the Board is derived from the workflowId field in the
+data returned by view-topiclist.
+
+if not hasattr(self, '_data'):
+self._load()
+self._uuid = self._data['workflowId']
+
+class Topic(FlowPage):
+
+A Flow discussion topic.
+
+def __init__(self, site, title=u, **kwargs):
+Constructor.
+
+@param site: Flow-enabled site
+@type site: Site
+@param title: normalized title of the page
+@type title: unicode
+
+@raise TypeError: incorrect use of parameters
+@raise ValueError: use of non-Flow-enabled Site
+
+super(Topic, self).__init__(site, title, **kwargs)
+
+def _load(self):
+Load and cache the Topic's data.
+if not hasattr(self, '_data'):
+self._data = self.site.topic(self)
+
+def _load_uuid(self):
+Load and save the UUID of the page.
+
+The UUID of the Topic is derived from the workflowId field in the
+data returned by view-topic.
+
+if not hasattr(self, '_data'):
+self._load()
+self._uuid = self._data['workflowId']
+
+class Post():
+
+A post to a Flow discussion topic.
+
+def __init__(self, site, page, uuid=u, **kwargs):
+
+Constructor
+
+@param site: Flow-enabled site
+@type site: Site
+@param page: Flow topic or board
+@type page: FlowPage
+@param uuid: UUID of a Flow post
+@type uuid: unicode
+
+@raise TypeError: incorrect types of parameters
+@raise ValueError: use of non-Flow-enabled Site or invalid UUID
+
+if not isinstance(site, 

[MediaWiki-commits] [Gerrit] Allow relative links to be handled in Link constructor - change (pywikibot/core)

2015-05-26 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/213816

Change subject: Allow relative links to be handled in Link constructor
..

Allow relative links to be handled in Link constructor

This patch allows a BasePage object to be passed in lieu of a Site
to the Link constructor. In this case, the link text will be handled
relative to the passed Page. This will allow for subpage links to be
parsed when relative links are used on the page. A new test, test_relative,
has been added to tests/link_tests.py to test this change.

Bug: T57113
Change-Id: Idd6366e82216c130b5143c9356245ff840af41ed
---
M pywikibot/page.py
M tests/link_tests.py
2 files changed, 21 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/16/213816/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 3f9c93a..240b99f 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4462,17 +4462,24 @@
 @type text: unicode
 @param source: the Site on which the link was found (not necessarily
 the site to which the link refers)
-@type source: Site
+@type source: Site or BasePage
 @param defaultNamespace: a namespace to use if the link does not
 contain one (defaults to 0)
 @type defaultNamespace: int
 
 
-assert source is None or isinstance(source, pywikibot.site.BaseSite), \
-source parameter should be a Site object
+
+source_is_page = isinstance(source, BasePage)
+
+assert source is None or source_is_page or isinstance(source, 
pywikibot.site.BaseSite), \
+source parameter should be either a Site or Page object
+
+if source_is_page:
+self._source = source.site
+else:
+self._source = source or pywikibot.Site()
 
 self._text = text
-self._source = source or pywikibot.Site()
 self._defaultns = defaultNamespace
 
 # preprocess text (these changes aren't site-dependent)
@@ -4515,6 +4522,9 @@
 t = t.replace(u\u200e, u).replace(u\u200f, u)
 self._text = t
 
+if source_is_page:
+self._text = source.title() + self._text
+
 def __repr__(self):
 Return a more complete string representation.
 return pywikibot.page.Link(%r, %r) % (self.title, self.site)
diff --git a/tests/link_tests.py b/tests/link_tests.py
index 83020ff..f094ff1 100644
--- a/tests/link_tests.py
+++ b/tests/link_tests.py
@@ -11,7 +11,7 @@
 
 import pywikibot
 from pywikibot import config2 as config
-from pywikibot.page import Link
+from pywikibot.page import Link, Page
 from pywikibot.exceptions import Error, InvalidTitle
 from tests.aspects import (
 unittest,
@@ -108,6 +108,12 @@
 self.assertRaises(InvalidTitle, Link('Category: ', 
self.get_site()).parse)
 self.assertRaises(InvalidTitle, Link('Category: #bar', 
self.get_site()).parse)
 
+def test_relative(self):
+Test that relative links are handled properly.
+p = Page(self.get_site(), 'A')
+l = Link('/B', p)
+self.assertEquals(l.title, 'A/B')
+self.assertEquals(l.site, self.get_site())
 
 #  The first set of tests are explicit links, starting with a ':'.
 

-- 
To view, visit https://gerrit.wikimedia.org/r/213816
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd6366e82216c130b5143c9356245ff840af41ed
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com
Gerrit-Reviewer: jenkins-bot 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Enabling the creation of Pages using links relative to anoth... - change (pywikibot/core)

2015-03-28 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/200328

Change subject: Enabling the creation of Pages using links relative to another 
Page
..

Enabling the creation of Pages using links relative to another Page

This commit allows the creation of Page objects using relative
links. (i.e. /foo) The BasePage constructor is modified to prepend
the title of a passed Page to the passed title, instead of only
using the passed title string. A new test, test_subpage, is added
to page_tests.py, containing equality and namespace checks.

Bug: T57113
Change-Id: Icac660e8fb49d3dc11582df952ff53789db58df3
---
M pywikibot/page.py
M tests/page_tests.py
2 files changed, 10 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/28/200328/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index e99694e..c0a5db8 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -125,7 +125,7 @@
  self.__dict__[k] is None)
 if title:
 # overwrite title
-self._link = Link(title, source=source.site,
+self._link = Link(source.title() + title, source=source.site,
   defaultNamespace=ns)
 elif isinstance(source, Link):
 self._link = source
diff --git a/tests/page_tests.py b/tests/page_tests.py
index d170cab..1ff1f53 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -312,6 +312,15 @@
 # Test not valid source.
 self.assertRaises(pywikibot.Error, pywikibot.Page, 'dummy')
 
+def test_subpage(self):
+Test creation of Pages for subpages using relative links.
+site = self.get_site()
+p1 = pywikibot.Page(site, uProject:Template:Test)
+p2 = pywikibot.Page(site, uProject:Template:Test/doc)
+p3 = pywikibot.Page(p1, u/doc)
+self.assertEqual(p2, p3)
+self.assertEqual(p3.namespace(), 4)
+
 def testTitle(self):
 Test title() method options in article namespace.
 # at last test article namespace

-- 
To view, visit https://gerrit.wikimedia.org/r/200328
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icac660e8fb49d3dc11582df952ff53789db58df3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Adding $message of caught WikitextException object to displa... - change (mediawiki...Flow)

2015-03-25 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/199816

Change subject: Adding $message of caught WikitextException object to displayed 
error
..

Adding $message of caught WikitextException object to displayed error

This commit pulls the $message field of a caught WikitextException object
and forwards it via the dieUsage method call. The message is passed as the
detail entry of the error object, meaning it will not be displayed to
the user.

Bug: T69000
Change-Id: I87cb484896ed1ac5369bf8c11b315d5f53ac3e8a
---
M includes/api/ApiParsoidUtilsFlow.php
1 file changed, 2 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/16/199816/1

diff --git a/includes/api/ApiParsoidUtilsFlow.php 
b/includes/api/ApiParsoidUtilsFlow.php
index 695adfa..0d13d8e 100644
--- a/includes/api/ApiParsoidUtilsFlow.php
+++ b/includes/api/ApiParsoidUtilsFlow.php
@@ -15,7 +15,8 @@
$content = Utils::convert( $params['from'], 
$params['to'], $params['content'], $page-getTitle() );
} catch ( WikitextException $e ) {
$code = $e-getErrorCode();
-   $this-dieUsage( $this-msg( $code 
)-inContentLanguage()-useDatabase( false )-plain(), $code );
+   $this-dieUsage( $this-msg( $code 
)-inContentLanguage()-useDatabase( false )-plain(), $code,
+   $e-getStatusCode(), array( 'detail' = 
$e-getMessage() ) );
return; // helps static analysis know execution does 
not continue past self::dieUsage
}
 

-- 
To view, visit https://gerrit.wikimedia.org/r/199816
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I87cb484896ed1ac5369bf8c11b315d5f53ac3e8a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Pre-fill fields in image dialog when image code is selected ... - change (mediawiki...WikiEditor)

2014-12-02 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/176927

Change subject: Pre-fill fields in image dialog when image code is selected in 
editor
..

Pre-fill fields in image dialog when image code is selected in editor

This commit adds a function to parse image syntax selected in the
editor and uses the parsed data to automatically fill the fields
of the WikiEditor image dialog. Surrounding whitespace in the
selected wikitext is now included in the result. This causes an
issue with the ownline option in line 840, which appends an extra
line regardless of the post text.

Bug: T40829
Change-Id: Ib117a2e6350400f9298d4892a00981ac41f3dbbf
---
M modules/jquery.wikiEditor.dialogs.config.js
1 file changed, 77 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiEditor 
refs/changes/27/176927/1

diff --git a/modules/jquery.wikiEditor.dialogs.config.js 
b/modules/jquery.wikiEditor.dialogs.config.js
index 8cd50a0..328c2db 100644
--- a/modules/jquery.wikiEditor.dialogs.config.js
+++ b/modules/jquery.wikiEditor.dialogs.config.js
@@ -797,8 +797,8 @@
width: 590,
buttons: {

'wikieditor-toolbar-tool-file-insert': function () {
-   var fileName, caption, 
fileFloat, fileFormat, fileSize, fileTitle,
-   options, 
fileUse,
+   var fileName, caption, 
fileFloat, fileFormat, fileSize, whitespace,
+   fileTitle, 
options, fileUse,
hasPxRgx = 
/.+px$/,
magicWordsI18N 
= mw.config.get( 'wgWikiEditorMagicWords' );
fileName = $( 
'#wikieditor-toolbar-file-target' ).val();
@@ -806,6 +806,7 @@
fileFloat = $( 
'#wikieditor-toolbar-file-float' ).val();
fileFormat = $( 
'#wikieditor-toolbar-file-format' ).val();
fileSize = $( 
'#wikieditor-toolbar-file-size' ).val();
+   whitespace = $( 
'#wikieditor-toolbar-file-dialog' ).data( 'whitespace' );
// Append px to end to 
size if not already contains it
if ( fileSize !== ''  
!hasPxRgx.test( fileSize ) ) {
fileSize += 
'px';
@@ -833,9 +834,9 @@
{
type: 
'replace',

options: {
-   
pre: '[[',
+   
pre: whitespace[0] + '[[',

peri: fileUse,
-   
post: ']]',
+   
post: ']]' + whitespace[1],

ownline: true
}
},
@@ -856,7 +857,79 @@
}
},
open: function () {
+   // Pre-fill the text fields 
based on the current selection
+   var context = $( this ).data( 
'context' );
+   // Restore and immediately save 
selection state, needed for inserting stuff later
+   
context.fn.restoreCursorAndScrollTop();
+   
context.fn.saveCursorAndScrollTop();
+   var selection = 
context.$textarea.textSelection( 'getSelection' );
+   // Set focus
$( 
'#wikieditor-toolbar-file-target' ).focus();
+   $( 
'#wikieditor-toolbar-file-dialog' ).data( 

[MediaWiki-commits] [Gerrit] Add QUnit test for ext.wikiEditor.toolbar - change (mediawiki...WikiEditor)

2014-11-25 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/175698

Change subject: Add QUnit test for ext.wikiEditor.toolbar
..

Add QUnit test for ext.wikiEditor.toolbar

This patch replaces the manually operated test module for ext.wikiEditor.toolbar
with one based on QUnit. The new test suite uncovered a bug with the 
removeFromToolbar
API function in jquery.wikiEditor.toolbar, which prevented the removal of 
select buttons
from the toolbar. This issue has also been fixed in this commit. .jshintrc was 
updated
to ignore the new QUnit global.

Bug: T39485
Change-Id: Icef3debcffa484a8d78628bcd9da0892b750bb40
---
M .jshintrc
M WikiEditor.hooks.php
M WikiEditor.php
D modules/ext.wikiEditor.tests.toolbar.js
M modules/jquery.wikiEditor.toolbar.js
A tests/qunit/ext.wikiEditor.toolbar.test.js
6 files changed, 303 insertions(+), 267 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiEditor 
refs/changes/98/175698/1

diff --git a/.jshintrc b/.jshintrc
index 5d335e3..81d1fa7 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -26,8 +26,9 @@
// Environment
browser: true,
 
-   predef: [
-   mediaWiki,
-   jQuery
-   ]
+   globals: {
+   mediaWiki: false,
+   jQuery: false,
+   QUnit: false
+   }
 }
diff --git a/WikiEditor.hooks.php b/WikiEditor.hooks.php
index 9226baa..11e461e 100644
--- a/WikiEditor.hooks.php
+++ b/WikiEditor.hooks.php
@@ -225,9 +225,6 @@
}
 
/**
-* MakeGlobalVariablesScript hook
-*
-* Adds enabled/disabled switches for WikiEditor modules
 * @param $vars array
 * @return bool
 */
@@ -255,6 +252,28 @@
}
 
/**
+* ResourceLoaderTestModules hook
+* 
+* Registers JavaScript test modules
+* 
+* @param $testModules array of javascript testing modules. 'qunit' is 
fed using tests/qunit/QUnitTestResources.php.
+* @param $resourceLoader object
+* @return bool
+*/
+   public static function resourceLoaderTestModules( $testModules, 
$resourceLoader ) {
+   $testModules['qunit']['ext.wikiEditor.toolbar.test'] = array(
+   'scripts' = array( 
'tests/qunit/ext.wikiEditor.toolbar.test.js' ),
+   'dependencies' = array( 'ext.wikiEditor.toolbar' ),
+   'localBasePath' = dirname( __FILE__ ),
+   'remoteExtPath' = 'WikiEditor',
+   );
+   return true;
+   }
+
+   /**
+* MakeGlobalVariablesScript hook
+*
+* Adds enabled/disabled switches for WikiEditor modules
 * @param $vars array
 * @return bool
 */
diff --git a/WikiEditor.php b/WikiEditor.php
index df36911..e205e5e 100644
--- a/WikiEditor.php
+++ b/WikiEditor.php
@@ -52,6 +52,7 @@
 $GLOBALS['wgHooks']['EditPage::showEditForm:initial'][] = 
'WikiEditorHooks::editPageShowEditFormInitial';
 $GLOBALS['wgHooks']['GetPreferences'][] = 'WikiEditorHooks::getPreferences';
 $GLOBALS['wgHooks']['ResourceLoaderGetConfigVars'][] = 
'WikiEditorHooks::resourceLoaderGetConfigVars';
+$GLOBALS['wgHooks']['ResourceLoaderTestModules'][] = 
'WikiEditorHooks::resourceLoaderTestModules';
 $GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 
'WikiEditorHooks::makeGlobalVariablesScript';
 $GLOBALS['wgHooks']['EditPageBeforeEditToolbar'][] = 
'WikiEditorHooks::EditPageBeforeEditToolbar';
 
@@ -412,10 +413,6 @@
'wikieditor-publish-dialog-publish',
'wikieditor-publish-dialog-goback',
),
-   ),
-   'ext.wikiEditor.tests.toolbar' = $wikiEditorTpl + array(
-   'scripts' = 'ext.wikiEditor.tests.toolbar.js',
-   'dependencies' = 'ext.wikiEditor.toolbar',
),
'ext.wikiEditor.toolbar' = $wikiEditorTpl + array(
'scripts' = 'ext.wikiEditor.toolbar.js',
diff --git a/modules/ext.wikiEditor.tests.toolbar.js 
b/modules/ext.wikiEditor.tests.toolbar.js
deleted file mode 100644
index 3475284..000
--- a/modules/ext.wikiEditor.tests.toolbar.js
+++ /dev/null
@@ -1,255 +0,0 @@
-/**
- * Test set for the edit toolbar
- */
-var textareaId = '#wpTextbox1';
-var wikiEditorTests = {
-   // Add emoticons section
-   'add_sections_toolbar': {
-   call: 'addToToolbar',
-   data: {
-   'sections': {
-   'emoticons': {
-   'type': 'toolbar',
-   'label': 'Emoticons'
-   }
-   }
-   },
-   test: '*[rel=emoticons].section',
-   pre: 0,
-   post: 1
-   },
-   // Add faces group to emoticons section
-   'add_groups': {
-  

[MediaWiki-commits] [Gerrit] Accept mw.title object as the title argument of frame:expand... - change (mediawiki...Scribunto)

2014-04-10 Thread Happy5214 (Code Review)
Happy5214 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/125207

Change subject: Accept mw.title object as the title argument of 
frame:expandTemplate()
..

Accept mw.title object as the title argument of frame:expandTemplate()

This commit fixes an error with using a mw.title object referring to a
mainspace page as the title argument to frame:expandTemplate(), by
adding a leading colon to prevent the function from searching in the
Template namespace.

Bug: 47601
Change-Id: I4cdc05571598bf7998f4cf0f2691bf86188c3c5d
---
M engines/LuaCommon/lualib/mw.lua
1 file changed, 5 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto 
refs/changes/07/125207/1

diff --git a/engines/LuaCommon/lualib/mw.lua b/engines/LuaCommon/lualib/mw.lua
index 4bc3e4b..d6d4e4c 100644
--- a/engines/LuaCommon/lualib/mw.lua
+++ b/engines/LuaCommon/lualib/mw.lua
@@ -398,7 +398,11 @@
if opt.title == nil then
error( frame:expandTemplate: a title is required )
else
-   title = tostring( opt.title )
+   if type( opt.title ) == 'table' and opt.title.namespace 
== 0 then
+   title = ':' .. tostring( opt.title )
+   else
+   title = tostring( opt.title )
+   end
end
local args
if opt.args == nil then

-- 
To view, visit https://gerrit.wikimedia.org/r/125207
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4cdc05571598bf7998f4cf0f2691bf86188c3c5d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Happy5214 happy5...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits