Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Merge bf800a1 into 0dc2539
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Dec 1, 2013
2 parents 0dc2539 + bf800a1 commit 8a8048b
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 164 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -35,6 +35,7 @@ script:
- if [ "$TESTSUITE" == "MediaWiki" ] ; then phpunit --coverage-clover build/logs/clover.xml ; fi

after_script:
- composer require satooshi/php-coveralls dev-master
- php vendor/bin/coveralls -v

notifications:
Expand Down
2 changes: 2 additions & 0 deletions RELEASE-NOTES.md
Expand Up @@ -4,6 +4,8 @@ These are the release notes for the [Wikibase Database library](README.md).

* Removed custom autoloaders is favour of using the Composer autoloader.
* MediaWiki plugin: added compatibility with changes in MediaWiki 1.22.
* Removed unused UnEscaper interface.
* Split Escaper interface into ValueEscaper and IdentifierEscaper, keeping Escaper itself.

## Version 0.1 (2013-11-01)

Expand Down
35 changes: 4 additions & 31 deletions WikibaseDatabase.mw.php
Expand Up @@ -12,6 +12,10 @@
die( 'Not an entry point.' );
}

if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require_once( __DIR__ . '/vendor/autoload.php' );
}

$GLOBALS['wgExtensionCredits']['wikibase'][] = array(
'path' => __DIR__,
'name' => 'Wikibase Database',
Expand All @@ -25,34 +29,3 @@
);

$GLOBALS['wgExtensionMessagesFiles']['WikibaseDatabase'] = __DIR__ . '/WikibaseDatabase.i18n.php';

if ( defined( 'MW_PHPUNIT_TEST' ) ) {
require_once __DIR__ . '/tests/testLoader.php';
}

/**
* Hook to add PHPUnit test cases.
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
*
* @since 0.1
*
* @param array $files
*
* @return boolean
*/
$GLOBALS['wgHooks']['UnitTestsList'][] = function( array &$files ) {
// @codeCoverageIgnoreStart
$directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests' );

/**
* @var SplFileInfo $fileInfo
*/
foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
$files[] = $fileInfo->getPathname();
}
}

return true;
// @codeCoverageIgnoreEnd
};
52 changes: 8 additions & 44 deletions WikibaseDatabase.php
Expand Up @@ -3,54 +3,18 @@
/**
* Entry point of the Wikibase Database component.
*
* @codeCoverageIgnore
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/

if ( defined( 'WIKIBASE_DATABASE_VERSION' ) ) {
// Do not initialize more then once.
return;
}

define( 'WIKIBASE_DATABASE_VERSION', '0.1' );

spl_autoload_register( function ( $className ) {
$className = ltrim( $className, '\\' );
$fileName = '';
$namespace = '';

if ( $lastNsPos = strripos( $className, '\\') ) {
$namespace = substr( $className, 0, $lastNsPos );
$className = substr( $className, $lastNsPos + 1 );
$fileName = str_replace( '\\', '/', $namespace ) . '/';
}

$fileName .= str_replace( '_', '/', $className ) . '.php';

$namespaceSegments = explode( '\\', $namespace );

$inQueryEngineNamespace = count( $namespaceSegments ) > 1
&& $namespaceSegments[0] === 'Wikibase'
&& $namespaceSegments[1] === 'Database';
if ( !defined( 'WIKIBASE_DATABASE_VERSION' ) ) {
define( 'WIKIBASE_DATABASE_VERSION', '0.2 alpha' );

if ( $inQueryEngineNamespace ) {
$inTestNamespace = count( $namespaceSegments ) > 2 && $namespaceSegments[2] === 'Tests';

if ( !$inTestNamespace ) {
$pathParts = explode( '/', $fileName );
array_shift( $pathParts );
array_shift( $pathParts );
$fileName = implode( '/', $pathParts );

require_once __DIR__ . '/src/' . $fileName;
}
if ( defined( 'MEDIAWIKI' ) ) {
call_user_func( function() {
require_once __DIR__ . '/WikibaseDatabase.mw.php';
} );
}
} );

// @codeCoverageIgnoreStart
if ( defined( 'MEDIAWIKI' ) ) {
call_user_func( function() {
require_once __DIR__ . '/WikibaseDatabase.mw.php';
} );
}
// @codeCoverageIgnoreEnd
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -28,10 +28,10 @@
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"classmap": [
"src"
],
"files" : [
"WikibaseDatabase.php"
]
Expand Down
16 changes: 1 addition & 15 deletions src/Escaper.php
Expand Up @@ -12,20 +12,6 @@
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
* @author Adam Shorland
*/
interface Escaper {

/**
* @param mixed $value
*
* @return string The escaped value
*/
public function getEscapedValue( $value );

/**
* @param mixed $identifier
*
* @return string The escaped identifier
*/
public function getEscapedIdentifier( $identifier );
interface Escaper extends ValueEscaper, IdentifierEscaper {

}
20 changes: 20 additions & 0 deletions src/IdentifierEscaper.php
@@ -0,0 +1,20 @@
<?php

namespace Wikibase\Database;

/**
* @since 0.2
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
interface IdentifierEscaper {

/**
* @param mixed $identifier
*
* @return string The escaped identifier
*/
public function getEscapedIdentifier( $identifier );

}
7 changes: 3 additions & 4 deletions src/SQLite/SQLiteUnEscaper.php
Expand Up @@ -2,15 +2,14 @@

namespace Wikibase\Database\SQLite;

use Wikibase\Database\UnEscaper;

/**
* UnEscaper to remove the Escaping from SQLLite escaped SQL strings
* UnEscaper to remove the Escaping from SQLLite escaped SQL strings.
*
* @since 0.1
* @licence GNU GPL v2+
* @author Adam Shorland
*/
class SQLiteUnEscaper implements UnEscaper {
class SQLiteUnEscaper {

/**
* @param string $identifier
Expand Down
45 changes: 45 additions & 0 deletions src/Standalone/DatabaseEscaper.php
@@ -0,0 +1,45 @@
<?php

namespace Wikibase\Database\Standalone;

use DatabaseBase;
use Wikibase\Database\Escaper;

/**
* Service for escaping values and identifiers.
*
* @since 0.2
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class DatabaseEscaper implements Escaper {

protected $dbConnection;

public function __construct( DatabaseBase $dbConnection ) {
$this->dbConnection = $dbConnection;
}

/**
* @see Escaper::getEscapedValue
*
* @param mixed $value
*
* @return string The escaped value
*/
public function getEscapedValue( $value ) {
return $this->dbConnection->addQuotes( $value );
}

/**
* @see Escaper::getEscapedIdentifier
*
* @param mixed $identifier
*
* @return string The escaped identifier
*/
public function getEscapedIdentifier( $identifier ) {
return $this->dbConnection->addIdentifierQuotes( $identifier );
}

}
23 changes: 0 additions & 23 deletions src/UnEscaper.php

This file was deleted.

20 changes: 20 additions & 0 deletions src/ValueEscaper.php
@@ -0,0 +1,20 @@
<?php

namespace Wikibase\Database;

/**
* @since 0.2
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
interface ValueEscaper {

/**
* @param mixed $value
*
* @return string The escaped value
*/
public function getEscapedValue( $value );

}
8 changes: 5 additions & 3 deletions tests/bootstrap.php
Expand Up @@ -9,10 +9,12 @@
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/

if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) {
die( 'You need to install this package with Composer before you can run the tests' );
}

if ( !in_array( '--testsuite=WikibaseDatabaseStandalone', $GLOBALS['argv'] ) ) {
require_once( __DIR__ . '/evilMediaWikiBootstrap.php' );
}

require_once( __DIR__ . '/../WikibaseDatabase.php' );

require_once( __DIR__ . '/testLoader.php' );
require_once( __DIR__ . '/../vendor/autoload.php' );
41 changes: 0 additions & 41 deletions tests/testLoader.php

This file was deleted.

0 comments on commit 8a8048b

Please sign in to comment.