r88836 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88835‎ | r88836 | r88837 >
Date:20:44, 25 May 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
Update to work with SMW 1.6
Modified paths:
  • /trunk/extensions/SemanticGlossary/SemanticGlossary.php (modified) (history)
  • /trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php (modified) (history)
  • /trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
@@ -251,15 +251,18 @@
252252 ) {
253253
254254 $this -> updateData( $page, array(
255 - '___glt' => $newTerm,
256 - '___gld' => $newDefinition,
257 - '___gll' => $newLink,
 255+ '___glt' => ($newTerm ? new SMWDIString( $newTerm ) : null),
 256+ '___gld' => ($newDefinition ? new SMWDIBlob( $newDefinition ) : null),
 257+ '___gll' => ($newLink ? new SMWDIString( $newLink ) : null)
258258 ) );
259259
260260 // issue a warning if the original definition is on a real page
261 - if ( $page -> getArticleID() != 0 ) {
262 - $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-storedtermdefinedinarticle', array( $oldTerm, $page -> getPrefixedText() ) )
263 - , SemanticGlossaryMessageLog::SG_WARNING
 261+
 262+ $title = $page -> getTitle();
 263+ if ( $title -> isKnown() ) {
 264+ $this -> mMessages -> addMessage(
 265+ wfMsg( 'semanticglossary-storedtermdefinedinarticle', array( $oldTerm, $title -> getPrefixedText() ) ),
 266+ SemanticGlossaryMessageLog::SG_WARNING
264267 );
265268 } else {
266269 $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-termchanged', array( $oldTerm ) ), SemanticGlossaryMessageLog::SG_NOTICE );
@@ -283,22 +286,13 @@
284287 $newDefinition = $wgRequest -> getText( 'newdefinition' );
285288 $newLink = $wgRequest -> getText( 'newlink' );
286289
287 - $termNumber = 1;
 290+ $page = $this -> findNextPageName();
288291
289 - // find unused SMW page
290 - do {
291 - $page = SMWWikiPageValue::makePage( "GlossaryTerm#$termNumber", 0 );
292 - $termNumber++;
293 - } while ( count( smwfGetStore() -> getProperties( $page ) ) > 0 );
294 -
295292 // store data
296293 $this -> updateData( $page, array(
297 - '___glt' => $newTerm,
298 - '___gld' => $newDefinition,
299 - '___gll' => $newLink,
300 -// wfMsg( 'semanticglossary-prop-glt' ) => $newTerm,
301 -// wfMsg( 'semanticglossary-prop-gld' ) => $newDefinition,
302 -// wfMsg( 'semanticglossary-prop-gll' ) => $newLink,
 294+ '___glt' => ($newTerm ? new SMWDIString( $newTerm ) : null),
 295+ '___gld' => ($newDefinition ? new SMWDIBlob( $newDefinition ) : null),
 296+ '___gll' => ($newLink ? new SMWDIString( $newLink ) : null)
303297 ) );
304298
305299 $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-termadded', array( $newTerm ) ), SemanticGlossaryMessageLog::SG_NOTICE );
@@ -327,14 +321,14 @@
328322 '___gll' => null,
329323 ) );
330324
331 - $title = $page -> getTitle();
332 -
333325 $oldTerm = $wgRequest -> getVal( $pageString . ':term' );
334326
335 - if ( $title && $title -> exists() ) {
 327+ $title = $page -> getTitle();
 328+ if ( $title && $title -> isKnown() ) {
336329
337 - $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-deletedtermdefinedinarticle', array( $oldTerm, $page -> getPrefixedText() ) )
338 - , SemanticGlossaryMessageLog::SG_WARNING
 330+ $this -> mMessages -> addMessage(
 331+ wfMsg( 'semanticglossary-deletedtermdefinedinarticle', array( $oldTerm, $title -> getPrefixedText() ) ),
 332+ SemanticGlossaryMessageLog::SG_WARNING
339333 );
340334 } else {
341335 $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-termdeleted', array( $oldTerm ) ), SemanticGlossaryMessageLog::SG_NOTICE );
@@ -345,12 +339,12 @@
346340
347341 protected function getPropertyFromData ( SMWSemanticData &$pageData, $propertyName ) {
348342
349 - $property = SMWPropertyValue::makeProperty( $propertyName );
 343+ $property = new SMWDIProperty( $propertyName );
350344 $propertyValues = $pageData -> getPropertyValues( $property );
351345
352346 if ( count( $propertyValues ) == 1 ) {
353347
354 - return $propertyValues[ 0 ] -> getShortWikiText();
 348+ return $propertyValues[ 0 ] -> getString();
355349 } else if ( count( $propertyValues ) > 1 ) {
356350
357351 if ( count( $propertyValues ) > 1 ) {
@@ -371,11 +365,44 @@
372366 preg_match( '/^(.*):(.*):(.*)$/', $pageString, $matches );
373367
374368 // create SMWWikiPageValue (SMW's wiki page representation)
375 - return SMWWikiPageValue::makePage( $matches[ 3 ], $matches[ 2 ], '', $matches[ 1 ] );
 369+ return new SMWDIWikiPage( $matches[ 3 ], $matches[ 2 ], $matches[ 1 ] );
376370 }
377371
378 - protected function updateData ( SMWWikiPageValue &$page, array $data ) {
 372+ // find unused SMW page
 373+ protected function findNextPageName () {
379374
 375+ $termPages = smwfGetStore() -> getAllPropertySubjects( new SMWDIProperty( '___glt' ) );
 376+ $defPages = smwfGetStore() -> getAllPropertySubjects( new SMWDIProperty( '___gld' ) );
 377+ $linkPages = smwfGetStore() -> getAllPropertySubjects( new SMWDIProperty( '___gll' ) );
 378+
 379+ $pages = array( );
 380+
 381+ foreach ( $termPages as $page ) {
 382+ $pages[ $page -> getDBkey() ] = $page -> getDBkey();
 383+ }
 384+
 385+ foreach ( $defPages as $page ) {
 386+ $pages[ $page -> getDBkey() ] = $page -> getDBkey();
 387+ }
 388+
 389+ foreach ( $linkPages as $page ) {
 390+ $pages[ $page -> getDBkey() ] = $page -> getDBkey();
 391+ }
 392+
 393+ $termNumber = count( $pages );
 394+
 395+
 396+ while ( array_key_exists( "GlossaryTerm#$termNumber", $pages ) ) {
 397+ $termNumber++;
 398+ }
 399+
 400+ return new SMWDIWikiPage( "GlossaryTerm#$termNumber", NS_MAIN, '' );
 401+
 402+ exit ();
 403+ }
 404+
 405+ protected function updateData ( SMWDIWikiPage &$page, array $data ) {
 406+
380407 $newData = new SMWSemanticData( $page, false );
381408
382409 $oldData = smwfGetStore() -> getSemanticData( $page );
@@ -384,16 +411,15 @@
385412 // get properties, replace as requested, retain other properties
386413 foreach ( $oldProps as $property ) {
387414
388 - $propertyID = $property -> getPropertyID();
 415+ $propertyID = $property -> getKey();
389416
390417 if ( array_key_exists( $propertyID, $data ) ) {
391418
392 -
393419 // set new data if defined, else ignore property (i.e. delete property from page)
394420 if ( $data[ $propertyID ] != null ) {
395421
396 - $value = SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
397 - $newData -> addPropertyObjectValue( $property, $value );
 422+// $value = SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
 423+ $newData -> addPropertyObjectValue( $property, $data[ $propertyID ] );
398424 }
399425
400426 unset( $data[ $propertyID ] );
@@ -413,9 +439,9 @@
414440 // set new data if defined, else ignore property (i.e. do not set property on this page)
415441 if ( $data[ $propertyID ] != null ) {
416442
417 - $property = SMWPropertyValue::makeProperty( $propertyID );
418 - $value = SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
419 - $newData -> addPropertyObjectValue( $property, $value );
 443+ $property = new SMWDIProperty( $propertyID );
 444+// $value = SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
 445+ $newData -> addPropertyObjectValue( $property, $data[ $propertyID ] );
420446 }
421447
422448 unset( $data[ $propertyID ] );
Index: trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
@@ -30,10 +30,15 @@
3131 */
3232 static function parse( &$parser, &$text ) {
3333
 34+ wfProfileIn( __METHOD__ );
 35+
3436 $sl = new SemanticGlossaryParser();
3537 $sl -> realParse( $parser, $text );
3638
 39+ wfProfileOut( __METHOD__ );
 40+
3741 return true;
 42+
3843 }
3944
4045 /**
@@ -45,10 +50,12 @@
4651
4752 global $smwgQDefaultNamespaces;
4853
 54+ wfProfileIn( __METHOD__ );
 55+
4956 $store = smwfGetStore(); // default store
5057
5158 // Create query
52 - $desc = new SMWSomeProperty(SMWPropertyValue::makeProperty( '___glt' ), new SMWThingDescription());
 59+ $desc = new SMWSomeProperty(new SMWDIProperty( '___glt' ), new SMWThingDescription());
5360 $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' ) ));
5461 $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' ) ));
5562 $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' ) ));
@@ -93,7 +100,7 @@
94101 continue;
95102 }
96103
97 - $source = $subject -> getDBkeys();
 104+ $source = array( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getDBkey() );
98105
99106 if ( array_key_exists( $term, $result ) ) {
100107 $result[ $term ] -> addDefinition( $definition, $link, $source );
@@ -102,6 +109,8 @@
103110 }
104111 }
105112
 113+ wfProfileOut( __METHOD__ );
 114+
106115 return $result;
107116 }
108117
@@ -118,6 +127,8 @@
119128
120129 global $wgRequest, $sggSettings;
121130
 131+ wfProfileIn( __METHOD__ );
 132+
122133 $action = $wgRequest -> getVal( 'action', 'view' );
123134 if ( $text == null || $text == '' || $action == "edit" || $action == "ajax" || isset( $_POST[ 'wpPreview' ] ) )
124135 return true;
@@ -149,7 +160,7 @@
150161
151162 for ( $pos = 0; $pos < $nb; $pos++ ) {
152163
153 - $el = &$elements -> item( $pos );
 164+ $el = $elements -> item( $pos );
154165
155166 if ( strlen( $el -> nodeValue ) < $min )
156167 continue;
@@ -202,6 +213,8 @@
203214 $this -> loadModules( $parser );
204215 }
205216
 217+ wfProfileOut( __METHOD__ );
 218+
206219 return true;
207220 }
208221
Index: trunk/extensions/SemanticGlossary/SemanticGlossary.php
@@ -116,20 +116,15 @@
117117
118118
119119 function SemanticGlossaryRegisterProperties () {
120 -// SMWPropertyValue::registerProperty( '___glt', '_str', false , true );
121 -// SMWPropertyValue::registerProperty( '___gld', '_txt', false , true );
122 -// SMWPropertyValue::registerProperty( '___gll', '_str', false , true );
123 -
124 - SMWPropertyValue::registerProperty( '___glt', '_str', SG_PROP_GLT, true );
125 - SMWPropertyValue::registerProperty( '___gld', '_txt', SG_PROP_GLD, true );
126 - SMWPropertyValue::registerProperty( '___gll', '_str', SG_PROP_GLL, true );
127 -
 120+ SMWDIProperty::registerProperty( '___glt', '_str', SG_PROP_GLT, true );
 121+ SMWDIProperty::registerProperty( '___gld', '_txt', SG_PROP_GLD, true );
 122+ SMWDIProperty::registerProperty( '___gll', '_str', SG_PROP_GLL, true );
128123 return true;
129124 }
130125
131126 function SemanticGlossaryRegisterPropertyAliases () {
132 - SMWPropertyValue::registerPropertyAlias( '___glt', wfMsg( 'semanticglossary-prop-glt' ) );
133 - SMWPropertyValue::registerPropertyAlias( '___gld', wfMsg( 'semanticglossary-prop-gld' ) );
134 - SMWPropertyValue::registerPropertyAlias( '___gll', wfMsg( 'semanticglossary-prop-gll' ) );
 127+ SMWDIProperty::registerPropertyAlias( '___glt', wfMsg( 'semanticglossary-prop-glt' ) );
 128+ SMWDIProperty::registerPropertyAlias( '___gld', wfMsg( 'semanticglossary-prop-gld' ) );
 129+ SMWDIProperty::registerPropertyAlias( '___gll', wfMsg( 'semanticglossary-prop-gll' ) );
135130 return true;
136131 }

Status & tagging log