r66936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66935‎ | r66936 | r66937 >
Date:22:51, 26 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Stylezed code, fixed some naming stuff and added FIXMEs for bug 23673
Modified paths:
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php
@@ -10,26 +10,28 @@
1111 * its properties.
1212 */
1313 class SIOInternalObject {
14 - var $main_title;
15 - var $index;
16 - var $property_value_pairs;
 14+ public $mPropertyValuePairs;
 15+
 16+ protected $mMainTitle;
 17+ protected $mIndex;
1718
18 - public function SIOInternalObject( $main_title, $index ) {
19 - $this->main_title = $main_title;
20 - $this->index = $index;
21 - $this->property_value_pairs = array();
 19+ public function SIOInternalObject( $mainTitle, $index ) {
 20+ $this->mMainTitle = $mainTitle;
 21+ $this->mIndex = $index;
 22+ $this->mPropertyValuePairs = array();
2223 }
2324
24 - public function addPropertyAndValue( $prop_name, $value ) {
25 - $property = SMWPropertyValue::makeUserProperty( $prop_name );
26 - $data_value = SMWDataValueFactory::newPropertyObjectValue( $property, $value );
27 - if ( $data_value->isValid() ) {
28 - $this->property_value_pairs[] = array( $property, $data_value );
 25+ public function addPropertyAndValue( $propName, $value ) {
 26+ $property = SMWPropertyValue::makeUserProperty( $propName );
 27+ $dataValue = SMWDataValueFactory::newPropertyObjectValue( $property, $value );
 28+
 29+ if ( $dataValue->isValid() ) {
 30+ $this->mPropertyValuePairs[] = array( $property, $dataValue );
2931 } // else - show an error message?
3032 }
3133
3234 public function getName() {
33 - return $this->main_title->getDBkey() . '#' . $this->index;
 35+ return $this->mMainTitle->getDBkey() . '#' . $this->mIndex;
3436 }
3537 }
3638
@@ -46,21 +48,26 @@
4749 $iw = '';
4850 $db = wfGetDB( DB_SLAVE );
4951 $res = $db->select( 'smw_ids', array( 'smw_id' ), 'smw_title LIKE ' . $db->addQuotes( $page_name . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $namespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ), 'SIO::getSMWPageObjectIDs', array() );
 52+
5053 while ( $row = $db->fetchObject( $res ) ) {
5154 $ids[] = $row->smw_id;
5255 }
 56+
5357 return $ids;
5458 }
5559
5660 function getStorageSQL( $main_page_name, $namespace, $internal_object ) {
5761 $main_page_id = $this->makeSMWPageID( $main_page_name, $namespace, '' );
5862 $io_id = $this->makeSMWPageID( $internal_object->getName(), $namespace, '' );
 63+
5964 $up_rels2 = array();
6065 $up_atts2 = array();
6166 $up_text2 = array();
 67+
6268 // set all the properties pointing from this internal object
63 - foreach ( $internal_object->property_value_pairs as $property_value_pair ) {
 69+ foreach ( $internal_object->mPropertyValuePairs as $property_value_pair ) {
6470 list( $property, $value ) = $property_value_pair;
 71+
6572 // handling changed in SMW 1.5
6673 if ( method_exists( 'SMWSQLStore2', 'findPropertyTableID' ) ) {
6774 $tableid = SMWSQLStore2::findPropertyTableID( $property );
@@ -73,6 +80,7 @@
7481 $is_attribute = ( $mode == SMW_SQL2_ATTS2 );
7582 $is_text = ( $mode == SMW_SQL2_TEXT2 );
7683 }
 84+
7785 if ( $is_relation ) {
7886 $up_rels2[] = array(
7987 's_id' => $io_id,
@@ -81,27 +89,31 @@
8290 );
8391 } elseif ( $is_attribute ) {
8492 $keys = $value->getDBkeys();
 93+
8594 if ( method_exists( $value, 'getValueKey' ) ) {
8695 $value_num = $value->getValueKey();
8796 } else {
8897 $value_num = $value->getNumericValue();
8998 }
 99+
90100 $up_atts2[] = array(
91101 's_id' => $io_id,
92102 'p_id' => $this->makeSMWPropertyID( $property ),
93103 'value_unit' => $value->getUnit(),
94 - 'value_xsd' => $keys[0],
 104+ 'value_xsd' => $keys[0], // FIXME: this fails for all datatypes with more then one value field
95105 'value_num' => $value_num
96106 );
97107 } elseif ( $is_text ) {
98108 $keys = $value->getDBkeys();
 109+
99110 $up_text2[] = array(
100111 's_id' => $io_id,
101112 'p_id' => $this->makeSMWPropertyID( $property ),
102 - 'value_blob' => $keys[0]
 113+ 'value_blob' => $keys[0] // FIXME: this fails for all datatypes with more then one value field
103114 );
104115 }
105116 }
 117+
106118 return array( $up_rels2, $up_atts2, $up_text2 );
107119 }
108120 }
@@ -120,12 +132,14 @@
121133 self::$cur_page_name = '';
122134 self::$cur_page_namespace = 0;
123135 self::$internal_object_index = 1;
 136+
124137 return true;
125138 }
126139
127140 public static function doSetInternal( &$parser ) {
128141 $main_page_name = $parser->getTitle()->getDBKey();
129142 $main_page_namespace = $parser->getTitle()->getNamespace();
 143+
130144 if ( $main_page_name == self::$cur_page_name &&
131145 $main_page_namespace == self::$cur_page_namespace ) {
132146 self::$internal_object_index++;
@@ -134,26 +148,35 @@
135149 self::$cur_page_namespace = $main_page_namespace;
136150 self::$internal_object_index = 1;
137151 }
 152+
138153 $cur_object_num = self::$internal_object_index;
 154+
139155 $params = func_get_args();
140156 array_shift( $params ); // we already know the $parser...
 157+
141158 $internal_object = new SIOInternalObject( $parser->getTitle(), $cur_object_num );
142159 $obj_to_page_prop_name = array_shift( $params );
143160 $main_page_name = $parser->getTitle()->getText();
 161+
144162 if ( ( $ns_text = $parser->getTitle()->getNsText() ) != '' ) {
145163 $main_page_name = $ns_text . ':' . $main_page_name;
146164 }
 165+
147166 $internal_object->addPropertyAndValue( $obj_to_page_prop_name, $main_page_name );
 167+
148168 foreach ( $params as $param ) {
149 - $parts = explode( "=", trim( $param ), 2 );
 169+ $parts = explode( '=', trim( $param ), 2 );
 170+
150171 if ( count( $parts ) == 2 ) {
151172 $key = $parts[0];
152173 $value = $parts[1];
 174+
153175 // if the property name ends with '#list', it's
154176 // a comma-delimited group of values
155177 if ( substr( $key, - 5 ) == '#list' ) {
156178 $key = substr( $key, 0, strlen( $key ) - 5 );
157179 $list_values = explode( ',', $value );
 180+
158181 foreach ( $list_values as $list_value ) {
159182 $internal_object->addPropertyAndValue( $key, trim( $list_value ) );
160183 }
@@ -162,11 +185,13 @@
163186 }
164187 }
165188 }
 189+
166190 self::$internal_objects[] = $internal_object;
167191 }
168192
169193 public static function updateData( $subject ) {
170194 $sio_sql_store = new SIOSQLStore();
 195+
171196 // Find all "pages" in the SMW IDs table that are internal
172197 // objects for this page, and delete their properties from
173198 // the SMW tables.
@@ -179,8 +204,10 @@
180205 $all_rels2_inserts = array();
181206 $all_atts2_inserts = array();
182207 $all_text2_inserts = array();
 208+
183209 foreach ( self::$internal_objects as $internal_object ) {
184210 list( $up_rels2, $up_atts2, $up_text2 ) = $sio_sql_store->getStorageSQL( $page_name, $namespace, $internal_object );
 211+
185212 $all_rels2_inserts = array_merge( $all_rels2_inserts, $up_rels2 );
186213 $all_atts2_inserts = array_merge( $all_atts2_inserts, $up_atts2 );
187214 $all_text2_inserts = array_merge( $all_text2_inserts, $up_text2 );
@@ -189,6 +216,7 @@
190217 // now save everything to the database, in a single transaction
191218 $db = wfGetDB( DB_MASTER );
192219 $db->begin( 'SIO::updatePageData' );
 220+
193221 if ( count( $ids_for_deletion ) > 0 ) {
194222 $ids_string = '(' . implode ( ', ', $ids_for_deletion ) . ')';
195223 $db->delete( 'smw_rels2', array( "(s_id IN $ids_string) OR (o_id IN $ids_string)" ), 'SIO::deleteRels2Data' );
@@ -199,15 +227,20 @@
200228 if ( count( $all_rels2_inserts ) > 0 ) {
201229 $db->insert( 'smw_rels2', $all_rels2_inserts, 'SIO::updateRels2Data' );
202230 }
 231+
203232 if ( count( $all_atts2_inserts ) > 0 ) {
204233 $db->insert( 'smw_atts2', $all_atts2_inserts, 'SIO::updateAtts2Data' );
205234 }
 235+
206236 if ( count( $all_text2_inserts ) > 0 ) {
207237 $db->insert( 'smw_text2', $all_text2_inserts, 'SIO::updateText2Data' );
208238 }
 239+
209240 // end transaction
210241 $db->commit( 'SIO::updatePageData' );
 242+
211243 self::$internal_objects = array();
 244+
212245 return true;
213246 }
214247
@@ -219,15 +252,19 @@
220253 */
221254 static function handleUpdatingOfInternalObjects( &$jobs ) {
222255 $unique_titles = array();
 256+
223257 foreach ( $jobs as $i => $job ) {
224258 $title = Title::makeTitleSafe( $job->title->getNamespace(), $job->title->getText() );
225259 $id = $title->getArticleID();
226260 $unique_titles[$id] = $title;
227261 }
 262+
228263 $jobs = array();
 264+
229265 foreach ( $unique_titles as $id => $title ) {
230266 $jobs[] = new SMWUpdateJob( $title );
231267 }
 268+
232269 return true;
233270 }
234271
@@ -238,13 +275,17 @@
239276 * will be in a single one of these batches so we remove everything updating
240277 * a SIO object instead of filtering them down to unique titles.
241278 */
242 - static function handleRefreshingOfInternalObjects(&$jobs) {
 279+ static function handleRefreshingOfInternalObjects( &$jobs ) {
243280 $all_jobs = $jobs;
244281 $jobs = array();
 282+
245283 foreach ( $all_jobs as $job ) {
246 - if ( strpos( $job->title->getText(), '#' ) === false )
 284+ if ( strpos( $job->title->getText(), '#' ) === false ) {
247285 $jobs[] = $job;
 286+ }
248287 }
 288+
249289 return true;
250290 }
251 -}
 291+
 292+}
\ No newline at end of file

Status & tagging log