Indefero

Indefero Commit Details


Date:2011-11-06 09:52:24 (13 years 5 months ago)
Author:William MARTIN
Branch:feature.wiki-default-page
Commit:bd94d5bf68b51a183ec4be0051383b51cf81a66b
Parents: f9629f3f7ba0d30928a9c676adec116664acd446
Message:Add a way to setup a wiki page instead of the listing page for the default wiki view

Changes:

File differences

src/IDF/Form/WikiConf.php
4141
4242
4343
44
4445
4546
4647
......
5960
6061
6162
63
64
65
66
67
68
69
6270
6371
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
6487
6588
6689
Deprecated           = Most users should NOT reference this';
    const init_one_max = '';
    const wiki_default_page = '';
    public function initFields($extra=array())
    {
                                            '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;
    }
}
src/IDF/Views/Project.php
418418
419419
420420
421
422
423
424
425
426
427
428
429
421430
422
431
423432
424433
425434
......
431440
432441
433442
434
443
435444
436445
437446
......
447456
448457
449458
459
450460
451461
452462
        $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);
            }
        } 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) {
                                               array(
                                                     'page_title' => $title,
                                                     'form' => $form,
                                                     'auto_wiki_page_name' => $auto_wiki_page_name,
                                                     ),
                                               $request);
    }
src/IDF/Views/Wiki.php
3535
3636
3737
38
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
3975
4076
4177
......
82118
83119
84120
85
121
86122
87123
88124
......
182218
183219
184220
185
221
186222
187223
188224
......
320356
321357
322358
323
359
324360
325361
326362
......
358394
359395
360396
361
397
362398
363399
364400
     * 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);
    {
        $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);
        }
                $urlpage = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
                                                    array($prj->shortname, $page->title));
                $request->user->setMessage(sprintf(__('The page <a href="%s">%s</a> 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'])) {
                $urlpage = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
                                                    array($prj->shortname, $page->title));
                $request->user->setMessage(sprintf(__('The page <a href="%s">%s</a> 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'])) {
            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);
            }
src/IDF/conf/urls.php
262262
263263
264264
265
266
267
268
269
265270
266271
267272
               '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',
src/IDF/templates/idf/admin/wiki.html
1616
1717
1818
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
1947
2048
2149
</td>
</tr>
<tr>
<td colspan="2">{$form.f.wiki_default_page.labelTag}:<br />
{if $form.f.wiki_default_page.errors}{$form.f.wiki_default_page.fieldErrors}{/if}
{$form.f.wiki_default_page|unsafe}
</td>
<script type="text/javascript" src="{media '/idf/js/jquery.bgiframe.min.js'}"></script>
<script type="text/javascript" src="{media '/idf/js/jquery.autocomplete.min.js'}"></script>
<script type="text/javascript" charset="utf-8">
{literal}
$(document).ready(function(){
  var auto_wiki_page_name = [{/literal}{$auto_wiki_page_name|safe}{literal}];
  $("#id_wiki_default_page").autocomplete(auto_wiki_page_name, {
        minChars: 0,
        width: 310,
        matchContains: true,
        max: 50,
        highlightItem: false,
        formatItem: function(row, i, max, term) {
            return row.to.replace(new RegExp("(" + term + ")", "gi"), "<strong>$1</strong>") + "  <span style='font-size: 80%;'>" + row.name + "</span>";
        },
        formatResult: function(row) {
            return row.to;
        }
    });
});
{/literal}
</script>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="{trans 'Save Changes'}" name="submit" />
</td>

Archive Download the corresponding diff file

Page rendered in 0.32869s using 13 queries.