diff --git a/src/IDF/Views/Wiki.php b/src/IDF/Views/Wiki.php index a70617b..f157062 100644 --- a/src/IDF/Views/Wiki.php +++ b/src/IDF/Views/Wiki.php @@ -275,7 +275,7 @@ class IDF_Views_Wiki } return Pluf_Shortcuts_RenderToResponse('idf/wiki/createResource.html', array( - 'resource_title' => $title, + 'page_title' => $title, 'form' => $form, ), $request); @@ -328,6 +328,64 @@ class IDF_Views_Wiki } /** + * View a documentation resource. + */ + public $viewResource_precond = array('IDF_Precondition::accessWiki'); + public function viewResource($request, $match) + { + $prj = $request->project; + $sql = new Pluf_SQL('project=%s AND title=%s', + array($prj->id, $match[2])); + $resources = Pluf::factory('IDF_Wiki_Resource')->getList(array('filter'=>$sql->gen())); + if ($resources->count() != 1) { + return new Pluf_HTTP_Response_NotFound($request); + } + $resource = $resources[0]; + $revision = $resource->get_current_revision(); + + // grab the old revision if requested. + if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) { + $revision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_ResourceRevision', + $request->GET['rev']); + if ($oldrev->wikiresource != $resource->id or $oldrev->is_head == true) { + return new Pluf_HTTP_Response_NotFound($request); + } + } + $pagerevs = $revision->getPageRevisions(); + $title = $resource->title; + $false = Pluf_DB_BooleanToDb(false, $resource->getDbConnection()); + $revs = $resource->get_revisions_list(array('order' => 'creation_dtime DESC', + 'filter' => 'is_head='.$false)); + return Pluf_Shortcuts_RenderToResponse('idf/wiki/viewResource.html', + array( + 'page_title' => $title, + 'resource' => $resource, + 'rev' => $revision, + 'revs' => $revs, + 'pagerevs' => $pagerevs, + ), + $request); + } + + + /** + * Returns a bytestream to the given raw resource revision + */ + public $rawResource_precond = array('IDF_Precondition::accessWiki'); + public function rawResource($request, $match) + { + $prj = $request->project; + $rev = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_ResourceRevision', + $match[2]); + $res = $rev->get_wikiresource(); + if ($res->get_project()->id != $prj->id) { + return new Pluf_HTTP_Response_NotFound($request); + } + + return new Pluf_HTTP_Response_File($rev->getFilePath(), $res->mime_type); + } + + /** * Remove a revision of a page. */ public $deletePageRev_precond = array('IDF_Precondition::accessWiki', diff --git a/src/IDF/Wiki/ResourceRevision.php b/src/IDF/Wiki/ResourceRevision.php index 43eadd4..59e319f 100644 --- a/src/IDF/Wiki/ResourceRevision.php +++ b/src/IDF/Wiki/ResourceRevision.php @@ -138,8 +138,55 @@ class IDF_Wiki_ResourceRevision extends Pluf_Model $this->get_wikiresource()->id, $this->id, $this->get_wikiresource()->orig_file_ext); } + function getFileURL() + { + $prj = $this->get_wikiresource()->get_project(); + return Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::rawResource', + array($prj->shortname, $this->id)); + } + function preDelete() { @unlink($this->getFilePath()); } + + /** + * Returns the page revisions which contain references to this resource revision + */ + function getPageRevisions() + { + $db =& Pluf::db(); + $sql_results = $db->select( + 'SELECT idf_wiki_pagerevision_id as id '. + 'FROM '.Pluf::f('db_table_prefix', '').'idf_wiki_pagerevision_idf_wiki_resourcerevision_assoc '. + 'WHERE idf_wiki_resourcerevision_id='.$this->id + ); + $ids = array(0); + foreach ($sql_results as $id) { + $ids[] = $id['id']; + } + $ids = implode (',', $ids); + + $sql = new Pluf_SQL('id IN ('.$ids.')'); + return Pluf::factory('IDF_Wiki_PageRevision') + ->getList(array('filter' => $sql->gen())); + } + + /** + * Renders the resource + */ + function render() + { + $url = $this->getFileURL(); + $resource = $this->get_wikiresource(); + if (preg_match('#^image/(gif|jpeg|png|tiff)$#', $resource->mime_type)) { + return sprintf('', $url, $url, $resource->title); + } + + if (preg_match('#^text/(xml|html|sgml|javascript|ecmascript|css)$#', $resource->mime_type)) { + return sprintf('', $url, $resource->title); + } + + return __('Unable to render preview for this MIME type.'); + } } diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 71e30f6..745a552 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -322,6 +322,11 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/res/delete/(\d+)/$#', 'model' => 'IDF_Views_Wiki', 'method' => 'deleteResource'); +$ctl[] = array('regex' => '#^/p/([\-\w]+)/res/raw/(.*)/$#', + 'base' => $base, + 'model' => 'IDF_Views_Wiki', + 'method' => 'rawResource'); + $ctl[] = array('regex' => '#^/p/([\-\w]+)/page/(.*)/$#', 'base' => $base, 'model' => 'IDF_Views_Wiki', diff --git a/src/IDF/templates/idf/wiki/viewResource.html b/src/IDF/templates/idf/wiki/viewResource.html new file mode 100644 index 0000000..3cd4e8d --- /dev/null +++ b/src/IDF/templates/idf/wiki/viewResource.html @@ -0,0 +1,55 @@ +{extends "idf/wiki/base.html"} + +{block extraheader} +{if !$rev.is_head}{/if} +{/block} + +{block docclass}yui-t3{assign $inResourceView=true}{/block} + +{block body} +{if !$rev.is_head} +{ashowuser 'submitter', $oldrev.get_submitter(), $request}{aurl 'url', 'IDF_Views_Wiki::viewResource', array($project.shortname, $resource.title)} +
{blocktrans}You are looking at an old revision of the resource +{$resource.title}. This revision was created +by {$submitter}.{/blocktrans}
+{$resource.summary}
+ +{$rev.render()|unsafe}
+ +{trans 'Delete this revision'}
+{/if} + +{trans 'Page Usage'}
+{if $pagerevs.count() == 0} +{trans 'This resource is not used on any pages yet.'}
+{else} +{trans 'Created:'} {$resource.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}
{ashowuser 'submitter', $rev.get_submitter(), $request}
+{trans 'Updated:'} {$rev.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}
{trans 'Old Revisions'}
+