r74216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74215‎ | r74216 | r74217 >
Date:15:51, 3 October 2010
Author:ialex
Status:ok
Tags:
Comment:
Converted AbuseFilter extension to use the new version of the LoadExtensionSchemaUpdates hook
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
@@ -165,35 +165,56 @@
166166 return true;
167167 }
168168
169 - public static function onLoadExtensionSchemaUpdates() {
170 - global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes, $wgDBtype;
171 -
 169+ public static function onLoadExtensionSchemaUpdates( $updater = null ) {
172170 $dir = dirname( __FILE__ );
173171
174 - // DB updates
175 - if ( $wgDBtype == 'mysql' ) {
176 - $wgExtNewTables[] = array( 'abuse_filter', "$dir/abusefilter.tables.sql" );
177 - $wgExtNewTables[] = array( 'abuse_filter_history', "$dir/db_patches/patch-abuse_filter_history.sql" );
178 - $wgExtNewFields[] = array( 'abuse_filter_history', 'afh_changed_fields', "$dir/db_patches/patch-afh_changed_fields.sql" );
179 - $wgExtNewFields[] = array( 'abuse_filter', 'af_deleted', "$dir/db_patches/patch-af_deleted.sql" );
180 - $wgExtNewFields[] = array( 'abuse_filter', 'af_actions', "$dir/db_patches/patch-af_actions.sql" );
181 - $wgExtNewFields[] = array( 'abuse_filter', 'af_global', "$dir/db_patches/patch-global_filters.sql" );
182 - $wgExtNewIndexes[] = array( 'abuse_filter_log', 'filter_timestamp', "$dir/db_patches/patch-fix-indexes.sql" );
183 - } elseif ( $wgDBtype == 'postgres' ) {
184 - $wgExtNewTables = array_merge( $wgExtNewTables,
185 - array(
186 - array( 'abuse_filter', "$dir/abusefilter.tables.pg.sql" ),
187 - array( 'abuse_filter_history', "$dir/db_patches/patch-abuse_filter_history.pg.sql" ),
188 - ) );
189 - $wgExtPGNewFields[] = array( 'abuse_filter', 'af_actions', "TEXT NOT NULL DEFAULT ''" );
190 - $wgExtPGNewFields[] = array( 'abuse_filter', 'af_deleted', 'SMALLINT NOT NULL DEFAULT 0' );
191 - $wgExtPGNewFields[] = array( 'abuse_filter', 'af_global', 'SMALLINT NOT NULL DEFAULT 0' );
192 -
193 - $wgExtPGNewFields[] = array( 'abuse_filter_log', 'afl_wiki', 'TEXT' );
194 - $wgExtPGNewFields[] = array( 'abuse_filter_log', 'afl_deleted', 'SMALLINT' );
195 - $wgExtPGAlteredFields[] = array( 'abuse_filter_log', 'afl_filter', 'TEXT' );
196 -
197 - $wgExtNewIndexes[] = array( 'abuse_filter_log', 'abuse_filter_log_ip', "(afl_ip)" );
 172+ if ( $updater === null ) {
 173+ global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes, $wgDBtype;
 174+ // DB updates
 175+ if ( $wgDBtype == 'mysql' ) {
 176+ $wgExtNewTables[] = array( 'abuse_filter', "$dir/abusefilter.tables.sql" );
 177+ $wgExtNewTables[] = array( 'abuse_filter_history', "$dir/db_patches/patch-abuse_filter_history.sql" );
 178+ $wgExtNewFields[] = array( 'abuse_filter_history', 'afh_changed_fields', "$dir/db_patches/patch-afh_changed_fields.sql" );
 179+ $wgExtNewFields[] = array( 'abuse_filter', 'af_deleted', "$dir/db_patches/patch-af_deleted.sql" );
 180+ $wgExtNewFields[] = array( 'abuse_filter', 'af_actions', "$dir/db_patches/patch-af_actions.sql" );
 181+ $wgExtNewFields[] = array( 'abuse_filter', 'af_global', "$dir/db_patches/patch-global_filters.sql" );
 182+ $wgExtNewIndexes[] = array( 'abuse_filter_log', 'filter_timestamp', "$dir/db_patches/patch-fix-indexes.sql" );
 183+ } elseif ( $wgDBtype == 'postgres' ) {
 184+ $wgExtNewTables = array_merge( $wgExtNewTables,
 185+ array(
 186+ array( 'abuse_filter', "$dir/abusefilter.tables.pg.sql" ),
 187+ array( 'abuse_filter_history', "$dir/db_patches/patch-abuse_filter_history.pg.sql" ),
 188+ ) );
 189+ $wgExtPGNewFields[] = array( 'abuse_filter', 'af_actions', "TEXT NOT NULL DEFAULT ''" );
 190+ $wgExtPGNewFields[] = array( 'abuse_filter', 'af_deleted', 'SMALLINT NOT NULL DEFAULT 0' );
 191+ $wgExtPGNewFields[] = array( 'abuse_filter', 'af_global', 'SMALLINT NOT NULL DEFAULT 0' );
 192+
 193+ $wgExtPGNewFields[] = array( 'abuse_filter_log', 'afl_wiki', 'TEXT' );
 194+ $wgExtPGNewFields[] = array( 'abuse_filter_log', 'afl_deleted', 'SMALLINT' );
 195+ $wgExtPGAlteredFields[] = array( 'abuse_filter_log', 'afl_filter', 'TEXT' );
 196+
 197+ $wgExtNewIndexes[] = array( 'abuse_filter_log', 'abuse_filter_log_ip', "(afl_ip)" );
 198+ }
 199+ } else {
 200+ if ( $updater->getDB()->getType() == 'mysql' ) {
 201+ $updater->addExtensionUpdate( array( 'addTable', 'abuse_filter', "$dir/abusefilter.tables.sql", true ) );
 202+ $updater->addExtensionUpdate( array( 'addTable', 'abuse_filter_history', "$dir/db_patches/patch-abuse_filter_history.sql", true ) );
 203+ $updater->addExtensionUpdate( array( 'addField', 'abuse_filter_history', 'afh_changed_fields', "$dir/db_patches/patch-afh_changed_fields.sql", true ) );
 204+ $updater->addExtensionUpdate( array( 'addField', 'abuse_filter', 'af_deleted', "$dir/db_patches/patch-af_deleted.sql", true ) );
 205+ $updater->addExtensionUpdate( array( 'addField', 'abuse_filter', 'af_actions', "$dir/db_patches/patch-af_actions.sql", true ) );
 206+ $updater->addExtensionUpdate( array( 'addField', 'abuse_filter', 'af_global', "$dir/db_patches/patch-global_filters.sql", true ) );
 207+ $updater->addExtensionUpdate( array( 'addIndex', 'abuse_filter_log', 'filter_timestamp', "$dir/db_patches/patch-fix-indexes.sql", true ) );
 208+ } elseif ( $updater->getDB()->getType() == 'postgres' ) {
 209+ $updater->addExtensionUpdate( array( 'addTable', 'abuse_filter', "$dir/abusefilter.tables.pg.sql", true ) );
 210+ $updater->addExtensionUpdate( array( 'addTable', 'abuse_filter_history', "$dir/db_patches/patch-abuse_filter_history.pg.sql", true ) );
 211+ $updater->addExtensionUpdate( array( 'addPgField', 'abuse_filter', 'af_actions', "TEXT NOT NULL DEFAULT ''" ) );
 212+ $updater->addExtensionUpdate( array( 'addPgField', 'abuse_filter', 'af_deleted', 'SMALLINT NOT NULL DEFAULT 0' ) );
 213+ $updater->addExtensionUpdate( array( 'addPgField', 'abuse_filter', 'af_global', 'SMALLINT NOT NULL DEFAULT 0' ) );
 214+ $updater->addExtensionUpdate( array( 'addPgField', 'abuse_filter_log', 'afl_wiki', 'TEXT' ) );
 215+ $updater->addExtensionUpdate( array( 'addPgField', 'abuse_filter_log', 'afl_deleted', 'SMALLINT' ) );
 216+ $updater->addExtensionUpdate( array( 'changeField', 'abuse_filter_log', 'afl_filter', 'TEXT' ) );
 217+ $updater->addExtensionUpdate( array( 'addPgExtIndex', 'abuse_filter_log', 'abuse_filter_log_ip', "(afl_ip)" ) );
 218+ }
198219 }
199220 return true;
200221 }

Status & tagging log