Skip to content

Commit

Permalink
Merge branch 'pkp:main' into f5000_7431
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhein authored Sep 18, 2023
2 parents 34cd3fe + 43e3855 commit 7132aab
Show file tree
Hide file tree
Showing 72 changed files with 1,799 additions and 851 deletions.
2 changes: 1 addition & 1 deletion classes/author/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Author extends Identity
/**
* Get the default/fall back locale the values should exist for
*/
public function getDefaultLocale(): string
public function getDefaultLocale(): ?string
{
return $this->getSubmissionLocale();
}
Expand Down
8 changes: 5 additions & 3 deletions classes/cliTool/CommandLineTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use PKP\plugins\PluginRegistry;
use PKP\security\Role;
use PKP\session\SessionManager;
use PKP\user\User;
use PKP\config\Config;

/** Initialization code */
define('PWD', getcwd());
Expand All @@ -50,10 +52,10 @@ class CommandLineTool
public $argv;

/** @var string the username provided */
public $username;
public ?string $username = null;

/** @var \PKP\user\User the user provided */
public $user;
public ?User $user = null;

public function __construct($argv = [])
{
Expand All @@ -77,7 +79,7 @@ public function __construct($argv = [])

$this->scriptName = isset($this->argv[0]) ? array_shift($this->argv) : '';

$this->checkArgsForUsername();
if (Config::getVar('general', 'installed')) $this->checkArgsForUsername();

if (isset($this->argv[0]) && $this->argv[0] == '-h') {
$this->exitWithUsageMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct($action, $locales, $announcementContext)
foreach ($announcementTypes as $announcementType) {
$announcementOptions[] = [
'value' => (int) $announcementType->getId(),
'label' => $announcementType->getLocalizedTypeName(),
'label' => htmlspecialchars($announcementType->getLocalizedTypeName()),
];
}
if (!empty($announcementOptions)) {
Expand Down
4 changes: 2 additions & 2 deletions classes/components/forms/context/PKPAppearanceSetupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($action, $locales, $context, $baseUrl, $temporaryFil
if (isset($plugins[$plugin])) {
$enabledOptions[] = [
'value' => $plugin,
'label' => $plugins[$plugin]->getDisplayName(),
'label' => htmlspecialchars($plugins[$plugin]->getDisplayName()),
];
}
}
Expand All @@ -67,7 +67,7 @@ public function __construct($action, $locales, $context, $baseUrl, $temporaryFil
if (!in_array($pluginName, $currentBlocks)) {
$disabledOptions[] = [
'value' => $pluginName,
'label' => $plugin->getDisplayName(),
'label' => htmlspecialchars($plugin->getDisplayName()),
];
}
}
Expand Down
4 changes: 2 additions & 2 deletions classes/components/forms/context/PKPPaymentSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct($action, $locales, $context)
foreach (Locale::getCurrencies() as $currency) {
$currencies[] = [
'value' => $currency->getLetterCode(),
'label' => $currency->getLocalName(),
'label' => htmlspecialchars($currency->getLocalName()),
];
}

Expand All @@ -57,7 +57,7 @@ public function __construct($action, $locales, $context)
foreach ($paymentPlugins as $plugin) {
$pluginList[] = [
'value' => $plugin->getName(),
'label' => $plugin->getDisplayName(),
'label' => htmlspecialchars($plugin->getDisplayName()),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($action, $context, LazyCollection $userGroups)
foreach ($userGroups as $userGroup) {
$userGroupOptions[] = [
'value' => $userGroup->getId(),
'label' => $userGroup->getLocalizedData('name'),
'label' => htmlspecialchars($userGroup->getLocalizedData('name')),
];
}

Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/context/PKPThemeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct($action, $locales, $context = null)
foreach ($plugins as $plugin) {
$themes[] = [
'value' => $plugin->getDirName(),
'label' => $plugin->getDisplayName(),
'label' => htmlspecialchars($plugin->getDisplayName()),
];
}

Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/site/PKPSiteAppearanceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($action, $locales, $site, $baseUrl, $temporaryFileAp
foreach ($plugins as $pluginName => $plugin) {
$sidebarOptions[] = [
'value' => $pluginName,
'label' => $plugin->getDisplayName(),
'label' => htmlspecialchars($plugin->getDisplayName()),
];
}

Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/site/PKPSiteBulkEmailsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct($action, $site, $contexts)
foreach ($contexts as $context) {
$options[] = [
'value' => $context->id,
'label' => $context->name,
'label' => htmlspecialchars($context->name),
];
}

Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/site/PKPSiteConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct($action, $locales, $site)
foreach ($contextsIterator as $context) {
$options[] = [
'value' => $context->getId(),
'label' => $context->getLocalizedData('name'),
'label' => htmlspecialchars($context->getLocalizedData('name')),
];
}
if (count($options) > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct($action, $genres)
'options' => array_map(function ($genre) {
return [
'value' => (int) $genre->getId(),
'label' => $genre->getLocalizedName(),
'label' => htmlspecialchars($genre->getLocalizedName()),
];
}, $genres),
'value' => 0,
Expand Down
6 changes: 5 additions & 1 deletion classes/components/listPanels/PKPSelectReviewerListPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class PKPSelectReviewerListPanel extends ListPanel
/** @var string URL to the API endpoint where items can be retrieved */
public $apiUrl = '';

/** @var array Affiliatory institutions of the publication authors */
public $authorAffiliations = [];

/** @var int Number of items to show at one time */
public $count = 30;

Expand Down Expand Up @@ -62,6 +65,7 @@ public function getConfig()
{
$config = parent::getConfig();
$config['apiUrl'] = $this->apiUrl;
$config['authorAffiliations'] = $this->authorAffiliations;
$config['count'] = $this->count;
$config['currentlyAssigned'] = $this->currentlyAssigned;
$config['selectorName'] = $this->selectorName;
Expand Down Expand Up @@ -129,7 +133,6 @@ public function getConfig()
}

$config['itemsMax'] = $this->itemsMax;

$config['activeReviewsCountLabel'] = __('reviewer.list.activeReviews');
$config['activeReviewsLabel'] = __('reviewer.list.activeReviewsDescription');
$config['assignedToLastRoundLabel'] = __('reviewer.list.assignedToLastRound');
Expand All @@ -148,6 +151,7 @@ public function getConfig()
$config['reassignLabel'] = __('reviewer.list.reassign');
$config['reassignWithNameLabel'] = __('reviewer.list.reassign.withName');
$config['reviewerRatingLabel'] = __('reviewer.list.reviewerRating');
$config['reviewerSameInstitutionLabel'] = __('reviewer.list.reviewerSameInstitution');
$config['reviewInterestsLabel'] = __('reviewer.list.reviewInterests');
$config['selectReviewerLabel'] = __('editor.submission.selectReviewer');
$config['warnOnAssignmentLabel'] = __('reviewer.list.warnOnAssign');
Expand Down
67 changes: 34 additions & 33 deletions classes/core/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
namespace PKP\core;

use APP\core\Application;
use Exception;
use PKP\db\DAO;
use PKP\db\DAORegistry;
use \PKP\filter\FilterDAO;
use PKP\facades\Locale;
use PKP\filter\FilterDAO;

/**
* @template T of EntityDAO|DAO
Expand Down Expand Up @@ -62,56 +61,59 @@ public function __construct()
/**
* Get a piece of data for this object, localized to the current
* locale if possible.
*
* @param string $key
* @param string $preferredLocale
*/
public function getLocalizedData($key, $preferredLocale = null)
public function getLocalizedData(string $key, string $preferredLocale = null, string &$selectedLocale = null): mixed
{
$localePrecedence = $this->_getLocalePrecedence();
foreach ($localePrecedence as $locale) {
foreach ($this->getLocalePrecedence($preferredLocale) as $locale) {
$value = & $this->getData($key, $locale);
if (!empty($value)) {
$selectedLocale = $locale;
return $value;
}
unset($value);
}

// Fallback: Get the first available piece of data.
$data = $this->getData($key, null);
if (!empty($data)) {
$locales = array_keys($data);
$firstLocale = array_shift($locales);
return $data[$firstLocale];
foreach ((array) $data as $locale => $dataValue) {
if (!empty($dataValue)) {
$selectedLocale = $locale;
return $dataValue;
}
}

return null;
}

/**
* Get the stack of "important" locales, most important first.
* Get the locale precedence order for object in the following order
*
* @return string[]
* 1. Preferred Locale if provided
* 2. User's current local
* 3. Object's default locale if set
* 4. Context's primary locale if context available
* 5. Site's primary locale
*/
private function _getLocalePrecedence(): array
public function getLocalePrecedence(string $preferredLocale = null): array
{
static $localePrecedence;
if (!isset($localePrecedence)) {
$request = Application::get()->getRequest();
$localePrecedence = [Locale::getLocale()];

$context = $request->getContext();
if ($context && !in_array($context->getPrimaryLocale(), $localePrecedence)) {
$localePrecedence[] = $context->getPrimaryLocale();
}
$request = Application::get()->getRequest();

return array_unique(
array_filter([
$preferredLocale ?? Locale::getLocale(),
$this->getDefaultLocale(),
$request->getContext()?->getPrimaryLocale(),
$request->getSite()->getPrimaryLocale(),
])
);
}

$site = $request->getSite();
if ($site && !in_array($site->getPrimaryLocale(), $localePrecedence)) {
$localePrecedence[] = $site->getPrimaryLocale();
}
}
return $localePrecedence;
/**
* Get the default locale for object
*/
public function getDefaultLocale(): ?string
{
return null;
}

/**
Expand All @@ -120,7 +122,6 @@ private function _getLocalePrecedence(): array
* @param string $key
* @param string $locale (optional)
*
* @return mixed
*/
public function &getData($key, $locale = null)
{
Expand Down Expand Up @@ -493,7 +494,7 @@ public function injectMetadata($metadataDescription)
*
* @param \PKP\metadata\MetadataSchema $metadataSchema
*
* @return $metadataDescription MetadataDescription
* @return MetadataDescription
*/
public function extractMetadata($metadataSchema)
{
Expand Down
4 changes: 2 additions & 2 deletions classes/core/ItemIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace PKP\core;

/**
* @template TKey
* @template TKey of array-key
* @template TValue
*/
class ItemIterator
Expand All @@ -43,7 +43,7 @@ public function next()
/**
* Return the next item with key.
*
* @return array<Tkey,TValue>
* @return array{?TKey, ?TValue}
*/
public function nextWithKey()
{
Expand Down
1 change: 0 additions & 1 deletion classes/core/PKPApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ public function getCurrentVersion()
public function getDAOMap()
{
return [
'AccessKeyDAO' => 'PKP\security\AccessKeyDAO',
'AnnouncementDAO' => 'PKP\announcement\AnnouncementDAO',
'AnnouncementTypeDAO' => 'PKP\announcement\AnnouncementTypeDAO',
'CitationDAO' => 'PKP\citation\CitationDAO',
Expand Down
14 changes: 10 additions & 4 deletions classes/facades/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use PKP\submissionFile\Repository as SubmissionFileRepository;
use PKP\userGroup\Repository as UserGroupRepository;
use PKP\log\event\Repository as EventLogRepository;
use PKP\invitation\repositories\Invitation as InvitationRepository;

class Repo
{
Expand Down Expand Up @@ -88,8 +89,13 @@ public static function userGroup(): UserGroupRepository
return app(UserGroupRepository::class);
}

public static function eventLog(): EventLogRepository
{
return app(EventLogRepository::class);
}
public static function eventLog(): EventLogRepository
{
return app(EventLogRepository::class);
}

public static function invitation(): InvitationRepository
{
return app(InvitationRepository::class);
}
}
2 changes: 1 addition & 1 deletion classes/filter/CompositeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function hasData($key, $locale = null)
*
* @param string $settingName
*
* @return $compositeSettingName string
* @return string Composite setting name
*/
public function _getCompositeSettingName($settingName)
{
Expand Down
2 changes: 1 addition & 1 deletion classes/filter/FilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function compareFilters(&$filterA, $filterBSettings, &$filterBSubfilters)
*
* @param XMLNode $settingNode
*
* @return $setting array a key-value pair.
* @return array A key-value pair.
*/
public function getFilterSetting($settingNode)
{
Expand Down
Loading

0 comments on commit 7132aab

Please sign in to comment.