Kaynağa Gözat

Add restore function in wiki

Léo Serre 9 ay önce
ebeveyn
işleme
ede83cec73
3 değiştirilmiş dosya ile 37 ekleme ve 7 silme
  1. 4
    0
      controllers/d.wiki.php
  2. 27
    2
      models/d.wiki.php
  3. 6
    5
      views/d.wiki.view.html

+ 4
- 0
controllers/d.wiki.php Dosyayı Görüntüle

@@ -54,6 +54,10 @@ else if(isset($controller->splitted_url[1]) && $wikiPage->checkPermalink($contro
54 54
 		// Delete page
55 55
 		$wikiPage->delete();
56 56
 		header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink);
57
+	} else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="restore" && $user->rankIsHigher('moderator')) {
58
+		// Restore page
59
+		$wikiPage->restore();
60
+		header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink);
57 61
 	} else {
58 62
 		// Display page
59 63
 		if($user->rankIsHigher('premium')) {

+ 27
- 2
models/d.wiki.php Dosyayı Görüntüle

@@ -125,7 +125,32 @@ class WikiPage
125 125
 		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
126 126
 			or die ("Could not connect to server\n");
127 127
 
128
-		$query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='wiki'";
128
+		$query = "UPDATE contents SET is_public=FALSE WHERE permalink=$1 AND type='wiki'";
129
+
130
+		pg_prepare($con, "prepare1", $query) 
131
+			or die ("Cannot prepare statement\n");
132
+		$result = pg_execute($con, "prepare1", array($this->permalink))
133
+			or die ("Cannot execute statement\n");
134
+
135
+		pg_close($con);
136
+
137
+		error_log(
138
+			date('r')." \t".$user->name." (".$user->id.") \tDELETE \tUnpublish wiki page '".$this->permalink."'\r\n",
139
+			3,
140
+			$config['logs_folder'].'wiki.log');
141
+	}
142
+
143
+	/*****
144
+	** Restore a page from unpublishing it
145
+	*****/
146
+	public function restore() {
147
+		global $config;
148
+		global $user;
149
+		
150
+		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
151
+			or die ("Could not connect to server\n");
152
+
153
+		$query = "UPDATE contents SET is_public=TRUE WHERE permalink=$1 AND type='wiki'";
129 154
 
130 155
 		pg_prepare($con, "prepare1", $query) 
131 156
 			or die ("Cannot prepare statement\n");
@@ -135,7 +160,7 @@ class WikiPage
135 160
 		pg_close($con);
136 161
 
137 162
 		error_log(
138
-			date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive wiki page '".$this->permalink."'\r\n",
163
+			date('r')." \t".$user->name." (".$user->id.") \tRESTORE \tPublish wiki page '".$this->permalink."'\r\n",
139 164
 			3,
140 165
 			$config['logs_folder'].'wiki.log');
141 166
 	}

+ 6
- 5
views/d.wiki.view.html Dosyayı Görüntüle

@@ -7,7 +7,7 @@
7 7
 
8 8
 		<? include('blocks/d.nav.html'); ?>
9 9
 
10
-		<section id="wiki_page" <?=$wikiPage->is_archive=="t"?'class="archive"':''?>>
10
+		<section id="wiki_page" <?=$wikiPage->is_archive=="t"||$wikiPage->is_public=="f"?'class="archive"':''?>>
11 11
 			<h1><?=$wikiPage->name?>.</h1>
12 12
 				<? if($user->rankIsHigher('premium')) { ?>
13 13
 					<span class="subtitle">
@@ -24,11 +24,12 @@
24 24
 						 &mdash; 
25 25
 					<? }
26 26
 					if ($user->rankIsHigher('moderator')) { ?>
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
-							 &mdash; 
27
+						<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/edit"><i class="fas fa-pencil-alt"></i> Éditer la page</a> &mdash; 
28
+						<? if ($wikiPage->is_public=="t") { ?>
30 29
 							<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/delete"><i class="fas fa-trash"></i> Effacer la page</a>
31
-						<? } ?>
30
+						<? } else { ?>
31
+							<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/restore"><i class="fas fa-eye"></i> Restaurer la page</a>
32
+						<? }?>
32 33
 					<? } ?>
33 34
 					</span>
34 35
 				<? } ?>

Loading…
İptal
Kaydet