wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / weblog-3.pl
blobb06bb33f0d22e20a4df7e724e7cffcce2fe42514
1 # Copyright (C) 2005, 2006, 2011 Alex Schroeder <alex@gnu.org>
3 # This program is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU General Public License as published by the Free Software
5 # Foundation; either version 3 of the License, or (at your option) any later
6 # version.
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along with
13 # this program. If not, see <http://www.gnu.org/licenses/>.
15 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/weblog-3.pl">weblog-3.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Create_a_Blog_Front_Page">Create a Blog Front Page</a></p>';
17 # Categories
19 use vars qw($CategoriesPage);
21 $CategoriesPage = 'Categories';
23 *CategoriesOldOpenPage = *OpenPage;
24 *OpenPage = *CategoriesNewOpenPage;
26 my %Category = (); # fast checking
27 my @Categories = (); # correct order
29 # handle reset of $NewText in mod_apache environment
31 my $CategoryNewText;
33 push(@MyInitVariables, sub {
34 if (defined $CategoryNewText) {
35 $NewText = $CategoryNewText;
36 } else {
37 $CategoryNewText = $NewText;
39 });
41 # Set $NewText on OpenPage in some case only
43 sub CategoriesNewOpenPage {
44 CategoryInit() unless $CategoryInit;
45 CategoriesOldOpenPage(@_);
46 if ($Page{revision} == 0) {
47 if ($OpenPageName eq $HomePage) {
48 $NewText = '<journal>';
49 } elsif (GetParam('tag','') or $Category{$OpenPageName}) {
50 # if the page is either on the categories page, or the tag=1
51 # parameter was added, show a journal
52 $NewText = T('Matching pages:')
53 . "\n\n"
54 . '<journal "^\d\d\d\d-\d\d-\d\d.*'
55 . $OpenPageName
56 . '">';
61 # Category page
63 sub CategoryParse {
64 my @paragraphs = split(/\n\n+/, shift);
65 my @result;
66 foreach (@paragraphs) {
67 next unless /^\*/;
68 while (/\*+\s*\[\[$FreeLinkPattern\]\]/g) {
69 my $id = FreeToNormal($1);
70 push(@result, $id);
72 last;
74 return @result;
77 my $CategoryInit = 0;
79 sub CategoryInit {
80 $CategoryInit = 1;
81 @Categories = CategoryParse(GetPageContent($CategoriesPage));
82 map { $Category{$_} = 1 } @Categories;
85 # New Action
87 $Action{new} = \&DoCategories;
89 sub DoCategories {
90 print GetHeader('', T('New')), $q->start_div({-class=>'content categories'}),
91 GetFormStart(undef, 'get', 'cat');
92 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime();
93 my $today = sprintf("%d-%02d-%02d", $year + 1900, $mon + 1, $mday);
94 CategoryInit() unless $CategoryInit;
95 print $q->p({-class=>'table'}, map {GetEditLink("$today $_", $_)} @Categories);
96 print $q->p($q->textfield('id', $today), GetHiddenValue('action', 'edit'));
97 print $q->p(Ts('Edit %s.', GetPageLink($CategoriesPage)));
98 print $q->submit("Go!");
99 print $q->end_form, $q->end_div();
100 PrintFooter();
103 # Goto Bar
105 my $GotoBarInit = 0;
107 sub GotoBarInit {
108 $GotoBarInit = 1;
109 @UserGotoBarPages = (@UserGotoBarPages,
110 CategoryParse(GetPageContent($HomePage)));
113 *GetGotoBar = * NewGetGotoBar;
115 sub NewGetGotoBar {
116 my $id = shift;
117 GotoBarInit() unless $GotoBarInit;
118 my @links;
119 foreach my $name (@UserGotoBarPages) {
120 push (@links, GetPageLink($name, $name));
122 my @parts = split(/_/, GetId());
123 CategoryInit() unless $CategoryInit;
124 if ($parts[0] =~ /\d\d\d\d-\d\d-\d\d/) {
125 shift(@parts);
126 push(@links, map {
127 if ($Category{$_}) {
128 $q->a({-href=>$ScriptName . ($UsePathInfo ? '/' : '?') . UrlEncode($_),
129 -class=>'local tag',
130 -rel=>'tag'}, $_);
131 } else {
132 # provide tag=1 parameter to tell OpenPage to add journal tag
133 $q->a({-href=>$ScriptName . '?tag=1;action=browse;id=' . UrlEncode($_),
134 -class=>'local tag',
135 -rel=>'tag'}, $_);
137 } @parts);
139 push (@links, ScriptLink('action=new', T('New')));
140 return $q->span({-class=>'gotobar bar'}, @links, $UserGotoBar);