r95495 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95494‎ | r95495 | r95496 >
Date:17:13, 25 August 2011
Author:reedy
Status:ok
Tags:
Comment:
Fix error that was reported as a fixme against r90668, not at fault though

Add __METHOD__ to all DB related call,s so we don't pass array ('campaign_id' => null) to the database caller as a function name

Probably means other stuff was broken too...
Modified paths:
  • /trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php (modified) (history)
  • /trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php (modified) (history)
  • /trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php
@@ -8,26 +8,26 @@
99 * @file
1010 * @ingroup SpecialPage
1111 * @ingroup Upload
12 - *
 12+ *
1313 * @since 1.2
14 - *
 14+ *
1515 * @licence GNU GPL v2+
1616 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1717 */
1818 class SpecialUploadCampaign extends FormSpecialPage {
19 -
 19+
2020 protected $subPage;
21 -
 21+
2222 /**
2323 * Constructor.
24 - *
 24+ *
2525 * @param $request is the request (usually wgRequest)
2626 * @param $par is everything in the URL after Special:UploadCampaign. Not sure what we can use it for
2727 */
2828 public function __construct( $request = null, $par = null ) {
2929 parent::__construct ( 'UploadCampaign', 'upwizcampaigns', false );
3030 }
31 -
 31+
3232 /**
3333 * Get the OutputPage being used for this instance.
3434 * This overrides the getOutput method of Specialpage added in MediaWiki 1.18,
@@ -40,7 +40,7 @@
4141 public function getOutput() {
4242 return version_compare( $GLOBALS['wgVersion'], '1.18', '>=' ) ? parent::getOutput() : $GLOBALS['wgOut'];
4343 }
44 -
 44+
4545 /**
4646 * (non-PHPdoc)
4747 * @see SpecialPage::getDescription()
@@ -48,7 +48,7 @@
4949 public function getDescription() {
5050 return wfMsg( 'mwe-upwiz-' . strtolower( $this->getName() ) );
5151 }
52 -
 52+
5353 /**
5454 * (non-PHPdoc)
5555 * @see FormSpecialPage::setParameter()
@@ -56,7 +56,7 @@
5757 protected function setParameter( $par ){
5858 $this->subPage = $par;
5959 }
60 -
 60+
6161 /**
6262 * (non-PHPdoc)
6363 * @see FormSpecialPage::getForm()
@@ -71,32 +71,30 @@
7272 'onclick' => 'window.location="' . SpecialPage::getTitleFor( 'UploadCampaigns' )->getFullURL() . '";return false;'
7373 )
7474 );
75 -
 75+
7676 return $form;
7777 }
78 -
 78+
7979 /**
8080 * (non-PHPdoc)
8181 * @see FormSpecialPage::getFormFields()
8282 */
8383 protected function getFormFields() {
84 - $dbr = wfGetDB( DB_SLAVE );
85 -
8684 $campaign = UploadWizardCampaign::newFromName( $this->subPage );
87 -
 85+
8886 $id = $campaign ? $campaign->getId() : null;
89 - $enabled = $campaign ? $campaign->getIsEnabled() : false;
 87+ $enabled = $campaign ? $campaign->getIsEnabled() : false;
9088 $configFields = $campaign ? $campaign->getAllConfig() : UploadWizardCampaign::getDefaultConfig();
91 -
 89+
9290 $fields = array();
93 -
 91+
9492 $fields['Campaignid'] = array ( 'type' => 'hidden', 'default' => $id );
9593 $fields['Campaignname'] = array ( 'type' => 'text', 'default' => $this->subPage, 'label-message' => 'mwe-upwiz-campaign-name' );
9694 $fields['Campaignenabled'] = array ( 'type' => 'check', 'default' => $enabled, 'label-message' => 'mwe-upwiz-campaign-enabled' );
97 -
 95+
9896 foreach ( $configFields as $name => $data ) {
9997 $data['label-message'] = 'mwe-upwiz-campaign-conf-' . $name;
100 -
 98+
10199 // Special handling for lists of values per input type.
102100 if ( is_array( $data['default'] ) ) {
103101 switch ( $data['type'] ) {
@@ -105,13 +103,13 @@
106104 break;
107105 }
108106 }
109 -
 107+
110108 $fields[$name] = $data;
111109 }
112 -
 110+
113111 return $fields;
114112 }
115 -
 113+
116114 /**
117115 * Process the form. At this point we know that the user passes all the criteria in
118116 * userCanExecute(), and if the data array contains 'Username', etc, then Username
@@ -121,26 +119,26 @@
122120 */
123121 public function onSubmit( array $data ) {
124122 global $wgRequest;
125 -
 123+
126124 $id = $data['Campaignid'] == '' ? null : $data['Campaignid'];
127125 unset( $data['Campaignid'] );
128 -
 126+
129127 $name = $data['Campaignname'];
130128 unset( $data['Campaignname'] );
131 -
 129+
132130 $enabled = $data['Campaignenabled'];
133131 unset( $data['Campaignenabled'] );
134 -
 132+
135133 if ( is_null( $id ) && !is_null( $wgRequest->getSessionData( 'uploadcampaignid-' . $name ) ) ) {
136134 $id = $wgRequest->getSessionData( 'uploadcampaignid-' . $name );
137135 }
138 -
 136+
139137 $campaign = new UploadWizardCampaign( $id, $name, $enabled, $data );
140 -
 138+
141139 $success = $campaign->writeToDB();
142 -
 140+
143141 $wgRequest->setSessionData( 'uploadcampaignid-' . $name, $campaign->getId() );
144 -
 142+
145143 if ( $success ) {
146144 return true;
147145 }
@@ -148,7 +146,7 @@
149147 return array(); // TODO
150148 }
151149 }
152 -
 150+
153151 public function onSuccess() {
154152 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() );
155153 }
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php
@@ -8,9 +8,9 @@
99 * @file
1010 * @ingroup SpecialPage
1111 * @ingroup Upload
12 - *
 12+ *
1313 * @since 1.2
14 - *
 14+ *
1515 * @licence GNU GPL v3+
1616 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1717 */
@@ -18,14 +18,14 @@
1919
2020 /**
2121 * Constructor.
22 - *
 22+ *
2323 * @param $request is the request (usually wgRequest)
2424 * @param $par is everything in the URL after Special:UploadCampaigns. Not sure what we can use it for
2525 */
2626 public function __construct( $request = null, $par = null ) {
2727 parent::__construct( 'UploadCampaigns', 'upwizcampaigns' );
2828 }
29 -
 29+
3030 /**
3131 * Get the OutputPage being used for this instance.
3232 * This overrides the getOutput method of Specialpage added in MediaWiki 1.18,
@@ -38,7 +38,7 @@
3939 public function getOutput() {
4040 return version_compare( $GLOBALS['wgVersion'], '1.18', '>=' ) ? parent::getOutput() : $GLOBALS['wgOut'];
4141 }
42 -
 42+
4343 /**
4444 * (non-PHPdoc)
4545 * @see SpecialPage::getDescription()
@@ -49,16 +49,16 @@
5050
5151 /**
5252 * Main method.
53 - *
 53+ *
5454 * @param string $subPage, e.g. the "foo" in Special:UploadCampaigns/foo.
5555 */
5656 public function execute( $subPage ) {
5757 global $wgRequest, $wgUser;
58 -
 58+
5959 $this->setHeaders();
6060 $this->outputHeader();
6161 $subPage = explode( '/', $subPage, 2 );
62 -
 62+
6363 // If the user is authorized, display the page, if not, show an error.
6464 if ( $this->userCanExecute( $wgUser ) ) {
6565 if ( $wgRequest->wasPosted()
@@ -78,39 +78,41 @@
7979 $this->displayRestrictionError();
8080 }
8181 }
82 -
 82+
8383 /**
8484 * Displays the pages regular output.
85 - *
 85+ *
8686 * @since 1.2
8787 */
8888 protected function displayUploadCamaigns() {
8989 $this->displayAddNewControl();
90 -
 90+
9191 $dbr = wfGetDB( DB_SLAVE );
92 -
 92+
9393 $campaigns = $dbr->select(
9494 'uw_campaigns',
9595 array(
9696 'campaign_id',
9797 'campaign_name',
9898 'campaign_enabled',
99 - )
 99+ ),
 100+ '',
 101+ __METHOD__
100102 );
101 -
 103+
102104 if ( $campaigns->numRows() > 0 ) {
103105 $this->displayCampaignTable( $campaigns );
104106 }
105107 }
106 -
 108+
107109 /**
108110 * Displays a small form to add a new campaign.
109 - *
 111+ *
110112 * @since 1.2
111113 */
112114 protected function displayAddNewControl() {
113115 $out = $this->getOutput();
114 -
 116+
115117 $out->addHTML( Html::openElement(
116118 'form',
117119 array(
@@ -118,47 +120,47 @@
119121 'action' => $this->getTitle()->getLocalURL(),
120122 )
121123 ) );
122 -
 124+
123125 $out->addHTML( '<fieldset>' );
124 -
 126+
125127 $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'mwe-upwiz-campaigns-addnew' ) ) . '</legend>' );
126 -
 128+
127129 $out->addHTML( Html::element( 'p', array(), wfMsg( 'mwe-upwiz-campaigns-namedoc' ) ) );
128 -
 130+
129131 $out->addHTML( Html::element( 'label', array( 'for' => 'newcampaign' ), wfMsg( 'mwe-upwiz-campaigns-newname' ) ) );
130 -
 132+
131133 $out->addHTML( '&#160;' . Html::input( 'newcampaign' ) . '&#160;' );
132 -
 134+
133135 $out->addHTML( Html::input(
134136 'addnewcampaign',
135137 wfMsg( 'mwe-upwiz-campaigns-add' ),
136138 'submit'
137139 ) );
138 -
 140+
139141 global $wgUser;
140142 $out->addHTML( Html::hidden( 'wpEditToken', $wgUser->editToken() ) );
141 -
 143+
142144 $out->addHTML( '</fieldset></form>' );
143145 }
144 -
 146+
145147 /**
146148 * Displays a list of all campaigns.
147 - *
 149+ *
148150 * @since 1.2
149 - *
 151+ *
150152 * @param ResultWrapper $campaigns
151153 */
152154 protected function displayCampaignTable( ResultWrapper $campaigns ) {
153155 $out = $this->getOutput();
154 -
 156+
155157 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'mwe-upwiz-campaigns-existing' ) ) );
156 -
 158+
157159 $out->addHTML( Xml::openElement(
158160 'table',
159161 array( 'class' => 'wikitable', 'style' => 'width:400px' )
160162 ) );
161 -
162 - $out->addHTML(
 163+
 164+ $out->addHTML(
163165 '<tr>' .
164166 Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-name' ) ) .
165167 Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-status' ) ) .
@@ -166,12 +168,12 @@
167169 Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-delete' ) ) .
168170 '</tr>'
169171 );
170 -
 172+
171173 foreach ( $campaigns as $campaign ) {
172174 $out->addHTML(
173175 '<tr>' .
174176 '<td>' .
175 - Html::element(
 177+ Html::element(
176178 'a',
177179 array(
178180 'href' => SpecialPage::getTitleFor( 'UploadWizard' )->getLocalURL( array( 'campaign' => $campaign->campaign_name ) )
@@ -181,7 +183,7 @@
182184 '</td>' .
183185 Html::element( 'td', array(), wfMsg( 'mwe-upwiz-campaigns-' . ( $campaign->campaign_enabled ? 'enabled' : 'disabled' ) ) ) .
184186 '<td>' .
185 - Html::element(
 187+ Html::element(
186188 'a',
187189 array(
188190 'href' => SpecialPage::getTitleFor( 'UploadCampaign', $campaign->campaign_name )->getLocalURL()
@@ -190,7 +192,7 @@
191193 ) .
192194 '</td>' .
193195 '<td>' .
194 - Html::element(
 196+ Html::element(
195197 'a',
196198 array(
197199 'href' => SpecialPage::getTitleFor( 'UploadCampaigns', 'del/' . $campaign->campaign_name )->getLocalURL(),
@@ -202,8 +204,8 @@
203205 '</tr>'
204206 );
205207 }
206 -
 208+
207209 $out->addHTML( '</table>' );
208 - }
 210+ }
209211
210212 }
Index: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php
@@ -5,61 +5,61 @@
66 *
77 * @file
88 * @ingroup Upload
9 - *
 9+ *
1010 * @since 1.2
11 - *
 11+ *
1212 * @licence GNU GPL v2+
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class UploadWizardCampaign {
16 -
 16+
1717 /**
1818 * If the ID of the campaign.
1919 * Either this matched a record in the uw_campaigns table or is null.
20 - *
 20+ *
2121 * @since 1.2
2222 * @var integer or null
2323 */
2424 protected $id;
25 -
 25+
2626 /**
2727 * If the name of the campaign.
2828 * This name is the string used to invoke the campaign via campaign=name.
29 - *
 29+ *
3030 * @since 1.2
3131 * @var string
3232 */
3333 protected $name;
34 -
 34+
3535 /**
3636 * If the campaign is enabled or not.
37 - *
 37+ *
3838 * @since 1.2
3939 * @var boolean
4040 */
4141 protected $isEnabled;
42 -
 42+
4343 /**
4444 * The campaign configuration.
45 - *
 45+ *
4646 * @since 1.2
4747 * @var array
4848 */
4949 protected $config;
50 -
 50+
5151 /**
5252 * If the campaign config has been loaded or not.
53 - *
 53+ *
5454 * @since 1.2
5555 * @var boolean
5656 */
5757 protected $loadedConfig = false;
58 -
 58+
5959 /**
6060 * Create a new instance of $campaignName.
61 - *
 61+ *
6262 * @since 1.2
63 - *
 63+ *
6464 * @param integer $id
6565 * @param string $name
6666 * @param boolean $isEnabled
@@ -69,53 +69,53 @@
7070 $this->id = $id;
7171 $this->name = $name;
7272 $this->isEnabled = $isEnabled;
73 -
 73+
7474 $this->setConfig( $config );
7575 }
76 -
 76+
7777 /**
7878 * Returns the UploadWizardCampaign with specified name, or false if there is no such campaign.
79 - *
 79+ *
8080 * @since 1.2
81 - *
 81+ *
8282 * @param string $campaignName
8383 * @param boolean $loadConfig
84 - *
 84+ *
8585 * @return UploadWizardCampaign or false
8686 */
8787 public static function newFromName( $campaignName, $loadConfig = true ) {
8888 return self::newFromDB( array( 'campaign_name' => $campaignName ), $loadConfig );
8989 }
90 -
 90+
9191 /**
9292 * Returns the UploadWizardCampaign with specified ID, or false if there is no such campaign.
93 - *
 93+ *
9494 * @since 1.2
95 - *
 95+ *
9696 * @param integer $campaignId
9797 * @param boolean $loadConfig
98 - *
 98+ *
9999 * @return UploadWizardCampaign or false
100100 */
101101 public static function newFromId( $campaignId, $loadConfig = true ) {
102102 return self::newFromDB( array( 'campaign_id' => $campaignId ), $loadConfig );
103103 }
104 -
 104+
105105 /**
106106 * Returns a new instance of UploadWizardCampaign build from a database result
107107 * obtained by doing a select with the porvided conditions on the uw_campaigns table.
108108 * If no campaign matches the conditions, false will be returned.
109 - *
 109+ *
110110 * @since 1.2
111 - *
 111+ *
112112 * @param array $conditions
113113 * @param boolean $loadConfig
114 - *
 114+ *
115115 * @return UploadWizardCampaign or false
116116 */
117117 protected static function newFromDB( array $conditions, $loadConfig = true ) {
118118 $dbr = wfGetDB( DB_SLAVE );
119 -
 119+
120120 $campaign = $dbr->selectRow(
121121 'uw_campaigns',
122122 array(
@@ -125,13 +125,13 @@
126126 ),
127127 $conditions
128128 );
129 -
 129+
130130 if ( !$campaign ) {
131131 return false;
132132 }
133133
134134 $config = $loadConfig ? self::getPropsFromDB( $dbr, $campaign->campaign_id ) : array();
135 -
 135+
136136 return new self(
137137 $campaign->campaign_id,
138138 $campaign->campaign_name,
@@ -139,25 +139,25 @@
140140 $config
141141 );
142142 }
143 -
 143+
144144 /**
145145 * Returns the list of configuration settings that can be modified by campaigns,
146146 * and the HTMLForm input type that can be used to represent their value.
147147 * Property name => HTMLForm input type
148 - *
 148+ *
149149 * @since 1.2
150 - *
 150+ *
151151 * @return array
152152 */
153153 public static function getConfigTypes() {
154154 $globalConfig = UploadWizardConfig::getConfig();
155 -
 155+
156156 $config = array(
157157 'headerLabelPage' => array(
158158 'type' => 'text',
159159 ),
160 - 'skipTutorial' => array(
161 - 'type' => 'check'
 160+ 'skipTutorial' => array(
 161+ 'type' => 'check'
162162 ),
163163 'tutorialTemplate' => array(
164164 'type' => 'text',
@@ -177,9 +177,9 @@
178178 'idFieldLabelPage' => array(
179179 'type' => 'text',
180180 ),
181 - 'ownWorkOption' => array(
 181+ 'ownWorkOption' => array(
182182 'type' => 'radio',
183 - 'options' => array(
 183+ 'options' => array(
184184 wfMsg( 'mwe-upwiz-campaign-owner-choice' ) => 'choice',
185185 wfMsg( 'mwe-upwiz-campaign-owner-own' ) => 'own',
186186 wfMsg( 'mwe-upwiz-campaign-owner-notown' ) => 'notown'
@@ -188,20 +188,20 @@
189189 'licensesOwnWork' => array(
190190 'type' => 'multiselect',
191191 'options' => array(),
192 - 'default' => $globalConfig['licensesOwnWork']['licenses']
 192+ 'default' => $globalConfig['licensesOwnWork']['licenses']
193193 ),
194194 'defaultOwnWorkLicence' => array(
195195 'type' => 'radio',
196196 'options' => array(),
197197 'default' => $globalConfig['licensesOwnWork']['defaults'][0]
198198 ),
199 - 'defaultCategories' => array(
 199+ 'defaultCategories' => array(
200200 'type' => 'text'
201201 ),
202 - 'autoCategories' => array(
 202+ 'autoCategories' => array(
203203 'type' => 'text'
204204 ),
205 - 'autoWikiText' => array(
 205+ 'autoWikiText' => array(
206206 'type' => 'textarea',
207207 'rows' => 4
208208 ),
@@ -209,32 +209,32 @@
210210 'type' => 'text'
211211 ),
212212 );
213 -
 213+
214214 foreach ( $globalConfig['licensesOwnWork']['licenses'] as $license ) {
215215 $licenceMsg = wfMsg( $globalConfig['licenses'][$license]['msg'] );
216216 $config['licensesOwnWork']['options'][$licenceMsg] = $license;
217217 }
218 -
 218+
219219 $config['defaultOwnWorkLicence']['options'] = $config['licensesOwnWork']['options'];
220 -
 220+
221221 return $config;
222222 }
223 -
 223+
224224 /**
225225 * Returns the default configuration values.
226226 * Property name => array( 'default' => $value, 'type' => HTMLForm input type )
227 - *
 227+ *
228228 * @since 1.2
229 - *
 229+ *
230230 * @return array
231231 */
232232 public static function getDefaultConfig() {
233233 static $config = false;
234 -
 234+
235235 if ( $config === false ) {
236236 $config = array();
237237 $globalConf = UploadWizardConfig::getConfig();
238 -
 238+
239239 foreach ( self::getConfigTypes() as $setting => $data ) {
240240 if ( array_key_exists( $setting, $globalConf ) ) {
241241 $config[$setting] = array_merge( array( 'default' => $globalConf[$setting] ), $data );
@@ -247,81 +247,81 @@
248248 else {
249249 wfWarn( "Nonexiting Upload Wizard configuration setting '$setting' will be ignored." );
250250 }
251 - }
 251+ }
252252 }
253 -
 253+
254254 return $config;
255255 }
256 -
 256+
257257 /**
258258 * Returns the id of the campaign.
259 - *
 259+ *
260260 * @since 1.2
261 - *
 261+ *
262262 * @return intgere
263263 */
264264 public function getId() {
265265 return $this->id;
266266 }
267 -
 267+
268268 /**
269269 * Returns the name of the campaign.
270 - *
 270+ *
271271 * @since 1.2
272 - *
 272+ *
273273 * @return string
274274 */
275275 public function getName() {
276276 return $this->name;
277277 }
278 -
 278+
279279 /**
280280 * Returns if the campaign is enabled.
281 - *
 281+ *
282282 * @since 1.2
283 - *
 283+ *
284284 * @return boolean
285285 */
286286 public function getIsEnabled() {
287287 return $this->isEnabled;
288288 }
289 -
 289+
290290 /**
291291 * Sets all config properties.
292 - *
 292+ *
293293 * @since 1.2
294 - *
 294+ *
295295 * @param array $config
296296 */
297297 public function setConfig( array $config ) {
298298 $defaultConfig = self::getDefaultConfig();
299 -
 299+
300300 foreach ( $config as $settingName => &$settingValue ) {
301301 if ( is_array( $defaultConfig[$settingName]['default'] ) && !is_array( $settingValue ) ) {
302302 $parts = explode( '| ', $settingValue );
303303 $settingValue = array();
304 -
 304+
305305 foreach ( $parts as $part ) {
306306 $part = trim( $part );
307 -
 307+
308308 if ( $part != '' ) {
309309 $settingValue[] = $part;
310310 }
311311 }
312312 }
313313 }
314 -
 314+
315315 $this->config = $config;
316 -
 316+
317317 $this->loadedConfig = count( $this->config ) > 0;
318318 }
319 -
 319+
320320 /**
321321 * Returns all set config properties.
322322 * Property name => property value
323 - *
 323+ *
324324 * @since 1.2
325 - *
 325+ *
326326 * @return array
327327 */
328328 public function getConfig() {
@@ -329,24 +329,24 @@
330330 if ( !is_null( $this->id ) ) {
331331 $this->config = self::getPropsFromDB( wfGetDB( DB_SLAVE ), $this->id );
332332 }
333 -
 333+
334334 $this->loadedConfig = true;
335335 }
336 -
 336+
337337 return $this->config;
338338 }
339 -
 339+
340340 /**
341341 * Returns the configuration, ready for merging with the
342342 * global configuration.
343 - *
 343+ *
344344 * @since 1.2
345 - *
 345+ *
346346 * @return arrayu
347347 */
348348 public function getConfigForGlobalMerge() {
349349 $config = $this->getConfig();
350 -
 350+
351351 foreach ( $config as $settingName => &$settingValue ) {
352352 switch ( $settingName ) {
353353 case 'licensesOwnWork':
@@ -357,49 +357,49 @@
358358 break;
359359 }
360360 }
361 -
 361+
362362 foreach ( self::getDefaultConfig() as $name => $data ) {
363363 if ( !array_key_exists( $name, $config ) ) {
364364 $config[$name] = $data['default'];
365365 }
366366 }
367 -
 367+
368368 $config['licensesOwnWork']['defaults'] = array( $config['defaultOwnWorkLicence'] );
369369 unset( $config['defaultOwnWorkLicence'] );
370 -
 370+
371371 return $config;
372372 }
373 -
 373+
374374 /**
375375 * Returns all config properties by merging the set ones with a list of default ones.
376376 * Property name => array( 'default' => $value, 'type' => HTMLForm input type )
377 - *
 377+ *
378378 * @since 1.2
379 - *
 379+ *
380380 * @return array
381381 */
382382 public function getAllConfig() {
383383 $setConfig = $this->getConfig();
384384 $config = array();
385 -
 385+
386386 foreach ( self::getDefaultConfig() as $name => $data ) {
387387 if ( array_key_exists( $name, $setConfig ) ) {
388388 $data['default'] = $setConfig[$name];
389389 }
390 -
 390+
391391 $config[$name] = $data;
392392 }
393 -
 393+
394394 return $config;
395395 }
396 -
 396+
397397 /**
398398 * Write the campaign to the DB.
399399 * If it's already there, it'll be updated, else it'll be inserted.
400 - *
 400+ *
401401 * @since 1.2
402 - *
403 - * @return boolean Success indicator
 402+ *
 403+ * @return boolean Success indicator
404404 */
405405 public function writeToDB() {
406406 if ( is_null( $this->id ) ) {
@@ -409,79 +409,82 @@
410410 return $this->updateInDB();
411411 }
412412 }
413 -
 413+
414414 /**
415415 * Insert the campaign into the DB.
416 - *
 416+ *
417417 * @since 1.2
418 - *
419 - * @return boolean Success indicator
 418+ *
 419+ * @return boolean Success indicator
420420 */
421421 protected function insertIntoDB() {
422422 $dbw = wfGetDB( DB_MASTER );
423 -
 423+
424424 $success = $dbw->insert(
425425 'uw_campaigns',
426426 array(
427427 'campaign_name' => $this->name,
428428 'campaign_enabled' => $this->isEnabled,
429429 ),
 430+ __METHOD__,
430431 array( 'campaign_id' => $this->id )
431432 );
432 -
 433+
433434 if ( $success ) {
434435 $this->id = $dbw->insertId();
435436 $success &= $this->writePropsToDB( $dbw );
436437 }
437 -
 438+
438439 return $success;
439440 }
440 -
 441+
441442 /**
442443 * Update the campaign in the DB.
443 - *
 444+ *
444445 * @since 1.2
445 - *
446 - * @return boolean Success indicator
 446+ *
 447+ * @return boolean Success indicator
447448 */
448449 protected function updateInDB() {
449450 $dbw = wfGetDB( DB_MASTER );
450 -
 451+
451452 $success = $dbw->update(
452453 'uw_campaigns',
453454 array(
454455 'campaign_name' => $this->name,
455456 'campaign_enabled' => $this->isEnabled,
456457 ),
457 - array( 'campaign_id' => $this->id )
 458+ array( 'campaign_id' => $this->id ),
 459+ __METHOD__
458460 );
459 -
 461+
460462 // Delete and insert instead of update.
461463 // This will not result into dead-data when config vars are removed.
462464 $success &= $dbw->delete(
463465 'uw_campaign_conf',
464 - array( 'cc_campaign_id' => $this->id )
 466+ array( 'cc_campaign_id' => $this->id ),
 467+ __METHOD__
465468 );
466 -
 469+
467470 $success &= $this->writePropsToDB( $dbw );
468 -
 471+
469472 return $success;
470473 }
471 -
 474+
472475 /**
473476 * Write (insert) the properties into the DB.
474 - *
 477+ *
475478 * @since 1.2
476 - *
 479+ *
477480 * @param Database $dbw
478 - *
479 - * @return boolean Success indicator
 481+ *
 482+ * @return boolean Success indicator
480483 */
481484 protected function writePropsToDB( DatabaseBase $dbw ) {
482485 $success = true;
483 -
 486+
484487 $dbw->begin();
485 -
 488+
486489 foreach ( $this->config as $prop => $value ) {
487490 $success &= $dbw->insert(
488491 'uw_campaign_conf',
@@ -489,66 +492,70 @@
490493 'cc_campaign_id' => $this->id,
491494 'cc_property' => $prop,
492495 'cc_value' => is_array( $value ) ? implode( '| ', $value ) : $value
493 - )
 496+ ),
 497+ __METHOD__
494498 );
495499 }
496 -
 500+
497501 $dbw->commit();
498 -
 502+
499503 return $success;
500504 }
501 -
 505+
502506 /**
503507 * Get the configuration properties from the DB.
504 - *
 508+ *
505509 * @since 1.2
506 - *
 510+ *
507511 * @param Database $dbr
508512 * @param integer $campaignId
509 - *
510 - * @return array
 513+ *
 514+ * @return array
511515 */
512516 protected static function getPropsFromDB( DatabaseBase $dbr, $campaignId ) {
513517 $config = array();
514 -
 518+
515519 $confProps = $dbr->select(
516520 'uw_campaign_conf',
517521 array( 'cc_property', 'cc_value' ),
518 - array( 'cc_campaign_id' => $campaignId )
 522+ array( 'cc_campaign_id' => $campaignId ),
 523+ __METHOD__
519524 );
520 -
 525+
521526 foreach ( $confProps as $confProp ) {
522527 $config[$confProp->cc_property] = $confProp->cc_value;
523528 }
524 -
 529+
525530 return $config;
526531 }
527 -
 532+
528533 /**
529534 * Delete the campaign from the DB (when present).
530 - *
 535+ *
531536 * @since 1.2
532 - *
533 - * @return boolean Success indicator
 537+ *
 538+ * @return boolean Success indicator
534539 */
535540 public function deleteFromDB() {
536541 if ( is_null( $this->id ) ) {
537542 return true;
538543 }
539 -
 544+
540545 $dbw = wfGetDB( DB_MASTER );
541 -
 546+
542547 $d1 = $dbw->delete(
543548 'uw_campaigns',
544 - array( 'campaign_id' => $this->id )
 549+ array( 'campaign_id' => $this->id ),
 550+ __METHOD__
545551 );
546 -
 552+
547553 $d2 = $dbw->delete(
548554 'uw_campaign_conf',
549 - array( 'cc_campaign_id' => $this->id )
 555+ array( 'cc_campaign_id' => $this->id ),
 556+ __METHOD__
550557 );
551 -
 558+
552559 return $d1 && $d2;
553560 }
554 -
 561+
555562 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90668Fix for r86722: pass the message 'dberrortext' unescaped to the output since ...ialex18:42, 23 June 2011

Status & tagging log