http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88335
Revision: 88335
Author: jeroendedauw
Date: 2011-05-17 18:12:56 +0000 (Tue, 17 May 2011)
Log Message:
-----------
further implemented semanticwatchlist API module and modified the corresponding
special page to use it via fauxrequest
Modified Paths:
--------------
trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql 2011-05-17
18:03:50 UTC (rev 88334)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql 2011-05-17
18:12:56 UTC (rev 88335)
@@ -18,7 +18,7 @@
--INSERT INTO mw_swl_groups
(group_name,group_categories,group_namespaces,group_properties,group_concepts)
VALUES ('bar', '', 102, '', '');
--INSERT INTO mw_swl_groups
(group_name,group_categories,group_namespaces,group_properties,group_concepts)
VALUES ('baz', 'Customers', 102, 'Has contract status', '');
--INSERT INTO mw_swl_users_per_group (upg_group_id,upg_user_id) VALUES(1,1);
---INSERT INTO mw_swl_sets (set_user_name,set_page_id,set_time)
VALUES('jeroen',1,1);
+--INSERT INTO mw_swl_sets (set_user_name,set_page_id,set_time)
VALUES('jeroen',1,20110517171422);
--INSERT INTO mw_swl_changes
(change_set_id,change_property,change_old_value,change_new_value) VALUES(1,'has
foobar','baz','bar');
-- List of all changes made to properties.
Modified: trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
2011-05-17 18:03:50 UTC (rev 88334)
+++ trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
2011-05-17 18:12:56 UTC (rev 88335)
@@ -37,12 +37,13 @@
break;
}
- $resultSets[] = array(
- 'id' => $set->set_id,
- 'user_name' => $set->set_user_name,
- 'page_id' => $set->set_page_id,
- 'time' => $set->set_time,
- );
+ $set = SWLChangeSet::newFromDBResult( $set )->toArray();
+
+ foreach ( $set['changes'] as $propName => $changes ) {
+ $this->getResult()->setIndexedTagName(
$set['changes'][$propName], 'change' );
+ }
+
+ $resultSets[] = $set;
}
$this->getResult()->setIndexedTagName( $resultSets, 'set' );
Modified: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-17 18:03:50 UTC (rev 88334)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-17 18:12:56 UTC (rev 88335)
@@ -35,13 +35,19 @@
/**
* The title of the page the changeset holds changes for.
+ * The title will be constructed from the subject of the SMWChangeSet
+ * the first time getTitle is called, so it should be accessed via this
+ * method.
*
* @var Title or false
*/
protected $title = false;
/**
+ * Creates and returns a new SWLChangeSet instance from a database
result
+ * obtained by doing a select on swl_sets.
*
+ * @since 0.1
*
* @param $set
*
@@ -69,14 +75,10 @@
foreach ( $changes as $change ) {
$property = SMWDIProperty::doUnserialize(
$change->change_property, '__pro' );
- $diType = SMWDataValueFactory::getDataItemId(
$property->findPropertyTypeID() );
$changeSet->addChange(
$property,
- new SMWPropertyChange(
- is_null( $change->change_old_value ) ?
null : SMWDataItem::newFromSerialization( $diType, $change->change_old_value ),
- is_null( $change->change_new_value ) ?
null : SMWDataItem::newFromSerialization( $diType, $change->change_new_value )
- )
+ SMWPropertyChange::newFromSerialization(
$property, $change->change_old_value, $change->change_new_value )
);
}
@@ -91,8 +93,50 @@
}
/**
+ * Creates and returns a new SWLChangeSet instance from a database
result
+ * obtained by doing a select on swl_sets.
+ *
+ * @since 0.1
+ *
+ * @param array $changeSetArray
+ *
+ * @return SWLChangeSet
+ */
+ public static function newFromArray( array $changeSetArray ) {
+ $changeSet = new SMWChangeSet(
+ SMWDIWikiPage::newFromTitle( Title::newFromID(
$changeSetArray['page_id'] ) )
+ );
+
+ foreach ( $changeSetArray['changes'] as $propName => $changes )
{
+ $property = SMWDIProperty::doUnserialize( $propName,
'__pro' );
+
+ foreach ( $changes as $change ) {
+ $changeSet->addChange(
+ $property,
+ SMWPropertyChange::newFromSerialization(
+ $property,
+ array_key_exists( 'old',
$change ) ? $change['old'] : null,
+ array_key_exists( 'new',
$change ) ? $change['new'] : null
+ )
+ );
+ }
+ }
+
+ $changeSet = new SWLChangeSet(
+ $changeSet,
+ User::newFromName( $changeSetArray['user_name'] ),
+ $changeSetArray['time'],
+ $changeSetArray['id']
+ );
+
+ return $changeSet;
+ }
+
+ /**
* Constructor.
*
+ * @since 0.1
+ *
* @param SMWChangeSet $changeSet
* @param User $user
* @param integer $time
@@ -116,9 +160,49 @@
*/
public function __call( $name, array $arguments ) {
return call_user_func_array( array( $this->changeSet, $name ),
$arguments );
- }
+ }
/**
+ * Serializes the object as an associative array, which can be passed
+ * to newFromArray to create a new instance.
+ *
+ * @since 0.1
+ *
+ * @return array
+ */
+ public function toArray() {
+ $changeSet = array(
+ 'id' => $this->id,
+ 'user_name' => $this->user->getName(),
+ 'page_id' => $this->getTitle()->getArticleID(),
+ 'time' => $this->time,
+ 'changes' => array()
+ );
+
+ foreach ( $this->changeSet->getAllProperties() as /*
SMWDIProperty */ $property ) {
+ $propChanges = array();
+
+ foreach ( $this->changeSet->getAllPropertyChanges(
$property ) as /* SMWPropertyChange */ $change ) {
+ $propChange = array();
+
+ if ( is_object( $change->getOldValue() ) ) {
+ $propChange['old'] =
$change->getOldValue()->getSerialization();
+ }
+
+ if ( is_object( $change->getNewValue() ) ) {
+ $propChange['new'] =
$change->getNewValue()->getSerialization();
+ }
+
+ $propChanges[] = $propChange;
+ }
+
+ $changeSet['changes'][$property->getSerialization()] =
$propChanges;
+ }
+
+ return $changeSet;
+ }
+
+ /**
* Save the change set to the database.
*
* @since 0.1
Modified:
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-17 18:03:50 UTC (rev 88334)
+++ trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-17 18:12:56 UTC (rev 88335)
@@ -78,37 +78,21 @@
* @return array of SWLChangeSet
*/
protected function getChangeSets() {
- global $wgUser;
-
- $dbr = wfGetDb( DB_SLAVE );
-
- $sets = $dbr->select(
- array( 'swl_sets', 'swl_sets_per_group',
'swl_users_per_group' ),
- array(
- 'set_id',
- 'set_user_name',
- 'set_page_id',
- 'set_time',
- ),
- array(
- 'upg_user_id' => $wgUser->getId()
- ),
- 'DatabaseBase::select',
- array(
- 'LIMIT' => 20,
- 'ORDER BY' => 'set_time DESC',
- 'DISTINCT'
- ),
- array(
- 'swl_sets_per_group' => array( 'INNER JOIN',
array( 'set_id=spg_set_id' ) ),
- 'swl_users_per_group' => array( 'INNER JOIN',
array( 'spg_group_id=upg_group_id' ) ),
- )
+ $requestData = array(
+ 'action' => 'query',
+ 'list' => 'semanticwatchlist',
+ 'format' => 'json',
+ 'swuserid' => $GLOBALS['wgUser']->getId()
);
+ $api = new ApiMain( new FauxRequest( $requestData, true ), true
);
+ $api->execute();
+ $response = $api->getResultData();
+
$changeSets = array();
- foreach ( $sets as $set ) {
- $changeSets[] = SWLChangeSet::newFromDBResult( $set );
+ foreach ( $response['sets'] as $set ) {
+ $changeSets[] = SWLChangeSet::newFromArray( $set );
}
return $changeSets;
@@ -122,9 +106,9 @@
foreach ( $changeSet->getAllProperties() as /* SMWDIProperty */
$property ) {
foreach ( $changeSet->getAllPropertyChanges( $property
) as /* SMWPropertyChange */ $change ) {
$old = $change->getOldValue();
- $old = is_null( $old ) ? wfMsg( 'swl-novalue' )
: SMWDataValueFactory::newDataItemValue( $old )->getLongWikiText();
+ $old = is_null( $old ) ? wfMsg( 'swl-novalue' )
: SMWDataValueFactory::newDataItemValue( $old, $property )->getLongWikiText();
$new = $change->getNewValue();
- $new = is_null( $new ) ? wfMsg( 'swl-novalue' )
: SMWDataValueFactory::newDataItemValue( $new )->getLongWikiText();
+ $new = is_null( $new ) ? wfMsg( 'swl-novalue' )
: SMWDataValueFactory::newDataItemValue( $new, $property )->getLongWikiText();
$wgOut->addHTML( '<li>' . $old . ' -> ' . $new
. '</li>' );
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs