Skip to content

Commit bd038c8

Browse files
JeroenDeDauwclaude
andcommitted
Restore Semantic MediaWiki 6 compatibility
Semantic MediaWiki 7 moved several classes into new namespaces (e.g. SMW\DataItems\DataItem) and the Semantic integration was switched to those, which do not exist on Semantic MediaWiki 6. Use the pre-7 names instead, which Semantic MediaWiki 7 keeps as aliases, so the integration runs on both major versions; the one symbol with no name common to both (the event dispatcher, namespaced in 7 but the Onoi interface in 6) loses its type hint. Also test both major versions in CI. The matrix shared one cache across all Semantic MediaWiki versions (the constraint's "^" dropped out of the cache key), so those rows silently skipped the Semantic tests; key the cache per version. Fixes #908 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 02eded9 commit bd038c8

10 files changed

Lines changed: 82 additions & 74 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,35 @@ jobs:
1313

1414
strategy:
1515
matrix:
16+
# smwCache keeps the cache key free of the version constraint's special
17+
# characters, which would otherwise collide and share one cache.
1618
include:
1719
- mw: 'REL1_43'
1820
php: 8.3
1921
smw: ''
22+
smwCache: 'none'
2023
experimental: false
2124
- mw: 'REL1_44'
2225
php: 8.3
2326
smw: ''
27+
smwCache: 'none'
2428
experimental: false
2529
- mw: 'REL1_45'
2630
php: 8.3
2731
smw: ''
32+
smwCache: 'none'
2833
experimental: false
2934
# Exercises the Semantic MediaWiki integration, which self-skips when SMW is absent.
35+
# Both supported major versions are tested, as they differ in API (e.g. class namespaces).
36+
- mw: 'REL1_43'
37+
php: 8.3
38+
smw: '^6.0'
39+
smwCache: 'smw6'
40+
experimental: false
3041
- mw: 'REL1_43'
3142
php: 8.3
3243
smw: '^7.0'
44+
smwCache: 'smw7'
3345
experimental: false
3446

3547
runs-on: ubuntu-latest
@@ -54,7 +66,7 @@ jobs:
5466
mediawiki
5567
!mediawiki/extensions/
5668
!mediawiki/vendor/
57-
key: mw_${{ matrix.mw }}-php${{ matrix.php }}-smw${{ matrix.smw }}-v23
69+
key: mw_${{ matrix.mw }}-php${{ matrix.php }}-${{ matrix.smwCache }}-v24
5870

5971
- name: Cache Composer cache
6072
uses: actions/cache@v4

src/GeoJsonPages/Semantic/SemanticGeoJsonStore.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
use Maps\GeoJsonPages\GeoJsonStore;
88
use MediaWiki\Title\Title;
9-
use SMW\DataItems\Property;
10-
use SMW\EventDispatcher\EventDispatcher;
9+
use SMW\DIProperty;
1110
use SMW\ParserData;
12-
use SMW\DataItems\Container;
11+
use SMWDIContainer;
1312

1413
class SemanticGeoJsonStore implements GeoJsonStore {
1514

1615
private ParserData $parserData;
1716
private Title $subjectPage;
18-
private EventDispatcher $smwEventDispatcher;
17+
/** @var \SMW\EventDispatcher\EventDispatcher|\Onoi\EventDispatcher\EventDispatcher Namespaced in SMW 7, the Onoi interface in SMW 6. */
18+
private $smwEventDispatcher;
1919
private SubObjectBuilder $subObjectBuilder;
2020

21-
public function __construct( ParserData $parserData, Title $subjectPage, EventDispatcher $smwEventDispatcher, SubObjectBuilder $subObjectBuilder ) {
21+
public function __construct( ParserData $parserData, Title $subjectPage, $smwEventDispatcher, SubObjectBuilder $subObjectBuilder ) {
2222
$this->parserData = $parserData;
2323
$this->subjectPage = $subjectPage;
2424
$this->smwEventDispatcher = $smwEventDispatcher;
@@ -28,8 +28,8 @@ public function __construct( ParserData $parserData, Title $subjectPage, EventDi
2828
public function storeGeoJson( string $geoJson ) {
2929
foreach ( $this->subObjectBuilder->getSubObjectsFromGeoJson( $geoJson ) as $subObject ) {
3030
$this->parserData->getSemanticData()->addPropertyObjectValue(
31-
new Property( Property::TYPE_SUBOBJECT ),
32-
new Container( $subObject->toContainerSemanticData( $this->subjectPage->getTitleValue() ) )
31+
new DIProperty( DIProperty::TYPE_SUBOBJECT ),
32+
new SMWDIContainer( $subObject->toContainerSemanticData( $this->subjectPage->getTitleValue() ) )
3333
);
3434
}
3535

src/GeoJsonPages/Semantic/SubObject.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@
55
namespace Maps\GeoJsonPages\Semantic;
66

77
use SMW\DataModel\ContainerSemanticData;
8-
use SMW\DataItems\Property;
9-
use SMW\DataItems\WikiPage;
8+
use SMW\DIProperty;
9+
use SMW\DIWikiPage;
1010
use TitleValue;
11-
use SMW\DataItems\DataItem;
1211

1312
class SubObject {
1413

1514
private string $name;
1615

1716
/**
18-
* @var array<string, array<int, DataItem>>
17+
* @var array<string, array<int, \SMWDataItem>>
1918
*/
2019
private array $values = [];
2120

2221
public function __construct( string $name ) {
2322
$this->name = $name;
2423
}
2524

26-
public function addPropertyValuePair( string $propertyName, DataItem $dataItem ) {
25+
public function addPropertyValuePair( string $propertyName, \SMWDataItem $dataItem ) {
2726
$this->values[$propertyName][] = $dataItem;
2827
}
2928

@@ -33,7 +32,7 @@ public function toContainerSemanticData( TitleValue $subjectPage ): ContainerSem
3332
foreach ( $this->values as $propertyName => $dataItems ) {
3433
foreach ( $dataItems as $dataItem ) {
3534
$container->addPropertyObjectValue(
36-
new Property( $propertyName ),
35+
new DIProperty( $propertyName ),
3736
$dataItem
3837
);
3938
}
@@ -44,7 +43,7 @@ public function toContainerSemanticData( TitleValue $subjectPage ): ContainerSem
4443

4544
private function newContainerSemanticData( TitleValue $subjectPage ): ContainerSemanticData {
4645
return new ContainerSemanticData(
47-
new WikiPage(
46+
new DIWikiPage(
4847
$subjectPage->getDBkey(),
4948
$subjectPage->getNamespace(),
5049
$subjectPage->getInterwiki(),

src/GeoJsonPages/Semantic/SubObjectBuilder.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use GeoJson\Feature\FeatureCollection;
99
use GeoJson\GeoJson;
1010
use GeoJson\Geometry\Point;
11-
use SMW\DataItems\GeoCoord;
12-
use SMW\DataItems\Blob;
1311

1412
class SubObjectBuilder {
1513

@@ -47,20 +45,20 @@ private function pointToSubobject( Point $point, array $properties ): SubObject
4745

4846
$subObject->addPropertyValuePair(
4947
'HasCoordinates',
50-
new GeoCoord( $point->getCoordinates()[1], $point->getCoordinates()[0] )
48+
new \SMWDIGeoCoord( $point->getCoordinates()[1], $point->getCoordinates()[0] )
5149
);
5250

5351
if ( array_key_exists( 'description', $properties ) && is_string( $properties['description'] ) ) {
5452
$subObject->addPropertyValuePair(
5553
'HasDescription',
56-
new Blob( $properties['description'] )
54+
new \SMWDIBlob( $properties['description'] )
5755
);
5856
}
5957

6058
if ( array_key_exists( 'title', $properties ) && is_string( $properties['title'] ) ) {
6159
$subObject->addPropertyValuePair(
6260
'HasTitle',
63-
new Blob( $properties['title'] )
61+
new \SMWDIBlob( $properties['title'] )
6462
);
6563
}
6664

src/Map/SemanticFormat/MapPrinter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use MediaWiki\Parser\Parser;
2121
use SMW\Query\QueryResult;
2222
use SMW\Query\ResultPrinters\ResultPrinter;
23-
use SMW\MediaWiki\Outputs;
23+
use SMWOutputs;
2424

2525
/**
2626
* @licence GNU GPL v2+
@@ -140,13 +140,13 @@ final public function getResultText( QueryResult $res, $outputMode ): string {
140140
}
141141

142142
private function outputResources( MapOutput $mapOutput ) {
143-
Outputs::requireHeadItem(
143+
SMWOutputs::requireHeadItem(
144144
$this->randomString(),
145145
$mapOutput->getHeadItems()
146146
);
147147

148148
foreach ( $mapOutput->getResourceModules() as $resourceModule ) {
149-
Outputs::requireResource( $resourceModule );
149+
SMWOutputs::requireResource( $resourceModule );
150150
}
151151
}
152152

src/SemanticMW/AreaDescription.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
use Maps\GeoFunctions;
1010
use Maps\Presentation\MapsDistanceParser;
1111
use SMW\DataValueFactory;
12-
use SMW\DataItems\Property;
12+
use SMW\DIProperty;
1313
use SMW\Query\Language\Description;
1414
use SMW\Query\Language\ThingDescription;
1515
use SMW\Query\Language\ValueDescription;
16+
use SMWDataItem;
17+
use SMWDIGeoCoord;
1618
use Wikimedia\Rdbms\IDatabase;
17-
use SMW\DataItems\GeoCoord;
18-
use SMW\DataItems\DataItem;
1919

2020
/**
2121
* Description of a geographical area defined by a coordinates set and a distance to the bounds.
@@ -27,12 +27,12 @@
2727
*/
2828
class AreaDescription extends ValueDescription {
2929

30-
private GeoCoord $center;
30+
private SMWDIGeoCoord $center;
3131
private string $radius;
3232

33-
public function __construct( DataItem $areaCenter, int $comparator, string $radius, ?Property $property = null ) {
34-
if ( !( $areaCenter instanceof GeoCoord ) ) {
35-
throw new InvalidArgumentException( '$areaCenter needs to be a GeoCoord' );
33+
public function __construct( SMWDataItem $areaCenter, int $comparator, string $radius, ?DIProperty $property = null ) {
34+
if ( !( $areaCenter instanceof SMWDIGeoCoord ) ) {
35+
throw new InvalidArgumentException( '$areaCenter needs to be a SMWDIGeoCoord' );
3636
}
3737

3838
parent::__construct( $areaCenter, $property, $comparator );
@@ -83,7 +83,7 @@ public function getQueryString( $asValue = false ): string {
8383
* @return string|false
8484
*/
8585
public function getSQLCondition( $tableName, array $fieldNames, IDatabase $db ) {
86-
if ( $this->center->getDIType() != DataItem::TYPE_GEO ) {
86+
if ( $this->center->getDIType() != SMWDataItem::TYPE_GEO ) {
8787
throw new \LogicException( 'Constructor should have prevented this' );
8888
}
8989

src/SemanticMW/CoordinateDescription.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use SMW\DataValueFactory;
88
use SMW\Query\Language\ValueDescription;
9+
use SMWDIGeoCoord;
910
use Wikimedia\Rdbms\IDatabase;
10-
use SMW\DataItems\GeoCoord;
1111

1212
/**
1313
* Description of one data value of type Geographical Coordinates.
@@ -41,7 +41,7 @@ public function getSQLCondition( $tableName, array $fieldNames, IDatabase $db )
4141

4242
// Only execute the query when the description's type is geographical coordinates,
4343
// the description is valid, and the near comparator is used.
44-
if ( $dataItem instanceof GeoCoord ) {
44+
if ( $dataItem instanceof SMWDIGeoCoord ) {
4545
switch ( $this->getComparator() ) {
4646
case SMW_CMP_EQ:
4747
$comparator = '=';

src/SemanticMW/CoordinateValue.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
use SMW\Query\Language\ThingDescription;
1414
use SMW\Query\QueryComparator;
1515
use ValueParsers\ParseException;
16-
use SMW\DataValues\DataValue;
17-
use SMW\DataItems\GeoCoord;
18-
use SMW\DataItems\DataItem;
19-
use SMW\Formatters\Highlighter;
16+
use SMWDataValue;
17+
use SMWDIGeoCoord;
18+
use SMWDataItem;
19+
use SMW\Highlighter;
2020

2121
/**
22-
* @property GeoCoord m_dataitem
22+
* @property SMWDIGeoCoord m_dataitem
2323
*
2424
* @licence GNU GPL v2+
2525
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
2626
* @author Markus Krötzsch
2727
*/
28-
class CoordinateValue extends DataValue {
28+
class CoordinateValue extends SMWDataValue {
2929

3030
private $wikiValue;
3131

3232
/**
33-
* Overwrite DataValue::getQueryDescription() to be able to process
33+
* Overwrite SMWDataValue::getQueryDescription() to be able to process
3434
* comparators between all values.
3535
*
3636
* @param string $value
@@ -67,7 +67,7 @@ public function getQueryDescription( $value ) {
6767
}
6868

6969
/**
70-
* @see DataValue::parseUserValue
70+
* @see SMWDataValue::parseUserValue
7171
*/
7272
protected function parseUserValue( $value ): void {
7373
$this->parseAndReturnUserValue( $value );
@@ -110,14 +110,14 @@ private function tryParseAndSetDataItem( string $coordinates ) {
110110

111111
try {
112112
$value = $parser->parse( $coordinates );
113-
$this->m_dataitem = new GeoCoord( $value->getLatitude(), $value->getLongitude() );
113+
$this->m_dataitem = new SMWDIGeoCoord( $value->getLatitude(), $value->getLongitude() );
114114
}
115115
catch ( ParseException $parseException ) {
116116
$this->addError( wfMessage( 'maps_unrecognized_coords', $coordinates, 1 )->text() );
117117

118118
// Make sure this is always set
119119
// TODO: Why is this needed?!
120-
$this->m_dataitem = new GeoCoord( [ 'lat' => 0, 'lon' => 0 ] );
120+
$this->m_dataitem = new SMWDIGeoCoord( [ 'lat' => 0, 'lon' => 0 ] );
121121
}
122122
}
123123

@@ -135,7 +135,7 @@ private function parserDistance( $distance ) {
135135
}
136136

137137
/**
138-
* @see DataValue::getShortHTMLText
138+
* @see SMWDataValue::getShortHTMLText
139139
*
140140
* @since 0.6
141141
*/
@@ -144,7 +144,7 @@ public function getShortHTMLText( $linker = null ) {
144144
}
145145

146146
/**
147-
* @see DataValue::getShortWikiText
147+
* @see SMWDataValue::getShortWikiText
148148
*/
149149
public function getShortWikiText( $linker = null ) {
150150
if ( $this->isValid() ) {
@@ -159,12 +159,12 @@ public function getShortWikiText( $linker = null ) {
159159
}
160160

161161
/**
162-
* @param GeoCoord $dataItem
162+
* @param SMWDIGeoCoord $dataItem
163163
* @param string|null $format
164164
*
165165
* @return string|null
166166
*/
167-
private function getFormattedCoord( GeoCoord $dataItem, ?string $format = null ) {
167+
private function getFormattedCoord( SMWDIGeoCoord $dataItem, ?string $format = null ) {
168168
return MapsFactory::globalInstance()->getCoordinateFormatter()->format(
169169
new LatLongValue(
170170
$dataItem->getLatitude(),
@@ -176,14 +176,14 @@ private function getFormattedCoord( GeoCoord $dataItem, ?string $format = null )
176176
}
177177

178178
/**
179-
* @see DataValue::getLongHTMLText
179+
* @see SMWDataValue::getLongHTMLText
180180
*/
181181
public function getLongHTMLText( $linker = null ) {
182182
return $this->getLongWikiText( $linker );
183183
}
184184

185185
/**
186-
* @see DataValue::getLongWikiText
186+
* @see SMWDataValue::getLongWikiText
187187
*
188188
* @since 0.6
189189
*/
@@ -215,21 +215,21 @@ public function getLongWikiText( $linked = null ) {
215215
}
216216

217217
/**
218-
* @see DataValue::getWikiValue
218+
* @see SMWDataValue::getWikiValue
219219
*/
220220
public function getWikiValue() {
221221
return $this->wikiValue;
222222
}
223223

224224
/**
225-
* @see DataValue::setDataItem
225+
* @see SMWDataValue::setDataItem
226226
*
227-
* @param DataItem $dataItem
227+
* @param SMWDataItem $dataItem
228228
*
229229
* @return boolean
230230
*/
231-
protected function loadDataItem( DataItem $dataItem ) {
232-
if ( $dataItem instanceof GeoCoord ) {
231+
protected function loadDataItem( SMWDataItem $dataItem ) {
232+
if ( $dataItem instanceof SMWDIGeoCoord ) {
233233
$formattedValue = $this->getFormattedCoord( $dataItem );
234234

235235
if ( $formattedValue !== null ) {
@@ -262,7 +262,7 @@ protected function getServiceLinkParams(): array {
262262
}
263263

264264
/**
265-
* @return GeoCoord|\SMW\DataItems\Error
265+
* @return SMWDIGeoCoord|\SMWDIError
266266
*/
267267
public function getDataItem() {
268268
return parent::getDataItem();

0 commit comments

Comments
 (0)