Mediawiki and databases - mediawiki

Is there a way I can create a database from which to pull data into my mediawiki table? Or is there a way to have a database like drupal and place a mediawiki type interface on it?

There is no way to directly do this in stock MediaWiki, although you can fake it up somewhat with templates. For example, you could can a template something like this:
{{#switch:{{{key}}}
| key1 = value1
| key2 = value2
| key3 = value3
...
}}
Template:NUMBEROF/data on the English Wikipedia is an example of this style (with two levels of keys).
Or you can create a set of templates, one for each "record", that each take an "output formatter" template as a parameter and pass that output formatter a named parameter for each column in the record. The Country data templates on the English Wikipedia are an example of this pattern.
Or you could combine the above two styles, with one parameter to select the row (as in the first style) and a second to provide the output formatter (as in the second).
If you don't mind installing extensions, you could use the Labeled Section Transclusion extension to transclude sections of a data page. Or you could install the Semantic MediaWiki extension, which I hear allows all sorts of querying of data from the wiki's pages. Or you could install one of the many Database extensions that may allow you to do what you want. Or you could write your own database extension.

You could also have a look at http://www.mediawiki.org/wiki/Extension:Data_Transfer, which do not require Semantic MediaWiki even though it's written for use with SMW. (If you use SMW there are, as noted in an earlier reply, plenty extensions and built in options.)

Related

How to pass parameters or variables of arm template in log query

While working on log Queries in an arm template, I stuck with how to pass parameter values or variable values in the log Query.
parameters:
{
"resProviderName":
{
"value": "Microsoft.Storage"
}
}
For Eg:
AzureMetrics | where ResourceProvider == **parameters('resProviderName')** | where Resource == 'testacc'
Here I am facing an error like, it was taking parameters('resProviderName') as a value and it was not reading value from that particular parameter "resProviderName" and my requirement is to take the values from parameters or variables and should not hardcode like what I did in the above query as Resource=='testacc'.
Do we have any option to read the values from either parameters or variables in the log query?
If so, please help on this issue.
The answer to this would depend on what this query segment is a part of, and how your template is structured.
It appears that you're trying to reference a resource in the query. It is best to use one of the many available template resource functions if you want the details of the resource like its resourceID (within the resources section). When referencing a resource that is deployed in the same template, provide the name of the resource through a parameter. When referencing a resource that isn't deployed in the same template, fetch the resource ID.
Also, I'd recommend referring to the ARM snippet given this example to understand how queries can be constructed as custom variables as opposed to the other way round. According to ARM template best practices, variables should be used for values that you need to use more than once in a template. If a value is used only once, a hard-coded value makes your template easier to read. For more info, please take a look at this doc.
Hope this helps.
This is an old question but I bumped into this while searching for the same issue.
I'm much more familiar with Bicep templates so what I did to figure out was to create a Bicep template, construct the query by using the variables and compile it. This will generate a ARM template and you can analyze it.
I figured out you can use both concat or format functions in order to construct your query using variables.
I preferred the format one since it looks more elegant and readable (also, Bicep build generates the string using the format function).
So based on this example, the query would be something like this:
query: "[format('AzureMetrics | where ResourceProvider == {0} | where Resource == ''testacc'' ', parameters('resProviderName') )]"
Don't forget to escape the ' in the ARM template which you do by doubling the single quote.
I hope this helps some people.
André

How to get all allowed languages for Wikidata

I'm writing a tool for interacting with Wikidata where labels and descriptions are added to items. But I would like to validate that the language is supported before trying to add it.
So my question is how do I get a list of the allowed language codes. The documentation describes this as UserLanguageCode but gives no info on retrieving the allowed values.
I know I can get a list of all of the used languages by doing the following SQL operation on the database, but that is both slow and inefficient: SELECT DISTINCT term_language FROM wb_terms.
As an aside is the list of allowed languages the same for MonolingualText statements?
There is now an API for getting the supported content languages (API sandbox):
https://www.wikidata.org/w/api.php?action=query&meta=wbcontentlanguages&wbclcontext=term&format=json&formatversion=2
By default it just returns the language code, but you can add the name and/or autonym (name in that language) via the wbclprop parameter. (To control the language in which the name is returned, set the global uselang parameter.)
To get allowed monolingual text languages, set wbclcontext to monolingualtext instead of term; on Wikidata, you can also set it to term-lexicographical for all language codes supported on lexicographical data (almost but not quite identical to the term languages).
User hoo on IRC channel #wikidata found this solution:
Get the JSON payload at this address:
https://www.wikidata.org/w/api.php?action=paraminfo&modules=wbsetlabel
And extract
modules[0].parameters[8].type
There are indeed less languages in this list than all the UI languages for MediaWiki.

Japanese Wikipedia categories DAG defined in "categorylinks" table has a cycle

I have found a reference cycle in the DAG defined by "categorylinks" and "page" tables inside the japanese Wikipedia database.
Is this a bug in the data?
Page ids reference cycle:
2904319 -> 133683 -> 988775 -> 424676 -> 2904319
(行動 -> 生活 -> 人間関係 -> コミュニケーション -> 行動)
I am considering only sub-categories (page_namespace = 14).
In the Wiki Category documentation it explicitly states that:
All categories (except root category 1) should be contained in at least one other category, and there should be no cycles (i.e. a category should not contain itself, directly or indirectly).
Could the data be broken?
Am I misunderstanding anything?
The data is probably not broken. There is nothing in MediaWiki that prevents category loops, or cycles. Category structures like A < B < C < A are valid, and not uncommon in MediaWiki installations. Categories can also be orphaned, not belonging to any category.
The text you are quoting is not from the MediaWiki documentation, but from a Wikimedia help page. It refers to a recommendation by Wikimedia to try and keep categories hierarchical on Wikimedia wikis (e.g. Wikipedia). However, as this depends on the editors, you will find plenty of exceptions in any major Wikimedia wiki. Sometimes they are unintentional, and sometimes they are considered acceptable by the community for one reason or another.
A more relevant place to look in your case, is the corresponding help page, and the policy page for categories on Japanese Wikipedia. You'll find them here:
Help:カテゴリ
Wikipedia:カテゴリの方針

site wide (global) variables on mediawiki

Folks,
I'd like to have similar set up to the one discussed in this question
Can I use templates to form a set of variables that I can then later include in various points in my wiki pages.
so for example have varables in my single template called MAIN_WEB_URL and MAIN_TEAM_DISTRIBUTION_LIST that I can store in a single template and reference site-wide where needed.
I'd like to avoid a template per variable if possible, but the other question seems to imply this is the only way to do it...
One way to do this would be to create a template called something like Template:Variable. In it, you would use one big {{#switch}} that would contain the variables and their values (this requires the ParserFunctions extension):
{{#switch: {{{1}}}
| MAIN_WEB_URL = some value
| MAIN_TEAM_DISTRIBUTION_LIST = another value
}}
You would then call it like this:
{{variable|MAIN_WEB_URL}}
(BTW, I am not a fan of ALL_CAPS names and I think there is no reason to use them here, but that's up to you.)

Extract all words from text field in mysql

I have a table that contains text fields. In those fields I store text. There are around 20 to 50 sentences in each field depending on the row. I am making an auto-complete HTML object with HTML and PHP, and I would like to start typing the beginning of a word and that the database return sentences containing those words (Like Microsoft office 2007/2010 navigation pane).
I need mysql to return those words or sentences as a separate result, so i can manipulate them further.
Example:
--------------------------------------------------------------------
| id | title |content |
--------------------------------------------------------------------
1 | test 1 | PHP is a very nice language and has nice features.
2 | test 2 | Spain is a nice country to visit and has nice language.
3 | test 3 | Perl isn\'t as nice a language as PHP.
I need mysql query to return following as different result:
1,"nice language"
1,"nice features"
2,"nice country"
2,"nice langugage"
3,"nicea a language"
Here is my sql query:
SELECT id, SUBSTR(content,POSITION('nice' IN content),50)
FROM entries
MATCH (title,entry) AGAINST ('nice' WITH QUERY EXPANSION)
New Answer
OP is actually asking nothing to do with php and javascript - his question concerns doing string manipulation directly within MySQL.
String manipulation isn't really the main focus of a DBMS. When dealing with "words" in a fluid text sense, there's a lot of logic required to determine where the next word boundary is, and you don't want your database doing this really. Plus, any queries written to do this will probably be incredibly difficult to read.
It depends exactly what you are doing, but it's quite likely that a DB only approach will be slower because there will be more function calls: SQL functions are pretty limited.
And for re-usability and best practice, what if you wanted to change your database in the future to say MongoDB? You'd need to re-write the whole damned awkward query.
No, my suggestion would be to pull the whole value using standard MySQL into PHP, throw it into PCRE, very simple regex, job done. It's better to show what you're actually doing in your PHP code as it's more "intention revealing".
At least 33% of a developer's work is picking the right tool for the job. PHP is the right tool in this example.
Original Answer
You have included the tags php and javascript, so I'm guessing (although your question needs more clarification on this) that you obviously want this 'autocomplete' running client-side. So as a result, you have to get your data from server-side to client-side first.
Twitter Bootstrap has something really cool called Typeahead. This uses JavaScript to perform (what I think) you require: the example on that page shows how you can type a country and it'll auto-complete it for you. It looks like this:
How do you get this working? Include the required JavaScript file first, and then write your HTML.
Here's some from the source code of the bootstrap page so you can see how it works:
<input type="text" data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California"]'>
Can you see how the data-source attribute is the one that gives the typeahead the information you want? You want to connect to MySQL, grab your data, and shove these into the data-source array for the JavaScript to work with, as above.
So, on your page load, you connect to MySQL and you pull all the relevant strings you would like to be "auto-complete-able" from the Database. You then put these as new Data attributes for the typeahead, and that's pretty much it!
--
Edit: There's a fork of twitter bootstrap's typeahead that allows AJAX calls, so you could use this to perform the data retrieval asynchronously (if you can figure it out, I'd recommend this approach).