Index: trunk/phase3/resources/mediawiki.page/mediawiki.page.ajaxCategories.js |
— | — | @@ -35,6 +35,23 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
| 39 | + * Generates a random id out of 62 alpha-numeric characters. |
| 40 | + * |
| 41 | + * @param {Number} Length of id (optional, defaults to 32) |
| 42 | + * @return {String} |
| 43 | + */ |
| 44 | + function generateRandomId( idLength ) { |
| 45 | + idLength = typeof idLength === 'number' ? idLength : 32; |
| 46 | + var seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', |
| 47 | + id = ''; |
| 48 | + for ( var r, i = 0; i < idLength; i++ ) { |
| 49 | + r = Math.floor( Math.random() * seed.length ); |
| 50 | + id += seed.substring( r, r + 1 ); |
| 51 | + } |
| 52 | + return id; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
39 | 56 | * Helper function for $.fn.suggestions |
40 | 57 | * |
41 | 58 | * @context {jQuery} |
— | — | @@ -872,7 +889,7 @@ |
873 | 890 | var token = data.edittoken, |
874 | 891 | timestamp = data.revisions[0].timestamp, |
875 | 892 | oldText = data.revisions[0]['*'], |
876 | | - nowikiKey = mw.user.generateId(), // Unique ID for nowiki replacement |
| 893 | + nowikiKey = generateRandomId(), // Unique ID for nowiki replacement |
877 | 894 | nowikiFragments = []; // Nowiki fragments will be stored here during the changes |
878 | 895 | |
879 | 896 | // Replace all nowiki parts with unique keys.. |