Skip to content

Commit 4d333d6

Browse files
committed
Merge pull request #717 from Martii/Issue-285LocalizationOfMeta
Localization of metadata blocks Auto-merge... dry run with migration on local pro and seems good to go... already did my account... taking production down to do this.
2 parents 861ba18 + ad08b6f commit 4d333d6

File tree

10 files changed

+305
-281
lines changed

10 files changed

+305
-281
lines changed

controllers/script.js

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ var getScriptPageTasks = function (aOptions) {
5050
var authedUser = aOptions.authedUser;
5151

5252
// Intermediates
53-
var homepagesURL = null;
54-
var copyrights = null;
55-
var licenses = null;
56-
var collaborators = null;
53+
var homepageURL = null;
54+
var copyright = null;
55+
var license = null;
56+
var author = null;
57+
var collaborator = null;
5758

5859
// Temporaries
5960
var htmlStub = null;
@@ -93,79 +94,55 @@ var getScriptPageTasks = function (aOptions) {
9394
});
9495

9596
// Show homepages of the script
96-
homepagesURL = scriptStorage.findMeta(script.meta, 'homepageURL');
97-
if (homepagesURL) {
98-
if (typeof homepagesURL === 'string') {
99-
htmlStub = '<a href="' + homepagesURL + '"></a>';
97+
homepageURL = scriptStorage.findMeta(script.meta, 'UserScript.homepageURL');
98+
if (homepageURL) {
99+
aOptions.script.homepages = [];
100+
homepageURL.forEach(function (aElement, aIndex, aArray) {
101+
htmlStub = '<a href="' + aElement.value + '"></a>';
100102
if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) {
101-
aOptions.script.homepages = [{
102-
url: homepagesURL,
103-
text: decodeURI(homepagesURL),
103+
aOptions.script.homepages.unshift({
104+
url: aElement.value,
105+
text: decodeURI(aElement.value),
104106
hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org\//i.
105-
test(homepagesURL)
106-
}];
107+
test(aElement.value)
108+
});
107109
}
108-
} else {
109-
aOptions.script.homepages = [];
110-
homepagesURL.forEach(function (aHomepage) {
111-
htmlStub = '<a href="' + aHomepage + '"></a>';
112-
if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) {
113-
aOptions.script.homepages.unshift({
114-
url: aHomepage,
115-
text: decodeURI(aHomepage),
116-
hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org/i.test(aHomepage)
117-
});
118-
}
119-
});
120-
}
110+
});
121111
}
122112

123113
// Show copyrights of the script
124-
copyrights = scriptStorage.findMeta(script.meta, 'copyright');
125-
if (copyrights) {
126-
if (typeof copyrights === 'string') {
127-
aOptions.script.copyrights = [{ name: copyrights }];
128-
} else {
129-
aOptions.script.copyrights = [];
130-
copyrights.forEach(function (aCopyright) {
131-
aOptions.script.copyrights.unshift({ name: aCopyright });
132-
});
133-
}
114+
copyright = scriptStorage.findMeta(script.meta, 'UserScript.copyright');
115+
if (copyright) {
116+
aOptions.script.copyrights = [];
117+
copyright.forEach(function (aElement, aIndex, aArray) {
118+
aOptions.script.copyrights.unshift({ name: aElement.value });
119+
});
134120
}
135121

136122
// Show licensings of the script
137-
licenses = scriptStorage.findMeta(script.meta, 'license');
138-
if (licenses) {
139-
if (typeof licenses === 'string') {
140-
aOptions.script.licenses = [{ name: licenses }];
141-
} else {
142-
aOptions.script.licenses = [];
143-
licenses.forEach(function (aLicense) {
144-
aOptions.script.licenses.unshift({ name: aLicense });
145-
});
146-
}
123+
license = scriptStorage.findMeta(script.meta, 'UserScript.license');
124+
if (license) {
125+
aOptions.script.licenses = [];
126+
license.forEach(function (aElement, aIndex, aArray) {
127+
aOptions.script.licenses.unshift({ name: aElement.value });
128+
});
147129
} else if (!script.isLib) {
148130
aOptions.script.licenses = [{ name: 'MIT License (Expat)' }];
149131
}
150132

151133
// Show collaborators of the script
152-
153-
collaborators = scriptStorage.findMeta(script.meta, 'oujs.collaborator');
154-
if (scriptStorage.findMeta(script.meta, 'oujs.author') && collaborators) {
155-
134+
author = scriptStorage.findMeta(script.meta, 'OpenUserJS.author.0.value');
135+
collaborator = scriptStorage.findMeta(script.meta, 'OpenUserJS.collaborator');
136+
if (author && collaborator) {
156137
aOptions.hasCollab = true;
157-
if (typeof collaborators === 'string') {
158-
aOptions.script.collaborators = [{
159-
url: encodeURIComponent(collaborators),
160-
text: collaborators }];
161-
} else {
162-
aOptions.script.collaborators = [];
163-
collaborators.forEach(function (aCollaborator) {
164-
aOptions.script.collaborators.unshift({
165-
url: encodeURIComponent(aCollaborator),
166-
text: aCollaborator });
138+
139+
aOptions.script.collaborators = [];
140+
collaborator.forEach(function (aElement, aIndex, aArray) {
141+
aOptions.script.collaborators.unshift({
142+
url: encodeURIComponent(aElement.value),
143+
text: aElement.value
167144
});
168-
}
145+
});
169146
}
170147

171148
// Show which libraries hosted on the site a script uses
@@ -339,7 +316,7 @@ exports.view = function (aReq, aRes, aNext) {
339316
function preRender() {
340317
if (script.groups) {
341318
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Scripts')],
342-
scriptStorage.findMeta(script.meta, 'description'), _.pluck(script.groups, 'name'));
319+
script.description, _.pluck(script.groups, 'name'));
343320
}
344321
}
345322
function render() { aRes.render('pages/scriptPage', options); }
@@ -368,7 +345,7 @@ exports.view = function (aReq, aRes, aNext) {
368345

369346
// Page metadata
370347
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Scripts')],
371-
scriptStorage.findMeta(script.meta, 'description'));
348+
script.description);
372349
options.isScriptPage = true;
373350

374351
// SearchBar

0 commit comments

Comments
 (0)