2009-01-27 02:18:51 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* {{#widget:<WidgetName>|<name1>=<value1>|<name2>=<value2>}}
|
|
|
|
*
|
|
|
|
* @author Sergey Chernyshev
|
|
|
|
* @version $Id: Widgets.php 15 2008-06-25 21:22:40Z sergey.chernyshev $
|
|
|
|
*/
|
|
|
|
|
2009-05-11 16:31:02 +04:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2013-02-21 02:16:29 +04:00
|
|
|
echo "This file is not a valid entry point.";
|
|
|
|
exit( 1 );
|
2009-05-11 16:31:02 +04:00
|
|
|
}
|
|
|
|
|
2009-01-27 02:18:51 +03:00
|
|
|
$wgExtensionCredits['parserhook'][] = array(
|
2009-04-27 08:45:10 +04:00
|
|
|
'path' => __FILE__,
|
2009-06-13 21:13:12 +04:00
|
|
|
'name' => 'Widgets',
|
|
|
|
'descriptionmsg' => 'widgets-desc',
|
2013-02-21 02:52:53 +04:00
|
|
|
'version' => '0.10.1',
|
2010-02-23 20:10:03 +03:00
|
|
|
'author' => '[http://www.sergeychernyshev.com Sergey Chernyshev]',
|
2011-12-14 03:49:33 +04:00
|
|
|
'url' => 'https://www.mediawiki.org/wiki/Extension:Widgets'
|
2009-01-27 02:18:51 +03:00
|
|
|
);
|
|
|
|
|
2009-05-11 16:31:02 +04:00
|
|
|
/**
|
|
|
|
* Set this to the index of the Widget namespace
|
|
|
|
*/
|
2009-05-22 21:32:04 +04:00
|
|
|
if ( !defined( 'NS_WIDGET' ) ) {
|
2013-02-21 02:16:29 +04:00
|
|
|
define( 'NS_WIDGET', 274 );
|
2009-05-22 21:32:04 +04:00
|
|
|
}
|
|
|
|
if ( !defined( 'NS_WIDGET_TALK' ) ) {
|
2013-02-21 02:16:29 +04:00
|
|
|
define( 'NS_WIDGET_TALK', NS_WIDGET + 1 );
|
2009-05-22 21:32:04 +04:00
|
|
|
} elseif ( NS_WIDGET_TALK != NS_WIDGET + 1 ) {
|
2013-02-21 02:16:29 +04:00
|
|
|
throw new MWException( 'Configuration error. Do not define NS_WIDGET_TALK, it is automatically set based on NS_WIDGET.' );
|
2009-05-22 21:32:04 +04:00
|
|
|
}
|
2009-05-11 16:31:02 +04:00
|
|
|
|
2009-06-13 21:13:12 +04:00
|
|
|
// Support subpages only for talk pages by default
|
|
|
|
$wgNamespacesWithSubpages[NS_WIDGET_TALK] = true;
|
|
|
|
|
2009-06-13 21:32:43 +04:00
|
|
|
// Define new right
|
|
|
|
$wgAvailableRights[] = 'editwidgets';
|
2011-07-25 03:36:41 +04:00
|
|
|
|
|
|
|
// Assign editing to widgeteditor and sysop groups only (widgets can be dangerous so we do it here, not in LocalSettings)
|
|
|
|
$wgGroupPermissions['*']['editwidgets'] = false;
|
|
|
|
$wgGroupPermissions['widgeteditor']['editwidgets'] = true;
|
2011-07-25 02:18:16 +04:00
|
|
|
$wgGroupPermissions['sysop']['editwidgets'] = true;
|
2009-06-13 21:32:43 +04:00
|
|
|
|
2010-04-17 01:24:38 +04:00
|
|
|
// Set this to true to use FlaggedRevs extension's stable version for widget security
|
|
|
|
$wgWidgetsUseFlaggedRevs = false;
|
|
|
|
|
2009-06-13 21:13:12 +04:00
|
|
|
$dir = dirname( __FILE__ ) . '/';
|
|
|
|
|
2009-01-27 02:18:51 +03:00
|
|
|
// Initialize Smarty
|
2013-02-21 02:52:53 +04:00
|
|
|
require_once( $dir . 'smarty/libs/Smarty.class.php' );
|
2009-06-13 21:32:43 +04:00
|
|
|
$wgExtensionMessagesFiles['Widgets'] = $dir . 'Widgets.i18n.php';
|
2012-06-22 02:18:47 +04:00
|
|
|
$wgExtensionMessagesFiles['WidgetsNamespaces'] = $dir . 'Widgets.i18n.namespaces.php';
|
2010-07-22 23:00:53 +04:00
|
|
|
$wgAutoloadClasses['WidgetRenderer'] = $dir . 'WidgetRenderer.php';
|
2009-01-27 02:18:51 +03:00
|
|
|
|
2012-01-19 18:02:15 +04:00
|
|
|
$wgExtensionMessagesFiles['WidgetsMagic'] = $dir . 'Widgets.i18n.magic.php';
|
2009-11-03 06:30:30 +03:00
|
|
|
|
2009-01-27 02:18:51 +03:00
|
|
|
// Parser function registration
|
2009-05-11 16:31:02 +04:00
|
|
|
$wgExtensionFunctions[] = 'widgetNamespacesInit';
|
2013-02-22 02:18:43 +04:00
|
|
|
$wgExtensionFunctions[] = 'WidgetRenderer::initRandomString';
|
2009-05-11 16:31:02 +04:00
|
|
|
$wgHooks['ParserFirstCallInit'][] = 'widgetParserFunctions';
|
2013-02-22 02:01:22 +04:00
|
|
|
$wgHooks['ParserAfterTidy'][] = 'WidgetRenderer::processEncodedWidgetOutput';
|
2013-02-21 02:16:29 +04:00
|
|
|
$wgHooks['CanonicalNamespaces'][] = 'widgetsAddNamespaces';
|
2009-01-27 02:18:51 +03:00
|
|
|
|
2011-07-25 03:12:08 +04:00
|
|
|
/**
|
|
|
|
* @param $parser Parser
|
|
|
|
* @return bool
|
|
|
|
*/
|
2009-06-13 21:13:12 +04:00
|
|
|
function widgetParserFunctions( &$parser ) {
|
2011-07-25 03:12:08 +04:00
|
|
|
$parser->setFunctionHook( 'widget', array( 'WidgetRenderer', 'renderWidget' ) );
|
2009-05-13 08:33:53 +04:00
|
|
|
|
2011-07-25 03:12:08 +04:00
|
|
|
return true;
|
2009-01-27 02:18:51 +03:00
|
|
|
}
|
|
|
|
|
2013-02-21 02:16:29 +04:00
|
|
|
// Define new namespaces
|
|
|
|
function widgetsAddNamespaces( &$list ) {
|
|
|
|
$list[NS_WIDGET] = 'Widget';
|
|
|
|
$list[NS_WIDGET_TALK] = 'Widget_talk';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-27 02:18:51 +03:00
|
|
|
function widgetNamespacesInit() {
|
2012-06-22 02:18:47 +04:00
|
|
|
global $wgNamespaceProtection, $wgWidgetsUseFlaggedRevs;
|
2009-01-27 02:18:51 +03:00
|
|
|
|
2011-07-25 02:18:16 +04:00
|
|
|
if ( !$wgWidgetsUseFlaggedRevs ) {
|
2010-04-17 01:24:38 +04:00
|
|
|
// Setting required namespace permission rights
|
|
|
|
$wgNamespaceProtection[NS_WIDGET] = array( 'editwidgets' );
|
|
|
|
}
|
2009-01-27 02:18:51 +03:00
|
|
|
}
|