Skip to content

Commit bda9d9b

Browse files
committed
Added a new property Description from Description2
1 parent 2711204 commit bda9d9b

File tree

12 files changed

+169
-1
lines changed

12 files changed

+169
-1
lines changed

data/definitions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
"alias": "sesp-property-view-count",
5252
"label": "Number of page views"
5353
},
54+
"_DESCRIPTION": {
55+
"id": "___DESCRIPTION",
56+
"type": "_txt",
57+
"show": false,
58+
"alias": "sesp-property-description",
59+
"label": "Description of the page"
60+
},
5461
"_NSID": {
5562
"id": "___NSID",
5663
"type": "_num",

data/import/groups/extra.group.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"___EUSER",
2525
"___CUSER",
2626
"___VIEWS",
27+
"___DESCRIPTION",
2728
"___SUBP",
2829
"___NREV",
2930
"___NTREV",

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Property labels differ according to the language the wiki was set up. An easy wa
4747
- `_APPROVEDDATE` adds a property called "Approved date" which records the date a page was approved if the [Approved Revs][Approved Revs] extension is installed
4848
- `_APPROVEDSTATUS` adds a property called "Approval status" which records the approvement status of a page if the [Approved Revs][Approved Revs] extension is installed
4949
- `_PAGEIMG` adds a property called "Page Images" which records PageImages of a page if the [PageImages][PageImages] extension is installed
50+
- `_DESCRIPTION` adds a property called "Description of the page" which records the description of the page when [Description2][Description2] extension is installed
5051

5152
## Additional configuration
5253

i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"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.",
2424
"sesp-property-view-count": "Number of page views",
2525
"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.",
26+
"sesp-property-description": "Description of the page",
27+
"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.",
2628
"sesp-property-subpages": "Subpage",
2729
"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.",
2830
"sesp-property-revisions": "Number of revisions",

i18n/fr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"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].",
3131
"sesp-property-view-count": "Nombre de vues de la page",
3232
"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].",
33+
"sesp-property-description": "Description de la page",
34+
"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].",
3335
"sesp-property-subpages": "Sous-page",
3436
"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].",
3537
"sesp-property-revisions": "Nombre de révisions",

i18n/qqq.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"sesp-property-page-img-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
2727
"sesp-property-view-count": "{{Doc-smw-sp|extension=SESP}}",
2828
"sesp-property-view-count-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
29+
"sesp-property-description": "{{Doc-smw-sp|extension=SESP}}",
30+
"sesp-property-description-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
2931
"sesp-property-subpages": "{{Doc-smw-sp|extension=SESP}}\n{{Identical|Subpage}}",
3032
"sesp-property-subpages-desc": "{{Doc-smw-sp-desc|extension=SESP}}",
3133
"sesp-property-revisions": "{{Doc-smw-sp|extension=SESP}}",

src/HookRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function initExtension( &$vars ) {
8686
$vars['wgHooks']['SMW::Config::BeforeCompletion'][] = function( &$config ) {
8787

8888
$exemptionlist = [
89-
'___EUSER', '___CUSER', '___SUBP', '___REVID', '___VIEWS',
89+
'___EUSER', '___CUSER', '___SUBP', '___REVID', '___VIEWS', '___DESCRIPTION',
9090
'___NREV', '___NTREV', '___USEREDITCNT', '___USEREDITCNTNS', '___EXIFDATA', '___NSID', '___NSNAME'
9191
];
9292

src/PropertyAnnotators/DispatchingPropertyAnnotator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ private function initDefaultPropertyAnnotators() {
111111
return new PageViewsPropertyAnnotator( $appFactory );
112112
},
113113

114+
PageDescriptionPropertyAnnotator::PROP_ID => function( $appFactory ) {
115+
return new PageDescriptionPropertyAnnotator( $appFactory );
116+
},
117+
114118
NamespacePropertyAnnotator::PROP_ID => function ( $appFactory ) {
115119
return new NamespacePropertyAnnotator( $appFactory );
116120
},
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace SESP\PropertyAnnotators;
4+
5+
use SMW\DIProperty;
6+
use SMW\SemanticData;
7+
use SMWDIString as DIString;
8+
use SESP\PropertyAnnotator;
9+
use SESP\AppFactory;
10+
use ParserOptions;
11+
12+
/**
13+
* @private
14+
* @ingroup SESP
15+
*
16+
* @license GNU GPL v2+
17+
* @since 2.0
18+
*
19+
* @author mwjames
20+
*/
21+
class PageDescriptionPropertyAnnotator implements PropertyAnnotator {
22+
23+
/**
24+
* Predefined property ID
25+
*/
26+
const PROP_ID = '___DESCRIPTION';
27+
28+
/**
29+
* @var AppFactory
30+
*/
31+
private $appFactory;
32+
33+
/**
34+
* @since 2.0
35+
*
36+
* @param AppFactory $appFactory
37+
*/
38+
public function __construct( AppFactory $appFactory ) {
39+
$this->appFactory = $appFactory;
40+
}
41+
42+
/**
43+
* @since 2.0
44+
*
45+
* {@inheritDoc}
46+
*/
47+
public function isAnnotatorFor( DIProperty $property ) {
48+
return $property->getKey() === self::PROP_ID;
49+
}
50+
51+
/**
52+
* @since 2.0
53+
*
54+
* {@inheritDoc}
55+
*/
56+
public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
57+
58+
$page = $this->appFactory->newWikiPage( $semanticData->getSubject()->getTitle() );
59+
$description = $this->getPageViewCount( $page );
60+
61+
if ( !empty( $description ) ) {
62+
$semanticData->addPropertyObjectValue( $property, new DIString( $description ) );
63+
}
64+
}
65+
66+
private function getPageViewCount( $page ) {
67+
68+
$parser = $page->getParserOutput( ParserOptions::newCanonical( 'canonical' ) );
69+
$description = $parser->getProperty( 'description' );
70+
71+
if ( $description !== false ) { // set by Description2 extension, install it if you want proper og:description support
72+
return $description;
73+
}
74+
75+
return null;
76+
}
77+
78+
}

tests/phpunit/Unit/HookRegistryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function testInitExtension() {
6666
'___SUBP',
6767
'___REVID',
6868
'___VIEWS',
69+
'___DESCRIPTION',
6970
'___NREV',
7071
'___NTREV',
7172
'___USEREDITCNT',

0 commit comments

Comments
 (0)