(file) Return to UI.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / lib / TWiki

  1 rizwank 1.1 # TWiki Collaboration Platform, http://TWiki.org/
  2             #
  3             # Copyright (C) 1999-2004 Peter Thoeny, peter@thoeny.com
  4             #
  5             # For licensing info read license.txt file in the TWiki root.
  6             # This program is free software; you can redistribute it and/or
  7             # modify it under the terms of the GNU General Public License
  8             # as published by the Free Software Foundation; either version 2
  9             # of the License, or (at your option) any later version.
 10             #
 11             # This program is distributed in the hope that it will be useful,
 12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
 13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14             # GNU General Public License for more details, published at 
 15             # http://www.gnu.org/copyleft/gpl.html
 16             
 17             # Service functions used by the UI packages
 18             
 19             package TWiki::UI;
 20             
 21             =pod twiki
 22 rizwank 1.1 
 23             ---+++ oops( $web, $topic, $oopsTmplName, ...)
 24             Generate a relevant URL to redirect to the given oops page
 25             
 26             =cut
 27             
 28             sub oops {
 29               my $webName = shift;
 30               my $topic = shift;
 31               my $script = shift;
 32             
 33               $webName = $TWiki::mainWebname unless ( $webName );
 34               $topic = $TWiki::mainTopicname unless ( $topic );
 35             
 36               my $url = TWiki::getOopsUrl( $webName, $topic, "oops$script", @_ );
 37               redirect( $url, @_ );
 38             }
 39             
 40             =pod twiki
 41             
 42             ---+++ redirect( $url, ... )
 43 rizwank 1.1 Generate a CGI redirect unless (1) TWiki::getCgiQuery() returns undef or
 44             (2) $query->param('noredirect') is set to any value. Thus a redirect is
 45             only generated when in a CGI context. The ... parameters are
 46             concatenated to the message written when printing to STDOUT, and are
 47             ignored for a redirect.
 48             
 49             =cut
 50             
 51             sub redirect {
 52               my $url = shift;
 53             
 54               my $query = TWiki::getCgiQuery();
 55             
 56               if ( $query && $query->param( 'noredirect' )) {
 57                 TWiki::writeHeader( $query );
 58               } elsif ( $query ) {
 59                 TWiki::redirect( $query, $url );
 60                 return; # no print to STDOUT
 61               }
 62             
 63               print join(" ", @_) . " \n";
 64 rizwank 1.1 }
 65             
 66             =pod twiki
 67             
 68             ---+++ webExists( $web, $topic ) => boolean
 69             Check if the web exists, returning 1 if it does, or
 70             calling TWiki::UI::oops and returning 0 if it doesn't.
 71             
 72             =cut
 73             
 74             sub webExists {
 75               my ( $webName, $topic ) = @_;
 76             
 77               return 1 if( TWiki::Store::webExists( $webName ) );
 78             
 79               oops( $webName, $topic, "noweb", "ERROR $webName.$topic Missing Web" );
 80             
 81               return 0;
 82             }
 83             
 84             =pod twiki
 85 rizwank 1.1 
 86             ---+++ webExists( $web, $topic, $fn ) => boolean
 87             Check if the given topic exists, returning 1 if it does, or
 88             invoking TWiki::UI::oops and returning 0 if it doesn't. $fn is
 89             the name of the command invoked, and will be used in composing
 90             the oops template name thus: oops${fn}notopic
 91             
 92             =cut
 93             
 94             sub topicExists {
 95               my ( $webName, $topic, $fn ) = @_;
 96             
 97               return 1 if TWiki::Store::topicExists( $webName, $topic );
 98             
 99               oops( $webName, $topic, "${fn}notopic", "ERROR $webName.$topic Missing topic" );
100             
101               return 0;
102             }
103             
104             =pod twiki
105             
106 rizwank 1.1 ---+++ isMirror( $web, $topic ) => boolean
107             Checks if this web is a mirror web, returning 0 if is isn't, or
108             calling TWiki::UI::oops and returning 1 if it doesn't.
109             
110             =cut
111             
112             sub isMirror {
113               my ( $webName, $topic ) = @_;
114             
115               my( $mirrorSiteName, $mirrorViewURL ) = TWiki::readOnlyMirrorWeb( $webName );
116             
117               return 0 unless ( $mirrorSiteName );
118             
119               if ( $print ) {
120                 print "ERROR: this is a mirror site\n";
121               } else {
122                 oopsRedirect( $webName, $topic, "mirror",
123                               $mirrorSiteName,
124                               $mirrorViewURL );
125               }
126               return 1;
127 rizwank 1.1 }
128             
129             =cut
130             
131             =pod twiki
132             
133             ---+++ isAccessPermitted( $web, $topic, $mode, $user ) => boolean
134             Check if the given mode of access by the given user to the given
135             web.topic is permissible. If it is, return 1. If not, invoke an
136             oops and return 0.
137             
138             =cut
139             
140             sub isAccessPermitted {
141                my ( $web, $topic, $mode, $user ) = @_;
142             
143                return 1 if TWiki::Access::checkAccessPermission( $mode, $user, "",
144                                                                  $topic, $web );
145                oops( $web, $topic, "access$mode" );
146             
147                return 0;
148 rizwank 1.1 }
149             
150             =pod twiki
151             
152             ---+++ userIsAdmin( $web, $topic, $user ) => boolean
153             Check if the user is an admin. If they are, return 1. If not, invoke an
154             oops and return 0.
155             
156             =cut
157             
158             sub userIsAdmin {
159               my ( $webName, $topic, $user ) = @_;
160             
161               use TWiki::Access;
162             
163               return 1 if TWiki::Access::userIsInGroup( $user, $TWiki::superAdminGroup );
164             
165               oops( $webName, $topic, "accessgroup",
166                     "$TWiki::mainWebname.$TWiki::superAdminGroup" );
167             
168               return 0;
169 rizwank 1.1 }
170             
171             =pod twiki
172             
173             ---+++ writeDebugTimes( $message )
174             Write a debugging message indicating the time at which this function
175             was called. Used for benchmarking.
176             
177             =cut
178             
179             sub writeDebugTimes {
180               my $mess = shift;
181               # TWiki::writeDebug();
182             }
183             
184             1;

Rizwan Kassim
Powered by
ViewCVS 0.9.2