Skip to content

Commit

Permalink
Merge pull request #1539 from SemanticMediaWiki/tidy
Browse files Browse the repository at this point in the history
Tidy
  • Loading branch information
mwjames committed Apr 29, 2016
2 parents 43acf66 + ba9ed55 commit 5d19761
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 135 deletions.
1 change: 1 addition & 0 deletions SemanticMediaWiki.php
Expand Up @@ -115,6 +115,7 @@ class_alias( 'SMW\ParameterProcessorFactory', 'SMW\ParameterFormatterFactory' );
// 2.4
class_alias( 'SMW\RequestOptions', 'SMWRequestOptions' );
class_alias( 'SMW\StringCondition', 'SMWStringCondition' );
class_alias( 'SMW\HashBuilder', 'SMW\Hash' );

// A flag used to indicate SMW defines a semantic extension type for extension credits.
// @deprecated, removal in SMW 3.0
Expand Down
23 changes: 1 addition & 22 deletions includes/SemanticData.php
Expand Up @@ -268,28 +268,7 @@ public function getHash() {
return $this->hash;
}

$hash = array();

$hash[] = $this->mSubject->getSerialization();

foreach ( $this->getProperties() as $property ) {
$hash[] = $property->getKey();

foreach ( $this->getPropertyValues( $property ) as $di ) {
$hash[] = $di->getSerialization();
}
}

foreach ( $this->getSubSemanticData() as $data ) {
$hash[] = $data->getHash();
}

sort( $hash );

$this->hash = md5( implode( '#', $hash ) );
unset( $hash );

return $this->hash;
return $this->hash = Hash::createFromSemanticData( $this );
}

/**
Expand Down
23 changes: 2 additions & 21 deletions includes/datavalues/SMW_DV_Property.php
Expand Up @@ -143,7 +143,7 @@ protected function parseUserValue( $value ) {
}

// @see the SMW_DV_PROV_DTITLE explanation
if ( $this->canFindPropertyByDisplayTitle() ) {
if ( $this->isEnabledFeature( SMW_DV_PROV_DTITLE ) ) {
$dataItem = $this->getPropertySpecificationLookup()->getPropertyFromDisplayTitle(
$value
);
Expand All @@ -153,7 +153,7 @@ protected function parseUserValue( $value ) {

$this->inceptiveProperty = $this->m_dataitem;

if ( $this->canFindPropertyRedirect() ) {
if ( $this->isEnabledFeature( SMW_DV_PROV_REDI ) ) {
$this->m_dataitem = $this->m_dataitem->getRedirectTarget();
}
}
Expand Down Expand Up @@ -350,25 +350,6 @@ protected function highlightText( $text, $linker = null ) {
return $text;
}


/**
* @since 2.4
*
* @return boolean
*/
protected function canFindPropertyRedirect() {
return ( $this->getOptionValueFor( 'smwgDVFeatures' ) & SMW_DV_PROV_REDI ) != 0;
}

/**
* @since 2.4
*
* @return boolean
*/
protected function canFindPropertyByDisplayTitle() {
return ( $this->getOptionValueFor( 'smwgDVFeatures' ) & SMW_DV_PROV_DTITLE ) != 0;
}

/**
* A function for registering/overwriting predefined properties for SMW. Should be called from
* within the hook 'smwInitProperties'. Ids should start with three underscores "___" to avoid
Expand Down
2 changes: 1 addition & 1 deletion includes/datavalues/SMW_DV_WikiPage.php
Expand Up @@ -557,7 +557,7 @@ protected function getWikiLinkTarget() {
* @return string sortkey
*/
public function getSortKey() {
return \SMW\StoreFactory::getStore()->getWikiPageSortKey( $this->m_dataitem );
return ApplicationFactory::getInstance()->getStore()->getWikiPageSortKey( $this->m_dataitem );
}

/**
Expand Down
17 changes: 0 additions & 17 deletions includes/storage/StoreFactory.php
Expand Up @@ -50,23 +50,6 @@ public static function getStore( $store = null ) {
return self::$instance[$store];
}

/**
* @note This method should not be used in production code and is mostly
* provided to inject instances during unit testing
*
* @since 2.0
*
* @param Store $instance
*/
public static function setDefaultStoreForUnitTest( Store $instance ) {

if ( self::$defaultStore === null ) {
self::$defaultStore = self::getConfiguration()->get( 'smwgDefaultStore' );
}

self::$instance[self::$defaultStore] = $instance;
}

/**
* @since 1.9
*/
Expand Down
13 changes: 12 additions & 1 deletion src/ApplicationFactory.php
Expand Up @@ -89,6 +89,17 @@ public function registerObject( $objectName, $objectSignature ) {
$this->callbackLoader->registerObject( $objectName, $objectSignature );
}

/**
* @private
*
* @since 2.4
*
* @return CallbackLoader
*/
public function getCallbackInstantiator() {
return $this->callbackLoader;
}

/**
* @since 2.0
*
Expand Down Expand Up @@ -160,7 +171,7 @@ public function newMaintenanceFactory() {
* @return CacheFactory
*/
public function newCacheFactory() {
return new CacheFactory( $this->getSettings()->get( 'smwgCacheType' ) );
return $this->callbackLoader->load( 'CacheFactory', $this->getSettings()->get( 'smwgCacheType' ) );
}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/CacheFactory.php
Expand Up @@ -19,12 +19,18 @@ class CacheFactory {
*/
private $mainCacheType;

/**
* @var CallbackInstantiator
*/
private $callbackInstantiator;

/**
* @since 2.2
*
* @param string|integer|null $mainCacheType
*/
public function __construct( $mainCacheType = null ) {
$this->callbackInstantiator = ApplicationFactory::getInstance()->getCallbackInstantiator();
$this->mainCacheType = $mainCacheType;

if ( $this->mainCacheType === null ) {
Expand Down Expand Up @@ -130,4 +136,25 @@ public function newMediaWikiCompositeCache( $mediaWikiCacheType = null ) {
return $compositeCache;
}

/**
* @since 2.4
*
* @param string $namespace
* @param string|integer|null $cacheType
* @param integer $cacheLifetime
*
* @return BlobStore
*/
public function newBlobStore( $namespace, $cacheType = null, $cacheLifetime = 0 ) {

$blobStore = $this->callbackInstantiator->load( 'BlobStore', $namespace, $cacheType, $cacheLifetime );

// If CACHE_NONE is selected, disable the usage
$blobStore->setUsageState(
$cacheType !== CACHE_NONE
);

return $blobStore;
}

}
Expand Up @@ -79,21 +79,18 @@ public function validate( $dataValue ) {

$this->hasConstraintViolation = false;

if (
!$dataValue instanceof DataValue ||
$dataValue->getContextPage() === null ||
!$dataValue->isEnabledFeature( SMW_DV_PVUC ) ) {
if ( !$this->canValidate( $dataValue ) ) {
return $this->hasConstraintViolation;
}

$dataItem = $dataValue->getDataItem();
$property = $dataValue->getProperty();

if ( !$dataValue->getPropertySpecificationLookup()->hasUniquenessConstraintFor( $property ) ) {
return $this->hasConstraintViolation;
}

$blobStore = $this->cachedPropertyValuesPrefetcher->getBlobStore();
$dataItem = $dataValue->getDataItem();

$hash = $this->cachedPropertyValuesPrefetcher->getHashFor(
$property->getKey() . ':' . $dataItem->getHash()
Expand Down Expand Up @@ -185,4 +182,8 @@ private function tryFindMatchResultFor( $hash, $dataValue ) {
return $page;
}

private function canValidate( $dataValue ) {
return $dataValue instanceof DataValue && $dataValue->getContextPage() !== null && $dataValue->isEnabledFeature( SMW_DV_PVUC );
}

}
45 changes: 42 additions & 3 deletions src/HashBuilder.php
Expand Up @@ -14,6 +14,35 @@
*/
class HashBuilder {

/**
* @since 2.4
*
* @param SemanticData $semanticData
*
* @return string
*/
public static function createFromSemanticData( SemanticData $semanticData ) {

$hash = array();
$hash[] = $semanticData->getSubject()->getSerialization();

foreach ( $semanticData->getProperties() as $property ) {
$hash[] = $property->getKey();

foreach ( $semanticData->getPropertyValues( $property ) as $di ) {
$hash[] = $di->getSerialization();
}
}

foreach ( $semanticData->getSubSemanticData() as $data ) {
$hash[] = $data->getHash();
}

sort( $hash );

return md5( implode( '#', $hash ) );
}

/**
* @since 2.1
*
Expand All @@ -32,6 +61,16 @@ public static function createHashIdForContent( $hashableContent, $prefix = '' )
}

/**
* @since 2.4
*
* @return string
*/
public static function createFromSegments( /* args */ ) {
return implode( '#', func_get_args() );
}

/**
* @deprecated since 2.4, use Hash::createFromSegments
* @since 2.1
*
* @param string $title
Expand All @@ -42,7 +81,7 @@ public static function createHashIdForContent( $hashableContent, $prefix = '' )
* @return string
*/
public static function createHashIdFromSegments( $title, $namespace, $interwiki = '', $fragment = '' ) {
return "$title#$namespace#$interwiki#$fragment";
return self::createFromSegments( $title, $namespace, $interwiki, $fragment );
}

/**
Expand All @@ -53,7 +92,7 @@ public static function createHashIdFromSegments( $title, $namespace, $interwiki
* @return string
*/
public static function getHashIdForTitle( Title $title ) {
return self::createHashIdFromSegments(
return self::createFromSegments(
$title->getDBKey(),
$title->getNamespace(),
$title->getInterwiki(),
Expand All @@ -69,7 +108,7 @@ public static function getHashIdForTitle( Title $title ) {
* @return string
*/
public static function getHashIdForDiWikiPage( DIWikiPage $dataItem ) {
return self::createHashIdFromSegments(
return self::createFromSegments(
$dataItem->getDBKey(),
$dataItem->getNamespace(),
$dataItem->getInterwiki(),
Expand Down
18 changes: 13 additions & 5 deletions src/MediaWiki/Hooks/NewRevisionFromEditComplete.php
Expand Up @@ -72,15 +72,23 @@ public function __construct( $wikiPage, $revision, $baseId, $user = null ) {
* @return boolean
*/
public function process() {
return $this->getParserOutputFromEditInfo() instanceof ParserOutput ? $this->performUpdate() : true;
return $this->canUseParserOutputFromEditInfo() ? $this->doProcess() : true;
}

protected function getParserOutputFromEditInfo() {
$editInfoProvider = new EditInfoProvider( $this->wikiPage, $this->revision, $this->user );
return $this->parserOutput = $editInfoProvider->fetchEditInfo()->getOutput();
private function canUseParserOutputFromEditInfo() {

$editInfoProvider = new EditInfoProvider(
$this->wikiPage,
$this->revision,
$this->user
);

$this->parserOutput = $editInfoProvider->fetchEditInfo()->getOutput();

return $this->parserOutput instanceof ParserOutput;
}

protected function performUpdate() {
private function doProcess() {

$applicationFactory = ApplicationFactory::getInstance();
$title = $this->wikiPage->getTitle();
Expand Down
21 changes: 4 additions & 17 deletions src/SQLStore/SQLStoreFactory.php
Expand Up @@ -2,7 +2,6 @@

namespace SMW\SQLStore;

use Onoi\BlobStore\BlobStore;
use SMW\ApplicationFactory;
use SMW\CircularReferenceGuard;
use SMW\DIProperty;
Expand Down Expand Up @@ -238,22 +237,10 @@ public function newCachedValueLookupStore() {

$cacheFactory = ApplicationFactory::getInstance()->newCacheFactory();

$blobStore = new BlobStore(
$blobStore = $cacheFactory->newBlobStore(
'smw:vl:store',
$cacheFactory->newMediaWikiCompositeCache( $GLOBALS['smwgValueLookupCacheType'] )
);

// If CACHE_NONE is selected, disable the usage
$blobStore->setUsageState(
$GLOBALS['smwgValueLookupCacheType'] !== CACHE_NONE
);

$blobStore->setExpiryInSeconds(
$GLOBALS['smwgValueLookupCacheLifetime']
);

$blobStore->setNamespacePrefix(
$cacheFactory->getCachePrefix()
$this->settings->get( 'smwgValueLookupCacheType' ),
$this->settings->get( 'smwgValueLookupCacheLifetime' )
);

$cachedValueLookupStore = new CachedValueLookupStore(
Expand All @@ -262,7 +249,7 @@ public function newCachedValueLookupStore() {
);

$cachedValueLookupStore->setValueLookupFeatures(
$GLOBALS['smwgValueLookupFeatures']
$this->settings->get( 'smwgValueLookupFeatures' )
);

$cachedValueLookupStore->setCircularReferenceGuard(
Expand Down

0 comments on commit 5d19761

Please sign in to comment.