Merge pull request #672 from cosmocode/cleanuo

Cleanup
This commit is contained in:
Andreas Gohr
2023-09-13 13:33:06 +02:00
committed by GitHub
84 changed files with 734 additions and 694 deletions

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\AccessTableGlobal;
use dokuwiki\plugin\struct\meta\AggregationEditorTable;
@ -21,10 +24,10 @@ use dokuwiki\plugin\struct\meta\Value;
*
* Handle global and serial data table editing
*/
class action_plugin_struct_aggregationeditor extends DokuWiki_Action_Plugin
class action_plugin_struct_aggregationeditor extends ActionPlugin
{
/** @var Column */
protected $column = null;
protected $column;
/** @var string */
protected $pid = '';
@ -38,7 +41,7 @@ class action_plugin_struct_aggregationeditor extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addJsinfo');
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax');
@ -49,18 +52,18 @@ class action_plugin_struct_aggregationeditor extends DokuWiki_Action_Plugin
*
* @param Doku_Event $event
*/
public function addJsinfo(Doku_Event $event)
public function addJsinfo(Event $event)
{
global $ID;
global $JSINFO;
$JSINFO['plugins']['struct']['isPageEditor'] = (bool)(auth_quickaclcheck($ID) >= AUTH_EDIT);
$JSINFO['plugins']['struct']['isPageEditor'] = auth_quickaclcheck($ID) >= AUTH_EDIT;
}
/**
* @param Doku_Event $event
*/
public function handleAjax(Doku_Event $event)
public function handleAjax(Event $event)
{
$len = strlen('plugin_struct_aggregationeditor_');
if (substr($event->data, 0, $len) != 'plugin_struct_aggregationeditor_') {

View File

@ -7,10 +7,13 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\Schema;
use dokuwiki\plugin\struct\meta\StructException;
class action_plugin_struct_ajax extends DokuWiki_Action_Plugin
class action_plugin_struct_ajax extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -18,7 +21,7 @@ class action_plugin_struct_ajax extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax');
}
@ -28,7 +31,7 @@ class action_plugin_struct_ajax extends DokuWiki_Action_Plugin
*
* @param Doku_Event $event event object by reference
*/
public function handleAjax(Doku_Event $event)
public function handleAjax(Event $event)
{
if ($event->data != 'plugin_struct') return;
$event->preventDefault();
@ -39,9 +42,9 @@ class action_plugin_struct_ajax extends DokuWiki_Action_Plugin
try {
$result = $this->executeTypeAjax();
} catch (StructException $e) {
$result = array(
$result = [
'error' => $e->getMessage() . ' ' . basename($e->getFile()) . ':' . $e->getLine()
);
];
if ($conf['allowdebug']) {
$result['stacktrace'] = $e->getTraceAsString();
}
@ -63,7 +66,7 @@ class action_plugin_struct_ajax extends DokuWiki_Action_Plugin
$col = $INPUT->str('column');
if (blank($col)) throw new StructException('No column provided');
list($schema, $colname) = explode('.', $col, 2);
[$schema, $colname] = explode('.', $col, 2);
if (blank($schema) || blank($colname)) throw new StructException('Column format is wrong');
$schema = new Schema($schema);

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\Schema;
@ -23,7 +26,7 @@ use dokuwiki\plugin\struct\types\Lookup;
* schema to the form. The struct_field type is added through standard naming convention - see
* helper/fiels.php for that.
*/
class action_plugin_struct_bureaucracy extends DokuWiki_Action_Plugin
class action_plugin_struct_bureaucracy extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -31,7 +34,7 @@ class action_plugin_struct_bureaucracy extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('PLUGIN_BUREAUCRACY_PAGENAME', 'BEFORE', $this, 'handleLookupFields');
$controller->register_hook('PLUGIN_BUREAUCRACY_EMAIL_SEND', 'BEFORE', $this, 'handleLookupFields');
@ -47,7 +50,7 @@ class action_plugin_struct_bureaucracy extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleSchema(Doku_Event $event, $param)
public function handleSchema(Event $event, $param)
{
$args = $event->data['args'];
if ($args[0] != 'struct_schema') return false;
@ -84,14 +87,14 @@ class action_plugin_struct_bureaucracy extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleLookupFields(Doku_Event $event, $param)
public function handleLookupFields(Event $event, $param)
{
foreach ($event->data['fields'] as $field) {
if (!is_a($field, 'helper_plugin_struct_field')) continue;
if (!$field->column->getType() instanceof Lookup) continue;
$value = $field->getParam('value');
if (!is_array($value)) $value = array($value);
if (!is_array($value)) $value = [$value];
$config = $field->column->getType()->getConfig();
@ -104,10 +107,11 @@ class action_plugin_struct_bureaucracy extends DokuWiki_Action_Plugin
$pids = $search->getPids();
$rids = $search->getRids();
$field->opt['struct_pids'] = array();
$new_value = array();
$field->opt['struct_pids'] = [];
$new_value = [];
foreach ($value as $pid) {
for ($i = 0; $i < count($result); $i++) {
$counter = count($result);
for ($i = 0; $i < $counter; $i++) {
// lookups can reference pages or global data, so check both pid and rid
// make sure not to double decode pid!
$originalPid = $pid;
@ -138,16 +142,16 @@ class action_plugin_struct_bureaucracy extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleSave(Doku_Event $event, $param)
public function handleSave(Event $event, $param)
{
// get all struct values and their associated schemas
$tosave = array();
$tosave = [];
foreach ($event->data['fields'] as $field) {
if (!is_a($field, 'helper_plugin_struct_field')) continue;
/** @var helper_plugin_struct_field $field */
$tbl = $field->column->getTable();
$lbl = $field->column->getLabel();
if (!isset($tosave[$tbl])) $tosave[$tbl] = array();
if (!isset($tosave[$tbl])) $tosave[$tbl] = [];
if ($field->column->isMulti() && $field->column->getType() instanceof Lookup) {
$tosave[$tbl][$lbl] = $field->opt['struct_pids'];

View File

@ -1,5 +1,9 @@
<?php
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler;
use dokuwiki\plugin\sqlite\SQLiteDB;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\SearchConfig;
use dokuwiki\plugin\struct\meta\SearchConfigParameters;
@ -7,7 +11,7 @@ use dokuwiki\plugin\struct\meta\SearchConfigParameters;
/**
* Handle caching of pages containing struct aggregations
*/
class action_plugin_struct_cache extends DokuWiki_Action_Plugin
class action_plugin_struct_cache extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -15,7 +19,7 @@ class action_plugin_struct_cache extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handleCacheSchemachange');
$controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handleCacheAggregation');
@ -40,7 +44,7 @@ class action_plugin_struct_cache extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleCacheSchemachange(Doku_Event $event, $param)
public function handleCacheSchemachange(Event $event, $param)
{
/** @var \cache_parser $cache */
$cache = $event->data;
@ -63,7 +67,7 @@ class action_plugin_struct_cache extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleCacheAggregation(Doku_Event $event, $param)
public function handleCacheAggregation(Event $event, $param)
{
global $INPUT;
@ -78,7 +82,7 @@ class action_plugin_struct_cache extends DokuWiki_Action_Plugin
$db = plugin_load('helper', 'struct_db');
// cache depends on last database save
$sqlite = $db->getDB(false);
if ($sqlite) {
if ($sqlite instanceof SQLiteDB) {
$cache->depends['files'][] = $sqlite->getDbFile();
}
@ -120,7 +124,7 @@ class action_plugin_struct_cache extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleCacheDynamic(Doku_Event $event, $param)
public function handleCacheDynamic(Event $event, $param)
{
/** @var \cache_parser $cache */
$cache = $event->data;
@ -130,11 +134,11 @@ class action_plugin_struct_cache extends DokuWiki_Action_Plugin
// disable cache use when one of these parameters is present
foreach (
array(
SearchConfigParameters::$PARAM_FILTER,
SearchConfigParameters::$PARAM_OFFSET,
SearchConfigParameters::$PARAM_SORT
) as $key
[
SearchConfigParameters::$PARAM_FILTER,
SearchConfigParameters::$PARAM_OFFSET,
SearchConfigParameters::$PARAM_SORT
] as $key
) {
if ($INPUT->has($key)) {
$event->result = false;

View File

@ -7,10 +7,13 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\Column;
use dokuwiki\plugin\struct\types\AbstractBaseType;
class action_plugin_struct_config extends DokuWiki_Action_Plugin
class action_plugin_struct_config extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -18,7 +21,7 @@ class action_plugin_struct_config extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax');
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addJsinfo');
@ -31,7 +34,7 @@ class action_plugin_struct_config extends DokuWiki_Action_Plugin
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
*/
public function handleAjax(Doku_Event $event, $param)
public function handleAjax(Event $event, $param)
{
if ($event->data != 'plugin_struct_config') return;
$event->preventDefault();
@ -53,7 +56,7 @@ class action_plugin_struct_config extends DokuWiki_Action_Plugin
*
* @param Doku_Event $event
*/
public function addJsinfo(Doku_Event $event)
public function addJsinfo(Event $event)
{
global $JSINFO;
$JSINFO['plugins']['struct']['disableDeleteSerial'] = $this->getConf('disableDeleteSerial');

View File

@ -7,11 +7,14 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\StructException;
class action_plugin_struct_diff extends DokuWiki_Action_Plugin
class action_plugin_struct_diff extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -19,7 +22,7 @@ class action_plugin_struct_diff extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, 'handleDiffload');
}
@ -34,7 +37,7 @@ class action_plugin_struct_diff extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleDiffload(Doku_Event $event, $param)
public function handleDiffload(Event $event, $param)
{
global $ACT;
global $INFO;

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\Form\Form;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
@ -17,7 +20,7 @@ use dokuwiki\plugin\struct\meta\Value;
*
* Handles adding struct forms to the default editor
*/
class action_plugin_struct_edit extends DokuWiki_Action_Plugin
class action_plugin_struct_edit extends ActionPlugin
{
/**
* @var string The form name we use to transfer schema data
@ -30,7 +33,7 @@ class action_plugin_struct_edit extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
// add the struct editor to the edit form;
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handleEditform');
@ -44,7 +47,7 @@ class action_plugin_struct_edit extends DokuWiki_Action_Plugin
*
* @return bool
*/
public function addFromData(Doku_Event $event, $_param)
public function addFromData(Event $event, $_param)
{
$html = $this->getEditorHtml();
@ -66,7 +69,7 @@ class action_plugin_struct_edit extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleEditform(Doku_Event $event, $param)
public function handleEditform(Event $event, $param)
{
$html = $this->getEditorHtml();
@ -120,11 +123,11 @@ class action_plugin_struct_edit extends DokuWiki_Action_Plugin
if (isset($structdata[$tablename])) {
$postdata = $structdata[$tablename];
} else {
$postdata = array();
$postdata = [];
}
// we need a short, unique identifier to use in the cookie. this should be good enough
$schemaid = 'SRCT' . substr(str_replace(array('+', '/'), '', base64_encode(sha1($tablename, true))), 0, 5);
$schemaid = 'SRCT' . substr(str_replace(['+', '/'], '', base64_encode(sha1($tablename, true))), 0, 5);
$html = '<fieldset data-schema="' . $schemaid . '">';
$html .= '<legend>' . hsc($schema->getSchema()->getTranslatedLabel()) . '</legend>';
foreach ($schemadata as $field) {

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessDataValidator;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
@ -16,7 +19,7 @@ use dokuwiki\plugin\struct\meta\Assignments;
*
* Handles the entry process of struct data with type "page"
*/
class action_plugin_struct_entry extends DokuWiki_Action_Plugin
class action_plugin_struct_entry extends ActionPlugin
{
/**
* @var string The form name we use to transfer schema data
@ -38,7 +41,7 @@ class action_plugin_struct_entry extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
// validate data on preview and save;
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleValidation');
@ -56,12 +59,12 @@ class action_plugin_struct_entry extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleValidation(Doku_Event $event, $param)
public function handleValidation(Event $event, $param)
{
global $ID, $INPUT;
$act = act_clean($event->data);
if (!in_array($act, array('save', 'preview'))) return false;
$this->tosave = array();
if (!in_array($act, ['save', 'preview'])) return false;
$this->tosave = [];
// run the validation for each assignded schema
$valid = AccessDataValidator::validateDataForPage($INPUT->arr(self::$VAR), $ID, $errors);
@ -94,7 +97,7 @@ class action_plugin_struct_entry extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handlePagesaveBefore(Doku_Event $event, $param)
public function handlePagesaveBefore(Event $event, $param)
{
if ($event->data['contentChanged']) return false; // will be saved for page changes
global $ACT;
@ -127,7 +130,7 @@ class action_plugin_struct_entry extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handlePagesaveAfter(Doku_Event $event, $param)
public function handlePagesaveAfter(Event $event, $param)
{
global $ACT;
if ($ACT == 'revert') return false; // handled in revert
@ -142,9 +145,9 @@ class action_plugin_struct_entry extends DokuWiki_Action_Plugin
$schemaData->clearData();
}
}
} else {
} elseif ($this->tosave) {
// save the provided data
if ($this->tosave) foreach ($this->tosave as $validation) {
foreach ($this->tosave as $validation) {
if ($validation->getAccessTable()->getSchema()->isEditable()) {
$validation->saveData($event->data['newRevision']);

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\AccessTablePage;
use dokuwiki\plugin\struct\meta\Assignments;
@ -19,13 +22,13 @@ use dokuwiki\plugin\struct\meta\ValueValidator;
*
* Handle inline editing
*/
class action_plugin_struct_inline extends DokuWiki_Action_Plugin
class action_plugin_struct_inline extends ActionPlugin
{
/** @var AccessTablePage */
protected $schemadata = null;
protected $schemadata;
/** @var Column */
protected $column = null;
protected $column;
/** @var String */
protected $pid = '';
@ -39,7 +42,7 @@ class action_plugin_struct_inline extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax');
}
@ -48,7 +51,7 @@ class action_plugin_struct_inline extends DokuWiki_Action_Plugin
* @param Doku_Event $event
* @param $param
*/
public function handleAjax(Doku_Event $event, $param)
public function handleAjax(Event $event, $param)
{
$len = strlen('plugin_struct_inline_');
if (substr($event->data, 0, $len) != 'plugin_struct_inline_') return;
@ -138,7 +141,7 @@ class action_plugin_struct_inline extends DokuWiki_Action_Plugin
$value = $INPUT->param('entry');
$validator = new ValueValidator();
if (!$validator->validateValue($this->column, $value)) {
throw new StructException(join("\n", $validator->getErrors()));
throw new StructException(implode("\n", $validator->getErrors()));
}
// current data
@ -210,7 +213,7 @@ class action_plugin_struct_inline extends DokuWiki_Action_Plugin
$rid = $INPUT->int('rid');
$rev = $updatedRev ?: $INPUT->int('rev');
list($table, $field) = explode('.', $INPUT->str('field'), 2);
[$table, $field] = explode('.', $INPUT->str('field'), 2);
if (blank($pid) && blank($rid)) return false;
if (blank($table)) return false;
if (blank($field)) return false;

View File

@ -1,23 +1,27 @@
<?php
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\sqlite\SQLiteDB;
/**
* DokuWiki Plugin struct (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
/**
* Class action_plugin_struct_migration
*
* Handle migrations that need more than just SQL
*/
class action_plugin_struct_migration extends DokuWiki_Action_Plugin
class action_plugin_struct_migration extends ActionPlugin
{
/**
* @inheritDoc
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('PLUGIN_SQLITE_DATABASE_UPGRADE', 'BEFORE', $this, 'handleMigrations');
}
@ -28,16 +32,16 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
* @param Doku_Event $event
* @param $param
*/
public function handleMigrations(Doku_Event $event, $param)
public function handleMigrations(Event $event, $param)
{
if ($event->data['adapter']->getDbname() !== 'struct') {
return;
}
$to = $event->data['to'];
if (is_callable(array($this, "migration$to"))) {
if (is_callable([$this, "migration$to"])) {
$event->preventDefault();
$event->result = call_user_func(array($this, "migration$to"), $event->data['adapter']);
$event->result = call_user_func([$this, "migration$to"], $event->data['adapter']);
}
}
@ -46,7 +50,7 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
*
* Add a latest column to all existing multi tables
*
* @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite
* @param SQLiteDB $sqlite
* @return bool
*/
protected function migration12($sqlite)
@ -69,7 +73,7 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
*
* Unifies previous page and lookup schema types
*
* @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite
* @param SQLiteDB $sqlite
* @return bool
*/
protected function migration16($sqlite)
@ -227,7 +231,7 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
* All lookups were presumed to reference lookup data, not pages, so the migrated value
* was always ["", <previous-pid-aka-new-rid>]. For page references it is ["<previous-pid>", 0]
*
* @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite
* @param SQLiteDB $sqlite
* @return bool
*/
protected function migration17($sqlite)
@ -257,7 +261,7 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
if (!empty($allValues)) {
foreach ($allValues as $row) {
list($pid, $rid, $rev, $colref, $rowno, $fixes) = $this->getFixedValues($row);
[$pid, $rid, $rev, $colref, $rowno, $fixes] = $this->getFixedValues($row);
// now fix the values
if (!empty($fixes)) {
$sql = "UPDATE data_$name
@ -277,7 +281,7 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
if (!empty($allValues)) {
foreach ($allValues as $row) {
list($pid, $rid, $rev, $colref, $rowno, $fixes) = $this->getFixedValues($row);
[$pid, $rid, $rev, $colref, $rowno, $fixes] = $this->getFixedValues($row);
// now fix the values
if (!empty($fixes)) {
$sql = "UPDATE multi_$name
@ -301,7 +305,7 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
/**
* Removes a temp table left over by migration 16
*
* @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite
* @param SQLiteDB $sqlite
* @return bool
*/
protected function migration18($sqlite)
@ -319,7 +323,7 @@ class action_plugin_struct_migration extends DokuWiki_Action_Plugin
*
* Add "published" column to all existing tables
*
* @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite
* @param SQLiteDB $sqlite
* @return bool
*/
protected function migration19($sqlite)

View File

@ -7,6 +7,10 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\sqlite\SQLiteDB;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\Column;
use dokuwiki\plugin\struct\meta\Schema;
@ -14,10 +18,10 @@ use dokuwiki\plugin\struct\types\Lookup;
use dokuwiki\plugin\struct\types\Media;
use dokuwiki\plugin\struct\types\Page;
class action_plugin_struct_move extends DokuWiki_Action_Plugin
class action_plugin_struct_move extends ActionPlugin
{
/** @var helper_plugin_sqlite */
protected $db = null;
protected $db;
/**
* Registers a callback function for a given event
@ -25,7 +29,7 @@ class action_plugin_struct_move extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('PLUGIN_MOVE_PAGE_RENAME', 'AFTER', $this, 'handleMove', true);
$controller->register_hook('PLUGIN_MOVE_MEDIA_RENAME', 'AFTER', $this, 'handleMove', false);
@ -38,12 +42,12 @@ class action_plugin_struct_move extends DokuWiki_Action_Plugin
* @param bool $ispage is this a page move operation?
* @return bool
*/
public function handleMove(Doku_Event $event, $ispage)
public function handleMove(Event $event, $ispage)
{
/** @var helper_plugin_struct_db $hlp */
$hlp = plugin_load('helper', 'struct_db');
$this->db = $hlp->getDB(false);
if (!$this->db) return false;
if (!$this->db instanceof SQLiteDB) return false;
$old = $event->data['src_id'];
$new = $event->data['dst_id'];
@ -63,20 +67,13 @@ class action_plugin_struct_move extends DokuWiki_Action_Plugin
$schema = new Schema($table);
foreach ($schema->getColumns() as $col) {
if ($ispage) {
switch (get_class($col->getType())) {
case Page::class:
$this->updateColumnID($schema, $col, $old, $new, true);
break;
case Lookup::class:
$this->updateColumnLookup($schema, $col, $old, $new);
break;
}
} else {
switch (get_class($col->getType())) {
case Media::class:
$this->updateColumnID($schema, $col, $old, $new);
break;
if (get_class($col->getType()) == Page::class) {
$this->updateColumnID($schema, $col, $old, $new, true);
} elseif (get_class($col->getType()) == Lookup::class) {
$this->updateColumnLookup($schema, $col, $old, $new);
}
} elseif ($col->getType() instanceof Media) {
$this->updateColumnID($schema, $col, $old, $new);
}
}
}
@ -104,11 +101,11 @@ class action_plugin_struct_move extends DokuWiki_Action_Plugin
foreach (Schema::getAll() as $tbl) {
/** @noinspection SqlResolve */
$sql = "UPDATE data_$tbl SET pid = ? WHERE pid = ?";
$this->db->query($sql, array($new, $old));
$this->db->query($sql, [$new, $old]);
/** @noinspection SqlResolve */
$sql = "UPDATE multi_$tbl SET pid = ? WHERE pid = ?";
$this->db->query($sql, array($new, $old));
$this->db->query($sql, [$new, $old]);
}
}
@ -122,7 +119,7 @@ class action_plugin_struct_move extends DokuWiki_Action_Plugin
{
// assignments
$sql = "UPDATE schema_assignments SET pid = ? WHERE pid = ?";
$this->db->query($sql, array($new, $old));
$this->db->query($sql, [$new, $old]);
// make sure assignments still match patterns;
$assignments = Assignments::getInstance();
$assignments->reevaluatePageAssignments($new);
@ -137,7 +134,7 @@ class action_plugin_struct_move extends DokuWiki_Action_Plugin
protected function updateTitles($old, $new)
{
$sql = "UPDATE titles SET pid = ? WHERE pid = ?";
$this->db->query($sql, array($new, $old));
$this->db->query($sql, [$new, $old]);
}
/**
@ -172,7 +169,7 @@ class action_plugin_struct_move extends DokuWiki_Action_Plugin
if ($hashes) {
$this->db->query($sql, [$old, $new, "$old#%"]); // match with hashes
}
if (get_class($col->getType()) === Lookup::class) {
if ($col->getType() instanceof Lookup) {
$this->db->query($sql, [$old, $new, "[\"$old\",%]"]); // match JSON string
if ($hashes) {
$this->db->query($sql, [$old, $new, "[\"$old#%\",%]"]); // match JSON string with hash

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler;
use dokuwiki\plugin\struct\meta\Schema;
/**
@ -18,7 +21,7 @@ use dokuwiki\plugin\struct\meta\Schema;
* The real output creation is done within the syntax component
* @see syntax_plugin_struct_output
*/
class action_plugin_struct_output extends DokuWiki_Action_Plugin
class action_plugin_struct_output extends ActionPlugin
{
protected const DW2PDF_PLACEHOLDER_PREFIX = 'PLUGIN_STRUCT';
@ -28,7 +31,7 @@ class action_plugin_struct_output extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'handleOutput');
$controller->register_hook('PLUGIN_DW2PDF_REPLACE', 'BEFORE', $this, 'replaceDw2pdf');
@ -42,9 +45,10 @@ class action_plugin_struct_output extends DokuWiki_Action_Plugin
* @param Doku_Event $event
* @param $param
*/
public function handleOutput(Doku_Event $event, $param)
public function handleOutput(Event $event, $param)
{
global $ID;
if (!$ID) return;
if (!page_exists($ID)) return;
$pos = 0;
@ -74,15 +78,15 @@ class action_plugin_struct_output extends DokuWiki_Action_Plugin
$event->data->calls,
$ins + 1,
0,
array(
array(
[
[
'plugin',
array(
'struct_output', array('pos' => $pos), DOKU_LEXER_SPECIAL, ''
),
[
'struct_output', ['pos' => $pos], DOKU_LEXER_SPECIAL, ''
],
$pos
)
)
]
]
);
}
@ -93,7 +97,7 @@ class action_plugin_struct_output extends DokuWiki_Action_Plugin
* @param Doku_Event $event
* @param $param
*/
public function replaceDw2pdf(Doku_Event $event, $param)
public function replaceDw2pdf(Event $event, $param)
{
if (!$event->data['id'] || !page_exists($event->data['id'])) return;
@ -129,7 +133,7 @@ class action_plugin_struct_output extends DokuWiki_Action_Plugin
* @param Doku_Event $event
* @param $param
*/
public function cleanupDw2pdf(Doku_Event $event, $param)
public function cleanupDw2pdf(Event $event, $param)
{
$pattern = '~@' . self::DW2PDF_PLACEHOLDER_PREFIX . '_[^@]+?@~';
$event->data['content'] = preg_replace($pattern, '', $event->data['content']);

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
@ -15,7 +18,7 @@ use dokuwiki\plugin\struct\meta\Assignments;
*
* Handles reverting to old data via revert action
*/
class action_plugin_struct_revert extends DokuWiki_Action_Plugin
class action_plugin_struct_revert extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -23,7 +26,7 @@ class action_plugin_struct_revert extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
// ensure a page revision is created when struct data changes:
$controller->register_hook('COMMON_WIKIPAGE_SAVE', 'BEFORE', $this, 'handlePagesaveBefore');
@ -39,7 +42,7 @@ class action_plugin_struct_revert extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handlePagesaveBefore(Doku_Event $event, $param)
public function handlePagesaveBefore(Event $event, $param)
{
if ($event->data['contentChanged']) return false; // will be saved for page changes already
global $ACT;
@ -49,7 +52,7 @@ class action_plugin_struct_revert extends DokuWiki_Action_Plugin
// force changes for revert if there are assignments
$assignments = Assignments::getInstance();
$tosave = $assignments->getPageAssignments($event->data['id']);
if (count($tosave)) {
if ($tosave !== []) {
$event->data['contentChanged'] = true; // save for data changes
}
@ -64,7 +67,7 @@ class action_plugin_struct_revert extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handlePagesaveAfter(Doku_Event $event, $param)
public function handlePagesaveAfter(Event $event, $param)
{
global $ACT;
global $REV;

View File

@ -7,13 +7,16 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
/**
* Inject struct data into indexed pages and search result snippets
*/
class action_plugin_struct_search extends DokuWiki_Action_Plugin
class action_plugin_struct_search extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -21,7 +24,7 @@ class action_plugin_struct_search extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexing');
$controller->register_hook('FULLTEXT_SNIPPET_CREATE', 'BEFORE', $this, 'handleSnippets');
@ -35,7 +38,7 @@ class action_plugin_struct_search extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleIndexing(Doku_Event $event, $param)
public function handleIndexing(Event $event, $param)
{
$id = $event->data['page'];
$assignments = Assignments::getInstance();
@ -56,7 +59,7 @@ class action_plugin_struct_search extends DokuWiki_Action_Plugin
* handler was registered]
* @return bool
*/
public function handleSnippets(Doku_Event $event, $param)
public function handleSnippets(Event $event, $param)
{
$id = $event->data['id'];
$assignments = Assignments::getInstance();

View File

@ -7,6 +7,9 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\PageMeta;
use dokuwiki\plugin\struct\meta\StructException;
@ -15,7 +18,7 @@ use dokuwiki\plugin\struct\meta\StructException;
*
* Saves the page title when meta data is saved
*/
class action_plugin_struct_title extends DokuWiki_Action_Plugin
class action_plugin_struct_title extends ActionPlugin
{
/**
* Registers a callback function for a given event
@ -23,7 +26,7 @@ class action_plugin_struct_title extends DokuWiki_Action_Plugin
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'handleMeta');
}
@ -34,7 +37,7 @@ class action_plugin_struct_title extends DokuWiki_Action_Plugin
* @param Doku_Event $event
* @param $param
*/
public function handleMeta(Doku_Event $event, $param)
public function handleMeta(Event $event, $param)
{
$id = $event->data['page'];

View File

@ -8,11 +8,11 @@
*/
// must be run within Dokuwiki
use dokuwiki\Extension\AdminPlugin;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\Schema;
use dokuwiki\plugin\struct\meta\StructException;
class admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin
class admin_plugin_struct_assignments extends AdminPlugin
{
/**
* @return int sort number in admin menu
@ -78,7 +78,7 @@ class admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin
}
send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_assignments'), true, '&'));
send_redirect(wl($ID, ['do' => 'admin', 'page' => 'struct_assignments'], true, '&'));
}
}
@ -119,14 +119,14 @@ class admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin
$link = wl(
$ID,
array(
[
'do' => 'admin',
'page' => 'struct_assignments',
'action' => 'delete',
'sectok' => getSecurityToken(),
'assignment[tbl]' => $schema,
'assignment[assign]' => $assignee,
)
'assignment[assign]' => $assignee
]
);
echo '<tr>';

View File

@ -7,6 +7,8 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\AdminPlugin;
use dokuwiki\Form\InputElement;
use dokuwiki\Form\Form;
use dokuwiki\plugin\struct\meta\CSVExporter;
use dokuwiki\plugin\struct\meta\CSVImporter;
@ -18,7 +20,7 @@ use dokuwiki\plugin\struct\meta\SchemaEditor;
use dokuwiki\plugin\struct\meta\SchemaImporter;
use dokuwiki\plugin\struct\meta\StructException;
class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
class admin_plugin_struct_schemas extends AdminPlugin
{
/**
* @return int sort number in admin menu
@ -44,7 +46,6 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
global $INPUT;
global $ID;
global $config_cascade;
$config_file_path = end($config_cascade['main']['local']);
// form submit
$table = Schema::cleanTableName($INPUT->str('table'));
@ -117,7 +118,7 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
$schema->delete();
msg($this->getLang('del_ok'), 1);
touch(action_plugin_struct_cache::getSchemaRefreshFile());
send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_schemas'), true, '&'));
send_redirect(wl($ID, ['do' => 'admin', 'page' => 'struct_schemas'], true, '&'));
} catch (StructException $e) {
msg(hsc($e->getMessage()), -1);
}
@ -134,7 +135,7 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
$schema->clear();
msg($this->getLang('clear_ok'), 1);
touch(action_plugin_struct_cache::getSchemaRefreshFile());
send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_schemas'), true, '&'));
send_redirect(wl($ID, ['do' => 'admin', 'page' => 'struct_schemas'], true, '&'));
} catch (StructException $e) {
msg(hsc($e->getMessage()), -1);
}
@ -189,7 +190,7 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
*/
protected function htmlJson(Schema $schema)
{
$form = new Form(array('enctype' => 'multipart/form-data', 'id' => 'plugin__struct_json'));
$form = new Form(['enctype' => 'multipart/form-data', 'id' => 'plugin__struct_json']);
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'struct_schemas');
$form->setHiddenField('table', $schema->getTable());
@ -200,7 +201,7 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
$form->addFieldsetClose();
$form->addFieldsetOpen($this->getLang('import'));
$form->addElement(new \dokuwiki\Form\InputElement('file', 'schemafile'))->attr('accept', '.json');
$form->addElement(new InputElement('file', 'schemafile'))->attr('accept', '.json');
$form->addButton('import', $this->getLang('btn_import'));
$form->addHTML('<p>' . $this->getLang('import_warning') . '</p>');
$form->addFieldsetClose();
@ -238,7 +239,7 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
->val(CSVExporter::DATATYPE_SERIAL)
->addClass('edit block');
$form->addHTML('<br>');
$form->addElement(new \dokuwiki\Form\InputElement('file', 'csvfile'))->attr('accept', '.csv');
$form->addElement(new InputElement('file', 'csvfile'))->attr('accept', '.csv');
$form->addButton('importcsv', $this->getLang('btn_import'));
$form->addCheckbox('createPage', 'Create missing pages')->addClass('block edit');
$form->addHTML(
@ -258,7 +259,7 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
*/
protected function htmlDelete(Schema $schema)
{
$form = new Form(array('id' => 'plugin__struct_delete'));
$form = new Form(['id' => 'plugin__struct_delete']);
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'struct_schemas');
$form->setHiddenField('table', $schema->getTable());
@ -306,21 +307,15 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
{
global $ID;
$toc = array();
$toc = [];
$link = wl(
$ID,
array(
'do' => 'admin',
'page' => 'struct_assignments'
)
['do' => 'admin', 'page' => 'struct_assignments']
);
$toc[] = html_mktocitem($link, $this->getLang('menu_assignments'), 0, '');
$slink = wl(
$ID,
array(
'do' => 'admin',
'page' => 'struct_schemas'
)
['do' => 'admin', 'page' => 'struct_schemas']
);
$toc[] = html_mktocitem($slink, $this->getLang('menu'), 0, '');
@ -331,11 +326,7 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin
$table = $schema->getTable();
$link = wl(
$ID,
array(
'do' => 'admin',
'page' => 'struct_schemas',
'table' => $table
)
['do' => 'admin', 'page' => 'struct_schemas', 'table' => $table]
);
$toc[] = html_mktocitem($link, hsc($table), 1, '');

View File

@ -7,6 +7,7 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\Plugin;
use dokuwiki\plugin\struct\meta\AccessDataValidator;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
@ -24,7 +25,7 @@ use dokuwiki\plugin\struct\meta\StructException;
*
* Remember to check permissions yourself!
*/
class helper_plugin_struct extends DokuWiki_Plugin
class helper_plugin_struct extends Plugin
{
/**
* Class names of renderers which should NOT render struct data.
@ -55,10 +56,10 @@ class helper_plugin_struct extends DokuWiki_Plugin
$assignments = Assignments::getInstance();
$schemas = $assignments->getPageAssignments($page, false);
} else {
$schemas = array($schema);
$schemas = [$schema];
}
$result = array();
$result = [];
foreach ($schemas as $schema) {
$schemaData = AccessTable::getPageAccess($schema, $page, $time);
$result[$schema] = $schemaData->getDataArray();
@ -101,7 +102,7 @@ class helper_plugin_struct extends DokuWiki_Plugin
// validate and see if anything changes
$valid = AccessDataValidator::validateDataForPage($data, $page, $errors);
if ($valid === false) {
throw new StructException("Validation failed:\n%s", join("\n", $errors));
throw new StructException("Validation failed:\n%s", implode("\n", $errors));
}
if (!$valid) return; // empty array when no changes were detected
@ -168,10 +169,10 @@ class helper_plugin_struct extends DokuWiki_Plugin
if (is_null($schema)) {
$schemas = Schema::getAll();
} else {
$schemas = array($schema);
$schemas = [$schema];
}
$result = array();
$result = [];
foreach ($schemas as $table) {
$result[$table] = new Schema($table);
}

View File

@ -1,5 +1,9 @@
<?php
use dokuwiki\Extension\Plugin;
use dokuwiki\plugin\struct\meta\StructException;
use dokuwiki\plugin\struct\meta\Search;
/**
* DokuWiki Plugin struct (Helper Component)
*
@ -7,7 +11,7 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
class helper_plugin_struct_config extends DokuWiki_Plugin
class helper_plugin_struct_config extends Plugin
{
/**
* @param string $val
@ -17,9 +21,9 @@ class helper_plugin_struct_config extends DokuWiki_Plugin
public function parseSort($val)
{
if (substr($val, 0, 1) == '^') {
return array(substr($val, 1), false);
return [substr($val, 1), false];
}
return array($val, true);
return [$val, true];
}
/**
@ -44,19 +48,19 @@ class helper_plugin_struct_config extends DokuWiki_Plugin
* @param string $val
*
* @return array ($col, $comp, $value)
* @throws dokuwiki\plugin\struct\meta\StructException
* @throws StructException
*/
protected function parseFilter($val)
{
$comps = dokuwiki\plugin\struct\meta\Search::$COMPARATORS;
$comps = Search::$COMPARATORS;
$comps[] = '*~';
array_unshift($comps, '<>');
$comps = array_map('preg_quote_cb', $comps);
$comps = join('|', $comps);
$comps = implode('|', $comps);
if (!preg_match('/^(.*?)(' . $comps . ')(.*)$/', $val, $match)) {
throw new dokuwiki\plugin\struct\meta\StructException('Invalid search filter %s', hsc($val));
throw new StructException('Invalid search filter %s', hsc($val));
}
array_shift($match); // we don't need the zeroth match
$match[0] = trim($match[0]);

View File

@ -7,11 +7,12 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\Plugin;
use dokuwiki\ErrorHandler;
use dokuwiki\plugin\sqlite\SQLiteDB;
use dokuwiki\plugin\struct\meta\StructException;
class helper_plugin_struct_db extends DokuWiki_Plugin
class helper_plugin_struct_db extends Plugin
{
/** @var SQLiteDB */
protected $sqlite;
@ -39,7 +40,7 @@ class helper_plugin_struct_db extends DokuWiki_Plugin
*/
public function getDB($throw = true)
{
if ($this->sqlite === null) {
if (!$this->sqlite instanceof SQLiteDB) {
if (!class_exists(SQLiteDB::class)) {
if ($throw || defined('DOKU_UNITTEST')) throw new StructException('no sqlite');
return null;
@ -77,9 +78,8 @@ class helper_plugin_struct_db extends DokuWiki_Plugin
* @param string ...
* @return string
*/
public function STRUCT_JSON() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function STRUCT_JSON(...$args) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
{
$args = func_get_args();
return json_encode($args);
}

View File

@ -60,7 +60,7 @@ class helper_plugin_struct_field extends helper_plugin_bureaucracy_field
}
}
if ($value === array() || $value === '') {
if ($value === [] || $value === '') {
if (!isset($this->opt['optional'])) {
$this->error = true;
if ($this->column) {
@ -112,7 +112,7 @@ class helper_plugin_struct_field extends helper_plugin_bureaucracy_field
$value = $this->getParam('value');
if (is_array($value)) {
return array($this, 'replacementMultiValueCallback');
return [$this, 'replacementMultiValueCallback'];
}
if (!empty($value) && $this->column->getType() instanceof User) {
@ -194,7 +194,7 @@ class helper_plugin_struct_field extends helper_plugin_bureaucracy_field
$class = $hint ? 'hashint' : '';
$lclass = $this->error ? 'bureaucracy_error' : '';
$colname = $field->getColumn()->getFullQualifiedLabel();
$required = !empty($this->opt['optional']) ? '' : ' <sup>*</sup>';
$required = empty($this->opt['optional']) ? ' <sup>*</sup>' : '';
$id = uniqid('struct__', true);
$input = $field->getValueEditor($name, $id);
@ -213,12 +213,12 @@ class helper_plugin_struct_field extends helper_plugin_bureaucracy_field
* Tries to find the correct column and schema
*
* @param string $colname
* @return \dokuwiki\plugin\struct\meta\Column
* @return Column
* @throws StructException
*/
protected function findColumn($colname)
{
list($table, $label) = explode('.', $colname, 2);
[$table, $label] = explode('.', $colname, 2);
if (!$table || !$label) {
throw new StructException('Field \'%s\' not given in schema.field form', $colname);
}

View File

@ -7,10 +7,14 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\Plugin;
use dokuwiki\plugin\sqlite\SQLiteDB;
use dokuwiki\plugin\struct\meta\StructException;
use dokuwiki\plugin\struct\meta\SchemaImporter;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\Schema;
class helper_plugin_struct_imexport extends DokuWiki_Plugin
class helper_plugin_struct_imexport extends Plugin
{
private $sqlite;
@ -33,10 +37,10 @@ class helper_plugin_struct_imexport extends DokuWiki_Plugin
/** @var \helper_plugin_struct_db $helper */
$helper = plugin_load('helper', 'struct_db');
$this->sqlite = $helper->getDB(false);
if (!$this->sqlite) return;
if (!$this->sqlite instanceof SQLiteDB) return;
$schemaName = $this->sqlite->escape_string($schemaName);
$sql = array();
$sql = [];
$sql[] = "DELETE FROM schema_assignments_patterns WHERE tbl = '$schemaName'";
$sql[] = "DELETE FROM schema_assignments WHERE tbl = '$schemaName'";
foreach ($patterns as $pattern) {
@ -60,7 +64,7 @@ class helper_plugin_struct_imexport extends DokuWiki_Plugin
/** @var \helper_plugin_struct_db $helper */
$helper = plugin_load('helper', 'struct_db');
$this->sqlite = $helper->getDB(false);
if (!$this->sqlite) return array();
if (!$this->sqlite instanceof SQLiteDB) return [];
$sql = 'SELECT pattern FROM schema_assignments_patterns WHERE tbl = ?';
$patterns = $this->sqlite->queryAll($sql, $schemaName);
@ -94,11 +98,11 @@ class helper_plugin_struct_imexport extends DokuWiki_Plugin
* If blank, the current user is used.
* @return bool|int the id of the new schema version or false on error.
*
* @throws dokuwiki\plugin\struct\meta\StructException
* @throws StructException
*/
public function importSchema($schemaName, $schemaJSON, $user = null)
{
$importer = new \dokuwiki\plugin\struct\meta\SchemaImporter($schemaName, $schemaJSON);
$importer = new SchemaImporter($schemaName, $schemaJSON);
if (!blank($user)) {
$importer->setUser($user);
}

View File

@ -24,13 +24,13 @@ class helper_plugin_struct_lookup extends helper_plugin_bureaucracy_action
global $ID;
// get all struct values and their associated schemas
$tosave = array();
$tosave = [];
foreach ($fields as $field) {
if (!is_a($field, 'helper_plugin_struct_field')) continue;
/** @var helper_plugin_struct_field $field */
$tbl = $field->column->getTable();
$lbl = $field->column->getLabel();
if (!isset($tosave[$tbl])) $tosave[$tbl] = array();
if (!isset($tosave[$tbl])) $tosave[$tbl] = [];
$tosave[$tbl][$lbl] = $field->getParam('value');
}

View File

@ -41,9 +41,9 @@ class AccessDataValidator extends ValueValidator
*/
public static function validateDataForPage($data, $pageid, &$errors)
{
$tosave = array();
$tosave = [];
$valid = true;
$errors = array();
$errors = [];
$assignments = Assignments::getInstance();
$tables = $assignments->getPageAssignments($pageid);
@ -53,10 +53,8 @@ class AccessDataValidator extends ValueValidator
if (!$validation->validate()) {
$valid = false;
$errors = array_merge($errors, $validation->getErrors());
} else {
if ($validation->hasChanges()) {
$tosave[] = $validation;
}
} elseif ($validation->hasChanges()) {
$tosave[] = $validation;
}
}
if ($valid) return $tosave;

View File

@ -296,7 +296,8 @@ abstract class AccessTable
protected function getSingleSql()
{
$cols = array_merge($this->getSingleNoninputCols(), $this->singleCols);
$cols = join(',', $cols);
$cols = implode(',', $cols);
$vals = array_merge($this->getSingleNoninputValues(), $this->singleValues);
return "INSERT INTO $this->stable ($cols) VALUES (" . trim(str_repeat('?,', count($vals)), ',') . ');';
@ -426,7 +427,7 @@ abstract class AccessTable
foreach ($data as $value) {
$key = $value->getColumn()->getFullQualifiedLabel();
$value = $value->getDisplayValue();
if (is_array($value)) $value = join(', ', $value);
if (is_array($value)) $value = implode(', ', $value);
$result .= sprintf("% -20s : %s\n", $key, $value);
}
return $result;
@ -439,7 +440,7 @@ abstract class AccessTable
protected function getDataFromDB()
{
$idColumn = self::isTypePage($this->pid, $this->ts) ? 'pid' : 'rid';
list($sql, $opt) = $this->buildGetDataSQL($idColumn);
[$sql, $opt] = $this->buildGetDataSQL($idColumn);
return $this->sqlite->queryAll($sql, $opt);
}
@ -453,7 +454,7 @@ abstract class AccessTable
*/
protected function consolidateData($DBdata, $asarray = false)
{
$data = array();
$data = [];
$sep = Search::CONCAT_SEPARATOR;

View File

@ -52,7 +52,8 @@ class AccessTableGlobal extends AccessTable
protected function getSingleSql()
{
$cols = array_merge($this->getSingleNoninputCols(), $this->singleCols);
$cols = join(',', $cols);
$cols = implode(',', $cols);
$vals = array_merge($this->getSingleNoninputValues(), $this->singleValues);
$rid = $this->getRid() ?: "(SELECT (COALESCE(MAX(rid), 0 ) + 1) FROM $this->stable)";

View File

@ -28,11 +28,11 @@ class AccessTablePage extends AccessTable
*/
public function clearData()
{
$data = array();
$data = [];
foreach ($this->schema->getColumns() as $col) {
if ($col->isMulti()) {
$data[$col->getLabel()] = array();
$data[$col->getLabel()] = [];
} else {
$data[$col->getLabel()] = '';
}

View File

@ -119,7 +119,7 @@ abstract class Aggregation
{
if ($this->mode == 'xhtml') {
$classes = $this->getScopeClasses();
$this->renderer->doc .= '<div class="' . join(' ', $classes) . '">';
$this->renderer->doc .= '<div class="' . implode(' ', $classes) . '">';
}
}

View File

@ -41,7 +41,7 @@ class AggregationEditorTable extends AggregationTable
// wrapping div
$classes = $this->getScopeClasses();
$classes[] = 'structaggregationeditor';
$classes = join(' ', $classes);
$classes = implode(' ', $classes);
$this->renderer->doc .= "<div class=\"$classes\"
data-schema=\"$table\" data-searchconf=\"$config\">";

View File

@ -40,16 +40,16 @@ class AggregationList extends Aggregation
protected function renderNode(NestedValue $node)
{
$self = $node->getValueObject(); // null for root node
$children = $node->getChildren($self === null && $this->data['index']); // sort only for index
$children = $node->getChildren(!$self instanceof Value && $this->data['index']); // sort only for index
$results = $node->getResultRows();
// all our content is in a listitem, unless we are the root node
if ($self) {
if ($self instanceof Value) {
$this->renderer->listitem_open($node->getDepth() + 1); // levels are 1 based
}
// render own value if available
if ($self) {
if ($self instanceof Value) {
$this->renderer->listcontent_open();
$this->renderListItem([$self], $node->getDepth(), true); // zero based depth
$this->renderer->listcontent_close();
@ -75,7 +75,7 @@ class AggregationList extends Aggregation
}
// close listitem if opened
if ($self) {
if ($self instanceof Value) {
$this->renderer->listitem_close();
}
}

View File

@ -2,6 +2,8 @@
namespace dokuwiki\plugin\struct\meta;
use dokuwiki\Extension\Event;
/**
* Creates the table aggregation output
*
@ -37,16 +39,16 @@ class AggregationTable extends Aggregation
$this->renderActiveFilters();
$rendercontext = array(
$rendercontext = [
'table' => $this,
'renderer' => $this->renderer,
'format' => $this->mode,
'search' => $this->searchConfig,
'columns' => $this->columns,
'data' => $this->result
);
];
$event = new \Doku_Event(
$event = new Event(
'PLUGIN_STRUCT_RENDER_AGGREGATION_TABLE',
$rendercontext
);
@ -127,9 +129,9 @@ class AggregationTable extends Aggregation
$filters = $dynamic->getFilters();
if (!$filters) return;
$fltrs = array();
$fltrs = [];
foreach ($filters as $column => $filter) {
list($comp, $value) = $filter;
[$comp, $value] = $filter;
// display the filters in a human readable format
foreach ($this->columns as $col) {
@ -216,7 +218,7 @@ class AggregationTable extends Aggregation
$dynamic = $this->searchConfig->getDynamicParameters();
$dynamic->setSort($column, true);
if (isset($sorts[$column->getFullQualifiedLabel()])) {
list(/*colname*/, $currentSort) = $sorts[$column->getFullQualifiedLabel()];
[/*colname*/, $currentSort] = $sorts[$column->getFullQualifiedLabel()];
if ($currentSort) {
$sortclass = 'sort-down';
$dynamic->setSort($column, false);
@ -273,7 +275,7 @@ class AggregationTable extends Aggregation
$this->renderer->doc .= '<th>';
// BEGIN FORM
$form = new \Doku_Form(array('method' => 'GET', 'action' => wl($this->id)));
$form = new \Doku_Form(['method' => 'GET', 'action' => wl($this->id)]);
unset($form->_hidden['sectok']); // we don't need it here
if (!$conf['userewrite']) $form->addHidden('id', $this->id);
@ -281,7 +283,7 @@ class AggregationTable extends Aggregation
$dynamic = $this->searchConfig->getDynamicParameters();
$filters = $dynamic->getFilters();
if (isset($filters[$column->getFullQualifiedLabel()])) {
list(, $current) = $filters[$column->getFullQualifiedLabel()];
[, $current] = $filters[$column->getFullQualifiedLabel()];
$dynamic->removeFilter($column);
} else {
$current = '';
@ -312,16 +314,16 @@ class AggregationTable extends Aggregation
protected function renderResult()
{
foreach ($this->result as $rownum => $row) {
$data = array(
$data = [
'id' => $this->id,
'mode' => $this->mode,
'renderer' => $this->renderer,
'searchConfig' => $this->searchConfig,
'data' => $this->data,
'rownum' => &$rownum,
'row' => &$row,
);
$evt = new \Doku_Event('PLUGIN_STRUCT_AGGREGATIONTABLE_RENDERRESULTROW', $data);
'row' => &$row
];
$evt = new Event('PLUGIN_STRUCT_AGGREGATIONTABLE_RENDERRESULTROW', $data);
if ($evt->advise_before()) {
$this->renderResultRow($rownum, $row);
}
@ -357,7 +359,7 @@ class AggregationTable extends Aggregation
/** @var Value $value */
foreach ($row as $colnum => $value) {
$align = isset($this->data['align'][$colnum]) ? $this->data['align'][$colnum] : null;
$align = $this->data['align'][$colnum] ?? null;
$this->renderer->tablecell_open(1, $align);
$value->render($this->renderer, $this->mode);
$this->renderer->tablecell_close();
@ -411,10 +413,8 @@ class AggregationTable extends Aggregation
if (!empty($this->sums[$i])) {
$this->renderer->cdata('∑ ');
$this->columns[$i]->getType()->renderValue($this->sums[$i], $this->renderer, $this->mode);
} else {
if ($this->mode == 'xhtml') {
$this->renderer->doc .= '&nbsp;';
}
} elseif ($this->mode == 'xhtml') {
$this->renderer->doc .= '&nbsp;';
}
$this->renderer->tableheader_close();
}

View File

@ -35,11 +35,10 @@ class AggregationValue extends Aggregation
{
// Check that we actually got a result
if ($this->resultCount) {
$this->renderValue($this->result[0]); // only one result
} else {
if ($show_not_found) {
$this->renderer->cdata($this->helper->getLang('none'));
}
$this->renderValue($this->result[0]);
// only one result
} elseif ($show_not_found) {
$this->renderer->cdata($this->helper->getLang('none'));
}
}
@ -48,7 +47,7 @@ class AggregationValue extends Aggregation
*/
protected function renderValue($resultrow)
{
foreach ($resultrow as $column => $value) {
foreach ($resultrow as $value) {
if ($value->isEmpty()) {
continue;
}

View File

@ -20,7 +20,7 @@ class Assignments
protected $patterns;
/** @var Assignments */
protected static $instance = null;
protected static $instance;
/**
* Get the singleton instance of the Assignments
@ -30,8 +30,8 @@ class Assignments
*/
public static function getInstance($forcereload = false)
{
if (is_null(self::$instance) or $forcereload) {
$class = get_called_class();
if (is_null(self::$instance) || $forcereload) {
$class = static::class;
self::$instance = new $class();
}
return self::$instance;
@ -174,7 +174,7 @@ class Assignments
public function assignPageSchema($page, $table)
{
$sql = 'REPLACE INTO schema_assignments (pid, tbl, assigned) VALUES (?, ?, 1)';
return (bool)$this->sqlite->query($sql, array($page, $table));
return (bool)$this->sqlite->query($sql, [$page, $table]);
}
/**
@ -187,7 +187,7 @@ class Assignments
public function deassignPageSchema($page, $table)
{
$sql = 'REPLACE INTO schema_assignments (pid, tbl, assigned) VALUES (?, ?, 0)';
return (bool)$this->sqlite->query($sql, array($page, $table));
return (bool)$this->sqlite->query($sql, [$page, $table]);
}
/**
@ -209,7 +209,7 @@ class Assignments
*/
public function getPageAssignments($page, $checkpatterns = true)
{
$tables = array();
$tables = [];
$page = cleanID($page);
if ($checkpatterns) {
@ -243,7 +243,7 @@ class Assignments
{
$sql = 'SELECT pid, tbl, assigned FROM schema_assignments WHERE 1=1';
$opts = array();
$opts = [];
if ($schema) {
$sql .= ' AND tbl = ?';
$opts[] = $schema;
@ -256,11 +256,11 @@ class Assignments
$list = $this->sqlite->queryAll($sql, $opts);
$result = array();
$result = [];
foreach ($list as $row) {
$pid = $row['pid'];
$tbl = $row['tbl'];
if (!isset($result[$pid])) $result[$pid] = array();
if (!isset($result[$pid])) $result[$pid] = [];
$result[$pid][$tbl] = (bool)$row['assigned'];
}
@ -299,11 +299,9 @@ class Assignments
if ($ans == $pns) {
return true;
}
} else {
} elseif (cleanID($pattern) == $page) {
// exact match
if (cleanID($pattern) == $page) {
return true;
}
return true;
}
return false;
@ -323,7 +321,7 @@ class Assignments
$sql = "SELECT DISTINCT tbl FROM schemas WHERE ts <= ? ORDER BY ts DESC";
$tables = $this->sqlite->queryAll($sql, [$ts]);
$assigned = array();
$assigned = [];
foreach ($tables as $row) {
$table = $row['tbl'];
/** @noinspection SqlResolve */

View File

@ -33,6 +33,7 @@ class CSVExporter
$search = new Search();
$search->addSchema($table);
$search->addColumn('*');
$result = $search->execute();
if ($this->type !== self::DATATYPE_GLOBAL) {
@ -65,7 +66,7 @@ class CSVExporter
$row .= ',';
}
foreach ($columns as $i => $col) {
foreach ($columns as $col) {
$row .= $this->escape($col->getLabel());
$row .= ',';
}
@ -90,7 +91,7 @@ class CSVExporter
foreach ($values as $value) {
/** @var Value $value */
$val = $value->getRawValue();
if (is_array($val)) $val = join(',', $val);
if (is_array($val)) $val = implode(',', $val);
// FIXME check escaping of composite ids (JSON with """")
$row .= $this->escape($val);

View File

@ -23,7 +23,7 @@ class CSVImporter
protected $sqlite;
/** @var Column[] The single values to store index => col */
protected $columns = array();
protected $columns = [];
/** @var int current line number */
protected $line = 0;
@ -179,7 +179,7 @@ class CSVImporter
protected function readLine($line)
{
// prepare values for single value table
$values = array();
$values = [];
foreach ($this->columns as $i => $column) {
if (!isset($line[$i])) throw new StructException('Missing field at CSV line %d', $this->line);
@ -209,7 +209,7 @@ class CSVImporter
{
$data = array_combine($this->header, $values);
// pid is a non-data column and must be supplied to the AccessTable separately
$pid = isset($data['pid']) ? $data['pid'] : '';
$pid = $data['pid'] ?? '';
unset($data['pid']);
$table = $this->schema->getTable();

View File

@ -4,7 +4,7 @@ namespace dokuwiki\plugin\struct\meta;
class CSVPageImporter extends CSVImporter
{
protected $importedPids = array();
protected $importedPids = [];
/** @var bool[] */
protected $createPage = [];
@ -106,7 +106,7 @@ class CSVPageImporter extends CSVImporter
return preg_replace_callback(
'/<ifnotempty (.+?)>([^<]*?)<\/ifnotempty>/',
function ($matches) use ($keys, $values) {
list (, $blockKey, $textIfNotEmpty) = $matches;
[, $blockKey, $textIfNotEmpty] = $matches;
$index = array_search($blockKey, $keys, true);
if ($index === false) {
msg('Import error: Key "' . hsc($blockKey) . '" not found!', -1);

View File

@ -189,7 +189,7 @@ class Column
if (!is_null($map) && !$reload) return $map;
// get our own types
$map = array();
$map = [];
$files = glob(DOKU_PLUGIN . 'struct/types/*.php');
foreach ($files as $file) {
$file = basename($file, '.php');

View File

@ -2,6 +2,8 @@
namespace dokuwiki\plugin\struct\meta;
use dokuwiki\Extension\Event;
/**
* Class ConfigParser
*
@ -11,7 +13,25 @@ namespace dokuwiki\plugin\struct\meta;
*/
class ConfigParser
{
protected $config = array();
protected $config = [
'limit' => 0,
'dynfilters' => false,
'summarize' => false,
'rownumbers' => false,
'sepbyheaders' => false,
'target' => '',
'align' => [],
'headers' => [],
'cols' => [],
'widths' => [],
'filter' => [],
'schemas' => [],
'sort' => [],
'csv' => true,
'nesting' => 0,
'index' => 0,
'classes' => []
];
/**
* Parser constructor.
@ -24,28 +44,9 @@ class ConfigParser
{
/** @var \helper_plugin_struct_config $helper */
$helper = plugin_load('helper', 'struct_config');
$this->config = array(
'limit' => 0,
'dynfilters' => false,
'summarize' => false,
'rownumbers' => false,
'sepbyheaders' => false,
'target' => '',
'align' => array(),
'headers' => array(),
'cols' => array(),
'widths' => array(),
'filter' => array(),
'schemas' => array(),
'sort' => array(),
'csv' => true,
'nesting' => 0,
'index' => 0,
'classes' => array(),
);
// parse info
foreach ($lines as $line) {
list($key, $val) = $this->splitLine($line);
[$key, $val] = $this->splitLine($line);
if (!$key) continue;
$logic = 'OR';
@ -87,7 +88,7 @@ class ConfigParser
case 'order':
case 'sort':
$sorts = $this->parseValues($val);
$sorts = array_map(array($helper, 'parseSort'), $sorts);
$sorts = array_map([$helper, 'parseSort'], $sorts);
$this->config['sort'] = array_merge($this->config['sort'], $sorts);
break;
case 'where':
@ -131,8 +132,8 @@ class ConfigParser
$this->config['classes'] = $this->parseClasses($val);
break;
default:
$data = array('config' => &$this->config, 'key' => $key, 'val' => $val);
$ev = new \Doku_Event('PLUGIN_STRUCT_CONFIGPARSER_UNKNOWNKEY', $data);
$data = ['config' => &$this->config, 'key' => $key, 'val' => $val];
$ev = new Event('PLUGIN_STRUCT_CONFIGPARSER_UNKNOWNKEY', $data);
if ($ev->advise_before()) {
throw new StructException("unknown option '%s'", hsc($key));
}
@ -193,15 +194,15 @@ class ConfigParser
*/
protected function parseSchema($val)
{
$schemas = array();
$schemas = [];
$parts = explode(',', $val);
foreach ($parts as $part) {
@list($table, $alias) = array_pad(explode(' ', trim($part)), 2, '');
[$table, $alias] = sexplode(' ', trim($part), 2, '');
$table = trim($table);
$alias = trim($alias);
if (!$table) continue;
$schemas[] = array($table, $alias,);
$schemas[] = [$table, $alias];
}
return $schemas;
}
@ -215,7 +216,7 @@ class ConfigParser
protected function parseAlignments($val)
{
$cols = explode(',', $val);
$data = array();
$data = [];
foreach ($cols as $col) {
$col = trim(strtolower($col));
if ($col[0] == 'c') {
@ -243,6 +244,7 @@ class ConfigParser
{
$vals = explode(',', $val);
$vals = array_map('trim', $vals);
$len = count($vals);
for ($i = 0; $i < $len; $i++) {
$val = trim(strtolower($vals[$i]));
@ -271,7 +273,7 @@ class ConfigParser
*/
protected function parseValues($line)
{
$values = array();
$values = [];
$inQuote = false;
$escapedQuote = false;
$value = '';
@ -288,7 +290,7 @@ class ConfigParser
$escapedQuote = true;
continue;
}
array_push($values, $value);
$values[] = $value;
$inQuote = false;
$value = '';
continue;
@ -305,7 +307,7 @@ class ConfigParser
if (strlen($value) < 1) {
continue;
}
array_push($values, trim($value));
$values[] = trim($value);
$value = '';
continue;
}
@ -313,7 +315,7 @@ class ConfigParser
$value .= $line[$i];
}
if (strlen($value) > 0) {
array_push($values, trim($value));
$values[] = trim($value);
}
return $values;
}

View File

@ -18,103 +18,103 @@ namespace dokuwiki\plugin\struct\meta;
*/
class DateFormatConverter
{
protected static $strftime = array(
protected static $strftime = [
// Day
'%a' => 'D', // An abbreviated textual representation of the day Sun through Sat
'%A' => 'l', // A full textual representation of the day Sunday through Saturday
'%d' => 'd', // Two-digit day of the month (with leading zeros) 01 to 31
'%e' => 'j', // Day of the month, with a space preceding single digits. Not implemented as described on Windows. See below for more information. 1 to 31
'%j' => '', // NOT SUPPORTED Day of the year, 3 digits with leading zeros 001 to 366
'%u' => 'N', // ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
'%w' => 'w', // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
'%a' => 'D', // An abbreviated textual representation of the day Sun through Sat
'%A' => 'l', // A full textual representation of the day Sunday through Saturday
'%d' => 'd', // Two-digit day of the month (with leading zeros) 01 to 31
'%e' => 'j', // Day of the month, with a space preceding single digits. Not implemented as described on Windows. See below for more information. 1 to 31
'%j' => '', // NOT SUPPORTED Day of the year, 3 digits with leading zeros 001 to 366
'%u' => 'N', // ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
'%w' => 'w', // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
// Week
'%U' => '', // NOT SUPPORTED Week number of the given year, starting with the first Sunday as the first week 13 (for the 13th full week of the year)
'%V' => 'W', // ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week 01 through 53 (where 53 accounts for an overlapping week)
'%W' => '', // NOT SUPPORTED A numeric representation of the week of the year, starting with the first Monday as the first week 46 (for the 46th week of the year beginning with a Monday)
'%U' => '', // NOT SUPPORTED Week number of the given year, starting with the first Sunday as the first week 13 (for the 13th full week of the year)
'%V' => 'W', // ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week 01 through 53 (where 53 accounts for an overlapping week)
'%W' => '', // NOT SUPPORTED A numeric representation of the week of the year, starting with the first Monday as the first week 46 (for the 46th week of the year beginning with a Monday)
// Month
'%b' => 'M', // Abbreviated month name, based on the locale Jan through Dec
'%B' => 'F', // Full month name, based on the locale January through December
'%h' => 'M', // Abbreviated month name, based on the locale (an alias of %b) Jan through Dec
'%m' => 'm', // Two digit representation of the month 01 (for January) through 12 (for December)
'%b' => 'M', // Abbreviated month name, based on the locale Jan through Dec
'%B' => 'F', // Full month name, based on the locale January through December
'%h' => 'M', // Abbreviated month name, based on the locale (an alias of %b) Jan through Dec
'%m' => 'm', // Two digit representation of the month 01 (for January) through 12 (for December)
// Year
'%C' => '', // NOT SUPPORTED Two digit representation of the century (year divided by 100, truncated to an integer) 19 for the 20th Century
'%g' => 'y', // Two digit representation of the year going by ISO-8601:1988 standards (see %V) Example: 09 for the week of January 6, 2009
'%G' => 'Y', // The full four-digit version of %g Example: 2008 for the week of January 3, 2009
'%y' => 'y', // Two digit representation of the year Example: 09 for 2009, 79 for 1979
'%Y' => 'Y', // Four digit representation for the year Example: 2038
'%C' => '', // NOT SUPPORTED Two digit representation of the century (year divided by 100, truncated to an integer) 19 for the 20th Century
'%g' => 'y', // Two digit representation of the year going by ISO-8601:1988 standards (see %V) Example: 09 for the week of January 6, 2009
'%G' => 'Y', // The full four-digit version of %g Example: 2008 for the week of January 3, 2009
'%y' => 'y', // Two digit representation of the year Example: 09 for 2009, 79 for 1979
'%Y' => 'Y', // Four digit representation for the year Example: 2038
// Time
'%H' => 'H', // Two digit representation of the hour in 24-hour format 00 through 23
'%k' => 'G', // Two digit representation of the hour in 24-hour format, with a space preceding single digits 0 through 23
'%I' => 'h', // Two digit representation of the hour in 12-hour format 01 through 12
'%l' => 'g', // (lower-case 'L') Hour in 12-hour format, with a space preceding single digits 1 through 12
'%M' => 'i', // Two digit representation of the minute 00 through 59
'%p' => 'A', // UPPER-CASE 'AM' or 'PM' based on the given time Example: AM for 00:31, PM for 22:23
'%P' => 'a', // lower-case 'am' or 'pm' based on the given time Example: am for 00:31, pm for 22:23
'%r' => 'h:i:s A', // Same as %I:%M:%S %p Example: 09:34:17 PM for 21:34:17
'%R' => 'H:i', // Same as %H:%M Example: 00:35 for 12:35 AM, 16:44for 4:44 PM
'%S' => 's', // Two digit representation of the second 00 through 59
'%T' => 'H:i:s', // Same as %H:%M:%S Example: 21:34:17 for 09:34:17 PM
'%X' => 'H:i:s', // Preferred time representation based on locale, without the date Example: 03:59:16 or 15:59:16
'%z' => 'z', // The time zone offset. Not implemented as described on Windows. See below for more information. Example: -0500 for US Eastern Time
'%Z' => 'T', // The time zone abbreviation. Not implemented as described on Windows. See below for more information. Example: EST for Eastern Time
'%H' => 'H', // Two digit representation of the hour in 24-hour format 00 through 23
'%k' => 'G', // Two digit representation of the hour in 24-hour format, with a space preceding single digits 0 through 23
'%I' => 'h', // Two digit representation of the hour in 12-hour format 01 through 12
'%l' => 'g', // (lower-case 'L') Hour in 12-hour format, with a space preceding single digits 1 through 12
'%M' => 'i', // Two digit representation of the minute 00 through 59
'%p' => 'A', // UPPER-CASE 'AM' or 'PM' based on the given time Example: AM for 00:31, PM for 22:23
'%P' => 'a', // lower-case 'am' or 'pm' based on the given time Example: am for 00:31, pm for 22:23
'%r' => 'h:i:s A', // Same as %I:%M:%S %p Example: 09:34:17 PM for 21:34:17
'%R' => 'H:i', // Same as %H:%M Example: 00:35 for 12:35 AM, 16:44for 4:44 PM
'%S' => 's', // Two digit representation of the second 00 through 59
'%T' => 'H:i:s', // Same as %H:%M:%S Example: 21:34:17 for 09:34:17 PM
'%X' => 'H:i:s', // Preferred time representation based on locale, without the date Example: 03:59:16 or 15:59:16
'%z' => 'z', // The time zone offset. Not implemented as described on Windows. See below for more information. Example: -0500 for US Eastern Time
'%Z' => 'T', // The time zone abbreviation. Not implemented as described on Windows. See below for more information. Example: EST for Eastern Time
// Time and Date Stamps
'%c' => 'D M j H:i:s Y', // Preferred date and time stamp based on locale Example: Tue Feb 5 00:45:10 2009 for February 5, 2009 at 12:45:10 AM
'%D' => 'm/d/y', // Same as %m/%d/%y Example: 02/05/09 for February 5, 2009
'%F' => 'Y/m/d', // Same as %Y-%m-%d (commonly used in database datestamps) Example: 2009-02-05 for February 5, 2009
'%s' => 'U', // Unix Epoch Time timestamp (same as the time() function) Example: 305815200 for September 10, 1979 08:40:00 AM
'%x' => 'm/d/y', // Preferred date representation based on locale, without the time Example: 02/05/09 for February 5, 2009
'%c' => 'D M j H:i:s Y', // Preferred date and time stamp based on locale Example: Tue Feb 5 00:45:10 2009 for February 5, 2009 at 12:45:10 AM
'%D' => 'm/d/y', // Same as %m/%d/%y Example: 02/05/09 for February 5, 2009
'%F' => 'Y/m/d', // Same as %Y-%m-%d (commonly used in database datestamps) Example: 2009-02-05 for February 5, 2009
'%s' => 'U', // Unix Epoch Time timestamp (same as the time() function) Example: 305815200 for September 10, 1979 08:40:00 AM
'%x' => 'm/d/y', // Preferred date representation based on locale, without the time Example: 02/05/09 for February 5, 2009
// Miscellaneous
'%n' => "\n", // A newline character (\n) ---
'%t' => "\t", // A Tab character (\t) ---
'%%' => '%', // A literal percentage character (%) ---
);
'%%' => '%',
];
protected static $date = array(
protected static $date = [
// Day
'd' => '%d', // Day of the month, 2 digits with leading zeros 01 to 31
'D' => '%a', // A textual representation of a day, three letters Mon through Sun
'j' => '%e', // Day of the month without leading zeros 1 to 31
'l' => '%A', // (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday
'N' => '%u', // ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday)
'S' => '', // NOT SUPPORTED English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
'w' => '%w', // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
'z' => '', // NOT SUPPORTED The day of the year (starting from 0) 0 through 365
'd' => '%d', // Day of the month, 2 digits with leading zeros 01 to 31
'D' => '%a', // A textual representation of a day, three letters Mon through Sun
'j' => '%e', // Day of the month without leading zeros 1 to 31
'l' => '%A', // (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday
'N' => '%u', // ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday)
'S' => '', // NOT SUPPORTED English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
'w' => '%w', // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
'z' => '', // NOT SUPPORTED The day of the year (starting from 0) 0 through 365
// Week
'W' => '%V', // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) Example: 42 (the 42nd week in the year)
'W' => '%V', // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) Example: 42 (the 42nd week in the year)
// Month
'F' => '%B', // A full textual representation of a month, such as January or March January through December
'm' => '%m', // Numeric representation of a month, with leading zeros 01 through 12
'M' => '%b', // A short textual representation of a month, three letters Jan through Dec
'n' => '%m', // Numeric representation of a month, without leading zeros 1 through 12
't' => '', // NOT SUPPORTED Number of days in the given month 28 through 31
'F' => '%B', // A full textual representation of a month, such as January or March January through December
'm' => '%m', // Numeric representation of a month, with leading zeros 01 through 12
'M' => '%b', // A short textual representation of a month, three letters Jan through Dec
'n' => '%m', // Numeric representation of a month, without leading zeros 1 through 12
't' => '', // NOT SUPPORTED Number of days in the given month 28 through 31
// Year
'L' => '', // NOT SUPPORTED Whether it's a leap year 1 if it is a leap year, 0 otherwise.
'o' => '%g', // ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0) Examples: 1999or 2003
'Y' => '%Y', // A full numeric representation of a year, 4 digits Examples: 1999or 2003
'y' => '%y', // A two digit representation of a year Examples: 99 or03
'L' => '', // NOT SUPPORTED Whether it's a leap year 1 if it is a leap year, 0 otherwise.
'o' => '%g', // ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0) Examples: 1999or 2003
'Y' => '%Y', // A full numeric representation of a year, 4 digits Examples: 1999or 2003
'y' => '%y', // A two digit representation of a year Examples: 99 or03
// Time
'a' => '%P', // Lowercase Ante meridiem and Post meridiem am or pm
'A' => '%p', // Uppercase Ante meridiem and Post meridiem AM or PM
'B' => '', // NOT SUPPORTED Swatch Internet time 000 through 999
'g' => '%l', // 12-hour format of an hour without leading zeros 1 through 12
'G' => '%k', // 24-hour format of an hour without leading zeros 0 through 23
'h' => '%I', // 12-hour format of an hour with leading zeros 01 through 12
'H' => '%H', // 24-hour format of an hour with leading zeros 00 through 23
'i' => '%M', // Minutes with leading zeros 00 to 59
's' => '%S', // Seconds, with leading zeros 00 through 59
'u' => '%s000000', // Microseconds (added in PHP 5.2.2). Note that date() will always generate000000 since it takes an integer parameter, whereas DateTime::format()does support microseconds if DateTime was created with microseconds. Example: 654321
'a' => '%P', // Lowercase Ante meridiem and Post meridiem am or pm
'A' => '%p', // Uppercase Ante meridiem and Post meridiem AM or PM
'B' => '', // NOT SUPPORTED Swatch Internet time 000 through 999
'g' => '%l', // 12-hour format of an hour without leading zeros 1 through 12
'G' => '%k', // 24-hour format of an hour without leading zeros 0 through 23
'h' => '%I', // 12-hour format of an hour with leading zeros 01 through 12
'H' => '%H', // 24-hour format of an hour with leading zeros 00 through 23
'i' => '%M', // Minutes with leading zeros 00 to 59
's' => '%S', // Seconds, with leading zeros 00 through 59
'u' => '%s000000', // Microseconds (added in PHP 5.2.2). Note that date() will always generate000000 since it takes an integer parameter, whereas DateTime::format()does support microseconds if DateTime was created with microseconds. Example: 654321
// Timezone
'e' => '%Z', // Timezone identifier (added in PHP 5.1.0) Examples: UTC,GMT,Atlantic/Azores
'I' => '', // NOT SUPPORTED (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0otherwise.
'O' => '%z', // Difference to Greenwich time (GMT) in hours Example: +0200
'P' => '%z', // Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00
'T' => '%Z', // Timezone abbreviation Examples: EST,MDT ...
'Z' => '', // NOT SUPPORTED Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through50400
'e' => '%Z', // Timezone identifier (added in PHP 5.1.0) Examples: UTC,GMT,Atlantic/Azores
'I' => '', // NOT SUPPORTED (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0otherwise.
'O' => '%z', // Difference to Greenwich time (GMT) in hours Example: +0200
'P' => '%z', // Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00
'T' => '%Z', // Timezone abbreviation Examples: EST,MDT ...
'Z' => '', // NOT SUPPORTED Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through50400
// Full Date/Time
'c' => '', // NOT SUPPORTED ISO 8601 date (added in PHP 5) 2004-02-12T15:19:21+00:00
'r' => '%a, %e %b %Y %H:%M:%S %s', // » RFC 2822 formatted date Example: Thu, 21 Dec 2000 16:01:07 +0200
'U' => '%s', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) See also time()
);
'r' => '%a, %e %b %Y %H:%M:%S %s', // » RFC 2822 formatted date Example: Thu, 21 Dec 2000 16:01:07 +0200
'U' => '%s',
];
/**
* Convert a strftime format string to a date format string

View File

@ -7,7 +7,7 @@ namespace dokuwiki\plugin\struct\meta;
*/
class FilterValueListHandler
{
protected $row = array();
protected $row = [];
protected $current_row = 0;
protected $token = '';
@ -52,10 +52,8 @@ class FilterValueListHandler
*/
public function singleQuoteString($match, $state, $pos)
{
switch ($state) {
case DOKU_LEXER_UNMATCHED:
$this->token .= $match;
break;
if ($state === DOKU_LEXER_UNMATCHED) {
$this->token .= $match;
}
return true;
}

View File

@ -30,13 +30,12 @@ class InlineConfigParser extends ConfigParser
public function __construct($inline)
{
// Start to build the main config array
$lines = array(); // Config lines to pass to full parser
$lines = []; // Config lines to pass to full parser
// Extract components
$parts = explode('?', $inline, 2);
$n_parts = count($parts);
$components = str_getcsv(trim($parts[0]), '.');
$n_components = count($components);
// Extract parameters if given
$filtering = false; // First initialisation of the variable

View File

@ -109,7 +109,7 @@ class NestedResult
}
$valObj = array_shift($row);
if (!$valObj) return; // no more values to nest, usually shouldn't happen
if (!$valObj instanceof Value) return; // no more values to nest, usually shouldn't happen
$parentPath = (string) $parent;

View File

@ -138,7 +138,7 @@ class NestedValue
*/
public function __toString()
{
if ($this->value === null) return ''; // root node
if (!$this->value instanceof Value) return ''; // root node
return $this->parentPath . '/' . $this->value->__toString();
}
@ -151,8 +151,8 @@ class NestedValue
*/
public function sortChildren(NestedValue $a, NestedValue $b)
{
$compA = join('-', (array)$a->getValueObject()->getCompareValue());
$compB = join('-', (array)$b->getValueObject()->getCompareValue());
$compA = implode('-', (array)$a->getValueObject()->getCompareValue());
$compB = implode('-', (array)$b->getValueObject()->getCompareValue());
// sort empty values to the end
if ($compA === $compB) {
@ -184,7 +184,7 @@ class NestedValue
$return = '';
if ($this->value) {
$val = join(', ', (array)$this->value->getDisplayValue());
$val = implode(', ', (array)$this->value->getDisplayValue());
if ($val === '') $val = '{n/a}';
$return .= str_pad('', $this->getDepth() * 4, ' ');
$return .= $val;
@ -196,7 +196,7 @@ class NestedValue
foreach ($this->getResultRows() as $row) {
$return .= str_pad('', $this->getDepth() * 4, ' ');
foreach ($row as $value) {
$val = join(', ', (array)$value->getDisplayValue());
$val = implode(', ', (array)$value->getDisplayValue());
if ($val === '') $val = '{n/a}';
$return .= ' ' . $val;
}

View File

@ -8,10 +8,10 @@ class PageMeta
protected $sqlite;
protected $pid;
protected $title = null;
protected $lasteditor = null;
protected $lastrev = null;
protected $lastsummary = null;
protected $title;
protected $lasteditor;
protected $lastrev;
protected $lastsummary;
protected $saveNeeded = false;

View File

@ -9,19 +9,19 @@ namespace dokuwiki\plugin\struct\meta;
class QueryBuilder
{
/** @var array placeholder -> values */
protected $values = array();
protected $values = [];
/** @var array (alias -> statement */
protected $select = array();
protected $select = [];
/** @var array (alias -> statement) */
protected $from = array();
protected $from = [];
/** @var array (alias -> "table"|"join") keeps how tables were added, as table or join */
protected $type = array();
protected $type = [];
/** @var QueryBuilderWhere */
protected $where;
/** @var string[] */
protected $orderby = array();
protected $orderby = [];
/** @var string[] */
protected $groupby = array();
protected $groupby = [];
/**
* QueryBuilder constructor.
@ -118,7 +118,7 @@ class QueryBuilder
$pos = array_search($leftalias, array_keys($this->from));
$statement = "LEFT OUTER JOIN $righttable AS $rightalias ON $onclause";
$this->from = $this->arrayInsert($this->from, array($rightalias => $statement), $pos + 1);
$this->from = $this->arrayInsert($this->from, [$rightalias => $statement], $pos + 1);
$this->type[$rightalias] = 'join';
}
@ -221,24 +221,24 @@ class QueryBuilder
}
// prepare aliases for the select columns
$selects = array();
$selects = [];
foreach ($this->select as $alias => $select) {
$selects[] = "$select AS $alias";
}
$sql =
' SELECT ' . join(",\n", $selects) . "\n" .
' SELECT ' . implode(",\n", $selects) . "\n" .
' FROM ' . $from . "\n" .
' WHERE ' . $this->where->toSQL() . "\n";
if ($this->groupby) {
$sql .=
'GROUP BY ' . join(",\n", $this->groupby) . "\n";
'GROUP BY ' . implode(",\n", $this->groupby) . "\n";
}
if ($this->orderby) {
$sql .=
'ORDER BY ' . join(",\n", $this->orderby) . "\n";
'ORDER BY ' . implode(",\n", $this->orderby) . "\n";
}
return $this->fixPlaceholders($sql);
@ -254,7 +254,7 @@ class QueryBuilder
*/
protected function fixPlaceholders($sql)
{
$vals = array();
$vals = [];
while (preg_match('/(:!!val\d+!!:)/', $sql, $m)) {
$pl = $m[1];
@ -267,7 +267,7 @@ class QueryBuilder
$vals[] = $this->values[$pl];
}
return array($sql, $vals);
return [$sql, $vals];
}
/**

View File

@ -27,7 +27,7 @@ class QueryBuilderWhere
$this->QB = $QB;
$this->type = $type;
if ($statement === null) {
$this->statement = array();
$this->statement = [];
} else {
$this->statement = $statement;
}

View File

@ -33,7 +33,7 @@ class Schema
protected $table = '';
/** @var Column[] all the colums */
protected $columns = array();
protected $columns = [];
/** @var int */
protected $maxsort = 0;
@ -45,7 +45,7 @@ class Schema
protected $structversion = '?';
/** @var array config array with label translations */
protected $config = array();
protected $config = [];
/**
* Schema constructor
@ -55,7 +55,7 @@ class Schema
*/
public function __construct($table, $ts = 0)
{
$baseconfig = array('allowed editors' => '', 'internal' => false);
$baseconfig = ['allowed editors' => '', 'internal' => false];
/** @var \helper_plugin_struct_db $helper */
$helper = plugin_load('helper', 'struct_db');
@ -64,6 +64,7 @@ class Schema
$this->sqlite = $helper->getDB();
$table = self::cleanTableName($table);
$this->table = $table;
$this->ts = $ts;
// load info about the schema itself
@ -74,17 +75,17 @@ class Schema
AND ts <= ?
ORDER BY ts DESC
LIMIT 1";
$opt = array($table, $ts);
$opt = [$table, $ts];
} else {
$sql = "SELECT *
FROM schemas
WHERE tbl = ?
ORDER BY ts DESC
LIMIT 1";
$opt = array($table);
$opt = [$table];
}
$schema = $this->sqlite->queryAll($sql, $opt);
$config = array();
$config = [];
if (!empty($schema)) {
$result = array_shift($schema);
@ -94,7 +95,7 @@ class Schema
$config = json_decode($result['config'], true);
}
$this->config = array_merge($baseconfig, $config);
$this->initTransConfig(array('label'));
$this->initTransConfig(['label']);
if (!$this->id) return;
// load existing columns
@ -141,7 +142,7 @@ class Schema
*/
public function __toString()
{
return __CLASS__ . ' ' . $this->table . ' (' . $this->id . ') ';
return self::class . ' ' . $this->table . ' (' . $this->id . ') ';
}
/**
@ -170,11 +171,11 @@ class Schema
/** @var \helper_plugin_struct_db $helper */
$helper = plugin_load('helper', 'struct_db');
$db = $helper->getDB(false);
if (!$db) return array();
if (!$db instanceof SQLiteDB) return [];
$tables = $db->queryAll("SELECT DISTINCT tbl FROM schemas ORDER BY tbl");
$result = array();
$result = [];
foreach ($tables as $row) {
$result[] = $row['tbl'];
}
@ -208,12 +209,14 @@ class Schema
AND SC.sid = S.id
AND S.tbl = ?";
$sql = "DELETE FROM types WHERE id IN ($sql)";
$this->sqlite->query($sql, [$this->table]);
$sql = "SELECT id
FROM schemas
WHERE tbl = ?";
$sql = "DELETE FROM schema_cols WHERE sid IN ($sql)";
$this->sqlite->query($sql, [$this->table]);
$sql = "DELETE FROM schemas WHERE tbl = ?";
@ -224,7 +227,7 @@ class Schema
// a deleted schema should not be used anymore, but let's make sure it's somewhat sane anyway
$this->id = 0;
$this->columns = array();
$this->columns = [];
$this->maxsort = 0;
$this->ts = 0;
}
@ -308,7 +311,7 @@ class Schema
*/
public function isInternal()
{
return (bool) $this->config['internal'];
return (bool)$this->config['internal'];
}
/**
@ -342,7 +345,7 @@ class Schema
public function findColumn($name)
{
foreach ($this->columns as $col) {
if ($col->isEnabled() && PhpString::strtolower($col->getLabel()) == PhpString::strtolower($name)) {
if ($col->isEnabled() && PhpString::strtolower($col->getLabel()) === PhpString::strtolower($name)) {
return $col;
}
}
@ -370,25 +373,25 @@ class Schema
*/
public function toJSON()
{
$data = array(
$data = [
'structversion' => $this->structversion,
'schema' => $this->getTable(),
'id' => $this->getId(),
'user' => $this->getUser(),
'config' => $this->getConfig(),
'columns' => array()
);
'columns' => []
];
foreach ($this->columns as $column) {
$data['columns'][] = array(
$data['columns'][] = [
'colref' => $column->getColref(),
'ismulti' => $column->isMulti(),
'isenabled' => $column->isEnabled(),
'sort' => $column->getSort(),
'label' => $column->getLabel(),
'class' => $column->getType()->getClass(),
'config' => $column->getType()->getConfig(),
);
'config' => $column->getType()->getConfig()
];
}
return json_encode($data, JSON_PRETTY_PRINT);

View File

@ -2,6 +2,7 @@
namespace dokuwiki\plugin\struct\meta;
use dokuwiki\plugin\sqlite\SQLiteDB;
use dokuwiki\Utf8\PhpString;
/**
@ -23,7 +24,7 @@ class SchemaBuilder
* @var array The posted new data for the schema
* @see Schema::AdminEditor()
*/
protected $data = array();
protected $data = [];
protected $user;
@ -43,7 +44,7 @@ class SchemaBuilder
/** @var \helper_plugin_struct_db */
protected $helper;
/** @var \dokuwiki\plugin\sqlite\SQLiteDB|null */
/** @var SQLiteDB|null */
protected $sqlite;
/** @var int the time for which this schema should be created - default to time() can be overriden for tests */
@ -108,7 +109,7 @@ class SchemaBuilder
*/
protected function fixLabelUniqueness()
{
$labels = array();
$labels = [];
if (isset($this->data['cols'])) foreach ($this->data['cols'] as $idx => $column) {
$this->data['cols'][$idx]['label'] = $this->fixLabel($column['label'], $labels);
@ -135,7 +136,7 @@ class SchemaBuilder
$fixedlabel = $wantedlabel . $idx++;
}
// did we actually do a rename? apply it.
if ($fixedlabel != $wantedlabel) {
if ($fixedlabel !== $wantedlabel) {
msg(sprintf($this->helper->getLang('duplicate_label'), $wantedlabel, $fixedlabel), -1);
$this->data['cols']['label'] = $fixedlabel;
}
@ -197,13 +198,13 @@ class SchemaBuilder
}
// add this type to the schema columns
$schemaEntry = array(
$schemaEntry = [
'sid' => $this->newschemaid,
'colref' => $column->getColref(),
'enabled' => $enabled,
'tid' => $newTid,
'sort' => $sort
);
];
$ok = $this->sqlite->saveRecord('schema_cols', $schemaEntry);
if (!$ok) return false;
}
@ -221,8 +222,8 @@ class SchemaBuilder
/** @noinspection SqlResolve */
$sqlSelect = "SELECT pid, rev, published, col$colref AS value FROM data_$table WHERE latest = 1";
$valueSet = $this->sqlite->queryAll($sqlSelect);
$valueString = array();
$arguments = array();
$valueString = [];
$arguments = [];
foreach ($valueSet as $values) {
if (blank($values['value']) || trim($values['value']) == '') {
continue;
@ -233,10 +234,10 @@ class SchemaBuilder
[$colref, $values['pid'], $values['rev'], $values['published'], 1, $values['value']]
);
}
if (empty($valueString)) {
if ($valueString === []) {
return;
}
$valueString = join(',', $valueString);
$valueString = implode(',', $valueString);
/** @noinspection SqlResolve */
$sqlInsert = "INSERT OR REPLACE INTO multi_$table (colref, pid, rev, published, row, value) VALUES $valueString"; // phpcs:ignore
$this->sqlite->query($sqlInsert, $arguments);
@ -257,7 +258,7 @@ class SchemaBuilder
if (!$column['isenabled']) continue; // we do not add a disabled column
// todo this duplicates the hardcoding as in the function above
$newEntry = array();
$newEntry = [];
$newEntry['config'] = $column['config'] ?? '{}';
$newEntry['label'] = $column['label'];
$newEntry['ismulti'] = $column['ismulti'] ?? 0;
@ -282,13 +283,13 @@ class SchemaBuilder
// add this type to the schema columns
$schemaEntry = array(
$schemaEntry = [
'sid' => $this->newschemaid,
'colref' => $colref,
'enabled' => true,
'tid' => $newTid,
'sort' => $sort
);
];
$ok = $this->sqlite->saveRecord('schema_cols', $schemaEntry);
if (!$ok) return false;
$colref++;

View File

@ -2,6 +2,7 @@
namespace dokuwiki\plugin\struct\meta;
use dokuwiki\Extension\Plugin;
use dokuwiki\Form\Form;
use dokuwiki\plugin\struct\types\Text;
@ -18,7 +19,7 @@ class SchemaEditor
/** @var Schema the schema that is edited */
protected $schema;
/** @var \DokuWiki_Plugin */
/** @var Plugin */
protected $hlp;
/**
@ -41,7 +42,7 @@ class SchemaEditor
*/
public function getEditor()
{
$form = new Form(array('method' => 'POST', 'id' => 'plugin__struct_editor'));
$form = new Form(['method' => 'POST', 'id' => 'plugin__struct_editor']);
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'struct_schemas');
$form->setHiddenField('table', $this->schema->getTable());
@ -58,7 +59,7 @@ class SchemaEditor
</tr>");
foreach ($this->schema->getColumns() as $key => $col) {
foreach ($this->schema->getColumns() as $col) {
$form->addHTML($this->adminColumn($col->getColref(), $col));
}
@ -68,6 +69,7 @@ class SchemaEditor
$form->addHTML('</table>');
$form->addFieldsetOpen();
$config = json_encode($this->schema->getConfig(), JSON_PRETTY_PRINT);
$form->addHTML(
'<textarea name="schema[config]" id="schemaConfig" cols="45" rows="10" class="config">' .

View File

@ -54,12 +54,8 @@ class SchemaImporter extends SchemaBuilder
throw new StructException('JSON couldn\'t be decoded: ' . $error);
}
$config = isset($input['config']) ? $input['config'] : array();
$data = array(
'config' => json_encode($config),
'cols' => array(),
'new' => array(),
);
$config = $input['config'] ?? [];
$data = ['config' => json_encode($config), 'cols' => [], 'new' => []];
foreach ($input['columns'] as $column) {
// config has to stay json

View File

@ -2,6 +2,7 @@
namespace dokuwiki\plugin\struct\meta;
use dokuwiki\Parsing\Lexer\Lexer;
use dokuwiki\plugin\struct\types\AutoSummary;
use dokuwiki\plugin\struct\types\DateTime;
use dokuwiki\plugin\struct\types\Decimal;
@ -19,9 +20,7 @@ class Search
* The list of known and allowed comparators
* (order matters)
*/
public static $COMPARATORS = array(
'<=', '>=', '=*', '=', '<', '>', '!=', '!~', '~', ' IN '
);
public static $COMPARATORS = ['<=', '>=', '=*', '=', '<', '>', '!=', '!~', '~', ' IN '];
/** @var \helper_plugin_struct_db */
protected $dbHelper;
@ -30,22 +29,22 @@ class Search
protected $sqlite;
/** @var Schema[] list of schemas to query */
protected $schemas = array();
protected $schemas = [];
/** @var Column[] list of columns to select */
protected $columns = array();
protected $columns = [];
/** @var array the sorting of the result */
protected $sortby = array();
protected $sortby = [];
/** @var array the filters */
protected $filter = array();
protected $filter = [];
/** @var array the filters */
protected $dynamicFilter = array();
protected $dynamicFilter = [];
/** @var array list of aliases tables can be referenced by */
protected $aliases = array();
protected $aliases = [];
/** @var int begin results from here */
protected $range_begin = 0;
@ -56,7 +55,7 @@ class Search
/** @var int the number of results */
protected $count = -1;
/** @var string[] the PIDs of the result rows */
protected $result_pids = null;
protected $result_pids;
/** @var array the row ids of the result rows */
protected $result_rids = [];
/** @var array the revisions of the result rows */
@ -113,7 +112,7 @@ class Search
if ($colname[0] == '-') { // remove column from previous wildcard lookup
$colname = substr($colname, 1);
foreach ($this->columns as $key => $col) {
if ($col->getLabel() == $colname) unset($this->columns[$key]);
if ($col->getLabel() === $colname) unset($this->columns[$key]);
}
return;
}
@ -138,7 +137,7 @@ class Search
$col = $this->findColumn($colname);
if (!$col) return; //FIXME do we really want to ignore missing columns?
$this->sortby[$col->getFullQualifiedLabel()] = array($col, $asc, $nc);
$this->sortby[$col->getFullQualifiedLabel()] = [$col, $asc, $nc];
}
/**
@ -210,7 +209,7 @@ class Search
}
if (!in_array($comp, self::$COMPARATORS))
throw new StructException("Bad comperator. Use " . join(',', self::$COMPARATORS));
throw new StructException("Bad comperator. Use " . implode(',', self::$COMPARATORS));
if ($op != 'OR' && $op != 'AND')
throw new StructException('Bad filter type . Only AND or OR allowed');
@ -242,7 +241,7 @@ class Search
}
// add the filter
return array($col, $value, $comp, $op);
return [$col, $value, $comp, $op];
}
/**
@ -256,7 +255,7 @@ class Search
$Handler = new FilterValueListHandler();
$LexerClass = class_exists('\Doku_Lexer') ? '\Doku_Lexer' : '\dokuwiki\Parsing\Lexer\Lexer';
$isLegacy = $LexerClass === '\Doku_Lexer';
/** @var \Doku_Lexer|\dokuwiki\Parsing\Lexer\Lexer $Lexer */
/** @var \Doku_Lexer|Lexer $Lexer */
$Lexer = new $LexerClass($Handler, 'base', true);
@ -456,14 +455,14 @@ class Search
*/
public function execute()
{
list($sql, $opts) = $this->getSQL();
[$sql, $opts] = $this->getSQL();
/** @var \PDOStatement $res */
$res = $this->sqlite->query($sql, $opts);
if ($res === false) throw new StructException("SQL execution failed for\n\n$sql");
$this->result_pids = array();
$result = array();
$this->result_pids = [];
$result = [];
$cursor = -1;
$pageidAndRevOnly = array_reduce($this->columns, function ($pageidAndRevOnly, Column $col) {
return $pageidAndRevOnly && ($col->getTid() == 0);
@ -474,7 +473,7 @@ class Search
if ($this->range_end && $cursor >= $this->range_end) continue;
$C = 0;
$resrow = array();
$resrow = [];
$isempty = true;
foreach ($this->columns as $col) {
$val = $row["C$C"];
@ -567,7 +566,7 @@ class Search
*/
protected function processWildcard($colname)
{
list($colname, $table) = $this->resolveColumn($colname);
[$colname, $table] = $this->resolveColumn($colname);
if ($colname !== '*') return false;
// no table given? assume the first is meant
@ -577,7 +576,7 @@ class Search
}
$schema = $this->schemas[$table] ?? null;
if (!$schema) return false;
if (!$schema instanceof Schema) return false;
$this->columns = array_merge($this->columns, $schema->getColumns(false));
return true;
}
@ -595,7 +594,7 @@ class Search
if (!$this->schemas) throw new StructException('noschemas');
// resolve the alias or table name
@list($table, $colname) = array_pad(explode('.', $colname, 2), 2, '');
[$table, $colname] = sexplode('.', $colname, 2, '');
if (!$colname) {
$colname = $table;
$table = null;
@ -606,7 +605,7 @@ class Search
if (!$colname) throw new StructException('nocolname');
return array($colname, $table);
return [$colname, $table];
}
/**
@ -625,7 +624,7 @@ class Search
return new PageColumn(0, new Page(), $schema_list[0]);
}
if ($colname == '%title%') {
return new PageColumn(0, new Page(array('usetitles' => true)), $schema_list[0]);
return new PageColumn(0, new Page(['usetitles' => true]), $schema_list[0]);
}
if ($colname == '%lastupdate%') {
return new RevisionColumn(0, new DateTime(), $schema_list[0]);
@ -643,7 +642,7 @@ class Search
return new PublishedColumn(0, new Decimal(), $schema_list[0]);
}
list($colname, $table) = $this->resolveColumn($colname);
[$colname, $table] = $this->resolveColumn($colname);
/*
* If table name is given search only that, otherwise if no strict behavior
@ -651,7 +650,7 @@ class Search
* column name.
*/
if ($table !== null && isset($this->schemas[$table])) {
$schemas = array($table => $this->schemas[$table]);
$schemas = [$table => $this->schemas[$table]];
} elseif ($table === null || !$strict) {
$schemas = $this->schemas;
} else {

View File

@ -32,6 +32,7 @@ class SearchCloud extends SearchConfig
// add conditional page clauses if pid has a value
$subAnd = $QB->filters()->whereSubAnd();
$subAnd->whereAnd("$datatable.pid = ''");
$subOr = $subAnd->whereSubOr();
$subOr->whereAnd("GETACCESSLEVEL($datatable.pid) > 0");
$subOr->whereAnd("PAGEEXISTS($datatable.pid) = 1");
@ -80,7 +81,7 @@ class SearchCloud extends SearchConfig
$QB->addGroupByStatement('tag');
$QB->addOrderBy('count DESC');
list($sql, $opts) = $QB->getSQL();
[$sql, $opts] = $QB->getSQL();
return [$sql . $this->limit, $opts];
}
@ -103,7 +104,7 @@ class SearchCloud extends SearchConfig
*/
public function execute()
{
list($sql, $opts) = $this->getSQL();
[$sql, $opts] = $this->getSQL();
/** @var \PDOStatement $res */
$res = $this->sqlite->query($sql, $opts);

View File

@ -114,25 +114,25 @@ class SearchConfig extends Search
global $INPUT;
global $INFO;
if (!isset($INFO['id'])) {
$INFO['id'] = null;
$INFO['id'] = '';
}
// apply inexpensive filters first
$filter = str_replace(
array(
[
'$ID$',
'$NS$',
'$PAGE$',
'$USER$',
'$TODAY$'
),
array(
],
[
$INFO['id'],
getNS($INFO['id']),
noNS($INFO['id']),
$INPUT->server->str('REMOTE_USER'),
date('Y-m-d')
),
],
$filter
);
@ -176,7 +176,7 @@ class SearchConfig extends Search
$label = $column->getLabel();
$table = $column->getTable();
} else {
list($table, $label) = array_pad(explode('.', $key), 2, '');
[$table, $label] = sexplode('.', $key, 2, '');
}
// get the data from the current page
@ -188,7 +188,7 @@ class SearchConfig extends Search
}
$value = $data[$label]->getCompareValue();
if (is_array($value) && !count($value)) {
if (is_array($value) && $value === []) {
$value = '';
}
} else {
@ -197,7 +197,7 @@ class SearchConfig extends Search
// apply any pre and postfixes, even when multi value
if (is_array($value)) {
$filter = array();
$filter = [];
foreach ($value as $item) {
$filter[] = $match[1] . $item . $match[3];
}
@ -220,7 +220,7 @@ class SearchConfig extends Search
$key = strtolower($match[2]);
if (!in_array($key, array('name', 'mail', 'grps'))) {
if (!in_array($key, ['name', 'mail', 'grps'])) {
throw new StructException('"%s" is not a valid USER key', $key);
}

View File

@ -20,11 +20,11 @@ class SearchConfigParameters
protected $searchConfig;
/** @var null|array */
protected $sort = null;
protected $sort;
/** @var int */
protected $offset = 0;
/** @var array */
protected $filters = array();
protected $filters = [];
/**
* Initializes the dynamic parameters from $INPUT
@ -39,13 +39,13 @@ class SearchConfigParameters
$confHlp = plugin_load('helper', 'struct_config');
if ($INPUT->has(self::$PARAM_SORT)) {
list($colname, $sort) = $confHlp->parseSort($INPUT->str(self::$PARAM_SORT));
[$colname, $sort] = $confHlp->parseSort($INPUT->str(self::$PARAM_SORT));
$this->setSort($colname, $sort);
}
if ($INPUT->has(self::$PARAM_FILTER)) {
foreach ($INPUT->arr(self::$PARAM_FILTER) as $colcomp => $filter) {
list($colname, $comp, $value,) = $confHlp->parseFilterLine('AND', $colcomp . $filter);
[$colname, $comp, $value, ] = $confHlp->parseFilterLine('AND', $colcomp . $filter);
$this->addFilter($colname, $comp, $value);
}
}
@ -81,7 +81,7 @@ class SearchConfigParameters
{
$column = $this->resolveColumn($column);
if (!$column) return;
$this->sort = array($column, $asc);
$this->sort = [$column, $asc];
}
/**
@ -128,7 +128,7 @@ class SearchConfigParameters
if (trim($value) === '') {
$this->removeFilter($column);
} else {
$this->filters[$column] = array($comp, $value);
$this->filters[$column] = [$comp, $value];
}
}
@ -149,7 +149,7 @@ class SearchConfigParameters
*/
public function clearFilters()
{
$this->filters = array();
$this->filters = [];
}
/**
@ -171,20 +171,20 @@ class SearchConfigParameters
*/
public function getURLParameters()
{
$params = array();
$params = [];
if ($this->offset) {
$params[self::$PARAM_OFFSET] = $this->offset;
}
if ($this->sort) {
list($column, $asc) = $this->sort;
[$column, $asc] = $this->sort;
if (!$asc) $column = "^$column";
$params[self::$PARAM_SORT] = $column;
}
if ($this->filters) {
foreach ($this->filters as $column => $filter) {
list($comp, $value) = $filter;
[$comp, $value] = $filter;
$key = self::$PARAM_FILTER . '[' . $column . $comp . ']';
$params[$key] = $value;
}
@ -208,7 +208,7 @@ class SearchConfigParameters
}
foreach ($this->filters as $colName => $filter) {
list($comp, $value) = $filter;
[$comp, $value] = $filter;
$this->searchConfig->addDynamicFilter($colName, $value, $comp, 'AND');
}
}

View File

@ -123,7 +123,7 @@ class SearchSQLBuilder
foreach ($filters as $filter) {
/** @var Column $col */
list($col, $value, $comp, $op) = $filter;
[$col, $value, $comp, $op] = $filter;
$datatable = "data_{$col->getTable()}";
$multitable = "multi_{$col->getTable()}";
@ -161,7 +161,7 @@ class SearchSQLBuilder
public function addSorts($sorts)
{
foreach ($sorts as $sort) {
list($col, $asc, $nc) = $sort;
[$col, $asc, $nc] = $sort;
/** @var $col Column */
$colname = $col->getColName(false);
if ($nc) $colname .= ' COLLATE NOCASE';

View File

@ -13,7 +13,7 @@ trait TranslationUtilities
*
* @param string[] $keysToInitialize the keys for which to initialize language fields
*/
protected function initTransConfig(array $keysToInitialize = array('label', 'hint'))
protected function initTransConfig(array $keysToInitialize = ['label', 'hint'])
{
global $conf;
$lang = $conf['lang'];
@ -27,7 +27,7 @@ trait TranslationUtilities
foreach ($keysToInitialize as $key) {
if (!isset($this->config[$key])) {
$this->config[$key] = array();
$this->config[$key] = [];
}
// initialize missing keys
foreach ($langs as $lang) {

View File

@ -18,13 +18,13 @@ class Value
protected $value;
/** @var array|int|string */
protected $rawvalue = null;
protected $rawvalue;
/** @var array|int|string */
protected $display = null;
protected $display;
/** @var array|int|string */
protected $compare = null;
protected $compare;
/** @var bool is this a raw value only? */
protected $rawonly = false;
@ -110,14 +110,14 @@ class Value
// treat all givens the same
if (!is_array($value)) {
$value = array($value);
$value = [$value];
}
// reset/init
$this->value = array();
$this->rawvalue = array();
$this->display = array();
$this->compare = array();
$this->value = [];
$this->rawvalue = [];
$this->display = [];
$this->compare = [];
// remove all blanks
foreach ($value as $val) {
@ -154,7 +154,7 @@ class Value
*/
public function isEmpty()
{
return ($this->rawvalue === '' || $this->rawvalue === array());
return ($this->rawvalue === '' || $this->rawvalue === []);
}
/**
@ -174,10 +174,8 @@ class Value
if (count($this->value)) {
return $this->column->getType()->renderMultiValue($this->value, $R, $mode);
}
} else {
if ($this->value !== '') {
return $this->column->getType()->renderValue($this->value, $R, $mode);
}
} elseif ($this->value !== '') {
return $this->column->getType()->renderValue($this->value, $R, $mode);
}
return true;
}
@ -231,6 +229,6 @@ class Value
public function __toString()
{
return '[' . $this->getColumn()->getFullQualifiedLabel() . '] ' .
join(',', (array)$this->getRawValue());
implode(',', (array)$this->getRawValue());
}
}

View File

@ -13,7 +13,7 @@ class ValueValidator
protected $hlp;
/** @var array list of validation errors */
protected $errors;
protected $errors = [];
/**
* ValueValidator constructor.
@ -21,7 +21,6 @@ class ValueValidator
public function __construct()
{
$this->hlp = plugin_load('helper', 'struct_db');
$this->errors = array();
}
/**
@ -44,7 +43,7 @@ class ValueValidator
// strip empty fields from multi vals
// but keep at least one so we can properly delete multivalues on update
if (is_array($rawvalue) && count($rawvalue) > 1) {
$rawvalue = array_filter($rawvalue, array($this, 'filter'));
$rawvalue = array_filter($rawvalue, [$this, 'filter']);
$rawvalue = array_values($rawvalue); // reset the array keys
}

View File

@ -8,11 +8,14 @@
*/
// must be run within Dokuwiki
use dokuwiki\Extension\RemotePlugin;
use dokuwiki\Remote\AccessDeniedException;
use dokuwiki\plugin\struct\meta\Value;
use dokuwiki\plugin\struct\meta\ConfigParser;
use dokuwiki\plugin\struct\meta\SearchConfig;
use dokuwiki\plugin\struct\meta\StructException;
class remote_plugin_struct extends DokuWiki_Remote_Plugin
class remote_plugin_struct extends RemotePlugin
{
/** @var helper_plugin_struct hlp */
protected $hlp;
@ -24,7 +27,6 @@ class remote_plugin_struct extends DokuWiki_Remote_Plugin
{
parent::__construct();
/** @var helper_plugin_struct hlp */
$this->hlp = plugin_load('helper', 'struct');
}
@ -43,7 +45,7 @@ class remote_plugin_struct extends DokuWiki_Remote_Plugin
$page = cleanID($page);
if (auth_quickaclcheck($page) < AUTH_READ) {
throw new RemoteAccessDeniedException('no permissions to access data of that page');
throw new AccessDeniedException('no permissions to access data of that page');
}
if (!$schema) $schema = null;
@ -51,7 +53,7 @@ class remote_plugin_struct extends DokuWiki_Remote_Plugin
try {
return $this->hlp->getData($page, $schema, $time);
} catch (StructException $e) {
throw new RemoteException($e->getMessage(), 0, $e);
throw new \dokuwiki\Remote\RemoteException($e->getMessage(), 0, $e);
}
}
@ -76,14 +78,14 @@ class remote_plugin_struct extends DokuWiki_Remote_Plugin
$page = cleanID($page);
if (auth_quickaclcheck($page) < AUTH_EDIT) {
throw new RemoteAccessDeniedException('no permissions to save data for that page');
throw new AccessDeniedException('no permissions to save data for that page');
}
try {
$this->hlp->saveData($page, $data, $summary, $minor);
return true;
} catch (StructException $e) {
throw new RemoteException($e->getMessage(), 0, $e);
throw new \dokuwiki\Remote\RemoteException($e->getMessage(), 0, $e);
}
}
@ -100,25 +102,26 @@ class remote_plugin_struct extends DokuWiki_Remote_Plugin
public function getSchema($schema = null)
{
if (!auth_ismanager()) {
throw new RemoteAccessDeniedException('you need to be manager to access schema info');
throw new AccessDeniedException('you need to be manager to access schema info');
}
try {
$result = array();
$result = [];
$schemas = $this->hlp::getSchema($schema ?: null);
foreach ($schemas as $name => $schema) {
$result[$name] = array();
$result[$name] = [];
foreach ($schema->getColumns(false) as $column) {
$result[$name][] = array(
$class = explode('\\', get_class($column->getType()));
$class = array_pop($class);
$result[$name][] = [
'name' => $column->getLabel(),
'type' => array_pop(explode('\\', get_class($column->getType()))),
'ismulti' => $column->isMulti()
);
'type' => $class,
'ismulti' => $column->isMulti()];
}
}
return $result;
} catch (StructException $e) {
throw new RemoteException($e->getMessage(), 0, $e);
throw new \dokuwiki\Remote\RemoteException($e->getMessage(), 0, $e);
}
}
@ -149,7 +152,7 @@ class remote_plugin_struct extends DokuWiki_Remote_Plugin
$search = new SearchConfig($config);
$results = $search->execute();
$data = [];
/** @var \dokuwiki\plugin\struct\meta\Value[] $rowValues */
/** @var Value[] $rowValues */
foreach ($results as $rowValues) {
$row = [];
foreach ($rowValues as $value) {
@ -159,7 +162,7 @@ class remote_plugin_struct extends DokuWiki_Remote_Plugin
}
return $data;
} catch (StructException $e) {
throw new RemoteException($e->getMessage(), 0, $e);
throw new \dokuwiki\Remote\RemoteException($e->getMessage(), 0, $e);
}
}
}

View File

@ -24,7 +24,7 @@ class renderer_plugin_struct_csv extends Doku_Renderer
global $INPUT;
if (
!isset($this->info['struct_table_hash']) or
!isset($this->info['struct_table_hash']) ||
$this->info['struct_table_hash'] != $INPUT->str('hash')
) {
return false;
@ -53,12 +53,12 @@ class renderer_plugin_struct_csv extends Doku_Renderer
public function document_start()
{
global $ID;
$filename = noNS($ID) . '.csv';
$headers = array(
$filename = noNS($ID ?? 'data') . '.csv';
$headers = [
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="' . $filename . '";'
);
p_set_metadata($ID, array('format' => array('struct_csv' => $headers)));
];
p_set_metadata($ID, ['format' => ['struct_csv' => $headers]]);
// don't cache
$this->nocache();
}
@ -147,7 +147,7 @@ class renderer_plugin_struct_csv extends Doku_Renderer
public function internallink($link, $title = null)
{
if (is_null($title) or is_array($title) or $title == '') {
if (is_null($title) || is_array($title) || $title == '') {
$title = $this->_simpleTitle($link);
}
$this->cdata($title);
@ -155,7 +155,7 @@ class renderer_plugin_struct_csv extends Doku_Renderer
public function externallink($link, $title = null)
{
if (is_null($title) or is_array($title) or $title == '') {
if (is_null($title) || is_array($title) || $title == '') {
$title = $link;
}
$this->cdata($title);
@ -247,7 +247,7 @@ class renderer_plugin_struct_csv extends Doku_Renderer
public function locallink($hash, $name = null)
{
if (is_null($name) or is_array($name) or $name == '') {
if (is_null($name) || is_array($name) || $name == '') {
$name = $hash;
}
$this->cdata($name);
@ -255,7 +255,7 @@ class renderer_plugin_struct_csv extends Doku_Renderer
public function interwikilink($link, $title, $wikiName, $wikiUri)
{
if (is_array($title) or $title == '') {
if (is_array($title) || $title == '') {
$title = $wikiName . '>' . $link;
}
$this->cdata($title);
@ -263,7 +263,7 @@ class renderer_plugin_struct_csv extends Doku_Renderer
public function filelink($link, $title = null)
{
if (is_null($title) or is_array($title) or $title == '') {
if (is_null($title) || is_array($title) || $title == '') {
$title = $link;
}
$this->cdata($title);
@ -271,7 +271,7 @@ class renderer_plugin_struct_csv extends Doku_Renderer
public function windowssharelink($link, $title = null)
{
if (is_null($title) or is_array($title) or $title == '') {
if (is_null($title) || is_array($title) || $title == '') {
$title = $link;
}
$this->cdata($title);

View File

@ -7,12 +7,13 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\SyntaxPlugin;
use dokuwiki\plugin\struct\meta\AggregationCloud;
use dokuwiki\plugin\struct\meta\ConfigParser;
use dokuwiki\plugin\struct\meta\SearchCloud;
use dokuwiki\plugin\struct\meta\StructException;
class syntax_plugin_struct_cloud extends DokuWiki_Syntax_Plugin
class syntax_plugin_struct_cloud extends SyntaxPlugin
{
/**
* @return string Syntax mode type

View File

@ -7,6 +7,7 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\plugin\struct\meta\AccessTablePage;
use dokuwiki\plugin\struct\meta\AggregationEditorTable;
class syntax_plugin_struct_global extends syntax_plugin_struct_table
@ -58,7 +59,7 @@ class syntax_plugin_struct_global extends syntax_plugin_struct_table
{
$config['filter'][] = [
'%rowid%', '!=',
(string)\dokuwiki\plugin\struct\meta\AccessTablePage::DEFAULT_PAGE_RID, 'AND'
(string)AccessTablePage::DEFAULT_PAGE_RID, 'AND'
];
$config['filter'][] = ['%pageid%', '=*', '^(?![\s\S])', 'AND'];
$config['withpid'] = 0; // flag for the editor to distinguish data types

View File

@ -7,11 +7,13 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\SyntaxPlugin;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\StructException;
class syntax_plugin_struct_output extends DokuWiki_Syntax_Plugin
class syntax_plugin_struct_output extends SyntaxPlugin
{
protected $hasBeenRendered = false;
@ -72,7 +74,7 @@ class syntax_plugin_struct_output extends DokuWiki_Syntax_Plugin
public function handle($match, $state, $pos, Doku_Handler $handler)
{
// this is never called
return array();
return [];
}
/**
@ -122,15 +124,15 @@ class syntax_plugin_struct_output extends DokuWiki_Syntax_Plugin
continue; // no such schema at this revision
}
$rendercontext = array(
$rendercontext = [
'renderer' => $renderer,
'format' => $format,
'meta' => p_get_metadata($ID),
'schemadata' => $schemadata,
'hasdata' => &$hasdata
);
];
$event = new \Doku_Event(
$event = new Event(
'PLUGIN_STRUCT_RENDER_SCHEMA_DATA',
$rendercontext
);

View File

@ -7,13 +7,14 @@
* @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
*/
use dokuwiki\Extension\SyntaxPlugin;
use dokuwiki\plugin\struct\meta\Aggregation;
use dokuwiki\plugin\struct\meta\AggregationTable;
use dokuwiki\plugin\struct\meta\ConfigParser;
use dokuwiki\plugin\struct\meta\SearchConfig;
use dokuwiki\plugin\struct\meta\StructException;
class syntax_plugin_struct_table extends DokuWiki_Syntax_Plugin
class syntax_plugin_struct_table extends SyntaxPlugin
{
/** @var string which class to use for output */
protected $tableclass = AggregationTable::class;
@ -116,7 +117,7 @@ class syntax_plugin_struct_table extends DokuWiki_Syntax_Plugin
}
$table = new $this->tableclass($mainId, $format, $renderer, $search);
if (!is_a($table, Aggregation::class)) {
if (!$table instanceof Aggregation) {
// this may happen with plugins that extend struct
throw new StructException('Aggregation class does not inherit Aggregation: ' . $this->tableclass);
}

View File

@ -8,14 +8,14 @@
*/
// phpcs:disable PSR1.Files.SideEffects
use dokuwiki\Extension\SyntaxPlugin;
use dokuwiki\plugin\struct\meta\AggregationValue;
use dokuwiki\plugin\struct\meta\InlineConfigParser;
use dokuwiki\plugin\struct\meta\SearchConfig;
use dokuwiki\plugin\struct\meta\StructException;
// phpcs:ignore PSR1.Classes.ClassDeclaration, Squiz.Classes.ValidClassName
class syntax_plugin_struct_value extends DokuWiki_Syntax_Plugin
class syntax_plugin_struct_value extends SyntaxPlugin
{
/**
* @return string Syntax mode type

View File

@ -2,6 +2,7 @@
namespace dokuwiki\plugin\struct\types;
use dokuwiki\Extension\Plugin;
use dokuwiki\plugin\struct\meta\Column;
use dokuwiki\plugin\struct\meta\QueryBuilder;
use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
@ -28,12 +29,12 @@ abstract class AbstractBaseType
/**
* @var array current config
*/
protected $config = array();
protected $config = [];
/**
* @var array config keys that should not be cleaned despite not being in $config
*/
protected $keepconfig = array('label', 'hint', 'visibility');
protected $keepconfig = ['label', 'hint', 'visibility'];
/**
* @var string label for the field
@ -53,12 +54,12 @@ abstract class AbstractBaseType
/**
* @var null|Column the column context this type is part of
*/
protected $context = null;
protected $context;
/**
* @var \DokuWiki_Plugin
* @var Plugin
*/
protected $hlp = null;
protected $hlp;
/**
* AbstractBaseType constructor.
@ -70,12 +71,12 @@ abstract class AbstractBaseType
public function __construct($config = null, $label = '', $ismulti = false, $tid = 0)
{
// general config options
$baseconfig = array(
'visibility' => array(
$baseconfig = [
'visibility' => [
'inpage' => true,
'ineditor' => true,
)
);
'ineditor' => true
]
];
// use previously saved configuration, ignoring all keys that are not supposed to be here
if (!is_null($config)) {
@ -117,12 +118,12 @@ abstract class AbstractBaseType
*/
public function getAsEntry()
{
return array(
return [
'config' => json_encode($this->config),
'label' => $this->label,
'ismulti' => $this->ismulti,
'class' => $this->getClass()
);
];
}
/**
@ -295,12 +296,12 @@ abstract class AbstractBaseType
$class .= ' struct_autocomplete';
}
$params = array(
$params = [
'name' => $name,
'value' => $rawvalue,
'class' => $class,
'id' => $htmlID
);
];
$attributes = buildAttributes($params, true);
return "<input $attributes>";
}

View File

@ -22,7 +22,7 @@ abstract class AbstractMultiBaseType extends AbstractBaseType
*/
public function multiValueEditor($name, $rawvalues, $htmlID)
{
$value = join(', ', $rawvalues);
$value = implode(', ', $rawvalues);
return
'<div class="multiwrap">' .

View File

@ -58,6 +58,5 @@ class AutoSummary extends AbstractBaseType
$sub = $add->where($op);
$pl = $QB->addValue($value);
$sub->whereOr("$rightalias.lastsummary $comp $pl");
return;
}
}

View File

@ -4,9 +4,7 @@ namespace dokuwiki\plugin\struct\types;
class Checkbox extends AbstractBaseType
{
protected $config = array(
'values' => 'one, two, three',
);
protected $config = ['values' => 'one, two, three'];
/**
* Creates the options array
@ -41,14 +39,14 @@ class Checkbox extends AbstractBaseType
$checked = '';
}
$opt = hsc($opt);
$params = array(
$params = [
'name' => $name,
'value' => $opt,
'class' => 'struct_' . strtolower($this->getClass()),
'type' => 'checkbox',
'id' => $htmlID,
'checked' => $checked,
);
'checked' => $checked
];
$attributes = buildAttributes($params, true);
return "<label><input $attributes>&nbsp;$opt</label>";
}
@ -74,14 +72,14 @@ class Checkbox extends AbstractBaseType
$checked = '';
}
$params = array(
$params = [
'name' => $name . '[]',
'value' => $opt,
'class' => $class,
'type' => 'checkbox',
'id' => $htmlID,
'checked' => $checked,
);
'checked' => $checked
];
$attributes = buildAttributes($params, true);
$htmlID = '';

View File

@ -6,9 +6,9 @@ use dokuwiki\plugin\struct\meta\ValidationException;
class Color extends AbstractBaseType
{
protected $config = array(
protected $config = [
'default' => '#ffffff'
);
];
/**
* @inheritDoc
@ -21,7 +21,7 @@ class Color extends AbstractBaseType
}
// ignore if default
if ($rawvalue == strtolower($this->config['default'])) {
if ($rawvalue === strtolower($this->config['default'])) {
$rawvalue = '';
}
@ -53,7 +53,7 @@ class Color extends AbstractBaseType
$this->renderValue($value, $R, $mode);
}
} else {
$R->cdata(join(', ', $values));
$R->cdata(implode(', ', $values));
}
return true;
}
@ -68,13 +68,13 @@ class Color extends AbstractBaseType
$rawvalue = $this->config['default'];
}
$params = array(
$params = [
'name' => $name,
'value' => $rawvalue,
'class' => 'struct_color',
'type' => 'color',
'id' => $htmlID
);
];
$attributes = buildAttributes($params, true);
return "<input $attributes />";
}
@ -125,16 +125,16 @@ class Color extends AbstractBaseType
$min = min([$red, $green, $blue]);
$max = max([$red, $green, $blue]);
if ($max == $red) {
if ($max === $red) {
$hue = ($green - $blue) / ($max - $min);
}
if ($max == $green) {
if ($max === $green) {
$hue = 2 + ($blue - $red) / ($max - $min);
}
if ($max == $blue) {
if ($max === $blue) {
$hue = 4 + ($red - $green) / ($max - $min);
}
$hue = $hue * 60;
$hue *= 60;
if ($hue < 0) {
$hue += 360;
}

View File

@ -6,12 +6,12 @@ use dokuwiki\plugin\struct\meta\ValidationException;
class Date extends AbstractBaseType
{
protected $config = array(
protected $config = [
'format' => 'Y/m/d',
'prefilltoday' => false,
'pastonly' => false,
'futureonly' => false
);
];
/**
* Output the stored data
@ -49,13 +49,13 @@ class Date extends AbstractBaseType
$rawvalue = date('Y-m-d');
}
$params = array(
$params = [
'name' => $name,
'value' => $rawvalue,
'class' => 'struct_date',
'type' => 'date', // HTML5 date picker
'type' => 'date', // HTML5 date picker
'id' => $htmlID,
);
];
$attributes = buildAttributes($params, true);
return "<input $attributes />";
}
@ -73,9 +73,9 @@ class Date extends AbstractBaseType
public function validate($rawvalue)
{
$rawvalue = parent::validate($rawvalue);
list($rawvalue) = explode(' ', $rawvalue, 2); // strip off time if there is any
[$rawvalue] = explode(' ', $rawvalue, 2); // strip off time if there is any
list($year, $month, $day) = explode('-', $rawvalue, 3);
[$year, $month, $day] = explode('-', $rawvalue, 3);
if (!checkdate((int)$month, (int)$day, (int)$year)) {
throw new ValidationException('invalid date format');
}

View File

@ -9,12 +9,12 @@ use dokuwiki\plugin\struct\meta\ValidationException;
class DateTime extends Date
{
protected $config = array(
protected $config = [
'format' => '', // filled by constructor
'prefilltoday' => false,
'pastonly' => false,
'futureonly' => false
);
'futureonly' => false,
];
/**
* DateTime constructor.
@ -47,13 +47,13 @@ class DateTime extends Date
$rawvalue = date('Y-m-d\TH:i');
}
$rawvalue = str_replace(' ', 'T', $rawvalue);
$params = array(
$params = [
'name' => $name,
'value' => $rawvalue,
'class' => 'struct_datetime',
'type' => 'datetime-local', // HTML5 datetime picker
'id' => $htmlID,
);
];
$attributes = buildAttributes($params, true);
return "<input $attributes />";
}
@ -71,11 +71,11 @@ class DateTime extends Date
public function validate($rawvalue)
{
$rawvalue = trim($rawvalue);
list($date, $time) = array_pad(preg_split('/[ |T]/', $rawvalue, 2), 2, '');
[$date, $time] = array_pad(preg_split('/[ |T]/', $rawvalue, 2), 2, '');
$date = trim($date);
$time = trim($time);
list($year, $month, $day) = explode('-', $date, 3);
[$year, $month, $day] = explode('-', $date, 3);
if (!checkdate((int)$month, (int)$day, (int)$year)) {
throw new ValidationException('invalid datetime format');
}
@ -86,7 +86,7 @@ class DateTime extends Date
throw new ValidationException('futureonly');
}
list($h, $m) = array_pad(explode(':', $time, 3), 2, ''); // drop seconds
[$h, $m] = array_pad(explode(':', $time, 3), 2, ''); // drop seconds
$h = (int)$h;
$m = (int)$m;
if ($h < 0 || $h > 23 || $m < 0 || $m > 59) {

View File

@ -15,7 +15,7 @@ use dokuwiki\plugin\struct\meta\ValidationException;
*/
class Decimal extends AbstractMultiBaseType
{
protected $config = array(
protected $config = [
'min' => '',
'max' => '',
'roundto' => '-1',
@ -24,8 +24,8 @@ class Decimal extends AbstractMultiBaseType
'trimzeros' => true,
'prefix' => '',
'postfix' => '',
'engineering' => false
);
'engineering' => false,
];
/**
* Output the stored data
@ -39,8 +39,8 @@ class Decimal extends AbstractMultiBaseType
{
if ($this->config['engineering']) {
$unitsh = array('', 'k', 'M', 'G', 'T');
$unitsl = array('', 'm', 'µ', 'n', 'p', 'f', 'a');
$unitsh = ['', 'k', 'M', 'G', 'T'];
$unitsl = ['', 'm', 'µ', 'n', 'p', 'f', 'a'];
$exp = floor(log10($value) / 3);
@ -53,7 +53,7 @@ class Decimal extends AbstractMultiBaseType
}
if (count($units) <= ($pfkey + 1)) { //check if number is within prefixes
$pfkey = sizeof($units) - 1;
$pfkey = count($units) - 1;
$exp = $pfkey * $exp / abs($exp);
}
@ -73,7 +73,7 @@ class Decimal extends AbstractMultiBaseType
$this->config['thousands']
);
} else {
$value = floatval($value);
$value = (float) $value;
$value = number_format(
$value,
(int)$this->config['roundto'],
@ -101,16 +101,16 @@ class Decimal extends AbstractMultiBaseType
$rawvalue = parent::validate($rawvalue);
$rawvalue = str_replace(',', '.', $rawvalue); // we accept both
if ((string)$rawvalue != (string)floatval($rawvalue)) {
if ((string)$rawvalue != (string)(float) $rawvalue) {
throw new ValidationException('Decimal needed');
}
if ($this->config['min'] !== '' && floatval($rawvalue) < floatval($this->config['min'])) {
throw new ValidationException('Decimal min', floatval($this->config['min']));
if ($this->config['min'] !== '' && (float) $rawvalue < (float) $this->config['min']) {
throw new ValidationException('Decimal min', (float) $this->config['min']);
}
if ($this->config['max'] !== '' && floatval($rawvalue) > floatval($this->config['max'])) {
throw new ValidationException('Decimal max', floatval($this->config['max']));
if ($this->config['max'] !== '' && (float) $rawvalue > (float) $this->config['max']) {
throw new ValidationException('Decimal max', (float) $this->config['max']);
}
return $rawvalue;
@ -131,7 +131,7 @@ class Decimal extends AbstractMultiBaseType
$was_neg = $number < 0; // Because +0 == -0
$tmp = explode('.', $number);
$out = number_format(abs(floatval($tmp[0])), 0, $dec_point, $thousands_sep);
$out = number_format(abs((float) $tmp[0]), 0, $dec_point, $thousands_sep);
if (isset($tmp[1])) $out .= $dec_point . $tmp[1];
if ($was_neg) $out = "-$out";
@ -165,7 +165,8 @@ class Decimal extends AbstractMultiBaseType
public function filter(QueryBuilderWhere $add, $tablealias, $colname, $comp, $value, $op)
{
$add = $add->where($op); // open a subgroup
$add->where('AND', "$tablealias.$colname != ''"); // make sure the field isn't empty
$add->where('AND', "$tablealias.$colname != ''");
// make sure the field isn't empty
$op = 'AND';
/** @var QueryBuilderWhere $add Where additionional queries are added to */

View File

@ -4,9 +4,9 @@ namespace dokuwiki\plugin\struct\types;
class Dropdown extends AbstractBaseType
{
protected $config = array(
'values' => 'one, two, three',
);
protected $config = [
'values' => 'one, two, three'
];
/**
* Creates the options array
@ -32,11 +32,11 @@ class Dropdown extends AbstractBaseType
*/
public function valueEditor($name, $rawvalue, $htmlID)
{
$params = array(
$params = [
'name' => $name,
'class' => 'struct_' . strtolower($this->getClass()),
'id' => $htmlID
);
];
$attributes = buildAttributes($params, true);
$html = "<select $attributes>";
foreach ($this->getOptions() as $opt => $val) {
@ -64,13 +64,13 @@ class Dropdown extends AbstractBaseType
*/
public function multiValueEditor($name, $rawvalues, $htmlID)
{
$params = array(
$params = [
'name' => $name . '[]',
'class' => 'struct_' . strtolower($this->getClass()),
'multiple' => 'multiple',
'size' => '5',
'id' => $htmlID
);
];
$attributes = buildAttributes($params, true);
$html = "<select $attributes>";
foreach ($this->getOptions() as $raw => $opt) {

View File

@ -6,12 +6,12 @@ class LongText extends AbstractMultiBaseType
{
use TraitFilterPrefix;
protected $config = array(
protected $config = [
'prefix' => '',
'postfix' => '',
'rows' => '5',
'cols' => '50'
);
];
/**
@ -58,13 +58,13 @@ class LongText extends AbstractMultiBaseType
public function valueEditor($name, $rawvalue, $htmlID)
{
$rawvalue = formText($rawvalue);
$params = array(
$params = [
'name' => $name,
'class' => 'struct_' . strtolower($this->getClass()),
'id' => $htmlID,
'rows' => $this->config['rows'],
'cols' => $this->config['cols']
);
];
$attributes = buildAttributes($params, true);
return "<textarea $attributes>$rawvalue</textarea>";

View File

@ -16,13 +16,10 @@ use dokuwiki\plugin\struct\meta\Value;
class Lookup extends Dropdown
{
protected $config = array(
'schema' => '',
'field' => ''
);
protected $config = ['schema' => '', 'field' => ''];
/** @var Column caches the referenced column */
protected $column = null;
protected $column;
/**
* Dropdown constructor.
@ -45,7 +42,7 @@ class Lookup extends Dropdown
*/
protected function getLookupColumn()
{
if ($this->column !== null) return $this->column;
if ($this->column instanceof Column) return $this->column;
$this->column = $this->getColumn($this->config['schema'], $this->config['field']);
return $this->column;
}
@ -80,7 +77,7 @@ class Lookup extends Dropdown
$column = new PageColumn(0, new Page(), $table);
}
if ($infield == '%title%') {
$column = new PageColumn(0, new Page(array('usetitles' => true)), $table);
$column = new PageColumn(0, new Page(['usetitles' => true]), $table);
}
if ($infield == '%lastupdate%') {
$column = new RevisionColumn(0, new DateTime(), $table);
@ -119,20 +116,20 @@ class Lookup extends Dropdown
{
$schema = $this->config['schema'];
$column = $this->getLookupColumn();
if (!$column) return array();
if (!$column) return [];
$field = $column->getLabel();
$search = new Search();
$search->addSchema($schema);
$search->addColumn($field);
$search->addSort($field);
$result = $search->execute();
$pids = $search->getPids();
$rids = $search->getRids();
$len = count($result);
/** @var Value[][] $result */
$options = array('' => '');
$options = ['' => ''];
for ($i = 0; $i < $len; $i++) {
$val = json_encode([$pids[$i], (int)$rids[$i]]);
$options[$val] = $result[$i][0]->getDisplayValue();
@ -151,7 +148,7 @@ class Lookup extends Dropdown
*/
public function renderValue($value, \Doku_Renderer $R, $mode)
{
list(, $value) = \helper_plugin_struct::decodeJson($value);
[, $value] = \helper_plugin_struct::decodeJson($value);
$column = $this->getLookupColumn();
if (!$column) return false;
return $column->getType()->renderValue($value, $R, $mode);
@ -169,7 +166,7 @@ class Lookup extends Dropdown
{
$values = array_map(
function ($val) {
list(, $val) = \helper_plugin_struct::decodeJson($val);
[, $val] = \helper_plugin_struct::decodeJson($val);
return $val;
},
$values
@ -185,7 +182,7 @@ class Lookup extends Dropdown
*/
public function rawValue($value)
{
list($value) = \helper_plugin_struct::decodeJson($value);
[$value] = \helper_plugin_struct::decodeJson($value);
return $value;
}
@ -195,7 +192,7 @@ class Lookup extends Dropdown
*/
public function displayValue($value)
{
list(, $value) = \helper_plugin_struct::decodeJson($value);
[, $value] = \helper_plugin_struct::decodeJson($value);
$column = $this->getLookupColumn();
if ($column) {
return $column->getType()->displayValue($value);
@ -215,7 +212,7 @@ class Lookup extends Dropdown
*/
public function compareValue($value)
{
list(, $value) = \helper_plugin_struct::decodeJson($value);
[, $value] = \helper_plugin_struct::decodeJson($value);
$column = $this->getLookupColumn();
if ($column) {
return $column->getType()->rawValue($value);

View File

@ -6,10 +6,10 @@ use dokuwiki\plugin\struct\meta\ValidationException;
class Mail extends Text
{
protected $config = array(
protected $config = [
'prefix' => '',
'postfix' => '',
);
'postfix' => ''
];
/**
* Output the stored data

View File

@ -6,13 +6,13 @@ use dokuwiki\plugin\struct\meta\ValidationException;
class Media extends AbstractBaseType
{
protected $config = array(
protected $config = [
'mime' => 'image/',
'width' => 90,
'height' => 90,
'agg_width' => '',
'agg_height' => ''
);
];
/**
* Checks against the allowed mime types
@ -29,7 +29,7 @@ class Media extends AbstractBaseType
$allows = array_map('trim', $allows);
$allows = array_filter($allows);
list(, $mime,) = mimetype($rawvalue, false);
[, $mime, ] = mimetype($rawvalue, false);
foreach ($allows as $allow) {
if (strpos($mime, $allow) === 0) return $rawvalue;
}
@ -59,9 +59,6 @@ class Media extends AbstractBaseType
if ($this->config['agg_width']) $width = $this->config['agg_width'];
if ($this->config['agg_height']) $height = $this->config['agg_height'];
}
// depending on renderer type directly output or get value from it
$returnLink = null;
$html = '';
if (!media_isexternal($value)) {
if (is_a($R, '\Doku_Renderer_xhtml')) {
@ -70,20 +67,18 @@ class Media extends AbstractBaseType
} else {
$R->internalmedia($value, null, null, $width, $height, null, 'direct');
}
} elseif (is_a($R, '\Doku_Renderer_xhtml')) {
/** @var \Doku_Renderer_xhtml $R */
$html = $R->externalmedia($value, null, null, $width, $height, null, 'direct', true);
} else {
if (is_a($R, '\Doku_Renderer_xhtml')) {
/** @var \Doku_Renderer_xhtml $R */
$html = $R->externalmedia($value, null, null, $width, $height, null, 'direct', true);
} else {
$R->externalmedia($value, null, null, $width, $height, null, 'direct');
}
$R->externalmedia($value, null, null, $width, $height, null, 'direct');
}
// add gallery meta data in XHTML
if ($mode == 'xhtml') {
list(, $mime,) = mimetype($value, false);
[, $mime, ] = mimetype($value, false);
if (substr($mime, 0, 6) == 'image/') {
$hash = !empty($R->info['struct_table_hash']) ? "[gal-" . $R->info['struct_table_hash'] . "]" : '';
$hash = empty($R->info['struct_table_hash']) ? '' : "[gal-" . $R->info['struct_table_hash'] . "]";
$html = str_replace('href', "rel=\"lightbox$hash\" href", $html);
}
$R->doc .= $html;
@ -109,12 +104,12 @@ class Media extends AbstractBaseType
$id = $htmlID ?: 'struct__' . md5($name . $count);
$params = array(
$params = [
'name' => $name,
'value' => $rawvalue,
'class' => 'struct_media',
'id' => $id
);
];
$attributes = buildAttributes($params, true);
$html = "<input $attributes />";
$html .= "<button type=\"button\" class=\"struct_media\">";
@ -134,7 +129,7 @@ class Media extends AbstractBaseType
$image = ml($media, ['h' => $weight, 'w' => $weight]);
$media_escaped = hsc($media);
$R->doc .= "<div style=\"height:{$weight}px; width:{$weight}px\">";
$R->doc .= "<a href='$url' class='struct_image' style='background-image:url(\"$image\")'
$R->doc .= "<a href='$url' class='struct_image' style='background-image:url(\"$image\")'
title='$media_escaped'>";
$R->doc .= "<span class='a11y'>$media_escaped</span>";
$R->doc .= "</a>";

View File

@ -16,15 +16,15 @@ use dokuwiki\Utf8\PhpString;
*/
class Page extends AbstractMultiBaseType
{
protected $config = array(
protected $config = [
'usetitles' => false,
'autocomplete' => array(
'autocomplete' => [
'mininput' => 2,
'maxresult' => 5,
'namespace' => '',
'postfix' => '',
),
);
'postfix' => ''
]
];
/**
* Output the stored data
@ -37,7 +37,7 @@ class Page extends AbstractMultiBaseType
public function renderValue($value, \Doku_Renderer $R, $mode)
{
if ($this->config['usetitles']) {
list($id, $title) = \helper_plugin_struct::decodeJson($value);
[$id, $title] = \helper_plugin_struct::decodeJson($value);
} else {
$id = $value;
$title = $id; // cannot be empty or internallink() might hijack %pageid% and use headings
@ -57,7 +57,7 @@ class Page extends AbstractMultiBaseType
*/
public function validate($rawvalue)
{
list($page, $fragment) = array_pad(explode('#', $rawvalue, 2), 2, '');
[$page, $fragment] = array_pad(explode('#', $rawvalue, 2), 2, '');
return cleanID($page) . (strlen(cleanID($fragment)) > 0 ? '#' . cleanID($fragment) : '');
}
@ -72,11 +72,11 @@ class Page extends AbstractMultiBaseType
// check minimum length
$lookup = trim($INPUT->str('search'));
if (PhpString::strlen($lookup) < $this->config['autocomplete']['mininput']) return array();
if (PhpString::strlen($lookup) < $this->config['autocomplete']['mininput']) return [];
// results wanted?
$max = $this->config['autocomplete']['maxresult'];
if ($max <= 0) return array();
if ($max <= 0) return [];
// lookup with namespace and postfix applied
$namespace = $this->config['autocomplete']['namespace'];
@ -91,10 +91,10 @@ class Page extends AbstractMultiBaseType
if ($namespace) $lookup .= ' @' . $namespace;
$data = ft_pageLookup($lookup, true, $this->config['usetitles']);
if (!count($data)) return array();
if ($data === []) return [];
// this basically duplicates what we do in ajax_qsearch()
$result = array();
$result = [];
$counter = 0;
foreach ($data as $id => $title) {
if ($this->config['usetitles']) {
@ -113,10 +113,10 @@ class Page extends AbstractMultiBaseType
continue; // page does not end in postfix, don't suggest it
}
$result[] = array(
$result[] = [
'label' => $name,
'value' => $id
);
];
$counter++;
if ($counter > $max) break;
@ -174,7 +174,7 @@ class Page extends AbstractMultiBaseType
public function rawValue($value)
{
if ($this->config['usetitles']) {
list($value) = \helper_plugin_struct::decodeJson($value);
[$value] = \helper_plugin_struct::decodeJson($value);
}
return $value;
}
@ -188,7 +188,7 @@ class Page extends AbstractMultiBaseType
public function displayValue($value)
{
if ($this->config['usetitles']) {
list($pageid, $value) = \helper_plugin_struct::decodeJson($value);
[$pageid, $value] = \helper_plugin_struct::decodeJson($value);
if (blank($value)) {
$value = $pageid;
}

View File

@ -10,13 +10,13 @@ use dokuwiki\Utf8\PhpString;
class Tag extends AbstractMultiBaseType
{
protected $config = array(
protected $config = [
'page' => '',
'autocomplete' => array(
'autocomplete' => [
'mininput' => 2,
'maxresult' => 5,
),
);
'maxresult' => 5
]
];
/**
* @param int|string $value
@ -48,27 +48,27 @@ class Tag extends AbstractMultiBaseType
// check minimum length
$lookup = trim($INPUT->str('search'));
if (PhpString::strlen($lookup) < $this->config['autocomplete']['mininput']) return array();
if (PhpString::strlen($lookup) < $this->config['autocomplete']['mininput']) return [];
// results wanted?
$max = $this->config['autocomplete']['maxresult'];
if ($max <= 0) return array();
if ($max <= 0) return [];
$context = $this->getContext();
$sql = $this->buildSQLFromContext($context);
$opt = array("%$lookup%");
$opt = ["%$lookup%"];
/** @var \helper_plugin_struct_db $hlp */
$hlp = plugin_load('helper', 'struct_db');
$sqlite = $hlp->getDB();
$rows = $sqlite->queryAll($sql, $opt);
$result = array();
$result = [];
foreach ($rows as $row) {
$result[] = array(
$result[] = [
'label' => $row['value'],
'value' => $row['value'],
);
'value' => $row['value']
];
}
return $result;

View File

@ -6,10 +6,10 @@ class Text extends AbstractMultiBaseType
{
use TraitFilterPrefix;
protected $config = array(
protected $config = [
'prefix' => '',
'postfix' => '',
);
'postfix' => ''
];
/**
* Output the stored data

View File

@ -27,7 +27,8 @@ trait TraitFilterPrefix
public function filter(QueryBuilderWhere $add, $tablealias, $colname, $comp, $value, $op)
{
$add = $add->where($op); // open a subgroup
$add->where('AND', "$tablealias.$colname != ''"); // make sure the field isn't empty
$add->where('AND', "$tablealias.$colname != ''");
// make sure the field isn't empty
$op = 'AND';
/** @var QueryBuilderWhere $add Where additionional queries are added to */

View File

@ -6,13 +6,13 @@ use dokuwiki\plugin\struct\meta\ValidationException;
class Url extends Text
{
protected $config = array(
protected $config = [
'autoscheme' => 'https',
'prefix' => '',
'postfix' => '',
'fixedtitle' => '',
'autoshorten' => true,
);
'autoshorten' => true
];
/**
* The final string should be an URL
@ -27,7 +27,7 @@ class Url extends Text
$url = $this->buildURL($rawvalue);
$schemes = getSchemes();
$regex = '^(' . join('|', $schemes) . '):\/\/.+';
$regex = '^(' . implode('|', $schemes) . '):\/\/.+';
if (!preg_match("/$regex/i", $url)) {
throw new ValidationException('Url invalid', $url);
}

View File

@ -2,6 +2,7 @@
namespace dokuwiki\plugin\struct\types;
use dokuwiki\Extension\AuthPlugin;
use dokuwiki\plugin\struct\meta\QueryBuilder;
use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
use dokuwiki\plugin\struct\meta\StructException;
@ -10,14 +11,14 @@ use dokuwiki\Utf8\PhpString;
class User extends AbstractMultiBaseType
{
protected $config = array(
protected $config = [
'existingonly' => true,
'autocomplete' => array(
'autocomplete' => [
'fullname' => true,
'mininput' => 2,
'maxresult' => 5,
),
);
'maxresult' => 5
]
];
/**
* @param string $rawvalue the user to validate
@ -28,7 +29,7 @@ class User extends AbstractMultiBaseType
$rawvalue = parent::validate($rawvalue);
if ($this->config['existingonly']) {
/** @var \DokuWiki_Auth_Plugin $auth */
/** @var AuthPlugin $auth */
global $auth;
$info = $auth->getUserData($rawvalue, false);
if ($info === false) throw new ValidationException('User not found', $rawvalue);
@ -63,7 +64,7 @@ class User extends AbstractMultiBaseType
*/
public function handleAjax()
{
/** @var \DokuWiki_Auth_Plugin $auth */
/** @var AuthPlugin $auth */
global $auth;
global $INPUT;
@ -73,25 +74,25 @@ class User extends AbstractMultiBaseType
// check minimum length
$lookup = trim($INPUT->str('search'));
if (PhpString::strlen($lookup) < $this->config['autocomplete']['mininput']) return array();
if (PhpString::strlen($lookup) < $this->config['autocomplete']['mininput']) return [];
// results wanted?
$max = $this->config['autocomplete']['maxresult'];
if ($max <= 0) return array();
if ($max <= 0) return [];
// find users by login, fill up with names if wanted
$logins = (array)$auth->retrieveUsers(0, $max, array('user' => $lookup));
$logins = (array)$auth->retrieveUsers(0, $max, ['user' => $lookup]);
if ((count($logins) < $max) && $this->config['autocomplete']['fullname']) {
$logins = array_merge($logins, (array)$auth->retrieveUsers(0, $max, array('name' => $lookup)));
$logins = array_merge($logins, (array)$auth->retrieveUsers(0, $max, ['name' => $lookup]));
}
// reformat result for jQuery UI Autocomplete
$users = array();
$users = [];
foreach ($logins as $login => $info) {
$users[] = array(
$users[] = [
'label' => $info['name'] . ' [' . $login . ']',
'value' => $login
);
];
}
return $users;