Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/246282
Change subject: Hygiene: Generalise search api requests across MobileFrontend
......................................................................
Hygiene: Generalise search api requests across MobileFrontend
By adding two config variables, this allows a MediaWiki instance
to tweak how searches are performed, where they might be different
for example Wikidata.
It also allows us to avoid getting warnings in API requests where
an optional extension such as Geodata or PageImages may not be installed.
TODO:
It seems it might be useful to generalise the displayTitle function so that
titles can be rendered differently to Wikidata users.
Change-Id: I49cf14db7857b077b8536ac654c04a4af2f4d2ee
---
M includes/Config.php
M includes/MobileFrontend.hooks.php
A includes/config/Search.php
M resources/mobile.nearby/NearbyGateway.js
M resources/mobile.search.api/SearchGateway.js
M resources/mobile.startup/Page.js
M resources/mobile.watchlist/WatchListGateway.js
7 files changed, 43 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/82/246282/1
diff --git a/includes/Config.php b/includes/Config.php
index 64442c9..bed0508 100644
--- a/includes/Config.php
+++ b/includes/Config.php
@@ -5,6 +5,7 @@
require_once __DIR__ . "/config/Experimental.php";
require_once __DIR__ . "/config/Legacy.php";
require_once __DIR__ . "/config/Nearby.php";
+ require_once __DIR__ . "/config/Search.php";
require_once __DIR__ . "/config/Site.php";
require_once __DIR__ . "/config/Skin.php";
require_once __DIR__ . "/config/Uploads.php";
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index 4c17e4d..ab3386b 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -339,9 +339,16 @@
$context = MobileContext::singleton();
$config = $context->getMFConfig();
+ $pageProps = $config->get( 'MFSearchPageProps' );
+ // Avoid API warnings and allow integration with optional
extensions.
+ if ( defined( 'PAGE_IMAGES_INSTALLED' ) ) {
+ $pageProps[] = 'pageimages';
+ }
+
// Get the licensing agreement that is displayed in the
uploading interface.
$wgMFUploadLicense = MobileFrontendSkinHooks::getLicense(
'upload' );
$vars += array(
+ 'wgMFSearchPageProps' => $pageProps,
'wgMFNearbyEndpoint' => $config->get(
'MFNearbyEndpoint' ),
'wgMFThumbnailSizes' => array(
'tiny' => MobilePage::TINY_IMAGE_WIDTH,
diff --git a/includes/config/Search.php b/includes/config/Search.php
new file mode 100644
index 0000000..827261a
--- /dev/null
+++ b/includes/config/Search.php
@@ -0,0 +1,15 @@
+<?php
+// Needs to be called within MediaWiki; not standalone
+if ( !defined( 'MEDIAWIKI' ) ) {
+ die( 'Not an entry point.' );
+}
+
+/**
+ * Define a set of params that should be passed in every gateway query.
+ */
+$wgMFSearchAPIParams = array( 'action' => 'query' );
+
+/**
+ * Define a set of page props that should be associated with requests for
pages via the API.
+ */
+$wgMFSearchPageProps = array();
diff --git a/resources/mobile.nearby/NearbyGateway.js
b/resources/mobile.nearby/NearbyGateway.js
index 926c28f..9e3a2c8 100644
--- a/resources/mobile.nearby/NearbyGateway.js
+++ b/resources/mobile.nearby/NearbyGateway.js
@@ -123,10 +123,8 @@
self = this;
requestParams = {
- action: 'query',
colimit: 'max',
- prop: 'pageprops|pageimages|coordinates',
- ppprop: 'displaytitle',
+ prop: [ 'pageprops', 'coordinates' ].concat(
mw.config.get( 'wgMFSearchPageProps' ) ),
pithumbsize: mw.config.get(
'wgMFThumbnailSizes' ).small,
pilimit: limit,
generator: 'geosearch',
@@ -135,7 +133,7 @@
ggslimit: limit,
formatversion: 2
};
- $.extend( requestParams, params );
+ $.extend( requestParams, params, mw.config.get(
'wgMFSearchAPIParams' ) );
this.api.ajax( requestParams ).then( function ( resp ) {
var pages;
@@ -170,7 +168,6 @@
var coords, lngLat, p;
// FIXME: API returns pageid rather
than id, should we rename Page option ?
page.id = page.pageid;
- page.displayTitle = page.pageprops &&
page.pageprops.displaytitle || '';
p = new Page( page );
p.anchor = 'item_' + i;
if ( page.coordinates && loc ) { //
FIXME: protect against bug 47133 (remove when resolved)
diff --git a/resources/mobile.search.api/SearchGateway.js
b/resources/mobile.search.api/SearchGateway.js
index c88f4f7..f8aa9d6 100644
--- a/resources/mobile.search.api/SearchGateway.js
+++ b/resources/mobile.search.api/SearchGateway.js
@@ -25,13 +25,12 @@
* @return {Object}
*/
getApiData: function ( query ) {
- return {
- action: 'query',
+ return $.extend( {
generator: 'prefixsearch',
gpssearch: query,
gpsnamespace: this.searchNamespace,
gpslimit: 15,
- prop: 'pageimages',
+ prop: mw.config.get( 'wgMFSearchPageProps' ),
piprop: 'thumbnail',
pithumbsize: mw.config.get(
'wgMFThumbnailSizes' ).tiny,
pilimit: 15,
@@ -39,7 +38,7 @@
list: 'prefixsearch',
pssearch: query,
pslimit: 15
- };
+ }, mw.config.get( 'wgMFSearchAPIParams' ) );
},
/**
diff --git a/resources/mobile.startup/Page.js b/resources/mobile.startup/Page.js
index 16c6367..9fe016b 100644
--- a/resources/mobile.startup/Page.js
+++ b/resources/mobile.startup/Page.js
@@ -65,13 +65,13 @@
var thumb;
// Fallback if no displayTitle provided
- options.displayTitle = options.displayTitle ||
options.title;
+ options.displayTitle = this.getDisplayTitle( options );
options.languageUrl = mw.util.getUrl(
'Special:MobileLanguages/' + options.title );
View.prototype.initialize.apply( this, arguments );
// allow usage in templates.
// FIXME: Should View map all options to properties?
this.title = options.title;
- this.displayTitle = options.displayTitle ||
options.title;
+ this.displayTitle = this.getDisplayTitle();
this.thumbnail = options.thumbnail;
this.url = options.url || mw.util.getUrl( options.title
);
this.id = options.id;
@@ -82,7 +82,17 @@
}
this.wikidataDescription = options.wikidataDescription;
},
-
+ /**
+ * Retrieve the title that should be displayed to the user
+ * @method
+ * @param [{Object}] options to select a titlefrom.
+ * @return {String}
+ */
+ getDisplayTitle: function ( options ) {
+ options = options || this.options;
+ // TODO: This could be configurable...?
+ return options.displayTitle || options.title;
+ },
/**
* Determine if current page is in a specified namespace
* @method
diff --git a/resources/mobile.watchlist/WatchListGateway.js
b/resources/mobile.watchlist/WatchListGateway.js
index 1b34abd..50ce170 100644
--- a/resources/mobile.watchlist/WatchListGateway.js
+++ b/resources/mobile.watchlist/WatchListGateway.js
@@ -35,7 +35,7 @@
var self = this,
params = $.extend( {
action: 'query',
- prop: 'pageimages|info|revisions',
+ prop: [ 'info|revisions' ].concat(
mw.config.get( 'wgMFSearchPageProps' ) ),
piprop: 'thumbnail',
pithumbsize: mw.config.get(
'wgMFThumbnailSizes' ).tiny,
pilimit: this.limit,
@@ -45,7 +45,7 @@
generator: 'watchlistraw',
gwrnamespace: '0',
gwrlimit: this.limit
- }, this.continueParams );
+ }, mw.config.get( 'wgMFSearchAPIParams' ),
this.continueParams );
if ( this.canContinue === false ) {
return $.Deferred();
--
To view, visit https://gerrit.wikimedia.org/r/246282
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I49cf14db7857b077b8536ac654c04a4af2f4d2ee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits