Disabling Moderator Inheritance
wnd Offline
Junior Member
**
Posts: 8
Joined: May 2010
Post: #1
Disabling Moderator Inheritance
I'm trying to figure out how to prevent moderators from being inherited from a parent forum.

I managed to disallow the ability itself, but now I'm having trouble with modifying the cache so that the moderator no longer displays as a moderator of that forum.

I've modified class_datacache.php, specifically the build_moderators function, in a way that prevents the parent forum's moderators from being added to the moderator list of that forum:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private function build_moderators($moderators=array(), $pid=0)
	{
		if($this->moderators_forum_cache[$pid])
		{
			foreach($this->moderators_forum_cache[$pid] as $main)
			{
				foreach($main as $forum)
				{
					$forum_mods = '';
					if($this->moderators[$forum['fid']])
					{
						$forum_mods = $this->moderators[$forum['fid']];
					}
					$this->built_moderators[$forum['fid']] = $forum_mods;
					$this->build_moderators($forum_mods, $forum['fid']);
				}
			}
		}
	}


However, even after rebuilding the cache with this new change, the moderator still continues to appear. What am I missing? I've looked at the function update_moderators above it, but it doesn't seem to have anything adding the parent moderators to the subforums.

(If this is in the wrong forum, a move would be appreciated.)

(This post was last modified: 07-02-2011 07:19 AM by wnd.)
07-02-2011 07:16 AM
Find all posts by this user Quote this message in a reply
wnd Offline
Junior Member
**
Posts: 8
Joined: May 2010
Post: #2
RE: Disabling Moderator Inheritance
I think I fixed it - the problem was in two other files which computed the moderators themselves for the forum display.

Now my question is, is there any other files which should be edited, or are these four enough? Also, are these edits to core files safe enough for production? (I'm currently on a localhost install.)

The four files I edited (which seem to have removed mod permission inheritance) are:
  • forumdisplay.php
  • functions.php
  • inc/class_datacache.php
  • inc/functions_forumlist.php
07-02-2011 11:02 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Online
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #3
RE: Disabling Moderator Inheritance
Sorry for the late response (have been spending time fixing up this server and various other things).
Unfortunately, there's not really an easy way to do this, and be sure you've got all cases (thanks to MyBB for not centralising/abstracting this stuff).

It does seem to be weird that MyBB does inheritance in both cache build and when displaying moderators (grandfathered code perhaps?), but oh well...
I'd probably just try tracing data sources in this case.  That is, do a search for $cache->read("moderators"); and $cache->read('moderators'); across all files:

Code:
1
2
3
4
5
6
forumdisplay.php
	Line 127: 	$moderatorcache = $cache->read("moderators");
index.php
	Line 316: 	$moderatorcache = $cache->read("moderators");
inc/functions.php
	Line 316:  $modcache = $cache->read('moderators');

And then a search for $moderatorcache

Code:
1
2
3
4
5
6
7
8
9
10
forumdisplay.php (3 hits)
	Line 127: 	$moderatorcache = $cache->read("moderators");
	Line 183: 	if(is_array($moderatorcache[$mfid]))
	Line 186: 		foreach($moderatorcache[$mfid] as $modtype)
inc/functions_forumlist.php (3 hits)
	Line 21: 	global $fcache, $moderatorcache, $forumpermissions, $theme, $mybb, $templates, $bgcolor, $collapsed, $lang, $showdepth, $plugins, $parser, $forum_viewers;
	Line 294: 					if(is_array($moderatorcache[$mfid]))
	Line 297: 						foreach($moderatorcache[$mfid] as $modtype)
index.php (1 hits)
	Line 316: 	$moderatorcache = $cache->read("moderators");


And maybe double check that the table isn't being queried directly:

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Search "TABLE_PREFIX."moderators" (12 hits in 6 files)
admin/modules/forum/management.php (3 hits)
	Line 1828: 				FROM ".TABLE_PREFIX."moderators m 
	Line 1837: 				FROM ".TABLE_PREFIX."moderators m 
	Line 2465: 			FROM ".TABLE_PREFIX."moderators m
inc/class_datacache.php (2 hits)
	Line 464: 			FROM ".TABLE_PREFIX."moderators m
	Line 485: 			FROM ".TABLE_PREFIX."moderators m
install/resources/upgrade3.php (3 hits)
	Line 721: 	$db->write_query("ALTER TABLE ".TABLE_PREFIX."moderators CHANGE mid mid smallint unsigned NOT NULL auto_increment;");
	Line 722: 	$db->write_query("ALTER TABLE ".TABLE_PREFIX."moderators CHANGE fid fid smallint unsigned NOT NULL;");
	Line 723: 	$db->write_query("ALTER TABLE ".TABLE_PREFIX."moderators CHANGE uid uid int unsigned NOT NULL;");
install/resources/upgrade5.php (2 hits)
	Line 170: 		$db->write_query("ALTER TABLE ".TABLE_PREFIX."moderators DROP canmovetononmodforum;");
	Line 172: 	$db->write_query("ALTER TABLE ".TABLE_PREFIX."moderators ADD canmovetononmodforum char(3) NOT NULL default '' AFTER canmanagethreads;");
report.php (1 hits)
	Line 83: 			FROM ".TABLE_PREFIX."moderators m
showteam.php (1 hits)
	Line 48: 		FROM ".TABLE_PREFIX."moderators m


Search "select("moderators"" (11 hits in 4 files)
admin/modules/forum/management.php (6 hits)
	Line 267: 	$query = $db->simple_select("moderators", "*", "mid='".intval($mybb->input['mid'])."'");
	Line 1805: 	$query = $db->simple_select("moderators", "*", "id='{$modid}' AND isgroup = '{$isgroup}' AND fid='{$fid}'");
	Line 1845: 		$query = $db->simple_select("moderators", "*", "id='{$mod['id']}' AND isgroup='0'");
	Line 1935: 		$query = $db->simple_select("moderators", "*", "fid='$fid' AND isgroup='0'");
	Line 1944: 			$query = $db->simple_select("moderators", "*", "fid != '$fid' AND id IN ($mod_list) AND isgroup='0'");
	Line 2110: 				$query = $db->simple_select("moderators", "id", "id='".$newmod['id']."' AND fid='".$fid."' AND isgroup='{$isgroup}'", array('limit' => 1));
inc/functions.php (2 hits)
	Line 1403: 		$query = $db->simple_select("moderators", "*", "((id IN ({$groups}) AND isgroup='1') OR (id='{$uid}' AND isgroup='0')) AND fid='$fid'");
	Line 1415: 		$query = $db->simple_select("moderators", "*", "((id IN ({$groups}) AND isgroup='1') OR (id='{$uid}' AND isgroup='0')) AND {$sql}");
modcp.php (1 hits)
	Line 49: 	$query = $db->simple_select("moderators", "*", "id='{$mybb->user['uid']}' AND isgroup = '0'");
search.php (2 hits)
	Line 235: 		$query = $db->simple_select("moderators", "fid", "(id='{$mybb->user['uid']}' AND isgroup='0') OR (id='{$mybb->user['usergroup']}' AND isgroup='1')");
	Line 638: 		$query = $db->simple_select("moderators", "fid", "(id='{$mybb->user['uid']}' AND isgroup='0') OR (id='{$mybb->user['usergroup']}' AND isgroup='1')");


Search "query("moderators"" (8 hits in 3 files)
admin/modules/forum/management.php (4 hits)
	Line 317: 			$db->update_query("moderators", $update_array, "mid='".intval($mybb->input['mid'])."'");
	Line 1844: 		$db->delete_query("moderators", "mid='{$mid}'");
	Line 1975: 		$db->delete_query("moderators", "fid='{$fid}' {$delquery}");
	Line 2125: 					$mid = $db->insert_query("moderators", $new_mod);
admin/modules/user/users.php (3 hits)
	Line 1625: 			$db->delete_query("moderators", "id='{$user['uid']}' AND isgroup = '0'");
	Line 1830: 				$db->delete_query("moderators", "id='{$source_user['uid']}' AND isgroup = '0'");
	Line 2438: 								$db->delete_query("moderators", "id='{$user['uid']}' AND isgroup = '0'");
inc/tasks/userpruning.php (1 hits)
	Line 72: 		$db->delete_query("moderators", "id IN({$uid_list}) AND isgroup='0'");


Search "TABLE_PREFIX.'moderators" (0 hits in 0 files)
Search "select('moderators'" (0 hits in 0 files)
Search "query('moderators'" (0 hits in 0 files)


You probably don't need to bother with the admin/* or install/* files.
Otherwise, I'd double check all the files/places above to see if they're consistent.

I think you've got all the main ones.  I haven't checked all of the above, but it looks like report.php may need a slight change (though it's probably not that important).
Hopefully that covers all the cases - after which, I'd just do some testing then use it.
Hope that helps.


My Blog
(This post was last modified: 07-04-2011 11:25 AM by ZiNgA BuRgA.)
07-04-2011 11:23 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: