Skip to content

Commit b8e7242

Browse files
author
Marcin Cieślak
committed
Handle Special:Mypage/skin.css and js files properly
* Allow the page owner to put custom styles and scripts * Check editusercss or edituserjs permissions introduced in 1.16 in addition to the obsolete editusercssjs https://bugzilla.wikimedia.org/show_bug.cgi?id=12110
1 parent 202a989 commit b8e7242

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

wikipedia.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,11 +1690,18 @@ def put(self, newtext, comment=None, watchArticle=None, minorEdit=True,
16901690
elif self.site().has_api() and self.namespace() in [2,3] \
16911691
and (self.title().endswith('.css') or \
16921692
self.title().endswith('.js')):
1693-
# API enable: if title ends with .css or .js in ns2,3
1694-
# it needs permission 'editusercssjs'
1695-
sysop = self._getActionUser(action='editusercssjs',
1696-
restriction=self.editRestriction,
1697-
sysop=True)
1693+
titleparts = self.title().split("/")
1694+
userpageowner = titleparts[0].split(":")[1]
1695+
if userpageowner != username:
1696+
# API enable: if title ends with .css or .js in ns2,3
1697+
# it needs permission to edit user pages
1698+
if self.title().endswith('css'):
1699+
permission = 'editusercss'
1700+
else:
1701+
permission = 'edituserjs'
1702+
sysop = self._getActionUser(action=permission,
1703+
restriction=self.editRestriction,
1704+
sysop=True)
16981705

16991706
# If there is an unchecked edit restriction, we need to load the page
17001707
if self._editrestriction:
@@ -4940,6 +4947,10 @@ def isAllowed(self, right, sysop = False):
49404947
else:
49414948
self._load(sysop = sysop)
49424949
index = self._userIndex(sysop)
4950+
# Handle obsolete editusercssjs permission
4951+
if right in ['editusercss', 'edituserjs'] \
4952+
and right not in self._rights[index]:
4953+
return 'editusercssjs' in self._rights[index]
49434954
return right in self._rights[index]
49444955

49454956
def server_time(self):

0 commit comments

Comments
 (0)