From e6853e1bfab1547a3a29d92868e22fd6e05a14b2 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 13 Mar 2011 00:15:02 +0000 Subject: [PATCH] * (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 :) --- RELEASE-NOTES | 1 + includes/api/ApiQueryAllmessages.php | 31 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 371932c262..bbee46af95 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index 709f1f9001..30ffeb1831 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -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&refix=ipb-', 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de', ); } -- 2.20.1