Yurik has uploaded a new change for review.

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

Change subject: Added abstract JCDataContent
......................................................................

Added abstract JCDataContent

The new class will be the base for geojson & tabular.
It supports license and localized information fields.

Change-Id: I3e6b8c3eb38855403587f7defdbd99025a4d0e76
---
M JsonConfig.php
A includes/JCDataContent.php
2 files changed, 67 insertions(+), 0 deletions(-)


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

diff --git a/JsonConfig.php b/JsonConfig.php
index 16c9022..2ced91c 100644
--- a/JsonConfig.php
+++ b/JsonConfig.php
@@ -46,6 +46,7 @@
                        'JCContent',
                        'JCContentHandler',
                        'JCContentView',
+                       'JCDataContent',
                        'JCDefaultContentView',
                        'JCDefaultObjContentView',
                        'JCObjContent',
diff --git a/includes/JCDataContent.php b/includes/JCDataContent.php
new file mode 100644
index 0000000..a11bfc8
--- /dev/null
+++ b/includes/JCDataContent.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace JsonConfig;
+
+use Html;
+use ParserOptions;
+use ParserOutput;
+use Title;
+
+/**
+ * @package JsonConfig
+ */
+abstract class JCDataContent extends JCObjContent {
+
+       protected function fillParserOutput( Title $title, $revId, 
ParserOptions $options,
+                                                                               
 $generateHtml, ParserOutput &$output ) {
+               if ( !$generateHtml ) {
+                       return;
+               }
+
+               // Use user's language, and split parser cache.  This should 
not have a big
+               // impact because data namespace is rarely viewed, but viewing 
it localized
+               // will be valuable
+               $lang = $options->getUserLangObj();
+
+               $status = $this->getStatus();
+               if ( !$status->isGood() ) {
+                       $html = $status->getHTML( false, false, $lang );
+               } else {
+                       $html = '';
+               }
+
+               /** @var object $data */
+               $data = $this->getValidationData();
+
+               if ( !$data->info->error() ) {
+                       $info = JCUtils::pickLocalizedString( 
$data->info->getValue(), $lang );
+                       $html .= Html::element( 'p', [ 'class' => 
'mw-jsonconfig-info' ], $info );
+               }
+
+               $html .= $this->createDefaultView()->valueToHtml( $this, $lang 
);
+
+               if ( !$data->license->error() ) {
+                       $license = $data->license->getValue();
+                       $html .= Html::element( 'p', [ 'class' => 
'mw-jsonconfig-license' ], $license );
+               }
+
+               $output->setText( $html );
+       }
+
+       /**
+        * Derived classes must implement this method to perform custom 
validation
+        * using the check(...) calls
+        */
+       public function validateContent() {
+
+               if ( !$this->thorough() ) {
+                       // We are not doing any modifications to the original, 
so no need to validate it
+                       return;
+               }
+
+               // TODO: handle well-known licenses and link to them
+               $this->test( 'license', JCValidators::isString() );
+               $this->test( 'info', JCValidators::isLocalizedString() );
+       }
+}

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

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

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

Reply via email to