r99887 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99886‎ | r99887 | r99888 >
Date:15:42, 15 October 2011
Author:cervidae
Status:deferred (Comments)
Tags:
Comment:
Adding SharedCssJs extension
Modified paths:
  • /trunk/extensions/SharedCssJs (added) (history)
  • /trunk/extensions/SharedCssJs/SharedCssJs.i18n.php (added) (history)
  • /trunk/extensions/SharedCssJs/SharedCssJs.php (added) (history)
  • /trunk/extensions/SharedCssJs/SharedCssJsProtector.php (added) (history)

Diff [purge]

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

Follow-up revisions

RevisionCommit summaryAuthorDate
r99888eol-style nativecervidae15:47, 15 October 2011
r99946Adding message documentation qqq for Translatewiki.netcervidae10:44, 16 October 2011
r100027Followup r99887: Fix type of extension: It is not a skin but "other". Fix ind...raymond14:05, 17 October 2011
r100028Add new extension to translatewiki (r99887)raymond14:05, 17 October 2011

Comments

#Comment by Reedy (talk | contribs)   15:45, 15 October 2011

Set svn:eol-style native

See Subversion/auto-props

#Comment by SVG (talk | contribs)   15:50, 15 October 2011

Hi. I already set it on my computer but it doesn't work (reboot). Don't know why. I fixed it here manually.

#Comment by Raymond (talk | contribs)   16:40, 15 October 2011

Please add message documentation for the newly added messages. Thanks.

#Comment by SVG (talk | contribs)   10:47, 16 October 2011

Thank you, Ray. Is it right? Special:Code/MediaWiki/99946

#Comment by Raymond (talk | contribs)   09:51, 17 October 2011

Yes, please do this for SharedCssJs too.

Pro tip: You can simply write r99946. This way the revisions are linked together.

#Comment by SVG (talk | contribs)   13:47, 17 October 2011

Okay, done. I saw it too late that r and the revision number is enough, now I know.

#Comment by Nikerabbit (talk | contribs)   10:19, 16 October 2011

Is this doing the same thing what the new Gadgets extension branch is doing?

#Comment by SVG (talk | contribs)   10:52, 16 October 2011

This extension is completely different to Gadgets extension. A bit similar to Extension:GlobalCssJs (breaks the cookies in 1.17) but it doesn't base on this. I'll write the documentation in the follow days.

#Comment by SVG (talk | contribs)   15:50, 16 October 2011

Fixed in [[Special:Code/MediaWiki/99888|r99888]]

Status & tagging log