MarkTraceur has uploaded a new change for review. https://gerrit.wikimedia.org/r/305740
Change subject: Add rendering for Wikipedia articles ...................................................................... Add rendering for Wikipedia articles Needs some style love that can come later. Change-Id: Id7f66b412becd98567e45b3576804771f5a7a3a0 --- M ApiFileAnnotations.php M resources/src/fileannotations.less 2 files changed, 52 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FileAnnotations refs/changes/40/305740/1 diff --git a/ApiFileAnnotations.php b/ApiFileAnnotations.php index ffbe666..99ffe10 100644 --- a/ApiFileAnnotations.php +++ b/ApiFileAnnotations.php @@ -100,6 +100,13 @@ $commonsMatches ); + $wpMatches = []; + $wpArticleMatch = preg_match( + '%^(https?://.*.wikipedia.org)/wiki/(.*)%', + $href, + $wpMatches + ); + if ( $commonsCategoryMatch === 1 ) { $categoryName = $commonsMatches[1]; @@ -136,6 +143,42 @@ '</a>' . '</div>'; } + + if ( $wpArticleMatch === 1 ) { + $articleName = $wpMatches[2]; + + $articleApiDataStr = file_get_contents( + $wpMatches[1] . + '/w/api.php?action=query' . + '&titles=' . urlencode( $articleName ) . + '&prop=pageimages|extracts' . + '&piprop=thumbnail|name' . + '&pithumbsize=250' . + '&exsentences=4' . + '&format=json' + ); + + $articleApiData = json_decode( $articleApiDataStr, true ); + + $pages = $articleApiData['query']['pages']; + + foreach ( $pages as $id => $page ) { + // There's only one page, so just do it here + $annotationData['parsed'] = + '<div class="wikipedia-article-annotation">' . + $page['extract'] . + '<p>' . + '<img src="' . + $page['thumbnail']['source'] . + '" width="' . + $page['thumbnail']['width'] . + '" height="' . + $page['thumbnail']['height'] . + '" />' . + '</p>' . + '</div>'; + } + } } } $annotationsData[] = $annotationData; diff --git a/resources/src/fileannotations.less b/resources/src/fileannotations.less index fce61cd..ebba43a 100644 --- a/resources/src/fileannotations.less +++ b/resources/src/fileannotations.less @@ -33,6 +33,15 @@ padding-bottom: 20px; } } + + .wikipedia-article-annotation { + width: 600px; + + & > p { + width: 250px; + display: inline-block; + } + } } } -- To view, visit https://gerrit.wikimedia.org/r/305740 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id7f66b412becd98567e45b3576804771f5a7a3a0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/FileAnnotations Gerrit-Branch: master Gerrit-Owner: MarkTraceur <mholmqu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits