Forráskód Böngészése

! Redo move topic stuff per comments on #921.

Signed-off-by: Michael Eshom <[email protected]>
Michael Eshom 10 éve
szülő
commit
c3f7ea3dca

+ 5 - 14
Sources/Display.php

@@ -1089,23 +1089,14 @@ function Display()
 	foreach ($anyown_permissions as $contextual => $perm)
 		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
 
-	if (!$user_info['is_admin'])
+	if (!$user_info['is_admin'] && !$modSettings['topic_move_any'])
 	{
 		// We'll use this in a minute
-		$boards_allowed = boardsAllowedTo(array('move_any', 'move_own'));
+		$boards_allowed = array_diff(boardsAllowedTo('post_new'), array($board));
 
-		// Boards other than this one where you can move_any or move_own 
-		$other_boards_move_any = array_diff($boards_allowed['move_any'], array($board));
-		$other_boards_move_own = array_diff($boards_allowed['move_own'], array($board));
-
-		// How many boards can you do this on besides this one?
-		$context['can_move_any'] = !empty($other_boards_move_any);
-		$context['can_move_own'] = !empty($other_boards_move_own);
-
-		/* You can't move this unless:
-			You have move_any on at least one other board OR
-			You started the topic and have move_own on at least one other board*/
-		$context['move'] &= $context['can_move_any'] || ($context['topic_starter_id'] == $user_info['id'] && $context['can_move_own']);
+		/* You can't move this unless you have permission
+			to start new topics on at least one other board */
+		$context['move'] &= count($boards_allowed) > 1;
 	}
 
 	// Cleanup all the permissions with extra stuff...

+ 1 - 0
Sources/ManageSettings.php

@@ -151,6 +151,7 @@ function ModifyBasicSettings($return_config = false)
 			array('check', 'allow_hideOnline'),
 			array('check', 'titlesEnable'),
 			array('text', 'default_personal_text', 'subtext' => $txt['default_personal_text_note'], 'disabled' => !$can_personal_text),
+			array('check', 'topic_move_any'),
 		'',
 			// Jquery source
 			array('select', 'jquery_source', array('auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn'], 'custom' => $txt['jquery_custom']), 'onchange' => 'if (this.value == \'custom\'){document.getElementById(\'jquery_custom\').disabled = false; } else {document.getElementById(\'jquery_custom\').disabled = true;}'),

+ 30 - 27
Sources/MessageIndex.php

@@ -629,20 +629,15 @@ function MessageIndex()
 		// Can we restore topics?
 		$context['can_restore'] = allowedTo('move_any') && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board;
 
-		if ($user_info['is_admin'])
-			$context['can_move_any'] = $context['can_move_own'] = true;
+		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
+			$context['can_move_any'] = true;
 		else
 		{
 			// We'll use this in a minute
-			$boards_allowed = boardsAllowedTo(array('move_any', 'move_own'));
-			
-			// Boards other than this one where you can move_any or move_own 
-			$other_boards_move_any = array_diff($boards_allowed['move_any'], array($board));
-			$other_boards_move_own = array_diff($boards_allowed['move_own'], array($board));
+			$boards_allowed = boardsAllowedTo('post_new');
 			
 			// How many boards can you do this on besides this one?
-			$context['can_move_any'] = !empty($other_boards_move_any);
-			$context['can_move_own'] = !empty($other_boards_move_own);
+			$context['can_move_any'] = count($boards_allowed) > 1;
 		}
 
 		// Set permissions for all the topics.
@@ -652,13 +647,13 @@ function MessageIndex()
 			$context['topics'][$t]['quick_mod'] = array(
 				'lock' => allowedTo('lock_any') || ($started && allowedTo('lock_own')),
 				'sticky' => allowedTo('make_sticky'),
-				'move' => (allowedTo('move_any') && $context['can_move_any']) || ($started && allowedTo('move_own') && ($context['can_move_own'] || $context['can_move_any'])),
+				'move' => (allowedTo('move_any') || ($started && allowedTo('move_own')) && $context['can_move_any']),
 				'modify' => allowedTo('modify_any') || ($started && allowedTo('modify_own')),
 				'remove' => allowedTo('remove_any') || ($started && allowedTo('remove_own')),
 				'approve' => $context['can_approve'] && $topic['unapproved_posts']
 			);
 			$context['can_lock'] |= ($started && allowedTo('lock_own'));
-			$context['can_move'] |= ($started && allowedTo('move_own') && ($context['can_move_own'] || $context['can_move_any']));
+			$context['can_move'] |= ($started && allowedTo('move_own') && $context['can_move_any']);
 			$context['can_remove'] |= ($started && allowedTo('remove_own'));
 		}
 
@@ -724,6 +719,8 @@ function QuickModeration()
 	{
 		$boards_can = array(
 			'make_sticky' => allowedTo('make_sticky') ? array($board) : array(),
+			'move_any' => allowedTo('move_any') ? array($board) : array(),
+			'move_own' => allowedTo('move_own') ? array($board) : array(),
 			'remove_any' => allowedTo('remove_any') ? array($board) : array(),
 			'remove_own' => allowedTo('remove_own') ? array($board) : array(),
 			'lock_any' => allowedTo('lock_any') ? array($board) : array(),
@@ -732,10 +729,8 @@ function QuickModeration()
 			'approve_posts' => allowedTo('approve_posts') ? array($board) : array(),
 		);
 
-		$boards_can['move_any'] = boardsAllowedTo('move_any');
-		$boards_can['move_own'] = boardsAllowedTo('move_own');
-
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
+		
 	}
 	else
 	{
@@ -748,14 +743,30 @@ function QuickModeration()
 		$redirect_url = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : (isset($_SESSION['old_url']) ? $_SESSION['old_url'] : '');
 	}
 
-	// Moving requires being able to move topics on at least two boards...
-	$num_boards_move = count(array_unique(array_merge($boards_can['move_any'], $boards_can['move_own'])));
+	// Are we enforcing the "no moving topics to boards where you can't post new ones" rule?
+	if (!$user_info['is_amdin'] && !$modSettings['topic_move_any'])
+	{
+		// Don't count this board, if it's specified
+		if (!empty($board))
+		{
+			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
+		}
+		else
+		{
+			$boards_can['post_new'] = boardsAllowedTo('post_new');
+		}
+		
+		if (empty($boards_can['post_new']))
+		{
+			$boards_can['move_any'] = $boards_can['move_own'] = array();
+		}
+	}
 
 	if (!$user_info['is_guest'])
 		$possibleActions[] = 'markread';
 	if (!empty($boards_can['make_sticky']))
 		$possibleActions[] = 'sticky';
-	if ($num_boards_move > 1)
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
 		$possibleActions[] = 'move';
 	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
 		$possibleActions[] = 'remove';
@@ -816,19 +827,11 @@ function QuickModeration()
 			)
 		);
 		while ($row = $smcFunc['db_fetch_assoc']($request))
-		{
-			$where = (int) (isset($_REQUEST['move_tos'][$row['id_topic']]) ? $_REQUEST['move_tos'][$row['id_topic']] : $_REQUEST['move_to']);
-			$can_move_there = ($row['id_member_started'] == $user_info['id'] && in_array($where, $boards_can['move_own'])) || in_array($where, $boards_can['move_any']);
-			
+		{		
 			if (!empty($board))
 			{
 				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
 					unset($_REQUEST['actions'][$row['id_topic']]);
-				elseif($_REQUEST['actions'][$row['id_topic']] == 'move')
-				{					
-					if (!$can_move_there)
-						unset($_REQUEST['actions'][$row['id_topic']]);
-				}
 			}
 			else
 			{
@@ -838,7 +841,7 @@ function QuickModeration()
 				// Goodness, this is fun.  We need to validate the action.
 				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
 					unset($_REQUEST['actions'][$row['id_topic']]);
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))) && !$can_move_there)
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))))
 					unset($_REQUEST['actions'][$row['id_topic']]);
 				elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))))
 					unset($_REQUEST['actions'][$row['id_topic']]);

+ 15 - 5
Sources/MoveTopic.php

@@ -59,13 +59,23 @@ function MoveTopic()
 		if ($id_member_started == $user_info['id'])
 		{
 			isAllowedTo('move_own');
-			$boards = array_unique(array_merge(boardsAllowedTo('move_own'), boardsAllowedTo('move_any')));
 		}
 		else
 			isAllowedTo('move_any');
 	}
-	else
-		$boards = boardsAllowedTo('move_any');
+	
+	$context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any'];
+	$boards = array();
+	
+	if (!$context['move_any'])
+	{
+		$boards = array_diff(boardsAllowedTo('post_new'), array($board));
+		if (empty($boards))
+		{
+			// No boards? Too bad...
+			fatal_lang_error('moveto_no_boards');
+		}
+	}
 
 	loadTemplate('MoveTopic');
 
@@ -75,8 +85,8 @@ function MoveTopic()
 		FROM {db_prefix}boards AS b
 			LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
 		WHERE {query_see_board}
-			AND b.redirect = {string:blank_redirect}
-			AND b.id_board IN ({array_int:boards})',
+			AND b.redirect = {string:blank_redirect}' . ($context['move_any'] ? '' : '
+			AND b.id_board IN ({array_int:boards})'),
 		array(
 			'blank_redirect' => '',
 			'current_board' => $board,

+ 1 - 0
Themes/default/languages/Help.english.php

@@ -638,4 +638,5 @@ $helptxt['custom_mask'] = 'The input mask is important for your forum\'s securit
 	</div><br /><br />
 	More information and advanced techniques may be found on the internet.';
 
+$helptxt['topic_move_any'] = 'If checked, users will be allowed to move topics to any board they can see. Otherwise, they will only be able to move them to boards where they can post new topics.';
 ?>

+ 2 - 0
Themes/default/languages/ManageSettings.english.php

@@ -356,4 +356,6 @@ $txt['setting_frame_security_DISABLE'] = 'Disabled';
 
 $txt['select_boards_from_list'] = 'Select boards which apply';
 
+$txt['topic_move_any'] = 'Allow moving of topics to read-only boards';
+
 ?>

+ 2 - 1
other/install_2-1_mysql.sql

@@ -1900,7 +1900,8 @@ VALUES ('smfVersion', '{$smf_version}'),
 	('drafts_pm_enabled', '1'),
 	('drafts_autosave_enabled', '1'),
 	('drafts_show_saved_enabled', '1'),
-	('drafts_keep_days', '7');
+	('drafts_keep_days', '7'),
+	('topic_move_any', '0');
 # --------------------------------------------------------
 
 #

+ 1 - 0
other/install_2-1_postgresql.sql

@@ -2410,6 +2410,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_pm_enabled',
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '0');
 # --------------------------------------------------------
 
 #

+ 1 - 0
other/install_2-1_sqlite.sql

@@ -2051,6 +2051,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_pm_enabled',
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '0');
 COMMIT;
 
 # --------------------------------------------------------

+ 1 - 0
other/install_2-1_sqlite3.sql

@@ -2051,6 +2051,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_pm_enabled',
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '0');
 COMMIT;
 
 # --------------------------------------------------------

+ 4 - 0
other/upgrade_2-1_mysql.sql

@@ -57,6 +57,10 @@ if (!isset($modSettings['allow_no_censored']))
 ---}
 ---#
 
+---# Adding new "topic_move_any" setting
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
+---#
+
 /******************************************************************************/
 --- Updating legacy attachments...
 /******************************************************************************/

+ 4 - 0
other/upgrade_2-1_postgresql.sql

@@ -59,6 +59,10 @@ if (!isset($modSettings['allow_no_censored']))
 ---}
 ---#
 
+---# Adding new "topic_move_any" setting
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
+---#
+
 /******************************************************************************/
 --- Updating legacy attachments...
 /******************************************************************************/

+ 4 - 0
other/upgrade_2-1_sqlite.sql

@@ -57,6 +57,10 @@ if (!isset($modSettings['allow_no_censored']))
 ---}
 ---#
 
+---# Adding new "topic_move_any" setting
+INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
+---#
+
 /******************************************************************************/
 --- Updating legacy attachments...
 /******************************************************************************/