Skip to content

Commit

Permalink
fix for data.warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kanasimi committed Nov 10, 2024
1 parent 482dd1e commit c750ab9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
5 changes: 3 additions & 2 deletions application/net/wiki/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,15 +876,16 @@ function module_code(library_namespace) {
}
// console.trace(language);
// console.trace(in_session);

// 正規化。
language = String(language
// || in_session && in_session.language
|| get_first_domain_name_of_session(in_session)
// else use default language
// 警告: 若是沒有輸入,則會直接回傳預設的語言。因此您或許需要先檢測是不是設定了 language。
|| wiki_API.language).trim().toLowerCase()
|| wiki_API.language).trim().toLowerCase();
// zh_yue → zh-yue
.replace(/[_ ]/g, '-');
language = language.replace(/[_ ]/g, '-');
// console.trace(language);

var API_URL;
Expand Down
27 changes: 24 additions & 3 deletions application/net/wiki/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,31 @@ function module_code(library_namespace) {

if (data.warnings) {
for ( var action in data.warnings) {
library_namespace.warn('handle_error: '
+ data.warnings[action]['*']);
if (data.warnings[action]['*']) {
library_namespace.warn('handle_error: '
+ data.warnings[action]['*']);

} else if (Array.isArray(data.warnings[action].messages)) {
library_namespace.warn('handle_error: '
/**
* <code>
{"wbeditentity":{"messages":[{"name":"wikibase-conflict-patched","parameters":[],"html":{"*":"Your edit was patched into the latest version."},"type":"warning"}]}}
// https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/repo/i18n/zh-hant.json
</code>
*/
+ data.warnings[action].messages.map(function(line) {
var message = '[' + line.name + ']';
var text = line.html && line.html['*'];
if (text)
message += ' ' + text;
return message;
}).join('\n'));
}

}
console.trace(data.warnings);
console.trace(JSON.stringify(data.warnings));
}

// 檢查 MediaWiki 伺服器是否回應錯誤資訊。
Expand Down

0 comments on commit c750ab9

Please sign in to comment.