Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/120333
Change subject: Add links to Global CSS/JS on Special:Preferences
......................................................................
Add links to Global CSS/JS on Special:Preferences
Bug: 62600
Change-Id: I6c367ee6bc657fcc4172299518c796029b8b4ea3
---
M GlobalCssJs.hooks.php
M GlobalCssJs.i18n.php
M GlobalCssJs.php
3 files changed, 71 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GlobalCssJs
refs/changes/33/120333/1
diff --git a/GlobalCssJs.hooks.php b/GlobalCssJs.hooks.php
index 329c998..5b0dfbd 100644
--- a/GlobalCssJs.hooks.php
+++ b/GlobalCssJs.hooks.php
@@ -21,17 +21,25 @@
return true;
}
- $wiki = $wgGlobalCssJsConfig['wiki'];
-
// If we are on a different site, use a hook to allow other
extensions
// like CentralAuth verify that the same account exists on both
sites
- if ( $wiki === wfWikiID() || ( $wiki !== false
- && wfRunHooks( 'LoadGlobalCssJs', array( $user, $wiki,
wfWikiID() ) ) )
- ) {
+ if ( self::loadForUser( $user ) ) {
$out->addModules( 'ext.globalcssjs.user' );
}
return true;
+ }
+
+ /**
+ * Given a user, should we load scripts for them?
+ * @param User $user
+ * @return bool
+ */
+ static function loadForUser( User $user ) {
+ global $wgGlobalCssJsConfig;
+ $wiki = $wgGlobalCssJsConfig['wiki'];
+ return $wiki === wfWikiID() || ( $wiki !== false ) &&
+ wfRunHooks( 'LoadGlobalCssJs', array( $user, $wiki,
wfWikiID() ) );
}
/**
@@ -89,4 +97,55 @@
return true;
}
+ /**
+ * Convenince function to make a link to page that might be on another
site
+ * @param Title $title
+ * @param string $msg message key
+ * @return string HTMl link
+ */
+ protected static function makeCentralLink( Title $title, $msg ) {
+ global $wgGlobalCssJsConfig;
+ $message = wfMessage( $msg )->escaped();
+ if ( $wgGlobalCssJsConfig['wiki'] === wfWikiID() ) {
+ return Linker::link( $title, $message );
+ } else {
+ return WikiMap::makeForeignLink(
+ $wgGlobalCssJsConfig['wiki'],
+ $title->getPrefixedText(),
+ $message
+ );
+ }
+ }
+
+ static function onGetPreferences( User $user, array &$prefs ) {
+ global $wgAllowUserCss, $wgAllowUserJs;
+ if ( !self::loadForUser( $user ) ) {
+ // No global scripts for this user :(
+ return true;
+ }
+ $ctx = RequestContext::getMain();
+ $userName = $user->getName();
+ $linkTools = array();
+ if ( $wgAllowUserCss ) {
+ $cssPage = Title::makeTitleSafe( NS_USER, $userName .
'/global.css' );
+ $linkTools[] = self::makeCentralLink( $cssPage,
'globalcssjs-custom-css' );
+ }
+ if ( $wgAllowUserJs ) {
+ $jsPage = Title::makeTitleSafe( NS_USER, $userName .
'/global.js' );
+ $linkTools[] = self::makeCentralLink( $jsPage,
'globalcssjs-custom-js' );
+ }
+
+ $prefs = wfArrayInsertAfter(
+ $prefs,
+ array( 'globalcssjs' => array(
+ 'type' => 'info',
+ 'raw' => 'true',
+ 'default' => $ctx->getLanguage()->pipeList(
$linkTools ),
+ 'label-message' => 'globalcssjs-custom-css-js',
+ 'section' => 'rendering/skin',
+ ) ),
+ 'commoncssjs'
+ );
+ return true;
+ }
}
diff --git a/GlobalCssJs.i18n.php b/GlobalCssJs.i18n.php
index 9f3493c..6cb14b8 100644
--- a/GlobalCssJs.i18n.php
+++ b/GlobalCssJs.i18n.php
@@ -15,6 +15,9 @@
'globalcssjs-desc' => 'Allows CSS and JavaScript on a central wiki to
be loaded for all connected wikis',
'globalcssjs-warning-js' => 'Any JavaScript added to this page will be
loaded on all wikis where you have an account.',
'globalcssjs-warning-css' => 'Any CSS added to this page will be loaded
on all wikis where you have an account.',
+ 'globalcssjs-custom-css-js' => 'Shared CSS/JavaScript for all wikis',
+ 'globalcssjs-custom-js' => 'Custom JavaScript',
+ 'globalcssjs-custom-css' => 'Custom CSS',
);
/** Message documentation (Message documentation)
@@ -24,6 +27,9 @@
'globalcssjs-desc' => '{{desc|name=Global
CSS/JS|url=https://www.mediawiki.org/wiki/Extension:GlobalCssJs}}',
'globalcssjs-warning-js' => 'Notice on top of edit window',
'globalcssjs-warning-css' => 'Notice on top of edit window',
+ 'globalcssjs-custom-css-js' => 'Help message next to links to a user\'s
global.js/global.css pages',
+ 'globalcssjs-custom-js' => 'Link text for link to a user\'s global.js
page',
+ 'globalcssjs-custom-css' => 'Link text for a link to a user\'s
global.css page',
);
/** Asturian (asturianu)
diff --git a/GlobalCssJs.php b/GlobalCssJs.php
index 3a47bac..adcbb76 100644
--- a/GlobalCssJs.php
+++ b/GlobalCssJs.php
@@ -61,3 +61,4 @@
$wgHooks['BeforePageDisplay'][] = 'GlobalCssJsHooks::onBeforePageDisplay';
$wgHooks['ResourceLoaderRegisterModules'][] =
'GlobalCssJsHooks::onResourceLoaderRegisterModules';
$wgHooks['EditPage::showEditForm:initial'][] =
'GlobalCssJsHooks::onEditPageshowEditForminitial';
+$wgHooks['GetPreferences'][] = 'GlobalCssJsHooks::onGetPreferences';
--
To view, visit https://gerrit.wikimedia.org/r/120333
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c367ee6bc657fcc4172299518c796029b8b4ea3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GlobalCssJs
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits