Himeshi has uploaded a new change for review.
https://gerrit.wikimedia.org/r/79556
Change subject: Added PageSchemas extension handling for page sections
......................................................................
Added PageSchemas extension handling for page sections
Implemented the handling of page sections for the PageSchemas extension
Bug: 46662
Change-Id: Ic7a1ce6b367999e81ce5c8c9e7d4bd5d22b9229d
---
M includes/SF_PageSchemas.php
M languages/SF_Messages.php
2 files changed, 88 insertions(+), 25 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms
refs/changes/56/79556/1
diff --git a/includes/SF_PageSchemas.php b/includes/SF_PageSchemas.php
index b3b1f2f..a220b2a 100644
--- a/includes/SF_PageSchemas.php
+++ b/includes/SF_PageSchemas.php
@@ -58,7 +58,7 @@
}
}
}
- if ( $tagName == "semanticforms_FormInput" ) {
+ if ( $tagName == "semanticforms_FormInput" || $tagName ==
"semanticforms_PageSection" ) {
foreach ( $xml->children() as $tag => $child ) {
if ( $tag == $tagName ) {
foreach ( $child->children() as $prop )
{
@@ -69,8 +69,8 @@
$sfarray[$prop->getName()] = (string)$prop;
} else {
$sfarray[(string)$prop->attributes()->name] = (string)$prop;
+ }
}
- }
}
return $sfarray;
}
@@ -216,30 +216,60 @@
}
} elseif ( substr( $var, 0, 14 ) == 'sf_key_values_' ) {
- if ( $val !== '' ) {
- // replace the comma substitution
character that has no chance of
- // being included in the values list -
namely, the ASCII beep
- $listSeparator = ',';
- $key_values_str = str_replace(
"\\$listSeparator", "\a", $val );
- $key_values_array = explode(
$listSeparator, $key_values_str );
- foreach ( $key_values_array as $value )
{
- // replace beep back with
comma, trim
- $value = str_replace( "\a",
$listSeparator, trim( $value ) );
- $param_value = explode( "=",
$value, 2 );
- if ( count( $param_value ) == 2
&& $param_value[1] != null ) {
- // Handles <Parameter
name="size">20</Parameter>
- $xml .= '<Parameter
name="' . $param_value[0] . '">' . $param_value[1] . '</Parameter>';
- } else {
- // Handles <Parameter
name="mandatory" />
- $xml .= '<Parameter
name="' . $param_value[0] . '"/>';
- }
- }
- }
+ $xml .= self::createFormInputXMLFromForm( $val
);
$xml .= '</semanticforms_FormInput>';
$xmlPerField[$fieldNum] = $xml;
}
}
return $xmlPerField;
+ }
+
+ /**
+ * Creates Page Schemas XML for page sections
+ */
+ public static function createPageSectionXMLFromForm() {
+ global $wgRequest;
+ $xmlPerPageSection = array();
+ $pageSectionNum = -1;
+
+ foreach ( $wgRequest->getValues() as $var => $val ) {
+ $val = str_replace( array( '<', '>' ), array( '<',
'>' ), $val );
+ if ( substr( $var, 0, 26 ) ==
'sf_pagesection_key_values_' ) {
+ $pageSectionNum = substr( $var, 26 );
+ $xml = "";
+ if ( $val != '' ) {
+ $xml = '<semanticforms_PageSection>';
+ $xml .=
self::createFormInputXMLFromForm( $val );
+ $xml .= '</semanticforms_PageSection>';
+ }
+ $xmlPerPageSection[$pageSectionNum] = $xml;
+ }
+ }
+ return $xmlPerPageSection;
+ }
+
+ static function createFormInputXMLFromForm( $valueFromForm ) {
+ $xml = '';
+ if ( $valueFromForm !== '' ) {
+ // replace the comma substitution character that has no
chance of
+ // being included in the values list - namely, the
ASCII beep
+ $listSeparator = ',';
+ $key_values_str = str_replace( "\\$listSeparator",
"\a", $valueFromForm );
+ $key_values_array = explode( $listSeparator,
$key_values_str );
+ foreach ( $key_values_array as $value ) {
+ // replace beep back with comma, trim
+ $value = str_replace( "\a", $listSeparator,
trim( $value ) );
+ $param_value = explode( "=", $value, 2 );
+ if ( count( $param_value ) == 2 &&
$param_value[1] != null ) {
+ // Handles <Parameter
name="size">20</Parameter>
+ $xml .= '<Parameter name="' .
$param_value[0] . '">' . $param_value[1] . '</Parameter>';
+ } else {
+ // Handles <Parameter name="mandatory"
/>
+ $xml .= '<Parameter name="' .
$param_value[0] . '"/>';
+ }
+ }
+ }
+ return $xml;
}
public static function getDisplayColor() {
@@ -429,7 +459,7 @@
$text .= "\t<p>Enter field
<b>description</b>:</p>\t<p>$inputDescription<br>$inputDescriptionTooltipMode
Show description as pop-up tooltip</p>\n";
// @todo FIXME: i18n issue: Hard coded text.
- $text .= "\t" . '<p>Enter parameter names and their values as
key=value pairs, separated by commas (if a value contains a comma, replace it
with "\,"). For example: size=20, mandatory</p>' . "\n";
+ $text .= "\t" . '<p>' . wfMessage( 'sf-pageschemas-otherparams'
)->escaped() . '</p>' . "\n";
$paramValues = array();
foreach ( $fieldValues as $param => $value ) {
if ( !empty( $param ) && $param != 'InputType' &&
$param != 'Description' && $param != 'DescriptionTooltipMode' && $param !=
'TextBeforeField' ) {
@@ -448,6 +478,33 @@
$inputParamsInput = Html::input( 'sf_key_values_num',
$param_value_str, 'text', $inputParamsAttrs );
$text .= "\t<p>$inputParamsInput</p>\n";
return array( $text, $hasExistingValues );
+ }
+
+ public static function getPageSectionEditingHTML( $psPageSection ) {
+ $otherParams = array();
+
+ if ( !is_null( $psPageSection ) ) {
+ $otherParams = $psPageSection->getObject(
'semanticforms_PageSection' );
+ }
+ $paramValues = array();
+ foreach ( $otherParams as $param => $value ) {
+ if ( !empty( $param ) ) {
+ if ( !empty( $value ) ) {
+ $paramValues[] = $param . '=' . $value;
+ } else {
+ $paramValues[] = $param;
+ }
+ }
+ }
+ foreach ( $paramValues as $i => $paramAndVal ) {
+ $paramValues[$i] = str_replace( ',', '\,', $paramAndVal
);
+ }
+ $param_value_str = implode( ', ', $paramValues );
+ $text = "\t" . '<p>' . wfMessage( 'sf-pageschemas-otherparams'
)->escaped() . '</p>' . "\n";
+ $inputParamsInput = Html::input(
'sf_pagesection_key_values_num', $param_value_str, 'text', array( 'size' => 80
) );
+ $text .= "\t<p>$inputParamsInput</p>\n";
+
+ return $text;
}
public static function getFormName( $pageSchemaObj ) {
@@ -785,12 +842,16 @@
return 'Form input';
}
+ public static function getSectionDisplayString() {
+ return wfMsg( 'ps-otherparams' );
+ }
+
/**
* Displays data on a single form input in the Page Schemas XML.
*/
- public static function getFieldDisplayValues( $fieldXML ) {
- foreach ( $fieldXML->children() as $tag => $child ) {
- if ( $tag == "semanticforms_FormInput" ) {
+ public static function getParameterDisplayValues( $inputXML ) {
+ foreach ( $inputXML->children() as $tag => $child ) {
+ if ( $tag == "semanticforms_FormInput" || $tag ==
"semanticforms_PageSection" ) {
$inputName = $child->attributes()->name;
$values = array();
foreach ( $child->children() as $prop ) {
diff --git a/languages/SF_Messages.php b/languages/SF_Messages.php
index 0a2bb2b..c048a0c 100644
--- a/languages/SF_Messages.php
+++ b/languages/SF_Messages.php
@@ -195,6 +195,7 @@
'sf-pageschemas-createtitle' => 'Title of form for new pages:',
'sf-pageschemas-edittitle' => 'Title of form for existing
pages:',
'sf-pageschemas-inputtype' => 'Input type (leave blank to set
to default):',
+ 'sf-pageschemas-otherparams' => 'Enter parameter names and
their values as key=value pairs, separated by commas (if a value contains a
comma, replace it with "\,"). For example: size=20, mandatory',
// content messages
'sf_property_isproperty' => 'This is a property of type
$1.',
@@ -449,6 +450,7 @@
'action-createclass' => '{{doc-action|createclass}}',
'action-editrestrictedfields' => '{{doc-action|editrestrictedfields}}',
'action-viewedittab' => '{{doc-action|viewedittab}}',
+ 'sf-pageschemas-otherparams' => 'Used as label for "Form inputs" and
"Other parameters" input boxes',
);
/** Afrikaans (Afrikaans)
--
To view, visit https://gerrit.wikimedia.org/r/79556
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7a1ce6b367999e81ce5c8c9e7d4bd5d22b9229d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Himeshi <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits