~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/If/OP_istopic.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See bottom of file for copyright and license details
 
2
 
 
3
=begin TML
 
4
 
 
5
---+ package Foswiki::If::OP_istopic
 
6
 
 
7
=cut
 
8
 
 
9
package Foswiki::If::OP_istopic;
 
10
use base 'Foswiki::Query::UnaryOP';
 
11
 
 
12
use strict;
 
13
 
 
14
sub new {
 
15
    my $class = shift;
 
16
    return $class->SUPER::new( name => 'istopic', prec => 600 );
 
17
}
 
18
 
 
19
sub evaluate {
 
20
    my $this    = shift;
 
21
    my $node    = shift;
 
22
    my $a       = $node->{params}->[0];
 
23
    my %domain  = @_;
 
24
    my $session = $domain{tom}->session;
 
25
    throw Error::Simple(
 
26
        'No context in which to evaluate "' . $a->stringify() . '"' )
 
27
      unless $session;
 
28
    my ( $web, $topic ) = ( $session->{webName}, $a->_evaluate(@_) );
 
29
    return 0 unless defined $topic;    # null topic cannot possibly exist
 
30
    ( $web, $topic ) = $session->normalizeWebTopicName( $web, $topic );
 
31
 
 
32
    return $session->{store}->topicExists( $web, $topic ) ? 1 : 0;
 
33
}
 
34
 
 
35
1;
 
36
__DATA__
 
37
 
 
38
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/
 
39
 
 
40
# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.
 
41
# Foswiki Contributors are listed in the AUTHORS file in the root
 
42
# of this distribution. NOTE: Please extend that file, not this notice.
 
43
#
 
44
# Additional copyrights apply to some or all of the code in this
 
45
# file as follows:
 
46
#
 
47
# Copyright (C) 2005-2007 TWiki Contributors. All Rights Reserved.
 
48
# TWiki Contributors are listed in the AUTHORS file in the root
 
49
# of this distribution. NOTE: Please extend that file, not this notice.
 
50
#
 
51
 
 
52
This program is free software; you can redistribute it and/or
 
53
modify it under the terms of the GNU General Public License
 
54
as published by the Free Software Foundation; either version 2
 
55
of the License, or (at your option) any later version. For
 
56
more details read LICENSE in the root of this distribution.
 
57
 
 
58
This program is distributed in the hope that it will be useful,
 
59
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
60
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
61
 
 
62
As per the GPL, removal of this notice is prohibited.
 
63
 
 
64
Author: Crawford Currie http://c-dot.co.uk
 
65
# See bottom of file for copyright and license details
 
66
 
 
67
=begin TML
 
68
 
 
69
---+ package Foswiki::If::OP_istopic
 
70
 
 
71
=cut
 
72
 
 
73
package Foswiki::If::OP_istopic;
 
74
use base 'Foswiki::Query::UnaryOP';
 
75
 
 
76
use strict;
 
77
 
 
78
sub new {
 
79
    my $class = shift;
 
80
    return $class->SUPER::new( name => 'istopic', prec => 600 );
 
81
}
 
82
 
 
83
sub evaluate {
 
84
    my $this = shift;
 
85
    my $node = shift;
 
86
    my $a = $node->{params}->[0];
 
87
    my %domain = @_;
 
88
    my $session = $domain{tom}->session;
 
89
    throw Error::Simple('No context in which to evaluate "'.
 
90
                          $a->stringify().'"') unless $session;
 
91
    my( $web, $topic) = ( $session->{webName}, $a->_evaluate(@_));
 
92
    return 0 unless defined $topic; # null topic cannot possibly exist
 
93
    ($web, $topic) = $session->normalizeWebTopicName($web, $topic);
 
94
 
 
95
    return $session->{store}->topicExists($web, $topic) ? 1 : 0;
 
96
}
 
97
 
 
98
1;
 
99
__DATA__
 
100
 
 
101
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/
 
102
 
 
103
# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.
 
104
# Foswiki Contributors are listed in the AUTHORS file in the root
 
105
# of this distribution. NOTE: Please extend that file, not this notice.
 
106
#
 
107
# Additional copyrights apply to some or all of the code in this
 
108
# file as follows:
 
109
#
 
110
# Copyright (C) 2005-2007 TWiki Contributors. All Rights Reserved.
 
111
# TWiki Contributors are listed in the AUTHORS file in the root
 
112
# of this distribution. NOTE: Please extend that file, not this notice.
 
113
#
 
114
 
 
115
This program is free software; you can redistribute it and/or
 
116
modify it under the terms of the GNU General Public License
 
117
as published by the Free Software Foundation; either version 2
 
118
of the License, or (at your option) any later version. For
 
119
more details read LICENSE in the root of this distribution.
 
120
 
 
121
This program is distributed in the hope that it will be useful,
 
122
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
123
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
124
 
 
125
As per the GPL, removal of this notice is prohibited.
 
126
 
 
127
Author: Crawford Currie http://c-dot.co.uk
 
128
# See bottom of file for copyright and license details
 
129
 
 
130
=begin TML
 
131
 
 
132
---+ package Foswiki::If::OP_istopic
 
133
 
 
134
=cut
 
135
 
 
136
package Foswiki::If::OP_istopic;
 
137
use base 'Foswiki::Query::UnaryOP';
 
138
 
 
139
use strict;
 
140
 
 
141
sub new {
 
142
    my $class = shift;
 
143
    return $class->SUPER::new( name => 'istopic', prec => 600 );
 
144
}
 
145
 
 
146
sub evaluate {
 
147
    my $this = shift;
 
148
    my $node = shift;
 
149
    my $a = $node->{params}->[0];
 
150
    my %domain = @_;
 
151
    my $session = $domain{tom}->session;
 
152
    throw Error::Simple('No context in which to evaluate "'.
 
153
                          $a->stringify().'"') unless $session;
 
154
    my( $web, $topic) = ( $session->{webName}, $a->_evaluate(@_));
 
155
    return 0 unless defined $topic; # null topic cannot possibly exist
 
156
    ($web, $topic) = $session->normalizeWebTopicName($web, $topic);
 
157
 
 
158
    return $session->{store}->topicExists($web, $topic) ? 1 : 0;
 
159
}
 
160
 
 
161
1;
 
162
__DATA__
 
163
 
 
164
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/
 
165
 
 
166
# Copyright (C) 2008-2009 Foswiki Contributors. All Rights Reserved.
 
167
# Foswiki Contributors are listed in the AUTHORS file in the root
 
168
# of this distribution. NOTE: Please extend that file, not this notice.
 
169
#
 
170
# Additional copyrights apply to some or all of the code in this
 
171
# file as follows:
 
172
#
 
173
# Copyright (C) 2005-2007 TWiki Contributors. All Rights Reserved.
 
174
# TWiki Contributors are listed in the AUTHORS file in the root
 
175
# of this distribution. NOTE: Please extend that file, not this notice.
 
176
#
 
177
 
 
178
This program is free software; you can redistribute it and/or
 
179
modify it under the terms of the GNU General Public License
 
180
as published by the Free Software Foundation; either version 2
 
181
of the License, or (at your option) any later version. For
 
182
more details read LICENSE in the root of this distribution.
 
183
 
 
184
This program is distributed in the hope that it will be useful,
 
185
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
186
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
187
 
 
188
As per the GPL, removal of this notice is prohibited.
 
189
 
 
190
Author: Crawford Currie http://c-dot.co.uk