Jhernandez has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/337829 )

Change subject: Hygiene: Remove unnecessary IIFE in processLinks.js
......................................................................

Hygiene: Remove unnecessary IIFE in processLinks.js

Change-Id: Icd6ab0a9b0a189c19310915cb77f861459aecddf
---
M src/processLinks.js
1 file changed, 77 insertions(+), 79 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/29/337829/1

diff --git a/src/processLinks.js b/src/processLinks.js
index 636a687..3ee2ee2 100644
--- a/src/processLinks.js
+++ b/src/processLinks.js
@@ -1,89 +1,87 @@
-( function ( mw, $ ) {
+var mw = window.mediaWiki;
 
-       /**
-        * @private
-        *
-        * Gets the title of a local page from an href given some configuration.
-        *
-        * @param {String} href
-        * @param {mw.Map} config
-        * @return {String|undefined}
-        */
-       function getTitle( href, config ) {
-               var linkHref,
-                       matches,
-                       queryLength,
-                       titleRegex = new RegExp( mw.RegExp.escape( config.get( 
'wgArticlePath' ) )
-                               .replace( '\\$1', '(.+)' ) );
+/**
+ * @private
+ *
+ * Gets the title of a local page from an href given some configuration.
+ *
+ * @param {String} href
+ * @param {mw.Map} config
+ * @return {String|undefined}
+ */
+function getTitle( href, config ) {
+       var linkHref,
+               matches,
+               queryLength,
+               titleRegex = new RegExp( mw.RegExp.escape( config.get( 
'wgArticlePath' ) )
+                       .replace( '\\$1', '(.+)' ) );
 
-               // Skip every URI that mw.Uri cannot parse
-               try {
-                       linkHref = new mw.Uri( href );
-               } catch ( e ) {
-                       return undefined;
-               }
-
-               // External links
-               if ( linkHref.host !== location.hostname ) {
-                       return undefined;
-               }
-
-               queryLength = Object.keys( linkHref.query ).length;
-
-               // No query params (pretty URL)
-               if ( !queryLength ) {
-                       matches = titleRegex.exec( linkHref.path );
-                       return matches ? decodeURIComponent( matches[ 1 ] ) : 
undefined;
-               } else if ( queryLength === 1 && linkHref.query.hasOwnProperty( 
'title' ) ) {
-                       // URL is not pretty, but only has a `title` parameter
-                       return linkHref.query.title;
-               }
-
+       // Skip every URI that mw.Uri cannot parse
+       try {
+               linkHref = new mw.Uri( href );
+       } catch ( e ) {
                return undefined;
        }
 
-       /**
-        * Processes and returns link elements (or "`<a>`s") that are eligible 
for
-        * previews in a given container.
-        *
-        * An `<a>` is eligible for a preview if:
-        *
-        * * It has an href and a title, i.e. `<a href="/wiki/Foo" title="Foo" 
/>`.
-        * * It doesn't have any blacklisted CSS classes.
-        * * Its href is a valid URI of a page on the local wiki.
-        *
-        * If an `<a>` is eligible, then the title of the page on the local 
wiki is
-        * stored in the `data-previews-page-title` attribute for later reuse.
-        *
-        * @param {jQuery} $container
-        * @param {String[]} blacklist If an `<a>` has one or more of these CSS
-        *  classes, then it will be ignored.
-        * @param {mw.Map} config
-        *
-        * @return {jQuery}
-        */
-       module.exports = function ( $container, blacklist, config ) {
-               var contentNamespaces;
+       // External links
+       if ( linkHref.host !== location.hostname ) {
+               return undefined;
+       }
 
-               contentNamespaces = config.get( 'wgContentNamespaces' );
+       queryLength = Object.keys( linkHref.query ).length;
 
-               return $container
-                       .find( 'a[href][title]:not(' + blacklist.join( ', ' ) + 
')' )
-                       .filter( function () {
-                               var title,
-                                       titleText = getTitle( this.href, config 
);
+       // No query params (pretty URL)
+       if ( !queryLength ) {
+               matches = titleRegex.exec( linkHref.path );
+               return matches ? decodeURIComponent( matches[ 1 ] ) : undefined;
+       } else if ( queryLength === 1 && linkHref.query.hasOwnProperty( 'title' 
) ) {
+               // URL is not pretty, but only has a `title` parameter
+               return linkHref.query.title;
+       }
 
-                               if ( !titleText ) {
-                                       return false;
-                               }
-                               // Is titleText in a content namespace?
-                               title = mw.Title.newFromText( titleText );
-                               if ( title && ( $.inArray( title.namespace, 
contentNamespaces ) >= 0 ) ) {
-                                       $( this ).data( 'page-previews-title', 
titleText );
+       return undefined;
+}
 
-                                       return true;
-                               }
-                       } );
-       };
+/**
+ * Processes and returns link elements (or "`<a>`s") that are eligible for
+ * previews in a given container.
+ *
+ * An `<a>` is eligible for a preview if:
+ *
+ * * It has an href and a title, i.e. `<a href="/wiki/Foo" title="Foo" />`.
+ * * It doesn't have any blacklisted CSS classes.
+ * * Its href is a valid URI of a page on the local wiki.
+ *
+ * If an `<a>` is eligible, then the title of the page on the local wiki is
+ * stored in the `data-previews-page-title` attribute for later reuse.
+ *
+ * @param {jQuery} $container
+ * @param {String[]} blacklist If an `<a>` has one or more of these CSS
+ *  classes, then it will be ignored.
+ * @param {mw.Map} config
+ *
+ * @return {jQuery}
+ */
+module.exports = function ( $container, blacklist, config ) {
+       var contentNamespaces;
 
-}( mediaWiki, jQuery ) );
+       contentNamespaces = config.get( 'wgContentNamespaces' );
+
+       return $container
+               .find( 'a[href][title]:not(' + blacklist.join( ', ' ) + ')' )
+               .filter( function () {
+                       var title,
+                               titleText = getTitle( this.href, config );
+
+                       if ( !titleText ) {
+                               return false;
+                       }
+                       // Is titleText in a content namespace?
+                       title = mw.Title.newFromText( titleText );
+                       if ( title && ( $.inArray( title.namespace, 
contentNamespaces ) >= 0 ) ) {
+                               $( this ).data( 'page-previews-title', 
titleText );
+
+                               return true;
+                       }
+               } );
+};

-- 
To view, visit https://gerrit.wikimedia.org/r/337829
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd6ab0a9b0a189c19310915cb77f861459aecddf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to