Index: trunk/extensions/Chemistry/SpecialChemicalsources.php |
— | — | @@ -1,11 +1,10 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * A MediaWiki extension that adds a Specialpage for Chemical sources. |
6 | 5 | * |
7 | 6 | * The i18n file is required for operation! |
8 | 7 | * 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) |
10 | 9 | * |
11 | 10 | * i18n is retrieved from ChemFunctions.i18n.php |
12 | 11 | * wfSpecialChemicalSources (adds the specialpage) |
— | — | @@ -31,19 +30,20 @@ |
32 | 31 | * You have to return a list which contains: $transParams['thestringtoreplaceinyourpage'] = 'withwhatitshouldbereplaced' |
33 | 32 | */ |
34 | 33 | |
35 | | -if (!defined('MEDIAWIKI')) die(); |
| 34 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
36 | 35 | |
37 | 36 | # Credentials. |
38 | 37 | $wgExtensionCredits['specialpage'][] = array( |
39 | 38 | 'path' => __FILE__, |
40 | 39 | 'name' => 'Special:Chemicalsources', |
41 | | - 'description' => '[[Special:Chemicalsources|Special page]] for Chemical sources', |
42 | 40 | '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', |
44 | 43 | ); |
45 | 44 | |
46 | | -$dir = dirname(__FILE__) . '/'; |
| 45 | +$dir = dirname( __FILE__ ) . '/'; |
47 | 46 | $wgAutoloadClasses['SpecialChemicalsources'] = $dir . 'SpecialChemicalsources_body.php'; |
48 | 47 | $wgExtensionMessagesFiles['SpecialChemicalsources'] = $dir . 'ChemFunctions.i18n.php'; |
49 | 48 | $wgExtensionAliasesFiles['ChemicalSources'] = $dir . 'ChemicalSources.alias.php'; |
50 | 49 | $wgSpecialPages['ChemicalSources'] = 'SpecialChemicalsources'; |
| 50 | +$wgSpecialPageGroups['ChemicalSources'] = 'wiki'; |
Index: trunk/extensions/Chemistry/ChemFunctions.i18n.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * MediaWiki Internationalisation file for ChemFunctions.php and SpecialChemicalsources.php. |
6 | 5 | * |
— | — | @@ -13,6 +12,7 @@ |
14 | 13 | $messages['en'] = array( |
15 | 14 | 'chemicalsources' => 'Chemical sources', |
16 | 15 | 'chemicalsource-desc' => 'Adds the tag <nowiki><chemform></nowiki>, for chemical formulae', |
| 16 | + 'chemicalsources-desc' => '[[Special:ChemicalSources|Special page]] for chemical sources', |
17 | 17 | 'chemFunctions_ListPage' => 'Chemical sources', |
18 | 18 | 'chemFunctions_DataList' => 'Below is a list of links to sites that may provide information about the chemical substance you are looking for.<br /><br /> |
19 | 19 | * <a href="http://webbook.nist.gov/cgi/cbook.cgi?ID=$MIXCASNameFormula&Units=SI">Compound $MIXCASNameFormula at NIST</a><br /> |
— | — | @@ -416,7 +416,7 @@ |
417 | 417 | 'chemicalsources' => 'Fontes químicas', |
418 | 418 | 'chemicalsource-desc' => 'Engada a etiqueta <nowiki><chemform></nowiki>, para fórmulas químicas', |
419 | 419 | '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 |
421 | 421 | href="http://webbook.nist.gov/cgi/cbook.cgi?ID=$MIXCASNameFormula&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 />', |
422 | 422 | 'chemFunctions_CAS' => 'número CAS', |
423 | 423 | 'chemFunctions_ATCCode' => 'Código ATC', |
Index: trunk/extensions/Chemistry/ChemFunctions.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * A MediaWiki extension that adds the following tags: |
6 | 5 | * <chemform>: for the formatting of chemical formulae. |
— | — | @@ -13,9 +12,9 @@ |
14 | 13 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
15 | 14 | */ |
16 | 15 | |
17 | | -if (!defined('MEDIAWIKI')) die(); |
| 16 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
18 | 17 | |
19 | | -$wgExtensionCredits['other'][] = array( |
| 18 | +$wgExtensionCredits['parserhook'][] = array( |
20 | 19 | 'name' => 'ChemFunctions', |
21 | 20 | 'descriptionmsg' => 'chemicalsource-desc', |
22 | 21 | 'author' => 'Dirk Beetstra', |
— | — | @@ -41,7 +40,7 @@ |
42 | 41 | * Written by Dirk Beetstra, Oct. 2, 2006. |
43 | 42 | */ |
44 | 43 | |
45 | | -$wgExtensionMessagesFiles['ChemFunctions'] = dirname(__FILE__) . '/ChemFunctions.i18n.php'; |
| 44 | +$wgExtensionMessagesFiles['ChemFunctions'] = dirname( __FILE__ ) . '/ChemFunctions.i18n.php'; |
46 | 45 | |
47 | 46 | $wgExtensionFunctions[] = "wfChemFormExtension"; |
48 | 47 | |
— | — | @@ -51,7 +50,6 @@ |
52 | 51 | } |
53 | 52 | |
54 | 53 | function RenderChemForm( $input, $argv ) { |
55 | | - |
56 | 54 | # add messages |
57 | 55 | wfLoadExtensionMessages( 'ChemFunctions' ); |
58 | 56 | |
— | — | @@ -63,42 +61,43 @@ |
64 | 62 | if ( isset( $argv["link"] ) ) |
65 | 63 | $link = $argv["link"]; |
66 | 64 | |
67 | | - if ( isset($argv["wikilink"] ) ) |
| 65 | + if ( isset( $argv["wikilink"] ) ) |
68 | 66 | $wikilink = $argv["wikilink"]; |
69 | 67 | |
70 | 68 | if ( isset( $argv["query"] ) ) |
71 | 69 | $searchfor = $argv["query"]; |
72 | 70 | |
73 | | - if (!$showthis) |
| 71 | + if ( !$showthis ) |
74 | 72 | $showthis = $searchfor; |
75 | 73 | |
76 | 74 | $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> |
81 | 79 | |
82 | 80 | $searchfor = htmlentities( Sanitizer::StripAllTags ( $searchfor ) ); |
83 | 81 | |
84 | | - if (! ( $showthis . $searchfor ) ) |
85 | | - return wfMsg('chemFunctions_ChemFormInputError'); |
| 82 | + if ( ! ( $showthis . $searchfor ) ) { |
| 83 | + return wfMsg( 'chemFunctions_ChemFormInputError' ); |
| 84 | + } |
86 | 85 | |
87 | 86 | if ( $link ) { |
88 | 87 | $title = Title::makeTitleSafe( NS_SPECIAL, 'Chemicalsources' ); |
89 | 88 | $output = "<a href=\"" . $title->getFullUrl() . "?Formula=" . $searchfor . "\">" . $showthis . "</a>"; |
90 | | - } elseif ( $wikilink) { |
| 89 | + } elseif ( $wikilink ) { |
91 | 90 | $title = Title::makeTitleSafe( NS_MAIN, $searchfor ); |
92 | 91 | |
93 | | - if ($title) { |
| 92 | + if ( $title ) { |
94 | 93 | $revision = Revision::newFromTitle( $title ); |
95 | 94 | |
96 | | - if ($revision ) { |
| 95 | + if ( $revision ) { |
97 | 96 | $output = "<a href=\"" . $title->getFullUrl() . "\">" . $showthis . "</a>"; |
98 | 97 | } else { |
99 | 98 | $output = "<a href=\"" . $title->getFullUrl() . "?action=edit\" class=\"new\">" . $showthis . "</a>"; |
100 | 99 | } |
101 | 100 | } else { |
102 | | - $output = wfMsg('chemFunctions_ChemFormInputError'); |
| 101 | + $output = wfMsg( 'chemFunctions_ChemFormInputError' ); |
103 | 102 | } |
104 | 103 | } else { |
105 | 104 | $output = $showthis; |
Index: trunk/extensions/Chemistry/SpecialChemicalsources_body.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | if ( ! defined( 'MEDIAWIKI' ) ) |
5 | 4 | die(); |
6 | 5 | |
— | — | @@ -23,7 +22,7 @@ |
24 | 23 | * containing the string as you want it displayed. |
25 | 24 | * So, if you have a parameter 'WhAtEvEr', you should have a 'YourPrefix_WhAtEvEr' with value 'Whatever' |
26 | 25 | */ |
27 | | - |
| 26 | + |
28 | 27 | /** |
29 | 28 | * This is a list of all the possible parameters supplied to Special:ChemicalSources |
30 | 29 | * Note: The names must be the same (also same case) as supplied in wgChemFunctions_Messages after the 'chemFunctions_' |
— | — | @@ -42,7 +41,7 @@ |
43 | 42 | * DrugBank = The DrugBank code for the chemical |
44 | 43 | * ECNumber = The EC Number for the compound |
45 | 44 | */ |
46 | | - |
| 45 | + |
47 | 46 | protected $wgChemFunctions_Prefix = "chemFunctions"; |
48 | 47 | protected $wgChemFunctions_Parameters = array ( |
49 | 48 | 'CAS', |
— | — | @@ -75,22 +74,21 @@ |
76 | 75 | $Params = $wgRequest->getValues(); |
77 | 76 | |
78 | 77 | $ParamsCheck = ""; |
79 | | - foreach ($this->Parameters as $key) { |
| 78 | + foreach ( $this->Parameters as $key ) { |
80 | 79 | if ( isset( $Params [$key] ) ) |
81 | 80 | $ParamsCheck .= $Params [$key]; |
82 | 81 | } |
83 | 82 | |
84 | | - if ($ParamsCheck) { |
85 | | - $transParams = $this->TransposeAndCheckParams($Params); |
86 | | - $this->OutputListPage($transParams); |
| 83 | + if ( $ParamsCheck ) { |
| 84 | + $transParams = $this->TransposeAndCheckParams( $Params ); |
| 85 | + $this->OutputListPage( $transParams ); |
87 | 86 | } else { |
88 | 87 | $Params = $this->getParams(); |
89 | 88 | } |
90 | 89 | } |
91 | 90 | |
92 | 91 | # Check the parameters supplied, make the mixed parameters, and put them into the transpose matrix. |
93 | | - |
94 | | - function TransposeAndCheckParams($Params) { |
| 92 | + function TransposeAndCheckParams( $Params ) { |
95 | 93 | if ( isset( $Params['CAS'] ) ) |
96 | 94 | $Params['CAS'] = preg_replace( '/[^0-9\-]/', "", $Params['CAS'] ); |
97 | 95 | else $Params['CAS'] = ''; |
— | — | @@ -134,35 +132,38 @@ |
135 | 133 | # Create some new from old ones |
136 | 134 | |
137 | 135 | $TEMPCASNAMEFORMULA = $Params["CAS"]; |
138 | | - if(empty ($TEMPCASNAMEFORMULA)){ |
| 136 | + if ( empty ( $TEMPCASNAMEFORMULA ) ) { |
139 | 137 | $TEMPCASNAMEFORMULA = $Params["Formula"]; |
140 | 138 | } |
141 | | - if(empty ($TEMPCASNAMEFORMULA)){ |
| 139 | + if ( empty ( $TEMPCASNAMEFORMULA ) ) { |
142 | 140 | $TEMPCASNAMEFORMULA = $Params["Name"]; |
143 | 141 | } |
144 | 142 | |
145 | 143 | $TEMPNAMEFORMULA = $Params["Name"]; |
146 | | - if(empty ($TEMPNAMEFORMULA)){ |
| 144 | + if ( empty ( $TEMPNAMEFORMULA ) ) { |
147 | 145 | $TEMPNAMEFORMULA = $Params["Formula"]; |
148 | 146 | } |
149 | 147 | |
150 | 148 | $TEMPCASFORMULA = $Params["CAS"]; |
151 | | - if(empty ($TEMPCASFORMULA)){ |
| 149 | + if ( empty ( $TEMPCASFORMULA ) ) { |
152 | 150 | $TEMPCASFORMULA = $Params["Formula"]; |
153 | 151 | } |
154 | 152 | |
155 | 153 | $TEMPCASNAME = $Params["CAS"]; |
156 | | - if(empty ($TEMPCASNAME)){ |
| 154 | + if ( empty ( $TEMPCASNAME ) ) { |
157 | 155 | $TEMPCASNAME = $Params["Name"]; |
158 | 156 | } |
159 | 157 | |
160 | 158 | # Put the parameters into the transpose array: |
161 | 159 | |
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 ) { |
167 | 168 | if ( isset( $Params[$key] ) ) { |
168 | 169 | $transParams["\$" . $key] = $Params[$key] ; |
169 | 170 | } else { |
— | — | @@ -172,60 +173,60 @@ |
173 | 174 | return $transParams; |
174 | 175 | } |
175 | 176 | |
176 | | - #Create the actual page |
177 | | - function OutputListPage($transParams) { |
| 177 | + # Create the actual page |
| 178 | + function OutputListPage( $transParams ) { |
178 | 179 | global $wgOut; |
179 | 180 | |
180 | 181 | # check all the parameters before we put them in the page |
181 | 182 | |
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 ) ) ); |
184 | 185 | } |
185 | 186 | |
186 | 187 | # First, see if we have a custom list setup |
187 | 188 | $bstitle = Title::makeTitleSafe( NS_PROJECT, wfMsg( $this->Prefix . '_ListPage' ) ); |
188 | | - if( $bstitle ) { |
| 189 | + if ( $bstitle ) { |
189 | 190 | $revision = Revision::newFromTitle( $bstitle ); |
190 | | - if( $revision ) { |
| 191 | + if ( $revision ) { |
191 | 192 | $bstext = $revision->getText(); |
192 | | - if( $bstext ) { |
193 | | - $bstext = strtr($bstext, $transParams); |
| 193 | + if ( $bstext ) { |
| 194 | + $bstext = strtr( $bstext, $transParams ); |
194 | 195 | $wgOut->addWikiText( $bstext ); |
195 | 196 | } |
196 | 197 | } else { |
197 | 198 | $bstext = wfMsg( $this->Prefix . '_DataList' ); |
198 | | - $bstext = strtr($bstext, $transParams); |
| 199 | + $bstext = strtr( $bstext, $transParams ); |
199 | 200 | $wgOut->addHTML( $bstext ); |
200 | 201 | } |
201 | 202 | } |
202 | 203 | } |
203 | 204 | |
204 | | - #If no parameters supplied, get them! |
| 205 | + # If no parameters supplied, get them! |
205 | 206 | function getParams() { |
206 | 207 | global $wgTitle, $wgOut; |
207 | | - if( !empty($wgTitle) ) { |
| 208 | + if ( !empty( $wgTitle ) ) { |
208 | 209 | $action = $wgTitle->escapeLocalUrl(); |
209 | 210 | $go = htmlspecialchars( wfMsg( "go" ) ); |
210 | 211 | |
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 ); |
215 | 216 | } |
216 | | - $wgOut->addHTML("</table>"); |
| 217 | + $wgOut->addHTML( "</table>" ); |
217 | 218 | } |
218 | 219 | } |
219 | 220 | |
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 ) { |
222 | 223 | global $wgOut; |
223 | 224 | $wgOut->addHTML ( wfMsg( $p ) . wfMsg( 'colon-separator' ) ); |
224 | | - $wgOut->addHTML("</td><td> |
| 225 | + $wgOut->addHTML( "</td><td> |
225 | 226 | <form action=\"$action\" method='post'> |
226 | 227 | <input name=\"$q\" id=\"$q\" /> |
227 | 228 | <input type='submit' value=\"$go\" /> |
228 | 229 | </form> |
229 | | - </td></tr>"); |
230 | | - $wgOut->addHTML("<tr><td>"); |
| 230 | + </td></tr>" ); |
| 231 | + $wgOut->addHTML( "<tr><td>" ); |
231 | 232 | } |
232 | 233 | } |