From 87172d2e0f2de91b52e6d7951247240418508bd5 Mon Sep 17 00:00:00 2001 From: annda <17853330+annda@users.noreply.github.com> Date: Thu, 10 Sep 2026 12:58:03 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Automatic=20code=20style=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/editor.php | 55 ++--- action/jsinfo.php | 7 +- action/newtable.php | 26 ++- action/preprocess.php | 11 +- action/sectionjump.php | 14 +- renderer/inverse.php | 482 ++++++++++++++++++++++++----------------- renderer/json.php | 90 ++++---- 7 files changed, 405 insertions(+), 280 deletions(-) diff --git a/action/editor.php b/action/editor.php index a57c84e..0ac3b51 100644 --- a/action/editor.php +++ b/action/editor.php @@ -1,4 +1,5 @@ */ +use dokuwiki\Extension\ActionPlugin; +use dokuwiki\Extension\EventHandler; +use dokuwiki\Extension\Event; +use dokuwiki\Utf8\PhpString; use dokuwiki\Form\Form; use dokuwiki\Utf8; @@ -14,12 +19,12 @@ * * like displaying the editor and adding custom edit buttons */ -class action_plugin_edittable_editor extends DokuWiki_Action_Plugin +class action_plugin_edittable_editor extends ActionPlugin { /** * Register its handlers with the DokuWiki's event controller */ - public function register(Doku_Event_Handler $controller) + public function register(EventHandler $controller) { // register custom edit buttons $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'secedit_button'); @@ -38,9 +43,9 @@ public function register(Doku_Event_Handler $controller) * * The target 'table' is provided by DokuWiki's XHTML core renderer in the table_close() method * - * @param Doku_Event $event + * @param Event $event */ - public function secedit_button(Doku_Event $event) + public function secedit_button(Event $event) { if ($event->data['target'] !== 'table') return; @@ -50,16 +55,16 @@ public function secedit_button(Doku_Event $event) /** * Creates the actual Table Editor form * - * @param Doku_Event $event + * @param Event $event */ - public function editform(Doku_Event $event) + public function editform(Event $event) { global $TEXT; global $RANGE; global $INPUT; if ($event->data['target'] !== 'table') return; - if (!$RANGE){ + if (!$RANGE) { // section editing failed, use default editor instead $event->data['target'] = 'section'; return; @@ -75,7 +80,7 @@ public function editform(Doku_Event $event) // Loop through the instructions foreach ($instructions as $instruction) { // Execute the callback against the Renderer - call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); + call_user_func_array([&$Renderer, $instruction[0]], $instruction[1]); } // output data and editor field @@ -83,7 +88,7 @@ public function editform(Doku_Event $event) /** @var Doku_Form $form */ $form =& $event->data['form']; - if (is_a($form, Form::class)) { // $event->name is EDIT_FORM_ADDTEXTAREA + if ($form instanceof Form) { // $event->name is EDIT_FORM_ADDTEXTAREA // data for handsontable $form->setHiddenField('edittable_data', $Renderer->getDataJSON()); $form->setHiddenField('edittable_meta', $Renderer->getMetaJSON()); @@ -97,7 +102,6 @@ public function editform(Doku_Event $event) // set target and range to keep track during previews $form->setHiddenField('target', 'table'); $form->setHiddenField('range', $RANGE); - } else { // $event->name is HTML_EDIT_FORMSELECTION // data for handsontable $form->addHidden('edittable_data', $Renderer->getDataJSON()); @@ -122,7 +126,7 @@ public function editform(Doku_Event $event) * * @author Andreas Gohr */ - public function handle_table_post(Doku_Event $event) + public function handle_table_post(Event $event) { global $TEXT; global $INPUT; @@ -149,7 +153,7 @@ public function build_table($data, $meta) $rows = count($data); $cols = $rows ? count($data[0]) : 0; - $colmax = $cols ? array_fill(0, $cols, 0) : array(); + $colmax = $cols ? array_fill(0, $cols, 0) : []; // find maximum column widths for ($row = 0; $row < $rows; $row++) { @@ -173,7 +177,6 @@ public function build_table($data, $meta) $last = '|'; // used to close the last cell for ($row = 0; $row < $rows; $row++) { for ($col = 0; $col < $cols; $col++) { - // hidden cells may carry no span info of their own if (!isset($meta[$row][$col]['colspan'])) $meta[$row][$col]['colspan'] = 1; if (!isset($meta[$row][$col]['rowspan'])) $meta[$row][$col]['rowspan'] = 1; @@ -218,8 +221,8 @@ public function build_table($data, $meta) // add the padding $cdata = $data[$row][$col]; - if (!(isset($meta[$row][$col]['hide']) && $meta[$row][$col]['hide']) || $cdata) { - $cdata = str_pad('', $lpad).$cdata.str_pad('', $rpad); + if (!isset($meta[$row][$col]['hide']) || !$meta[$row][$col]['hide'] || $cdata) { + $cdata = str_pad('', $lpad) . $cdata . str_pad('', $rpad); } // finally add the cell @@ -248,19 +251,17 @@ public function strWidth($str) if (isset($callable)) { return $callable($str); + } + if (UTF8_MBSTRING) { + // count fullwidth characters as 2, halfwidth characters as 1 + $callable = 'mb_strwidth'; + } elseif (method_exists(PhpString::class, 'strlen')) { + // count any characters as 1 + $callable = PhpString::strlen(...); } else { - if (UTF8_MBSTRING) { - // count fullwidth characters as 2, halfwidth characters as 1 - $callable = 'mb_strwidth'; - } elseif (method_exists(Utf8\PhpString::class, 'strlen')) { - // count any characters as 1 - $callable = [Utf8\PhpString::class, 'strlen']; - } else { - // fallback deprecated utf8_strlen since 2019-06-09 - $callable = 'utf8_strlen'; - } - return $this->strWidth($str); + // fallback deprecated utf8_strlen since 2019-06-09 + $callable = 'utf8_strlen'; } + return $this->strWidth($str); } - } diff --git a/action/jsinfo.php b/action/jsinfo.php index de80c4f..cb6aa63 100644 --- a/action/jsinfo.php +++ b/action/jsinfo.php @@ -1,16 +1,19 @@ register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'fill_jsinfo'); diff --git a/action/newtable.php b/action/newtable.php index c3a5bc0..f3d72c9 100644 --- a/action/newtable.php +++ b/action/newtable.php @@ -1,19 +1,23 @@ */ - /** * Handles the inserting of a new table in a running edit session */ -class action_plugin_edittable_newtable extends DokuWiki_Action_Plugin +class action_plugin_edittable_newtable extends ActionPlugin { /** * Register its handlers with the DokuWiki's event controller */ - function register(Doku_Event_Handler $controller) + public function register(EventHandler $controller) { $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'toolbar'); @@ -24,24 +28,24 @@ function register(Doku_Event_Handler $controller) /** * Add a button for inserting tables to the toolbar array * - * @param Doku_Event $event + * @param Event $event */ - public function toolbar(Doku_Event $event) + public function toolbar(Event $event) { - $event->data[] = array( + $event->data[] = [ 'title' => $this->getLang('add_table'), 'type' => 'NewTable', 'icon' => '../../plugins/edittable/images/add_table.png', 'block' => true - ); + ]; } /** * Handle the click on the new table button in the toolbar * - * @param Doku_Event $event + * @param Event $event */ - public function handle_newtable(Doku_Event $event) + public function handle_newtable(Event $event) { global $INPUT; global $TEXT; @@ -80,13 +84,13 @@ public function handle_newtable(Doku_Event $event) case 'draftdel': // not sure if/how this would happen, we restore all data and hand over to section edit $INPUT->post->set('target', 'section'); - $TEXT = $fields['pre'].$fields['text'].$fields['suf']; + $TEXT = $fields['pre'] . $fields['text'] . $fields['suf']; $event->data = 'edit'; break; case 'save': // return to edit page $INPUT->post->set('target', 'section'); - $TEXT = $fields['pre'].$TEXT.$fields['suf']; + $TEXT = $fields['pre'] . $TEXT . $fields['suf']; $event->data = 'edit'; break; } diff --git a/action/preprocess.php b/action/preprocess.php index c8b9825..1d8e45f 100644 --- a/action/preprocess.php +++ b/action/preprocess.php @@ -1,10 +1,13 @@ */ +use dokuwiki\Extension\ActionPlugin; +use dokuwiki\Extension\EventHandler; use dokuwiki\Extension\Event; /** @@ -14,12 +17,12 @@ * That's currently not possible to guarantee, so we catch the event only once and emit two of our own * in the right order. Once DokuWiki supports a sort we can skip this. */ -class action_plugin_edittable_preprocess extends DokuWiki_Action_Plugin +class action_plugin_edittable_preprocess extends ActionPlugin { /** * Register its handlers with the DokuWiki's event controller */ - public function register(Doku_Event_Handler $controller) + public function register(EventHandler $controller) { // register preprocessing for accepting editor data $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_preprocess'); @@ -28,9 +31,9 @@ public function register(Doku_Event_Handler $controller) /** * See class description for WTF we're doing here * - * @param Doku_Event $event + * @param Event $event */ - public function handle_preprocess(Doku_Event $event) + public function handle_preprocess(Event $event) { Event::createAndTrigger('PLUGIN_EDITTABLE_PREPROCESS_EDITOR', $event->data); Event::createAndTrigger('PLUGIN_EDITTABLE_PREPROCESS_NEWTABLE', $event->data); diff --git a/action/sectionjump.php b/action/sectionjump.php index 63346ff..a3951a1 100644 --- a/action/sectionjump.php +++ b/action/sectionjump.php @@ -1,19 +1,23 @@ */ - /** * redirect to the section containg the table */ -class action_plugin_edittable_sectionjump extends DokuWiki_Action_Plugin +class action_plugin_edittable_sectionjump extends ActionPlugin { /** * Register its handlers with the DokuWiki's event controller */ - function register(Doku_Event_Handler $controller) + public function register(EventHandler $controller) { $controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'jump_to_section'); } @@ -21,9 +25,9 @@ function register(Doku_Event_Handler $controller) /** * Jump after save to the section containing this table * - * @param Doku_Event $event + * @param Event $event */ - function jump_to_section($event) + public function jump_to_section($event) { global $INPUT; if (!$INPUT->has('edittable_data')) return; diff --git a/renderer/inverse.php b/renderer/inverse.php index 9b52520..bc32579 100644 --- a/renderer/inverse.php +++ b/renderer/inverse.php @@ -1,4 +1,10 @@ block(); $this->doc = rtrim($this->doc); } - function header($text, $level, $pos) { + public function header($text, $level, $pos) + { $this->block(); - if(!$text) return; //skip empty headlines + if (!$text) return; //skip empty headlines // write the header $markup = str_repeat('=', 7 - $level); - $this->doc .= "$markup $text $markup".DOKU_LF; + $this->doc .= "$markup $text $markup" . DOKU_LF; } - function section_open($level) { + public function section_open($level) + { $this->block(); # $this->doc .= DOKU_LF; } - function section_close() { + public function section_close() + { $this->block(); $this->doc .= DOKU_LF; } // FIXME this did something compllicated with surrounding whitespaces. Why? - function cdata($text) { - if(strlen($text) === 0) { + public function cdata($text) + { + if ((string) $text === '') { $this->not_block(); return; } @@ -79,320 +93,371 @@ function cdata($text) { $this->doc .= $text; } - function p_close() { + public function p_close() + { $this->block(); - if($this->quotelvl === 0) { - $this->doc = rtrim($this->doc, DOKU_LF).DOKU_LF.DOKU_LF; + if ($this->quotelvl === 0) { + $this->doc = rtrim($this->doc, DOKU_LF) . DOKU_LF . DOKU_LF; } } - function p_open() { + public function p_open() + { $this->block(); - if(strlen($this->doc) > 0 && substr($this->doc, 1, -1) !== DOKU_LF) { - $this->doc .= DOKU_LF.DOKU_LF; + if ((string) $this->doc !== '' && substr($this->doc, 1, -1) !== DOKU_LF) { + $this->doc .= DOKU_LF . DOKU_LF; } $this->doc .= str_repeat('>', $this->quotelvl); } - function linebreak() { + public function linebreak() + { $this->not_block(); $this->doc .= '\\\\ '; } - function hr() { + public function hr() + { $this->block(); $this->doc .= '----'; } - function block() { - if(isset($this->prepend_not_block)) { + public function block() + { + if (isset($this->prepend_not_block)) { unset($this->prepend_not_block); } $this->previous_block = true; } - function not_block() { - if(isset($this->prepend_not_block)) { + public function not_block() + { + if (isset($this->prepend_not_block)) { $this->doc .= $this->prepend_not_block; unset($this->prepend_not_block); } $this->previous_block = false; } - function strong_open() { + public function strong_open() + { $this->not_block(); $this->doc .= '**'; } - function strong_close() { + public function strong_close() + { $this->not_block(); $this->doc .= '**'; } - function emphasis_open() { + public function emphasis_open() + { $this->not_block(); $this->doc .= '//'; } - function emphasis_close() { + public function emphasis_close() + { $this->not_block(); $this->doc .= '//'; } - function underline_open() { + public function underline_open() + { $this->not_block(); $this->doc .= '__'; } - function underline_close() { + public function underline_close() + { $this->not_block(); $this->doc .= '__'; } - function monospace_open() { + public function monospace_open() + { $this->not_block(); $this->doc .= "''"; } - function monospace_close() { + public function monospace_close() + { $this->not_block(); $this->doc .= "''"; } - function subscript_open() { + public function subscript_open() + { $this->not_block(); $this->doc .= ''; } - function subscript_close() { + public function subscript_close() + { $this->not_block(); $this->doc .= ''; } - function superscript_open() { + public function superscript_open() + { $this->not_block(); $this->doc .= ''; } - function superscript_close() { + public function superscript_close() + { $this->not_block(); $this->doc .= ''; } - function deleted_open() { + public function deleted_open() + { $this->not_block(); $this->doc .= ''; } - function deleted_close() { + public function deleted_close() + { $this->not_block(); $this->doc .= ''; } - function footnote_open() { + public function footnote_open() + { $this->not_block(); $this->doc .= '(('; } - function footnote_close() { + public function footnote_close() + { $this->not_block(); $this->doc .= '))'; } - function listu_open() { + public function listu_open() + { $this->block(); - if(!isset($this->_liststack)) { - $this->_liststack = array(); + if (!isset($this->_liststack)) { + $this->_liststack = []; } - if(count($this->_liststack) === 0) { + if (count($this->_liststack) === 0) { $this->doc .= DOKU_LF; } $this->_liststack[] = '*'; } - function listu_close() { + public function listu_close() + { $this->block(); array_pop($this->_liststack); - if(count($this->_liststack) === 0) { + if (count($this->_liststack) === 0) { $this->doc .= DOKU_LF; } } - function listo_open() { + public function listo_open() + { $this->block(); - if(!isset($this->_liststack)) { - $this->_liststack = array(); + if (!isset($this->_liststack)) { + $this->_liststack = []; } - if(count($this->_liststack) === 0) { + if (count($this->_liststack) === 0) { $this->doc .= DOKU_LF; } $this->_liststack[] = '-'; } - function listo_close() { + public function listo_close() + { $this->block(); array_pop($this->_liststack); - if(count($this->_liststack) === 0) { + if (count($this->_liststack) === 0) { $this->doc .= DOKU_LF; } } - function listitem_open($level, $node = false) { + public function listitem_open($level, $node = false) + { $this->block(); - $this->doc .= str_repeat(' ', $level * 2).end($this->_liststack).' '; + $this->doc .= str_repeat(' ', $level * 2) . end($this->_liststack) . ' '; } - function listcontent_close() { + public function listcontent_close() + { $this->block(); $this->doc .= DOKU_LF; } - function unformatted($text) { + public function unformatted($text) + { $this->not_block(); - if(strpos($text, '%%') !== false) { + if (str_contains($text, '%%')) { $this->doc .= "$text"; - } elseif($text[0] == "\n") { + } elseif ($text[0] == "\n") { $this->doc .= "$text"; } else { $this->doc .= "%%$text%%"; } } - function php($text, $wrapper = 'code') { + public function php($text, $wrapper = 'code') + { $this->not_block(); $this->doc .= "$text"; } - function phpblock($text) { + public function phpblock($text) + { $this->block(); $this->doc .= "$text"; } - function html($text, $wrapper = 'code') { + public function html($text, $wrapper = 'code') + { $this->not_block(); $this->doc .= "$text"; } - function htmlblock($text) { + public function htmlblock($text) + { $this->block(); $this->doc .= "$text"; } - function quote_open() { + public function quote_open() + { $this->block(); - if(substr($this->doc, -(++$this->quotelvl)) === DOKU_LF.str_repeat('>', $this->quotelvl - 1)) { + if (substr($this->doc, -(++$this->quotelvl)) === DOKU_LF . str_repeat('>', $this->quotelvl - 1)) { $this->doc .= '>'; } else { - $this->doc .= DOKU_LF.str_repeat('>', $this->quotelvl); + $this->doc .= DOKU_LF . str_repeat('>', $this->quotelvl); } $this->prepend_not_block = ' '; } - function quote_close() { + public function quote_close() + { $this->block(); $this->quotelvl--; - if(strrpos($this->doc, DOKU_LF) === strlen($this->doc) - 1) { + if (strrpos($this->doc, DOKU_LF) === strlen($this->doc) - 1) { return; } - $this->doc .= DOKU_LF.DOKU_LF; + $this->doc .= DOKU_LF . DOKU_LF; } - function preformatted($text) { + public function preformatted($text) + { $this->block(); - $this->doc .= preg_replace('/^/m', ' ', $text).DOKU_LF; + $this->doc .= preg_replace('/^/m', ' ', $text) . DOKU_LF; } - function file($text, $language = null, $filename = null) { + public function file($text, $language = null, $filename = null) + { $this->_highlight('file', $text, $language, $filename); } - function code($text, $language = null, $filename = null) { + public function code($text, $language = null, $filename = null) + { $this->_highlight('code', $text, $language, $filename); } - function _highlight($type, $text, $language = null, $filename = null) { - if( $this->previous_block ) $this->doc .= "\n"; + public function _highlight($type, $text, $language = null, $filename = null) + { + if ($this->previous_block) $this->doc .= "\n"; $this->block(); $this->doc .= "<$type"; - if($language != null) { + if ($language != null) { $this->doc .= " $language"; } - if($filename != null) { + if ($filename != null) { $this->doc .= " $filename"; } $this->doc .= ">"; $this->doc .= $text; - if($text[0] == "\n") $this->doc .= "\n"; + if ($text[0] == "\n") $this->doc .= "\n"; $this->doc .= ""; } - function acronym($acronym) { + public function acronym($acronym) + { $this->not_block(); $this->doc .= $acronym; } - function smiley($smiley) { + public function smiley($smiley) + { $this->not_block(); $this->doc .= $smiley; } - function entity($entity) { + public function entity($entity) + { $this->not_block(); $this->doc .= $entity; } - function multiplyentity($x, $y) { + public function multiplyentity($x, $y) + { $this->not_block(); $this->doc .= "{$x}x{$y}"; } - function singlequoteopening() { + public function singlequoteopening() + { $this->not_block(); $this->doc .= "'"; } - function singlequoteclosing() { + public function singlequoteclosing() + { $this->not_block(); $this->doc .= "'"; } - function apostrophe() { + public function apostrophe() + { $this->not_block(); $this->doc .= "'"; } - function doublequoteopening() { + public function doublequoteopening() + { $this->not_block(); $this->doc .= '"'; } - function doublequoteclosing() { + public function doublequoteclosing() + { $this->not_block(); $this->doc .= '"'; } /** */ - function camelcaselink($link) { + public function camelcaselink($link) + { $this->not_block(); $this->doc .= $link; } - function locallink($hash, $name = null) { + public function locallink($hash, $name = null) + { $this->not_block(); $this->doc .= "[[#$hash"; - if($name !== null) { + if ($name !== null) { $this->doc .= '|'; $this->_echoLinkTitle($name); } $this->doc .= ']]'; } - function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { + public function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') + { $this->not_block(); $this->doc .= "[[$id"; - if($name !== null) { + if ($name !== null) { $this->doc .= '|'; $this->_echoLinkTitle($name); } @@ -404,9 +469,9 @@ function internallink($id, $name = null, $search = null, $returnonly = false, $l * * @author Andreas Gohr * @param $url - * @param null $name */ - function externallink($url, $name = null) { + public function externallink($url, $name = null) + { $this->not_block(); /* @@ -417,20 +482,20 @@ function externallink($url, $name = null) { * a single tick >>'<< which seems to work. Since the patterns contain wordboundaries they are matched * against the URL surrounded by spaces. */ - if($name === null) { + if ($name === null) { // get the patterns from the parser if available, otherwise use a duplicate - if(is_null($this->extlinkparser)) { + if (is_null($this->extlinkparser)) { if ( class_exists('\dokuwiki\Parsing\ParserMode\Externallink') && method_exists('\dokuwiki\Parsing\ParserMode\Externallink', 'getPatterns') ) { global $conf; - $this->extlinkparser = new \dokuwiki\Parsing\ParserMode\Externallink(); + $this->extlinkparser = new Externallink(); // The Externallink mode reads its ModeRegistry in preConnect(). // Provide one when the setter is available. - if(method_exists($this->extlinkparser, 'setModeRegistry')) { + if (method_exists($this->extlinkparser, 'setModeRegistry')) { $this->extlinkparser->setModeRegistry( - new \dokuwiki\Parsing\ModeRegistry($conf['syntax'] ?? 'dw') + new ModeRegistry($conf['syntax'] ?? 'dw') ); } $this->extlinkparser->preConnect(); @@ -444,17 +509,17 @@ class_exists('\dokuwiki\Parsing\ParserMode\Externallink') && $schemes = getSchemes(); foreach ($schemes as $scheme) { - $this->extlinkPatterns[] = '\b(?i)'.$scheme.'(?-i)://['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; + $this->extlinkPatterns[] = '\b(?i)' . $scheme . '(?-i)://[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])'; } - $this->extlinkPatterns[] = '(?<=\s)(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; - $this->extlinkPatterns[] = '(?<=\s)(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])'; + $this->extlinkPatterns[] = '(?<=\s)(?i)www?(?-i)\.[' . $host . ']+?\.[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])'; + $this->extlinkPatterns[] = '(?<=\s)(?i)ftp?(?-i)\.[' . $host . ']+?\.[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])'; } } // check if URL matches pattern - foreach($this->extlinkPatterns as $pattern) { - if(preg_match("'$pattern'", " $url ")) { + foreach ($this->extlinkPatterns as $pattern) { + if (preg_match("'$pattern'", " $url ")) { $this->doc .= $url; // gotcha! return; } @@ -462,13 +527,13 @@ class_exists('\dokuwiki\Parsing\ParserMode\Externallink') && } // still here? - if(is_string($name) && ($url === "http://$name" || $url === "ftp://$name")) { + if (is_string($name) && ($url === "http://$name" || $url === "ftp://$name")) { // special case - www.* or ftp.* matching $this->doc .= $name; } else { // link syntax! definitively link syntax $this->doc .= "[[$url"; - if(!is_null($name)) { + if (!is_null($name)) { // we do have a name! $this->doc .= '|'; $this->_echoLinkTitle($name); @@ -477,29 +542,32 @@ class_exists('\dokuwiki\Parsing\ParserMode\Externallink') && } } - function interwikilink($match, $name = null, $wikiName, $wikiUri) { + public function interwikilink($match, $name = null, $wikiName = null, $wikiUri = null) + { $this->not_block(); $this->doc .= "[[$wikiName>$wikiUri"; - if($name !== null) { + if ($name !== null) { $this->doc .= '|'; $this->_echoLinkTitle($name); } $this->doc .= ']]'; } - function windowssharelink($url, $name = null) { + public function windowssharelink($url, $name = null) + { $this->not_block(); $this->doc .= "[[$url"; - if($name !== null) { + if ($name !== null) { $this->doc .= '|'; $this->_echoLinkTitle($name); } $this->doc .= "]]"; } - function emaillink($address, $name = null) { + public function emaillink($address, $name = null) + { $this->not_block(); - if($name === null) { + if ($name === null) { $this->doc .= "<$address>"; } else { $this->doc .= "[[$address|"; @@ -508,44 +576,58 @@ function emaillink($address, $name = null) { } } - function internalmedia($src, $title = null, $align = null, $width = null, - $height = null, $cache = null, $linking = null) { + public function internalmedia( + $src, + $title = null, + $align = null, + $width = null, + $height = null, + $cache = null, + $linking = null + ) { $this->not_block(); $this->doc .= '{{'; - if($align === 'center' || $align === 'right') { + if ($align === 'center' || $align === 'right') { $this->doc .= ' '; } $this->doc .= $src; - $params = array(); - if($width !== null) { + $params = []; + if ($width !== null) { $params[0] = $width; - if($height !== null) { + if ($height !== null) { $params[0] .= "x$height"; } } - if($cache !== 'cache') { + if ($cache !== 'cache') { $params[] = $cache; } - if($linking !== 'details') { + if ($linking !== 'details') { $params[] = $linking; } - if(count($params) > 0) { + if (count($params) > 0) { $this->doc .= '?'; } - $this->doc .= join('&', $params); + $this->doc .= implode('&', $params); - if($align === 'center' || $align === 'left') { + if ($align === 'center' || $align === 'left') { $this->doc .= ' '; } - if($title != null) { + if ($title != null) { $this->doc .= "|$title"; } $this->doc .= '}}'; } - function externalmedia($src, $title = null, $align = null, $width = null, - $height = null, $cache = null, $linking = null) { + public function externalmedia( + $src, + $title = null, + $align = null, + $width = null, + $height = null, + $cache = null, + $linking = null + ) { $this->internalmedia($src, $title, $align, $width, $height, $cache, $linking); } @@ -554,96 +636,105 @@ function externalmedia($src, $title = null, $align = null, $width = null, * * @author Andreas Gohr */ - function rss($url, $params) { + public function rss($url, $params) + { $this->block(); - $this->doc .= '{{rss>'.$url; - $vals = array(); - if($params['max'] !== 8) { + $this->doc .= '{{rss>' . $url; + $vals = []; + if ($params['max'] !== 8) { $vals[] = $params['max']; } - if($params['reverse']) { + if ($params['reverse']) { $vals[] = 'reverse'; } - if($params['author']) { + if ($params['author']) { $vals[] = 'author'; } - if($params['date']) { + if ($params['date']) { $vals[] = 'date'; } - if($params['details']) { + if ($params['details']) { $vals[] = 'desc'; } - if($params['refresh'] !== 14400) { + if ($params['refresh'] !== 14400) { $val = '10m'; - foreach(array('d' => 86400, 'h' => 3600, 'm' => 60) as $p => $div) { + foreach (['d' => 86400, 'h' => 3600, 'm' => 60] as $p => $div) { $res = $params['refresh'] / $div; - if($res === intval($res)) { + if ($res === intval($res)) { $val = "$res$p"; break; } } $vals[] = $val; } - if(count($vals) > 0) { - $this->doc .= ' '.join(' ', $vals); + if (count($vals) > 0) { + $this->doc .= ' ' . implode(' ', $vals); } $this->doc .= '}}'; } - function table_open($maxcols = null, $numrows = null, $pos = null) { + public function table_open($maxcols = null, $numrows = null, $pos = null) + { $this->block(); - $this->_table = array(); + $this->_table = []; $this->_row = 0; - $this->_rowspans = array(); + $this->_rowspans = []; } - function table_close($pos = null) { + public function table_close($pos = null) + { $this->doc .= $this->_table_to_wikitext($this->_table); } - function tablerow_open() { + public function tablerow_open() + { $this->block(); - $this->_table[++$this->_row] = array(); + $this->_table[++$this->_row] = []; $this->_key = 1; - while(isset($this->_rowspans[$this->_key])) { + while (isset($this->_rowspans[$this->_key])) { --$this->_rowspans[$this->_key]; - if($this->_rowspans[$this->_key] === 1) { + if ($this->_rowspans[$this->_key] === 1) { unset($this->_rowspans[$this->_key]); } ++$this->_key; } } - function tablerow_close() { + public function tablerow_close() + { $this->block(); } - function tableheader_open($colspan = 1, $align = null, $rowspan = 1) { + public function tableheader_open($colspan = 1, $align = null, $rowspan = 1) + { $this->_cellopen('th', $colspan, $align, $rowspan); } - function _cellopen($tag, $colspan, $align, $rowspan) { + public function _cellopen($tag, $colspan, $align, $rowspan) + { $this->block(); - $this->_table[$this->_row][$this->_key] = compact('tag', 'colspan', 'align', 'rowspan'); - if($rowspan > 1) { + $this->_table[$this->_row][$this->_key] = ['tag' => $tag, 'colspan' => $colspan, 'align' => $align, 'rowspan' => $rowspan]; + if ($rowspan > 1) { $this->_rowspans[$this->_key] = $rowspan; $this->_ownspan = true; } $this->_pos = strlen($this->doc); } - function tableheader_close() { + public function tableheader_close() + { $this->_cellclose(); } - function _cellclose() { + public function _cellclose() + { $this->block(); $this->_table[$this->_row][$this->_key]['text'] = trim(substr($this->doc, $this->_pos)); $this->doc = substr($this->doc, 0, $this->_pos); $this->_key += $this->_table[$this->_row][$this->_key]['colspan']; - while(isset($this->_rowspans[$this->_key]) && !$this->_ownspan) { + while (isset($this->_rowspans[$this->_key]) && !$this->_ownspan) { --$this->_rowspans[$this->_key]; - if($this->_rowspans[$this->_key] === 1) { + if ($this->_rowspans[$this->_key] === 1) { unset($this->_rowspans[$this->_key]); } ++$this->_key; @@ -651,15 +742,18 @@ function _cellclose() { $this->_ownspan = false; } - function tablecell_open($colspan = 1, $align = null, $rowspan = 1) { + public function tablecell_open($colspan = 1, $align = null, $rowspan = 1) + { $this->_cellopen('td', $colspan, $align, $rowspan); } - function tablecell_close() { + public function tablecell_close() + { $this->_cellclose(); } - function plugin($name, $args, $state = '', $match = '') { + public function plugin($name, $args, $state = '', $match = '') + { $this->not_block(); // This will break for plugins which provide a catch-all render method // like the do or pagenavi plugins @@ -669,8 +763,9 @@ function plugin($name, $args, $state = '', $match = '') { # } } - function _echoLinkTitle($title) { - if(is_array($title)) { + public function _echoLinkTitle($title) + { + if (is_array($title)) { $this->internalmedia( $title['src'], $title['title'], @@ -692,25 +787,26 @@ function _echoLinkTitle($title) { * @param array $_table * @return string */ - private function _table_to_wikitext($_table) { + private function _table_to_wikitext($_table) + { // Preprocess table for rowspan, make table 0-based. - $table = array(); + $table = []; $keys = array_keys($_table); $start = array_pop($keys); - foreach($_table as $i => $row) { + foreach ($_table as $i => $row) { $inorm = $i - $start; - if(!isset($table[$inorm])) $table[$inorm] = array(); + if (!isset($table[$inorm])) $table[$inorm] = []; $nextkey = 0; - foreach($row as $cell) { - while(isset($table[$inorm][$nextkey])) { + foreach ($row as $cell) { + while (isset($table[$inorm][$nextkey])) { $nextkey++; } $nextkey += $cell['colspan'] - 1; $table[$inorm][$nextkey] = $cell; $rowspan = $cell['rowspan']; $i2 = $inorm + 1; - while($rowspan-- > 1) { - if(!isset($table[$i2])) $table[$i2] = array(); + while ($rowspan-- > 1) { + if (!isset($table[$i2])) $table[$i2] = []; $nu_cell = $cell; $nu_cell['text'] = ':::'; $nu_cell['rowspan'] = 1; @@ -721,47 +817,47 @@ private function _table_to_wikitext($_table) { } // Get the max width for every column to do table prettyprinting. - $m_width = array(); - foreach($table as $row) { - foreach($row as $n => $cell) { + $m_width = []; + foreach ($table as $row) { + foreach ($row as $n => $cell) { // Calculate cell width. - $diff = (utf8_strlen($cell['text']) + $cell['colspan'] + + $diff = (PhpString::strlen($cell['text']) + $cell['colspan'] + ($cell['align'] === 'center' ? 3 : 2)); // Calculate current max width. $span = $cell['colspan']; - while(--$span >= 0) { - if(isset($m_width[$n - $span])) { + while (--$span >= 0) { + if (isset($m_width[$n - $span])) { $diff -= $m_width[$n - $span]; } } - if($diff > 0) { + if ($diff > 0) { // Just add the difference to all cols. - while(++$span < $cell['colspan']) { - $m_width[$n - $span] = (isset($m_width[$n - $span]) ? $m_width[$n - $span] : 0) + ceil($diff / $cell['colspan']); + while (++$span < $cell['colspan']) { + $m_width[$n - $span] = ($m_width[$n - $span] ?? 0) + ceil($diff / $cell['colspan']); } } } } // Write the table. - $types = array('th' => '^', 'td' => '|'); + $types = ['th' => '^', 'td' => '|']; $str = ''; - foreach($table as $row) { + foreach ($table as $row) { $pos = 0; - foreach($row as $n => $cell) { - $pos += utf8_strlen($cell['text']) + 1; + foreach ($row as $n => $cell) { + $pos += PhpString::strlen($cell['text']) + 1; $span = $cell['colspan']; $target = 0; - while(--$span >= 0) { - if(isset($m_width[$n - $span])) { + while (--$span >= 0) { + if (isset($m_width[$n - $span])) { $target += $m_width[$n - $span]; } } - $pad = $target - utf8_strlen($cell['text']); + $pad = $target - PhpString::strlen($cell['text']); $pos += $pad + ($cell['colspan'] - 1); - switch($cell['align']) { + switch ($cell['align']) { case 'right': $lpad = $pad - 1; break; @@ -773,11 +869,11 @@ private function _table_to_wikitext($_table) { $lpad = floor($pad / 2); break; } - $str .= $types[$cell['tag']].str_repeat(' ', $lpad). - $cell['text'].str_repeat(' ', $pad - $lpad). + $str .= $types[$cell['tag']] . str_repeat(' ', $lpad) . + $cell['text'] . str_repeat(' ', $pad - $lpad) . str_repeat($types[$cell['tag']], $cell['colspan'] - 1); } - $str .= $types[$cell['tag']].DOKU_LF; + $str .= $types[$cell['tag']] . DOKU_LF; } return $str; } diff --git a/renderer/json.php b/renderer/json.php index 19de5e4..e451d74 100644 --- a/renderer/json.php +++ b/renderer/json.php @@ -1,4 +1,5 @@ tdata); } @@ -43,44 +46,53 @@ public function getDataJSON() { * * @return array */ - public function getMetaJSON() { + public function getMetaJSON() + { return json_encode($this->tmeta); } // renderer functions below - function table_open($maxcols = null, $numrows = null, $pos = null) { + public function table_open($maxcols = null, $numrows = null, $pos = null) + { // FIXME: is this needed somewhere? $this->_counter['table_begin_pos'] = strlen($this->doc); } - function table_close($pos = null) { + public function table_close($pos = null) + { } - function tablerow_open() { + public function tablerow_open() + { // move counters $this->current_row++; $this->current_col = 0; } - function tablerow_close() { + public function tablerow_close() + { // resort just for better debug readability ksort($this->tdata[$this->current_row]); ksort($this->tmeta[$this->current_row]); } - function tableheader_open($colspan = 1, $align = null, $rowspan = 1) { + public function tableheader_open($colspan = 1, $align = null, $rowspan = 1) + { $this->_tablefield_open('th', $colspan, $align, $rowspan); } - function tableheader_close() { + public function tableheader_close() + { $this->_tablefield_close(); } - function tablecell_open($colspan = 1, $align = null, $rowspan = 1) { + public function tablecell_open($colspan = 1, $align = null, $rowspan = 1) + { $this->_tablefield_open('td', $colspan, $align, $rowspan); } - function tablecell_close() { + public function tablecell_close() + { $this->_tablefield_close(); } @@ -92,14 +104,15 @@ function tablecell_close() { * @param $align * @param $rowspan */ - private function _tablefield_open($tag, $colspan, $align, $rowspan) { + private function _tablefield_open($tag, $colspan, $align, $rowspan) + { // skip cells that already exist - those are previous (span) cells! - while(isset($this->tmeta[$this->current_row][$this->current_col])) { + while (isset($this->tmeta[$this->current_row][$this->current_col])) { $this->current_col++; } // remember these, we use them when closing - $this->tmetacell = array(); + $this->tmetacell = []; $this->tmetacell['tag'] = $tag; $this->tmetacell['colspan'] = $colspan; $this->tmetacell['rowspan'] = $rowspan; @@ -112,7 +125,8 @@ private function _tablefield_open($tag, $colspan, $align, $rowspan) { /** * Used for closing THs and TDs */ - private function _tablefield_close() { + private function _tablefield_close() + { // these have been set to the correct cell already $row = $this->current_row; $col = $this->current_col; @@ -125,29 +139,29 @@ private function _tablefield_close() { $rowspan = $this->tmetacell['rowspan']; $colspan = $this->tmetacell['colspan']; - for($c = 1; $c < $colspan; $c++) { - // hide colspanned cell in same row - $this->tmeta[$row][$col + $c]['hide'] = true; - $this->tmeta[$row][$col + $c]['rowspan'] = 1; - $this->tmeta[$row][$col + $c]['colspan'] = 1; - $this->tdata[$row][$col + $c] = ''; - - // hide colspanned rows below if rowspan is in effect as well - for($r = 1; $r < $rowspan; $r++) { - $this->tmeta[$row + $r][$col + $c]['hide'] = true; - $this->tmeta[$row + $r][$col + $c]['rowspan'] = 1; - $this->tmeta[$row + $r][$col + $c]['colspan'] = 1; - $this->tdata[$row + $r][$col + $c] = ''; - } + for ($c = 1; $c < $colspan; $c++) { + // hide colspanned cell in same row + $this->tmeta[$row][$col + $c]['hide'] = true; + $this->tmeta[$row][$col + $c]['rowspan'] = 1; + $this->tmeta[$row][$col + $c]['colspan'] = 1; + $this->tdata[$row][$col + $c] = ''; + + // hide colspanned rows below if rowspan is in effect as well + for ($r = 1; $r < $rowspan; $r++) { + $this->tmeta[$row + $r][$col + $c]['hide'] = true; + $this->tmeta[$row + $r][$col + $c]['rowspan'] = 1; + $this->tmeta[$row + $r][$col + $c]['colspan'] = 1; + $this->tdata[$row + $r][$col + $c] = ''; } + } // hide rowspanned columns - for($r = 1; $r < $rowspan; $r++) { - $this->tmeta[$row + $r][$col]['hide'] = true; - $this->tmeta[$row + $r][$col]['rowspan'] = 1; - $this->tmeta[$row + $r][$col]['colspan'] = 1; - $this->tdata[$row + $r][$col] = ':::'; - } + for ($r = 1; $r < $rowspan; $r++) { + $this->tmeta[$row + $r][$col]['hide'] = true; + $this->tmeta[$row + $r][$col]['rowspan'] = 1; + $this->tmeta[$row + $r][$col]['colspan'] = 1; + $this->tdata[$row + $r][$col] = ':::'; + } } } }