r6795 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r6794‎ | r6795 | r6796 >
Date:13:36, 23 December 2004
Author:vibber
Status:old
Tags:
Comment:
Extension to add special-character inserts for the edit page
Modified paths:
  • /trunk/extensions/CharInsert (added) (history)
  • /trunk/extensions/CharInsert/CharInsert.php (added) (history)

Diff [purge]

Index: trunk/extensions/CharInsert/CharInsert.php
@@ -0,0 +1,93 @@
 2+<?php
 3+# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
 4+# http://www.mediawiki.org/
 5+#
 6+# This program is free software; you can redistribute it and/or modify
 7+# it under the terms of the GNU General Public License as published by
 8+# the Free Software Foundation; either version 2 of the License, or
 9+# (at your option) any later version.
 10+#
 11+# This program is distributed in the hope that it will be useful,
 12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+# GNU General Public License for more details.
 15+#
 16+# You should have received a copy of the GNU General Public License along
 17+# with this program; if not, write to the Free Software Foundation, Inc.,
 18+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 19+# http://www.gnu.org/copyleft/gpl.html
 20+
 21+/**
 22+ * Extension to create new character inserts which can be used on
 23+ * the edit page to make it easy to get at special characters and
 24+ * such forth.
 25+ *
 26+ * @author Brion Vibber <brion at pobox.com>
 27+ * @package MediaWiki
 28+ * @subpackage Extensions
 29+ */
 30+
 31+if( !defined( 'MEDIAWIKI' ) ) {
 32+ die();
 33+}
 34+
 35+$wgExtensionFunctions[] = 'setupSpecialChars';
 36+
 37+function setupSpecialChars() {
 38+ global $wgParser;
 39+ $wgParser->setHook( 'charinsert', 'charInsert' );
 40+}
 41+
 42+function charInsert( $data ) {
 43+ return implode( "<br />\n",
 44+ array_map( 'charInsertLine',
 45+ explode( "\n", trim( $data ) ) ) );
 46+}
 47+
 48+function charInsertLine( $data ) {
 49+ return implode( "\n",
 50+ array_map( 'charInsertItem',
 51+ preg_split( '/\\s+/', $data ) ) );
 52+}
 53+
 54+function charInsertItem( $data ) {
 55+ $chars = array_map( 'charInsertCleanChar', explode( '+', $data ) );
 56+ if( count( $chars ) > 1 ) {
 57+ return charInsertChar( $chars[0], $chars[1], 'CLick the character while selecting a text' );
 58+ } elseif( count( $chars ) == 1 ) {
 59+ return charInsertChar( $chars[0] );
 60+ } else {
 61+ return charInsertChar( '+' );
 62+ }
 63+}
 64+
 65+function charInsertCleanChar( $data ) {
 66+ if( preg_match( '/^&#\d+;$/', $data ) ) {
 67+ return $data;
 68+ } elseif( preg_match( '/^&#x[0-9a-f]+;$/i', $data ) ) {
 69+ return $data;
 70+ } elseif( preg_match( '/^&[0-9a-z]+;$/i', $data ) ) {
 71+ return $data;
 72+ } else {
 73+ return htmlspecialchars( $data, ENT_QUOTES );
 74+ }
 75+}
 76+
 77+function charInsertChar( $start, $end = '', $title = null ) {
 78+ $estart = htmlspecialchars( $start );
 79+ $eend = htmlspecialchars( $end );
 80+ if( $eend == '' ) {
 81+ $inline = $start;
 82+ } else {
 83+ $inline = $start . $end;
 84+ }
 85+ if( $title ) {
 86+ $extra = ' title="' . htmlspecialchars( $title ) . '"';
 87+ } else {
 88+ $extra = '';
 89+ }
 90+ return "<a href=\"javascript:insertTags('$estart','$eend','')\">$inline</a>";
 91+}
 92+
 93+
 94+?>
\ No newline at end of file
Property changes on: trunk/extensions/CharInsert/CharInsert.php
___________________________________________________________________
Name: svn:keywords
195 + Author Date Id Revision
Name: svn:eol-style
296 + native

Status & tagging log