From 1854075a62c6ca0422040b4e5ebf89088b0d02b2 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Tue, 15 Feb 2011 00:32:19 +0000 Subject: added wiki - part 1 --- .../Application/Controllers/BaseController.php | 8 +- .../Application/Controllers/GenericController.php | 21 +- .../Application/Controllers/UsersController.php | 32 +- .../Application/Controllers/WikiController.php | 475 +++++++++++++++++++++ h-source/Application/Include/languages.php | 18 + h-source/Application/Include/myFunctions.php | 48 ++- h-source/Application/Models/BaseModel.php | 69 --- h-source/Application/Models/GenericModel.php | 59 +++ h-source/Application/Models/HardwareModel.php | 2 +- h-source/Application/Models/NotebooksModel.php | 2 +- h-source/Application/Models/PrintersModel.php | 2 +- h-source/Application/Models/ScannersModel.php | 2 +- h-source/Application/Models/SoundcardsModel.php | 2 +- h-source/Application/Models/ThreegcardsModel.php | 2 +- h-source/Application/Models/VideocardsModel.php | 2 +- h-source/Application/Models/WebcamsModel.php | 2 +- h-source/Application/Models/WifiModel.php | 2 +- h-source/Application/Models/WikiModel.php | 228 ++++++++++ h-source/Application/Models/WikirevisionsModel.php | 45 ++ h-source/Application/Models/WikitalkModel.php | 50 +++ h-source/Application/Views/Issues/view.php | 2 +- h-source/Application/Views/Issues/viewall.php | 2 +- h-source/Application/Views/Wiki/climb.php | 50 +++ h-source/Application/Views/Wiki/differences.php | 61 +++ h-source/Application/Views/Wiki/form.php | 96 +++++ h-source/Application/Views/Wiki/history.php | 70 +++ h-source/Application/Views/Wiki/not_found.php | 34 ++ h-source/Application/Views/Wiki/page.php | 102 +++++ h-source/Application/Views/Wiki/talk.php | 122 ++++++ h-source/Application/Views/right.php | 6 +- h-source/Application/Views/talk.php | 4 +- h-source/Config/Route.php | 8 + h-source/Public/Css/main.css | 18 + h-source/tables.sql | 44 ++ 34 files changed, 1577 insertions(+), 113 deletions(-) create mode 100644 h-source/Application/Controllers/WikiController.php delete mode 100644 h-source/Application/Models/BaseModel.php create mode 100644 h-source/Application/Models/GenericModel.php create mode 100644 h-source/Application/Models/WikiModel.php create mode 100644 h-source/Application/Models/WikirevisionsModel.php create mode 100644 h-source/Application/Models/WikitalkModel.php create mode 100644 h-source/Application/Views/Wiki/climb.php create mode 100644 h-source/Application/Views/Wiki/differences.php create mode 100644 h-source/Application/Views/Wiki/form.php create mode 100644 h-source/Application/Views/Wiki/history.php create mode 100644 h-source/Application/Views/Wiki/not_found.php create mode 100644 h-source/Application/Views/Wiki/page.php create mode 100644 h-source/Application/Views/Wiki/talk.php diff --git a/h-source/Application/Controllers/BaseController.php b/h-source/Application/Controllers/BaseController.php index 7d03735..0f7c532 100644 --- a/h-source/Application/Controllers/BaseController.php +++ b/h-source/Application/Controllers/BaseController.php @@ -27,7 +27,7 @@ class BaseController extends Controller protected $ismoderator = false; protected $querySanitized = true; protected $token = 'token'; - + protected $_topMenuClasses = array( "home" => null, "hardware" => null, @@ -82,9 +82,11 @@ class BaseController extends Controller $data['tm'] = $this->_topMenuClasses; -// print_r($this->_queryString); $this->_queryString = $this->sanitizeQueryString($this->_queryString); - + + $data['querySanitized'] = $this->querySanitized; + $data['queryString'] = Url::createUrl($this->_queryString); + $this->append($data); } diff --git a/h-source/Application/Controllers/GenericController.php b/h-source/Application/Controllers/GenericController.php index 49685f3..884f915 100644 --- a/h-source/Application/Controllers/GenericController.php +++ b/h-source/Application/Controllers/GenericController.php @@ -117,7 +117,7 @@ class GenericController extends BaseController } else { - $this->redirect('users/login/'.$this->lang.'/'.$this->controller.'/catalogue',0); + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/catalogue/".$this->lang,0); } } @@ -252,7 +252,7 @@ class GenericController extends BaseController } else { - $this->redirect('users/login/'.$this->lang.'/'.$this->controller.'/view/'.$clean['id_hard'],0); + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/view/".$this->lang."/".$clean['id_hard'],0); } } else @@ -468,6 +468,7 @@ class GenericController extends BaseController $data['ne_name'] = null; $data['tree'] = null; $data['isDeleted'] = 'no'; + $data['title'] = 'revision - '.Website::$generalName; if (count($data['table']) > 0) { @@ -476,8 +477,6 @@ class GenericController extends BaseController $data['name'] = encodeUrl($data['ne_name']); $data['tree'] = $this->getSpecHardLink() . " » " . $this->getViewLink($data['id_hard'],$data['ne_name'])." » " . $this->getHistoryLink($data['id_hard']) . " » revision"; - $data['title'] = 'revision - '.Website::$generalName; - $data['updated_by'] = $data['table'][0]['revisions']['updated_by']; $data['update_date'] = $data['table'][0]['revisions']['update_date']; } @@ -611,7 +610,7 @@ class GenericController extends BaseController } else { - $this->redirect('users/login/'.$this->lang.'/'.$this->controller.'/view/'.$clean['id_hard'],0); + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/view/".$this->lang."/".$clean['id_hard'],0); } } } @@ -675,4 +674,16 @@ class GenericController extends BaseController return "controller.'/catalogue/'.$this->lang.$this->viewStatus."'>".$this->controller.""; } + protected function goToLoginForm() + { + if ($this->querySanitized) + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/".$this->action.Url::createUrl($this->_queryString)); + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=home/index".Url::createUrl($this->_queryString)); + } + } + } \ No newline at end of file diff --git a/h-source/Application/Controllers/UsersController.php b/h-source/Application/Controllers/UsersController.php index 1249647..7f42a2a 100644 --- a/h-source/Application/Controllers/UsersController.php +++ b/h-source/Application/Controllers/UsersController.php @@ -42,28 +42,20 @@ class UsersController extends BaseController $this->append($data); } - public function login($lang = 'en', $type = null,$the_action = null,$the_id = null) + public function login($lang = 'en') { $data = array(); if ( strcmp($this->_updating,'no') === 0 ) { $data['flag'] = isset($type) ? 'setted' : null; - $html['type'] = in_array($type,Hardware::$controllers) ? sanitizeAll($type) : 'notebooks'; - $html['the_action'] = sanitizeAlphanum($the_action); - $html['the_id'] = (int)$the_id; $html['lang'] = Lang::sanitize($lang); $data['title'] = 'Login - '.Website::$generalName; + + $redirect = $this->request->get('redirect','','sanitizeAll'); - if (isset($type)) - { - $data['action'] = Url::getRoot("users/login/".$html['lang']."/".$html['type']."/".$html['the_action']."/".$html['the_id']); - } - else - { - $data['action'] = Url::getRoot("users/login/".$html['lang']); - } + $data['action'] = Url::getRoot("users/login/".$this->lang."?redirect=$redirect"); $data['notice'] = null; @@ -82,11 +74,9 @@ class UsersController extends BaseController $this->redirect('home/index/'.Lang::$current,3,'You are already logged...'); break; case 'accepted': - if (isset($type)) + if (strcmp($redirect,'') !== 0) { - $address = strcmp($html['the_action'],'view') === 0 ? $html['type']."/view/".$html['lang']."/".$html['the_id'] : $html['type']."/catalogue/".$html['lang']; - - $this->redirect($address,0); + $this->redirect($redirect,0); } else { @@ -117,7 +107,15 @@ class UsersController extends BaseController } else if ($res === 'was-logged') { - $this->redirect('home/index/'.Lang::$current,0); + $redirect = $this->request->get('redirect','','sanitizeAll'); + if (strcmp($redirect,'') !== 0) + { + $this->redirect($redirect,0); + } + else + { + $this->redirect('home/index/'.Lang::$current,0); + } } else if ($res === 'error') { diff --git a/h-source/Application/Controllers/WikiController.php b/h-source/Application/Controllers/WikiController.php new file mode 100644 index 0000000..33647ef --- /dev/null +++ b/h-source/Application/Controllers/WikiController.php @@ -0,0 +1,475 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class WikiController extends BaseController +{ + + public function __construct($model, $controller, $queryString) { + parent::__construct($model, $controller, $queryString); + + $this->model('UsersModel'); + $this->model('WikiModel'); + $this->model('WikirevisionsModel'); + $this->model('WikitalkModel'); + + $this->m['WikiModel']->id_user = (int)$this->s['registered']->status['id_user']; + } + + public function insert($lang = 'en') + { + $this->shift(1); + + $data['title'] = 'insert a wiki page - '.Website::$generalName; + + $this->m['WikiModel']->setFields('title,page','sanitizeAll'); + + $data['notice'] = null; + + $this->s['registered']->checkStatus(); + + if ($this->s['registered']->status['status'] === 'logged') + { + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + if (isset($_POST['insertAction'])) + { + //insert the new wiki page + $this->m['WikiModel']->updateTable('insert'); + + $this->viewRedirect($this->m['WikiModel']->lastTitleClean); + } + + $data['notice'] = $this->m['WikiModel']->notice; + + $data['submitName'] = "insertAction"; + $data['hiddenInput'] = null; + + $data['values'] = $this->m['WikiModel']->getFormValues('insert','sanitizeHtml'); + $this->append($data); + + $this->load('form'); + $this->load('bottom_left'); + $this->right(); + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/insert/".$this->lang,0); + } + } + + public function update($lang = 'en') + { + $this->shift(1); + + $data['title'] = 'update a wiki page - '.Website::$generalName; + + $this->m['WikiModel']->setFields('title,page','sanitizeAll'); + + $data['notice'] = null; + $this->s['registered']->checkStatus(); + + if (isset($_POST['id_wiki'])) + { + //get the id + $clean['id_wiki'] = (int)$_POST['id_wiki']; + $title = $this->m['WikiModel']->getTheModelName($clean['id_wiki']); + + if ($this->s['registered']->status['status'] === 'logged') + { + + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + $deleted = $this->m['WikiModel']->select("wiki.deleted")->where(array("id_wiki"=>$clean['id_wiki']))->limit(1)->toList('wiki.deleted')->send(); + + if (strcmp($deleted[0],'no') === 0) + { + $data['tree_name'] = $title; + + if (isset($_POST['updateAction'])) + { + //carry out the update database action + $this->m['WikiModel']->updateTable('update'); + + $this->viewRedirect($this->m['WikiModel']->lastTitleClean); + } + + $data['notice'] = $this->m['WikiModel']->notice; + + $data['id_wiki'] = $clean['id_wiki']; + $data['submitName'] = "updateAction"; + + $data['values'] = $this->m['WikiModel']->getFormValues('update','sanitizeHtml'); + $data['hiddenInput'] = "\n"; + + $this->append($data); + + $this->load('form'); + $this->load('bottom_left'); + $this->right(); + } + else + { + $this->redirect($this->controller.'/page/'.$this->lang,2,'deleted..'); + } + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/page/".$this->lang."/".encodeUrl($title),0); + } + } + else + { + $this->redirect($this->controller.'/page/'.$this->lang); + } + } + + protected function viewRedirect($titleClean) + { + if ($this->m['WikiModel']->queryResult) + { + $this->redirect($this->controller.'/page/'.$this->lang.'/'.$titleClean); + } + } + + public function page($lang = 'en', $title_clean = null) + { + $this->shift(2); + + $data['title'] = 'main page - '.Website::$generalName; + $clean['title_clean'] = sanitizeAll($title_clean); + + $data['isDeleted'] = 'no'; + + $res = $this->m['WikiModel']->select()->where(array('title_clean'=>$clean['title_clean']))->send(); + + if ( count($res) > 0 ) + { + $data['table'] = $res; + $data['tree_name'] = $res[0]['wiki']['title']; + $data['title'] = $res[0]['wiki']['title'] . ' - ' . Website::$generalName; + $data['isDeleted'] = $res[0]['wiki']['deleted']; + + if ( count($res) < 2 ) + { + $data['talk_number'] = $this->m['WikitalkModel']->select('count(*) as numb,id_wiki')->where(array('id_wiki'=>$res[0]['wiki']['id_wiki'],'deleted'=>'no'))->rowNumber(); + + $viewFile = 'page'; + $data['id_wiki'] = $res[0]['wiki']['id_wiki']; + } + else + { + $viewFile = 'select'; + } + } + else + { + $viewFile = 'not_found'; + } + + $this->append($data); + + $this->load($viewFile); + $this->load('bottom_left'); + $this->right(); + } + + public function history($lang = 'en', $id = 0) + { + $argKeys = array( + 'page:forceNat' => 1, + ); + + $this->setArgKeys($argKeys); + $this->shift(2); + + $clean['id'] = (int)$id; + $data['id'] = $clean['id']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($clean['id']); + + $data['title'] = 'history - '.Website::$generalName; + + //get the first revision + $res = $this->m['WikirevisionsModel']->db->select('revisions','id_rev','id_wiki='.$clean['id'],null,'id_rev',1); + if (count($res) > 0) + { + $data['firstRev'] = $res[0]['wiki_revisions']['id_rev']; + } + + $res1 = $this->m['WikiModel']->db->select('wiki','update_date,created_by','id_wiki='.$clean['id']); + + $this->m['WikirevisionsModel']->setWhereQueryClause(array('id_wiki' => $clean['id'])); + + //load the Pages helper + $this->helper('Pages',$this->controller.'/history/'.$this->lang.'/'.$clean['id'],'page'); + //get the number of records + $recordNumber = $this->m['WikirevisionsModel']->rowNumber(); + $page = $this->viewArgs['page']; + //set the limit clause + $this->m['WikirevisionsModel']->limit = $this->h['Pages']->getLimit($page,$recordNumber,20); + $res2 = $this->m['WikirevisionsModel']->getFields('update_date,created_by,id_rev'); + + $data['pageList'] = $this->h['Pages']->render($page-3,7); + + $data['rev1'] = $res1; + $data['rev2'] = $res2; + + $this->append($data); + $this->load('history'); + $this->load('bottom_left'); + $this->right(); + } + + public function revision($lang = 'en', $id_rev = 0) + { + $argKeys = array( + 'page:forceNat' => 1, + ); + + $this->setArgKeys($argKeys); + $this->shift(2); + + $clean['id_rev'] = (int)$id_rev; + + $this->m['WikirevisionsModel']->setWhereQueryClause(array("id_rev" => $clean['id_rev'])); + $data['table'] = $this->m['WikirevisionsModel']->getAll(); + + $data['id_wiki'] = 0; + $data['created_by'] = null; + $data['update_date'] = null; + $data['tree_name'] = null; + $data['tree'] = null; + $data['tree'] = null; + $data['title'] = 'revision - '.Website::$generalName; + $data['isDeleted'] = 'no'; + + if (count($data['table']) > 0) + { + $data['id_wiki'] = (int)$data['table'][0]['wiki_revisions']['id_wiki']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($data['id_wiki']); + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » " . $this->getHistoryLink($data['id_wiki']) . " » ".gtext('Revision'); + + $data['created_by'] = $data['table'][0]['wiki_revisions']['created_by']; + $data['update_date'] = $data['table'][0]['wiki_revisions']['update_date']; + } + + $this->append($data); + $this->load('page'); + $this->load('bottom_left'); + $this->right(); + } + + public function differences($lang = 'en', $id_wiki = 0, $id_rev = 0) + { + $this->shift(3); + + $data['title'] = 'differences - '.Website::$generalName; + + $clean['id_wiki'] = (int)$id_wiki; + $clean['id_rev'] = (int)$id_rev; + + $data['id_wiki'] = $clean['id_wiki']; + $tree_name = $this->m['WikiModel']->getTheModelName((int)$data['id_wiki']); + $data['tree_name'] = $tree_name; + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » " . $this->getHistoryLink($data['id_wiki']) . " » ".gtext('Differences'); + + $data['showDiff'] = false; + + $diffArray = array(); + + if (strcmp($clean['id_wiki'],0) !== 0 and strcmp($clean['id_rev'],0) !== 0) + { + $this->m['WikirevisionsModel']->where(array('id_wiki' => $clean['id_wiki'],'id_rev' => '<='.$clean['id_rev'])); + $this->m['WikirevisionsModel']->limit = 2; + $res = $this->m['WikirevisionsModel']->getAll(); + if (count($res) > 1) + { + $newArray = $res[0]['wiki_revisions']; + $oldArray = $res[1]['wiki_revisions']; + + $data['update_new'] = $newArray['update_date']; + $data['update_old'] = $oldArray['update_date']; + $data['created_by'] = $newArray['created_by']; + + $diffArray = $this->m['WikiModel']->getDiffArray($oldArray, $newArray); + + $data['showDiff'] = true; + } + } + else if (strcmp($clean['id_wiki'],0) !== 0 and strcmp($clean['id_rev'],0) === 0) + { + $this->m['WikiModel']->where(array('id_wiki' => $clean['id_wiki'])); + $lastRes = $this->m['WikiModel']->getAll(); + + if (count($lastRes) > 0) + { + $this->m['WikirevisionsModel']->setWhereQueryClause(array('id_wiki' => $clean['id_wiki'])); + $this->m['WikirevisionsModel']->limit = 1; + $revRes = $this->m['WikirevisionsModel']->getAll(); + + if (count($revRes) > 0) + { + $newArray = $lastRes[0]['wiki']; + $oldArray = $revRes[0]['wiki_revisions']; + + $data['update_new'] = $newArray['update_date']; + $data['update_old'] = $oldArray['update_date']; + $data['created_by'] = $newArray['created_by']; + + $diffArray = $this->m['WikiModel']->getDiffArray($oldArray, $newArray); + + $data['showDiff'] = true; + } + } + + } + + $data['fieldsWithBreaks'] = $this->m['WikiModel']->fieldsWithBreaks; + $data['diffArray'] = $diffArray; + + $this->append($data); + $this->load('differences'); + $this->load('bottom_left'); + $this->right(); + } + + public function climb($lang = 'en', $id_rev = 0) + { + $this->shift(2); + + $this->m['WikiModel']->setFields('title,page','sanitizeAll'); + + $data['title'] = 'make current - '.Website::$generalName; + + $clean['id_rev'] = (int)$id_rev; + $clean['id_wiki'] = (int)$this->m['WikirevisionsModel']->getIdPage($clean['id_rev']); + + if ($clean['id_wiki'] !== 0) + { + $deleted = $this->m['WikiModel']->select("wiki.deleted")->where(array("id_wiki"=>$clean['id_wiki']))->limit(1)->toList('wiki.deleted')->send(); + + $data['isDeleted'] = $deleted[0]; + + $data['id_rev'] = $clean['id_rev']; + $data['id_wiki'] = $clean['id_wiki']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($clean['id_wiki']); + $data['name'] = $data['tree_name']; + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » " . $this->getHistoryLink($clean['id_wiki']) . " » " . gtext('Make current'); + + $data['notice'] = null; + $this->s['registered']->checkStatus(); + + if ($this->s['registered']->status['status'] === 'logged') + { + + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + if (isset($_POST['confirmAction'])) + { + if (strcmp($deleted[0],'no') === 0) + { + $this->m['WikiModel']->makeCurrent($clean['id_rev']); + + $this->viewRedirect($this->m['WikiModel']->lastTitleClean); + + $data['notice'] = $this->m['WikiModel']->notice; + } + else + { + $this->redirect($this->controller.'/page/'.$this->lang,2,'deleted..'); + } + } + + $this->append($data); + $this->load('climb'); + $this->load('bottom_left'); + $this->right(); + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/page/".$this->lang."/".encodeUrl($data['tree_name']),0); + } + } + } + + public function talk($lang = 'en', $id_wiki = 0) + { + $this->shift(2); + + $this->m['WikitalkModel']->setFields('title,message','sanitizeAll'); + + $data['title'] = 'talk - '.Website::$generalName; + + $clean['id_wiki'] = (int)$id_wiki; + $data['id_wiki'] = $clean['id_wiki']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($clean['id_wiki']); + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » ".gtext('Talk'); + + if (isset($_POST['insertAction'])) + { + if ($this->s['registered']->status['status'] === 'logged') + { + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + $this->m['WikitalkModel']->values['created_by'] = $this->s['registered']->status['id_user']; + $this->m['WikitalkModel']->values['id_wiki'] = $clean['id_wiki']; + + $this->m['WikitalkModel']->updateTable('insert'); + + if ($this->m['WikitalkModel']->queryResult) + { + header('Refresh: 0;url=http://'.DOMAIN_NAME.$_SERVER['REQUEST_URI']); + exit; + } + } + } + + $data['table'] = $this->m['WikitalkModel']->select()->where(array('id_wiki'=>$clean['id_wiki']))->orderBy('id_talk')->send(); + + $data['values'] = $this->m['WikitalkModel']->getFormValues('insert','sanitizeHtml'); + $data['notice'] = $this->m['WikitalkModel']->notice; + +// javascript for moderator +// $data['md_javascript'] = "moderator_dialog(\"hide\",\"talk\");moderator_dialog(\"show\",\"talk\");"; +// $data['go_to'] = $this->currPage."/".$this->lang."/".$clean['id_wiki']; + + $this->append($data); + $this->load('talk'); + $this->right(); +// $this->loadViewAll('talk,moderator_dialog'); + } + + protected function getViewLink($ne_name) + { + return "controller.'/page/'.$this->lang.'/'.encodeUrl($ne_name)."'>".$ne_name.""; + } + + protected function getHistoryLink($id) + { + return "controller.'/history/'.$this->lang.'/'.$id."'>".gtext('History').""; + } + + protected function getSpecPageLink() + { + return "controller.'/page/'.$this->lang."'>".$this->controller.""; + } + +} \ No newline at end of file diff --git a/h-source/Application/Include/languages.php b/h-source/Application/Include/languages.php index 9b0d9ab..4bfb7fe 100644 --- a/h-source/Application/Include/languages.php +++ b/h-source/Application/Include/languages.php @@ -175,6 +175,24 @@ class Lang "at" => "alle ore", "last modifications" => "ultime modifiche", "watch all modifications" => "guarda tutte le modifiche", + "title" => "titolo", + "text of the wiki page" => "testo della pagina", + "the wiki page has not been found" => "la pagina della wiki non è stata trovata", + "Page not-found" => "Pagina non trovata", + "Insert" => "Inserisci", + "Update" => "Modifica", + "History" => "History", + "Revision" => "Revisione", + "Differences" => "Differenze", + "Insert a new wiki page" => "Inserisci una nuova pagina nella wiki", + "Edit the wiki page" => "Modifica la pagina della wiki", + "Make current" => "Rendi revisione corrente", + "I want to make this revision the current revision" => "Voglio che questa revisione diventi quella corrente", + "Confirm" => "Conferma", + "Make this revision the current revision of the page" => "Rendi questa revisione la revisione corrente della pagina", + "This wiki page has been hidden" => "Questa pagina della wiki è stata nascosta", + "Talk" => "Discussione", + "Talk page of the wiki page" => "Pagina di discussione della pagina della wiki" ), 'es' => array ( diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index daefb59..0f87893 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -29,12 +29,39 @@ function encodeUrl($url) $url = str_replace(')','-',$url); $url = str_replace('/','-',$url); $url = str_replace('@','-at-',$url); - $url = urlencode($url); -// $url = html_entity_decode($url, ENT_QUOTES); -// $url = xml_encode($url); - return $url; + + $temp = null; + for ($i=0;$i$urlView,'urlTalk'=>$urlTalk,'modelName'=>$deviceName); +} + +function getDiffArray($associativeArray, $oldArray, $newArray) +{ + $diffArray = array(); + foreach ($associativeArray as $field => $label) + { + if (array_key_exists($field,$oldArray) and array_key_exists($field,$newArray)) + { + $diffArray[$label] = htmlDiff($oldArray[$field], $newArray[$field]); + } + } + return $diffArray; } \ No newline at end of file diff --git a/h-source/Application/Models/BaseModel.php b/h-source/Application/Models/BaseModel.php deleted file mode 100644 index ce613c5..0000000 --- a/h-source/Application/Models/BaseModel.php +++ /dev/null @@ -1,69 +0,0 @@ -. - -if (!defined('EG')) die('Direct access not allowed!'); - -class BaseModel extends Model_Tree { - - public $type = ''; //device type - public $diffFields = array(); - public $fieldsWithBreaks = array(); - - public function __construct() { - $this->_tables = 'hardware'; - $this->_idFields = 'id_hard'; - - $this->_where=array( - 'type' => 'hardware', - 'vendor' => 'hardware', - 'compatibility' => 'hardware', - 'comm_year' => 'hardware', - ); - - $this->orderBy = 'hardware.id_hard desc'; - parent::__construct(); - } - - public function checkType($id_hard = 0) - { - $clean['id_hard'] = (int)$id_hard; - $res = $this->db->select('hardware','type','id_hard='.$clean['id_hard']); - if (count($res) > 0) - { - return (strcmp($this->type,$res[0]['hardware']['type']) === 0 ) ? true : false; - } - return false; - } - - public function getDiffArray($oldArray, $newArray) - { - $diffArray = array(); - foreach ($this->diffFields as $field => $label) - { - if (array_key_exists($field,$oldArray) and array_key_exists($field,$newArray)) - { -// echo htmlDiff($oldArray[$field], $newArray[$field]); -// echo $oldArray[$field].$newArray[$field]; - $diffArray[$label] = htmlDiff($oldArray[$field], $newArray[$field]); - } - } - return $diffArray; - } -} \ No newline at end of file diff --git a/h-source/Application/Models/GenericModel.php b/h-source/Application/Models/GenericModel.php new file mode 100644 index 0000000..0ccd332 --- /dev/null +++ b/h-source/Application/Models/GenericModel.php @@ -0,0 +1,59 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class GenericModel extends Model_Tree { + + public $type = ''; //device type + public $diffFields = array(); + public $fieldsWithBreaks = array(); + + public function __construct() { + $this->_tables = 'hardware'; + $this->_idFields = 'id_hard'; + + $this->_where=array( + 'type' => 'hardware', + 'vendor' => 'hardware', + 'compatibility' => 'hardware', + 'comm_year' => 'hardware', + ); + + $this->orderBy = 'hardware.id_hard desc'; + parent::__construct(); + } + + public function checkType($id_hard = 0) + { + $clean['id_hard'] = (int)$id_hard; + $res = $this->db->select('hardware','type','id_hard='.$clean['id_hard']); + if (count($res) > 0) + { + return (strcmp($this->type,$res[0]['hardware']['type']) === 0 ) ? true : false; + } + return false; + } + + public function getDiffArray($oldArray, $newArray) + { + return getDiffArray($this->diffFields, $oldArray, $newArray); + } +} \ No newline at end of file diff --git a/h-source/Application/Models/HardwareModel.php b/h-source/Application/Models/HardwareModel.php index 10f899e..17565ff 100644 --- a/h-source/Application/Models/HardwareModel.php +++ b/h-source/Application/Models/HardwareModel.php @@ -157,7 +157,7 @@ class HardwareModel extends Model_Map { { //get the values of the revision $revisions->setWhereQueryClause(array('id_rev'=>$clean['id_rev'])); - $newStruct = $revisions->getFields($this->fields.',created_by,updated_by,update_date,type,id_hard'); + $newStruct = $revisions->getFields($this->fields.',created_by,updated_by,update_date,type'); if (count($newStruct > 0)) { diff --git a/h-source/Application/Models/NotebooksModel.php b/h-source/Application/Models/NotebooksModel.php index a8fcdf2..c8d5993 100644 --- a/h-source/Application/Models/NotebooksModel.php +++ b/h-source/Application/Models/NotebooksModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class NotebooksModel extends BaseModel { +class NotebooksModel extends GenericModel { public $type = 'notebook'; //device type diff --git a/h-source/Application/Models/PrintersModel.php b/h-source/Application/Models/PrintersModel.php index af86980..f69d543 100644 --- a/h-source/Application/Models/PrintersModel.php +++ b/h-source/Application/Models/PrintersModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class PrintersModel extends BaseModel +class PrintersModel extends GenericModel { public $type = 'printer'; //device type diff --git a/h-source/Application/Models/ScannersModel.php b/h-source/Application/Models/ScannersModel.php index 87807b3..f30b505 100644 --- a/h-source/Application/Models/ScannersModel.php +++ b/h-source/Application/Models/ScannersModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class ScannersModel extends BaseModel +class ScannersModel extends GenericModel { public $type = 'scanner'; //device type diff --git a/h-source/Application/Models/SoundcardsModel.php b/h-source/Application/Models/SoundcardsModel.php index cea12be..f872427 100644 --- a/h-source/Application/Models/SoundcardsModel.php +++ b/h-source/Application/Models/SoundcardsModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class SoundcardsModel extends BaseModel +class SoundcardsModel extends GenericModel { public $type = 'soundcard'; //device type diff --git a/h-source/Application/Models/ThreegcardsModel.php b/h-source/Application/Models/ThreegcardsModel.php index 85dcd3e..6bde5c8 100644 --- a/h-source/Application/Models/ThreegcardsModel.php +++ b/h-source/Application/Models/ThreegcardsModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class ThreegcardsModel extends BaseModel +class ThreegcardsModel extends GenericModel { public $type = '3G-card'; //device type diff --git a/h-source/Application/Models/VideocardsModel.php b/h-source/Application/Models/VideocardsModel.php index bfcaa25..472931e 100644 --- a/h-source/Application/Models/VideocardsModel.php +++ b/h-source/Application/Models/VideocardsModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class VideocardsModel extends BaseModel +class VideocardsModel extends GenericModel { public $type = 'videocard'; //device type diff --git a/h-source/Application/Models/WebcamsModel.php b/h-source/Application/Models/WebcamsModel.php index 567bd2f..c5634ac 100644 --- a/h-source/Application/Models/WebcamsModel.php +++ b/h-source/Application/Models/WebcamsModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class WebcamsModel extends BaseModel +class WebcamsModel extends GenericModel { public $type = 'webcam'; //device type diff --git a/h-source/Application/Models/WifiModel.php b/h-source/Application/Models/WifiModel.php index 7be244b..729101a 100644 --- a/h-source/Application/Models/WifiModel.php +++ b/h-source/Application/Models/WifiModel.php @@ -20,7 +20,7 @@ if (!defined('EG')) die('Direct access not allowed!'); -class WifiModel extends BaseModel +class WifiModel extends GenericModel { public $type = 'wifi'; //device type diff --git a/h-source/Application/Models/WikiModel.php b/h-source/Application/Models/WikiModel.php new file mode 100644 index 0000000..1372a04 --- /dev/null +++ b/h-source/Application/Models/WikiModel.php @@ -0,0 +1,228 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class WikiModel extends Model_Map { + + public $id_user = 0; + public $lastId = 0; //the id of the last record inserted + public $lastTitle = null; //the title of the last page inserted + public $lastTitleClean = null; //the cleaned title of the last page inserted + + public $diffFields = array(); + public $fieldsWithBreaks = array(); + + public function __construct() { + $this->_tables='wiki,regusers,wiki_users'; + $this->_idFields='id_wiki,id_user'; + $this->_where=array( + 'username' => 'regusers', + 'id_user' => 'regusers', + 'has_confirmed' => 'regusers', + 'deleted' => 'regusers' + ); + + $this->printAssError = "no"; + + $this->diffFields = array( + 'title' => gtext("title"), + 'page' => gtext('wiki page'), + ); + + $this->fieldsWithBreaks = array(gtext('wiki page')); + + $this->strongConditions['insert'] = array( + "checkLength|99" => 'title', + "+checkLength|5000" => 'page', + ); + + $this->strongConditions['update'] = array( + "checkLength|99" => 'title', + "+checkLength|5000" => 'page', + ); + + parent::__construct(); + } + + public function insert() + { + $this->values['created_by'] = (int)$this->id_user; + $this->values['update_date'] = date('Y-m-d H:i:s'); + + //random ID + $randomId = md5(uniqid(mt_rand(),true)); + $this->values["title_clean"] = $randomId; + + parent::insert(); + + //associate the user to the record + if ($this->queryResult) + { + $resId = $this->select()->where(array('title_clean'=>$randomId))->send(); + $clean['id'] = $resId[0]['wiki']['id_wiki']; + $this->lastId = $clean['id']; + $this->lastTitle = $resId[0]['wiki']['title']; + $this->lastTitleClean = encodeUrl($resId[0]['wiki']['title']); + $this->db->update('wiki','title_clean',array($this->lastTitleClean),'id_wiki='.$clean['id']); + + //update the history table + $this->updateHistory('insert'); + + $this->associate($clean['id']); + } + + } + + public function update($id) + { + $clean['id'] = (int)$id; + + $this->values['update_date'] = date('Y-m-d H:i:s'); + $this->values['title_clean'] = encodeUrl($this->values['title']); + + //save the old fields in the revisions table + $this->setWhereQueryClause(array('id_wiki' => $clean['id'])); + $oldStruct = $this->getFields($this->fields.',title_clean,created_by,update_date,id_wiki'); + + if (count($oldStruct > 0)) + { + $oldValues = $oldStruct[0]['wiki']; + + $revisions = new WikirevisionsModel(); + $revisions->values = $oldValues; + if ($revisions->insert()) + { + parent::update($clean['id']); + if ($this->queryResult) + { + $this->lastId = $clean['id']; + $this->lastTitle = $this->values['title']; + $this->lastTitleClean = $this->values['title_clean']; + + //update the history table + $this->updateHistory('update'); + + if (!$this->checkAssociation($clean['id'],(int)$this->id_user)) + { + $this->associate($clean['id']); + } + } + } + } + } + + public function makeCurrent($id_rev) + { + $clean['id_rev'] = (int)$id_rev; + + $revisions = new WikirevisionsModel(); + + $clean['id_wiki'] = (int)$revisions->getIdPage($clean['id_rev']); + + //save the old fields in the revisions table + $this->where(array('id_wiki'=>$clean['id_wiki'])); + $oldStruct = $this->getFields($this->fields.',title_clean,created_by,update_date,id_wiki'); + + if (count($oldStruct > 0)) + { + //get the values of the revision + $revisions->where(array('id_rev'=>$clean['id_rev'])); + $newStruct = $revisions->getFields($this->fields.',title_clean,created_by,update_date'); + + if (count($newStruct > 0)) + { + $revisions->values = $oldStruct[0]['wiki']; + + $this->values = $newStruct[0]['wiki_revisions']; + $this->values['created_by'] = (int)$this->id_user; + $this->values['update_date'] = date('Y-m-d H:i:s'); + + if ($revisions->insert()) + { + if (parent::update($clean['id_wiki'])) + { + $this->lastId = $clean['id_wiki']; + $this->lastTitle = $this->values['title']; + $this->lastTitleClean = $this->values['title_clean']; + + //update the history table + $this->updateHistory('update'); + + if (!$this->checkAssociation($clean['id_wiki'],(int)$this->id_user)) + { + $this->associate($clean['id_wiki']); + } + } + } + } + } + + } + + public function associate($id_record) + { + return parent::associate((int)$id_record,(int)$this->id_user); + } + + //get the model name + public function getTheModelName($id) + { + $clean['id'] = (int)$id; + $this->setWhereQueryClause(array('id_wiki' => $clean['id'])); + $res = $this->getFields('title'); + $name = count($res) > 0 ? $res[0]['wiki']['title'] : ''; + return $name; + } + + //save in the history all the action carried out by users + protected function updateHistory($action) + { + $translations = array( + 'insert' => 'inserted', + 'update' => 'updated', + ); + + $allowedActions = array('insert','update'); + + if (in_array($action,$allowedActions)) + { + $users = new UsersModel(); + + $clean['user'] = sanitizeAll($users->getUser($this->id_user)); + + $history = new HistoryModel(); + $history->values = array( + 'created_by' => $this->id_user, + 'type' => 'wiki', + 'action' => $action, + 'id' => $this->lastId, + 'message' => 'The wiki page having id='.$this->lastId.' has been '.$translations[$action].' by the user ' . $clean['user'] . ' (id_user='.$this->id_user.') ', + 'gr' => 'registered', + ); + $history->insert(); + } + } + + public function getDiffArray($oldArray, $newArray) + { + return getDiffArray($this->diffFields, $oldArray, $newArray); + } +} \ No newline at end of file diff --git a/h-source/Application/Models/WikirevisionsModel.php b/h-source/Application/Models/WikirevisionsModel.php new file mode 100644 index 0000000..fdf5558 --- /dev/null +++ b/h-source/Application/Models/WikirevisionsModel.php @@ -0,0 +1,45 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class WikirevisionsModel extends Model_Tree { + + public $id_user = 0; + + public function __construct() { + $this->_tables='wiki_revisions'; + $this->_idFields='id_rev'; + + $this->orderBy = 'id_rev desc'; + + parent::__construct(); + } + + public function getIdPage($id_rev = 0) + { + $clean['id_rev'] = (int)$id_rev; + + $res = $this->db->select('wiki_revisions','id_wiki','id_rev='.$clean['id_rev']); + + return (count($res) > 0) ? $res[0]['wiki_revisions']['id_wiki'] : 0; + } + +} \ No newline at end of file diff --git a/h-source/Application/Models/WikitalkModel.php b/h-source/Application/Models/WikitalkModel.php new file mode 100644 index 0000000..2de10ba --- /dev/null +++ b/h-source/Application/Models/WikitalkModel.php @@ -0,0 +1,50 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class WikitalkModel extends Model_Tree +{ + + public function __construct() { + $this->_tables = 'wiki_talk'; + $this->_idFields = 'id_talk'; + + $this->orderBy = 'talk.id_talk'; + + $this->strongConditions['insert'] = array( + "checkLength|99" => 'title', + "+checkLength|5000" => 'message', + ); + + parent::__construct(); + } + + public $formStruct = array( + 'entries' => array( + 'title' => array(), + 'message' => array('type'=>'Textarea'), + 'id_talk' => array( + 'type' => 'Hidden' + ) + ), + ); + +} \ No newline at end of file diff --git a/h-source/Application/Views/Issues/view.php b/h-source/Application/Views/Issues/view.php index d5e536e..0af4780 100644 --- a/h-source/Application/Views/Issues/view.php +++ b/h-source/Application/Views/Issues/view.php @@ -223,7 +223,7 @@ diff --git a/h-source/Application/Views/Issues/viewall.php b/h-source/Application/Views/Issues/viewall.php index b47294f..0374fc7 100644 --- a/h-source/Application/Views/Issues/viewall.php +++ b/h-source/Application/Views/Issues/viewall.php @@ -110,7 +110,7 @@ diff --git a/h-source/Application/Views/Wiki/climb.php b/h-source/Application/Views/Wiki/climb.php new file mode 100644 index 0000000..bd502d1 --- /dev/null +++ b/h-source/Application/Views/Wiki/climb.php @@ -0,0 +1,50 @@ + + +. +?> +
+ +
+ ">Home » +
+ +
+ +
+ + + +
+ + + +
+ + +
" method="POST"> + : +
+ + +
+ +
\ No newline at end of file diff --git a/h-source/Application/Views/Wiki/differences.php b/h-source/Application/Views/Wiki/differences.php new file mode 100644 index 0000000..1709cbf --- /dev/null +++ b/h-source/Application/Views/Wiki/differences.php @@ -0,0 +1,61 @@ + + +. +?> + +
+ +
+ ">Home » +
+ + +
+ Differences between the revision of , created by getUser($created_by));?>, and the revision of +
+ + + + +
+ +
+ Notice: the text in red has been deleted from the previous revision, the text in green has been added in this revision and the text in gray has not been changed. +
+ + $text) { ?> + +
+ +
+ : +
+ +
+ +
+ +
+ + + +
diff --git a/h-source/Application/Views/Wiki/form.php b/h-source/Application/Views/Wiki/form.php new file mode 100644 index 0000000..0a448dd --- /dev/null +++ b/h-source/Application/Views/Wiki/form.php @@ -0,0 +1,96 @@ + + +. +?> + + + +
+ + action,'insert') === 0 ) { ?> + +
+ ">Home » ">Wiki » +
+ +
+ +
+ + + + action,'update') === 0 ) { ?> + +
+ ">Home » ">Wiki » "> » +
+ +
+ +
+ + + + + +
+
License Informations:
+ Any text submitted by you will be put in the Public Domain (see the CC0 page for detailed information). +
+ + + +
+ +
controller."/".$this->action."/$lang";?>" method="POST"> + +
+ +
+ + +
+ +
+ + +
+ + + + + +
+ +
+
+ diff --git a/h-source/Application/Views/Wiki/history.php b/h-source/Application/Views/Wiki/history.php new file mode 100644 index 0000000..b979063 --- /dev/null +++ b/h-source/Application/Views/Wiki/history.php @@ -0,0 +1,70 @@ + + +. +?> + +
+ +
+ ">Home » ">Wiki » "> » +
+ +
+ History of the wiki page +
+ + + +
+ + + +
+ +
+ : +
+ diff --git a/h-source/Application/Views/Wiki/not_found.php b/h-source/Application/Views/Wiki/not_found.php new file mode 100644 index 0000000..dc95c21 --- /dev/null +++ b/h-source/Application/Views/Wiki/not_found.php @@ -0,0 +1,34 @@ + + +. +?> + +
+ +
+ ">Home » ">Wiki » +
+ +
+
+ +
+
+ diff --git a/h-source/Application/Views/Wiki/page.php b/h-source/Application/Views/Wiki/page.php new file mode 100644 index 0000000..92e3c9b --- /dev/null +++ b/h-source/Application/Views/Wiki/page.php @@ -0,0 +1,102 @@ + + +. +?> + +
+ + action,'page') === 0 ? 'wiki' : 'wiki_revisions'; ?> + + action,'page') === 0 ) { ?> + +
+ ">Home » ">Wiki » +
+ + + + + + action,'revision') === 0 ) { ?> + +
+ ">Home » +
+ +
+ Revision of the wiki page +
+ + + + + +
+ + + +
+ +
+ + + + + + + action,'revision') === 0) { ?> +
+ This is an old revision of this page, as edited by getUser($created_by));?> at . It may differ significantly from the ">current revision. +
+ + + +
+ +
+
+ +
+ + + + +
diff --git a/h-source/Application/Views/Wiki/talk.php b/h-source/Application/Views/Wiki/talk.php new file mode 100644 index 0000000..67ecbeb --- /dev/null +++ b/h-source/Application/Views/Wiki/talk.php @@ -0,0 +1,122 @@ + + +. +?> + + + +
+ +
+ ">Home » +
+ +
+ +
+ + + +
+ + + + + + +
+ +
+ +
+ +
+ +
+ by getUser($message['wiki_talk']['created_by']));?>, +
+
+ +
+ +
+ +
+ + + + + + + + +
+ + + +
+ + + + +
+
controller."/talk/$lang/$id_wiki";?>#form" method="POST"> + +
+ +
+ + +
+ +
+ + +
+ + + +
+ +
+
+
+ + + + + + + +
\ No newline at end of file diff --git a/h-source/Application/Views/right.php b/h-source/Application/Views/right.php index bc97fba..b931151 100644 --- a/h-source/Application/Views/right.php +++ b/h-source/Application/Views/right.php @@ -30,10 +30,12 @@