http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88787
Revision: 88787
Author: janpaul123
Date: 2011-05-25 13:48:19 +0000 (Wed, 25 May 2011)
Log Message:
-----------
Rewrite of module structure per comments by Krinkle
Modified Paths:
--------------
trunk/extensions/WikiLove/WikiLove.hooks.php
trunk/extensions/WikiLove/WikiLove.php
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js
Added Paths:
-----------
trunk/extensions/WikiLove/WikiLove.local.php
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js
Modified: trunk/extensions/WikiLove/WikiLove.hooks.php
===================================================================
--- trunk/extensions/WikiLove/WikiLove.hooks.php 2011-05-25 12:10:07 UTC
(rev 88786)
+++ trunk/extensions/WikiLove/WikiLove.hooks.php 2011-05-25 13:48:19 UTC
(rev 88787)
@@ -55,7 +55,7 @@
$title = self::getUserTalkPage( $skin->getTitle() );
if ( !is_null( $title ) ) {
$out->addModules( 'ext.wikiLove.icon' );
- $out->addModules( 'ext.wikiLove' );
+ $out->addModules( 'ext.wikiLove.init' );
}
return true;
}
Added: trunk/extensions/WikiLove/WikiLove.local.php
===================================================================
--- trunk/extensions/WikiLove/WikiLove.local.php
(rev 0)
+++ trunk/extensions/WikiLove/WikiLove.local.php 2011-05-25 13:48:19 UTC
(rev 88787)
@@ -0,0 +1,17 @@
+<?php
+/*
+ * Custom ResourceLoader module that loads a custom WikiLove.js per-wiki.
+ */
+class WikiLoveLocal extends ResourceLoaderWikiModule {
+ protected function getPages( ResourceLoaderContext $context ) {
+ return array(
+ 'MediaWiki:WikiLove.js' => array( 'type' =>
'script' ),
+ );
+ }
+
+ public function getDependencies() {
+ return array(
+ 'ext.wikiLove.startup',
+ );
+ }
+}
Property changes on: trunk/extensions/WikiLove/WikiLove.local.php
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/extensions/WikiLove/WikiLove.php
===================================================================
--- trunk/extensions/WikiLove/WikiLove.php 2011-05-25 12:10:07 UTC (rev
88786)
+++ trunk/extensions/WikiLove/WikiLove.php 2011-05-25 13:48:19 UTC (rev
88787)
@@ -56,6 +56,7 @@
// add autoload classes
$wgAutoloadClasses['WikiLoveApi'] = $dir . 'WikiLove.api.php';
$wgAutoloadClasses['WikiLoveHooks'] = $dir .
'WikiLove.hooks.php';
+$wgAutoloadClasses['WikiLoveLocal'] = $dir .
'WikiLove.local.php';
// i18n messages
$wgExtensionMessagesFiles['WikiLove'] = $dir . 'WikiLove.i18n.php';
@@ -81,7 +82,7 @@
'styles' => 'ext.wikiLove.icon.css',
'position' => 'top',
),
- 'ext.wikiLove' => $extWikiLoveTpl + array(
+ 'ext.wikiLove.startup' => $extWikiLoveTpl + array(
'scripts' => array(
'ext.wikiLove.core.js',
'ext.wikiLove.defaultOptions.js',
@@ -119,6 +120,20 @@
'jquery.localize',
),
),
+ 'ext.wikiLove.local' => array(
+ 'class' => 'WikiLoveLocal',
+ /* for information only, this is actually in the class!
+ 'dependencies' => array(
+ 'ext.wikiLove.startup',
+ ),
+ */
+ ),
+ 'ext.wikiLove.init' => $extWikiLoveTpl + array(
+ 'scripts' => 'ext.wikiLove.init.js',
+ 'dependencies' => array(
+ 'ext.wikiLove.local',
+ ),
+ ),
'jquery.elastic' => array(
'localBasePath' => dirname( __FILE__ ) .
'/modules/jquery.elastic',
'remoteExtPath' => 'WikiLove/modules/jquery.elastic',
Modified: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
===================================================================
--- trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
2011-05-25 12:10:07 UTC (rev 88786)
+++ trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
2011-05-25 13:48:19 UTC (rev 88787)
@@ -1,5 +1,7 @@
( function( $ ) { $.wikiLove = {
-
+
+ options: {}, // options modifiable by the user
+ optionsHook: function() { return {}; }, // hook that can be overridden
by the user to modify options
$dialog: null, // dialog jQuery object
currentTypeId: null, // id of the currently selected type (e.g.
'barnstar' or 'makeyourown')
currentSubtypeId: null, // id of the currently selected subtype (e.g.
'original' or 'special')
@@ -7,43 +9,30 @@
previewData: null, // data of the currently previewed thing is set here
emailable: false,
gallery: {},
- defaultText: '{| style="background-color: $5; border: 1px solid $6;"\n\
-|rowspan="2" style="vertical-align: middle; padding: 5px;" | [[Image:$3|$4]]\n\
-|style="font-size: x-large; padding: 3px; height: 1.5em;" | \'\'\'$2\'\'\'\n\
-|-\n\
-|style="vertical-align: middle; padding: 3px;" | $1 ~~~~\n\
-|}',
- defaultBackgroundColor: '#fdffe7',
- defaultBorderColor: '#fceb92',
- defaultImageSize: '100px',
/*
* Opens the dialog and builds it if necessary.
*/
openDialog: function() {
if ( $.wikiLove.$dialog === null ) {
- // Load local configuration
- var wikiLoveConfigUrl = wgServer + wgScript + '?' +
$.param( { 'title': 'MediaWiki:WikiLove.js', 'action': 'raw', 'ctype':
'text/javascript' } );
- mw.loader.load( wikiLoveConfigUrl );
-
// Test to see if the 'E-mail this user' link exists
$.wikiLove.emailable = $( '#t-emailuser' ).length ?
true : false;
// Build a type list like this:
var $typeList = $( '<ul id="mw-wikilove-types"></ul>' );
- for( var typeId in $.wikiLove.types ) {
+ for( var typeId in $.wikiLove.options.types ) {
var $button = $( '<a href="#"></a>' );
var $buttonInside = $( '<div
class="mw-wikilove-inside"></div>' );
- if( typeof $.wikiLove.types[typeId].icon ==
'string' ) {
+ if( typeof
$.wikiLove.options.types[typeId].icon == 'string' ) {
$buttonInside.append( '<div
class="mw-wikilove-icon-box"><img src="'
- + mw.html.escape(
$.wikiLove.types[typeId].icon ) + '"/></div>' );
+ + mw.html.escape(
$.wikiLove.options.types[typeId].icon ) + '"/></div>' );
}
else {
$buttonInside.addClass(
'mw-wikilove-no-icon' );
}
- $buttonInside.append( '<div
class="mw-wikilove-link-text">' + $.wikiLove.types[typeId].name + '</div>' );
+ $buttonInside.append( '<div
class="mw-wikilove-link-text">' + $.wikiLove.options.types[typeId].name +
'</div>' );
$button.append( '<div
class="mw-wikilove-left-cap"></div>');
$button.append( $buttonInside );
@@ -149,14 +138,14 @@
$( '#mw-wikilove-types a' ).removeClass( 'selected' );
$( this ).addClass( 'selected' ); // highlight the new
type in the menu
- if( typeof
$.wikiLove.types[$.wikiLove.currentTypeId].subtypes == 'object' ) {
+ if( typeof
$.wikiLove.options.types[$.wikiLove.currentTypeId].subtypes == 'object' ) {
// we're dealing with subtypes here
$.wikiLove.currentTypeOrSubtype = null; //
reset the (sub)type object until a subtype is selected
$( '#mw-wikilove-subtype' ).html( '' ); //
clear the subtype menu
- for( var subtypeId in
$.wikiLove.types[$.wikiLove.currentTypeId].subtypes ) {
+ for( var subtypeId in
$.wikiLove.options.types[$.wikiLove.currentTypeId].subtypes ) {
// add all the subtypes to the menu
while setting their subtype ids in jQuery data
- var subtype =
$.wikiLove.types[$.wikiLove.currentTypeId].subtypes[subtypeId];
+ var subtype =
$.wikiLove.options.types[$.wikiLove.currentTypeId].subtypes[subtypeId];
$( '#mw-wikilove-subtype' ).append(
$( '<option></option>' ).text(
subtype.option ).data( 'subtypeId', subtypeId )
);
@@ -164,13 +153,13 @@
$( '#mw-wikilove-subtype' ).show();
// change and show the subtype label depending
on the type
- $( '#mw-wikilove-subtype-label' ).text(
$.wikiLove.types[$.wikiLove.currentTypeId].select || mw.msg(
'wikilove-select-type' ) );
+ $( '#mw-wikilove-subtype-label' ).text(
$.wikiLove.options.types[$.wikiLove.currentTypeId].select || mw.msg(
'wikilove-select-type' ) );
$( '#mw-wikilove-subtype-label' ).show();
$.wikiLove.changeSubtype(); // update controls
depending on the currently selected (i.e. first) subtype
}
else {
// there are no subtypes, just use this type
for the current (sub)type
- $.wikiLove.currentTypeOrSubtype =
$.wikiLove.types[$.wikiLove.currentTypeId];
+ $.wikiLove.currentTypeOrSubtype =
$.wikiLove.options.types[$.wikiLove.currentTypeId];
$( '#mw-wikilove-subtype' ).hide();
$( '#mw-wikilove-subtype-label' ).hide();
$.wikiLove.updateAllDetails(); // update
controls depending on this type
@@ -190,7 +179,7 @@
var newSubtypeId = $( '#mw-wikilove-subtype option:selected'
).first().data( 'subtypeId' );
if( $.wikiLove.currentSubtypeId != newSubtypeId ) { // only
change stuff when a different subtype is selected
$.wikiLove.currentSubtypeId = newSubtypeId;
- $.wikiLove.currentTypeOrSubtype =
$.wikiLove.types[$.wikiLove.currentTypeId]
+ $.wikiLove.currentTypeOrSubtype =
$.wikiLove.options.types[$.wikiLove.currentTypeId]
.subtypes[$.wikiLove.currentSubtypeId];
$( '#mw-wikilove-subtype-description' ).html(
$.wikiLove.currentTypeOrSubtype.descr );
$.wikiLove.updateAllDetails();
@@ -293,7 +282,7 @@
}
var msg = $.wikiLove.prepareMsg(
- $.wikiLove.currentTypeOrSubtype.text ||
$.wikiLove.defaultText,
+ $.wikiLove.currentTypeOrSubtype.text ||
$.wikiLove.options.defaultText,
$.wikiLove.currentTypeOrSubtype.imageSize,
$.wikiLove.currentTypeOrSubtype.backgroundColor,
$.wikiLove.currentTypeOrSubtype.borderColor
@@ -332,9 +321,9 @@
msg = msg.replace( '$2', $( '#mw-wikilove-title' ).val() ); //
replace the title
msg = msg.replace( '$3', $( '#mw-wikilove-image' ).val() ); //
replace the image
- var myImageSize = imageSize || $.wikiLove.defaultImageSize;
- var myBackgroundColor = backgroundColor ||
$.wikiLove.defaultBackgroundColor;
- var myBorderColor = borderColor ||
$.wikiLove.defaultBorderColor;
+ var myImageSize = imageSize ||
$.wikiLove.options.defaultImageSize;
+ var myBackgroundColor = backgroundColor ||
$.wikiLove.options.defaultBackgroundColor;
+ var myBorderColor = borderColor ||
$.wikiLove.options.defaultBorderColor;
msg = msg.replace( '$4', myImageSize ); // replace the image
size
msg = msg.replace( '$5', myBackgroundColor ); // replace the
background color
@@ -580,17 +569,7 @@
}
});
},
-
- /*
- * Init function which is called upon page load. Binds the WikiLove
icon to opening the dialog.
- */
- init: function() {
- $( '#ca-wikilove a' ).click( function( e ) {
- $.wikiLove.openDialog();
- e.preventDefault();
- });
- }
};
-
-$( document ).ready( $.wikiLove.init );
} ) ( jQuery );
+
+mw.log( 'core loaded' );
\ No newline at end of file
Modified:
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js
===================================================================
---
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js
2011-05-25 12:10:07 UTC (rev 88786)
+++
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js
2011-05-25 13:48:19 UTC (rev 88787)
@@ -1,68 +1,80 @@
-$.wikiLove.types = {
- // example type, could be removed later (also no i18n)
- 'barnstar': {
- name: 'Barnstar', // name of the type (appears in the types
menu)
- select: 'Select a barnstar:', // subtype select label
- subtypes: { // some different subtypes
- // note that when not using subtypes you should use
these subtype options
- // for the top-level type
- 'original': {
- fields: [ 'notify' ], // fields to ask for in
form
- option: 'Original barnstar', // option listed
in the select list
- descr: 'This barnstar is given to recognize
particularly fine contributions to Wikipedia, to let people know that their
hard work is seen and appreciated.', // description
- header: 'A barnstar for you!', // header that
appears at the top of the talk page post (optional)
- title: 'The Original Barnstar', // title that
appears inside the award box (optional)
- image: 'Original Barnstar Hires.png', // image
for the award
- mail: 'Hello $7!\n\nI just awarded you a
barnstar.' // message to use in email notification; $7 is replaced by the
recipient's username
+$.wikiLove.optionsHook = function() { return {
+ defaultText: '{| style="background-color: $5; border: 1px solid $6;"\n\
+|rowspan="2" style="vertical-align: middle; padding: 5px;" | [[Image:$3|$4]]\n\
+|style="font-size: x-large; padding: 3px; height: 1.5em;" | \'\'\'$2\'\'\'\n\
+|-\n\
+|style="vertical-align: middle; padding: 3px;" | $1 ~~~~\n\
+|}',
+ defaultBackgroundColor: '#fdffe7',
+ defaultBorderColor: '#fceb92',
+ defaultImageSize: '100px',
+
+ types: {
+ // example type, could be removed later (also no i18n)
+ 'barnstar': {
+ name: 'Barnstar', // name of the type (appears in the
types menu)
+ select: 'Select a barnstar:', // subtype select label
+ subtypes: { // some different subtypes
+ // note that when not using subtypes you should
use these subtype options
+ // for the top-level type
+ 'original': {
+ fields: [ 'notify' ], // fields to ask
for in form
+ option: 'Original barnstar', // option
listed in the select list
+ descr: 'This barnstar is given to
recognize particularly fine contributions to Wikipedia, to let people know that
their hard work is seen and appreciated.', // description
+ header: 'A barnstar for you!', //
header that appears at the top of the talk page post (optional)
+ title: 'The Original Barnstar', //
title that appears inside the award box (optional)
+ image: 'Original Barnstar Hires.png',
// image for the award
+ mail: 'Hello $7!\n\nI just awarded you
a barnstar.' // message to use in email notification; $7 is replaced by the
recipient's username
+ },
+ 'editors': {
+ fields: [ 'notify' ],
+ option: 'Editor\'s barnstar',
+ descr: 'The Editor\'s Barnstar is
awarded to individuals who display particularly fine decisions in general
editing.',
+ header: 'A barnstar for you!',
+ title: 'The Editor\'s Barnstar',
+ image: 'Editors Barnstar Hires.png',
+ mail: 'Hello $7!\n\nI just awarded you
a barnstar.'
+ },
+ 'tireless': {
+ fields: [ 'title', 'notify' ],
+ option: 'Tireless contributor barnstar',
+ descr: 'The Tireless Contributor
Barnstar is awarded to especially tireless Wikipedians who contribute an
especially large body of work without sacrificing quality.',
+ header: 'A barnstar for you!',
+ title: 'Tireless contributor barnstar',
+ image: 'Tireless Contributor Barnstar
Hires.gif',
+ mail: 'Hello $7!\n\nI just awarded you
a barnstar.'
+ }
},
- 'editors': {
- fields: [ 'notify' ],
- option: 'Editor\'s barnstar',
- descr: 'The Editor\'s Barnstar is awarded to
individuals who display particularly fine decisions in general editing.',
- header: 'A barnstar for you!',
- title: 'The Editor\'s Barnstar',
- image: 'Editors Barnstar Hires.png',
- mail: 'Hello $7!\n\nI just awarded you a
barnstar.'
- },
- 'tireless': {
- fields: [ 'title', 'notify' ],
- option: 'Tireless contributor barnstar',
- descr: 'The Tireless Contributor Barnstar is
awarded to especially tireless Wikipedians who contribute an especially large
body of work without sacrificing quality.',
- header: 'A barnstar for you!',
- title: 'Tireless contributor barnstar',
- image: 'Tireless Contributor Barnstar
Hires.gif',
- mail: 'Hello $7!\n\nI just awarded you a
barnstar.'
+ icon: mw.config.get( 'wgServer' ) + mw.config.get(
'wgScriptPath' ) +
'/extensions/WikiLove/images/icons/wikilove-icon-barnstar.png' // icon for
left-side menu
+ },
+ 'puppy': {
+ name: 'Puppy',
+ fields: [ 'header' ],
+ header: 'A puppy for you!',
+ text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear:
both"/>', // custom text
+ gallery: {
+ // right now we can only query the local wiki
(not e.g. commons)
+ category: 'Category:Puppies',
+ total: 100, // total number of pictures to
retrieve, and to randomise
+ num: 3, // number of pictures to show from the
randomised set
+ width: 145 // width of each picture in pixels
in the interface (not in the template)
}
},
- icon: mw.config.get( 'wgServer' ) + mw.config.get(
'wgScriptPath' ) +
'/extensions/WikiLove/images/icons/wikilove-icon-barnstar.png' // icon for
left-side menu
- },
- 'puppy': {
- name: 'Puppy',
- fields: [ 'header' ],
- header: 'A puppy for you!',
- text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear:
both"/>', // custom text
- gallery: {
- // right now we can only query the local wiki (not e.g.
commons)
- category: 'Category:Puppies',
- total: 100, // total number of pictures to retrieve,
and to randomise
- num: 3, // number of pictures to show from the
randomised set
- width: 145 // width of each picture in pixels in the
interface (not in the template)
+ 'kitten': {
+ name: 'Kitten',
+ fields: [ 'header' ],
+ header: 'A kitten for you!',
+ text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear:
both"/>', // $3 is the image filename
+ gallery: {
+ imageList: ['File:Cucciolo gatto
Bibo.jpg','File:Kitten (06) by Ron.jpg','File:Kitten-stare.jpg'],
+ width: 145
+ }
+ },
+ // default type, nice to leave this one in place when adding
other types
+ 'makeyourown': {
+ name: mw.msg( 'wikilove-type-makeyourown' ),
+ fields: [ 'header', 'title', 'image', 'notify' ],
+ imageSize: '150px'
}
- },
- 'kitten': {
- name: 'Kitten',
- fields: [ 'header' ],
- header: 'A kitten for you!',
- text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear:
both"/>', // $3 is the image filename
- gallery: {
- imageList: ['File:Cucciolo gatto Bibo.jpg','File:Kitten
(06) by Ron.jpg','File:Kitten-stare.jpg'],
- width: 145
- }
- },
- // default type, nice to leave this one in place when adding other types
- 'makeyourown': {
- name: mw.msg( 'wikilove-type-makeyourown' ),
- fields: [ 'header', 'title', 'image', 'notify' ],
- imageSize: '150px'
}
-}
\ No newline at end of file
+}; };
\ No newline at end of file
Added: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js
===================================================================
--- trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js
(rev 0)
+++ trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js
2011-05-25 13:48:19 UTC (rev 88787)
@@ -0,0 +1,13 @@
+/*
+ * Init function which is called upon page load. Binds the WikiLove icon to
opening the dialog.
+ */
+
+$.wikiLove.init = function() {
+ $.wikiLove.options = $.wikiLove.optionsHook();
+ $( '#ca-wikilove a' ).click( function( e ) {
+ $.wikiLove.openDialog();
+ e.preventDefault();
+ });
+}
+
+$( document ).ready( $.wikiLove.init );
Property changes on:
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js
___________________________________________________________________
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs