From d395ad7042611fc58e14f75f3b6a3e694b61d343 Mon Sep 17 00:00:00 2001
From: "Eloy Lafuente (stronk7)" <stronk7@moodle.org>
Date: Fri, 9 Mar 2012 01:58:09 +0100
Subject: [PATCH] Revert "[MDL-31708] - wiki 2.0 non-group member can see edit
 option in navigation block."

This reverts commit ebadb9b9a674f5e91ddb7460ea3f9dafc6c34523.
---
 mod/wiki/lang/en/wiki.php |  2 --
 mod/wiki/lib.php          |  2 +-
 mod/wiki/locallib.php     |  2 +-
 mod/wiki/pagelib.php      | 10 ++++++++--
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/mod/wiki/lang/en/wiki.php b/mod/wiki/lang/en/wiki.php
index 569b5575766..09a6c586a21 100644
--- a/mod/wiki/lang/en/wiki.php
+++ b/mod/wiki/lang/en/wiki.php
@@ -22,10 +22,8 @@ $string['backoldversion'] = 'Back to old version';
 $string['backpage'] = 'Back to page';
 $string['backtomapmenu'] = 'Back to map menu';
 $string['changerate'] = 'Do you wish to change it?';
-$string['cannoteditpage'] = 'You can not edit this page.';
 $string['cannotmanagefiles'] = 'You don\'t have permission to manage the wiki files.';
 $string['cannotviewfiles'] = 'You don\'t have permission to view the wiki files.';
-$string['cannotviewpage'] = 'You can not view this page.';
 $string['comparesel'] = 'Compare selected';
 $string['comments'] = 'Comments';
 $string['commentscount'] = 'Comments ({$a})';
diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php
index f7b5e7ea515..d1e78cb7fee 100644
--- a/mod/wiki/lib.php
+++ b/mod/wiki/lib.php
@@ -543,7 +543,7 @@ function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm)
             $node = $navref->add(get_string('view', 'wiki'), $link, navigation_node::TYPE_SETTING);
         }
 
-		if (wiki_user_can_edit($subwiki)) {
+        if (has_capability('mod/wiki:editpage', $context)) {
             $link = new moodle_url('/mod/wiki/edit.php', array('pageid' => $pageid));
             $node = $navref->add(get_string('edit', 'wiki'), $link, navigation_node::TYPE_SETTING);
         }
diff --git a/mod/wiki/locallib.php b/mod/wiki/locallib.php
index 2351f4327c4..4270d2b4275 100644
--- a/mod/wiki/locallib.php
+++ b/mod/wiki/locallib.php
@@ -764,7 +764,7 @@ function wiki_user_can_view($subwiki) {
         //      Each person owns a wiki.
         if ($wiki->wikimode == 'collaborative' || $wiki->wikimode == 'individual') {
             // Only members of subwiki group could view that wiki
-            if (groups_is_member($subwiki->groupid)) {
+            if ($subwiki->groupid == groups_get_activity_group($cm)) {
                 // Only view capability needed
                 return has_capability('mod/wiki:viewpage', $context);
 
diff --git a/mod/wiki/pagelib.php b/mod/wiki/pagelib.php
index 180d5c3cd22..ac21684ebc4 100644
--- a/mod/wiki/pagelib.php
+++ b/mod/wiki/pagelib.php
@@ -172,6 +172,10 @@ abstract class page_wiki {
             if (!$manage and !($edit and groups_is_member($currentgroup))) {
                 unset($this->tabs['edit']);
             }
+        } else {
+            if (!has_capability('mod/wiki:editpage', $PAGE->context)) {
+                unset($this->tabs['edit']);
+            }
         }
 
 
@@ -320,7 +324,8 @@ class page_wiki_view extends page_wiki {
                 }
             }
         } else {
-            echo get_string('cannotviewpage', 'wiki');
+            // @TODO: Tranlate it
+            echo "You can not view this page";
         }
     }
 
@@ -413,7 +418,8 @@ class page_wiki_edit extends page_wiki {
         if (wiki_user_can_edit($this->subwiki)) {
             $this->print_edit();
         } else {
-            echo get_string('cannoteditpage', 'wiki');
+            // @TODO: Translate it
+            echo "You can not edit this page";
         }
     }