2 rcs_id('$Id: ModeratedPage.php,v 1.1 2004-11-19 19:22:35 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * This plugin requires an action page (Default: ModeratedPage)
24 * and provides delayed execution of restricted actions, after
25 * a special moderators request:
26 * http://mywiki/SomeModeratedPage?action=ModeratedPage&id=kdclcr78431zr43uhrn&pass=approve
31 require_once("lib/WikiPlugin.php");
33 class WikiPlugin_ModeratedPage
37 return _("ModeratedPage");
39 function getDescription () {
40 return _("Support moderated pages");
42 function getVersion() {
43 return preg_replace("/[Revision: $]/", '',
46 function getDefaultArguments() {
47 return array('page' => '[pagename]',
48 'moderators' => false,
49 'require_level' => false, // 1=bogo
50 'require_access' => 'edit,remove,change',
56 function run($dbi, $argstr, &$request, $basepage) {
57 $args = $this->getArgs($argstr, $request);
59 // handle moderation request from the email
60 if (!empty($args['id']) and !empty($args['pass'])) {
62 return $this->error("No page specified");
63 $page = $dbi->getPage($args['page']);
64 $moderation = $page->get("moderation");
66 if (isset($moderation['id']) and $moderation['id'] == $args['id']) {
69 if ($args['pass'] == 'approve')
70 return $this->approve($args, $moderation);
71 elseif ($args['pass'] == 'reject')
72 return $this->reject($args, $moderation);
74 return $this->error("Wrong pass ".$args['pass']);
76 return $this->error("Wrong id");
84 * resolve moderators and require_access from actionpage plugin argstr
86 function resolve_argstr(&$request, $argstr) {
87 $args = $this->getArgs($argstr);
88 $group = $request->getGroup();
89 if (empty($args['moderators'])) {
90 $admins = $group->getSpecialMembersOf(GROUP_ADMIN);
91 // email or usernames?
92 $args['moderators'] = array_merge($admins, array(ADMIN_USER));
94 // resolve possible group names
95 $moderators = explode(',',$args['moderators']);
96 for ($i=0; $i<count($moderators); $i++) {
97 $members = $group->getMembersOf($moderators[$i]);
98 if (!empty($members)) {
99 array_splice($moderators,$i,1,$members);
102 if (!$moderators) $moderators = array(ADMIN_USER);
103 $args['moderators'] = $moderators;
105 //resolve email for $args['moderators']
106 $page = $request->getPage();
108 foreach ($args['moderators'] as $userid) {
111 list($args['emails'], $args['moderators']) = $page->getPageChangeEmails(array($page->getName() => $users));
113 unset($args['page']);
114 unset($args['pass']);
119 * Handle moderation change request by the user.
120 * Hook called on the lock action, if moderation metadata already exists.
122 function lock_check(&$request, &$page, $moderated) {
123 $action_page = $request->getPage(_("ModeratedPage"));
124 $old_moderation = $this->getStatus($request, $page, $action_page);
125 if (is_array($old_moderation)) {
126 $page->set('moderation', $moderation);
127 return $this->notice(
128 fmt("ModeratedPage status update:\n Moderators: '%s'\n require_access: '%s'",
129 join(',',$moderation['moderators']), $moderation['require_access']));
131 $page->set('moderation', false);
132 return $this->notice(HTML($old_moderation,
133 fmt("'%s' is no ModeratedPage anymore.", $page->getName())));
138 * Handle moderation change request by the user.
139 * Hook called on the lock action, if moderation metadata should be added.
140 * Need to store the the plugin args (who, when) in the page meta-data
142 function lock_add(&$request, &$page, &$action_page) {
143 $moderation = $this->getStatus($request, $page, $action_page);
144 if (is_array($moderation)) {
145 $page->set('moderation', $moderation);
146 return $this->notice(
147 fmt("ModeratedPage status update: '%s' is now a ModeratedPage.\n Moderators: '%s'\n require_access: '%s'",
148 $page->getName(), join(',',$moderation['moderators']), $moderation['require_access']));
155 function notice($msg) {
156 return HTML::div(array('class' => 'wiki-edithelp'), $msg);
159 function getStatus(&$request, &$page, &$action_page) {
160 $loader = new WikiPluginLoader();
161 $rev = $action_page->getCurrentRevision();
162 $content = $rev->getPackedContent();
163 list($pi) = explode("\n", $content, 2); // plugin ModeratedPage must be first line!
164 if ($parsed = $loader->parsePI($pi)) {
165 $plugin =& $parsed[1];
166 if ($plugin->getName() != _("ModeratedPage"))
167 return $this->error(sprintf(_("<?plugin ModeratedPage ... ?> not found in first line of %s"),
168 $action_page->getName()));
169 if (!$action_page->get('locked'))
170 return $this->error(sprintf(_("%s is not locked!"),
171 $action_page->getName()));
172 return $plugin->resolve_argstr($request, $parsed[2]);
174 return $this->error(sprintf(_("<?plugin ModeratedPage ... ?> not found in first line of %s"),
175 $action_page->getName()));
181 // $Log: not supported by cvs2svn $
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil