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