https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114069
Revision: 114069
Author: van-de-bugger
Date: 2012-03-17 21:05:27 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
SemanticTitle: New hook implemented to eliminate need in DEFAULTSORT, but not
enabled due to issue (unknown parser).
Modified Paths:
--------------
trunk/extensions/SemanticTitle/SemanticTitle.class.php
trunk/extensions/SemanticTitle/SemanticTitle.php
Modified: trunk/extensions/SemanticTitle/SemanticTitle.class.php
===================================================================
--- trunk/extensions/SemanticTitle/SemanticTitle.class.php 2012-03-17
21:03:47 UTC (rev 114068)
+++ trunk/extensions/SemanticTitle/SemanticTitle.class.php 2012-03-17
21:05:27 UTC (rev 114069)
@@ -131,6 +131,43 @@
} // function onParserFirstCallInit
+ // This hook is not enabled yet.
+ static public function onSMWStore_updateDataAfter( SMWStore $smw_store,
SMWSemanticData $data ) {
+
+ global $egSemanticTitle;
+
+ $subject = $data->getSubject();
+ if ( ! $subject->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) {
+ return true;
+ }; // if
+ $ns = $subject->getNamespace();
+ if ( ! isset( $egSemanticTitle[ $ns ] ) ) {
+ return true;
+ }; // if
+ $name = $egSemanticTitle[ $ns ];
+ $props = $data->getProperties();
+ if ( ! isset( $props[ $name ] ) ) {
+ return true;
+ }; // if
+ $values = $data->getPropertyValues( $props[ $name ] );
+ if ( count( $values ) == 0 ) {
+ return true;
+ }; // if
+ $value = array_shift( $values );
+ if ( $value->getDIType() != SMWDataItem::TYPE_STRING ) {
+ return true;
+ }; // if
+ $semantic = $value->getString();
+ $title = $subject->getTitle();
+
+ // Oops. I need parser to set default sort key. :-(
+ // $parser->setDefaultSort( $semantic );
+
+ return true;
+
+ } // function onSMWStore_updateDataAfter
+
+
static public function hookSemanticTitle( $parser, $arg ) {
$res = $arg;
$title = Title::newFromText( $arg );
Modified: trunk/extensions/SemanticTitle/SemanticTitle.php
===================================================================
--- trunk/extensions/SemanticTitle/SemanticTitle.php 2012-03-17 21:03:47 UTC
(rev 114068)
+++ trunk/extensions/SemanticTitle/SemanticTitle.php 2012-03-17 21:05:27 UTC
(rev 114069)
@@ -27,10 +27,12 @@
$wgAutoloadClasses[ 'SemanticTitle' ] = __DIR__ . '/SemanticTitle.class.php';
global $wgHooks;
-$wgHooks[ 'BeforePageDisplay' ][] = 'SemanticTitle::onBeforePageDisplay';
-$wgHooks[ 'LanguageGetMagic' ][] = 'SemanticTitle::onLanguageGetMagic';
-$wgHooks[ 'LinkBegin' ][] = 'SemanticTitle::onLinkBegin';
-$wgHooks[ 'ParserFirstCallInit' ][] =
'SemanticTitle::onParserFirstCallInit';
+$wgHooks[ 'BeforePageDisplay' ][] =
'SemanticTitle::onBeforePageDisplay';
+$wgHooks[ 'LanguageGetMagic' ][] =
'SemanticTitle::onLanguageGetMagic';
+$wgHooks[ 'LinkBegin' ][] = 'SemanticTitle::onLinkBegin';
+$wgHooks[ 'ParserFirstCallInit' ][] =
'SemanticTitle::onParserFirstCallInit';
+// Not yet implemented.
+//~ $wgHooks[ 'SMWStore::updateDataAfter' ][] =
'SemanticTitle::onSMWStore_updateDataAfter';
global $wgExtensionMessagesFiles;
$wgExtensionMessagesFiles[ 'SemanticTitle' ] = __DIR__ .
'/SemanticTitle.i18n.php';
@@ -43,7 +45,7 @@
'path' => __FILE__,
'name' => 'SemanticTitle',
'license' => 'AGPLv3',
- 'version' => '0.0.2',
+ 'version' => '0.0.2+',
'author' => array( '[https://www.mediawiki.org/wiki/User:Van_de_Bugger
Van de Bugger]' ),
'url' => 'https://www.mediawiki.org/wiki/Extension:SemanticTitle',
'descriptionmsg' => 'semantictitle-desc',
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs