Victorbarbu has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324216

Change subject: Provide special page with list of all available badges
......................................................................

Provide special page with list of all available badges

Bug: T114473
Change-Id: I8cd2912b629bc4e9f744156653b28cd4c5ef531a
---
M repo/Wikibase.php
M repo/i18n/en.json
M repo/i18n/qqq.json
A repo/includes/Specials/SpecialAvailableBadges.php
4 files changed, 94 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/16/324216/1

diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index f4cb472..2b96e52 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -209,6 +209,7 @@
                = Wikibase\Repo\Specials\SpecialMyLanguageFallbackChain::class;
        $wgSpecialPages['MergeItems'] = 
Wikibase\Repo\Specials\SpecialMergeItems::class;
        $wgSpecialPages['RedirectEntity'] = 
Wikibase\Repo\Specials\SpecialRedirectEntity::class;
+       $wgSpecialPages['AvailableBadges'] = 
Wikibase\Repo\Specials\SpecialAvailableBadges::class;
 
        // Jobs
        $wgJobClasses['UpdateRepoOnMove'] = 
Wikibase\Repo\UpdateRepo\UpdateRepoOnMoveJob::class;
diff --git a/repo/i18n/en.json b/repo/i18n/en.json
index eac67a6..0343566 100644
--- a/repo/i18n/en.json
+++ b/repo/i18n/en.json
@@ -136,6 +136,7 @@
        "wikibase-wikibaserepopage-invalid-id": "The ID \"$1\" is unknown to 
the system. Please use a valid entity ID.",
        "wikibase-wikibaserepopage-unresolved-redirect": "$1 is a redirect.",
        "wikibase-wikibaserepopage-storage-exception": "An error occurred while 
trying to load $1: $2.",
+       "special-availablebadges": "Available badges",
        "special-itembytitle": "Item by title",
        "wikibase-itembytitle-lookup-fieldset": "Search for items by site and 
title",
        "wikibase-itembytitle-lookup-site": "Site:",
diff --git a/repo/i18n/qqq.json b/repo/i18n/qqq.json
index 17b040d..a6265a4 100644
--- a/repo/i18n/qqq.json
+++ b/repo/i18n/qqq.json
@@ -167,6 +167,7 @@
        "wikibase-wikibaserepopage-invalid-id": "Response informing that the 
selected entity ID is not valid.\n\nParameters:\n* $1 - the invalid ID",
        "wikibase-wikibaserepopage-unresolved-redirect": "Error message shown 
when the user supplied an entity ID that refers to a redirect.\nParameters:\n* 
$1 - the entity ID",
        "wikibase-wikibaserepopage-storage-exception": "Error message shown 
when an entity could not be loaded due to a storage layer 
exception.\nParameters:\n* $1 - the entity ID\n* $2 - the (unlocalized and 
possibly technical) error message.",
+       "special-availablebadges": "{{doc-special|AvailableBadges}}\nTitle of 
the page containing a list of all available badges",
        "special-itembytitle": "{{doc-special|ItemByTitle}}\nThe item is 
identified through use of the site and title, but the lookup failed and further 
qualification must be done. See also the Wikidata glossary for 
[[d:Wikidata:Glossary#languageattribute-label|label]] and 
[[d:Wikidata:Glossary#Items|items]].",
        "wikibase-itembytitle-lookup-fieldset": "This is the title for the 
fieldset on the special page for further refining the search. This is the 
search by site and title.",
        "wikibase-itembytitle-lookup-site": "Label for the textfield holding 
the site id. See also the Wikidata glossary for 
[[d:Wikidata:Glossary#sitelinks|sitelinks]].\n{{Identical|Site}}",
diff --git a/repo/includes/Specials/SpecialAvailableBadges.php 
b/repo/includes/Specials/SpecialAvailableBadges.php
new file mode 100644
index 0000000..776f5e4
--- /dev/null
+++ b/repo/includes/Specials/SpecialAvailableBadges.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace Wikibase\Repo\Specials;
+
+use Html;
+use HTMLForm;
+use Linker;
+use Wikibase\Client\Store\TitleFactory;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\ItemIdParser;
+use Wikibase\Lib\ContentLanguages;
+use Wikibase\Lib\LanguageNameLookup;
+use Wikibase\Repo\WikibaseRepo;
+
+/**
+ * Page for displaying diagnostics about the dispatch process.
+ *
+ * @since 0.4
+ *
+ * @license GPL-2.0+
+ * @author Victor Barbu < victorbarb...@gmail.com >
+ */
+class SpecialAvailableBadges extends SpecialWikibasePage {
+
+       /**
+        * @var WikibaseRepo
+        */
+       private $repo;
+
+       /**
+        * @var \Wikibase\Store\BufferingTermLookup
+        */
+       private $bufferingTermLookup;
+
+       public function __construct() {
+               parent::__construct( 'AvailableBadges' );
+
+               $this->repo = WikibaseRepo::getDefaultInstance();
+               $this->bufferingTermLookup = 
$this->repo->getBufferingTermLookup();
+       }
+
+       public function execute( $subPage ) {
+               parent::execute( $subPage );
+
+               $this->displayResult();
+       }
+
+       private function displayResult() {
+               $out = $this->getOutput();
+               $badgeItems = 
WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( 'badgeItems' );
+               $itemIdParser = new ItemIdParser();
+
+               $itemIds = array_map( function( $item ) use ( $itemIdParser ) {
+                       return $itemIdParser->parse( $item );
+               }, array_keys( $badgeItems ) );
+
+               $this->bufferingTermLookup->prefetchTerms( $itemIds );
+
+               $out->addHTML( Html::openElement( 'ol' ) );
+               foreach ( $itemIds as $item ) {
+                       $this->displayRow( $item, 
$badgeItems[$item->getSerialization()] );
+               }
+               $out->addHTML( Html::closeElement( 'ol' ) );
+       }
+
+       /**
+        * Render one badge.
+        *
+        * @param \Wikibase\DataModel\Entity\ItemId $item Item ID to render
+        * @param string $badgeClass The given badge class
+        */
+       private function displayRow( ItemId $item, $badgeClass ) {
+               $out = $this->getOutput();
+               $entityTitleLookup = $this->repo->getEntityTitleLookup();
+
+               $title = $entityTitleLookup->getTitleForId( $item );
+               $description = $this->bufferingTermLookup->getDescription(
+                       $item,
+                       $this->getLanguage()->getCode()
+               );
+
+               $out->addHTML( Html::openElement( 'li' ) );
+               $out->addHTML( Html::element( 'span', [
+                       'class' => 'wb-badge ' . $badgeClass,
+               ] ) );
+               $out->addHTML( Linker::link( $title ) );
+               $out->addHTML( ' - ' . $description );
+               $out->addHTML( Html::closeElement( 'li' ) );
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/324216
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8cd2912b629bc4e9f744156653b28cd4c5ef531a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Victorbarbu <victorbarb...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to