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