class FiveUpgrade {
function FiveUpgrade() {
- global $wgDatabase;
$this->conversionTables = $this->prepareWindows1252();
$this->dbw =& $this->newConnection();
* @access private
*/
function &newConnection() {
- global $wgDBadminuser, $wgDBadminpassword;
+ global $wgDBadminuser, $wgDBadminpassword, $wgDBtype;
global $wgDBserver, $wgDBname;
- $db = new Database( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+ $dbclass = 'Database' . ucfirst( $wgDBtype ) ;
+ $db = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
return $db;
}
* @access private
*/
function &streamConnection() {
+ global $wgDBtype;
+
$timeout = 3600 * 24;
$db =& $this->newConnection();
$db->bufferResults( false );
- $db->query( "SET net_read_timeout=$timeout" );
- $db->query( "SET net_write_timeout=$timeout" );
+ if ($wgDBtype == 'mysql') {
+ $db->query( "SET net_read_timeout=$timeout" );
+ $db->query( "SET net_write_timeout=$timeout" );
+ }
return $db;
}
# http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
static $cp1252 = array(
0x80 => 0x20AC, #EURO SIGN
- 0x81 => UNICODE_REPLACEMENT,
+ 0x81 => 0xFFFD, #REPLACEMENT CHARACTER (no mapping)
0x82 => 0x201A, #SINGLE LOW-9 QUOTATION MARK
0x83 => 0x0192, #LATIN SMALL LETTER F WITH HOOK
0x84 => 0x201E, #DOUBLE LOW-9 QUOTATION MARK
0x8A => 0x0160, #LATIN CAPITAL LETTER S WITH CARON
0x8B => 0x2039, #SINGLE LEFT-POINTING ANGLE QUOTATION MARK
0x8C => 0x0152, #LATIN CAPITAL LIGATURE OE
- 0x8D => UNICODE_REPLACEMENT,
+ 0x8D => 0xFFFD, #REPLACEMENT CHARACTER (no mapping)
0x8E => 0x017D, #LATIN CAPITAL LETTER Z WITH CARON
- 0x8F => UNICODE_REPLACEMENT,
- 0x90 => UNICODE_REPLACEMENT,
+ 0x8F => 0xFFFD, #REPLACEMENT CHARACTER (no mapping)
+ 0x90 => 0xFFFD, #REPLACEMENT CHARACTER (no mapping)
0x91 => 0x2018, #LEFT SINGLE QUOTATION MARK
0x92 => 0x2019, #RIGHT SINGLE QUOTATION MARK
0x93 => 0x201C, #LEFT DOUBLE QUOTATION MARK
0x9A => 0x0161, #LATIN SMALL LETTER S WITH CARON
0x9B => 0x203A, #SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
0x9C => 0x0153, #LATIN SMALL LIGATURE OE
- 0x9D => UNICODE_REPLACEMENT,
+ 0x9D => 0xFFFD, #REPLACEMENT CHARACTER (no mapping)
0x9E => 0x017E, #LATIN SMALL LETTER Z WITH CARON
0x9F => 0x0178, #LATIN CAPITAL LETTER Y WITH DIAERESIS
);
$name_temp = $name . '_temp';
$this->log( "Migrating $name table to $name_temp..." );
- $table = $this->dbw->tableName( $name );
$table_temp = $this->dbw->tableName( $name_temp );
// Create temporary table; we're going to copy everything in there,
$this->log( "...converting from cur/old to page/revision/text DB structure." );
- extract( $this->dbw->tableNames( 'cur', 'old', 'page', 'revision', 'text' ) );
+ list ($cur, $old, $page, $revision, $text) = $this->dbw->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
$this->log( "Creating page and revision tables..." );
$this->dbw->query("CREATE TABLE $page (
function upgradeLinks() {
$fname = 'FiveUpgrade::upgradeLinks';
$chunksize = 200;
- extract( $this->dbw->tableNames( 'links', 'brokenlinks', 'pagelinks', 'cur' ) );
+ list ($links, $brokenlinks, $pagelinks, $cur) = $this->dbw->tableNamesN( 'links', 'brokenlinks', 'pagelinks', 'cur' );
$this->log( 'Checking for interwiki table change in case of bogus items...' );
if( $this->dbw->fieldExists( 'interwiki', 'iw_trans' ) ) {
$this->log( 'interwiki has iw_trans.' );
} else {
+ global $IP;
$this->log( 'adding iw_trans...' );
- dbsource( 'maintenance/archives/patch-interwiki-trans.sql', $this->dbw );
+ dbsource( $IP . '/maintenance/archives/patch-interwiki-trans.sql', $this->dbw );
$this->log( 'added iw_trans.' );
}
return $copy;
}
- function imageInfo( $name, $subdirCallback='wfImageDir', $basename = null ) {
- if( is_null( $basename ) ) $basename = $name;
- $dir = call_user_func( $subdirCallback, $basename );
- $filename = $dir . '/' . $name;
+ function imageInfo( $filename ) {
$info = array(
'width' => 0,
'height' => 0,
'major' => '',
'minor' => '' );
- $magic =& wfGetMimeMagic();
+ $magic = MimeMagic::singleton();
$mime = $magic->guessMimeType( $filename, true );
list( $info['major'], $info['minor'] ) = explode( '/', $mime );
$info['media'] = $magic->getMediaType( $filename, $mime );
- # Height and width
- $gis = false;
- if( $mime == 'image/svg' ) {
- $gis = wfGetSVGsize( $filename );
- } elseif( $magic->isPHPImageType( $mime ) ) {
- $gis = getimagesize( $filename );
- } else {
- $this->log( "Surprising mime type: $mime" );
- }
- if( $gis ) {
- $info['width' ] = $gis[0];
- $info['height'] = $gis[1];
- }
- if( isset( $gis['bits'] ) ) {
+ $image = UnregisteredLocalFile::newFromPath( $filename, $mime );
+
+ $info['width'] = $image->getWidth();
+ $info['height'] = $image->getHeight();
+
+ $gis = $image->getImageSize();
+ if ( isset( $gis['bits'] ) ) {
$info['bits'] = $gis['bits'];
}
function clearTable( $table ) {
print "Clearing $table...\n";
$tableName = $this->db->tableName( $table );
- $this->db->query( 'TRUNCATE $tableName' );
+ $this->db->query( "TRUNCATE $tableName" );
}
/**
$this->log( "$oldpath -> $newpath" );
if( rename( $oldpath, $newpath ) ) {
- $relpath = $this->relativize( $newpath, dirname( $oldpath ) );
+ $relpath = wfRelativePath( $newpath, dirname( $oldpath ) );
if( !symlink( $relpath, $oldpath ) ) {
$this->log( "... symlink failed!" );
}
}
}
- /**
- * Generate a relative path name to the given file.
- * Assumes Unix-style paths, separators, and semantics.
- *
- * @param string $path Absolute destination path including target filename
- * @param string $from Absolute source path, directory only
- * @return string
- * @access private
- * @static
- */
- function relativize( $path, $from ) {
- $pieces = explode( '/', dirname( $path ) );
- $against = explode( '/', $from );
-
- // Trim off common prefix
- while( count( $pieces ) && count( $against )
- && $pieces[0] == $against[0] ) {
- array_shift( $pieces );
- array_shift( $against );
- }
-
- // relative dots to bump us to the parent
- while( count( $against ) ) {
- array_unshift( $pieces, '..' );
- array_shift( $against );
- }
-
- array_push( $pieces, wfBaseName( $path ) );
-
- return implode( '/', $pieces );
- }
-
function upgradeOldImage() {
$tabledef = <<<END
CREATE TABLE $1 (
$fname = 'FiveUpgrade::upgradeWatchlist';
$chunksize = 100;
- extract( $this->dbw->tableNames( 'watchlist', 'watchlist_temp' ) );
+ list ($watchlist, $watchlist_temp) = $this->dbw->tableNamesN( 'watchlist', 'watchlist_temp' );
$this->log( 'Migrating watchlist table to watchlist_temp...' );
$this->dbw->query(
$add = array();
while( $row = $this->dbr->fetchObject( $result ) ) {
- $now = $this->dbw->timestamp();
$add[] = array(
'wl_user' => $row->wl_user,
'wl_namespace' => Namespace::getSubject( $row->wl_namespace ),
}
function upgradeLogging() {
- $tabledef = <<<END
+ $tabledef = <<<ENDS
CREATE TABLE $1 (
-- Symbolic keys for the general log type and the action type
-- within the log. The output format will be controlled by the
KEY page_time (log_namespace, log_title, log_timestamp)
) TYPE=InnoDB
-END;
+ENDS;
$fields = array(
'log_type' => MW_UPGRADE_COPY,
'log_action' => MW_UPGRADE_COPY,
}
function upgradeArchive() {
- $tabledef = <<<END
+ $tabledef = <<<ENDS
CREATE TABLE $1 (
ar_namespace int NOT NULL default '0',
ar_title varchar(255) binary NOT NULL default '',
KEY name_title_timestamp (ar_namespace,ar_title,ar_timestamp)
) TYPE=InnoDB
-END;
+ENDS;
$fields = array(
'ar_namespace' => MW_UPGRADE_COPY,
'ar_title' => MW_UPGRADE_ENCODE,
function upgradeImagelinks() {
global $wgUseLatin1;
if( $wgUseLatin1 ) {
- $tabledef = <<<END
+ $tabledef = <<<ENDS
CREATE TABLE $1 (
-- Key to page_id of the page containing the image / media link.
il_from int(8) unsigned NOT NULL default '0',
KEY (il_to)
) TYPE=InnoDB
-END;
+ENDS;
$fields = array(
'il_from' => MW_UPGRADE_COPY,
'il_to' => MW_UPGRADE_ENCODE );
function upgradeCategorylinks() {
global $wgUseLatin1;
if( $wgUseLatin1 ) {
- $tabledef = <<<END
+ $tabledef = <<<ENDS
CREATE TABLE $1 (
cl_from int(8) unsigned NOT NULL default '0',
cl_to varchar(255) binary NOT NULL default '',
KEY cl_sortkey(cl_to,cl_sortkey),
KEY cl_timestamp(cl_to,cl_timestamp)
) TYPE=InnoDB
-END;
+ENDS;
$fields = array(
'cl_from' => MW_UPGRADE_COPY,
'cl_to' => MW_UPGRADE_ENCODE,
function upgradeIpblocks() {
global $wgUseLatin1;
if( $wgUseLatin1 ) {
- $tabledef = <<<END
+ $tabledef = <<<ENDS
CREATE TABLE $1 (
ipb_id int(8) NOT NULL auto_increment,
ipb_address varchar(40) binary NOT NULL default '',
INDEX ipb_user (ipb_user)
) TYPE=InnoDB
-END;
+ENDS;
$fields = array(
'ipb_id' => MW_UPGRADE_COPY,
'ipb_address' => MW_UPGRADE_COPY,
function upgradeRecentchanges() {
// There's a format change in the namespace field
- $tabledef = <<<END
+ $tabledef = <<<ENDS
CREATE TABLE $1 (
rc_id int(8) NOT NULL auto_increment,
rc_timestamp varchar(14) binary NOT NULL default '',
INDEX rc_ip (rc_ip)
) TYPE=InnoDB
-END;
+ENDS;
$fields = array(
'rc_id' => MW_UPGRADE_COPY,
'rc_timestamp' => MW_UPGRADE_COPY,
function upgradeQuerycache() {
// There's a format change in the namespace field
- $tabledef = <<<END
+ $tabledef = <<<ENDS
CREATE TABLE $1 (
-- A key name, generally the base name of of the special page.
qc_type char(32) NOT NULL,
KEY (qc_type,qc_value)
) TYPE=InnoDB
-END;
+ENDS;
$fields = array(
'qc_type' => MW_UPGRADE_COPY,
'qc_value' => MW_UPGRADE_COPY,