r82750 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82749‎ | r82750 | r82751 >
Date:22:51, 24 February 2011
Author:yaron
Status:deferred
Tags:
Comment:
Changed doSpecialCreateProperty to a class method, printCreatePropertyForm(); also fixed static declarations for mehotds
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_CreateProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateProperty.php
@@ -20,10 +20,10 @@
2121
2222 function execute( $query ) {
2323 $this->setHeaders();
24 - doSpecialCreateProperty();
 24+ self::printCreatePropertyForm();
2525 }
2626
27 - function createPropertyText( $property_type, $default_form, $allowed_values_str ) {
 27+ static function createPropertyText( $property_type, $default_form, $allowed_values_str ) {
2828 global $smwgContLang;
2929 $prop_labels = $smwgContLang->getPropertyLabels();
3030 $type_tag = "[[{$prop_labels['_TYPE']}::$property_type]]";
@@ -56,44 +56,42 @@
5757 return $text;
5858 }
5959
60 -}
 60+ static function printCreatePropertyForm() {
 61+ global $wgOut, $wgRequest, $sfgScriptPath;
 62+ global $smwgContLang;
6163
62 -function doSpecialCreateProperty() {
63 - global $wgOut, $wgRequest, $sfgScriptPath;
64 - global $smwgContLang;
 64+ SFUtils::loadMessages();
6565
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' );
6771
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' );
7374
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+ }
9291 }
93 - }
9492
95 - $datatype_labels = $smwgContLang->getDatatypeLabels();
 93+ $datatype_labels = $smwgContLang->getDatatypeLabels();
9694
97 - $javascript_text = <<<END
 95+ $javascript_text = <<<END
9896 function toggleDefaultForm(property_type) {
9997 var default_form_div = document.getElementById("default_form_div");
10098 if (property_type == '{$datatype_labels['_wpg']}') {
@@ -105,28 +103,28 @@
106104
107105 END;
108106
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
116114 <form action="" method="post">
117115 <input type="hidden" name="title" value="$special_namespace:CreateProperty">
118116 <p>$name_label <input size="25" name="property_name" value="">
119117 <span style="color: red;">$property_name_error_str</span>
120118 $type_label
121119 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";
127125
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
131129 <div id="default_form_div" style="padding: 5px 0 5px 0; margin: 7px 0 7px 0;">
132130 <p>$default_form_input
133131 <input size="20" name="default_form" value="" /></p>
@@ -137,12 +135,14 @@
138136 </div>
139137
140138 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";
145143
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+
149149 }