https://bugzilla.wikimedia.org/show_bug.cgi?id=30803

--- Comment #12 from Krinkle <[email protected]> ---
(Reviewing attachment 9039)
>--- mediawiki.util.js
>+++ mediawiki.util.js
>@@ -110,7 +110,17 @@
>               },
> 
>               /**
>-               * Encode page titles for use in a URL
>+               * Decode the string like PHP's rawurldecode
>+               *
>+               * @param str {String} String to be decoded
>+               */
>+              'rawurldecode' : function( str ) {
>+                      str = ( str + '' ).toString();
>+                      return decodeURIComponent( str );


This doesn't make sense. This is triple conversion to string:
* + ''
* toString
* [internal] decodeURIComponent casts value `str = String(value)`

Suggest to use String(str) (not `new String`) instead of '' and/or toString
So just `return decodeURIComponent( String( str ) );`

>+              },
>+
>+              /**
>                * Get the link to a page name (relative to wgServer)
>                */
>-              'wikiGetlink' : function( str ) {
>-                      return mw.config.get( 'wgArticlePath' ).replace( '$1',
>-                              this.wikiUrlencode( str || mw.config.get( 
>'wgPageName' ) ) );
>+              'wikiGetlink' : function( page, params ) {
>+                      var url, query;
>+                      if ( $.isPlainObject( page ) ) {
>+                              params = page;
>+                              page = params.title || mw.config.get( 
>'wgPageName' );
>+                      } else if ( !page ) {
>+                              page = mw.config.get( 'wgPageName' );
>+                      }
>+                      query = $.extend( params || {} , {} );
>+                      if ( 'title' in query ) {
>+                              delete query.title;
>+                      }
>+                      if ( $.isEmptyObject( query ) ) {
>+                              return mw.config.get( 'wgArticlePath' 
>).replace( '$1', this.wikiUrldecode( page ) );

Why is this decoding the page parameter? This is a url, it should be encoded.

>+                      }
>+                      if ( 'action' in query ) {
>+                              url = mw.config.get( 'wgActionPaths', {} )[ 
>query.action ];
>+                              if ( url ) {
>+                                      url = url.replace( '$1', 
>this.wikiUrldecode( page ) ) + '?';

Why is this decoding the page parameter? It should be encoded instead of
decoded.

>+                                      delete query.action;
>+                              }
>+                      }
>+                      if ( !url ) {
>+                              url = mw.config.get( 'wgScript' ) + '?title=' + 
>this.wikiUrlencode( page ) + '&';
>+                      }
>+                      return url + $.param( query );
>               },
> 
>               /**

* The wikiUrldecode method appears to be unneeded.
* Needs unit tests.

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to