Browse Source

First implementation of wiki

Léo Serre 10 months ago
parent
commit
2ff2d03b9c

+ 19
- 20
controllers/d.wiki.php View File

@@ -6,18 +6,22 @@ $head['css'] = "d.index.css;d.wiki.css";
6 6
 
7 7
 $wikiPage = new Kabano\WikiPage();
8 8
 // Page doesn't exists
9
-if(isset($controller->splitted_url[1]) && !$wikiPage->checkUrl($controller->splitted_url[1],$user->rankIsHigher('premium')) && $controller->splitted_url[1]!="") {
9
+if(isset($controller->splitted_url[1]) && !$wikiPage->checkPermalink($controller->splitted_url[1],$user->rankIsHigher('premium')) && $controller->splitted_url[1]!="") {
10 10
 	if($user->rankIsHigher('moderator')) {
11
+		$wikiPage->permalink = $controller->splitted_url[1];
11 12
 		// Create new page
12 13
 		if(isset($_POST['submit'])) {
13 14
 			$wikiPage->content = $_POST['content'];
14 15
 			$wikiPage->locale = $_POST['locale'];
15
-			$wikiPage->title = $_POST['title'];
16
+			$wikiPage->name = $_POST['name'];
16 17
 			$wikiPage->insert();
17 18
 
18
-			header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->url);
19
+			header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink);
19 20
 		}
20 21
 		else {
22
+			$locales = new Kabano\Locales();
23
+			$locales->getAll();
24
+
21 25
 			$head['title'] = "Nouvelle page";
22 26
 			include ($config['views_folder']."d.wiki.edit.html");
23 27
 		}
@@ -27,45 +31,40 @@ if(isset($controller->splitted_url[1]) && !$wikiPage->checkUrl($controller->spli
27 31
 	}
28 32
 }
29 33
 // Page exists
30
-else if(isset($controller->splitted_url[1]) && $wikiPage->checkUrl($controller->splitted_url[1],$user->rankIsHigher('premium'))) {
31
-	if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="edit" && $user->rankIsHigher('administrator')) {
34
+else if(isset($controller->splitted_url[1]) && $wikiPage->checkPermalink($controller->splitted_url[1],$user->rankIsHigher('premium'))) {
35
+	$wikiPage->permalink = $controller->splitted_url[1];
36
+	if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="edit" && $user->rankIsHigher('moderator')) {
32 37
 		// Edit page
33 38
 		if(isset($_POST['submit'])) {
34 39
 			$wikiPage->content = $_POST['content'];
35 40
 			$wikiPage->locale = $_POST['locale'];
36
-			$wikiPage->title = $_POST['title'];
41
+			$wikiPage->name = $_POST['name'];
37 42
 			$wikiPage->update();
38 43
 
39
-			header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->url);
44
+			header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink);
40 45
 		}
41 46
 		else {
42
-			$wikiPage->populate();
43
-			$head['title'] = $wikiPage->title;
47
+			$locales = new Kabano\Locales();
48
+			$locales->getAll();
49
+			
50
+			$head['title'] = $wikiPage->name;
44 51
 			include ($config['views_folder']."d.wiki.edit.html");
45 52
 		}
46 53
 	} else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="delete" && $user->rankIsHigher('moderator')) {
47 54
 		// Delete page
48 55
 		$wikiPage->delete();
49
-		header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->url);
56
+		header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink);
50 57
 	} else {
51 58
 		// Display page
52 59
 		if($user->rankIsHigher('premium')) {
53 60
 			$wikiHistory = new Kabano\WikiPages();
54 61
 			$wikiHistory->getHistory($controller->splitted_url[1]);
55
-
56
-			$i = 0;
57
-			foreach ($wikiHistory->ids as $row) {
58
-				$wikiHistory_list[$i] = new Kabano\WikiPage();
59
-				$wikiHistory_list[$i]->id = $row;
60
-				$wikiHistory_list[$i]->populate();
61
-				$i++;
62
-			}
63 62
 		}
64 63
 		if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2]))
65
-			$wikiPage->checkUrl($controller->splitted_url[1], $user->rankIsHigher('premium'), $controller->splitted_url[2]);
64
+			$wikiPage->checkPermalink($controller->splitted_url[1], $user->rankIsHigher('premium'), $controller->splitted_url[2]);
66 65
 
67 66
 		$wikiPage->md2html();
68
-		$head['title'] = $wikiPage->title;
67
+		$head['title'] = $wikiPage->name;
69 68
 		include ($config['views_folder']."d.wiki.view.html");
70 69
 	}
71 70
 }

+ 1
- 8
models/d.locales.php View File

@@ -12,7 +12,7 @@ namespace Kabano;
12 12
 
13 13
 class Locale
14 14
 {
15
-    private $name = 0;
15
+    public $name = 0;
16 16
     public $display_name = NULL;
17 17
     public $flag_name = NULL;
18 18
 
@@ -52,13 +52,6 @@ class Locale
52 52
 	    $this->display_name = $row['display_name'];
53 53
 	    $this->flag_name = $row['flag_name'];
54 54
 	}
55
-
56
-	/*****
57
-	** Simple return only functions
58
-	*****/
59
-	public function get_name() {
60
-	    return $this->name;
61
-	}
62 55
 }
63 56
 
64 57
 /**********************************************************

+ 1
- 1
models/d.users.php View File

@@ -218,7 +218,7 @@ class User
218 218
 			or die ("Could not connect to server\n");
219 219
 
220 220
 		$query = "INSERT INTO users (name, version, email, password, website, is_avatar_present, is_archive, rank, locale, timezone, visit_date, register_date) VALUES
221
-			($1, '0', $2, $3, $4, 'f', 'f', 'registered', $5, $6, $7, $8)";
221
+			($1, '0', $2, $3, $4, FALSE, FALSE, 'registered', $5, $6, $7, $8)";
222 222
 
223 223
 		pg_prepare($con, "prepare1", $query) 
224 224
 			or die ("Cannot prepare statement\n");

+ 46
- 48
models/d.wiki.php View File

@@ -14,30 +14,30 @@ require_once($config['third_folder']."Md/MarkdownExtra.inc.php");
14 14
 
15 15
 class WikiPage
16 16
 {
17
-	private $id = 0;
18
-	private $permalink = 0;
19
-	private $version = 0;
20
-	private $locale = NULL;
21
-	private $creation_date = NULL;
22
-	private $update_date = NULL;
23
-	private $author = NULL;
24
-	private $is_public = NULL;
25
-	private $is_archive = NULL;
26
-	private $is_commentable = NULL;
27
-	private $type = "wiki";
17
+	public $id = 0;
18
+	public $permalink = 0;
19
+	public $version = 0;
20
+	public $locale = NULL;
21
+	public $creation_date = NULL;
22
+	public $update_date = NULL;
23
+	public $author = NULL;
24
+	public $is_public = NULL;
25
+	public $is_archive = NULL;
26
+	public $is_commentable = NULL;
27
+	public $type = "wiki";
28 28
 	public $name = NULL;
29 29
 	public $content = NULL;
30 30
 
31 31
 	/*****
32
-	** Checks if a page at this URL exists and return the populated element
32
+	** Checks if a page at this ermalink exists and return the populated element
33 33
 	*****/
34
-	public function checkUrl($url, $withArchive=0, $elementNb=0) {
34
+	public function checkPermalink($permalink, $withArchive=0, $elementNb=0) {
35 35
 		global $config;
36 36
 		
37 37
 		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
38 38
 			or die ("Could not connect to server\n");
39 39
 
40
-		$query = "SELECT * FROM contents WHERE permalink=$1";
40
+		$query = "SELECT * FROM contents WHERE permalink=$1 AND type='wiki'";
41 41
 		if($withArchive==0) {
42 42
 			$query .= " AND is_archive=FALSE AND is_public=TRUE";
43 43
 		}
@@ -45,7 +45,7 @@ class WikiPage
45 45
 
46 46
 		pg_prepare($con, "prepare1", $query) 
47 47
 			or die ("Cannot prepare statement\n");
48
-		$result = pg_execute($con, "prepare1", array($url, $elementNb))
48
+		$result = pg_execute($con, "prepare1", array($permalink, $elementNb))
49 49
 			or die ("Cannot execute statement\n");
50 50
 
51 51
 		pg_close($con);
@@ -63,7 +63,8 @@ class WikiPage
63 63
 	/*****
64 64
 	** Populate the object using raw data from SQL
65 65
 	*****/
66
-	private function populate($row) {
66
+	public function populate($row) {
67
+		$this->id = $row['id'];
67 68
 		$this->permalink = $row['permalink'];
68 69
 		$this->version = $row['version'];
69 70
 		$this->locale = $row['locale'];
@@ -79,49 +80,37 @@ class WikiPage
79 80
 	}
80 81
 
81 82
 	/*****
82
-	** Return archive status
83
-	*****/
84
-	public function is_archive() {
85
-		return $this->is_archive;
86
-	}
87
-
88
-	/*****
89
-	** Return archive status
90
-	*****/
91
-	public function update_date() {
92
-		return $this->update_date;
93
-	}
94
-
95
-	/*****
96 83
 	** Edit a page by archiving the current one and inserting a new one ID
97 84
 	*****/
98 85
 	public function update() {
99 86
 		global $config;
100
-		global $user;
87
+		//global $user;
101 88
 		
89
+		$this->version++;
90
+
102 91
 		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
103 92
 			or die ("Could not connect to server\n");
104 93
 
105
-		$query = "UPDATE wiki SET archive = TRUE WHERE url = $1";
94
+		$query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='wiki'";
106 95
 
107 96
 		pg_prepare($con, "prepare1", $query) 
108 97
 			or die ("Cannot prepare statement\n");
109
-		$result = pg_execute($con, "prepare1", array($this->url))
98
+		$result = pg_execute($con, "prepare1", array($this->permalink))
110 99
 			or die ("Cannot execute statement\n");
111 100
 
112 101
 
113
-		$query = "INSERT INTO wiki (url, title, content, lastedit, archive, locale) VALUES
114
-			($1, $2, $3, $4, FALSE, $5)";
102
+		$query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES
103
+			($1, $2, $3, $4, $5, $6, TRUE, FALSE, FALSE, 'wiki', $7, $8)";
115 104
 
116 105
 		pg_prepare($con, "prepare2", $query) 
117 106
 			or die ("Cannot prepare statement\n");
118
-		$result = pg_execute($con, "prepare2", array($this->url, $this->title, $this->content, date('r'), $this->locale))
107
+		$result = pg_execute($con, "prepare2", array($this->permalink, $this->version, $this->locale, $this->creation_date, date('r'), $this->author, $this->name, $this->content))
119 108
 			or die ("Cannot execute statement\n");
120 109
 
121 110
 		pg_close($con);
122 111
 
123 112
 		error_log(
124
-			date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit wiki page '".$this->url."'\r\n",
113
+			date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit wiki page '".$this->permalink."'\r\n",
125 114
 			3,
126 115
 			$config['logs_folder'].'wiki.log');
127 116
 	}
@@ -136,17 +125,17 @@ class WikiPage
136 125
 		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
137 126
 			or die ("Could not connect to server\n");
138 127
 
139
-		$query = "UPDATE wiki SET archive = TRUE WHERE url = $1";
128
+		$query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='wiki'";
140 129
 
141 130
 		pg_prepare($con, "prepare1", $query) 
142 131
 			or die ("Cannot prepare statement\n");
143
-		$result = pg_execute($con, "prepare1", array($this->url))
132
+		$result = pg_execute($con, "prepare1", array($this->permalink))
144 133
 			or die ("Cannot execute statement\n");
145 134
 
146 135
 		pg_close($con);
147 136
 
148 137
 		error_log(
149
-			date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive wiki page '".$this->url."'\r\n",
138
+			date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive wiki page '".$this->permalink."'\r\n",
150 139
 			3,
151 140
 			$config['logs_folder'].'wiki.log');
152 141
 	}
@@ -161,18 +150,18 @@ class WikiPage
161 150
 		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
162 151
 			or die ("Could not connect to server\n");
163 152
 
164
-		$query = "INSERT INTO wiki (url, title, content, lastedit, archive, locale) VALUES
165
-			($1, $2, $3, $4, FALSE, $5)";
153
+		$query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES
154
+			($1, '0', $2, $3, $4, $5, TRUE, FALSE, FALSE, 'wiki', $6, $7)";
166 155
 
167
-		pg_prepare($con, "prepare2", $query) 
156
+		pg_prepare($con, "prepare1", $query) 
168 157
 			or die ("Cannot prepare statement\n");
169
-		$result = pg_execute($con, "prepare2", array($this->url, $this->title, $this->content, date('r'), $this->locale))
158
+		$result = pg_execute($con, "prepare1", array($this->permalink, $this->locale, date('r'), date('r'), $user->id, $this->name, $this->content))
170 159
 			or die ("Cannot execute statement\n");
171 160
 
172 161
 		pg_close($con);
173 162
 
174 163
 		error_log(
175
-			date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new wiki page '".$this->url."'\r\n",
164
+			date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new wiki page '".$this->permalink."'\r\n",
176 165
 			3,
177 166
 			$config['logs_folder'].'wiki.log');
178 167
 	}
@@ -185,9 +174,17 @@ class WikiPage
185 174
 	}
186 175
 }
187 176
 
177
+/**********************************************************
178
+***********************************************************
179
+**  
180
+**  This class is to manage a wiki page object
181
+**  
182
+***********************************************************
183
+**********************************************************/
184
+
188 185
 class WikiPages
189 186
 {
190
-	public $ids = array();
187
+	public $objs = array();
191 188
 	public $number = NULL;
192 189
 
193 190
 	/*****
@@ -199,7 +196,7 @@ class WikiPages
199 196
 		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
200 197
 			or die ("Could not connect to server\n");
201 198
 
202
-		$query = "SELECT id FROM wiki WHERE url=$1 ORDER BY lastedit DESC";
199
+		$query = "SELECT * FROM contents WHERE permalink=$1 AND type='wiki' ORDER BY update_date DESC";
203 200
 
204 201
 		pg_prepare($con, "prepare1", $query) 
205 202
 			or die ("Cannot prepare statement\n");
@@ -212,7 +209,8 @@ class WikiPages
212 209
 
213 210
 		for($i = 0; $i < $this->number; $i++) {
214 211
 			$row = pg_fetch_assoc($result, $i);
215
-			$this->ids[$i] = $row['id'];
212
+			$this->objs[$i] = new WikiPage;
213
+			$this->objs[$i]->populate($row);
216 214
 		}
217 215
 	}
218 216
 }

+ 1
- 1
views/d.user.profile.edit.html View File

@@ -44,7 +44,7 @@
44 44
 								<li><label for="locale">Langue :</label>
45 45
 									<select name="locale" id="locale">
46 46
 										<? foreach($locales->objs as $locale) { ?>
47
-											<option <?=$userProfile->get_locale()==$locale->display_name?'selected':''?> value="<?=$locale->get_name()?>"><?=$locale->display_name?></option>
47
+											<option <?=$userProfile->get_locale()==$locale->display_name?'selected':''?> value="<?=$locale->name?>"><?=$locale->display_name?></option>
48 48
 										<? } ?>
49 49
 									</select></li>
50 50
 								<? if($user->rankIsHigher("administrator")) { ?>

+ 4
- 4
views/d.wiki.edit.html View File

@@ -8,14 +8,14 @@
8 8
 		<? include('blocks/d.nav.html'); ?>
9 9
 
10 10
 		<section>
11
-			<form class="form" action="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->url?>/edit" method="post">
11
+			<form class="form" action="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/edit" method="post">
12 12
 				<h1>
13 13
 					<select name="locale" id="locale">
14
-						<? foreach($config['locales'] as $locale) { ?>
15
-							<option <?=$wikiPage->locale==$locale[0]?'selected':''?> value="<?=$locale[0]?>"><?=$locale[5]?></option>
14
+						<? foreach($locales->objs as $locale) { ?>
15
+							<option <?=$wikiPage->locale==$locale->name?'selected':''?> value="<?=$locale->name?>"><?=$locale->display_name?></option>
16 16
 						<? } ?>
17 17
 					</select>
18
-					<input type="text" value="<?=$wikiPage->title?>" name="title" id="title" placeholder="Titre">
18
+					<input type="text" value="<?=$wikiPage->name?>" name="name" id="name" placeholder="Titre">
19 19
 				</h1>
20 20
 
21 21
 				<textarea rows="30" name="content" id="content" placeholder="Contenu de la page"><?=$wikiPage->content?></textarea>

+ 10
- 10
views/d.wiki.view.html View File

@@ -7,27 +7,27 @@
7 7
 
8 8
 		<? include('blocks/d.nav.html'); ?>
9 9
 
10
-		<section id="wiki_page" <?=!$wikiPage->is_archive()?'class="archive"':''?>>
10
+		<section id="wiki_page" <?=$wikiPage->is_archive=="t"?'class="archive"':''?>>
11 11
 			<h1><?=$wikiPage->name?>.</h1>
12 12
 				<? if($user->rankIsHigher('premium')) { ?>
13 13
 					<span class="subtitle">
14
-					<? if(isset($wikiHistory_list)) { ?>
14
+					<? if(isset($wikiHistory)) { ?>
15 15
 						<select id="wikihistory">
16 16
 							<? $i = 0;
17
-							foreach ($wikiHistory_list as $row) { ?>
18
-								<option <?=$row->id==$wikiPage->id?'selected':''?> value="<?=$i?>"><?=$row->is_archive=="f"?'&bull; ':''?><? echo strftime('%d/%m/%Y %H:%M:%S',strtotime($row->lastedit)) ?></option>
17
+							foreach ($wikiHistory->objs as $row) { ?>
18
+								<option <?=$row->id==$wikiPage->id?'selected':''?> value="<?=$i?>"><?=$row->is_archive=="f"?'&bull; ':''?><? echo strftime('%d/%m/%Y %H:%M:%S',strtotime($row->update_date)) ?></option>
19 19
 							<? $i++;
20 20
 							} ?>
21 21
 						</select>
22 22
 					<? } 
23
-					if ($user->rankIsHigher('moderator') && isset($wikiHistory_list)) { ?>
23
+					if ($user->rankIsHigher('moderator') && isset($wikiHistory)) { ?>
24 24
 						 &mdash; 
25 25
 					<? }
26 26
 					if ($user->rankIsHigher('moderator')) { ?>
27
-						<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->url?>/edit"><i class="fa fa-pencil"></i> Éditer la page</a>
28
-						<? if (!$wikiPage->is_archive()) { ?>
27
+						<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/edit"><i class="fas fa-pencil-alt"></i> Éditer la page</a>
28
+						<? if ($wikiPage->is_archive=="f") { ?>
29 29
 							 &mdash; 
30
-							<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->url?>/delete"><i class="fa fa-trash"></i> Effacer la page</a>
30
+							<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/delete"><i class="fas fa-trash"></i> Effacer la page</a>
31 31
 						<? } ?>
32 32
 					<? } ?>
33 33
 					</span>
@@ -37,7 +37,7 @@
37 37
 				<?=$wikiPage->content_html?>
38 38
 			</div>
39 39
 
40
-			<p id="wikiTimestamp">Page mise à jour le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($wikiPage->update_date())) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
40
+			<p id="wikiTimestamp">Page mise à jour le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($wikiPage->update_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
41 41
 
42 42
 			<div style="clear: both;"> </div>
43 43
 		</section>
@@ -45,7 +45,7 @@
45 45
 <? if($user->rankIsHigher('premium')) { ?>
46 46
 		<script type="text/javascript">
47 47
 $( "#wikihistory" ).change(function() {
48
-  window.location.href = "<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->url?>/"+$( this ).val();
48
+  window.location.href = "<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/"+$( this ).val();
49 49
 });
50 50
 		</script>
51 51
 <? } ?>

Loading…
Cancel
Save