Benutzer:Rene/ImageInsert
aus Stargate Wiki, dem deutschsprachigen Stargate-Lexikon
MediaWiki Erweiterung die es ermöglicht Bilder in den Editor einzufügen. Diese Erweiterung basiert auf der Erweiterung CharInsert.
Anwendung
<imageinsert>Bildname</imageinsert>
Code
<?php # Copyright (C) 2004,2006 Brion Vibber <brion@pobox.com> # http://www.mediawiki.org/ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # http://www.gnu.org/copyleft/gpl.html /** * Extension to create new character inserts which can be used on * the edit page to make it easy to get at special characters and * such forth. * * @author Brion Vibber <brion at pobox.com> * @addtogroup Extensions */ if( !defined( 'MEDIAWIKI' ) ) { die(); } $wgExtensionFunctions[] = 'setupSpecialImages'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'ImageInsert', 'author' => 'Rene Raule', 'url' => 'http://www.stargate-wiki.de/index.php/Benutzer:Rene/ImageInsert', 'description' => 'Allows creation of JavaScript box for inserting Images (Based on CharInsert by Brion Vibber)', ); function setupSpecialImages() { global $wgParser; $wgParser->setHook( 'imageinsert', 'imageInsert' ); } function imageInsert( $data ) { return implode( "<br />\n", array_map( 'imageInsertLine', explode( "\n", trim( $data ) ) ) ); } function imageInsertLine( $data ) { return implode( "\n", array_map( 'imageInsertItem', preg_split( '/\\s+/', imageInsertArmor( $data ) ) ) ); } function imageInsertArmor( $data ) { return preg_replace_callback( '!(.*?)!i', 'imageInsertNowiki', $data ); } function imageInsertNowiki( $matches ) { return str_replace( array( '\t', '\r', ' ' ), array( ' ', '', ' ' ), $matches[1] ); } function imageInsertItem( $data ) { $chars = explode( '+', $data ); if( count( $chars ) > 1 ) { return imageInsertChar( $chars[0], $chars[1], 'Click the character while selecting a text' ); } elseif( count( $chars ) == 1 ) { return imageInsertChar( $chars[0] ); } else { return imageInsertChar( '+' ); } } function imageInsertChar( $start, $end = '', $title = null ) { $estart = imageInsertJsString( '[[Bild:'.$start.']]' ); $eend = imageInsertJsString( $end ); if( $eend == '' ) { $inline = imageInsertDisplay( $start ); } else { $inline = imageInsertDisplay( $start . $end ); } if( $title ) { $extra = ' title="' . htmlspecialchars( $title ) . '"'; } else { $extra = ''; } # Bild URL holen $image = Image::newFromName($start); if( !$image->exists() ) return; $iURL = $image->getURL(); $iHTML = "<img src='$iURL' />"; return "<a onclick=\"insertTags('$estart','$eend','');return false\" href='#'>$iHTML</a>"; # return wfElements( 'a', array('onclick' => "insertTags('$estart','$eend','');return false", 'href' => '#' ),$iHTML ); } function imageInsertJsString( $text ) { return strtr( imageInsertDisplay( $text ), array( "\\" => "\\\\", "\"" => "\\\"", "'" => "\\'", "\r\n" => "\\n", "\r" => "\\n", "\n" => "\\n", ) ); } function imageInsertDisplay( $text ) { static $invisibles = array( ' ', ' ' ); static $visibles = array( ' ', ' ' ); return Sanitizer::decodeCharReferences( str_replace( $invisibles, $visibles, $text ) ); } ?>