Yaron Koren has uploaded a new change for review.
https://gerrit.wikimedia.org/r/93805
Change subject: Added ability to add #subobject to templates
......................................................................
Added ability to add #subobject to templates
Change-Id: Iead8952994b6fc1ab1d962ee6108857dd95c0568
---
M includes/SF_TemplateField.php
M specials/SF_CreateClass.php
2 files changed, 40 insertions(+), 22 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms
refs/changes/05/93805/1
diff --git a/includes/SF_TemplateField.php b/includes/SF_TemplateField.php
index 09f2d47..d17e42c 100644
--- a/includes/SF_TemplateField.php
+++ b/includes/SF_TemplateField.php
@@ -194,12 +194,22 @@
$text .= $template_options['beforeText']."\n";
}
- // Only add a call to #set_internal if the Semantic Internal
- // Objects extension is also installed.
- if ( $internal_obj_property && defined( 'SIO_VERSION' ) ) {
- $setInternalText = '{{#set_internal:' .
$internal_obj_property;
- } else {
- $setInternalText = null;
+ // $internalObjText can be either a call to #set_internal
+ // or to #subobject (or null); which one we go with
+ // depends on whether Semantic Internal Objects is installed,
+ // and on the SMW version.
+ // Thankfully, the syntaxes of #set_internal and #subobject
+ // are quite similar, so we don't need too much extra logic.
+ $internalObjText = null;
+ if ( $internal_obj_property ) {
+ global $smwgDefaultStore;
+ if ( defined( 'SIO_VERSION' ) ) {
+ $useSubobject = false;
+ $internalObjText = '{{#set_internal:' .
$internal_obj_property;
+ } elseif ( $smwgDefaultStore == "SMWSQLStore3" ) {
+ $useSubobject = true;
+ $internalObjText = '{{#subobject:-|' .
$internal_obj_property . '={{PAGENAME}}';
+ }
}
$setText = '';
@@ -283,12 +293,16 @@
$tableText .= " }}";
}
$tableText .= "\n";
- } elseif ( !is_null( $setInternalText ) ) {
+ } elseif ( !is_null( $internalObjText ) ) {
$tableText .= "$separator $fieldBefore {{{" .
$field->mFieldName . "|}}} $fieldAfter\n";
if ( $field->mIsList ) {
- $setInternalText .= '|' .
$field->mSemanticProperty . '#list={{{' . $field->mFieldName . '|}}}';
+ if ( $useSubobject ) {
+ $internalObjText .= '|' .
$field->mSemanticProperty . '={{{' . $field->mFieldName . '|}}}|+sep=,';
+ } else {
+ $internalObjText .= '|' .
$field->mSemanticProperty . '#list={{{' . $field->mFieldName . '|}}}';
+ }
} else {
- $setInternalText .= '|' .
$field->mSemanticProperty . '={{{' . $field->mFieldName . '|}}}';
+ $internalObjText .= '|' .
$field->mSemanticProperty . '={{{' . $field->mFieldName . '|}}}';
}
} elseif ( $field->mDisplay == 'hidden' ) {
if ( $field->mIsList ) {
@@ -345,13 +359,13 @@
// Leave out newlines if there's an internal property
// set here (which would mean that there are meant to be
// multiple instances of this template.)
- if ( is_null( $setInternalText ) ) {
+ if ( is_null( $internalObjText ) ) {
if ( $template_format == 'standard' || $template_format
== 'infobox' ) {
$tableText .= "\n";
}
} else {
- $setInternalText .= "}}";
- $text .= $setInternalText;
+ $internalObjText .= "}}";
+ $text .= $internalObjText;
}
// Add a call to #set, if necessary
diff --git a/specials/SF_CreateClass.php b/specials/SF_CreateClass.php
index ceddf15..5d3ba7f 100644
--- a/specials/SF_CreateClass.php
+++ b/specials/SF_CreateClass.php
@@ -123,16 +123,16 @@
$full_text = SFTemplateField::createTemplateText(
$template_name, $fields, $connecting_property, $category_name, null, null,
$template_format );
$template_title = Title::makeTitleSafe( NS_TEMPLATE,
$template_name );
$edit_summary = '';
- if ( method_exists( 'WikiPage', 'doEditContent' ) ) {
+ if ( method_exists( 'WikiPage', 'doEditContent' ) ) {
// MW 1.21+
- $template_page = new WikiPage( $template_title );
- $content = new WikitextContent( $full_text );
- $template_page->doEditContent( $content, $edit_summary
);
- } else {
+ $template_page = new WikiPage( $template_title );
+ $content = new WikitextContent( $full_text );
+ $template_page->doEditContent( $content, $edit_summary
);
+ } else {
// MW <= 1.20
- $template_article = new Article( $template_title );
- $template_article->doEdit( $full_text, $edit_summary );
- }
+ $template_article = new Article( $template_title );
+ $template_article->doEdit( $full_text, $edit_summary );
+ }
// Create the form, and make a job for it.
if ( $form_name != '' ) {
@@ -216,13 +216,17 @@
'id' => 'template_multiple',
'onclick' => "disableFormAndCategoryInputs()",
) ) . ' ' . wfMessage(
'sf_createtemplate_multipleinstance' )->text() ) . "\n";
- if ( defined( 'SIO_VERSION' ) ) {
+ // Either #set_internal or #subobject will be added to the
+ // template, depending on whether Semantic Internal Objects is
+ // installed.
+ global $smwgDefaultStore;
+ if ( defined( 'SIO_VERSION' ) || $smwgDefaultStore ==
"SMWSQLStore3" ) {
$templateInfo .= Html::rawElement( 'div',
array (
'id' => 'connecting_property_div',
'style' => 'display: none;',
),
- wfMessage(
'semanticinternalobjects-mainpropertyname' )->text() . "\n" .
+ wfMessage(
'sf_createtemplate_connectingproperty' )->text() . "\n" .
Html::element( 'input', array(
'type' => 'text',
'name' => 'connecting_property',
--
To view, visit https://gerrit.wikimedia.org/r/93805
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iead8952994b6fc1ab1d962ee6108857dd95c0568
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits