[MediaWiki-commits] [Gerrit] new JCSingleton::getContentClass($modelId) - change (mediawiki...JsonConfig)

2014-09-21 Thread Yurik (Code Review)
Yurik has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/161893

Change subject: new JCSingleton::getContentClass($modelId)
..

new JCSingleton::getContentClass($modelId)

Change-Id: I2ea5ce57059c26058dd92f3941c02ef551088159
---
M includes/JCContentHandler.php
M includes/JCSingleton.php
2 files changed, 23 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/JsonConfig 
refs/changes/93/161893/1

diff --git a/includes/JCContentHandler.php b/includes/JCContentHandler.php
index b4b077e..40a5d90 100644
--- a/includes/JCContentHandler.php
+++ b/includes/JCContentHandler.php
@@ -52,27 +52,10 @@
 * @return JCContent the JsonSchemaContent object wrapping $text
 */
public function unserializeContent( $text, $format = null, $isSaving = 
true ) {
-   global $wgJsonConfigModels;
$this-checkFormat( $format );
$modelId = $this-getModelID();
-   $class = null;
-   if ( array_key_exists( $modelId, $wgJsonConfigModels ) ) {
-   $value = $wgJsonConfigModels[$modelId];
-   if ( is_array( $value ) ) {
-   if ( !array_key_exists( 'class', $value ) ) {
-   wfLogWarning( JsonConfig: Invalid 
\$wgJsonConfigModels['$modelId'] array value, 'class' not found );
-   } else {
-   $class = $value['class'];
-   }
-   } else {
-   $class = $value;
-   }
-   }
-   if ( $class ) {
-   return new $class( $text, $modelId, $isSaving );
-   } else {
-   return new JCContent( $text, $modelId, $isSaving );
-   }
+   $class = JCSingleton::getContentClass( $modelId );
+   return new $class( $text, $modelId, $isSaving );
}
 
/**
diff --git a/includes/JCSingleton.php b/includes/JCSingleton.php
index 46aa44e..de69b05 100644
--- a/includes/JCSingleton.php
+++ b/includes/JCSingleton.php
@@ -336,6 +336,27 @@
return self::$titleMap;
}
 
+   public static function getContentClass( $modelId ) {
+   global $wgJsonConfigModels;
+   $class = null;
+   if ( array_key_exists( $modelId, $wgJsonConfigModels ) ) {
+   $value = $wgJsonConfigModels[$modelId];
+   if ( is_array( $value ) ) {
+   if ( !array_key_exists( 'class', $value ) ) {
+   wfLogWarning( JsonConfig: Invalid 
\$wgJsonConfigModels['$modelId'] array value, 'class' not found );
+   } else {
+   $class = $value['class'];
+   }
+   } else {
+   $class = $value;
+   }
+   }
+   if ( !$class ) {
+   $class = __NAMESPACE__ . '\JCContent';
+   }
+   return $class;
+   }
+
/**
 * Returns an array with settings if the $titleValue object is handled 
by the JsonConfig extension,
 * false if unrecognized namespace, and null if namespace is handled 
but not this title

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2ea5ce57059c26058dd92f3941c02ef551088159
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Yurik yu...@wikimedia.org

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


[MediaWiki-commits] [Gerrit] new JCSingleton::getContentClass($modelId) - change (mediawiki...JsonConfig)

2014-09-21 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: new JCSingleton::getContentClass($modelId)
..


new JCSingleton::getContentClass($modelId)

Change-Id: I2ea5ce57059c26058dd92f3941c02ef551088159
---
M includes/JCContentHandler.php
M includes/JCSingleton.php
2 files changed, 23 insertions(+), 19 deletions(-)

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



diff --git a/includes/JCContentHandler.php b/includes/JCContentHandler.php
index b4b077e..40a5d90 100644
--- a/includes/JCContentHandler.php
+++ b/includes/JCContentHandler.php
@@ -52,27 +52,10 @@
 * @return JCContent the JsonSchemaContent object wrapping $text
 */
public function unserializeContent( $text, $format = null, $isSaving = 
true ) {
-   global $wgJsonConfigModels;
$this-checkFormat( $format );
$modelId = $this-getModelID();
-   $class = null;
-   if ( array_key_exists( $modelId, $wgJsonConfigModels ) ) {
-   $value = $wgJsonConfigModels[$modelId];
-   if ( is_array( $value ) ) {
-   if ( !array_key_exists( 'class', $value ) ) {
-   wfLogWarning( JsonConfig: Invalid 
\$wgJsonConfigModels['$modelId'] array value, 'class' not found );
-   } else {
-   $class = $value['class'];
-   }
-   } else {
-   $class = $value;
-   }
-   }
-   if ( $class ) {
-   return new $class( $text, $modelId, $isSaving );
-   } else {
-   return new JCContent( $text, $modelId, $isSaving );
-   }
+   $class = JCSingleton::getContentClass( $modelId );
+   return new $class( $text, $modelId, $isSaving );
}
 
/**
diff --git a/includes/JCSingleton.php b/includes/JCSingleton.php
index 46aa44e..de69b05 100644
--- a/includes/JCSingleton.php
+++ b/includes/JCSingleton.php
@@ -336,6 +336,27 @@
return self::$titleMap;
}
 
+   public static function getContentClass( $modelId ) {
+   global $wgJsonConfigModels;
+   $class = null;
+   if ( array_key_exists( $modelId, $wgJsonConfigModels ) ) {
+   $value = $wgJsonConfigModels[$modelId];
+   if ( is_array( $value ) ) {
+   if ( !array_key_exists( 'class', $value ) ) {
+   wfLogWarning( JsonConfig: Invalid 
\$wgJsonConfigModels['$modelId'] array value, 'class' not found );
+   } else {
+   $class = $value['class'];
+   }
+   } else {
+   $class = $value;
+   }
+   }
+   if ( !$class ) {
+   $class = __NAMESPACE__ . '\JCContent';
+   }
+   return $class;
+   }
+
/**
 * Returns an array with settings if the $titleValue object is handled 
by the JsonConfig extension,
 * false if unrecognized namespace, and null if namespace is handled 
but not this title

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2ea5ce57059c26058dd92f3941c02ef551088159
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Yurik yu...@wikimedia.org
Gerrit-Reviewer: Yurik yu...@wikimedia.org
Gerrit-Reviewer: jenkins-bot 

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