First implementation of wiki
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user