Bmansurov has uploaded a new change for review. https://gerrit.wikimedia.org/r/202092
Change subject: Alpha: better parsing for a link title for quickLookup ...................................................................... Alpha: better parsing for a link title for quickLookup Previously we used to look information up about a link by looking at the link's text, which usually didn't match the page title the link pointed to. This patch extracts the page title by looking at the href of a link instead. Change-Id: Icf7a2cfd9b3501a124552a3b2967dbc66ff2b2dd --- M includes/Resources.php M javascripts/modules/quickLookup/init.js 2 files changed, 28 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/92/202092/1 diff --git a/includes/Resources.php b/includes/Resources.php index b081bef..acab1dd 100644 --- a/includes/Resources.php +++ b/includes/Resources.php @@ -1058,6 +1058,8 @@ 'mobile.quickLookup' => $wgMFResourceParsedMessageModuleBoilerplate + array( 'dependencies' => array( + 'mediawiki.Title', + 'mediawiki.Uri', 'mobile.startup', 'mobile.drawers', 'mobile.toast', diff --git a/javascripts/modules/quickLookup/init.js b/javascripts/modules/quickLookup/init.js index cf0a777..e7ff624 100644 --- a/javascripts/modules/quickLookup/init.js +++ b/javascripts/modules/quickLookup/init.js @@ -13,8 +13,9 @@ /** * Search API for a brief intro about a page. * @param {String} title title of the page + * @param {String} titleText user friendly text of the title */ - function lookup( title ) { + function lookup( title, titleText ) { var deferred = $.Deferred(), promise = deferred.promise(); @@ -44,7 +45,7 @@ extract = OO.getProp( pages, pageID, 'extract' ); if ( extract ) { cache[title] = { - title: title, + title: titleText, text: extract, id: pageID }; @@ -70,25 +71,41 @@ * @param {jQuery.Event} ev Event object of the swipe gesture */ function showDrawer( ev ) { - var link = ev.currentTarget, - title = $( link ).text(); + var uri, + title; toast.hide(); if ( drawer ) { drawer.hide(); } - if ( link.hostname === hostname ) { - toast.show( 'Looking for <b>' + title + '</b>...', 'toast quick-lookup' ); - lookup( title ).done( function ( page ) { + try { + uri = new mw.Uri( ev.currentTarget.href ); + } catch ( e ) { + // invalid link + toast.show( 'Sorry, could not parse the url.', 'toast quick-lookup' ); + return; + } + + if ( uri && uri.host === hostname ) { + if ( /^\/wiki\/.+$/.test( uri.path ) ) { + // create a mw.Title object from the url decoding it and skipping the '/wiki/' part + title = mw.Title.newFromText( decodeURI( uri.path ).substr( 6 ) ); + } + } + + if ( title ) { + toast.show( 'Looking for <b>"' + title.getMainText() + '"</b>...', 'toast quick-lookup' ); + lookup( title.getMain(), title.getMainText() ).done( function ( page ) { toast.hide(); drawer = new QuickLookupDrawer( page ); drawer.show(); } ).fail( function () { - toast.show( 'Couldn\'t find anything matching <b>' + title + '</b>.', 'toast quick-lookup' ); + toast.show( 'Couldn\'t find anything matching <b>"' + title.getMainText() + '"</b>.', + 'toast quick-lookup' ); } ); } else { - toast.show( 'Sorry, only internal links are searchable.', 'toast quick-lookup' ); + toast.show( 'Sorry, nothing found.', 'toast quick-lookup' ); } } -- To view, visit https://gerrit.wikimedia.org/r/202092 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icf7a2cfd9b3501a124552a3b2967dbc66ff2b2dd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits