diff --git a/components/UserPermissions.php b/components/UserPermissions.php index 090b7184..942e7476 100644 --- a/components/UserPermissions.php +++ b/components/UserPermissions.php @@ -161,6 +161,16 @@ public static function canManageNews() return Yii::$app->user->can(self::PERMISSION_MANAGE_NEWS); } + /** + * Authenticated user can manage wiki if he's wiki admin. + * + * @return bool + */ + public static function canManageWiki() + { + return Yii::$app->user->can(self::PERMISSION_MANAGE_WIKI); + } + /** * Check whether authenticated user is an admin. * diff --git a/controllers/WikiController.php b/controllers/WikiController.php index ed723726..b2fe22cd 100644 --- a/controllers/WikiController.php +++ b/controllers/WikiController.php @@ -137,11 +137,24 @@ public function actionIndex($category = null, $tag = null, $version = '2.0') Yii::$app->response->statusCode = 404; } + // Get popular tags, excluding those from deleted wikis for regular users + $tagQuery = WikiTag::find(); + $tagQuery->orderBy(['frequency' => SORT_DESC]); + if (!UserPermissions::canManageWiki()) { + $tagQuery->select(['id' => 'wiki_tag_id', 'name', 'wiki_tags.slug', 'frequency' => 'COUNT(*)']) + ->joinWith(['wikis']) + ->andWhere(['wikis.status' => Wiki::STATUS_PUBLISHED]) + ->groupBy(['wiki_tag_id', 'name', 'slug']) + ->orderBy(['frequency' => SORT_DESC]); + } + $popularTags = $tagQuery->limit(10)->all(); + return $this->render('index', [ 'dataProvider' => $dataProvider, 'tag' => $tagModel, 'category' => $categoryModel, 'version' => $version, + 'popularTags' => $popularTags, ]); } diff --git a/views/wiki/_sidebar.php b/views/wiki/_sidebar.php index 489a14bc..ace1b863 100644 --- a/views/wiki/_sidebar.php +++ b/views/wiki/_sidebar.php @@ -1,8 +1,6 @@ Writenew article', ['create'], ['class' => 'btn btn-block btn-new-wiki-article']) ?> @@ -52,7 +51,7 @@