From fa022cc96c4c24d779282a56fb5f3cd7624cb8a8 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sun, 4 Sep 2011 17:04:09 +0000 Subject: [PATCH] Add local generator function to account for revert of r93063 in r96236. --- .../mediawiki.page.ajaxCategories.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js index b7fe3c2ff1..916ec6b4a6 100644 --- a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js +++ b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js @@ -34,6 +34,23 @@ return ''; } + /** + * Generates a random id out of 62 alpha-numeric characters. + * + * @param {Number} Length of id (optional, defaults to 32) + * @return {String} + */ + function generateRandomId( idLength ) { + idLength = typeof idLength === 'number' ? idLength : 32; + var seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', + id = ''; + for ( var r, i = 0; i < idLength; i++ ) { + r = Math.floor( Math.random() * seed.length ); + id += seed.substring( r, r + 1 ); + } + return id; + } + /** * Helper function for $.fn.suggestions * @@ -872,7 +889,7 @@ mw.ajaxCategories.prototype = { var token = data.edittoken, timestamp = data.revisions[0].timestamp, oldText = data.revisions[0]['*'], - nowikiKey = mw.user.generateId(), // Unique ID for nowiki replacement + nowikiKey = generateRandomId(), // Unique ID for nowiki replacement nowikiFragments = []; // Nowiki fragments will be stored here during the changes // Replace all nowiki parts with unique keys.. -- 2.20.1