Skip to content

Commit

Permalink
Code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
annda committed Oct 8, 2024
1 parent 5cd8e0f commit ca33838
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 92 deletions.
104 changes: 43 additions & 61 deletions action/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @author Andreas Gohr <[email protected]>
*/

// must be run within Dokuwiki
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
Expand All @@ -17,10 +16,6 @@
use dokuwiki\plugin\prosemirror\parser\InternalLinkNode;
use dokuwiki\plugin\prosemirror\parser\LinkNode;

if (!defined('DOKU_INC')) {
die();
}

class action_plugin_prosemirror_ajax extends ActionPlugin
{
/**
Expand All @@ -42,12 +37,10 @@ public function register(EventHandler $controller)
* Event: AJAX_CALL_UNKNOWN
*
* @param Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
*
* @return void
*/
public function handleAjax(Event $event, $param)
public function handleAjax(Event $event)
{
if ($event->data !== 'plugin_prosemirror') {
return;
Expand All @@ -61,61 +54,52 @@ public function handleAjax(Event $event, $param)
foreach ($INPUT->arr('actions') as $action) {
switch ($action) {
case 'resolveInternalLink':
{
$inner = $INPUT->str('inner');
$responseData[$action] = $this->resolveInternalLink($inner, $ID);
break;
}
$inner = $INPUT->str('inner');
$responseData[$action] = $this->resolveInternalLink($inner, $ID);
break;
case 'resolveInterWikiLink':
{
$inner = $INPUT->str('inner');
[$shortcut, $reference] = explode('>', $inner);
$responseData[$action] = $this->resolveInterWikiLink($shortcut, $reference);
break;
}
$inner = $INPUT->str('inner');
[$shortcut, $reference] = explode('>', $inner);
$responseData[$action] = $this->resolveInterWikiLink($shortcut, $reference);
break;
case 'resolveMedia':
{
$attrs = $INPUT->arr('attrs');
$responseData[$action] = [
'data-resolvedHtml' => ImageNode::resolveMedia(
$attrs['id'],
$attrs['title'],
$attrs['align'],
$attrs['width'],
$attrs['height'],
$attrs['cache'],
$attrs['linking']
)
];
break;
}
$attrs = $INPUT->arr('attrs');
$responseData[$action] = [
'data-resolvedHtml' => ImageNode::resolveMedia(
$attrs['id'],
$attrs['title'],
$attrs['align'],
$attrs['width'],
$attrs['height'],
$attrs['cache'],
$attrs['linking']
)
];
break;
case 'resolveImageTitle':
{
$image = $INPUT->arr('image');
$responseData[$action] = [];
$responseData[$action]['data-resolvedImage'] = LinkNode::resolveImageTitle(
$ID,
$image['id'],
$image['title'],
$image['align'],
$image['width'],
$image['height'],
$image['cache']
);
break;
}
$image = $INPUT->arr('image');
$responseData[$action] = [];
$responseData[$action]['data-resolvedImage'] = LinkNode::resolveImageTitle(
$ID,
$image['id'],
$image['title'],
$image['align'],
$image['width'],
$image['height'],
$image['cache']
);
break;
case 'resolveRSS':
{
$attrs = json_decode($INPUT->str('attrs'), true);
$responseData[$action] = RSSNode::renderAttrsToHTML($attrs);
break;
}
$attrs = json_decode($INPUT->str('attrs'), true);
$responseData[$action] = RSSNode::renderAttrsToHTML($attrs);
break;
default:
{
dbglog('Unknown action: ' . $action, __FILE__ . ': ' . __LINE__);
http_status(400, 'unknown action');
return;
}
dokuwiki\Logger::getInstance(dokuwiki\Logger::LOG_DEBUG)->log(
__FILE__ . ': ' . __LINE__,
'Unknown action: ' . $action
);
http_status(400, 'unknown action');
return;
}
}

Expand Down Expand Up @@ -148,12 +132,10 @@ protected function resolveInternalLink($inner, $curId)
* Event: AJAX_CALL_UNKNOWN
*
* @param Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
*
* @return void
*/
public function switchEditors(Event $event, $param)
public function switchEditors(Event $event)
{
if ($event->data !== 'plugin_prosemirror_switch_editors') {
return;
Expand Down
34 changes: 21 additions & 13 deletions action/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
* @author Andreas Gohr <[email protected]>
*/

// must be run within Dokuwiki
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\Form\Form;
use dokuwiki\Form\ButtonElement;

if (!defined('DOKU_INC')) {
die();
}

class action_plugin_prosemirror_editor extends ActionPlugin
{
/**
Expand Down Expand Up @@ -208,7 +203,9 @@ public function addAddtionalForms(Event $event)
$linkForm->addRadioButton('linktype', $this->getLang('type:wiki page'))->val('internallink');
$linkForm->addRadioButton('linktype', $this->getLang('type:interwiki'))->val('interwikilink');
$linkForm->addRadioButton('linktype', $this->getLang('type:email'))->val('emaillink');
$linkForm->addRadioButton('linktype', $this->getLang('type:external'))->val('externallink')->attr('checked', 'checked');
$linkForm->addRadioButton('linktype', $this->getLang('type:external'))
->val('externallink')
->attr('checked', 'checked');
$linkForm->addRadioButton('linktype', $this->getLang('type:other'))->val('other');
$linkForm->addTagClose('fieldset');
$linkForm->addTagClose('div');
Expand All @@ -218,7 +215,9 @@ public function addAddtionalForms(Event $event)
$linkForm->addTagOpen('legend');
$linkForm->addHTML('Link Name Type');
$linkForm->addTagClose('legend');
$linkForm->addRadioButton('nametype', $this->getLang('type:automatic title'))->val('automatic')->attr('checked', 'checked');
$linkForm->addRadioButton('nametype', $this->getLang('type:automatic title'))
->val('automatic')
->attr('checked', 'checked');
$linkForm->addRadioButton('nametype', $this->getLang('type:custom title'))->val('custom');
$linkForm->addRadioButton('nametype', $this->getLang('type:image'))->val('image');
$linkForm->addTextInput('linkname', 'Link name')->attr('placeholder', $this->getLang('placeholder:link name'));
Expand All @@ -240,9 +239,12 @@ public function addAddtionalForms(Event $event)
'style' => 'display: none;',
]);
$mediaForm->addFieldsetOpen($this->getLang('legend:media'))->addClass('js-media-fieldset');
$mediaForm->addButtonHTML('mediamanager', inlineSVG(DOKU_PLUGIN . 'prosemirror/images/file-image-outline.svg'))->attrs([
'type' => 'button',
'class' => 'js-open-mediamanager mediaform_mediamanager'
$mediaForm->addButtonHTML(
'mediamanager',
inlineSVG(DOKU_PLUGIN . 'prosemirror/images/file-image-outline.svg')
)->attrs([
'type' => 'button',
'class' => 'js-open-mediamanager mediaform_mediamanager'
]);
$mediaForm->addTextInput('mediatarget', $this->getLang('media target'))->attrs(
[
Expand Down Expand Up @@ -272,7 +274,9 @@ public function addAddtionalForms(Event $event)
$mediaForm->addTagOpen('legend');
$mediaForm->addHTML($this->getLang('legend:alignment'));
$mediaForm->addTagClose('legend');
$mediaForm->addRadioButton('alignment', $this->getLang('label:default alignment'))->val('')->attr('checked', 'checked');
$mediaForm->addRadioButton('alignment', $this->getLang('label:default alignment'))
->val('')
->attr('checked', 'checked');
$mediaForm->addRadioButton('alignment', $this->getLang('label:float left'))->val('left');
$mediaForm->addRadioButton('alignment', $this->getLang('label:center alignment'))->val('center');
$mediaForm->addRadioButton('alignment', $this->getLang('label:float right'))->val('right');
Expand All @@ -284,7 +288,9 @@ public function addAddtionalForms(Event $event)
$mediaForm->addTagOpen('legend');
$mediaForm->addHTML($this->getLang('legend:linking'));
$mediaForm->addTagClose('legend');
$mediaForm->addRadioButton('linking', $this->getLang('label:default linking'))->val('details')->attr('checked', 'checked');
$mediaForm->addRadioButton('linking', $this->getLang('label:default linking'))
->val('details')
->attr('checked', 'checked');
$mediaForm->addRadioButton('linking', $this->getLang('label:direct linking'))->val('direct');
$mediaForm->addRadioButton('linking', $this->getLang('label:nolink'))->val('nolink');
$mediaForm->addRadioButton('linking', $this->getLang('label:linkonly'))->val('linkonly');
Expand All @@ -296,7 +302,9 @@ public function addAddtionalForms(Event $event)
$mediaForm->addTagOpen('legend');
$mediaForm->addHTML($this->getLang('legend:caching'));
$mediaForm->addTagClose('legend');
$mediaForm->addRadioButton('caching', $this->getLang('label:default caching'))->val('')->attr('checked', 'checked');
$mediaForm->addRadioButton('caching', $this->getLang('label:default caching'))
->val('')
->attr('checked', 'checked');
$mediaForm->addRadioButton('caching', $this->getLang('label:recache'))->val('recache');
$mediaForm->addRadioButton('caching', $this->getLang('label:nocache'))->val('nocache');
$mediaForm->addTagClose('fieldset');
Expand Down
13 changes: 4 additions & 9 deletions action/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
* @author Andreas Gohr <[email protected]>
*/

// must be run within Dokuwiki
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\prosemirror\parser\SyntaxTreeBuilder;

if (!defined('DOKU_INC')) {
die();
}

class action_plugin_prosemirror_parser extends ActionPlugin
{
/**
Expand All @@ -28,8 +23,8 @@ class action_plugin_prosemirror_parser extends ActionPlugin
*/
public function register(EventHandler $controller)
{
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_preprocess');
$controller->register_hook('DRAFT_SAVE', 'BEFORE', $this, 'handle_draft');
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handlePreprocess');
$controller->register_hook('DRAFT_SAVE', 'BEFORE', $this, 'handleDraft');
}

/**
Expand All @@ -38,7 +33,7 @@ public function register(EventHandler $controller)
* @param Event $event
* @param $param
*/
public function handle_draft(Event $event, $param)
public function handleDraft(Event $event, $param)
{
global $INPUT;
$unparsedJSON = $INPUT->post->str('prosemirror_json');
Expand Down Expand Up @@ -80,7 +75,7 @@ public function handle_draft(Event $event, $param)
*
* @return void
*/
public function handle_preprocess(Event $event, $param)
public function handlePreprocess(Event $event, $param)
{
global $TEXT, $INPUT;
if (
Expand Down
6 changes: 5 additions & 1 deletion parser/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public static function getSubNode($node, Node $parent, Node $previous = null)
}
return $eventData['newNode'];
} catch (\Error $e) {
$exception = new ProsemirrorException('FIXME: better message for general error! Invalid node type received: ' . $node['type'], 0, $e);
$exception = new ProsemirrorException(
'FIXME: better message for general error! Invalid node type received: ' . $node['type'],
0,
$e
);
$exception->addExtraData('nodeData', $node);
$exception->addExtraData('parentNodeType', get_class($parent));

Expand Down
9 changes: 2 additions & 7 deletions renderer.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps

/**
* DokuWiki Plugin prosemirror (Renderer Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/

// must be run within Dokuwiki
use dokuwiki\plugin\prosemirror\parser\ImageNode;
use dokuwiki\plugin\prosemirror\parser\LocalLinkNode;
use dokuwiki\plugin\prosemirror\parser\InternalLinkNode;
Expand All @@ -20,12 +21,6 @@
use dokuwiki\plugin\prosemirror\schema\Node;
use dokuwiki\plugin\prosemirror\schema\NodeStack;

if (!defined('DOKU_INC')) {
die();
}

require_once DOKU_INC . 'inc/parser/renderer.php';

class renderer_plugin_prosemirror extends Doku_Renderer
{
/** @var NodeStack */
Expand Down
4 changes: 3 additions & 1 deletion schema/NodeStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public function drop($type)
$node = array_pop($this->stack);
$this->stacklength--;
if ($node->getType() != $type) {
throw new \RuntimeException("Expected the current node to be of type $type found " . $node->getType() . " instead.");
throw new \RuntimeException(
"Expected the current node to be of type $type found " . $node->getType() . " instead."
);
}
return $node;
}
Expand Down

0 comments on commit ca33838

Please sign in to comment.