Index: trunk/extensions/WikiBhasha/wikibhasha.php |
— | — | @@ -32,11 +32,7 @@ |
33 | 33 | |
34 | 34 | //static Paths |
35 | 35 | $dir = dirname(__FILE__) . '/'; |
36 | | -$ExtDir = str_replace( "\\", "/", $dir ); |
37 | | -$top_dir = explode( '/', $ExtDir ); |
38 | | -echo $top_dir = array_pop( $top_dir ); |
39 | | -$ScriptPath = $wgScriptPath . '/extensions' . ( ( $top_dir == 'extensions' ) ? '' : '/' . $top_dir ); |
40 | | -$jsPath = "extensions/WikiBhasha/src/"; |
| 36 | +$jsPath = "extensions/WikiBhasha/WikiBhasha/"; |
41 | 37 | |
42 | 38 | //add a special page |
43 | 39 | $wgSpecialPages['wikiBhasha'] = 'WikiBhasha'; |
Index: trunk/extensions/WikiBhasha/src/js/main.js.bak |
— | — | @@ -1,354 +0,0 @@ |
2 | | -/********************************************************
|
3 | | -* *
|
4 | | -* Copyright (C) Microsoft. All rights reserved. *
|
5 | | -/*
|
6 | | -*
|
7 | | -* Copyright (c) Microsoft. All rights reserved.
|
8 | | -*
|
9 | | -* This code is licensed under the Apache License, Version 2.0.
|
10 | | -* THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
11 | | -* ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
12 | | -* IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
13 | | -* PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
14 | | -*
|
15 | | -* The apache license details from
|
16 | | -* ‘http://www.apache.org/licenses/’ are reproduced
|
17 | | -* in ‘Apache2_license.txt’
|
18 | | -*
|
19 | | -*/
|
20 | | -
|
21 | | -//* Available Classes:
|
22 | | -//* 1) splashWindow - Describes the splash window for the application, to notify the user that the application is in the process of loading.
|
23 | | -//*
|
24 | | -//* Available Methods:
|
25 | | -//* 1) loadApplicationRequiredFiles - wikiBhasha function to download application styles and JavaScript files
|
26 | | -//* 2) loadLocalizedStrings - load localized strings(javascript file) as per user settings
|
27 | | -//* 3) loadJQuery - loads jQuery library.
|
28 | | -//* 4) loadApplication - initiates the application load on UI, once the required JavaScript,CSS and localized strings are loaded.
|
29 | | -
|
30 | | -//make sure the base namespace exists.
|
31 | | -if (typeof (wikiBhasha) === "undefined") {
|
32 | | - wikiBhasha = {};
|
33 | | -}
|
34 | | -
|
35 | | -// settings for enabling debug mode to get asserts & debug breaks when an assert expression fails.
|
36 | | -// for production, debugMode is set to false. Change it to true when debugging application.
|
37 | | -wikiBhasha.debugMode = false;
|
38 | | -wikiBhasha.debugHelper = {};
|
39 | | -wikiBhasha.debugHelper.assertExpr = (wikiBhasha.debugMode) ?
|
40 | | - function(expr, message) { if (!expr) { alert(message || "debug assert failed"); debugger; } }
|
41 | | - : function() { };
|
42 | | -
|
43 | | -//initiates the application load on UI, once the required JavaScript,CSS and localized strings are loaded.
|
44 | | -wikiBhasha.loadApplication = function() {
|
45 | | -
|
46 | | - //remove 'loading...' div after successful call of wikiBhasha.
|
47 | | - $("#wbLoadDiv").remove();
|
48 | | -
|
49 | | - //describes whether current domain is 'Wikipedia' or not.
|
50 | | - var isWikipediaDomain = true,
|
51 | | - currentLanguageCode = wbWikiSite.getCurrentLanguage();
|
52 | | -
|
53 | | - //set the current domain is Wikipedia or not
|
54 | | - isWikipediaDomain = wbWikiSite.isWikiDomain(document.location.href);
|
55 | | -
|
56 | | - //set the direction for the content. Eg: Arabic, Hebrew are with orientation of right to left.
|
57 | | - wbGlobalSettings.direction = (wbGlobalSettings.isLanguageRTL(currentLanguageCode)) ? "rtl" : "ltr";
|
58 | | -
|
59 | | -
|
60 | | - //set target language, if current language code is not english
|
61 | | - if (currentLanguageCode !== wbGlobalSettings.sourceLanguageCode) {
|
62 | | - wbGlobalSettings.targetLanguageCode = currentLanguageCode;
|
63 | | - if (currentLanguageCode === 'zh') {
|
64 | | - var urlGetMltCode = wbUtil.getQueryStringValue('mltCode');
|
65 | | - if (urlGetMltCode) {
|
66 | | - wbGlobalSettings.mtTargetLanguageCode = urlGetMltCode;
|
67 | | - }
|
68 | | - } else {
|
69 | | - wbGlobalSettings.mtTargetLanguageCode = currentLanguageCode;
|
70 | | - }
|
71 | | - }
|
72 | | -
|
73 | | - if (isWikipediaDomain) {
|
74 | | -
|
75 | | - if (currentLanguageCode === 'en' && !wgArticleId) {
|
76 | | - //check if the user clicked title exists in Wikipedia or not
|
77 | | - wbUIHelper.hideLightBox();
|
78 | | - window.alert(wbLocal.noSourceArticleFound);
|
79 | | - return false;
|
80 | | - }
|
81 | | -
|
82 | | - //display language selection window if current article language code and target article language code both are english
|
83 | | - if (currentLanguageCode == wbGlobalSettings.sourceLanguageCode) {
|
84 | | - try {
|
85 | | - wbUIHelper.hideScroll();
|
86 | | - wbUIHelper.showLightBox();
|
87 | | -
|
88 | | - //display language selection window
|
89 | | - //if application is launched in source language article from the same language application link
|
90 | | - if (wbGlobalSettings.targetLanguageCode == wbGlobalSettings.sourceLanguageCode) {
|
91 | | - wikiBhasha.windowManagement.languageSelectionWindow.show(true /*show the language dropdown*/);
|
92 | | - }
|
93 | | - else {
|
94 | | - wikiBhasha.windowManagement.languageSelectionWindow.show(false /*hide the language dropdown*/);
|
95 | | - }
|
96 | | - return;
|
97 | | - }
|
98 | | - catch (e) {
|
99 | | - wbUIHelper.hideLightBox();
|
100 | | - window.alert(wbLocal.failureMsg + "\n" + e);
|
101 | | - return;
|
102 | | - }
|
103 | | - }
|
104 | | - //invalid application link clicked,
|
105 | | - //if current article language and target language code are different
|
106 | | - else if ((currentLanguageCode != wbGlobalSettings.sourceLanguageCode) &&
|
107 | | - (currentLanguageCode != wbGlobalSettings.targetLanguageCode) &&
|
108 | | - (wbGlobalSettings.targetLanguageCode != wbGlobalSettings.sourceLanguageCode)) {
|
109 | | - wbUIHelper.hideLightBox();
|
110 | | - window.alert(wbLocal.invalidBookmarklet);
|
111 | | - return;
|
112 | | - }
|
113 | | - }
|
114 | | -
|
115 | | - wbGlobalSettings.setTargetLanguageValues();
|
116 | | -
|
117 | | - //set source title, if target language code is english
|
118 | | - if (currentLanguageCode == wbGlobalSettings.sourceLanguageCode) {
|
119 | | - wbGlobalSettings.sourceLanguageArticleTitle = decodeURIComponent($.trim(wbWikiSite.getCurrentArticleTitle()));
|
120 | | - }
|
121 | | - //set target title, if target language code is other than english
|
122 | | - else {
|
123 | | - wbGlobalSettings.targetLanguageArticleTitle = decodeURIComponent($.trim(wbWikiSite.getCurrentArticleTitle()));
|
124 | | - }
|
125 | | -
|
126 | | - //if source title is empty, try to get new article title from browser Url (New article)
|
127 | | - if (wbGlobalSettings.sourceLanguageArticleTitle.length == 0) {
|
128 | | - var newArticleKey = "wbTitle",
|
129 | | - //new article title from query string
|
130 | | - sTitle = wbUtil.getQueryStringValue(newArticleKey);
|
131 | | - if (sTitle && sTitle.length && sTitle.length > 0) {
|
132 | | - wbGlobalSettings.sourceLanguageArticleTitle = decodeURIComponent($.trim(sTitle));
|
133 | | - wbGlobalSettings.isNewArticle = true;
|
134 | | - }
|
135 | | - }
|
136 | | -
|
137 | | - //load application window with source and target articles
|
138 | | - try {
|
139 | | - wbSplash.show();
|
140 | | - wbMainWindow.show();
|
141 | | - }
|
142 | | - catch (e) {
|
143 | | - wbSplash.close();
|
144 | | - window.alert(wbLocal.failureMsg + "\n" + e);
|
145 | | - }
|
146 | | -};
|
147 | | -
|
148 | | -//describes the splash window for the application, to notify the user that the
|
149 | | -//application is in the process of loading.
|
150 | | -wikiBhasha.splashWindow = {
|
151 | | - //splash window div Id.
|
152 | | - windowId: "wbSplashWindow",
|
153 | | - //creates and displays splash window on application UI
|
154 | | - show: function() {
|
155 | | - wbUIHelper.blockUI();
|
156 | | - wbUIHelper.createWindow(this.windowId, wbGlobalSettings.splashWindowHTML);
|
157 | | - },
|
158 | | -
|
159 | | - //hides and removes splash window from application UI
|
160 | | - close: function() {
|
161 | | - wbUIHelper.unblockUI();
|
162 | | - $("#" + this.windowId).remove();
|
163 | | - }
|
164 | | -};
|
165 | | -
|
166 | | -//shortcut to call wikiBhasha.splashWindow window
|
167 | | -wbSplash = wikiBhasha.splashWindow;
|
168 | | -
|
169 | | -//downloads styles and JavaScript files for application
|
170 | | -wikiBhasha.loadApplicationRequiredFiles = function() {
|
171 | | -
|
172 | | - //if jQuery object is loaded and '$' symbol is not defined then assign jQuery object to '$' symbol
|
173 | | - //in wikiPedia article '$' is set to 'undefined' by some tracking code, so we need to reassign
|
174 | | - //jQuery object to '$' for normal use.
|
175 | | - if (typeof $ == 'undefined' && typeof jQuery != 'undefined') {
|
176 | | - $ = jQuery;
|
177 | | - }
|
178 | | -
|
179 | | - function attachStyle(url, id /*[Optional]*/) {
|
180 | | - if (url && url.length > 0) {
|
181 | | - var head = document.getElementsByTagName("head")[0];
|
182 | | - var link = document.createElement("link");
|
183 | | - if (id) {
|
184 | | - link.id = id;
|
185 | | - }
|
186 | | - link.type = "text/css";
|
187 | | - link.rel = "stylesheet";
|
188 | | - link.media = "screen";
|
189 | | - link.href = url;
|
190 | | - head.appendChild(link);
|
191 | | - }
|
192 | | - };
|
193 | | -
|
194 | | - if (typeof baseUrl != "undefined") {
|
195 | | - //wikiBhasha application css files
|
196 | | - var reqCSS = ["styles/jquery-ui-1.7.2.css",
|
197 | | - "styles/hybridModeStyles.css",
|
198 | | - "styles/wikiBhasha.css"],
|
199 | | -
|
200 | | - //files required for loading language selection window
|
201 | | - reqJSForLanguageSelection = ["js/jsLib/jquery-ui-1.7.2.min.js",
|
202 | | - "js/extern/wikipediaInterface.js",
|
203 | | - "js/extern/languageServicesInterface.js",
|
204 | | - "js/extern/loggerInterface.js",
|
205 | | - "js/core/configurations.js",
|
206 | | - "js/core/configurations.templateMappers.js",
|
207 | | - "js/core/globalSettings.js",
|
208 | | - "js/core/languageSelectionWindow.js",
|
209 | | - "js/core/utils.js"],
|
210 | | -
|
211 | | - //files required for loading complete application
|
212 | | - reqJSForCoreApplication = ["js/jsLib/jquery-ui-1.7.2.min.js",
|
213 | | - "js/jsLib/jquery.contextmenu.js",
|
214 | | - "js/jsLib/jquery.shortcut.js",
|
215 | | - "js/extern/wikipediaInterface.js",
|
216 | | - "js/extern/languageServicesInterface.js",
|
217 | | - "js/extern/transliterationServicesInterface.js",
|
218 | | - "js/extern/loggerInterface.js",
|
219 | | - "js/core/configurations.js",
|
220 | | - "js/core/configurations.templateMappers.js",
|
221 | | - "js/core/globalSettings.js",
|
222 | | - "js/core/historyManagement.js",
|
223 | | - "js/core/mainWindow.js",
|
224 | | - "js/core/paneManagement.js",
|
225 | | - "js/core/scratchpadWindow.js",
|
226 | | - "js/core/feedbackWindow.js",
|
227 | | - "js/core/searchWindow.js",
|
228 | | - "js/core/templateAndLinkTranslator.js",
|
229 | | - "js/core/themes.js",
|
230 | | - "js/core/utils.js",
|
231 | | - "js/core/wikiModeConverters.js",
|
232 | | - "js/core/chineaseLangSelection.js",
|
233 | | - "js/core/wikiParser.js"],
|
234 | | -
|
235 | | - //wikiBhasha default theme
|
236 | | - themeCss = ["styles/themes/wikiBhasha.blue.css"];
|
237 | | -
|
238 | | - //load css files
|
239 | | - for (var i = 0; i < reqCSS.length; i++) {
|
240 | | - //create url
|
241 | | - var url = baseUrl + reqCSS[i];
|
242 | | - //attach other style expect themes
|
243 | | - attachStyle(url);
|
244 | | - }
|
245 | | -
|
246 | | - //load themes css files
|
247 | | - for (var i = 0; i < themeCss.length; i++) {
|
248 | | - //create url
|
249 | | - var url = baseUrl + themeCss[i],
|
250 | | - id = "wbCSSBlue";
|
251 | | - attachStyle(url, id);
|
252 | | - }
|
253 | | -
|
254 | | - //load javascript files
|
255 | | - var fileCount = 0,
|
256 | | - //check whether source language is 'english' or not. if so then load the language selection window else complete application files
|
257 | | - reqJS = (wikiSourceLanguage == "en") ? reqJSForLanguageSelection : reqJSForCoreApplication;
|
258 | | - for (var i = 0; i < reqJS.length; i++) {
|
259 | | - var url = baseUrl + reqJS[i];
|
260 | | - $.getScript(url, function() {
|
261 | | - fileCount = fileCount + 1;
|
262 | | - //check if all the files are loaded
|
263 | | - if (fileCount == reqJS.length) {
|
264 | | - //download strings after downloading all application files
|
265 | | - wikiBhasha.loadLocalizedStrings();
|
266 | | - }
|
267 | | - });
|
268 | | - }
|
269 | | - }
|
270 | | -};
|
271 | | -
|
272 | | -//loads localized strings(javascript file) as per user settings
|
273 | | -wikiBhasha.loadLocalizedStrings = function() {
|
274 | | - // set global values
|
275 | | - wbGlobalSettings.baseUrl = baseUrl;
|
276 | | - wbGlobalSettings.targetLanguageCode = targetLanguageCode;
|
277 | | - wbGlobalSettings.userLanguageCode = wbGlobalSettings.getUserLanguage();
|
278 | | -
|
279 | | - //create localized string file URL
|
280 | | - var url = wbGlobalSettings.baseUrl + wbGlobalSettings.languageFolder + wbGlobalSettings.userLanguageCode + "/strings.js";
|
281 | | - $.getScript(url, function() {
|
282 | | - try {
|
283 | | - // Initialize configurations and create session first.
|
284 | | - wikiBhasha.configurations.initialize();
|
285 | | - wbUIHelper.createSession();
|
286 | | -
|
287 | | - var curLangCode = wbWikiSite.getCurrentLanguage();
|
288 | | - if (curLangCode != wbGlobalSettings.sourceLanguageCode) {
|
289 | | - // Check if the article is protected. If so, don’t allow the user to edit it. Just show the message and close WikiBhasha. Otherwise proceed further to load the page in WikiBhasha.
|
290 | | - wbWikiSite.isArticleProtected(curLangCode, $.trim(wbWikiSite.getCurrentArticleTitle()), function(isArticleProtected) {
|
291 | | - if (isArticleProtected) {
|
292 | | - window.alert(wbLocal.nonEditableMessage);
|
293 | | - //remove 'loading...' div after successful call of wikiBhasha.
|
294 | | - $("#wbLoadDiv").remove();
|
295 | | - } else {
|
296 | | - if (curLangCode === 'zh') {
|
297 | | - var urlGetMltCode = wbUtil.getQueryStringValue('mltCode');
|
298 | | - if (!urlGetMltCode) {
|
299 | | - $("#wbLoadDiv").remove();
|
300 | | - wbChineseLangSelection.show();
|
301 | | - return;
|
302 | | - }
|
303 | | - }
|
304 | | - wikiBhasha.loadApplication();
|
305 | | - }
|
306 | | - return;
|
307 | | - });
|
308 | | - } else {
|
309 | | - wikiBhasha.loadApplication();
|
310 | | - }
|
311 | | - return;
|
312 | | - }
|
313 | | - catch (e) {
|
314 | | - window.alert(wbLocal.failureMsg + "\n" + e);
|
315 | | - return;
|
316 | | - }
|
317 | | - });
|
318 | | -};
|
319 | | -
|
320 | | -// load jquery library if it is not downloaded yet
|
321 | | -// We require separate function for loading jQuery because this should not use any jQuery methods by itself.
|
322 | | -// NOTE: Never use any jQuery functions within this function.
|
323 | | -wikiBhasha.loadJQuery = function(callback) {
|
324 | | - if (typeof baseUrl != "undefined") {
|
325 | | - var script = document.createElement("script")
|
326 | | - script.type = "text/javascript";
|
327 | | - //check whether file is loaded or not if so, call the the 'callback' function
|
328 | | - //IE fix, in IE 'readyState' event is fired once the file is loaded
|
329 | | - if (script.readyState) {
|
330 | | - script.onreadystatechange = function() {
|
331 | | - if (script.readyState == "loaded" ||
|
332 | | - script.readyState == "complete") {
|
333 | | - script.onreadystatechange = null;
|
334 | | - callback();
|
335 | | - }
|
336 | | - };
|
337 | | - }
|
338 | | - //other browsers, 'onload' event will be fired
|
339 | | - else {
|
340 | | - script.onload = function() {
|
341 | | - callback();
|
342 | | - };
|
343 | | - }
|
344 | | - script.src = baseUrl + "js/jsLib/jquery-1.3.2.min.js";
|
345 | | - document.body.appendChild(script);
|
346 | | - }
|
347 | | -};
|
348 | | -
|
349 | | -//load jquery library if it is not loaded
|
350 | | -if (typeof jQuery === "undefined") {
|
351 | | - //after loading jQuery load other required files only after some time gap(ex:100ms), assuming that jQuery will take some time to load into browser.
|
352 | | - wikiBhasha.loadJQuery(function() { window.setTimeout("wikiBhasha.loadApplicationRequiredFiles()", 100); });
|
353 | | -} else {
|
354 | | - wikiBhasha.loadApplicationRequiredFiles();
|
355 | | -} |
\ No newline at end of file |
Index: trunk/extensions/WikiBhasha/src/js/main.js |
— | — | @@ -52,6 +52,13 @@ |
53 | 53 | //set the current domain is Wikipedia or not |
54 | 54 | isWikipediaDomain = wbWikiSite.isWikiDomain(document.location.href); |
55 | 55 | |
| 56 | + //avoid launching of application on non-wiki domain articles and on any special pages from Wikipedia. |
| 57 | + if ((wbWikiSite.isWikiMainPage()) || (typeof wbWikiSite.getCurrentArticleTitle() == "undefined") |
| 58 | + || (!wbWikiSite.getCurrentArticleTitle()) || wgNamespaceNumber != 0) { |
| 59 | + window.alert(wbLocal.nonWikiDomainMsg); |
| 60 | + return; |
| 61 | + } |
| 62 | + |
56 | 63 | //set the direction for the content. Eg: Arabic, Hebrew are with orientation of right to left. |
57 | 64 | wbGlobalSettings.direction = (wbGlobalSettings.isLanguageRTL(currentLanguageCode)) ? "rtl" : "ltr"; |
58 | 65 | |
— | — | @@ -111,6 +118,12 @@ |
112 | 119 | } |
113 | 120 | } |
114 | 121 | |
| 122 | + //check the current language is supported by application or not. |
| 123 | + if (!(wbGlobalSettings.isWikiBhashaSupportedLanguage(wbGlobalSettings.mtTargetLanguageCode))) { |
| 124 | + window.alert(wbLocal.unSupportedLanguage); |
| 125 | + return; |
| 126 | + } |
| 127 | + |
115 | 128 | wbGlobalSettings.setTargetLanguageValues(); |
116 | 129 | |
117 | 130 | //set source title, if target language code is english |