r89371 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89370‎ | r89371 | r89372 >
Date:23:49, 2 June 2011
Author:demon
Status:deferred (Comments)
Tags:
Comment:
Various OpenID cleanups (did them as I went)
* Drop 1.15 and below Preference hooks
* Drop some unused functions
* Fix $wgAvailableRights
* Move SQL stuff to patches/, use shorthand for /*_*/ and fix /*i*/
* Just used echo instead of wfOut() in LoadExtensionSchemaUpdates. Yeah it's ugly, but I don't feel like fixing the 1.16/1.17 discrepency here yet
Modified paths:
  • /trunk/extensions/OpenID/OpenID.hooks.php (modified) (history)
  • /trunk/extensions/OpenID/OpenID.setup.php (modified) (history)
  • /trunk/extensions/OpenID/openid_table.pg.sql (deleted) (history)
  • /trunk/extensions/OpenID/openid_table.sql (deleted) (history)
  • /trunk/extensions/OpenID/patch-uoi_user-not-unique.sql (deleted) (history)
  • /trunk/extensions/OpenID/patches (added) (history)
  • /trunk/extensions/OpenID/patches/openid_table.pg.sql (added) (history)
  • /trunk/extensions/OpenID/patches/openid_table.sql (added) (history)
  • /trunk/extensions/OpenID/patches/patch-uoi_user-not-unique.sql (added) (history)

Diff [purge]

Index: trunk/extensions/OpenID/openid_table.sql
@@ -1,10 +0,0 @@
2 -
3 -CREATE TABLE /*$wgDBprefix*/user_openid (
4 - uoi_openid varchar(255) NOT NULL PRIMARY KEY,
5 - uoi_user int(5) unsigned NOT NULL
6 -) /*$wgDBTableOptions*/;
7 -
8 -CREATE INDEX /*$wgDBprefix*/user_openid_user ON /*$wgDBprefix*/user_openid(uoi_user);
Index: trunk/extensions/OpenID/patch-uoi_user-not-unique.sql
@@ -1,6 +0,0 @@
2 -
3 -ALTER TABLE /*$wgDBprefix*/user_openid DROP INDEX uoi_user;
4 -CREATE INDEX /*$wgDBprefix*/user_openid_user ON /*$wgDBprefix*/user_openid(uoi_user);
Index: trunk/extensions/OpenID/openid_table.pg.sql
@@ -1,9 +0,0 @@
2 -
3 -
4 -CREATE TABLE user_openid (
5 - uoi_openid VARCHAR(255) NOT NULL PRIMARY KEY,
6 - uoi_user INTEGER NOT NULL REFERENCES mwuser(user_id)
7 -);
8 -
9 -CREATE INDEX user_openid_user ON user_openid(uoi_user);
Index: trunk/extensions/OpenID/OpenID.hooks.php
@@ -150,7 +150,6 @@
151151 $info .= $user->getSkin()->link( SpecialPage::getTitleFor( 'OpenIDConvert' ), wfMsgHtml( 'openid-add-url' ) );
152152 return $info;
153153 }
154 -
155154
156155 public static function onGetPreferences( $user, &$preferences ) {
157156 global $wgOpenIDShowUrlOnUserPage, $wgAllowRealName;
@@ -234,7 +233,6 @@
235234 return true;
236235 }
237236
238 -
239237 public static function onDeleteAccount( &$userObj ) {
240238 global $wgOut;
241239
@@ -288,105 +286,8 @@
289287
290288 }
291289
292 - # list of preferences used by extension
293 - private static $oidPrefs = array( 'hide' );
294 - private static $oidUpdateOnLogin = array( 'nickname', 'email', 'fullname',
295 - 'language', 'timezone' );
296 -
297 - private static function getToggles() {
298 - $toggles = self::$oidPrefs;
299 - foreach( self::$oidUpdateOnLogin as $pref ) {
300 - $toggles[] = 'update-on-login-' . $pref;
301 - }
302 - return $toggles;
303 - }
304 -
305 - public static function onInitPreferencesForm( $prefs, $request ) {
306 - foreach ( self::getToggles() as $oidPref ) {
307 - $prefs->mToggles['openid-' . $oidPref]
308 - = $request->getCheck( "wpOpOpenID-" . $oidPref ) ? 1 : 0;
309 - }
310 -
311 - return true;
312 - }
313 -
314 - public static function onRenderPreferencesForm( $prefs, $out ) {
315 - global $wgUser;
316 -
317 - $out->addHeadItem( 'openidwikitablestyle', self::wikitableStyle() );
318 -
319 - $out->addHTML( "\n<fieldset>\n<legend>" . wfMsgHtml( 'prefs-openid' ) . "</legend>\n<table>\n" );
320 -
321 - #$out->addWikiText( wfMsg( 'openid-prefstext' ) );
322 -
323 - foreach ( self::$oidPrefs as $oidPref ) {
324 - $name = 'wpOpOpenID-' . $oidPref;
325 - $out->addHTML(
326 - Xml::tags( 'tr', array(),
327 - Xml::tags( 'td', array( 'style' => 'width: 20%;' ), '' ) .
328 - Xml::tags( 'td', array(),
329 - Xml::tags( 'div', array( 'class' => 'toggle' ),
330 - Xml::check( $name, $prefs->mToggles['openid-' . $oidPref] ) .
331 - Xml::tags( 'span', array( 'class' => 'toggletext' ),
332 - Xml::label( wfMsg( 'openid-pref-' . $oidPref ), $name )
333 - )
334 - )
335 - )
336 - )
337 - );
338 - }
339 -
340 - $out->addHTML( Xml::openElement( 'tr' ) . Xml::element( 'td', array(),
341 - wfMsg( 'openid-pref-update-userinfo-on-login' ) ) . Xml::openElement( 'td' ) );
342 -
343 - $first = true;
344 - foreach ( self::$oidUpdateOnLogin as $oidPref ) {
345 - if ( $first ) {
346 - $first = false;
347 - } else {
348 - #$out->addHTML( '<br />' );
349 - }
350 - $name = 'wpOpOpenID-update-on-login-' . $oidPref;
351 - $out->addHTML(
352 - Xml::tags( 'div', array( 'class' => 'toggle' ),
353 - Xml::check( $name, $prefs->mToggles['openid-update-on-login-' . $oidPref] ) .
354 - Xml::tags( 'span', array( 'class' => 'toggletext' ),
355 - Xml::label( wfMsg( 'openid' . $oidPref ), $name )
356 - )
357 - )
358 - );
359 - }
360 -
361 - $out->addHTML(
362 - "</td></tr>\n<tr><td>" . wfMsgHtml( 'openid-urls-desc' ) .
363 - "</td><td>" . self::getInfoTable( $wgUser ) .
364 - "</td></tr></table></fieldset>\n\n"
365 - );
366 -
367 - return true;
368 - }
369 -
370 - public static function onSavePreferences( $prefs, $user, &$message, $old ) {
371 - foreach ( self::getToggles() as $oidPref ) {
372 - $user->setOption( 'openid-' . $oidPref, $prefs->mToggles['openid-' . $oidPref] );
373 - wfDebugLog( 'OpenID', 'Setting user preferences: ' . print_r( $user, true ) );
374 - }
375 -
376 - $user->saveSettings();
377 -
378 - return true;
379 - }
380 -
381 - public static function onResetPreferences( $prefs, $user ) {
382 - foreach ( self::getToggles() as $oidPref ) {
383 - $prefs->mToggles['openid-' . $oidPref] = $user->getOption( 'openid-' . $oidPref );
384 - }
385 -
386 - return true;
387 - }
388 -
389290 public static function onLoadExtensionSchemaUpdates( $updater = null ) {
390 - $base = dirname( __FILE__ );
 291+ $base = dirname( __FILE__ ) . '/patches';
391292 if ( $updater === null ) { // < 1.17
392293 global $wgDBtype, $wgUpdates, $wgExtNewTables;
393294 if ( $wgDBtype == 'mysql' ) {
@@ -421,11 +322,11 @@
422323
423324 $info = $db->fieldInfo( 'user_openid', 'uoi_user' );
424325 if ( !$info->isMultipleKey() ) {
425 - wfOut( "Making uoi_user filed not unique..." );
 326+ echo( "Making uoi_user filed not unique..." );
426327 $db->sourceFile( dirname( __FILE__ ) . '/patch-uoi_user-not-unique.sql' );
427 - wfOut( " done.\n" );
 328+ echo( " done.\n" );
428329 } else {
429 - wfOut( "...uoi_user field is already not unique.\n" );
 330+ echo( "...uoi_user field is already not unique.\n" );
430331 }
431332 }
432333
@@ -442,29 +343,4 @@
443344
444345 EOS;
445346 }
446 -
447 - private static function wikitableStyle() {
448 - return <<<EOS
449 -<style type='text/css'>
450 -table.wikitable {
451 - margin: 1em 1em 1em 0;
452 - background: #f9f9f9;
453 - border: 1px #aaa solid;
454 - border-collapse: collapse;
455347 }
456 -.wikitable th, .wikitable td {
457 - border: 1px #aaa solid;
458 - padding: 0.2em;
459 -}
460 -.wikitable th {
461 - background: #f2f2f2;
462 - text-align: center;
463 -}
464 -.wikitable caption {
465 - font-weight: bold;
466 -}
467 -</style>
468 -
469 -EOS;
470 - }
471 -}
Index: trunk/extensions/OpenID/patches/openid_table.sql
@@ -0,0 +1,10 @@
 2+--
 3+-- SQL schema for OpenID extension
 4+--
 5+
 6+CREATE TABLE /*_*/user_openid (
 7+ uoi_openid varchar(255) NOT NULL PRIMARY KEY,
 8+ uoi_user int(5) unsigned NOT NULL
 9+) /*$wgDBTableOptions*/;
 10+
 11+CREATE INDEX /*i*/user_openid_user ON /*_*/user_openid(uoi_user);
Property changes on: trunk/extensions/OpenID/patches/openid_table.sql
___________________________________________________________________
Added: svn:eol-style
112 + native
Index: trunk/extensions/OpenID/patches/patch-uoi_user-not-unique.sql
@@ -0,0 +1,6 @@
 2+--
 3+-- SQL schema update for OpenID extension to make the uoi_user field not unique
 4+--
 5+
 6+ALTER TABLE /*_*/user_openid DROP INDEX uoi_user;
 7+CREATE INDEX /*i*/user_openid_user ON /*_*/user_openid(uoi_user);
Property changes on: trunk/extensions/OpenID/patches/patch-uoi_user-not-unique.sql
___________________________________________________________________
Added: svn:eol-style
18 + native
Index: trunk/extensions/OpenID/patches/openid_table.pg.sql
@@ -0,0 +1,9 @@
 2+
 3+-- Schema for the OpenID extension (Postgres version)
 4+
 5+CREATE TABLE /*_*/user_openid (
 6+ uoi_openid VARCHAR(255) NOT NULL PRIMARY KEY,
 7+ uoi_user INTEGER NOT NULL REFERENCES mwuser(user_id)
 8+);
 9+
 10+CREATE INDEX /*i*/user_openid_user ON /*_*/user_openid(uoi_user);
Property changes on: trunk/extensions/OpenID/patches/openid_table.pg.sql
___________________________________________________________________
Added: svn:eol-style
111 + native
Index: trunk/extensions/OpenID/OpenID.setup.php
@@ -287,17 +287,12 @@
288288 # 1.16+
289289 $wgHooks['GetPreferences'][] = 'OpenIDHooks::onGetPreferences';
290290
291 -# < 1.16
292 -$wgHooks['RenderPreferencesForm'][] = 'OpenIDHooks::onRenderPreferencesForm';
293 -$wgHooks['InitPreferencesForm'][] = 'OpenIDHooks::onInitPreferencesForm';
294 -$wgHooks['ResetPreferences'][] = 'OpenIDHooks::onResetPreferences';
295 -$wgHooks['SavePreferences'][] = 'OpenIDHooks::onSavePreferences';
296 -
297291 # FIXME, function does not exist
298292 # $wgHooks['UserLoginForm'][] = 'OpenIDHooks::onUserLoginForm';
299293
300294 # new user rights
301 -$wgAvailableRights[] = array( 'openid-dashboard-access', 'openid-dashboard-admin' );
 295+$wgAvailableRights[] = 'openid-dashboard-access';
 296+$wgAvailableRights[] = 'openid-dashboard-admin';
302297
303298 # allow users to read access the dashboard
304299 $wgGroupPermissions['user']['openid-dashboard-access'] = true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r89377* Rewrite optionToTable to be like a modern maintenance script...demon02:05, 3 June 2011

Comments

#Comment by Nikerabbit (talk | contribs)   08:34, 3 June 2011

This should probably be field.

+echo( "Making uoi_user filed not unique..." );
#Comment by Wikinaut (talk | contribs)   21:18, 6 June 2011

It is not fully clear (to me) and not fully tested whether the "dropping 1.15 and below Preference hooks" breaks anything in the OpenID specific user preferences saving/restoring. I need to check this, marked as "fixme" until then. All other patches are ok.

#Comment by 😂 (talk | contribs)   21:27, 6 June 2011

Those hooks don't even exist in 1.16 or above, so removing them won't affect anything. All preferences are done by a single hook now, which I kept.

#Comment by 😂 (talk | contribs)   17:48, 21 July 2011

This was tested before I committed it. There's absolutely nothing wrong with this revision, setting back to new.

Status & tagging log