Skip to content

Commit

Permalink
Merge pull request #12 from s7eph4n/2.0-dev
Browse files Browse the repository at this point in the history
Make compatible to Lingo 2.0; introduce extension.json
  • Loading branch information
s7eph4n committed Mar 9, 2016
2 parents c333bb1 + aec1175 commit 1f4d6e6
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 117 deletions.
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
language: php

env:
- THENEEDFORTHIS=FAIL

matrix:
include:
- env: DB=mysql; MW=master; TYPE=coverage
php: 5.5
- env: DB=sqlite; MW=1.22.0
- env: DB=sqlite; MW=1.26.0
php: 5.3
exclude:
- env: THENEEDFORTHIS=FAIL

install:
- bash ./tests/travis/install-mediawiki.sh
Expand All @@ -30,4 +25,4 @@ notifications:
channels:
- "chat.freenode.net#semantic-mediawiki"
on_success: change
on_failure: always
on_failure: always
35 changes: 0 additions & 35 deletions SemanticGlossary.i18n.php

This file was deleted.

80 changes: 31 additions & 49 deletions SemanticGlossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,45 @@
use SMW\ApplicationFactory;

/**
* A terminology markup extension with a Semantic MediaWiki backend
* Class SemanticGlossary
*
* @defgroup SemanticGlossary Semantic Glossary
* @author Stephan Gambke
* @ingroup Skins
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' );
}
class SemanticGlossary {

if ( defined( 'SG_VERSION' ) ) {
// Do not initialize more than once.
return 1;
}
/**
* @since 2.0
*/
public static function initExtension() {

/**
* The Semantic Glossary version
*/
define( 'SG_VERSION', '1.2.0-alpha' );
// must NOT use ExtensionRegistry::getInstance() to avoid recursion!
$registry = new ExtensionRegistry();
$registry->load( $GLOBALS[ 'wgExtensionDirectory' ] . '/Lingo/extension.json' );

if ( !defined( 'SMW_VERSION' ) ) {
die( 'Semantic Glossary depends on the Semantic MediaWiki extension. You need to install Semantic MediaWiki first.' );
}
$GLOBALS[ 'wgexLingoBackend' ] = 'SG\LingoBackendAdapter';

if ( !defined( 'LINGO_VERSION' ) ) {
die( 'Semantic Glossary depends on the Lingo extension. You need to install Lingo first.' );
}
$GLOBALS[ 'wgExtensionFunctions' ][] = function () {

call_user_func( function () {
$hookRegistry = new HookRegistry(
ApplicationFactory::getInstance()->getStore()
);

// register the extension
$GLOBALS[ 'wgExtensionCredits' ][ 'semantic' ][] = array(
'path' => __FILE__,
'name' => 'Semantic Glossary',
'author' => array( '[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]', 'James Hong Kong' ),
'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Glossary',
'descriptionmsg' => 'semanticglossary-desc',
'version' => SG_VERSION,
'license-name' => 'GPL-2.0+'
);
$hookRegistry->register();
};
}

// set SemanticGlossaryBackend as the backend to access the glossary
$GLOBALS[ 'wgexLingoBackend' ] = 'SG\LingoBackendAdapter';
/**
* @since 2.0
*
* @return string|null
*/
public static function getVersion() {
$extensionData = ExtensionRegistry::getInstance()->getAllThings();

// server-local path to this file
$dir = __DIR__;
if ( isset( $extensionData['Semantic Glossary'] ) ) {
return $extensionData['Semantic Glossary']['version'];
}

// register message file
$GLOBALS[ 'wgMessagesDirs' ]['SemanticGlossary'] = $dir . '/i18n';
$GLOBALS[ 'wgExtensionMessagesFiles' ]['SemanticGlossary'] = $dir . '/SemanticGlossary.i18n.php';

$GLOBALS['wgExtensionFunctions'][] = function() {

$hookRegistry = new HookRegistry(
ApplicationFactory::getInstance()->getStore()
);

$hookRegistry->register();
};

} );
return null;
}
}
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"require": {
"php": ">=5.3.0",
"composer/installers":"^1.0.12",
"mediawiki/semantic-media-wiki": "~2.2",
"mediawiki/lingo": "~1.2"
"mediawiki/semantic-media-wiki": "~2.3",
"mediawiki/lingo": "~2.0"
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "2.x-dev"
}
},
"autoload": {
Expand All @@ -52,4 +52,4 @@
"scripts":{
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"
}
}
}
23 changes: 23 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Semantic Glossary",
"version": "2.0-dev",
"author": [
"[https://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]",
"[https://www.semantic-mediawiki.org/wiki/User:MWJames James Hong Kong]",
"..."
],
"url": "https://www.mediawiki.org/wiki/Extension:Semantic_Glossary",
"descriptionmsg": "semanticglossary-desc",
"license-name": "GPL-2.0+",
"type": "semantic",
"requires": {
"MediaWiki": "~1.26"
},
"MessagesDirs": {
"SemanticGlossary": [
"i18n"
]
},
"callback": "SemanticGlossary::initExtension",
"manifest_version": 1
}
2 changes: 1 addition & 1 deletion src/Cache/CacheInvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use SMW\DIWikiPage;
use SMW\DIProperty;

use LingoParser;
use Lingo\LingoParser;

use Title;

Expand Down
13 changes: 6 additions & 7 deletions src/Cache/ElementsCacheBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SG\Cache;

use SG\Cache\GlossaryCache;
use SG\PropertyRegistry;

use SMW\Store;
Expand All @@ -15,7 +14,7 @@
use SMWSomeProperty as SomeProperty;
use SMWQuery as Query;

use LingoElement;
use Lingo\Element;

/**
* @ingroup SG
Expand Down Expand Up @@ -114,11 +113,11 @@ private function buildElements( $terms, $definition, $link, $style, $page ) {

foreach ( $terms as $term ) {
$tmp_ret = array(
LingoElement::ELEMENT_TERM => $term,
LingoElement::ELEMENT_DEFINITION => $definition,
LingoElement::ELEMENT_LINK => $link,
LingoElement::ELEMENT_STYLE => $style,
LingoElement::ELEMENT_SOURCE => $page
Element::ELEMENT_TERM => $term,
Element::ELEMENT_DEFINITION => $definition,
Element::ELEMENT_LINK => $link,
Element::ELEMENT_STYLE => $style,
Element::ELEMENT_SOURCE => $page
);

$ret[] = $tmp_ret;
Expand Down
12 changes: 6 additions & 6 deletions src/LingoBackendAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use SMW\StoreFactory;

use LingoBackend;
use LingoMessageLog;
use Lingo\Backend;
use Lingo\MessageLog;

/**
* @ingroup SG
Expand All @@ -19,7 +19,7 @@
*
* @author mwjames
*/
class LingoBackendAdapter extends LingoBackend {
class LingoBackendAdapter extends Backend {

/* @var ElementsCacheBuilder */
protected $elementsCacheBuilder = null;
Expand All @@ -29,10 +29,10 @@ class LingoBackendAdapter extends LingoBackend {
/**
* @since 1.1
*
* @param LingoMessageLog|null &$messages
* @param MessageLog|null &$messages
* @param ElementsCacheBuilder|null $elementsCacheBuilder
*/
public function __construct( LingoMessageLog &$messages = null, ElementsCacheBuilder $elementsCacheBuilder = null ) {
public function __construct( MessageLog &$messages = null, ElementsCacheBuilder $elementsCacheBuilder = null ) {
parent::__construct( $messages );
$this->elementsCacheBuilder = $elementsCacheBuilder;

Expand Down Expand Up @@ -69,7 +69,7 @@ public function next() {
* This backend is cache-enabled so this function returns true.
*
* Actual caching is done by the parser, the backend just calls
* LingoParser::purgeCache when necessary.
* Parser::purgeCache when necessary.
*
* @since 1.1
*
Expand Down
6 changes: 5 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
die( 'The SemanticMediaWiki test autoloader is not available' );
}

print sprintf( "\n%-20s%s\n", "Semantic Glossary: ", SG_VERSION );
if ( ( $version = SemanticGlossary::getVersion() ) === null ) {
die( 'SemanticGlossary is not registered via wfLoadExtension, please adapt your LocalSettings.' );
}

print sprintf( "\n%-20s%s\n", "Semantic Glossary: ", $version );

$autoloader = require $autoloaderClassPath;
$autoloader->addPsr4( 'SG\\Tests\\', __DIR__ . '/phpunit/Unit' );
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/Integration/MwDBSQLStoreIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MwDBSQLStoreIntegrationTest extends MwDBaseUnitTestCase {
private $runnerFactory;

protected function setUp() {
parent::setUp();

$this->pageCreator = UtilityFactory::getInstance()->newPageCreator();
$this->pageDeleter = UtilityFactory::getInstance()->newPageDeleter();
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/Unit/Cache/ElementsCacheBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SG\Cache\ElementsCacheBuilder;
use SG\Cache\GlossaryCache;

use LingoElement;
use Lingo\Element;

use SMWDIWikiPage as DIWikiPage;
use SMWDIBlob as DIBlob;
Expand Down Expand Up @@ -99,14 +99,14 @@ public function testGetTermsForSingleTermWithDefinitionOnNonCachedResult() {

protected function assertLingoElement( $term, $definition, $link, $style, $result ) {

$this->assertEquals( $term, $result[ LingoElement::ELEMENT_TERM ] );
$this->assertEquals( $definition, $result[ LingoElement::ELEMENT_DEFINITION ] );
$this->assertEquals( $link, $result[ LingoElement::ELEMENT_LINK ] );
$this->assertEquals( $style, $result[ LingoElement::ELEMENT_STYLE ] );
$this->assertEquals( $term, $result[ Element::ELEMENT_TERM ] );
$this->assertEquals( $definition, $result[ Element::ELEMENT_DEFINITION ] );
$this->assertEquals( $link, $result[ Element::ELEMENT_LINK ] );
$this->assertEquals( $style, $result[ Element::ELEMENT_STYLE ] );

$this->assertInstanceOf(
'SMWDIWikiPage',
$result[ LingoElement::ELEMENT_SOURCE ]
$result[ Element::ELEMENT_SOURCE ]
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Unit/LingoBackendAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testCanConstruct() {

public function testNextOnEmptyElementsResult() {

$lingoMessageLog = $this->getMockBuilder( '\LingoMessageLog' )
$lingoMessageLog = $this->getMockBuilder( '\Lingo\MessageLog' )
->disableOriginalConstructor()
->getMock();

Expand Down
1 change: 1 addition & 0 deletions tests/travis/install-semantic-glossary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function updateConfiguration {
echo '$wgShowExceptionDetails = true;' >> LocalSettings.php
echo '$wgDevelopmentWarnings = true;' >> LocalSettings.php
echo "putenv( 'MW_INSTALL_PATH=$(pwd)' );" >> LocalSettings.php
echo "wfLoadExtension('SemanticGlossary');" >> LocalSettings.php

php maintenance/update.php --quick
}
Expand Down

0 comments on commit 1f4d6e6

Please sign in to comment.