Filippo Giunchedi has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/262068 )

Change subject: Optionally filter private wiki results in mwgrep
......................................................................


Optionally filter private wiki results in mwgrep

Bug: T71581
Change-Id: Ie893e3d2953b246eaa54e6805a6063923f063ec5
---
M modules/scap/files/mwgrep
1 file changed, 19 insertions(+), 4 deletions(-)

Approvals:
  Krinkle: Looks good to me, but someone else must approve
  jenkins-bot: Verified
  Filippo Giunchedi: Looks good to me, approved



diff --git a/modules/scap/files/mwgrep b/modules/scap/files/mwgrep
index 3e84938..0f7671c 100755
--- a/modules/scap/files/mwgrep
+++ b/modules/scap/files/mwgrep
@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 """
   usage: mwgrep [-h] [--max-results N] [--timeout N] [--user | --module]
-                [--title TITLE | --etitle REGEX] regex
+                [--title TITLE | --etitle REGEX] [--no-private] regex
 
   Grep for Lua or CSS and JS code fragments on (per default) MediaWiki wiki 
pages
 
@@ -17,6 +17,7 @@
     --module         search NS_MODULE rather than NS_MEDIAWIKI
     --title TITLE    restrict search to pages with this exact title
     --etitle REGEX   restrict search to pages with this title pattern
+    --no-private     show only results from public wikis (may result in less 
than max-results results)
 
   mwgrep will grep the MediaWiki namespace across Wikimedia wikis. specify
   --user to search the user namespace instead. See the lucene documentation
@@ -68,6 +69,12 @@
     type='{0}s'.format,
     default='30',
     help='abort search after this many seconds (default: 30)'
+)
+
+ap.add_argument(
+    '--no-private',
+    action='store_true',
+    help='Restricts search to public wikis'
 )
 
 ns_group = ap.add_mutually_exclusive_group()
@@ -154,11 +161,19 @@
             bisect.insort(matches['public'], (db_name, page_name))
 
     if matches['public']:
-        print('## Public wiki results')
+        if matches['private'] and args.no_private is False:
+             print('## Public wiki results')
         for db_name, page_name in matches['public']:
             print('{:<20}{}'.format(db_name, page_name))
 
-    if matches['private']:
+    total = result['total']
+    hits = len(result['hits'])
+
+    if args.no_private:
+        private_len = len(matches['private'])
+        total -= private_len
+        hits -= private_len
+    elif matches['private']:
         if matches['public']:
             print('')
         print('## Private wiki results')
@@ -166,7 +181,7 @@
             print('{:<20}{}'.format(db_name, page_name))
 
     print('')
-    print('(total: %s, shown: %s)' % (result['total'], len(result['hits'])))
+    print('(total: %s, shown: %s)' % (total, hits))
     if full_result['timed_out']:
         print("""
 The query was unable to complete within the alloted time. Only partial results

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie893e3d2953b246eaa54e6805a6063923f063ec5
Gerrit-PatchSet: 8
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Reedy <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to