r65645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65644‎ | r65645 | r65646 >
Date:23:09, 28 April 2010
Author:siebrand
Status:deferred
Tags:
Comment:
* stylize.php, trailing whitespace removed, indentation updated
* i18n for extension description message of special page
* parserhook extension type changed from other to parserhook
* added special page in special page group wiki
Modified paths:
  • /trunk/extensions/Chemistry/ChemFunctions.i18n.php (modified) (history)
  • /trunk/extensions/Chemistry/ChemFunctions.php (modified) (history)
  • /trunk/extensions/Chemistry/SpecialChemicalsources.php (modified) (history)
  • /trunk/extensions/Chemistry/SpecialChemicalsources_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Chemistry/SpecialChemicalsources.php
@@ -1,11 +1,10 @@
22 <?php
3 -
43 /**
54 * A MediaWiki extension that adds a Specialpage for Chemical sources.
65 *
76 * The i18n file is required for operation!
87 * Installation: copy this file and ChemFunctions.i18n.php into the extensions directory
9 - * and add 'require_once( "$IP/extensions/SpecialChemicalsources.php" );' to localsettings.php (using the correct path)
 8+ * and add 'require_once( "$IP/extensions/SpecialChemicalsources.php" );' to LocalSettings.php (using the correct path)
109 *
1110 * i18n is retrieved from ChemFunctions.i18n.php
1211 * wfSpecialChemicalSources (adds the specialpage)
@@ -31,19 +30,20 @@
3231 * You have to return a list which contains: $transParams['thestringtoreplaceinyourpage'] = 'withwhatitshouldbereplaced'
3332 */
3433
35 -if (!defined('MEDIAWIKI')) die();
 34+if ( !defined( 'MEDIAWIKI' ) ) die();
3635
3736 # Credentials.
3837 $wgExtensionCredits['specialpage'][] = array(
3938 'path' => __FILE__,
4039 'name' => 'Special:Chemicalsources',
41 - 'description' => '[[Special:Chemicalsources|Special page]] for Chemical sources',
4240 'author' => 'Dirk Beetstra',
43 - 'url' => 'http://www.mediawiki.org/wiki/Extension:Chemistry/ChemFunctions.php'
 41+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Chemistry/ChemFunctions.php',
 42+ 'descriptionmsg' => 'chemicalsources-desc',
4443 );
4544
46 -$dir = dirname(__FILE__) . '/';
 45+$dir = dirname( __FILE__ ) . '/';
4746 $wgAutoloadClasses['SpecialChemicalsources'] = $dir . 'SpecialChemicalsources_body.php';
4847 $wgExtensionMessagesFiles['SpecialChemicalsources'] = $dir . 'ChemFunctions.i18n.php';
4948 $wgExtensionAliasesFiles['ChemicalSources'] = $dir . 'ChemicalSources.alias.php';
5049 $wgSpecialPages['ChemicalSources'] = 'SpecialChemicalsources';
 50+$wgSpecialPageGroups['ChemicalSources'] = 'wiki';
Index: trunk/extensions/Chemistry/ChemFunctions.i18n.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * MediaWiki Internationalisation file for ChemFunctions.php and SpecialChemicalsources.php.
65 *
@@ -13,6 +12,7 @@
1413 $messages['en'] = array(
1514 'chemicalsources' => 'Chemical sources',
1615 'chemicalsource-desc' => 'Adds the tag <nowiki><chemform></nowiki>, for chemical formulae',
 16+ 'chemicalsources-desc' => '[[Special:ChemicalSources|Special page]] for chemical sources',
1717 'chemFunctions_ListPage' => 'Chemical sources',
1818 'chemFunctions_DataList' => 'Below is a list of links to sites that may provide information about the chemical substance you are looking for.<br /><br />
1919 * <a href="http://webbook.nist.gov/cgi/cbook.cgi?ID=$MIXCASNameFormula&amp;Units=SI">Compound $MIXCASNameFormula at NIST</a><br />
@@ -416,7 +416,7 @@
417417 'chemicalsources' => 'Fontes químicas',
418418 'chemicalsource-desc' => 'Engada a etiqueta <nowiki><chemform></nowiki>, para fórmulas químicas',
419419 'chemFunctions_ListPage' => 'Fontes químicas',
420 - 'chemFunctions_DataList' => 'Embaixo hai unha lista das ligazóns aos sitios que poden proporcionar información acerca da sustancia química que procura.<br /><br /> * <a
 420+ 'chemFunctions_DataList' => 'Embaixo hai unha lista das ligazóns aos sitios que poden proporcionar información acerca da sustancia química que procura.<br /><br /> * <a
421421 href="http://webbook.nist.gov/cgi/cbook.cgi?ID=$MIXCASNameFormula&amp;Units=SI">Composto $MIXCASNameFormula en NIST</a><br /> * <a href="http://ptcl.chem.ox.ac.uk/MSDS/">MSDS na Universidade de Oxford (UK) (non consultábel)</a><br />',
422422 'chemFunctions_CAS' => 'número CAS',
423423 'chemFunctions_ATCCode' => 'Código ATC',
Index: trunk/extensions/Chemistry/ChemFunctions.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * A MediaWiki extension that adds the following tags:
65 * <chemform>: for the formatting of chemical formulae.
@@ -13,9 +12,9 @@
1413 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1514 */
1615
17 -if (!defined('MEDIAWIKI')) die();
 16+if ( !defined( 'MEDIAWIKI' ) ) die();
1817
19 -$wgExtensionCredits['other'][] = array(
 18+$wgExtensionCredits['parserhook'][] = array(
2019 'name' => 'ChemFunctions',
2120 'descriptionmsg' => 'chemicalsource-desc',
2221 'author' => 'Dirk Beetstra',
@@ -41,7 +40,7 @@
4241 * Written by Dirk Beetstra, Oct. 2, 2006.
4342 */
4443
45 -$wgExtensionMessagesFiles['ChemFunctions'] = dirname(__FILE__) . '/ChemFunctions.i18n.php';
 44+$wgExtensionMessagesFiles['ChemFunctions'] = dirname( __FILE__ ) . '/ChemFunctions.i18n.php';
4645
4746 $wgExtensionFunctions[] = "wfChemFormExtension";
4847
@@ -51,7 +50,6 @@
5251 }
5352
5453 function RenderChemForm( $input, $argv ) {
55 -
5654 # add messages
5755 wfLoadExtensionMessages( 'ChemFunctions' );
5856
@@ -63,42 +61,43 @@
6462 if ( isset( $argv["link"] ) )
6563 $link = $argv["link"];
6664
67 - if ( isset($argv["wikilink"] ) )
 65+ if ( isset( $argv["wikilink"] ) )
6866 $wikilink = $argv["wikilink"];
6967
7068 if ( isset( $argv["query"] ) )
7169 $searchfor = $argv["query"];
7270
73 - if (!$showthis)
 71+ if ( !$showthis )
7472 $showthis = $searchfor;
7573
7674 $showthis = htmlentities( Sanitizer::StripAllTags ( $showthis ) ); # tagstripping
77 - $showthis = preg_replace("/[0-9]+/", "<sub>$0</sub>", $showthis); # All numbers down
78 - $showthis = preg_replace("/[\+\-]/", "<sup>$0</sup>", $showthis); # + and - up
79 - $showthis = preg_replace("/<\/sub><sup>/", "", $showthis); # </sub><sup> should not occur
80 - $showthis = preg_replace("/<sub>([0-9\+\-]+)<\/sup>/", "<sup>$1</sup>", $showthis); # and <sub>whatever</sup> to <sup>..</sup>
 75+ $showthis = preg_replace( "/[0-9]+/", "<sub>$0</sub>", $showthis ); # All numbers down
 76+ $showthis = preg_replace( "/[\+\-]/", "<sup>$0</sup>", $showthis ); # + and - up
 77+ $showthis = preg_replace( "/<\/sub><sup>/", "", $showthis ); # </sub><sup> should not occur
 78+ $showthis = preg_replace( "/<sub>([0-9\+\-]+)<\/sup>/", "<sup>$1</sup>", $showthis ); # and <sub>whatever</sup> to <sup>..</sup>
8179
8280 $searchfor = htmlentities( Sanitizer::StripAllTags ( $searchfor ) );
8381
84 - if (! ( $showthis . $searchfor ) )
85 - return wfMsg('chemFunctions_ChemFormInputError');
 82+ if ( ! ( $showthis . $searchfor ) ) {
 83+ return wfMsg( 'chemFunctions_ChemFormInputError' );
 84+ }
8685
8786 if ( $link ) {
8887 $title = Title::makeTitleSafe( NS_SPECIAL, 'Chemicalsources' );
8988 $output = "<a href=\"" . $title->getFullUrl() . "?Formula=" . $searchfor . "\">" . $showthis . "</a>";
90 - } elseif ( $wikilink) {
 89+ } elseif ( $wikilink ) {
9190 $title = Title::makeTitleSafe( NS_MAIN, $searchfor );
9291
93 - if ($title) {
 92+ if ( $title ) {
9493 $revision = Revision::newFromTitle( $title );
9594
96 - if ($revision ) {
 95+ if ( $revision ) {
9796 $output = "<a href=\"" . $title->getFullUrl() . "\">" . $showthis . "</a>";
9897 } else {
9998 $output = "<a href=\"" . $title->getFullUrl() . "?action=edit\" class=\"new\">" . $showthis . "</a>";
10099 }
101100 } else {
102 - $output = wfMsg('chemFunctions_ChemFormInputError');
 101+ $output = wfMsg( 'chemFunctions_ChemFormInputError' );
103102 }
104103 } else {
105104 $output = $showthis;
Index: trunk/extensions/Chemistry/SpecialChemicalsources_body.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 if ( ! defined( 'MEDIAWIKI' ) )
54 die();
65
@@ -23,7 +22,7 @@
2423 * containing the string as you want it displayed.
2524 * So, if you have a parameter 'WhAtEvEr', you should have a 'YourPrefix_WhAtEvEr' with value 'Whatever'
2625 */
27 -
 26+
2827 /**
2928 * This is a list of all the possible parameters supplied to Special:ChemicalSources
3029 * Note: The names must be the same (also same case) as supplied in wgChemFunctions_Messages after the 'chemFunctions_'
@@ -42,7 +41,7 @@
4342 * DrugBank = The DrugBank code for the chemical
4443 * ECNumber = The EC Number for the compound
4544 */
46 -
 45+
4746 protected $wgChemFunctions_Prefix = "chemFunctions";
4847 protected $wgChemFunctions_Parameters = array (
4948 'CAS',
@@ -75,22 +74,21 @@
7675 $Params = $wgRequest->getValues();
7776
7877 $ParamsCheck = "";
79 - foreach ($this->Parameters as $key) {
 78+ foreach ( $this->Parameters as $key ) {
8079 if ( isset( $Params [$key] ) )
8180 $ParamsCheck .= $Params [$key];
8281 }
8382
84 - if ($ParamsCheck) {
85 - $transParams = $this->TransposeAndCheckParams($Params);
86 - $this->OutputListPage($transParams);
 83+ if ( $ParamsCheck ) {
 84+ $transParams = $this->TransposeAndCheckParams( $Params );
 85+ $this->OutputListPage( $transParams );
8786 } else {
8887 $Params = $this->getParams();
8988 }
9089 }
9190
9291 # Check the parameters supplied, make the mixed parameters, and put them into the transpose matrix.
93 -
94 - function TransposeAndCheckParams($Params) {
 92+ function TransposeAndCheckParams( $Params ) {
9593 if ( isset( $Params['CAS'] ) )
9694 $Params['CAS'] = preg_replace( '/[^0-9\-]/', "", $Params['CAS'] );
9795 else $Params['CAS'] = '';
@@ -134,35 +132,38 @@
135133 # Create some new from old ones
136134
137135 $TEMPCASNAMEFORMULA = $Params["CAS"];
138 - if(empty ($TEMPCASNAMEFORMULA)){
 136+ if ( empty ( $TEMPCASNAMEFORMULA ) ) {
139137 $TEMPCASNAMEFORMULA = $Params["Formula"];
140138 }
141 - if(empty ($TEMPCASNAMEFORMULA)){
 139+ if ( empty ( $TEMPCASNAMEFORMULA ) ) {
142140 $TEMPCASNAMEFORMULA = $Params["Name"];
143141 }
144142
145143 $TEMPNAMEFORMULA = $Params["Name"];
146 - if(empty ($TEMPNAMEFORMULA)){
 144+ if ( empty ( $TEMPNAMEFORMULA ) ) {
147145 $TEMPNAMEFORMULA = $Params["Formula"];
148146 }
149147
150148 $TEMPCASFORMULA = $Params["CAS"];
151 - if(empty ($TEMPCASFORMULA)){
 149+ if ( empty ( $TEMPCASFORMULA ) ) {
152150 $TEMPCASFORMULA = $Params["Formula"];
153151 }
154152
155153 $TEMPCASNAME = $Params["CAS"];
156 - if(empty ($TEMPCASNAME)){
 154+ if ( empty ( $TEMPCASNAME ) ) {
157155 $TEMPCASNAME = $Params["Name"];
158156 }
159157
160158 # Put the parameters into the transpose array:
161159
162 - $transParams = array("\$MIXCASNameFormula" => $TEMPCASNAMEFORMULA,
163 - "\$MIXCASName" => $TEMPCASNAME,
164 - "\$MIXCASFormula" => $TEMPCASFORMULA,
165 - "\$MIXNameFormula" => $TEMPNAMEFORMULA);
166 - foreach ($this->Parameters as $key) {
 160+ $transParams = array(
 161+ "\$MIXCASNameFormula" => $TEMPCASNAMEFORMULA,
 162+ "\$MIXCASName" => $TEMPCASNAME,
 163+ "\$MIXCASFormula" => $TEMPCASFORMULA,
 164+ "\$MIXNameFormula" => $TEMPNAMEFORMULA
 165+ );
 166+
 167+ foreach ( $this->Parameters as $key ) {
167168 if ( isset( $Params[$key] ) ) {
168169 $transParams["\$" . $key] = $Params[$key] ;
169170 } else {
@@ -172,60 +173,60 @@
173174 return $transParams;
174175 }
175176
176 - #Create the actual page
177 - function OutputListPage($transParams) {
 177+ # Create the actual page
 178+ function OutputListPage( $transParams ) {
178179 global $wgOut;
179180
180181 # check all the parameters before we put them in the page
181182
182 - foreach ($transParams as $key => $value) {
183 - $transParams[$key] = wfUrlEncode( htmlentities( preg_replace( "/\<.*?\>/","", $value) ) );
 183+ foreach ( $transParams as $key => $value ) {
 184+ $transParams[$key] = wfUrlEncode( htmlentities( preg_replace( "/\<.*?\>/", "", $value ) ) );
184185 }
185186
186187 # First, see if we have a custom list setup
187188 $bstitle = Title::makeTitleSafe( NS_PROJECT, wfMsg( $this->Prefix . '_ListPage' ) );
188 - if( $bstitle ) {
 189+ if ( $bstitle ) {
189190 $revision = Revision::newFromTitle( $bstitle );
190 - if( $revision ) {
 191+ if ( $revision ) {
191192 $bstext = $revision->getText();
192 - if( $bstext ) {
193 - $bstext = strtr($bstext, $transParams);
 193+ if ( $bstext ) {
 194+ $bstext = strtr( $bstext, $transParams );
194195 $wgOut->addWikiText( $bstext );
195196 }
196197 } else {
197198 $bstext = wfMsg( $this->Prefix . '_DataList' );
198 - $bstext = strtr($bstext, $transParams);
 199+ $bstext = strtr( $bstext, $transParams );
199200 $wgOut->addHTML( $bstext );
200201 }
201202 }
202203 }
203204
204 - #If no parameters supplied, get them!
 205+ # If no parameters supplied, get them!
205206 function getParams() {
206207 global $wgTitle, $wgOut;
207 - if( !empty($wgTitle) ) {
 208+ if ( !empty( $wgTitle ) ) {
208209 $action = $wgTitle->escapeLocalUrl();
209210 $go = htmlspecialchars( wfMsg( "go" ) );
210211
211 - $wgOut->addWikitext ( wfMsg($this->Prefix . '_SearchExplanation'));
212 - $wgOut->addHTML("<table><tr><td>");
213 - foreach ($this->Parameters as $key) {
214 - $this->GetParam_Row($this->Prefix . "_" . $key, $key, $action, $go);
 212+ $wgOut->addWikitext ( wfMsg( $this->Prefix . '_SearchExplanation' ) );
 213+ $wgOut->addHTML( "<table><tr><td>" );
 214+ foreach ( $this->Parameters as $key ) {
 215+ $this->GetParam_Row( $this->Prefix . "_" . $key, $key, $action, $go );
215216 }
216 - $wgOut->addHTML("</table>");
 217+ $wgOut->addHTML( "</table>" );
217218 }
218219 }
219220
220 - #Creates a table row
221 - function GetParam_Row($p, $q, $action, $go) {
 221+ # Creates a table row
 222+ function GetParam_Row( $p, $q, $action, $go ) {
222223 global $wgOut;
223224 $wgOut->addHTML ( wfMsg( $p ) . wfMsg( 'colon-separator' ) );
224 - $wgOut->addHTML("</td><td>
 225+ $wgOut->addHTML( "</td><td>
225226 <form action=\"$action\" method='post'>
226227 <input name=\"$q\" id=\"$q\" />
227228 <input type='submit' value=\"$go\" />
228229 </form>
229 - </td></tr>");
230 - $wgOut->addHTML("<tr><td>");
 230+ </td></tr>" );
 231+ $wgOut->addHTML( "<tr><td>" );
231232 }
232233 }

Status & tagging log