r100345 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100344‎ | r100345 | r100346 >
Date:13:58, 20 October 2011
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Translation review interface
Internationalization/#129
Internationalization/#130
Modified paths:
  • /trunk/extensions/Translate/Message.php (modified) (history)
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateTasks.php (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.messagetable.css (modified) (history)
  • /trunk/extensions/Translate/utils/MessageTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageCollection.php
@@ -42,6 +42,9 @@
4343 /// \type{Database Result Resource} Stored translations in database.
4444 protected $dbData = null;
4545
 46+ /// \type{Database Result Resource} Stored reviews in database.
 47+ protected $dbReviewData = null;
 48+
4649 /**
4750 * Tags, copied to thin messages
4851 * tagtype => keys
@@ -51,6 +54,9 @@
5255 /// \list{String} Authors.
5356 protected $authors = array();
5457
 58+ /// bool Whether review info is loaded
 59+ protected $reviewMode = false;
 60+
5561 /**
5662 * Constructors. Use newFromDefinitions() instead.
5763 * @param $code \string Language code.
@@ -184,6 +190,14 @@
185191 $this->authors = array_unique( $authors );
186192 }
187193
 194+ /**
 195+ * Call this to load list of reviewers for each message.
 196+ * Can be accessed from TMessage::getReviewers().
 197+ */
 198+ public function setReviewMode( $value = true ) {
 199+ $this->reviewMode = $value;
 200+ }
 201+
188202 // Data modifiers
189203
190204 /**
@@ -195,6 +209,9 @@
196210 public function loadTranslations( $dbtype = DB_SLAVE ) {
197211 $this->loadData( $this->keys, $dbtype );
198212 $this->loadInfo( $this->keys, $dbtype );
 213+ if ( $this->reviewMode ) {
 214+ $this->loadReviewInfo( $this->keys, $dbtype );
 215+ }
199216 $this->initMessages();
200217 }
201218
@@ -510,6 +527,40 @@
511528 }
512529
513530 /**
 531+ * Loads reviewers for given messages.
 532+ * @param $keys \list{String} List of keys in database format.
 533+ * @param $dbtype One of DB_* constants.
 534+ */
 535+ protected function loadReviewInfo( array $keys, $dbtype = DB_SLAVE ) {
 536+ if ( $this->dbReviewData !== null ) {
 537+ return;
 538+ }
 539+
 540+ $this->dbReviewData = array();
 541+
 542+ if ( !count( $keys ) ) {
 543+ return;
 544+ }
 545+
 546+ $dbr = wfGetDB( $dbtype );
 547+
 548+ $tables = array( 'page', 'translate_reviews' );
 549+ $fields = array( 'page_title', 'trr_user' );
 550+ $conds = array(
 551+ 'page_namespace' => $this->definitions->namespace,
 552+ 'page_title' => array_values( $keys ),
 553+ );
 554+ $joins = array( 'translate_reviews' =>
 555+ array(
 556+ 'JOIN',
 557+ array( 'page_id=trr_page', 'page_latest=trr_revision' )
 558+ )
 559+ );
 560+
 561+ $this->dbReviewData = $dbr->select( $tables, $fields, $conds, __METHOD__, array(), $joins );
 562+ }
 563+
 564+ /**
514565 * Loads translation for given list of keys.
515566 * @param $keys \list{String} List of keys in database format.
516567 * @param $dbtype One of DB_* constants.
@@ -528,7 +579,7 @@
529580 $dbr = wfGetDB( $dbtype );
530581
531582 $tables = array( 'page', 'revision', 'text' );
532 - $fields = array( 'page_title', 'rev_user_text', 'old_flags', 'old_text' );
 583+ $fields = array( 'page_title', 'page_latest', 'rev_user_text', 'old_flags', 'old_text' );
533584 $conds = array(
534585 'page_namespace' => $this->definitions->namespace,
535586 'page_title' => array_values( $keys ),
@@ -567,6 +618,7 @@
568619
569620 $key = $flipKeys[$row->page_title];
570621 $messages[$key]->setRow( $row );
 622+ $messages[$key]->setProperty( 'revision', $row->page_latest );
571623 }
572624 }
573625
@@ -601,6 +653,16 @@
602654 }
603655 }
604656
 657+ if ( $this->dbReviewData !== null ) {
 658+ foreach ( $this->dbReviewData as $row ) {
 659+ if ( !isset( $flipKeys[$row->page_title] ) ) {
 660+ continue;
 661+ }
 662+ $key = $flipKeys[$row->page_title];
 663+ $messages[$key]->addReviewer( $row->trr_user );
 664+ }
 665+ }
 666+
605667 $this->messages = $messages;
606668 }
607669
Index: trunk/extensions/Translate/Message.php
@@ -20,6 +20,10 @@
2121 protected $infile;
2222 /// \list{String} Message tags.
2323 protected $tags = array();
 24+ /// \array Message properties.
 25+ protected $props = array();
 26+ /// \list{String} Message reviewers.
 27+ protected $reviewers = array();
2428
2529 /**
2630 * Creates new message object.
@@ -97,6 +101,22 @@
98102 public function getTags() {
99103 return $this->tags;
100104 }
 105+
 106+ public function setProperty( $key, $value ) {
 107+ $this->props[$key] = $value;
 108+ }
 109+
 110+ public function getProperty( $key ) {
 111+ return isset( $this->props[$key] ) ? $this->props[$key] : null;
 112+ }
 113+
 114+ public function addReviewer( $userid ) {
 115+ $this->reviewers[] = $userid;
 116+ }
 117+
 118+ public function getReviewers() {
 119+ return $this->reviewers;
 120+ }
101121 }
102122
103123 /**
Index: trunk/extensions/Translate/Translate.php
@@ -165,8 +165,17 @@
166166 ) + $resourcePaths;
167167
168168 $wgResourceModules['ext.translate.messagetable'] = array(
 169+ 'scripts' => 'resources/ext.translate.messagetable.js',
169170 'styles' => 'resources/ext.translate.messagetable.css',
170171 'position' => 'top',
 172+ 'messages' => array(
 173+ 'translate-messagereview-submit',
 174+ 'translate-messagereview-progress',
 175+ 'translate-messagereview-failure',
 176+ 'translate-messagereview-done',
 177+ 'translate-messagereview-apierror-invalidrevision',
 178+ 'translate-messagereview-apierror-unknownmessage',
 179+ ),
171180 ) + $resourcePaths;
172181
173182 $wgResourceModules['ext.translate.special.translate'] = array(
Index: trunk/extensions/Translate/TranslateTasks.php
@@ -204,6 +204,7 @@
205205 protected function preinit() {
206206 $code = $this->options->getLanguage();
207207 $this->collection = $this->group->initCollection( $code );
 208+ $this->collection->setReviewMode( true );
208209 $this->collection->setInfile( $this->group->load( $code ) );
209210 $this->collection->filter( 'ignored' );
210211 $this->collection->filter( 'hastranslation', false );
@@ -328,6 +329,7 @@
329330 protected function preinit() {
330331 $code = $this->options->getLanguage();
331332 $this->collection = $this->group->initCollection( $code );
 333+ $this->collection->setReviewMode( true );
332334 $this->collection->setInfile( $this->group->load( $code ) );
333335 $this->collection->filter( 'ignored' );
334336 $this->collection->filter( 'hastranslation', false );
Index: trunk/extensions/Translate/utils/MessageTable.php
@@ -95,28 +95,17 @@
9696
9797 public function contents() {
9898 global $wgUser;
99 -
10099 $sk = $wgUser->getSkin();
101100
102101 $optional = wfMsgHtml( 'translate-optional' );
103102
104 - $batch = new LinkBatch();
105 - if ( method_exists( $batch, 'setCaller' ) ) {
106 - $batch->setCaller( __METHOD__ );
107 - }
 103+ $this->doLinkBatch();
108104
109 - $ns = $this->group->getNamespace();
110 -
111 - foreach ( $this->collection->keys() as $key ) {
112 - $batch->add( $ns, $key );
113 - }
114 -
115 - $batch->execute();
116 -
117105 $sourceLang = Language::factory( $this->group->getSourceLanguage() );
118106 $targetLang = Language::factory( $this->collection->getLanguage() );
119107
120108 $output = '';
 109+
121110 $this->collection->initMessages(); // Just to be sure
122111 foreach ( $this->collection as $key => $m ) {
123112 $tools = array();
@@ -135,7 +124,6 @@
136125 }
137126
138127 global $wgLang;
139 -
140128 $niceTitle = htmlspecialchars( $wgLang->truncate( $key, - 30 ) );
141129
142130 $tools['edit'] = $sk->link(
@@ -153,9 +141,9 @@
154142 if ( $m->hasTag( 'optional' ) ) {
155143 $extra = '<br />' . $optional;
156144 }
 145+
 146+ $leftColumn = $anchor . $tools['edit'] . $this->getReviewButton( $m ) . $extra . $this->getReviewStatus( $m );
157147
158 - $leftColumn = $anchor . $tools['edit'] . $extra;
159 -
160148 if ( $this->reviewMode && $original !== $message ) {
161149 $output .= Xml::tags( 'tr', array( 'class' => 'orig' ),
162150 Xml::tags( 'td', array( 'rowspan' => '2' ), $leftColumn ) .
@@ -217,4 +205,68 @@
218206
219207 return array( 'lang' => $code, 'dir' => $dir );
220208 }
 209+
 210+ protected function getReviewButton( TMessage $message ) {
 211+ global $wgUser;
 212+ $revision = $message->getProperty( 'revision' );
 213+ if ( !$this->reviewMode || !$wgUser->isAllowed( 'translate-messagereview' ) || !$revision || $message->hasTag( 'fuzzy' ) ) {
 214+ return '';
 215+ }
 216+
 217+ $attribs = array(
 218+ 'type' => 'button',
 219+ 'class' => 'mw-translate-messagereviewbutton',
 220+ 'data-token' => ApiTranslationReview::getToken( 0, '' ),
 221+ 'data-revision' => $revision,
 222+ );
 223+
 224+ $reviewers = $message->getReviewers();
 225+ if ( in_array( $wgUser->getId(), $reviewers ) ) {
 226+ $attribs['value'] = wfMessage( 'translate-messagereview-done' )->text();
 227+ $attribs['disabled'] = 'disabled';
 228+ } else {
 229+ $attribs['value'] = wfMessage( 'translate-messagereview-submit' )->text();
 230+ }
 231+
 232+
 233+ $review = Html::element( 'input', $attribs );
 234+ return $review;
 235+ }
 236+
 237+ protected function getReviewStatus( TMessage $message ) {
 238+ global $wgUser;
 239+ if ( !$this->reviewMode ) {
 240+ return '';
 241+ }
 242+
 243+ $reviewers = $message->getReviewers();
 244+ if ( count( $reviewers ) === 0 ) {
 245+ return '';
 246+ }
 247+
 248+ $you = $wgUser->getId();
 249+ if ( in_array( $you, $reviewers ) ) {
 250+ if ( count( $reviewers ) === 1 ) {
 251+ $msg = wfMessage( 'translate-messagereview-reviewsyou' )->parse();
 252+ } else {
 253+ $msg = wfMessage( 'translate-messagereview-reviewswithyou' )->numParams( count( $reviewers ) )->parse();
 254+ }
 255+ } else {
 256+ $msg = wfMessage( 'translate-messagereview-reviews' )->numParams( count( $reviewers ) )->parse();
 257+ }
 258+ return Html::rawElement( 'div', array( 'class' => 'mw-translate-messagereviewstatus' ), $msg );
 259+ }
 260+
 261+ protected function doLinkBatch() {
 262+ $batch = new LinkBatch();
 263+ if ( method_exists( $batch, 'setCaller' ) ) {
 264+ $batch->setCaller( __METHOD__ );
 265+ }
 266+ $ns = $this->group->getNamespace();
 267+ foreach ( $this->collection->keys() as $key ) {
 268+ $batch->add( $ns, $key );
 269+ }
 270+ $batch->execute();
 271+ }
 272+
221273 }
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -366,6 +366,16 @@
367367 'translate-searchprofile-tooltip' => 'Search from all translations',
368368 'translate-search-languagefilter' => 'Filter by language:',
369369 'translate-search-nofilter' => 'No filtering',
 370+
 371+ 'translate-messagereview-submit' => 'Review',
 372+ 'translate-messagereview-progress' => 'Reviewing...',
 373+ 'translate-messagereview-failure' => 'Reviewing... failed: $1',
 374+ 'translate-messagereview-done' => 'Reviewed',
 375+ 'translate-messagereview-apierror-invalidrevision' => 'Translation was not found',
 376+ 'translate-messagereview-apierror-unknownmessage' => 'Message was not found',
 377+ 'translate-messagereview-reviews' => 'Reviewed by {{PLURAL:$1|one user|$1 users}}',
 378+ 'translate-messagereview-reviewswithyou' => 'Reviewed by {{PLURAL:$1|one user|$1 users}} including you',
 379+ 'translate-messagereview-reviewsyou' => 'Reviewed by you',
370380 );
371381
372382 /** Message documentation (Message documentation)
@@ -575,6 +585,16 @@
576586 'translate-searchprofile' => 'Tab in [[Special:Search]]
577587 {{Identical|Translation}}',
578588 'translate-searchprofile-tooltip' => 'Tooltip for a tab in [[Special:Search]]',
 589+
 590+ 'translate-messagereview-submit' => 'Button label in Special:Translate review mode',
 591+ 'translate-messagereview-progress' => 'Button label in Special:Translate review mode. Button is disabled.',
 592+ 'translate-messagereview-failure' => 'Button label in Special:Translate review mode. Button is disabled. $1 can be {{msg-mw|translate-messagereview-apierror-invalidrevision}} or {{msg-mw|translate-messagereview-apierror-unknownmessage}}.',
 593+ 'translate-messagereview-done' => 'Button label in Special:Translate review mode. Button is disabled.',
 594+ 'translate-messagereview-apierror-invalidrevision' => 'Error message for {{msg-mw|translate-messagereview-failure}}',
 595+ 'translate-messagereview-apierror-unknownmessage' => 'Error message for {{msg-mw|translate-messagereview-failure}}',
 596+ 'translate-messagereview-reviews' => 'Status message in Special:Translate in review mode',
 597+ 'translate-messagereview-reviewswithyou' => 'Status message in Special:Translate in review mode',
 598+ 'translate-messagereview-reviewsyou' => 'Status message in Special:Translate in review mode',
579599 );
580600
581601 /** Faeag Rotuma (Faeag Rotuma)
Index: trunk/extensions/Translate/resources/ext.translate.messagetable.css
@@ -39,4 +39,13 @@
4040 vertical-align: top;
4141 border-style: solid;
4242 border-width: 1px;
43 -}
\ No newline at end of file
 43+}
 44+
 45+.mw-translate-messagereviewbutton {
 46+ float: right;
 47+}
 48+
 49+.mw-translate-messagereviewstatus {
 50+ clear: right;
 51+ text-align: right;
 52+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r100413Added a forgotten file...nikerabbit06:04, 21 October 2011
r100420Followup r100345 - protect part of the code with configuration variablenikerabbit14:06, 21 October 2011
r100587setCaller exists since 1.17 so no need to check whether it exists, spotted by...nikerabbit09:07, 24 October 2011

Comments

#Comment by Amire80 (talk | contribs)   10:32, 24 October 2011

Unneeded "method_exists( $batch, 'setCaller' )" removed in r100587.

Status & tagging log