Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php |
— | — | @@ -8,26 +8,26 @@ |
9 | 9 | * @file |
10 | 10 | * @ingroup SpecialPage |
11 | 11 | * @ingroup Upload |
12 | | - * |
| 12 | + * |
13 | 13 | * @since 1.2 |
14 | | - * |
| 14 | + * |
15 | 15 | * @licence GNU GPL v2+ |
16 | 16 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
17 | 17 | */ |
18 | 18 | class SpecialUploadCampaign extends FormSpecialPage { |
19 | | - |
| 19 | + |
20 | 20 | protected $subPage; |
21 | | - |
| 21 | + |
22 | 22 | /** |
23 | 23 | * Constructor. |
24 | | - * |
| 24 | + * |
25 | 25 | * @param $request is the request (usually wgRequest) |
26 | 26 | * @param $par is everything in the URL after Special:UploadCampaign. Not sure what we can use it for |
27 | 27 | */ |
28 | 28 | public function __construct( $request = null, $par = null ) { |
29 | 29 | parent::__construct ( 'UploadCampaign', 'upwizcampaigns', false ); |
30 | 30 | } |
31 | | - |
| 31 | + |
32 | 32 | /** |
33 | 33 | * Get the OutputPage being used for this instance. |
34 | 34 | * This overrides the getOutput method of Specialpage added in MediaWiki 1.18, |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | public function getOutput() { |
42 | 42 | return version_compare( $GLOBALS['wgVersion'], '1.18', '>=' ) ? parent::getOutput() : $GLOBALS['wgOut']; |
43 | 43 | } |
44 | | - |
| 44 | + |
45 | 45 | /** |
46 | 46 | * (non-PHPdoc) |
47 | 47 | * @see SpecialPage::getDescription() |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | public function getDescription() { |
50 | 50 | return wfMsg( 'mwe-upwiz-' . strtolower( $this->getName() ) ); |
51 | 51 | } |
52 | | - |
| 52 | + |
53 | 53 | /** |
54 | 54 | * (non-PHPdoc) |
55 | 55 | * @see FormSpecialPage::setParameter() |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | protected function setParameter( $par ){ |
58 | 58 | $this->subPage = $par; |
59 | 59 | } |
60 | | - |
| 60 | + |
61 | 61 | /** |
62 | 62 | * (non-PHPdoc) |
63 | 63 | * @see FormSpecialPage::getForm() |
— | — | @@ -71,32 +71,30 @@ |
72 | 72 | 'onclick' => 'window.location="' . SpecialPage::getTitleFor( 'UploadCampaigns' )->getFullURL() . '";return false;' |
73 | 73 | ) |
74 | 74 | ); |
75 | | - |
| 75 | + |
76 | 76 | return $form; |
77 | 77 | } |
78 | | - |
| 78 | + |
79 | 79 | /** |
80 | 80 | * (non-PHPdoc) |
81 | 81 | * @see FormSpecialPage::getFormFields() |
82 | 82 | */ |
83 | 83 | protected function getFormFields() { |
84 | | - $dbr = wfGetDB( DB_SLAVE ); |
85 | | - |
86 | 84 | $campaign = UploadWizardCampaign::newFromName( $this->subPage ); |
87 | | - |
| 85 | + |
88 | 86 | $id = $campaign ? $campaign->getId() : null; |
89 | | - $enabled = $campaign ? $campaign->getIsEnabled() : false; |
| 87 | + $enabled = $campaign ? $campaign->getIsEnabled() : false; |
90 | 88 | $configFields = $campaign ? $campaign->getAllConfig() : UploadWizardCampaign::getDefaultConfig(); |
91 | | - |
| 89 | + |
92 | 90 | $fields = array(); |
93 | | - |
| 91 | + |
94 | 92 | $fields['Campaignid'] = array ( 'type' => 'hidden', 'default' => $id ); |
95 | 93 | $fields['Campaignname'] = array ( 'type' => 'text', 'default' => $this->subPage, 'label-message' => 'mwe-upwiz-campaign-name' ); |
96 | 94 | $fields['Campaignenabled'] = array ( 'type' => 'check', 'default' => $enabled, 'label-message' => 'mwe-upwiz-campaign-enabled' ); |
97 | | - |
| 95 | + |
98 | 96 | foreach ( $configFields as $name => $data ) { |
99 | 97 | $data['label-message'] = 'mwe-upwiz-campaign-conf-' . $name; |
100 | | - |
| 98 | + |
101 | 99 | // Special handling for lists of values per input type. |
102 | 100 | if ( is_array( $data['default'] ) ) { |
103 | 101 | switch ( $data['type'] ) { |
— | — | @@ -105,13 +103,13 @@ |
106 | 104 | break; |
107 | 105 | } |
108 | 106 | } |
109 | | - |
| 107 | + |
110 | 108 | $fields[$name] = $data; |
111 | 109 | } |
112 | | - |
| 110 | + |
113 | 111 | return $fields; |
114 | 112 | } |
115 | | - |
| 113 | + |
116 | 114 | /** |
117 | 115 | * Process the form. At this point we know that the user passes all the criteria in |
118 | 116 | * userCanExecute(), and if the data array contains 'Username', etc, then Username |
— | — | @@ -121,26 +119,26 @@ |
122 | 120 | */ |
123 | 121 | public function onSubmit( array $data ) { |
124 | 122 | global $wgRequest; |
125 | | - |
| 123 | + |
126 | 124 | $id = $data['Campaignid'] == '' ? null : $data['Campaignid']; |
127 | 125 | unset( $data['Campaignid'] ); |
128 | | - |
| 126 | + |
129 | 127 | $name = $data['Campaignname']; |
130 | 128 | unset( $data['Campaignname'] ); |
131 | | - |
| 129 | + |
132 | 130 | $enabled = $data['Campaignenabled']; |
133 | 131 | unset( $data['Campaignenabled'] ); |
134 | | - |
| 132 | + |
135 | 133 | if ( is_null( $id ) && !is_null( $wgRequest->getSessionData( 'uploadcampaignid-' . $name ) ) ) { |
136 | 134 | $id = $wgRequest->getSessionData( 'uploadcampaignid-' . $name ); |
137 | 135 | } |
138 | | - |
| 136 | + |
139 | 137 | $campaign = new UploadWizardCampaign( $id, $name, $enabled, $data ); |
140 | | - |
| 138 | + |
141 | 139 | $success = $campaign->writeToDB(); |
142 | | - |
| 140 | + |
143 | 141 | $wgRequest->setSessionData( 'uploadcampaignid-' . $name, $campaign->getId() ); |
144 | | - |
| 142 | + |
145 | 143 | if ( $success ) { |
146 | 144 | return true; |
147 | 145 | } |
— | — | @@ -148,7 +146,7 @@ |
149 | 147 | return array(); // TODO |
150 | 148 | } |
151 | 149 | } |
152 | | - |
| 150 | + |
153 | 151 | public function onSuccess() { |
154 | 152 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() ); |
155 | 153 | } |
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php |
— | — | @@ -8,9 +8,9 @@ |
9 | 9 | * @file |
10 | 10 | * @ingroup SpecialPage |
11 | 11 | * @ingroup Upload |
12 | | - * |
| 12 | + * |
13 | 13 | * @since 1.2 |
14 | | - * |
| 14 | + * |
15 | 15 | * @licence GNU GPL v3+ |
16 | 16 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
17 | 17 | */ |
— | — | @@ -18,14 +18,14 @@ |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Constructor. |
22 | | - * |
| 22 | + * |
23 | 23 | * @param $request is the request (usually wgRequest) |
24 | 24 | * @param $par is everything in the URL after Special:UploadCampaigns. Not sure what we can use it for |
25 | 25 | */ |
26 | 26 | public function __construct( $request = null, $par = null ) { |
27 | 27 | parent::__construct( 'UploadCampaigns', 'upwizcampaigns' ); |
28 | 28 | } |
29 | | - |
| 29 | + |
30 | 30 | /** |
31 | 31 | * Get the OutputPage being used for this instance. |
32 | 32 | * This overrides the getOutput method of Specialpage added in MediaWiki 1.18, |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | public function getOutput() { |
40 | 40 | return version_compare( $GLOBALS['wgVersion'], '1.18', '>=' ) ? parent::getOutput() : $GLOBALS['wgOut']; |
41 | 41 | } |
42 | | - |
| 42 | + |
43 | 43 | /** |
44 | 44 | * (non-PHPdoc) |
45 | 45 | * @see SpecialPage::getDescription() |
— | — | @@ -49,16 +49,16 @@ |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Main method. |
53 | | - * |
| 53 | + * |
54 | 54 | * @param string $subPage, e.g. the "foo" in Special:UploadCampaigns/foo. |
55 | 55 | */ |
56 | 56 | public function execute( $subPage ) { |
57 | 57 | global $wgRequest, $wgUser; |
58 | | - |
| 58 | + |
59 | 59 | $this->setHeaders(); |
60 | 60 | $this->outputHeader(); |
61 | 61 | $subPage = explode( '/', $subPage, 2 ); |
62 | | - |
| 62 | + |
63 | 63 | // If the user is authorized, display the page, if not, show an error. |
64 | 64 | if ( $this->userCanExecute( $wgUser ) ) { |
65 | 65 | if ( $wgRequest->wasPosted() |
— | — | @@ -78,39 +78,41 @@ |
79 | 79 | $this->displayRestrictionError(); |
80 | 80 | } |
81 | 81 | } |
82 | | - |
| 82 | + |
83 | 83 | /** |
84 | 84 | * Displays the pages regular output. |
85 | | - * |
| 85 | + * |
86 | 86 | * @since 1.2 |
87 | 87 | */ |
88 | 88 | protected function displayUploadCamaigns() { |
89 | 89 | $this->displayAddNewControl(); |
90 | | - |
| 90 | + |
91 | 91 | $dbr = wfGetDB( DB_SLAVE ); |
92 | | - |
| 92 | + |
93 | 93 | $campaigns = $dbr->select( |
94 | 94 | 'uw_campaigns', |
95 | 95 | array( |
96 | 96 | 'campaign_id', |
97 | 97 | 'campaign_name', |
98 | 98 | 'campaign_enabled', |
99 | | - ) |
| 99 | + ), |
| 100 | + '', |
| 101 | + __METHOD__ |
100 | 102 | ); |
101 | | - |
| 103 | + |
102 | 104 | if ( $campaigns->numRows() > 0 ) { |
103 | 105 | $this->displayCampaignTable( $campaigns ); |
104 | 106 | } |
105 | 107 | } |
106 | | - |
| 108 | + |
107 | 109 | /** |
108 | 110 | * Displays a small form to add a new campaign. |
109 | | - * |
| 111 | + * |
110 | 112 | * @since 1.2 |
111 | 113 | */ |
112 | 114 | protected function displayAddNewControl() { |
113 | 115 | $out = $this->getOutput(); |
114 | | - |
| 116 | + |
115 | 117 | $out->addHTML( Html::openElement( |
116 | 118 | 'form', |
117 | 119 | array( |
— | — | @@ -118,47 +120,47 @@ |
119 | 121 | 'action' => $this->getTitle()->getLocalURL(), |
120 | 122 | ) |
121 | 123 | ) ); |
122 | | - |
| 124 | + |
123 | 125 | $out->addHTML( '<fieldset>' ); |
124 | | - |
| 126 | + |
125 | 127 | $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'mwe-upwiz-campaigns-addnew' ) ) . '</legend>' ); |
126 | | - |
| 128 | + |
127 | 129 | $out->addHTML( Html::element( 'p', array(), wfMsg( 'mwe-upwiz-campaigns-namedoc' ) ) ); |
128 | | - |
| 130 | + |
129 | 131 | $out->addHTML( Html::element( 'label', array( 'for' => 'newcampaign' ), wfMsg( 'mwe-upwiz-campaigns-newname' ) ) ); |
130 | | - |
| 132 | + |
131 | 133 | $out->addHTML( ' ' . Html::input( 'newcampaign' ) . ' ' ); |
132 | | - |
| 134 | + |
133 | 135 | $out->addHTML( Html::input( |
134 | 136 | 'addnewcampaign', |
135 | 137 | wfMsg( 'mwe-upwiz-campaigns-add' ), |
136 | 138 | 'submit' |
137 | 139 | ) ); |
138 | | - |
| 140 | + |
139 | 141 | global $wgUser; |
140 | 142 | $out->addHTML( Html::hidden( 'wpEditToken', $wgUser->editToken() ) ); |
141 | | - |
| 143 | + |
142 | 144 | $out->addHTML( '</fieldset></form>' ); |
143 | 145 | } |
144 | | - |
| 146 | + |
145 | 147 | /** |
146 | 148 | * Displays a list of all campaigns. |
147 | | - * |
| 149 | + * |
148 | 150 | * @since 1.2 |
149 | | - * |
| 151 | + * |
150 | 152 | * @param ResultWrapper $campaigns |
151 | 153 | */ |
152 | 154 | protected function displayCampaignTable( ResultWrapper $campaigns ) { |
153 | 155 | $out = $this->getOutput(); |
154 | | - |
| 156 | + |
155 | 157 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'mwe-upwiz-campaigns-existing' ) ) ); |
156 | | - |
| 158 | + |
157 | 159 | $out->addHTML( Xml::openElement( |
158 | 160 | 'table', |
159 | 161 | array( 'class' => 'wikitable', 'style' => 'width:400px' ) |
160 | 162 | ) ); |
161 | | - |
162 | | - $out->addHTML( |
| 163 | + |
| 164 | + $out->addHTML( |
163 | 165 | '<tr>' . |
164 | 166 | Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-name' ) ) . |
165 | 167 | Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-status' ) ) . |
— | — | @@ -166,12 +168,12 @@ |
167 | 169 | Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-delete' ) ) . |
168 | 170 | '</tr>' |
169 | 171 | ); |
170 | | - |
| 172 | + |
171 | 173 | foreach ( $campaigns as $campaign ) { |
172 | 174 | $out->addHTML( |
173 | 175 | '<tr>' . |
174 | 176 | '<td>' . |
175 | | - Html::element( |
| 177 | + Html::element( |
176 | 178 | 'a', |
177 | 179 | array( |
178 | 180 | 'href' => SpecialPage::getTitleFor( 'UploadWizard' )->getLocalURL( array( 'campaign' => $campaign->campaign_name ) ) |
— | — | @@ -181,7 +183,7 @@ |
182 | 184 | '</td>' . |
183 | 185 | Html::element( 'td', array(), wfMsg( 'mwe-upwiz-campaigns-' . ( $campaign->campaign_enabled ? 'enabled' : 'disabled' ) ) ) . |
184 | 186 | '<td>' . |
185 | | - Html::element( |
| 187 | + Html::element( |
186 | 188 | 'a', |
187 | 189 | array( |
188 | 190 | 'href' => SpecialPage::getTitleFor( 'UploadCampaign', $campaign->campaign_name )->getLocalURL() |
— | — | @@ -190,7 +192,7 @@ |
191 | 193 | ) . |
192 | 194 | '</td>' . |
193 | 195 | '<td>' . |
194 | | - Html::element( |
| 196 | + Html::element( |
195 | 197 | 'a', |
196 | 198 | array( |
197 | 199 | 'href' => SpecialPage::getTitleFor( 'UploadCampaigns', 'del/' . $campaign->campaign_name )->getLocalURL(), |
— | — | @@ -202,8 +204,8 @@ |
203 | 205 | '</tr>' |
204 | 206 | ); |
205 | 207 | } |
206 | | - |
| 208 | + |
207 | 209 | $out->addHTML( '</table>' ); |
208 | | - } |
| 210 | + } |
209 | 211 | |
210 | 212 | } |
Index: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php |
— | — | @@ -5,61 +5,61 @@ |
6 | 6 | * |
7 | 7 | * @file |
8 | 8 | * @ingroup Upload |
9 | | - * |
| 9 | + * |
10 | 10 | * @since 1.2 |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v2+ |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class UploadWizardCampaign { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * If the ID of the campaign. |
19 | 19 | * Either this matched a record in the uw_campaigns table or is null. |
20 | | - * |
| 20 | + * |
21 | 21 | * @since 1.2 |
22 | 22 | * @var integer or null |
23 | 23 | */ |
24 | 24 | protected $id; |
25 | | - |
| 25 | + |
26 | 26 | /** |
27 | 27 | * If the name of the campaign. |
28 | 28 | * This name is the string used to invoke the campaign via campaign=name. |
29 | | - * |
| 29 | + * |
30 | 30 | * @since 1.2 |
31 | 31 | * @var string |
32 | 32 | */ |
33 | 33 | protected $name; |
34 | | - |
| 34 | + |
35 | 35 | /** |
36 | 36 | * If the campaign is enabled or not. |
37 | | - * |
| 37 | + * |
38 | 38 | * @since 1.2 |
39 | 39 | * @var boolean |
40 | 40 | */ |
41 | 41 | protected $isEnabled; |
42 | | - |
| 42 | + |
43 | 43 | /** |
44 | 44 | * The campaign configuration. |
45 | | - * |
| 45 | + * |
46 | 46 | * @since 1.2 |
47 | 47 | * @var array |
48 | 48 | */ |
49 | 49 | protected $config; |
50 | | - |
| 50 | + |
51 | 51 | /** |
52 | 52 | * If the campaign config has been loaded or not. |
53 | | - * |
| 53 | + * |
54 | 54 | * @since 1.2 |
55 | 55 | * @var boolean |
56 | 56 | */ |
57 | 57 | protected $loadedConfig = false; |
58 | | - |
| 58 | + |
59 | 59 | /** |
60 | 60 | * Create a new instance of $campaignName. |
61 | | - * |
| 61 | + * |
62 | 62 | * @since 1.2 |
63 | | - * |
| 63 | + * |
64 | 64 | * @param integer $id |
65 | 65 | * @param string $name |
66 | 66 | * @param boolean $isEnabled |
— | — | @@ -69,53 +69,53 @@ |
70 | 70 | $this->id = $id; |
71 | 71 | $this->name = $name; |
72 | 72 | $this->isEnabled = $isEnabled; |
73 | | - |
| 73 | + |
74 | 74 | $this->setConfig( $config ); |
75 | 75 | } |
76 | | - |
| 76 | + |
77 | 77 | /** |
78 | 78 | * Returns the UploadWizardCampaign with specified name, or false if there is no such campaign. |
79 | | - * |
| 79 | + * |
80 | 80 | * @since 1.2 |
81 | | - * |
| 81 | + * |
82 | 82 | * @param string $campaignName |
83 | 83 | * @param boolean $loadConfig |
84 | | - * |
| 84 | + * |
85 | 85 | * @return UploadWizardCampaign or false |
86 | 86 | */ |
87 | 87 | public static function newFromName( $campaignName, $loadConfig = true ) { |
88 | 88 | return self::newFromDB( array( 'campaign_name' => $campaignName ), $loadConfig ); |
89 | 89 | } |
90 | | - |
| 90 | + |
91 | 91 | /** |
92 | 92 | * Returns the UploadWizardCampaign with specified ID, or false if there is no such campaign. |
93 | | - * |
| 93 | + * |
94 | 94 | * @since 1.2 |
95 | | - * |
| 95 | + * |
96 | 96 | * @param integer $campaignId |
97 | 97 | * @param boolean $loadConfig |
98 | | - * |
| 98 | + * |
99 | 99 | * @return UploadWizardCampaign or false |
100 | 100 | */ |
101 | 101 | public static function newFromId( $campaignId, $loadConfig = true ) { |
102 | 102 | return self::newFromDB( array( 'campaign_id' => $campaignId ), $loadConfig ); |
103 | 103 | } |
104 | | - |
| 104 | + |
105 | 105 | /** |
106 | 106 | * Returns a new instance of UploadWizardCampaign build from a database result |
107 | 107 | * obtained by doing a select with the porvided conditions on the uw_campaigns table. |
108 | 108 | * If no campaign matches the conditions, false will be returned. |
109 | | - * |
| 109 | + * |
110 | 110 | * @since 1.2 |
111 | | - * |
| 111 | + * |
112 | 112 | * @param array $conditions |
113 | 113 | * @param boolean $loadConfig |
114 | | - * |
| 114 | + * |
115 | 115 | * @return UploadWizardCampaign or false |
116 | 116 | */ |
117 | 117 | protected static function newFromDB( array $conditions, $loadConfig = true ) { |
118 | 118 | $dbr = wfGetDB( DB_SLAVE ); |
119 | | - |
| 119 | + |
120 | 120 | $campaign = $dbr->selectRow( |
121 | 121 | 'uw_campaigns', |
122 | 122 | array( |
— | — | @@ -125,13 +125,13 @@ |
126 | 126 | ), |
127 | 127 | $conditions |
128 | 128 | ); |
129 | | - |
| 129 | + |
130 | 130 | if ( !$campaign ) { |
131 | 131 | return false; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $config = $loadConfig ? self::getPropsFromDB( $dbr, $campaign->campaign_id ) : array(); |
135 | | - |
| 135 | + |
136 | 136 | return new self( |
137 | 137 | $campaign->campaign_id, |
138 | 138 | $campaign->campaign_name, |
— | — | @@ -139,25 +139,25 @@ |
140 | 140 | $config |
141 | 141 | ); |
142 | 142 | } |
143 | | - |
| 143 | + |
144 | 144 | /** |
145 | 145 | * Returns the list of configuration settings that can be modified by campaigns, |
146 | 146 | * and the HTMLForm input type that can be used to represent their value. |
147 | 147 | * Property name => HTMLForm input type |
148 | | - * |
| 148 | + * |
149 | 149 | * @since 1.2 |
150 | | - * |
| 150 | + * |
151 | 151 | * @return array |
152 | 152 | */ |
153 | 153 | public static function getConfigTypes() { |
154 | 154 | $globalConfig = UploadWizardConfig::getConfig(); |
155 | | - |
| 155 | + |
156 | 156 | $config = array( |
157 | 157 | 'headerLabelPage' => array( |
158 | 158 | 'type' => 'text', |
159 | 159 | ), |
160 | | - 'skipTutorial' => array( |
161 | | - 'type' => 'check' |
| 160 | + 'skipTutorial' => array( |
| 161 | + 'type' => 'check' |
162 | 162 | ), |
163 | 163 | 'tutorialTemplate' => array( |
164 | 164 | 'type' => 'text', |
— | — | @@ -177,9 +177,9 @@ |
178 | 178 | 'idFieldLabelPage' => array( |
179 | 179 | 'type' => 'text', |
180 | 180 | ), |
181 | | - 'ownWorkOption' => array( |
| 181 | + 'ownWorkOption' => array( |
182 | 182 | 'type' => 'radio', |
183 | | - 'options' => array( |
| 183 | + 'options' => array( |
184 | 184 | wfMsg( 'mwe-upwiz-campaign-owner-choice' ) => 'choice', |
185 | 185 | wfMsg( 'mwe-upwiz-campaign-owner-own' ) => 'own', |
186 | 186 | wfMsg( 'mwe-upwiz-campaign-owner-notown' ) => 'notown' |
— | — | @@ -188,20 +188,20 @@ |
189 | 189 | 'licensesOwnWork' => array( |
190 | 190 | 'type' => 'multiselect', |
191 | 191 | 'options' => array(), |
192 | | - 'default' => $globalConfig['licensesOwnWork']['licenses'] |
| 192 | + 'default' => $globalConfig['licensesOwnWork']['licenses'] |
193 | 193 | ), |
194 | 194 | 'defaultOwnWorkLicence' => array( |
195 | 195 | 'type' => 'radio', |
196 | 196 | 'options' => array(), |
197 | 197 | 'default' => $globalConfig['licensesOwnWork']['defaults'][0] |
198 | 198 | ), |
199 | | - 'defaultCategories' => array( |
| 199 | + 'defaultCategories' => array( |
200 | 200 | 'type' => 'text' |
201 | 201 | ), |
202 | | - 'autoCategories' => array( |
| 202 | + 'autoCategories' => array( |
203 | 203 | 'type' => 'text' |
204 | 204 | ), |
205 | | - 'autoWikiText' => array( |
| 205 | + 'autoWikiText' => array( |
206 | 206 | 'type' => 'textarea', |
207 | 207 | 'rows' => 4 |
208 | 208 | ), |
— | — | @@ -209,32 +209,32 @@ |
210 | 210 | 'type' => 'text' |
211 | 211 | ), |
212 | 212 | ); |
213 | | - |
| 213 | + |
214 | 214 | foreach ( $globalConfig['licensesOwnWork']['licenses'] as $license ) { |
215 | 215 | $licenceMsg = wfMsg( $globalConfig['licenses'][$license]['msg'] ); |
216 | 216 | $config['licensesOwnWork']['options'][$licenceMsg] = $license; |
217 | 217 | } |
218 | | - |
| 218 | + |
219 | 219 | $config['defaultOwnWorkLicence']['options'] = $config['licensesOwnWork']['options']; |
220 | | - |
| 220 | + |
221 | 221 | return $config; |
222 | 222 | } |
223 | | - |
| 223 | + |
224 | 224 | /** |
225 | 225 | * Returns the default configuration values. |
226 | 226 | * Property name => array( 'default' => $value, 'type' => HTMLForm input type ) |
227 | | - * |
| 227 | + * |
228 | 228 | * @since 1.2 |
229 | | - * |
| 229 | + * |
230 | 230 | * @return array |
231 | 231 | */ |
232 | 232 | public static function getDefaultConfig() { |
233 | 233 | static $config = false; |
234 | | - |
| 234 | + |
235 | 235 | if ( $config === false ) { |
236 | 236 | $config = array(); |
237 | 237 | $globalConf = UploadWizardConfig::getConfig(); |
238 | | - |
| 238 | + |
239 | 239 | foreach ( self::getConfigTypes() as $setting => $data ) { |
240 | 240 | if ( array_key_exists( $setting, $globalConf ) ) { |
241 | 241 | $config[$setting] = array_merge( array( 'default' => $globalConf[$setting] ), $data ); |
— | — | @@ -247,81 +247,81 @@ |
248 | 248 | else { |
249 | 249 | wfWarn( "Nonexiting Upload Wizard configuration setting '$setting' will be ignored." ); |
250 | 250 | } |
251 | | - } |
| 251 | + } |
252 | 252 | } |
253 | | - |
| 253 | + |
254 | 254 | return $config; |
255 | 255 | } |
256 | | - |
| 256 | + |
257 | 257 | /** |
258 | 258 | * Returns the id of the campaign. |
259 | | - * |
| 259 | + * |
260 | 260 | * @since 1.2 |
261 | | - * |
| 261 | + * |
262 | 262 | * @return intgere |
263 | 263 | */ |
264 | 264 | public function getId() { |
265 | 265 | return $this->id; |
266 | 266 | } |
267 | | - |
| 267 | + |
268 | 268 | /** |
269 | 269 | * Returns the name of the campaign. |
270 | | - * |
| 270 | + * |
271 | 271 | * @since 1.2 |
272 | | - * |
| 272 | + * |
273 | 273 | * @return string |
274 | 274 | */ |
275 | 275 | public function getName() { |
276 | 276 | return $this->name; |
277 | 277 | } |
278 | | - |
| 278 | + |
279 | 279 | /** |
280 | 280 | * Returns if the campaign is enabled. |
281 | | - * |
| 281 | + * |
282 | 282 | * @since 1.2 |
283 | | - * |
| 283 | + * |
284 | 284 | * @return boolean |
285 | 285 | */ |
286 | 286 | public function getIsEnabled() { |
287 | 287 | return $this->isEnabled; |
288 | 288 | } |
289 | | - |
| 289 | + |
290 | 290 | /** |
291 | 291 | * Sets all config properties. |
292 | | - * |
| 292 | + * |
293 | 293 | * @since 1.2 |
294 | | - * |
| 294 | + * |
295 | 295 | * @param array $config |
296 | 296 | */ |
297 | 297 | public function setConfig( array $config ) { |
298 | 298 | $defaultConfig = self::getDefaultConfig(); |
299 | | - |
| 299 | + |
300 | 300 | foreach ( $config as $settingName => &$settingValue ) { |
301 | 301 | if ( is_array( $defaultConfig[$settingName]['default'] ) && !is_array( $settingValue ) ) { |
302 | 302 | $parts = explode( '| ', $settingValue ); |
303 | 303 | $settingValue = array(); |
304 | | - |
| 304 | + |
305 | 305 | foreach ( $parts as $part ) { |
306 | 306 | $part = trim( $part ); |
307 | | - |
| 307 | + |
308 | 308 | if ( $part != '' ) { |
309 | 309 | $settingValue[] = $part; |
310 | 310 | } |
311 | 311 | } |
312 | 312 | } |
313 | 313 | } |
314 | | - |
| 314 | + |
315 | 315 | $this->config = $config; |
316 | | - |
| 316 | + |
317 | 317 | $this->loadedConfig = count( $this->config ) > 0; |
318 | 318 | } |
319 | | - |
| 319 | + |
320 | 320 | /** |
321 | 321 | * Returns all set config properties. |
322 | 322 | * Property name => property value |
323 | | - * |
| 323 | + * |
324 | 324 | * @since 1.2 |
325 | | - * |
| 325 | + * |
326 | 326 | * @return array |
327 | 327 | */ |
328 | 328 | public function getConfig() { |
— | — | @@ -329,24 +329,24 @@ |
330 | 330 | if ( !is_null( $this->id ) ) { |
331 | 331 | $this->config = self::getPropsFromDB( wfGetDB( DB_SLAVE ), $this->id ); |
332 | 332 | } |
333 | | - |
| 333 | + |
334 | 334 | $this->loadedConfig = true; |
335 | 335 | } |
336 | | - |
| 336 | + |
337 | 337 | return $this->config; |
338 | 338 | } |
339 | | - |
| 339 | + |
340 | 340 | /** |
341 | 341 | * Returns the configuration, ready for merging with the |
342 | 342 | * global configuration. |
343 | | - * |
| 343 | + * |
344 | 344 | * @since 1.2 |
345 | | - * |
| 345 | + * |
346 | 346 | * @return arrayu |
347 | 347 | */ |
348 | 348 | public function getConfigForGlobalMerge() { |
349 | 349 | $config = $this->getConfig(); |
350 | | - |
| 350 | + |
351 | 351 | foreach ( $config as $settingName => &$settingValue ) { |
352 | 352 | switch ( $settingName ) { |
353 | 353 | case 'licensesOwnWork': |
— | — | @@ -357,49 +357,49 @@ |
358 | 358 | break; |
359 | 359 | } |
360 | 360 | } |
361 | | - |
| 361 | + |
362 | 362 | foreach ( self::getDefaultConfig() as $name => $data ) { |
363 | 363 | if ( !array_key_exists( $name, $config ) ) { |
364 | 364 | $config[$name] = $data['default']; |
365 | 365 | } |
366 | 366 | } |
367 | | - |
| 367 | + |
368 | 368 | $config['licensesOwnWork']['defaults'] = array( $config['defaultOwnWorkLicence'] ); |
369 | 369 | unset( $config['defaultOwnWorkLicence'] ); |
370 | | - |
| 370 | + |
371 | 371 | return $config; |
372 | 372 | } |
373 | | - |
| 373 | + |
374 | 374 | /** |
375 | 375 | * Returns all config properties by merging the set ones with a list of default ones. |
376 | 376 | * Property name => array( 'default' => $value, 'type' => HTMLForm input type ) |
377 | | - * |
| 377 | + * |
378 | 378 | * @since 1.2 |
379 | | - * |
| 379 | + * |
380 | 380 | * @return array |
381 | 381 | */ |
382 | 382 | public function getAllConfig() { |
383 | 383 | $setConfig = $this->getConfig(); |
384 | 384 | $config = array(); |
385 | | - |
| 385 | + |
386 | 386 | foreach ( self::getDefaultConfig() as $name => $data ) { |
387 | 387 | if ( array_key_exists( $name, $setConfig ) ) { |
388 | 388 | $data['default'] = $setConfig[$name]; |
389 | 389 | } |
390 | | - |
| 390 | + |
391 | 391 | $config[$name] = $data; |
392 | 392 | } |
393 | | - |
| 393 | + |
394 | 394 | return $config; |
395 | 395 | } |
396 | | - |
| 396 | + |
397 | 397 | /** |
398 | 398 | * Write the campaign to the DB. |
399 | 399 | * If it's already there, it'll be updated, else it'll be inserted. |
400 | | - * |
| 400 | + * |
401 | 401 | * @since 1.2 |
402 | | - * |
403 | | - * @return boolean Success indicator |
| 402 | + * |
| 403 | + * @return boolean Success indicator |
404 | 404 | */ |
405 | 405 | public function writeToDB() { |
406 | 406 | if ( is_null( $this->id ) ) { |
— | — | @@ -409,79 +409,82 @@ |
410 | 410 | return $this->updateInDB(); |
411 | 411 | } |
412 | 412 | } |
413 | | - |
| 413 | + |
414 | 414 | /** |
415 | 415 | * Insert the campaign into the DB. |
416 | | - * |
| 416 | + * |
417 | 417 | * @since 1.2 |
418 | | - * |
419 | | - * @return boolean Success indicator |
| 418 | + * |
| 419 | + * @return boolean Success indicator |
420 | 420 | */ |
421 | 421 | protected function insertIntoDB() { |
422 | 422 | $dbw = wfGetDB( DB_MASTER ); |
423 | | - |
| 423 | + |
424 | 424 | $success = $dbw->insert( |
425 | 425 | 'uw_campaigns', |
426 | 426 | array( |
427 | 427 | 'campaign_name' => $this->name, |
428 | 428 | 'campaign_enabled' => $this->isEnabled, |
429 | 429 | ), |
| 430 | + __METHOD__, |
430 | 431 | array( 'campaign_id' => $this->id ) |
431 | 432 | ); |
432 | | - |
| 433 | + |
433 | 434 | if ( $success ) { |
434 | 435 | $this->id = $dbw->insertId(); |
435 | 436 | $success &= $this->writePropsToDB( $dbw ); |
436 | 437 | } |
437 | | - |
| 438 | + |
438 | 439 | return $success; |
439 | 440 | } |
440 | | - |
| 441 | + |
441 | 442 | /** |
442 | 443 | * Update the campaign in the DB. |
443 | | - * |
| 444 | + * |
444 | 445 | * @since 1.2 |
445 | | - * |
446 | | - * @return boolean Success indicator |
| 446 | + * |
| 447 | + * @return boolean Success indicator |
447 | 448 | */ |
448 | 449 | protected function updateInDB() { |
449 | 450 | $dbw = wfGetDB( DB_MASTER ); |
450 | | - |
| 451 | + |
451 | 452 | $success = $dbw->update( |
452 | 453 | 'uw_campaigns', |
453 | 454 | array( |
454 | 455 | 'campaign_name' => $this->name, |
455 | 456 | 'campaign_enabled' => $this->isEnabled, |
456 | 457 | ), |
457 | | - array( 'campaign_id' => $this->id ) |
| 458 | + array( 'campaign_id' => $this->id ), |
| 459 | + __METHOD__ |
458 | 460 | ); |
459 | | - |
| 461 | + |
460 | 462 | // Delete and insert instead of update. |
461 | 463 | // This will not result into dead-data when config vars are removed. |
462 | 464 | $success &= $dbw->delete( |
463 | 465 | 'uw_campaign_conf', |
464 | | - array( 'cc_campaign_id' => $this->id ) |
| 466 | + array( 'cc_campaign_id' => $this->id ), |
| 467 | + __METHOD__ |
465 | 468 | ); |
466 | | - |
| 469 | + |
467 | 470 | $success &= $this->writePropsToDB( $dbw ); |
468 | | - |
| 471 | + |
469 | 472 | return $success; |
470 | 473 | } |
471 | | - |
| 474 | + |
472 | 475 | /** |
473 | 476 | * Write (insert) the properties into the DB. |
474 | | - * |
| 477 | + * |
475 | 478 | * @since 1.2 |
476 | | - * |
| 479 | + * |
477 | 480 | * @param Database $dbw |
478 | | - * |
479 | | - * @return boolean Success indicator |
| 481 | + * |
| 482 | + * @return boolean Success indicator |
480 | 483 | */ |
481 | 484 | protected function writePropsToDB( DatabaseBase $dbw ) { |
482 | 485 | $success = true; |
483 | | - |
| 486 | + |
484 | 487 | $dbw->begin(); |
485 | | - |
| 488 | + |
486 | 489 | foreach ( $this->config as $prop => $value ) { |
487 | 490 | $success &= $dbw->insert( |
488 | 491 | 'uw_campaign_conf', |
— | — | @@ -489,66 +492,70 @@ |
490 | 493 | 'cc_campaign_id' => $this->id, |
491 | 494 | 'cc_property' => $prop, |
492 | 495 | 'cc_value' => is_array( $value ) ? implode( '| ', $value ) : $value |
493 | | - ) |
| 496 | + ), |
| 497 | + __METHOD__ |
494 | 498 | ); |
495 | 499 | } |
496 | | - |
| 500 | + |
497 | 501 | $dbw->commit(); |
498 | | - |
| 502 | + |
499 | 503 | return $success; |
500 | 504 | } |
501 | | - |
| 505 | + |
502 | 506 | /** |
503 | 507 | * Get the configuration properties from the DB. |
504 | | - * |
| 508 | + * |
505 | 509 | * @since 1.2 |
506 | | - * |
| 510 | + * |
507 | 511 | * @param Database $dbr |
508 | 512 | * @param integer $campaignId |
509 | | - * |
510 | | - * @return array |
| 513 | + * |
| 514 | + * @return array |
511 | 515 | */ |
512 | 516 | protected static function getPropsFromDB( DatabaseBase $dbr, $campaignId ) { |
513 | 517 | $config = array(); |
514 | | - |
| 518 | + |
515 | 519 | $confProps = $dbr->select( |
516 | 520 | 'uw_campaign_conf', |
517 | 521 | array( 'cc_property', 'cc_value' ), |
518 | | - array( 'cc_campaign_id' => $campaignId ) |
| 522 | + array( 'cc_campaign_id' => $campaignId ), |
| 523 | + __METHOD__ |
519 | 524 | ); |
520 | | - |
| 525 | + |
521 | 526 | foreach ( $confProps as $confProp ) { |
522 | 527 | $config[$confProp->cc_property] = $confProp->cc_value; |
523 | 528 | } |
524 | | - |
| 529 | + |
525 | 530 | return $config; |
526 | 531 | } |
527 | | - |
| 532 | + |
528 | 533 | /** |
529 | 534 | * Delete the campaign from the DB (when present). |
530 | | - * |
| 535 | + * |
531 | 536 | * @since 1.2 |
532 | | - * |
533 | | - * @return boolean Success indicator |
| 537 | + * |
| 538 | + * @return boolean Success indicator |
534 | 539 | */ |
535 | 540 | public function deleteFromDB() { |
536 | 541 | if ( is_null( $this->id ) ) { |
537 | 542 | return true; |
538 | 543 | } |
539 | | - |
| 544 | + |
540 | 545 | $dbw = wfGetDB( DB_MASTER ); |
541 | | - |
| 546 | + |
542 | 547 | $d1 = $dbw->delete( |
543 | 548 | 'uw_campaigns', |
544 | | - array( 'campaign_id' => $this->id ) |
| 549 | + array( 'campaign_id' => $this->id ), |
| 550 | + __METHOD__ |
545 | 551 | ); |
546 | | - |
| 552 | + |
547 | 553 | $d2 = $dbw->delete( |
548 | 554 | 'uw_campaign_conf', |
549 | | - array( 'cc_campaign_id' => $this->id ) |
| 555 | + array( 'cc_campaign_id' => $this->id ), |
| 556 | + __METHOD__ |
550 | 557 | ); |
551 | | - |
| 558 | + |
552 | 559 | return $d1 && $d2; |
553 | 560 | } |
554 | | - |
| 561 | + |
555 | 562 | } |