diff --git a/controllers/d.wiki.php b/controllers/d.wiki.php index b2be1a2..c8e7cdc 100755 --- a/controllers/d.wiki.php +++ b/controllers/d.wiki.php @@ -6,18 +6,22 @@ $head['css'] = "d.index.css;d.wiki.css"; $wikiPage = new Kabano\WikiPage(); // Page doesn't exists -if(isset($controller->splitted_url[1]) && !$wikiPage->checkUrl($controller->splitted_url[1],$user->rankIsHigher('premium')) && $controller->splitted_url[1]!="") { +if(isset($controller->splitted_url[1]) && !$wikiPage->checkPermalink($controller->splitted_url[1],$user->rankIsHigher('premium')) && $controller->splitted_url[1]!="") { if($user->rankIsHigher('moderator')) { + $wikiPage->permalink = $controller->splitted_url[1]; // Create new page if(isset($_POST['submit'])) { $wikiPage->content = $_POST['content']; $wikiPage->locale = $_POST['locale']; - $wikiPage->title = $_POST['title']; + $wikiPage->name = $_POST['name']; $wikiPage->insert(); - header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->url); + header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink); } else { + $locales = new Kabano\Locales(); + $locales->getAll(); + $head['title'] = "Nouvelle page"; include ($config['views_folder']."d.wiki.edit.html"); } @@ -27,45 +31,40 @@ if(isset($controller->splitted_url[1]) && !$wikiPage->checkUrl($controller->spli } } // Page exists -else if(isset($controller->splitted_url[1]) && $wikiPage->checkUrl($controller->splitted_url[1],$user->rankIsHigher('premium'))) { - if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="edit" && $user->rankIsHigher('administrator')) { +else if(isset($controller->splitted_url[1]) && $wikiPage->checkPermalink($controller->splitted_url[1],$user->rankIsHigher('premium'))) { + $wikiPage->permalink = $controller->splitted_url[1]; + if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="edit" && $user->rankIsHigher('moderator')) { // Edit page if(isset($_POST['submit'])) { $wikiPage->content = $_POST['content']; $wikiPage->locale = $_POST['locale']; - $wikiPage->title = $_POST['title']; + $wikiPage->name = $_POST['name']; $wikiPage->update(); - header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->url); + header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink); } else { - $wikiPage->populate(); - $head['title'] = $wikiPage->title; + $locales = new Kabano\Locales(); + $locales->getAll(); + + $head['title'] = $wikiPage->name; include ($config['views_folder']."d.wiki.edit.html"); } } else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="delete" && $user->rankIsHigher('moderator')) { // Delete page $wikiPage->delete(); - header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->url); + header('Location: '.$config['rel_root_folder']."wiki/".$wikiPage->permalink); } else { // Display page if($user->rankIsHigher('premium')) { $wikiHistory = new Kabano\WikiPages(); $wikiHistory->getHistory($controller->splitted_url[1]); - - $i = 0; - foreach ($wikiHistory->ids as $row) { - $wikiHistory_list[$i] = new Kabano\WikiPage(); - $wikiHistory_list[$i]->id = $row; - $wikiHistory_list[$i]->populate(); - $i++; - } } if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2])) - $wikiPage->checkUrl($controller->splitted_url[1], $user->rankIsHigher('premium'), $controller->splitted_url[2]); + $wikiPage->checkPermalink($controller->splitted_url[1], $user->rankIsHigher('premium'), $controller->splitted_url[2]); $wikiPage->md2html(); - $head['title'] = $wikiPage->title; + $head['title'] = $wikiPage->name; include ($config['views_folder']."d.wiki.view.html"); } } diff --git a/models/d.locales.php b/models/d.locales.php index a570933..66840bd 100644 --- a/models/d.locales.php +++ b/models/d.locales.php @@ -12,7 +12,7 @@ namespace Kabano; class Locale { - private $name = 0; + public $name = 0; public $display_name = NULL; public $flag_name = NULL; @@ -52,13 +52,6 @@ class Locale $this->display_name = $row['display_name']; $this->flag_name = $row['flag_name']; } - - /***** - ** Simple return only functions - *****/ - public function get_name() { - return $this->name; - } } /********************************************************** diff --git a/models/d.users.php b/models/d.users.php index 6b85211..b03573d 100755 --- a/models/d.users.php +++ b/models/d.users.php @@ -218,7 +218,7 @@ class User or die ("Could not connect to server\n"); $query = "INSERT INTO users (name, version, email, password, website, is_avatar_present, is_archive, rank, locale, timezone, visit_date, register_date) VALUES - ($1, '0', $2, $3, $4, 'f', 'f', 'registered', $5, $6, $7, $8)"; + ($1, '0', $2, $3, $4, FALSE, FALSE, 'registered', $5, $6, $7, $8)"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); diff --git a/models/d.wiki.php b/models/d.wiki.php index d9c06c5..e59a33a 100755 --- a/models/d.wiki.php +++ b/models/d.wiki.php @@ -14,30 +14,30 @@ require_once($config['third_folder']."Md/MarkdownExtra.inc.php"); class WikiPage { - private $id = 0; - private $permalink = 0; - private $version = 0; - private $locale = NULL; - private $creation_date = NULL; - private $update_date = NULL; - private $author = NULL; - private $is_public = NULL; - private $is_archive = NULL; - private $is_commentable = NULL; - private $type = "wiki"; + public $id = 0; + public $permalink = 0; + public $version = 0; + public $locale = NULL; + public $creation_date = NULL; + public $update_date = NULL; + public $author = NULL; + public $is_public = NULL; + public $is_archive = NULL; + public $is_commentable = NULL; + public $type = "wiki"; public $name = NULL; public $content = NULL; /***** - ** Checks if a page at this URL exists and return the populated element + ** Checks if a page at this ermalink exists and return the populated element *****/ - public function checkUrl($url, $withArchive=0, $elementNb=0) { + public function checkPermalink($permalink, $withArchive=0, $elementNb=0) { global $config; $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 = "SELECT * FROM contents WHERE permalink=$1"; + $query = "SELECT * FROM contents WHERE permalink=$1 AND type='wiki'"; if($withArchive==0) { $query .= " AND is_archive=FALSE AND is_public=TRUE"; } @@ -45,7 +45,7 @@ class WikiPage pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare1", array($url, $elementNb)) + $result = pg_execute($con, "prepare1", array($permalink, $elementNb)) or die ("Cannot execute statement\n"); pg_close($con); @@ -63,7 +63,8 @@ class WikiPage /***** ** Populate the object using raw data from SQL *****/ - private function populate($row) { + public function populate($row) { + $this->id = $row['id']; $this->permalink = $row['permalink']; $this->version = $row['version']; $this->locale = $row['locale']; @@ -78,50 +79,38 @@ class WikiPage $this->content = $row['content']; } - /***** - ** Return archive status - *****/ - public function is_archive() { - return $this->is_archive; - } - - /***** - ** Return archive status - *****/ - public function update_date() { - return $this->update_date; - } - /***** ** Edit a page by archiving the current one and inserting a new one ID *****/ public function update() { global $config; - global $user; + //global $user; + $this->version++; + $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 wiki SET archive = TRUE WHERE url = $1"; + $query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='wiki'"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare1", array($this->url)) + $result = pg_execute($con, "prepare1", array($this->permalink)) or die ("Cannot execute statement\n"); - $query = "INSERT INTO wiki (url, title, content, lastedit, archive, locale) VALUES - ($1, $2, $3, $4, FALSE, $5)"; + $query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES + ($1, $2, $3, $4, $5, $6, TRUE, FALSE, FALSE, 'wiki', $7, $8)"; pg_prepare($con, "prepare2", $query) or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare2", array($this->url, $this->title, $this->content, date('r'), $this->locale)) + $result = pg_execute($con, "prepare2", array($this->permalink, $this->version, $this->locale, $this->creation_date, date('r'), $this->author, $this->name, $this->content)) or die ("Cannot execute statement\n"); pg_close($con); error_log( - date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit wiki page '".$this->url."'\r\n", + date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit wiki page '".$this->permalink."'\r\n", 3, $config['logs_folder'].'wiki.log'); } @@ -136,17 +125,17 @@ 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 wiki SET archive = TRUE WHERE url = $1"; + $query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='wiki'"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare1", array($this->url)) + $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 \tArchive wiki page '".$this->url."'\r\n", + date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive wiki page '".$this->permalink."'\r\n", 3, $config['logs_folder'].'wiki.log'); } @@ -161,18 +150,18 @@ 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 = "INSERT INTO wiki (url, title, content, lastedit, archive, locale) VALUES - ($1, $2, $3, $4, FALSE, $5)"; + $query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES + ($1, '0', $2, $3, $4, $5, TRUE, FALSE, FALSE, 'wiki', $6, $7)"; - pg_prepare($con, "prepare2", $query) + pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare2", array($this->url, $this->title, $this->content, date('r'), $this->locale)) + $result = pg_execute($con, "prepare1", array($this->permalink, $this->locale, date('r'), date('r'), $user->id, $this->name, $this->content)) or die ("Cannot execute statement\n"); pg_close($con); error_log( - date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new wiki page '".$this->url."'\r\n", + date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new wiki page '".$this->permalink."'\r\n", 3, $config['logs_folder'].'wiki.log'); } @@ -185,9 +174,17 @@ class WikiPage } } +/********************************************************** +*********************************************************** +** +** This class is to manage a wiki page object +** +*********************************************************** +**********************************************************/ + class WikiPages { - public $ids = array(); + public $objs = array(); public $number = NULL; /***** @@ -199,7 +196,7 @@ class WikiPages $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 = "SELECT id FROM wiki WHERE url=$1 ORDER BY lastedit DESC"; + $query = "SELECT * FROM contents WHERE permalink=$1 AND type='wiki' ORDER BY update_date DESC"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); @@ -212,7 +209,8 @@ class WikiPages for($i = 0; $i < $this->number; $i++) { $row = pg_fetch_assoc($result, $i); - $this->ids[$i] = $row['id']; + $this->objs[$i] = new WikiPage; + $this->objs[$i]->populate($row); } } } diff --git a/views/d.user.profile.edit.html b/views/d.user.profile.edit.html index 3c20063..4efa182 100755 --- a/views/d.user.profile.edit.html +++ b/views/d.user.profile.edit.html @@ -44,7 +44,7 @@
  • rankIsHigher("administrator")) { ?> diff --git a/views/d.wiki.edit.html b/views/d.wiki.edit.html index 6ec3716..462d8a0 100755 --- a/views/d.wiki.edit.html +++ b/views/d.wiki.edit.html @@ -8,14 +8,14 @@
    -
    +

    - +

    diff --git a/views/d.wiki.view.html b/views/d.wiki.view.html index 0fc1ba5..4ec9e10 100755 --- a/views/d.wiki.view.html +++ b/views/d.wiki.view.html @@ -7,27 +7,27 @@ -
    is_archive()?'class="archive"':''?>> +
    is_archive=="t"?'class="archive"':''?>>

    name?>.

    rankIsHigher('premium')) { ?> - + rankIsHigher('moderator') && isset($wikiHistory_list)) { ?> + if ($user->rankIsHigher('moderator') && isset($wikiHistory)) { ?> — rankIsHigher('moderator')) { ?> - Éditer la page - is_archive()) { ?> + Éditer la page + is_archive=="f") { ?> — - Effacer la page + Effacer la page @@ -37,7 +37,7 @@ content_html?> -

    Page mise à jour le update_date())) ?> UTC

    +

    Page mise à jour le update_date)) ?> UTC

    @@ -45,7 +45,7 @@ rankIsHigher('premium')) { ?>