MaxSem has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/352285 )

Change subject: Parse map data on central wiki
......................................................................

Parse map data on central wiki

I'm still not sure this is worth the added complexity though.

Bug: T155216

Change-Id: If8f62098ba702ebc35950e9d299357a1d0a8b708
---
M includes/JCCache.php
M includes/JCContent.php
M includes/JCMapDataContent.php
3 files changed, 42 insertions(+), 3 deletions(-)


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

diff --git a/includes/JCCache.php b/includes/JCCache.php
index 1815780..a2ad991 100644
--- a/includes/JCCache.php
+++ b/includes/JCCache.php
@@ -57,7 +57,12 @@
                                if ( $this->titleValue->getConfig()->store ) {
                                        $this->loadLocal(); // Get it from the 
local wiki
                                } else {
-                                       $this->loadRemote(); // Get it from HTTP
+                                       // Get it from HTTP
+                                       $class = JCSingleton::getContentClass( 
$this->titleValue->getConfig()->model );
+                                       $method = $class && isset( 
$class::$remoteLoadingMethod )
+                                                       ? 
$class::$remoteLoadingMethod
+                                                       : 'loadRemotePageData';
+                                       $this->$method();
                                }
                                $this->memcSet(); // Save result to memcached
                        } elseif ( $value === '' ) {
@@ -147,7 +152,7 @@
        /**
         * Retrieves the config using HTTP and sets $this->content to string or 
false
         */
-       private function loadRemote() {
+       private function loadRemotePageData() {
                do {
                        $result = false;
                        $conf = $this->titleValue->getConfig();
@@ -207,6 +212,37 @@
                $this->content = $result;
        }
 
+       /**
+        * Same as loadRemotePageData() but uses API action=jsondata
+        */
+       private function loadRemoteJsonData() {
+               $this->content = false;
+
+               $conf = $this->titleValue->getConfig();
+               $remote = $conf->remote;
+               $req = JCUtils::initApiRequestObj( $remote->url, 
$remote->username, $remote->password );
+               if ( !$req ) {
+                       return;
+               }
+               $articleName = $this->titleValue->getText();
+               $params = [
+                       'action' => 'jsondata',
+                       'titles' => $articleName,
+                       'formatversion' => 2,
+               ];
+
+               $data = JCUtils::callApi( $req, $params, 'get remote JSON data 
from ' . __METHOD__ );
+
+               if ( !$data ) {
+                       return;
+               }
+
+               if ( !is_object( $data ) || isset( $data->jsondata ) ) {
+                       JCUtils::warn( 'Unrecognizable API result', [ 'title' 
=> $articleName ], $data );
+               }
+               $this->content = json_encode( $data->jsondata );
+       }
+
        /** Given a legal set of API parameters, return page from API
         * @param string $articleName title name used for warnings
         * @param \CurlHttpRequest|\PhpHttpRequest $req logged-in session
@@ -215,7 +251,7 @@
         */
        private function getPageFromApi( $articleName, $req, $query ) {
 
-               $revInfo = JCUtils::callApi( $req, $query, 'get remote 
JsonConfig' );
+               $revInfo = JCUtils::callApi( $req, $query, 'get remote 
JsonConfig from ' . __METHOD__ );
                if ( $revInfo === false ) {
                        return false;
                }
diff --git a/includes/JCContent.php b/includes/JCContent.php
index 50ffc49..ec6af44 100644
--- a/includes/JCContent.php
+++ b/includes/JCContent.php
@@ -18,6 +18,8 @@
  * @author Yuri Astrakhan <[email protected]>, based on Ori Livneh 
<[email protected]> extension schema
  */
 class JCContent extends \TextContent {
+       public static $remoteLoadingMethod = 'loadRemotePageData';
+
        /** @var array */
        private $rawData = null;
        /** @var stdClass|array */
diff --git a/includes/JCMapDataContent.php b/includes/JCMapDataContent.php
index ad181ae..73474ec 100644
--- a/includes/JCMapDataContent.php
+++ b/includes/JCMapDataContent.php
@@ -11,6 +11,7 @@
  * @package JsonConfig
  */
 class JCMapDataContent extends JCDataContent {
+       public static $remoteLoadingMethod = 'loadRemoteJsonData';
 
        public function validateContent() {
                parent::validateContent();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If8f62098ba702ebc35950e9d299357a1d0a8b708
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to