Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51179
Change subject: (bug 45037) show edit link only if we have repo links
......................................................................
(bug 45037) show edit link only if we have repo links
This also fixes bug 44536 to have Q### links instead of link via
Special:ItemByTitle
This patch adds parser output and output page properties that indicate:
1) userepolinks: if a page uses repo links... e.g. they've been suppressed or
not.
if not, it considers if the page is associated with the repo and has links.
2) wikibase-itemid: the associated item id. this is added regardless if
userepolinks
is true or not.
Then it's easier and more efficient for the code to determine whether or not to
add "edit links" link and build the link to the associated item.
Change-Id: I9bcf497f23b3d28f58fda964d74b7097b28aac2b
---
M client/WikibaseClient.hooks.php
M client/WikibaseClient.php
M client/includes/LangLinkHandler.php
3 files changed, 46 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/79/51179/1
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index ba14405..9c07526 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -582,12 +582,33 @@
}
/**
+ * Add output page property if repo links are suppressed, and property
for item id
+ *
+ * @since 0.4
+ *
+ * @param \OutputPage &$out
+ * @param \ParserOutput $pout
+ *
+ * @return bool
+ */
+ public static function onOutputPageParserOutput( \OutputPage &$out,
\ParserOutput $pout ) {
+ $out->setProperty( 'hasrepolinks', $pout->getProperty(
'hasrepolinks' ) );
+
+ $itemId = $pout->getProperty( 'wikibase-itemid' );
+ if ( $itemId !== false ) {
+ $out->setProperty( 'wikibase-itemid', $itemId );
+ }
+
+ return true;
+ }
+
+ /**
* Displays a list of links to pages on the central wiki at the end of
the language box.
+ *
+ * @since 0.1
*
* @param \Skin $skin
* @param \QuickTemplate $template
- *
- * @since 0.1
*
* @return bool
*/
@@ -595,19 +616,12 @@
wfProfileIn( __METHOD__ );
$title = $skin->getContext()->getTitle();
- if ( in_array( $title->getNamespace(), Settings::get(
'namespaces' ) ) && $title->exists() ) {
-
- $title = $skin->getContext()->getTitle();
-
- // gets the main part of the title, no underscores used
in this db table
- $titleText = $title->getPrefixedText();
- $siteId = Settings::get( 'siteGlobalID' );
+ if ( $title->exists() && $skin->getOutput()->getProperty(
'hasrepolinks' ) === true ) {
if ( empty( $template->data['language_urls'] ) &&
\Action::getActionName( $skin->getContext() ) === 'view' ) {
// Placeholder in case the page doesn't have
any langlinks yet
// self::onBeforePageDisplay adds the
JavaScript module which will overwrite this with a link
$template->data['language_urls'][] = array(
- 'href' => ClientUtils::repoArticleUrl(
"Special:CreateItem/$siteId/$titleText" ),
'text' => wfMessage( 'parentheses',
wfMessage( 'wikibase-nolanglinks' )->escaped() ),
'id' => 'wbc-linkToItem',
'class' => 'wbc-editpage',
@@ -617,12 +631,13 @@
return true;
}
- $itemId =
ClientStoreFactory::getStore()->newSiteLinkTable()->getItemIdForLink( $siteId,
$titleText );
+ $itemId = $skin->getOutput()->getProperty(
'wikibase-itemid' );
- if ( $itemId ) {
+ if ( $itemId !== null ) {
// links to the special page
$template->data['language_urls'][] = array(
- 'href' => ClientUtils::repoArticleUrl(
"Special:ItemByTitle/$siteId/$titleText" ),
+ // todo: make nicer without strtoupper
here
+ 'href' => ClientUtils::repoArticleUrl(
strtoupper( $itemId ) ),
'text' => wfMessage(
'wikibase-editlinks' )->text(),
'title' => wfMessage(
'wikibase-editlinkstitle' )->text(),
'class' => 'wbc-editpage',
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index 29fa870..9a2b467 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -97,6 +97,7 @@
$wgHooks['UnitTestsList'][] =
'\Wikibase\ClientHooks::registerUnitTests';
$wgHooks['LoadExtensionSchemaUpdates'][] =
'\Wikibase\ClientHooks::onSchemaUpdate';
$wgHooks['OldChangesListRecentChangesLine'][] =
'\Wikibase\ClientHooks::onOldChangesListRecentChangesLine';
+$wgHooks['OutputPageParserOutput'][] =
'\Wikibase\ClientHooks::onOutputPageParserOutput';
$wgHooks['ParserAfterParse'][] =
'\Wikibase\ClientHooks::onParserAfterParse';
$wgHooks['ParserFirstCallInit'][] =
'\Wikibase\ClientHooks::onParserFirstCallInit';
$wgHooks['MagicWordwgVariableIDs'][] =
'\Wikibase\ClientHooks::onMagicWordwgVariableIDs';
diff --git a/client/includes/LangLinkHandler.php
b/client/includes/LangLinkHandler.php
index 1ae8943..b6ab893 100644
--- a/client/includes/LangLinkHandler.php
+++ b/client/includes/LangLinkHandler.php
@@ -46,6 +46,8 @@
*/
protected $sites;
+ protected $itemId;
+
private $sitesByNavigationId = null;
/**
@@ -77,18 +79,19 @@
wfProfileIn( __METHOD__ );
wfDebugLog( __CLASS__, __FUNCTION__ . ": Looking for sitelinks
defined by the corresponding item on the wikibase repo." );
- $itemId = $this->siteLinksLookup->getItemIdForLink(
+ // @todo have something that returns entity id object
+ $numericItemId = $this->siteLinksLookup->getItemIdForLink(
$this->siteId,
$title->getFullText()
);
$links = array();
- if ( $itemId !== false ) {
- wfDebugLog( __CLASS__, __FUNCTION__ . ": Item ID for "
. $title->getFullText() . " is " . $itemId );
+ if ( $numericItemId !== false ) {
+ wfDebugLog( __CLASS__, __FUNCTION__ . ": Item ID for "
. $title->getFullText() . " is " . $numericItemId );
- $links = $this->siteLinksLookup->getSiteLinksForItem(
- new EntityId( Item::ENTITY_TYPE, $itemId ) );
+ $this->itemId = new EntityId( Item::ENTITY_TYPE,
$numericItemId );
+ $links = $this->siteLinksLookup->getSiteLinksForItem(
$this->itemId );
} else {
wfDebugLog( __CLASS__, __FUNCTION__ . ": No
corresponding item found for " . $title->getFullText() );
}
@@ -351,6 +354,15 @@
$repoLinks = array_diff_key( $repoLinks, $onPageLinks ); //
remove local links
+ if ( $this->itemId instanceof EntityId ) {
+ // @todo get prefixed id in nicer way, or maybe we want
it to be numeric id
+ $out->setProperty( 'wikibase-itemid',
$this->itemId->getPrefixedId() );
+ }
+
+ if ( $repoLinks !== array() ) {
+ $out->setProperty( 'hasrepolinks', true );
+ }
+
wfProfileOut( __METHOD__ );
return $repoLinks;
}
--
To view, visit https://gerrit.wikimedia.org/r/51179
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9bcf497f23b3d28f58fda964d74b7097b28aac2b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits