Index: trunk/extensions/SharedCssJs/SharedCssJs.i18n.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Localisation file for the SharedCssJs extension |
| 5 | + * |
| 6 | + * @since 1.0 |
| 7 | + * |
| 8 | + * @file SharedCssJs.i18n.php |
| 9 | + * @ingroup SharedCssJs |
| 10 | + * |
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + * @author Tim Weyer (SVG) <svg@tim-weyer.org> |
| 13 | + */ |
| 14 | + |
| 15 | +$messages = array(); |
| 16 | + |
| 17 | +/** English |
| 18 | + * @author SVG |
| 19 | + */ |
| 20 | +$messages['en'] = array( |
| 21 | + 'sharedcssjs-desc' => 'Enables fetching of global wiki and user CSS and JS from central wiki', |
| 22 | + 'sharedcssjs-error' => "This page is included from central wiki by another way and can only editing there.", |
| 23 | + 'global.css' => "/* CSS placed here will be applied to all skins on all wikis of the wiki farm */", |
| 24 | + 'global.js' => "/* JavaScript placed here will be applied to all skins on all wikis of the wiki farm */", |
| 25 | +); |
| 26 | + |
| 27 | +/** German (Deutsch) |
| 28 | + * @author SVG |
| 29 | + */ |
| 30 | +$messages['de'] = array( |
| 31 | + 'sharedcssjs-desc' => 'Ermöglicht das Nutzen von globalen Wiki- und Benutzer-CSS und JS-Dateien aus dem Zentral Wiki', |
| 32 | + 'sharedcssjs-error' => 'Diese Seite ist aus dem Zentral Wiki auf einem anderen Weg eingebunden und kann auch nur dort bearbeitet werden.', |
| 33 | + 'global.css' => "/* Das folgende CSS wird für alle Benutzeroberflächen auf allen Wikis der Wiki-Farm geladen */", |
| 34 | + 'global.js' => "/* Das folgende JavaScript wird für alle Benutzeroberflächen auf allen Wikis der Wiki-Farm geladen */", |
| 35 | +); |
\ No newline at end of file |
Index: trunk/extensions/SharedCssJs/SharedCssJs.php |
— | — | @@ -0,0 +1,94 @@ |
| 2 | +<?php |
| 3 | +/**
|
| 4 | + * SharedCssJs
|
| 5 | + *
|
| 6 | + * @package MediaWiki
|
| 7 | + * @subpackage Extensions
|
| 8 | + *
|
| 9 | + * @author Tim Weyer (SVG) <svg@tim-weyer.org>
|
| 10 | + *
|
| 11 | + * @copyright Copyright (C) 2011 by Tim Weyer
|
| 12 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
|
| 13 | + */ |
| 14 | + |
| 15 | +if(!defined('MEDIAWIKI')) { |
| 16 | + echo("This is an extension to the MediaWiki software and cannot be used standalone"); |
| 17 | + die(1); |
| 18 | +} |
| 19 | + |
| 20 | +$wgExtensionCredits['skin'][] = array( |
| 21 | + 'name' => 'SharedCssJs', |
| 22 | + 'author' => array( "Tim Weyer" ), |
| 23 | + 'version' => '1.0', |
| 24 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:SharedCssJs', |
| 25 | + 'descriptionmsg' => 'sharedcssjs-desc', |
| 26 | +); |
| 27 | + |
| 28 | +// Localisation of this extension
|
| 29 | +$dir = dirname( __FILE__ ) . '/';
|
| 30 | +$wgExtensionMessagesFiles['SharedCssJs'] = $dir . 'SharedCssJs.i18n.php'; |
| 31 | + |
| 32 | +// Loading page protector |
| 33 | +$dir = dirname( __FILE__ ) . '/';
|
| 34 | +require_once ( "$dir/SharedCssJsProtector.php" ); |
| 35 | + |
| 36 | +// Hooks |
| 37 | +$wgHooks['SkinTemplateSetupPageCss'][] = 'wfSharedCSS'; |
| 38 | +$wgHooks['SkinTemplateSetupPageCss'][] = 'wfSharedUserCSS'; |
| 39 | +$wgHooks['BeforePageDisplay'][] = 'wfSharedJS'; |
| 40 | +$wgHooks['BeforePageDisplay'][] = 'wfSharedUserJS'; |
| 41 | + |
| 42 | + |
| 43 | +function wfSharedCSS( &$out ) { |
| 44 | + global $wgDisableSharedCSS, $wgSharedCssJsUrl; |
| 45 | + if( !empty( $wgDisableSharedCSS ) ) { |
| 46 | + return true; |
| 47 | + } |
| 48 | + |
| 49 | + if ($wgSharedCssJsUrl) { |
| 50 | + $url = $wgSharedCssJsUrl; |
| 51 | + $out .= "@import \"{$url}?title=MediaWiki:Global.css&action=raw&ctype=text/css&smaxage=0\";"; |
| 52 | + } |
| 53 | + return true; |
| 54 | +} |
| 55 | + |
| 56 | +function wfSharedJS( &$out ) { |
| 57 | + global $wgDisableSharedJS, $wgJsMimeType, $wgSharedCssJsUrl; |
| 58 | + if( !empty( $wgDisableSharedJS ) ) { |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + if ($wgSharedCssJsUrl) { |
| 63 | + $url = $wgSharedCssJsUrl; |
| 64 | + $out->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$url}?title=MediaWiki:Global.js&action=raw&ctype={$wgJsMimeType}\"></script>"); |
| 65 | + } |
| 66 | + return true; |
| 67 | +} |
| 68 | + |
| 69 | +function wfSharedUserCSS( &$out ) { |
| 70 | + global $wgDisableSharedUserCSS, $wgSharedCssJsUrl, $wgUser; |
| 71 | + if( !empty( $wgDisableSharedUserCSS ) || !isset( $wgSharedCssJsUrl ) ) { |
| 72 | + return true; |
| 73 | + } |
| 74 | + |
| 75 | + if (!$wgUser->isAnon()) { |
| 76 | + $url = $wgSharedCssJsUrl; |
| 77 | + $userName = str_replace(' ', '_', $wgUser->getName()); |
| 78 | + $out .= "@import \"{$url}?title=User:{$userName}/global.css&action=raw&ctype=text/css&smaxage=0\";"; |
| 79 | + } |
| 80 | + return true; |
| 81 | +} |
| 82 | + |
| 83 | +function wfSharedUserJS( &$out ) { |
| 84 | + global $wgDisableSharedUserJS, $wgJsMimeType, $wgSharedCssJsUrl, $wgUser; |
| 85 | + if( !empty( $wgDisableSharedUserJS ) || !isset( $wgSharedCssJsUrl ) ) { |
| 86 | + return true; |
| 87 | + } |
| 88 | + |
| 89 | + if (!$wgUser->isAnon()) { |
| 90 | + $url = $wgSharedCssJsUrl; |
| 91 | + $userName = str_replace(' ', '_', $wgUser->getName()); |
| 92 | + $out->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$url}?title=User:{$userName}/global.js&action=raw&ctype={$wgJsMimeType}\"></script>"); |
| 93 | + } |
| 94 | + return true; |
| 95 | +} |
\ No newline at end of file |
Index: trunk/extensions/SharedCssJs/SharedCssJsProtector.php |
— | — | @@ -0,0 +1,52 @@ |
| 2 | +<?php
|
| 3 | +/** |
| 4 | + * Page protector file for the SharedCssJs extension |
| 5 | + * |
| 6 | + * @since 1.0 |
| 7 | + * |
| 8 | + * @file SharedCssJsProtector.php |
| 9 | + * @ingroup SharedCssJs |
| 10 | + * |
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + * @author Tim Weyer (SVG) <svg@tim-weyer.org> |
| 13 | + */
|
| 14 | +
|
| 15 | +if(!defined('MEDIAWIKI')) { |
| 16 | + echo("This is an extension to the MediaWiki software and cannot be used standalone"); |
| 17 | + die(1); |
| 18 | +}
|
| 19 | +
|
| 20 | +$wgHooks['getUserPermissionsErrors'][] = 'fnProtectSharedCssJs'; |
| 21 | +
|
| 22 | +function fnProtectSharedCssJs( &$title, &$user, $action, &$result) {
|
| 23 | + global $wgSharedCssJsDB, $wgDBname; |
| 24 | + |
| 25 | + // only protect MediaWiki:Global.css and MediaWiki:Global.js on non-central wikis |
| 26 | + if( $wgSharedCssJsDB != $wgDBname ) { |
| 27 | + |
| 28 | + // block actions 'edit' and 'create'
|
| 29 | + if( $action != 'edit' && $action != 'create') {
|
| 30 | + return true;
|
| 31 | + }
|
| 32 | +
|
| 33 | + // check pagenames
|
| 34 | + if( $title->getText() != 'Global.css' && $title->getText() != 'Global.js' ) {
|
| 35 | + return true;
|
| 36 | + }
|
| 37 | +
|
| 38 | + $ns = $title->getNamespace();
|
| 39 | +
|
| 40 | + // check namespaces
|
| 41 | + if($ns == 8 || $ns == 9 ) { |
| 42 | +
|
| 43 | + // error message if action is blocked
|
| 44 | + $result = array('sharedcssjs-error');
|
| 45 | +
|
| 46 | + // bail, and stop the request
|
| 47 | + return false;
|
| 48 | + } |
| 49 | + |
| 50 | + }
|
| 51 | +
|
| 52 | + return true;
|
| 53 | +} |
\ No newline at end of file |