r100010 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100009‎ | r100010 | r100011 >
Date:01:30, 17 October 2011
Author:yaron
Status:deferred
Tags:
Comment:
Modified to reflect changes in Page Schemas v0.3
Modified paths:
  • /trunk/extensions/SemanticInternalObjects/SIO_PageSchemas.php (modified) (history)
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticInternalObjects/SIO_PageSchemas.php
@@ -9,136 +9,134 @@
1010 * @ingroup SIO
1111 */
1212
13 -class SIOPageSchemas {
 13+class SIOPageSchemas extends PSExtensionHandler {
1414
 15+ public static function getDisplayColor() {
 16+ return '#FF8';
 17+ }
 18+
 19+ public static function getTemplateDisplayString() {
 20+ return 'Internal property';
 21+ }
 22+
1523 /**
1624 * Returns the display info for the property (if any is defined)
1725 * for a single field in the Page Schemas XML.
1826 */
19 - function getPropertyDisplayInfo( $templateXML, &$text_object ) {
 27+ public static function getTemplateDisplayValues( $templateXML ) {
2028 foreach ( $templateXML->children() as $tag => $child ) {
2129 if ( $tag == "semanticinternalobjects_MainProperty" ) {
2230 $propName = $child->attributes()->name;
2331 $values = array();
24 - $text_object['sio'] = array( 'Internal property', $propName, '#FF8', $values );
25 - break;
 32+ return array( $propName, $values );
2633 }
2734 }
28 - return true;
 35+ return null;
2936 }
3037
3138 /**
3239 * Constructs XML for the SIO property, based on what was submitted
3340 * in the 'edit schema' form.
3441 */
35 - function getTemplateXML( $request, &$templateXMLFromExtensions ) {
 42+ public static function createTemplateXMLFromForm() {
 43+ global $wgRequest;
 44+
3645 $fieldNum = -1;
3746 $xmlPerTemplate = array();
38 - foreach ( $request->getValues() as $var => $val ) {
 47+ foreach ( $wgRequest->getValues() as $var => $val ) {
3948 if ( substr( $var, 0, 18 ) == 'sio_property_name_' ) {
4049 $templateNum = substr( $var, 18 );
4150 $xml = '<semanticinternalobjects_MainProperty name="' . $val . '" />';
4251 $xmlPerTemplate[$templateNum] = $xml;
4352 }
4453 }
45 - $templateXMLFromExtensions['sio'] = $xmlPerTemplate;
46 - return true;
 54+ return $xmlPerTemplate;
4755 }
4856
4957 /**
5058 * Returns the HTML necessary for getting information about the
5159 * semantic property within the Page Schemas 'editschema' page.
5260 */
53 - function getTemplateHTML( $psTemplate, &$templateHTMLFromExtensions ) {
 61+ public static function getTemplateEditingHTML( $psTemplate) {
5462 $prop_array = array();
5563 $hasExistingValues = false;
5664 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 ) ) {
6067 $hasExistingValues = true;
6168 }
6269 }
6370 $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' );
6972 $text .= Html::input( 'sio_property_name_num', $propName, array( 'size' => 15 ) ) . "\n";
7073
71 - $templateHTMLFromExtensions['sio'] = array( 'Internal property', '#FF8', $text, $hasExistingValues );
72 -
73 - return true;
 74+ return array( $text, $hasExistingValues );
7475 }
7576
7677 /**
7778 * Returns the property based on the XML passed from the Page Schemas
7879 * extension.
7980 */
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();
8586 $propName = $child->attributes()->name;
8687 $sio_array['name'] = (string)$propName;
87 - $count = 0;
8888 foreach ( $child->children() as $prop => $value ) {
8989 $sio_array[$prop] = (string)$value;
9090 }
91 - $object['sio'] = $sio_array;
92 - return true;
 91+ return $sio_array;
9392 }
9493 }
9594 }
96 - return true;
 95+ return null;
9796 }
9897
9998 function getInternalObjectPropertyName ( $psTemplate ) {
10099 // TODO - there should be a more direct way to get
101100 // 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' );
110103 }
111104
112 - function getPageList( $pageSchemaObj , &$genPageList ) {
 105+ public static function getPagesToGenerate( $pageSchemaObj ) {
 106+ $pagesToGenerate = array();
113107 $psTemplates = $pageSchemaObj->getTemplates();
114108 foreach ( $psTemplates as $psTemplate ) {
115109 $sioPropertyName = self::getInternalObjectPropertyName( $psTemplate );
116110 if ( is_null( $sioPropertyName ) ) {
117111 continue;
118112 }
119 - $genPageList[] = Title::makeTitleSafe( SMW_NS_PROPERTY, $sioPropertyName );
 113+ $pagesToGenerate[] = Title::makeTitleSafe( SMW_NS_PROPERTY, $sioPropertyName );
120114 }
121 - return true;
 115+ return $pagesToGenerate;
122116 }
123117
124 - function generatePages( $psSchemaObj, $selectedPageList ) {
125 - global $smwgContLang;
 118+ public static function generatePages( $pageSchemaObj, $selectedPages ) {
 119+ global $smwgContLang, $wgUser;
126120
127121 $datatypeLabels = $smwgContLang->getDatatypeLabels();
128122 $pageTypeLabel = $datatypeLabels['_wpg'];
129123
130 - $psTemplates = $psSchemaObj->getTemplates();
 124+ $jobs = array();
 125+ $jobParams = array();
 126+ $jobParams['user_id'] = $wgUser->getId();
 127+
 128+ $psTemplates = $pageSchemaObj->getTemplates();
131129 foreach ( $psTemplates as $psTemplate ) {
132130 $sioPropertyName = self::getInternalObjectPropertyName( $psTemplate );
133131 if ( is_null( $sioPropertyName ) ) {
134132 continue;
135133 }
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 ) ) {
139136 continue;
140137 }
141 - SMWPageSchemas::createProperty( $sioPropertyName, $pageTypeLabel, null );
 138+ $jobParams['page_text'] = SMWPageSchemas::createPropertyText( $pageTypeLabel, null );
 139+ $jobs[] = new PSCreatePageJob( $propTitle, $jobParams );
142140 }
143 - return true;
 141+ Job::batchInsert( $jobs );
144142 }
145143 }
Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php
@@ -29,13 +29,12 @@
3030 $wgHooks['TitleMoveComplete'][] = 'SIOHandler::handlePageMove';
3131 $wgHooks['smwRefreshDataJobs'][] = 'SIOHandler::handleRefreshingOfInternalObjects';
3232 $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';
3933
 34+// Register class with the Page Schemas extension
 35+if ( isset( $wgPageSchemasHandlerClasses ) ) {
 36+ $wgPageSchemasHandlerClasses[] = 'SIOPageSchemas';
 37+}
 38+
4039 $siogIP = dirname( __FILE__ );
4140 $wgExtensionMessagesFiles['SemanticInternalObjects'] = $siogIP . '/SemanticInternalObjects.i18n.php';
4241 $wgAutoloadClasses['SIOHandler'] = $siogIP . '/SemanticInternalObjects_body.php';