4 * Backend for handling CVS repository.
6 * ASSUMES: that the shell commands 'cvs', 'grep', 'rm', are all located
7 * ASSUMES: in the path of the server calling this script.
9 * Author: Gerrit Riessen, gerrit.riessen@open-source-consultants.de
12 require_once 'lib/WikiDB/backend.php';
13 require_once 'lib/ErrorManager.php';
16 * Constants used by the CVS backend
18 // these are the parameters defined in db_params
19 define('CVS_DOC_DIR', 'doc_dir');
20 define('CVS_REPOSITORY', 'repository');
21 define('CVS_CHECK_FOR_REPOSITORY', 'check_for_repository');
22 define('CVS_DEBUG_FILE', 'debug_file');
23 define('CVS_PAGE_SOURCE', 'pgsrc');
24 define('CVS_MODULE_NAME', 'module_name');
26 // these are the things that are defined in the page hash
27 // CMD == Cvs Meta Data
28 define('CMD_LAST_MODIFIED', 'lastmodified');
29 define('CMD_CONTENT', '%content');
30 define('CMD_CREATED', 'created');
31 define('CMD_VERSION', 'version');
32 define('CMD_AUTHOR', 'author');
33 define('CMD_LINK_ATT', '_links_');
35 // file names used to store specific information
36 define('CVS_MP_FILE', '.most_popular');
37 define('CVS_MR_FILE', '.most_recent');
39 class WikiDB_backend_cvs
40 extends WikiDB_backend
48 * In the following parameters should be defined in dbparam:
49 * . wiki ==> directory where the pages should be stored
50 * this is not the CVS repository location
51 * . repository ==> local directory where the repository should be
52 * created. This can also be a :pserver: but then
53 * set check_for_repository to false and checkout
54 * the documents beforehand. (This is basically CVSROOT)
55 * . check_for_repository ==> boolean flag to indicate whether the
56 * repository should be created, this only
57 * applies to local directories, for pserver
58 * set this to false and check out the
59 * document base beforehand
60 * . debug_file ==> file name where debug information should be sent.
61 * If file doesn't exist then it's created, if this
62 * is empty, then debugging is turned off.
63 * . pgsrc ==> directory name where the default wiki pages are stored.
64 * This is only required if the backend is to create a
67 * The class also adds a parameter 'module_name' to indicate the name
68 * of the cvs module that is being used to version the documents. The
69 * module_name is assumed to be the base name of directory given in
70 * wiki, e.g. if wiki == '/some/path/to/documents' then module_name
71 * becomes 'documents' and this module will be created in the CVS
72 * repository or assumed to exist. If on the other hand the parameter
73 * already exists, then it is not overwritten.
75 function WikiDB_backend_cvs($dbparam)
77 // setup all the instance values.
78 $this->_docDir = $dbparam{CVS_DOC_DIR};
79 $this->_repository = $dbparam{CVS_REPOSITORY};
80 if (!$dbparam{CVS_MODULE_NAME}) {
81 $this->_module_name = basename($this->_docDir);
82 $dbparam{CVS_MODULE_NAME} = $this->_module_name;
84 $this->_module_name = $dbparam{CVS_MODULE_NAME};
86 $this->_debug_file = $dbparam{CVS_DEBUG_FILE};
88 if ($dbparam{CVS_CHECK_FOR_REPOSITORY}
89 && !(is_dir($this->_repository)
90 && is_dir($this->_repository . "/CVSROOT")
91 && is_dir($this->_repository . "/" . $this->_module_name))
94 $this->_cvsDebug(sprintf("Creating new repository [%s]", $this->_repository));
96 // doesn't exist, need to create it and the replace the wiki
97 // document directory.
98 $this->_mkdir($this->_repository, 0775);
100 // assume that the repository is a local directory, prefix :local:
101 if (!ereg("^:local:", $this->_repository)) {
102 $this->_repository = ":local:" . $this->_repository;
105 $cmdLine = sprintf("cvs -d \"%s\" init", $this->_repository);
106 $this->_execCommand($cmdLine, $cmdOutput, true);
108 $this->_mkdir($this->_docDir, 0775);
109 $cmdLine = sprintf("cd %s; cvs -d \"%s\" import -m no_message "
110 . "%s V R", $this->_docDir, $this->_repository,
111 $this->_module_name);
112 $this->_execCommand($cmdLine, $cmdOutput, true);
114 // remove the wiki directory and check it out from the
116 $cmdLine = sprintf("rm -fr %s; cd %s; cvs -d \"%s\" co %s",
117 $this->_docDir, dirname($this->_docDir),
118 $this->_repository, $this->_module_name);
119 $this->_execCommand($cmdLine, $cmdOutput, true);
121 // add the default pages using the update_pagedata
123 $metaData[$AUTHOR] = "PhpWiki -- CVS Backend";
125 if (is_dir($dbparam[CVS_PAGE_SOURCE])) {
126 $d = opendir($dbparam[CVS_PAGE_SOURCE]);
127 while ($entry = readdir($d)) {
128 $filename = $dbparam[CVS_PAGE_SOURCE] . "/" . $entry;
129 $this->_cvsDebug(sprintf("Found [%s] in [%s]", $entry, $dbparam[CVS_PAGE_SOURCE]));
131 if (is_file($filename)) {
132 $metaData[CMD_CONTENT] = join('', file($filename));
133 $this->update_pagedata($entry, $metaData);
139 // ensure that the results of the is_dir are cleared
145 * Return: metadata about page
147 function get_pagedata($pagename)
149 // the metadata information about a page is stored in the
150 // CVS directory of the document root in serialized form. The
151 // file always has the name, i.e. '_$pagename'.
152 $metaFile = $this->_docDir . "/CVS/_" . $pagename;
154 if (file_exists($metaFile)) {
157 unserialize(join('', $this->_readFileWithPath($metaFile)));
159 $filename = $this->_docDir . "/" . $pagename;
160 if (file_exists($filename)) {
161 $megaHash[CMD_CONTENT] = $this->_readFileWithPath($filename);
163 $megaHash[CMD_CONTENT] = "";
166 $this->_updateMostRecent($pagename);
167 $this->_updateMostPopular($pagename);
176 * This will create a new page if page being requested does not
179 function update_pagedata($pagename, $newdata = array())
182 if (!is_array($newdata)) {
183 trigger_error("update_pagedata: Argument 'newdata' was not array",
187 // retrieve the meta data
188 $metaData = $this->get_pagedata($pagename);
191 $this->_cvsDebug("update_pagedata: no meta data found");
192 // this means that the page does not exist, we need to create
196 $metaData[CMD_CREATED] = time();
197 $metaData[CMD_VERSION] = "1";
199 if (!isset($newdata[CMD_CONTENT])) {
200 $metaData[CMD_CONTENT] = "";
202 $metaData[CMD_CONTENT] = $newdata[CMD_CONTENT];
205 // create an empty page ...
206 $this->_writePage($pagename, $metaData[CMD_CONTENT]);
207 $this->_addPage($pagename);
209 // make sure that the page is written and committed a second time
210 unset($newdata[CMD_CONTENT]);
211 unset($metaData[CMD_CONTENT]);
214 // change any meta data information
215 foreach ($newdata as $key => $value) {
216 if ($value == false || empty($value)) {
217 unset($metaData[$key]);
219 $metaData[$key] = $value;
223 // update the page data, if required. Use newdata because it could
224 // be empty and thus unset($metaData[CMD_CONTENT]).
225 if (isset($newdata[CMD_CONTENT])) {
226 $this->_writePage($pagename, $newdata[CMD_CONTENT]);
229 // remove any content from the meta data before storing it
230 unset($metaData[CMD_CONTENT]);
231 $metaData[CMD_LAST_MODIFIED] = time();
233 $metaData[CMD_VERSION] = $this->_commitPage($pagename, $metaData);
234 $this->_writeMetaInfo($pagename, $metaData);
237 function get_latest_version($pagename)
239 $metaData = $this->get_pagedata($pagename);
241 // the version number is everything after the '1.'
242 return $metaData[CMD_VERSION];
244 $this->_cvsDebug(sprintf("get_latest_versioned FAILED for [%s]", $pagename));
249 function get_previous_version($pagename, $version)
251 // cvs increments the version numbers, so this is real easy ;-)
252 return ($version > 0 ? $version - 1 : 0);
256 * the version parameter is assumed to be everything after the '1.'
257 * in the CVS versioning system.
259 function get_versiondata($pagename, $version, $want_content = false)
261 $this->_cvsDebug("get_versiondata: [$pagename] [$version] [$want_content]");
265 // retrieve the version from the repository
266 $cmdLine = sprintf("cvs -d \"%s\" co -p -r 1.%d %s/%s 2>&1",
267 $this->_repository, $version,
268 $this->_module_name, $pagename);
269 $this->_execCommand($cmdLine, $filedata, true);
271 // TODO: DEBUG: 5 is a magic number here, depending on the
272 // TODO: DEBUG: version of cvs used here, 5 might have to
273 // TODO: DEBUG: change. Basically find a more reliable way of
274 // TODO: DEBUG: doing this.
275 // the first 5 lines contain various bits of
276 // administrative information that can be ignored.
277 for ($i = 0; $i < 5; $i++) {
278 array_shift($filedata);
283 * Now obtain the rest of the pagehash information, this is contained
284 * in the log message for the revision in serialized form.
286 $cmdLine = sprintf("cd %s; cvs log -r1.%d %s", $this->_docDir,
287 $version, $pagename);
288 $this->_execCommand($cmdLine, $logdata, true);
290 // shift log data until we get to the 'revision X.X' line
291 // FIXME: ensure that we don't enter an endless loop here
292 while (!ereg("^revision 1.([0-9]+)$", $logdata[0], $revInfo)) {
293 array_shift($logdata);
296 // serialized hash information now stored in position 2
297 $rVal = unserialize(_unescape($logdata[2]));
299 // version information is incorrect
300 $rVal[CMD_VERSION] = $revInfo[1];
301 $rVal[CMD_CONTENT] = $filedata;
303 foreach ($rVal as $key => $value) {
304 $this->_cvsDebug("$key == [$value]");
311 * See ADODB for a better delete_page(), which can be undone and is seen in RecentChanges.
314 //function delete_page($pagename) { $this->purge_page($pagename); }
317 * This returns false if page was not deleted or could not be deleted
320 function purge_page($pagename)
322 $this->_cvsDebug("delete_page [$pagename]");
323 $filename = $this->_docDir . "/" . $pagename;
324 $metaFile = $this->_docDir . "/CVS/_" . $pagename;
326 // obtain a write block before deleting the file
327 if ($this->_deleteFile($filename) == false) {
331 $this->_deleteFile($metaFile);
333 $this->_removePage($pagename);
339 * For now delete and create a new one.
341 * This returns false if page was not renamed,
344 function rename_page($pagename, $to)
346 $this->_cvsDebug("rename_page [$pagename,$to]");
347 $data = get_pagedata($pagename);
348 if (isset($data['pagename']))
349 $data['pagename'] = $to;
350 //$version = $this->get_latest_version($pagename);
351 //$vdata = get_versiondata($pagename, $version, 1);
352 //$data[CMD_CONTENT] = $vdata[CMD_CONTENT];
353 $this->delete_page($pagename);
354 $this->update_pagedata($to, $data);
358 function delete_versiondata($pagename, $version)
360 // TODO: Not Implemented.
361 // TODO: This is, for CVS, difficult because it implies removing a
362 // TODO: revision somewhere in the middle of a revision tree, and
363 // TODO: this is basically not possible!
364 trigger_error("delete_versiondata: Not Implemented", E_USER_WARNING);
367 function set_versiondata($pagename, $version, $data)
369 // TODO: Not Implemented.
370 // TODO: requires changing the log(commit) message for a particular
371 // TODO: version and this can't be done??? (You can edit the repository
372 // TODO: file directly but i don't know of a way of doing it via
373 // TODO: the cvs tools).
374 trigger_error("set_versiondata: Not Implemented", E_USER_WARNING);
377 function update_versiondata($pagename, $version, $newdata)
379 // TODO: same problem as set_versiondata
380 trigger_error("set_versiondata: Not Implemented", E_USER_WARNING);
383 function set_links($pagename, $links)
385 // TODO: needs to be tested ....
386 $megaHash = get_pagedata($pagename);
387 $megaHash[CMD_LINK_ATT] = $links;
388 $this->_writeMetaInfo($pagename, $megaHash);
391 function get_links($pagename, $reversed = true, $include_empty = false,
392 $sortby = '', $limit = '', $exclude = '')
394 // TODO: ignores the $reversed argument and returns
395 // TODO: the value of _links_ attribute of the meta information
396 // TODO: to implement a reversed version, i guess, we going to
397 // TODO: need to do a grep on all files for the pagename in
398 // TODO: in question and return all those page names that contained
399 // TODO: the required pagename!
400 $megaHash = get_pagedata($pagename);
401 return $megaHash[CMD_LINK_ATT];
404 /* function get_all_revisions($pagename) {
405 // TODO: should replace this with something more efficient
406 include_once 'lib/WikiDB/backend/dumb/AllRevisionsIter.php';
407 return new WikiDB_backend_dumb_AllRevisionsIter($this, $pagename);
410 function get_all_pages($include_empty = false, $sortby = '', $limit = '')
412 // FIXME: this ignores the parameters.
413 return new Cvs_Backend_Array_Iterator(
414 $this->_getAllFileNamesInDir($this->_docDir));
417 function text_search($search, $fullsearch = false, $orderby = false, $limit = '', $exclude = '')
420 $iter = new Cvs_Backend_Full_Search_Iterator(
421 $this->_getAllFileNamesInDir($this->_docDir),
424 $iter->stoplisted =& $search->stoplisted;
427 return new Cvs_Backend_Title_Search_Iterator(
428 $this->_getAllFileNamesInDir($this->_docDir),
433 function most_popular($limit, $sortby = '')
435 // TODO: needs to be tested ...
436 $mp = $this->_getMostPopular();
438 asort($mp, SORT_NUMERIC);
441 arsort($mp, SORT_NUMERIC);
443 $returnVal = array();
445 while ((list($key, $val) = each($a)) && $limit > 0) {
453 * This only accepts the 'since' and 'limit' attributes, everything
456 function most_recent($params)
458 // TODO: needs to be tested ...
459 // most recent are those pages with the highest time value ...
460 $mr = $this->_getMostRecent();
462 $returnVal = array();
463 if (isset($params['limit'])) {
464 $limit = $params['limit'];
468 arsort($mr, SORT_NUMERIC);
470 asort($mr, SORT_NUMERIC);
473 while ((list($key, $val) = each($a)) && $limit > 0) {
477 } elseif (isset($params['since'])) {
478 while ((list($key, $val) = each($a))) {
480 if ($val > $params['since']) {
486 return new Cvs_Backend_Array_Iterator($returnVal);
489 function lock($write_lock = true)
491 // TODO: to be implemented
492 trigger_error("lock: Not Implemented", E_USER_WARNING);
495 function unlock($force = false)
497 // TODO: to be implemented
498 trigger_error("unlock: Not Implemented", E_USER_WARNING);
514 * What we do here is take a listing of the documents directory and
515 * check that each page has metadata file. If not, then a metadata
516 * file is created for the page.
518 * This can happen if rebuild() was called and someone has added
519 * files to the CVS repository not via PhpWiki. These files are
520 * added to the document directory but without any metadata files.
525 // TODO: test this .... i.e. add test to unit test file.
527 $page_names = $this->_getAllFileNamesInDir($this->_docDir);
528 $meta_names = $this->_getAllFileNamesInDir($this->_docDir . "/CVS");
530 array_walk($meta_names, '_strip_leading_underscore');
532 $no_meta_files = array_diff($page_names, $meta_names);
534 array_walk($no_meta_files, '_create_meta_file', $this);
540 * Do an update of the CVS repository
545 // TODO: test this .... i.e. add test to unit test file.
547 $cmdLine = sprintf("cd %s; cvs update -d 2>&1", $this->_docDir);
548 $this->_execCommand($cmdLine, $cmdOutput, true);
553 // ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....
554 // The rest are all internal methods, not to be used
556 // ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....
558 function _create_meta_file($page_name, $key, &$backend)
560 // this is used as part of an array walk and therefore takes
561 // the backend argument
562 $backend->_cvsDebug(sprintf("Creating meta file for [%s]", $page_name));
563 $backend->update_pagedata($page_name, array());
566 function _strip_leading_underscore(&$item)
568 $item = ereg_replace("^_", "", $item);
572 * update the most popular information by incrementing the count
573 * for the following page. If the page was not defined, it is entered
576 function _updateMostPopular($pagename)
578 $mp = $this->_getMostPopular();
579 if (isset($mp[$pagename])) {
584 $this->_writeFileWithPath($this->_docDir . "/CVS/" . CVS_MP_FILE,
589 * Returns an array containing the most popular information. This
590 * creates the most popular file if it does not exist.
592 function _getMostPopular()
594 $mostPopular = $this->_docDir . "/CVS/" . CVS_MP_FILE;
595 if (!file_exists($mostPopular)) {
596 $this->_writeFileWithPath($mostPopular, serialize(array()));
598 return unserialize(join('', $this->_readFileWithPath($mostPopular)));
601 function _getMostRecent()
603 $mostRecent = $this->_docDir . "/CVS/" . CVS_MR_FILE;
604 if (!file_exists($mostRecent)) {
605 $this->_writeFileWithPath($mostRecent, serialize(array()));
607 return unserialize(join('', $this->_readFileWithPath($mostRecent)));
610 function _updateMostRecent($pagename)
612 $mr = $this->_getMostRecent();
613 $mr[$pagename] = time();
614 $this->_writeFileWithPath($this->_docDir . "/CVS/" . CVS_MR_FILE,
618 function _writeMetaInfo($pagename, $hashInfo)
620 $this->_writeFileWithPath($this->_docDir . "/CVS/_" . $pagename,
621 serialize($hashInfo));
624 function _writePage($pagename, $content)
626 $this->_writeFileWithPath($this->_docDir . "/" . $pagename, $content);
629 function _removePage($pagename)
631 $cmdLine = sprintf("cd %s; cvs remove %s 2>&1; cvs commit -m '%s' "
632 . "%s 2>&1", $this->_docDir, $pagename,
633 "remove page", $pagename);
635 $this->_execCommand($cmdLine, $cmdRemoveOutput, true);
639 * this returns the new version number of the file.
641 function _commitPage($pagename, &$meta_data)
643 $cmdLine = sprintf("cd %s; cvs commit -m \"%s\" %s 2>&1",
645 escapeshellcmd(serialize($meta_data)),
647 $this->_execCommand($cmdLine, $cmdOutput, true);
649 $cmdOutput = implode("\n", $cmdOutput);
651 ereg("\nnew revision: 1[.]([0-9]+); previous revision: ", $cmdOutput,
654 $this->_cvsDebug("CP: revInfo 0: $revInfo[0]");
655 $this->_cvsDebug("CP: $cmdOutput");
656 if (isset($revInfo[1])) {
657 $this->_cvsDebug("CP: got revision information");
660 ereg("\ninitial revision: 1[.]([0-9]+)", $cmdOutput, $revInfo);
661 if (isset($revInfo[1])) {
662 $this->_cvsDebug("CP: is initial release");
665 $this->_cvsDebug("CP: returning old version");
666 return $meta_data[CMD_VERSION];
670 function _addPage($pagename)
672 // TODO: need to add a check for the mimetype so that binary
673 // TODO: files are added as binary files
674 $cmdLine = sprintf("cd %s; cvs add %s 2>&1", $this->_docDir,
676 $this->_execCommand($cmdLine, $cmdAddOutput, true);
680 * Returns an array containing all the names of files contained
681 * in a particular directory. The list is sorted according the
682 * string representation of the filenames.
684 function _getAllFileNamesInDir($dirName)
687 $d = opendir($dirName);
688 while ($entry = readdir($d)) {
689 $namelist[] = $entry;
692 sort($namelist, SORT_STRING);
697 * Recursively create all directories.
699 function _mkdir($path, $mode)
701 $directoryName = dirname($path);
702 if ($directoryName != "/" && $directoryName != "\\"
703 && !is_dir($directoryName) && $directoryName != ""
705 $rVal = $this->_mkdir($directoryName, $mode);
710 return ($rVal && @mkdir($path, $mode));
714 * Recursively create all directories and then the file.
716 function _createFile($path, $mode)
718 $this->_mkdir(dirname($path), $mode);
724 * The lord giveth, and the lord taketh.
726 function _deleteFile($filename)
728 if ($fd = fopen($filename, 'a')) {
730 $locked = flock($fd, 2); // Exclusive blocking lock
733 $this->_cvsError("Unable to delete file, lock was not obtained.",
734 __LINE__, $filename, EM_NOTICE_ERRORS);
737 if (($rVal = unlink($filename)) != 0) {
738 $this->_cvsDebug("[$filename] --> Unlink returned [$rVal]");
743 $this->_cvsError("deleteFile: Unable to open file",
744 __LINE__, $filename, EM_NOTICE_ERRORS);
750 * Called when something happened that causes the CVS backend to
753 function _cvsError($msg = "no message",
755 $errfile = "lib/WikiDB/backend/cvs.php",
756 $errno = EM_FATAL_ERRORS)
758 $err = new PhpError($errno, "[CVS(be)]: " . $msg, $errfile, $errline);
759 // send error to the debug routine
760 $this->_cvsDebug($err->asXML());
761 // send the error to the error manager
762 $GLOBALS['ErrorManager']->handleError($err);
766 * Debug function specifically for the CVS database functions.
767 * Can be deactived by setting the WikiDB['debug_file'] to ""
769 function _cvsDebug($msg)
771 if ($this->_debug_file == "") {
775 if (!file_exists($this->_debug_file)) {
776 $this->_createFile($this->_debug_file, 0755);
779 if ($fdlock = @fopen($this->_debug_file, 'a')) {
780 $locked = flock($fdlock, 2);
786 $fdappend = @fopen($this->_debug_file, 'a');
787 fwrite($fdappend, ($msg . "\n"));
791 // TODO: this should be replaced ...
792 printf("unable to locate/open [%s], turning debug off\n", $filename);
793 $this->_debug_file = "";
798 * Execute a command and potentially exit if the flag exitOnNonZero is
799 * set to true and the return value was nonZero
801 function _execCommand($cmdLine, &$cmdOutput, $exitOnNonZero)
803 $this->_cvsDebug(sprintf("Preparing to execute [%s]", $cmdLine));
804 exec($cmdLine, $cmdOutput, $cmdReturnVal);
805 if ($exitOnNonZero && ($cmdReturnVal != 0)) {
806 $this->_cvsDebug(sprintf("Command failed [%s], Output: ", $cmdLine) . "[" .
807 join("\n", $cmdOutput) . "]");
808 $this->_cvsError(sprintf("Command failed [%s], Return value: %s", $cmdLine, $cmdReturnVal),
811 $this->_cvsDebug("Done execution [" . join("\n", $cmdOutput) . "]");
813 return $cmdReturnVal;
817 * Read locks a file, reads it, and returns it contents
819 function _readFileWithPath($filename)
821 if ($fd = @fopen($filename, "r")) {
822 $locked = flock($fd, 1); // read lock
825 $this->_cvsError("Unable to obtain read lock.", __LINE__);
828 $content = file($filename);
832 $this->_cvsError(sprintf("Unable to open file '%s' for reading", $filename),
839 * Either replace the contents of an existing file or create a
840 * new file in the particular store using the page name as the
843 * Nothing is returned, might be useful to return something ;-)
845 function _writeFileWithPath($filename, $contents)
847 // TODO: $contents should probably be a reference parameter ...
848 if ($fd = fopen($filename, 'a')) {
849 $locked = flock($fd, 2); // Exclusive blocking lock
851 $this->_cvsError("Timeout while obtaining lock.", __LINE__);
854 // Second filehandle -- we use this to write the contents
855 $fdsafe = fopen($filename, 'w');
856 fwrite($fdsafe, $contents);
860 $this->_cvsError(sprintf("Could not open file '%s' for writing", $filename),
866 * Copy the contents of the source directory to the destination directory.
868 function _copyFilesFromDirectory($src, $dest)
870 $this->_cvsDebug(sprintf("Copying from [%s] to [%s]", $src, $dest));
872 if (is_dir($src) && is_dir($dest)) {
873 $this->_cvsDebug("Copying ");
875 while ($entry = readdir($d)) {
876 if (is_file($src . "/" . $entry)
877 && copy($src . "/" . $entry, $dest . "/" . $entry)
879 $this->_cvsDebug(sprintf("Copied to [%s]", "$dest/$entry"));
881 $this->_cvsDebug(sprintf("Failed to copy [%s]", "$src/$entry"));
887 $this->_cvsDebug("Not copying");
893 * Unescape a string value. Normally this comes from doing an
894 * escapeshellcmd. This converts the following:
900 function _unescape($val)
902 $val = str_replace("\\{", "{", $val);
903 $val = str_replace("\\}", "}", $val);
904 $val = str_replace("\\;", ";", $val);
905 $val = str_replace("\\\"", "\"", $val);
911 * Function for removing the newlines from the ends of the
912 * file data returned from file(..). This is used in retrievePage
914 function _strip_newlines(&$item, $key)
916 $item = ereg_replace("\n$", "", $item);
919 } /* End of WikiDB_backend_cvs class */
922 * Generic iterator for stepping through an array of values.
924 class Cvs_Backend_Array_Iterator
925 extends WikiDB_backend_iterator
929 function Cvs_Backend_Iterator($arrayValue = Array())
931 $this->_array = $arrayValue;
936 while (($rVal = array_pop($this->_array)) != NULL) {
944 return count($this->_array);
949 unset($this->_array);
953 class Cvs_Backend_Full_Search_Iterator
954 extends Cvs_Backend_Array_Iterator
956 public $_searchString = '';
957 public $_docDir = "";
959 function Cvs_Backend_Title_Search_Iterator($arrayValue = Array(),
963 $this->Cvs_Backend_Array_Iterator($arrayValue);
964 $_searchString = $searchString;
965 $_docDir = $documentDir;
971 $pageName = Cvs_Backend_Array_Iterator::next();
972 } while (!$this->_searchFile($_searchString,
973 $_docDir . "/" . $pageName));
979 * Does nothing more than a grep and search the entire contents
980 * of the given file. Returns TRUE of the searchstring was found,
981 * false if the search string wasn't find or the file was a directory
982 * or could not be read.
984 function _searchFile($searchString, $fileName)
986 // TODO: using grep here, it might make more sense to use
987 // TODO: some sort of inbuilt/language specific method for
988 // TODO: searching files.
989 $cmdLine = sprintf("grep -E -i '%s' %s > /dev/null 2>&1",
990 $searchString, $fileName);
992 return (WikiDB_backend_cvs::_execCommand($cmdLine, $cmdOutput,
998 * Iterator used for doing a title search.
1000 class Cvs_Backend_Title_Search_Iterator
1001 extends Cvs_Backend_Array_Iterator
1003 public $_searchString = '';
1005 function Cvs_Backend_Title_Search_Iterator($arrayValue = Array(),
1008 $this->Cvs_Backend_Array_Iterator($arrayValue);
1009 $_searchString = $searchString;
1015 $pageName = Cvs_Backend_Array_Iterator::next();
1016 } while (!eregi($this->_searchString, $pageName));
1025 // c-basic-offset: 4
1026 // c-hanging-comment-ender-p: nil
1027 // indent-tabs-mode: nil