From d85570c9946aef61d8d935d9f50169215338d665 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Tue, 15 Feb 2011 11:45:38 +0000 Subject: improved wiki --- .../Application/Controllers/BaseController.php | 1 + .../Application/Controllers/WikiController.php | 55 +++++++++++++++------- h-source/Application/Include/languages.php | 7 ++- h-source/Application/Include/myFunctions.php | 7 +++ h-source/Application/Models/UsersModel.php | 18 +++++++ h-source/Application/Models/WikiModel.php | 41 ++++++++++++++-- h-source/Application/Views/Wiki/history.php | 6 +-- h-source/Application/Views/Wiki/not_found.php | 2 +- h-source/Application/Views/Wiki/page.php | 6 +-- h-source/Application/Views/header.php | 2 +- h-source/Application/Views/history.php | 4 +- h-source/Application/Views/right.php | 2 + h-source/Public/Css/explorer6.css | 6 ++- h-source/Public/Css/explorer7.css | 8 ++++ h-source/Public/Css/main.css | 14 ++++-- h-source/tables.sql | 5 +- 16 files changed, 147 insertions(+), 37 deletions(-) diff --git a/h-source/Application/Controllers/BaseController.php b/h-source/Application/Controllers/BaseController.php index 0f7c532..29d0642 100644 --- a/h-source/Application/Controllers/BaseController.php +++ b/h-source/Application/Controllers/BaseController.php @@ -38,6 +38,7 @@ class BaseController extends Controller "news" => null, "download" => null, "help" => null, + "wiki" => null, ); public function __construct($model, $controller, $queryString) { diff --git a/h-source/Application/Controllers/WikiController.php b/h-source/Application/Controllers/WikiController.php index 2ddc54d..1c4c154 100644 --- a/h-source/Application/Controllers/WikiController.php +++ b/h-source/Application/Controllers/WikiController.php @@ -24,6 +24,9 @@ class WikiController extends BaseController { public function __construct($model, $controller, $queryString) { + + $this->_topMenuClasses['wiki'] = " class='currentitem'"; + parent::__construct($model, $controller, $queryString); $this->model('UsersModel'); @@ -158,33 +161,51 @@ class WikiController extends BaseController $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 ) + if (isset($title_clean)) { - $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 ) + $res = $this->m['WikiModel']->select()->where(array('title_clean'=>$clean['title_clean']))->orderBy('id_wiki desc')->limit(1)->send(); + + if ( count($res) > 0 ) { - $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']; + $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 = 'select'; + $rev = new WikirevisionsModel(); + $res_rev = $rev->select()->where(array('title_clean'=>$clean['title_clean']))->orderBy('id_rev desc')->limit(1)->send(); + if ( count($res_rev) > 0 ) + { + $clean['idWiki'] = $rev->getIdPage($res_rev[0]['wiki_revisions']['id_rev']); + $newTitle = $this->m['WikiModel']->getTheModelName($clean['idWiki']); + $this->redirect('wiki/page/'.$this->lang.'/'.encodeUrl($newTitle)); + } + else + { + $viewFile = 'not_found'; + } } } else { - $viewFile = 'not_found'; + $this->redirect('wiki/page/'.$this->lang.'/Main-Page'); } - + $this->append($data); $this->load($viewFile); @@ -470,7 +491,7 @@ class WikiController extends BaseController protected function getSpecPageLink() { - return "controller.'/page/'.$this->lang."'>".$this->controller.""; + return "controller.'/page/'.$this->lang."/Main-Page'>".ucfirst($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 4bfb7fe..692c214 100644 --- a/h-source/Application/Include/languages.php +++ b/h-source/Application/Include/languages.php @@ -192,7 +192,12 @@ class Lang "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" + "Talk page of the wiki page" => "Pagina di discussione della pagina della wiki", + "a page with the same title already exists" => "esiste già una pagina con questo titolo", + "title is too length" => "il titolo è troppo lungo", + "the page text is too length" => "il testo della pagina è troppo lungo", + "History of the wiki page" => "History della pagina della wiki", + "Would you like to insert it?" => "Vuoi inserirla?", ), 'es' => array ( diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index d494eb6..8299157 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -195,6 +195,8 @@ function decodeWikiText($string) $string = preg_replace('/(\[hr\])/', '
',$string); + $string = preg_replace_callback('/(\[\[)(.*?)(\]\])/', 'linkToInternalPage' ,$string); + $string = preg_replace_callback('/(\[a\])(.*?)(\[\/a\])/', 'linkTo',$string); $string = preg_replace_callback('/(\[a\])(.*?)\|(.*?)(\[\/a\])/', 'linkToWithText',$string); @@ -269,6 +271,11 @@ function linkTo($match) } } +function linkToInternalPage($match) +{ + return "".$match[2].""; +} + function linkToWithText($match) { if (checkUrl($match[2])) diff --git a/h-source/Application/Models/UsersModel.php b/h-source/Application/Models/UsersModel.php index a7c3845..fe72ce7 100755 --- a/h-source/Application/Models/UsersModel.php +++ b/h-source/Application/Models/UsersModel.php @@ -88,6 +88,24 @@ class UsersModel extends Model_Map } } + public function getLinkToUser($user) + { + if (strstr($user,'__')) + { + return str_replace('__',null,$user); + } + else + { + return "$user"; + } + } + + public function getLinkToUserFromId($id_user = 0) + { + $clean['id_user'] = (int)$id_user; + return $this->getLinkToUser($this->getUser($clean['id_user'])); + } + //get the user id from the username public function getUserId($username = '') { diff --git a/h-source/Application/Models/WikiModel.php b/h-source/Application/Models/WikiModel.php index 1372a04..0a00bfb 100644 --- a/h-source/Application/Models/WikiModel.php +++ b/h-source/Application/Models/WikiModel.php @@ -50,13 +50,21 @@ class WikiModel extends Model_Map { $this->fieldsWithBreaks = array(gtext('wiki page')); $this->strongConditions['insert'] = array( - "checkLength|99" => 'title', - "+checkLength|5000" => 'page', + "checkLength|99" => 'title|'.gtext('title is too length'), + "+checkLength|9000" => 'page|'.gtext('the page text is too length'), ); $this->strongConditions['update'] = array( - "checkLength|99" => 'title', - "+checkLength|5000" => 'page', + "checkLength|99" => 'title|'.gtext('title is too length'), + "+checkLength|9000" => 'page|'.gtext('the page text is too length'), + ); + + $this->databaseConditions['insert'] = array( + "checkUnique" => 'title|'.gtext('a page with the same title already exists'), + ); + + $this->databaseConditions['update'] = array( + "checkUniqueCompl" => 'title|'.gtext('a page with the same title already exists'), ); parent::__construct(); @@ -95,6 +103,7 @@ class WikiModel extends Model_Map { { $clean['id'] = (int)$id; + $this->values['created_by'] = (int)$this->id_user; $this->values['update_date'] = date('Y-m-d H:i:s'); $this->values['title_clean'] = encodeUrl($this->values['title']); @@ -110,6 +119,13 @@ class WikiModel extends Model_Map { $revisions->values = $oldValues; if ($revisions->insert()) { + + if ($this->isMain($clean['id'])) + { + $this->values['title'] = 'Main Page'; + $this->values['title_clean'] = 'Main-Page'; + } + parent::update($clean['id']); if ($this->queryResult) { @@ -155,6 +171,12 @@ class WikiModel extends Model_Map { $this->values['created_by'] = (int)$this->id_user; $this->values['update_date'] = date('Y-m-d H:i:s'); + if ($this->isMain($clean['id_wiki'])) + { + $this->values['title'] = 'Main Page'; + $this->values['title_clean'] = 'Main-Page'; + } + if ($revisions->insert()) { if (parent::update($clean['id_wiki'])) @@ -221,6 +243,17 @@ class WikiModel extends Model_Map { } } + public function isMain($id) + { + $clean['id'] = (int)$id; + $res = $this->select('is_main')->where(array('id_wiki'=>$clean['id']))->send(); + if ( count($res) > 0 ) + { + return strcmp($res[0]['wiki']['is_main'],'no') === 0 ? false : true; + } + return false; + } + public function getDiffArray($oldArray, $newArray) { return getDiffArray($this->diffFields, $oldArray, $newArray); diff --git a/h-source/Application/Views/Wiki/history.php b/h-source/Application/Views/Wiki/history.php index b979063..5e5c041 100644 --- a/h-source/Application/Views/Wiki/history.php +++ b/h-source/Application/Views/Wiki/history.php @@ -27,7 +27,7 @@
- History of the wiki page +
+ controller,'wiki') !== 0 ) { ?>
@@ -105,6 +106,7 @@
+
diff --git a/h-source/Public/Css/explorer6.css b/h-source/Public/Css/explorer6.css index c4bacc8..29b6456 100644 --- a/h-source/Public/Css/explorer6.css +++ b/h-source/Public/Css/explorer6.css @@ -93,10 +93,14 @@ ul#menuBlock li ul { { margin-top:-30px; } -.talk_numb_ext a +.talk_numb_ext a, .talk_numb_ext_wiki a { margin-bottom:0px; } +.talk_numb_ext_wiki +{ + width:130px; +} .language_links_box a.current_lang { background:#6495ED; diff --git a/h-source/Public/Css/explorer7.css b/h-source/Public/Css/explorer7.css index 4060474..f63bf5b 100644 --- a/h-source/Public/Css/explorer7.css +++ b/h-source/Public/Css/explorer7.css @@ -14,4 +14,12 @@ .last_modifications ul { margin-left:0px; +} +.talk_numb_ext a, .talk_numb_ext_wiki a +{ + margin-bottom:0px; +} +.talk_numb_ext_wiki +{ + width:130px; } \ No newline at end of file diff --git a/h-source/Public/Css/main.css b/h-source/Public/Css/main.css index 3eed9d2..abdeb0a 100644 --- a/h-source/Public/Css/main.css +++ b/h-source/Public/Css/main.css @@ -684,7 +684,7 @@ ins .div_h1 { font:bold 15px/1 sans-serif,arial; - border-bottom:1px solid gray; + border-bottom:1px dashed #000; padding:3px 0px; margin:10px 0px; color:gray; @@ -1399,7 +1399,7 @@ ins text-align:left; margin-left:10px; } -.talk_numb_ext a +.talk_numb_ext a, .talk_numb_ext_wiki a { display:block; width:150px; @@ -1662,13 +1662,14 @@ td.text_item_date .wiki_external_box { - margin:4em 10px; + margin:4em 5px; clear:both; clear:right; } .wiki_page_title { font:bold 16px/1 sans-serif,arial; + color:gray; margin:20px 0px; padding-bottom:4px; border-bottom:1px solid #000; @@ -1676,4 +1677,11 @@ td.text_item_date .wiki_page_content { margin:2em 0px; +} + +.talk_numb_ext_wiki +{ + float:left; + text-align:left; + margin-left:10px; } \ No newline at end of file diff --git a/h-source/tables.sql b/h-source/tables.sql index 3a50a1a..c59cf23 100644 --- a/h-source/tables.sql +++ b/h-source/tables.sql @@ -274,4 +274,7 @@ create table wiki_talk ( message text CHARACTER SET utf8 not null, id_wiki INT UNSIGNED NOT NULL, deleted char(4) not null default 'no' -)engine=innodb; \ No newline at end of file +)engine=innodb; + +insert into wiki (title,title_clean,is_main) values ('Main Page','Main-Page','yes'); +update wiki set update_date=creation_date where title='Main Page'; \ No newline at end of file -- cgit v1.2.3