Robert Vogel has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/352847 )

Change subject: [WiP] BSPageAssignments: Adding Asignee "everyone"
......................................................................

[WiP] BSPageAssignments: Adding Asignee "everyone"

Allows to assign every user

Change-Id: Ia3d41c4e75a18dd842154c17004e35ad8cc6bfe9
---
M PageAssignments/PageAssignments.class.php
M PageAssignments/extension.json
M PageAssignments/i18n/de.json
M PageAssignments/i18n/en.json
M PageAssignments/i18n/qqq.json
M PageAssignments/includes/BSAssignableBase.php
A PageAssignments/includes/BSAssignableEveryone.php
M PageAssignments/includes/BSAssignableGroup.php
M PageAssignments/includes/BSAssignableUser.php
M PageAssignments/includes/PageAssignmentsHooks.php
M PageAssignments/includes/api/BSApiMyPageAssignmentStore.php
M PageAssignments/resources/ext.bluespice.pageassignments.less
12 files changed, 161 insertions(+), 50 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/47/352847/1

diff --git a/PageAssignments/PageAssignments.class.php 
b/PageAssignments/PageAssignments.class.php
index 7db8865..77dde40 100644
--- a/PageAssignments/PageAssignments.class.php
+++ b/PageAssignments/PageAssignments.class.php
@@ -26,6 +26,7 @@
         */
        public static function onRegistration() {
                $GLOBALS['bsgPageAssigneeTypes'] = array(
+                       #'specialeveryone' => 'BSAssignableEveryone', //Can be 
activated in LocalSettings.php if needed
                        'group' => 'BSAssignableGroup',
                        'user' => 'BSAssignableUser'
                );
diff --git a/PageAssignments/extension.json b/PageAssignments/extension.json
index 0215283..57f910d 100644
--- a/PageAssignments/extension.json
+++ b/PageAssignments/extension.json
@@ -60,6 +60,7 @@
                "PageAssignmentsWikiExplorerHooks": 
"includes/PageAssignmentsWikiExplorerHooks.php",
                "PageAssignmentsDashboardHooks": 
"includes/PageAssignmentsDashboardHooks.php",
                "BSAssignableBase": "includes/BSAssignableBase.php",
+               "BSAssignableEveryone": "includes/BSAssignableEveryone.php",
                "BSAssignableUser": "includes/BSAssignableUser.php",
                "BSAssignableGroup": "includes/BSAssignableGroup.php",
                "SpecialPageAssignments": 
"includes/specials/SpecialPageAssignments.php",
@@ -193,5 +194,8 @@
                "BSGroupManagerGroupNameChanged": 
"PageAssignmentsHooks::onBSGroupManagerGroupNameChanged",
                "BSGroupManagerGroupDeleted": 
"PageAssignmentsHooks::onBSGroupManagerGroupDeleted"
        },
+       "ResourceLoaderLESSVars" : {
+               "bs-pageassignments-icon-specialeveryone-color": 
"@bs-color-tertiary"
+       },
        "manifest_version": 1
 }
diff --git a/PageAssignments/i18n/de.json b/PageAssignments/i18n/de.json
index ff937d6..7fe89c4 100644
--- a/PageAssignments/i18n/de.json
+++ b/PageAssignments/i18n/de.json
@@ -65,5 +65,6 @@
        "right-pageassignments": "Die Zuweisungen einer Seite bearbeiten 
können",
        "prefs-pageassign": "Zuweisung",
        "bs-usagetracker-pageassignments": "Seiten mit Zuweisungen",
-       "apihelp-bs-mypageassignment-store-description": "Gibt Seiten zurück, 
die dem aktuellen Benutzer zugewiesen sind."
+       "apihelp-bs-mypageassignment-store-description": "Gibt Seiten zurück, 
die dem aktuellen Benutzer zugewiesen sind.",
+       "bs-pageassignments-assignee-special-everyone-label": "Jeder"
 }
diff --git a/PageAssignments/i18n/en.json b/PageAssignments/i18n/en.json
index fa4d838..824d433 100644
--- a/PageAssignments/i18n/en.json
+++ b/PageAssignments/i18n/en.json
@@ -66,5 +66,6 @@
        "apihelp-bs-pageassignable-store-description": "Returns the list of 
assignees",
        "apihelp-bs-pageassignment-store-description": "Returns assignments of 
the specific page",
        "apihelp-bs-mypageassignment-store-description": "Returns pages 
assigned to current user",
-       "apihelp-bs-pageassignment-tasks-description": "Get or edit the list of 
assignments for specific page"
+       "apihelp-bs-pageassignment-tasks-description": "Get or edit the list of 
assignments for specific page",
+       "bs-pageassignments-assignee-special-everyone-label": "Everyone"
 }
diff --git a/PageAssignments/i18n/qqq.json b/PageAssignments/i18n/qqq.json
index cd51560..77f6b4b 100644
--- a/PageAssignments/i18n/qqq.json
+++ b/PageAssignments/i18n/qqq.json
@@ -69,5 +69,6 @@
        "apihelp-bs-pageassignable-store-description": 
"{{doc-apihelp-description|bs-pageassignable-store}}",
        "apihelp-bs-pageassignment-store-description": 
"{{doc-apihelp-description|bs-pageassignment-store}}",
        "apihelp-bs-mypageassignment-store-description": 
"{{doc-apihelp-description|bs-mypageassignment-store}}",
-       "apihelp-bs-pageassignment-tasks-description": 
"{{doc-apihelp-description|bs-pageassignment-tasks}}"
+       "apihelp-bs-pageassignment-tasks-description": 
"{{doc-apihelp-description|bs-pageassignment-tasks}}",
+       "bs-pageassignments-assignee-special-everyone-label": "Label for 
combobox list entry that assignes all users to a certain page"
 }
diff --git a/PageAssignments/includes/BSAssignableBase.php 
b/PageAssignments/includes/BSAssignableBase.php
index ed2da9d..1a26666 100644
--- a/PageAssignments/includes/BSAssignableBase.php
+++ b/PageAssignments/includes/BSAssignableBase.php
@@ -41,6 +41,64 @@
                return $aResult;
        }
 
+       /**
+        *
+        * @global array $bsgPageAssigneeTypes
+        * @param User $oUser
+        * @return BSAssignableBase[]
+        */
+       public final static function getForUser( $oUser ) {
+               global $bsgPageAssigneeTypes;
+               $aResult = array();
+
+               foreach( $bsgPageAssigneeTypes as $sTypeKey => $sClassName ) {
+                       $aSubResult = call_user_func_array( 
"$sClassName::doGetForUser", array( $oUser ) );
+                       foreach( $aSubResult as $iPageId => $aAssignables ) {
+                               foreach( $aAssignables as $oAsignee ) {
+                                       self::addOrAppend( $aResult, $iPageId, 
$oAsignee );
+                               }
+                       }
+               }
+
+               return $aResult;
+       }
+
+       /**
+        *
+        * @param User $oUser
+        * @return array in form of [ <page_id> => [ <AssignableBase>, 
<AssignableBase>, ... ] ]
+        */
+       protected static function doGetForUser( $oUser ) {
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                       'bs_pageassignments',
+                       '*',
+                       static::getQueryConds( $oUser )
+               );
+
+               $aResult = [];
+               foreach( $res as $row ) {
+                       $oAssignee = self::factory( $row->pa_assignee_type, 
$row->pa_assignee_key );
+                       static::addOrAppend( $aResult, $row->pa_page_id, 
$oAssignee );
+               }
+               return $aResult;
+       }
+
+       /**
+        * Just a little helper function to stay DRY
+        * @param array $aResult
+        * @param mixed $mKey
+        * @param mixed $mValue
+        */
+       protected static function addOrAppend( &$aResult, $mKey, $mValue ) {
+               if( isset( $aResult[$mKey] ) ) {
+                       $aResult[$mKey][] = $mValue;
+               }
+               else {
+                       $aResult[$mKey] = [ $mValue ];
+               }
+       }
+
        public function __toString() {
                return $this->sText;
        }
@@ -75,4 +133,6 @@
                        throw new MWException( "Assignee type '$sType' not 
registered" );
                }
        }
+
+       abstract protected static function getQueryConds( $oUser );
 }
\ No newline at end of file
diff --git a/PageAssignments/includes/BSAssignableEveryone.php 
b/PageAssignments/includes/BSAssignableEveryone.php
new file mode 100644
index 0000000..9ffd1e3
--- /dev/null
+++ b/PageAssignments/includes/BSAssignableEveryone.php
@@ -0,0 +1,43 @@
+<?php
+
+class BSAssignableEveryone extends BSAssignableBase {
+
+    protected $sType = 'specialeveryone';
+    protected $sId = 'specialeveryone/everyone';
+
+    public function __construct( $sKey ) {
+               $this->sText = 
wfMessage('bs-pageassignments-assignee-special-everyone-label')->plain();
+               $this->sAnchor = Html::element(
+                       'span',
+                       [
+                       'class' => 'bs-pa-special-everyone'
+                       ],
+                       
wfMessage('bs-pageassignments-assignee-special-everyone-label')->plain()
+               );
+    }
+
+    public static function getList($sQuery, $oContext) {
+               $oAssignableEveryone = new BSAssignableEveryone();
+               return [
+                       $oAssignableEveryone->toStdClass()
+               ];
+    }
+       
+       public function getUserIds() {
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'user', 'user_id' );
+               $aUserIds = [];
+               foreach( $res as $row ) {
+                       $aUserIds[] = $row->user_id;
+               }
+
+               return $aUserIds;
+       }
+
+       protected static function getQueryConds( $oUser ) {
+               return array(
+                       'pa_assignee_type' => 'specialeveryone'
+               );
+       }
+
+}
diff --git a/PageAssignments/includes/BSAssignableGroup.php 
b/PageAssignments/includes/BSAssignableGroup.php
index 2d415d8..2f690a5 100644
--- a/PageAssignments/includes/BSAssignableGroup.php
+++ b/PageAssignments/includes/BSAssignableGroup.php
@@ -66,4 +66,12 @@
 
        }
 
+       protected static function getQueryConds($oUser) {
+               $aGroups = $oUser->getEffectiveGroups();
+               return array(
+                       'pa_assignee_type' => 'group',
+                       'pa_assignee_key' => $aGroups
+               );
+       }
+
 }
\ No newline at end of file
diff --git a/PageAssignments/includes/BSAssignableUser.php 
b/PageAssignments/includes/BSAssignableUser.php
index 721d01a..be305b5 100644
--- a/PageAssignments/includes/BSAssignableUser.php
+++ b/PageAssignments/includes/BSAssignableUser.php
@@ -64,4 +64,11 @@
                );
        }
 
+       protected static function getQueryConds( $oUser ) {
+               return array(
+                       'pa_assignee_type' => 'user',
+                       'pa_assignee_key' => $oUser->getName()
+               );
+       }
+
 }
\ No newline at end of file
diff --git a/PageAssignments/includes/PageAssignmentsHooks.php 
b/PageAssignments/includes/PageAssignmentsHooks.php
index c29a710..629e208 100644
--- a/PageAssignments/includes/PageAssignmentsHooks.php
+++ b/PageAssignments/includes/PageAssignmentsHooks.php
@@ -25,12 +25,13 @@
         * @return boolean
         */
        public static function onBeforePageDisplay( &$out, &$skin ) {
+               $out->addModuleStyles( 'ext.pageassignments.styles' );
+
                if ( $out->getRequest()->getVal( 'action', 'view') !== 'view' 
|| $out->getTitle()->isSpecialPage() ) {
                        return true;
                }
 
                $out->addModules( 'ext.pageassignments.scripts' );
-               $out->addModuleStyles( 'ext.pageassignments.styles' );
 
                return true;
        }
diff --git a/PageAssignments/includes/api/BSApiMyPageAssignmentStore.php 
b/PageAssignments/includes/api/BSApiMyPageAssignmentStore.php
index f347fac..017d240 100644
--- a/PageAssignments/includes/api/BSApiMyPageAssignmentStore.php
+++ b/PageAssignments/includes/api/BSApiMyPageAssignmentStore.php
@@ -2,60 +2,28 @@
 
 class BSApiMyPageAssignmentStore extends BSApiExtJSStoreBase {
 
-       protected function makeData($sQuery = '') {
-               $aResult = array();
+       protected function makeData($sQuery = '') {             
+               $aAssignments = BSAssignableBase::getForUser( $this->getUser() 
);
 
-               //Step 1: get all assignments caused by group membership
-               //TODO: encapsulate and abstract
-               $aGroups = $this->getUser()->getEffectiveGroups();
-               $res = $this->getDB()->select(
-                       'bs_pageassignments',
-                       '*',
-                       array(
-                               'pa_assignee_type' => 'group',
-                               'pa_assignee_key' => $aGroups
-                       )
-               );
+               $aResult = [];
+               foreach( $aAssignments as $iPageId => $aAssignees ) {
+                       $aAssignedBy = [];
+                       foreach( $aAssignees as $oAssignee ) {
+                               $oAssigneeStdClass = $oAssignee->toStdClass();
+                               $aAssignedBy[$oAssigneeStdClass->id] = 
$oAssigneeStdClass;
+                       }
 
-               foreach( $res as $row ) {
-                       $this->appendResult( $aResult, $row );
-               }
-
-               //Step 2: get all assignments caused by direct user assignment
-               //TODO: encapsulate and abstract
-               $res = $this->getDB()->select(
-                       'bs_pageassignments',
-                       '*',
-                       array(
-                               'pa_assignee_type' => 'user',
-                               'pa_assignee_key' => $this->getUser()->getName()
-                       )
-               );
-               foreach( $res as $row ) {
-                       $this->appendResult( $aResult, $row );
-               }
-
-               return $aResult;
-       }
-
-       public function appendResult( &$aResult, $row ) {
-               $oAssignee = BSAssignableBase::factory( $row->pa_assignee_type, 
$row->pa_assignee_key )->toStdClass();
-
-               if( isset( $aResult[$row->pa_page_id] ) ) {
-                       $aResult[$row->pa_page_id]->assigned_by[$oAssignee->id] 
= $oAssignee;
-               }
-               else {
-                       $oTitle = Title::newFromID( $row->pa_page_id );
+                       $oTitle = Title::newFromID( $iPageId );
                        $oDataSet = (object)array(
                                'page_id' => $oTitle->getArticleID(),
                                'page_prefixedtext' => 
$oTitle->getPrefixedText(),
                                'page_link' => Linker::link( $oTitle ),
-                               'assigned_by' => array(
-                                       $oAssignee->id => $oAssignee
-                               )
+                               'assigned_by' => $aAssignedBy
                        );
-                       $aResult[$row->pa_page_id] = $oDataSet;
+                       $aResult[] = $oDataSet;
                }
+
+               return $aResult;
        }
 
        public function filterString($oFilter, $aDataSet) {
diff --git a/PageAssignments/resources/ext.bluespice.pageassignments.less 
b/PageAssignments/resources/ext.bluespice.pageassignments.less
index 615458b..ce3d9ea 100644
--- a/PageAssignments/resources/ext.bluespice.pageassignments.less
+++ b/PageAssignments/resources/ext.bluespice.pageassignments.less
@@ -1,4 +1,20 @@
 #sbb-PageAssignments-Body-text ul {
        list-style-type: none;
        margin: 0;
+}
+
+
+
+#content {
+       #bs-pageassignments-manager,
+       #bs-pageassignments-overview {
+               span.bs-typeicon::before {
+                       color: #333;
+               }
+       }
+       span.bs-icon-specialeveryone:before {
+               content: "\f12e";
+               font-family: 'fontawesome' !important;
+               color: @bs-pageassignments-icon-specialeveryone-color;
+       }
 }
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3d41c4e75a18dd842154c17004e35ad8cc6bfe9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <[email protected]>

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

Reply via email to