http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82772
Revision: 82772
Author: yaron
Date: 2011-02-25 00:37:22 +0000 (Fri, 25 Feb 2011)
Log Message:
-----------
Turned doSpecialCreateTemplate() function into a class method,
printCreateTemplateForm(); replaced some hardcoded HTML with calls to the Xml
class
Modified Paths:
--------------
trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
Modified: trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
===================================================================
--- trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
2011-02-25 00:12:53 UTC (rev 82771)
+++ trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
2011-02-25 00:37:22 UTC (rev 82772)
@@ -24,7 +24,7 @@
public function execute( $query ) {
$this->setHeaders();
- doSpecialCreateTemplate();
+ self::printCreateTemplateForm();
}
public static function getAllPropertyNames() {
@@ -52,29 +52,32 @@
}
public static function printPropertiesDropdown( $all_properties, $id,
$selected_property ) {
- $dropdown_str = "<select name=\"semantic_property_$id\">\n";
- $dropdown_str .= "<option value=\"\"></option>\n";
-
+ $selectBody = "<option value=\"\"></option>\n";
foreach ( $all_properties as $prop_name ) {
- $selected = ( $selected_property == $prop_name ) ?
"selected" : "";
- $dropdown_str .= "<option value=\"$prop_name\"
$selected>$prop_name</option>\n";
+ $optionAttrs = array( 'value' => $prop_name );
+ if ( $selected_property == $prop_name ) {
$optionAttrs['selected'] = 'selected'; }
+ $selectBody .= Xml::element( 'option', $optionAttrs,
$prop_name ) . "\n";
}
-
- $dropdown_str .= "</select>\n";
-
- return $dropdown_str;
+ return Xml::tags( 'select', array( 'name' =>
"semantic_property_$id" ), $selectBody ) . "\n";
}
public static function printFieldEntryBox( $id, $f, $all_properties ) {
SFUtils::loadMessages();
- $dropdown_html = SFCreateTemplate::printPropertiesDropdown(
$all_properties, $id, $f->semantic_property );
- $text = ' <div class="fieldBox">' . "\n";
- $text .= ' <p>' . wfMsg( 'sf_createtemplate_fieldname' ) .
' <input size="15" name="name_' . $id . '" value="' . $f->field_name . '">' .
"\n";
- $text .= ' ' . wfMsg( 'sf_createtemplate_displaylabel' ) .
' <input size="15" name="label_' . $id . '" value="' . $f->label . '">' . "\n";
- $text .= ' ' . wfMsg( 'sf_createtemplate_semanticproperty'
) . ' ' . $dropdown_html . "</p>\n";
+ $text = "\t" . '<div class="fieldBox">' . "\n";
+ $text .= "\t<p>" . wfMsg( 'sf_createtemplate_fieldname' ) . ' '
.
+ Xml::element( 'input',
+ array( 'size' => '15', 'name' => 'name_' . $id,
'value' => $f->field_name ), null
+ ) . "\n";
+ $text .= "\t" . wfMsg( 'sf_createtemplate_displaylabel' ) . ' '
.
+ Xml::element( 'input',
+ array( 'size' => '15', 'name' => 'label_' .
$id, 'value' => $f->label ), null
+ ) . "\n";
+
+ $dropdown_html = self::printPropertiesDropdown(
$all_properties, $id, $f->semantic_property );
+ $text .= "\t" . wfMsg( 'sf_createtemplate_semanticproperty' ) .
' ' . $dropdown_html . "</p>\n";
$checked_str = ( $f->is_list ) ? " checked" : "";
- $text .= ' <p><input type="checkbox" name="is_list_' . $id
. '"' . $checked_str . '> ' . wfMsg( 'sf_createtemplate_fieldislist' ) . "\n";
+ $text .= "\t<p>" . '<input type="checkbox" name="is_list_' .
$id . '"' . $checked_str . '> ' . wfMsg( 'sf_createtemplate_fieldislist' ) .
"\n";
if ( $id != "new" ) {
$text .= '   <input name="del_' . $id .
'" type="submit" value="' . wfMsg( 'sf_createtemplate_deletefield' ) . '">' .
"\n";
@@ -87,94 +90,104 @@
END;
return $text;
}
-
-}
-function doSpecialCreateTemplate() {
- global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
+ static function printCreateTemplateForm() {
+ global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
- SFUtils::loadMessages();
+ SFUtils::loadMessages();
- $all_properties = SFCreateTemplate::getAllPropertyNames();
-
- $template_name = $wgRequest->getVal( 'template_name' );
- $template_name_error_str = "";
- $category = $wgRequest->getVal( 'category' );
- $cur_id = 1;
- $fields = array();
- # cycle through the query values, setting the appropriate local
variables
- foreach ( $wgRequest->getValues() as $var => $val ) {
- $var_elements = explode( "_", $var );
- // we only care about query variables of the form "a_b"
- if ( count( $var_elements ) != 2 )
- continue;
- list ( $field_field, $old_id ) = $var_elements;
- if ( $field_field == "name" ) {
- if ( $old_id != "new" || ( $old_id == "new" && $val !=
"" ) ) {
- if ( $wgRequest->getVal( 'del_' . $old_id ) !=
'' ) {
- # do nothing - this field won't get
added to the new list
- } else {
- $field = SFTemplateField::create( $val,
$wgRequest->getVal( 'label_' . $old_id ) );
- $field->semantic_property =
$wgRequest->getVal( 'semantic_property_' . $old_id );
- $field->is_list = $wgRequest->getCheck(
'is_list_' . $old_id );
- $fields[] = $field;
+ $all_properties = self::getAllPropertyNames();
+
+ $template_name = $wgRequest->getVal( 'template_name' );
+ $template_name_error_str = "";
+ $category = $wgRequest->getVal( 'category' );
+ $cur_id = 1;
+ $fields = array();
+ # cycle through the query values, setting the appropriate local
variables
+ foreach ( $wgRequest->getValues() as $var => $val ) {
+ $var_elements = explode( "_", $var );
+ // we only care about query variables of the form "a_b"
+ if ( count( $var_elements ) != 2 )
+ continue;
+ list ( $field_field, $old_id ) = $var_elements;
+ if ( $field_field == "name" ) {
+ if ( $old_id != "new" || ( $old_id == "new" &&
$val != "" ) ) {
+ if ( $wgRequest->getVal( 'del_' .
$old_id ) != '' ) {
+ // Do nothing - this field
won't get added to the new list
+ } else {
+ $field =
SFTemplateField::create( $val, $wgRequest->getVal( 'label_' . $old_id ) );
+ $field->semantic_property =
$wgRequest->getVal( 'semantic_property_' . $old_id );
+ $field->is_list =
$wgRequest->getCheck( 'is_list_' . $old_id );
+ $fields[] = $field;
+ }
}
}
}
- }
- $aggregating_property = $wgRequest->getVal(
'semantic_property_aggregation' );
- $aggregation_label = $wgRequest->getVal( 'aggregation_label' );
- $template_format = $wgRequest->getVal( 'template_format' );
+ $aggregating_property = $wgRequest->getVal(
'semantic_property_aggregation' );
+ $aggregation_label = $wgRequest->getVal( 'aggregation_label' );
+ $template_format = $wgRequest->getVal( 'template_format' );
- $text = "";
- $save_button_text = wfMsg( 'savearticle' );
- $preview_button_text = wfMsg( 'preview' );
- $save_page = $wgRequest->getCheck( 'wpSave' );
- $preview_page = $wgRequest->getCheck( 'wpPreview' );
- if ( $save_page || $preview_page ) {
- # validate template name
- if ( $template_name == '' ) {
- $template_name_error_str = wfMsg( 'sf_blank_error' );
- } else {
- // redirect to wiki interface
- $wgOut->setArticleBodyOnly( true );
- $title = Title::makeTitleSafe( NS_TEMPLATE,
$template_name );
- $full_text = SFTemplateField::createTemplateText(
$template_name, $fields, $category, $aggregating_property, $aggregation_label,
$template_format );
- $text = SFUtils::printRedirectForm( $title, $full_text,
"", $save_page, $preview_page, false, false, false, null, null );
- $wgOut->addHTML( $text );
- return;
+ $text = "";
+ $save_button_text = wfMsg( 'savearticle' );
+ $preview_button_text = wfMsg( 'preview' );
+ $save_page = $wgRequest->getCheck( 'wpSave' );
+ $preview_page = $wgRequest->getCheck( 'wpPreview' );
+ if ( $save_page || $preview_page ) {
+ # validate template name
+ if ( $template_name == '' ) {
+ $template_name_error_str = wfMsg(
'sf_blank_error' );
+ } else {
+ // redirect to wiki interface
+ $wgOut->setArticleBodyOnly( true );
+ $title = Title::makeTitleSafe( NS_TEMPLATE,
$template_name );
+ $full_text =
SFTemplateField::createTemplateText( $template_name, $fields, $category,
$aggregating_property, $aggregation_label, $template_format );
+ $text = SFUtils::printRedirectForm( $title,
$full_text, "", $save_page, $preview_page, false, false, false, null, null );
+ $wgOut->addHTML( $text );
+ return;
+ }
}
- }
- $text .= ' <form action="" method="post">' . "\n";
- // set 'title' field, in case there's no URL niceness
- $mw_namespace_labels = $wgContLang->getNamespaces();
- $special_namespace = $mw_namespace_labels[NS_SPECIAL];
- $text .= ' <input type="hidden" name="title" value="' .
$special_namespace . ':CreateTemplate">' . "\n";
- $text .= ' <p>' . wfMsg( 'sf_createtemplate_namelabel' ) . '
<input size="25" name="template_name" value="' . $template_name . '"> <font
color="red">' . $template_name_error_str . '</font></p>' . "\n";
- $text .= ' <p>' . wfMsg( 'sf_createtemplate_categorylabel' ) . '
<input size="25" name="category" value="' . $category . '"></p>' . "\n";
- $text .= " <fieldset>\n";
- $text .= ' ' . Xml::element( 'legend', null, wfMsg(
'sf_createtemplate_templatefields' ) ) . "\n";
- $text .= ' ' . Xml::element( 'p', null, wfMsg(
'sf_createtemplate_fieldsdesc' ) ) . "\n";
+ $text .= ' <form action="" method="post">' . "\n";
+ // set 'title' field, in case there's no URL niceness
+ $mw_namespace_labels = $wgContLang->getNamespaces();
+ $special_namespace = $mw_namespace_labels[NS_SPECIAL];
+ $text .= "\t" . '<input type="hidden" name="title" value="' .
$special_namespace . ':CreateTemplate">' . "\n";
+ $text .= "\t<p>" . wfMsg( 'sf_createtemplate_namelabel' ) . '
<input size="25" name="template_name" value="' . $template_name . '"> <font
color="red">' . $template_name_error_str . '</font></p>' . "\n";
+ $text .= "\t<p>" . wfMsg( 'sf_createtemplate_categorylabel' ) .
' <input size="25" name="category" value="' . $category . '"></p>' . "\n";
+ $text .= "\t<fieldset>\n";
+ $text .= "\t" . Xml::element( 'legend', null, wfMsg(
'sf_createtemplate_templatefields' ) ) . "\n";
+ $text .= "\t" . Xml::element( 'p', null, wfMsg(
'sf_createtemplate_fieldsdesc' ) ) . "\n";
- foreach ( $fields as $i => $field ) {
- $text .= SFCreateTemplate::printFieldEntryBox( $i + 1, $field,
$all_properties );
- }
- $new_field = new SFTemplateField();
- $text .= SFCreateTemplate::printFieldEntryBox( "new", $new_field,
$all_properties );
+ foreach ( $fields as $i => $field ) {
+ $text .= self::printFieldEntryBox( $i + 1, $field,
$all_properties );
+ }
+ $new_field = new SFTemplateField();
+ $text .= self::printFieldEntryBox( "new", $new_field,
$all_properties );
- $text .= ' <p><input type="submit" value="' . wfMsg(
'sf_createtemplate_addfield' ) . '"></p>' . "\n";
- $text .= " </fieldset>\n";
- $text .= " <fieldset>\n";
- $text .= ' ' . Xml::element( 'legend', null, wfMsg(
'sf_createtemplate_aggregation' ) ) . "\n";
- $text .= ' ' . Xml::element( 'p', null, wfMsg(
'sf_createtemplate_aggregationdesc' ) ) . "\n";
- $text .= ' <p>' . wfMsg( 'sf_createtemplate_semanticproperty' ) .
" " . SFCreateTemplate::printPropertiesDropdown( $all_properties,
"aggregation", $aggregating_property ) . "</p>\n";
- $text .= ' <p>' . wfMsg( 'sf_createtemplate_aggregationlabel' ) .
' <input size="25" name="aggregation_label" value="' . $aggregation_label .
'"></p>' . "\n";
- $text .= " </fieldset>\n";
- $text .= ' <p>' . wfMsg( 'sf_createtemplate_outputformat' ) . "\n";
- $text .= ' <input type="radio" name="template_format" checked
value="standard" />' . wfMsg( 'sf_createtemplate_standardformat' ) . "\n";
- $text .= ' <input type="radio" name="template_format"
value="infobox" />' . wfMsg( 'sf_createtemplate_infoboxformat' ) . "</p>\n";
- $text .= <<<END
+ $text .= "\t<p>" . Xml::element( 'input',
+ array( 'type' => 'submit', 'value' => wfMsg(
'sf_createtemplate_addfield' ) ), null ) . "</p>\n";
+ $text .= "\t</fieldset>\n";
+ $text .= "\t<fieldset>\n";
+ $text .= "\t" . Xml::element( 'legend', null, wfMsg(
'sf_createtemplate_aggregation' ) ) . "\n";
+ $text .= "\t" . Xml::element( 'p', null, wfMsg(
'sf_createtemplate_aggregationdesc' ) ) . "\n";
+ $text .= "\t<p>" . wfMsg( 'sf_createtemplate_semanticproperty'
) . ' ' .
+ self::printPropertiesDropdown( $all_properties,
"aggregation", $aggregating_property ) . "</p>\n";
+ $text .= "\t<p>" . wfMsg( 'sf_createtemplate_aggregationlabel'
) . ' ' .
+ Xml::element( 'input',
+ array( 'size' => '25', 'name' => 'aggregation_label',
'value' => $aggregation_label ), null ) .
+ "</p>\n";
+ $text .= "\t</fieldset>\n";
+ $text .= "\t<p>" . wfMsg( 'sf_createtemplate_outputformat' ) .
"\n";
+ $text .= "\t" . Xml::element( 'input', array(
+ 'type' => 'radio',
+ 'name' => 'template_format',
+ 'checked' => 'checked',
+ 'value' => 'standard'
+ ), null ) . ' ' . wfMsg( 'sf_createtemplate_standardformat' ) .
"\n";
+ $text .= "\t" . Xml::element( 'input',
+ array( 'type' => 'radio', 'name' => 'template_format',
'value' => 'infobox'), null ) .
+ ' ' . wfMsg( 'sf_createtemplate_infoboxformat' ) .
"</p>\n";
+ $text .= <<<END
<div class="editButtons">
<input type="submit" id="wpSave" name="wpSave"
value="$save_button_text" />
<input type="submit" id="wpPreview" name="wpPreview"
value="$preview_button_text" />
@@ -182,11 +195,13 @@
</form>
END;
- $sk = $wgUser->getSkin();
- $create_property_link = SFUtils::linkForSpecialPage( $sk,
'CreateProperty' );
- $text .= " <br /><hr /><br />\n";
- $text .= " " . Xml::tags( 'p', null, $create_property_link . '.' )
. "\n";
+ $sk = $wgUser->getSkin();
+ $create_property_link = SFUtils::linkForSpecialPage( $sk,
'CreateProperty' );
+ $text .= "\t<br /><hr /><br />\n";
+ $text .= "\t" . Xml::tags( 'p', null, $create_property_link .
'.' ) . "\n";
- $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css"
);
- $wgOut->addHTML( $text );
+ $wgOut->addExtensionStyle( $sfgScriptPath .
"/skins/SemanticForms.css" );
+ $wgOut->addHTML( $text );
+ }
+
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs