r97000 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96999‎ | r97000 | r97001 >
Date:20:58, 13 September 2011
Author:yaron
Status:ok
Tags:
Comment:
Follow-up to r96910 - removed now-obsolete Page Schemas-related functions
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -610,197 +610,7 @@
611611 /***** language settings *****/
612612 /**********************************************/
613613
614 -function smwfParseFieldElements( $field_xml, &$text_object ) {
615 - foreach ( $field_xml->children() as $tag => $child ) {
616 - if ( $tag == "semanticmediawiki_Property" ) {
617 - $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 - }
625 - $text_object['smw']=$text;
626 - }
627 - }
628 - return true;
629 -}
630 -
631 -function smwfGetPageList( $psSchemaObj , &$genPageList ) {
632 - $template_all = $psSchemaObj->getTemplates();
633 - foreach ( $template_all as $template ) {
634 - $field_all = $template->getFields();
635 - $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
637 - $field_count++;
638 - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
639 - $prop_array = $smw_array['smw'];
640 - if($prop_array != null){
641 - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
642 - $genPageList[] = $title;
643 - }
644 - }
645 - }
646 - return true;
647 -}
648 -
649 -function smwfGetFieldXMLForPS( $request, &$xmlArray ) {
650 - $templateNum = -1;
651 - $xmlPerField = array();
652 - foreach ( $request->getValues() as $var => $val ) {
653 - if ( substr( $var, 0, 18 ) == 'smw_property_name_' ) {
654 - $templateNum = substr($var,18,1);
655 - $xml = '<semanticmediawiki_Property name="'.$val.'" >';
656 - } elseif ( substr( $var, 0, 18 ) == 'smw_property_type_'){
657 - $xml .= '<Type>'.$val.'</Type>';
658 - } elseif ( substr( $var, 0, 11 ) == 'smw_values_') {
659 - if ( $val != '' ) {
660 - // replace the comma substitution character that has no chance of
661 - // being included in the values list - namely, the ASCII beep
662 - $listSeparator = ',';
663 - $allowed_values_str = str_replace( "\\$listSeparator", "\a", $val );
664 - $allowed_values_array = explode( $listSeparator, $allowed_values_str );
665 - foreach ( $allowed_values_array as $i => $value ) {
666 - // replace beep back with comma, trim
667 - $value = str_replace( "\a", $listSeparator, trim( $value ) );
668 - $xml .= '<AllowedValue>'.$value.'</AllowedValue>';
669 - }
670 - }
671 - $xml .= '</semanticmediawiki_Property>';
672 - $xmlPerField[] = $xml;
673 - }
674 - }
675 - $xmlArray['smw'] = $xmlPerField;
676 - return true;
677 -}
678 -
679 -function smwfGetFieldHTMLForPS( $field, &$text_extensions ) {
680 - global $smwgContLang;
681 - $datatype_labels = $smwgContLang->getDatatypeLabels();
682 - if ( !is_null( $field ) ) {
683 - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
684 - $prop_array = $smw_array['smw'];
685 - } else {
686 - $prop_array = array();
687 - }
688 - $html_text = '<p>Property name: <input size="15" name="smw_property_name_num" value="'.$prop_array['name'].'" >' . "\n";
689 - $select_body = "";
690 - foreach ( $datatype_labels as $label ) {
691 - $optionAttrs = array();
692 - if ( $label == $prop_array['Type'] ) {
693 - $optionAttrs['selected'] = 'selected';
694 - }
695 - $select_body .= "\t" . Xml::element( 'option', $optionAttrs, $label ) . "\n";
696 - }
697 - $propertyDropdownAttrs = array( 'id' => 'property_dropdown', 'name' => 'smw_property_type_num' );
698 - if ( array_key_exists( 'Type', $prop_array ) ) {
699 - $propertyDropdownAttrs['value'] = $prop_array['Type'];
700 - }
701 - $html_text .= "Type: " . Xml::tags( 'select', $propertyDropdownAttrs, $select_body ) . "</p>\n";
702 - $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>';
703 - $allowedValsInputAttrs = array(
704 - 'size' => 80
705 - );
706 - if ( array_key_exists( 'allowed_value_array', $prop_array ) ) {
707 - $allowed_val_string = implode( ', ', $prop_array['allowed_value_array'] );
708 - } else {
709 - $allowed_val_string = '';
710 - }
711 - $html_text .= '<p>' . Html::input( 'smw_values_num', $allowed_val_string, 'text', $allowedValsInputAttrs ) . "</p>\n";
712 -
713 - $text_extensions['smw'] = array( 'Property', '#DEF', $html_text );
714 -
715 - return true;
716 -}
717 -
718 -function smwfGeneratePages( $psSchemaObj, $toGenPageList ) {
719 - $template_all = $psSchemaObj->getTemplates();
720 - foreach ( $template_all as $template ) {
721 - $field_all = $template->getFields();
722 - $field_count = 0; //counts the number of fields
723 - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
724 - $field_count++;
725 - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
726 - $prop_array = $smw_array['smw'];
727 - if($prop_array != null){
728 - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
729 - $key_title = PageSchemas::titleString( $title );
730 - if(in_array( $key_title, $toGenPageList )){
731 - smwfCreateProperty( $prop_array['name'], $prop_array['Type'], $prop_array['allowed_value_array'] ) ;
732 - }
733 - }
734 - }
735 - }
736 - return true;
737 -}
738 -
739 -function smwfCreatePropertyText( $property_type, $allowed_value_array ) {
740 - global $smwgContLang;
741 - $prop_labels = $smwgContLang->getPropertyLabels();
742 - $type_tag = "[[{$prop_labels['_TYPE']}::$property_type]]";
743 - $text = wfMsgForContent( 'ps-property-isproperty', $type_tag );
744 - if ( $allowed_value_array != null) {
745 - // replace the comma substitution character that has no chance of
746 - // being included in the values list - namely, the ASCII beep
747 - $text .= "\n\n" . wfMsgExt( 'ps-property-allowedvals', array( 'parsemag', 'content' ), count( $allowed_value_array ) );
748 - foreach ( $allowed_value_array as $i => $value ) {
749 - // replace beep back with comma, trim
750 - $value = str_replace( "\a",',' , trim( $value ) );
751 - if ( method_exists( $smwgContLang, 'getPropertyLabels' ) ) {
752 - $prop_labels = $smwgContLang->getPropertyLabels();
753 - $text .= "\n* [[" . $prop_labels['_PVAL'] . "::$value]]";
754 - } else {
755 - $spec_props = $smwgContLang->getSpecialPropertiesArray();
756 - $text .= "\n* [[" . $spec_props[SMW_SP_POSSIBLE_VALUE] . "::$value]]";
757 - }
758 - }
759 - }
760 - return $text;
761 -}
762 -
763 -function smwfCreateProperty( $prop_name, $prop_type, $allowed_value_array ) {
764 - global $wgUser;
765 - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_name );
766 - $text = smwfCreatePropertyText( $prop_type, $allowed_value_array );
767 - $jobs = array();
768 - $params = array();
769 - $params['user_id'] = $wgUser->getId();
770 - $params['page_text'] = $text;
771 - $jobs[] = new PSCreatePageJob( $title, $params );
772 - Job::batchInsert( $jobs );
773 - return true;
774 -}
775 -
776614 /**
777 -* Function to return the Property based on the xml passed from the PageSchema extension
778 -*/
779 -function smwfCreatePageSchemasObject( $objectName, $xmlForField, &$object ) {
780 - $smw_array = array();
781 - if ( $objectName == "semanticmediawiki_Property" ) {
782 - foreach ( $xmlForField->children() as $tag => $child ) {
783 - if ( $tag == $objectName ) {
784 - $propName = $child->attributes()->name;
785 - //this means object has already been initialized by some other extension.
786 - $smw_array['name']=(string)$propName;
787 - $allowed_value_array = array();
788 - $count = 0;
789 - foreach ( $child->children() as $prop => $value ) {
790 - if ( $prop == "AllowedValue" ) {
791 - $allowed_value_array[$count++] = $value;
792 - } else {
793 - $smw_array[$prop] = (string)$value;
794 - }
795 - }
796 - $smw_array['allowed_value_array'] = $allowed_value_array;
797 - }
798 - }
799 - $object['smw'] = $smw_array;
800 - }
801 - return true;
802 -}
803 -
804 -/**
805615 * Set up (possibly localised) names for SMW's parser functions.
806616 * @todo Can be removed when new style magic words are used (introduced in r52503).
807617 */

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96910Moved all functions related to the Page Schemas extensions into a new class, ...yaron21:27, 12 September 2011

Status & tagging log