* (bug 27182) API: Add filter by prefix for meta=allmessages
authorSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 00:15:02 +0000 (00:15 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 00:15:02 +0000 (00:15 +0000)
Patch by Harry Burt (Jarry1250)

Comment tweaked, logic inversed ( so skip == true means we skip ), makes a bit more sense then :)

RELEASE-NOTES
includes/api/ApiQueryAllmessages.php

index 371932c..bbee46a 100644 (file)
@@ -246,6 +246,7 @@ PHP if you have not done so prior to upgrading MediaWiki.
   groups if a user doesn't have explicit groups
 * (bug 27670) Ordering by timestamp (and usage of start and end) isn't as clear
   in auto generated document, as it is on mw.org
+* (bug 27182) API: Add filter by prefix for meta=allmessages
 
 
 === Languages updated in 1.18 ===
index 709f1f9..30ffeb1 100644 (file)
@@ -71,8 +71,27 @@ class ApiQueryAllmessages extends ApiQueryBase {
                } else {
                        $messages_target = $params['messages'];
                }
-
-               // Filter messages
+               
+               // Filter messages that have the specified prefix
+               // Because we sorted the message array earlier, they will appear in a clump:
+               if ( isset( $params['prefix'] ) ) {
+                       $skip = false;
+                       $messages_filtered = array();
+                       foreach ( $messages_target as $message ) {
+                               // === 0: must be at beginning of string (position 0)
+                               if ( strpos( $message, $params['prefix'] ) === 0 ) {
+                                       if( !$skip ) {
+                                               $skip = true;
+                                       }
+                                       $messages_filtered[] = $message;
+                               } else if ( $skip ) {
+                                       break;
+                               }
+                       }
+                       $messages_target = $messages_filtered;
+               }
+                       
+               // Filter messages that contain specified string
                if ( isset( $params['filter'] ) ) {
                        $messages_filtered = array();
                        foreach ( $messages_target as $message ) {
@@ -170,18 +189,20 @@ class ApiQueryAllmessages extends ApiQueryBase {
                        'from' => null,
                        'to' => null,
                        'title' => null,
+                       'prefix' => null,
                );
        }
 
        public function getParamDescription() {
                return array(
-                       'messages' => 'Which messages to output. "*" means all messages',
+                       'messages' => 'Which messages to output. "*" (default) means all messages',
                        'prop' => 'Which properties to get',
                        'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
                                                          'Will substitute magic words, handle templates etc.' ),
                        'title' => 'Page name to use as context when parsing message (for enableparser option)',
                        'args' => 'Arguments to be substituted into message',
-                       'filter' => 'Return only messages that contain this string',
+                       'prefix' => 'Return messages with this prefix',
+                       'filter' => 'Return only messages with names that contain this string',
                        'lang' => 'Return messages in this language',
                        'from' => 'Return messages starting at this message',
                        'to' => 'Return messages ending at this message',
@@ -194,7 +215,7 @@ class ApiQueryAllmessages extends ApiQueryBase {
 
        protected function getExamples() {
                return array(
-                       'api.php?action=query&meta=allmessages&amfilter=ipb-',
+                       'api.php?action=query&meta=allmessages&amprefix=ipb-',
                        'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
                );
        }