Mholloway has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/284267

Change subject: Redirect incorrect domain to wiktionary.org instead of throwing 
error
......................................................................

Redirect incorrect domain to wiktionary.org instead of throwing error

While debugging or otherwise making definition requests from the browser
for whatever reason, it's easy to request a definition from wikipedia.org
by mistake.  Redirecting such requests rather than throwing an error makes
life easier.

Change-Id: Id80ab530b3175fb745c2ccccbc5384f897fc073d
---
M lib/parsoid-access.js
M routes/definition.js
2 files changed, 6 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/67/284267/1

diff --git a/lib/parsoid-access.js b/lib/parsoid-access.js
index ffc3df6..dc324e5 100644
--- a/lib/parsoid-access.js
+++ b/lib/parsoid-access.js
@@ -257,14 +257,6 @@
  * @return {promise} a promise to retrieve a set of definitions from 
Wiktionary.
  */
 function definitionPromise(app, req) {
-    if (req.params.domain.indexOf('wiktionary.org') === -1) {
-        throw new sUtil.HTTPError({
-            status: 400,
-            type: 'invalid_domain',
-            title: 'Invalid domain',
-            detail: 'Definition requests only supported for wiktionary.org 
domains.'
-        });
-    }
     if (req.params.domain.indexOf('en') !== 0) {
         throw new sUtil.HTTPError({
             status: 501,
diff --git a/routes/definition.js b/routes/definition.js
index 95e22ac..21a7dc9 100644
--- a/routes/definition.js
+++ b/routes/definition.js
@@ -25,6 +25,12 @@
  * Gets the Wiktionary definition for a given term (and optional revision ID).
  */
 router.get('/definition/:title/:revision?', function (req, res) {
+    if (req.params.domain.indexOf('wiktionary.org') === -1) {
+        var domain = req.params.domain;
+        var langCode = domain.substring(0, domain.indexOf('.'));
+        return res.redirect(req.originalUrl.replace(req.params.domain,
+          langCode + '.wiktionary.org'));
+    }
     return parsoid.definitionPromise(app, req)
     .then(function (response) {
         res.status(200);

-- 
To view, visit https://gerrit.wikimedia.org/r/284267
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id80ab530b3175fb745c2ccccbc5384f897fc073d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to