wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / new.pl
blob4b8e651081f0a6b48e4f22d235f32d64f5f3ea91
1 #!/usr/bin/env perl
2 # ====================[ new.pl ]====================
4 =head1 NAME
6 new - An Oddmuse module for creating new pages
8 =head1 INSTALLATION
10 new is easily installable; move this file into the B<wiki/modules/>
11 directory for your Oddmuse Wiki.
13 =head1 DESCRIPTION
15 This module allows you to create new pages without any hassles. You
16 no longer have to create dead links and follow them to create new
17 pages. Use this module if your wiki uses large number of standalone
18 pages.
20 Look out for `New' links added to the `Administration' page and the
21 Goto Bar. Clicking on the `New' 'link will take you to a form that is
22 filled with today's date. If you submit this form, a new page with
23 today's date will be created. If you would rather prefer to create a
24 page with a different name, provide a different `Title'. The pagename
25 that you fill in I<need not> be a fully new page. It can be I<any>
26 existing page. If a page with the name that you typed already exists
27 you will be offered to edit the current revision of the page. Don't
28 be afraid that content on existing page will be erased. Feel
29 adventurous!
31 =cut
33 package OddMuse;
35 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/new.pl">new.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Create_New_Page">New Page Extension</a></p>';
37 push(@MyInitVariables, sub {
38 $EditorGotoBar .= ScriptLink('action=new', T('New'), 'new');
39 });
41 push(@MyAdminCode, \&NewMenu);
43 sub NewMenu {
44 my ($id, $menuref, $restref) = @_;
45 push(@$menuref, ScriptLink('action=new', T('New'), 'new'));
48 # New Action
49 $Action{new} = \&DoNewPage;
51 =head1 GetNewPageName
53 Return the default page name for new pages. Override this function to
54 choose a different default.
56 Use C<CalcDay> to return today's date in YYYY-MM-DD format. If you
57 have localtime.pl loaded, the date will match your local timezone.
58 Otherwise, it will be in UTC.
60 =cut
62 sub GetNewPageName {
63 return CalcDay($Now); # Use `CalcDay' and not gmtime. This
64 # ensures that if localtime.pl is
65 # loaded, then dates of new pages will
66 # match user expectations.
69 sub DoNewPage {
70 my $id = GetParam('id', '');
71 if ($id) {
72 $id = UrlEncode(FreeToNormal($id)); # FIXME: Is this correct?
73 return DoEdit($id);
74 } else {
75 # FIXME: Use a new class or just stick with what weblog-4.pl uses...
76 print GetHeader('', T('New')), $q->start_div({-class=>'content categories'}),
77 GetFormStart(undef, 'get', 'cat');
78 my $go = T('Go!');
79 $id = GetNewPageName();
80 print $q->p(T('Title: '),
81 qq{<input type="text" name="id" value="$id" tabindex="1" />},
82 GetHiddenValue('action', 'new'));
83 print $q->p(qq{<input type="submit" value="$go" tabindex="2" />});
84 print $q->end_form, $q->end_div();
85 PrintFooter();
89 =head1 COPYRIGHT AND LICENSE
91 Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
92 2013 Jambunathan <kjambunathan at gmail dot com>
94 This program is free software; you can redistribute it and/or modify
95 it under the terms of the GNU General Public License as published by
96 the Free Software Foundation; either version 2 of the License, or
97 (at your option) any later version.
99 This program is distributed in the hope that it will be useful, but
100 WITHOUT ANY WARRANTY; without even the implied warranty of
101 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
102 General Public License for more details.
104 You should have received a copy of the GNU General Public License
105 along with this program; if not, write to the
106 Free Software Foundation, Inc.
107 59 Temple Place, Suite 330
108 Boston, MA 02111-1307 USA