remote forking: use the original http/https url in description
[phorkie.git] / README.rst
1 ************************************
2 phorkie - PHP and Git based pastebin
3 ************************************
4 Self-hosted pastebin software written in PHP.
5 Pastes are editable, may have multiple files and are stored in git repositories.
6
7 Project page: http://sourceforge.net/p/phorkie/
8
9 .. contents:: Table of Contents
10
11 ========
12 Features
13 ========
14 - every paste is a git repository
15
16   - repositories can be cloned
17   - clone url can be displayed
18 - paste editing
19
20   - add new files
21   - delete existing files
22   - replace file with upload
23 - OpenID authentication
24 - multiple files in one paste
25 - syntax highlighting with GeSHi
26 - rST and Markdown rendering
27 - image upload + display
28 - external tool support
29
30   - xmllint
31   - php syntax check
32 - history in the sidebar
33
34   - old files can be downloaded easily
35 - search across pastes: description, file names and file content
36
37   - options: quoting, logical and, or, not, partial words
38
39
40 ============
41 Installation
42 ============
43 1. Unzip the phorkie release file::
44
45    $ tar xjvf phorkie-0.3.0.tar.bz2
46
47 2. Create the git directories::
48
49    $ mkdir -p repos/git repos/work
50    $ chmod og+w repos/git repos/work
51
52 3. Install dependencies_
53
54 4. Copy ``data/config.php.dist`` to ``data/config.php`` and adjust it
55    to your needs::
56
57    $ cp data/config.php.dist data/config.php
58    $ $EDITOR data/config.php
59
60    Look at ``config.default.php`` for values that you may adjust.
61
62 5. Set your web server's document root to ``/path/to/phorkie/www/``
63
64 6. Open phorkie in your web browser
65
66
67 Dependencies
68 ============
69 phorkie stands on the shoulders of giants.
70
71 It requires the following programs to be installed
72 on your machine:
73
74 - Git v1.7.5 or later
75 - PHP v5.3.0 or later
76 - PEAR v1.9.2 or later
77
78 ::
79
80   $ pear install versioncontrol_git-alpha
81   $ pear install services_libravatar-alpha
82   $ pear install http_request2
83   $ pear install pager
84   $ pear install date_humandiff-alpha
85
86   $ pear channel-discover pear.twig-project.org
87   $ pear install twig/Twig
88
89   $ pear channel-discover mediawiki.googlecode.com/svn
90   $ pear install mediawiki/geshi
91
92   $ pear channel-discover zustellzentrum.cweiske.de
93   $ pear install zz/mime_type_plaindetect-alpha
94
95   $ pear channel-discover pear.michelf.ca
96   $ pear install michelf/Markdown
97
98 Note that this version of GeSHi is a bit outdated, but it's the fastest
99 way to install it.
100 If you install it manually be sure to update the
101 path from ``data/config.default.php``.
102
103 ======
104 Search
105 ======
106
107 phorkie makes use of an Elasticsearch__ installation, if you have one.
108
109 It is used to provide search capabilities and the list of recent pastes.
110
111 __ http://www.elasticsearch.org/
112
113 Setup
114 =====
115 Edit ``config.php``, setting the ``elasticsearch`` property to the HTTP URL
116 of the index, e.g. ::
117
118   http://localhost:9200/phorkie/
119
120 Run the index script to import all existing pastes into the index::
121
122   php scripts/index.php
123
124 That's all. Open phorkie in your browser, and you'll notice the search box
125 in the top menu.
126
127
128 Reset
129 =====
130 In case something really went wrong and you need to reset the search
131 index, run the following command::
132
133   $ curl -XDELETE http://localhost:9200/phorkie/
134   {"ok":true,"acknowledged"}
135
136 Phorkie will automatically re-index everything when ``setupcheck`` is enabled
137 in the configuration file.
138
139
140 =====
141 HowTo
142 =====
143
144 Make git repositories clonable
145 ==============================
146 To make git repositories clonable, you need to install ``git-daemon``
147 (``git-daemon-run`` package on Debian/Ubuntu).
148
149 Make the repositories available by symlinking the paste repository
150 directory (``$GLOBALS['phorkie']['cfg']['repos']`` setting) into
151 ``/var/cache/git``, e.g.::
152
153   $ ln -s /home/user/www/paste/repos/git /var/cache/git/paste
154
155 Edit your ``config.php`` and set the ``$GLOBALS['phorkie']['cfg']['git']['public']``
156 setting to ``git://$yourhostname/git/paste/``.
157 The rest will be appended automatically.
158
159
160 You're on your own to setup writable repositories.
161
162
163 Protect your site with OpenID
164 =============================
165 You have the option of enabling OpenID authentication to help secure your
166 pastes on phorkie.
167 Set the ``$GLOBALS['phorkie']['auth']`` values in the
168 ``data/config.php`` file as desired.
169
170 There are two different types of security you can apply.
171 First, you can restrict to one of three ``securityLevels``:
172
173 - completely open (``0``)
174 - protection of write-enabled functions such as add, edit, etc. (``1``)
175 - full site protection (``2``)
176
177 Additionally, you can restrict your site to ``listedUsersOnly``.
178 You will need to add the individual OpenID urls to the
179 ``$GLOBALS['phorkie']['auth']['users']`` variable.
180
181
182 Get information about paste editors
183 ===================================
184 Phorkie stores the user's OpenID or IP address (when not logged in) when
185 a paste is edited.
186 It is possible to get this information for each single commit::
187
188     // IP / OpenID for the latest commit
189     $ git notes --ref=identity show
190     127.0.0.1
191
192     // show IP / OpenID for a given commit
193     $ git notes --ref=identity show 29f82a
194     http://cweiske.de/
195
196
197 =================
198 Technical details
199 =================
200
201 TODO
202 ====
203 - filters (``xmllint --format``, ``rapper``)
204 - document how to keep disk usage low (block size)
205 - comments
206 - when 2 people edit, merge changes
207 - diff changes
208 - configurable highlights
209 - Atom feed for new pastes
210 - Atom feed for paste changes
211
212
213 URLs
214 ====
215
216 ``/``
217   Index page.
218 ``/[0-9]+``
219   Display page for paste
220 ``/[0-9]/edit``
221   Edit the paste
222 ``/[0-9]+/raw/(.+)``
223   Display raw file contents
224 ``/[0-9]/tool/[a-zA-Z]+/(.+)``
225   Run a tool on the given file
226 ``/[0-9]/rev/[a-z0-9]+``
227   Show specific revision of the paste
228 ``/[0-9]/delete``
229   Delete the paste
230 ``/[0-9]/doap``
231   Show DOAP document for paste
232 ``/[0-9]/fork``
233   Create a fork of the paste
234 ``/search?q=..(&page=[0-9]+)?``
235   Search for term, with optional page
236 ``/list(/[0-9])?``
237   List all pastes, with optional page
238 ``/new``
239   Shows form for new paste
240 ``/login``
241   Login page for protecting site
242 ``/user``
243   Edit logged-in user information
244
245
246 Internal directory layout
247 =========================
248 ::
249
250   repos/
251     work/
252       1/ - work directory for paste #1
253       2/ - work directory for paste #2
254     git/
255       1.git/ - git repository for paste #1
256         description - Description for the repository
257       2.git/ - git repository for paste #2
258
259 nginx rewrites
260 ==============
261 If you use nginx, place the following lines into your ``server`` block:
262
263 ::
264
265   if (!-e $request_uri) {
266     rewrite ^/([0-9]+)$ /display.php?id=$1;
267     rewrite ^/([0-9]+)/delete$ /delete.php?id=$1;
268     rewrite ^/([0-9]+)/delete/confirm$ /delete.php?id=$1&confirm=1;
269     rewrite ^/([0-9]+)/doap$ /doap.php?id=$1;
270     rewrite ^/([0-9]+)/edit$ /edit.php?id=$1;
271     rewrite ^/([0-9]+)/fork$ /fork.php?id=$1;
272     rewrite ^/([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2;
273     rewrite ^/([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2;
274     rewrite ^/([0-9]+)/rev-raw/(.+)$ /raw.php?id=$1&rev=$2&file=$3;
275     rewrite ^/([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3;
276
277     rewrite ^/new$ /new.php;
278     rewrite ^/list$ /list.php;
279     rewrite ^/list/([0-9]+)$ /list.php?page=$1;
280
281     rewrite ^/search$ /search.php;
282     rewrite ^/search/([0-9]+)$ /search.php?page=$1;
283
284     rewrite ^/login$ /login.php;
285     rewrite ^/user$ /user.php;
286   }