http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88421

Revision: 88421
Author:   jeroendedauw
Date:     2011-05-19 19:09:07 +0000 (Thu, 19 May 2011)
Log Message:
-----------
work on watchlist group management

Modified Paths:
--------------
    trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
    trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
    trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
    trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js

Added Paths:
-----------
    trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
    trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php
    trunk/extensions/SemanticWatchlist/api/ApiEditWatchlistGroup.php

Removed Paths:
-------------
    trunk/extensions/SemanticWatchlist/api/ApiSemanticWatchlist.php

Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.php    2011-05-19 
19:03:24 UTC (rev 88420)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.php    2011-05-19 
19:09:07 UTC (rev 88421)
@@ -5,7 +5,7 @@
  * 
  * Documentation:                      
http://www.mediawiki.org/wiki/Extension:Semantic_Watchlist
  * Support                                     
http://www.mediawiki.org/wiki/Extension_talk:Semantic_Watchlist
- * Source code:             
http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SemanticWatchlist
+ * Source code:                         
http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SemanticWatchlist
  *
  * @file SemanticWatchlist.php
  * @ingroup SemanticWatchlist
@@ -52,21 +52,23 @@
 
 $egSWLScriptPath = $wgExtensionAssetsPath === false ? $wgScriptPath . 
'/extensions/SemanticWatchlist' : $wgExtensionAssetsPath . '/SemanticWatchlist';
 
-$wgExtensionMessagesFiles['SemanticWatchlist']      = dirname( __FILE__ ) . 
'/SemanticWatchlist.i18n.php';
+$wgExtensionMessagesFiles['SemanticWatchlist']         = dirname( __FILE__ ) . 
'/SemanticWatchlist.i18n.php';
 $wgExtensionAliasesFiles['SemanticWatchlist']          = dirname( __FILE__ ) . 
'/SemanticWatchlist.i18n.alias.php';
 
-$wgAutoloadClasses['SWLHooks']                      = dirname( __FILE__ ) . 
'/SemanticWatchlist.hooks.php';
+$wgAutoloadClasses['SWLHooks']                                         = 
dirname( __FILE__ ) . '/SemanticWatchlist.hooks.php';
 
-$wgAutoloadClasses['ApiQuerySemanticWatchlist']     = dirname( __FILE__ ) . 
'/api/ApiQuerySemanticWatchlist.php';
-$wgAutoloadClasses['ApiSemanticWatchlist']          = dirname( __FILE__ ) . 
'/api/ApiSemanticWatchlist.php';
+$wgAutoloadClasses['ApiAddWatchlistGroup']                     = dirname( 
__FILE__ ) . '/api/ApiAddWatchlistGroup.php';
+$wgAutoloadClasses['ApiDeleteWatchlistGroup']          = dirname( __FILE__ ) . 
'/api/ApiDeleteWatchlistGroup.php';
+$wgAutoloadClasses['ApiEditWatchlistGroup']                    = dirname( 
__FILE__ ) . '/api/ApiEditWatchlistGroup.php';
+$wgAutoloadClasses['ApiQuerySemanticWatchlist']                = dirname( 
__FILE__ ) . '/api/ApiQuerySemanticWatchlist.php';
 
-$wgAutoloadClasses['SWLChangeSet']                     = dirname( __FILE__ ) . 
'/includes/SWL_ChangeSet.php';
-$wgAutoloadClasses['SWLEmailer']                               = dirname( 
__FILE__ ) . '/includes/SWL_Emailer.php';
-$wgAutoloadClasses['SWLGroup']                                 = dirname( 
__FILE__ ) . '/includes/SWL_Group.php';
-$wgAutoloadClasses['SWLGroups']                                = dirname( 
__FILE__ ) . '/includes/SWL_Groups.php';
+$wgAutoloadClasses['SWLChangeSet']                                     = 
dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php';
+$wgAutoloadClasses['SWLEmailer']                                       = 
dirname( __FILE__ ) . '/includes/SWL_Emailer.php';
+$wgAutoloadClasses['SWLGroup']                                         = 
dirname( __FILE__ ) . '/includes/SWL_Group.php';
+$wgAutoloadClasses['SWLGroups']                                                
= dirname( __FILE__ ) . '/includes/SWL_Groups.php';
 
-$wgAutoloadClasses['SpecialSemanticWatchlist']      = dirname( __FILE__ ) . 
'/specials/SpecialSemanticWatchlist.php';
-$wgAutoloadClasses['SpecialWatchlistConditions']    = dirname( __FILE__ ) . 
'/specials/SpecialWatchlistConditions.php';
+$wgAutoloadClasses['SpecialSemanticWatchlist']         = dirname( __FILE__ ) . 
'/specials/SpecialSemanticWatchlist.php';
+$wgAutoloadClasses['SpecialWatchlistConditions']       = dirname( __FILE__ ) . 
'/specials/SpecialWatchlistConditions.php';
 
 $wgSpecialPages['SemanticWatchlist'] = 'SpecialSemanticWatchlist';
 $wgSpecialPageGroups['SemanticWatchlist'] = 'changes';
@@ -74,7 +76,9 @@
 $wgSpecialPages['WatchlistConditions'] = 'SpecialWatchlistConditions';
 $wgSpecialPageGroups['WatchlistConditions'] = 'changes';
 
-$wgAPIModules['semanticwatchlist'] = 'ApiSemanticWatchlist';
+$wgAPIModules['addswlgroup'] = 'ApiAddWatchlistGroup';
+$wgAPIModules['deleteswlgroup'] = 'ApiDeleteWatchlistGroup';
+$wgAPIModules['editswlgroup'] = 'ApiEditWatchlistGroup';
 $wgAPIListModules['semanticwatchlist'] = 'ApiQuerySemanticWatchlist';
 
 $wgHooks['LoadExtensionSchemaUpdates'][] = 'SWLHooks::onSchemaUpdate';
@@ -128,5 +132,5 @@
 $wgAvailableRights[] = 'semanticwatchgroups';
 
 if ( $egSWLEnableEmailNotify ) {
-    $wgHooks['SWLGroupNotify'][] = 'SWLHooks::onGroupNotify';
+       $wgHooks['SWLGroupNotify'][] = 'SWLHooks::onGroupNotify';
 }

Added: trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php             
                (rev 0)
+++ trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php     
2011-05-19 19:09:07 UTC (rev 88421)
@@ -0,0 +1,97 @@
+<?php
+
+/**
+ * API module to add semantic watchlist groups.
+ *
+ * @since 0.1
+ *
+ * @file ApiAddWatchlistGroup.php
+ * @ingroup SemanticWatchlist
+ * @ingroup API
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ApiAddWatchlistGroup extends ApiBase {
+       
+       public function __construct( $main, $action ) {
+               parent::__construct( $main, $action );
+       }
+       
+       public function execute() {
+               global $wgUser;
+               
+               if ( !$wgUser->isAllowed( 'semanticwatchgroups' ) || 
$wgUser->isBlocked() ) {
+                       $this->dieUsageMsg( array( 'badaccess-groups' ) );
+               }                       
+               
+               $params = $this->extractRequestParams();
+               
+               $group = new SWLGroup(
+                       null,
+                       $params['name'],
+                       $params['categories'],
+                       $params['namespaces'],
+                       $params['properties'],
+                       $params['concepts']
+               );
+               
+               $group->writeToDB();
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'name' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true,
+                       ),
+                       'properties' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_REQUIRED => true,
+                       ),
+                       'categories' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_DFLT => '',
+                       ),
+                       'namespaces' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_DFLT => '',
+                       ),
+                       'concepts' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_DFLT => '',
+                       ),
+               );
+       }
+       
+       public function getParamDescription() {
+               return array(
+               );
+       }
+       
+       public function getDescription() {
+               return array(
+                       'API module to add semantic watchlist groups.'
+               );
+       }
+       
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+               ) );
+       }
+
+       protected function getExamples() {
+               return array(
+                       'api.php?action=addswlgroup&name=My group of 
awesome&properties=Has awesomeness|Has epicness&categories=Awesome stuff',
+               );
+       }       
+       
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }               
+       
+}


Property changes on: 
trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php          
                (rev 0)
+++ trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php  
2011-05-19 19:09:07 UTC (rev 88421)
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * API module to delete semantic watchlist groups.
+ *
+ * @since 0.1
+ *
+ * @file ApiDeleteWatchlistGroup.php
+ * @ingroup SemanticWatchlist
+ * @ingroup API
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ApiDeleteWatchlistGroup extends ApiBase {
+       
+       public function __construct( $main, $action ) {
+               parent::__construct( $main, $action );
+       }
+       
+       public function execute() {
+               global $wgUser;
+               
+               if ( !$wgUser->isAllowed( 'semanticwatchgroups' ) || 
$wgUser->isBlocked() ) {
+                       $this->dieUsageMsg( array( 'badaccess-groups' ) );
+               }
+               
+               $params = $this->extractRequestParams();
+               
+               $dbw = wfGetDB( DB_MASTER );
+               
+               $dbw->begin();
+               
+               foreach ( $params['ids'] as $id ) {
+                       $dbw->delete(
+                               'swl_groups',
+                               array( 'group_id' => $id )
+                       );                      
+               }
+               
+               $dbw->commit();
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'ids' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_REQUIRED => true,
+                               ApiBase::PARAM_ISMULTI => true,
+                       ),
+               );
+       }
+       
+       public function getParamDescription() {
+               return array(
+               );
+       }
+       
+       public function getDescription() {
+               return array(
+                       'API module to delete semantic watchlist groups.'
+               );
+       }
+               
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'missingparam', 'ids' ),
+               ) );
+       }
+
+       protected function getExamples() {
+               return array(
+                       'api.php?action=deleteswlgroup&ids=42|34',
+               );
+       }       
+       
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }               
+       
+}


Property changes on: 
trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: trunk/extensions/SemanticWatchlist/api/ApiEditWatchlistGroup.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiEditWatchlistGroup.php            
                (rev 0)
+++ trunk/extensions/SemanticWatchlist/api/ApiEditWatchlistGroup.php    
2011-05-19 19:09:07 UTC (rev 88421)
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * API module to modify semantic watchlist groups.
+ *
+ * @since 0.1
+ *
+ * @file ApiEditWatchlistGroup.php
+ * @ingroup SemanticWatchlist
+ * @ingroup API
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ApiEditWatchlistGroup extends ApiBase {
+       
+       public function __construct( $main, $action ) {
+               parent::__construct( $main, $action );
+       }
+       
+       public function execute() {
+               global $wgUser;
+               
+               if ( !$wgUser->isAllowed( 'semanticwatchgroups' ) || 
$wgUser->isBlocked() ) {
+                       $this->dieUsageMsg( array( 'badaccess-groups' ) );
+               }
+               
+               $params = $this->extractRequestParams();
+               
+       }
+
+       public function getAllowedParams() {
+               return array(
+               );
+       }
+       
+       public function getParamDescription() {
+               return array(
+               );
+       }
+       
+       public function getDescription() {
+               return array(
+                       'API module to modify semantic watchlist groups.'
+               );
+       }
+               
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+               ) );
+       }
+
+       protected function getExamples() {
+               return array(
+                       'api.php?action=semanticwatchlist',
+               );
+       }       
+       
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }               
+       
+}


Property changes on: 
trunk/extensions/SemanticWatchlist/api/ApiEditWatchlistGroup.php
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php        
2011-05-19 19:03:24 UTC (rev 88420)
+++ trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php        
2011-05-19 19:09:07 UTC (rev 88421)
@@ -7,6 +7,7 @@
  *
  * @file ApiQuerySemanticWatchlist.php
  * @ingroup SemanticWatchlist
+ * @ingroup API
  *
  * @licence GNU GPL v3+
  * @author Jeroen De Dauw < [email protected] >

Deleted: trunk/extensions/SemanticWatchlist/api/ApiSemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiSemanticWatchlist.php     
2011-05-19 19:03:24 UTC (rev 88420)
+++ trunk/extensions/SemanticWatchlist/api/ApiSemanticWatchlist.php     
2011-05-19 19:09:07 UTC (rev 88421)
@@ -1,56 +0,0 @@
-<?php
-
-/**
- * API module to modify semantic watchlist groups.
- *
- * @since 0.1
- *
- * @file ApiSemanticWatchlist.php
- * @ingroup SemanticWatchlist
- *
- * @licence GNU GPL v3+
- * @author Jeroen De Dauw < [email protected] >
- */
-class ApiSemanticWatchlist extends ApiBase {
-       
-       public function __construct( $main, $action ) {
-               parent::__construct( $main, $action );
-       }
-       
-       public function execute() {
-               $params = $this->extractRequestParams();
-               
-       }
-
-       public function getAllowedParams() {
-               return array(
-               );
-       }
-       
-       public function getParamDescription() {
-               return array(
-               );
-       }
-       
-       public function getDescription() {
-               return array(
-                       'API module to modify semantic watchlist groups.'
-               );
-       }
-               
-       public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
-               ) );
-       }
-
-       protected function getExamples() {
-               return array(
-                       'api.php?action=semanticwatchlist',
-               );
-       }       
-       
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
-       }               
-       
-}

Modified: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_Group.php   2011-05-19 
19:03:24 UTC (rev 88420)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_Group.php   2011-05-19 
19:09:07 UTC (rev 88421)
@@ -47,6 +47,46 @@
                $this->concepts = $concepts;    
        }
        
+       public function writeToDB() {
+               if ( is_null( $this->id ) ) {
+                       $this->insertIntoDB();
+               }
+               else {
+                       $this->updateInDB();
+               }
+       }
+       
+       protected function updateInDB() {
+               $dbr = wfGetDB( DB_MASTER );
+               
+               $dbr->update(
+                       'swl_groups',
+                       array(
+                               'group_name' => $this->name,
+                               'group_properties' => $this->properties,
+                               'group_categories' => $this->categories,
+                               'group_namespaces' => $this->namespaces,
+                               'group_concepts' => $this->concepts,
+                       ),
+                       array( 'group_id' => $this->id )
+               );
+       }
+       
+       protected function insertIntoDB() {
+               $dbr = wfGetDB( DB_MASTER );
+               
+               $dbr->insert(
+                       'swl_groups',
+                       array(
+                               'group_name' => $this->name,
+                               'group_properties' => $this->properties,
+                               'group_categories' => $this->categories,
+                               'group_namespaces' => $this->namespaces,
+                               'group_concepts' => $this->concepts,
+                       )
+               );
+       }
+       
        /**
         * Returns the categories specified by the group.
         * 

Modified: 
trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js    
2011-05-19 19:03:24 UTC (rev 88420)
+++ trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js    
2011-05-19 19:09:07 UTC (rev 88421)
@@ -16,8 +16,7 @@
                var table = $( '<table />' ).attr( { 'class': 'swltable' } );
                
                var propTd = $( '<td />' ).attr( {
-                       //'bgcolor': 'gray',
-                       'rowspan': 3
+                       'rowspan': 2
                } );
                
                propTd.html( mediaWiki.msg( 'swl-group-properties' ) );
@@ -26,15 +25,13 @@
                        propTd.append( this.getPropertyDiv( group.properties[i] 
) );
                }
                
-               table.append( $( '<tr />' ).html( $( '<td />' ) ).append( 
propTd ) );
-               
                var nameInput = $( '<input />' ).attr( {
                        'type': 'text',
                        'value': group.name,
                        'size': 30
                } );
                var nameTd = $( '<td />' ).html( $( '<p />' ).text( 
mediaWiki.msg( 'swl-group-name' ) + ' ' ).append( nameInput ) );
-               table.append( $( '<tr />' ).html( nameTd ) );
+               table.append( $( '<tr />' ).html( nameTd ).append( propTd ) );
                
                var conditionValue, conditionType;
                
@@ -114,6 +111,18 @@
        }
        
        this.doSave = function( callback ) {
+               $.getJSON(
+                       wgScriptPath + '/api.php',
+                       {
+                               'action': 'semanticwatchlist',
+                               'format': 'json',
+                               'images': images.join( '|' ), 
+                               'targets': targetUrl
+                       },
+                       function( data ) {
+                               callback();
+                       }
+               );
                
        }
        


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to