http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83800
Revision: 83800 Author: reedy Date: 2011-03-13 00:15:02 +0000 (Sun, 13 Mar 2011) Log Message: ----------- * (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 trunk/phase3/includes/api/ApiQueryAllmessages.php Modified: trunk/phase3/RELEASE-NOTES =================================================================== --- trunk/phase3/RELEASE-NOTES 2011-03-13 00:07:22 UTC (rev 83799) +++ trunk/phase3/RELEASE-NOTES 2011-03-13 00:15:02 UTC (rev 83800) @@ -246,6 +246,7 @@ 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 === Modified: trunk/phase3/includes/api/ApiQueryAllmessages.php =================================================================== --- trunk/phase3/includes/api/ApiQueryAllmessages.php 2011-03-13 00:07:22 UTC (rev 83799) +++ trunk/phase3/includes/api/ApiQueryAllmessages.php 2011-03-13 00:15:02 UTC (rev 83800) @@ -71,8 +71,27 @@ } 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 @@ '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 @@ protected function getExamples() { return array( - 'api.php?action=query&meta=allmessages&amfilter=ipb-', + 'api.php?action=query&meta=allmessages&refix=ipb-', 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de', ); } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs