Skip to content

Commit

Permalink
1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Jun 2, 2015
1 parent 1e29bd8 commit 43f646d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 65 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with content generated from selected properties with:

- PHP 5.3.2 or later
- MediaWiki 1.23 or later
- [Semantic MediaWiki][smw] 2.1+
- [Semantic MediaWiki][smw] 2.1 or later

## Installation

Expand All @@ -28,27 +28,27 @@ The recommended way to install Semantic Meta Tags is by using [Composer][compose
```json
{
"require": {
"mediawiki/semantic-meta-tags": "~1.0"
"mediawiki/semantic-meta-tags": "~1.1"
}
}
```
1. From your MediaWiki installation directory, execute
`composer require mediawiki/semantic-meta-tags:~1.0`
`composer require mediawiki/semantic-meta-tags:~1.1`
2. Navigate to _Special:Version_ on your wiki and verify that the package
have been successfully installed.

## Usage

You can specify which meta tags you want to enable, and where their values should come from with the `smtgTagsProperties` setting.
You can specify which meta tags you want to enable, and where their values should come from with the `$GLOBALS['smtgTagsProperties']` setting.

The setting is an array that has the meta tags as keys (the left part). The values (right part) contain the name of the semantic property on your wiki that you want to use the value of. In case you want to put multiple property values in your meta tag, you can enter multiple property names, separated by commas.

If `smtgTagsPropertyFallbackUsage` is set `true` then the first property that returns a valid content for an assigned tag will be used exclusively. If a given property has multiple values (including subobjects) on your wiki page, the values are concatenated into a single string separated by commas.

The setting `smtgTagsStrings` can be used to describe static content for an assigned `<meta>` tag while tags specified in `smtgTagsBlacklist` are generally disabled for free assignments.

If a tag contains a `og:` it is identified as an [Open Graph][opg] metadata tag and annotated using `meta property=""` description.

- `$GLOBALS['smtgTagsPropertyFallbackUsage']` is set `true` then the first property that returns a valid content for an assigned tag will be used exclusively. If a given property has multiple values (including subobjects) on your wiki page, the values are concatenated into a single string separated by commas.
- `$GLOBALS['smtgTagsStrings']` can be used to describe static content for an assigned `<meta>` tag
- Tags specified in `$GLOBALS['smtgTagsBlacklist']` are generally disabled for free assignments

### Output example

![image](https://cloud.githubusercontent.com/assets/1245473/7828511/b9cf5a2a-0434-11e5-8aa6-33ee8189f44b.png)
Expand Down
7 changes: 5 additions & 2 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
This file contains the RELEASE-NOTES of the Semantic Meta Tags (a.k.a. SMT) extension.

### 1.0.0
### 1.1.0 (2015-06-02)

Released on 2015-02-28
* Minor clean-up
* Localisation updates from https://translatewiki.net

### 1.0.0 (2015-02-28)

* Initial release
* `$smtgTagsProperties` to set which meta tags should be enabled
Expand Down
9 changes: 7 additions & 2 deletions SemanticMetaTags.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use SMT\HookRegistry;
use SMW\ApplicationFactory;

/**
* @see https://github.com/SemanticMediaWiki/SemanticMetaTags/
Expand All @@ -20,7 +21,7 @@
return 1;
}

define( 'SMT_VERSION', '1.0' );
define( 'SMT_VERSION', '1.1.0' );

/**
* @codeCoverageIgnore
Expand Down Expand Up @@ -63,7 +64,11 @@
'metaTagsFallbackUseForMultipleProperties' => $GLOBALS['smtgTagsPropertyFallbackUsage']
);

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

$hookRegistry->register();
};

Expand Down
4 changes: 1 addition & 3 deletions src/FallbackSemanticDataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ private function fetchSemanticData() {
return $semanticData;
}

// let's try the SemanticDataCache before using the
// DB access
// SMW 2.2
// 2.3 SMW-core will handle caching using #1035

// Final method is the Store
return $this->store->getSemanticData(
Expand Down
50 changes: 22 additions & 28 deletions src/HookRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SMT;

use SMW\ApplicationFactory;
use SMW\Store;
use Hooks;

/**
Expand All @@ -21,10 +22,11 @@ class HookRegistry {
/**
* @since 1.0
*
* @param Store $store
* @param array $configuration
*/
public function __construct( $configuration ) {
$this->registerCallbackHandlers( $configuration );
public function __construct( Store $store, $configuration ) {
$this->addCallbackHandlers( $store, $configuration );
}

/**
Expand All @@ -36,22 +38,6 @@ public function register() {
}
}

/**
* @since 1.0
*/
public function deregister() {
foreach ( array_keys( $this->handlers ) as $name ) {

Hooks::clear( $name );

// Remove registered `wgHooks` hooks that are not cleared by the
// previous call
if ( isset( $GLOBALS['wgHooks'][$name] ) ) {
unset( $GLOBALS['wgHooks'][$name] );
}
}
}

/**
* @since 1.0
*
Expand All @@ -64,22 +50,22 @@ public function isRegistered( $name ) {
}

/**
* @since 1.0
* @since 1.1
*
* @param string $name
*
* @return array
* @return Callable|false
*/
public function getHandlers( $name ) {
return Hooks::getHandlers( $name );
public function getHandlersFor( $name ) {
return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false;
}

private function registerCallbackHandlers( $configuration ) {
private function addCallbackHandlers( $store, $configuration ) {

/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageParserOutput
*/
$this->handlers['OutputPageParserOutput'] = function ( &$outputPage, $parserOutput ) use( $configuration ) {
$this->handlers['OutputPageParserOutput'] = function ( &$outputPage, $parserOutput ) use( $store, $configuration ) {

$parserData = ApplicationFactory::getInstance()->newParserData(
$outputPage->getTitle(),
Expand All @@ -88,23 +74,31 @@ private function registerCallbackHandlers( $configuration ) {

$fallbackSemanticDataFetcher = new FallbackSemanticDataFetcher(
$parserData,
ApplicationFactory::getInstance()->getStore()
$store
);

$outputPageTagFormatter = new OutputPageTagFormatter( $outputPage );
$outputPageTagFormatter->setMetaTagsBlacklist( $configuration['metaTagsBlacklist'] );
$outputPageTagFormatter->setViewActionState( \Action::getActionName( $outputPage->getContext() ) );

$propertyValuesContentFetcher = new PropertyValuesContentFetcher( $fallbackSemanticDataFetcher );
$propertyValuesContentFetcher->useFallbackChainForMultipleProperties( $configuration['metaTagsFallbackUseForMultipleProperties'] );

$propertyValuesContentFetcher->useFallbackChainForMultipleProperties(
$configuration['metaTagsFallbackUseForMultipleProperties']
);

$metaTagsModifier = new MetaTagsModifier(
$propertyValuesContentFetcher,
$outputPageTagFormatter
);

$metaTagsModifier->setMetaTagsContentPropertySelector( $configuration['metaTagsContentPropertySelector'] );
$metaTagsModifier->setMetaTagsStaticContentDescriptor( $configuration['metaTagsStaticContentDescriptor'] );
$metaTagsModifier->setMetaTagsContentPropertySelector(
$configuration['metaTagsContentPropertySelector']
);

$metaTagsModifier->setMetaTagsStaticContentDescriptor(
$configuration['metaTagsStaticContentDescriptor']
);

$metaTagsModifier->addMetaTags();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use SMW\Tests\Utils\UtilityFactory;
use SMT\HookRegistry;
use SMW\DIWikiPage;
use Title;

/**
* @group semantic-meta-tags
Expand Down Expand Up @@ -52,15 +51,14 @@ protected function setUp() {
'metaTagsFallbackUseForMultipleProperties' => false
);

// Deregister all hooks to ensure that only the one that is ought to be
// tested is tested
$hookRegistry = new HookRegistry( $configuration );
$hookRegistry->deregister();
$hookRegistry = new HookRegistry( $this->getStore(), $configuration );
$hookRegistry->register();
}

protected function tearDown() {
$this->pageDeleter->doDeletePoolOfPages( $this->subjects );
$this->pageDeleter->doDeletePoolOfPages(
$this->subjects
);

parent::tearDown();
}
Expand All @@ -74,7 +72,7 @@ public function testAddStandardMetaTag() {
$this->markTestSkipped( 'OutputPage::getMetaTags does not exist for this MW version' );
}

$subject = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) );
$subject = new DIWikiPage( __METHOD__, NS_MAIN );
$requestContext->setTitle( $subject->getTitle() );

$this->pageCreator
Expand Down Expand Up @@ -103,7 +101,7 @@ public function testAddStandardMetaTag() {
$outputPage->hasHeadItem( 'meta:property:og:title' )
);

$this->subjects = array( $subject );
$this->subjects[] = $subject;
}

public function testAddOpenGraphMetaTag() {
Expand All @@ -115,7 +113,7 @@ public function testAddOpenGraphMetaTag() {
$this->markTestSkipped( 'OutputPage::addParserOutputMetadata does not exist for this MW version' );
}

$subject = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) );
$subject = new DIWikiPage( __METHOD__, NS_MAIN );
$requestContext->setTitle( $subject->getTitle() );

$this->pageCreator
Expand All @@ -129,7 +127,7 @@ public function testAddOpenGraphMetaTag() {
$outputPage->hasHeadItem( 'meta:property:og:title' )
);

$this->subjects = array( $subject );
$this->subjects[] = $subject;
}

}
28 changes: 16 additions & 12 deletions tests/phpunit/Unit/HookRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@ class HookRegistryTest extends \PHPUnit_Framework_TestCase {

public function testCanConstruct() {

$store = $this->getMockBuilder( '\SMW\Store' )
->disableOriginalConstructor()
->getMockForAbstractClass();

$configuration = array();

$this->assertInstanceOf(
'\SMT\HookRegistry',
new HookRegistry( $configuration )
new HookRegistry( $store, $configuration )
);
}

public function testRegister() {

$store = $this->getMockBuilder( '\SMW\Store' )
->disableOriginalConstructor()
->getMockForAbstractClass();

$configuration = array(
'metaTagsContentPropertySelector' => array(),
'metaTagsStaticContentDescriptor' => array(),
'metaTagsBlacklist' => array(),
'metaTagsFallbackUseForMultipleProperties' => false
);

$instance = new HookRegistry( $configuration );
$instance->deregister();
$instance = new HookRegistry( $store, $configuration );
$instance->register();

$this->doTestRegisteredOutputPageParserOutputHandler( $instance );
Expand Down Expand Up @@ -80,19 +87,16 @@ public function doTestRegisteredOutputPageParserOutputHandler( $instance ) {
->getMock();

$this->assertThatHookIsExcutable(
$instance->getHandlers( 'OutputPageParserOutput' ),
$instance->getHandlersFor( 'OutputPageParserOutput' ),
array( &$outputPage, $parserOutput )
);
}

private function assertThatHookIsExcutable( array $hooks, $arguments ) {
foreach ( $hooks as $hook ) {

$this->assertInternalType(
'boolean',
call_user_func_array( $hook, $arguments )
);
}
private function assertThatHookIsExcutable( \Closure $handler, $arguments ) {
$this->assertInternalType(
'boolean',
call_user_func_array( $handler, $arguments )
);
}

}

0 comments on commit 43f646d

Please sign in to comment.