Dalba has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364423 )

Change subject: site.categorymembers: Support cmstartsortkeyprefix API parameter
......................................................................

site.categorymembers: Support cmstartsortkeyprefix API parameter

site.py:

    The old `startsort` is passed to API as `cmstartsortkey` which is deprecated
    and is not compatible with `cmstartsortkeyprefix`. Also working with
    `startsort` is difficult as it should be a "binary string" usually obtained
    via API or directrly from database. (See T74101)

    Add two new parameters, `startprefix` and `endprefix`, to be passed to API
    as `cmstartsortkeyprefix` and `cmendsortkeyprefix`.

    Fix the docstring for `startsort` and `endsort`. They are in binary string
    format and connot be compared with a title directly. Also mention that they
    are deprecated in MW 1.24.

page.py:

    Add the new parameters to `Category.articles`.

Bug: T170265
Change-Id: I08f4a7a4bb1bbe5c10fe678cc7a951a273f61d07
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 56 insertions(+), 15 deletions(-)


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

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 32663d6..6ff08c8 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2774,7 +2774,9 @@
     def articles(self, recurse=False, total=None,
                  content=False, namespaces=None, sortby=None,
                  reverse=False, starttime=None, endtime=None,
-                 startsort=None, endsort=None):
+                 startsort=None, endsort=None,
+                 startprefix=None, endprefix=None,
+                 ):
         """
         Yield all articles in the current category.
 
@@ -2805,12 +2807,22 @@
         @param endtime: if provided, only generate pages added before this
             time; not valid unless sortby="timestamp"
         @type endtime: pywikibot.Timestamp
-        @param startsort: if provided, only generate pages >= this title
-            lexically; not valid if sortby="timestamp"
+        @param startsort: if provided, only generate pages that have a
+            sortkey >= startsort; not valid if sortby="timestamp"
+            (Deprecated in MW 1.24)
         @type startsort: str
-        @param endsort: if provided, only generate pages <= this title
-            lexically; not valid if sortby="timestamp"
+        @param endsort: if provided, only generate pages that have a
+            sortkey <= endsort; not valid if sortby="timestamp"
+            (Deprecated in MW 1.24)
         @type endsort: str
+        @param startprefix: if provided, only generate pages >= this title
+            lexically; not valid if sortby="timestamp"; overrides "startsort"
+            (requires MW 1.18+)
+        @type startprefix: str
+        @param endprefix: if provided, only generate pages < this title
+            lexically; not valid if sortby="timestamp"; overrides "endsort"
+            (requires MW 1.18+)
+        @type endprefix: str
         """
         for member in self.site.categorymembers(self,
                                                 namespaces=namespaces,
@@ -2820,6 +2832,8 @@
                                                 starttime=starttime,
                                                 endtime=endtime,
                                                 startsort=startsort,
+                                                startprefix=startprefix,
+                                                endprefix=endprefix,
                                                 endsort=endsort,
                                                 member_type=['page', 'file']
                                                 ):
@@ -2840,7 +2854,9 @@
                                                starttime=starttime,
                                                endtime=endtime,
                                                startsort=startsort,
-                                               endsort=endsort
+                                               endsort=endsort,
+                                               startprefix=startprefix,
+                                               endprefix=endprefix,
                                                ):
                     yield article
                     if total is not None:
diff --git a/pywikibot/site.py b/pywikibot/site.py
index e2bc6cc..6646ab4 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3742,7 +3742,9 @@
     def categorymembers(self, category, namespaces=None, sortby=None,
                         reverse=False, starttime=None, endtime=None,
                         startsort=None, endsort=None, total=None,
-                        content=False, member_type=None):
+                        content=False, member_type=None,
+                        startprefix=None, endprefix=None,
+                        ):
         """Iterate members of specified category.
 
         @param category: The Category to iterate.
@@ -3764,13 +3766,22 @@
         @type starttime: pywikibot.Timestamp
         @param endtime: if provided, only generate pages added before this
             time; not valid unless sortby="timestamp"
-        @type endtime: pywikibot.Timestamp
-        @param startsort: if provided, only generate pages >= this title
-            lexically; not valid if sortby="timestamp"
+        @param startsort: if provided, only generate pages that have a
+            sortkey >= startsort; not valid if sortby="timestamp"
+            (Deprecated in MW 1.24)
         @type startsort: str
-        @param endsort: if provided, only generate pages <= this title
-            lexically; not valid if sortby="timestamp"
+        @param endsort: if provided, only generate pages that have a
+            sortkey <= endsort; not valid if sortby="timestamp"
+            (Deprecated in MW 1.24)
         @type endsort: str
+        @param startprefix: if provided, only generate pages >= this title
+            lexically; not valid if sortby="timestamp"; overrides "startsort"
+            (requires MW 1.18+)
+        @type startprefix: str
+        @param endprefix: if provided, only generate pages < this title
+            lexically; not valid if sortby="timestamp"; overrides "endsort"
+            (requires MW 1.18+)
+        @type endprefix: str
         @param content: if True, load the current content of each iterated page
             (default False)
         @type content: bool
@@ -3799,7 +3810,10 @@
         if starttime and endtime and starttime > endtime:
             raise ValueError(
                 "categorymembers: starttime must be before endtime")
-        if startsort and endsort and startsort > endsort:
+        if startprefix and endprefix and startprefix > endprefix:
+            raise ValueError(
+                "categorymembers: startprefix must be less than endprefix")
+        elif startsort and endsort and startsort > endsort:
             raise ValueError(
                 "categorymembers: startsort must be less than endsort")
 
@@ -3854,6 +3868,7 @@
             # sort; we take care of this reversal for the user
             (starttime, endtime) = (endtime, starttime)
             (startsort, endsort) = (endsort, startsort)
+            (startprefix, endprefix) = (endprefix, startprefix)
         if starttime and sortby == "timestamp":
             cmargs["gcmstart"] = starttime
         elif starttime:
@@ -3864,12 +3879,22 @@
         elif endtime:
             raise ValueError("categorymembers: "
                              "invalid combination of 'sortby' and 'endtime'")
-        if startsort and sortby != "timestamp":
+        if startprefix and sortby != 'timestamp':
+            cmargs['gcmstartsortkeyprefix'] = startprefix
+        elif startprefix:
+            raise ValueError("categorymembers: invalid combination of "
+                             "'sortby' and 'startprefix'")
+        elif startsort and sortby != 'timestamp':
             cmargs["gcmstartsortkey"] = startsort
         elif startsort:
             raise ValueError("categorymembers: "
                              "invalid combination of 'sortby' and 'startsort'")
-        if endsort and sortby != "timestamp":
+        if endprefix and sortby != 'timestamp':
+            cmargs['cmendsortkeyprefix'] = endprefix
+        elif endprefix:
+            raise ValueError("categorymembers: "
+                             "invalid combination of 'sortby' and 'endprefix'")
+        elif endsort and sortby != 'timestamp':
             cmargs["gcmendsortkey"] = endsort
         elif endsort:
             raise ValueError("categorymembers: "

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I08f4a7a4bb1bbe5c10fe678cc7a951a273f61d07
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to