summaryrefslogtreecommitdiff
path: root/includes/composer
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/composer
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/composer')
-rw-r--r--includes/composer/ComposerHookHandler.php37
-rw-r--r--includes/composer/ComposerPackageModifier.php62
-rw-r--r--includes/composer/ComposerVersionNormalizer.php66
3 files changed, 165 insertions, 0 deletions
diff --git a/includes/composer/ComposerHookHandler.php b/includes/composer/ComposerHookHandler.php
new file mode 100644
index 00000000..2587b1d8
--- /dev/null
+++ b/includes/composer/ComposerHookHandler.php
@@ -0,0 +1,37 @@
+<?php
+
+use Composer\Package\Package;
+use Composer\Script\Event;
+
+$GLOBALS['IP'] = __DIR__ . '/../../';
+require_once __DIR__ . '/../AutoLoader.php';
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class ComposerHookHandler {
+
+ public static function onPreUpdate( Event $event ) {
+ self::handleChangeEvent( $event );
+ }
+
+ public static function onPreInstall( Event $event ) {
+ self::handleChangeEvent( $event );
+ }
+
+ private static function handleChangeEvent( Event $event ) {
+ $package = $event->getComposer()->getPackage();
+
+ if ( $package instanceof Package ) {
+ $packageModifier = new ComposerPackageModifier(
+ $package,
+ new ComposerVersionNormalizer(),
+ new MediaWikiVersionFetcher()
+ );
+
+ $packageModifier->setProvidesMediaWiki();
+ }
+ }
+
+}
diff --git a/includes/composer/ComposerPackageModifier.php b/includes/composer/ComposerPackageModifier.php
new file mode 100644
index 00000000..64c69ef5
--- /dev/null
+++ b/includes/composer/ComposerPackageModifier.php
@@ -0,0 +1,62 @@
+<?php
+
+use Composer\Package\Link;
+use Composer\Package\LinkConstraint\VersionConstraint;
+use Composer\Package\Package;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class ComposerPackageModifier {
+
+ const MEDIAWIKI_PACKAGE_NAME = 'mediawiki/mediawiki';
+
+ protected $package;
+ protected $versionNormalizer;
+ protected $versionFetcher;
+
+ public function __construct( Package $package,
+ ComposerVersionNormalizer $versionNormalizer, MediaWikiVersionFetcher $versionFetcher
+ ) {
+ $this->package = $package;
+ $this->versionNormalizer = $versionNormalizer;
+ $this->versionFetcher = $versionFetcher;
+ }
+
+ public function setProvidesMediaWiki() {
+ $this->setLinkAsProvides( $this->newMediaWikiLink() );
+ }
+
+ private function setLinkAsProvides( Link $link ) {
+ $this->package->setProvides( array( $link ) );
+ }
+
+ private function newMediaWikiLink() {
+ $version = $this->getMediaWikiVersionConstraint();
+
+ $link = new Link(
+ '__root__',
+ self::MEDIAWIKI_PACKAGE_NAME,
+ $version,
+ 'provides',
+ $version->getPrettyString()
+ );
+
+ return $link;
+ }
+
+ private function getMediaWikiVersionConstraint() {
+ $mvVersion = $this->versionFetcher->fetchVersion();
+ $mvVersion = $this->versionNormalizer->normalizeSuffix( $mvVersion );
+
+ $version = new VersionConstraint(
+ '==',
+ $this->versionNormalizer->normalizeLevelCount( $mvVersion )
+ );
+ $version->setPrettyString( $mvVersion );
+
+ return $version;
+ }
+
+}
diff --git a/includes/composer/ComposerVersionNormalizer.php b/includes/composer/ComposerVersionNormalizer.php
new file mode 100644
index 00000000..a0d31cf2
--- /dev/null
+++ b/includes/composer/ComposerVersionNormalizer.php
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class ComposerVersionNormalizer {
+
+ /**
+ * Ensures there is a dash in between the version and the stability suffix.
+ *
+ * Examples:
+ * - 1.23RC => 1.23-RC
+ * - 1.23alpha => 1.23-alpha
+ * - 1.23alpha3 => 1.23-alpha3
+ * - 1.23-beta => 1.23-beta
+ *
+ * @param string $version
+ *
+ * @return string
+ * @throws InvalidArgumentException
+ */
+ public function normalizeSuffix( $version ) {
+ if ( !is_string( $version ) ) {
+ throw new InvalidArgumentException( '$version must be a string' );
+ }
+
+ return preg_replace( '/^(\d[\d\.]*)([a-zA-Z]+)(\d*)$/', '$1-$2$3', $version, 1 );
+ }
+
+ /**
+ * Ensures the version has four levels.
+ * Version suffixes are supported, as long as they start with a dash.
+ *
+ * Examples:
+ * - 1.19 => 1.19.0.0
+ * - 1.19.2.3 => 1.19.2.3
+ * - 1.19-alpha => 1.19.0.0-alpha
+ * - 1337 => 1337.0.0.0
+ *
+ * @param string $version
+ *
+ * @return string
+ * @throws InvalidArgumentException
+ */
+ public function normalizeLevelCount( $version ) {
+ if ( !is_string( $version ) ) {
+ throw new InvalidArgumentException( '$version must be a string' );
+ }
+
+ $dashPosition = strpos( $version, '-' );
+
+ if ( $dashPosition !== false ) {
+ $suffix = substr( $version, $dashPosition );
+ $version = substr( $version, 0, $dashPosition );
+ }
+
+ $version = implode( '.', array_pad( explode( '.', $version ), 4, '0' ) );
+
+ if ( $dashPosition !== false ) {
+ $version .= $suffix;
+ }
+
+ return $version;
+ }
+}