Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -58,9 +58,12 @@ |
59 | 59 | $wgAutoloadClasses['SpecialSurveys'] = dirname( __FILE__ ) . '/specials/SpecialSurveys.php'; |
60 | 60 | $wgAutoloadClasses['SpecialSurveyStats'] = dirname( __FILE__ ) . '/specials/SpecialSurveyStats.php'; |
61 | 61 | |
62 | | -$wgSpecialPages['SpecialSurveys'] = 'SpecialSurveys'; |
63 | | -$wgSpecialPages['SpecialSurveyStats'] = 'SpecialSurveyStats'; |
| 62 | +$wgSpecialPages['Surveys'] = 'SpecialSurveys'; |
| 63 | +$wgSpecialPages['SurveyStats'] = 'SpecialSurveyStats'; |
64 | 64 | |
| 65 | +$wgSpecialPageGroups['Surveys'] = 'other'; |
| 66 | +$wgSpecialPageGroups['SurveyStats'] = 'other'; |
| 67 | + |
65 | 68 | $wgAPIModules['addsurvey'] = 'ApiAddSurvey'; |
66 | 69 | $wgAPIModules['deletesurvey'] = 'ApiDeleteSurvey'; |
67 | 70 | $wgAPIModules['editsurvey'] = 'ApiEditSurvey'; |
— | — | @@ -72,6 +75,20 @@ |
73 | 76 | $wgAvailableRights[] = 'surveyadmin'; |
74 | 77 | $wgAvailableRights[] = 'surveysubmit'; |
75 | 78 | |
| 79 | +# Users that can manage the surveys. |
| 80 | +$wgGroupPermissions['*' ]['surveyadmin'] = false; |
| 81 | +$wgGroupPermissions['user' ]['surveyadmin'] = false; |
| 82 | +$wgGroupPermissions['autoconfirmed']['surveyadmin'] = false; |
| 83 | +$wgGroupPermissions['bot' ]['surveyadmin'] = false; |
| 84 | +$wgGroupPermissions['sysop' ]['surveyadmin'] = true; |
| 85 | + |
| 86 | +# Users that can submit surveys. |
| 87 | +$wgGroupPermissions['*' ]['surveysubmit'] = true; |
| 88 | +$wgGroupPermissions['user' ]['surveysubmit'] = true; |
| 89 | +$wgGroupPermissions['autoconfirmed']['surveysubmit'] = true; |
| 90 | +$wgGroupPermissions['bot' ]['surveysubmit'] = false; |
| 91 | +$wgGroupPermissions['sysop' ]['surveysubmit'] = true; |
| 92 | + |
76 | 93 | $egSurveyScriptPath = $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath; |
77 | 94 | $egSurveyScriptPath .= '/Survey/resources'; |
78 | 95 | |
Index: trunk/extensions/Survey/api/ApiDeleteSurvey.php |
— | — | @@ -27,32 +27,105 @@ |
28 | 28 | |
29 | 29 | $params = $this->extractRequestParams(); |
30 | 30 | |
| 31 | + $everythingOk = true; |
| 32 | + |
| 33 | + foreach ( $params['ids'] as $id ) { |
| 34 | + $everythingOk = $this->deleteSurvey( $id ) && $everythingOk; |
| 35 | + } |
| 36 | + |
| 37 | + $this->getResult()->addValue( |
| 38 | + null, |
| 39 | + 'success', |
| 40 | + $everythingOk |
| 41 | + ); |
31 | 42 | } |
| 43 | + |
| 44 | + /** |
| 45 | + * Delete the survey with provided id. |
| 46 | + * |
| 47 | + * @since 0.1 |
| 48 | + * |
| 49 | + * @param integer $id |
| 50 | + * |
| 51 | + * @return boolean Success indicator |
| 52 | + */ |
| 53 | + protected function deleteSurvey( $id ) { |
| 54 | + $dbr = wfgetDB( DB_SLAVE ); |
| 55 | + |
| 56 | + $submissionsForSurvey = $dbr->select( |
| 57 | + 'survey_submissions', |
| 58 | + array( 'submission_id' ), |
| 59 | + array( 'submission_survey_id' => $id ) |
| 60 | + ); |
| 61 | + |
| 62 | + $dbw = wfgetDB( DB_MASTER ); |
| 63 | + |
| 64 | + $dbw->begin(); |
| 65 | + |
| 66 | + $everythingOk = $dbw->delete( |
| 67 | + 'surveys', |
| 68 | + array( 'survey_id' => $id ) |
| 69 | + ); |
| 70 | + |
| 71 | + $everythingOk = $dbw->delete( |
| 72 | + 'survey_questions', |
| 73 | + array( 'question_survey_id' => $id ) |
| 74 | + ) && $everythingOk; |
| 75 | + |
| 76 | + $everythingOk = $dbw->delete( |
| 77 | + 'survey_submissions', |
| 78 | + array( 'submission_survey_id' => $id ) |
| 79 | + ) && $everythingOk; |
| 80 | + |
| 81 | + foreach ( $submissionsForSurvey as $nr => $submission ) { |
| 82 | + $everythingOk = $dbw->delete( |
| 83 | + 'survey_answers', |
| 84 | + array( 'answer_submission_id' => $submission->submission_id ) |
| 85 | + ) && $everythingOk; |
| 86 | + |
| 87 | + if ( $nr % 500 == 0 ) { |
| 88 | + $dbw->commit(); |
| 89 | + $dbw->begin(); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + $dbw->commit(); |
| 94 | + |
| 95 | + return $everythingOk; |
| 96 | + } |
32 | 97 | |
33 | 98 | public function getAllowedParams() { |
34 | 99 | return array( |
| 100 | + 'ids' => array( |
| 101 | + ApiBase::PARAM_TYPE => 'integer', |
| 102 | + ApiBase::PARAM_REQUIRED => true, |
| 103 | + ApiBase::PARAM_ISMULTI => true, |
| 104 | + ), |
35 | 105 | ); |
36 | 106 | } |
37 | 107 | |
38 | 108 | public function getParamDescription() { |
39 | 109 | return array( |
| 110 | + 'ids' => 'The IDs of the surveys to delete' |
40 | 111 | ); |
41 | 112 | } |
42 | 113 | |
43 | 114 | public function getDescription() { |
44 | 115 | return array( |
45 | | - '' |
| 116 | + 'API module for deleting surveys.' |
46 | 117 | ); |
47 | 118 | } |
48 | 119 | |
49 | 120 | public function getPossibleErrors() { |
50 | 121 | return array_merge( parent::getPossibleErrors(), array( |
| 122 | + array( 'missingparam', 'ids' ), |
51 | 123 | ) ); |
52 | 124 | } |
53 | 125 | |
54 | 126 | protected function getExamples() { |
55 | 127 | return array( |
56 | | - 'api.php?action=deletesurvey&', |
| 128 | + 'api.php?action=deletesurvey&ids=42', |
| 129 | + 'api.php?action=deletesurvey&ids=4|2', |
57 | 130 | ); |
58 | 131 | } |
59 | 132 | |