Skip to content
Browse files

Bugfix: Rewrote as parser function instead of tag function. Now works…

… with SMW facts
  • Loading branch information...
1 parent 779b6ab commit b681cab79993648a06e940dca4961d688727a809 @samuell committed Mar 25, 2014
Showing with 62 additions and 18 deletions.
  1. +7 −0 GeneIdConvert.i18n.php
  2. +48 −14 GeneIdConvert.php
  3. +7 −4 README.md
View
7 GeneIdConvert.i18n.php
@@ -0,0 +1,7 @@
+<?php
+
+$magicWords = array();
+
+$magicWords['en'] = array(
+ 'geneidconv' => array( 0, 'geneidconv' ),
+);
View
62 GeneIdConvert.php
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* Simple MediaWiki extension that converts from Ensembl Gene ID to
* desired target gene ID type, by using the CrossRef endpoint of the
@@ -21,7 +21,7 @@
*
* Example usage of the extension within a MediaWiki article:
*
- * <geneidconv to="EntrezGene">ENSG00000157764</gene>
+ * {{ #geneidconv: ENSG00000157764 | EntrezGene }}
*
* A few of the avaible options for the "to" parameter, is (as of
* writing this):
@@ -37,30 +37,65 @@
*
*/
-$wgHooks['ParserFirstCallInit'][] = 'wfGeneIdConvertParserInit';
+// Take credit for your work.
+$wgExtensionCredits['parserhook'][] = array(
+ // The full path and filename of the file. This allows MediaWiki
+ // to display the Subversion revision number on Special:Version.
+ 'path' => __FILE__,
+
+ // The name of the extension, which will appear on Special:Version.
+ 'name' => 'Gene ID Convert',
+
+ // A description of the extension, which will appear on Special:Version.
+ 'description' => 'Simple MediaWiki extension that converts from Ensembl Gene ID to desired target gene ID type',
+
+ // Alternatively, you can specify a message key for the description.
+ // 'descriptionmsg' => 'exampleextension-desc',
+
+ // The version of the extension, which will appear on Special:Version.
+ // This can be a number or a string.
+ 'version' => 1,
+
+ // Your name, which will appear on Special:Version.
+ 'author' => 'Samuel Lampa',
+
+ // The URL to a wiki page/web page with information about the extension,
+ // which will appear on Special:Version.
+ 'url' => 'https://www.mediawiki.org/wiki/Manual:Parser_functions',
+
+);
+
+// Specify the function that will initialize the parser function.
+$wgHooks['ParserFirstCallInit'][] = 'GeneIdConvertSetupParserFunction';
+
+// Allow translation of the parser function name
+$wgExtensionMessagesFiles['GeneIdConvert'] = __DIR__ . '/GeneIdConvert.i18n.php';
+
// Hook our callback function into the parser
-function wfGeneIdConvertParserInit( Parser $parser ) {
+function GeneIdConvertSetupParserFunction( &$parser ) {
// When the parser sees the <geneidconv> tag, it executes
- $parser->setHook( 'geneidconv', 'wfGeneIdConvRender' );
+ $parser->setFunctionHook( 'geneidconv', 'GeneIdConvertRenderParserFunction' );
// Always return true from this function. The return value does not denote
// success or otherwise have meaning - it just must always be true.
return true;
}
-// Execute
-function wfGeneIdConvRender( $srcGeneId, array $args, Parser $parser, PPFrame $frame ) {
+// function geneIDConvert( $srcGeneId, array $args, Parser $parser, PPFrame $frame ) {
+function GeneIdConvertRenderParserFunction( $parser, $srcGeneId = '', $toFormat = '' ) {
+ if ( $srcGeneId === '' ) {
+ return 'ERROR:Field_1_gene_id_missing';
+ }
+ if ( $toFormat === '' ) {
+ return 'ERROR:Field_2_target_format_missing';
+ }
// Disable cache, at least for debugging purposes
$parser->disableCache();
- // Parse any wiki text in the content of the tag:
- $srcGeneId = $parser->recursiveTagParse( $srcGeneId, $frame );
-
// Set some variables
$ensemblRestBaseUrl = "http://beta.rest.ensembl.org/xrefs/id"; // Without trailing slash
- $targetId = "";
- $toFormat = $args['to'];
+ $targetId = '';
// Construct the Query URL
$queryUrl = $ensemblRestBaseUrl . '/' . $srcGeneId . '?content-type=application/json';
@@ -87,8 +122,7 @@ function wfGeneIdConvRender( $srcGeneId, array $args, Parser $parser, PPFrame $f
} else {
$targetId = 'N/A';
}
- // echo "TargetId: [$targetId]";
- return (string)$targetId;
+ return $targetId;
}
function wfGetRemoteData( $url ) {
View
11 README.md
@@ -3,7 +3,7 @@ desired target gene ID type, by using the CrossRef endpoint of the
new Ensembl REST API.
Author: Samuel Lampa - samuel.lampa@gmail.com
-Date: 2013-05-31
+Created Date: 2013-05-31
More info on the REST API Here:
@@ -24,11 +24,14 @@ require_once("$IP/extensions/GeneIdConvert/GeneIdConvert.php");
- Example usage of the extension within a MediaWiki article:
````
-<geneidconv to="EntrezGene">ENSG00000157764</gene>
+{{ #geneidconv: ENSG00000157764 | EntrezGene }}
````
- A few of the avaible options for the "to" parameter, is (as of
- writing this):
+... where the first field is the source ID (in Ensembl ID format)
+and the second field is the target id type.
+
+A few of the avaible options for the "to" parameter, is (as of
+writing this) are the following:
- OTTG
- ArrayExpress

0 comments on commit b681cab

Please sign in to comment.
Something went wrong with that request. Please try again.