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

Change subject: Convert to extension registration and PSR4
......................................................................


Convert to extension registration and PSR4

Also move all classes to their own files in 'includes' and
namespace, and update the code accordingly.

Bug: T173209
Change-Id: I8c8a47b13ca79be5789f796fe77e2b4fff28cb03
---
M GraphViz.php
M README.md
M RELEASE-NOTES.md
M composer.json
A extension.json
R includes/GraphRenderParms.php
R includes/GraphViz.php
A includes/Settings.php
A includes/UploadFromLocalFile.php
R includes/UploadLocalFile.php
M tests/phpunit/GraphVizTest.php
11 files changed, 255 insertions(+), 198 deletions(-)

Approvals:
  Welterkj: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/GraphViz.php b/GraphViz.php
index 77acb12..7e1b59d 100644
--- a/GraphViz.php
+++ b/GraphViz.php
@@ -30,97 +30,14 @@
  * @file
  * @ingroup Extensions
  */
-
-define( 'GraphViz_VERSION', '2.1.0' );
-
-/**
- * The GraphViz settings class.
- */
-class GraphVizSettings {
-       /**
-        * dot executable path
-        * Windows Default: C:/Programme/ATT/Graphviz/bin/
-        * Other Platform : /usr/local/bin/dot
-        *
-        * '/' will be converted to '\\' later on, so feel free how to write 
your path C:/ or C:\\
-        *
-        * @var string $execPath
-        */
-       public $execPath;
-
-       /**
-        * mscgen executable path
-        * Commonly '/usr/bin/', '/usr/local/bin/' or (if set) '$DOT_PATH/'.
-        *
-        * '/' will be converted to '\\' later on, so feel free how to write 
your path C:/ or C:\\
-        *
-        * @var string $mscgenPath
-        */
-       public $mscgenPath;
-
-       /**
-        * default image type for the output of dot or mscgen
-        * The "default default" is png.
-        *
-        * @var string $defaultImageType
-        */
-       public $defaultImageType;
-
-       /**
-        * Whether or not to automatically create category pages for images 
created by this extension.
-        * yes|no (case insensitive). The default is no.
-        *
-        * @var string $createCategoryPages
-        */
-       public $createCategoryPages;
-
-       /**
-        * Constructor for setting configuration variable defaults.
-        */
-       public function __construct() {
-               // Set execution path
-               if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'Darwin' ) ) 
{
-                       $this->execPath = 'C:/Program Files/Graphviz/bin/';
-               } else {
-                       $this->execPath = '/usr/bin/';
-               }
-
-               $this->mscgenPath = '';
-               $this->defaultImageType = 'png';
-               $this->createCategoryPages = 'no';
-       }
-};
-
-if ( defined( 'MEDIAWIKI' ) ) {
-       $GLOBALS['wgGraphVizSettings'] = new GraphVizSettings();
-
-       // self executing anonymous function to prevent global scope assumptions
-       call_user_func( function () {
-               $dir = __DIR__ . '/';
-
-               $GLOBALS['wgMessagesDirs']['GraphViz'] = $dir . 'i18n';
-               $GLOBALS['wgAutoloadClasses']['GraphViz'] = $dir . 
"GraphViz_body.php";
-               $GLOBALS['wgAutoloadClasses']['GraphRenderParms'] = $dir . 
"GraphRenderParms.php";
-               $GLOBALS['wgAutoloadClasses']['UploadLocalFile'] = $dir . 
"UploadLocalFile.php";
-               $GLOBALS['wgAutoloadClasses']['UploadFromLocalFile'] = $dir . 
"UploadLocalFile.php";
-               $GLOBALS['wgHooks']['ParserFirstCallInit'][] = 
'GraphViz::onParserInit';
-               $GLOBALS['wgHooks']['ArticleDeleteComplete'][] = 
'GraphViz::onArticleDeleteComplete';
-               $GLOBALS['wgHooks']['UnitTestsList'][] = 
'GraphViz::onUnitTestsList';
-               $GLOBALS['wgHooks']['PageContentSave'][] = 
'GraphViz::onPageContentSave';
-               $GLOBALS['wgHooks']['RejectParserCacheValue'][] = 
'GraphViz::onRejectParserCacheValue';
-               $GLOBALS['wgExtensionCredits']['parserhook'][] = [
-                       'name' => 'Graphviz',
-                       'path' => __FILE__,
-                       'version' => GraphViz_VERSION,
-                       'author' => [
-                               '[http://wickle.com CoffMan]',
-                               '[mailto://arno.ven...@gmail.com 
MasterOfDesaster]',
-                               '[http://hummel-universe.net Thomas Hummel]',
-                               '[mailto://welt...@gmail.com Keith Welter]'
-                       ],
-                       'url' => 
'https://www.mediawiki.org/wiki/Extension:GraphViz',
-                       'descriptionmsg' => 'graphviz-desc',
-                       'license-name' => 'GPL-2.0+'
-               ];
-       } );
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'GraphViz' );
+       $wgMessageDirs['GraphViz'] = __DIR__ . '/i18n';
+       wfWarn(
+               'Deprecated PHP entry point used for GraphViz extension. ' .
+               'Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );
+} else {
+       die( 'This version of the GraphViz extension requires MediaWiki 1.29+' 
);
 }
diff --git a/README.md b/README.md
index 81342c4..2f283db 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
 ```json
 {
        "require": {
-               "mediawiki/graph-viz": "~1.1"
+               "mediawiki/graph-viz": "^2.0"
        }
 }
 ```
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index dc6fd76..92b4f15 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -1,10 +1,15 @@
 These are the release notes for the [MediaWiki][mediawiki] [GraphViz 
extension][gv_ext].
 
+## GraphViz 3.0.0
+* Add support for MediaWiki 1.29 [bug 
T173209](https://phabricator.wikimedia.org/T173209)
+* Drop support for MediaWiki 1.28 and earlier.
+* Add extension registration and move classes to their own namespace.
+
 ## GraphViz 2.1.0 ## (2017-08-02)
-* Remove compat with PHP 5.3 and earlier
-* Remove compat with MW 1.22 and earlier
-* Remove I18n php shim [bug T168353](https://phabricator.wikimedia.org/T168353)
-* Fix for dying on phpcs run [bug 
T168738](https://phabricator.wikimedia.org/T168738)
+* Remove compatibilty with PHP 5.3 and earlier.
+* Remove compatiblity with MW 1.22 and earlier.
+* Remove I18n php shim [bug 
T168353](https://phabricator.wikimedia.org/T168353).
+* Fix for dying on phpcs run [bug 
T168738](https://phabricator.wikimedia.org/T168738).
 
 ## GraphViz 2.0.1 ## (2017-04-18)
 * Fix for [bug T163103](https://phabricator.wikimedia.org/T163103).
diff --git a/composer.json b/composer.json
index 8808d80..a48dc1a 100644
--- a/composer.json
+++ b/composer.json
@@ -19,14 +19,9 @@
                "mediawiki/image-map": "The ImageMap extension is required and 
is bundled with MediaWiki.  See 
https://www.mediawiki.org/wiki/Extension:ImageMap";
        },
        "autoload": {
-               "files": [
-                       "GraphViz.php"
-               ],
-               "classmap": [
-                       "GraphRenderParms.php",
-                       "GraphViz_body.php",
-                       "UploadLocalFile.php"
-               ]
+               "psr-4": {
+                       "MediaWiki\\Extension\\GraphViz\\": "includes/"
+               }
        },
        "require-dev": {
                "jakub-onderka/php-parallel-lint": "0.9.2",
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..7e01f70
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,47 @@
+{
+       "name": "GraphViz",
+       "version": "3.0.0",
+       "type": "parserhook",
+       "author": [
+               "Keith Welter",
+               "[https://meta.wikimedia.org/wiki/User:Coffman Victor FariƱa]",
+               "[https://www.mediawiki.org/wiki/User:Matthewpearson Matthew 
Pearson]",
+               "[https://www.mediawiki.org/wiki/User:Hummel-riegel Thomas 
Hummel]",
+               "Gregory Szorc"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:GraphViz";,
+       "descriptionmsg": "graphviz-desc",
+       "license-name": "GPL-2.0+",
+       "requires": {
+               "MediaWiki": ">= 1.29.0"
+       },
+       "AutoloadClasses": {
+               "MediaWiki\\Extension\\GraphViz\\GraphViz": 
"includes/GraphViz.php",
+               "MediaWiki\\Extension\\GraphViz\\Settings": 
"includes/Settings.php",
+               "MediaWiki\\Extension\\GraphViz\\UploadLocalFile": 
"includes/UploadLocalFile.php",
+               "MediaWiki\\Extension\\GraphViz\\UploadFromLocalFile": 
"includes/UploadFromLocalFile.php",
+               "MediaWiki\\Extension\\GraphViz\\GraphRenderParms": 
"includes/GraphRenderParms.php"
+       },
+       "MessagesDirs": {
+               "GraphViz": [
+                       "i18n"
+               ]
+       },
+       "config": {
+               "AdminCanReadAll": {
+                       "value": true,
+                       "description": "Sysop users can read all restricted 
pages"
+               },
+               "GraphVizRedirect": {
+                       "value": true,
+                       "description": "Do not redirect from page in search 
results to restricted pages"
+               }
+       },
+       "Hooks": {
+               "ParserFirstCallInit": 
"MediaWiki\\Extension\\GraphViz\\GraphViz::onParserInit",
+               "ArticleDeleteComplete": 
"MediaWiki\\Extension\\GraphViz\\GraphViz::onArticleDeleteComplete",
+               "PageContentSave": 
"MediaWiki\\Extension\\GraphViz\\GraphViz::onPageContentSave",
+               "RejectParserCacheValue": 
"MediaWiki\\Extension\\GraphViz\\GraphViz::onRejectParserCacheValue"
+       },
+       "manifest_version": 2
+}
diff --git a/GraphRenderParms.php b/includes/GraphRenderParms.php
similarity index 97%
rename from GraphRenderParms.php
rename to includes/GraphRenderParms.php
index 18b1af8..29f5f66 100644
--- a/GraphRenderParms.php
+++ b/includes/GraphRenderParms.php
@@ -24,6 +24,8 @@
  * @ingroup Extensions
  */
 
+namespace MediaWiki\Extension\GraphViz;
+
 /**
  * A convenience class for holding the parameters pertaining to graph 
rendering using dot or mscgen.
  * @author Keith Welter
@@ -73,14 +75,13 @@
        private $imageDir = '';
 
        public function __construct( $renderer, $graphName, $userName, 
$imageType, $sourceAndMapDir, $imageDir ) {
-               global $wgGraphVizSettings;
-
                $this->graphName = $graphName;
                $this->userName = $userName;
                $this->renderer = $renderer;
                $this->sourceAndMapDir = $sourceAndMapDir;
                $this->imageDir = $imageDir;
-               $this->execPath = $wgGraphVizSettings->execPath;
+               $settings = new Settings();
+               $this->execPath = $settings->execPath;
 
                wfDebug( __METHOD__ . ": userName: $userName graphName: 
$graphName\n" );
                wfDebug( __METHOD__ . ": sourceAndMapDir: $sourceAndMapDir 
imageDir: $imageDir\n" );
@@ -97,7 +98,7 @@
                                break;
                        case 'mscgen':
                                $this->mapType = 'ismap';
-                               $this->execPath = 
$wgGraphVizSettings->mscgenPath;
+                               $this->execPath = $settings->mscgenPath;
                                break;
                        default:
                                $this->renderer = 'dot';
diff --git a/GraphViz_body.php b/includes/GraphViz.php
similarity index 97%
rename from GraphViz_body.php
rename to includes/GraphViz.php
index 9134687..58d97eb 100644
--- a/GraphViz_body.php
+++ b/includes/GraphViz.php
@@ -23,12 +23,21 @@
  * @ingroup Extensions
  */
 
- /**
-  * This is the principal class of the GraphViz extension, responsible
-  * for graph file management and rendering graph images and maps as HTML.
-  * Graph source, image and map files are saved in the file system in order to 
avoid
-  * regenerating them every time a page containing a graph is rendered.
-  * The ImageMap extension is used for the rendering of graph images and maps 
as HTML.
+namespace MediaWiki\Extension\GraphViz;
+
+use Html;
+use ImageMap;
+use MWException;
+use Parser;
+use Sanitizer;
+use User;
+
+/**
+  *  This is the principal class of the GraphViz extension, responsible
+  *  for graph file management and rendering graph images and maps as HTML.
+  *  Graph source, image and map files are saved in the file system in order 
to avoid
+  *  regenerating them every time a page containing a graph is rendered.
+  *  The ImageMap extension is used for the rendering of graph images and maps 
as HTML.
   *
   * @ingroup Extensions
   */
@@ -171,16 +180,6 @@
         */
        protected static function getDotImagePattern() {
                return "~(?i)image\s*=\s*(" . self::DOT_ID_STRING . "|" . 
self::DOT_NUMERAL . "|" . self::DOT_QUOTED_STRING . "|" .  
self::DOT_HTML_STRING . ")~";
-       }
-
-       /**
-        * Unit test hook.
-        * @author Keith Welter
-        * @return true
-        */
-       public static function onUnitTestsList( &$files ) {
-               $files = array_merge( $files, glob( __DIR__ . 
'/tests/phpunit/*Test.php' ) );
-               return true;
        }
 
        /**
@@ -480,9 +479,7 @@
         * @author Keith Welter et al.
         */
        protected static function render( $input, $args, $parser, $frame ) {
-               global
-               $wgUser,
-               $wgGraphVizSettings;
+               global $wgUser;
 
                // sanity check the input
                $input = trim( $input );
@@ -537,7 +534,8 @@
                if ( isset( $args['format'] ) ) {
                        $imageType = $args['format'];
                } else {
-                       $imageType = $wgGraphVizSettings->defaultImageType;
+                       $settings = new Settings();
+                       $imageType = $settings->defaultImageType;
                }
 
                // determine user...
diff --git a/includes/Settings.php b/includes/Settings.php
new file mode 100644
index 0000000..2ee631e
--- /dev/null
+++ b/includes/Settings.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace MediaWiki\Extension\GraphViz;
+
+/**
+ * The GraphViz settings class.
+ */
+class Settings {
+       /**
+        * dot executable path
+        * Windows Default: C:/Programme/ATT/Graphviz/bin/
+        * Other Platform : /usr/local/bin/dot
+        *
+        * '/' will be converted to '\\' later on, so feel free how to write 
your path C:/ or C:\\
+        *
+        * @var string $execPath
+        */
+       public $execPath;
+
+       /**
+        * mscgen executable path
+        * Commonly '/usr/bin/', '/usr/local/bin/' or (if set) '$DOT_PATH/'.
+        *
+        * '/' will be converted to '\\' later on, so feel free how to write 
your path C:/ or C:\\
+        *
+        * @var string $mscgenPath
+        */
+       public $mscgenPath;
+
+       /**
+        * default image type for the output of dot or mscgen
+        * The "default default" is png.
+        *
+        * @var string $defaultImageType
+        */
+       public $defaultImageType;
+
+       /**
+        * Whether or not to automatically create category pages for images 
created by this extension.
+        * yes|no (case insensitive). The default is no.
+        *
+        * @var string $createCategoryPages
+        */
+       public $createCategoryPages;
+
+       /**
+        * Constructor for setting configuration variable defaults.
+        */
+       public function __construct() {
+               // Set execution path
+               if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'Darwin' ) ) 
{
+                       $this->execPath = 'C:/Program Files/Graphviz/bin/';
+               } else {
+                       $this->execPath = '/usr/bin/';
+               }
+
+               $this->mscgenPath = '';
+               $this->defaultImageType = 'png';
+               $this->createCategoryPages = 'no';
+       }
+}
diff --git a/includes/UploadFromLocalFile.php b/includes/UploadFromLocalFile.php
new file mode 100644
index 0000000..c40062e
--- /dev/null
+++ b/includes/UploadFromLocalFile.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace MediaWiki\Extension\GraphViz;
+
+use File;
+use RepoGroup;
+use Status;
+use UploadBase;
+
+/**
+ * Supports local file uploads in the absence of a WebRequest.
+ * Simplified from UploadFromFile.
+ *
+ * @ingroup Upload
+ * @author Keith Welter
+ */
+class UploadFromLocalFile extends UploadBase {
+       /**
+        * This function is a no-op because a WebRequest is not used.
+        * It exists here because it is abstract in UploadBase.
+        */
+       function initializeFromRequest( &$request ) {
+       }
+
+       /**
+        * @return string 'file'
+        */
+       public function getSourceType() {
+               return 'file';
+       }
+
+       /**
+        * Return the local file and initializes if necessary.
+        *
+        * @return UploadLocalFile|null
+        */
+       public function getLocalFile() {
+               if ( is_null( $this->mLocalFile ) ) {
+                       $nt = $this->getTitle();
+                       $repo = RepoGroup::singleton()->getLocalRepo();
+                       $this->mLocalFile = is_null( $nt ) ? null : 
UploadLocalFile::newFromTitle( $nt, $repo );
+               }
+
+               return $this->mLocalFile;
+       }
+
+       /**
+        * Really perform the upload.
+        *
+        * @param string $comment
+        * @return Status Indicating the whether the upload succeeded.
+        */
+       public function performUpload2( $comment ) {
+               global $wgUser;
+               $user = $wgUser;
+
+               $this->getLocalFile()->load( File::READ_LATEST );
+               $props = $this->mFileProps;
+
+               $pageText = '';
+
+               $status = $this->getLocalFile()->upload2(
+                       $this->mTempPath,
+                       $comment,
+                       $props,
+                       File::DELETE_SOURCE
+               );
+
+               if ( $status->isGood() ) {
+                       $this->postProcessUpload();
+               }
+
+               return $status;
+       }
+}
diff --git a/UploadLocalFile.php b/includes/UploadLocalFile.php
similarity index 91%
rename from UploadLocalFile.php
rename to includes/UploadLocalFile.php
index 2874677..847c1de 100644
--- a/UploadLocalFile.php
+++ b/includes/UploadLocalFile.php
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Extension to allow Graphviz to work inside MediaWiki.
  * See mediawiki.org/wiki/Extension:GraphViz for more information
@@ -24,6 +25,24 @@
  * @ingroup Upload
  * @author Keith Welter
  */
+
+namespace MediaWiki\Extension\GraphViz;
+
+use CdnCacheUpdate;
+use DeferredUpdates;
+use File;
+use FileRepo;
+use FSFile;
+use HTMLCacheUpdate;
+use LinksUpdate;
+use LocalFile;
+use MediaHandler;
+use MWException;
+use RepoGroup;
+use SiteStatsUpdate;
+use Status;
+use Title;
+use UploadBase;
 
 /**
  * Implements local file uploads in the absence of a WebRequest in conjunction 
with UploadFromLocalFile.
@@ -458,72 +477,5 @@
                }
 
                return true;
-       }
-}
-
-/**
- * Supports local file uploads in the absence of a WebRequest.
- * Simplified from UploadFromFile.
- *
- * @ingroup Upload
- * @author Keith Welter
- */
-class UploadFromLocalFile extends UploadBase {
-       /**
-        * This function is a no-op because a WebRequest is not used.
-        * It exists here because it is abstract in UploadBase.
-        */
-       function initializeFromRequest( &$request ) {
-       }
-
-       /**
-        * @return string 'file'
-        */
-       public function getSourceType() {
-               return 'file';
-       }
-
-       /**
-        * Return the local file and initializes if necessary.
-        *
-        * @return UploadLocalFile|null
-        */
-       public function getLocalFile() {
-               if ( is_null( $this->mLocalFile ) ) {
-                       $nt = $this->getTitle();
-                       $repo = RepoGroup::singleton()->getLocalRepo();
-                       $this->mLocalFile = is_null( $nt ) ? null : 
UploadLocalFile::newFromTitle( $nt, $repo );
-               }
-
-               return $this->mLocalFile;
-       }
-
-       /**
-        * Really perform the upload.
-        *
-        * @param string $comment
-        * @return Status Indicating the whether the upload succeeded.
-        */
-       public function performUpload2( $comment ) {
-               global $wgUser;
-               $user = $wgUser;
-
-               $this->getLocalFile()->load( File::READ_LATEST );
-               $props = $this->mFileProps;
-
-               $pageText = '';
-
-               $status = $this->getLocalFile()->upload2(
-                       $this->mTempPath,
-                       $comment,
-                       $props,
-                       File::DELETE_SOURCE
-               );
-
-               if ( $status->isGood() ) {
-                       $this->postProcessUpload();
-               }
-
-               return $status;
        }
 }
diff --git a/tests/phpunit/GraphVizTest.php b/tests/phpunit/GraphVizTest.php
index c3a3bcb..26ee1d8 100644
--- a/tests/phpunit/GraphVizTest.php
+++ b/tests/phpunit/GraphVizTest.php
@@ -1,5 +1,11 @@
 <?php
 
+namespace MediaWiki\Extension\GraphViz\Test;
+
+use MediaWiki\Extension\GraphViz\GraphViz;
+use MediaWikiTestCase;
+use ReflectionClass;
+
 /**
  *  @group GraphViz
  */
@@ -15,7 +21,7 @@
        }
 
        protected static function getGraphVizMethod( $name ) {
-               $class = new ReflectionClass( 'GraphViz' );
+               $class = new ReflectionClass( GraphViz::class );
                $method = $class->getMethod( $name );
                $method->setAccessible( true );
                return $method;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8c8a47b13ca79be5789f796fe77e2b4fff28cb03
Gerrit-PatchSet: 18
Gerrit-Project: mediawiki/extensions/GraphViz
Gerrit-Branch: master
Gerrit-Owner: Reception123 <utilizator.receptie...@gmail.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Mainframe98 <k.s.w...@hotmail.com>
Gerrit-Reviewer: Reception123 <utilizator.receptie...@gmail.com>
Gerrit-Reviewer: Samwilson <s...@samwilson.id.au>
Gerrit-Reviewer: Welterkj <welterkj+...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to