Skip to content

Commit

Permalink
Remove Wikidata autocomplete for tags
Browse files Browse the repository at this point in the history
Also fix up error in pagination status and add i18n for the
form field label.

Bug: #169
  • Loading branch information
samwilson committed Jan 22, 2023
1 parent 618d335 commit 595fb1d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
18 changes: 4 additions & 14 deletions src/Controller/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ public function viewTag(
*/
public function tagSearchJson(
Request $request,
TagRepository $tagRepository,
WikidataRepository $wikidataRepository
TagRepository $tagRepository
) {
$q = $request->get('q', '');
$page = (int)$request->get('page', 1);
$tagsResults = $tagRepository->search($q, $page, $this->getUser());
$pageSize = 20;
$tagsResults = $tagRepository->search($q, $page, $pageSize, $this->getUser());
$tags = [
'results' => [],
];
if ($page === 1) {
if ($page === 1 && count($tagsResults) >= $pageSize) {
$tags['pagination'] = ['more' => true];
}
foreach ($tagsResults as $tag) {
Expand All @@ -88,16 +88,6 @@ public function tagSearchJson(
'text' => $tag->getTitle(),
];
}
// If not many local results are found, augment them with Wikidata items.
if ($q && $page > 1 && count($tags['results']) < 10) {
$wikidata = $wikidataRepository->search($q);
foreach ($wikidata['results'] as $result) {
$tags['results'][] = [
'id' => $result['text'],
'text' => $result['text'] . ' (' . $result['id'] . ' - ' . $result['description'] . ')',
];
}
}
return new JsonResponse($tags);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ public function findWikidata(): array
* @param User|null $user
* @return array
*/
public function search(string $term, int $pageNum, ?User $user = null): array
public function search(string $term, int $pageNum, int $pageSize, ?User $user = null): array
{
if (empty($term)) {
return [];
}
$pageSize = 20;
$groupList = $user ? $user->getGroupIdList() : false;
if (!$groupList) {
$groupList = UserGroup::PUBLIC;
Expand Down
2 changes: 1 addition & 1 deletion templates/post/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</span>
</p>
<p>
<label for="tags">Tags (semicolon-separated):</label>
<label for="tags">{{'posts.tags_label'|trans}}</label>
<select multiple id="tags" name="tags[]" class="app-select2" tabindex="80">
{% for tag in post.tags %}
<option value="{{ tag.title }}" selected>{{ tag.title }}</option>
Expand Down
1 change: 1 addition & 0 deletions translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ security:
log_in: 'Log in'
remember_me: 'Remember me'
posts:
tags_label: 'Tags:'
replies: 'Replies'
download_link: 'Download'
save_tooltip: 'Save the full version of this file'
Expand Down

0 comments on commit 595fb1d

Please sign in to comment.