r101124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101123‎ | r101124 | r101125 >
Date:09:13, 28 October 2011
Author:nikerabbit
Status:ok (Comments)
Tags:
Comment:
Allow filtering by properties in the API.
Had to drop preconstructed list of allowed filters, because with values the can be arbitrary.
Used as : as key:value separator, because = is already reserved in query parameters
Modified paths:
  • /trunk/extensions/Translate/api/ApiQueryMessageCollection.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/api/ApiQueryMessageCollection.php
@@ -46,13 +46,17 @@
4747 $messages->setInFile( $group->load( $params['language'] ) );
4848
4949 foreach ( $params['filter'] as $filter ) {
 50+ $value = null;
 51+ if ( strpos( $filter, ':' ) !== false ) {
 52+ list( $filter, $value ) = explode( ':', $filter, 2 );
 53+ }
5054 /* The filtering params here are swapped wrt MessageCollection.
5155 * There (fuzzy) means do not show fuzzy, which is the same as !fuzzy
5256 * here and fuzzy here means (fuzzy, false) there. */
5357 if ( $filter[0] === '!' ) {
54 - $messages->filter( substr( $filter, 1 ) );
 58+ $messages->filter( substr( $filter, 1 ), true, $value );
5559 } else {
56 - $messages->filter( $filter, false );
 60+ $messages->filter( $filter, false, $value );
5761 }
5862 }
5963
@@ -112,19 +116,6 @@
113117 return $data;
114118 }
115119
116 - /**
117 - * @return array
118 - */
119 - public function getFilters() {
120 - $basic = MessageCollection::getAvailableFilters();
121 - $full = array();
122 - foreach ( $basic as $filter ) {
123 - $full[] = $filter;
124 - $full[] = "!$filter";
125 - }
126 - return $full;
127 - }
128 -
129120 public function getAllowedParams() {
130121
131122 // Ugly code for BC <= 1.16
@@ -156,7 +147,7 @@
157148 ApiBase::PARAM_TYPE => 'integer',
158149 ),
159150 'filter' => array(
160 - ApiBase::PARAM_TYPE => $this->getFilters(),
 151+ ApiBase::PARAM_TYPE => 'string',
161152 ApiBase::PARAM_DFLT => '!optional|!ignored',
162153 ApiBase::PARAM_ISMULTI => true,
163154 ),
@@ -188,6 +179,7 @@
189180 'hastranslation - messages which have a translation regardless if it is fuzzy or not',
190181 'translated - messages which have a translation which is not fuzzy',
191182 'changed - messages which has been translated or changed since last export',
 183+ 'reviewer:# - messages where given userid # is among reviewers',
192184 ),
193185 );
194186 }

Comments

#Comment by Nikerabbit (talk | contribs)   09:14, 28 October 2011

Forgot to mention, this is Internationalization/#146

Status & tagging log