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 MTrackIssue) {
33 } else if (is_string($no) || is_int($no)) {
34 static $cache = array();
40 if (!isset($cache[$no])) {
41 $tkt = MTrackIssue::loadByNSIdent($no);
43 $tkt = MTrackIssue::loadById($no);
50 // FIXME: hinted data from reports
52 $tkt->tid = $no['ticket'];
53 $tkt->summary = $no['summary'];
56 if (isset($no['state'])) {
57 $tkt->status = $no['state'];
58 } elseif (isset($no['status'])) {
59 $tkt->status = $no['status'];
60 } elseif (isset($no['__status__'])) {
61 $tkt->status = $no['__status__'];
68 $tkt->summary = 'No such ticket';
69 $tkt->status = 'No such ticket';
71 $html = "<a class='ticketlink";
72 if ($tkt->status == 'closed') {
73 $html .= ' completed';
75 if (!empty($tkt->nsident)) {
76 $ident = $tkt->nsident;
80 if (isset($extras['#'])) {
81 $anchor = '#' . $extras['#'];
85 $html .= "' href=\"{$this->baseURL}/Ticket/$ident$anchor\">";
86 if (isset($extras['display'])) {
87 $html .= htmlspecialchars($extras['display']);
89 $html .= '#' . htmlspecialchars($ident);
95 function milestone( $target, $label)
97 // silly but we assume target is urlencoded???...
98 $ms = MTrack_Milestone::loadByName($target);
100 return '<span class="milestone' .
101 (($ms->deleted || $ms->completed) ? ' completed' : '') .
102 '"><a href="'. $this->baseURL . '/Milestone/'. $target .'">'.
103 htmlspecialchars(urldecode($target)) .
107 function help($target, $label, $anchor = '')
111 $target .= !empty($anchor) ? "#$anchor" : '';
113 return '<a class="wikilink"
114 href="'.$this->baseURL . '/Help/' . htmlspecialchars($target) .
115 '">' . htmlspecialchars($label) . '</a>';
118 function username($target, $opts=array())
120 if (is_object($target)) {
122 $target = $person->id;
124 $person = DB_DataObject::factory('Person');
125 $person->get($target);
128 if (is_string($opts)) {
129 parse_str($opts, $opts);
134 // we did not find the ysers...
135 // we currently ignore all the formating....
137 href="'. $this->baseURL .'/User/'. urlencode($target) . '" class="userlink">' .
138 htmlspecialchars($target).
142 if (!ctype_alnum($username)) {
143 $target = "{$ABSWEB}user.php?user=" . urlencode($username);
144 if (isset($opts['edit'])) {
145 $target .= '&edit=1';
152 '<a title="' . htmlspecialchars($person->name) . '"
154 $this->baseURL .'/User/'.
155 urlencode($person->id) .
156 (empty($opts['edit']) ? '' : '?edit=1') .
159 (isset($opts['class']) ? ' ' . $opts['class'] : '') .
162 $dispname = $person->name;
163 //$dispname = preg_match("/^([^+]*)(\+.*)?@(.*)$/", $target) ? $target : $person->id;
166 $size = empty($opts['size']) ? 24 : (int) $opts['size'];
169 (!empty($opts['no_image']) ? '' : ($open_a .
170 '<img class="gravatar"
171 width="' . $size . '" height="' . $size . '"
172 src="' . $this->baseURL . '/Avatar.png?u=' .
173 urlencode($person->id) . '&s='. $size . '">
176 // at this point the old code tries to chop it...
177 // I'm not sure that is a great idea....
178 (!empty($opts['no_name']) ? '' : ($open_a . htmlspecialchars($dispname) . '</a>'));
179 //var_dump( htmlspecialchars($ret));
183 function browse($target, $label)
185 return '<a href="'. $this->baseURL . '/Browse/'. htmlspecialchars($target) .'">'.
186 htmlspecialchars($label) .
189 function log($target, $label) // what does this do...
191 return '<a href="'. $this->baseURL . '/Log/'. htmlspecialchars($target) .'">'.
192 htmlspecialchars($label) .
196 function branch($branch, $repo = null)
198 return "<span class='branchname'>" . htmlspecialchars($branch) . "</span>";
204 function changeset($cs, $repo = null)
206 $display = substr($cs, 0, 12);
208 $repo = MTrack_Repo::loadByChangeSet($cs);
210 if (is_string($repo)) {
211 $repo = MTrack_Repo::loadByName($rep);
213 if (!is_a($repo, 'MTrack_Repo')) {
214 $repo = MTrack_Repo::defaultRepo();
216 $p = $repo->getBrowseRootName() . '/'. $cs;
219 return '<a class="changesetlink"
220 href="'. $this->baseURL . '/Changeset/'. htmlspecialchars($p) .'">[' . substr($cs, 0, 12) . ']</a>';
224 function wiki($pagename, $extras = array())
227 if ($pagename instanceof MTrack_Wiki_Item) {
229 } else if (is_string($pagename)) {
230 $wiki = new MTrack_Wiki_Item($pagename);
235 // FIXME: hinted data from reports
236 throw new Exception("FIXME: wiki");
240 $pagename = $wiki->pagename;
242 $pagename .= empty( $extras['#']) ? '' : '#' . $extras['#'];
244 return '<a class="wikilink"
245 href="'.$this->baseURL . '/Wiki/'. htmlspecialchars($pagename) .'">'.
246 htmlspecialchars(empty($extras['display']) ? $pagename : $extras['display']) .
250 // all these are prtty much the same..
251 function query($target, $label)
254 return '<a href="'. $this->baseURL . '/Query/'. htmlspecialchars($target) .'">'.
255 htmlspecialchars($label) .
258 function report($target, $label)
260 return '<a href="'. $this->baseURL . '/Report/'. htmlspecialchars($target) .'">'.
261 htmlspecialchars($label) .
265 // technically not a link....
266 function date($tstring, $show_full = false)
268 /* database time is always relative to UTC */
269 $d = date_create($tstring, new DateTimeZone('UTC'));
270 if (!is_object($d)) {
271 throw new Exception("could not represent $tstring as a datetime object");
273 $iso8601 = $d->format(DateTime::W3C);
274 /* but we want to render relative to user prefs */
275 date_timezone_set($d, new DateTimeZone(date_default_timezone_get()));
276 $full = $d->format('D, M d Y H:i');
279 return "<abbr title=\"$iso8601\" class='timeinterval'>$full</abbr>";
282 return "<abbr title='$iso8601' class='timeinterval'>$full</abbr> <span class='fulldate'>$full</span>";