From 8b356ff3afc32c8ba3c071c0f85802950f9d92f7 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 13 Sep 2023 15:36:54 +0200 Subject: [PATCH 1/3] use new test workflows --- .github/workflows/dokuwiki.yml | 11 +++++++ .github/workflows/phpTestLinux.yml | 52 ------------------------------ 2 files changed, 11 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/dokuwiki.yml delete mode 100644 .github/workflows/phpTestLinux.yml diff --git a/.github/workflows/dokuwiki.yml b/.github/workflows/dokuwiki.yml new file mode 100644 index 00000000..31b4b081 --- /dev/null +++ b/.github/workflows/dokuwiki.yml @@ -0,0 +1,11 @@ +name: DokuWiki Default Tasks +on: + push: + pull_request: + schedule: + - cron: '22 12 25 * *' + + +jobs: + all: + uses: dokuwiki/github-action/.github/workflows/all.yml@main diff --git a/.github/workflows/phpTestLinux.yml b/.github/workflows/phpTestLinux.yml deleted file mode 100644 index 4853ad1c..00000000 --- a/.github/workflows/phpTestLinux.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: PHP Tests on Linux - -on: [push, pull_request] - -jobs: - testLinux: - name: PHP ${{ matrix.php-versions }} DokuWiki ${{ matrix.dokuwiki-branch }} - runs-on: ubuntu-latest - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository - - strategy: - matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0'] - dokuwiki-branch: [ 'master', 'stable'] - exclude: - - dokuwiki-branch: 'stable' - php-versions: '8.0' - fail-fast: false - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring, intl, PDO, pdo_sqlite, bz2 - - - name: Setup problem matchers - run: | - echo ::add-matcher::${{ runner.tool_cache }}/php.json - echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json - - - name: Download DokuWiki Test-setup - run: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh - - - name: Run DokuWiki Test-setup - env: - CI_SERVER: 1 - DOKUWIKI: ${{ matrix.dokuwiki-branch }} - run: sh travis.sh - - - name: Setup PHPUnit - run: | - php _test/fetchphpunit.php - cd _test - - - name: Run PHPUnit - run: | - cd _test - php phpunit.phar --verbose --stderr --group plugin_dw2pdf From 852931daed0aa7c73fc4da5d421d2c117decf509 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 13 Sep 2023 16:13:49 +0200 Subject: [PATCH 2/3] rector and php sniffer cleanups --- DokuImageProcessorDecorator.php | 57 ++++++----- DokuPDF.class.php | 33 +++---- MenuItem.php | 14 +-- _test/ActionPagenameSortTest.php | 6 +- action.php | 161 +++++++++++++++++-------------- conf/default.php | 1 + conf/metadata.php | 2 +- renderer.php | 155 ++++++++++++++++------------- syntax/exportlink.php | 6 +- syntax/pagesetting.php | 38 ++++---- 10 files changed, 259 insertions(+), 214 deletions(-) diff --git a/DokuImageProcessorDecorator.php b/DokuImageProcessorDecorator.php index 8ac719af..2c2c2571 100644 --- a/DokuImageProcessorDecorator.php +++ b/DokuImageProcessorDecorator.php @@ -2,10 +2,10 @@ namespace dokuwiki\plugin\dw2pdf; -require_once __DIR__ . '/vendor/autoload.php'; - -class DokuImageProcessorDecorator extends \Mpdf\Image\ImageProcessor { +use Mpdf\Image\ImageProcessor; +class DokuImageProcessorDecorator extends ImageProcessor +{ /** * Override the mpdf _getImage function * @@ -14,14 +14,21 @@ class DokuImageProcessorDecorator extends \Mpdf\Image\ImageProcessor { * making sure that only cached file paths are passed to mpdf. It also * takes care of checking image ACls. */ - public function getImage (&$file, $firsttime = true, $allowvector = true, $orig_srcpath = false, $interpolation = false) { - list($file, $orig_srcpath) = self::adjustGetImageLinks($file, $orig_srcpath); + public function getImage( + &$file, + $firsttime = true, + $allowvector = true, + $orig_srcpath = false, + $interpolation = false + ) { + [$file, $orig_srcpath] = self::adjustGetImageLinks($file, $orig_srcpath); return parent::getImage($file, $firsttime, $allowvector, $orig_srcpath, $interpolation); } - public static function adjustGetImageLinks($file, $orig_srcpath) { + public static function adjustGetImageLinks($file, $orig_srcpath) + { global $conf; // build regex to parse URL back to media info @@ -29,42 +36,44 @@ public static function adjustGetImageLinks($file, $orig_srcpath) { $re = str_replace('xxx123yyy', '([^&\?]*)', $re); // extract the real media from a fetch.php uri and determine mime - if(preg_match("/^$re/", $file, $m) || + if ( + preg_match("/^$re/", $file, $m) || preg_match('/[&?]media=([^&?]*)/', $file, $m) ) { $media = rawurldecode($m[1]); - list($ext, $mime) = mimetype($media); + [$ext, $mime] = mimetype($media); } else { - list($ext, $mime) = mimetype($file); + [$ext, $mime] = mimetype($file); } // local files $local = ''; - if(substr($file, 0, 9) == 'dw2pdf://') { + if (substr($file, 0, 9) == 'dw2pdf://') { // support local files passed from plugins $local = substr($file, 9); - } elseif(!preg_match('/(\.php|\?)/', $file)) { + } elseif (!preg_match('/(\.php|\?)/', $file)) { $re = preg_quote(DOKU_URL, '/'); // directly access local files instead of using HTTP, skip dynamic content $local = preg_replace("/^$re/i", DOKU_INC, $file); } - if(substr($mime, 0, 6) == 'image/') { - if(!empty($media)) { + if (substr($mime, 0, 6) == 'image/') { + if (!empty($media)) { // any size restrictions? - $w = $h = 0; + $w = 0; + $h = 0; $rev = ''; - if(preg_match('/[?&]w=(\d+)/', $file, $m)) $w = $m[1]; - if(preg_match('/[?&]h=(\d+)/', $file, $m)) $h = $m[1]; - if(preg_match('/[&?]rev=(\d+)/', $file, $m)) $rev = $m[1]; + if (preg_match('/[?&]w=(\d+)/', $file, $m)) $w = $m[1]; + if (preg_match('/[?&]h=(\d+)/', $file, $m)) $h = $m[1]; + if (preg_match('/[&?]rev=(\d+)/', $file, $m)) $rev = $m[1]; - if(media_isexternal($media)) { + if (media_isexternal($media)) { $local = media_get_from_URL($media, $ext, -1); - if(!$local) $local = $media; // let mpdf try again + if (!$local) $local = $media; // let mpdf try again } else { $media = cleanID($media); //check permissions (namespace only) - if(auth_quickaclcheck(getNS($media) . ':X') < AUTH_READ) { + if (auth_quickaclcheck(getNS($media) . ':X') < AUTH_READ) { $file = ''; $local = ''; } else { @@ -73,18 +82,18 @@ public static function adjustGetImageLinks($file, $orig_srcpath) { } //handle image resizing/cropping - if($w && file_exists($local)) { - if($h) { + if ($w && file_exists($local)) { + if ($h) { $local = media_crop_image($local, $ext, $w, $h); } else { $local = media_resize_image($local, $ext, $w, $h); } } - } elseif(!file_exists($local) && media_isexternal($file)) { // fixed external URLs + } elseif (!file_exists($local) && media_isexternal($file)) { // fixed external URLs $local = media_get_from_URL($file, $ext, $conf['cachetime']); } - if($local) { + if ($local) { $file = $local; $orig_srcpath = $local; } diff --git a/DokuPDF.class.php b/DokuPDF.class.php index e5ec2a0c..a64fffa3 100644 --- a/DokuPDF.class.php +++ b/DokuPDF.class.php @@ -1,4 +1,10 @@ */ - -use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator; - -require_once __DIR__ . '/vendor/autoload.php'; - -/** - * Class DokuPDF - * Some DokuWiki specific extentions - */ -class DokuPDF extends \Mpdf\Mpdf +class DokuPDF extends Mpdf { - /** * DokuPDF constructor. * @@ -26,12 +22,16 @@ class DokuPDF extends \Mpdf\Mpdf * @param string $orientation * @param int $fontsize */ - function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11, $docLang = 'en') + public function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11, $docLang = 'en') { global $conf; global $lang; - if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/'); + require_once __DIR__ . '/vendor/autoload.php'; + + if (!defined('_MPDF_TEMP_PATH')) { + define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . random_int(1, 1000) . '/'); + } io_mkdir_p(_MPDF_TEMP_PATH); $format = $pagesize; @@ -48,7 +48,6 @@ function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11 break; default: $mode = 'UTF-8-s'; - } parent::__construct([ @@ -76,7 +75,7 @@ function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11 /** * Cleanup temp dir */ - function __destruct() + public function __destruct() { io_rmdir(_MPDF_TEMP_PATH, true); } @@ -87,11 +86,9 @@ function __destruct() * @param string $path * @param string $basepath */ - function GetFullPath(&$path, $basepath = '') + public function GetFullPath(&$path, $basepath = '') { $path = htmlspecialchars_decode($path); parent::GetFullPath($path, $basepath); } - - } diff --git a/MenuItem.php b/MenuItem.php index 6aaf6b5d..735e8ed0 100644 --- a/MenuItem.php +++ b/MenuItem.php @@ -11,8 +11,8 @@ * * @package dokuwiki\plugin\dw2pdf */ -class MenuItem extends AbstractItem { - +class MenuItem extends AbstractItem +{ /** @var string do action for this plugin */ protected $type = 'export_pdf'; @@ -22,13 +22,14 @@ class MenuItem extends AbstractItem { /** * MenuItem constructor. */ - public function __construct() { + public function __construct() + { parent::__construct(); global $REV, $DATE_AT; - if($DATE_AT) { + if ($DATE_AT) { $this->params['at'] = $DATE_AT; - } elseif($REV) { + } elseif ($REV) { $this->params['rev'] = $REV; } } @@ -38,7 +39,8 @@ public function __construct() { * * @return string */ - public function getLabel() { + public function getLabel() + { $hlp = plugin_load('action', 'dw2pdf'); return $hlp->getLang('export_pdf_button'); } diff --git a/_test/ActionPagenameSortTest.php b/_test/ActionPagenameSortTest.php index d946e599..f7188d6c 100644 --- a/_test/ActionPagenameSortTest.php +++ b/_test/ActionPagenameSortTest.php @@ -17,8 +17,8 @@ public function testDirectPagenameSort() { $action = new \action_plugin_dw2pdf(); - $this->assertLessThan(0, $action->_pagenamesort(['id' => 'bar'], ['id' => 'bar:start'])); - $this->assertGreaterThan(0, $action->_pagenamesort(['id' => 'bar:bar'], ['id' => 'bar:start'])); + $this->assertLessThan(0, $action->cbPagenameSort(['id' => 'bar'], ['id' => 'bar:start'])); + $this->assertGreaterThan(0, $action->cbPagenameSort(['id' => 'bar:bar'], ['id' => 'bar:start'])); } /** @@ -96,7 +96,7 @@ public function testPagenameSort($comment, $expected) // run sort $action = new \action_plugin_dw2pdf(); - usort($input, [$action, '_pagenamesort']); + usort($input, [$action, 'cbPagenameSort']); $this->assertSame($prepared, $input); } diff --git a/action.php b/action.php index cde0d63d..2c03b857 100644 --- a/action.php +++ b/action.php @@ -1,32 +1,31 @@ * @author Andreas Gohr */ - -/** - * Class action_plugin_dw2pdf - * - * Export html content to pdf, for different url parameter configurations - * DokuPDF which extends mPDF is used for generating the pdf from html. - */ - -use dokuwiki\Cache\Cache; -use dokuwiki\plugin\dw2pdf\MenuItem; -use dokuwiki\StyleUtils; -use Mpdf\MpdfException; - -class action_plugin_dw2pdf extends DokuWiki_Action_Plugin +class action_plugin_dw2pdf extends ActionPlugin { /** * Settings for current export, collected from url param, plugin config, global config * * @var array */ - protected $exportConfig = null; + protected $exportConfig; /** @var string template name, to use templates from dw2pdf/tpl/