fiveupgrade.inc

来自「php 开发的内容管理系统」· INC 代码 · 共 1,215 行 · 第 1/3 页

INC
1,215
字号
	function upgradeOldImage() {		$tabledef = <<<ENDCREATE TABLE $1 (  -- Base filename: key to image.img_name  oi_name varchar(255) binary NOT NULL default '',  -- Filename of the archived file.  -- This is generally a timestamp and '!' prepended to the base name.  oi_archive_name varchar(255) binary NOT NULL default '',  -- Other fields as in image...  oi_size int(8) unsigned NOT NULL default 0,  oi_width int(5) NOT NULL default 0,  oi_height int(5) NOT NULL default 0,  oi_bits int(3) NOT NULL default 0,  oi_description tinyblob NOT NULL default '',  oi_user int(5) unsigned NOT NULL default '0',  oi_user_text varchar(255) binary NOT NULL default '',  oi_timestamp char(14) binary NOT NULL default '',  INDEX oi_name (oi_name(10))) TYPE=InnoDB;END;		$fields = array(			'oi_name'         => MW_UPGRADE_ENCODE,			'oi_archive_name' => MW_UPGRADE_ENCODE,			'oi_size'         => MW_UPGRADE_COPY,			'oi_width'        => MW_UPGRADE_CALLBACK,			'oi_height'       => MW_UPGRADE_CALLBACK,			'oi_bits'         => MW_UPGRADE_CALLBACK,			'oi_description'  => MW_UPGRADE_ENCODE,			'oi_user'         => MW_UPGRADE_COPY,			'oi_user_text'    => MW_UPGRADE_ENCODE,			'oi_timestamp'    => MW_UPGRADE_COPY );		$this->copyTable( 'oldimage', $tabledef, $fields,			array( &$this, 'oldimageCallback' ) );	}	function oldimageCallback( $row, $copy ) {		global $options;		if( !isset( $options['noimage'] ) ) {			// Fill in the new image info fields			$info = $this->imageInfo( $row->oi_archive_name, 'wfImageArchiveDir', $row->oi_name );			$copy['oi_width' ] = $info['width' ];			$copy['oi_height'] = $info['height'];			$copy['oi_bits'  ] = $info['bits'  ];		}		// If doing UTF8 conversion the file must be renamed		$this->renameFile( $row->oi_archive_name, 'wfImageArchiveDir', $row->oi_name );		return $copy;	}	function upgradeWatchlist() {		$fname = 'FiveUpgrade::upgradeWatchlist';		$chunksize = 100;		extract( $this->dbw->tableNames( 'watchlist', 'watchlist_temp' ) );		$this->log( 'Migrating watchlist table to watchlist_temp...' );		$this->dbw->query("CREATE TABLE $watchlist_temp (  -- Key to user_id  wl_user int(5) unsigned NOT NULL,  -- Key to page_namespace/page_title  -- Note that users may watch patches which do not exist yet,  -- or existed in the past but have been deleted.  wl_namespace int NOT NULL default '0',  wl_title varchar(255) binary NOT NULL default '',  -- Timestamp when user was last sent a notification e-mail;  -- cleared when the user visits the page.  -- FIXME: add proper null support etc  wl_notificationtimestamp varchar(14) binary NOT NULL default '0',  UNIQUE KEY (wl_user, wl_namespace, wl_title),  KEY namespace_title (wl_namespace,wl_title)) TYPE=InnoDB;", $fname );		// Fix encoding for Latin-1 upgrades, add some fields,		// and double article to article+talk pairs		$numwatched = $this->dbw->selectField( 'watchlist', 'count(*)', '', $fname );		$this->setChunkScale( $chunksize, $numwatched * 2, 'watchlist_temp', $fname );		$result = $this->dbr->select( 'watchlist',			array(				'wl_user',				'wl_namespace',				'wl_title' ),			'',			$fname );		$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 ),				'wl_title'     =>           $this->conv( $row->wl_title ),				'wl_notificationtimestamp' =>            '0' );			$this->addChunk( $add );			$add[] = array(				'wl_user'      =>                        $row->wl_user,				'wl_namespace' =>    Namespace::getTalk( $row->wl_namespace ),				'wl_title'     =>           $this->conv( $row->wl_title ),				'wl_notificationtimestamp' =>            '0' );			$this->addChunk( $add );		}		$this->lastChunk( $add );		$this->dbr->freeResult( $result );		$this->log( 'Done converting watchlist.' );		$this->cleanupSwaps[] = 'watchlist';	}	function upgradeLogging() {		$tabledef = <<<ENDCREATE TABLE $1 (  -- Symbolic keys for the general log type and the action type  -- within the log. The output format will be controlled by the  -- action field, but only the type controls categorization.  log_type char(10) NOT NULL default '',  log_action char(10) NOT NULL default '',  -- Timestamp. Duh.  log_timestamp char(14) NOT NULL default '19700101000000',  -- The user who performed this action; key to user_id  log_user int unsigned NOT NULL default 0,  -- Key to the page affected. Where a user is the target,  -- this will point to the user page.  log_namespace int NOT NULL default 0,  log_title varchar(255) binary NOT NULL default '',  -- Freeform text. Interpreted as edit history comments.  log_comment varchar(255) NOT NULL default '',  -- LF separated list of miscellaneous parameters  log_params blob NOT NULL default '',  KEY type_time (log_type, log_timestamp),  KEY user_time (log_user, log_timestamp),  KEY page_time (log_namespace, log_title, log_timestamp)) TYPE=InnoDBEND;		$fields = array(			'log_type'      => MW_UPGRADE_COPY,			'log_action'    => MW_UPGRADE_COPY,			'log_timestamp' => MW_UPGRADE_COPY,			'log_user'      => MW_UPGRADE_COPY,			'log_namespace' => MW_UPGRADE_COPY,			'log_title'     => MW_UPGRADE_ENCODE,			'log_comment'   => MW_UPGRADE_ENCODE,			'log_params'    => MW_UPGRADE_ENCODE );		$this->copyTable( 'logging', $tabledef, $fields );	}	function upgradeArchive() {		$tabledef = <<<ENDCREATE TABLE $1 (  ar_namespace int NOT NULL default '0',  ar_title varchar(255) binary NOT NULL default '',  ar_text mediumblob NOT NULL default '',  ar_comment tinyblob NOT NULL default '',  ar_user int(5) unsigned NOT NULL default '0',  ar_user_text varchar(255) binary NOT NULL,  ar_timestamp char(14) binary NOT NULL default '',  ar_minor_edit tinyint(1) NOT NULL default '0',  ar_flags tinyblob NOT NULL default '',  ar_rev_id int(8) unsigned,  ar_text_id int(8) unsigned,  KEY name_title_timestamp (ar_namespace,ar_title,ar_timestamp)) TYPE=InnoDBEND;		$fields = array(			'ar_namespace'  => MW_UPGRADE_COPY,			'ar_title'      => MW_UPGRADE_ENCODE,			'ar_text'       => MW_UPGRADE_COPY,			'ar_comment'    => MW_UPGRADE_ENCODE,			'ar_user'       => MW_UPGRADE_COPY,			'ar_user_text'  => MW_UPGRADE_ENCODE,			'ar_timestamp'  => MW_UPGRADE_COPY,			'ar_minor_edit' => MW_UPGRADE_COPY,			'ar_flags'      => MW_UPGRADE_COPY,			'ar_rev_id'     => MW_UPGRADE_NULL,			'ar_text_id'    => MW_UPGRADE_NULL );		$this->copyTable( 'archive', $tabledef, $fields );	}	function upgradeImagelinks() {		global $wgUseLatin1;		if( $wgUseLatin1 ) {			$tabledef = <<<ENDCREATE TABLE $1 (  -- Key to page_id of the page containing the image / media link.  il_from int(8) unsigned NOT NULL default '0',  -- Filename of target image.  -- This is also the page_title of the file's description page;  -- all such pages are in namespace 6 (NS_IMAGE).  il_to varchar(255) binary NOT NULL default '',  UNIQUE KEY il_from(il_from,il_to),  KEY (il_to)) TYPE=InnoDBEND;			$fields = array(				'il_from' => MW_UPGRADE_COPY,				'il_to'   => MW_UPGRADE_ENCODE );			$this->copyTable( 'imagelinks', $tabledef, $fields );		}	}	function upgradeCategorylinks() {		global $wgUseLatin1;		if( $wgUseLatin1 ) {			$tabledef = <<<ENDCREATE TABLE $1 (  cl_from int(8) unsigned NOT NULL default '0',  cl_to varchar(255) binary NOT NULL default '',  cl_sortkey varchar(86) binary NOT NULL default '',  cl_timestamp timestamp NOT NULL,  UNIQUE KEY cl_from(cl_from,cl_to),  KEY cl_sortkey(cl_to,cl_sortkey),  KEY cl_timestamp(cl_to,cl_timestamp)) TYPE=InnoDBEND;			$fields = array(				'cl_from'      => MW_UPGRADE_COPY,				'cl_to'        => MW_UPGRADE_ENCODE,				'cl_sortkey'   => MW_UPGRADE_ENCODE,				'cl_timestamp' => MW_UPGRADE_COPY );			$this->copyTable( 'categorylinks', $tabledef, $fields );		}	}	function upgradeIpblocks() {		global $wgUseLatin1;		if( $wgUseLatin1 ) {			$tabledef = <<<ENDCREATE TABLE $1 (  ipb_id int(8) NOT NULL auto_increment,  ipb_address varchar(40) binary NOT NULL default '',  ipb_user int(8) unsigned NOT NULL default '0',  ipb_by int(8) unsigned NOT NULL default '0',  ipb_reason tinyblob NOT NULL default '',  ipb_timestamp char(14) binary NOT NULL default '',  ipb_auto tinyint(1) NOT NULL default '0',  ipb_expiry char(14) binary NOT NULL default '',  PRIMARY KEY ipb_id (ipb_id),  INDEX ipb_address (ipb_address),  INDEX ipb_user (ipb_user)) TYPE=InnoDBEND;			$fields = array(				'ipb_id'        => MW_UPGRADE_COPY,				'ipb_address'   => MW_UPGRADE_COPY,				'ipb_user'      => MW_UPGRADE_COPY,				'ipb_by'        => MW_UPGRADE_COPY,				'ipb_reason'    => MW_UPGRADE_ENCODE,				'ipb_timestamp' => MW_UPGRADE_COPY,				'ipb_auto'      => MW_UPGRADE_COPY,				'ipb_expiry'    => MW_UPGRADE_COPY );			$this->copyTable( 'ipblocks', $tabledef, $fields );		}	}	function upgradeRecentchanges() {		// There's a format change in the namespace field		$tabledef = <<<ENDCREATE TABLE $1 (  rc_id int(8) NOT NULL auto_increment,  rc_timestamp varchar(14) binary NOT NULL default '',  rc_cur_time varchar(14) binary NOT NULL default '',  rc_user int(10) unsigned NOT NULL default '0',  rc_user_text varchar(255) binary NOT NULL default '',  rc_namespace int NOT NULL default '0',  rc_title varchar(255) binary NOT NULL default '',  rc_comment varchar(255) binary NOT NULL default '',  rc_minor tinyint(3) unsigned NOT NULL default '0',  rc_bot tinyint(3) unsigned NOT NULL default '0',  rc_new tinyint(3) unsigned NOT NULL default '0',  rc_cur_id int(10) unsigned NOT NULL default '0',  rc_this_oldid int(10) unsigned NOT NULL default '0',  rc_last_oldid int(10) unsigned NOT NULL default '0',  rc_type tinyint(3) unsigned NOT NULL default '0',  rc_moved_to_ns tinyint(3) unsigned NOT NULL default '0',  rc_moved_to_title varchar(255) binary NOT NULL default '',  rc_patrolled tinyint(3) unsigned NOT NULL default '0',  rc_ip char(15) NOT NULL default '',  PRIMARY KEY rc_id (rc_id),  INDEX rc_timestamp (rc_timestamp),  INDEX rc_namespace_title (rc_namespace, rc_title),  INDEX rc_cur_id (rc_cur_id),  INDEX new_name_timestamp(rc_new,rc_namespace,rc_timestamp),  INDEX rc_ip (rc_ip)) TYPE=InnoDBEND;		$fields = array(			'rc_id'             => MW_UPGRADE_COPY,			'rc_timestamp'      => MW_UPGRADE_COPY,			'rc_cur_time'       => MW_UPGRADE_COPY,			'rc_user'           => MW_UPGRADE_COPY,			'rc_user_text'      => MW_UPGRADE_ENCODE,			'rc_namespace'      => MW_UPGRADE_COPY,			'rc_title'          => MW_UPGRADE_ENCODE,			'rc_comment'        => MW_UPGRADE_ENCODE,			'rc_minor'          => MW_UPGRADE_COPY,			'rc_bot'            => MW_UPGRADE_COPY,			'rc_new'            => MW_UPGRADE_COPY,			'rc_cur_id'         => MW_UPGRADE_COPY,			'rc_this_oldid'     => MW_UPGRADE_COPY,			'rc_last_oldid'     => MW_UPGRADE_COPY,			'rc_type'           => MW_UPGRADE_COPY,			'rc_moved_to_ns'    => MW_UPGRADE_COPY,			'rc_moved_to_title' => MW_UPGRADE_ENCODE,			'rc_patrolled'      => MW_UPGRADE_COPY,			'rc_ip'             => MW_UPGRADE_COPY );		$this->copyTable( 'recentchanges', $tabledef, $fields );	}	function upgradeQuerycache() {		// There's a format change in the namespace field		$tabledef = <<<ENDCREATE TABLE $1 (  -- A key name, generally the base name of of the special page.  qc_type char(32) NOT NULL,  -- Some sort of stored value. Sizes, counts...  qc_value int(5) unsigned NOT NULL default '0',  -- Target namespace+title  qc_namespace int NOT NULL default '0',  qc_title char(255) binary NOT NULL default '',  KEY (qc_type,qc_value)) TYPE=InnoDBEND;		$fields = array(			'qc_type'      => MW_UPGRADE_COPY,			'qc_value'     => MW_UPGRADE_COPY,			'qc_namespace' => MW_UPGRADE_COPY,			'qc_title'     => MW_UPGRADE_ENCODE );		$this->copyTable( 'querycache', $tabledef, $fields );	}	/**	 * Rename all our temporary tables into final place.	 * We've left things in place so a read-only wiki can continue running	 * on the old code during all this.	 */	function upgradeCleanup() {		$this->renameTable( 'old', 'text' );		foreach( $this->cleanupSwaps as $table ) {			$this->swap( $table );		}	}	function renameTable( $from, $to ) {		$this->log( "Renaming $from to $to..." );		$fromtable = $this->dbw->tableName( $from );		$totable   = $this->dbw->tableName( $to );		$this->dbw->query( "ALTER TABLE $fromtable RENAME TO $totable" );	}	function swap( $base ) {		$this->renameTable( $base, "{$base}_old" );		$this->renameTable( "{$base}_temp", $base );	}}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?