r95558 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95557‎ | r95558 | r95559 >
Date:15:08, 26 August 2011
Author:nikerabbit
Status:resolved
Tags:
Comment:
Get rid of revtag_type table, as suggested by Roan.
Includes migration script and code which works on both schemas.
Modified paths:
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)
  • /trunk/extensions/Translate/_autoload.php (modified) (history)
  • /trunk/extensions/Translate/revtags.sql (modified) (history)
  • /trunk/extensions/Translate/scripts/createCheckIndex.php (modified) (history)
  • /trunk/extensions/Translate/scripts/pagetranslation-check-database.php (modified) (history)
  • /trunk/extensions/Translate/scripts/populateFuzzy.php (modified) (history)
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageCollection.php
@@ -4,7 +4,7 @@
55 *
66 * @file
77 * @author Niklas Laxström
8 - * @copyright Copyright © 2007-2010, Niklas Laxström
 8+ * @copyright Copyright © 2007-2011, Niklas Laxström
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 */
1111
@@ -479,11 +479,6 @@
480480
481481 $dbr = wfGetDB( DB_SLAVE );
482482
483 - static $id = null;
484 -
485 - if ( $id === null )
486 - $id = $dbr->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ );
487 -
488483 $tables = array( 'page', 'revtag' );
489484 $fields = array( 'page_title', 'rt_type' );
490485 $conds = array(
@@ -493,7 +488,7 @@
494489 $joins = array( 'revtag' =>
495490 array(
496491 'LEFT JOIN',
497 - array( 'page_id=rt_page', 'page_latest=rt_revision', 'rt_type' => $id )
 492+ array( 'page_id=rt_page', 'page_latest=rt_revision', 'rt_type' => RevTag::getType( 'fuzzy' ) )
498493 )
499494 );
500495
Index: trunk/extensions/Translate/scripts/createCheckIndex.php
@@ -3,7 +3,7 @@
44 * Creates serialised database of messages that need checking for problems.
55 *
66 * @author Niklas Laxstrom
7 - * @copyright Copyright © 2008-2010, Niklas Laxström
 7+ * @copyright Copyright © 2008-2011, Niklas Laxström
88 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
99 * @file
1010 */
@@ -88,7 +88,6 @@
8989 }
9090
9191 $db = wfGetDB( DB_MASTER );
92 - $id = $db->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ );
9392 foreach ( $problematic as $p ) {
9493 $title = Title::makeTitleSafe( $p[0], $p[1] );
9594 $titleText = $title->getDBKey();
@@ -100,7 +99,7 @@
101100 $inserts = array(
102101 'rt_page' => $r->page_id,
103102 'rt_revision' => $r->page_latest,
104 - 'rt_type' => $id
 103+ 'rt_type' => RevTag::getType( 'fuzzy' )
105104 );
106105 }
107106 $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
Index: trunk/extensions/Translate/scripts/populateFuzzy.php
@@ -3,7 +3,7 @@
44 * A script to populate fuzzy tags to revtag table.
55 *
66 * @author Niklas Laxstrom
7 - * @copyright Copyright © 2009-2010, Niklas Laxström
 7+ * @copyright Copyright © 2009-2011, Niklas Laxström
88 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
99 * @file
1010 */
@@ -14,12 +14,6 @@
1515
1616 $db = wfGetDB( DB_MASTER );
1717
18 -$id = $db->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ );
19 -if ( $id === false ) {
20 - echo "Fuzzy tag is not registered\n";
21 - exit();
22 -}
23 -
2418 $count = $db->selectField( 'page', 'count(*)', array( 'page_namespace' => $wgTranslateMessageNamespaces ), __METHOD__ );
2519 if ( !$count ) {
2620 echo "Nothing to update";
@@ -52,7 +46,7 @@
5347 $inserts[] = array(
5448 'rt_page' => $r->page_id,
5549 'rt_revision' => $r->rev_id,
56 - 'rt_type' => $id
 50+ 'rt_type' => RevTag::getType( 'fuzzy' ),
5751 );
5852 }
5953 }
Index: trunk/extensions/Translate/scripts/pagetranslation-check-database.php
@@ -4,7 +4,7 @@
55 * feature and fix problems.
66 *
77 * @author Niklas Laxstrom
8 - * @copyright Copyright © 2010, Niklas Laxström
 8+ * @copyright Copyright © 2010-2011, Niklas Laxström
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 * @file
1111 */
@@ -104,15 +104,8 @@
105105
106106 $dbr = wfGetDB( DB_SLAVE );
107107
108 - $result = $dbr->select( 'revtag_type', '*', null, __METHOD__ );
109 - $idToTag = array();
 108+ $tags = array( 'tp:mark', 'tp:tag', 'tp:transver', 'fuzzy' );
110109
111 - foreach ( $result as $_ ) {
112 - $idToTag[$_->rtt_id] = $_->rtt_name;
113 - }
114 -
115 - $tagToId = array_flip( $idToTag );
116 -
117110 $pages = $dbr->select( 'revtag', 'rt_page', null, __METHOD__, array( 'GROUP BY' => 'rt_page' ) );
118111 $this->output( "Checking that tags match a valid page...\n\n" );
119112
@@ -137,16 +130,14 @@
138131 $this->output( "\n\nValidating tags...\n" );
139132
140133 $result = $dbr->select( 'revtag', '*', null, __METHOD__ );
141 - $transver = $tagToId['tp:transver'];
142 -
143134 foreach ( $result as $_ ) {
144 - if ( !isset( $idToTag[$_->rt_type] ) ) {
 135+ if ( !isset( $tags[$_->rt_type] ) ) {
145136 $name = $this->idToName( $_->rt_page );
146137 $this->output( "Page $name has unknown tag {$_->rt_type}\n" );
147138 $fixes["$name <revtag:unknown:{$_->rt_type}>"] =
148139 array( 'delete tag', 'revtag', array( 'rt_page' => $id, 'rt_type' => $_->rt_type ) );
149140 continue;
150 - } elseif ( $_->rt_type === $transver ) {
 141+ } elseif ( $_->rt_type === RevTag::getType( 'tp:transver' ) ) {
151142 $check = $this->checkTransrevRevision( $rev );
152143 if ( $check !== true ) {
153144 $name = $this->idToName( $_->rt_page );
Index: trunk/extensions/Translate/revtags.sql
@@ -1,16 +1,8 @@
 2+-- These tables could go into core someday, but not likely
23
3 -CREATE TABLE /*$wgDBprefix*/revtag_type (
4 - rtt_id int not null primary key auto_increment,
5 - rtt_name varbinary(60) not null
6 -) /*$wgDBTableOptions*/;
7 -CREATE UNIQUE INDEX /*i*/rtt_name ON /*$wgDBprefix*/revtag_type (rtt_name);
8 -
94 -- Revision tags
105 CREATE TABLE /*$wgDBprefix*/revtag (
11 - -- Link to revtag_type.rtt_id
12 - rt_type int not null,
 6+ rt_type varbinary(60) not null,
137
148 -- Link to page.page_id
159 rt_page int not null,
Index: trunk/extensions/Translate/MessageGroups.php
@@ -921,9 +921,9 @@
922922 if ( $wgEnablePageTranslation ) {
923923 $dbr = wfGetDB( DB_SLAVE );
924924
925 - $tables = array( 'page', 'revtag', 'revtag_type' );
 925+ $tables = array( 'page', 'revtag' );
926926 $vars = array( 'page_id', 'page_namespace', 'page_title', );
927 - $conds = array( 'page_id=rt_page', 'rtt_id=rt_type', 'rtt_name' => 'tp:mark' );
 927+ $conds = array( 'page_id=rt_page', 'rt_type' => RevTag::getType( 'tp:mark') );
928928 $options = array( 'GROUP BY' => 'page_id' );
929929 $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
930930
Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -425,7 +425,6 @@
426426 protected function addTag( $tag, $revision, $value = null ) {
427427 $dbw = wfGetDB( DB_MASTER );
428428
429 - $id = self::getTagId( $tag );
430429 $aid = $this->getTitle()->getArticleId();
431430
432431 if ( is_object( $revision ) ) {
@@ -434,7 +433,7 @@
435434
436435 $conds = array(
437436 'rt_page' => $aid,
438 - 'rt_type' => $id,
 437+ 'rt_type' => RevTag::getType( $tag ),
439438 'rt_revision' => $revision
440439 );
441440 $dbw->delete( 'revtag', $conds, __METHOD__ );
@@ -478,8 +477,8 @@
479478 $conds = array(
480479 'rt_page' => $aid,
481480 'rt_type' => array(
482 - self::getTagId( 'tp:mark' ),
483 - self::getTagId( 'tp:tag' ),
 481+ RevTag::getType( 'tp:mark' ),
 482+ RevTag::getType( 'tp:tag' ),
484483 ),
485484 );
486485
@@ -501,11 +500,10 @@
502501 }
503502
504503 $db = wfGetDB( $dbt );
505 - $id = self::getTagId( $tag );
506504
507505 $conds = array(
508506 'rt_page' => $aid,
509 - 'rt_type' => $id,
 507+ 'rt_type' => RevTag::getType( $tag ),
510508 );
511509
512510 $options = array( 'ORDER BY' => 'rt_revision DESC' );
@@ -536,7 +534,7 @@
537535 $fields = array( 'rt_revision', 'rt_value' );
538536 $conds = array(
539537 'rt_page' => $this->getTitle()->getArticleId(),
540 - 'rt_type' => self::getTagId( 'tp:mark' ),
 538+ 'rt_type' => RevTag::getType( 'tp:mark' ),
541539 );
542540 $options = array( 'ORDER BY' => 'rt_revision DESC' );
543541
@@ -663,52 +661,19 @@
664662 }
665663
666664 public function getTransRev( $suffix ) {
667 - $id = self::getTagId( 'tp:transver' );
668665 $title = Title::makeTitle( NS_TRANSLATIONS, $suffix );
669666
670667 $db = wfGetDB( DB_SLAVE );
671668 $fields = 'rt_value';
672669 $conds = array(
673670 'rt_page' => $title->getArticleId(),
674 - 'rt_type' => $id,
 671+ 'rt_type' => RevTag::getType( 'tp:transver' ),
675672 );
676673 $options = array( 'ORDER BY' => 'rt_revision DESC' );
677674
678675 return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options );
679676 }
680677
681 - protected static function getTagId( $tag ) {
682 - $validTags = array( 'tp:mark', 'tp:tag', 'tp:transver' );
683 - if ( !in_array( $tag, $validTags ) ) {
684 - throw new MWException( "Invalid tag $tag requested" );
685 - }
686 -
687 - global $wgTranslateStaticTags;
688 -
689 - if ( is_array( $wgTranslateStaticTags ) ) {
690 - return $wgTranslateStaticTags[$tag];
691 - }
692 -
693 - // Simple static cache
694 - static $tagcache = array();
695 -
696 - if ( !count( $tagcache ) ) {
697 - $db = wfGetDB( DB_SLAVE );
698 - $res = $db->select(
699 - 'revtag_type', // Table
700 - array( 'rtt_name', 'rtt_id' ),
701 - array( 'rtt_name' => $validTags ),
702 - __METHOD__
703 - );
704 -
705 - foreach ( $res as $r ) {
706 - $tagcache[$r->rtt_name] = $r->rtt_id;
707 - }
708 - }
709 -
710 - return $tagcache[$tag];
711 - }
712 -
713678 public static function isTranslationPage( Title $title ) {
714679 list( $key, $code ) = TranslateUtils::figureMessage( $title->getText() );
715680
@@ -769,7 +734,7 @@
770735 $conds = array(
771736 'rt_page = page_id',
772737 'rt_revision = page_latest',
773 - 'rt_type' => array( self::getTagId( 'tp:mark' ), self::getTagId( 'tp:tag' ) ),
 738+ 'rt_type' => array( RevTag::getType( 'tp:mark' ), RevTag::getType( 'tp:tag' ) ),
774739 );
775740 $options = array( 'GROUP BY' => 'rt_page' );
776741
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -5,7 +5,7 @@
66 * @file
77 * @author Niklas Laxström
88 * @author Siebrand Mazeland
9 - * @copyright Copyright © 2008-2010 Niklas Laxström, Siebrand Mazeland
 9+ * @copyright Copyright © 2008-2011 Niklas Laxström, Siebrand Mazeland
1010 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1111 */
1212
@@ -138,16 +138,15 @@
139139
140140 public function loadPagesFromDB() {
141141 $dbr = wfGetDB( DB_SLAVE );
142 - $tables = array( 'page', 'revtag_type', 'revtag' );
143 - $vars = array( 'page_id', 'page_title', 'page_namespace', 'page_latest', 'MAX(rt_revision) as rt_revision', 'rtt_name' );
 142+ $tables = array( 'page', 'revtag' );
 143+ $vars = array( 'page_id', 'page_title', 'page_namespace', 'page_latest', 'MAX(rt_revision) as rt_revision', 'rt_type' );
144144 $conds = array(
145145 'page_id=rt_page',
146 - 'rt_type=rtt_id',
147 - 'rtt_name' => array( 'tp:mark', 'tp:tag' ),
 146+ 'rt_type' => array( RevTag::getType( 'tp:mark' ), RevTag::getType( 'tp:tag' ) ),
148147 );
149148 $options = array(
150149 'ORDER BY' => 'page_namespace, page_title',
151 - 'GROUP BY' => 'page_id, rtt_id',
 150+ 'GROUP BY' => 'page_id, rt_type',
152151 );
153152 $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
154153
@@ -172,7 +171,8 @@
173172 $pages[$r->page_id]['latest'] = intval( $title->getLatestRevID() );
174173 }
175174
176 - $pages[$r->page_id][$r->rtt_name] = intval( $r->rt_revision );
 175+ $tag = RevTag::typeToTag( $r->rt_type );
 176+ $pages[$r->page_id][$tag] = intval( $r->rt_revision );
177177 }
178178
179179 // Pages where mark <= tag
@@ -560,8 +560,6 @@
561561
562562 $titleCond = $db->makeList( $titles, LIST_OR );
563563
564 - $id = $db->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ );
565 -
566564 $fields = array( 'page_id', 'page_latest' );
567565 $conds = array( 'page_namespace' => NS_TRANSLATIONS, $titleCond );
568566 $res = $db->select( 'page', $fields, $conds, __METHOD__ );
@@ -571,7 +569,7 @@
572570 foreach ( $res as $r ) {
573571 $inserts[] = array(
574572 'rt_page' => $r->page_id,
575 - 'rt_type' => $id,
 573+ 'rt_type' => RevTag::getType( 'fuzzy' ),
576574 'rt_revision' => $r->page_latest,
577575 );
578576 }
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -4,7 +4,7 @@
55 *
66 * @file
77 * @author Niklas Laxström
8 - * @copyright Copyright © 2008-2010, Niklas Laxström
 8+ * @copyright Copyright © 2008-2011, Niklas Laxström
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 */
1111
@@ -150,13 +150,9 @@
151151
152152 $dbw = wfGetDB( DB_MASTER );
153153
154 - // Can this be done in one query?
155 - $id = $dbw->selectField( 'revtag_type', 'rtt_id',
156 - array( 'rtt_name' => 'tp:transver' ), __METHOD__ );
157 -
158154 $conds = array(
159155 'rt_page' => $title->getArticleId(),
160 - 'rt_type' => $id,
 156+ 'rt_type' => RevTag::getType( 'tp:transver' ),
161157 'rt_revision' => $revision
162158 );
163159 $dbw->delete( 'revtag', $conds, __METHOD__ );
@@ -397,11 +393,11 @@
398394
399395 $wgExtNewTables[] = array( 'translate_sections', "$dir/translate.sql" );
400396 $wgExtNewFields[] = array( 'translate_sections', 'trs_order', "$dir/translate-add-trs_order.patch.sql" );
401 - $wgExtNewTables[] = array( 'revtag_type', "$dir/revtags.sql" );
 397+ $wgExtNewTables[] = array( 'revtag', "$dir/revtags.sql" );
402398 } else {
403399 $updater->addExtensionUpdate( array( 'addTable', 'translate_sections', "$dir/translate.sql", true ) );
404400 $updater->addExtensionUpdate( array( 'addField', 'translate_sections', 'trs_order', "$dir/translate-add-trs_order.patch.sql", true ) );
405 - $updater->addExtensionUpdate( array( 'addTable', 'revtag_type', "$dir/revtags.sql", true ) );
 401+ $updater->addExtensionUpdate( array( 'addTable', 'revtag', "$dir/revtags.sql", true ) );
406402 }
407403 return true;
408404 }
@@ -528,9 +524,7 @@
529525 }
530526
531527 public static function parserTestTables( &$tables ) {
532 - $tables[] = 'revtag_type';
533528 $tables[] = 'revtag';
534 -
535529 return true;
536530 }
537531
Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -279,14 +279,13 @@
280280 */
281281 public static function isFuzzy( Title $title ) {
282282 $dbr = wfGetDB( DB_SLAVE );
283 - $id = $dbr->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ );
284283
285284 $tables = array( 'page', 'revtag' );
286285 $fields = array( 'rt_type' );
287286 $conds = array(
288287 'page_namespace' => $title->getNamespace(),
289288 'page_title' => $title->getDBkey(),
290 - 'rt_type' => $id,
 289+ 'rt_type' => RevTag::getType( 'fuzzy' ),
291290 'page_id=rt_page',
292291 'page_latest=rt_revision'
293292 );
@@ -394,11 +393,9 @@
395394 // begin fuzzy tag.
396395 $dbw = wfGetDB( DB_MASTER );
397396
398 - $id = $dbw->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ );
399 -
400397 $conds = array(
401398 'rt_page' => $article->getTitle()->getArticleId(),
402 - 'rt_type' => $id,
 399+ 'rt_type' => RevTag::getType( 'fuzzy' ),
403400 'rt_revision' => $rev
404401 );
405402 // Remove any existing fuzzy tags for this revision
@@ -424,12 +421,9 @@
425422 if ( $definitionTitle && $definitionTitle->exists() ) {
426423 $definitionRevision = $definitionTitle->getLatestRevID();
427424
428 - $id = $dbw->selectField( 'revtag_type', 'rtt_id',
429 - array( 'rtt_name' => 'tp:transver' ), __METHOD__ );
430 -
431425 $conds = array(
432426 'rt_page' => $title->getArticleId(),
433 - 'rt_type' => $id,
 427+ 'rt_type' => RevTag::getType( 'tp:transver' ),
434428 'rt_revision' => $rev,
435429 'rt_value' => $definitionRevision,
436430 );
Index: trunk/extensions/Translate/Translate.php
@@ -15,7 +15,7 @@
1616 /**
1717 * Version number used in extension credits and in other placed where needed.
1818 */
19 -define( 'TRANSLATE_VERSION', '2011-08-23' );
 19+define( 'TRANSLATE_VERSION', '2011-08-26' );
2020
2121 /**
2222 * Extension credits properties.
@@ -672,30 +672,13 @@
673673 return true;
674674 }
675675
676 - /** Add our tags if they are not registered yet
677 - * tp:tag is called also the ready tag
678 - * @todo Remove useless complication that is revtag_type table.
679 - */
680 - $tags = array( 'tp:mark', 'tp:tag', 'tp:transver', 'fuzzy' );
681 -
682676 $dbw = wfGetDB( DB_MASTER );
683 - if ( !$dbw->tableExists( 'revtag_type' ) ) {
 677+ if ( !$dbw->tableExists( 'revtag' ) ) {
684678 $wgHooks['SiteNoticeAfter'][] = array( 'efTranslateCheckWarn', 'tpt-install' );
685679 return false;
686680 }
687681
688 - foreach ( $tags as $tag ) {
689 - /// @todo: use insert ignore
690 - $field = array( 'rtt_name' => $tag );
691 - $ret = $dbw->selectField( 'revtag_type', 'rtt_name', $field, __METHOD__ );
692 -
693 - if ( $ret !== $tag ) {
694 - $dbw->insert( 'revtag_type', $field, __METHOD__ );
695 - }
696 - }
697 -
698682 $wgMemc->set( $memcKey, $version );
699 -
700683 return true;
701684 }
702685
Index: trunk/extensions/Translate/_autoload.php
@@ -112,6 +112,7 @@
113113 $wgAutoloadClasses['TranslateYaml'] = $dir . 'utils/TranslateYaml.php';
114114
115115 $wgAutoloadClasses['TranslateBC'] = $dir . 'utils/CompatibilityCode.php';
 116+$wgAutoloadClasses['RevTag'] = $dir . 'utils/RevTag.php';
116117
117118 $wgAutoloadClasses['MessageHandle'] = $dir . 'utils/MessageHandle.php';
118119
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -878,12 +878,9 @@
879879 }
880880
881881 $db = wfGetDB( DB_MASTER );
882 - $id = $db->selectField( 'revtag_type', 'rtt_id',
883 - array( 'rtt_name' => 'tp:transver' ), __METHOD__ );
884 -
885882 $conds = array(
886883 'rt_page' => $this->title->getArticleId(),
887 - 'rt_type' => $id,
 884+ 'rt_type' => RevTag::getType( 'tp:transver' ),
888885 'rt_revision' => $this->title->getLatestRevID(),
889886 );
890887

Sign-offs

UserFlagDate
Siebrandtested14:06, 30 August 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r95592Followup r95558: forgot to svn add this filenikerabbit07:38, 27 August 2011
r95593Another followup to r95558: missed on $idnikerabbit08:15, 27 August 2011

Status & tagging log