Skip to content

Commit 25bd2ac

Browse files
committed
Merge #18223 - Add a configuration option to allow shared bookmarks: $cfg['AllowSharedBookmarks']
Pull-request: #18223 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents b12b3f2 + c716102 commit 25bd2ac

13 files changed

Lines changed: 79 additions & 13 deletions

File tree

doc/config.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,15 @@ Various display setting
35403540
specify the amount of saved history items using
35413541
:config:option:`$cfg['QueryHistoryMax']`.
35423542

3543+
.. config:option:: $cfg['AllowSharedBookmarks']
3544+
3545+
:type: boolean
3546+
:default: true
3547+
3548+
.. versionadded:: 6.0.0
3549+
3550+
Allow users to create bookmarks that are available for all other users
3551+
35433552
.. config:option:: $cfg['BrowseMIME']
35443553
35453554
:type: boolean

libraries/classes/Bookmark.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function applyVariables(array $variables): string
175175
/**
176176
* Creates a Bookmark object from the parameters
177177
*
178-
* @param mixed[] $bkmFields the properties of the bookmark to add; here, $bkm_fields['bkm_sql_query'] is urlencoded
178+
* @param mixed[] $bkmFields the properties of the bookmark to add; here, $bkmFields['bkm_sql_query'] is urlencoded
179179
* @param bool $allUsers whether to make the bookmark available for all users
180180
*/
181181
public static function createBookmark(
@@ -191,6 +191,14 @@ public static function createBookmark(
191191
return false;
192192
}
193193

194+
if (! $GLOBALS['cfg']['AllowSharedBookmarks']) {
195+
$allUsers = false;
196+
}
197+
198+
if (! $allUsers && ! strlen((string) $bkmFields['bkm_user'])) {
199+
return false;
200+
}
201+
194202
$bookmark = new Bookmark($dbi, new Relation($dbi));
195203
$bookmark->database = $bkmFields['bkm_database'];
196204
$bookmark->label = $bkmFields['bkm_label'];
@@ -227,10 +235,17 @@ public static function getList(
227235
string $user,
228236
string|false $db = false,
229237
): array {
238+
$exactUserMatch = ! $GLOBALS['cfg']['AllowSharedBookmarks'];
239+
230240
$query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database)
231241
. '.' . Util::backquote($bookmarkFeature->bookmark)
232-
. " WHERE ( `user` = ''"
233-
. ' OR `user` = ' . $dbi->quoteString($user) . ' )';
242+
. ' WHERE (`user` = ' . $dbi->quoteString($user);
243+
if (! $exactUserMatch) {
244+
$query .= " OR `user` = ''";
245+
}
246+
247+
$query .= ')';
248+
234249
if ($db !== false) {
235250
$query .= ' AND dbase = ' . $dbi->quoteString($db);
236251
}
@@ -275,6 +290,10 @@ public static function get(
275290
return null;
276291
}
277292

293+
if (! $GLOBALS['cfg']['AllowSharedBookmarks']) {
294+
$exactUserMatch = true;
295+
}
296+
278297
$query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database)
279298
. '.' . Util::backquote($bookmarkFeature->bookmark)
280299
. ' WHERE dbase = ' . $dbi->quoteString($db->getName());

libraries/classes/Config/Descriptions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ private static function getDescriptions(): array
329329
. 'storage). If disabled, this utilizes JS-routines to display query history '
330330
. '(lost by window close).',
331331
),
332+
'AllowSharedBookmarks_desc' => __('Allow users to create bookmarks that are available for all other users'),
332333
'Servers_SessionTimeZone_desc' => __(
333334
'Sets the effective timezone; possibly different than the one from your database server',
334335
),
@@ -854,6 +855,7 @@ private static function getNames(): array
854855
'ProtectBinary_name' => __('Protect binary columns'),
855856
'QueryHistoryDB_name' => __('Permanent query history'),
856857
'QueryHistoryMax_name' => __('Query history length'),
858+
'AllowSharedBookmarks_name' => __('Allow shared bookmarks between users'),
857859
'RecodingEngine_name' => __('Recoding engine'),
858860
'RememberSorting_name' => __('Remember table\'s sorting'),
859861
'TablePrimaryKeyOrder_name' => __('Primary key default sort order'),

libraries/classes/Config/Forms/Setup/SqlForm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static function getForms(): array
1515
$result = parent::getForms();
1616
/* Following are not available to user */
1717
$result['Sql_queries'][] = 'QueryHistoryDB';
18+
$result['Sql_queries'][] = 'AllowSharedBookmarks';
1819

1920
return $result;
2021
}

libraries/classes/Config/Settings.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,17 @@ final class Settings
19251925
*/
19261926
public int $QueryHistoryMax;
19271927

1928+
/**
1929+
* Allow shared bookmarks between users
1930+
*
1931+
* ```php
1932+
* $cfg['AllowSharedBookmarks'] = true;
1933+
* ```
1934+
*
1935+
* @link https://docs.phpmyadmin.net/en/latest/config.html#cfg_AllowSharedBookmarks
1936+
*/
1937+
public bool $AllowSharedBookmarks;
1938+
19281939
/**
19291940
* Use MIME-Types (stored in column comments table) for
19301941
*
@@ -2565,6 +2576,7 @@ public function __construct(array $settings)
25652576
$this->repeatCells = $this->setRepeatCells($settings);
25662577
$this->QueryHistoryDB = $this->setQueryHistoryDB($settings);
25672578
$this->QueryHistoryMax = $this->setQueryHistoryMax($settings);
2579+
$this->AllowSharedBookmarks = $this->setAllowSharedBookmarks($settings);
25682580
$this->BrowseMIME = $this->setBrowseMIME($settings);
25692581
$this->MaxExactCount = $this->setMaxExactCount($settings);
25702582
$this->MaxExactCountViews = $this->setMaxExactCountViews($settings);
@@ -2762,6 +2774,7 @@ public function asArray(): array
27622774
'RepeatCells' => $this->repeatCells,
27632775
'QueryHistoryDB' => $this->QueryHistoryDB,
27642776
'QueryHistoryMax' => $this->QueryHistoryMax,
2777+
'AllowSharedBookmarks' => $this->AllowSharedBookmarks,
27652778
'BrowseMIME' => $this->BrowseMIME,
27662779
'MaxExactCount' => $this->MaxExactCount,
27672780
'MaxExactCountViews' => $this->MaxExactCountViews,
@@ -4796,6 +4809,16 @@ private function setQueryHistoryMax(array $settings): int
47964809
return $queryHistoryMax >= 1 ? $queryHistoryMax : 25;
47974810
}
47984811

4812+
/** @param array<int|string, mixed> $settings */
4813+
private function setAllowSharedBookmarks(array $settings): bool
4814+
{
4815+
if (! isset($settings['AllowSharedBookmarks'])) {
4816+
return true;
4817+
}
4818+
4819+
return (bool) $settings['AllowSharedBookmarks'];
4820+
}
4821+
47994822
/** @param array<int|string, mixed> $settings */
48004823
private function setBrowseMIME(array $settings): bool
48014824
{

libraries/classes/Sql.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ private function getQueryResponseForNoResultsReturned(
10351035
]),
10361036
'user' => $GLOBALS['cfg']['Server']['user'],
10371037
'sql_query' => $completeQuery ?? $sqlQuery,
1038+
'allow_shared_bookmarks' => $GLOBALS['cfg']['AllowSharedBookmarks'],
10381039
]);
10391040
}
10401041

libraries/classes/SqlQueryForm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function getHtml(
116116
'bookmarks' => $bookmarks,
117117
'can_convert_kanji' => Encoding::canConvertKanji(),
118118
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
119+
'allow_shared_bookmarks' => $GLOBALS['cfg']['AllowSharedBookmarks'],
119120
]);
120121
}
121122

psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@
610610
<file src="libraries/classes/Config/Forms/Setup/SqlForm.php">
611611
<MixedArrayAssignment>
612612
<code><![CDATA[$result['Sql_queries'][]]]></code>
613+
<code><![CDATA[$result['Sql_queries'][]]]></code>
613614
</MixedArrayAssignment>
614615
</file>
615616
<file src="libraries/classes/Config/ServerConfigChecks.php">

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
cached_affected_rows: int|numeric-string,
4545
cfg: array{
4646
AllowArbitraryServer: bool,
47+
AllowSharedBookmarks: bool,
4748
AllowThirdPartyFraming: bool|'sameorigin',
4849
ArbitraryServerRegexp: string,
4950
AvailableCharsets: string[],

templates/sql/bookmark.twig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
<input class="form-control" id="bookmarkLabelField" type="text" name="bkm_fields[bkm_label]" value="">
1616
</div>
1717

18-
<div class="form-check form-switch">
19-
<input class="form-check-input" type="checkbox" role="switch" id="bookmarkAllUsersCheckbox" name="bkm_all_users" value="true">
20-
<label class="form-check-label" for="bookmarkAllUsersCheckbox">{% trans 'Let every user access this bookmark' %}</label>
21-
</div>
18+
{% if allow_shared_bookmarks %}
19+
<div class="form-check form-switch">
20+
<input class="form-check-input" type="checkbox" role="switch" id="bookmarkAllUsersCheckbox" name="bkm_all_users" value="true">
21+
<label class="form-check-label" for="bookmarkAllUsersCheckbox">{% trans 'Let every user access this bookmark' %}</label>
22+
</div>
23+
{% endif %}
2224
</div>
2325
<div class="card-footer">
2426
<input class="btn btn-secondary" type="submit" value="{% trans 'Create new bookmark' %}">

0 commit comments

Comments
 (0)