MTrackWeb/Wiki.php
[web.mtrack] / MTrackWeb / Wiki.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4 /**
5  *  This is alot simpler now...
6  *
7  *  In our horrifically simple version...
8  *
9  *  We could just use a database, and go from there.
10  *  ... that looses the diff feature... although we can use the mtrack_change stuff....
11  *
12  *  ... That sounds alot better in our context as we can show data on the changelog..
13  *  -----> It will mean that the change log will have to honour our privacy settings..
14  *  
15  *  
16  *  oK - uses new mtrack_wiki table..
17  *
18  */
19
20
21 require_once 'MTrack/Attachment.php';
22 require_once 'MTrackWeb.php';
23
24 class MTrackWeb_Wiki extends MTrackWeb
25 {
26     
27     var $conflicted = 0;
28     var $message = false;
29     var $hasHistory = false;
30     
31     function getAuth()
32     {
33         return parent::getAuth();
34     }
35     
36     function get($pi='')
37     {
38         // non 'json' request...
39         if (!isset($_REQUEST['ajax_body'])) {
40             $this->title = "Browse: " . $pi;
41             return;
42         }
43         DB_DataObject::debugLevel(1);
44         $p = DB_DataObject::Factory('mtrack_wiki');
45         $p->project_id =  $this->currentProject();
46
47         $p->path = $pi;
48         if (!$p->find(true)) {
49             $this->returnNotFound($pi);
50         }
51         $this->jdata($p->toArray());
52  
53         //echo '<PRE>';print_r($this);echo '</PRE>';
54     }
55  
56  
57     function returnNotFound($pi) {
58         $this->jdata(array(
59             'id' => 0,
60             'path' => $pi,
61             'wikidata' => ''
62         
63         ));
64         
65         
66         
67     }
68  
69     function post()
70     {
71         
72         $p = DB_DataObject::factory('mtrack_wiki');
73         $p->project_id =  $this->currentProject();
74
75         if (empty($_REQUEST['id']) && !$p->get($_REQUEST['id'])) {
76             
77             $this->jerr('invalid id');
78         
79         }
80         $o = clone($p);
81         $this->setFrom($_POST);
82         if ($o->project_id != $p->project_id) {
83              $this->jerr("changing project id not permitted");
84         }
85         call_user_method($o->id ? 'update' : 'insert', $p, $o);
86         
87         $this->jok($p->toArray());
88         
89     }
90 }