Skip to content

Commit

Permalink
Remove some warnings
Browse files Browse the repository at this point in the history
PHP8 become picky.
We favour the use of the Input class to access Request Variables
(https://www.dokuwiki.org/devel:request_vars).
  • Loading branch information
atisne committed Feb 15, 2024
1 parent 097de43 commit f161d4f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
23 changes: 14 additions & 9 deletions action/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private function __get_siteexport_list_and_init_tocs($NS, $isRedirected = false)
* Add page with ID to the package
**/
private function __siteexport_add_site($ID) {
global $conf, $CURRENT_ID, $CURRENT_PARENT;
global $conf, $CURRENT_ID, $CURRENT_PARENT, $INPUT;

// Which is the current ID?
$CURRENT_ID = $ID;
Expand All @@ -486,26 +486,26 @@ private function __siteexport_add_site($ID) {
// say, what to export and Build URL
// http://documentation:81/helpdesk/de/hds/getting-started?depthType=0&do=siteexport&ens=helpdesk%3Ade%3Ahds%3Agetting-started&pdfExport=1&renderer=siteexport_siteexportpdf&template=helpdesk

$do = (intval($_REQUEST['exportbody'] ?? 0) == 1 ? (empty($_REQUEST['renderer'] ?? '') ? $conf['renderer_xhtml'] : $_REQUEST['renderer']) : '');
$do = $INPUT->int('exportbody', 0, true) == 1 ? $INPUT->str('renderer', $conf['renderer_xhtml'], true) : '';

if ($do == 'pdf' && $this->filewriter->canDoPDF())
{
$do = 'export_siteexport_pdf';
$_REQUEST['origRenderer'] = (empty($_REQUEST['renderer']) ? $conf['renderer_xhtml'] : $_REQUEST['renderer']);
} else if ( ($_REQUEST['renderer'] ?? '') == 'dw2pdf') {
$INPUT->set('origRenderer', $INPUT->str('renderer', $conf['renderer_xhtml'], true));
} else if ($INPUT->str('renderer') == 'dw2pdf') {
$do = 'pdf';
}

$do = ($do == $conf['renderer_xhtml'] && intval($_REQUEST['exportbody']) != 1) ? '' : 'export_' . $do;
$do = ($do == $conf['renderer_xhtml'] && $INPUT->int('exportbody', 0, true) != 1) ? '' : 'export_' . $do;

if ($do != 'export_' && !empty($do) )
{
$request['do'] = $do;
}

// set Template
if (!empty($_REQUEST['template'])) {
$request['template'] = $_REQUEST['template'];
if (!empty($INPUT->str('template'))) {
$request['template'] = $INPUT->str('template');
}

$this->functions->debug->message("REQUEST for add_site:", $request, 2);
Expand Down Expand Up @@ -1040,6 +1040,8 @@ private function __fetchAndReplaceLinkFinish( $DATA, $url, $noDeepReplace, $newA
$this->functions->debug->message("Final Link after empty file from '$url'", null, 2);

return $link;
} elseif ($tmpFile === true) {
return "file_not_found_and_ignored.html";
}

$this->functions->debug->message("The fetched file looks good.", $tmpFile, 2);
Expand Down Expand Up @@ -1233,13 +1235,16 @@ private function __getInternalRewriteURL($url) {
**/
private function __getParamsAndDataRewritten(&$DATA, &$PARAMS, $IDKEY = 'id') {

if (empty($PARAMS))
return array();

$PARRAY = explode('&', str_replace('&', '&', $PARAMS));
$PARAMS = array();

foreach ($PARRAY as $item) {
list($key, $value) = explode('=', $item, 2);
list($key, $value) = array_pad( explode('=', $item, 2), 2, null );
if (empty($key) || empty($value))
continue;
continue;

if (strtolower(trim($key)) == $IDKEY) {
$DATA[2] = preg_replace("%^" . preg_quote(DOKU_BASE, '%') . "%", "", str_replace(':', '/', $value));
Expand Down
6 changes: 3 additions & 3 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function __getOrderedListOfPagesForStartEnd($ID, $start, $end)

public function __siteexport_addpage() {

global $ID, $conf;
global $ID, $conf, $INPUT;

$templateSwitching = false;
$pdfExport = false;
Expand Down Expand Up @@ -177,10 +177,10 @@ public function __siteexport_addpage() {
$form->addElement(form_makeTextField('ens', $ID, $this->getLang('ens') . ':', 'ens'));

$form->addElement(form_makeTag('br'));
$form->addElement(form_makeListboxField('depthType', array("0.0" => $this->getLang('depth.pageOnly'), "1.0" => $this->getLang('depth.allSubNameSpaces'), "2.0" => $this->getLang('depth.specifiedDepth')), (empty($_REQUEST['depthType']) ? $this->getLang('depth.allSubNameSpaces') : $_REQUEST['depthType']), $this->getLang('depthType') . ':', 'depthType', null, array_merge(array('class' => 'edit'))));
$form->addElement(form_makeListboxField('depthType', array("0.0" => $this->getLang('depth.pageOnly'), "1.0" => $this->getLang('depth.allSubNameSpaces'), "2.0" => $this->getLang('depth.specifiedDepth')), $INPUT->str('depthType', $this->getLang('depth.allSubNameSpaces'), true), $this->getLang('depthType') . ':', 'depthType', null, array_merge(array('class' => 'edit'))));

$form->addElement(form_makeTag('br'));
$form->addElement(form_makeOpenTag("div", array('style' => 'display:' . ($_REQUEST['depthType'] == "2" ? "block" : "none") . ';', 'id' => 'depthContainer')));
$form->addElement(form_makeOpenTag("div", array('style' => 'display:' . ($INPUT->str('depthType') == "2" ? "block" : "none") . ';', 'id' => 'depthContainer')));
$form->addElement(form_makeTextField('depth', $this->getConf('depth'), $this->getLang('depth') . ':', 'depth'));
$form->addElement(form_makeCloseTag("div"));

Expand Down
7 changes: 6 additions & 1 deletion inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ public function parseStringToRequestArray($inputArray, $decode=false)
$outputArray = $inputArray;
if ( !is_array($inputArray) )
{
if (empty($inputArray))
return array();

$intermediate = str_replace("&", "&", $inputArray);

$outputArray = array();
Expand Down Expand Up @@ -677,7 +680,9 @@ public function getRelativeURL($replaceURL, $baseURL, $existingPageID = null)
$isExternalPage = count($baseParts) == $originalBasePartsCount;

// the new page is in the same plugin, with a different subcontext and same language
$isExternalPage = $isExternalPage || ($didKickSomeParts == 1 && $baseParts[0] != $replaceParts[0] && $baseParts[1] == $replaceParts[1] );
$parts0equal = (isset($baseParts[0]) && isset($replaceParts[0]) && $baseParts[0] == $replaceParts[0]);
$parts1equal = (isset($baseParts[1]) && isset($replaceParts[1]) && $baseParts[1] == $replaceParts[1]);
$isExternalPage = $isExternalPage || ($didKickSomeParts == 1 && !$parts0equal && $parts1equal);

// find out if this is outside of our own export context, beyond the baseURL
$offsiteTemplate = $this->getConf("offSiteLinkTemplate");
Expand Down
8 changes: 4 additions & 4 deletions inc/httpproxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HTTPProxy extends _HTTPProxy {
* @param siteexport_functions $functions
*/
public function __construct($functions) {
global $conf;
global $conf, $INPUT;

// The proxy should only be used if configured.
// Usually the proxy will allow connections away from the current server.
Expand Down Expand Up @@ -74,9 +74,9 @@ public function __construct($functions) {

$this->headers['X-Real-Ip'] = clientIP(true);
$this->headers['X-Site-Exporter'] = $functions->getSecurityToken();
$this->headers['Accept-Encoding'] = $_SERVER['HTTP_ACCEPT_ENCODING'] ?? '';
$this->headers['Accept-Charset'] = $_SERVER['HTTP_ACCEPT_CHARSET'] ?? '';
$this->agent = $_SERVER['HTTP_USER_AGENT'] . ' DokuWiki/SiteExport';
$this->headers['Accept-Encoding'] = $INPUT->server->str('HTTP_ACCEPT_ENCODING');
$this->headers['Accept-Charset'] = $INPUT->server->str('HTTP_ACCEPT_CHARSET');
$this->agent = $INPUT->server->str('HTTP_USER_AGENT') . ' DokuWiki/SiteExport';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function __construct($functions) {
$ens = $INPUT->str( 'ens' );
$this->exportNamespace = !empty($ens) && preg_match("%^" . preg_quote($functions->getNamespaceFromID($ens, $pg), '%') . "%", $this->namespace) ? $functions->getNamespaceFromID($ens, $pg) : $this->namespace;

$this->TOCMapWithoutTranslation = intval($_REQUEST['TOCMapWithoutTranslation'] ?? 0) == 1 ? true : false;
$this->TOCMapWithoutTranslation = ($INPUT->int('TOCMapWithoutTranslation', 0, true) == 1);

$this->defaultLang = $INPUT->str( 'defaultLang', $conf['lang'], true );

Expand Down
10 changes: 6 additions & 4 deletions preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ class preload_plugin_siteexport_controller extends _preload_plugin_siteexport_co
* Setup disabling
*/
public function __construct() {
global $INPUT;

parent::__construct();

$disabledPlugins = array();

// support of old syntax
if (is_array($_REQUEST['diPlu'] ?? null)) {
$disabledPlugins = $_REQUEST['diPlu'];
if (is_array($INPUT->arr('diPlu'))) {
$disabledPlugins = $INPUT->arr('diPlu');
}

if (!empty($_REQUEST['diInv']))
Expand All @@ -193,11 +195,11 @@ public function __construct() {
if ($enabled == 1 && !file_exists(DOKU_PLUGIN . "$plugin/script.js") && !file_exists(DOKU_PLUGIN . "$plugin/style.css") && !file_exists(DOKU_PLUGIN . "$plugin/print.css")) { continue; }
$allPlugins[] = $plugin;
}
$disabledPlugins = empty($_REQUEST['diPlu']) ? $allPlugins : array_diff($allPlugins, $_REQUEST['diPlu']);
$disabledPlugins = empty($INPUT->arr('diPlu')) ? $allPlugins : array_diff($allPlugins, $INPUT->arr('diPlu'));
}

// if this is defined, it overrides the settings made above. obviously.
$disabledPlugins = empty($_REQUEST['disableplugin']) ? $disabledPlugins : $_REQUEST['disableplugin'];
$disabledPlugins = $INPUT->arr('disableplugin', $disabledPlugins, true);

foreach ($disabledPlugins as $plugin) {
$this->disable($plugin);
Expand Down

0 comments on commit f161d4f

Please sign in to comment.