Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92597
Change subject: (DRAFT) stash from review conversation
......................................................................
(DRAFT) stash from review conversation
Change-Id: I300b3b38e3432882b06626ca597c39da175a83da
---
M MultimediaViewerHooks.php
M js/ext.multimediaViewer.js
2 files changed, 49 insertions(+), 45 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer
refs/changes/97/92597/1
diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php
index 9d8bb7b..78caf19 100644
--- a/MultimediaViewerHooks.php
+++ b/MultimediaViewerHooks.php
@@ -8,7 +8,7 @@
* (at your option) any later version.
*
* MultimediaViewer is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
@@ -25,18 +25,22 @@
/*
* Handler for BeforePageDisplay hook
+ *
* Add JavaScript to the page when an image is on it
- * and the user has enabled the feature if BetaFeatures is installed
+ * and the user has enabled the feature if BetaFeatures is installed.
+ *
* @param OutputPage $out
* @param Skin $skin
* @return bool
*/
static function getModules( &$out, &$skin ) {
if ( class_exists( 'BetaFeatures')
- && !BetaFeatures::isFeatureEnabled( $out->getUser(),
'multimedia-viewer' ) ) {
+ && !BetaFeatures::isFeatureEnabled( $out->getUser(),
'multimedia-viewer' )
+ ) {
return true;
}
- if ( count( $out->getFileSearchOptions() ) > 0 ) {
+
+ if ( count( $out->getFileSearchOptions() ) ) {
$out->addModules( array( 'ext.multimediaViewer' ) );
}
diff --git a/js/ext.multimediaViewer.js b/js/ext.multimediaViewer.js
index 2c39791..46a664d 100755
--- a/js/ext.multimediaViewer.js
+++ b/js/ext.multimediaViewer.js
@@ -16,7 +16,9 @@
*/
( function ( mw, $ ) {
- var MultiLightbox, LightboxImage, lightboxHooks,
+ var MultiLightbox = window.MultiLightbox,
+ LightboxImage = window.LightboxImage,
+ lightboxHooks = window.lightboxHooks,
validExtensions = {
'jpg': true,
'jpeg': true,
@@ -95,33 +97,41 @@
viewer.lightbox.open();
viewer.fetchImageInfo( fileTitle, function (
imageInfo ) {
- function whitelistHtml( $ele ) {
- function test( $ele ) {
- return $ele.jquery && (
- $ele.is( 'a' )
||
- false
- );
- }
+ var extmeta,
+ repoInfo, articlePath,
+ desc,
+ datetime, dtmsg,
+ username,
+ source, author,
+ ui = viewer.lightbox.iface,
+ innerInfo =
imageInfo.imageinfo[0] || {};
+ function whitelistHtml( $ele ) {
var $children,
whitelisted = '';
- if ( $ele && $ele.jquery &&
$ele.contents ) {
- $children =
$ele.contents();
- } else if ( $ele &&
$ele.textContent ) {
- return $ele.textContent;
- } else if ( $ele ) {
- return $ele;
+ function test( $ele ) {
+ return $ele.is( 'a' );
}
- if ( !$children ||
$children.length === 0 ) {
+ if ( $ele ) {
+ if ( $ele.jquery ) {
+ $children =
$ele.contents();
+ } else if (
$ele.textContent ) {
+ return
$ele.textContent;
+ } else {
+ return $ele;
+ }
+ }
+
+ if ( !$children ||
!$children.length ) {
return $ele.text();
}
$children.each( function ( i,
ele ) {
var $ele = $( ele );
- if ( test( $ele ) ===
true ) {
+ if ( test( $ele ) ) {
whitelisted +=
$ele.html( whitelistHtml( $ele ) ).get( 0 ).outerHTML;
} else {
whitelisted +=
'<span>' + whitelistHtml( $ele ) + '</span>';
@@ -148,15 +158,6 @@
ui.$usernameLi.toggleClass(
'empty', !Boolean( username ) );
}
-
- var extmeta,
- repoInfo, articlePath,
- desc,
- datetime, dtmsg,
- username,
- source, author,
- ui = viewer.lightbox.iface,
- innerInfo =
imageInfo.imageinfo[0] || {};
viewer.lightbox.images[index].src =
innerInfo.url;
viewer.lightbox.open();
@@ -292,17 +293,17 @@
} );
} );
- if ( $thumbs.length > 0 ) {
+ if ( $thumbs.length ) {
this.lightbox = new MultiLightbox( urls );
}
lightboxHooks.register( 'imageLoaded', function () {
// Add link wrapper to the image div, put image inside
it
this.$imageLink = $( '<a>' )
- .addClass( 'mw-mlb-image-link' )
- .html( this.$image.detach() );
+ .addClass( 'mw-mlb-image-link' )
+ .append( this.$image );
- this.$imageDiv.append( this.$imageLink );
+ this.$imageDiv.append( this.$imageLink );
} );
lightboxHooks.register( 'modifyInterface', function () {
@@ -313,7 +314,7 @@
this.$imageDescDiv = $( '<div>' )
.addClass( 'mw-mlb-image-desc-div' )
- .html( this.$imageDesc );
+ .append( this.$imageDesc );
this.$imageLinks = $( '<ul>' )
.addClass( 'mw-mlb-image-links' );
@@ -324,8 +325,7 @@
this.$imageMetadata = $( '<div>' )
.addClass( 'mw-mlb-image-metadata' )
- .html( this.$imageDescDiv )
- .append( this.$imageLinkDiv );
+ .append( this.$imageDescDiv, this.$imageLinkDiv
);
this.$postDiv.append( this.$imageMetadata );
@@ -334,8 +334,7 @@
.prop( 'href', '#' );
this.$repoLi = $( '<li>' )
- .addClass( 'mw-mlb-repo-li' )
- .addClass( 'empty' )
+ .addClass( 'mw-mlb-repo-li empty' )
.append( this.$repo );
this.$imageLinks.append( this.$repoLi );
@@ -421,6 +420,9 @@
} );
}
+ /**
+ * @param {Function} cb
+ */
MultimediaViewer.prototype.fetchRepoInfo = function ( cb ) {
var viewer = this;
@@ -431,7 +433,7 @@
action: 'query',
format: 'json',
meta: 'filerepoinfo'
- }, function ( data ) {
+ } ).done( function ( data ) {
if ( !data || !data.query ) {
// Damn, failure. Do it gracefully-ish.
cb( {} );
@@ -444,6 +446,9 @@
}
};
+ /**
+ * @param {Array} [repos] Optional?
+ */
MultimediaViewer.prototype.setRepoInfo = function ( repos ) {
var i, repo;
@@ -551,12 +556,7 @@
};
$( function () {
- MultiLightbox = window.MultiLightbox;
- LightboxImage = window.LightboxImage;
- lightboxHooks = window.lightboxHooks;
-
- var viewer = new MultimediaViewer();
- mw.mediaViewer = viewer;
+ mw.mediaViewer = new MultimediaViewer();
} );
mw.MultimediaViewer = MultimediaViewer;
--
To view, visit https://gerrit.wikimedia.org/r/92597
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I300b3b38e3432882b06626ca597c39da175a83da
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits