r100971 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100970‎ | r100971 | r100972 >
Date:13:12, 27 October 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Allow filtering by property values.
Converted recently added reviewers to a property
Internationalization/#145
Modified paths:
  • /trunk/extensions/Translate/Message.php (modified) (history)
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageCollection.php
@@ -49,8 +49,13 @@
5050 * Tags, copied to thin messages
5151 * tagtype => keys
5252 */
53 - protected $tags = array(); //
 53+ protected $tags = array();
5454
 55+ /**
 56+ * Properties, copied to thin messages
 57+ */
 58+ protected $properties = array();
 59+
5560 /// \list{String} Authors.
5661 protected $authors = array();
5762
@@ -225,6 +230,7 @@
226231 $this->keys = $this->fixKeys( array_keys( $this->definitions->messages ) );
227232 $this->dbInfo = null;
228233 $this->dbData = null;
 234+ $this->dbReviewData = null;
229235 $this->messages = null;
230236 $this->infile = array();
231237 $this->authors = array();
@@ -261,21 +267,14 @@
262268 * (INFILE, TRANSLATIONS)
263269 * @param $condition \bool Whether to return messages which do not satisfy
264270 * the given filter condition (true), or only which do (false).
 271+ * @param $value Mixed Value for properties filtering.
265272 * @throws \type{MWException} If given invalid filter name.
266273 */
267 - public function filter( $type, $condition = true ) {
268 - switch( $type ) {
269 - case 'fuzzy':
270 - case 'optional':
271 - case 'ignored':
272 - case 'hastranslation':
273 - case 'changed':
274 - case 'translated':
275 - $this->applyFilter( $type, $condition );
276 - break;
277 - default:
278 - throw new MWException( "Unknown filter $type" );
 274+ public function filter( $type, $condition = true, $value = null ) {
 275+ if ( !in_array( $type, self::getAvailableFilters(), true ) ) {
 276+ throw new MWException( "Unknown filter $type" );
279277 }
 278+ $this->applyFilter( $type, $condition, $value );
280279 }
281280
282281 /**
@@ -296,9 +295,10 @@
297296 * Really apply a filter. Some filters need multiple conditions.
298297 * @param $filter \string Filter name.
299298 * @param $condition \bool Whether to return messages which do not satisfy
 299+ * @param $value Mixed Value for properties filtering.
300300 * the given filter condition (true), or only which do (false).
301301 */
302 - protected function applyFilter( $filter, $condition ) {
 302+ protected function applyFilter( $filter, $condition, $value ) {
303303 $keys = $this->keys;
304304 if ( $filter === 'fuzzy' ) {
305305 $keys = $this->filterFuzzy( $keys, $condition );
@@ -647,6 +647,15 @@
648648 }
649649 }
650650
 651+ // Copy properties if any.
 652+ foreach ( $this->properties as $type => $keys ) {
 653+ foreach ( $keys as $key => $value ) {
 654+ if ( isset( $messages[$key] ) ) {
 655+ $messages[$key]->setProperty( $type, $value );
 656+ }
 657+ }
 658+ }
 659+
651660 // Copy infile if any.
652661 foreach ( $this->infile as $key => $value ) {
653662 if ( isset( $messages[$key] ) ) {
@@ -660,7 +669,7 @@
661670 continue;
662671 }
663672 $key = $flipKeys[$row->page_title];
664 - $messages[$key]->addReviewer( $row->trr_user );
 673+ $messages[$key]->appendProperty( 'reviewers', $row->trr_user );
665674 }
666675 }
667676
Index: trunk/extensions/Translate/Message.php
@@ -106,17 +106,17 @@
107107 $this->props[$key] = $value;
108108 }
109109
 110+ public function appendProperty( $key, $value ) {
 111+ if ( !isset( $this->props[$key] ) ) {
 112+ $this->props[$key] = array();
 113+ }
 114+ $this->props[$key][] = $value;
 115+ }
 116+
110117 public function getProperty( $key ) {
111118 return isset( $this->props[$key] ) ? $this->props[$key] : null;
112119 }
113120
114 - public function addReviewer( $userid ) {
115 - $this->reviewers[] = $userid;
116 - }
117 -
118 - public function getReviewers() {
119 - return $this->reviewers;
120 - }
121121 }
122122
123123 /**
Index: trunk/extensions/Translate/utils/MessageTable.php
@@ -220,7 +220,7 @@
221221 'data-revision' => $revision,
222222 );
223223
224 - $reviewers = $message->getReviewers();
 224+ $reviewers = (array) $message->getProperty( 'reviewers' );
225225 if ( in_array( $wgUser->getId(), $reviewers ) ) {
226226 $attribs['value'] = wfMessage( 'translate-messagereview-done' )->text();
227227 $attribs['disabled'] = 'disabled';
@@ -248,7 +248,7 @@
249249 return '';
250250 }
251251
252 - $reviewers = $message->getReviewers();
 252+ $reviewers = (array) $message->getProperty( 'reviewers' );
253253 if ( count( $reviewers ) === 0 ) {
254254 return '';
255255 }

Status & tagging log