Index: trunk/extensions/OpenID/optionToTable.php |
— | — | @@ -23,28 +23,40 @@ |
24 | 24 | * @ingroup Extensions |
25 | 25 | */ |
26 | 26 | |
27 | | -require_once( 'commandLine.inc' ); |
28 | | -ini_set( "include_path", "/usr/share/php:" . ini_get( "include_path" ) ); |
29 | | - |
30 | | -require_once( "$IP/extensions/OpenID/Consumer.php" ); |
31 | | - |
32 | | -global $wgSharedDB, $wgDBprefix; |
33 | | -$tableName = "${wgDBprefix}user_openid"; |
34 | | -if ( isset( $wgSharedDB ) ) { |
35 | | - $tableName = "`$wgSharedDB`.$tableName"; |
| 27 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 28 | +if ( $IP === false ) { |
| 29 | + $IP = dirname( __FILE__ ) . '/../..'; |
36 | 30 | } |
| 31 | +require( "$IP/maintenance/Maintenance.php" ); |
37 | 32 | |
38 | | -$dbr = wfGetDB( DB_SLAVE ); |
| 33 | +class OpenIDOptionToTable extends Maintenance { |
| 34 | + public function __construct() { |
| 35 | + parent::__construct(); |
| 36 | + $this->mDescription = 'Convert user_option-stored urls to the new openID table'; |
| 37 | + } |
39 | 38 | |
40 | | -$res = $dbr->select( array( 'user' ), |
41 | | - array( 'user_name' ), |
42 | | - array( 'user_options LIKE "%openid_url%"' ), |
43 | | - 'optionToTable', |
44 | | - array( 'ORDER BY' => 'user_name' ) ); |
| 39 | + public function execute() { |
| 40 | + $dbr = wfGetDB( DB_SLAVE ); |
| 41 | + if( !$dbr->tableExists( 'user_properties' ) ) { |
| 42 | + $this->error( "The OpenID extension requires at least MediaWiki 1.16.", true ); |
| 43 | + } |
45 | 44 | |
46 | | -while ( $res && $row = $dbr->fetchObject( $res ) ) { |
47 | | - $user = User::newFromName( $row->user_name ); |
48 | | - print( $user->getName() . ": " . $user->getOption( 'openid_url' ) . "\n" ); |
49 | | - OpenIDSetUserUrl( $user, $user->getOption( 'openid_url' ) ); |
| 45 | + $this->output( "Checking for legacy user_property rows..." ); |
| 46 | + $dbr = wfGetDB( DB_SLAVE ); |
| 47 | + $res = $dbr->select( array( 'user_properties' ), array( 'up_user' ), |
| 48 | + array( 'up_property' => 'openid_url' ), __METHOD__ ); |
| 49 | + if( $dbr->numRows( $res ) ) { |
| 50 | + foreach( $res as $row ) { |
| 51 | + $user = User::newFromId( $row->up_user ); |
| 52 | + $this->output( "\n\tFixing {$user->getName()}" ); |
| 53 | + SpecialOpenID::addUserUrl( $user, $user->getOption( 'openid_url' ) ); |
| 54 | + } |
| 55 | + $this->output( "done\n" ); |
| 56 | + } else { |
| 57 | + $this->output( "none found\n" ); |
| 58 | + } |
| 59 | + } |
50 | 60 | } |
51 | | -$dbr->freeResult( $res ); |
| 61 | + |
| 62 | +$maintClass = 'OpenIDOptionToTable'; |
| 63 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |