Wiki

Contents

1. Introduction

A wiki in QM

2. Model

2.1. models/wiki.r

Rebol [
Title: "Wiki Table"
Type: 'roughcut
]
 
record: make record [
title: does [get 'id]
 
populate: injects [
content: string! length is less-than 10'000
]
 
content: does [
any [
get 'content
rejoin ["!!!!!" title " does not exist!!!!!"]
]
]
]

3. Controller

3.1. controllers/wiki.r

Rebol [
Title: "Quick Wiki Example"
Type: 'controller
Default: "show"
Template: %templates/qm.rsp
]
 
event "prepare" does [
title: none select-new: [
page: select wiki 'new
page/set 'id title
]
format: func [text][
rejoin ["<p>" replace/all sanitize text newline <br /> "</p>"]
]
link-up: func [text] [
text: parse/all text "*"
rejoin map-each [txt lnk] text [
lnk: either lnk [
build/with {<%! a wiki/show/(lnk) %><%= lnk %></a>} [lnk]
][""]
]
]
]
 
protect "edit" "store" (not user/has-role? 'participant) [
redirect-to user/sign-in
]
 
action "show" [title: opt string! [some chars-f]] does [
title: any [title "Start"]
unless page: select wiki title select-new
]
 
action "edit" [title: string! [some chars-f]] does [
unless page: select wiki title select-new
]
 
action "store" [title: string! [some chars-f]] does [
unless page: select wiki title select-new
 
either page/populate get-param 'page [
page/store
redirect-to wiki/show/(page/title)
][
render %edit.rsp
]
]
 
action "index" [page: opt integer!] does [
pages: paginate/size wiki page 5
title: reform ["Page" pages/current "of" pages/last]
]

4. Views

4.1. views/wiki/wiki.rsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<title><%= title: any [title page/title] %></title>
<link href="/styles/anywhere.css" type="text/css" rel="stylesheet" />
</head>
<body>
<h1>Wiki!</h1>
<h2><%= title %></h2>
<hr />
<%= yield %>
<hr />
<p><%! a wiki/edit/(any [id "Start"]) %>Edit</a> || <%! a wiki/index %>Index</a> || <%! a user/sign-out %>Sign Out</a></p>
</body>
</html>

4.2. views/wiki/index.rsp

<p><a href="/wiki">Start</a><% if pages/previous [ %>
|| <%! a wiki/index/(pages/previous) %>Previous Page</a><% ] if pages/next [ %>
|| <%! a wiki/index/(pages/next) %>Next Page</a><% ] %></p>
 
<ul class="index"><% foreach page pages/records [ %>
<li><%! a wiki/show/(page/title) %><%= page/title %></a></li><% ] %>
</ul>

4.3. views/wiki/show.rsp

<div class="hfeed">
<div class="hentry" id="post-<%= page/title %>">
 
<h3>Page #<%= page/title %></h3>
 
<div class="entry-content">
<%= link-up format page/content %>
</div>
 
<p><a href="/wiki">Start</a>
|| <a href="/wiki/index">Index</a><% if user/has-role? 'editor [ %>
|| <%! a wiki/edit/(page/title) %>Edit</a><% ] %></p>
 
</div>
</div>

4.4. views/wiki/edit.rsp

<%! form wiki/store/(title) %><fieldset>
<legend>Edit "<%= page/title %>"</legend>
<table><tr>
<th><label for="page.content">Content</label></th>
<td><%! area page/content (page/content) 100x10 %></td>
</tr><tr>
<td></td>
<td><%! submit store "Store" %></td>
</tr></table>
</fieldset></form>