From: <var...@us...> - 2009-06-03 14:35:39
|
Revision: 6850 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=6850&view=rev Author: vargenau Date: 2009-06-03 14:35:30 +0000 (Wed, 03 Jun 2009) Log Message: ----------- New plugin to set pages as external Added Paths: ----------- trunk/lib/plugin/WikiAdminSetExternal.php Added: trunk/lib/plugin/WikiAdminSetExternal.php =================================================================== --- trunk/lib/plugin/WikiAdminSetExternal.php (rev 0) +++ trunk/lib/plugin/WikiAdminSetExternal.php 2009-06-03 14:35:30 UTC (rev 6850) @@ -0,0 +1,155 @@ +<?php // -*-php-*- +rcs_id('$Id$'); +/* + Copyright 2005 $ThePhpWikiProgrammingTeam + Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent + + This file is part of PhpWiki. + + PhpWiki is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PhpWiki is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PhpWiki; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** + * Usage: <<WikiAdminSetExternal s||=* >> or called via WikiAdminSelect + * @author: Marc-Etienne Vargenau, Alcatel-Lucent + */ +require_once('lib/PageList.php'); +require_once('lib/plugin/WikiAdminSelect.php'); + +class WikiPlugin_WikiAdminSetExternal +extends WikiPlugin_WikiAdminSelect +{ + function getName() { + return _("WikiAdminSetExternal"); + } + + function getDescription() { + return _("Mark selected pages as external."); + } + + function getVersion() { + return preg_replace("/[Revision: $]/", '', + "\$Revision$"); + } + + function getDefaultArguments() { + return array_merge + ( + PageList::supportedArgs(), + array( + 's' => false, + 'external' => 1, + /* Columns to include in listing */ + 'info' => 'pagename,external,mtime', + )); + } + + function setExternalPages(&$dbi, &$request, $pages) { + $result = HTML::div(); + $ul = HTML::ul(); + $count = 0; + foreach ($pages as $name) { + $page = $dbi->getPage($name); + $current = $page->getCurrentRevision(); + $external = $current->get('external'); + if (!$external) $external = 0; + $external = (bool)$external; + if (!$external) { + if (!mayAccessPage('change', $name)) { + $result->setAttr('class', 'error'); + $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.", + WikiLink($name)))); + } else { + $version = $current->getVersion(); + $page->set('external', (bool)1); + $ul->pushContent(HTML::li(fmt("change page '%s' to external.", WikiLink($name)))); + $count++; + } + } + } + if ($count) { + $dbi->touch(); + $result->setAttr('class', 'feedback'); + $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count))); + $result->pushContent($ul); + return $result; + } else { + $result->setAttr('class', 'error'); + $result->pushContent(HTML::p("No pages changed.")); + return $result; + } + } + + function run($dbi, $argstr, &$request, $basepage) { + if ($request->getArg('action') != 'browse') + if (!$request->getArg('action') == _("PhpWikiAdministration/SetExternal")) + return $this->disabled("(action != 'browse')"); + + $args = $this->getArgs($argstr, $request); + $this->_args = $args; + $this->preSelectS($args, $request); + + $p = $request->getArg('p'); + if (!$p) $p = $this->_list; + $post_args = $request->getArg('admin_external'); + if (!$request->isPost() and empty($post_args['external'])) + $post_args['external'] = $args['external']; + $pages = array(); + if ($p && !$request->isPost()) + $pages = $p; + if ($p && $request->isPost() && + !empty($post_args['button']) && empty($post_args['cancel'])) { + // without individual PagePermissions: + if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) { + $request->_notAuthorized(WIKIAUTH_ADMIN); + $this->disabled("! user->isAdmin"); + } + // Real action + return $this->setExternalPages($dbi, $request, array_keys($p)); + } + $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']); + $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args); + $pagelist->addPageList($pages); + + $header = HTML::fieldset(); + $button_label = _("Set pages to external"); + $header->pushContent(HTML::legend(_("Select the pages to set as external"))); + + $buttons = HTML::p(Button('submit:admin_external[button]', $button_label, 'wikiadmin'), + Button('submit:admin_external[cancel]', _("Cancel"), 'button')); + $header->pushContent($buttons); + + return HTML::form(array('action' => $request->getPostURL(), + 'method' => 'post'), + $header, + $pagelist->getContent(), + HiddenInputs($request->getArgs(), + false, + array('admin_external')), + ENABLE_PAGEPERM + ? '' + : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN))); + } + +} + +// Local Variables: +// mode: php +// tab-width: 8 +// c-basic-offset: 4 +// c-hanging-comment-ender-p: nil +// indent-tabs-mode: nil +// End: +?> Property changes on: trunk/lib/plugin/WikiAdminSetExternal.php ___________________________________________________________________ Added: svn:keywords + Id Revision This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <var...@us...> - 2021-12-09 16:52:09
|
Revision: 10759 http://sourceforge.net/p/phpwiki/code/10759 Author: vargenau Date: 2021-12-09 16:52:08 +0000 (Thu, 09 Dec 2021) Log Message: ----------- WikiAdminSetExternal plugin: avoid warning Modified Paths: -------------- trunk/lib/plugin/WikiAdminSetExternal.php Modified: trunk/lib/plugin/WikiAdminSetExternal.php =================================================================== --- trunk/lib/plugin/WikiAdminSetExternal.php 2021-12-09 14:34:19 UTC (rev 10758) +++ trunk/lib/plugin/WikiAdminSetExternal.php 2021-12-09 16:52:08 UTC (rev 10759) @@ -51,7 +51,7 @@ )); } - private function setExternalPages(&$dbi, &$request, $pages) + private function setExternalPages($dbi, $pages) { $result = HTML::div(); $ul = HTML::ul(); @@ -68,7 +68,7 @@ $result->pushContent(HTML::p(fmt("Access denied to change page “%s”.", WikiLink($name)))); } else { - $page->set('external', (bool)1); + $page->set('external', true); $ul->pushContent(HTML::li(fmt("change page “%s” to external.", WikiLink($name)))); $count++; } @@ -83,12 +83,11 @@ $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count))); } $result->pushContent($ul); - return $result; } else { $result->setAttr('class', 'error'); $result->pushContent(HTML::p(_("No pages changed."))); - return $result; } + return $result; } /** @@ -113,6 +112,9 @@ $p = $request->getArg('p'); if (!$p) $p = $this->_list; $post_args = $request->getArg('admin_external'); + if ($post_args === false) { + $post_args = array(); + } if (!$request->isPost() and empty($post_args['external'])) $post_args['external'] = $args['external']; $pages = array(); @@ -127,7 +129,7 @@ $this->disabled("! user->isAdmin"); } // Real action - return $this->setExternalPages($dbi, $request, array_keys($p)); + return $this->setExternalPages($dbi, array_keys($p)); } $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']); $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |