Bene has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234961
Change subject: Add SpecialPagesWithBadges
......................................................................
Add SpecialPagesWithBadges
This version of the special page extends QueryPage and needs
three joins to get the actual data. While QueryPage caches
the result, the query is very complex to get the result
required by QueryPage. I'm not sure if this is the best way
of implementing the special page.
Bug: T72209
Change-Id: I690b94af0ac11163c80e4422e6d72dacce447959
---
M client/WikibaseClient.hooks.php
M client/WikibaseClient.php
M client/i18n/en.json
A client/includes/specials/SpecialPagesWithBadges.php
4 files changed, 234 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/61/234961/1
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 0de0d8e..0725b88 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -601,6 +601,7 @@
public static function onwgQueryPages( &$queryPages ) {
$queryPages[] = array(
'Wikibase\Client\Specials\SpecialUnconnectedPages', 'UnconnectedPages' );
+ $queryPages[] = array(
'Wikibase\Client\Specials\SpecialPagesWithBadges', 'Badges' );
return true;
}
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index 1fbb397..81d5b4f 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -151,6 +151,7 @@
// Special page registration
$wgSpecialPages['UnconnectedPages'] =
'Wikibase\Client\Specials\SpecialUnconnectedPages';
+ $wgSpecialPages['PagesWithBadges'] =
'Wikibase\Client\Specials\SpecialPagesWithBadges';
$wgHooks['wgQueryPages'][] = 'Wikibase\ClientHooks::onwgQueryPages';
// Resource loader modules
diff --git a/client/i18n/en.json b/client/i18n/en.json
index 68c261b..37266b2 100644
--- a/client/i18n/en.json
+++ b/client/i18n/en.json
@@ -65,12 +65,13 @@
"wikibase-error-invalid-entity-id": "The ID entered is unknown to the
system. Please use a valid entity ID.",
"unconnectedpages": "Pages not connected to items",
"unconnectedpages-summary": "This page lists pages with no connected
data item (in namespaces that support connected items). The list is sorted by
descending page ID, so that newer pages are listed first.",
- "wikibase-unconnectedpages-page": "Start result list with page:",
- "wikibase-unconnectedpages-submit": "Go",
- "wikibase-unconnectedpages-invalid-language": "\"$1\" is not a valid
language code.",
- "wikibase-unconnectedpages-page-warning": "The page title could not be
used for the query and is ignored.",
- "wikibase-unconnectedpages-iwdata-label": "Only pages with
interlanguage links",
"wikibase-unconnectedpages-format-row": "($1 {{PLURAL:$1|interlanguage
link|interlanguage links}} on the page)",
+ "pageswithbadges": "Pages with badges",
+ "pageswithbadges-summary": "This page lists pages with badges (eg. good
article or featured article). The list is sorted by descending page ID, so that
newer pages are listed first.",
+ "wikibase-pageswithbadges-invalid-id": "$1 is not a valid item id",
+ "wikibase-pageswithbadges-legend": "List of pages with a given badge",
+ "wikibase-pageswithbadges-badge": "Badge:",
+ "wikibase-pageswithbadges-submit": "Show pages",
"wikibase-pageinfo-entity-id": "{{WBREPONAME}} item ID",
"wikibase-pageinfo-entity-id-none": "None",
"wikibase-property-render-error": "Failed to render property $1: $2",
diff --git a/client/includes/specials/SpecialPagesWithBadges.php
b/client/includes/specials/SpecialPagesWithBadges.php
new file mode 100644
index 0000000..67639bb
--- /dev/null
+++ b/client/includes/specials/SpecialPagesWithBadges.php
@@ -0,0 +1,226 @@
+<?php
+
+
+namespace Wikibase\Client\Specials;
+
+use Html;
+use InvalidArgumentException;
+use Linker;
+use QueryPage;
+use Skin;
+use Title;
+use Wikibase\Client\WikibaseClient;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
+
+/**
+ * Show pages with a given badge.
+ *
+ * @licence GNU GPL v2+
+ * @author Bene* < [email protected] >
+ */
+class SpecialPagesWithBadges extends QueryPage {
+
+ /**
+ * @var string[]
+ */
+ private $badgeIds;
+
+ /**
+ * @var string
+ */
+ private $siteId;
+
+ /**
+ * @var LanguageFallbackLabelDescriptionLookupFactory
+ */
+ private $labelDescriptionLookupFactory;
+
+ /**
+ * @var ItemId|null
+ */
+ private $badgeId;
+
+ /**
+ * @see SpecialPage::__construct
+ *
+ * @param string $name
+ */
+ public function __construct( $name = 'PagesWithBadges' ) {
+ parent::__construct( $name );
+
+ $wikibaseClient = WikibaseClient::getDefaultInstance();
+ $this->setServices(
+ array_keys( $wikibaseClient->getSettings()->getSetting(
'badgeClassNames' ) ),
+ $wikibaseClient->getSettings()->getSetting(
'siteGlobalID' ),
+ new LanguageFallbackLabelDescriptionLookupFactory(
+
$wikibaseClient->getLanguageFallbackChainFactory(),
+ $wikibaseClient->getStore()->getTermIndex()
+ )
+ );
+ }
+
+ public function setServices(
+ array $badgeIds,
+ $siteId,
+ LanguageFallbackLabelDescriptionLookupFactory
$labelDescriptionLookupFactory
+ ) {
+ $this->badgeIds = $badgeIds;
+ $this->siteId = $siteId;
+ $this->labelDescriptionLookupFactory =
$labelDescriptionLookupFactory;
+ }
+
+ /**
+ * @see QueryPage::execute
+ *
+ * @param string $subPage
+ */
+ public function execute( $subPage ) {
+ $this->prepareParams( $subPage );
+
+ if ( $this->badgeId !== null ) {
+ parent::execute( $subPage );
+ } else {
+ $this->setHeaders();
+ $this->outputHeader();
+ $this->getOutput()->addHTML( $this->getPageHeader() );
+ }
+ }
+
+ private function prepareParams( $subPage ) {
+ $badge = $this->getRequest()->getText( 'badge', $subPage );
+
+ try {
+ $this->badgeId = new ItemId( $badge );
+ } catch ( InvalidArgumentException $ex ) {
+ if ( $badge ) {
+ $this->getOutput()->addHTML(
+ Html::element(
+ 'p',
+ array(
+ 'class' => 'error'
+ ),
+ $this->msg(
'wikibase-pageswithbadges-invalid-id', $badge )
+ )
+ );
+ }
+ }
+ }
+
+ function getPageHeader() {
+ return Html::openElement(
+ 'form',
+ array(
+ 'action' => $this->getPageTitle()->getLocalURL()
+ )
+ ) .
+ Html::openElement( 'fieldset' ) .
+ Html::element(
+ 'legend',
+ array(),
+ $this->msg( 'wikibase-pageswithbadges-legend' )->text()
+ ) .
+ Html::openElement( 'p' ) .
+ Html::element(
+ 'label',
+ array(
+ 'for' => 'wb-pageswithbadges-badge'
+ ),
+ $this->msg( 'wikibase-pageswithbadges-badge' )->text()
+ ) . ' ' .
+ Html::rawElement(
+ 'select',
+ array(
+ 'name' => 'badge',
+ 'id' => 'wb-pageswithbadges-badge',
+ 'class' => 'wb-select'
+ ),
+ $this->getOptionsHtml()
+ ) . ' ' .
+ Html::input(
+ '',
+ $this->msg( 'wikibase-pageswithbadges-submit' )->text(),
+ 'submit',
+ array(
+ 'id' => 'wikibase-pageswithbadges-submit',
+ 'class' => 'wb-input-button'
+ )
+ ) .
+ Html::closeElement( 'p' ) .
+ Html::closeElement( 'fieldset' ) .
+ Html::closeElement( 'form' );
+ }
+
+ private function getOptionsHtml() {
+ $html = '';
+
+ foreach ( $this->badgeIds as $badgeId ) {
+ $html .= Html::element(
+ 'option',
+ array(
+ 'value' => $badgeId,
+ 'selected' => $this->badgeId !== null
&& $this->badgeId->getSerialization() === $badgeId
+ ),
+ $badgeId // TODO show label
+ );
+ }
+
+ return $html;
+ }
+
+ /**
+ * @see QueryPage::getQueryInfo
+ *
+ * @return array[]
+ */
+ function getQueryInfo() {
+ return array(
+ 'tables' => array(
+ 'page',
+ 'page_props',
+ 'wb_items_per_site',
+ 'wb_badges_per_sitelink',
+ ),
+ 'fields' => array(
+ 'value' => 'page_id',
+ 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ ),
+ 'conds' => array(
+ 'bps_site_id' => $this->siteId,
+ 'bps_badge_id' =>
$this->badgeId->getSerialization()
+ ),
+ 'options' => array(), // sorting is determined
getOrderFields(), which returns array( 'value' ) per default.
+ 'join_conds' => array(
+ 'page_props' => array( 'JOIN', array( 'page_id
= pp_page' ) ),
+ 'wb_items_per_site' => array( 'JOIN', array(
"pp_value = CONCAT( 'Q', ips_item_id )", "pp_propname = 'wikibase_item'" ) ),
+ 'wb_badges_per_sitelink' => array( 'JOIN',
array( 'ips_site_page = bps_site_page' ) )
+ )
+ );
+ }
+
+ /**
+ * @see QueryPage::formatResult
+ *
+ * @param Skin $skin
+ * @param object $result
+ *
+ * @return string
+ */
+ function formatResult( $skin, $result ) {
+ $title = Title::newFromID( $result->value );
+ $out = Linker::linkKnown( $title );
+
+ return $out;
+ }
+
+ /**
+ * @see SpecialPage::getGroupName
+ *
+ * @return string
+ */
+ protected function getGroupName() {
+ return 'pages';
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/234961
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I690b94af0ac11163c80e4422e6d72dacce447959
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits