Просмотр исходного кода

Add restore function in wiki

master
Léo Serre 1 год назад
Родитель
Сommit
ede83cec73
3 измененных файлов: 37 добавлений и 7 удалений
  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 Просмотреть файл

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

+ 27
- 2
models/d.wiki.php Просмотреть файл

@@ -125,7 +125,32 @@ class WikiPage
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");

$query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='wiki'";
$query = "UPDATE contents SET is_public=FALSE WHERE permalink=$1 AND type='wiki'";

pg_prepare($con, "prepare1", $query)
or die ("Cannot prepare statement\n");
$result = pg_execute($con, "prepare1", array($this->permalink))
or die ("Cannot execute statement\n");

pg_close($con);

error_log(
date('r')." \t".$user->name." (".$user->id.") \tDELETE \tUnpublish wiki page '".$this->permalink."'\r\n",
3,
$config['logs_folder'].'wiki.log');
}

/*****
** Restore a page from unpublishing it
*****/
public function restore() {
global $config;
global $user;
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");

$query = "UPDATE contents SET is_public=TRUE WHERE permalink=$1 AND type='wiki'";

pg_prepare($con, "prepare1", $query)
or die ("Cannot prepare statement\n");
@@ -135,7 +160,7 @@ class WikiPage
pg_close($con);

error_log(
date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive wiki page '".$this->permalink."'\r\n",
date('r')." \t".$user->name." (".$user->id.") \tRESTORE \tPublish wiki page '".$this->permalink."'\r\n",
3,
$config['logs_folder'].'wiki.log');
}

+ 6
- 5
views/d.wiki.view.html Просмотреть файл

@@ -7,7 +7,7 @@

<? include('blocks/d.nav.html'); ?>

<section id="wiki_page" <?=$wikiPage->is_archive=="t"?'class="archive"':''?>>
<section id="wiki_page" <?=$wikiPage->is_archive=="t"||$wikiPage->is_public=="f"?'class="archive"':''?>>
<h1><?=$wikiPage->name?>.</h1>
<? if($user->rankIsHigher('premium')) { ?>
<span class="subtitle">
@@ -24,11 +24,12 @@
&mdash;
<? }
if ($user->rankIsHigher('moderator')) { ?>
<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/edit"><i class="fas fa-pencil-alt"></i> Éditer la page</a>
<? if ($wikiPage->is_archive=="f") { ?>
&mdash;
<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/edit"><i class="fas fa-pencil-alt"></i> Éditer la page</a> &mdash;
<? if ($wikiPage->is_public=="t") { ?>
<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/delete"><i class="fas fa-trash"></i> Effacer la page</a>
<? } ?>
<? } else { ?>
<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/restore"><i class="fas fa-eye"></i> Restaurer la page</a>
<? }?>
<? } ?>
</span>
<? } ?>

Загрузка…
Отмена
Сохранить