Skip to content

Commit

Permalink
Merge pull request #290 from splitbrain/bot/autofix
Browse files Browse the repository at this point in the history
🤖 Automatic code style fixes
  • Loading branch information
splitbrain committed Dec 13, 2023
2 parents a0a5f87 + 44afde7 commit aa91e5d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 66 deletions.
57 changes: 29 additions & 28 deletions action.php
@@ -1,19 +1,23 @@
<?php

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

/**
* Translation Plugin: Simple multilanguage plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
* @author Guy Brand <gb@isis.u-strasbg.fr>
*/
class action_plugin_translation extends DokuWiki_Action_Plugin
class action_plugin_translation extends ActionPlugin
{
/**
* For the helper plugin
* @var helper_plugin_translation
*/
protected $helper = null;
protected $helper;

/**
* Constructor. Load helper plugin
Expand All @@ -26,9 +30,9 @@ public function __construct()
/**
* Registers a callback function for a given event
*
* @param Doku_Event_Handler $controller
* @param EventHandler $controller
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
if ($this->getConf('translateui')) {
$controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'translateUI');
Expand All @@ -50,9 +54,9 @@ public function register(Doku_Event_Handler $controller)
/**
* Hook Callback. Set the language for the UI
*
* @param Doku_Event $event INIT_LANG_LOAD
* @param Event $event INIT_LANG_LOAD
*/
public function translateUI(Doku_Event $event)
public function translateUI(Event $event)
{
global $conf;
global $ACT;
Expand Down Expand Up @@ -88,9 +92,9 @@ public function translateUI(Doku_Event $event)
/**
* Hook Callback. Pass language code to JavaScript dispatcher
*
* @param Doku_Event $event TPL_METAHEADER_OUTPUT
* @param Event $event TPL_METAHEADER_OUTPUT
*/
public function translateJS(Doku_Event $event)
public function translateJS(Event $event)
{
global $conf;

Expand All @@ -105,9 +109,9 @@ public function translateJS(Doku_Event $event)
/**
* Hook Callback. Cache JavaScript per language
*
* @param Doku_Event $event JS_CACHE_USE
* @param Event $event JS_CACHE_USE
*/
public function translateJSCache(Doku_Event $event)
public function translateJSCache(Event $event)
{
global $conf;

Expand All @@ -121,9 +125,9 @@ public function translateJSCache(Doku_Event $event)
/**
* Hook Callback. Add lang and dir attributes when UI isn't translated
*
* @param Doku_Event $event TPL_CONTENT_DISPLAY
* @param Event $event TPL_CONTENT_DISPLAY
*/
public function addLanguageAttributes(Doku_Event $event)
public function addLanguageAttributes(Event $event)
{
global $ID;
global $conf;
Expand All @@ -147,9 +151,9 @@ public function addLanguageAttributes(Doku_Event $event)
/**
* Hook Callback. Redirect to translated start page
*
* @param Doku_Event $event DOKUWIKI_STARTED
* @param Event $event DOKUWIKI_STARTED
*/
public function redirectStartPage(Doku_Event $event)
public function redirectStartPage(Event $event)
{
global $ID;
global $ACT;
Expand All @@ -158,7 +162,7 @@ public function redirectStartPage(Doku_Event $event)
if ($ID == $conf['start'] && $ACT == 'show') {
$lc = $this->helper->getBrowserLang();

list($translatedStartpage,) = $this->helper->buildTransID($lc, $conf['start']);
[$translatedStartpage, ] = $this->helper->buildTransID($lc, $conf['start']);
if (cleanID($translatedStartpage) !== cleanID($ID)) {
send_redirect(wl(cleanID($translatedStartpage), '', true));
}
Expand All @@ -168,9 +172,9 @@ public function redirectStartPage(Doku_Event $event)
/**
* Hook Callback. Add hreflang attributes to the page header
*
* @param Doku_Event $event TPL_METAHEADER_OUTPUT
* @param Event $event TPL_METAHEADER_OUTPUT
*/
public function addHrefLangAttributes(Doku_Event $event)
public function addHrefLangAttributes(Event $event)
{
global $ID;
global $conf;
Expand Down Expand Up @@ -201,9 +205,9 @@ public function addHrefLangAttributes(Doku_Event $event)
* Hook Callback. Make current language available as page template placeholder and handle
* original language copying
*
* @param Doku_Event $event COMMON_PAGETPL_LOAD
* @param Event $event COMMON_PAGETPL_LOAD
*/
public function handlePageTemplates(Doku_Event $event)
public function handlePageTemplates(Event $event)
{
global $ID;

Expand All @@ -227,19 +231,16 @@ public function handlePageTemplates(Doku_Event $event)

// show user a choice of translations if any
if (count($translations) > 1) {
$links = array();
foreach ($translations as $t => $l) {
$links[] = '<a href="' . wl($ID, array(
'do' => 'edit',
'fromlang' => $t,
)) . '">' . $this->helper->getLocalName($t) . '</a>';
$links = [];
foreach (array_keys($translations) as $t) {
$links[] = '<a href="' . wl($ID, ['do' => 'edit', 'fromlang' => $t]) . '">' . $this->helper->getLocalName($t) . '</a>';
}

msg(
sprintf(
$this->getLang('transloaded'),
$this->helper->getLocalName($orig),
join(', ', $links)
implode(', ', $links)
)
);
}
Expand All @@ -255,9 +256,9 @@ public function handlePageTemplates(Doku_Event $event)
* Hook Callback. Resort page match results so that results are ordered by translation, having the
* default language first
*
* @param Doku_Event $event SEARCH_QUERY_PAGELOOKUP
* @param Event $event SEARCH_QUERY_PAGELOOKUP
*/
public function sortSearchResults(Doku_Event $event)
public function sortSearchResults(Event $event)
{
// sort into translation slots
$res = [];
Expand Down
16 changes: 9 additions & 7 deletions admin.php
@@ -1,12 +1,14 @@
<?php

use dokuwiki\Extension\AdminPlugin;

/**
* DokuWiki Plugin translation (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <andi@splitbrain.org>
*/
class admin_plugin_translation extends DokuWiki_Admin_Plugin
class admin_plugin_translation extends AdminPlugin
{
/** @inheritdoc */
public function forAdminOnly()
Expand All @@ -15,12 +17,12 @@ public function forAdminOnly()
}

/** @inheritdoc */
function handle()
public function handle()
{
}

/** @inheritdoc */
function html()
public function html()
{

/** @var helper_plugin_translation $helper */
Expand Down Expand Up @@ -60,14 +62,14 @@ function html()
$row .= "<td>" . $xhtml_renderer->internallink($page['id'], $page['id'], null, true) . "</td>";
}

list(/* $lc */, $idpart) = $helper->getTransParts($page["id"]);
[, $idpart] = $helper->getTransParts($page["id"]);

foreach ($helper->translations as $t) {
if ($t === $default_language) {
continue;
}

list($translID, /* $name */) = $helper->buildTransID($t, $idpart);
[$translID, ] = $helper->buildTransID($t, $idpart);

$difflink = '';
if (!page_exists($translID)) {
Expand Down Expand Up @@ -113,8 +115,8 @@ protected function getAllPages()
{
$namespace = $this->getConf("translationns");
$dir = dirname(wikiFN("$namespace:foo"));
$pages = array();
search($pages, $dir, 'search_allpages', array());
$pages = [];
search($pages, $dir, 'search_allpages', []);
return $pages;
}
}
46 changes: 23 additions & 23 deletions helper.php
@@ -1,12 +1,15 @@
<?php

use dokuwiki\Extension\Plugin;
use dokuwiki\ChangeLog\PageChangeLog;

/**
* Translation Plugin: Simple multilanguage plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
class helper_plugin_translation extends DokuWiki_Plugin
class helper_plugin_translation extends Plugin
{
public $translations = [];
public $translationNs = '';
Expand All @@ -26,7 +29,7 @@ public function __construct()
$this->loadTranslationNamespaces();

// load language names
$this->LN = confToHash(dirname(__FILE__) . '/lang/langnames.txt');
$this->LN = confToHash(__DIR__ . '/lang/langnames.txt');

// display options
$this->opts = $this->getConf('display');
Expand Down Expand Up @@ -70,7 +73,7 @@ public function loadTranslationNamespaces()
*/
public function getLangPart($id)
{
list($lng) = $this->getTransParts($id);
[$lng] = $this->getTransParts($id);
return $lng;
}

Expand All @@ -83,11 +86,11 @@ public function getLangPart($id)
*/
public function getTransParts($id)
{
$rx = '/^' . $this->translationNs . '(' . join('|', $this->translations) . '):(.*)/';
$rx = '/^' . $this->translationNs . '(' . implode('|', $this->translations) . '):(.*)/';
if (preg_match($rx, $id, $match)) {
return array($match[1], $match[2]);
return [$match[1], $match[2]];
}
return array('', $id);
return ['', $id];
}

/**
Expand All @@ -101,7 +104,7 @@ public function getBrowserLang()
if (!in_array($conf['lang'], $langs)) {
$langs[] = $conf['lang'];
}
$rx = '/(^|,|:|;|-)(' . join('|', $langs) . ')($|,|:|;|-)/i';
$rx = '/(^|,|:|;|-)(' . implode('|', $langs) . ')($|,|:|;|-)/i';
if (preg_match($rx, $_SERVER['HTTP_ACCEPT_LANGUAGE'], $match)) {
return strtolower($match[2]);
}
Expand All @@ -125,7 +128,7 @@ public function buildTransID($lng, $idpart)
$link = ':' . $this->translationNs . $idpart;
$name = $this->realLC('');
}
return array($link, $name);
return [$link, $name];
}

/**
Expand Down Expand Up @@ -180,8 +183,8 @@ public function showAbout()

$about = $this->getConf('about');
if ($this->getConf('localabout')) {
list(/* $lc */, $idpart) = $this->getTransParts($about);
list($about, /* $name */) = $this->buildTransID($curlc, $idpart);
[, $idpart] = $this->getTransParts($about);
[$about, ] = $this->buildTransID($curlc, $idpart);
$about = cleanID($about);
}

Expand All @@ -200,13 +203,13 @@ public function showAbout()
*/
public function getAvailableTranslations($id)
{
$result = array();
$result = [];

list($lc, $idpart) = $this->getTransParts($id);
[$lc, $idpart] = $this->getTransParts($id);

foreach ($this->translations as $t) {
if ($t == $lc) continue; //skip self
list($link, $name) = $this->buildTransID($t, $idpart);
[$link, $name] = $this->buildTransID($t, $idpart);
if (page_exists($link)) {
$result[$name] = $link;
}
Expand All @@ -229,7 +232,7 @@ public function showTranslations($checkage = true)
if (!$this->istranslatable($INFO['id'])) return '';
if ($checkage) $this->checkage();

list(/* $lc */, $idpart) = $this->getTransParts($INFO['id']);
[, $idpart] = $this->getTransParts($INFO['id']);

$out = '<div class="plugin_translation ' . ($this->getConf('dropdown') ? 'is-dropdown' : '') . '">';

Expand Down Expand Up @@ -264,10 +267,7 @@ public function showTranslations($checkage = true)
*/
public function getLocalName($lang)
{
if (isset($this->LN[$lang])) {
return $this->LN[$lang];
}
return $lang;
return $this->LN[$lang] ?? $lang;
}

/**
Expand All @@ -280,7 +280,7 @@ public function getLocalName($lang)
*/
protected function prepareLanguageSelectorItem($lc, $idpart, $current)
{
list($target, $lang) = $this->buildTransID($lc, $idpart);
[$target, $lang] = $this->buildTransID($lc, $idpart);
$target = cleanID($target);
$exists = page_exists($target, '', false);

Expand Down Expand Up @@ -329,11 +329,11 @@ public function checkage()
$lng = $this->getLangPart($ID);
if ($lng == $this->defaultlang) return;

$rx = '/^' . $this->translationNs . '((' . join('|', $this->translations) . '):)?/';
$rx = '/^' . $this->translationNs . '((' . implode('|', $this->translations) . '):)?/';
$idpart = preg_replace($rx, '', $ID);

// compare modification times
list($orig, /* $name */) = $this->buildTransID($this->defaultlang, $idpart);
[$orig, ] = $this->buildTransID($this->defaultlang, $idpart);
$origfn = wikiFN($orig);
if ($INFO['lastmod'] >= @filemtime($origfn)) return;

Expand All @@ -360,7 +360,7 @@ public function getOldDiffLink($id, $lastmod)
{
// get revision from before translation
$orev = false;
$changelog = new \dokuwiki\ChangeLog\PageChangeLog($id);
$changelog = new PageChangeLog($id);
$revs = $changelog->getRevisions(0, 100);
foreach ($revs as $rev) {
if ($rev < $lastmod) {
Expand All @@ -372,6 +372,6 @@ public function getOldDiffLink($id, $lastmod)
return false;
}
$id = cleanID($id);
return wl($id, array('do' => 'diff', 'rev' => $orev));
return wl($id, ['do' => 'diff', 'rev' => $orev]);
}
}

0 comments on commit aa91e5d

Please sign in to comment.