Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php |
— | — | @@ -10,41 +10,47 @@ |
11 | 11 | * @ingroup SMW |
12 | 12 | */ |
13 | 13 | |
14 | | -class SMWPageSchemas { |
| 14 | +class SMWPageSchemas extends PSExtensionHandler { |
15 | 15 | |
| 16 | + public static function getDisplayColor() { |
| 17 | + return '#DEF'; |
| 18 | + } |
| 19 | + |
| 20 | + public static function getFieldDisplayString() { |
| 21 | + return 'Semantic property'; |
| 22 | + } |
| 23 | + |
16 | 24 | /** |
17 | 25 | * Returns the display info for the property (if any is defined) |
18 | 26 | * for a single field in the Page Schemas XML. |
19 | 27 | */ |
20 | | - function getPropertyDisplayInfo( $field_xml, &$text_object ) { |
21 | | - foreach ( $field_xml->children() as $tag => $child ) { |
| 28 | + public static function getFieldDisplayValues( $fieldXML ) { |
| 29 | + foreach ( $fieldXML->children() as $tag => $child ) { |
22 | 30 | if ( $tag == "semanticmediawiki_Property" ) { |
23 | 31 | $propName = $child->attributes()->name; |
24 | 32 | $values = array(); |
25 | 33 | foreach ( $child->children() as $prop => $value ) { |
26 | 34 | $values[$prop] = (string)$value; |
27 | 35 | } |
28 | | - $text_object['smw'] = array( 'Semantic property', $propName, '#DEF', $values ); |
29 | | - break; |
| 36 | + return array( $propName, $values ); |
30 | 37 | } |
31 | 38 | } |
32 | | - return true; |
| 39 | + return null; |
33 | 40 | } |
34 | 41 | |
35 | 42 | /** |
36 | 43 | * Returns the set of SMW property data from the entire page schema. |
37 | 44 | */ |
38 | | - static function getAllPropertyData( $psSchemaObj ) { |
| 45 | + static function getAllPropertyData( $pageSchemaObj ) { |
39 | 46 | $propertyDataArray = array(); |
40 | | - $psTemplates = $psSchemaObj->getTemplates(); |
| 47 | + $psTemplates = $pageSchemaObj->getTemplates(); |
41 | 48 | foreach ( $psTemplates as $psTemplate ) { |
42 | 49 | $psTemplateFields = $psTemplate->getFields(); |
43 | 50 | foreach ( $psTemplateFields as $psTemplateField ) { |
44 | | - $smw_array = $psTemplateField->getObject('semanticmediawiki_Property'); |
45 | | - if ( !array_key_exists( 'smw', $smw_array ) ) { |
| 51 | + $prop_array = $psTemplateField->getObject('semanticmediawiki_Property'); |
| 52 | + if ( empty( $prop_array ) ) { |
46 | 53 | continue; |
47 | 54 | } |
48 | | - $prop_array = $smw_array['smw']; |
49 | 55 | if ( !array_key_exists( 'name', $prop_array ) ) { |
50 | 56 | continue; |
51 | 57 | } |
— | — | @@ -59,25 +65,28 @@ |
60 | 66 | |
61 | 67 | /** |
62 | 68 | * Sets the list of property pages defined by the passed-in |
63 | | - * Page Schemas XML object. |
| 69 | + * Page Schemas object. |
64 | 70 | */ |
65 | | - function getPageList( $psSchemaObj , &$genPageList ) { |
66 | | - $propertyDataArray = self::getAllPropertyData( $psSchemaObj ); |
| 71 | + public static function getPagesToGenerate( $pageSchemaObj ) { |
| 72 | + $pagesToGenerate = array(); |
| 73 | + $propertyDataArray = self::getAllPropertyData( $pageSchemaObj ); |
67 | 74 | foreach ( $propertyDataArray as $propertyData ) { |
68 | 75 | $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $propertyData['name'] ); |
69 | | - $genPageList[] = $title; |
| 76 | + $pagesToGenerate[] = $title; |
70 | 77 | } |
71 | | - return true; |
| 78 | + return $pagesToGenerate; |
72 | 79 | } |
73 | 80 | |
74 | 81 | /** |
75 | 82 | * Constructs XML for the SMW property, based on what was submitted |
76 | 83 | * in the 'edit schema' form. |
77 | 84 | */ |
78 | | - function getFieldXML( $request, &$xmlArray ) { |
| 85 | + public static function createFieldXMLFromForm() { |
| 86 | + global $wgRequest; |
| 87 | + |
79 | 88 | $fieldNum = -1; |
80 | 89 | $xmlPerField = array(); |
81 | | - foreach ( $request->getValues() as $var => $val ) { |
| 90 | + foreach ( $wgRequest->getValues() as $var => $val ) { |
82 | 91 | if ( substr( $var, 0, 18 ) == 'smw_property_name_' ) { |
83 | 92 | $fieldNum = substr( $var, 18 ); |
84 | 93 | $xml = '<semanticmediawiki_Property name="' . $val . '" >'; |
— | — | @@ -100,38 +109,28 @@ |
101 | 110 | $xmlPerField[$fieldNum] = $xml; |
102 | 111 | } |
103 | 112 | } |
104 | | - $xmlArray['smw'] = $xmlPerField; |
105 | | - return true; |
| 113 | + return $xmlPerField; |
106 | 114 | } |
107 | 115 | |
108 | 116 | /** |
109 | 117 | * Returns the HTML necessary for getting information about the |
110 | 118 | * semantic property within the Page Schemas 'editschema' page. |
111 | 119 | */ |
112 | | - function getFieldHTML( $field, &$fieldHTMLFromExtensions ) { |
| 120 | + public static function getFieldEditingHTML( $psTemplateField ) { |
113 | 121 | global $smwgContLang; |
114 | 122 | |
115 | 123 | $prop_array = array(); |
116 | 124 | $hasExistingValues = false; |
117 | | - if ( !is_null( $field ) ) { |
118 | | - $smw_array = $field->getObject('semanticmediawiki_Property'); |
119 | | - if ( array_key_exists( 'smw', $smw_array ) ) { |
120 | | - $prop_array = $smw_array['smw']; |
| 125 | + if ( !is_null( $psTemplateField ) ) { |
| 126 | + $prop_array = $psTemplateField->getObject('semanticmediawiki_Property'); |
| 127 | + if ( !is_null( $prop_array ) ) { |
121 | 128 | $hasExistingValues = true; |
122 | 129 | } |
123 | 130 | } |
124 | 131 | $html_text = '<p>' . wfMsg( 'ps-optional-name' ) . ' '; |
125 | | - if ( array_key_exists( 'name', $prop_array ) ) { |
126 | | - $propName = $prop_array['name']; |
127 | | - } else { |
128 | | - $propName = null; |
129 | | - } |
| 132 | + $propName = PageSchemas::getValueFromObject( $prop_array, 'name' ); |
130 | 133 | $html_text .= Html::input( 'smw_property_name_num', $propName, array( 'size' => 15 ) ) . "\n"; |
131 | | - if ( array_key_exists( 'Type', $prop_array ) ) { |
132 | | - $propType = $prop_array['Type']; |
133 | | - } else { |
134 | | - $propType = null; |
135 | | - } |
| 134 | + $propType = PageSchemas::getValueFromObject( $prop_array, 'Type' ); |
136 | 135 | $select_body = ""; |
137 | 136 | $datatype_labels = $smwgContLang->getDatatypeLabels(); |
138 | 137 | foreach ( $datatype_labels as $label ) { |
— | — | @@ -151,50 +150,51 @@ |
152 | 151 | $allowedValsInputAttrs = array( |
153 | 152 | 'size' => 80 |
154 | 153 | ); |
155 | | - if ( array_key_exists( 'allowed_values', $prop_array ) ) { |
156 | | - $allowed_val_string = implode( ', ', $prop_array['allowed_values'] ); |
157 | | - } else { |
| 154 | + $allowedValues = PageSchemas::getValueFromObject( $prop_array, 'allowed_values' ); |
| 155 | + if ( is_null( $allowedValues ) ) { |
158 | 156 | $allowed_val_string = ''; |
| 157 | + } else { |
| 158 | + $allowed_val_string = implode( ', ', $allowedValues ); |
159 | 159 | } |
160 | 160 | $html_text .= '<p>' . Html::input( 'smw_values_num', $allowed_val_string, 'text', $allowedValsInputAttrs ) . "</p>\n"; |
161 | 161 | |
162 | | - $fieldHTMLFromExtensions['smw'] = array( 'Semantic property', '#DEF', $html_text, $hasExistingValues ); |
163 | | - |
164 | | - return true; |
| 162 | + return array( $html_text, $hasExistingValues ); |
165 | 163 | } |
166 | 164 | |
167 | 165 | /** |
168 | 166 | * Creates the property page for each property specified in the |
169 | 167 | * passed-in Page Schemas XML object. |
170 | 168 | */ |
171 | | - function generatePages( $psSchemaObj, $selectedPageList ) { |
172 | | - $propertyDataArray = self::getAllPropertyData( $psSchemaObj ); |
| 169 | + public static function generatePages( $pageSchemaObj, $selectedPages ) { |
| 170 | + global $wgUser; |
| 171 | + |
| 172 | + $jobs = array(); |
| 173 | + $jobParams = array(); |
| 174 | + $jobParams['user_id'] = $wgUser->getId(); |
| 175 | + $propertyDataArray = self::getAllPropertyData( $pageSchemaObj ); |
173 | 176 | foreach ( $propertyDataArray as $propertyData ) { |
174 | | - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $propertyData['name'] ); |
175 | | - if ( !in_array( $title, $selectedPageList ) ) { |
| 177 | + $propTitle = Title::makeTitleSafe( SMW_NS_PROPERTY, $propertyData['name'] ); |
| 178 | + if ( !in_array( $propTitle, $selectedPages ) ) { |
176 | 179 | continue; |
177 | 180 | } |
178 | | - self::createProperty( $propertyData['name'], $propertyData['Type'], $propertyData['allowed_values'] ); |
| 181 | + $jobParams['page_text'] = self::createPropertyText( $propertyData['Type'], $propertyData['allowed_values'] ); |
| 182 | + $jobs[] = new PSCreatePageJob( $propTitle, $jobParams ); |
179 | 183 | } |
180 | | - return true; |
| 184 | + Job::batchInsert( $jobs ); |
181 | 185 | } |
182 | 186 | |
183 | 187 | /** |
184 | 188 | * Creates the text for a property page. |
185 | 189 | */ |
186 | | - function createPropertyText( $property_type, $allowed_values ) { |
| 190 | + function createPropertyText( $propertyType, $allowedValues ) { |
187 | 191 | global $smwgContLang; |
188 | | - $prop_labels = $smwgContLang->getPropertyLabels(); |
189 | | - $type_tag = "[[{$prop_labels['_TYPE']}::$property_type]]"; |
190 | | - $text = wfMsgForContent( 'ps-property-isproperty', $type_tag ); |
191 | | - if ( $allowed_values != null) { |
192 | | - // Replace the comma with a substitution character |
193 | | - // that has no chance of being included in the values |
194 | | - // list - namely, the ASCII beep. |
195 | | - $text .= "\n\n" . wfMsgExt( 'ps-property-allowedvals', array( 'parsemag', 'content' ), count( $allowed_values ) ); |
196 | | - foreach ( $allowed_values as $i => $value ) { |
197 | | - // Replace beep back with comma, trim. |
198 | | - $value = str_replace( "\a",',' , trim( $value ) ); |
| 192 | + $propLabels = $smwgContLang->getPropertyLabels(); |
| 193 | + $hasTypeLabel = $propLabels['_TYPE']; |
| 194 | + $typeTag = "[[$hasTypeLabel::$propertyType]]"; |
| 195 | + $text = wfMsgForContent( 'ps-property-isproperty', $typeTag ); |
| 196 | + if ( $allowedValues != null) { |
| 197 | + $text .= "\n\n" . wfMsgExt( 'ps-property-allowedvals', array( 'parsemag', 'content' ), count( $allowedValues ) ); |
| 198 | + foreach ( $allowedValues as $i => $value ) { |
199 | 199 | if ( method_exists( $smwgContLang, 'getPropertyLabels' ) ) { |
200 | 200 | $prop_labels = $smwgContLang->getPropertyLabels(); |
201 | 201 | $text .= "\n* [[" . $prop_labels['_PVAL'] . "::$value]]"; |
— | — | @@ -207,28 +207,15 @@ |
208 | 208 | return $text; |
209 | 209 | } |
210 | 210 | |
211 | | - function createProperty( $prop_name, $prop_type, $allowed_values ) { |
212 | | - global $wgUser; |
213 | | - |
214 | | - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_name ); |
215 | | - $params = array(); |
216 | | - $params['user_id'] = $wgUser->getId(); |
217 | | - $params['page_text'] = self::createPropertyText( $prop_type, $allowed_values ); |
218 | | - $jobs = array(); |
219 | | - $jobs[] = new PSCreatePageJob( $title, $params ); |
220 | | - Job::batchInsert( $jobs ); |
221 | | - return true; |
222 | | - } |
223 | | - |
224 | 211 | /** |
225 | 212 | * Returns the property based on the XML passed from the Page Schemas |
226 | 213 | * extension. |
227 | 214 | */ |
228 | | - function createPageSchemasObject( $objectName, $xmlForField, &$object ) { |
229 | | - $smw_array = array(); |
230 | | - if ( $objectName == "semanticmediawiki_Property" ) { |
231 | | - foreach ( $xmlForField->children() as $tag => $child ) { |
232 | | - if ( $tag == $objectName ) { |
| 215 | + public static function createPageSchemasObject( $tagName, $xml ) { |
| 216 | + if ( $tagName == "semanticmediawiki_Property" ) { |
| 217 | + foreach ( $xml->children() as $tag => $child ) { |
| 218 | + if ( $tag == $tagName ) { |
| 219 | + $smw_array = array(); |
233 | 220 | $propName = $child->attributes()->name; |
234 | 221 | $smw_array['name'] = (string)$propName; |
235 | 222 | $allowed_values = array(); |
— | — | @@ -241,11 +228,10 @@ |
242 | 229 | } |
243 | 230 | } |
244 | 231 | $smw_array['allowed_values'] = $allowed_values; |
245 | | - $object['smw'] = $smw_array; |
246 | | - return true; |
| 232 | + return $smw_array; |
247 | 233 | } |
248 | 234 | } |
249 | 235 | } |
250 | | - return true; |
| 236 | + return null; |
251 | 237 | } |
252 | 238 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -73,6 +73,11 @@ |
74 | 74 | return true; |
75 | 75 | } |
76 | 76 | |
| 77 | +// Register class with the Page Schemas extension |
| 78 | +if ( isset( $wgPageSchemasHandlerClasses ) ) { |
| 79 | + $wgPageSchemasHandlerClasses[] = 'SMWPageSchemas'; |
| 80 | +} |
| 81 | + |
77 | 82 | /** |
78 | 83 | * Register all SMW hooks with MediaWiki. |
79 | 84 | */ |
— | — | @@ -93,13 +98,6 @@ |
94 | 99 | // For pre-MediaWiki 1.17 alpha. |
95 | 100 | $wgHooks['SpecialVersionExtensionTypes'][] = 'smwfOldAddSemanticExtensionType'; |
96 | 101 | } |
97 | | - |
98 | | - $wgHooks['PageSchemasGetObject'][] = 'SMWPageSchemas::createPageSchemasObject'; |
99 | | - $wgHooks['PageSchemasGeneratePages'][] = 'SMWPageSchemas::generatePages'; |
100 | | - $wgHooks['PageSchemasGetFieldHTML'][] = 'SMWPageSchemas::getFieldHTML'; |
101 | | - $wgHooks['PageSchemasGetFieldXML'][] = 'SMWPageSchemas::getFieldXML'; |
102 | | - $wgHooks['PageSchemasGetFieldDisplayInfo'][] = 'SMWPageSchemas::getPropertyDisplayInfo'; |
103 | | - $wgHooks['PageSchemasGetPageList'][] = 'SMWPageSchemas::getPageList'; |
104 | 102 | } |
105 | 103 | |
106 | 104 | /** |