Indefero

Indefero Git Source Tree

Root/src/IDF/WikiPage.php

1<?php
2/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3/*
4# ***** BEGIN LICENSE BLOCK *****
5# This file is part of InDefero, an open source project management application.
6# Copyright (C) 2008 Céondo Ltd and contributors.
7#
8# InDefero is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# InDefero is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21#
22# ***** END LICENSE BLOCK ***** */
23
24Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
25Pluf::loadFunction('Pluf_Template_dateAgo');
26
27/**
28 * Base definition of a wiki page.
29 *
30 * A wiki page can have tags and be starred by the users. The real
31 * content of the page is stored in the IDF_WikiRevision
32 * object. Several revisions are associated to a given page.
33 */
34class IDF_WikiPage extends Pluf_Model
35{
36 public $_model = __CLASS__;
37
38 function init()
39 {
40 $this->_a['table'] = 'idf_wikipages';
41 $this->_a['model'] = __CLASS__;
42 $this->_a['cols'] = array(
43 // It is mandatory to have an "id" column.
44 'id' =>
45 array(
46 'type' => 'Pluf_DB_Field_Sequence',
47 'blank' => true,
48 ),
49 'project' =>
50 array(
51 'type' => 'Pluf_DB_Field_Foreignkey',
52 'model' => 'IDF_Project',
53 'blank' => false,
54 'verbose' => __('project'),
55 'relate_name' => 'wikipages',
56 ),
57 'title' =>
58 array(
59 'type' => 'Pluf_DB_Field_Varchar',
60 'blank' => false,
61 'size' => 250,
62 'verbose' => __('title'),
63 'help_text' => __('The title of the page must only contain letters, digits or the dash character. For example: My-new-Wiki-Page.'),
64 ),
65 'summary' =>
66 array(
67 'type' => 'Pluf_DB_Field_Varchar',
68 'blank' => false,
69 'size' => 250,
70 'verbose' => __('summary'),
71 'help_text' => __('A one line description of the page content.'),
72 ),
73 'submitter' =>
74 array(
75 'type' => 'Pluf_DB_Field_Foreignkey',
76 'model' => 'Pluf_User',
77 'blank' => false,
78 'verbose' => __('submitter'),
79 'relate_name' => 'submitted_wikipages',
80 ),
81 'interested' =>
82 array(
83 'type' => 'Pluf_DB_Field_Manytomany',
84 'model' => 'Pluf_User',
85 'blank' => true,
86 'verbose' => __('interested users'),
87 'help_text' => 'Interested users will get an email notification when the wiki page is changed.',
88 ),
89 'tags' =>
90 array(
91 'type' => 'Pluf_DB_Field_Manytomany',
92 'blank' => true,
93 'model' => 'IDF_Tag',
94 'verbose' => __('labels'),
95 ),
96 'creation_dtime' =>
97 array(
98 'type' => 'Pluf_DB_Field_Datetime',
99 'blank' => true,
100 'verbose' => __('creation date'),
101 ),
102 'modif_dtime' =>
103 array(
104 'type' => 'Pluf_DB_Field_Datetime',
105 'blank' => true,
106 'verbose' => __('modification date'),
107 ),
108 );
109 $this->_a['idx'] = array(
110 'modif_dtime_idx' =>
111 array(
112 'col' => 'modif_dtime',
113 'type' => 'normal',
114 ),
115 );
116 $table = $this->_con->pfx.'idf_tag_idf_wikipage_assoc';
117 $this->_a['views'] = array(
118 'join_tags' =>
119 array(
120 'join' => 'LEFT JOIN '.$table
121 .' ON idf_wikipage_id=id',
122 ),
123 );
124 }
125
126 function __toString()
127 {
128 return $this->title.' - '.$this->summary;
129 }
130
131 function _toIndex()
132 {
133 $rev = $this->get_current_revision()->_toIndex();
134 $str = str_repeat($this->summary.' ', 4).' '.$rev;
135 return Pluf_Text::cleanString(html_entity_decode($str, ENT_QUOTES, 'UTF-8'));
136 }
137
138 function get_current_revision()
139 {
140 $db = $this->getDbConnection();
141 $true = Pluf_DB_BooleanToDb(true, $db);
142 $rev = $this->get_revisions_list(array('filter' => 'is_head='.$true,
143 'nb' => 1));
144 return ($rev->count() == 1) ? $rev[0] : null;
145 }
146
147 function preSave($create=false)
148 {
149 if ($this->id == '') {
150 $this->creation_dtime = gmdate('Y-m-d H:i:s');
151 }
152 $this->modif_dtime = gmdate('Y-m-d H:i:s');
153 }
154
155 function postSave($create=false)
156 {
157 // Note: No indexing is performed here. The indexing is
158 // triggered in the postSave step of the revision to ensure
159 // that the page as a given revision in the database when
160 // doing the indexing.
161 if ($create) {
162 IDF_Timeline::insert($this, $this->get_project(),
163 $this->get_submitter());
164 }
165 }
166
167 /**
168 * Returns an HTML fragment used to display this wikipage in the
169 * timeline.
170 *
171 * The request object is given to be able to check the rights and
172 * as such create links to other items etc. You can consider that
173 * if displayed, you can create a link to it.
174 *
175 * @param Pluf_HTTP_Request
176 * @return Pluf_Template_SafeString
177 */
178 public function timelineFragment($request)
179 {
180 $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
181 array($request->project->shortname,
182 $this->title));
183 $out = '<tr class="log"><td><a href="'.$url.'">'.
184 Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')).
185 '</a></td><td>';
186 $submitter = $this->get_submitter();
187 $out .= sprintf(__('<a href="%1$s" title="View page">%2$s</a>, %3$s'), $url, Pluf_esc($this->title), Pluf_esc($this->summary)).'</td>';
188 $out .= "\n".'<tr class="extra"><td colspan="2">
189<div class="helptext right">'.sprintf(__('Creation of <a href="%s">page&nbsp;%s</a>'), $url, Pluf_esc($this->title)).', '.__('by').' '.Pluf_esc($submitter).'</div></td></tr>';
190 return Pluf_Template::markSafe($out);
191 }
192}

Archive Download this file