$templateHeader
END;
$text .= '{{' . $this->mTemplateName;
if ( count( $this->mTemplateFields ) > 0 ) {
$text .= "\n";
}
foreach ( $this->mTemplateFields as $field ) {
if ( $field->getFieldName() == '' ) {
continue;
}
$text .= "|" . $field->getFieldName() . "=\n";
}
if ( defined( 'CARGO_VERSION' ) && !defined( 'SMW_VERSION' ) && $this->mCargoTable != '' ) {
$cargoInUse = true;
$cargoDeclareCall = $this->createCargoDeclareCall() . "\n";
$cargoStoreCall = $this->createCargoStoreCall();
} else {
$cargoInUse = false;
$cargoDeclareCall = '';
$cargoStoreCall = '';
}
$templateFooter = wfMessage( 'pf_template_docufooter' )->inContentLanguage()->text();
$text .= <<
$templateFooter
$cargoDeclareCall$cargoStoreCall
END;
// Before text
$text .= $this->mTemplateStart;
// $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 ( $this->mConnectingProperty ) {
global $smwgDefaultStore;
if ( defined( 'SIO_VERSION' ) ) {
$useSubobject = false;
$internalObjText = '{{#set_internal:' . $this->mConnectingProperty;
} elseif ( $smwgDefaultStore == "SMWSQLStore3" ) {
$useSubobject = true;
$internalObjText = '{{#subobject:-|' . $this->mConnectingProperty . '={{PAGENAME}}';
}
}
$setText = '';
// Topmost part of table depends on format.
if ( !$this->mTemplateFormat ) {
$this->mTemplateFormat = 'standard';
}
if ( $this->mTemplateFormat == 'standard' ) {
$tableText = '{| class="wikitable"' . "\n";
} elseif ( $this->mTemplateFormat == 'infobox' ) {
// A CSS style can't be used, unfortunately, since most
// MediaWiki setups don't have an 'infobox' or
// comparable CSS class.
$tableText = <<{{PAGENAME}}
|-
END;
} else {
$tableText = '';
}
foreach ( $this->mTemplateFields as $i => $field ) {
if ( $field->getFieldName() == '' ) {
continue;
}
$fieldParam = '{{{' . $field->getFieldName() . '|}}}';
if ( is_null( $field->getNamespace() ) ) {
$fieldString = $fieldParam;
} else {
$fieldString = $field->getNamespace() . ':' . $fieldParam;
}
$separator = '';
$fieldLabel = $field->getLabel();
if ( $fieldLabel == '' ) {
$fieldLabel = $field->getFieldName();
}
$fieldDisplay = $field->getDisplay();
$fieldProperty = $field->getSemanticProperty();
$fieldIsList = $field->isList();
// Header/field label column
if ( is_null( $fieldDisplay ) ) {
if ( $this->mTemplateFormat == 'standard' || $this->mTemplateFormat == 'infobox' ) {
if ( $i > 0 ) {
$tableText .= "|-\n";
}
$tableText .= '! ' . $fieldLabel . "\n";
} elseif ( $this->mTemplateFormat == 'plain' ) {
$tableText .= "\n'''" . $fieldLabel . ":''' ";
} elseif ( $this->mTemplateFormat == 'sections' ) {
$tableText .= "\n==" . $fieldLabel . "==\n";
}
} elseif ( $fieldDisplay == 'nonempty' ) {
if ( $this->mTemplateFormat == 'plain' || $this->mTemplateFormat == 'sections' ) {
$tableText .= "\n";
}
$tableText .= '{{#if:' . $fieldParam . '|';
if ( $this->mTemplateFormat == 'standard' || $this->mTemplateFormat == 'infobox' ) {
if ( $i > 0 ) {
$tableText .= "\n{{!}}-\n";
}
$tableText .= '! ' . $fieldLabel . "\n";
$separator = '{{!}}';
} elseif ( $this->mTemplateFormat == 'plain' ) {
$tableText .= "'''" . $fieldLabel . ":''' ";
$separator = '';
} elseif ( $this->mTemplateFormat == 'sections' ) {
$tableText .= '==' . $fieldLabel . "==\n";
$separator = '';
}
} // If it's 'hidden', do nothing
// Value column
if ( $this->mTemplateFormat == 'standard' || $this->mTemplateFormat == 'infobox' ) {
if ( $fieldDisplay == 'hidden' ) {
} elseif ( $fieldDisplay == 'nonempty' ) {
// $tableText .= "{{!}} ";
} else {
$tableText .= "| ";
}
}
// If we're using Cargo, fields can simply be displayed
// normally - no need for any special tags - *unless*
// the field holds a list of Page value, in which case
// we need to apply #arraymap.
$isCargoListOfPages = $cargoInUse && $field->isList() && $field->getFieldType() == 'Page';
if ( !$fieldProperty && !$isCargoListOfPages ) {
if ( $separator != '' ) {
$tableText .= "$separator ";
}
$tableText .= $this->createTextForField( $field );
if ( $fieldDisplay == 'nonempty' ) {
$tableText .= " }}";
}
$tableText .= "\n";
} elseif ( !is_null( $internalObjText ) ) {
if ( $separator != '' ) {
$tableText .= "$separator ";
}
$tableText .= $this->createTextForField( $field );
if ( $fieldDisplay == 'nonempty' ) {
$tableText .= " }}";
}
$tableText .= "\n";
if ( $field->isList() ) {
if ( $useSubobject ) {
$internalObjText .= '|' . $fieldProperty . '=' . $fieldString . '|+sep=,';
} else {
$internalObjText .= '|' . $fieldProperty . '#list=' . $fieldString;
}
} else {
$internalObjText .= '|' . $fieldProperty . '=' . $fieldString;
}
} elseif ( $fieldDisplay == 'hidden' ) {
if ( $fieldIsList ) {
$setText .= $fieldProperty . '#list=' . $fieldString . '|';
} else {
$setText .= $fieldProperty . '=' . $fieldString . '|';
}
} elseif ( $fieldDisplay == 'nonempty' ) {
if ( $this->mTemplateFormat == 'standard' || $this->mTemplateFormat == 'infobox' ) {
$tableText .= '{{!}} ';
}
$tableText .= $this->createTextForField( $field ) . "\n";
} else {
$tableText .= $this->createTextForField( $field ) . "\n";
}
}
// Add an inline query to the output text, for
// aggregation, if a property was specified.
if ( !is_null( $this->mAggregatingProperty ) && $this->mAggregatingProperty !== '' ) {
if ( $this->mTemplateFormat == 'standard' || $this->mTemplateFormat == 'infobox' ) {
if ( count( $this->mTemplateFields ) > 0 ) {
$tableText .= "|-\n";
}
$tableText .= <<mAggregationLabel
|
END;
} elseif ( $this->mTemplateFormat == 'plain' ) {
$tableText .= "\n'''" . $this->mAggregationLabel . ":''' ";
} elseif ( $this->mTemplateFormat == 'sections' ) {
$tableText .= "\n==" . $this->mAggregationLabel . "==\n";
}
$tableText .= "{{#ask:[[" . $this->mAggregatingProperty . "::{{SUBJECTPAGENAME}}]]|format=list}}\n";
}
if ( $this->mTemplateFormat == 'standard' || $this->mTemplateFormat == 'infobox' ) {
$tableText .= "|}";
}
// 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( $internalObjText ) ) {
if ( $this->mTemplateFormat == 'standard' || $this->mTemplateFormat == 'infobox' ) {
$tableText .= "\n";
}
} else {
$internalObjText .= "}}";
$text .= $internalObjText;
}
// Add a call to #set, if necessary
if ( $setText !== '' ) {
$setText = '{{#set:' . $setText . "}}\n";
$text .= $setText;
}
$text .= $tableText;
if ( ( $this->mCategoryName !== '' ) && ( $this->mCategoryName !== null ) ) {
global $wgContLang;
$namespaceLabels = $wgContLang->getNamespaces();
$categoryNamespace = $namespaceLabels[NS_CATEGORY];
$text .= "\n[[$categoryNamespace:" . $this->mCategoryName . "]]\n";
}
// After text
$text .= $this->mTemplateEnd;
$text .= "\n";
return $text;
}
function createTextForField( $field ) {
$text = '';
$fieldStart = $this->mFieldStart;
Hooks::run( 'PageForms::TemplateFieldStart', array( $field, &$fieldStart ) );
if ( $fieldStart != '' ) {
$text .= "$fieldStart ";
}
$cargoInUse = defined( 'CARGO_VERSION' ) && !defined( 'SMW_VERSION' ) && $this->mCargoTable != '';
$text .= $field->createText( $cargoInUse );
$fieldEnd = $this->mFieldEnd;
Hooks::run( 'PageForms::TemplateFieldEnd', array( $field, &$fieldEnd ) );
if ( $fieldEnd != '' ) {
$text .= " $fieldEnd";
}
return $text;
}
}