Ladsgroup has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/349868 )
Change subject: Very basic meta description tag
......................................................................
Very basic meta description tag
Bug: T157466
Change-Id: I63c8d98194217d9b531c5950ee4d40033581be3d
---
M includes/AboutTopicRenderer.php
M tests/phpunit/includes/AboutTopicRendererTest.php
2 files changed, 58 insertions(+), 6 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticlePlaceholder
refs/changes/68/349868/1
diff --git a/includes/AboutTopicRenderer.php b/includes/AboutTopicRenderer.php
index 8d519c9..9c9bd57 100644
--- a/includes/AboutTopicRenderer.php
+++ b/includes/AboutTopicRenderer.php
@@ -110,6 +110,7 @@
$this->showLanguageLinks( $entityId, $output );
$this->setOtherProjectsLinks( $entityId, $output );
+ $this->addMetaTags( $entityId, $output, $language );
}
/**
@@ -161,6 +162,23 @@
if ( $label !== null ) {
return $label->getText();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param ItemId $entityId
+ * @param Language $language
+ *
+ * @return string|null null if the item doesn't have a description
+ */
+ private function getDescription( ItemId $entityId, Language $language )
{
+ $description =
$this->termLookupFactory->newLabelDescriptionLookup( $language )
+ ->getDescription( $entityId );
+
+ if ( $description !== null ) {
+ return $description->getText();
}
return null;
@@ -225,4 +243,20 @@
$output->setProperty( 'wikibase-otherprojects-sidebar',
$otherProjects );
}
+ private function addMetaTags( ItemId $itemId, OutputPage $output,
Language $language ) {
+ $title = $this->getLabel( $itemId, $language );
+ $description = $this->getDescription( $itemId, $language );
+
+ $descriptionTag = '';
+ if ( $title !== null ) {
+ $descriptionTag .= $title . '. ';
+ }
+ if ( $description !== null ) {
+ $descriptionTag .= $description . '. ';
+ }
+
+ if ( $descriptionTag !== '' ) {
+ $output->addMeta( 'description', trim( $descriptionTag
) );
+ }
+ }
}
diff --git a/tests/phpunit/includes/AboutTopicRendererTest.php
b/tests/phpunit/includes/AboutTopicRendererTest.php
index 8a2d1e5..b919339 100644
--- a/tests/phpunit/includes/AboutTopicRendererTest.php
+++ b/tests/phpunit/includes/AboutTopicRendererTest.php
@@ -170,6 +170,17 @@
}
/**
+ * Test meta tags
+ */
+ public function testMetaTags() {
+ $output = $this->getInstanceOutput( new ItemId( 'Q123' ) );
+ $this->assertSame(
+ [ [ 'description', 'Label of Q123. Description of
Q123.' ] ],
+ $output->getMetaTags()
+ );
+ }
+
+ /**
* @return LanguageFallbackLabelDescriptionLookupFactory
*/
private function getTermLookupFactory() {
@@ -178,10 +189,10 @@
)
->disableOriginalConstructor()
->getMock();
- $labelDescriptionLookupFactory->expects( $this->once() )
+ $labelDescriptionLookupFactory->expects( $this->atLeastOnce() )
->method( 'newLabelDescriptionLookup' )
->with( Language::factory( 'eo' ) )
- ->will( $this->returnValue( $this->getLabelLookup() ) );
+ ->will( $this->returnValue(
$this->getLabelDescriptionLookup() ) );
return $labelDescriptionLookupFactory;
}
@@ -189,17 +200,24 @@
/**
* @return LabelDescriptionLookup
*/
- private function getLabelLookup() {
- $labelLookup = $this->getMock( LabelDescriptionLookup::class );
- $labelLookup->expects( $this->any() )
+ private function getLabelDescriptionLookup() {
+ $labelDescriptionLookup = $this->getMock(
LabelDescriptionLookup::class );
+ $labelDescriptionLookup->expects( $this->any() )
->method( 'getLabel' )
->will( $this->returnCallback( function( ItemId $id ) {
return new Term( 'eo', 'Label of ' .
$id->getSerialization() );
} ) );
- return $labelLookup;
+ $labelDescriptionLookup->expects( $this->any() )
+ ->method( 'getDescription' )
+ ->will( $this->returnCallback( function( ItemId $id ) {
+ return new Term( 'eo', 'Description of ' .
$id->getSerialization() );
+ } ) );
+
+ return $labelDescriptionLookup;
}
+
/**
* @return SiteLinkLookup
*/
--
To view, visit https://gerrit.wikimedia.org/r/349868
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I63c8d98194217d9b531c5950ee4d40033581be3d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits