fiveupgrade.inc
来自「php 开发的内容管理系统」· INC 代码 · 共 1,215 行 · 第 1/3 页
INC
1,215 行
$this->setChunkScale( $chunksize, $maxcur, 'old', $fname ); $result = $this->dbr->query( "SELECT cur_id, cur_namespace, cur_title, $cur_text AS text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags AS flags FROM $cur ORDER BY cur_id", $fname ); $add = array(); while( $row = $this->dbr->fetchObject( $result ) ) { $add[] = array( 'old_namespace' => $row->cur_namespace, 'old_title' => $row->cur_title, 'old_text' => $row->text, 'old_comment' => $row->cur_comment, 'old_user' => $row->cur_user, 'old_user_text' => $row->cur_user_text, 'old_timestamp' => $row->cur_timestamp, 'old_minor_edit' => $row->cur_minor_edit, 'old_flags' => $row->flags ); $this->addChunk( $add, $row->cur_id ); } $this->lastChunk( $add ); $this->dbr->freeResult( $result ); /** * Copy revision metadata from old into revision. * We'll also do UTF-8 conversion of usernames and comments. */ #$newmaxold = $this->dbw->selectField( 'old', 'max(old_id)', '', $fname ); #$this->setChunkScale( $chunksize, $newmaxold, 'revision', $fname ); #$countold = $this->dbw->selectField( 'old', 'count(old_id)', '', $fname ); $countold = $this->dbw->selectField( 'old', 'max(old_id)', '', $fname ); $this->setChunkScale( $chunksize, $countold, 'revision', $fname ); $this->log( "......Setting up revision table." ); $result = $this->dbr->query( "SELECT old_id, cur_id, old_comment, old_user, old_user_text, old_timestamp, old_minor_edit FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname ); $add = array(); while( $row = $this->dbr->fetchObject( $result ) ) { $add[] = array( 'rev_id' => $row->old_id, 'rev_page' => $row->cur_id, 'rev_text_id' => $row->old_id, 'rev_comment' => $this->conv( $row->old_comment ), 'rev_user' => $row->old_user, 'rev_user_text' => $this->conv( $row->old_user_text ), 'rev_timestamp' => $row->old_timestamp, 'rev_minor_edit' => $row->old_minor_edit ); $this->addChunk( $add ); } $this->lastChunk( $add ); $this->dbr->freeResult( $result ); /** * Copy page metadata from cur into page. * We'll also do UTF-8 conversion of titles. */ $this->log( "......Setting up page table." ); $this->setChunkScale( $chunksize, $maxcur, 'page', $fname ); $result = $this->dbr->query( " SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new, cur_random, cur_touched, rev_id, LENGTH(cur_text) AS len FROM $cur,$revision WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold} ORDER BY cur_id", $fname ); $add = array(); while( $row = $this->dbr->fetchObject( $result ) ) { $add[] = array( 'page_id' => $row->cur_id, 'page_namespace' => $row->cur_namespace, 'page_title' => $this->conv( $row->cur_title ), 'page_restrictions' => $row->cur_restrictions, 'page_counter' => $row->cur_counter, 'page_is_redirect' => $row->cur_is_redirect, 'page_is_new' => $row->cur_is_new, 'page_random' => $row->cur_random, 'page_touched' => $this->dbw->timestamp(), 'page_latest' => $row->rev_id, 'page_len' => $row->len ); #$this->addChunk( $add, $row->cur_id ); $this->addChunk( $add ); } $this->lastChunk( $add ); $this->dbr->freeResult( $result ); $this->log( "...done with cur/old -> page/revision." ); } function upgradeLinks() { $fname = 'FiveUpgrade::upgradeLinks'; $chunksize = 200; extract( $this->dbw->tableNames( '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 { $this->log( 'adding iw_trans...' ); dbsource( 'maintenance/archives/patch-interwiki-trans.sql', $this->dbw ); $this->log( 'added iw_trans.' ); } $this->log( 'Creating pagelinks table...' ); $this->dbw->query( "CREATE TABLE $pagelinks ( -- Key to the page_id of the page containing the link. pl_from int(8) unsigned NOT NULL default '0', -- Key to page_namespace/page_title of the target page. -- The target page may or may not exist, and due to renames -- and deletions may refer to different page records as time -- goes by. pl_namespace int NOT NULL default '0', pl_title varchar(255) binary NOT NULL default '', UNIQUE KEY pl_from(pl_from,pl_namespace,pl_title), KEY (pl_namespace,pl_title)) TYPE=InnoDB" ); $this->log( 'Importing live links -> pagelinks' ); $nlinks = $this->dbw->selectField( 'links', 'count(*)', '', $fname ); if( $nlinks ) { $this->setChunkScale( $chunksize, $nlinks, 'pagelinks', $fname ); $result = $this->dbr->query( " SELECT l_from,cur_namespace,cur_title FROM $links, $cur WHERE l_to=cur_id", $fname ); $add = array(); while( $row = $this->dbr->fetchObject( $result ) ) { $add[] = array( 'pl_from' => $row->l_from, 'pl_namespace' => $row->cur_namespace, 'pl_title' => $this->conv( $row->cur_title ) ); $this->addChunk( $add ); } $this->lastChunk( $add ); } else { $this->log( 'no links!' ); } $this->log( 'Importing brokenlinks -> pagelinks' ); $nbrokenlinks = $this->dbw->selectField( 'brokenlinks', 'count(*)', '', $fname ); if( $nbrokenlinks ) { $this->setChunkScale( $chunksize, $nbrokenlinks, 'pagelinks', $fname ); $result = $this->dbr->query( "SELECT bl_from, bl_to FROM $brokenlinks", $fname ); $add = array(); while( $row = $this->dbr->fetchObject( $result ) ) { $pagename = $this->conv( $row->bl_to ); $title = Title::newFromText( $pagename ); if( is_null( $title ) ) { $this->log( "** invalid brokenlink: $row->bl_from -> '$pagename' (converted from '$row->bl_to')" ); } else { $add[] = array( 'pl_from' => $row->bl_from, 'pl_namespace' => $title->getNamespace(), 'pl_title' => $title->getDBkey() ); $this->addChunk( $add ); } } $this->lastChunk( $add ); } else { $this->log( 'no brokenlinks!' ); } $this->log( 'Done with links.' ); } function upgradeUser() { // Apply unique index, if necessary: $duper = new UserDupes( $this->dbw ); if( $duper->hasUniqueIndex() ) { $this->log( "Already have unique user_name index." ); } else { $this->log( "Clearing user duplicates..." ); if( !$duper->clearDupes() ) { $this->log( "WARNING: Duplicate user accounts, may explode!" ); } } $tabledef = <<<ENDCREATE TABLE $1 ( user_id int(5) unsigned NOT NULL auto_increment, user_name varchar(255) binary NOT NULL default '', user_real_name varchar(255) binary NOT NULL default '', user_password tinyblob NOT NULL default '', user_newpassword tinyblob NOT NULL default '', user_email tinytext NOT NULL default '', user_options blob NOT NULL default '', user_touched char(14) binary NOT NULL default '', user_token char(32) binary NOT NULL default '', user_email_authenticated CHAR(14) BINARY, user_email_token CHAR(32) BINARY, user_email_token_expires CHAR(14) BINARY, PRIMARY KEY user_id (user_id), UNIQUE INDEX user_name (user_name), INDEX (user_email_token)) TYPE=InnoDBEND; $fields = array( 'user_id' => MW_UPGRADE_COPY, 'user_name' => MW_UPGRADE_ENCODE, 'user_real_name' => MW_UPGRADE_ENCODE, 'user_password' => MW_UPGRADE_COPY, 'user_newpassword' => MW_UPGRADE_COPY, 'user_email' => MW_UPGRADE_ENCODE, 'user_options' => MW_UPGRADE_ENCODE, 'user_touched' => MW_UPGRADE_CALLBACK, 'user_token' => MW_UPGRADE_COPY, 'user_email_authenticated' => MW_UPGRADE_CALLBACK, 'user_email_token' => MW_UPGRADE_NULL, 'user_email_token_expires' => MW_UPGRADE_NULL ); $this->copyTable( 'user', $tabledef, $fields, array( &$this, 'userCallback' ) ); } function userCallback( $row, $copy ) { $now = $this->dbw->timestamp(); $copy['user_touched'] = $now; $copy['user_email_authenticated'] = $this->emailAuth ? $now : null; return $copy; } function upgradeImage() { $tabledef = <<<ENDCREATE TABLE $1 ( img_name varchar(255) binary NOT NULL default '', img_size int(8) unsigned NOT NULL default '0', img_width int(5) NOT NULL default '0', img_height int(5) NOT NULL default '0', img_metadata mediumblob NOT NULL, img_bits int(3) NOT NULL default '0', img_media_type ENUM("UNKNOWN", "BITMAP", "DRAWING", "AUDIO", "VIDEO", "MULTIMEDIA", "OFFICE", "TEXT", "EXECUTABLE", "ARCHIVE") default NULL, img_major_mime ENUM("unknown", "application", "audio", "image", "text", "video", "message", "model", "multipart") NOT NULL default "unknown", img_minor_mime varchar(32) NOT NULL default "unknown", img_description tinyblob NOT NULL default '', img_user int(5) unsigned NOT NULL default '0', img_user_text varchar(255) binary NOT NULL default '', img_timestamp char(14) binary NOT NULL default '', PRIMARY KEY img_name (img_name), INDEX img_size (img_size), INDEX img_timestamp (img_timestamp)) TYPE=InnoDBEND; $fields = array( 'img_name' => MW_UPGRADE_ENCODE, 'img_size' => MW_UPGRADE_COPY, 'img_width' => MW_UPGRADE_CALLBACK, 'img_height' => MW_UPGRADE_CALLBACK, 'img_metadata' => MW_UPGRADE_CALLBACK, 'img_bits' => MW_UPGRADE_CALLBACK, 'img_media_type' => MW_UPGRADE_CALLBACK, 'img_major_mime' => MW_UPGRADE_CALLBACK, 'img_minor_mime' => MW_UPGRADE_CALLBACK, 'img_description' => MW_UPGRADE_ENCODE, 'img_user' => MW_UPGRADE_COPY, 'img_user_text' => MW_UPGRADE_ENCODE, 'img_timestamp' => MW_UPGRADE_COPY ); $this->copyTable( 'image', $tabledef, $fields, array( &$this, 'imageCallback' ) ); } function imageCallback( $row, $copy ) { global $options; if( !isset( $options['noimage'] ) ) { // Fill in the new image info fields $info = $this->imageInfo( $row->img_name ); $copy['img_width' ] = $info['width']; $copy['img_height' ] = $info['height']; $copy['img_metadata' ] = ""; // loaded on-demand $copy['img_bits' ] = $info['bits']; $copy['img_media_type'] = $info['media']; $copy['img_major_mime'] = $info['major']; $copy['img_minor_mime'] = $info['minor']; } // If doing UTF8 conversion the file must be renamed $this->renameFile( $row->img_name, 'wfImageDir' ); return $copy; } function imageInfo( $name, $subdirCallback='wfImageDir', $basename = null ) { if( is_null( $basename ) ) $basename = $name; $dir = call_user_func( $subdirCallback, $basename ); $filename = $dir . '/' . $name; $info = array( 'width' => 0, 'height' => 0, 'bits' => 0, 'media' => '', 'major' => '', 'minor' => '' ); $magic =& wfGetMimeMagic(); $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'] ) ) { $info['bits'] = $gis['bits']; } return $info; } /** * Truncate a table. * @param string $table The table name to be truncated */ function clearTable( $table ) { print "Clearing $table...\n"; $tableName = $this->db->tableName( $table ); $this->db->query( 'TRUNCATE $tableName' ); } /** * Rename a given image or archived image file to the converted filename, * leaving a symlink for URL compatibility. * * @param string $oldname pre-conversion filename * @param string $basename pre-conversion base filename for dir hashing, if an archive * @access private */ function renameFile( $oldname, $subdirCallback='wfImageDir', $basename=null ) { $newname = $this->conv( $oldname ); if( $newname == $oldname ) { // No need to rename; another field triggered this row. return false; } if( is_null( $basename ) ) $basename = $oldname; $ubasename = $this->conv( $basename ); $oldpath = call_user_func( $subdirCallback, $basename ) . '/' . $oldname; $newpath = call_user_func( $subdirCallback, $ubasename ) . '/' . $newname; $this->log( "$oldpath -> $newpath" ); if( rename( $oldpath, $newpath ) ) { $relpath = $this->relativize( $newpath, dirname( $oldpath ) ); if( !symlink( $relpath, $oldpath ) ) { $this->log( "... symlink failed!" ); } return $newname; } else { $this->log( "... rename failed!" ); return false; } } /** * 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, basename( $path ) ); return implode( '/', $pieces ); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?