Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php |
— | — | @@ -1,13 +1,10 @@ |
2 | 2 | <?php |
3 | | -/** |
4 | | - * @author Yaron Koren |
5 | | - */ |
6 | 3 | |
7 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
8 | | - |
9 | 4 | /** |
10 | 5 | * Class that holds information on a single internal object, including all |
11 | 6 | * its properties. |
| 7 | + * |
| 8 | + * @author Yaron Koren |
12 | 9 | */ |
13 | 10 | class SIOInternalObject { |
14 | 11 | protected $mMainTitle; |
— | — | @@ -75,6 +72,7 @@ |
76 | 73 | function __construct($name, $namespace) { |
77 | 74 | $this->mSIOTitle = new SIOTitle( $name, $namespace ); |
78 | 75 | } |
| 76 | + |
79 | 77 | function getExportData() { |
80 | 78 | global $smwgNamespace; |
81 | 79 | return new SMWExpData( new SMWExpResource( SIOExporter::getResolverURL() . $this->mSIOTitle->getPrefixedURL() ) ); |
— | — | @@ -106,6 +104,7 @@ |
107 | 105 | * protected, and thus can't be accessed externally. |
108 | 106 | */ |
109 | 107 | class SIOSQLStore extends SMWSQLStore2 { |
| 108 | + |
110 | 109 | static function deleteDataForPage( $subject ) { |
111 | 110 | $pageName = $subject->getDBKey(); |
112 | 111 | $namespace = $subject->getNamespace(); |
— | — | @@ -120,6 +119,7 @@ |
121 | 120 | 'smw_title LIKE ' . $db->addQuotes( $pageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $namespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ), |
122 | 121 | 'SIO::getSMWPageObjectIDs' |
123 | 122 | ); |
| 123 | + |
124 | 124 | while ( $row = $db->fetchObject( $res ) ) { |
125 | 125 | $idsForDeletion[] = $row->smw_id; |
126 | 126 | } |
— | — | @@ -154,6 +154,7 @@ |
155 | 155 | // set all the properties pointing from this internal object |
156 | 156 | foreach ( $internalObject->getPropertyValuePairs() as $propertyValuePair ) { |
157 | 157 | list( $property, $value ) = $propertyValuePair; |
| 158 | + |
158 | 159 | // handling changed in SMW 1.5 |
159 | 160 | if ( method_exists( 'SMWSQLStore2', 'findPropertyTableID' ) ) { |
160 | 161 | $tableid = SMWSQLStore2::findPropertyTableID( $property ); |
— | — | @@ -169,6 +170,7 @@ |
170 | 171 | $isText = ( $mode == SMW_SQL2_TEXT2 ); |
171 | 172 | $isCoords = false; |
172 | 173 | } |
| 174 | + |
173 | 175 | if ( $isRelation ) { |
174 | 176 | $upRels2[] = array( |
175 | 177 | 's_id' => $ioID, |
— | — | @@ -182,6 +184,7 @@ |
183 | 185 | } else { |
184 | 186 | $valueNum = $value->getNumericValue(); |
185 | 187 | } |
| 188 | + |
186 | 189 | $upAtts2[] = array( |
187 | 190 | 's_id' => $ioID, |
188 | 191 | 'p_id' => $this->makeSMWPropertyID( $property ), |
— | — | @@ -206,6 +209,7 @@ |
207 | 210 | ); |
208 | 211 | } |
209 | 212 | } |
| 213 | + |
210 | 214 | return array( $upRels2, $upAtts2, $upText2, $upCoords ); |
211 | 215 | } |
212 | 216 | |
— | — | @@ -228,6 +232,7 @@ |
229 | 233 | 'smw_title LIKE ' . $db->addQuotes( $pageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $namespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ), |
230 | 234 | 'SIO::getSMWPageObjectIDs' |
231 | 235 | ); |
| 236 | + |
232 | 237 | while ( $row = $db->fetchObject( $res ) ) { |
233 | 238 | $value = new SIOInternalObjectValue( $row->smw_title, $row->smw_namespace ); |
234 | 239 | $semdata = new SMWSemanticData( $value, false ); |
— | — | @@ -238,8 +243,10 @@ |
239 | 244 | $semdata->addPropertyStubValue( reset( $d ), end( $d ) ); |
240 | 245 | } |
241 | 246 | } |
| 247 | + |
242 | 248 | $rdfDataArray[] = SMWExporter::makeExportData( $semdata, null ); |
243 | 249 | } |
| 250 | + |
244 | 251 | return true; |
245 | 252 | } |
246 | 253 | } |
— | — | @@ -269,8 +276,10 @@ |
270 | 277 | if ( ! empty( self::$mCurPageFullName ) ) { |
271 | 278 | self::$mHandledPages[] = self::$mCurPageFullName; |
272 | 279 | } |
| 280 | + |
273 | 281 | self::$mCurPageFullName = ''; |
274 | 282 | self::$mInternalObjectIndex = 1; |
| 283 | + |
275 | 284 | return true; |
276 | 285 | } |
277 | 286 | |
— | — | @@ -296,14 +305,17 @@ |
297 | 306 | self::$mCurPageFullName = $mainPageFullName; |
298 | 307 | self::$mInternalObjectIndex = 1; |
299 | 308 | } |
| 309 | + |
300 | 310 | $curObjectNum = self::$mInternalObjectIndex; |
301 | 311 | $params = func_get_args(); |
302 | 312 | array_shift( $params ); // we already know the $parser... |
303 | 313 | $internalObject = new SIOInternalObject( $title, $curObjectNum ); |
304 | 314 | $objToPagePropName = array_shift( $params ); |
305 | 315 | $internalObject->addPropertyAndValue( $objToPagePropName, self::$mCurPageFullName ); |
| 316 | + |
306 | 317 | foreach ( $params as $param ) { |
307 | | - $parts = explode( "=", trim( $param ), 2 ); |
| 318 | + $parts = explode( '=', trim( $param ), 2 ); |
| 319 | + |
308 | 320 | if ( count( $parts ) == 2 ) { |
309 | 321 | $key = $parts[0]; |
310 | 322 | $value = $parts[1]; |
— | — | @@ -312,6 +324,7 @@ |
313 | 325 | if ( substr( $key, - 5 ) == '#list' ) { |
314 | 326 | $key = substr( $key, 0, strlen( $key ) - 5 ); |
315 | 327 | $listValues = explode( ',', $value ); |
| 328 | + |
316 | 329 | foreach ( $listValues as $listValue ) { |
317 | 330 | $internalObject->addPropertyAndValue( $key, trim( $listValue ) ); |
318 | 331 | } |
— | — | @@ -320,6 +333,7 @@ |
321 | 334 | } |
322 | 335 | } |
323 | 336 | } |
| 337 | + |
324 | 338 | self::$mInternalObjects[] = $internalObject; |
325 | 339 | } |
326 | 340 | |
— | — | @@ -339,6 +353,7 @@ |
340 | 354 | } else { |
341 | 355 | $results = SMWParserExtensions::getDatesForRecurringEvent( $params ); |
342 | 356 | } |
| 357 | + |
343 | 358 | if ( $results == null ) { |
344 | 359 | return null; |
345 | 360 | } |
— | — | @@ -352,6 +367,7 @@ |
353 | 368 | $objToPagePropName, |
354 | 369 | "$property=$date_string" |
355 | 370 | ); |
| 371 | + |
356 | 372 | $cur_params = array_merge( $first_params, $unused_params ); |
357 | 373 | call_user_func_array( 'SIOHandler::doSetInternal', $cur_params ); |
358 | 374 | } |
— | — | @@ -384,6 +400,7 @@ |
385 | 401 | $allAtts2Inserts = array(); |
386 | 402 | $allText2Inserts = array(); |
387 | 403 | $allCoordsInserts = array(); |
| 404 | + |
388 | 405 | foreach ( self::$mInternalObjects as $internalObject ) { |
389 | 406 | list( $upRels2, $upAtts2, $upText2, $upCoords ) = $sioSQLStore->getStorageSQL( $internalObject ); |
390 | 407 | $allRels2Inserts = array_merge( $allRels2Inserts, $upRels2 ); |
— | — | @@ -408,9 +425,11 @@ |
409 | 426 | if ( count( $allCoordsInserts ) > 0 ) { |
410 | 427 | $db->insert( 'sm_coords', $allCoordsInserts, 'SIO::updateCoordsData' ); |
411 | 428 | } |
| 429 | + |
412 | 430 | // end transaction |
413 | 431 | $db->commit( 'SIO::updatePageData' ); |
414 | 432 | self::$mInternalObjects = array(); |
| 433 | + |
415 | 434 | return true; |
416 | 435 | } |
417 | 436 | |
— | — | @@ -437,9 +456,11 @@ |
438 | 457 | 'smw_title LIKE ' . $db->addQuotes( $oldPageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $oldNamespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ), |
439 | 458 | 'SIO::getTitlesForPageMove' |
440 | 459 | ); |
| 460 | + |
441 | 461 | while ( $row = $db->fetchObject( $res ) ) { |
442 | 462 | $sioNames[] = $row->smw_title; |
443 | 463 | } |
| 464 | + |
444 | 465 | foreach ( $sioNames as $sioName ) { |
445 | 466 | // update the name, and possibly the namespace as well |
446 | 467 | $newSIOName = str_replace( $oldPageName, $newPageName, $sioName ); |
— | — | @@ -450,6 +471,7 @@ |
451 | 472 | 'SIO::updateTitlesForPageMove' |
452 | 473 | ); |
453 | 474 | } |
| 475 | + |
454 | 476 | return true; |
455 | 477 | } |
456 | 478 | |
— | — | @@ -461,15 +483,19 @@ |
462 | 484 | */ |
463 | 485 | static function handleUpdatingOfInternalObjects( &$jobs ) { |
464 | 486 | $uniqueTitles = array(); |
| 487 | + |
465 | 488 | foreach ( $jobs as $i => $job ) { |
466 | 489 | $title = Title::makeTitleSafe( $job->title->getNamespace(), $job->title->getText() ); |
467 | 490 | $id = $title->getArticleID(); |
468 | 491 | $uniqueTitles[$id] = $title; |
469 | 492 | } |
| 493 | + |
470 | 494 | $jobs = array(); |
| 495 | + |
471 | 496 | foreach ( $uniqueTitles as $id => $title ) { |
472 | 497 | $jobs[] = new SMWUpdateJob( $title ); |
473 | 498 | } |
| 499 | + |
474 | 500 | return true; |
475 | 501 | } |
476 | 502 | |
— | — | @@ -483,10 +509,14 @@ |
484 | 510 | static function handleRefreshingOfInternalObjects( &$jobs ) { |
485 | 511 | $allJobs = $jobs; |
486 | 512 | $jobs = array(); |
| 513 | + |
487 | 514 | foreach ( $allJobs as $job ) { |
488 | | - if ( strpos( $job->title->getText(), '#' ) === false ) |
| 515 | + if ( strpos( $job->title->getText(), '#' ) === false ) { |
489 | 516 | $jobs[] = $job; |
| 517 | + } |
490 | 518 | } |
| 519 | + |
491 | 520 | return true; |
492 | 521 | } |
| 522 | + |
493 | 523 | } |