From f473691479b243b7b9bec9e400c758e3ea966360 Mon Sep 17 00:00:00 2001 From: Andrew Nguyen Date: Mon, 3 Aug 2009 22:38:14 +0200 Subject: [PATCH] Fixed issue 262, embbed documents from repository in Documentation wiki. You can now embbed text documents frome the repository into the documentation wiki. Changes in the repository are automatically reflected into the wiki. The syntax is [[[path/to/file, optional commit]]]. --- src/IDF/Template/Markdown.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/IDF/Template/Markdown.php b/src/IDF/Template/Markdown.php index 23a3384..feb8512 100644 --- a/src/IDF/Template/Markdown.php +++ b/src/IDF/Template/Markdown.php @@ -39,8 +39,14 @@ class IDF_Template_Markdown extends Pluf_Template_Tag // Replace like in the issue text $tag = new IDF_Template_IssueComment(); $text = $tag->start($text, $request, false, false, false, false); + // Replace [[[path/to/file.mdtext, commit]]] with embedding + // the content of the file into the wki page + if ($this->request->rights['hasSourceAccess']) { + $text = preg_replace_callback('#\[\[\[([^\,]+)(?:, ([^/]+))?\]\]\]#im', + array($this, 'callbackEmbeddedDoc'), + $text); + } // Replace [[PageName]] with corresponding link to the page. - // if not the right to see the $text = preg_replace_callback('#\[\[([A-Za-z0-9\-]+)\]\]#im', array($this, 'callbackWikiPage'), $text); @@ -65,5 +71,25 @@ class IDF_Template_Markdown extends Pluf_Template_Tag } return ''.$m[1].''; } + + function callbackEmbeddedDoc($m) + { + $scm = IDF_Scm::get($this->request->project); + $view_source = new IDF_Views_Source(); + $match = array('dummy', $this->request->project->shortname); + $match[] = (isset($m[2])) ? $m[2] : $scm->getMainBranch(); + $match[] = $m[1]; + $res = $view_source->getFile($this->request, $match); + if ($res->status_code != 200) { + return $m[0]; + } + $info = pathinfo($m[1]); + $fileinfo = array($res->headers['Content-Type'], $m[1], + isset($info['extension']) ? $info['extension'] : 'bin'); + if (!IDF_Views_Source::isText($fileinfo)) { + return $m[0]; + } + return $res->content; + } }