jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/368129 )

Change subject: Switch to extension registration system
......................................................................


Switch to extension registration system

This moves to the new-style extension registration and removes the
old style. Also removes the Git submodule and adds that library
as a (manual) Composer dependency.

Coding standards are also updated.

Bug: T171819
Change-Id: I46d1a2dd04903b7a3207b9c4a709b80214626fc5
---
D .gitmodules
M FlickrAPI.hooks.php
D FlickrAPI.php
M FlickrAPICache.php
M FlickrAPIUtils.php
A composer.json
A extension.json
D modules/phpflickr
A phpcs.xml
9 files changed, 141 insertions(+), 99 deletions(-)

Approvals:
  Umherirrender: Looks good to me, but someone else must approve
  jenkins-bot: Verified
  tosfos: Looks good to me, approved



diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 4414c1f..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "modules/phpflickr"]
-       path = modules/phpflickr
-       url = https://github.com/dan-coulter/phpflickr.git
diff --git a/FlickrAPI.hooks.php b/FlickrAPI.hooks.php
index 1a8645e..c2f7332 100644
--- a/FlickrAPI.hooks.php
+++ b/FlickrAPI.hooks.php
@@ -9,11 +9,22 @@
 class FlickrAPIHooks {
 
        /**
+        * Hooked to ParserFirstCallInit.
+        * @link https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
+        * @param Parser &$parser The parser.
+        * @return bool
+        */
+       public static function onParserFirstCallInit( Parser &$parser ) {
+               $parser->setHook( 'flickr', self::class.'::flickrAPITag' );
+               return true;
+       }
+
+       /**
         * Get output for the <flickr> tag
         *
-        * @param string $optionsString
-        * @param array $args
-        * @param Parser $parser
+        * @param string $optionsString Tag content.
+        * @param array $args Tag attributes.
+        * @param Parser $parser The parser.
         * @return string
         */
        public static function flickrAPITag( $optionsString, array $args, 
Parser $parser ) {
@@ -34,12 +45,12 @@
        private static function extractOptions( $optionsString ) {
                $parts = StringUtils::explode( '|', $optionsString );
 
-               $options = array( 'id' => $parts->current() );
+               $options = [ 'id' => $parts->current() ];
                $parts->next();
 
                $validSizes = self::getValidSizes();
-               $validTypes = array( 'thumb', 'frame', 'frameless' );
-               $validAligns = array( 'right', 'left', 'center', 'none' );
+               $validTypes = [ 'thumb', 'frame', 'frameless' ];
+               $validAligns = [ 'right', 'left', 'center', 'none' ];
                # Okay now deal with parameters
                /** @todo Copied from Flickr extension. Refactor. */
                while ( $parts->valid() ) {
@@ -69,13 +80,13 @@
         * @return array
         */
        private static function getValidSizes() {
-               return array(
+               return [
                        's' => 'Square',
                        't' => 'Thumbnail',
                        'm' => 'Small',
                        '-' => 'Medium',
                        'b' => 'Large',
-               );
+               ];
        }
 
        /**
@@ -109,7 +120,7 @@
         * @return string HTML
         */
        private static function handleError( MWException $e ) {
-               return Html::element( 'strong', array( 'class' => array( 
'error', 'flickrapi-error' ) ),
+               return Html::element( 'strong', [ 'class' => [ 'error', 
'flickrapi-error' ] ],
                                $e->getMessage() );
        }
 
@@ -151,7 +162,7 @@
                        $phpFlickr->enableCache( 'fs', $wgFileCacheDirectory );
                } else {
                        $phpFlickr->enableCache( 'custom',
-                               array( 'FlickrAPICache::getCache', 
'FlickrAPICache::setCache' ) );
+                               [ 'FlickrAPICache::getCache', 
'FlickrAPICache::setCache' ] );
                }
 
                $info = $phpFlickr->photos_getInfo( $options['id'] );
@@ -164,13 +175,13 @@
 
                $linkUrl = $info['photo']['urls']['url']['0']['_content'];
 
-               $frameParams = array(
+               $frameParams = [
                        'align' => $options['location'],
                        'alt' => $options['caption'],
                        'caption' => $options['caption'],
                        'title' => $options['caption'],
                        'link-url' => $linkUrl
-               );
+               ];
 
                if ( $options['type'] == 'thumb' ) {
                        $frameParams['thumbnail'] = true;
@@ -179,7 +190,7 @@
                }
 
                $validSizes = self::getValidSizes();
-               $handlerParams = array();
+               $handlerParams = [];
                foreach ( $flickrSizes as $flickrSize ) {
                        if ( $flickrSize['label'] === 
$validSizes[$options['size']] ) {
                                $handlerParams['width'] = $flickrSize['width'];
@@ -196,6 +207,6 @@
                $imageLink = FlickrAPIUtils::makeImageLink( $parser, $url, 
$frameParams, $handlerParams );
 
                wfProfileOut( __METHOD__ );
-               return Html::rawElement( 'div', array( 'class' => 'flickrapi' 
), $imageLink );
+               return Html::rawElement( 'div', [ 'class' => 'flickrapi' ], 
$imageLink );
        }
 }
diff --git a/FlickrAPI.php b/FlickrAPI.php
deleted file mode 100644
index 87b6689..0000000
--- a/FlickrAPI.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/**
- * FlickrAPI extension
- *
- * For more info see http://mediawiki.org/wiki/Extension:FlickrAPI
- *
- * @file
- * @ingroup Extensions
- * @author Ike Hecht, 2015
- * @license GNU General Public Licence 2.0 or later
- */
-
-$wgExtensionCredits['parserhook'][] = array(
-       'path' => __FILE__,
-       'name' => 'FlickrAPI',
-       'author' => array(
-               'Ike Hecht',
-       ),
-       'version' => '1.0.0',
-       'url' => 'https://www.mediawiki.org/wiki/Extension:FlickrAPI',
-       'descriptionmsg' => 'flickrapi-desc',
-);
-
-/* Setup */
-
-// Register files
-$wgAutoloadClasses['FlickrAPIHooks'] = __DIR__ . '/FlickrAPI.hooks.php';
-$wgAutoloadClasses['FlickrAPIUtils'] = __DIR__ . '/FlickrAPIUtils.php';
-$wgAutoloadClasses['FlickrAPICache'] = __DIR__ . '/FlickrAPICache.php';
-/** @todo Spit out better error message if phpflickr module doesn't exist */
-$wgAutoloadClasses['phpFlickr'] = __DIR__ . '/modules/phpflickr/phpFlickr.php';
-$wgAutoloadClasses['phpFlickr_pager'] = __DIR__ . 
'/modules/phpflickr/phpFlickr.php';
-
-$wgMessagesDirs['FlickrAPI'] = __DIR__ . '/i18n';
-
-// Register hooks
-$wgHooks['ParserFirstCallInit'][] = function ( &$parser ) {
-       $parser->setHook( 'flickr', 'FlickrAPIHooks::flickrAPITag' );
-       return true;
-};
-
-/* Configuration */
-$wgFlickrAPIKey = '';
-$wgFlickrAPISecret = '';
-$wgFlickrAPIDefaults = array( 'type' => 'frameless', 'location' => 'right', 
'size' => '-' );
diff --git a/FlickrAPICache.php b/FlickrAPICache.php
index 8cb3ed3..d8879f9 100644
--- a/FlickrAPICache.php
+++ b/FlickrAPICache.php
@@ -10,8 +10,8 @@
        /**
         * Get this call from db cache
         *
-        * @param string $reqhash
-        * @return string|boolean
+        * @param string $reqhash The cache key.
+        * @return string|bool
         */
        public static function getCache( $reqhash ) {
                $cache = wfGetCache( CACHE_ANYTHING );
@@ -23,12 +23,12 @@
        }
 
        /**
-        * Store this call in cache
+        * Store this call in cache.
         *
-        * @param string $reqhash
-        * @param string $response
-        * @param integer $cache_expire
-        * @return boolean
+        * @param string $reqhash The cache key.
+        * @param string $response The response to cache.
+        * @param integer $cache_expire Either an interval in seconds or a unix 
timestamp for expiry.
+        * @return bool
         */
        public static function setCache( $reqhash, $response, $cache_expire ) {
                $cache = wfGetCache( CACHE_ANYTHING );
diff --git a/FlickrAPIUtils.php b/FlickrAPIUtils.php
index 6f91dac..301ffff 100644
--- a/FlickrAPIUtils.php
+++ b/FlickrAPIUtils.php
@@ -13,7 +13,7 @@
         * Given parameters derived from [[Image:Foo|options...]], generate the
         * HTML that that syntax inserts in the page.
         *
-        * @param Parser $parser
+        * @param Parser $parser The parser.
         * @param string $url URL of the image being displayed
         * @param array $frameParams Associative array of parameters external 
to the media handler.
         *     Boolean parameters are indicated by presence or absence, the 
value is arbitrary and
@@ -39,12 +39,11 @@
         *       to transform(). Typical keys are "width" and "page".
         * @param string|bool $time Timestamp of the file, set as false for 
current
         * @param string $query Query params for desc url
-        * @param int|null $widthOption Used by the parser to remember the user 
preference thumbnailsize
         * @since 1.20
         * @return string HTML for an image, with links, wrappers, etc.
         */
-       public static function makeImageLink( Parser $parser, $url, 
$frameParams = array(),
-               $handlerParams = array(), $time = false, $query = "" ) {
+       public static function makeImageLink( Parser $parser, $url, 
$frameParams = [],
+               $handlerParams = [], $time = false, $query = "" ) {
                // Shortcuts
                $fp = & $frameParams;
                $hp = & $handlerParams;
@@ -72,23 +71,25 @@
                }
 
                if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) 
|| isset( $fp['framed'] ) ) {
-                       # Create a thumbnail. Alignment depends on the writing 
direction of
-                       # the page content language (right-aligned for LTR 
languages,
-                       # left-aligned for RTL languages)
-                       #
-                       # If a thumbnail width has not been provided, it is set
-                       # to the default user option as specified in 
Language*.php
+                       /*
+                        * Create a thumbnail. Alignment depends on the writing 
direction of
+                        * the page content language (right-aligned for LTR 
languages,
+                        * left-aligned for RTL languages).
+                        *
+                        * If a thumbnail width has not been provided, it is set
+                        * to the default user option as specified in 
Language*.php
+                        */
                        if ( $fp['align'] == '' ) {
                                $fp['align'] = 
$parser->getTargetLanguage()->alignEnd();
                        }
                        return $prefix . self::makeThumbLink2( $url, $fp, $hp, 
$time, $query ) . $postfix;
                }
 
-               $params = array(
+               $params = [
                        'alt' => $fp['alt'],
                        'title' => $fp['title'],
                        'valign' => isset( $fp['valign'] ) ? $fp['valign'] : 
false,
-                       'img-class' => $fp['class'] );
+                       'img-class' => $fp['class'] ];
                if ( isset( $fp['border'] ) ) {
                        $params['img-class'] .= ( $params['img-class'] !== '' ? 
' ' : '' ) . 'thumbborder';
                }
@@ -105,14 +106,14 @@
        /**
         * Scaled down & modified version of Linker::makeThumbLink2. Not all 
options are implemented yet.
         *
-        * @param string $url
-        * @param array $frameParams
-        * @param array $handlerParams
-        * @param bool $time
-        * @param string $query
+        * @param string $url Image URL.
+        * @param array $frameParams The frame parameters: align, alt, title, 
caption.
+        * @param array $handlerParams The handler parameters: width, 
custom-url-link.
+        * @param bool $time Not used.
+        * @param string $query An optional query string to add to description 
page links.
         * @return string
         */
-       public static function makeThumbLink2( $url, $frameParams = array(), 
$handlerParams = array(),
+       public static function makeThumbLink2( $url, $frameParams = [], 
$handlerParams = [],
                $time = false, $query = ""
        ) {
                # Shortcuts
@@ -142,23 +143,24 @@
                $s = "<div class=\"thumb t{$fp['align']}\">"
                        . "<div class=\"thumbinner\" 
style=\"width:{$outerWidth}px;\">";
 
-               $params = array(
+               $params = [
                        'alt' => $fp['alt'],
                        'title' => $fp['title'],
                        'img-class' => ( isset( $fp['class'] ) && $fp['class'] 
!== '' ? $fp['class'] . ' ' : '' )
                        . 'thumbimage'
-               );
+               ];
                $imageLinkparams = self::getImageLinkMTOParams( $fp, $query ) + 
$params;
                $s .= self::thumbToHtml( $imageLinkparams, $url );
 
                if ( isset( $fp['framed'] ) ) {
                        $zoomIcon = "";
                } else {
-                       $zoomIcon = Html::rawElement( 'div', array( 'class' => 
'magnify' ),
+                       $zoomIcon = Html::rawElement( 'div', [ 'class' => 
'magnify' ],
                                        Html::rawElement( 'a',
-                                               array(
+                                               [
                                                'href' => 
$hp['custom-url-link'],
-                                               'title' => wfMessage( 
'thumbnail-more' )->text() ), "" ) );
+                                               'title' => wfMessage( 
'thumbnail-more' )->text()
+                                               ], "" ) );
                }
                $s .= '  <div class="thumbcaption">' . $zoomIcon . 
$fp['caption'] . "</div></div></div>";
                return str_replace( "\n", ' ', $s );
@@ -175,7 +177,7 @@
         * @return array
         */
        private static function getImageLinkMTOParams( $frameParams, $query = 
'', $parser = null ) {
-               $mtoParams = array();
+               $mtoParams = [];
                if ( isset( $frameParams['link-url'] ) && 
$frameParams['link-url'] !== '' ) {
                        $mtoParams['custom-url-link'] = 
$frameParams['link-url'];
                        if ( isset( $frameParams['link-target'] ) ) {
@@ -228,16 +230,16 @@
         *
         * For images, desc-link and file-link are implemented as a 
click-through. For
         * sounds and videos, they may be displayed in other ways.
-        * @param string $url
+        * @param string $url The image URL.
         * @return string
         */
-       public static function thumbToHtml( $options = array(), $url ) {
+       public static function thumbToHtml( $options = [], $url ) {
                $alt = empty( $options['alt'] ) ? '' : $options['alt'];
 
                $query = empty( $options['desc-query'] ) ? '' : 
$options['desc-query'];
 
                if ( !empty( $options['custom-url-link'] ) ) {
-                       $linkAttribs = array( 'href' => 
$options['custom-url-link'] );
+                       $linkAttribs = [ 'href' => $options['custom-url-link'] 
];
                        if ( !empty( $options['title'] ) ) {
                                $linkAttribs['title'] = $options['title'];
                        }
@@ -259,10 +261,10 @@
                        $linkAttribs = false;
                }
 
-               $attribs = array(
+               $attribs = [
                        'alt' => $alt,
                        'src' => $url,
-               );
+               ];
 
                if ( !empty( $options['valign'] ) ) {
                        $attribs['style'] = "vertical-align: 
{$options['valign']}";
diff --git a/composer.json b/composer.json
new file mode 100755
index 0000000..b03ced6
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,38 @@
+{
+       "require": {
+               "dan-coulter/phpflickr": "dev-master"
+       },
+       "require-dev": {
+               "jakub-onderka/php-parallel-lint": "^0.9",
+               "mediawiki/mediawiki-codesniffer": "^0.10",
+               "jakub-onderka/php-console-highlighter": "0.3.2"
+       },
+       "scripts": {
+               "test": [
+                       "parallel-lint . --exclude node_modules --exclude 
vendor",
+                       "phpcs -p -s"
+               ],
+               "fix": [
+                       "phpcbf"
+               ]
+       },
+       "repositories": [
+               {
+                       "type": "package",
+                       "package": {
+                               "name": "dan-coulter/phpflickr",
+                               "version": "dev-master",
+                               "source": {
+                                       "url": 
"https://github.com/dan-coulter/phpflickr.git";,
+                                       "type": "git",
+                                       "reference": 
"bc4f2092b15d347e3d40c19fe0dbff8759fc8e51"
+                               },
+                               "autoload": {
+                                       "classmap": [
+                                               "phpFlickr.php"
+                                       ]
+                               }
+                       }
+               }
+       ]
+}
diff --git a/extension.json b/extension.json
new file mode 100755
index 0000000..5ca6384
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,35 @@
+{
+       "name": "FlickrAPI",
+       "version": "2.0.0",
+       "author": [
+               "Ike Hecht",
+               "Sam Wilson"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:FlickrAPI";,
+       "descriptionmsg": "flickrapi-desc",
+       "type": "parserhook",
+       "MessagesDirs": {
+               "FlickrAPI": [
+                       "i18n"
+               ]
+       },
+       "AutoloadClasses": {
+               "FlickrAPIHooks": "FlickrAPI.hooks.php",
+               "FlickrAPIUtils": "FlickrAPIUtils.php",
+               "FlickrAPICache": "FlickrAPICache.php"
+       },
+       "Hooks": {
+               "ParserFirstCallInit": "FlickrAPIHooks::onParserFirstCallInit"
+       },
+       "config": {
+               "FlickrAPIKey": "",
+               "FlickrAPISecret": "",
+               "FlickrAPIDefaults": {
+                       "type": "frameless",
+                       "location": "right",
+                       "size": "-"
+               }
+       },
+       "load_composer_autoloader": true,
+       "manifest_version": 1
+}
diff --git a/modules/phpflickr b/modules/phpflickr
deleted file mode 160000
index bc4f209..0000000
--- a/modules/phpflickr
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit bc4f2092b15d347e3d40c19fe0dbff8759fc8e51
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..14a0ffd
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<ruleset>
+       <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
+       <file>.</file>
+</ruleset>

-- 
To view, visit https://gerrit.wikimedia.org/r/368129
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I46d1a2dd04903b7a3207b9c4a709b80214626fc5
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/FlickrAPI
Gerrit-Branch: master
Gerrit-Owner: Samwilson <s...@samwilson.id.au>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Umherirrender <umherirrender_de...@web.de>
Gerrit-Reviewer: jenkins-bot <>
Gerrit-Reviewer: tosfos <tos...@yahoo.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to