4 * This handles link creation for the wiki..
6 * it get's registered by MTrackWeb as the link handler..
9 require_once 'MTrack/Interface/WikiLinkHandler.php';
12 class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
14 function MTrackWeb_LinkHandler()
16 $ff = HTML_FlexyFramework::get();
18 $this->baseURL = $ff->cli ? $ff->MTrackCLI['baseURL'] : $ff->page->baseURL;
25 * [display] = text to display
28 function ticket($no, $extras=array())
31 if ($no instanceof DB_DataObject) {
33 } else if (is_string($no) || is_int($no)) {
34 static $cache = array();
40 if (!isset($cache[$no])) {
41 $tkt = DB_DataOBject::Factory('mtrack_ticket');
49 // FIXME: hinted data from reports
51 $tkt->id = $no['ticket'];
52 $tkt->summary = $no['summary'];
55 if (isset($no['state'])) {
56 $tkt->status = $no['state'];
57 } elseif (isset($no['status'])) {
58 $tkt->status = $no['status'];
59 } elseif (isset($no['__status__'])) {
60 $tkt->status = $no['__status__'];
67 $tkt->summary = 'No such ticket';
68 $tkt->status = 'No such ticket';
70 $html = "<a class='ticketlink";
71 if ($tkt->status == 'closed') {
72 $html .= ' completed';
74 if (!empty($tkt->nsident)) {
75 $ident = $tkt->nsident;
79 if (isset($extras['#'])) {
80 $anchor = '#' . $extras['#'];
84 $html .= "' href=\"{$this->baseURL}/Ticket/$ident$anchor\">";
85 if (isset($extras['display'])) {
86 $html .= htmlspecialchars($extras['display']);
88 $html .= '#' . htmlspecialchars($ident);
94 function milestone( $target, $label)
96 // silly but we assume target is urlencoded???...
97 $ms = MTrack_Milestone::loadByName($target);
99 return '<span class="milestone' .
100 (($ms->deleted || $ms->completed) ? ' completed' : '') .
101 '"><a href="'. $this->baseURL . '/Milestone/'. $target .'">'.
102 htmlspecialchars(urldecode($target)) .
106 function help($target, $label, $anchor = '')
110 $target .= !empty($anchor) ? "#$anchor" : '';
112 return '<a class="wikilink"
113 href="'.$this->baseURL . '/Help/' . htmlspecialchars($target) .
114 '">' . htmlspecialchars($label) . '</a>';
117 function username($target, $opts=array())
119 if (is_object($target)) {
121 $target = $person->id;
123 $person = DB_DataObject::factory('Person');
124 $person->get($target);
127 if (is_string($opts)) {
128 parse_str($opts, $opts);
133 // we did not find the ysers...
134 // we currently ignore all the formating....
136 href="'. $this->baseURL .'/User/'. urlencode($target) . '" class="userlink">' .
137 htmlspecialchars($target).
141 if (!ctype_alnum($username)) {
142 $target = "{$ABSWEB}user.php?user=" . urlencode($username);
143 if (isset($opts['edit'])) {
144 $target .= '&edit=1';
151 '<a title="' . htmlspecialchars($person->name) . '"
153 $this->baseURL .'/User/'.
154 urlencode($person->id) .
155 (empty($opts['edit']) ? '' : '?edit=1') .
158 (isset($opts['class']) ? ' ' . $opts['class'] : '') .
161 $dispname = $person->name;
162 //$dispname = preg_match("/^([^+]*)(\+.*)?@(.*)$/", $target) ? $target : $person->id;
165 $size = empty($opts['size']) ? 24 : (int) $opts['size'];
168 (!empty($opts['no_image']) ? '' : ($open_a .
169 '<img class="gravatar"
170 width="' . $size . '" height="' . $size . '"
171 src="' . $this->baseURL . '/Avatar.png?u=' .
172 urlencode($person->id) . '&s='. $size . '">
175 // at this point the old code tries to chop it...
176 // I'm not sure that is a great idea....
177 (!empty($opts['no_name']) ? '' : ($open_a . htmlspecialchars($dispname) . '</a>'));
178 //var_dump( htmlspecialchars($ret));
182 function browse($target, $label)
184 return '<a href="'. $this->baseURL . '/Browse/'. htmlspecialchars($target) .'">'.
185 htmlspecialchars($label) .
188 function log($target, $label) // what does this do...
190 return '<a href="'. $this->baseURL . '/Log/'. htmlspecialchars($target) .'">'.
191 htmlspecialchars($label) .
195 function branch($branch, $repo = null)
197 return "<span class='branchname'>" . htmlspecialchars($branch) . "</span>";
203 function changeset($cs, $repo = null)
205 $display = substr($cs, 0, 12);
207 $repo = MTrack_Repo::loadByChangeSet($cs);
209 if (is_string($repo)) {
210 $repo = MTrack_Repo::loadByName($rep);
212 if (!is_a($repo, 'MTrack_Repo')) {
213 $repo = MTrack_Repo::defaultRepo();
215 $p = $repo->getBrowseRootName() . '/'. $cs;
218 return '<a class="changesetlink"
219 href="'. $this->baseURL . '/Changeset/'. htmlspecialchars($p) .'">[' . substr($cs, 0, 12) . ']</a>';
223 function wiki($pagename, $extras = array())
225 return htmlspecialchars($pagename);
226 if ($pagename instanceof MTrack_Wiki_Item) {
228 } else if (is_string($pagename)) {
229 $wiki = new MTrack_Wiki_Item($pagename);
234 // FIXME: hinted data from reports
235 throw new Exception("FIXME: wiki");
239 $pagename = $wiki->pagename;
241 $pagename .= empty( $extras['#']) ? '' : '#' . $extras['#'];
243 return '<a class="wikilink"
244 href="'.$this->baseURL . '/Wiki/'. htmlspecialchars($pagename) .'">'.
245 htmlspecialchars(empty($extras['display']) ? $pagename : $extras['display']) .
249 // all these are prtty much the same..
250 function query($target, $label)
253 return '<a href="'. $this->baseURL . '/Query/'. htmlspecialchars($target) .'">'.
254 htmlspecialchars($label) .
257 function report($target, $label)
259 return '<a href="'. $this->baseURL . '/Report/'. htmlspecialchars($target) .'">'.
260 htmlspecialchars($label) .
264 // technically not a link....
265 function date($tstring, $show_full = false)
267 /* database time is always relative to UTC */
268 $d = date_create($tstring, new DateTimeZone('UTC'));
269 if (!is_object($d)) {
270 throw new Exception("could not represent $tstring as a datetime object");
272 $iso8601 = $d->format(DateTime::W3C);
273 /* but we want to render relative to user prefs */
274 date_timezone_set($d, new DateTimeZone(date_default_timezone_get()));
275 $full = $d->format('D, M d Y H:i');
278 return "<abbr title=\"$iso8601\" class='timeinterval'>$full</abbr>";
281 return "<abbr title='$iso8601' class='timeinterval'>$full</abbr> <span class='fulldate'>$full</span>";