Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Global functions used for setting up the Semantic MediaWiki extension. |
6 | | - * |
| 6 | + * |
7 | 7 | * @file SMW_Setup.php |
8 | 8 | * @ingroup SMW |
9 | 9 | */ |
— | — | @@ -81,7 +81,7 @@ |
82 | 82 | $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks'; |
83 | 83 | $wgHooks['ParserFirstCallInit'][] = 'SMWSMWDoc::staticInit'; |
84 | 84 | $wgHooks['LanguageGetMagic'][] = 'SMWSMWDoc::staticMagic'; |
85 | | - |
| 85 | + |
86 | 86 | if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) { |
87 | 87 | // For MediaWiki 1.17 alpha and later. |
88 | 88 | $wgHooks['ExtensionTypes'][] = 'smwfAddSemanticExtensionType'; |
— | — | @@ -90,11 +90,10 @@ |
91 | 91 | $wgHooks['SpecialVersionExtensionTypes'][] = 'smwfOldAddSemanticExtensionType'; |
92 | 92 | } |
93 | 93 | |
94 | | - /* Hooks related to Pageschemas extension. TODO: Should be moved to separate file. */ |
95 | | - $wgHooks['PageSchemasGetObject'][] = 'smwfCreatePageSchemasObject' ; // Hook for returning PageSchema(extension) object from a given xml |
| 94 | + /* Hooks related to Pageschemas extension. TODO: Should be moved to separate file. */ |
| 95 | + $wgHooks['PageSchemasGetObject'][] = 'smwfCreatePageSchemasObject' ; // Hook for returning PageSchema(extension) object from a given xml |
96 | 96 | $wgHooks['PageSchemasGeneratePages'][] = 'smwfGeneratePages' ; // Hook for creating Pages |
97 | | - $wgHooks['getHtmlTextForFieldInputs'][] = 'smwfgetHtmlTextForPS' ; // Hook for retuning html text to PS schema |
98 | | - $wgHooks['getFilledHtmlTextForFieldInputs'][] = 'smwfgetFilledHtmlTextForPS' ; //Hook for retuning html text to PS schema |
| 97 | + $wgHooks['PageSchemasGetFieldHTML'][] = 'smwfGetFieldHTMLForPS' ; // Hook for retuning html text to PS schema |
99 | 98 | $wgHooks['PageSchemasGetFieldXML'][] = 'smwfGetFieldXMLForPS'; |
100 | 99 | $wgHooks['PSParseFieldElements'][] = 'smwfParseFieldElements' ; // Hook for creating Pages |
101 | 100 | $wgHooks['PageSchemasGetPageList'][] = 'smwfGetPageList' ; //Hook for creating Pages |
— | — | @@ -112,18 +111,18 @@ |
113 | 112 | 'remoteBasePath' => $smwgScriptPath, |
114 | 113 | 'group' => 'ext.smw' |
115 | 114 | ); |
116 | | - |
| 115 | + |
117 | 116 | $wgResourceModules['ext.smw'] = $moduleTemplate + array( |
118 | 117 | 'scripts' => array( |
119 | 118 | 'resources/ext.smw.js', |
120 | 119 | 'resources/ext.smw.compat.js', |
121 | 120 | ), |
122 | 121 | ); |
123 | | - |
| 122 | + |
124 | 123 | $wgResourceModules['ext.smw.style'] = $moduleTemplate + array( |
125 | 124 | 'styles' => 'skins/SMW_custom.css' |
126 | 125 | ); |
127 | | - |
| 126 | + |
128 | 127 | $wgResourceModules['ext.smw.tooltips'] = $moduleTemplate + array( |
129 | 128 | 'scripts' => 'skins/SMW_tooltip.js', |
130 | 129 | 'dependencies' => array( |
— | — | @@ -165,7 +164,7 @@ |
166 | 165 | ); |
167 | 166 | $wgResourceModules['jquery.ui.dialog'] = $moduleTemplate + array( |
168 | 167 | 'scripts' => 'libs/jquery-ui/jquery.ui.dialog.min.js', |
169 | | - 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget', 'jquery.ui.position', |
| 168 | + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget', 'jquery.ui.position', |
170 | 169 | 'jquery.ui.button' /*, 'jquery.ui.draggable', 'jquery.ui.mouse', 'jquery.ui.resizable'*/ ) |
171 | 170 | ); |
172 | 171 | } |
— | — | @@ -264,7 +263,7 @@ |
265 | 264 | // Parameter classes |
266 | 265 | $parDir = $smwgIP . 'includes/params/'; |
267 | 266 | $wgAutoloadClasses['SMWParamFormat'] = $parDir . 'SMW_ParamFormat.php'; |
268 | | - |
| 267 | + |
269 | 268 | // Parser hooks |
270 | 269 | $phDir = $smwgIP . 'includes/parserhooks/'; |
271 | 270 | $wgAutoloadClasses['SMWAsk'] = $phDir . 'SMW_Ask.php'; |
— | — | @@ -275,7 +274,7 @@ |
276 | 275 | $wgAutoloadClasses['SMWSetRecurringEvent'] = $phDir . 'SMW_SetRecurringEvent.php'; |
277 | 276 | $wgAutoloadClasses['SMWDeclare'] = $phDir . 'SMW_Declare.php'; |
278 | 277 | $wgAutoloadClasses['SMWSMWDoc'] = $phDir . 'SMW_SMWDoc.php'; |
279 | | - |
| 278 | + |
280 | 279 | // Stores & queries |
281 | 280 | $wgAutoloadClasses['SMWQueryProcessor'] = $smwgIP . 'includes/SMW_QueryProcessor.php'; |
282 | 281 | $wgAutoloadClasses['SMWQueryParser'] = $smwgIP . 'includes/SMW_QueryParser.php'; |
— | — | @@ -614,13 +613,13 @@ |
615 | 614 | foreach ( $field_xml->children() as $tag => $child ) { |
616 | 615 | if ( $tag == "semanticmediawiki_Property" ) { |
617 | 616 | $text = ""; |
618 | | - $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticMediaWiki", (string)$tag ); |
619 | | - $propName = $child->attributes()->name; |
620 | | - //this means object has already been initialized by some other extension. |
621 | | - $text .= PageSchemas::tableMessageRowHTML( "paramAttrMsg", "name", (string)$propName ); |
622 | | - foreach ( $child->children() as $prop => $value ) { |
623 | | - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop, (string)$value ); |
624 | | - } |
| 617 | + $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticMediaWiki", (string)$tag ); |
| 618 | + $propName = $child->attributes()->name; |
| 619 | + //this means object has already been initialized by some other extension. |
| 620 | + $text .= PageSchemas::tableMessageRowHTML( "paramAttrMsg", "name", (string)$propName ); |
| 621 | + foreach ( $child->children() as $prop => $value ) { |
| 622 | + $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop, (string)$value ); |
| 623 | + } |
625 | 624 | $text_object['smw']=$text; |
626 | 625 | } |
627 | 626 | } |
— | — | @@ -632,7 +631,7 @@ |
633 | 632 | foreach ( $template_all as $template ) { |
634 | 633 | $field_all = $template->getFields(); |
635 | 634 | $field_count = 0; //counts the number of fields |
636 | | - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
| 635 | + foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
637 | 636 | $field_count++; |
638 | 637 | $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
639 | 638 | $prop_array = $smw_array['smw']; |
— | — | @@ -675,73 +674,53 @@ |
676 | 675 | return true; |
677 | 676 | } |
678 | 677 | |
679 | | -function smwfgetFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ){ |
| 678 | +function smwfGetFieldHTMLForPS( $field, &$text_extensions ) { |
680 | 679 | global $smwgContLang; |
681 | 680 | $datatype_labels = $smwgContLang->getDatatypeLabels(); |
682 | | - $html_text = ""; |
683 | | - $template_all = $pageSchemaObj->getTemplates(); |
684 | | - $html_text_array = array(); |
685 | | - foreach ( $template_all as $template ) { |
686 | | - $field_all = $template->getFields(); |
687 | | - $field_count = 0; //counts the number of fields |
688 | | - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
689 | | - $field_count++; |
690 | | - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
691 | | - $prop_array = $smw_array['smw']; |
692 | | - if($prop_array != null){ |
693 | | - $html_text .= '<fieldset style="background: #DEF;"><legend>Property</legend>'; |
694 | | - $html_text .= '<p> Property Name: <input size="15" name="smw_property_name_starter" value="'.$prop_array['name'].'" >Type: '; |
695 | | - $select_body = ""; |
696 | | - foreach ( $datatype_labels as $label ) { |
697 | | - if( $label == $prop_array['Type'] ){ |
698 | | - $select_body .= " " . '<option selected>'.$label.'</option>' . "\n"; |
699 | | - }else{ |
700 | | - $select_body .= " " . Xml::element( 'option', null, $label ) . "\n"; |
701 | | - } |
702 | | - } |
703 | | - $html_text .= Xml::tags( 'select', array( 'id' => 'property_dropdown', 'name' => 'smw_property_type_starter','value' =>$prop_array['Type'] ), $select_body ); |
704 | | - $html_text .= ' </p> |
705 | | - <p>If you want this property to only be allowed to have certain values, enter the list of allowed values, separated by commas (if a value contains a comma, replace it with "\,"):</p>'; |
706 | | - $allowed_val_string = ""; |
707 | | - foreach( $prop_array['allowed_value_array'] as $allowed_value ){ |
708 | | - $allowed_val_string .= $allowed_value.', '; |
709 | | - } |
710 | | - |
711 | | - $html_text .= '<p><input name="smw_values_starter" size="80" value="'.$allowed_val_string.'" ></p></fieldset>'; |
712 | | - $html_text_array[] = $html_text; |
713 | | - } |
714 | | - } |
| 681 | + if ( !is_null( $field ) ) { |
| 682 | + $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
| 683 | + $prop_array = $smw_array['smw']; |
| 684 | + } else { |
| 685 | + $prop_array = array(); |
715 | 686 | } |
716 | | - $text_extensions['smw'] = $html_text_array; |
717 | | - return true; |
718 | | - |
719 | | -} |
720 | | -function smwfgetHtmlTextForPS( &$js_extensions ,&$text_extensions ) { |
721 | | - global $smwgContLang; |
722 | | - $datatype_labels = $smwgContLang->getDatatypeLabels(); |
723 | | - $html_text = ""; |
724 | | - $html_text .= '<fieldset style="background: #DEF;"><legend>Property</legend> |
725 | | - <p> Property Name: <input size="15" name="smw_property_name_starter">Type: '; |
| 687 | + $html_text = '<p>Property name: <input size="15" name="smw_property_name_num" value="'.$prop_array['name'].'" >' . "\n"; |
726 | 688 | $select_body = ""; |
727 | 689 | foreach ( $datatype_labels as $label ) { |
728 | | - $select_body .= " " . Xml::element( 'option', null, $label ) . "\n"; |
| 690 | + $optionAttrs = array(); |
| 691 | + if ( $label == $prop_array['Type'] ) { |
| 692 | + $optionAttrs['selected'] = 'selected'; |
| 693 | + } |
| 694 | + $select_body .= "\t" . Xml::element( 'option', $optionAttrs, $label ) . "\n"; |
729 | 695 | } |
730 | | - $html_text .= Xml::tags( 'select', array( 'id' => 'property_dropdown', 'name' => 'smw_property_type_starter' ), $select_body ); |
731 | | - $html_text .= ' </p> |
732 | | - <p>If you want this property to only be allowed to have certain values, enter the list of allowed values, separated by commas (if a value contains a comma, replace it with "\,"):</p> |
733 | | - <p><input value="" name="smw_values_starter" size="80"></p></fieldset>'; |
| 696 | + $propertyDropdownAttrs = array( 'id' => 'property_dropdown', 'name' => 'smw_property_type_num' ); |
| 697 | + if ( array_key_exists( 'Type', $prop_array ) ) { |
| 698 | + $propertyDropdownAttrs['value'] = $prop_array['Type']; |
| 699 | + } |
| 700 | + $html_text .= "Type: " . Xml::tags( 'select', $propertyDropdownAttrs, $select_body ) . "</p>\n"; |
| 701 | + $html_text .= '<p>If you want this property to only be allowed to have certain values, enter the list of allowed values, separated by commas (if a value contains a comma, replace it with "\,"):</p>'; |
| 702 | + $allowedValsInputAttrs = array( |
| 703 | + 'size' => 80 |
| 704 | + ); |
| 705 | + if ( array_key_exists( 'allowed_value_array', $prop_array ) ) { |
| 706 | + $allowed_val_string = implode( ', ', $prop_array['allowed_value_array'] ); |
| 707 | + } else { |
| 708 | + $allowed_val_string = ''; |
| 709 | + } |
| 710 | + $html_text .= '<p>' . Html::input( 'smw_values_num', $allowed_val_string, 'text', $allowedValsInputAttrs ) . "</p>\n"; |
734 | 711 | |
735 | | - $text_extensions['smw'] = $html_text; |
| 712 | + $text_extensions['smw'] = array( 'Property', '#DEF', $html_text ); |
| 713 | + |
736 | 714 | return true; |
737 | 715 | } |
| 716 | + |
738 | 717 | function smwfGeneratePages( $psSchemaObj, $toGenPageList ) { |
739 | 718 | $template_all = $psSchemaObj->getTemplates(); |
740 | 719 | foreach ( $template_all as $template ) { |
741 | 720 | $field_all = $template->getFields(); |
742 | 721 | $field_count = 0; //counts the number of fields |
743 | | - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
| 722 | + foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
744 | 723 | $field_count++; |
745 | | - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
| 724 | + $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
746 | 725 | $prop_array = $smw_array['smw']; |
747 | 726 | if($prop_array != null){ |
748 | 727 | $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] ); |
— | — | @@ -754,34 +733,35 @@ |
755 | 734 | } |
756 | 735 | return true; |
757 | 736 | } |
| 737 | + |
758 | 738 | function smwfCreatePropertyText( $property_type, $allowed_value_array ) { |
759 | | - global $smwgContLang; |
760 | | - $prop_labels = $smwgContLang->getPropertyLabels(); |
761 | | - $type_tag = "[[{$prop_labels['_TYPE']}::$property_type]]"; |
762 | | - $text = wfMsgForContent( 'ps-property-isproperty', $type_tag ); |
763 | | - if ( $allowed_value_array != null) { |
764 | | - // replace the comma substitution character that has no chance of |
765 | | - // being included in the values list - namely, the ASCII beep |
766 | | - $text .= "\n\n" . wfMsgExt( 'ps-property-allowedvals', array( 'parsemag', 'content' ), count( $allowed_value_array ) ); |
767 | | - foreach ( $allowed_value_array as $i => $value ) { |
768 | | - // replace beep back with comma, trim |
769 | | - $value = str_replace( "\a",',' , trim( $value ) ); |
770 | | - if ( method_exists( $smwgContLang, 'getPropertyLabels' ) ) { |
771 | | - $prop_labels = $smwgContLang->getPropertyLabels(); |
772 | | - $text .= "\n* [[" . $prop_labels['_PVAL'] . "::$value]]"; |
773 | | - } else { |
774 | | - $spec_props = $smwgContLang->getSpecialPropertiesArray(); |
775 | | - $text .= "\n* [[" . $spec_props[SMW_SP_POSSIBLE_VALUE] . "::$value]]"; |
776 | | - } |
| 739 | + global $smwgContLang; |
| 740 | + $prop_labels = $smwgContLang->getPropertyLabels(); |
| 741 | + $type_tag = "[[{$prop_labels['_TYPE']}::$property_type]]"; |
| 742 | + $text = wfMsgForContent( 'ps-property-isproperty', $type_tag ); |
| 743 | + if ( $allowed_value_array != null) { |
| 744 | + // replace the comma substitution character that has no chance of |
| 745 | + // being included in the values list - namely, the ASCII beep |
| 746 | + $text .= "\n\n" . wfMsgExt( 'ps-property-allowedvals', array( 'parsemag', 'content' ), count( $allowed_value_array ) ); |
| 747 | + foreach ( $allowed_value_array as $i => $value ) { |
| 748 | + // replace beep back with comma, trim |
| 749 | + $value = str_replace( "\a",',' , trim( $value ) ); |
| 750 | + if ( method_exists( $smwgContLang, 'getPropertyLabels' ) ) { |
| 751 | + $prop_labels = $smwgContLang->getPropertyLabels(); |
| 752 | + $text .= "\n* [[" . $prop_labels['_PVAL'] . "::$value]]"; |
| 753 | + } else { |
| 754 | + $spec_props = $smwgContLang->getSpecialPropertiesArray(); |
| 755 | + $text .= "\n* [[" . $spec_props[SMW_SP_POSSIBLE_VALUE] . "::$value]]"; |
777 | 756 | } |
778 | 757 | } |
779 | | - return $text; |
780 | 758 | } |
| 759 | + return $text; |
| 760 | +} |
| 761 | + |
781 | 762 | function smwfCreateProperty( $prop_name, $prop_type, $allowed_value_array ) { |
782 | 763 | global $wgUser; |
783 | 764 | $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_name ); |
784 | 765 | $text = smwfCreatePropertyText( $prop_type, $allowed_value_array ); |
785 | | - #$text = "This is a property of type [[Has type:Number]]."; |
786 | 766 | $jobs = array(); |
787 | 767 | $params = array(); |
788 | 768 | $params['user_id'] = $wgUser->getId(); |
— | — | @@ -792,14 +772,14 @@ |
793 | 773 | } |
794 | 774 | |
795 | 775 | /** |
796 | | -* Function to return the Property based on the xml passed from the PageSchema extension |
| 776 | +* Function to return the Property based on the xml passed from the PageSchema extension |
797 | 777 | */ |
798 | 778 | function smwfCreatePageSchemasObject( $objectName, $xmlForField, &$object ) { |
799 | 779 | $smw_array = array(); |
800 | 780 | if ( $objectName == "semanticmediawiki_Property" ) { |
801 | 781 | foreach ( $xmlForField->children() as $tag => $child ) { |
802 | 782 | if ( $tag == $objectName ) { |
803 | | - $propName = $child->attributes()->name; |
| 783 | + $propName = $child->attributes()->name; |
804 | 784 | //this means object has already been initialized by some other extension. |
805 | 785 | $smw_array['name']=(string)$propName; |
806 | 786 | $allowed_value_array = array(); |
— | — | @@ -872,7 +852,7 @@ |
873 | 853 | * This hook registers parser functions and hooks to the given parser. It is |
874 | 854 | * called during SMW initialisation. Note that parser hooks are something different |
875 | 855 | * than MW hooks in general, which explains the two-level registration. |
876 | | - * |
| 856 | + * |
877 | 857 | * @since 1.5.3 |
878 | 858 | */ |
879 | 859 | function smwfRegisterParserFunctions( Parser &$parser ) { |