Merge "SpecialPage: DRY array filter for prefixSearchSubpages()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 26 Jun 2014 15:44:29 +0000 (15:44 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 26 Jun 2014 15:44:29 +0000 (15:44 +0000)
includes/specialpage/SpecialPage.php
includes/specials/SpecialEditWatchlist.php
includes/specials/SpecialLog.php
includes/specials/SpecialWatchlist.php

index c062e27..4cfde33 100644 (file)
@@ -335,6 +335,21 @@ class SpecialPage {
                return array();
        }
 
+       /**
+        * Helper function for implementations of prefixSearchSubpages() that
+        * filter the values in memory (as oppposed to making a query).
+        *
+        * @since 1.24
+        * @param string $search
+        * @param int $limit
+        * @param array $subpages
+        * @return string[]
+        */
+       protected static function prefixSearchArray( $search, $limit, Array $subpages ) {
+               $escaped = preg_quote( $search );
+               return array_slice( preg_grep( "/^$escaped/i", $subpages ), 0, $limit );
+       }
+
        /**
         * Sets headers - this should be called from the execute() method of all derived classes!
         */
index 02d8d70..369f11f 100644 (file)
@@ -125,11 +125,16 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
         * @return string[] Matching subpages
         */
        public function prefixSearchSubpages( $search, $limit = 10 ) {
-               // SpecialWatchlist uses SpecialEditWatchlist::getMode, so new types should be added
-               // here and there - no 'edit' here, because that the default for this page
-               $subpages = array( 'clear', 'raw' );
-               $escaped = preg_quote( $search );
-               return array_slice( preg_grep( "/^$escaped/i", $subpages ), 0, $limit );
+               return self::prefixSearchArray(
+                       $search,
+                       $limit,
+                       // SpecialWatchlist uses SpecialEditWatchlist::getMode, so new types should be added
+                       // here and there - no 'edit' here, because that the default for this page
+                       array(
+                               'clear',
+                               'raw',
+                       )
+               );
        }
 
        /**
index aaa55a3..ced5d25 100644 (file)
@@ -127,8 +127,7 @@ class SpecialLog extends SpecialPage {
                $subpages = $wgLogTypes;
                $subpages[] = 'all';
                sort( $subpages );
-               $escaped = preg_quote( $search );
-               return array_slice( preg_grep( "/^$escaped/i", $subpages ), 0, $limit );
+               return self::prefixSearchArray( $search, $limit, $subpages );
        }
 
        private function parseParams( FormOptions $opts, $par ) {
index 9c28d06..21a1f9b 100644 (file)
@@ -88,9 +88,15 @@ class SpecialWatchlist extends ChangesListSpecialPage {
         */
        public function prefixSearchSubpages( $search, $limit = 10 ) {
                // See also SpecialEditWatchlist::prefixSearchSubpages
-               $subpages = array( 'clear', 'edit', 'raw' );
-               $escaped = preg_quote( $search );
-               return array_slice( preg_grep( "/^$escaped/i", $subpages ), 0, $limit );
+               return self::prefixSearchArray(
+                       $search,
+                       $limit,
+                       array(
+                               'clear',
+                               'edit',
+                               'raw',
+                       )
+               );
        }
 
        /**