r101130 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101129‎ | r101130 | r101131 >
Date:13:14, 28 October 2011
Author:nikerabbit
Status:ok (Comments)
Tags:
Comment:
Implemented last-translator property filter
Internationalization/#148
Modified paths:
  • /trunk/extensions/Translate/Message.php (modified) (history)
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageCollection.php
@@ -288,7 +288,8 @@
289289 'hastranslation',
290290 'changed',
291291 'translated',
292 - 'reviewer'
 292+ 'reviewer',
 293+ 'last-translator',
293294 );
294295 }
295296
@@ -315,6 +316,8 @@
316317 $keys = $this->filterChanged( $keys, $condition );
317318 } elseif ( $filter === 'reviewer' ) {
318319 $keys = $this->filterReviewer( $keys, $condition, $value );
 320+ } elseif ( $filter === 'last-translator' ) {
 321+ $keys = $this->filterLastTranslator( $keys, $condition, $value );
319322 } else {
320323 // Filter based on tags.
321324 if ( !isset( $this->tags[$filter] ) ) {
@@ -509,6 +512,37 @@
510513 return $keys;
511514 }
512515
 516+ /**
 517+ * @param $keys \list{String} List of keys to filter.
 518+ * @param $condition \bool True to remove translatations where last translator is $user
 519+ * false to get only last translations done by others.
 520+ * @param $user \int Userid
 521+ * @return \list{String} Filtered keys.
 522+ */
 523+ protected function filterLastTranslator( array $keys, $condition, $user ) {
 524+ $this->loadData( $keys );
 525+
 526+ if ( $condition === false ) {
 527+ $origKeys = $keys;
 528+ }
 529+
 530+ $flipKeys = array_flip( $keys );
 531+ $user = intval( $user );
 532+ foreach ( $this->dbData as $row ) {
 533+ if ( intval($row->rev_user) === $user ) {
 534+ $realKey = $flipKeys[$row->page_title];
 535+ unset( $keys[$realKey] );
 536+ }
 537+ }
 538+
 539+ if ( $condition === false ) {
 540+ // List of keys that are missing from $keys
 541+ $keys = array_diff( $origKeys, $keys );
 542+ }
 543+
 544+ return $keys;
 545+ }
 546+
513547 /** @} */
514548
515549 /**
@@ -620,7 +654,7 @@
621655 $dbr = wfGetDB( $dbtype );
622656
623657 $tables = array( 'page', 'revision', 'text' );
624 - $fields = array( 'page_title', 'page_latest', 'rev_user_text', 'old_flags', 'old_text' );
 658+ $fields = array( 'page_title', 'page_latest', 'rev_user', 'rev_user_text', 'old_flags', 'old_text' );
625659 $conds = array(
626660 'page_namespace' => $this->definitions->namespace,
627661 'page_title' => array_values( $keys ),
Index: trunk/extensions/Translate/Message.php
@@ -125,6 +125,12 @@
126126 * text.
127127 */
128128 class ThinMessage extends TMessage {
 129+ // This maps properties to fields in the database result row
 130+ protected static $propertyMap = array(
 131+ 'last-translator-text' => 'rev_user_text',
 132+ 'last-translator-id' => 'rev_user',
 133+ );
 134+
129135 /// \type{Database Result Row}
130136 protected $row;
131137
@@ -143,6 +149,7 @@
144150 return Revision::getRevisionText( $this->row );
145151 }
146152
 153+ /// Deprecated, use getProperty( 'last-translator-text' )
147154 public function author() {
148155 if ( !isset( $this->row ) ) {
149156 return null;
@@ -150,6 +157,20 @@
151158 return $this->row->rev_user_text;
152159 }
153160
 161+ // Re-implemented
 162+ public function getProperty( $key ) {
 163+ if ( !isset( self::$propertyMap[$key] ) ) {
 164+ return parent::getProperty( $key );
 165+ }
 166+
 167+ $field = self::$propertyMap[$key];
 168+ if ( !isset( $this->row->$field ) ) {
 169+ return null;
 170+ }
 171+
 172+ return $this->row->$field;
 173+ }
 174+
154175 }
155176
156177 /**

Comments

#Comment by Amire80 (talk | contribs)   17:39, 31 October 2011

public function author is now marked as deprecated, but it's still used in a couple of places. It should probably be removed some time.

Status & tagging log