Implement request #12: DOAP documents for all pastes
authorChristian Weiske <cweiske@cweiske.de>
Sun, 16 Sep 2012 21:22:55 +0000 (23:22 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 16 Sep 2012 21:22:55 +0000 (23:22 +0200)
ChangeLog
data/templates/display.htm
data/templates/doap.htm [new file with mode: 0644]
src/phorkie/Repository.php
www/.htaccess
www/doap.php [new file with mode: 0644]

index 7e45b7d..afefa9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2012-09-16  Christian Weiske  <cweiske@cweiske.de>
+
+       * Implement request #12: DOAP documents for all pastes
+
 2012-09-08  Christian Weiske  <cweiske@cweiske.de>
 
        * Fix bug #11: do not index edit, delete and tool pages
index 6d84c46..5bcb016 100644 (file)
@@ -3,6 +3,10 @@
  {{repo.getTitle}}
 {% endblock %}
 
+{% block meta %}
+<link rel="meta" title="DOAP" type="application/rdf+xml" href="{{repo.getLink('doap')}}"/>
+{% endblock %}
+
 {% block content %}
  {% include 'display-head.htm' %}
 
diff --git a/data/templates/doap.htm b/data/templates/doap.htm
new file mode 100644 (file)
index 0000000..5302dd4
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+       xmlns="http://usefulinc.com/ns/doap#">
+ <Project rdf:about="{{link}}">
+  <name>{{repo.getTitle}}</name>
+  <homepage rdf:resource="{{link}}" />
+  <created>{{date}}</created>
+  {% if repo.getCloneURL(true) %}
+  <repository>
+   <GitRepository>
+    <location rdf:resource="{{repo.getCloneURL(true)}}" />
+    <browse rdf:resource="{{link}}" />
+   </GitRepository>
+  </repository>
+  {%endif %}
+ </Project>
+</rdf:RDF>
index 448982b..46b2f65 100644 (file)
@@ -228,6 +228,8 @@ class Repository
             return '/' . $this->id;
         } else if ($type == 'fork') {
             return '/' . $this->id . '/fork';
+        } else if ($type == 'doap') {
+            return '/' . $this->id . '/doap';
         } else if ($type == 'delete') {
             return '/' . $this->id . '/delete';
         } else if ($type == 'delete-confirm') {
index a8f2eed..c379b23 100644 (file)
@@ -5,6 +5,7 @@ RewriteBase /
 RewriteRule ^([0-9]+)$ /display.php?id=$1
 RewriteRule ^([0-9]+)/delete$ /delete.php?id=$1
 RewriteRule ^([0-9]+)/delete/confirm$ /delete.php?id=$1&confirm=1
+RewriteRule ^([0-9]+)/doap$ /doap.php?id=$1
 RewriteRule ^([0-9]+)/edit$ /edit.php?id=$1
 RewriteRule ^([0-9]+)/fork$ /fork.php?id=$1
 RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
diff --git a/www/doap.php b/www/doap.php
new file mode 100644 (file)
index 0000000..db00df4
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+namespace phorkie;
+/**
+ * Display DOAP of the paste.
+ * Contains a machine-readable project description with Git URL.
+ */
+require_once 'www-header.php';
+
+$repo = new Repository();
+$repo->loadFromRequest();
+
+header('Content-Type: application/rdf+xml');
+render(
+    'doap',
+    array(
+        'repo' => $repo,
+        'date' => date('Y-m-d', end($repo->getHistory())->committerTime),
+        'link' => Tools::fullUrl($repo->getLink('display'))
+    )
+);
+?>