r89259 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89258‎ | r89259 | r89260 >
Date:13:53, 1 June 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added handling for SMW 1.6; changed TemplateField's field_type and field_type_id to property_type; some formatting improvements for code and comments
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -71,9 +71,15 @@
7272 $defaultProperties = call_user_func( array( $inputTypeClass, 'getDefaultPropTypes' ) );
7373 foreach ( $defaultProperties as $propertyTypeID => $additionalValues ) {
7474 if ( $smwgContLang != null ) {
75 - $datatypeLabels = $smwgContLang->getDatatypeLabels();
76 - $datatypeLabels['enumeration'] = 'enumeration';
77 - $propertyType = $datatypeLabels[$propertyTypeID];
 75+ if ( class_exists( 'SMWDIProperty' ) ) {
 76+ // For SMW 1.6+, we use the ID of each
 77+ // property, instead of its label.
 78+ $propertyType = $propertyTypeID;
 79+ } else {
 80+ $datatypeLabels = $smwgContLang->getDatatypeLabels();
 81+ $datatypeLabels['enumeration'] = 'enumeration';
 82+ $propertyType = $datatypeLabels[$propertyTypeID];
 83+ }
7884 $this->setSemanticTypeHook( $propertyType, false, array( $inputTypeClass, 'getHTML' ), $additionalValues );
7985 }
8086 $this->mDefaultInputForPropType[$propertyTypeID] = $inputTypeName;
@@ -81,9 +87,15 @@
8288 $defaultPropertyLists = call_user_func( array( $inputTypeClass, 'getDefaultPropTypeLists' ) );
8389 foreach ( $defaultPropertyLists as $propertyTypeID => $additionalValues ) {
8490 if ( $smwgContLang != null ) {
85 - $datatypeLabels = $smwgContLang->getDatatypeLabels();
86 - $datatypeLabels['enumeration'] = 'enumeration';
87 - $propertyType = $datatypeLabels[$propertyTypeID];
 91+ if ( class_exists( 'SMWDIProperty' ) ) {
 92+ // For SMW 1.6+, we use the ID of each
 93+ // property, instead of its label.
 94+ $propertyType = $propertyTypeID;
 95+ } else {
 96+ $datatypeLabels = $smwgContLang->getDatatypeLabels();
 97+ $datatypeLabels['enumeration'] = 'enumeration';
 98+ $propertyType = $datatypeLabels[$propertyTypeID];
 99+ }
88100 $this->setSemanticTypeHook( $propertyType, true, array( $inputTypeClass, 'getHTML' ), $additionalValues );
89101 }
90102 $this->mDefaultInputForPropTypeList[$propertyTypeID] = $inputTypeName;
@@ -159,9 +171,10 @@
160172
161173 /**
162174 * Show the set of previous deletions for the page being added.
163 - * This function is copied almost exactly from EditPage::showDeletionLog() -
164 - * unfortunately, neither that function nor Article::showDeletionLog() can
165 - * be called from here, since they're both protected
 175+ * This function is copied almost exactly from
 176+ * EditPage::showDeletionLog() - unfortunately, neither that function
 177+ * nor Article::showDeletionLog() can be called from here, since
 178+ * they're both protected.
166179 */
167180 function showDeletionLog( $out ) {
168181 // if MW doesn't have LogEventsList defined, exit immediately
@@ -202,8 +215,8 @@
203216 }
204217
205218 /**
206 - * Like PHP's str_replace(), but only replaces the first found instance -
207 - * unfortunately, str_replace() doesn't allow for that.
 219+ * Like PHP's str_replace(), but only replaces the first found
 220+ * instance - unfortunately, str_replace() doesn't allow for that.
208221 * This code is basically copied directly from
209222 * http://www.php.net/manual/en/function.str-replace.php#86177
210223 * - this might make sense in the SFUtils class, if it's useful in
@@ -253,8 +266,8 @@
254267 * This function is the real heart of the entire Semantic Forms
255268 * extension. It handles two main actions: (1) displaying a form on the
256269 * screen, given a form definition and possibly page contents (if an
257 - * existing page is being edited); and (2) creating actual page contents,
258 - * if the form was already submitted by the user.
 270+ * existing page is being edited); and (2) creating actual page
 271+ * contents, if the form was already submitted by the user.
259272 *
260273 * It also does some related tasks, like figuring out the page name (if
261274 * only a page formula exists).
@@ -285,10 +298,10 @@
286299 // If we have existing content and we're not in an active replacement
287300 // situation, preserve the original content. We do this because we want
288301 // to pass the original content on IF this is a partial form.
289 - // TODO: A better approach here would be to pass the revision id of the
 302+ // TODO: A better approach here would be to pass the revision ID of the
290303 // existing page content through the replace value, which would
291304 // minimize the html traffic and would allow us to do a concurrent
292 - // update check. For now, we pass it through the hidden text field...
 305+ // update check. For now, we pass it through a hidden text field.
293306
294307 if ( ! $wgRequest->getCheck( 'partial' ) ) {
295308 $original_page_content = $existing_page_content;
@@ -300,14 +313,14 @@
301314 }
302315 }
303316
304 - // Disable all form elements if user doesn't have edit permission -
305 - // two different checks are needed, because editing permissions can be
306 - // set in different ways.
307 - // HACK - sometimes we don't know the page name in advance, but we still
308 - // need to set a title here for testing permissions
 317+ // Disable all form elements if user doesn't have edit
 318+ // permission - two different checks are needed, because
 319+ // editing permissions can be set in different ways.
 320+ // HACK - sometimes we don't know the page name in advance, but
 321+ // we still need to set a title here for testing permissions.
309322 if ( $embedded ) {
310 - // if this is an embedded form (probably a 'RunQuery'), just use the
311 - // name of the actual page we're on
 323+ // If this is an embedded form (probably a 'RunQuery'),
 324+ // just use the name of the actual page we're on.
312325 global $wgTitle;
313326 $this->mPageTitle = $wgTitle;
314327 } elseif ( $page_name == '' ) {
@@ -334,8 +347,8 @@
335348 $form_text = "";
336349 if ( $userCanEditPage || $is_query ) {
337350 $form_is_disabled = false;
338 - // Show "Your IP address will be recorded" warning if user is
339 - // anonymous, and it's not a query -
 351+ // Show "Your IP address will be recorded" warning if
 352+ // user is anonymous, and it's not a query -
340353 // wiki-text for bolding has to be replaced with HTML.
341354 if ( $wgUser->isAnon() && ! $is_query ) {
342355 $anon_edit_warning = preg_replace( "/'''(.*)'''/", "<strong>$1</strong>", wfMsg( 'anoneditwarning' ) );
@@ -410,9 +423,10 @@
411424 } // end while
412425 $form_def_sections[] = trim( substr( $form_def, $section_start ) );
413426
414 - // Cycle through form definition file (and possibly an existing article
415 - // as well), finding template and field declarations and replacing them
416 - // with form elements, either blank or pre-populated, as appropriate.
 427+ // Cycle through the form definition file, and possibly an
 428+ // existing article as well, finding template and field
 429+ // declarations and replacing them with form elements, either
 430+ // blank or pre-populated, as appropriate.
417431 $all_fields = array();
418432 $data_text = "";
419433 $template_name = "";
@@ -424,8 +438,8 @@
425439 $tif = new SFTemplateInForm();
426440 $start_position = 0;
427441 $template_text = "";
428 - // the append is there to ensure that the original array doesn't get
429 - // modified; is it necessary?
 442+ // the append is there to ensure that the original
 443+ // array doesn't get modified; is it necessary?
430444 $section = " " . $form_def_sections[$section_num];
431445
432446 while ( $brackets_loc = strpos( $section, '{{{', $start_position ) ) {
@@ -1042,7 +1056,7 @@
10431057 ( $cur_value == '' || $cur_value == 'now' ) ) {
10441058 if ( $input_type == 'date' || $input_type == 'datetime' ||
10451059 $input_type == 'year' ||
1046 - ( $input_type == '' && $form_field->template_field->field_type_id == '_dat' ) ) {
 1060+ ( $input_type == '' && $form_field->template_field->property_type == '_dat' ) ) {
10471061 // Get current time, for the time zone specified in the wiki.
10481062 global $wgLocaltimezone;
10491063 if ( isset( $wgLocaltimezone ) ) {
@@ -1287,11 +1301,14 @@
12881302 $this->multipleTemplateInstanceTableHTML( $section )
12891303 ) . "\n";
12901304
1291 - // this will cause the section to be re-parsed on the next go
 1305+ // This will cause the section to be
 1306+ // re-parsed on the next go.
12921307 $section_num--;
12931308 } else {
1294 - // This is the last instance of this template - print all the
1295 - // sections necessary for adding additional instances.
 1309+ // This is the last instance of this
 1310+ // template - print all the sections
 1311+ // necessary for adding additional
 1312+ // instances.
12961313 $form_text .= "\t\t" . Xml::tags( 'div',
12971314 array(
12981315 'class' => "multipleTemplateStarter",
@@ -1468,17 +1485,17 @@
14691486 $funcArgs[] = $other_args;
14701487 $text = call_user_func_array( $hook_values[0], $funcArgs );
14711488 } else { // input type not defined in form
1472 - $field_type = $template_field->field_type;
 1489+ $property_type = $template_field->property_type;
14731490 $is_list = ( $form_field->is_list || $template_field->is_list );
1474 - if ( $field_type != '' &&
1475 - array_key_exists( $field_type, $this->mSemanticTypeHooks ) &&
1476 - isset( $this->mSemanticTypeHooks[$field_type][$is_list] ) ) {
 1491+ if ( $property_type != '' &&
 1492+ array_key_exists( $property_type, $this->mSemanticTypeHooks ) &&
 1493+ isset( $this->mSemanticTypeHooks[$property_type][$is_list] ) ) {
14771494 $funcArgs = array();
14781495 $funcArgs[] = $cur_value;
14791496 $funcArgs[] = $form_field->input_name;
14801497 $funcArgs[] = $form_field->is_mandatory;
14811498 $funcArgs[] = $form_field->is_disabled;
1482 - $hook_values = $this->mSemanticTypeHooks[$field_type][$is_list];
 1499+ $hook_values = $this->mSemanticTypeHooks[$property_type][$is_list];
14831500 $other_args = $form_field->getArgumentsForInputCall( $hook_values[1] );
14841501 $funcArgs[] = $other_args;
14851502 $text = call_user_func_array( $hook_values[0], $funcArgs );