Allow wildcard searching in wiki IDs for interwiki user rights logs
authorAlex Monk <krenair@gmail.com>
Tue, 12 Feb 2013 19:33:23 +0000 (19:33 +0000)
committerReedy <reedy@wikimedia.org>
Sat, 25 Jan 2014 04:11:17 +0000 (04:11 +0000)
Bug: 10545
Change-Id: I21331d44e5501af3322d0f48dc52001ac5579402

includes/logging/LogPager.php

index 900ece9..2321300 100644 (file)
@@ -207,6 +207,17 @@ class LogPager extends ReverseChronologicalPager {
                $ns = $title->getNamespace();
                $db = $this->mDb;
 
+               if ( $this->types == array( 'rights' ) ) {
+                       global $wgUserrightsInterwikiDelimiter;
+                       $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBKey() );
+                       if ( count( $parts ) == 2 ) {
+                               list( $name, $database ) = array_map( 'trim', $parts );
+                               if ( strstr( $database, '*' ) ) { // Search for wildcard in database name
+                                       $doUserRightsLogLike = true;
+                               }
+                       }
+               }
+
                # Using the (log_namespace, log_title, log_timestamp) index with a
                # range scan (LIKE) on the first two parts, instead of simple equality,
                # makes it unusable for sorting.  Sorted retrieval using another index
@@ -218,12 +229,19 @@ class LogPager extends ReverseChronologicalPager {
                # use the page_time index.  That should have no more than a few hundred
                # log entries for even the busiest pages, so it can be safely scanned
                # in full to satisfy an impossible condition on user or similar.
-               if ( $pattern && !$wgMiserMode ) {
-                       $this->mConds['log_namespace'] = $ns;
-                       $this->mConds[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() );
+               $this->mConds['log_namespace'] = $ns;
+               if ( $doUserRightsLogLike ) {
+                       $params = array( $name . $wgUserrightsInterwikiDelimiter );
+                       foreach ( explode( '*', $database ) as $databasepart ) {
+                               $params[] = $databasepart;
+                               $params[] = $db->anyString();
+                       }
+                       array_pop( $params ); // Get rid of the last % we added.
+                       $this->mConds[] = 'log_title' . $db->buildLike( $params );
+               } elseif ( $pattern && !$wgMiserMode ) {
+                       $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() );
                        $this->pattern = $pattern;
                } else {
-                       $this->mConds['log_namespace'] = $ns;
                        $this->mConds['log_title'] = $title->getDBkey();
                }
                // Paranoia: avoid brute force searches (bug 17342)