Extension talk:External Data

From MediaWiki.org
Jump to navigation Jump to search

Get template data from another wiki[edit]

Hello, Can I use this extension to do a semantic query from another site?

If I have a a page "Foo" on SiteA that contains a template "Foo" as:

{{Foo|Bar=123}} 

and I want to create a page on SiteB called "Foo Status" that contains a template "Foo" as:

{{Foo|Bar= {{#get_web_data:url=SiteA |format={???}}} |}}

is this possible?

Yes - if the source wiki stores its data via either SMW or Cargo, both of those extensions provide an API of sorts to let you get query results in either CSV or JSON formats, either of which is parseable by External Data. Yaron Koren (talk) 18:46, 17 April 2019 (UTC)
Thanks, Yaron. Any chance you could point me to an SMW example of this? :-)
I can't think of one. Yaron Koren (talk) 02:18, 18 April 2019 (UTC)

prerequisites for getting LDAP data[edit]

Hi.

I'm trying to use the #get_ldap_data: function of "External Data" to get LDAP attributes about my users and I'm getting the following error:

Fatal error: Call to undefined function ldap_connect() in /opt/htdocs/mediawiki/extensions/ExternalData/ED_Utils.php on line 136

A quick "grep -R ldap_connect" in the "extensions/External Data" folder shows only a use-call to ldap_connect and nothing anywhere actually defining it.

A quick search online of "ldap_connect" seems to indicate that it is defined in the PHP module "PHP-LDAP"

A quick inspection of my phpinfo() page shows that the php-ldap module is not loaded.

Before I install the php-ldap module on my system, can someone confirm that php-ldap is indeed a pre-requisite for the #get_ldap_data: function of "External Data" to work.

Poor man's Sync from WikiA to WikiB[edit]

Hi.

Can I use this extension as a real-time clone of a page in one wiki to another?

For example, Mediawiki Site A has a page called "Foo" with arbitrary text.

Can I create a page called "Foo" on another wiki that contains something like:

{{#get_web_data:url=https://www.mysite.com/A/Special:GetData/Foo|format=raw|data=Foo=Foo}}
{{#external_value:Foo}}

and functionally get a copy of the page Foo on Site A?

Well, I'm pretty you can get the right wikitext - after all, a single piece of text is valid CSV. Whether it'll display correctly is a different story - template calls won't work, for instance, unless you have a local copy of those templates. It's probably easier to just do an iframe, using one of the iframe-supporting extensions, with "action=render" on the source URL to leave out the skin. Yaron Koren (talk) 02:25, 18 April 2019 (UTC)

Nested SQL functions throw a rdbms error[edit]

ExternalData (rdbms error with nested sql commands).png
Per an email with Yoren, "There's no special handling of replace() or any other commands."
This would lead me to think the below syntax should work... but it does not.
Does anyone have any suggestions or corrections to the code I'm trying to get working? Much appreciated if you do.

Unable to perform nested SQL REPLACE functions[edit]

I am attempting to query data from a local database, but need to replace 3 different characters with alternatives that won't trigger mediawiki parsing of the result. No matter the format I have tried, I receive the error pictured to the right when trying to display the page.

This snippet works, but only replaces one of the three characters necessary:

|data=zoneNAME=replace(zone_settings.name,'_',' ')

I need the below SQL code to work, but it creates a parse error whenever run inside a mediawiki page:

|data=zoneNAME=replace(replace(replace(zone_settings.name,'_',' '), '[','('), ']',')')

or with html codes in place of characters:

|data=zoneNAME=replace(replace(replace(zone_settings.name,'_',' '), [,(), ],))

and in any combination of the character/html code I could think of. I even tried variations using the mediawiki replace command like this:

|data=zoneNAME={{#replace:{{#replace:(replace(zone_settings.name,'_',' ')|[|(}}|]|)}}

and

|data=zoneNAME={{#replace:{{#replace:(replace(zone_settings.name,'_',' ')|<nowiki>[</nowiki>|<nowiki>(</nowiki>}}|<nowiki>]</nowiki>|<nowiki>)</nowiki>}}

Same error, different SQL commands[edit]

In a very similar usage scenario, I would like to capitalize the first letter of the string returned, and make sure the rest of the letters are lowercase. Unfortunately, I must also replace all '_' with a space, as in my above issue. Each of these examples works separately, but once they are nested together, I get the same error as in my image above:

|data=itemNAME=REPLACE(item_basic.name,'_',' ')
|data=itemNAME=UCASE(item_basic.name)
|data=itemNAME=LCASE(item_basic.name)

Once nested, in any combination, the same error as above is shown:

|data=itemNAME=REPLACE(UCASE(item_basic.name),'_',' ')

Eventually, this is the SQL I would like run, but if it's too much for the extension I will work on finding a different solution:

CONCAT(UCASE(LEFT(item_basic.name, 1)), LCASE(SUBSTRING(item_basic.name, 2)))

or

UPPER(LEFT(mob_spawn_points.polutils_name,1))+LOWER(SUBSTRING(mob_spawn_points.polutils_name,2,LEN(mob_spawn_points.polutils_name)))

Thanks for any help provided!

Get nested JSON data[edit]

If an API returns a non-flat JSON structure, it seems like it's not possible to access the deeper data. Or is it? Sophivorus (talk) 03:27, 28 June 2019 (UTC)