sync
[web.mtrack] / MTrackWeb / LinkHandler.php
index 1f618db..ec777ff 100644 (file)
@@ -6,10 +6,10 @@
  * it get's registered by MTrackWeb as the link handler..
  * 
  */
-require_once 'MTrack/Interface/WikiLinkHandler.php';
+//require_once 'MTrack/Interface/WikiLinkHandler.php';
 
 
-class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
+class MTrackWeb_LinkHandler  //implements MTrack_Interface_WikiLinkHandler
 {
     function MTrackWeb_LinkHandler()
     {
@@ -28,7 +28,7 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
     function ticket($no, $extras=array())
     {
         
-        if ($no instanceof MTrackIssue) {
+        if ($no instanceof DB_DataObject) {
             $tkt = $no;
         } else if (is_string($no) || is_int($no)) {
             static $cache = array();
@@ -38,10 +38,9 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
             }
 
             if (!isset($cache[$no])) {
-                $tkt = MTrackIssue::loadByNSIdent($no);
-                if (!$tkt) {
-                    $tkt = MTrackIssue::loadById($no);
-                }
+                $tkt  = DB_DataOBject::Factory('mtrack_ticket');
+                $tkt->get($no);
+                
                 $cache[$no] = $tkt;
             } else {
                 $tkt = $cache[$no];
@@ -49,7 +48,7 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
         } else {
             // FIXME: hinted data from reports
             $tkt = new stdClass;
-            $tkt->tid = $no['ticket'];
+            $tkt->id = $no['ticket'];
             $tkt->summary = $no['summary'];
             $tkt->status = '';
             
@@ -64,7 +63,7 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
         }
         if ($tkt == NULL) {
             $tkt = new stdClass;
-            $tkt->tid = $no;
+            $tkt->id = $no;
             $tkt->summary = 'No such ticket';
             $tkt->status = 'No such ticket';
         }
@@ -72,11 +71,9 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
         if ($tkt->status == 'closed') {
             $html .= ' completed';
         }
-        if (!empty($tkt->nsident)) {
-            $ident = $tkt->nsident;
-        } else {
-            $ident = $tkt->tid;
-        }
+        
+       $ident = $tkt->id;
+         
         if (isset($extras['#'])) {
             $anchor = '#' . $extras['#'];
         } else {
@@ -92,15 +89,24 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
         return $html;
     }
 
-    function milestone(  $target, $label)
+    function milestone(  $id, $label = '')
     {
         // silly but we assume target is urlencoded???...
-        $ms = MTrack_Milestone::loadByName($target);
+        $ms = DB_DataObjecT::factory('mtrack_milestone');
+        if (empty($label)) {
+            if (empty($id) || !$ms->get($id)) {
+                return '???';
+            }
+        } else {
+            $ms->id = $id;
+            $ms->name = $label;
+        }
+        
         
         return  '<span class="milestone' .
             (($ms->deleted || $ms->completed) ? ' completed' : '') .
-            '"><a href="'. $this->baseURL . '/Milestone/'. $target .'">'.
-                htmlspecialchars(urldecode($target))  . 
+            '"><a href="'. $this->baseURL . '/Milestone/'. $ms->id.'">'.
+                htmlspecialchars(urldecode($ms->name))  . 
             '</a></span>';
     }
     
@@ -118,18 +124,20 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
     function username($target, $opts=array())
     {
         if (is_object($target)) {
-            $userinfo  = $target;
-            $target = $userinfo->userid;
+            $person = $target;
+            $target = $person->id;
         } else {
-            $userinfo  = MTrack_DataObjects_Userinfo::findString($target);
+            $person  = DB_DataObject::factory('core_person');
+            $person->get($target);
         }
         
         if (is_string($opts)) {
             parse_str($opts, $opts);
         }
+        //print_r($opts);
         
-        //print_R($userinfo);
-        if (!$userinfo) {
+        //print_R($person);
+        if (!$person->id) {
             // we did not find the ysers...
             // we currently ignore all the formating....
             return '<a 
@@ -148,18 +156,18 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
         
         
         $open_a = 
-            '<a  title="' . htmlspecialchars($userinfo->fullname) . '" 
+            '<a  title="' . htmlspecialchars($person->name) . '" 
             href="' . 
                 $this->baseURL .'/User/'.
-                    urlencode($userinfo->userid)  . 
+                    urlencode($person->id)  . 
                     (empty($opts['edit']) ? '' : '?edit=1') .
             '" 
             class="userlink' . 
                 (isset($opts['class']) ? ' ' . $opts['class'] : '') .
             '">';
         
-        $dispname = $userinfo->fullname;
-        //$dispname = preg_match("/^([^+]*)(\+.*)?@(.*)$/", $target) ? $target : $userinfo->userid;
+        $dispname = $person->name;
+        //$dispname = preg_match("/^([^+]*)(\+.*)?@(.*)$/", $target) ? $target : $person->id;
         
         
         $size = empty($opts['size']) ? 24 : (int) $opts['size'];
@@ -169,7 +177,7 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
                 '<img class="gravatar"
                     width="' . $size . '" height="' . $size . '" 
                     src="' . $this->baseURL . '/Avatar.png?u=' . 
-                        urlencode($userinfo->userid) . '&amp;s='. $size . '">
+                        urlencode($person->id) . '&amp;s='. $size . '">
                 </a>')) .
             
             // at this point the old code tries to chop it...
@@ -222,7 +230,7 @@ class MTrackWeb_LinkHandler implements MTrack_Interface_WikiLinkHandler
         
     function wiki($pagename, $extras = array())
     {
-        
+        return htmlspecialchars($pagename);
         if ($pagename instanceof MTrack_Wiki_Item) {
             $wiki = $pagename;
         } else if (is_string($pagename)) {