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