Index: branches/hashar/prettyURL/resources/mediawiki.action/mediawiki.action.watch.ajax.js |
— | — | @@ -65,8 +65,8 @@ |
66 | 66 | var link = this; |
67 | 67 | $link |
68 | 68 | .data( 'icon', $link.closest( 'li' ).hasClass( 'icon' ) ) |
69 | | - .data( 'action', mw.util.getParamValue( 'action', link.href ) == 'unwatch' ? 'unwatch' : 'watch' ); |
70 | | - var title = mw.util.getParamValue( 'title', link.href ); |
| 69 | + .data( 'action', mw.util.getActionFrom( link.href ) == 'unwatch' ? 'unwatch' : 'watch' ); |
| 70 | + var title = mw.util.getTitleFrom( link.href ); |
71 | 71 | $link.data( 'target', title.replace( /_/g, ' ' ) ); |
72 | 72 | }); |
73 | 73 | |
Index: branches/hashar/prettyURL/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -209,6 +209,12 @@ |
210 | 210 | /** |
211 | 211 | * Grab the URL parameter value for the given parameter. |
212 | 212 | * Returns null if not found. |
| 213 | + * Beware! When action paths are enabled (wgActionPaths) using this function |
| 214 | + * to retrieve the 'action' or 'title' parameter will probably fail since |
| 215 | + * those parameters are hidden in the path. |
| 216 | + * To safely query for: |
| 217 | + * 'action' use getActionFrom( url ) |
| 218 | + * 'title' use getTitleFrom( url ) |
213 | 219 | * |
214 | 220 | * @param param The parameter name |
215 | 221 | * @param url URL to search through (optional) |
— | — | @@ -224,6 +230,63 @@ |
225 | 231 | return null; |
226 | 232 | }, |
227 | 233 | |
| 234 | + /** |
| 235 | + * Try to find the wiki action for a given URL with actions paths support |
| 236 | + * |
| 237 | + * @param url URL to search for a wiki action |
| 238 | + */ |
| 239 | + 'getActionFrom' : function( url ) { |
| 240 | + // attempt to get the action from the parameter [&?]action= |
| 241 | + var action = mw.util.getParamValue( 'action', url ); |
| 242 | + if( action !== null ) { |
| 243 | + return action; |
| 244 | + } |
| 245 | + |
| 246 | + // now from the action paths |
| 247 | + var actionPaths = mw.config.get( 'wgActionPaths' ); |
| 248 | + if( actionPaths.length == 0 ) { |
| 249 | + actionPaths['view'] = mw.config.get( 'wgArticlePath' ); |
| 250 | + } |
| 251 | + var action = ''; |
| 252 | + for ( action in actionPaths ) { |
| 253 | + var actionRe = new RegExp( actionPaths[action].replace( '$1', '.*?' ) ); |
| 254 | + if( url.match( actionRe ) ) { |
| 255 | + return action; |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + return null; |
| 260 | + }, |
| 261 | + |
| 262 | + /** |
| 263 | + * Try to find the wiki title for a given URL with actions paths support |
| 264 | + * |
| 265 | + * @param url URL to search for a title |
| 266 | + */ |
| 267 | + 'getTitleFrom' : function( url ) { |
| 268 | + // attempt to get the title from the parameter [&?]title= |
| 269 | + var title = mw.util.getParamValue( 'title', url ); |
| 270 | + if( title !== null ) { |
| 271 | + return title; |
| 272 | + } |
| 273 | + |
| 274 | + // now from the action paths |
| 275 | + var actionPaths = mw.config.get( 'wgActionPaths' ); |
| 276 | + if( actionPaths.length == 0 ) { |
| 277 | + actionPaths['view'] = mw.config.get( 'wgArticlePath' ); |
| 278 | + } |
| 279 | + var action = ''; |
| 280 | + for ( action in actionPaths ) { |
| 281 | + var actionRe = new RegExp( '.*' + actionPaths[action].replace( '$1', '([^&?#]+)' ) ); |
| 282 | + var title = url.match( actionRe ); |
| 283 | + if( title !== null ) { |
| 284 | + return title[1]; |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + return null; |
| 289 | + }, |
| 290 | + |
228 | 291 | // Access key prefix. |
229 | 292 | // Will be re-defined based on browser/operating system detection in |
230 | 293 | // mw.util.init(). |
— | — | @@ -577,4 +640,4 @@ |
578 | 641 | |
579 | 642 | mw.util.init(); |
580 | 643 | |
581 | | -} )( jQuery, mediaWiki ); |
\ No newline at end of file |
| 644 | +} )( jQuery, mediaWiki ); |