diff --git a/src/IDF/Form/WikiConf.php b/src/IDF/Form/WikiConf.php index 7038486..dadcd8b 100644 --- a/src/IDF/Form/WikiConf.php +++ b/src/IDF/Form/WikiConf.php @@ -41,6 +41,7 @@ Phase:Support = Plans for user support and advocacy Deprecated = Most users should NOT reference this'; const init_one_max = ''; + const wiki_default_page = ''; public function initFields($extra=array()) { @@ -59,8 +60,30 @@ Deprecated = Most users should NOT reference this'; 'initial' => self::init_one_max, 'widget_attrs' => array('size' => 60), )); + + $this->fields['wiki_default_page'] = new Pluf_Form_Field_Varchar( + array('required' => false, + 'label' => __('Set a default wiki page instead of the page listing.'), + 'initial' => self::wiki_default_page, + 'widget_attrs' => array('size' => 60), + )); } + + public function clean_wiki_default_page() + { + $pageName = trim($this->cleaned_data['wiki_default_page']); + if (empty($pageName)) { + return ''; + } + $sql = new Pluf_SQL('project=%s AND title=%s', array($this->data['projectId'], $pageName)); + $pages = Pluf::factory('IDF_WikiPage')->getList(array('filter'=>$sql->gen())); + + if ($pages->count() != 1) { + return ''; + } + return $pageName; + } } diff --git a/src/IDF/Views/Project.php b/src/IDF/Views/Project.php index 11c08f4..ea56d75 100644 --- a/src/IDF/Views/Project.php +++ b/src/IDF/Views/Project.php @@ -418,8 +418,17 @@ class IDF_Views_Project $title = sprintf(__('%s Documentation Configuration'), (string) $prj); $conf = new IDF_Conf(); $conf->setProject($prj); + + // Get the Wiki list pages + $sql = new Pluf_SQL('project=%s', array($prj->id)); + $pages = Pluf::factory('IDF_WikiPage')->getList(array('filter'=>$sql->gen())); + $auto_wiki_page_name = ""; + foreach ($pages as $p) { + $auto_wiki_page_name .= '{ name: "' . $p->summary . '", to: "' . $p->title . '" }, '; + } + if ($request->method == 'POST') { - $form = new IDF_Form_WikiConf($request->POST); + $form = new IDF_Form_WikiConf(array_merge($request->POST, array('projectId' => $prj->id))); if ($form->isValid()) { foreach ($form->cleaned_data as $key=>$val) { $conf->setVal($key, $val); @@ -431,7 +440,7 @@ class IDF_Views_Project } } else { $params = array(); - $keys = array('labels_wiki_predefined', 'labels_wiki_one_max'); + $keys = array('labels_wiki_predefined', 'labels_wiki_one_max', 'wiki_default_page'); foreach ($keys as $key) { $_val = $conf->getVal($key, false); if ($_val !== false) { @@ -447,6 +456,7 @@ class IDF_Views_Project array( 'page_title' => $title, 'form' => $form, + 'auto_wiki_page_name' => $auto_wiki_page_name, ), $request); } diff --git a/src/IDF/Views/Wiki.php b/src/IDF/Views/Wiki.php index 6880f4c..35c1ca8 100644 --- a/src/IDF/Views/Wiki.php +++ b/src/IDF/Views/Wiki.php @@ -35,7 +35,43 @@ class IDF_Views_Wiki * View list of issues for a given project. */ public $index_precond = array('IDF_Precondition::accessWiki'); - public function index($request, $match, $api=false) + public function index($request, $match) + { + $project = $request->project; + + // Search for the default page + $conf = new IDF_Conf(); + $conf->setProject($project); + $page = $conf->getVal('wiki_default_page', null); + if ($page === null) { + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing', + array($project->shortname)); + return new Pluf_HTTP_Response_Redirect($url); + } + + // Find the page + $sql = new Pluf_SQL('project=%s AND title=%s', + array($project->id, $page)); + $pages = Pluf::factory('IDF_WikiPage')->getList(array('filter'=>$sql->gen())); + if ($pages->count() != 1) { + // The default page have been delete + $conf->setVal('wiki_default_page', null); + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing', + array($project->shortname)); + return new Pluf_HTTP_Response_Redirect($url); + } + $page = $pages[0]; + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', + array($project->shortname, $page->title)); + return new Pluf_HTTP_Response_Redirect($url); + } + + + /** + * View list of issues for a given project. + */ + public $listing_precond = array('IDF_Precondition::accessWiki'); + public function listing($request, $match, $api=false) { $prj = $request->project; $title = sprintf(__('%s Documentation'), (string) $prj); @@ -82,7 +118,7 @@ class IDF_Views_Wiki { $prj = $request->project; if (!isset($request->REQUEST['q']) or trim($request->REQUEST['q']) == '') { - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } @@ -182,7 +218,7 @@ class IDF_Views_Wiki $urlpage = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', array($prj->shortname, $page->title)); $request->user->setMessage(sprintf(__('The page %s has been created.'), $urlpage, Pluf_esc($page->title))); - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } elseif (isset($request->POST['preview'])) { @@ -320,7 +356,7 @@ class IDF_Views_Wiki $urlpage = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', array($prj->shortname, $page->title)); $request->user->setMessage(sprintf(__('The page %s has been updated.'), $urlpage, Pluf_esc($page->title))); - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } elseif (isset($request->POST['preview'])) { @@ -358,7 +394,7 @@ class IDF_Views_Wiki if ($form->isValid()) { $form->save(); $request->user->setMessage(__('The documentation page has been deleted.')); - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 74bacf9..9ac10e2 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -262,6 +262,11 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/$#', 'model' => 'IDF_Views_Wiki', 'method' => 'index'); +$ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/list/$#', + 'base' => $base, + 'model' => 'IDF_Views_Wiki', + 'method' => 'listing'); + $ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/create/$#', 'base' => $base, 'model' => 'IDF_Views_Wiki', diff --git a/src/IDF/templates/idf/admin/wiki.html b/src/IDF/templates/idf/admin/wiki.html index cd28aca..a54b89a 100644 --- a/src/IDF/templates/idf/admin/wiki.html +++ b/src/IDF/templates/idf/admin/wiki.html @@ -16,6 +16,34 @@