Ljonka has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311101

Change subject: init commit: create editnotify connector to make user 
preferences available for namespace action notifications
......................................................................

init commit: create editnotify connector to make user preferences available for 
namespace action notifications

disable category notification settings by default

Change-Id: Idf3b35593a664928b1b3cde87464692781853e42
---
A extension.json
A i18n/en.json
A i18n/qqq.json
A includes/BlueSpiceEditNotifyConnector.php
4 files changed, 225 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceEditNotifyConnector
 refs/changes/01/311101/1

diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..eea3268
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,28 @@
+{
+       "name": "BlueSpiceEditNotifyConnector",
+       "version": "0.1.0",
+       "url": 
"https://www.mediawiki.org/wiki/Extension:BlueSpiceEditNotifyConnector";,
+       "authors": ["Leonid Verhovskij"],
+       "AutoloadClasses": {
+               "BlueSpiceEditNotifyConnector": 
"includes/BlueSpiceEditNotifyConnector.php"
+       },
+       "Hooks": {
+               "GetPreferences": 
"BlueSpiceEditNotifyConnector::onGetPreferences",
+               "PageContentSave": 
"BlueSpiceEditNotifyConnector::onPageContentSave"
+       },
+       "AvailableRights": ["namespace-notifications"],
+       "GroupPermissions": {
+               "sysop": {
+                       "namespace-notifications": true
+               }
+       },
+       "config": {
+               "BlueSpiceEditNotifyConnectorShowCategories": false
+       },
+       "MessagesDirs": {
+               "BlueSpiceEditNotifyConnector": [
+                       "i18n"
+               ]
+       },
+       "callback":"BlueSpiceEchoConnector::onRegistry"
+}
\ No newline at end of file
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..2f2b4c7
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,11 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Ljonka"
+               ]
+       },
+       "bluespiceeditnotifyconnector-desc": "Extends EditNotify with user 
options.",
+       "bluespiceeditnotifyconnector-action-message": "Create or edit 
notification for selected namespaces will be send.",
+       "prefs-categories": "Notifications on category events",
+       "prefs-namespace-notifications": "Notifications on namespace events"
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..07be554
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,11 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Ljonka"
+               ]
+       },
+       "bluespiceeditnotifyconnector-desc": "Extension description",
+       "bluespiceeditnotifyconnector-action-message": "Action message for 
extension",
+       "prefs-categories": "Label for user preferences section for 
notification selection matrix of categories",
+       "prefs-namespace-notifications": "Label for user preferences section 
for notification selection matrix of namespaces"
+}
diff --git a/includes/BlueSpiceEditNotifyConnector.php 
b/includes/BlueSpiceEditNotifyConnector.php
new file mode 100644
index 0000000..a416f43
--- /dev/null
+++ b/includes/BlueSpiceEditNotifyConnector.php
@@ -0,0 +1,175 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+class BlueSpiceEditNotifyConnector {
+
+       static $arrActions = array(
+               "create" => "Creation",
+               "edit" => "Edit to existing pages"
+       );
+       static $prefixNamespace = "notify-namespace-selectionpage-";
+       static $prefixCategory = "notify-category-selectionpage-";
+
+       public static function onRegistry() {
+               global $wgExtensionFunctions;
+               $wgExtensionFunctions[] = function() {
+                       global $wgHooks;
+                       $wgHooks[ 'BeforeCreateEchoEvent' ][] = 
"BlueSpiceEditNotifyConnector::onBeforeCreateEchoEvent";
+               };
+       }
+
+       public static function onBeforeCreateEchoEvent( &$echoNotifications, 
$echoNotificationCategories ) {
+               foreach ( $echoNotifications as $key => $val ) {
+                       if ( preg_match( '#^edit-notify#', $key ) === 1 ) {
+                               $val['formatter-class'] = 
"BsNotificationsFormatter";
+                               $echoNotifications[$key] = $val;
+                       }
+               }
+       }
+
+       public static function getColumns() {
+               $arrColumns = array();
+               foreach ( self::$arrActions as $aKey => $aVal ) {
+                       $arrColumns[ wfMessage( $aKey )->text() ] = "page-" . 
$aKey;
+               }
+               return $arrColumns;
+       }
+
+       /**
+        * Hooks/GetPreferences
+        *
+        * https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
+        *
+        * @global type $wgContLang
+        * @param User $user
+        * @param array $preferences
+        * @return boolean
+        */
+       public static function onGetPreferences( User $user, array 
&$preferences ) {
+
+               global $wgContLang, 
$wgBlueSpiceEditNotifyConnectorShowCategories;
+
+               //Add namespace selection matrix
+               $arrNamespaces = array();
+
+               foreach ( $wgContLang->getFormattedNamespaces() as $ns => 
$title ) {
+                       if ( $ns > 0 ) {
+                               $arrNamespaces[ $title ] = $ns;
+                       } elseif ( $ns == 0 ) {
+                               $arrNamespaces[ 'Main' ] = $ns;
+                       }
+               }
+
+               $preferences[ 'notify-namespace-selection' ] = array(
+                       'type' => 'checkmatrix',
+                       'section' => 'echo/namespace-notifications',
+                       'help-message' => 
'tog-help-notify-namespace-selection', // a system message (optional)
+                       'rows' => $arrNamespaces,
+                       'columns' => self::getColumns()
+               );
+
+               //Add category selection matrix, if activated by config var
+               if ( !( boolean ) $wgBlueSpiceEditNotifyConnectorShowCategories 
) {
+                       return true;
+               }
+
+               $arrCategories = array();
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                 'category', // $table
+                 array( 'cat_title', 'cat_id' ), '', // $conds
+                 __METHOD__, // $fname = 'Database::select',
+                 array( 'ORDER BY' => 'cat_title ASC' )  // $options = array()
+               );
+               foreach ( $res as $row ) {
+                       $arrCategories[ $row->cat_title ] = $row->cat_id;
+               }
+
+               $preferences[ 'notify-category-selection' ] = array(
+                       'type' => 'checkmatrix',
+                       'section' => 'echo/categories',
+                       'help-message' => 'tog-help-notify-category-selection', 
// a system message (optional)
+                       'rows' => $arrCategories,
+                       'columns' => self::getColumns()
+               );
+
+               return true;
+       }
+
+       public static function onPageContentSave( WikiPage &$wikiPage, &$user, 
&$content, &$summary, $isMinor, $isWatch, $section, &$flags, &$status ) {
+
+               global $wgContLang, $wgEditNotifyAlerts, 
$wgBlueSpiceEditNotifyConnectorShowCategories;
+
+               $wgEditNotifyAlerts = array();
+
+               $nsID = $wikiPage->getTitle()->getNamespace();
+               $arrNamespaces = $wgContLang->getFormattedNamespaces();
+               $nsTitle = $arrNamespaces[ $nsID ];
+
+               $dbr = wfGetDB( DB_SLAVE );
+
+               //set config for namespaces
+               foreach ( self::$arrActions as $aKey => $aVal ) {
+                       $arrNSNotifyConfig = array();
+                       $arrNSNotifyConfig[ "namespace" ] = $nsTitle;
+                       $arrNSNotifyConfig[ "action" ] = $aKey;
+                       $dbProperty = self::$prefixNamespace . $aKey . '-' . 
$nsID;
+                       //get users with abo fir current namespace and action 
combination
+                       $res = $dbr->select(
+                         array( 'user_properties', 'user' ), array( 
'user_name' ), array( 'up_property' => $dbProperty, 'up_value' => 1 ), 
__METHOD__, array(), array( 'user' =>
+                               array( 'INNER JOIN',
+                                       array( 'user_id=up_user' )
+                               )
+                         )
+                       );
+                       $arrUser = array();
+                       foreach ( $res as $row ) {
+                               $arrUser[] = $row->user_name;
+                       }
+                       $arrNSNotifyConfig[ "users" ] = $arrUser;
+
+                       $wgEditNotifyAlerts[] = $arrNSNotifyConfig;
+               }
+
+               //Add category config, if activated by config var
+               if ( !( boolean ) $wgBlueSpiceEditNotifyConnectorShowCategories 
) {
+                       return true;
+               }
+
+               $arrCategories = $wikiPage->getCategories();
+
+               //set config for categories
+               foreach ( $arrCategories as $category ) {
+                       foreach ( self::$arrActions as $aKey => $aVal ) {
+                               $arrNSNotifyConfig = array();
+                               $arrNSNotifyConfig[ "category" ] = $category;
+                               $arrNSNotifyConfig[ "action" ] = $aKey;
+                               $dbProperty = self::$prefixCategory . $aKey . 
'-' . $nsID;
+                               //get users with abo fir current namespace and 
action combination
+                               $res = $dbr->select(
+                                 array( 'user_properties', 'user' ), array( 
'user_name' ), array( 'up_property' => $dbProperty, 'up_value' => 1 ), 
__METHOD__, array(), array( 'user' =>
+                                       array( 'INNER JOIN',
+                                               array( 'user_id=up_user' )
+                                       )
+                                 )
+                               );
+                               $arrUser = array();
+                               foreach ( $res as $row ) {
+                                       $arrUser[] = $row->user_name;
+                               }
+                               $arrNSNotifyConfig[ "users" ] = $arrUser;
+
+                               $wgEditNotifyAlerts[] = $arrNSNotifyConfig;
+                       }
+               }
+
+               return true;
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/311101
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idf3b35593a664928b1b3cde87464692781853e42
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceEditNotifyConnector
Gerrit-Branch: master
Gerrit-Owner: Ljonka <l.verhovs...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to