Index: trunk/extensions/SemanticInternalObjects/SIO_PageSchemas.php |
— | — | @@ -9,136 +9,134 @@ |
10 | 10 | * @ingroup SIO |
11 | 11 | */ |
12 | 12 | |
13 | | -class SIOPageSchemas { |
| 13 | +class SIOPageSchemas extends PSExtensionHandler { |
14 | 14 | |
| 15 | + public static function getDisplayColor() { |
| 16 | + return '#FF8'; |
| 17 | + } |
| 18 | + |
| 19 | + public static function getTemplateDisplayString() { |
| 20 | + return 'Internal property'; |
| 21 | + } |
| 22 | + |
15 | 23 | /** |
16 | 24 | * Returns the display info for the property (if any is defined) |
17 | 25 | * for a single field in the Page Schemas XML. |
18 | 26 | */ |
19 | | - function getPropertyDisplayInfo( $templateXML, &$text_object ) { |
| 27 | + public static function getTemplateDisplayValues( $templateXML ) { |
20 | 28 | foreach ( $templateXML->children() as $tag => $child ) { |
21 | 29 | if ( $tag == "semanticinternalobjects_MainProperty" ) { |
22 | 30 | $propName = $child->attributes()->name; |
23 | 31 | $values = array(); |
24 | | - $text_object['sio'] = array( 'Internal property', $propName, '#FF8', $values ); |
25 | | - break; |
| 32 | + return array( $propName, $values ); |
26 | 33 | } |
27 | 34 | } |
28 | | - return true; |
| 35 | + return null; |
29 | 36 | } |
30 | 37 | |
31 | 38 | /** |
32 | 39 | * Constructs XML for the SIO property, based on what was submitted |
33 | 40 | * in the 'edit schema' form. |
34 | 41 | */ |
35 | | - function getTemplateXML( $request, &$templateXMLFromExtensions ) { |
| 42 | + public static function createTemplateXMLFromForm() { |
| 43 | + global $wgRequest; |
| 44 | + |
36 | 45 | $fieldNum = -1; |
37 | 46 | $xmlPerTemplate = array(); |
38 | | - foreach ( $request->getValues() as $var => $val ) { |
| 47 | + foreach ( $wgRequest->getValues() as $var => $val ) { |
39 | 48 | if ( substr( $var, 0, 18 ) == 'sio_property_name_' ) { |
40 | 49 | $templateNum = substr( $var, 18 ); |
41 | 50 | $xml = '<semanticinternalobjects_MainProperty name="' . $val . '" />'; |
42 | 51 | $xmlPerTemplate[$templateNum] = $xml; |
43 | 52 | } |
44 | 53 | } |
45 | | - $templateXMLFromExtensions['sio'] = $xmlPerTemplate; |
46 | | - return true; |
| 54 | + return $xmlPerTemplate; |
47 | 55 | } |
48 | 56 | |
49 | 57 | /** |
50 | 58 | * Returns the HTML necessary for getting information about the |
51 | 59 | * semantic property within the Page Schemas 'editschema' page. |
52 | 60 | */ |
53 | | - function getTemplateHTML( $psTemplate, &$templateHTMLFromExtensions ) { |
| 61 | + public static function getTemplateEditingHTML( $psTemplate) { |
54 | 62 | $prop_array = array(); |
55 | 63 | $hasExistingValues = false; |
56 | 64 | if ( !is_null( $psTemplate ) ) { |
57 | | - $sio_array = $psTemplate->getObject( 'semanticinternalobjects_MainProperty' ); |
58 | | - if ( array_key_exists( 'sio', $sio_array ) ) { |
59 | | - $prop_array = $sio_array['sio']; |
| 65 | + $prop_array = $psTemplate->getObject( 'semanticinternalobjects_MainProperty' ); |
| 66 | + if ( !is_null( $prop_array ) ) { |
60 | 67 | $hasExistingValues = true; |
61 | 68 | } |
62 | 69 | } |
63 | 70 | $text = '<p>' . 'Name of property to connect this template\'s fields to the rest of the page (should only be used if this template can have multiple instances):' . ' '; |
64 | | - if ( array_key_exists( 'name', $prop_array ) ) { |
65 | | - $propName = $prop_array['name']; |
66 | | - } else { |
67 | | - $propName = null; |
68 | | - } |
| 71 | + $propName = PageSchemas::getValueFromObject( $prop_array, 'name' ); |
69 | 72 | $text .= Html::input( 'sio_property_name_num', $propName, array( 'size' => 15 ) ) . "\n"; |
70 | 73 | |
71 | | - $templateHTMLFromExtensions['sio'] = array( 'Internal property', '#FF8', $text, $hasExistingValues ); |
72 | | - |
73 | | - return true; |
| 74 | + return array( $text, $hasExistingValues ); |
74 | 75 | } |
75 | 76 | |
76 | 77 | /** |
77 | 78 | * Returns the property based on the XML passed from the Page Schemas |
78 | 79 | * extension. |
79 | 80 | */ |
80 | | - function createPageSchemasObject( $objectName, $xmlForField, &$object ) { |
81 | | - $sio_array = array(); |
82 | | - if ( $objectName == "semanticinternalobjects_MainProperty" ) { |
83 | | - foreach ( $xmlForField->children() as $tag => $child ) { |
84 | | - if ( $tag == $objectName ) { |
| 81 | + public static function createPageSchemasObject( $tagName, $xml ) { |
| 82 | + if ( $tagName == "semanticinternalobjects_MainProperty" ) { |
| 83 | + foreach ( $xml->children() as $tag => $child ) { |
| 84 | + if ( $tag == $tagName ) { |
| 85 | + $sio_array = array(); |
85 | 86 | $propName = $child->attributes()->name; |
86 | 87 | $sio_array['name'] = (string)$propName; |
87 | | - $count = 0; |
88 | 88 | foreach ( $child->children() as $prop => $value ) { |
89 | 89 | $sio_array[$prop] = (string)$value; |
90 | 90 | } |
91 | | - $object['sio'] = $sio_array; |
92 | | - return true; |
| 91 | + return $sio_array; |
93 | 92 | } |
94 | 93 | } |
95 | 94 | } |
96 | | - return true; |
| 95 | + return null; |
97 | 96 | } |
98 | 97 | |
99 | 98 | function getInternalObjectPropertyName ( $psTemplate ) { |
100 | 99 | // TODO - there should be a more direct way to get |
101 | 100 | // this data. |
102 | | - $sioPropertyObj = $psTemplate->getObject( 'semanticinternalobjects_MainProperty' ); |
103 | | - if ( !array_key_exists( 'sio', $sioPropertyObj ) ) { |
104 | | - return null; |
105 | | - } |
106 | | - if ( !array_key_exists( 'name', $sioPropertyObj['sio'] ) ) { |
107 | | - return null; |
108 | | - } |
109 | | - return $sioPropertyObj['sio']['name']; |
| 101 | + $sioPropertyArray = $psTemplate->getObject( 'semanticinternalobjects_MainProperty' ); |
| 102 | + return PageSchemas::getValueFromObject( $sioPropertyArray, 'name' ); |
110 | 103 | } |
111 | 104 | |
112 | | - function getPageList( $pageSchemaObj , &$genPageList ) { |
| 105 | + public static function getPagesToGenerate( $pageSchemaObj ) { |
| 106 | + $pagesToGenerate = array(); |
113 | 107 | $psTemplates = $pageSchemaObj->getTemplates(); |
114 | 108 | foreach ( $psTemplates as $psTemplate ) { |
115 | 109 | $sioPropertyName = self::getInternalObjectPropertyName( $psTemplate ); |
116 | 110 | if ( is_null( $sioPropertyName ) ) { |
117 | 111 | continue; |
118 | 112 | } |
119 | | - $genPageList[] = Title::makeTitleSafe( SMW_NS_PROPERTY, $sioPropertyName ); |
| 113 | + $pagesToGenerate[] = Title::makeTitleSafe( SMW_NS_PROPERTY, $sioPropertyName ); |
120 | 114 | } |
121 | | - return true; |
| 115 | + return $pagesToGenerate; |
122 | 116 | } |
123 | 117 | |
124 | | - function generatePages( $psSchemaObj, $selectedPageList ) { |
125 | | - global $smwgContLang; |
| 118 | + public static function generatePages( $pageSchemaObj, $selectedPages ) { |
| 119 | + global $smwgContLang, $wgUser; |
126 | 120 | |
127 | 121 | $datatypeLabels = $smwgContLang->getDatatypeLabels(); |
128 | 122 | $pageTypeLabel = $datatypeLabels['_wpg']; |
129 | 123 | |
130 | | - $psTemplates = $psSchemaObj->getTemplates(); |
| 124 | + $jobs = array(); |
| 125 | + $jobParams = array(); |
| 126 | + $jobParams['user_id'] = $wgUser->getId(); |
| 127 | + |
| 128 | + $psTemplates = $pageSchemaObj->getTemplates(); |
131 | 129 | foreach ( $psTemplates as $psTemplate ) { |
132 | 130 | $sioPropertyName = self::getInternalObjectPropertyName( $psTemplate ); |
133 | 131 | if ( is_null( $sioPropertyName ) ) { |
134 | 132 | continue; |
135 | 133 | } |
136 | | - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $sioPropertyName ); |
137 | | - $key_title = PageSchemas::titleString( $title ); |
138 | | - if ( !in_array( $key_title, $selectedPageList ) ) { |
| 134 | + $propTitle = Title::makeTitleSafe( SMW_NS_PROPERTY, $sioPropertyName ); |
| 135 | + if ( !in_array( $propTitle, $selectedPages ) ) { |
139 | 136 | continue; |
140 | 137 | } |
141 | | - SMWPageSchemas::createProperty( $sioPropertyName, $pageTypeLabel, null ); |
| 138 | + $jobParams['page_text'] = SMWPageSchemas::createPropertyText( $pageTypeLabel, null ); |
| 139 | + $jobs[] = new PSCreatePageJob( $propTitle, $jobParams ); |
142 | 140 | } |
143 | | - return true; |
| 141 | + Job::batchInsert( $jobs ); |
144 | 142 | } |
145 | 143 | } |
Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php |
— | — | @@ -29,13 +29,12 @@ |
30 | 30 | $wgHooks['TitleMoveComplete'][] = 'SIOHandler::handlePageMove'; |
31 | 31 | $wgHooks['smwRefreshDataJobs'][] = 'SIOHandler::handleRefreshingOfInternalObjects'; |
32 | 32 | $wgHooks['smwAddToRDFExport'][] = 'SIOSQLStore::createRDF'; |
33 | | -$wgHooks['PageSchemasGetTemplateHTML'][] = 'SIOPageSchemas::getTemplateHTML'; |
34 | | -$wgHooks['PageSchemasGetTemplateXML'][] = 'SIOPageSchemas::getTemplateXML'; |
35 | | -$wgHooks['PageSchemasGetTemplateDisplayInfo'][] = 'SIOPageSchemas::getPropertyDisplayInfo'; |
36 | | -$wgHooks['PageSchemasGetObject'][] = 'SIOPageSchemas::createPageSchemasObject'; |
37 | | -$wgHooks['PageSchemasGetPageList'][] = 'SIOPageSchemas::getPageList'; |
38 | | -$wgHooks['PageSchemasGeneratePages'][] = 'SIOPageSchemas::generatePages'; |
39 | 33 | |
| 34 | +// Register class with the Page Schemas extension |
| 35 | +if ( isset( $wgPageSchemasHandlerClasses ) ) { |
| 36 | + $wgPageSchemasHandlerClasses[] = 'SIOPageSchemas'; |
| 37 | +} |
| 38 | + |
40 | 39 | $siogIP = dirname( __FILE__ ); |
41 | 40 | $wgExtensionMessagesFiles['SemanticInternalObjects'] = $siogIP . '/SemanticInternalObjects.i18n.php'; |
42 | 41 | $wgAutoloadClasses['SIOHandler'] = $siogIP . '/SemanticInternalObjects_body.php'; |