Ljonka has submitted this change and it was merged. 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 improve documentation and resource context usage fix extensionjson typo add custom table for faster lookup on notification action add return onBeforeCreateEchoEvent complete version information in extension.json Change-Id: Idf3b35593a664928b1b3cde87464692781853e42 --- A db/editnotifyconnector.sql A extension.json A i18n/en.json A i18n/qqq.json A includes/BlueSpiceEditNotifyConnector.php 5 files changed, 283 insertions(+), 0 deletions(-) Approvals: Robert Vogel: Looks good to me, approved Ljonka: Verified diff --git a/db/editnotifyconnector.sql b/db/editnotifyconnector.sql new file mode 100644 index 0000000..24c0fd3 --- /dev/null +++ b/db/editnotifyconnector.sql @@ -0,0 +1,16 @@ +BEGIN; + +CREATE TABLE /*_*/editnotifyconnector( +-- Primary key +enc_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, +-- namespace.id of the namespace for notifications +enc_ns_id INT UNSIGNED NOT NULL, +-- user.username of the user who selected to be notified on namespace activity +enc_username VARCHAR(256), +-- action type like "edit" or "create" +enc_action VARCHAR(256) +)/*$wgDBTableOptions*/; + +CREATE INDEX /*i*/enc_ns_id ON /*_*/editnotifyconnector (enc_ns_id); +CREATE INDEX /*i*/enc_action ON /*_*/editnotifyconnector (enc_action); +COMMIT; \ No newline at end of file diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..855dd07 --- /dev/null +++ b/extension.json @@ -0,0 +1,34 @@ +{ + "name": "BlueSpiceEditNotifyConnector", + "version": "0.1.0", + "url": "https://www.mediawiki.org/wiki/Extension:BlueSpiceEditNotifyConnector", + "license-name": "GPL-2.0+", + "descriptionmsg": "bluespiceeditnotifyconnector-desc", + "author": [ + "Leonid Verhovskij" + ], + "AutoloadClasses": { + "BlueSpiceEditNotifyConnector": "includes/BlueSpiceEditNotifyConnector.php" + }, + "Hooks": { + "GetPreferences": "BlueSpiceEditNotifyConnector::onGetPreferences", + "PageContentSave": "BlueSpiceEditNotifyConnector::onPageContentSave", + "LoadExtensionSchemaUpdates": "BlueSpiceEditNotifyConnector::onLoadExtensionSchemaUpdates", + "UserSaveOptions": "BlueSpiceEditNotifyConnector::onUserSaveOptions" + }, + "AvailableRights": ["namespace-notifications"], + "GroupPermissions": { + "sysop": { + "namespace-notifications": true + } + }, + "config": { + "BlueSpiceEditNotifyConnectorShowCategories": false + }, + "MessagesDirs": { + "BlueSpiceEditNotifyConnector": [ + "i18n" + ] + }, + "callback":"BlueSpiceEditNotifyConnector::onRegistry" +} \ No newline at end of file diff --git a/i18n/en.json b/i18n/en.json new file mode 100644 index 0000000..99c095f --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,11 @@ +{ + "@metadata": { + "authors": [ + "Ljonka" + ] + }, + "bluespiceeditnotifyconnector-desc": "Extends EditNotify with useroptions.", + "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..cbc37f4 --- /dev/null +++ b/includes/BlueSpiceEditNotifyConnector.php @@ -0,0 +1,211 @@ +<?php + +class BlueSpiceEditNotifyConnector { + + static $tableName = "editnotifyconnector"; + + /** + * + * @var array available action types with labels + */ + static $arrActions = array( //labels will not be used + "create" => "Creation", + "edit" => "Edit to existing pages" + ); + + /** + * + * @var string prefix + */ + static $prefixNamespace = "notify-namespace-selectionpage-"; + + /** + * + * @var string prefix + */ + static $prefixCategory = "notify-category-selectionpage-"; + + /** + * change echo notification formatter to bluespice custom version before editnotify process notifications + * @global array $wgExtensionFunctions + */ + public static function onRegistry() { + global $wgExtensionFunctions; + $wgExtensionFunctions[] = function() { + global $wgHooks; + $wgHooks[ 'BeforeCreateEchoEvent' ][] = "BlueSpiceEditNotifyConnector::onBeforeCreateEchoEvent"; + }; + } + + /** + * register notifications for editnotify, should be included / started before same hook call of editnotify + * @param array $echoNotifications + * @param array $echoNotificationCategories + */ + 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; + } + } + return true; + } + + /** + * + * @return array converted column options from $arrActions for checkmatrix + */ + public static function getColumns() { + $arrColumns = array(); + foreach ( self::$arrActions as $sKey => $oVal ) { + $arrColumns[ wfMessage( $sKey )->text() ] = "page-" . $sKey; + } + return $arrColumns; + } + + /** + * Hooks/GetPreferences + * + * make user options available to set namespace and category notifications + * per default categories are hidden and can be activated over config setting + * "$wgBlueSpiceEditNotifyConnectorShowCategories = true" in LocalSettings.php + * + * https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences + * + * @param User $user + * @param array $preferences + * @return boolean + */ + public static function onGetPreferences( User $user, array &$preferences ) { + + $requestContext = RequestContext::getMain(); + $contLang = $requestContext->getLanguage(); + + //Add namespace selection matrix + $arrNamespaces = array(); + + foreach ( $contLang->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() + ); + + return true; + } + + /** + * save namespace notification settings in seperate table + * @param User $user + * @param array $options + * @return boolean handover to next call + */ + public static function onUserSaveOptions( User $user, array &$options ) { + $dbw = wfGetDB( DB_MASTER ); + //remove all namespace settings for current user from editnotifyconnector table + $dbw->delete( self::$tableName, array( "enc_username" => $user->getName() ) ); + //set editnotifyconnector entries for current user + $nsNotifyOptions = array_filter( $options, function( $key ) { + if ( strpos( $key, 'notify-namespace-selection' ) === 0 ) { + return true; + } else { + return false; + } + }, ARRAY_FILTER_USE_KEY ); + foreach ( $nsNotifyOptions as $sKey => $sValue ) { + $arrKey = explode( "-", $sKey ); + $action = $arrKey[ 3 ]; + $nsId = $arrKey[ 4 ]; + if ( $sValue ) { + $dbw->insert( + self::$tableName, + array( + "enc_ns_id" => $nsId, + "enc_username" => $user->getName(), + "enc_action" => $action + ) + ); + } + } + + return true; + } + + /** + * append content on global settings "$wgEditNotifyAlerts" for editnotify + * from database for namespace of current page, lookup user settings with maching + * namespace notification settings + * + * @global type $wgContLang + * @global type $wgEditNotifyAlerts + * @global type $wgBlueSpiceEditNotifyConnectorShowCategories + * @param WikiPage $wikiPage + * @param User $user + * @param type $content + * @param type $summary + * @param type $isMinor + * @param type $isWatch + * @param type $section + * @param type $flags + * @param type $status + * @return boolean + */ + public static function onPageContentSave( WikiPage &$wikiPage, &$user, &$content, &$summary, $isMinor, $isWatch, $section, &$flags, &$status ) { + + $requestContext = RequestContext::getMain(); + $contLang = $requestContext->getLanguage(); + + global $wgEditNotifyAlerts; + + $wgEditNotifyAlerts = array(); + + $nsID = $wikiPage->getTitle()->getNamespace(); + $arrNamespaces = $contLang->getFormattedNamespaces(); + $nsTitle = $arrNamespaces[ $nsID ]; + + $dbr = wfGetDB( DB_SLAVE ); + + //set config for namespaces + foreach ( self::$arrActions as $oKey => $oVal ) { + $arrNSNotifyConfig = array(); + $arrNSNotifyConfig[ "namespace" ] = $nsTitle; + $arrNSNotifyConfig[ "action" ] = $oKey; + //get users with abo for current namespace and action combination + $res = $dbr->select( + array( self::$tableName ), + array( 'enc_username' ), + array( 'enc_ns_id' => $nsID, 'enc_action' => $oKey ) + ); + $arrUser = array(); + foreach ( $res as $row ) { + $arrUser[] = $row->enc_username; + } + $arrNSNotifyConfig[ "users" ] = $arrUser; + + $wgEditNotifyAlerts[] = $arrNSNotifyConfig; + } + + return true; + } + + /** + * + * @param DatabaseUpdater $updater + * @return boolean + */ + public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { + $updater->addExtensionTable( self::$tableName, __DIR__ . "/../db/editnotifyconnector.sql" ); + return true; + } + +} -- To view, visit https://gerrit.wikimedia.org/r/311101 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Idf3b35593a664928b1b3cde87464692781853e42 Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/extensions/BlueSpiceEditNotifyConnector Gerrit-Branch: master Gerrit-Owner: Ljonka <l.verhovs...@gmail.com> Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com> Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz> Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz> Gerrit-Reviewer: Raimond Spekking <raimond.spekk...@gmail.com> Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits