Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
"alias": "sesp-property-view-count",
"label": "Number of page views"
},
"_DESCRIPTION": {
"id": "___DESCRIPTION",
"type": "_txt",
"show": false,
"alias": "sesp-property-description",
"label": "Description of the page"
},
"_NSID": {
"id": "___NSID",
"type": "_num",
Expand Down
1 change: 1 addition & 0 deletions data/import/groups/extra.group.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"___EUSER",
"___CUSER",
"___VIEWS",
"___DESCRIPTION",
"___SUBP",
"___NREV",
"___NTREV",
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Property labels differ according to the language the wiki was set up. An easy wa
- `_APPROVEDDATE` adds a property called "Approved date" which records the date a page was approved if the [Approved Revs][Approved Revs] extension is installed
- `_APPROVEDSTATUS` adds a property called "Approval status" which records the approvement status of a page if the [Approved Revs][Approved Revs] extension is installed
- `_PAGEIMG` adds a property called "Page Images" which records PageImages of a page if the [PageImages][PageImages] extension is installed
- `_DESCRIPTION` adds a property called "Description of the page" which records the description of the page when [Description2][Description2] extension is installed

## Additional configuration

Expand Down
2 changes: 2 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"sesp-property-page-img-desc": "\"$1\" records the PageImages (Extension:PageImages) of a page . It is is provided by the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Semantic Extra Special Properties] extension.",
"sesp-property-view-count": "Number of page views",
"sesp-property-view-count-desc": "\"$1\" records the number of page views of a page. It is provided by the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Semantic Extra Special Properties] extension.",
"sesp-property-description": "Description of the page",
"sesp-property-description-desc": "\"$1\" records the description of page views of a page. It is provided by the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Semantic Extra Special Properties] extension.",
"sesp-property-subpages": "Subpage",
"sesp-property-subpages-desc": "\"$1\" records all subpages of a page. It is provided by the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Semantic Extra Special Properties] extension.",
"sesp-property-revisions": "Number of revisions",
Expand Down
2 changes: 2 additions & 0 deletions i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"sesp-property-page-img-desc": "« $1 » enregistre les images de page (Extension:PageImages) pour une page donnée. Ceci est fourni par l’extension [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Propriétés sémantiques spéciales complémentaires].",
"sesp-property-view-count": "Nombre de vues de la page",
"sesp-property-view-count-desc": "« $1 » enregistre le nombre de consultations d’une page. Ceci est fourni par l’extension [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Propriétés sémantiques spéciales complémentaires].",
"sesp-property-description": "Description de la page",
"sesp-property-description-desc": "« $1 » enregistre la description de la page. Il est fourni par l’extension [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Propriétés sémantiques spéciales supplémentaires].",
"sesp-property-subpages": "Sous-page",
"sesp-property-subpages-desc": "« $1 » enregistre toutes les sous-pages d’une page. Ceci est fourni par l’extension [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties Propriétés sémantiques spéciales complémentaires].",
"sesp-property-revisions": "Nombre de révisions",
Expand Down
2 changes: 2 additions & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"sesp-property-page-img-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
"sesp-property-view-count": "{{Doc-smw-sp|extension=SESP}}",
"sesp-property-view-count-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
"sesp-property-description": "{{Doc-smw-sp|extension=SESP}}",
"sesp-property-description-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
"sesp-property-subpages": "{{Doc-smw-sp|extension=SESP}}\n{{Identical|Subpage}}",
"sesp-property-subpages-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
"sesp-property-revisions": "{{Doc-smw-sp|extension=SESP}}",
Expand Down
2 changes: 1 addition & 1 deletion src/HookRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function initExtension( &$vars ) {
$vars['wgHooks']['SMW::Config::BeforeCompletion'][] = function( &$config ) {

$exemptionlist = [
'___EUSER', '___CUSER', '___SUBP', '___REVID', '___VIEWS',
'___EUSER', '___CUSER', '___SUBP', '___REVID', '___VIEWS', '___DESCRIPTION',
'___NREV', '___NTREV', '___USEREDITCNT', '___USEREDITCNTNS', '___EXIFDATA', '___NSID', '___NSNAME'
];

Expand Down
4 changes: 4 additions & 0 deletions src/PropertyAnnotators/DispatchingPropertyAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ private function initDefaultPropertyAnnotators() {
return new PageViewsPropertyAnnotator( $appFactory );
},

PageDescriptionPropertyAnnotator::PROP_ID => function( $appFactory ) {
return new PageDescriptionPropertyAnnotator( $appFactory );
},

NamespacePropertyAnnotator::PROP_ID => function ( $appFactory ) {
return new NamespacePropertyAnnotator( $appFactory );
},
Expand Down
78 changes: 78 additions & 0 deletions src/PropertyAnnotators/PageDescriptionPropertyAnnotator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace SESP\PropertyAnnotators;

use SMW\DIProperty;
use SMW\SemanticData;
use SMWDIString as DIString;
use SESP\PropertyAnnotator;
use SESP\AppFactory;
use ParserOptions;

/**
* @private
* @ingroup SESP
*
* @license GNU GPL v2+
* @since 2.0
*
* @author mwjames
*/
class PageDescriptionPropertyAnnotator implements PropertyAnnotator {

/**
* Predefined property ID
*/
const PROP_ID = '___DESCRIPTION';

/**
* @var AppFactory
*/
private $appFactory;

/**
* @since 2.0
*
* @param AppFactory $appFactory
*/
public function __construct( AppFactory $appFactory ) {
$this->appFactory = $appFactory;
}

/**
* @since 2.0
*
* {@inheritDoc}
*/
public function isAnnotatorFor( DIProperty $property ) {
return $property->getKey() === self::PROP_ID;
}

/**
* @since 2.0
*
* {@inheritDoc}
*/
public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {

$page = $this->appFactory->newWikiPage( $semanticData->getSubject()->getTitle() );
$description = $this->getPageDescription( $page );

if ( !empty( $description ) ) {
$semanticData->addPropertyObjectValue( $property, new DIString( $description ) );
}
}

private function getPageDescription( $page ) {

$parser = $page->getParserOutput( ParserOptions::newCanonical( 'canonical' ) );
$description = $parser->getProperty( 'description' );

if ( $description !== false ) { // set by Description2 extension, install it if you want proper og:description support
return $description;
}

return null;
}

}
1 change: 1 addition & 0 deletions tests/phpunit/Unit/HookRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function testInitExtension() {
'___SUBP',
'___REVID',
'___VIEWS',
'___DESCRIPTION',
'___NREV',
'___NTREV',
'___USEREDITCNT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SESP\PropertyAnnotators\CreatorPropertyAnnotator;
use SESP\PropertyAnnotators\PageImagesPropertyAnnotator;
use SESP\PropertyAnnotators\PageViewsPropertyAnnotator;
use SESP\PropertyAnnotators\PageDescriptionPropertyAnnotator;
use SESP\PropertyAnnotators\LocalPropertyAnnotator;
use SESP\PropertyAnnotators\UserRegistrationDatePropertyAnnotator;
use SESP\PropertyAnnotators\UserEditCountPropertyAnnotator;
Expand Down Expand Up @@ -124,6 +125,11 @@ public function propertyAnnotatorProvider() {
PageViewsPropertyAnnotator::class
];

$provider[] = [
PageDescriptionPropertyAnnotator::PROP_ID,
PageDescriptionPropertyAnnotator::class
];

$provider[] = [
NamespacePropertyAnnotator::PROP_ID,
NamespacePropertyAnnotator::class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace SESP\Tests\PropertyAnnotators;

use SESP\AppFactory;
use SESP\PropertyAnnotators\PageDescriptionPropertyAnnotator;
use SMW\DIProperty;
use SMW\DIWikiPage;
use SMW\SemanticData;
use User;
use WikiPage;

/**
* @covers PageDescriptionPropertyAnnotator
* @group semantic-extra-special-properties
*
* @license GNU GPL v2+
* @since 2.0
*
* @author mwjames
*/
class PageDescriptionPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {

private $property;
private $appFactory;

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

$this->appFactory = $this->getMockBuilder( AppFactory::class )
->disableOriginalConstructor()
->getMock();

$this->property = new DIProperty( '___DESCRIPTION' );
}

public function testCanConstruct() {

$this->assertInstanceOf(
PageDescriptionPropertyAnnotator::class,
new PageDescriptionPropertyAnnotator( $this->appFactory )
);
}

public function testIsAnnotatorFor() {

$instance = new PageDescriptionPropertyAnnotator(
$this->appFactory
);

$this->assertTrue(
$instance->isAnnotatorFor( $this->property )
);
}

public function testAddAnnotation() {

$subject = DIWikiPage::newFromText( __METHOD__ );


// to implement
}

}