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         
49         
50         //var_dump($p);
51         if (!$p->find(true)) {
52             $this->returnNotFound($pi);
53         }
54         $this->jdata($p->toArray());
55  
56         //echo '<PRE>';print_r($this);echo '</PRE>';
57     }
58  
59  
60     function returnNotFound($pi) {
61         $this->jdata(array(
62             'id' => 0,
63             'path' => $pi,
64             'wikidata' => ''
65         
66         ));
67         
68         
69         
70     }
71  
72     function post()
73     {
74         
75         $au = $this->getAuthUser();
76         if (!$au) {
77             // autherr?
78             $this->jerr("permission denied");
79         }
80         
81         $p = DB_DataObject::factory('mtrack_wiki');
82         $p->project_id =  $this->currentProject();
83
84         if (empty($_REQUEST['id']) && !$p->get($_REQUEST['id'])) {
85             
86             $this->jerr('invalid id');
87         
88         }
89         $o = clone($p);
90         $p->setFrom($_POST);
91         if ($o->project_id != $p->project_id) {
92              $this->jerr("changing project id not permitted");
93         }
94         
95         // check change of path...
96         if (!$o->id || ($o->path != $p->path)) {
97             $c = DB_DataObject::factory('mtrack_wiki');
98             $c->project_id = $p->project_id;
99             $c->path = $p->path;
100             if ($c->count()) {
101                 $this->jerr("Path is not valid");
102             }
103             
104         }
105         
106         
107         call_user_method($o->id ? 'update' : 'insert', $p, $o);
108         
109         $this->jok($p->toArray());
110         
111     }
112 }