getWorkingCopy(); } return self::$wc; } static function getRepoAndRoot(&$repo) { // $repo = MTrack_Repo::factory(array('default/wiki'); // <<< difficult... Frontend can set up the REPO object, // but we should not be able to call frontend. if (!self::$repo) { throw new Exception("WIKI REPO IS NOT SET UP - MTrack_Wiki_Item::$repo must point to default/wiki"); } $repo = self::$repo; return self::$repo->getDefaultRoot(); } static function index_item($object) { list($ignore, $ident) = explode(':', $object, 2); $w = new MTrack_Wiki_Item($ident); MTrackSearchDB::add("wiki:$w->pagename", array( 'wiki' => $w->content, 'who' => $w->who, ), true); } static function _get_parent_for_acl($objectid) { if (preg_match("/^(wiki:.*)\/([^\/]+)$/", $objectid, $M)) { return $M[1]; } if (preg_match("/^wiki:.*$/", $objectid, $M)) { return 'Wiki'; } return null; } function __construct($name, $version = null) { $this->pagename = $name; $this->filename = self::getRepoAndRoot($repo) . $name . '.wiki'; //$suf = MTrackConfig::get('core', 'wikifilenamesuffix'); //var_dump($suf); exit; //if ($suf) { // $this->filename .= $suf; //} if ($version !== null) { $this->file = $repo->file($this->filename, 'rev', $version); } else { $this->file = $repo->file($this->filename); } if ($this->file && $repo->history($this->filename, 1)) { $this->version = $this->file->rev; } else { $this->file = null; } } /* function __get($name) //??? overload???/ { throw new Exception("Overload is no going to work any more - it's just too confusing "); if ($name == 'content') { $this->content = stream_get_contents($this->file->cat()); return $this->content; } } */ function save(MTrackChangeset $changeset) { $wc = self::getWC(); $lfilename = $this->pagename . '.wiki';; //$suf = MTrackConfig::get('core', 'wikifilenamesuffix'); //if ($suf) { //$lfilename .= $suf; //} if (!strlen(trim($this->content))) { if ($wc->file_exists($lfilename)) { // removing $wc->delFile($lfilename); } } else { if (!$wc->file_exists($lfilename)) { // handle dirs $elements = explode('/', $lfilename); $accum = array(); while (count($elements) > 1) { $ent = array_shift($elements); $accum[] = $ent; $base = join(DIRECTORY_SEPARATOR, $accum); if (!$wc->file_exists($base)) { if (!mkdir($wc->getDir() . DIRECTORY_SEPARATOR . $base)) { throw new Exception( "unable to mkdir(" . $wc->getDir() . DIRECTORY_SEPARATOR . "$base)"); } $wc->addFile($base); } else if (!is_dir($wc->getDir() . DIRECTORY_SEPARATOR . $base)) { throw new Exception("$base is not a dir; cannot create $lfilename"); } } file_put_contents($wc->getDir() . DIRECTORY_SEPARATOR . $lfilename, $this->content); $wc->addFile($lfilename); } else { file_put_contents($wc->getDir() . DIRECTORY_SEPARATOR . $lfilename, $this->content); } } /* use an env var to signal to the commit hook that it does not * need to make a changeset for this commit */ putenv("MTRACK_WIKI_COMMIT=1"); $wc->commit($changeset); } function toHTML() { return MTrack_Wiki::format_to_html($this->content); } }