r95037 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95036‎ | r95037 | r95038 >
Date:20:03, 19 August 2011
Author:jeroendedauw
Status:ok (Comments)
Tags:
Comment:
fix issue with obtaining messages from config pages
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.config.php (modified) (history)
  • /trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php (modified) (history)
  • /trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/UploadWizard.config.php
@@ -54,7 +54,7 @@
5555
5656 // Page on which the text to display with the id field is stored.
5757 // Overrides idFieldLabel when set. $1 is replaced by the language code.
58 - 'idFieldLabelPage' => false,
 58+ 'idFieldLabelPage' => '',
5959
6060 // 'licenses' is a list of licenses you could possibly use elsewhere, for instance in
6161 // licensesOwnWork or licensesThirdParty.
Index: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php
@@ -364,39 +364,10 @@
365365 $config['licensesOwnWork']['defaults'] = array( $config['defaultOwnWorkLicence'] );
366366 unset( $config['defaultOwnWorkLicence'] );
367367
368 - $config['idFieldLabelPage'] = $this->getPageContent( $config['idFieldLabelPage'] );
369 - $config['headerLabelPage'] = $this->getPageContent( $config['headerLabelPage'] );
370 -
371368 return $config;
372369 }
373370
374371 /**
375 - * Gets content of the specified page, or false if there is no such page.
376 - * '$1' in $pageName is replaced by the code of the current language.
377 - *
378 - * @since 1.2
379 - *
380 - * @param string $pageName
381 - *
382 - * @return string|false
383 - */
384 - protected function getPageContent( $pageName ) {
385 - $content = false;
386 -
387 - if ( trim( $pageName ) != '' ) {
388 - global $wgLang;
389 - $page = Title::newFromText( str_replace( '$1', $wgLang->getCode(), $pageName ) );
390 -
391 - if ( !is_null( $page ) && $page->exists() ) {
392 - $article = new Article( $page );
393 - $content = $article->getContent();
394 - }
395 - }
396 -
397 - return $content;
398 - }
399 -
400 - /**
401372 * Returns all config properties by merging the set ones with a list of default ones.
402373 * Property name => array( 'default' => $value, 'type' => HTMLForm input type )
403374 *
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php
@@ -132,10 +132,17 @@
133133 public function addJsVars( $subPage ) {
134134 global $wgOut, $wgSitename;
135135
 136+ $config = UploadWizardConfig::getConfig( $this->campaign );
 137+
 138+ $labelPageContent = $this->getPageContent( $config['idFieldLabelPage'] );
 139+ if ( $labelPageContent !== false ) {
 140+ $config['idFieldLabel'] = $labelPageContent;
 141+ }
 142+
136143 $wgOut->addScript(
137144 Skin::makeVariablesScript(
138145 array(
139 - 'UploadWizardConfig' => UploadWizardConfig::getConfig( $this->campaign )
 146+ 'UploadWizardConfig' => $config
140147 ) +
141148 // Site name is a true global not specific to Upload Wizard
142149 array(
@@ -143,8 +150,33 @@
144151 )
145152 )
146153 );
147 -
148154 }
 155+
 156+ /**
 157+ * Gets content of the specified page, or false if there is no such page.
 158+ * '$1' in $pageName is replaced by the code of the current language.
 159+ *
 160+ * @since 1.2
 161+ *
 162+ * @param string $pageName
 163+ *
 164+ * @return string|false
 165+ */
 166+ protected function getPageContent( $pageName ) {
 167+ $content = false;
 168+
 169+ if ( trim( $pageName ) != '' ) {
 170+ global $wgLang;
 171+ $page = Title::newFromText( str_replace( '$1', $wgLang->getCode(), $pageName ) );
 172+
 173+ if ( !is_null( $page ) && $page->exists() ) {
 174+ $article = new Article( $page );
 175+ $content = $article->getContent();
 176+ }
 177+ }
 178+
 179+ return $content;
 180+ }
149181
150182 /**
151183 * Check if anyone can upload (or if other sitewide config prevents this)
@@ -212,9 +244,10 @@
213245
214246 $globalConf = UploadWizardConfig::getConfig( $this->campaign );
215247
216 - if ( $globalConf['headerLabelPage'] !== false ) {
 248+ $headerContent = $this->getPageContent( $globalConf['headerLabelPage'] );
 249+ if ( $headerContent !== false ) {
217250 global $wgOut;
218 - $wgOut->addWikiText( $globalConf['headerLabelPage'] );
 251+ $wgOut->addWikiText( $headerContent );
219252 }
220253
221254 if ( array_key_exists( 'fallbackToAltUploadForm', $globalConf )
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
@@ -180,15 +180,8 @@
181181 var idFieldId = "idField" + ( _this.upload.index ).toString();
182182 _this.idFieldInput = $j( '<input type="text" id="' + idFieldId + '" name="' + idFieldId + '" class="mwe-idfield" maxlength="15"/>' );
183183
184 - if ( mw.UploadWizard.config.idFieldLabelPage !== false ) {
185 - var label = mw.UploadWizard.config.idFieldLabelPage;
186 - }
187 - else {
188 - var label = mw.UploadWizard.config.idFieldLabel;
189 - }
190 -
191184 _this.$form.append(
192 - $j( '<div class="mwe-upwiz-details-fieldname"></div>' ).text( label ),
 185+ $j( '<div class="mwe-upwiz-details-fieldname"></div>' ).text( mw.UploadWizard.config.idFieldLabel ),
193186 $j( '<div class="mwe-id-field"></div>' ).append( _this.idFieldInput )
194187 );
195188 }

Comments

#Comment by NeilK (talk | contribs)   13:50, 22 August 2011

Not sure what your plan for errors here is -- if the Article doesn't exist will we just get loud exceptions?

#Comment by NeilK (talk | contribs)   14:36, 22 August 2011

I tried this and it just falls back to the generic message. Okay, that's acceptable.

Status & tagging log