r50379 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50378‎ | r50379 | r50380 >
Date:19:25, 9 May 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
* <languages /> on translation pages
* track changed sections
* purge key cache when marking pages
* fix order bys
* score calculation with per section tracking
Modified paths:
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -181,15 +181,15 @@
182182 return $section;
183183 }
184184
185 - public function addMarkedTag( $revision ) {
186 - $this->addTag( 'tp:mark', $revision );
 185+ public function addMarkedTag( $revision, $value = null ) {
 186+ $this->addTag( 'tp:mark', $revision, $value );
187187 }
188188
189189 public function addReadyTag( $revision ) {
190190 $this->addTag( 'tp:tag', $revision );
191191 }
192192
193 - protected function addTag( $tag, $revision ) {
 193+ protected function addTag( $tag, $revision, $value = null ) {
194194 $dbw = wfGetDB( DB_MASTER );
195195
196196 // Can this be done in one query?
@@ -202,6 +202,7 @@
203203 'rt_revision' => $revision
204204 );
205205 $dbw->delete( 'revtag', $conds, __METHOD__ );
 206+ if ( $value !== null ) $conds['rt_value'] = serialize($value);
206207 $dbw->insert( 'revtag', $conds, __METHOD__ );
207208 }
208209
@@ -215,16 +216,14 @@
216217 protected function getTag( $tag, $dbt = DB_SLAVE ) {
217218 $db = wfGetDB( $dbt );
218219
219 - // Can this be done in one query?
220 - $id = $db->selectField( 'revtag_type', 'rtt_id',
221 - array( 'rtt_name' => $tag ), __METHOD__ );
 220+ $id = $this->getTagId( $tag );
222221
223222 $fields = 'rt_revision';
224223 $conds = array(
225224 'rt_page' => $this->getTitle()->getArticleId(),
226225 'rt_type' => $id,
227226 );
228 - $options = array( 'ORDER BY', 'rt_revision DESC' );
 227+ $options = array( 'ORDER BY' => 'rt_revision DESC' );
229228 return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options );
230229 }
231230
@@ -251,7 +250,7 @@
252251 'rt_page' => $this->getTitle()->getArticleId(),
253252 'rt_type' => $id,
254253 );
255 - $options = array( 'ORDER BY', 'rt_revision DESC' );
 254+ $options = array( 'ORDER BY' => 'rt_revision DESC' );
256255 return $db->select( 'revtag', $fields, $conds, __METHOD__, $options );
257256 }
258257
@@ -315,7 +314,16 @@
316315 $rev = $this->getTransrev( $key .'/' . $collection->code );
317316 foreach ( $markedRevs as $r ) {
318317 if ( $rev === $r->rt_revision ) break;
319 - $score *= 0.8;
 318+ $changed = unserialize($r->rt_value);
 319+
 320+ // Get a suitable section key
 321+ $parts = explode( '/', $key );
 322+ $ikey = $parts[count($parts)-1];
 323+
 324+ // If the section was changed, reduce the score
 325+ if ( in_array($ikey, $changed, true) ) {
 326+ $score *= 0.8;
 327+ }
320328 }
321329 $total += $score;
322330 }
@@ -324,9 +332,7 @@
325333
326334 protected function getTransRev( $suffix ) {
327335 $id = $this->getTagId( 'tp:transver' );
328 - $title = Title::makeTitle( NS_TRANSLATIONS,
329 - $this->getTitle()->getPrefixedText() . '/' . $suffix
330 - );
 336+ $title = Title::makeTitle( NS_TRANSLATIONS, $suffix );
331337
332338 $db = wfGetDB( DB_SLAVE );
333339 $fields = 'rt_value';
@@ -334,14 +340,14 @@
335341 'rt_page' => $title->getArticleId(),
336342 'rt_type' => $id,
337343 );
338 - $options = array( 'ORDER BY', 'rt_revision DESC' );
 344+ $options = array( 'ORDER BY' => 'rt_revision DESC' );
339345 return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options );
340346
341347 }
342348
343349 protected function getTagId( $tag ) {
344350 static $tagcache = array();
345 - if ( !isset( $tagcache[$tag] ) ) {
 351+ if ( !isset($tagcache[$tag]) ) {
346352 $db = wfGetDB( DB_SLAVE );
347353 $tagcache[$tag] = $db->selectField(
348354 'revtag_type', // Table
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -308,21 +308,26 @@
309309 }
310310
311311 $inserts = array();
 312+ $changed = array();
312313 foreach ( $sections as $s ) {
 314+ if ( $s->type === 'changed' ) $changed[] = $s->name;
313315 $inserts[] = array(
314316 'trs_page' => $page->getTitle()->getArticleId(),
315317 'trs_key' => $s->name,
316318 'trs_text' => $s->getText(),
317319 );
318320 }
 321+ // Don't add empty rows
 322+ if ( !count($changed) ) $changed = null;
319323
320324 $dbw = wfGetDB( DB_MASTER );
321325 $dbw->delete( 'translate_sections', array( 'trs_page' => $page->getTitle()->getArticleId() ), __METHOD__ );
322326 $ok = $dbw->insert( 'translate_sections', $inserts, __METHOD__ );
323327 if ( $ok === false ) return array( 'tpt-insert-failed' );
324328
325 - $page->addMarkedTag( $newrevision );
 329+ $page->addMarkedTag( $newrevision, $changed );
326330
 331+ MessageIndex::cache( NS_TRANSLATIONS );
327332 return false;
328333 }
329334
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -137,7 +137,16 @@
138138
139139 public static function languages( $data, $params, $parser ) {
140140 $title = $parser->getTitle();
 141+
 142+ // Check if this is a source page or a translation page
141143 $page = TranslatablePage::newFromTitle( $title );
 144+ if ( $page->getMarkedTag() === false ) {
 145+ $title = Title::makeTitle( $title->getNamespace(), $title->getBaseText() );
 146+ $page = TranslatablePage::newFromTitle( $title );
 147+ }
 148+ if ( $page->getMarkedTag() === false ) return '';
 149+
 150+
142151 $status = $page->getTranslationPercentages();
143152 if ( !$status ) return '';
144153
@@ -157,7 +166,7 @@
158167 $name = TranslateUtils::getLanguageName( $code, false, $wgLang->getCode() );
159168
160169 $percent *= 100;
161 - if ( $percent < 10 ) continue;
 170+ if ( $percent < 10 ) continue; // Hide.. not very useful
162171 if ( $percent < 20 ) $image = 1;
163172 elseif ( $percent < 40 ) $image = 2;
164173 elseif ( $percent < 60 ) $image = 3;
@@ -215,7 +224,7 @@
216225
217226 // Add the ready tag
218227 $page = TranslatablePage::newFromTitle( $article->getTitle() );
219 - $page->addReadyTag( $revision->getId() );
 228+ $page->addReadyTag( $revision->getId() );
220229
221230 return true;
222231 }
@@ -290,15 +299,15 @@
291300
292301 $sk = $wgUser->getSkin();
293302
294 - $page = TranslatablePage::newFromText( $title, '' );
 303+ $page = TranslatablePage::newFromTitle( $title );
295304
296305 $marked = $page->getMarkedTag();
297306 $ready = $page->getReadyTag();
 307+
298308 if ( $marked === false && $ready === false ) return '';
299309
300310 $latest = $title->getLatestRevId();
301311 $canmark = $ready === $latest && $marked !== $latest;
302 -
303312 wfLoadExtensionMessages( 'PageTranslation' );
304313
305314 $actions = array();

Status & tagging log