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         DB_DataObject::debugLevel(1);
34         return parent::getAuth();
35     }
36     
37     function get($pi='')
38     {
39         // non 'json' request...
40         if (!isset($_REQUEST['ajax_body'])) {
41             $this->title = "Browse: " . $pi;
42             return;
43         }
44         
45         $p = DB_DataObject::Factory('Mtrack_wiki');
46         $p->project_id =  $this->currentProject();
47
48         $p->path = $pi;
49        
50         // we add stuff on the end..
51         if (empty($pi)) {
52             $px = DB_DataObject::Factory('Mtrack_wiki');
53             $px->project_id =  $this->currentProject();
54             $px->orderBy('path');
55             
56             $pr = DB_DataObject::factory('core_project');
57             $pr->get($px->project_id);
58             
59             $ar = $px->fetchAll('path');
60             $wikidata = "## Index of pages in Wiki - {$pr->name} \n\n";
61             foreach($ar as $pp) {
62                 $wikidata .= " * [$pp](wiki:$pp)\n";
63             }
64             $p->wikidata = $wikidata;
65             $this->jdata($p->toArray());
66             
67             
68             
69             
70         }
71         
72         //var_dump($p);
73         if (!$p->find(true)) {
74             $p->id = 0;
75             $this->jdata($p->toArray());
76         }
77         $this->jdata($p->toArray());
78  
79         //echo '<PRE>';print_r($this);echo '</PRE>';
80     }
81  
82  
83     function returnNotFound($p) {
84         
85         
86         
87         
88         
89     }
90  
91     function post()
92     {
93         
94         $au = $this->getAuthUser();
95         if (!$au) {
96             // autherr?
97             $this->jerr("permission denied");
98         }
99         
100         $p = DB_DataObject::factory('mtrack_wiki');
101         $p->project_id =  $this->currentProject();
102         
103         $id = empty($_REQUEST['id']) ? 0 : $_REQUEST['id'] * 1;
104         if (!empty($id) && !$p->get($id)) {
105             
106             $this->jerr('invalid id');
107         
108         }
109         $o = clone($p);
110         $p->setFrom($_POST);
111         if ($o->project_id != $p->project_id) {
112              $this->jerr("changing project id not permitted");
113         }
114         
115         // check change of path...
116         if (!$o->id || ($o->path != $p->path)) {
117             $c = DB_DataObject::factory('mtrack_wiki');
118             $c->project_id = $p->project_id;
119             $c->path = $p->path;
120             if ($c->count()) {
121                 $this->jerr("Path is not valid - that path already exists");
122             }
123         }
124         
125         
126         call_user_func(array($p, $o->id ? 'update' : 'insert'),  $o);
127         
128         $this->jok($p->toArray());
129         
130     }
131 }