|
From: <var...@us...> - 2021-02-20 11:23:39
|
Revision: 10245
http://sourceforge.net/p/phpwiki/code/10245
Author: vargenau
Date: 2021-02-20 11:23:33 +0000 (Sat, 20 Feb 2021)
Log Message:
-----------
Better test boolean arguments
Modified Paths:
--------------
trunk/lib/plugin/AddComment.php
trunk/lib/plugin/AllPages.php
trunk/lib/plugin/CreatePage.php
trunk/lib/plugin/WikiAdminSetExternal.php
Modified: trunk/lib/plugin/AddComment.php
===================================================================
--- trunk/lib/plugin/AddComment.php 2021-02-20 11:10:02 UTC (rev 10244)
+++ trunk/lib/plugin/AddComment.php 2021-02-20 11:23:33 UTC (rev 10245)
@@ -61,7 +61,7 @@
return array('pagename' => '[pagename]',
'order' => 'normal',
'mode' => 'add,show',
- 'jshide' => '0',
+ 'jshide' => false,
'noheader' => false,
//'sortby' => '-pagename' // oldest first. reverse by order=reverse
);
@@ -81,6 +81,24 @@
return $this->error(sprintf(_("A required argument “%s” is missing."), 'pagename'));
}
+ $jshide = $args['jshide'];
+ if (($jshide == '0') || ($jshide == 'false')) {
+ $jshide = false;
+ } elseif (($jshide == '1') || ($jshide == 'true')) {
+ $jshide = true;
+ } else {
+ return $this->error(sprintf(_("Argument '%s' must be a boolean"), "jshide"));
+ }
+
+ $noheader = $args['noheader'];
+ if (($noheader == '0') || ($noheader == 'false')) {
+ $noheader = false;
+ } elseif (($noheader == '1') || ($noheader == 'true')) {
+ $noheader = true;
+ } else {
+ return $this->error(sprintf(_("Argument '%s' must be a boolean"), "noheader"));
+ }
+
// Get our form args.
$comment = $request->getArg("comment");
$request->setArg('comment', false);
@@ -92,7 +110,7 @@
// Now we display previous comments and/or provide entry box
// for new comments
$html = HTML();
- if ($args['jshide']) {
+ if ($jshide) {
$div = HTML::div(array('id' => 'comments', 'style' => 'display:none;'));
//$list->setAttr('style','display:none;');
$div->pushContent(JavaScript("
Modified: trunk/lib/plugin/AllPages.php
===================================================================
--- trunk/lib/plugin/AllPages.php 2021-02-20 11:10:02 UTC (rev 10244)
+++ trunk/lib/plugin/AllPages.php 2021-02-20 11:23:33 UTC (rev 10245)
@@ -52,7 +52,7 @@
}
// info arg allows multiple columns
- // info=mtime,hits,summary,version,author,locked,minor,markup or all
+ // info=mtime,hits,summary,version,author,locked,minor or all
// exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
// sortby: [+|-] pagename|mtime|hits
@@ -67,6 +67,33 @@
{
$args = $this->getArgs($argstr, $request);
+ $include_empty = $args['include_empty'];
+ if (($include_empty == '0') || ($include_empty == 'false')) {
+ $include_empty = false;
+ } elseif (($include_empty == '1') || ($include_empty == 'true')) {
+ $include_empty = true;
+ } else {
+ return $this->error(sprintf(_("Argument '%s' must be a boolean"), "include_empty"));
+ }
+
+ $noheader = $args['noheader'];
+ if (($noheader == '0') || ($noheader == 'false')) {
+ $noheader = false;
+ } elseif (($noheader == '1') || ($noheader == 'true')) {
+ $noheader = true;
+ } else {
+ return $this->error(sprintf(_("Argument '%s' must be a boolean"), "noheader"));
+ }
+
+ $userpages = $args['userpages'];
+ if (($userpages == '0') || ($userpages == 'false')) {
+ $userpages = false;
+ } elseif (($userpages == '1') || ($userpages == 'true')) {
+ $userpages = true;
+ } else {
+ return $this->error(sprintf(_("Argument '%s' must be a boolean"), "userpages"));
+ }
+
if (isset($args['limit']) && !is_limit($args['limit'])) {
return HTML::p(array('class' => "error"),
_("Illegal “limit” argument: must be an integer or two integers separated by comma"));
@@ -80,12 +107,12 @@
// Todo: extend given _GET args
$caption = _("All pages in this wiki (%d total):");
- if (!empty($args['userpages'])) {
- $pages = PageList::allUserPages($args['include_empty'], $args['sortby'], '');
+ if ($userpages) {
+ $pages = PageList::allUserPages($include_empty, $args['sortby'], '');
$caption = _("List of user-created pages (%d total):");
$args['count'] = count($pages);
} elseif (!empty($args['owner'])) {
- $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'], $args['sortby'], '');
+ $pages = PageList::allPagesByOwner($args['owner'], $include_empty, $args['sortby'], '');
$args['count'] = count($pages);
$caption = fmt("List of pages owned by %s (%d total):",
WikiLink($args['owner'] == '[]'
@@ -93,7 +120,7 @@
: $args['owner'],
'if_known'), $args['count']);
} elseif (!empty($args['author'])) {
- $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'], $args['sortby'], '');
+ $pages = PageList::allPagesByAuthor($args['author'], $include_empty, $args['sortby'], '');
$args['count'] = count($pages);
$caption = fmt("List of pages last edited by %s (%d total):",
WikiLink($args['author'] == '[]'
@@ -101,7 +128,7 @@
: $args['author'],
'if_known'), $args['count']);
} elseif (!empty($args['creator'])) {
- $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'], $args['sortby'], '');
+ $pages = PageList::allPagesByCreator($args['creator'], $include_empty, $args['sortby'], '');
$args['count'] = count($pages);
$caption = fmt("List of pages created by %s (%d total):",
WikiLink($args['creator'] == '[]'
@@ -111,24 +138,25 @@
} elseif ($pages) {
$args['count'] = count($pages);
} else {
- if (!$request->getArg('count'))
- $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
- else
+ if (!$request->getArg('count')) {
+ $args['count'] = $dbi->numPages($include_empty, $args['exclude']);
+ } else {
$args['count'] = $request->getArg('count');
+ }
}
if (empty($args['count']) and !empty($pages)) {
$args['count'] = count($pages);
}
$pagelist = new PageList($args['info'], $args['exclude'], $args);
- if (!$args['noheader']) {
+ if (!$noheader) {
$pagelist->setCaption($caption);
}
- if ($pages !== false)
+ if ($pages !== false) {
$pagelist->addPageList($pages);
- else
- $pagelist->addPages($dbi->getAllPages($args['include_empty'], $args['sortby'],
- $args['limit']));
+ } else {
+ $pagelist->addPages($dbi->getAllPages($include_empty, $args['sortby'], $args['limit']));
+ }
return $pagelist;
}
}
Modified: trunk/lib/plugin/CreatePage.php
===================================================================
--- trunk/lib/plugin/CreatePage.php 2021-02-20 11:10:02 UTC (rev 10244)
+++ trunk/lib/plugin/CreatePage.php 2021-02-20 11:23:33 UTC (rev 10245)
@@ -53,8 +53,6 @@
'vars' => false,
'overwrite' => false,
'verify' => false, // true or a pagename
- //'buttontext' => false,
- //'method' => 'POST'
);
}
@@ -68,6 +66,15 @@
function run($dbi, $argstr, &$request, $basepage)
{
extract($this->getArgs($argstr, $request));
+
+ if (($overwrite == '0') || ($overwrite == 'false')) {
+ $overwrite = false;
+ } elseif (($overwrite == '1') || ($overwrite == 'true')) {
+ $overwrite = true;
+ } else {
+ return $this->error(sprintf(_("Argument '%s' must be a boolean"), "overwrite"));
+ }
+
// Prevent spaces at the start and end of a page name
$s = trim($s);
if (!$s) {
Modified: trunk/lib/plugin/WikiAdminSetExternal.php
===================================================================
--- trunk/lib/plugin/WikiAdminSetExternal.php 2021-02-20 11:10:02 UTC (rev 10244)
+++ trunk/lib/plugin/WikiAdminSetExternal.php 2021-02-20 11:23:33 UTC (rev 10245)
@@ -45,7 +45,7 @@
(
parent::getDefaultArguments(),
array(
- 'external' => 1,
+ 'external' => true,
/* Columns to include in listing */
'info' => 'pagename,external,mtime',
));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|