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