r70487 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70486‎ | r70487 | r70488 >
Date:05:11, 5 August 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Include section order in db schema for page translation sections
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/translate-add-trs_order.patch.sql (added) (history)
  • /trunk/extensions/Translate/translate.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/translate-add-trs_order.patch.sql
@@ -0,0 +1,2 @@
 2+ALTER TABLE /*_*/translate_sections
 3+ ADD trs_order int unsigned;
\ No newline at end of file
Property changes on: trunk/extensions/Translate/translate-add-trs_order.patch.sql
___________________________________________________________________
Added: svn:eol-style
14 + native
Index: trunk/extensions/Translate/MessageGroups.php
@@ -755,7 +755,11 @@
756756 $tables = 'translate_sections';
757757 $vars = array( 'trs_key', 'trs_text' );
758758 $conds = array( 'trs_page' => $this->getTitle()->getArticleId() );
759 - $res = $dbr->select( $tables, $vars, $conds, __METHOD__ );
 759+ $options = array();
 760+ if ( $dbr->fieldExists( 'translate_sections', 'trs_order', __METHOD__ ) ) {
 761+ $options['GROUP BY'] = 'trs_order';
 762+ }
 763+ $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
760764
761765 $defs = array();
762766 $prefix = $this->getTitle()->getPrefixedDBKey() . '/';
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -467,7 +467,7 @@
468468 $changed = array();
469469
470470 $pageId = $page->getTitle()->getArticleId();
471 - foreach ( $sections as $s ) {
 471+ foreach ( array_values( $sections ) as $index => $s ) {
472472 if ( $s->type === 'changed' ) {
473473 // Allow silent changes to avoid fuzzying unnecessary.
474474 if ( !$wgRequest->getCheck( "tpt-sect-{$s->id}-action-nofuzzy" ) ) {
@@ -479,15 +479,23 @@
480480 'trs_page' => $pageId,
481481 'trs_key' => $s->name,
482482 'trs_text' => $s->getText(),
 483+ 'trs_order' => $index
483484 );
484485 }
485486
 487+
486488 // Don't add stuff if no changes, use the plain null instead for prettiness
487489 if ( !count( $changed ) ) {
488490 $changed = null;
489491 }
490492
491493 $dbw = wfGetDB( DB_MASTER );
 494+ if ( !$dbw->fieldExists( 'translate_sections', 'trs_order', __METHOD__ ) ) {
 495+ error_log( 'Field trs_order does not exists. Please run update.php.' );
 496+ foreach ( array_keys( $inserts ) as $index ) {
 497+ unset( $inserts[$index]['trs_order'] );
 498+ }
 499+ }
492500 $dbw->delete( 'translate_sections', array( 'trs_page' => $page->getTitle()->getArticleId() ), __METHOD__ );
493501 $dbw->insert( 'translate_sections', $inserts, __METHOD__ );
494502
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -359,10 +359,11 @@
360360 }
361361
362362 public static function schemaUpdates() {
363 - global $wgExtNewTables;
 363+ global $wgExtNewTables, $wgExtNewFields;
364364
365365 $dir = dirname( __FILE__ ) . '/..';
366366 $wgExtNewTables[] = array( 'translate_sections', "$dir/translate.sql" );
 367+ $wgExtNewFields[] = array( 'translate_sections', 'trs_order', "$dir/translate-add-trs_order.patch.sql" );
367368 $wgExtNewTables[] = array( 'revtag_type', "$dir/revtags.sql" );
368369
369370 return true;
Index: trunk/extensions/Translate/translate.sql
@@ -11,6 +11,9 @@
1212 -- Section contents
1313 trs_text mediumblob NOT NULL,
1414
 15+ -- Section order
 16+ trs_order int unsigned,
 17+
1518 PRIMARY KEY (trs_page, trs_key)
1619 ) /*$wgDBTableOptions*/;
1720

Status & tagging log