2007-04-03 22:34:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-06-01 17:50:34 +00:00
|
|
|
* Syntax highlighting extension for MediaWiki using GeSHi
|
2007-04-03 22:34:07 +00:00
|
|
|
* Copyright (C) 2005 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.,
|
2010-06-21 13:45:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-04-03 22:34:07 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-06-06 15:12:22 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
2007-04-03 22:34:07 +00:00
|
|
|
* @author Brion Vibber
|
|
|
|
*
|
|
|
|
* This extension wraps the GeSHi highlighter: http://qbnz.com/highlighter/
|
|
|
|
*
|
|
|
|
* A language is specified like: <source lang="c">void main() {}</source>
|
|
|
|
* If you forget, or give an unsupported value, the extension spits out
|
|
|
|
* some help text and a list of all supported languages.
|
|
|
|
*/
|
|
|
|
|
2010-08-09 06:56:38 +00:00
|
|
|
if( !defined( 'MEDIAWIKI' ) ) {
|
2007-04-03 22:34:07 +00:00
|
|
|
die();
|
2010-08-09 06:56:38 +00:00
|
|
|
}
|
2007-04-03 22:34:07 +00:00
|
|
|
|
2014-11-10 22:49:40 +00:00
|
|
|
if ( version_compare( $wgVersion, '1.24', '<' ) ) {
|
|
|
|
die( "This version of SyntaxHighlight GeSHi requires MediaWiki 1.24" );
|
|
|
|
}
|
|
|
|
|
2014-11-19 00:32:46 +00:00
|
|
|
include_once __DIR__ . '/SyntaxHighlight_GeSHi.langs.php';
|
|
|
|
|
2014-11-11 13:40:07 +00:00
|
|
|
$wgExtensionCredits['parserhook'][] = array(
|
2009-04-27 03:15:19 +00:00
|
|
|
'path' => __FILE__,
|
2008-02-06 23:37:30 +00:00
|
|
|
'name' => 'SyntaxHighlight',
|
2008-07-10 12:45:20 +00:00
|
|
|
'author' => array( 'Brion Vibber', 'Tim Starling', 'Rob Church', 'Niklas Laxström' ),
|
2008-02-06 23:37:30 +00:00
|
|
|
'descriptionmsg' => 'syntaxhighlight-desc',
|
2011-12-13 23:49:33 +00:00
|
|
|
'url' => 'https://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi',
|
2007-04-03 22:34:07 +00:00
|
|
|
);
|
|
|
|
|
2013-09-05 16:31:53 +00:00
|
|
|
// Change these in LocalSettings.php
|
|
|
|
$wgSyntaxHighlightDefaultLang = null;
|
|
|
|
$wgSyntaxHighlightKeywordLinks = false;
|
|
|
|
|
2014-03-28 21:39:14 +00:00
|
|
|
$dir = __DIR__ . '/';
|
|
|
|
$wgMessagesDirs['SyntaxHighlight_GeSHi'] = __DIR__ . '/i18n';
|
2008-01-11 09:05:18 +00:00
|
|
|
$wgExtensionMessagesFiles['SyntaxHighlight_GeSHi'] = $dir . 'SyntaxHighlight_GeSHi.i18n.php';
|
2014-04-16 20:23:12 +00:00
|
|
|
|
2008-01-11 09:05:18 +00:00
|
|
|
$wgAutoloadClasses['SyntaxHighlight_GeSHi'] = $dir . 'SyntaxHighlight_GeSHi.class.php';
|
2014-04-16 20:23:12 +00:00
|
|
|
$wgAutoloadClasses['ResourceLoaderGeSHiModule'] = $dir . 'ResourceLoaderGeSHiModule.php';
|
2014-06-01 17:57:10 +00:00
|
|
|
$wgAutoloadClasses['ResourceLoaderGeSHiLocalModule'] = $dir . 'ResourceLoaderGeSHiLocalModule.php';
|
2014-04-16 20:23:12 +00:00
|
|
|
|
2014-11-19 16:27:25 +00:00
|
|
|
$wgHooks['ExtensionTypes'][] = 'SyntaxHighlight_GeSHi::extensionTypes';
|
2014-04-16 20:23:12 +00:00
|
|
|
$wgHooks['ResourceLoaderRegisterModules'][] = 'SyntaxHighlight_GeSHi::resourceLoaderRegisterModules';
|
2014-05-10 21:28:07 +00:00
|
|
|
$wgHooks['ContentGetParserOutput'][] = 'SyntaxHighlight_GeSHi::renderHook';
|
2014-09-17 19:32:35 +00:00
|
|
|
$wgHooks['ApiFormatHighlight'][] = 'SyntaxHighlight_GeSHi::apiFormatHighlight';
|
2012-10-16 10:33:26 +00:00
|
|
|
|
2014-04-16 20:23:12 +00:00
|
|
|
// Module to load MediaWiki:Geshi.css.
|
2014-06-16 07:47:13 +00:00
|
|
|
$wgResourceModules['ext.geshi.local'] = array( 'class' => 'ResourceLoaderGeSHiLocalModule' );
|
2014-04-16 20:23:12 +00:00
|
|
|
// More modules are defined by SyntaxHighlight_GeSHi::resourceLoaderRegisterModules,
|
|
|
|
// one for each supported language. The general name template is 'ext.geshi.language.<lang>'.
|
2010-08-09 06:25:28 +00:00
|
|
|
|
2012-10-16 10:33:26 +00:00
|
|
|
/**
|
|
|
|
* Map content models to the corresponding language names to be used with the highlighter.
|
|
|
|
* Pages with one of the given content models will automatically be highlighted.
|
|
|
|
*/
|
2014-11-10 22:49:40 +00:00
|
|
|
$wgSyntaxHighlightModels[CONTENT_MODEL_CSS] = 'css';
|
|
|
|
$wgSyntaxHighlightModels[CONTENT_MODEL_JAVASCRIPT] = 'javascript';
|
2012-10-16 10:33:26 +00:00
|
|
|
|
2007-04-03 22:34:07 +00:00
|
|
|
/**
|
2007-06-29 04:33:14 +00:00
|
|
|
* Register parser hook
|
2011-05-26 00:08:16 +00:00
|
|
|
*
|
|
|
|
* @param $parser Parser
|
2014-06-01 17:40:09 +00:00
|
|
|
* @return bool
|
2007-04-03 22:34:07 +00:00
|
|
|
*/
|
2014-06-01 17:40:09 +00:00
|
|
|
$wgHooks['ParserFirstCallInit'][] = function ( &$parser ) {
|
2009-09-04 01:05:04 +00:00
|
|
|
$parser->setHook( 'source', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
|
|
|
|
$parser->setHook( 'syntaxhighlight', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
|
2008-05-25 21:09:41 +00:00
|
|
|
return true;
|
2014-06-01 17:40:09 +00:00
|
|
|
};
|