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         $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               DB_DataObject::debugLevel(1);
94   
95         $au = $this->getAuthUser();
96         if (!$au) {
97             // autherr?
98             $this->jerr("permission denied");
99         }
100         
101         $p = DB_DataObject::factory('mtrack_wiki');
102         $p->project_id =  $this->currentProject();
103         
104         $id = empty($_REQUEST['id']) ? 0 : $_REQUEST['id'] * 1;
105         if (!empty($id) && !$p->get($id)) {
106             
107             $this->jerr('invalid id');
108         
109         }
110         $o = clone($p);
111         $p->setFrom($_POST);
112         if ($o->project_id != $p->project_id) {
113              $this->jerr("changing project id not permitted");
114         }
115         
116         // check change of path...
117         if (!$o->id || ($o->path != $p->path)) {
118             $c = DB_DataObject::factory('mtrack_wiki');
119             $c->project_id = $p->project_id;
120             $c->path = $p->path;
121             if ($c->count()) {
122                 $this->jerr("Path is not valid - that path already exists");
123             }
124         }
125         
126         
127         call_user_func(array($p, $o->id ? 'update' : 'insert'),  $o);
128         
129         $this->jok($p->toArray());
130         
131     }
132 }