Index: trunk/extensions/SemanticForms/specials/SF_CreateProperty.php |
— | — | @@ -20,10 +20,10 @@ |
21 | 21 | |
22 | 22 | function execute( $query ) { |
23 | 23 | $this->setHeaders(); |
24 | | - doSpecialCreateProperty(); |
| 24 | + self::printCreatePropertyForm(); |
25 | 25 | } |
26 | 26 | |
27 | | - function createPropertyText( $property_type, $default_form, $allowed_values_str ) { |
| 27 | + static function createPropertyText( $property_type, $default_form, $allowed_values_str ) { |
28 | 28 | global $smwgContLang; |
29 | 29 | $prop_labels = $smwgContLang->getPropertyLabels(); |
30 | 30 | $type_tag = "[[{$prop_labels['_TYPE']}::$property_type]]"; |
— | — | @@ -56,44 +56,42 @@ |
57 | 57 | return $text; |
58 | 58 | } |
59 | 59 | |
60 | | -} |
| 60 | + static function printCreatePropertyForm() { |
| 61 | + global $wgOut, $wgRequest, $sfgScriptPath; |
| 62 | + global $smwgContLang; |
61 | 63 | |
62 | | -function doSpecialCreateProperty() { |
63 | | - global $wgOut, $wgRequest, $sfgScriptPath; |
64 | | - global $smwgContLang; |
| 64 | + SFUtils::loadMessages(); |
65 | 65 | |
66 | | - SFUtils::loadMessages(); |
| 66 | + # cycle through the query values, setting the appropriate local variables |
| 67 | + $property_name = $wgRequest->getVal( 'property_name' ); |
| 68 | + $property_type = $wgRequest->getVal( 'property_type' ); |
| 69 | + $default_form = $wgRequest->getVal( 'default_form' ); |
| 70 | + $allowed_values = $wgRequest->getVal( 'values' ); |
67 | 71 | |
68 | | - # cycle through the query values, setting the appropriate local variables |
69 | | - $property_name = $wgRequest->getVal( 'property_name' ); |
70 | | - $property_type = $wgRequest->getVal( 'property_type' ); |
71 | | - $default_form = $wgRequest->getVal( 'default_form' ); |
72 | | - $allowed_values = $wgRequest->getVal( 'values' ); |
| 72 | + $save_button_text = wfMsg( 'savearticle' ); |
| 73 | + $preview_button_text = wfMsg( 'preview' ); |
73 | 74 | |
74 | | - $save_button_text = wfMsg( 'savearticle' ); |
75 | | - $preview_button_text = wfMsg( 'preview' ); |
76 | | - |
77 | | - $property_name_error_str = ''; |
78 | | - $save_page = $wgRequest->getCheck( 'wpSave' ); |
79 | | - $preview_page = $wgRequest->getCheck( 'wpPreview' ); |
80 | | - if ( $save_page || $preview_page ) { |
81 | | - # validate property name |
82 | | - if ( $property_name == '' ) { |
83 | | - $property_name_error_str = wfMsg( 'sf_blank_error' ); |
84 | | - } else { |
85 | | - # redirect to wiki interface |
86 | | - $wgOut->setArticleBodyOnly( true ); |
87 | | - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $property_name ); |
88 | | - $full_text = SFCreateProperty::createPropertyText( $property_type, $default_form, $allowed_values ); |
89 | | - $text = SFUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false, null, null ); |
90 | | - $wgOut->addHTML( $text ); |
91 | | - return; |
| 75 | + $property_name_error_str = ''; |
| 76 | + $save_page = $wgRequest->getCheck( 'wpSave' ); |
| 77 | + $preview_page = $wgRequest->getCheck( 'wpPreview' ); |
| 78 | + if ( $save_page || $preview_page ) { |
| 79 | + # validate property name |
| 80 | + if ( $property_name == '' ) { |
| 81 | + $property_name_error_str = wfMsg( 'sf_blank_error' ); |
| 82 | + } else { |
| 83 | + # redirect to wiki interface |
| 84 | + $wgOut->setArticleBodyOnly( true ); |
| 85 | + $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $property_name ); |
| 86 | + $full_text = self::createPropertyText( $property_type, $default_form, $allowed_values ); |
| 87 | + $text = SFUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false, null, null ); |
| 88 | + $wgOut->addHTML( $text ); |
| 89 | + return; |
| 90 | + } |
92 | 91 | } |
93 | | - } |
94 | 92 | |
95 | | - $datatype_labels = $smwgContLang->getDatatypeLabels(); |
| 93 | + $datatype_labels = $smwgContLang->getDatatypeLabels(); |
96 | 94 | |
97 | | - $javascript_text = <<<END |
| 95 | + $javascript_text = <<<END |
98 | 96 | function toggleDefaultForm(property_type) { |
99 | 97 | var default_form_div = document.getElementById("default_form_div"); |
100 | 98 | if (property_type == '{$datatype_labels['_wpg']}') { |
— | — | @@ -105,28 +103,28 @@ |
106 | 104 | |
107 | 105 | END; |
108 | 106 | |
109 | | - // set 'title' as hidden field, in case there's no URL niceness |
110 | | - global $wgContLang; |
111 | | - $mw_namespace_labels = $wgContLang->getNamespaces(); |
112 | | - $special_namespace = $mw_namespace_labels[NS_SPECIAL]; |
113 | | - $name_label = wfMsg( 'sf_createproperty_propname' ); |
114 | | - $type_label = wfMsg( 'sf_createproperty_proptype' ); |
115 | | - $text = <<<END |
| 107 | + // set 'title' as hidden field, in case there's no URL niceness |
| 108 | + global $wgContLang; |
| 109 | + $mw_namespace_labels = $wgContLang->getNamespaces(); |
| 110 | + $special_namespace = $mw_namespace_labels[NS_SPECIAL]; |
| 111 | + $name_label = wfMsg( 'sf_createproperty_propname' ); |
| 112 | + $type_label = wfMsg( 'sf_createproperty_proptype' ); |
| 113 | + $text = <<<END |
116 | 114 | <form action="" method="post"> |
117 | 115 | <input type="hidden" name="title" value="$special_namespace:CreateProperty"> |
118 | 116 | <p>$name_label <input size="25" name="property_name" value=""> |
119 | 117 | <span style="color: red;">$property_name_error_str</span> |
120 | 118 | $type_label |
121 | 119 | END; |
122 | | - $select_body = ""; |
123 | | - foreach ( $datatype_labels as $label ) { |
124 | | - $select_body .= " " . Xml::element( 'option', null, $label ) . "\n"; |
125 | | - } |
126 | | - $text .= Xml::tags( 'select', array( 'id' => 'property_dropdown', 'name' => 'property_type', 'onChange' => 'toggleDefaultForm(this.value);' ), $select_body ) . "\n"; |
| 120 | + $select_body = ""; |
| 121 | + foreach ( $datatype_labels as $label ) { |
| 122 | + $select_body .= " " . Xml::element( 'option', null, $label ) . "\n"; |
| 123 | + } |
| 124 | + $text .= Xml::tags( 'select', array( 'id' => 'property_dropdown', 'name' => 'property_type', 'onChange' => 'toggleDefaultForm(this.value);' ), $select_body ) . "\n"; |
127 | 125 | |
128 | | - $default_form_input = wfMsg( 'sf_createproperty_linktoform' ); |
129 | | - $values_input = wfMsg( 'sf_createproperty_allowedvalsinput' ); |
130 | | - $text .= <<<END |
| 126 | + $default_form_input = wfMsg( 'sf_createproperty_linktoform' ); |
| 127 | + $values_input = wfMsg( 'sf_createproperty_allowedvalsinput' ); |
| 128 | + $text .= <<<END |
131 | 129 | <div id="default_form_div" style="padding: 5px 0 5px 0; margin: 7px 0 7px 0;"> |
132 | 130 | <p>$default_form_input |
133 | 131 | <input size="20" name="default_form" value="" /></p> |
— | — | @@ -137,12 +135,14 @@ |
138 | 136 | </div> |
139 | 137 | |
140 | 138 | END; |
141 | | - $edit_buttons = ' ' . Xml::element( 'input', array( 'id' => 'wpSave', 'type' => 'submit', 'name' => 'wpSave', 'value' => $save_button_text ) ); |
142 | | - $edit_buttons .= ' ' . Xml::element( 'input', array( 'id' => 'wpPreview', 'type' => 'submit', 'name' => 'wpPreview', 'value' => $preview_button_text ) ); |
143 | | - $text .= ' ' . Xml::tags( 'div', array( 'class' => 'editButtons' ), $edit_buttons ) . "\n"; |
144 | | - $text .= " </form>\n"; |
| 139 | + $edit_buttons = "\t" . Xml::element( 'input', array( 'id' => 'wpSave', 'type' => 'submit', 'name' => 'wpSave', 'value' => $save_button_text ) ); |
| 140 | + $edit_buttons .= "\t" . Xml::element( 'input', array( 'id' => 'wpPreview', 'type' => 'submit', 'name' => 'wpPreview', 'value' => $preview_button_text ) ); |
| 141 | + $text .= "\t" . Xml::tags( 'div', array( 'class' => 'editButtons' ), $edit_buttons ) . "\n"; |
| 142 | + $text .= "\t</form>\n"; |
145 | 143 | |
146 | | - $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); |
147 | | - $wgOut->addScript( '<script type="text/javascript">' . $javascript_text . '</script>' ); |
148 | | - $wgOut->addHTML( $text ); |
| 144 | + $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); |
| 145 | + $wgOut->addScript( '<script type="text/javascript">' . $javascript_text . '</script>' ); |
| 146 | + $wgOut->addHTML( $text ); |
| 147 | + } |
| 148 | + |
149 | 149 | } |