http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88140
Revision: 88140
Author: janpaul123
Date: 2011-05-15 10:16:07 +0000 (Sun, 15 May 2011)
Log Message:
-----------
* Basic gallery functionality
* Basic error messages
This still needs major cleanup but I wanted to commit this huge thing first.
Modified Paths:
--------------
trunk/extensions/WikiLove/README
trunk/extensions/WikiLove/WikiLove.i18n.php
trunk/extensions/WikiLove/WikiLove.php
trunk/extensions/WikiLove/wikiLove.css
trunk/extensions/WikiLove/wikiLove.js
Modified: trunk/extensions/WikiLove/README
===================================================================
--- trunk/extensions/WikiLove/README 2011-05-15 09:54:31 UTC (rev 88139)
+++ trunk/extensions/WikiLove/README 2011-05-15 10:16:07 UTC (rev 88140)
@@ -1,5 +1,5 @@
-WikiLove is an extension designed to promote the spread of WikiLove within
-Wikipedia.
+WikiLove is an extension designed to promote the spread of WikiLove,
+message of positive reinforcement that users can send to each other.
See documentation at the MediaWiki wiki:
http://www.mediawiki.org/wiki/Extension:WikiLove
Modified: trunk/extensions/WikiLove/WikiLove.i18n.php
===================================================================
--- trunk/extensions/WikiLove/WikiLove.i18n.php 2011-05-15 09:54:31 UTC (rev
88139)
+++ trunk/extensions/WikiLove/WikiLove.i18n.php 2011-05-15 10:16:07 UTC (rev
88140)
@@ -24,6 +24,7 @@
'wikilove-get-started-list-2' => 'Add details to your WikiLove',
'wikilove-get-started-list-3' => 'Send your WikiLove!',
'wikilove-add-details' => 'Add details',
+ 'wikilove-gallery' => 'Picture:',
'wikilove-title' => 'Title:',
'wikilove-enter-message' => 'Enter a message:',
'wikilove-omit-sig' => '(without a signature)',
@@ -31,5 +32,9 @@
'wikilove-preview' => 'Preview',
'wikilove-button-send' => 'Send WikiLove',
'wikilove-type-makeyourown' => 'Make your own',
+ 'wikilove-err-title' => 'Please enter a title.',
+ 'wikilove-err-msg' => 'Please enter a message.',
+ 'wikilove-err-image' => 'Please select an image.',
+ 'wikilove-err-sig' => 'Please do not include a signature in the
message.',
);
Modified: trunk/extensions/WikiLove/WikiLove.php
===================================================================
--- trunk/extensions/WikiLove/WikiLove.php 2011-05-15 09:54:31 UTC (rev
88139)
+++ trunk/extensions/WikiLove/WikiLove.php 2011-05-15 10:16:07 UTC (rev
88140)
@@ -88,6 +88,7 @@
'wikilove-get-started-list-2',
'wikilove-get-started-list-3',
'wikilove-add-details',
+ 'wikilove-gallery',
'wikilove-title',
'wikilove-enter-message',
'wikilove-omit-sig',
@@ -95,6 +96,10 @@
'wikilove-preview',
'wikilove-button-send',
'wikilove-type-makeyourown',
+ 'wikilove-err-title',
+ 'wikilove-err-msg',
+ 'wikilove-err-image',
+ 'wikilove-err-sig',
),
'dependencies' => array(
'jquery.ui.dialog',
Modified: trunk/extensions/WikiLove/wikiLove.css
===================================================================
--- trunk/extensions/WikiLove/wikiLove.css 2011-05-15 09:54:31 UTC (rev
88139)
+++ trunk/extensions/WikiLove/wikiLove.css 2011-05-15 10:16:07 UTC (rev
88140)
@@ -254,23 +254,45 @@
resize: none;
}
+#wikiLoveDialog #wlAddDetails #wlNotify {
+ float: left;
+}
+
#wikiLoveDialog .wlSpinner {
float: right;
margin-top: 6px;
display: none;
}
+/* add details gallery */
+#wikiLoveDialog #wlGallery img {
+ margin-right: 5px;
+ margin-bottom: 5px;
+ padding: 5px;
+}
+
+#wikiLoveDialog #wlGallery a:hover img,
+#wikiLoveDialog #wlGallery a:focus img {
+ background-color: #aacfe9;
+}
+
+#wikiLoveDialog #wlGallery a.selected img {
+ background-color: #f56427;
+}
+
/* dialog preview */
#wikiLoveDialog #wlPreview {
float: right;
width: 480px;
}
-#wikiLoveDialog #wlPreview div {
+#wikiLoveDialog #wlPreview #wlPreviewArea {
margin-left: 15px;
+ width: 465px;
+ overflow: auto;
}
-#wikiLoveDialog #wlPreview .editsection {
+#wikiLoveDialog #wlPreview #wlPreviewArea .editsection {
display: none;
}
Modified: trunk/extensions/WikiLove/wikiLove.js
===================================================================
--- trunk/extensions/WikiLove/wikiLove.js 2011-05-15 09:54:31 UTC (rev
88139)
+++ trunk/extensions/WikiLove/wikiLove.js 2011-05-15 10:16:07 UTC (rev
88140)
@@ -10,14 +10,14 @@
'original': {
title: 'An Original Barnstar for you!',
// subject title for the message
descr: 'Original barnstar', //
description in the menu
- text: '{{subst:The Original
Barnstar|$1}}', // message text, $1 is replaced by the user message
+ text: '{{subst:The Original Barnstar|$1
~~~~}}', // message text, $1 is replaced by the user message
template: 'The Original Barnstar', //
template that is used, for statistics
message: 'Hello '+wgTitle+'!\n\nI just
awarded you a barnstar.' // message to use in email notification
},
'special': {
title: null, // no predefined title,
allows the user to enter a title
descr: 'Special barnstar',
- text: '{{subst:The Special
Barnstarl|$1}}',
+ text: '{{subst:The Special Barnstarl|$1
~~~~}}',
template: 'The Special Barnstar',
message: 'Hello '+wgTitle+'!\n\nI just
awarded you the special barnstar.'
}
@@ -25,6 +25,18 @@
email: true, // add email notices as an option for each
award of this type
icon: mw.config.get( 'wgServer' ) + mw.config.get(
'wgScriptPath' ) +
'/extensions/WikiLove/images/icons/wikilove-icon-barnstar.png'
},
+ 'cat': {
+ descr: 'Cat',
+ title: null,
+ text: "[[$2|left|150px]]\n$1\n\n~~~~",
+ template: '',
+ gallery: {
+ category: 'Category:Tropical',
+ total: 100,
+ num: 3,
+ width: 150
+ }
+ },
// default type, nice to leave this one in place when adding
other types
'makeyourown': {
title: null,
@@ -40,6 +52,8 @@
currentTypeOrSubtype: null, // content of the current (sub)type (i.e.
an object with title, descr, text, etc.)
previewData: null, // data of the currently previewed thing is set here
emailable: false,
+ gallery: {},
+ imageTitle: '',
/*
* Opens the dialog and builds it if necessary.
@@ -115,7 +129,9 @@
.append( '<h3>' + mw.msg(
'wikilove-add-details' ) + '</h3>' )
.append( '<label for="wlSubtype"
id="wlSubtypeLabel"></label>' )
.append( $( '<form id="wlPreviewForm"></form>' )
- .append( '<select
id="wlSubtype"></select>' )
+ .append( '<select
id="wlSubtype"></select>' )
+ .append( '<label id="wlGalleryLabel">'
+ mw.msg( 'wikilove-gallery' ) + '</label>' )
+ .append( '<div id="wlGallery"/>' )
.append( '<label for="wlTitle"
id="wlTitleLabel">' + mw.msg( 'wikilove-title' ) + '</label>' )
.append( '<input type="text"
class="text" id="wlTitle"/>' )
.append( '<label for="wlMessage"
id="wlMessageLabel">' + mw.msg( 'wikilove-enter-message' ) + '</label>' )
@@ -273,6 +289,17 @@
$( '#wlTitle' ).show();
$( '#wlTitle' ).val( '' );
}
+
+ if( typeof $.wikiLove.currentTypeOrSubtype.gallery == 'object'
) {
+ $( '#wlGalleryLabel' ).show();
+ $( '#wlGallery' ).show();
+ $.wikiLove.makeGallery();
+ }
+ else {
+ $( '#wlGalleryLabel' ).hide();
+ $( '#wlGallery' ).hide();
+ }
+
if( $.wikiLove.types[$.wikiLove.currentTypeId].email ) {
$( '#wlNotify' ).show();
} else {
@@ -286,13 +313,28 @@
*/
submitPreview: function( e ) {
e.preventDefault();
+ if( $( '#wlTitle' ).val().length <= 0 ) {
+ $.wikiLove.showError( 'wikilove-err-title' ); return
false;
+ }
+ if( $( '#wlMessage' ).val().length <= 0 ) {
+ $.wikiLove.showError( 'wikilove-err-msg' ); return
false;
+ }
+
var title = '==' + $( '#wlTitle' ).val() + "==\n";
var rawMessage = $( '#wlMessage' ).val();
- // If there isn't a signature already in the message, add one
to the end.
- if ( rawMessage.indexOf( '~~~' ) == -1 ) {
- rawMessage += ' ~~~~';
+ // If there isn't a signature already in the message, throw an
error
+ if ( rawMessage.indexOf( '~~~' ) >= 0 ) {
+ $.wikiLove.showError( 'wikilove-err-sig' ); return
false;
}
var msg = $.wikiLove.currentTypeOrSubtype.text.replace( '$1',
rawMessage );
+ if( typeof $.wikiLove.currentTypeOrSubtype.gallery == 'object'
) {
+ if ( $.wikiLove.imageTitle ) {
+ msg = msg.replace( '$2', $.wikiLove.imageTitle
);
+ }
+ else {
+ $.wikiLove.showError( 'wikilove-err-img' );
return false;
+ }
+ }
$.wikiLove.doPreview( title + msg );
$.wikiLove.previewData = {
'title': title,
@@ -305,6 +347,10 @@
return false;
},
+ showError: function( errmsg ) {
+ $.wikiLove.showPreview( mw.msg( errmsg ) );
+ },
+
/*
* Fires AJAX request for previewing wikitext.
*/
@@ -396,6 +442,65 @@
});
},
+ makeGallery: function() {
+ $( '#wlGallery' ).html( '' );
+ $.wikiLove.gallery = {};
+ $.ajax({
+ url: mw.config.get( 'wgServer' ) + mw.config.get(
'wgScriptPath' ) + '/api.php?',
+ data: {
+ 'action' : 'query',
+ 'format' : 'json',
+ 'prop' : 'imageinfo',
+ 'iiprop' : 'mime|url',
+ 'iiurlwidth' :
$.wikiLove.currentTypeOrSubtype.gallery.width,
+ 'generator' : 'categorymembers',
+ 'gcmtitle' :
$.wikiLove.currentTypeOrSubtype.gallery.category,
+ 'gcmnamespace': 6,
+ 'gcmsort' : 'timestamp',
+ 'gcmlimit' :
$.wikiLove.currentTypeOrSubtype.gallery.total
+ },
+ dataType: 'json',
+ type: 'POST',
+ success: function( data ) {
+ $( '#wlGallery' ).html( '' );
+ $.wikiLove.gallery = {};
+ if( data.query) {
+ var keys = Object.keys(
data.query.pages );
+ for( var i=0;
i<$.wikiLove.currentTypeOrSubtype.gallery.num; i++ ) {
+ while( keys.length > 0 ) {
+ var id = Math.floor(
Math.random() * keys.length );
+ var page =
data.query.pages[keys[id]];
+ keys.splice(id, 1);
+ if(
page.imageinfo[0].mime.substr(0,5) == 'image' ) {
+ $img = $(
'<img/>' );
+ $img.attr(
'src', page.imageinfo[0].url );
+ $img.attr(
'width', $.wikiLove.currentTypeOrSubtype.gallery.width );
+ $( '#wlGallery'
).append(
+ $( '<a
href="#"></a>' )
+
.attr( 'id', 'wlGalleryImg' + i )
+
.append( $img )
+
.click( function( e ) {
+
e.preventDefault();
+
$( '#wlGallery a' ).removeClass( 'selected' );
+
$( this ).addClass( 'selected' );
+
$.wikiLove.imageTitle = $.wikiLove.gallery[$( this ).attr( 'id' )];
+
return false;
+
})
+ );
+
$.wikiLove.gallery['wlGalleryImg' + i] = page.title;
+ break;
+ }
+ }
+ }
+ }
+ if( $( '#wlGallery' ).html().length <= 0 ) {
+ $( '#wlGallery' ).hide();
+ $( '#wlGalleryTitle' ).hide();
+ }
+ }
+ });
+ },
+
/*
* Init function which is called upon page load. Binds the WikiLove
icon to opening the dialog.
*/
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs