Extension:Astro
Astro Release status: unknown |
|
---|---|
Implementation | Tag |
Description | |
License | No license specified |
Download | See below |
Check usage (experimental) |
The Astro extension provides capabilities to parse Astronomical Equatorial coordinates and pass results into an article.
Contents |
[edit] Install
Create a file called 'astro_extension.php' in your extensions/
directory, and add the following code:
[edit] Code
<?php # Astro Extension # Extract astronomical coordinates from astro_params http request's parameter. # # Example Code # # <astro>{ra_hour}<sup>h</sup> {ra_min}<sup>m</sup> {ra_sec}<sup>s</sup> {dec_deg}° {dec_min}′ {dec_sec}″</astro> # $wgExtensionFunctions[] = "wfAstroExtension"; $wgExtensionCredits['parserhook'][] = array( 'name' => 'Astro', 'author' => 'Friendlystar', 'description' => 'adds <astro> tag, for astronomical coordinates insertion ', 'url' => 'http://www.mediawiki.org/wiki/Extension:Astro' ); /* DO NOT EDIT BEYOND THIS LINE */ function wfAstroExtension() { global $wgParser; $wgParser->setHook( "astro", "astro" ); $wgParser->setHook( "astro_ra", "astro_ra" ); $wgParser->setHook( "astro_dec", "astro_dec" ); } # The callback function for converting the input text to HTML output function astro($input) { global $wgRequest, $wgOut; #$input = $wgOut->parse($input, false); #return $input; # /* #new method to parse: http://meta.wikimedia.org/wiki/MediaWiki_extensions_FAQ $localParser = new Parser(); $output = $localParser->parse("<big>$input</big>", $parser->mTitle, $parser->mOptions); $text = $output->getText(); */ $title = $wgRequest->getVal( 'title', false ); $mTitle = Title::makeTitle( NS_MAIN, $title ); $coor = $wgRequest->getVal( 'astro_params', false ); if ($coor) { $p = new astro_coord( $coor ); if ($p->error) { return $p->error; } else { $search = array( "{ra}", "{ra_hour}", "{ra_min}", "{ra_sec}", "{ra-in-deg}", "{dec}", "{dec_deg}", "{dec_min}", "{dec_sec}", "{dec_deg_url}", "{dec_deg_html}", "{angle}", "{angle-in-deg}", "{view}", "{box}", "{box_size}", "{box_width}", "{box_height}", "{box_color}", "{name}" ); $replace = array( $p->ra, $p->ra_hour, $p->ra_min, $p->ra_sec, $p->ra*15, $p->dec, $p->dec_deg, $p->dec_min, $p->dec_sec, str_replace( '+', '%2B', $p->dec_deg), str_replace( '-', '−', $p->dec_deg), $p->angle, $p->angle/60, $wgRequest->getVal( 'view', '' ), $wgRequest->getVal( 'astro_pointer', '' ), $wgRequest->getVal( 'astro_pointer_size', '' ), $wgRequest->getVal( 'astro_pointer_width', '' ), $wgRequest->getVal( 'astro_pointer_height', '' ), $wgRequest->getVal( 'astro_pointer_color', '' ), $p->name ); #return $wgParser->parse(str_replace( $search, $replace, $input ), $mTitle, ParserOptions::newFromUser($wgUser), false, false)->getText(); return str_replace( $search, $replace, $input ); } } else { return "(Undefined)"; } /**/ } # The callback function for converting the input text to HTML output function astro_ra($input) { global $wgRequest; $coor = $wgRequest->getVal( 'astro_params', false ); if ($coor) { $p = new astro_param( $coor, $title ); return $p->ra; } return $text; } # The callback function for converting the input text to HTML output function astro_dec($input) { global $wgRequest; $coor = $wgRequest->getVal( 'astro_params', false ); if ($coor) { $p = new astro_param( $coor, $title ); return $p->dec; } return $text; } /** * Parse astro parameters */ class astro_coord { var $ra; var $dec; var $ra_hour; var $ra_min; var $ra_sec; var $dec_deg; var $dec_min; var $dec_sec; var $angle; var $name; var $pieces; var $error; var $coor; var $title; /** * Constructor: * Read coordinates, and if there is a range, read the range */ function astro_coord( $param ) { $this->pieces = explode(" ", str_replace( ' ', ' +', str_replace( '_', ' ', $param ) )); if ($i = strpos($this->pieces[0],';')) { /* ra;dec (two values seperated by a semicolon) */ $this->ra = substr($this->pieces[0],0,$i); $this->dec = substr($this->pieces[0],$i+1); array_shift($this->pieces); $this->angle = array_shift($this->pieces); $this->name = array_shift($this->pieces); $this->dec = str_replace( '−', '-', str_replace( '\u2212', '-', $this->dec ) ); $this->ra_hour = floor($this->ra); $this->ra_min = floor(($this->ra-$this->ra_hour)*60); $this->ra_sec = round((($this->ra-$this->ra_hour)*60-$this->ra_min)*60*10000)/10000; $decfactor = 1.0 ; if (strpos($this->dec,'-')!==false) { $decfactor = -1.0 ; $this->dec = -$this->dec; } $dec_int = floor($this->dec); $this->dec_deg = ($decfactor==1.0?'+':'-').$dec_int; $this->dec_min = floor(($this->dec-$dec_int)*60); $this->dec_sec = round((($this->dec-$dec_int)*60-$this->dec_min)*60*10000)/10000; } else { $this->ra_hour = array_shift($this->pieces); $this->ra_min = array_shift($this->pieces); $this->ra_sec = array_shift($this->pieces); $this->dec_deg = array_shift($this->pieces); $this->dec_min = array_shift($this->pieces); $this->dec_sec = array_shift($this->pieces); $this->angle = array_shift($this->pieces); $this->name = array_shift($this->pieces); $decfactor = 1.0 ; $this->dec_deg = str_replace( '−', '-', str_replace( '\u2212', '-', $this->dec_deg ) ); if (strpos($this->dec_deg,'-')!==false) { $decfactor = -1.0 ; } $this->ra = $this->ra_hour + $this->ra_min/60.0 + $this->ra_sec/3600.0; $this->dec = $this->dec_deg + $decfactor*($this->dec_min/60.0 + $this->dec_sec/3600.0); if (strpos($this->dec_deg,'-')===false && strpos($this->dec_deg,'+')===false) { $this->dec_deg = '+' . $this->dec_deg; } } if ($this->ra > 24 or $this->ra < 0 or $this->dec > 90 or $this->dec < -90 or $ra_min > 60 or $ra_min < 0 or $dec_min > 60 or $dec_min < 0 or $ra_sec > 60 or $ra_sec < 0 or $dec_sec > 60 or $dec_sec < 0) { $this->error = "Out of range"; } } }
[edit] LocalSettings changes
Then simply add the following line to the end of your LocalSettings.php
file:
include("extensions/astro_extension.php");
You also have to make sure the page with extension is not cached. One of the ways to turn off cache is to add line in your LocalSettings.php
file:
$wgCachePages = false;
and you are ready to go! Go to the sandbox and see if it works!
[edit] Usage
Basic syntax for embedding data in article, as detailed in the code:
<astro>{ra_hour}h {ra_min}m {ra_sec}s {dec_deg_html}° {dec_min}′ {dec_sec}″</astro>
For details go to http://wikisky.org/w/index.php?title=Astro_extension&astro_params=12_22_54.9_+15_49_21_15_M100
Feel free to contact me [[w:User talk:Friendlystar<Friendlystar]]
[edit] Comments
Warning: Default sort key "Astro" overrides earlier default sort key "ASTRO".