?? cvs.php
字號:
<?phprcs_id('$Id: cvs.php,v 1.24 2004/12/08 12:55:51 rurban Exp $');/** * Backend for handling CVS repository. * * ASSUMES: that the shell commands 'cvs', 'grep', 'rm', are all located * ASSUMES: in the path of the server calling this script. * * Author: Gerrit Riessen, gerrit.riessen@open-source-consultants.de */require_once('lib/WikiDB/backend.php');require_once('lib/ErrorManager.php');/** * Constants used by the CVS backend **/// these are the parameters defined in db_paramsdefine( 'CVS_DOC_DIR', 'doc_dir' );define( 'CVS_REPOSITORY', 'repository' );define( 'CVS_CHECK_FOR_REPOSITORY', 'check_for_repository' );define( 'CVS_DEBUG_FILE', 'debug_file' );define( 'CVS_PAGE_SOURCE', 'pgsrc' );define( 'CVS_MODULE_NAME', 'module_name' );// these are the things that are defined in the page hash// CMD == Cvs Meta Datadefine( 'CMD_LAST_MODIFIED', 'lastmodified' );define( 'CMD_CONTENT', '%content');define( 'CMD_CREATED', 'created');define( 'CMD_VERSION', 'version');define( 'CMD_AUTHOR', 'author');define( 'CMD_LINK_ATT', '_links_' );// file names used to store specific informationdefine( 'CVS_MP_FILE', '.most_popular' );define( 'CVS_MR_FILE', '.most_recent' );class WikiDB_backend_cvsextends WikiDB_backend{ var $_docDir; var $_repository; var $_module_name; var $_debug_file; /** * In the following parameters should be defined in dbparam: * . wiki ==> directory where the pages should be stored * this is not the CVS repository location * . repository ==> local directory where the repository should be * created. This can also be a :pserver: but then * set check_for_repository to false and checkout * the documents beforehand. (This is basically CVSROOT) * . check_for_repository ==> boolean flag to indicate whether the * repository should be created, this only * applies to local directories, for pserver * set this to false and check out the * document base beforehand * . debug_file ==> file name where debug information should be sent. * If file doesn't exist then it's created, if this * is empty, then debugging is turned off. * . pgsrc ==> directory name where the default wiki pages are stored. * This is only required if the backend is to create a * new CVS repository. * * The class also adds a parameter 'module_name' to indicate the name * of the cvs module that is being used to version the documents. The * module_name is assumed to be the base name of directory given in * wiki, e.g. if wiki == '/some/path/to/documents' then module_name * becomes 'documents' and this module will be created in the CVS * repository or assumed to exist. If on the other hand the parameter * already exists, then it is not overwritten. */ function WikiDB_backend_cvs( $dbparam ) { // setup all the instance values. $this->_docDir = $dbparam{CVS_DOC_DIR}; $this->_repository = $dbparam{CVS_REPOSITORY}; if ( ! $dbparam{CVS_MODULE_NAME} ) { $this->_module_name = basename( $this->_docDir ); $dbparam{CVS_MODULE_NAME} = $this->_module_name; } else { $this->_module_name = $dbparam{CVS_MODULE_NAME}; } $this->_debug_file = $dbparam{CVS_DEBUG_FILE}; if ( $dbparam{CVS_CHECK_FOR_REPOSITORY} && !( is_dir( $this->_repository ) && is_dir( $this->_repository . "/CVSROOT" ) && is_dir( $this->_repository . "/" . $this->_module_name ))) { $this->_cvsDebug( sprintf("Creating new repository [%s]", $this->_repository) ); // doesn't exist, need to create it and the replace the wiki // document directory. $this->_mkdir( $this->_repository, 0775 ); // assume that the repository is a local directory, prefix :local: if ( !ereg( "^:local:", $this->_repository ) ) { $this->_repository = ":local:" . $this->_repository; } $cmdLine = sprintf( "cvs -d \"%s\" init", $this->_repository); $this->_execCommand( $cmdLine, $cmdOutput, true ); $this->_mkdir( $this->_docDir, 0775 ); $cmdLine = sprintf("cd %s; cvs -d \"%s\" import -m no_message " ."%s V R", $this->_docDir, $this->_repository, $this->_module_name ); $this->_execCommand( $cmdLine, $cmdOutput, true ); // remove the wiki directory and check it out from the // CVS repository $cmdLine = sprintf( "rm -fr %s; cd %s; cvs -d \"%s\" co %s", $this->_docDir, dirname($this->_docDir), $this->_repository, $this->_module_name); $this->_execCommand( $cmdLine, $cmdOutput, true ); // add the default pages using the update_pagedata $metaData = array(); $metaData[$AUTHOR] = "PhpWiki -- CVS Backend"; if ( is_dir( $dbparam[CVS_PAGE_SOURCE] ) ) { $d = opendir( $dbparam[CVS_PAGE_SOURCE] ); while ( $entry = readdir( $d ) ) { $filename = $dbparam[CVS_PAGE_SOURCE] . "/" . $entry; $this->_cvsDebug( sprintf("Found [%s] in [%s]", $entry, $dbparam[CVS_PAGE_SOURCE]) ); if ( is_file( $filename ) ) { $metaData[CMD_CONTENT] = join('',file($filename)); $this->update_pagedata( $entry, $metaData ); } } closedir( $d ); } // ensure that the results of the is_dir are cleared clearstatcache(); } } /** * Return: metadata about page */ function get_pagedata($pagename) { // the metadata information about a page is stored in the // CVS directory of the document root in serialized form. The // file always has the name, i.e. '_$pagename'. $metaFile = $this->_docDir . "/CVS/_" . $pagename; if ( file_exists( $metaFile ) ) { $megaHash = unserialize(join( '',$this->_readFileWithPath($metaFile))); $filename = $this->_docDir . "/" . $pagename; if ( file_exists( $filename ) ) { $megaHash[CMD_CONTENT] = $this->_readFileWithPath( $filename ); } else { $megaHash[CMD_CONTENT] = ""; } $this->_updateMostRecent( $pagename ); $this->_updateMostPopular( $pagename ); return $megaHash; } else { return false; } } /** * This will create a new page if page being requested does not * exist. */ function update_pagedata($pagename, $newdata = array() ) { // check argument if ( ! is_array( $newdata ) ) { trigger_error("update_pagedata: Argument 'newdata' was not array", E_USER_WARNING); } // retrieve the meta data $metaData = $this->get_pagedata( $pagename ); if ( ! $metaData ) { $this->_cvsDebug("update_pagedata: no meta data found"); // this means that the page does not exist, we need to create // it. $metaData = array(); $metaData[CMD_CREATED] = time(); $metaData[CMD_VERSION] = "1"; if ( ! isset($newdata[CMD_CONTENT])) { $metaData[CMD_CONTENT] = ""; } else { $metaData[CMD_CONTENT] = $newdata[CMD_CONTENT]; } // create an empty page ... $this->_writePage( $pagename, $metaData[CMD_CONTENT] ); $this->_addPage( $pagename ); // make sure that the page is written and committed a second time unset( $newdata[CMD_CONTENT] ); unset( $metaData[CMD_CONTENT] ); } // change any meta data information foreach ( $newdata as $key => $value ) { if ( $value == false || empty( $value ) ) { unset( $metaData[$key] ); } else { $metaData[$key] = $value; } } // update the page data, if required. Use newdata because it could // be empty and thus unset($metaData[CMD_CONTENT]). if ( isset( $newdata[CMD_CONTENT] ) ) { $this->_writePage( $pagename, $newdata[CMD_CONTENT] ); } // remove any content from the meta data before storing it unset( $metaData[CMD_CONTENT] ); $metaData[CMD_LAST_MODIFIED] = time(); $metaData[CMD_VERSION] = $this->_commitPage( $pagename, $metaData ); $this->_writeMetaInfo( $pagename, $metaData ); } function get_latest_version($pagename) { $metaData = $this->get_pagedata( $pagename ); if ( $metaData ) { // the version number is everything after the '1.' return $metaData[CMD_VERSION]; } else { $this->_cvsDebug(sprintf("get_latest_versioned FAILED for [%s]", $pagename)); return 0; } } function get_previous_version($pagename, $version) { // cvs increments the version numbers, so this is real easy ;-) return ($version > 0 ? $version - 1 : 0); } /** * the version parameter is assumed to be everything after the '1.' * in the CVS versioning system. */ function get_versiondata($pagename, $version, $want_content = false) { $this->_cvsDebug( "get_versiondata: [$pagename] [$version] [$want_content]" ); $filedata = ""; if ( $want_content ) { // retrieve the version from the repository $cmdLine = sprintf("cvs -d \"%s\" co -p -r 1.%d %s/%s 2>&1", $this->_repository, $version, $this->_module_name, $pagename ); $this->_execCommand( $cmdLine, $filedata, true ); // TODO: DEBUG: 5 is a magic number here, depending on the // TODO: DEBUG: version of cvs used here, 5 might have to // TODO: DEBUG: change. Basically find a more reliable way of // TODO: DEBUG: doing this. // the first 5 lines contain various bits of // administrative information that can be ignored. for ( $i = 0; $i < 5; $i++ ) { array_shift( $filedata ); } } /** * Now obtain the rest of the pagehash information, this is contained * in the log message for the revision in serialized form. */ $cmdLine = sprintf("cd %s; cvs log -r1.%d %s", $this->_docDir, $version, $pagename ); $this->_execCommand( $cmdLine, $logdata, true ); // shift log data until we get to the 'revision X.X' line // FIXME: ensure that we don't enter an endless loop here while ( !ereg( "^revision 1.([0-9]+)$", $logdata[0], $revInfo ) ) { array_shift( $logdata ); } // serialized hash information now stored in position 2 $rVal = unserialize( _unescape( $logdata[2] ) ); // version information is incorrect $rVal[CMD_VERSION] = $revInfo[1]; $rVal[CMD_CONTENT] = $filedata; foreach ( $rVal as $key => $value ) { $this->_cvsDebug( "$key == [$value]" ); } return $rVal; } /** * See ADODB for a better delete_page(), which can be undone and is seen in RecentChanges. * See backend.php */ //function delete_page($pagename) { $this->purge_page($pagename); } /** * This returns false if page was not deleted or could not be deleted * else return true. */ function purge_page($pagename) { $this->_cvsDebug( "delete_page [$pagename]") ; $filename = $this->_docDir . "/" . $pagename; $metaFile = $this->_docDir . "/CVS/_" . $pagename; // obtain a write block before deleting the file if ( $this->_deleteFile( $filename ) == false ) { return false; } $this->_deleteFile( $metaFile ); $this->_removePage( $pagename ); return true; } /** * For now delete and create a new one. * * This returns false if page was not renamed, * else return true. */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -