Skip to content

Commit

Permalink
Merge branch 'dev' into channels-tab
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Dec 18, 2024
2 parents 4e35e52 + 45dff88 commit ad70bc7
Show file tree
Hide file tree
Showing 62 changed files with 507 additions and 339 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"laminas/laminas-text": "2.11.0",
"laminas/laminas-validator": "2.64.2",
"laminas/laminas-view": "2.27.0",
"laminas/laminas-translator": "^1",
"league/commonmark": "2.6.0",
"league/oauth2-client": "^2.7",
"league/oauth2-server": "8.5.4",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/vufind/RateLimiter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ Policies:
# - storage settings for the result cache
# And see the required config in contentsecuritypolicy.ini if CSP is used.
#Turnstile:
#enabled: false

# These two keys are required. See also values they can be set to for testing purposes:
# https://developers.cloudflare.com/turnstile/troubleshooting/testing/
#siteKey: 0x1234567890
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
'Laminas\Session\SessionManager' => 'VuFind\Session\ManagerFactory',
],
'delegators' => [
'Laminas\I18n\Translator\TranslatorInterface' => [
'Laminas\Mvc\I18n\Translator' => [
'VuFind\I18n\Translator\TranslatorFactory',
],
'SlmLocale\Locale\Detector' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace VuFind\I18n\Translator;

use Laminas\I18n\Translator\TranslatorInterface;
use Laminas\Mvc\I18n\Translator;
use VuFind\Config\PathResolver;
use VuFind\I18n\Locale\LocaleSettings;

Expand Down Expand Up @@ -101,14 +101,14 @@ protected function getTextDomains(): array
/**
* Configure a translator to support the requested language.
*
* @param TranslatorInterface $translator Translator
* @param LocaleSettings $settings Locale settings
* @param string $language Language to set up
* @param Translator $translator Translator
* @param LocaleSettings $settings Locale settings
* @param string $language Language to set up
*
* @return void
*/
protected function addLanguageToTranslator(
TranslatorInterface $translator,
Translator $translator,
LocaleSettings $settings,
string $language
): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function load($locale, $filename)
*/
public function getLanguageFilename($locale, $domain)
{
return empty($domain)
return (empty($domain) || $domain === 'default')
? $locale . '.ini'
: $domain . '/' . $locale . '.ini';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace VuFind\I18n\Translator;

use Laminas\I18n\Translator\TranslatorInterface;
use Laminas\Translator\TranslatorInterface;

/**
* Lightweight translator aware marker interface (used as an alternative to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace VuFind\I18n\Translator;

use Laminas\I18n\Translator\TranslatorInterface;
use Laminas\Translator\TranslatorInterface;

use function count;
use function is_array;
Expand All @@ -50,7 +50,7 @@ trait TranslatorAwareTrait
/**
* Translator
*
* @var \Laminas\I18n\Translator\TranslatorInterface
* @var TranslatorInterface
*/
protected $translator = null;

Expand All @@ -70,7 +70,7 @@ public function setTranslator(TranslatorInterface $translator)
/**
* Get translator object.
*
* @return \Laminas\I18n\Translator\TranslatorInterface
* @return TranslatorInterface
*/
public function getTranslator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace VuFind\I18n\Translator;

use Laminas\I18n\Translator\TranslatorInterface;
use Laminas\Mvc\I18n\Translator;
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\Factory\DelegatorFactoryInterface;
Expand Down Expand Up @@ -94,13 +94,13 @@ public function __invoke(
/**
* Add caching to a translator object
*
* @param TranslatorInterface $translator Translator object
* @param ContainerInterface $container Service manager
* @param Translator $translator Translator object
* @param ContainerInterface $container Service manager
*
* @return void
*/
protected function enableCaching(
TranslatorInterface $translator,
Translator $translator,
ContainerInterface $container
): void {
// Set up language caching for better performance:
Expand Down
34 changes: 5 additions & 29 deletions module/VuFind/src/VuFind/ILS/Driver/Aleph.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

namespace VuFind\ILS\Driver;

use Laminas\I18n\Translator\TranslatorInterface;
use Laminas\Mvc\I18n\Translator;
use VuFind\Date\DateException;
use VuFind\Exception\ILS as ILSException;

Expand Down Expand Up @@ -78,27 +78,6 @@ class Aleph extends AbstractBase implements
*/
protected $alephTranslator = false;

/**
* Cache manager
*
* @var \VuFind\Cache\Manager
*/
protected $cacheManager;

/**
* Translator
*
* @var TranslatorInterface
*/
protected $translator;

/**
* Date converter object
*
* @var \VuFind\Date\Converter
*/
protected $dateConverter = null;

/**
* The base URL, where the REST DLF API is running
*
Expand Down Expand Up @@ -240,16 +219,13 @@ class Aleph extends AbstractBase implements
*
* @param \VuFind\Date\Converter $dateConverter Date converter
* @param ?\VuFind\Cache\Manager $cacheManager Cache manager (optional)
* @param ?TranslatorInterface $translator Translator (optional)
* @param ?Translator $translator Translator (optional)
*/
public function __construct(
\VuFind\Date\Converter $dateConverter,
?\VuFind\Cache\Manager $cacheManager = null,
?TranslatorInterface $translator = null
protected \VuFind\Date\Converter $dateConverter,
protected ?\VuFind\Cache\Manager $cacheManager = null,
protected ?Translator $translator = null
) {
$this->dateConverter = $dateConverter;
$this->cacheManager = $cacheManager;
$this->translator = $translator;
}

/**
Expand Down
43 changes: 28 additions & 15 deletions module/VuFind/src/VuFind/OAI/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use VuFind\Db\Service\ChangeTrackerServiceInterface;
use VuFind\Db\Service\OaiResumptionServiceInterface;
use VuFind\Exception\RecordMissing as RecordMissingException;
use VuFind\RecordDriver\AbstractBase as AbstractRecordDriver;
use VuFind\SimpleXML;
use VuFindApi\Formatter\RecordFormatter;

Expand Down Expand Up @@ -378,7 +379,7 @@ protected function attachRecordHeader(
*
* @param object $record A record driver object
*
* @return string
* @return string|false String on success and false if an error occurred
*/
protected function getVuFindMetadata($record)
{
Expand Down Expand Up @@ -444,24 +445,20 @@ protected function attachNonDeleted(
$headerOnly = false,
$set = ''
) {
// Get the XML (and display an error if it is unsupported):
if ($format === false) {
$xml = ''; // no metadata if in header-only mode!
} elseif ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) {
$xml = $this->getVuFindMetadata($record); // special case
} else {
$xml = $record
->getXML($format, $this->baseHostURL, $this->recordLinkerHelper);
if ($xml === false) {
return false;
}
// If no format was requested, report success without doing anything:
return true;
}

$xml = $this->getRecordAsXML($record, $format);

// Headers should be returned only if the metadata format matching
// the supplied metadataPrefix is available.
// If RecordDriver returns nothing, skip this record.
if (empty($xml)) {
return true;
// If returned XML is empty, return true to simply skip this record.
// If returned XML is false, an error was encountered during the process
// of generating the XML file.
if (!$xml) {
return $xml !== false;
}

// Check for sets:
Expand Down Expand Up @@ -492,14 +489,30 @@ protected function attachNonDeleted(
);

// Inject metadata if necessary:
if (!$headerOnly && !empty($xml)) {
if (!$headerOnly) {
$metadata = $recXml->addChild('metadata');
SimpleXML::appendElement($metadata, $xml);
}

return true;
}

/**
* Get record as a metadata presentation
*
* @param AbstractRecordDriver $record A record driver object
* @param string $format Metadata format to obtain
*
* @return string|false String or false if an error occured
*/
protected function getRecordAsXML(AbstractRecordDriver $record, string $format): string|false
{
if ('oai_vufind_json' === $format && $this->supportsVuFindMetadata()) {
return $this->getVuFindMetadata($record);
}
return $record->getXML($format, $this->baseHostURL, $this->recordLinkerHelper);
}

/**
* Respond to a GetRecord request.
*
Expand Down
23 changes: 20 additions & 3 deletions module/VuFind/src/VuFind/RateLimiter/RateLimiterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class RateLimiterManager implements LoggerAwareInterface, TranslatorAwareInterfa
use LoggerAwareTrait;
use TranslatorAwareTrait;

/**
* Turnstile service
*
* @var ?Turnstile
*/
protected $turnstile = null;

/**
* Current event description for logging
*
Expand All @@ -77,15 +84,13 @@ class RateLimiterManager implements LoggerAwareInterface, TranslatorAwareInterfa
* @param string $clientIp Client's IP address
* @param ?int $userId User ID or null if not logged in
* @param Closure $rateLimiterFactoryCallback Rate limiter factory callback
* @param Turnstile $turnstile Turnstile service
* @param IpAddressUtils $ipUtils IP address utilities
*/
public function __construct(
protected array $config,
protected string $clientIp,
protected ?int $userId,
protected Closure $rateLimiterFactoryCallback,
protected Turnstile $turnstile,
protected IpAddressUtils $ipUtils
) {
$this->clientLogDetails = "ip:$clientIp";
Expand All @@ -94,6 +99,18 @@ public function __construct(
}
}

/**
* Set the turnstile service instance.
*
* @param Turnstile $turnstile Turnstile service
*
* @return void
*/
public function setTurnstile(Turnstile $turnstile)
{
$this->turnstile = $turnstile;
}

/**
* Check if rate limiter is enabled
*
Expand Down Expand Up @@ -152,7 +169,7 @@ public function check(EventInterface $event): array
if (
$limit->isAccepted() &&
($this->config['Policies'][$policyId]['turnstileRateLimiterSettings'] ?? false) &&
$this->turnstile->isChallengeAllowed($event)
$this->turnstile?->isChallengeAllowed($event)
) {
$turnstileLimiter = ($this->rateLimiterFactoryCallback)(
$this->config,
Expand Down
13 changes: 11 additions & 2 deletions module/VuFind/src/VuFind/RateLimiter/RateLimiterManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,23 @@ public function __invoke(
$authManager = $container->get(\VuFind\Auth\Manager::class);
$request = $container->get('Request');

return new $requestedName(
$rateLimiterManager = new $requestedName(
$config,
$request->getServer('REMOTE_ADDR'),
$authManager->getUserObject()?->getId(),
Closure::fromCallable([$this, 'getRateLimiter']),
$container->get(\VuFind\RateLimiter\Turnstile\Turnstile::class),
$container->get(\VuFind\Net\IpAddressUtils::class)
);

if (
($config['Turnstile']['enabled'] ?? false)
&& (strtolower($config['Storage']['adapter']) != 'redis')
) {
$turnstile = $container->get(\VuFind\RateLimiter\Turnstile\Turnstile::class);
$rateLimiterManager->setTurnstile($turnstile);
}

return $rateLimiterManager;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Recommend/AuthorInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace VuFind\Recommend;

use Exception;
use Laminas\I18n\Translator\TranslatorInterface;
use Laminas\Translator\TranslatorInterface;
use VuFind\Connection\Wikipedia;
use VuFind\I18n\Translator\TranslatorAwareInterface;
use VuFindSearch\Query\Query;
Expand Down
8 changes: 3 additions & 5 deletions module/VuFind/src/VuFind/Service/CurrencyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ class CurrencyFormatter
/**
* Constructor
*
* @param string $defaultCurrency Default currency format (ISO 4217) to use (null
* for default from system locale)
* @param string $locale Locale to use for number formatting (null for
* default system locale)
* @param string $defaultCurrency Default currency format (ISO 4217) to use (null for default from system locale)
* @param ?string $locale Locale to use for number formatting (null for default system locale)
*/
public function __construct($defaultCurrency = null, $locale = null)
{
// Initialize number formatter:
$locale ??= setlocale(LC_MONETARY, 0);
$locale ??= setlocale(LC_MONETARY, '');
$this->formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);

// Initialize default currency:
Expand Down
Loading

0 comments on commit ad70bc7

Please sign in to comment.