r83800 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83799‎ | r83800 | r83801 >
Date:00:15, 13 March 2011
Author:reedy
Status:ok
Tags:
Comment:
* (bug 27182) API: Add filter by prefix for meta=allmessages

Patch by Harry Burt (Jarry1250)

Comment tweaked, logic inversed ( so skip == true means we skip ), makes a bit more sense then :)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllmessages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllmessages.php
@@ -71,8 +71,27 @@
7272 } else {
7373 $messages_target = $params['messages'];
7474 }
75 -
76 - // Filter messages
 75+
 76+ // Filter messages that have the specified prefix
 77+ // Because we sorted the message array earlier, they will appear in a clump:
 78+ if ( isset( $params['prefix'] ) ) {
 79+ $skip = false;
 80+ $messages_filtered = array();
 81+ foreach ( $messages_target as $message ) {
 82+ // === 0: must be at beginning of string (position 0)
 83+ if ( strpos( $message, $params['prefix'] ) === 0 ) {
 84+ if( !$skip ) {
 85+ $skip = true;
 86+ }
 87+ $messages_filtered[] = $message;
 88+ } else if ( $skip ) {
 89+ break;
 90+ }
 91+ }
 92+ $messages_target = $messages_filtered;
 93+ }
 94+
 95+ // Filter messages that contain specified string
7796 if ( isset( $params['filter'] ) ) {
7897 $messages_filtered = array();
7998 foreach ( $messages_target as $message ) {
@@ -170,18 +189,20 @@
171190 'from' => null,
172191 'to' => null,
173192 'title' => null,
 193+ 'prefix' => null,
174194 );
175195 }
176196
177197 public function getParamDescription() {
178198 return array(
179 - 'messages' => 'Which messages to output. "*" means all messages',
 199+ 'messages' => 'Which messages to output. "*" (default) means all messages',
180200 'prop' => 'Which properties to get',
181201 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
182202 'Will substitute magic words, handle templates etc.' ),
183203 'title' => 'Page name to use as context when parsing message (for enableparser option)',
184204 'args' => 'Arguments to be substituted into message',
185 - 'filter' => 'Return only messages that contain this string',
 205+ 'prefix' => 'Return messages with this prefix',
 206+ 'filter' => 'Return only messages with names that contain this string',
186207 'lang' => 'Return messages in this language',
187208 'from' => 'Return messages starting at this message',
188209 'to' => 'Return messages ending at this message',
@@ -194,7 +215,7 @@
195216
196217 protected function getExamples() {
197218 return array(
198 - 'api.php?action=query&meta=allmessages&amfilter=ipb-',
 219+ 'api.php?action=query&meta=allmessages&amprefix=ipb-',
199220 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
200221 );
201222 }
Index: trunk/phase3/RELEASE-NOTES
@@ -246,6 +246,7 @@
247247 groups if a user doesn't have explicit groups
248248 * (bug 27670) Ordering by timestamp (and usage of start and end) isn't as clear
249249 in auto generated document, as it is on mw.org
 250+* (bug 27182) API: Add filter by prefix for meta=allmessages
250251
251252
252253 === Languages updated in 1.18 ===

Status & tagging log