Skip to content

Commit

Permalink
Merge pull request #145 from Klap-in/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
splitbrain authored Oct 30, 2023
2 parents c6d79ae + 4d75850 commit d045ee9
Show file tree
Hide file tree
Showing 18 changed files with 2,195 additions and 1,649 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/dokuwiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: DokuWiki Default Tasks
on:
push:
pull_request:
schedule:
- cron: '54 0 2 * *'


jobs:
all:
uses: dokuwiki/github-action/.github/workflows/all.yml@main
3 changes: 1 addition & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ Repository Plugin for DokuWiki

All documentation for the Repository Plugin is available online at:

* http://www.dokuwiki.org/plugin:repository
* https://www.dokuwiki.org/plugin:repository

This plugin is tested with DokuWiki 2010-10-14 and later.

(c) 2010 by Andreas Gohr/Håkan Sandell
----
Expand Down
86 changes: 86 additions & 0 deletions _test/GeneralTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace dokuwiki\plugin\pluginrepo\test;

use DokuWikiTest;

/**
* General tests for the pluginrepo plugin
*
* @group plugin_pluginrepo
* @group plugins
*/
class GeneralTest extends DokuWikiTest
{

/**
* Simple test to make sure the plugin.info.txt is in correct format
*/
public function testPluginInfo(): void
{
$file = __DIR__ . '/../plugin.info.txt';
$this->assertFileExists($file);

$info = confToHash($file);

$this->assertArrayHasKey('base', $info);
$this->assertArrayHasKey('author', $info);
$this->assertArrayHasKey('email', $info);
$this->assertArrayHasKey('date', $info);
$this->assertArrayHasKey('name', $info);
$this->assertArrayHasKey('desc', $info);
$this->assertArrayHasKey('url', $info);

$this->assertEquals('pluginrepo', $info['base']);
$this->assertRegExp('/^https?:\/\//', $info['url']);
$this->assertTrue(mail_isvalid($info['email']));
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
$this->assertTrue(false !== strtotime($info['date']));
}

/**
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
* conf/metadata.php.
*/
public function testPluginConf(): void
{
$conf_file = __DIR__ . '/../conf/default.php';
$meta_file = __DIR__ . '/../conf/metadata.php';

if (!file_exists($conf_file) && !file_exists($meta_file)) {
self::markTestSkipped('No config files exist -> skipping test');
}

if (file_exists($conf_file)) {
include($conf_file);
}
if (file_exists($meta_file)) {
include($meta_file);
}

$this->assertEquals(
gettype($conf),
gettype($meta),
'Both ' . DOKU_PLUGIN . 'pluginrepo/conf/default.php and ' . DOKU_PLUGIN . 'pluginrepo/conf/metadata.php have to exist and contain the same keys.'
);

if ($conf !== null && $meta !== null) {
foreach ($conf as $key => $value) {
$this->assertArrayHasKey(
$key,
$meta,
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'pluginrepo/conf/metadata.php'
);
}

foreach ($meta as $key => $value) {
$this->assertArrayHasKey(
$key,
$conf,
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'pluginrepo/conf/default.php'
);
}
}

}
}
31 changes: 20 additions & 11 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;

/**
* Removes entries from repository database when removed from page
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*/

/**
* Register actions for event hooks
*/
class action_plugin_pluginrepo extends DokuWiki_Action_Plugin {

class action_plugin_pluginrepo extends ActionPlugin
{
/**
* Registers a callback function for a given event
*
* @param Doku_Event_Handler $controller
*/
public function register(Doku_Event_Handler $controller) {
public function register(EventHandler $controller)
{
$controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, '_cleanOldEntry');
}

Expand All @@ -25,21 +30,26 @@ public function register(Doku_Event_Handler $controller) {
*
* @param Doku_Event $event event object
*/
public function _cleanOldEntry(Doku_Event $event) {
public function _cleanOldEntry(Event $event)
{
global $ID;

$data = $event->data;
$haspluginentry = preg_match('/----+ *plugin *-+/', $data[0][1]); // addSpecialPattern: ----+ *plugin *-+\n.*?\n----+
$hastemplateentry = preg_match('/----+ *template *-+/', $data[0][1]); // addSpecialPattern: ----+ *template *-+\n.*?\n----+
if($haspluginentry || $hastemplateentry) {
// addSpecialPattern: ----+ *plugin *-+\n.*?\n----+
$haspluginentry = preg_match('/----+ *plugin *-+/', $data[0][1]);
// addSpecialPattern: ----+ *template *-+\n.*?\n----+
$hastemplateentry = preg_match('/----+ *template *-+/', $data[0][1]);
if ($haspluginentry || $hastemplateentry) {
return; // plugin seems still to be there
}

/** @var helper_plugin_pluginrepo_repository $hlp */
$hlp = $this->loadHelper('pluginrepo_repository');
if(!$hlp) return;
if (!$hlp) {
return;
}

if(curNS($ID) == 'plugin') {
if (curNS($ID) == 'plugin') {
$id = noNS($ID);
} else {
$id = curNS($ID) . ':' . noNS($ID);
Expand All @@ -48,4 +58,3 @@ public function _cleanOldEntry(Doku_Event $event) {
$hlp->deletePlugin($id);
}
}

16 changes: 9 additions & 7 deletions api.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../');
require_once(DOKU_INC.'inc/init.php');
if (!defined('DOKU_INC')) {
define('DOKU_INC', __DIR__ . '/../../../');
}
require_once(DOKU_INC . 'inc/init.php');

require_once(DOKU_PLUGIN . 'pluginrepo/helper/repository.php');

Expand All @@ -26,24 +28,24 @@
header('Pragma: public');
header('X-Robots-Tag: noindex');

if($INPUT->str('cmd') == 'ping') {
if ($INPUT->str('cmd') == 'ping') {
header('Content-Type: text/plain; charset=utf-8');
echo '1';
} else {
switch($INPUT->str('fmt')) {
switch ($INPUT->str('fmt')) {
case 'debug':
header('Content-Type: text/plain; charset=utf-8');
print_r($extensions);
break;
case 'xml':
header('Content-Type: application/xml; charset=utf-8');
require('classes/A2Xml.php');
require(__DIR__ . '/classes/A2Xml.php');
$xml = xml_encode((object) $extensions, "hash");
echo $xml;
break;
case 'yaml':
header('Content-Type: text/yaml');
require('classes/Spyc.php');
require(__DIR__ . '/classes/Spyc.php');
echo Spyc::YAMLDump($extensions, false, 0);
break;
case 'php':
Expand All @@ -54,7 +56,7 @@
$data = json_encode($extensions);
$cb = $INPUT->str('cb');
$cb = preg_replace('/\W+/', '', $cb);
if($cb) {
if ($cb) {
header('Content-Type: text/javascript');
echo "$cb($data);";
} else {
Expand Down
62 changes: 33 additions & 29 deletions classes/A2Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,39 @@
Source code from http://blog.waaile.com/array-to-xml
*/

function xml_encode($value, $tag = "root") {
if( !is_array($value)
&& !is_string($value)
&& !is_bool($value)
&& !is_numeric($value)
&& !is_object($value) ) {
return false;
}
function x2str($xml,$key) {
if (!is_array($xml) && !is_object($xml)) {
return "<$key>".htmlspecialchars($xml)."</$key>";
}
$xml_str="";
foreach ($xml as $k=>$v) {
if(is_numeric($k)) {
$k = "_".$k;
}
$xml_str.=x2str($v,$k);
}
return "<$key>$xml_str</$key>";
}
return simplexml_load_string(x2str($value,$tag))->asXml();
function xml_encode($value, $tag = "root")
{
if (
!is_array($value)
&& !is_string($value)
&& !is_bool($value)
&& !is_numeric($value)
&& !is_object($value)
) {
return false;
}
function x2str($xml, $key)
{
if (!is_array($xml) && !is_object($xml)) {
return "<$key>" . htmlspecialchars($xml) . "</$key>";
}
$xml_str = "";
foreach ($xml as $k => $v) {
if (is_numeric($k)) {
$k = "_" . $k;
}
$xml_str .= x2str($v, $k);
}
return "<$key>$xml_str</$key>";
}
return simplexml_load_string(x2str($value, $tag))->asXml();
}

function xml_decode($xml) {
if(!is_string($xml)) {
return false;
}
$xml = @simplexml_load_string($xml);
return $xml;
function xml_decode($xml)
{
if (!is_string($xml)) {
return false;
}
$xml = @simplexml_load_string($xml);
return $xml;
}
?>
Loading

0 comments on commit d045ee9

Please sign in to comment.