⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvs.php

📁 PhpWiki是sourceforge的一个开源项目
💻 PHP
📖 第 1 页 / 共 3 页
字号:
    function rename_page($pagename, $to)     {        $this->_cvsDebug( "rename_page [$pagename,$to]") ;	$data = get_pagedata($pagename);	if (isset($data['pagename']))	  $data['pagename'] = $to;	//$version = $this->get_latest_version($pagename);	//$vdata = get_versiondata($pagename, $version, 1);        //$data[CMD_CONTENT] = $vdata[CMD_CONTENT];	$this->delete_page($pagename);	$this->update_pagedata($to, $data);	return true;    }    function delete_versiondata($pagename, $version)     {        // TODO: Not Implemented.        // TODO: This is, for CVS, difficult because it implies removing a        // TODO: revision somewhere in the middle of a revision tree, and        // TODO: this is basically not possible!        trigger_error("delete_versiondata: Not Implemented", E_USER_WARNING);    }    function set_versiondata($pagename, $version, $data)     {        // TODO: Not Implemented.        // TODO: requires changing the log(commit) message for a particular        // TODO: version and this can't be done??? (You can edit the repository        // TODO: file directly but i don't know of a way of doing it via        // TODO: the cvs tools).        trigger_error("set_versiondata: Not Implemented", E_USER_WARNING);    }    function update_versiondata($pagename, $version, $newdata)     {        // TODO: same problem as set_versiondata        trigger_error("set_versiondata: Not Implemented", E_USER_WARNING);    }    function set_links($pagename, $links)     {        // TODO: needs to be tested ....        $megaHash = get_pagedata( $pagename );        $megaHash[CMD_LINK_ATT] = $links;        $this->_writeMetaInfo( $pagename, $megaHash );    }    function get_links($pagename, $reversed=true, $include_empty=false,                       $sortby=false, $limit=false, $exclude=false)    {        // TODO: ignores the $reversed argument and returns        // TODO: the value of _links_ attribute of the meta information        // TODO: to implement a reversed version, i guess, we going to        // TODO: need to do a grep on all files for the pagename in         // TODO: in question and return all those page names that contained        // TODO: the required pagename!        $megaHash = get_pagedata( $pagename );        return $megaHash[CMD_LINK_ATT];    }    /* function get_all_revisions($pagename) {        // TODO: should replace this with something more efficient        include_once('lib/WikiDB/backend/dumb/AllRevisionsIter.php');        return new WikiDB_backend_dumb_AllRevisionsIter($this, $pagename);    } */    function get_all_pages($include_empty=false, $sortby=false, $limit=false)     {        // FIXME: this ignores the parameters.        return new Cvs_Backend_Array_Iterator(                              $this->_getAllFileNamesInDir( $this->_docDir ));    }    function text_search($search = '', $fullsearch = false)     {        if ( $fullsearch ) {            return new Cvs_Backend_Full_Search_Iterator(                               $this->_getAllFileNamesInDir( $this->_docDir ),                                $search,                                $this->_docDir );        } else {            return new Cvs_Backend_Title_Search_Iterator(                               $this->_getAllFileNamesInDir( $this->_docDir ),                               $search);        }    }    function most_popular($limit, $sortby='') {        // TODO: needs to be tested ...        $mp = $this->_getMostPopular();        if ($limit < 0){            asort ($mp, SORT_NUMERIC);            $limit = -$limit;        } else {            arsort( $mp, SORT_NUMERIC );        }        $returnVal = array();                while ( (list($key, $val) = each($a)) && $limit > 0 ) {            $returnVal[] = $key;            $limit--;        }        return $returnVal;    }    /**     * This only accepts the 'since' and 'limit' attributes, everything     * else is ignored.     */    function most_recent($params)     {        // TODO: needs to be tested ...        // most recent are those pages with the highest time value ...        $mr = $this->_getMostRecent();        $rev = false;        $returnVal = array();        if ( isset( $params['limit'] ) ) {            $limit = $params['limit'];            $rev = $limit < 0;        }        if ($rev){            arsort( $mr, SORT_NUMERIC );        } else {            asort( $mr, SORT_NUMERIC );        }        if ( isset( $limit ) ) {            while ( (list($key, $val) = each($a)) && $limit > 0 ) {                $returnVal[] = $key;                $limit--;            }        } else if ( isset( $params['since'] ) ) {            while ( (list($key, $val) = each($a)) ) {                                if ( $val > $params['since'] ) {                    $returnVal[] = $key;                }            }        }        return new Cvs_Backend_Array_Iterator( $returnVal );    }    function lock($write_lock = true)     {        // TODO: to be implemented        trigger_error("lock: Not Implemented", E_USER_WARNING);    }    function unlock($force = false)     {        // TODO: to be implemented        trigger_error("unlock: Not Implemented", E_USER_WARNING);    }    function close ()     {    }    function sync()     {    }    function optimize()     {    }    /**     * What we do here is take a listing of the documents directory and     * check that each page has metadata file. If not, then a metadata     * file is created for the page.     *     * This can happen if rebuild() was called and someone has added     * files to the CVS repository not via PhpWiki. These files are      * added to the document directory but without any metadata files.     */    function check()     {        // TODO:        // TODO: test this .... i.e. add test to unit test file.        // TODO:        $page_names = $this->_getAllFileNamesInDir($this->_docDir);        $meta_names = $this->_getAllFileNamesInDir($this->_docDir . "/CVS");        array_walk( $meta_names, '_strip_leading_underscore' );        reset( $meta_names );        $no_meta_files = array_diff( $page_names, $meta_names );        array_walk( $no_meta_files, '_create_meta_file', $this );        return true;    }    /**     * Do an update of the CVS repository      */    function rebuild()     {        // TODO:        // TODO: test this .... i.e. add test to unit test file.        // TODO:        $cmdLine = sprintf( "cd %s; cvs update -d 2>&1", $this->_docDir );        $this->_execCommand( $cmdLine, $cmdOutput, true );        return true;    }        //     // ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....    // The rest are all internal methods, not to be used     // directly.    // ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....    //    function _create_meta_file( $page_name, $key, &$backend )    {        // this is used as part of an array walk and therefore takes        // the backend argument        $backend->_cvsDebug(sprintf("Creating meta file for [%s]", $page_name));        $backend->update_pagedata( $page_name, array() );    }    function _strip_leading_underscore( &$item )     {        $item = ereg_replace( "^_", "", $item );    }    /**     * update the most popular information by incrementing the count     * for the following page. If the page was not defined, it is entered     * with a value of 1.     */    function _updateMostPopular( $pagename )    {        $mp = $this->_getMostPopular();        if ( isset( $mp[$pagename] ) ) {            $mp[$pagename]++;        } else {            $mp[$pagename] = 1;        }        $this->_writeFileWithPath( $this->_docDir . "/CVS/" . CVS_MP_FILE,                                    serialize( $mp ) );    }    /**     * Returns an array containing the most popular information. This     * creates the most popular file if it does not exist.     */    function _getMostPopular()    {        $mostPopular = $this->_docDir . "/CVS/" . CVS_MP_FILE;        if ( !file_exists( $mostPopular ) ) {            $this->_writeFileWithPath( $mostPopular, serialize( array() ) );        }        return unserialize(join( '',$this->_readFileWithPath($mostPopular)));    }    function _getMostRecent()    {        $mostRecent = $this->_docDir . "/CVS/" . CVS_MR_FILE;        if ( !file_exists( $mostRecent ) ) {            $this->_writeFileWithPath( $mostRecent, serialize( array() ) );        }        return unserialize(join( '',$this->_readFileWithPath($mostRecent)));    }    function _updateMostRecent( $pagename )    {        $mr = $this->_getMostRecent();        $mr[$pagename] = time();        $this->_writeFileWithPath( $this->_docDir . "/CVS/" . CVS_MR_FILE,                                    serialize( $mr ) );    }    function _writeMetaInfo( $pagename, $hashInfo )    {        $this->_writeFileWithPath( $this->_docDir . "/CVS/_" . $pagename,                                    serialize( $hashInfo ) );    }    function _writePage( $pagename, $content )    {        $this->_writeFileWithPath( $this->_docDir . "/". $pagename, $content );    }    function _removePage( $pagename )    {        $cmdLine = sprintf("cd %s; cvs remove %s 2>&1; cvs commit -m '%s' "                           ."%s 2>&1", $this->_docDir, $pagename,                            "remove page", $pagename );                $this->_execCommand( $cmdLine, $cmdRemoveOutput, true );    }    /**     * this returns the new version number of the file.     */    function _commitPage( $pagename, &$meta_data )    {        $cmdLine = sprintf( "cd %s; cvs commit -m \"%s\" %s 2>&1",                             $this->_docDir,                             escapeshellcmd( serialize( $meta_data ) ),                            $pagename );        $this->_execCommand( $cmdLine, $cmdOutput, true );        $cmdOutput = implode( "\n", $cmdOutput );        $revInfo = array();        ereg( "\nnew revision: 1[.]([0-9]+); previous revision: ", $cmdOutput,              $revInfo );        $this->_cvsDebug( "CP: revInfo 0: $revInfo[0]" );        $this->_cvsDebug( "CP: $cmdOutput" );        if ( isset( $revInfo[1] ) ) {            $this->_cvsDebug( "CP: got revision information" );            return $revInfo[1];        } else {            ereg( "\ninitial revision: 1[.]([0-9]+)", $cmdOutput, $revInfo );            if ( isset( $revInfo[1] ) ) {                $this->_cvsDebug( "CP: is initial release" );                return 1;            }            $this->_cvsDebug( "CP: returning old version" );            return $meta_data[CMD_VERSION];        }    }    function _addPage( $pagename )    {        // TODO: need to add a check for the mimetype so that binary        // TODO: files are added as binary files        $cmdLine = sprintf("cd %s; cvs add %s 2>&1", $this->_docDir,                            $pagename );        $this->_execCommand( $cmdLine, $cmdAddOutput, true );    }    /**     * Returns an array containing all the names of files contained     * in a particular directory. The list is sorted according the      * string representation of the filenames.     */    function _getAllFileNamesInDir( $dirName )     {        $namelist = array();        $d = opendir( $dirName );        while ( $entry = readdir( $d ) ) {            $namelist[] = $entry;        }

⌨️ 快捷键说明

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