http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88836
Revision: 88836
Author: foxtrott
Date: 2011-05-25 20:44:09 +0000 (Wed, 25 May 2011)
Log Message:
-----------
Update to work with SMW 1.6
Modified Paths:
--------------
trunk/extensions/SemanticGlossary/SemanticGlossary.php
trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
Modified: trunk/extensions/SemanticGlossary/SemanticGlossary.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-05-25
20:43:35 UTC (rev 88835)
+++ trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-05-25
20:44:09 UTC (rev 88836)
@@ -116,20 +116,15 @@
function SemanticGlossaryRegisterProperties () {
-// SMWPropertyValue::registerProperty( '___glt', '_str', false , true );
-// SMWPropertyValue::registerProperty( '___gld', '_txt', false , true );
-// SMWPropertyValue::registerProperty( '___gll', '_str', false , true );
-
- SMWPropertyValue::registerProperty( '___glt', '_str', SG_PROP_GLT, true
);
- SMWPropertyValue::registerProperty( '___gld', '_txt', SG_PROP_GLD, true
);
- SMWPropertyValue::registerProperty( '___gll', '_str', SG_PROP_GLL, true
);
-
+ SMWDIProperty::registerProperty( '___glt', '_str', SG_PROP_GLT, true );
+ SMWDIProperty::registerProperty( '___gld', '_txt', SG_PROP_GLD, true );
+ SMWDIProperty::registerProperty( '___gll', '_str', SG_PROP_GLL, true );
return true;
}
function SemanticGlossaryRegisterPropertyAliases () {
- SMWPropertyValue::registerPropertyAlias( '___glt', wfMsg(
'semanticglossary-prop-glt' ) );
- SMWPropertyValue::registerPropertyAlias( '___gld', wfMsg(
'semanticglossary-prop-gld' ) );
- SMWPropertyValue::registerPropertyAlias( '___gll', wfMsg(
'semanticglossary-prop-gll' ) );
+ SMWDIProperty::registerPropertyAlias( '___glt', wfMsg(
'semanticglossary-prop-glt' ) );
+ SMWDIProperty::registerPropertyAlias( '___gld', wfMsg(
'semanticglossary-prop-gld' ) );
+ SMWDIProperty::registerPropertyAlias( '___gll', wfMsg(
'semanticglossary-prop-gll' ) );
return true;
}
Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
2011-05-25 20:43:35 UTC (rev 88835)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
2011-05-25 20:44:09 UTC (rev 88836)
@@ -30,10 +30,15 @@
*/
static function parse( &$parser, &$text ) {
+ wfProfileIn( __METHOD__ );
+
$sl = new SemanticGlossaryParser();
$sl -> realParse( $parser, $text );
+ wfProfileOut( __METHOD__ );
+
return true;
+
}
/**
@@ -45,10 +50,12 @@
global $smwgQDefaultNamespaces;
+ wfProfileIn( __METHOD__ );
+
$store = smwfGetStore(); // default store
// Create query
- $desc = new SMWSomeProperty(SMWPropertyValue::makeProperty(
'___glt' ), new SMWThingDescription());
+ $desc = new SMWSomeProperty(new SMWDIProperty( '___glt' ), new
SMWThingDescription());
$desc -> addPrintRequest(new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' )
));
$desc -> addPrintRequest(new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' )
));
$desc -> addPrintRequest(new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' )
));
@@ -93,7 +100,7 @@
continue;
}
- $source = $subject -> getDBkeys();
+ $source = array( $subject->getDBkey(),
$subject->getNamespace(), $subject->getInterwiki(), $subject->getDBkey() );
if ( array_key_exists( $term, $result ) ) {
$result[ $term ] -> addDefinition( $definition,
$link, $source );
@@ -102,6 +109,8 @@
}
}
+ wfProfileOut( __METHOD__ );
+
return $result;
}
@@ -118,6 +127,8 @@
global $wgRequest, $sggSettings;
+ wfProfileIn( __METHOD__ );
+
$action = $wgRequest -> getVal( 'action', 'view' );
if ( $text == null || $text == '' || $action == "edit" ||
$action == "ajax" || isset( $_POST[ 'wpPreview' ] ) )
return true;
@@ -149,7 +160,7 @@
for ( $pos = 0; $pos < $nb; $pos++ ) {
- $el = &$elements -> item( $pos );
+ $el = $elements -> item( $pos );
if ( strlen( $el -> nodeValue ) < $min )
continue;
@@ -202,6 +213,8 @@
$this -> loadModules( $parser );
}
+ wfProfileOut( __METHOD__ );
+
return true;
}
Modified: trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
===================================================================
--- trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
2011-05-25 20:43:35 UTC (rev 88835)
+++ trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
2011-05-25 20:44:09 UTC (rev 88836)
@@ -251,15 +251,18 @@
) {
$this -> updateData( $page, array(
- '___glt' => $newTerm,
- '___gld' => $newDefinition,
- '___gll' => $newLink,
+ '___glt' => ($newTerm ? new
SMWDIString( $newTerm ) : null),
+ '___gld' => ($newDefinition ?
new SMWDIBlob( $newDefinition ) : null),
+ '___gll' => ($newLink ? new
SMWDIString( $newLink ) : null)
) );
// issue a warning if the original
definition is on a real page
- if ( $page -> getArticleID() != 0 ) {
- $this -> mMessages ->
addMessage( wfMsg( 'semanticglossary-storedtermdefinedinarticle', array(
$oldTerm, $page -> getPrefixedText() ) )
- ,
SemanticGlossaryMessageLog::SG_WARNING
+
+ $title = $page -> getTitle();
+ if ( $title -> isKnown() ) {
+ $this -> mMessages ->
addMessage(
+ wfMsg(
'semanticglossary-storedtermdefinedinarticle', array( $oldTerm, $title ->
getPrefixedText() ) ),
+
SemanticGlossaryMessageLog::SG_WARNING
);
} else {
$this -> mMessages ->
addMessage( wfMsg( 'semanticglossary-termchanged', array( $oldTerm ) ),
SemanticGlossaryMessageLog::SG_NOTICE );
@@ -283,22 +286,13 @@
$newDefinition = $wgRequest -> getText( 'newdefinition' );
$newLink = $wgRequest -> getText( 'newlink' );
- $termNumber = 1;
+ $page = $this -> findNextPageName();
- // find unused SMW page
- do {
- $page = SMWWikiPageValue::makePage(
"GlossaryTerm#$termNumber", 0 );
- $termNumber++;
- } while ( count( smwfGetStore() -> getProperties( $page ) ) > 0
);
-
// store data
$this -> updateData( $page, array(
- '___glt' => $newTerm,
- '___gld' => $newDefinition,
- '___gll' => $newLink,
-// wfMsg( 'semanticglossary-prop-glt' ) => $newTerm,
-// wfMsg( 'semanticglossary-prop-gld' ) => $newDefinition,
-// wfMsg( 'semanticglossary-prop-gll' ) => $newLink,
+ '___glt' => ($newTerm ? new SMWDIString( $newTerm ) :
null),
+ '___gld' => ($newDefinition ? new SMWDIBlob(
$newDefinition ) : null),
+ '___gll' => ($newLink ? new SMWDIString( $newLink ) :
null)
) );
$this -> mMessages -> addMessage( wfMsg(
'semanticglossary-termadded', array( $newTerm ) ),
SemanticGlossaryMessageLog::SG_NOTICE );
@@ -327,14 +321,14 @@
'___gll' => null,
) );
- $title = $page -> getTitle();
-
$oldTerm = $wgRequest -> getVal( $pageString .
':term' );
- if ( $title && $title -> exists() ) {
+ $title = $page -> getTitle();
+ if ( $title && $title -> isKnown() ) {
- $this -> mMessages -> addMessage(
wfMsg( 'semanticglossary-deletedtermdefinedinarticle', array( $oldTerm, $page
-> getPrefixedText() ) )
- ,
SemanticGlossaryMessageLog::SG_WARNING
+ $this -> mMessages -> addMessage(
+ wfMsg(
'semanticglossary-deletedtermdefinedinarticle', array( $oldTerm, $title ->
getPrefixedText() ) ),
+
SemanticGlossaryMessageLog::SG_WARNING
);
} else {
$this -> mMessages -> addMessage(
wfMsg( 'semanticglossary-termdeleted', array( $oldTerm ) ),
SemanticGlossaryMessageLog::SG_NOTICE );
@@ -345,12 +339,12 @@
protected function getPropertyFromData ( SMWSemanticData &$pageData,
$propertyName ) {
- $property = SMWPropertyValue::makeProperty( $propertyName );
+ $property = new SMWDIProperty( $propertyName );
$propertyValues = $pageData -> getPropertyValues( $property );
if ( count( $propertyValues ) == 1 ) {
- return $propertyValues[ 0 ] -> getShortWikiText();
+ return $propertyValues[ 0 ] -> getString();
} else if ( count( $propertyValues ) > 1 ) {
if ( count( $propertyValues ) > 1 ) {
@@ -371,11 +365,44 @@
preg_match( '/^(.*):(.*):(.*)$/', $pageString, $matches );
// create SMWWikiPageValue (SMW's wiki page representation)
- return SMWWikiPageValue::makePage( $matches[ 3 ], $matches[ 2
], '', $matches[ 1 ] );
+ return new SMWDIWikiPage( $matches[ 3 ], $matches[ 2 ],
$matches[ 1 ] );
}
- protected function updateData ( SMWWikiPageValue &$page, array $data ) {
+ // find unused SMW page
+ protected function findNextPageName () {
+ $termPages = smwfGetStore() -> getAllPropertySubjects( new
SMWDIProperty( '___glt' ) );
+ $defPages = smwfGetStore() -> getAllPropertySubjects( new
SMWDIProperty( '___gld' ) );
+ $linkPages = smwfGetStore() -> getAllPropertySubjects( new
SMWDIProperty( '___gll' ) );
+
+ $pages = array( );
+
+ foreach ( $termPages as $page ) {
+ $pages[ $page -> getDBkey() ] = $page -> getDBkey();
+ }
+
+ foreach ( $defPages as $page ) {
+ $pages[ $page -> getDBkey() ] = $page -> getDBkey();
+ }
+
+ foreach ( $linkPages as $page ) {
+ $pages[ $page -> getDBkey() ] = $page -> getDBkey();
+ }
+
+ $termNumber = count( $pages );
+
+
+ while ( array_key_exists( "GlossaryTerm#$termNumber", $pages )
) {
+ $termNumber++;
+ }
+
+ return new SMWDIWikiPage( "GlossaryTerm#$termNumber", NS_MAIN,
'' );
+
+ exit ();
+ }
+
+ protected function updateData ( SMWDIWikiPage &$page, array $data ) {
+
$newData = new SMWSemanticData( $page, false );
$oldData = smwfGetStore() -> getSemanticData( $page );
@@ -384,16 +411,15 @@
// get properties, replace as requested, retain other properties
foreach ( $oldProps as $property ) {
- $propertyID = $property -> getPropertyID();
+ $propertyID = $property -> getKey();
if ( array_key_exists( $propertyID, $data ) ) {
-
// set new data if defined, else ignore
property (i.e. delete property from page)
if ( $data[ $propertyID ] != null ) {
- $value =
SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
- $newData -> addPropertyObjectValue(
$property, $value );
+// $value =
SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
+ $newData -> addPropertyObjectValue(
$property, $data[ $propertyID ] );
}
unset( $data[ $propertyID ] );
@@ -413,9 +439,9 @@
// set new data if defined, else ignore property (i.e.
do not set property on this page)
if ( $data[ $propertyID ] != null ) {
- $property = SMWPropertyValue::makeProperty(
$propertyID );
- $value =
SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
- $newData -> addPropertyObjectValue( $property,
$value );
+ $property = new SMWDIProperty( $propertyID );
+// $value =
SMWDataValueFactory::newPropertyObjectValue( $property, $data[ $propertyID ] );
+ $newData -> addPropertyObjectValue( $property,
$data[ $propertyID ] );
}
unset( $data[ $propertyID ] );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs