Привет всем!!
У месня возникла проблема для движка mediawiki существует расширение YandexMaps написанное Valerian Ivashenko. Как оказалось оно совместимо только для версий 1.16-1.17. При последенем обновлении движка чтото стало работать не так
Я к сожалению не разбираюсь в PHP5.3 и API Яндекс.Карт настолько хорошо чтобы соватся в чужой код
PS смайлики в коде на месте ) и ; без смайликов код можно скачать в zip архиве со страницы расширения отсюда
/**
* YandexMaps MediaWiki extension
*
* @package MediaWiki
* @subpackage Extensions
*
* @link http://www.mediawiki.org/
*
* @author Valerian Ivashenko
* @copyright Copyright © 2011
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0
* or later
*
* To activate this extension, include it from your LocalSettings.php
* with: require_once("$IP/extensi
*/
if ( !defined( "MEDIAWIKI" ) )
{
die( "This file is a MediaWiki extension, it is not a valid entry point"
}
$YAM_MAP_SCRIPT_INCLUDED = false;
function addYandexScript( $parser, $js ) {
global $YAM_MAP_SCRIPT_INCLUDED;
global $wgYandexMapServer;
global $wgYandexMapAPIKey;
if( !$YAM_MAP_SCRIPT_INCLUDED ) {
$tag = '<script type=\'text/javascript\' src=\'';
$tag .= $wgYandexMapServer;
$tag .= $wgYandexMapAPIKey;
$tag .= '\'></script>';
$parser->mOutput->addHeadItem($tag);
$parser->mOutput->addHeadItem($js);
$YAM_MAP_SCRIPT_INCLUDED = true;
}
}
function addMapScript( $parser, $js ) {
$parser->mOutput->addHeadItem($js);
}
$wgHooks[ 'ParserFirstCallInit' ][] = $wgHooks[ 'LanguageGetMagic' ][]
= ExtYandexMaps::getInstance(
$wgExtensionCredits[ 'parserhook' ][] = array(
'path' => __FILE__,
"author" => "Valerian Ivashenko",
"name" => "YandexMaps",
"version" => ExtYandexMaps::VERSION,
"description" => "Parser function for rendering yandex maps",
"url" => "http://www.mediawiki.org/
class ExtYandexMaps
{
const VERSION = "1.8.2";
private static $instance = null;
private $parserFunctions = array(
'yandexmap' => array( 'renderYandexMap', SFH_OBJECT_ARGS ),
private $mapcounter = 0;
public static function getInstance()
{
// create the singleton if needed
if ( self::$instance === null )
self::$instance = new self(
return self::$instance;
}
/**
* limited-access constructor to insure singleton
*/
protected function __construct()
{
}
public function onParserFirstCallInit( &$parser )
{
global $wgMessageCache, $wgHooks;
// These functions accept DOM-style arguments
foreach( $this->parserFunctions as $hook => $callAndFlags )
$parser->setFunctionHook( $hook, array( $this, $callAndFlags[ 0 ] ),
$callAndFlags[ 1 ]
require_once( dirname( __FILE__ ) . '/YandexMaps.i18n.php'
foreach( YandexMaps_i18n::getInstance()->getMessages()
as $lang => $messages )
$wgMessageCache->addMessages( $messages, $lang
return true;
}
public function onLanguageGetMagic( &$magicWords, $langCode )
{
require_once( dirname( __FILE__ ) . '/YandexMaps.i18n.php'
foreach( YandexMaps_i18n::getInstance()->magicWords( $langCode )
as $word => $trans )
$magicWords[ $word ] = $trans;
return true;
}
public function renderYandexMap( &$parser, $frame, $args ) {
// bug 12842: first argument is automatically
// expanded, so we ignore this one
$location = array_shift( $args
$width = intval(trim( $frame->expand( array_shift( $args )))
$height = intval(trim( $frame->expand( array_shift( $args )))
$options = array_shift( $args
$options = isset( $options ) ? $frame->expand( $options ) : 'cdzMB';
$opt = 0;
if (strpos($options,'c') !== false) {
$opt = $opt + 1;
}
if (strpos($options,'d') !== false) {
$opt = $opt + 2;
}
if (strpos($options,'r') !== false) {
$opt = $opt + 4;
}
if (strpos($options,'z') !== false) {
$opt = $opt + 8;
}
if (strpos($options,'h') !== false) {
$opt = $opt + 16;
}
if (strpos($options,'m') !== false) {
$opt = $opt + 32;
}
if (strpos($options,'b') !== false) {
$opt = $opt + 64;
}
if (strpos($options,'M') !== false) {
$opt = $opt + 128;
}
if (strpos($options,'H') !== false) {
$opt = $opt + 256;
}
if (strpos($options,'S') !== false) {
$opt = $opt + 512;
}
if ((strpos($options,'P')||strpos($options,'B')) !== false) {
$opt = $opt + 1024;
}
if (strpos($options,'B') !== false) {
$opt = $opt + 2048;
}
$output = '';
$js = '<script type="text/javascript">
/*<![CDATA[*/
// Map render function creation
function renderYandexMap(YMaps,id,location,p) {
// Map instance creation and association with the created container
var map = new YMaps.Map(document.getElementById(id)
// Map center and scale zoom settings
if ((p&128)==128) { //M
map.setCenter(new YMaps.GeoPoint(27.55, 53.9), 10, YMaps.MapType.MAP);
}
if ((p&256)==256) { //H
map.setCenter(new YMaps.GeoPoint(27.55, 53.9), 10, YMaps.MapType.HYBRID);
}
if ((p&512)==512) { //S
map.setCenter(new YMaps.GeoPoint(27.55, 53.9), 10, YMaps.MapType.SATELLITE);
}
if ((p&1)==0) { //c
map.disableDblClickZoom(
}
if ((p&2)==0) { //d
map.disableDragging(
}
if ((p&4)==4) { //r
map.enableRuler(
}
if ((p&8)==8) { //z
map.enableScrollZoom(
var zoomControl = new YMaps.Zoom(
map.addControl(zoomControl);
}
if ((p&16)==16) { //h
map.enableHotKeys(
}
if ((p&32)==32) { //m
map.enableMagnifier(
}
if ((p&64)==64) { //b
map.enableRightButtonMagnifier(
}
// Geocode process launching
var geocoder = new YMaps.Geocoder(location,{prefLang : "ru"}
// Geocode ending process success handler
YMaps.Events.observe(geocoder, geocoder.Events.Load, function (geocoder) {
if (this.length()) {
if ((p&1024)==1024) { //P
// Balloon content style creation
var s = new YMaps.Style(
s.balloonContentStyle = new YMaps.BalloonContentStyle(
new YMaps.Template("<div style=\"background:none;c
// User defined style placemark and its adding to the map
var placemark = new YMaps.Placemark(this.get(0).getGeoPoint(), {style: s}
placemark.description = location;
map.addOverlay(placemark);
if ((p&2048)==2048) //B
placemark.openBalloon(
}
map.setBounds(this.get(0).getBounds()
}else {
alert("Nothing Found")
}
}
// Geocode ending failure handler
YMaps.Events.observe(geocoder, geocoder.Events.Fault, function (error) {
alert("An error has occurred: " + error.message)
}
}
/*]]>*/
</script>';
addYandexScript($parser, $js);
$id = 'YMapsID';
$id .= intval ($this->mapcounter++);
$js = '<script type="text/javascript">
/*<![CDATA[*/
// window.onLoad event handler creation
YMaps.jQuery(function () {
// map render function call
renderYandexMap(YMaps,"';
$js .= <<<ENDID
{$id}
ENDID;
$js .= '","';
$js .= <<<ENDLOCATION
{$location}
ENDLOCATION;
$js .= '",';
$js .= <<<ENDOPTION
{$opt}
ENDOPTION;
$js .= ');
}
/*]]>*/
</script>';
addMapScript($parser, $js);
$output .= '<div id="';
$output .= <<<ENDOUTID
{$id}
ENDOUTID;
$output .= '" style="width:';
$output .= <<<ENDWIDTH
{$width}
ENDWIDTH;
$output .= 'px;height:';
$output .= <<<ENDHEIGHT
{$height}
ENDHEIGHT;
$output .= 'px"></div>';
return $output;
}
}
class YandexMaps_i18n
{
private $words = array(
// English
'en' => array(
'yandexmap' => array( 0, 'yandexmap' ),
),
private $messages = array(
// English
'en' => array(
)
private static $instance = null;
public static function getInstance()
{
// create the singleton if needed
if ( self::$instance === null )
self::$instance = new self(
return self::$instance;
}
/**
* limited-access constructor to insure singleton
*/
protected function __construct()
{
}
/**
* Get translated magic words, if available
*
* @param string $lang Language code
* @return array
*/
public function magicWords( $lang )
{
// English is used as a fallback, and the English synonyms are
// used if a translation has not been provided for a given word
return ( $lang == 'en' || !isset( $this->words[ $lang ] ) ) ?
$this->words[ 'en' ] :
array_merge( $this->words[ 'en' ], $this->words[ $lang ]
}
public function getMessages()
{
return $this->messages;
}
}