Index: trunk/extensions/WikiBhasha/src/js/extern/wikipediaInterface.js |
— | — | @@ -21,299 +21,302 @@ |
22 | 22 | |
23 | 23 | //make sure the namespace exists. |
24 | 24 | if (typeof (wikiBhasha.extern) === "undefined") { |
25 | | - wikiBhasha.extern = {}; |
| 25 | + wikiBhasha.extern = {}; |
26 | 26 | } |
27 | 27 | |
28 | 28 | (function() { |
29 | | - //includes all the properties and methods to interact with external interfaces |
30 | | - //(Ex: interacting with wikipedia APIs). |
31 | | - wikiBhasha.extern.wikipediaInterface = { |
| 29 | + //includes all the properties and methods to interact with external interfaces |
| 30 | + //(Ex: interacting with wikipedia APIs). |
| 31 | + wikiBhasha.extern.wikipediaInterface = { |
32 | 32 | |
33 | | - //regular expression to check wikipedia page url |
34 | | - wikiPageUrlRegex: /^(http):\/\/[A-Za-z]+\.(wikipedia.org)/, |
| 33 | + //regular expression to check wikipedia page url |
| 34 | + wikiPageUrlRegex: /^(http):\/\/[A-Za-z]+\.(wikipedia.org)/, |
35 | 35 | |
36 | | - //API to get wikipedia article |
37 | | - wikiArticleMarkupAPI: "http://{0}.wikipedia.org/w/api.php?&action=query&titles={1}&rvprop=content&prop=revisions&redirects=1&format=json", |
| 36 | + //API to get wikipedia article |
| 37 | + wikiArticleMarkupAPI: "http://{0}.wikipedia.org/w/api.php?&action=query&titles={1}&rvprop=content&prop=revisions&redirects=1&format=json", |
38 | 38 | |
39 | | - //API to search wikipedia article |
40 | | - wikiSearchAPI: "http://{0}.wikipedia.org/w/api.php?action=query&list=search&srsearch={1}&format=json", |
| 39 | + //API to search wikipedia article |
| 40 | + wikiSearchAPI: "http://{0}.wikipedia.org/w/api.php?action=query&list=search&srsearch={1}&format=json", |
41 | 41 | |
42 | | - //API to search wikipedia article |
43 | | - wikiPreviewAPI: "http://{0}.wikipedia.org/w/api.php?action=parse&text={1}&format=json", |
| 42 | + //API to search wikipedia article |
| 43 | + wikiPreviewAPI: "http://{0}.wikipedia.org/w/api.php?action=parse&text={1}&format=json", |
44 | 44 | |
45 | | - //API to get wikipedia language links |
46 | | - wikiLangLinksAPI: "http://{0}.wikipedia.org/w/api.php?action=query&prop=langlinks&format=json&redirects=1&titles={1}&lllimit=5000", |
| 45 | + //API to get wikipedia language links |
| 46 | + wikiLangLinksAPI: "http://{0}.wikipedia.org/w/api.php?action=query&prop=langlinks&format=json&redirects=1&titles={1}&lllimit=5000", |
47 | 47 | |
48 | | - //API to get wikipedia article page Id |
49 | | - wikiArticlePageIdAPI: "http://{0}.wikipedia.org/w/api.php?action=query&titles={1}&indexpageids&redirects=1&format=json", |
| 48 | + //API to get wikipedia article page Id |
| 49 | + wikiArticlePageIdAPI: "http://{0}.wikipedia.org/w/api.php?action=query&titles={1}&indexpageids&redirects=1&format=json", |
50 | 50 | |
51 | | - //wikipedia URL to get the article in Edit mode |
52 | | - wikiEditUrl: "http://{0}.wikipedia.org/w/index.php?title={1}&action=edit", |
| 51 | + //wikipedia URL to get the article in Edit mode |
| 52 | + wikiEditUrl: "http://{0}.wikipedia.org/w/index.php?title={1}&action=edit", |
53 | 53 | |
54 | | - // wikipedia URL to get the protection information for a given article |
55 | | - wikiArticleProtectionInfoAPI: "http://{0}.wikipedia.org/w/api.php?action=query&prop=info&inprop=protection&titles={1}&format=json", |
| 54 | + // wikipedia URL to get the protection information for a given article |
| 55 | + wikiArticleProtectionInfoAPI: "http://{0}.wikipedia.org/w/api.php?action=query&prop=info&inprop=protection&titles={1}&format=json", |
56 | 56 | |
57 | | - //API to get interwiki links for given titles |
58 | | - wikiGetInterWikiLinksAPI: "http://{0}.wikipedia.org/w/api.php?action=query&titles={1}&prop=langlinks&lllimit=500&format=json", |
| 57 | + //API to get interwiki links for given titles |
| 58 | + wikiGetInterWikiLinksAPI: "http://{0}.wikipedia.org/w/api.php?action=query&titles={1}&prop=langlinks&lllimit=500&format=json", |
| 59 | + |
| 60 | + wikiMaxTitlesPerInterWikiLinksApi: 50, |
| 61 | + |
| 62 | + //wikipedia base URL |
| 63 | + wikiUrlFormat: "http://{0}.wikipedia.org/wiki/{1}", |
59 | 64 | |
60 | | - wikiMaxTitlesPerInterWikiLinksApi: 50, |
| 65 | + //wikipedia Editable 'textarea' Id/name |
| 66 | + wikiComposeTextArea: "wpTextbox1", |
61 | 67 | |
62 | | - //wikipedia base URL |
63 | | - wikiUrlFormat: "http://{0}.wikipedia.org/wiki/{1}", |
| 68 | + //wikipedia Editable summery field Id/name |
| 69 | + wikiSummeryField: "wpSummary", |
64 | 70 | |
65 | | - //wikipedia Editable 'textarea' Id/name |
66 | | - wikiComposeTextArea: "wpTextbox1", |
| 71 | + //list of elements to be removed for publish step to give more real-estate to edit text area |
| 72 | + wikiEditPageNonCriticalDivs: "#mw-panel, #p-Contribuer, #p-help,#p-cactions,#centralNotice,#p-navigation,#p-logo,#firstHeading,#siteSub,#p-search,#p-interaction,#p-tb,#p-lang,#coordinates", |
67 | 73 | |
68 | | - //list of elements to be removed for publish step to give more real-estate to edit text area |
69 | | - wikiEditPageNonCriticalDivs: "#mw-panel, #p-Contribuer, #p-help,#p-cactions,#centralNotice,#p-navigation,#p-logo,#firstHeading,#siteSub,#p-search,#p-interaction,#p-tb,#p-lang,#coordinates", |
| 74 | + //wikipedia compose area element id |
| 75 | + wikiComposeDiv: "#content", |
70 | 76 | |
71 | | - //wikipedia compose area element id |
72 | | - wikiComposeDiv: "#content", |
| 77 | + //wikipedia compose links |
| 78 | + wikiComposeLinks: "#globalWrapper a", |
73 | 79 | |
74 | | - //wikipedia compose links |
75 | | - wikiComposeLinks: "#globalWrapper a", |
| 80 | + //wikipedia save button id |
| 81 | + wikiSaveButton: "wpSave", |
76 | 82 | |
77 | | - //wikipedia save button id |
78 | | - wikiSaveButton: "wpSave", |
| 83 | + //gets the corresponding source language article title for a given target language article |
| 84 | + getSourceTitle: function(targetLanguageCode, sourceLanguageCode, targetLanguageArticleTitle, callback) { |
| 85 | + this.getTargetLanguageTitle(targetLanguageCode, sourceLanguageCode, targetLanguageArticleTitle, function(data) { |
| 86 | + var sourceLanguageArticleTitle = (data && data.length) ? $.trim(data) : null; |
| 87 | + callback(sourceLanguageArticleTitle); |
| 88 | + }); |
| 89 | + }, |
79 | 90 | |
80 | | - //gets the corresponding source language article title for a given target language article |
81 | | - getSourceTitle: function(targetLanguageCode, sourceLanguageCode, targetLanguageArticleTitle, callback) { |
82 | | - this.getTargetLanguageTitle(targetLanguageCode, sourceLanguageCode, targetLanguageArticleTitle, function(data) { |
83 | | - var sourceLanguageArticleTitle = (data && data.length) ? $.trim(data) : null; |
84 | | - callback(sourceLanguageArticleTitle); |
85 | | - }); |
86 | | - }, |
| 91 | + //searches wikipedia articles for the given search key |
| 92 | + search: function(lang, $searchKey, callback) { |
| 93 | + if (lang && lang.length && $searchKey && $searchKey.length) { |
| 94 | + var results = [], |
| 95 | + urlData = wbUtil.stringFormat(this.wikiSearchAPI, lang, encodeURIComponent($searchKey)), |
| 96 | + kbSize = 1024, |
| 97 | + searchResult = "", |
| 98 | + targetUrl = ""; |
87 | 99 | |
88 | | - //searches wikipedia articles for the given search key |
89 | | - search: function(lang, $searchKey, callback) { |
90 | | - if (lang && lang.length && $searchKey && $searchKey.length) { |
91 | | - var results = [], |
92 | | - urlData = wbUtil.stringFormat(this.wikiSearchAPI, lang, encodeURIComponent($searchKey)), |
93 | | - kbSize = 1024, |
94 | | - searchResult = "", |
95 | | - targetUrl = ""; |
| 100 | + $.getJSON(urlData, 'callback=?', function(data) { |
| 101 | + if (data && data.query && data.query.search) { |
| 102 | + for (i = 0; i < data.query.search.length; i++) { |
| 103 | + searchResult = data.query.search[i]; |
| 104 | + //opera fix: |
| 105 | + //Pages displayed inside an iframe will inherit the character encoding of the parent page, unless they specify their own character encoding. |
| 106 | + //A malicious page that uses the UTF-7 character encoding can include other sites for example inside iframes. This can be exploited to perform cross-site scripting on certain sites, allowing the attacker to get access to the user's session data for those sites. |
| 107 | + //http://www.opera.com/support/kb/view/855/ |
| 108 | + if ($.browser.opera) { |
| 109 | + targetUrl = wbUtil.stringFormat(wbWikiSite.wikiUrlFormat, lang, searchResult.title); |
| 110 | + } |
| 111 | + //Other browsers, open with edit url |
| 112 | + else { |
| 113 | + targetUrl = wbUtil.stringFormat(wbWikiSite.wikiEditUrl, lang, searchResult.title); |
| 114 | + } |
| 115 | + results[i] = { wikiUrlFormat: targetUrl, |
| 116 | + title: searchResult.title, |
| 117 | + snippet: searchResult.snippet, |
| 118 | + size: Math.round((searchResult.size / kbSize), 2), |
| 119 | + wordcount: searchResult.wordcount, |
| 120 | + timestamp: searchResult.timestamp |
| 121 | + }; |
| 122 | + } |
| 123 | + } |
| 124 | + callback(results); |
| 125 | + }); |
| 126 | + } |
| 127 | + }, |
96 | 128 | |
97 | | - $.getJSON(urlData, 'callback=?', function(data) { |
98 | | - if (data && data.query && data.query.search) { |
99 | | - for (i = 0; i < data.query.search.length; i++) { |
100 | | - searchResult = data.query.search[i]; |
101 | | - //opera fix: |
102 | | - //Pages displayed inside an iframe will inherit the character encoding of the parent page, unless they specify their own character encoding. |
103 | | - //A malicious page that uses the UTF-7 character encoding can include other sites for example inside iframes. This can be exploited to perform cross-site scripting on certain sites, allowing the attacker to get access to the user's session data for those sites. |
104 | | - //http://www.opera.com/support/kb/view/855/ |
105 | | - if ($.browser.opera) { |
106 | | - targetUrl = wbUtil.stringFormat(wbWikiSite.wikiUrlFormat, lang, searchResult.title); |
107 | | - } |
108 | | - //Other browsers, open with edit url |
109 | | - else { |
110 | | - targetUrl = wbUtil.stringFormat(wbWikiSite.wikiEditUrl, lang, searchResult.title); |
111 | | - } |
112 | | - results[i] = { wikiUrlFormat: targetUrl, |
113 | | - title: searchResult.title, |
114 | | - snippet: searchResult.snippet, |
115 | | - size: Math.round((searchResult.size / kbSize), 2), |
116 | | - wordcount: searchResult.wordcount, |
117 | | - timestamp: searchResult.timestamp |
118 | | - }; |
119 | | - } |
120 | | - } |
121 | | - callback(results); |
122 | | - }); |
123 | | - } |
124 | | - }, |
| 129 | + //gets the title of target language article for given source language article title |
| 130 | + getTargetLanguageTitle: function(sourceLanguage, targetLanguage, sourceLanguageArticleTitle, callback) { |
| 131 | + if (sourceLanguage && sourceLanguage.length && targetLanguage && |
| 132 | + targetLanguage.length && sourceLanguageArticleTitle && sourceLanguageArticleTitle.length) { |
| 133 | + var result = "", |
| 134 | + urlData = wbUtil.stringFormat(this.wikiLangLinksAPI, sourceLanguage, encodeURIComponent(sourceLanguageArticleTitle.replace("%20", " "))); |
125 | 135 | |
126 | | - //gets the title of target language article for given source language article title |
127 | | - getTargetLanguageTitle: function(sourceLanguage, targetLanguage, sourceLanguageArticleTitle, callback) { |
128 | | - if (sourceLanguage && sourceLanguage.length && targetLanguage && |
129 | | - targetLanguage.length && sourceLanguageArticleTitle && sourceLanguageArticleTitle.length) { |
130 | | - var result = "", |
131 | | - urlData = wbUtil.stringFormat(this.wikiLangLinksAPI, sourceLanguage, encodeURIComponent(sourceLanguageArticleTitle.replace("%20", " "))); |
| 136 | + this.getArticlePageId(sourceLanguage, sourceLanguageArticleTitle, function(pageID) { |
| 137 | + if (pageID) { |
| 138 | + $.getJSON(urlData, 'callback=?', function(data) { |
| 139 | + var langLinkList = data.query.pages[pageID].langlinks; |
| 140 | + if (langLinkList) { |
| 141 | + for (i = 0; i < langLinkList.length; i++) { |
| 142 | + if (targetLanguage === langLinkList[i].lang) { |
| 143 | + result = langLinkList[i]["*"]; |
| 144 | + break; |
| 145 | + } |
| 146 | + } |
| 147 | + callback(result); |
| 148 | + } |
| 149 | + else { |
| 150 | + callback(null); |
| 151 | + } |
| 152 | + }); |
| 153 | + } |
| 154 | + else { |
| 155 | + callback(null); |
| 156 | + } |
| 157 | + }); |
| 158 | + } |
| 159 | + }, |
132 | 160 | |
133 | | - this.getArticlePageId(sourceLanguage, sourceLanguageArticleTitle, function(pageID) { |
134 | | - if (pageID) { |
135 | | - $.getJSON(urlData, 'callback=?', function(data) { |
136 | | - var langLinkList = data.query.pages[pageID].langlinks; |
137 | | - if (langLinkList) { |
138 | | - for (i = 0; i < langLinkList.length; i++) { |
139 | | - if (targetLanguage === langLinkList[i].lang) { |
140 | | - result = langLinkList[i]["*"]; |
141 | | - break; |
142 | | - } |
143 | | - } |
144 | | - callback(result); |
145 | | - } |
146 | | - else { |
147 | | - callback(null); |
148 | | - } |
149 | | - }); |
150 | | - } |
151 | | - else { |
152 | | - callback(null); |
153 | | - } |
154 | | - }); |
155 | | - } |
156 | | - }, |
| 161 | + //gets source article content in wiki format for a given article title |
| 162 | + getArticleInWikiFormat: function(lang, title, callback) { |
| 163 | + if (lang && lang.length && title && title.length) { |
| 164 | + var markupArticle = ""; |
| 165 | + this.getArticlePageId(lang, title, function(data) { |
| 166 | + if (data) { |
| 167 | + var pageId = data; |
| 168 | + var urlData = wbUtil.stringFormat(wbWikiSite.wikiArticleMarkupAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
| 169 | + $.getJSON(urlData, 'callback=?', function(data) { |
| 170 | + if (data && data.query && data.query.pages && data.query.pages[pageId].revisions) { |
| 171 | + markupArticle = data.query.pages[pageId].revisions[0]["*"]; |
| 172 | + callback(markupArticle); |
| 173 | + } |
| 174 | + else { |
| 175 | + callback(null); |
| 176 | + } |
| 177 | + }); |
| 178 | + } |
| 179 | + else { |
| 180 | + callback(null); |
| 181 | + } |
| 182 | + }); |
| 183 | + } |
| 184 | + }, |
157 | 185 | |
158 | | - //gets source article content in wiki format for a given article title |
159 | | - getArticleInWikiFormat: function(lang, title, callback) { |
160 | | - if (lang && lang.length && title && title.length) { |
161 | | - var markupArticle = ""; |
162 | | - this.getArticlePageId(lang, title, function(data) { |
163 | | - if (data) { |
164 | | - var pageId = data; |
165 | | - var urlData = wbUtil.stringFormat(wbWikiSite.wikiArticleMarkupAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
166 | | - $.getJSON(urlData, 'callback=?', function(data) { |
167 | | - if (data && data.query && data.query.pages && data.query.pages[pageId].revisions) { |
168 | | - markupArticle = data.query.pages[pageId].revisions[0]["*"]; |
169 | | - callback(markupArticle); |
170 | | - } |
171 | | - else { |
172 | | - callback(null); |
173 | | - } |
174 | | - }); |
175 | | - } |
176 | | - else { |
177 | | - callback(null); |
178 | | - } |
179 | | - }); |
180 | | - } |
181 | | - }, |
| 186 | + //checks the protection information for the given article title in the given langauge. Returns ‘true’ |
| 187 | + //for the callback function, if the given article is protected. Otherwise returns ‘false’ for the callback function. |
| 188 | + isArticleProtected: function(lang, title, callback) { |
| 189 | + if (lang && lang.length && title && title.length) { |
| 190 | + var urlData = wbUtil.stringFormat(wbWikiSite.wikiArticleProtectionInfoAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
| 191 | + $.getJSON(urlData, 'callback=?', function(data) { |
| 192 | + if (data && data.query && data.query.pages) { |
| 193 | + var pages = data.query.pages; |
| 194 | + for (var page in pages) { |
| 195 | + if (typeof pages[page].protection !== "undefined" && pages[page].protection.length > 0) { |
| 196 | + callback(true); |
| 197 | + return; |
| 198 | + } |
| 199 | + else { |
| 200 | + callback(false); |
| 201 | + return; |
| 202 | + } |
| 203 | + } |
182 | 204 | |
183 | | - //checks the protection information for the given article title in the given langauge. Returns ‘true’ |
184 | | - //for the callback function, if the given article is protected. Otherwise returns ‘false’ for the callback function. |
185 | | - isArticleProtected: function(lang, title, callback) { |
186 | | - if (lang && lang.length && title && title.length) { |
187 | | - var urlData = wbUtil.stringFormat(wbWikiSite.wikiArticleProtectionInfoAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
188 | | - $.getJSON(urlData, 'callback=?', function(data) { |
189 | | - if (data && data.query && data.query.pages) { |
190 | | - var pages = data.query.pages; |
191 | | - for (var page in pages) { |
192 | | - if (typeof pages[page].protection !== "undefined" && pages[page].protection.length > 0) { |
193 | | - callback(true); |
194 | | - return; |
195 | | - } |
196 | | - else { |
197 | | - callback(false); |
198 | | - return; |
199 | | - } |
200 | | - } |
| 205 | + } |
| 206 | + else { |
| 207 | + callback(false); |
| 208 | + return; |
| 209 | + } |
| 210 | + }); |
| 211 | + } |
| 212 | + }, |
201 | 213 | |
202 | | - } |
203 | | - else { |
204 | | - callback(false); |
205 | | - return; |
206 | | - } |
207 | | - }); |
208 | | - } |
209 | | - }, |
| 214 | + //gets article page Id for a given article title |
| 215 | + getArticlePageId: function(lang, title, callback) { |
| 216 | + if (lang && lang.length && title && title.length) { |
| 217 | + var pageId = "", |
| 218 | + urlData = wbUtil.stringFormat(this.wikiArticlePageIdAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
| 219 | + $.getJSON(urlData, 'callback=?', function(data) { |
| 220 | + if (data && data.query && data.query.pageids) { |
| 221 | + pageId = data.query.pageids[0]; |
| 222 | + callback(pageId); |
| 223 | + } |
| 224 | + else { |
| 225 | + callback(null); |
| 226 | + } |
| 227 | + }); |
| 228 | + } |
| 229 | + }, |
210 | 230 | |
211 | | - //gets article page Id for a given article title |
212 | | - getArticlePageId: function(lang, title, callback) { |
213 | | - if (lang && lang.length && title && title.length) { |
214 | | - var pageId = "", |
215 | | - urlData = wbUtil.stringFormat(this.wikiArticlePageIdAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
216 | | - $.getJSON(urlData, 'callback=?', function(data) { |
217 | | - if (data && data.query && data.query.pageids) { |
218 | | - pageId = data.query.pageids[0]; |
219 | | - callback(pageId); |
220 | | - } |
221 | | - else { |
222 | | - callback(null); |
223 | | - } |
224 | | - }); |
225 | | - } |
226 | | - }, |
| 231 | + //gets inter wiki links for a given set of titles |
| 232 | + getInterWikiLinks: function(titles, optionalApiTags, interWikiLinksCallback) { |
| 233 | + if (titles && titles.length) { |
| 234 | + var urlData = wbUtil.stringFormat(this.wikiGetInterWikiLinksAPI, "en", encodeURIComponent(titles.replace("%20", " "))); |
| 235 | + if (optionalApiTags) { |
| 236 | + urlData = urlData + "&" + optionalApiTags; |
| 237 | + } |
| 238 | + |
| 239 | + $.getJSON(urlData, 'callback=?', function(data) { |
| 240 | + if (data) { |
| 241 | + interWikiLinksCallback(data, titles); |
| 242 | + } |
| 243 | + }); |
| 244 | + } |
| 245 | + }, |
| 246 | + |
| 247 | + //gets the wiki edit page URL for the given title and language code |
| 248 | + getEditPageUrl: function(lang, title) { |
| 249 | + //if all the parameters are not null |
| 250 | + if (lang && lang.length && title && title.length) { |
| 251 | + return wbUtil.stringFormat(this.wikiEditUrl, lang, encodeURIComponent(title)); |
| 252 | + } |
| 253 | + }, |
227 | 254 | |
228 | | - //gets inter wiki links for a given set of titles |
229 | | - getInterWikiLinks: function(titles, optionalApiTags, interWikiLinksCallback) { |
230 | | - if (titles && titles.length) { |
231 | | - var urlData = wbUtil.stringFormat(this.wikiGetInterWikiLinksAPI, "en", encodeURIComponent(titles.replace("%20", " "))); |
232 | | - if (optionalApiTags) { |
233 | | - urlData = urlData + "&" + optionalApiTags; |
234 | | - } |
| 255 | + //gets the current article language code |
| 256 | + getCurrentLanguage: function() { |
| 257 | + return (typeof wikiSourceLanguage !== "undefined") ? wikiSourceLanguage : "en"; |
| 258 | + }, |
235 | 259 | |
236 | | - $.getJSON(urlData, 'callback=?', function(data) { |
237 | | - if (data) { |
238 | | - interWikiLinksCallback(data, titles); |
239 | | - } |
240 | | - }); |
241 | | - } |
242 | | - }, |
| 260 | + //checks for the given article availability in particular language. |
| 261 | + isArticleAvailable: function(lang, title, callback) { |
| 262 | + if (lang && lang.length && title && title.length) { |
| 263 | + var targetArticleWikiApi = wbUtil.stringFormat(wbWikiSite.wikiArticleMarkupAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
| 264 | + $.getJSON(targetArticleWikiApi, 'callback=?', function(data) { |
| 265 | + var pages = data.query.pages; |
| 266 | + if (pages) { |
| 267 | + for (var i in pages) { |
| 268 | + //if article data available |
| 269 | + if (pages[i].revisions) { |
| 270 | + callback(true); |
| 271 | + return; |
| 272 | + } |
| 273 | + else { |
| 274 | + callback(false); |
| 275 | + return; |
| 276 | + } |
| 277 | + } |
| 278 | + } |
| 279 | + else { |
| 280 | + callback(false); |
| 281 | + } |
| 282 | + }); |
| 283 | + } |
| 284 | + }, |
243 | 285 | |
244 | | - //gets the wiki edit page URL for the given title and language code |
245 | | - getEditPageUrl: function(lang, title) { |
246 | | - //if all the parameters are not null |
247 | | - if (lang && lang.length && title && title.length) { |
248 | | - return wbUtil.stringFormat(this.wikiEditUrl, lang, encodeURIComponent(title)); |
249 | | - } |
250 | | - }, |
| 286 | + //gets current page article title |
| 287 | + //NOTE: we need to depend on wikipedia's javascript variables to get current article title |
| 288 | + getCurrentArticleTitle: function() { |
| 289 | + if (typeof wgTitle !== "undefined") { |
| 290 | + if (wgAction === "view" && wgArticleId === 0 && wgIsArticle === false) { |
| 291 | + return false; |
| 292 | + } |
| 293 | + //in addition to the page title, get the name space also if it exists. |
| 294 | + if (typeof wgCanonicalNamespace !== "undefined" && wgCanonicalNamespace.length > 0) { |
| 295 | + return wgCanonicalNamespace + ":" + wgTitle; |
| 296 | + } |
| 297 | + return wgTitle; |
| 298 | + } |
| 299 | + }, |
251 | 300 | |
252 | | - //gets the current article language code |
253 | | - getCurrentLanguage: function() { |
254 | | - return (typeof wikiSourceLanguage !== "undefined") ? wikiSourceLanguage : "en"; |
255 | | - }, |
| 301 | + //checks whether current page is wikipedia main page or not |
| 302 | + //NOTE: we need to depend on wikipedia's javascript variables to check whether current page is main page or not |
| 303 | + isWikiMainPage: function() { |
| 304 | + return ((typeof wgPageName !== "undefined") && ((wgPageName === wgMainPageTitle) || (wgTitle === wgMainPageTitle))) ? true : false; |
| 305 | + }, |
256 | 306 | |
257 | | - //checks for the given article availability in particular language. |
258 | | - isArticleAvailable: function(lang, title, callback) { |
259 | | - if (lang && lang.length && title && title.length) { |
260 | | - var targetArticleWikiApi = wbUtil.stringFormat(wbWikiSite.wikiArticleMarkupAPI, lang, encodeURIComponent(title.replace("%20", " "))); |
261 | | - $.getJSON(targetArticleWikiApi, 'callback=?', function(data) { |
262 | | - var pages = data.query.pages; |
263 | | - if (pages) { |
264 | | - for (var i in pages) { |
265 | | - //if article data available |
266 | | - if (pages[i].revisions) { |
267 | | - callback(true); |
268 | | - return; |
269 | | - } |
270 | | - else { |
271 | | - callback(false); |
272 | | - return; |
273 | | - } |
274 | | - } |
275 | | - } |
276 | | - else { |
277 | | - callback(false); |
278 | | - } |
279 | | - }); |
280 | | - } |
281 | | - }, |
282 | | - |
283 | | - //gets current page article title |
284 | | - //NOTE: we need to depend on wikipedia's javascript variables to get current article title |
285 | | - getCurrentArticleTitle: function() { |
286 | | - if (typeof wgTitle !== "undefined") { |
287 | | - if (wgAction === "view" && wgArticleId === 0 && wgIsArticle === false) { |
288 | | - return false; |
289 | | - } |
290 | | - //in addition to the page title, get the name space also if it exists. |
291 | | - if (typeof wgCanonicalNamespace !== "undefined" && wgCanonicalNamespace.length > 0) { |
292 | | - return wgCanonicalNamespace + ":" + wgTitle; |
293 | | - } |
294 | | - return wgTitle; |
295 | | - } |
296 | | - }, |
297 | | - |
298 | | - //checks whether current page is wikipedia main page or not |
299 | | - //NOTE: we need to depend on wikipedia's javascript variables to check whether current page is main page or not |
300 | | - isWikiMainPage: function() { |
301 | | - return ((typeof wgPageName !== "undefined") && ((wgPageName === wgMainPageTitle) || (wgTitle === wgMainPageTitle))) ? true : false; |
302 | | - }, |
303 | | - |
304 | | - //checks whether current domain is wikipedia or not |
305 | | - isWikiDomain: function(url) { |
306 | | - return (url.match(this.wikiPageUrlRegex) === null) ? false : true; |
307 | | - }, |
308 | | - //function to view the preview of the edited article |
309 | | - getPreviewContent: function(lang, composeText, callback) { |
310 | | - urlData = wbUtil.stringFormat(wbWikiSite.wikiPreviewAPI, lang, encodeURIComponent(composeText.replace(/<br>/gi, '').replace(/<br\/>/ig, '').replace('\'\'', '\'')).replace(/'/g, '%27')); |
311 | | - $.getJSON(urlData, 'callback=?', function(data) { |
312 | | - if (data && data.parse && data.parse.text) { |
313 | | - callback(data.parse.text['*']); |
314 | | - }else{ |
315 | | - callback(false); |
316 | | - } |
317 | | - }); |
318 | | - } |
319 | | - }; |
| 307 | + //checks whether current domain is wikipedia or not |
| 308 | + isWikiDomain: function(url) { |
| 309 | + return (url.match(this.wikiPageUrlRegex) === null) ? false : true; |
| 310 | + }, |
| 311 | + //function to view the preview of the edited article |
| 312 | + getPreviewContent: function(lang, composeText, callback) { |
| 313 | + urlData = wbUtil.stringFormat(wbWikiSite.wikiPreviewAPI, lang, encodeURIComponent(composeText.replace(/<br>/gi, '').replace(/<br\/>/ig, '').replace('\'\'', '\'')).replace(/'/g, '%27')); |
| 314 | + $.getJSON(urlData, 'callback=?', function(data) { |
| 315 | + if (data && data.parse && data.parse.text) { |
| 316 | + callback(data.parse.text['*']); |
| 317 | + }else{ |
| 318 | + callback(false); |
| 319 | + } |
| 320 | + }); |
| 321 | + } |
| 322 | + }; |
320 | 323 | })(); |
\ No newline at end of file |
Index: trunk/extensions/WikiBhasha/src/js/core/paneManagement.js |
— | — | @@ -183,36 +183,17 @@ |
184 | 184 | saveButton.onclick = function() { |
185 | 185 | |
186 | 186 | // get the text from the wikipedia edit text area. |
187 | | - var composedContent = new String(wbPublishDisplayPane.getWikiTextareaElement().val()); |
188 | | - |
189 | | - /* |
190 | | - # the below code is to add an HTMl comment to the Wikipedia article edit box. |
191 | | - # the HTML comment is used to track the usage of the tool and this will be replaced with a better implementation soon. |
192 | | - |
193 | | - // get the version number which says number of times this document was edited using wikiBhasha |
194 | | - if (wbGlobalSettings.wbEditRevisionCount === null) { |
195 | | - // getEditVersion returns the version number if exists, otherwise it returns null |
196 | | - wbGlobalSettings.wbEditRevisionCount = wbPublishDisplayPane.getEditVersion(composedContent); |
| 187 | + var composedContent = new String(wbPublishDisplayPane.getWikiTextareaElement().val()); |
| 188 | + var summeryContent = new String(wbPublishDisplayPane.getWikiSummeryFieldElement().val()); |
| 189 | + |
| 190 | + if(summeryContent.length < (wbGlobalSettings.summeryFieldCutoffLength - wbGlobalSettings.snippet.length)){ |
| 191 | + //insert the snippet to the summery field'. |
| 192 | + summeryContent = summeryContent + wbGlobalSettings.snippet; |
| 193 | + // update the summery field content with the snippet. |
| 194 | + wbPublishDisplayPane.getWikiSummeryFieldElement().val(summeryContent); |
197 | 195 | } |
198 | | - |
199 | | - //Check the number of times this document edited using WikiBhasha. |
200 | | - //If this count is zero, that means document is edited using WikiBhasha for the first time |
201 | | - //and so insert the snippet "<!-- WikiBhasha v=1 time=[[timestamp]] -->" where v=1 says that this document is edited using WikiBhasha once at '[[timestamp]]'. |
202 | | - if (wbGlobalSettings.wbEditRevisionCount === null) { |
203 | | - var snippet = "\n<!-- WikiBhasha v=1 time=" + wbUIHelper.getTimeStamp() + "-->"; |
204 | | - composedContent = composedContent + snippet; |
205 | | - } |
206 | | - //If the count is non zero, increment the versioning count and updated the current time into existing code snippet. |
207 | | - else { |
208 | | - var regEx = /<!--\s*WikiBhasha\s*v=(\d*)\s*time=.*-->/ig, |
209 | | - snippet = "<!-- WikiBhasha v=" + (wbGlobalSettings.wbEditRevisionCount + 1) + " time=" + wbUIHelper.getTimeStamp() + "-->"; |
210 | | - composedContent = composedContent.replace(regEx, snippet); |
211 | | - } |
212 | | - */ |
213 | | - |
214 | 196 | // call the method to check and insert the interwiki link |
215 | 197 | composedContent = wbPublishDisplayPane.insertInterWikiLink(composedContent); |
216 | | - |
217 | 198 | // update the text area content with the snippet. |
218 | 199 | wbPublishDisplayPane.getWikiTextareaElement().val(composedContent); |
219 | 200 | // returning true will allow the execution to continue on saving the content in wikipedia. |
— | — | @@ -269,22 +250,12 @@ |
270 | 251 | |
271 | 252 | //gets the textarea element available in wiki edit page |
272 | 253 | getWikiTextareaElement: function() { |
273 | | - return $("#" + wbWikiSite.wikiComposeTextArea + ", textarea[name='" + wbWikiSite.wikiComposeTextArea + "']", wbPublishDisplayPane.wbChildWikipedia.document); |
| 254 | + return $("#" + wbWikiSite.wikiComposeTextArea , wbPublishDisplayPane.wbChildWikipedia.document); |
274 | 255 | }, |
275 | 256 | |
276 | | - //gets the number of times current document edited using WikiBhasha. |
277 | | - //Receives the content of the page and looks for the snippet "<!-- WikiBhasha v=[[editedCount]] time=[[timestamp]] -->”. If the snippet exists then it returns the count ‘[[editedCount]]’. Otherwise it returns null. |
278 | | - getEditVersion: function(wikiContent) { |
279 | | - if (wikiContent.search(/<!--\s*WikiBhasha\s*v=/ig) === -1) { |
280 | | - return null; |
281 | | - } |
282 | | - else { |
283 | | - var regEx = /<!--\s*WikiBhasha\s*v=(\d*)\s*time=/ig; |
284 | | - var temp = regEx.exec(wikiContent); |
285 | | - var verCount = parseInt(temp[1]); |
286 | | - return verCount; |
287 | | - } |
288 | | - return false; |
| 257 | + //gets the Summery Field element available in wiki edit page |
| 258 | + getWikiSummeryFieldElement: function() { |
| 259 | + return $("#" + wbWikiSite.wikiSummeryField , wbPublishDisplayPane.wbChildWikipedia.document); |
289 | 260 | }, |
290 | 261 | |
291 | 262 | // checks the inverwiki link and creates if it does not exist. |
Index: trunk/extensions/WikiBhasha/src/js/core/globalSettings.js |
— | — | @@ -86,7 +86,13 @@ |
87 | 87 | |
88 | 88 | //cutoff length to be used for pane titles |
89 | 89 | paneTitleCutoffLength: 100, |
| 90 | + |
| 91 | + //cutoff length to be used for edit page summery field |
| 92 | + summeryFieldCutoffLength: 200, |
90 | 93 | |
| 94 | + //WikiBhasha usage monitoring summery field snipet |
| 95 | + snippet: "<<WB1.1>>", |
| 96 | + |
91 | 97 | //max length of characters allowed by scratch pad window |
92 | 98 | scratchpadTextMaxLength: 1600, |
93 | 99 | |