Paladox has uploaded a new change for review.
https://gerrit.wikimedia.org/r/169787
Change subject: Adding files
......................................................................
Adding files
* Adding collapsiblenav
Change-Id: I14acfc38a98036e391fa5b8cc6bb916ffd8bb8d3
---
A .gitignore
A CollapsibleVector.hooks.php
A CollapsibleVector.i18n.php
A CollapsibleVector.php
A README
A modules/ext.vector.collapsibleNav.js
A modules/ext.vector.collapsibleNav.less
A modules/images/arrow-collapsed-ltr.png
A modules/images/arrow-collapsed-ltr.svg
A modules/images/arrow-collapsed-rtl.png
A modules/images/arrow-collapsed-rtl.svg
A modules/images/arrow-expanded.png
A modules/images/arrow-expanded.svg
A modules/images/edit-faded.png
A modules/images/edit.png
A modules/images/portal-break.png
A switchExperimentPrefs.php
17 files changed, 587 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollapsibleVector
refs/changes/87/169787/1
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b42cb43
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+.svn
+*~
+*.kate-swp
+.*.swp
+.DS_Store
+
diff --git a/CollapsibleVector.hooks.php b/CollapsibleVector.hooks.php
new file mode 100644
index 0000000..798b04b
--- /dev/null
+++ b/CollapsibleVector.hooks.php
@@ -0,0 +1,153 @@
+<?php
+/**
+ * Hooks for Vector extension
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+class VectorHooks {
+
+ /* Protected Static Members */
+
+ protected static $features = array(
+ 'collapsiblenav' => array(
+ 'preferences' => array(
+ 'vector-collapsiblenav' => array(
+ 'type' => 'toggle',
+ 'label-message' =>
'vector-collapsiblenav-preference',
+ 'section' =>
'rendering/advancedrendering',
+ ),
+ ),
+ 'requirements' => array(
+ 'vector-collapsiblenav' => true,
+ ),
+ 'configurations' => array(
+ 'wgCollapsibleNavBucketTest',
+ 'wgCollapsibleNavForceNewVersion',
+ ),
+ 'modules' => array( 'ext.vector.collapsibleNav' ),
+ ),
+ 'experiments' => array(
+ 'preferences' => array(
+ 'vector-noexperiments' => array(
+ 'type' => 'toggle',
+ 'label-message' =>
'vector-noexperiments-preference',
+ 'section' =>
'rendering/advancedrendering',
+ ),
+ ),
+ ),
+ );
+
+ /* Protected Static Methods */
+
+ protected static function isEnabled( $name ) {
+ global $wgVectorFeatures, $wgUser;
+
+ // Features with global set to true are always enabled
+ if ( !isset( $wgVectorFeatures[$name] ) ||
$wgVectorFeatures[$name]['global'] ) {
+ return true;
+ }
+ // Features with user preference control can have any number of
preferences to be specific values to be enabled
+ if ( $wgVectorFeatures[$name]['user'] ) {
+ if ( isset( self::$features[$name]['requirements'] ) ) {
+ foreach (
self::$features[$name]['requirements'] as $requirement => $value ) {
+ // Important! We really do want fuzzy
evaluation here
+ if ( $wgUser->getOption( $requirement )
!= $value ) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ // Features controlled by $wgVectorFeatures with both global
and user set to false are awlways disabled
+ return false;
+ }
+
+ /* Static Methods */
+
+ /**
+ * BeforePageDisplay hook
+ *
+ * Adds the modules to the page
+ *
+ * @param $out OutputPage output page
+ * @param $skin Skin current skin
+ */
+ public static function beforePageDisplay( $out, $skin ) {
+ if ( $skin instanceof SkinVector ) {
+ // Add modules for enabled features
+ foreach ( self::$features as $name => $feature ) {
+ if ( isset( $feature['modules'] ) &&
self::isEnabled( $name ) ) {
+ $out->addModules( $feature['modules'] );
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * GetPreferences hook
+ *
+ * Adds Vector-releated items to the preferences
+ *
+ * @param $user User current user
+ * @param $defaultPreferences array list of default user preference
controls
+ */
+ public static function getPreferences( $user, &$defaultPreferences ) {
+ global $wgVectorFeatures;
+
+ foreach ( self::$features as $name => $feature ) {
+ if (
+ isset( $feature['preferences'] ) &&
+ ( !isset( $wgVectorFeatures[$name] ) ||
$wgVectorFeatures[$name]['user'] )
+ ) {
+ foreach ( $feature['preferences'] as $key =>
$options ) {
+ $defaultPreferences[$key] = $options;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * ResourceLoaderGetConfigVars hook
+ *
+ * Adds enabled/disabled switches for Vector modules
+ */
+ public static function resourceLoaderGetConfigVars( &$vars ) {
+ global $wgVectorFeatures;
+
+ $configurations = array();
+ foreach ( self::$features as $name => $feature ) {
+ if (
+ isset( $feature['configurations'] ) &&
+ ( !isset( $wgVectorFeatures[$name] ) ||
self::isEnabled( $name ) )
+ ) {
+ foreach ( $feature['configurations'] as
$configuration ) {
+ global $$configuration;
+ $configurations[$configuration] =
$$configuration;
+ }
+ }
+ }
+ if ( count( $configurations ) ) {
+ $vars = array_merge( $vars, $configurations );
+ }
+ return true;
+ }
+
+ /**
+ * @param $vars array
+ * @return bool
+ */
+ public static function makeGlobalVariablesScript( &$vars ) {
+ // Build and export old-style wgVectorEnabledModules object for
back compat
+ $enabledModules = array();
+ foreach ( self::$features as $name => $feature ) {
+ $enabledModules[$name] = self::isEnabled( $name );
+ }
+
+ $vars['wgVectorEnabledModules'] = $enabledModules;
+ return true;
+ }
+}
diff --git a/CollapsibleVector.i18n.php b/CollapsibleVector.i18n.php
new file mode 100644
index 0000000..1183f50
--- /dev/null
+++ b/CollapsibleVector.i18n.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Internationalisation for Vector extension
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$messages = array();
+
+/** English
+ * @author Trevor Parscal
+ */
+$messages['en'] = array(
+ 'vector' => 'UI improvements for Vector',
+ 'collapsiblevector-desc' => 'Enhances the user interface when using the
Vector skin',
+ 'vector-collapsiblenav-preference' => 'Enable collapsing of items in
the sidebar in Vector skin',
+ 'vector-collapsiblenav-more' => 'More languages',
+ 'vector-noexperiments-preference' => 'Exclude me from feature
experiments',
+);
+
+/** Message documentation (Message documentation)
+ * @author Fryed-peach
+ * @author Lloffiwr
+ * @author Nemo bis
+ * @author Shirayuki
+ * @author Srtxg
+ * @author Umherirrender
+ */
+$messages['qqq'] = array(
+ 'vector' => 'UI means User Interface. Vector is the name of an
interface skin.',
+ 'collapsiblevector-desc' =>
'{{desc|name=CollapsibleVector|url=http://www.mediawiki.org/wiki/Extension:CollapsibleVector}}',
+ 'vector-collapsiblenav-preference' => 'The message refers to the
sidebar, whose sections are collapsible in Vector skin (some of them collapsed
by default and some no); the preference disables collapsing entirely and is
among "Advanced options" in the "Appearence" section.',
+);
diff --git a/CollapsibleVector.php b/CollapsibleVector.php
new file mode 100644
index 0000000..da95a8c
--- /dev/null
+++ b/CollapsibleVector.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * CollapsibleVector extension
+ *
+ * @file
+ * @ingroup Extensions
+ *
+ * @license GPL v2 or later
+ * @version 0.1.0
+*
+* Requires MediaWiki 1.24+
+ */
+
+
+if ( version_compare( $GLOBALS['wgVersion'], '1.24c', '<' ) ) {
+ die( '<b>Error:</b> CollapsibleVector requires MediaWiki 1.24 or above.' );
+}
+
+
+/* Configuration */
+
+// Each module may be configured individually to be globally on/off or user
preference based
+$wgVectorFeatures = array(
+ 'collapsiblenav' => array( 'global' => true, 'user' => true ),
+);
+
+// Enable bucket testing for new version of collapsible nav
+$wgCollapsibleNavBucketTest = false;
+// Force the new version
+$wgCollapsibleNavForceNewVersion = false;
+
+/* Setup */
+
+$wgExtensionCredits['other'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'CollapsibleVector',
+ 'author' => array( 'paladox' ),
+ 'version' => '0.1.0',
+ 'url' => 'https://www.mediawiki.org/wiki/Extension:CollapsibleVector',
+ 'descriptionmsg' => 'collapsiblevector-desc',
+);
+$wgAutoloadClasses['VectorHooks'] = dirname( __FILE__ ) .
'/CollapsibleVector.hooks.php';
+$wgExtensionMessagesFiles['CollapsibleVector'] = dirname( __FILE__ ) .
'/CollapsibleVector.i18n.php';
+$wgHooks['BeforePageDisplay'][] = 'VectorHooks::beforePageDisplay';
+$wgHooks['GetPreferences'][] = 'VectorHooks::getPreferences';
+$wgHooks['ResourceLoaderGetConfigVars'][] =
'VectorHooks::resourceLoaderGetConfigVars';
+$wgHooks['MakeGlobalVariablesScript'][] =
'VectorHooks::makeGlobalVariablesScript';
+
+$vectorResourceTemplate = array(
+ 'localBasePath' => dirname( __FILE__ ) . '/modules',
+ 'remoteExtPath' => 'CollapsibleVector/modules',
+ 'group' => 'ext.vector',
+);
+$wgResourceModules += array(
+ // TODO this module should be merged with ext.vector.collapsibleTabs
+ 'ext.vector.collapsibleNav' => $vectorResourceTemplate + array(
+ 'scripts' => 'ext.vector.collapsibleNav.js',
+ 'styles' => 'ext.vector.collapsibleNav.less',
+ 'messages' => array(
+ 'vector-collapsiblenav-more',
+ ),
+ 'dependencies' => array(
+ 'jquery.client',
+ 'jquery.cookie',
+ 'jquery.tabIndex',
+ ),
+ ),
+);
diff --git a/README b/README
new file mode 100644
index 0000000..af33bf4
--- /dev/null
+++ b/README
@@ -0,0 +1,17 @@
+# Vector provides enhancements to the Vector skin
+
+# This extension requires MediaWiki 1.24+.
+
+# Example LocalSettings.php additions
+
+require_once( "$IP/extensions/CollapsibleVector/CollapsibleVector.php" );
+
+# Before configuring this extension, see CollapsibleVector.php and become
familiar with the initial state and structure of the
+# $wgVectorFeatures configuration variable. Essentially it's an array of
arrays, keyed by feature name, each containing
+# global and user keys with boolean values. "global" indicates that it should
be turned on for everyone always, while
+# user indicates that users should be allowed to turn it on or off in their
user preferences.
+
+# To enable a preference by default but still allow users to disable it in
preferences, use something like...
+
+$wgDefaultUserOptions['vector-collapsiblenav'] = 1;
+
diff --git a/modules/ext.vector.collapsibleNav.js
b/modules/ext.vector.collapsibleNav.js
new file mode 100644
index 0000000..45258e5
--- /dev/null
+++ b/modules/ext.vector.collapsibleNav.js
@@ -0,0 +1,152 @@
+/**
+ * Collapsible navigation for Vector
+ */
+( function ( mw, $ ) {
+ 'use strict';
+ var map;
+
+ // Use the same function for all navigation headings - don't repeat
+ function toggle( $element ) {
+ var isCollapsed = $element.parent().is( '.collapsed' );
+
+ $.cookie(
+ 'vector-nav-' + $element.parent().attr( 'id' ),
+ isCollapsed,
+ { 'expires': 30, 'path': '/' }
+ );
+
+ $element
+ .parent()
+ .toggleClass( 'expanded' )
+ .toggleClass( 'collapsed' )
+ .find( '.body' )
+ .slideToggle( 'fast' );
+ isCollapsed = !isCollapsed;
+
+ $element
+ .find( '> a' )
+ .attr( {
+ 'aria-pressed': isCollapsed ? 'false' : 'true',
+ 'aria-expanded': isCollapsed ? 'false' : 'true'
+ } );
+ }
+
+ /* Browser Support */
+
+ map = {
+ // Left-to-right languages
+ ltr: {
+ // Collapsible Nav is broken in Opera < 9.6 and
Konqueror < 4
+ opera: [['>=', 9.6]],
+ konqueror: [['>=', 4.0]],
+ blackberry: false,
+ ipod: false,
+ iphone: false,
+ ps3: false
+ },
+ // Right-to-left languages
+ rtl: {
+ opera: [['>=', 9.6]],
+ konqueror: [['>=', 4.0]],
+ blackberry: false,
+ ipod: false,
+ iphone: false,
+ ps3: false
+ }
+ };
+ if ( !$.client.test( map ) ) {
+ return true;
+ }
+
+ $( function ( $ ) {
+ var $headings, tabIndex;
+
+ /* General Portal Modification */
+
+ // Always show the first portal
+ $( '#mw-panel > .portal:first' ).addClass( 'first persistent' );
+ // Apply a class to the entire panel to activate styles
+ $( '#mw-panel' ).addClass( 'collapsible-nav' );
+ // Use cookie data to restore preferences of what to show and
hide
+ $( '#mw-panel > .portal:not(.persistent)' )
+ .each( function ( i ) {
+ var id = $(this).attr( 'id' ),
+ state = $.cookie( 'vector-nav-' + id );
+ $(this).find( 'ul:first' ).attr( 'id', id +
'-list' );
+ // Add anchor tag to heading for better
accessibility
+ $( this ).find( 'h3' ).wrapInner(
+ $( '<a>' )
+ .attr( {
+ href: '#',
+ 'aria-haspopup': 'true',
+ 'aria-controls': id +
'-list',
+ role: 'button'
+ } )
+ .click( false )
+ );
+ // In the case that we are not showing the new
version, let's show the languages by default
+ if (
+ state === 'true' ||
+ ( state === null && i < 1 ) ||
+ ( state === null && id === 'p-lang' )
+ ) {
+ $(this)
+ .addClass( 'expanded' )
+ .removeClass( 'collapsed' )
+ .find( '.body' )
+ .hide() // bug 34450
+ .show();
+ $(this).find( 'h3 > a' )
+ .attr( {
+ 'aria-pressed': 'true',
+ 'aria-expanded': 'true'
+ } );
+ } else {
+ $(this)
+ .addClass( 'collapsed' )
+ .removeClass( 'expanded' );
+ $(this).find( 'h3 > a' )
+ .attr( {
+ 'aria-pressed': 'false',
+ 'aria-expanded': 'false'
+ } );
+ }
+ // Re-save cookie
+ if ( state !== null ) {
+ $.cookie( 'vector-nav-' + $(this).attr(
'id' ), state, { 'expires': 30, 'path': '/' } );
+ }
+ } );
+
+ /* Tab Indexing */
+
+ $headings = $( '#mw-panel > .portal:not(.persistent) > h3' );
+
+ // Get the highest tab index
+ tabIndex = $( document ).lastTabIndex() + 1;
+
+ // Fix the search not having a tabindex
+ $( '#searchInput' ).attr( 'tabindex', tabIndex++ );
+
+ // Make it keyboard accessible
+ $headings.attr( 'tabindex', function () {
+ return tabIndex++;
+ });
+
+ // Toggle the selected menu's class and expand or collapse the
menu
+ $( '#mw-panel' )
+ .delegate( '.portal:not(.persistent) > h3', 'keydown',
function ( e ) {
+ // Make the space and enter keys act as a click
+ if ( e.which === 13 /* Enter */ || e.which ===
32 /* Space */ ) {
+ toggle( $(this) );
+ }
+ } )
+ .delegate( '.portal:not(.persistent) > h3',
'mousedown', function ( e ) {
+ if ( e.which !== 3 ) { // Right mouse click
+ toggle( $(this) );
+ $(this).blur();
+ }
+ return false;
+ } );
+ });
+
+}( mediaWiki, jQuery ) );
diff --git a/modules/ext.vector.collapsibleNav.less
b/modules/ext.vector.collapsibleNav.less
new file mode 100644
index 0000000..acfb4d2
--- /dev/null
+++ b/modules/ext.vector.collapsibleNav.less
@@ -0,0 +1,91 @@
+/**
+ * LESS Stylesheet for collapsible nav
+ */
+@import "mediawiki.mixins.less";
+
+#mw-panel.collapsible-nav {
+ .portal {
+ background-position: left top;
+ background-repeat: no-repeat;
+ .background-image('images/portal-break.png');
+ padding: 0.25em 0 !important;
+ margin: -11px 9px 10px 11px;
+
+ h3 {
+ font-size: 0.75em;
+ color: #4d4d4d;
+ font-weight: normal;
+ background-position: left center;
+ background-repeat: no-repeat;
+ .background-image-svg('images/arrow-expanded.svg',
'images/arrow-expanded.png');
+ padding: 4px 0 3px 1.5em;
+ margin-bottom: 0;
+
+ &:hover {
+ cursor: pointer;
+ text-decoration: none;
+ }
+
+ a {
+ color: #4d4d4d;
+ text-decoration: none;
+ }
+ }
+
+ .body {
+ margin: 0 0 0 1.25em;
+ background-image: none !important;
+ padding-top: 0;
+ display: none;
+
+ ul {
+ li {
+ padding: 0.25em 0;
+ }
+ }
+ }
+
+
+ /* First */
+ &.first {
+ background-image: none;
+ margin-top: 0;
+ h3 {
+ display: none;
+ }
+ }
+
+ /* Persistent */
+ &.persistent {
+ .body {
+ display: block;
+ margin-left: 0.5em;
+ }
+
+ h3 {
+ background-image: none !important;
+ padding-left: 0.7em;
+ cursor: default;
+ }
+ }
+
+ /* Collapsed */
+ &.collapsed {
+ h3 {
+ color: #0645ad;
+ background-position: left center;
+ background-repeat: no-repeat;
+
.background-image-svg('images/arrow-collapsed-ltr.svg',
'images/arrow-collapsed-ltr.png');
+ margin-bottom: 0;
+
+ &:hover {
+ text-decoration: underline;
+ }
+
+ a {
+ color: #0645ad;
+ }
+ }
+ }
+ }
+}
diff --git a/modules/images/arrow-collapsed-ltr.png
b/modules/images/arrow-collapsed-ltr.png
new file mode 100644
index 0000000..063ac6f
--- /dev/null
+++ b/modules/images/arrow-collapsed-ltr.png
Binary files differ
diff --git a/modules/images/arrow-collapsed-ltr.svg
b/modules/images/arrow-collapsed-ltr.svg
new file mode 100644
index 0000000..b943caa
--- /dev/null
+++ b/modules/images/arrow-collapsed-ltr.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg"
width="16" height="16"><path d="M6.001 2.998l5.001 5-5.001 5z"
fill="#797979"/></svg>
\ No newline at end of file
diff --git a/modules/images/arrow-collapsed-rtl.png
b/modules/images/arrow-collapsed-rtl.png
new file mode 100644
index 0000000..c346218
--- /dev/null
+++ b/modules/images/arrow-collapsed-rtl.png
Binary files differ
diff --git a/modules/images/arrow-collapsed-rtl.svg
b/modules/images/arrow-collapsed-rtl.svg
new file mode 100644
index 0000000..5faf356
--- /dev/null
+++ b/modules/images/arrow-collapsed-rtl.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg"
width="16" height="16"><path d="M9.999 13.002l-5.001-5 5.001-5z"
fill="#797979"/></svg>
\ No newline at end of file
diff --git a/modules/images/arrow-expanded.png
b/modules/images/arrow-expanded.png
new file mode 100644
index 0000000..0221028
--- /dev/null
+++ b/modules/images/arrow-expanded.png
Binary files differ
diff --git a/modules/images/arrow-expanded.svg
b/modules/images/arrow-expanded.svg
new file mode 100644
index 0000000..e744ec3
--- /dev/null
+++ b/modules/images/arrow-expanded.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg"
width="16" height="16"><path d="M13.002 6.001l-5 5.001-5-5.001z"
fill="#797979"/></svg>
\ No newline at end of file
diff --git a/modules/images/edit-faded.png b/modules/images/edit-faded.png
new file mode 100644
index 0000000..1e2e5d8
--- /dev/null
+++ b/modules/images/edit-faded.png
Binary files differ
diff --git a/modules/images/edit.png b/modules/images/edit.png
new file mode 100644
index 0000000..fe28125
--- /dev/null
+++ b/modules/images/edit.png
Binary files differ
diff --git a/modules/images/portal-break.png b/modules/images/portal-break.png
new file mode 100644
index 0000000..10cd7f8
--- /dev/null
+++ b/modules/images/portal-break.png
Binary files differ
diff --git a/switchExperimentPrefs.php b/switchExperimentPrefs.php
new file mode 100644
index 0000000..82ddd86
--- /dev/null
+++ b/switchExperimentPrefs.php
@@ -0,0 +1,63 @@
+<?php
+
+$path = '../..';
+
+if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
+ $path = getenv( 'MW_INSTALL_PATH' );
+}
+
+require_once( $path . '/maintenance/Maintenance.php' );
+
+class SwitchExperimentPrefs extends Maintenance {
+ function __construct() {
+ parent::__construct();
+ $this->addOption( 'pref', 'Preference to set', true, true );
+ $this->addOption( 'value', 'Value to set the preference to',
true, true );
+ $this->mDescription = 'Set a preference for all users that have
the vector-noexperiments preference enabled.';
+ }
+
+ function execute() {
+ $dbw = wfGetDB( DB_MASTER );
+
+ $batchSize = 100;
+ $total = 0;
+ $lastUserID = 0;
+ while ( true ) {
+ $res = $dbw->select( 'user_properties', array(
'up_user' ),
+ array( 'up_property' => 'vector-noexperiments',
"up_user > $lastUserID" ),
+ __METHOD__,
+ array( 'LIMIT' => $batchSize ) );
+ if ( !$res->numRows() ) {
+ $dbw->commit();
+ break;
+ }
+ $total += $res->numRows();
+
+ $ids = array();
+ foreach ( $res as $row ) {
+ $ids[] = $row->up_user;
+ }
+ $lastUserID = max( $ids );
+
+
+ foreach ( $ids as $id ) {
+ $user = User::newFromId( $id );
+ if ( !$user->isLoggedIn() )
+ continue;
+ $user->setOption( $this->getOption( 'pref' ),
$this->getOption( 'value' ) );
+ $user->saveSettings();
+ }
+
+ echo "$total\n";
+
+ wfWaitForSlaves(); // Must be
wfWaitForSlaves_masterPos(); on 1.17wmf1
+ }
+ echo "Done\n";
+
+ }
+}
+
+$maintClass = 'SwitchExperimentPrefs';
+require_once( RUN_MAINTENANCE_IF_MAIN );
+
+
--
To view, visit https://gerrit.wikimedia.org/r/169787
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I14acfc38a98036e391fa5b8cc6bb916ffd8bb8d3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CollapsibleVector
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits