Yurik has uploaded a new change for review.

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

Change subject: Added "sources" field to tabular & map data
......................................................................

Added "sources" field to tabular & map data

* Now both tabular and map data supports an optional
  unlimited "sources" string field treated as a wiki markup.
* Cleaned up the pre-populated "new page" content.

Change-Id: Ic2cdb4fc77a80363180942c763f034c06d091a0c
---
M includes/JCDataContent.php
M includes/JCMapDataContentView.php
M includes/JCTabularContentView.php
3 files changed, 48 insertions(+), 5 deletions(-)


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

diff --git a/includes/JCDataContent.php b/includes/JCDataContent.php
index 8850277..fe99fcd 100644
--- a/includes/JCDataContent.php
+++ b/includes/JCDataContent.php
@@ -4,7 +4,10 @@
 
 use Html;
 use Language;
+use Parser;
+use ParserOptions;
 use stdClass;
+use Title;
 
 /**
  * @package JsonConfig
@@ -24,6 +27,7 @@
 
                $this->test( 'license', JCValidators::isStringLine(), 
self::isValidLicense() );
                $this->testOptional( 'info', [ 'en' => '' ], 
JCValidators::isLocalizedString() );
+               $this->testOptional( 'sources', '', JCValidators::isString() );
        }
 
        /** Returns a validator function to check if the value is a valid string
@@ -72,6 +76,9 @@
                                'url' => wfMessage( 'jsonconfig-license-url-' . 
$data->license )->plain(),
                        ];
                }
+               if ( property_exists( $data, 'sources' ) ) {
+                       $result->sources = $data->sources;
+               }
        }
 
        public function renderInfo( $lang ) {
@@ -103,4 +110,17 @@
 
                return $html;
        }
+
+       public function renderSources( Parser $parser, Title $title, $revId, 
ParserOptions $options ) {
+               $sources = $this->getField( 'sources' );
+
+               if ( $sources && !$sources->error() ) {
+                       $text = $parser->parse( $sources->getValue(), $title, 
$options, true, true, $revId );
+                       $html = Html::rawElement( 'p', [ 'class' => 
'mw-jsonconfig-sources' ], $text );
+               } else {
+                       $html = '';
+               }
+
+               return $html;
+       }
 }
diff --git a/includes/JCMapDataContentView.php 
b/includes/JCMapDataContentView.php
index 3ed21f0..8ec1c55 100644
--- a/includes/JCMapDataContentView.php
+++ b/includes/JCMapDataContentView.php
@@ -29,6 +29,8 @@
                                                                 $generateHtml, 
ParserOutput &$output ) {
                global $wgParser;
 
+               $parser = $wgParser->getFreshParser();
+
                $localizedData = $content->getLocalizedData( 
$options->getUserLangObj() );
                if ( $localizedData ) {
 
@@ -67,12 +69,13 @@
                                }
                        }
                        $output =
-                               $wgParser->getFreshParser()->parse( $text, 
$title, $options, true, true, $revId );
+                               $parser->parse( $text, $title, $options, true, 
true, $revId );
                }
 
                return
                        $content->renderInfo( $options->getUserLangObj() ) . 
'<br>' .
                        $output->getRawText() . '<br clear=all>' .
+                       $content->renderSources( $parser, $title, $revId, 
$options ) .
                        $content->renderLicense();
        }
 
@@ -85,13 +88,24 @@
        public function getDefault( $modelId ) {
                return <<<EOT
 {
-       "info": { "en": "description" },
-       "license": "CC0-1.0",
+    // !!!!! All comments will be automatically deleted on save !!!!!
+
+    // Optional "info" field to describe this map
+    "info": {"en": "map description"},
+
+    // Optional "sources" field to describe the sources of the map.  Can use 
Wiki Markup
+    "sources": "Copied from [http://example.com Example Map Source]",
+    
+    // Mandatory "license" field. Only CC-0 (public domain dedication) is 
supported.
+    "license": "CC0-1.0",
+
        "zoom": 3,
        "latitude": 0,
        "longitude": 0,
        "data": {
-               ...
+               
+               ... GeoJSON ...
+               
        }
 }
 EOT;
diff --git a/includes/JCTabularContentView.php 
b/includes/JCTabularContentView.php
index 265c96a..c7c1cab 100644
--- a/includes/JCTabularContentView.php
+++ b/includes/JCTabularContentView.php
@@ -118,10 +118,13 @@
                        }
                }
 
+               global $wgParser;
+
                $html =
                        $content->renderInfo( $lang ) .
                        Html::rawElement( 'table', $dataAttrs,
                                Html::rawElement( 'tbody', null, implode( "\n", 
$result ) ) ) .
+                       $content->renderSources( $wgParser->getFreshParser(), 
$title, $revId, $options ) .
                        $content->renderLicense();
 
                return $html;
@@ -154,8 +157,14 @@
        public function getDefault( $modelId ) {
                return <<<EOT
 {
-    // All comments will be automatically deleted on save
+    // !!!!! All comments will be automatically deleted on save !!!!!
 
+    // Optional "info" field to describe this data
+    "info": {"en": "table description"},
+
+    // Optional "sources" field to describe the sources of the data.  Can use 
Wiki Markup
+    "sources": "Copied from [http://example.com Example Data Source]",
+    
     // Mandatory "license" field. Only CC-0 (public domain dedication) is 
supported.
     "license": "CC0-1.0",
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic2cdb4fc77a80363180942c763f034c06d091a0c
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

Reply via email to