jenkins-bot has submitted this change and it was merged. Change subject: Add special rendering for Commons categories ......................................................................
Add special rendering for Commons categories
Still not the prettiest things in the world, but they work!
Change-Id: If9e32838482e6672afe14b46e48f8d7ca749222a
---
M ApiFileAnnotations.php
M resources/src/fileannotations.less
2 files changed, 79 insertions(+), 0 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ApiFileAnnotations.php b/ApiFileAnnotations.php
index 0c1eaa6..ffbe666 100644
--- a/ApiFileAnnotations.php
+++ b/ApiFileAnnotations.php
@@ -79,6 +79,64 @@
if ( $shouldParse ) {
$presult =
$parser->parse( $text, $faTitle, $popts );
$annotationData['parsed'] = $presult->mText;
+
+ // Check to see if we
can return a special display for this annotation.
+ $dom = new
DOMDocument();
+ $domFragment =
$dom->createDocumentFragment();
+
$domFragment->appendXml( $presult->mText );
+
+ // The first element
will always be a paragraph. Get its first child.
+ $possibleLink =
$domFragment->firstChild->firstChild;
+
+ // Check if it's a link
element.
+ if (
$possibleLink->nodeType === XML_ELEMENT_NODE && $possibleLink->nodeName === 'a'
) {
+ // Find out if
the link is something we care about.
+ $href =
$possibleLink->attributes->getNamedItem( 'href' )->value;
+
+ $commonsMatches
= [];
+
$commonsCategoryMatch = preg_match(
+
'%^https?://commons.wikimedia.org.*(Category:.*)%',
+ $href,
+
$commonsMatches
+ );
+
+ if (
$commonsCategoryMatch === 1 ) {
+
$categoryName = $commonsMatches[1];
+
+
$imagesApiDataStr = file_get_contents(
+
'https://commons.wikimedia.org/w/api.php?' .
+
'action=query&prop=imageinfo&generator=categorymembers' .
+
'&gcmtype=file&gcmtitle=' .
+
urlencode( $categoryName ) .
+
'&gcmlimit=5&iiprop=url&iiurlwidth=100' .
+
'&iiurlheight=100&format=json'
+ );
+
+
$imagesApiData = json_decode( $imagesApiDataStr, true );
+
+ $pages
= $imagesApiData['query']['pages'];
+
+
$imagesHtml = '<div class="category-members">';
+
+ foreach
( $pages as $id => $page ) {
+
$info = $page['imageinfo'][0];
+
$imagesHtml .=
+
'<a class="category-member" href="' . $info['descriptionurl'] . '">' .
+
'<img src="' . $info['thumburl'] . '" />' .
+
'</a>';
+ }
+
+
$imagesHtml .= '</div>';
+
+
$annotationData['parsed'] =
+
'<div class="commons-category-annotation">' .
+
$imagesHtml .
+
'<a href="' . $href . '">' .
+
'See more images' .
+
'</a>' .
+
'</div>';
+ }
+ }
}
$annotationsData[] =
$annotationData;
}
diff --git a/resources/src/fileannotations.less
b/resources/src/fileannotations.less
index f4e3406..fce61cd 100644
--- a/resources/src/fileannotations.less
+++ b/resources/src/fileannotations.less
@@ -13,6 +13,27 @@
position: absolute;
padding: 2px;
z-index: 1;
+
+ .file-annotation {
+ .commons-category-annotation {
+ text-align: center;
+
+ .category-members {
+ width: 600px;
+ .category-member {
+ padding: 10px;
+ width: 100px;
+ height: 100px;
+ text-align: center;
+ img {
+ display:
inline-block;
+ }
+ }
+
+ padding-bottom: 20px;
+ }
+ }
+ }
}
&.editing-annotation {
--
To view, visit https://gerrit.wikimedia.org/r/305690
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If9e32838482e6672afe14b46e48f8d7ca749222a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/FileAnnotations
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Prtksxna <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
