http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88089
Revision: 88089
Author: jeroendedauw
Date: 2011-05-14 14:53:12 +0000 (Sat, 14 May 2011)
Log Message:
-----------
more work on semantic wahctlist special page and related code
Modified Paths:
--------------
trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
2011-05-14 14:49:17 UTC (rev 88088)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
2011-05-14 14:53:12 UTC (rev 88089)
@@ -26,11 +26,15 @@
*/
public static function onDataChanged( SMWStore $store, SMWChangeSet
$changes ) {
$changes = new SWLChangeSet( $changes );
- $changes->writeToStore();
+ $groups = SWLGroups::getMatchingWatchGroups(
$changes->getTitle() );
- foreach ( SWLGroups::getMatchingWatchGroups( $changes->getTitle() ) as
/* SWLGroup */ $group ) {
- $group->notifyWatchingUsers( $changes );
- }
+ $wasInserted = $changes->writeToStore( $groups ) != 0;
+
+ if ( $wasInserted ) {
+ foreach ( $groups as /* SWLGroup */ $group ) {
+ $group->notifyWatchingUsers( $changes );
+ }
+ }
return true;
}
Modified: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-14 14:49:17 UTC (rev 88088)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-14 14:53:12 UTC (rev 88089)
@@ -69,12 +69,13 @@
foreach ( $changes as $change ) {
$property = SMWDIProperty::doUnserialize(
$change->change_property, '__pro' );
+ static $foo=0;$foo++;
$changeSet->addChange(
$property,
new SMWPropertyChange( // TODO: directly create
the DI, no need to get it via a DV...
- SMWDataValueFactory::newTypeIdValue(
$property->findPropertyTypeID(), $change->change_old_value )->getDataItem(),
- SMWDataValueFactory::newTypeIdValue(
$property->findPropertyTypeID(), $change->change_new_value )->getDataItem()
+ is_null( $change->change_old_value ) ?
null : SMWDataValueFactory::newTypeIdValue( $property->findPropertyTypeID(),
$change->change_old_value )->getDataItem(),
+ is_null( $change->change_new_value ) ?
null : SMWDataValueFactory::newTypeIdValue( $property->findPropertyTypeID(),
$change->change_new_value )->getDataItem()
)
);
}
@@ -122,9 +123,24 @@
*
* @since 0.1
*
- * @return boolean Success indicator
+ * @param array of SWLGroup
+ *
+ * @return integer ID of the inserted row (0 if nothing was inserted).
*/
- public function writeToStore() {
+ public function writeToStore( array $groupsToAssociate ) {
+ $properties = array();
+
+ foreach ( $this->getAllProperties() as /* SMWDIProperty */
$property ) {
+ if ( $property->isUserDefined() ) {
+ $properties[] = $property;
+ }
+ }
+
+ // If there are no changed user properties, don't insert a new
entry.
+ if ( count( $properties ) == 0 ) {
+ return 0;
+ }
+
$dbw = wfGetDB( DB_MASTER );
$dbw->insert(
@@ -140,7 +156,7 @@
$changes = array();
- foreach ( $this->getAllProperties() as /* SMWDIProperty */
$property ) {
+ foreach ( $properties as /* SMWDIProperty */ $property ) {
if ( $property->isUserDefined() ) {
$propSerialization =
$property->getSerialization();
@@ -188,6 +204,18 @@
)
);
}
+
+ foreach ( $groupsToAssociate as /* SWLGroup */ $group ) {
+ $dbw->insert(
+ 'swl_sets_per_group',
+ array(
+ 'spg_group_id' => $group->getId(),
+ 'spg_set_id' => $id
+ )
+ );
+ }
+
+ return $id;
}
/**
Modified:
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-14 14:49:17 UTC (rev 88088)
+++ trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-14 14:53:12 UTC (rev 88089)
@@ -96,8 +96,8 @@
'DatabaseBase::select',
array(
'LIMIT' => 20,
- 'ORDER BY' => 'set_time',
- 'SORT DESC'
+ 'ORDER BY' => 'set_time DESC',
+ 'DISTINCT'
),
array(
'swl_sets_per_group' => array( 'INNER JOIN',
array( 'set_id=spg_set_id' ) ),
@@ -121,8 +121,10 @@
foreach ( $changeSet->getAllProperties() as /* SMWDIProperty */
$property ) {
foreach ( $changeSet->getAllPropertyChanges( $property
) as /* SMWPropertyChange */ $change ) {
- $old = SMWDataValueFactory::newDataItemValue(
$change->getOldValue() )->getLongWikiText();
- $new = SMWDataValueFactory::newDataItemValue(
$change->getNewValue() )->getLongWikiText();
+ $old = $change->getOldValue();
+ $old = is_null( $old ) ? wfMsg( 'swl-novalue' )
: SMWDataValueFactory::newDataItemValue( $old )->getLongWikiText();
+ $new = $change->getNewValue();
+ $new = is_null( $new ) ? wfMsg( 'swl-novalue' )
: SMWDataValueFactory::newDataItemValue( $new )->getLongWikiText();
$wgOut->addHTML( '<li>' . $old . ' -> ' . $new
. '</li>' );
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs