Extension:Wikibase Repository

From MediaWiki.org
(Redirected from Extension:Wikibase)
Jump to: navigation, search
shortcut: WBR
MediaWiki extensions manual - list
Crystal Clear action run.png
Wikibase Repository

Release status: beta

Implementation API, Ajax, User interface, ContentHandler
Description Structured data repository
Author(s) The Wikidata team
(contributors list)
Latest version 0.5 alpha (2013-08-30)
MediaWiki 1.23.0 or higher
PHP 5.3 or above
Database changes yes
License GNU GPL v2+
Download
readme
release notes

Translate the Wikibase Repository extension if possible

Check usage and version matrix; code metrics
Bugs: list open list all report

Wikibase is an extension that allows you to use your wiki as a structured data repository. Its development is part of the Wikidata project. The data can in turn be used in a wiki using the Wikibase Client extension.

Feature overview[edit | edit source]

  • Creation and maintenance of items
  • Histories and diffs of structured data
  • Labels, descriptions, and aliases for items
  • Rich interface and functionality for managing language links to items
  • Adds the content handler for structured data

Requirements[edit | edit source]

Wikibase Repository requires:

Wikibase optionally depends on:

And one of the following:

Download[edit | edit source]

Wikibase Repository is included in Wikidata build

You can download the extension directly from the MediaWiki source code repository (browse code). You can get:

One of the extensions tags

Not all extensions have tags. Some extensions have tags for each release, in which case those tags have the same stability as the release. To download a tag

  • Go to the tags list
  • Click the name of the tag you want to download
  • Click "snapshot"
The latest version of one of the extensions branches

Each extension has a master branch containing the latest code (might be unstable). Extensions can have further branches as well.

  • Go to the branches list
  • Click the branch name
  • Click "snapshot"
A snapshot made during the release of a MediaWiki version.

This might be unstable and is not guaranteed to work with the associated MediaWiki version.

After you've got the code, save it into the extensions/Wikibase directory of your wiki.

If you are familiar with git and have shell access to your server, you can obtain the extension, with all its tags and branches, as follows:

cd extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Wikibase.git

Installation[edit | edit source]

Wikibase supports composer for installing all its dependencies. You can try using composer to make installation of dependencies easier, and then look at the config info below.

If you want items in the main namespace, then delete or move your Main Page before enabling Wikibase.

Now add the following code to your LocalSettings.php file:

# Wikibase
require_once( "$IP/extensions/Wikibase/repo/Wikibase.php" );

Then run php maintenance/update.php

this will fail without having set up the namespaces as described below (by default and you will not get an error message)

You will need to run the populateSitesTable.php maintenance script in Wikibase Lib:

php extensions/Wikibase/lib/maintenance/populateSitesTable.php

The script is by default configured to fetch sites matrix information from meta.wikimedia.org via a https connection. If you have any problems with the script, then try specifying the --load-from http://meta.wikimedia.org/w/api.php option (without the https).

You need to configure which namespaces should be used before the extension will work. Wikibase needs three namespaces: one for items, one for properties and one for queries. Typically these are either three new namespaces, or two new ones and the main namespace being used for items. Both set ups are given in the following. You can also simply add require_once( "$IP/extensions/Wikibase/repo/ExampleSettings.php" ); to your LocalSettings.php (after the require_once of lib/WikibaseLib.php and repo/Wikibase.php).

After that, run php maintenance/update.php from your MediaWiki root directory.

Note: If the Wikibase extensions are already present when the Mediawiki installation is run, it will add the following lines to LocalSettings.php, which will cause Mediawiki to display This script must be run from the command line and nothing else:

require_once( "$IP/extensions/Wikibase/Wikibase.php" );
require_once( "$IP/extensions/WikibaseDataModel/WikibaseDataModel.php" );

These lines have to be removed and replaced by the ones stated above.

Setting up items in the main namespace[edit | edit source]

If you want to set up your items in the main namespace:

$baseNs = 100;
 
// Define the namespace indexes
define( 'WB_NS_PROPERTY', $baseNs + 2 );
define( 'WB_NS_PROPERTY_TALK', $baseNs + 3 );
 
// Define the namespaces
$wgExtraNamespaces[WB_NS_PROPERTY] = 'Property';
$wgExtraNamespaces[WB_NS_PROPERTY_TALK] = 'Property_talk';
 
// Assigning the correct content models to the namespaces
$wgWBRepoSettings['entityNamespaces'][CONTENT_MODEL_WIKIBASE_ITEM] = NS_MAIN; 
$wgWBRepoSettings['entityNamespaces'][CONTENT_MODEL_WIKIBASE_PROPERTY] = WB_NS_PROPERTY;

If you are also using the query components, then you can add:

define( 'WB_NS_QUERY', $baseNs + 4 );
define( 'WB_NS_QUERY_TALK', $baseNs + 5 );
 
$wgExtraNamespaces[WB_NS_QUERY] = 'Query';
$wgExtraNamespaces[WB_NS_QUERY_TALK] = 'Query_talk';
 
$wgWBRepoSettings['entityNamespaces'][CONTENT_MODEL_WIKIBASE_QUERY] = WB_NS_QUERY;

Note that if the "Main Page" is still in the Main namespace there will be thrown an exception, at least when you try to access that page. If you see this exception comment out the content model for the Main namespace, and then move the "Main Page" out of Main space without leaving an redirect. Usually the page will be moved to "Project:Main Page". If so the system message Mediawiki:Mainpage should be updated, or a similar message if Mediawiki:Sidebar is changed. Also check if there are other pages in the Main namespace by using Special:Allpages. After the Main namespace is cleansed for other pages you can reenable the content model for Main namespace.

Items in a dedicated item namespace[edit | edit source]

If you want to set up your items in a namespace of its own, here called Item:

$baseNs = 100;
 
// Define the namespace indexes
define( 'WB_NS_DATA', $baseNs );
define( 'WB_NS_DATA_TALK', $baseNs + 1 );
define( 'WB_NS_PROPERTY', $baseNs + 2 );
define( 'WB_NS_PROPERTY_TALK', $baseNs + 3 );
 
// Define the namespaces
$wgExtraNamespaces[WB_NS_DATA] = 'Item';
$wgExtraNamespaces[WB_NS_DATA_TALK] = 'Item_talk';
$wgExtraNamespaces[WB_NS_PROPERTY] = 'Property';
$wgExtraNamespaces[WB_NS_PROPERTY_TALK] = 'Property_talk';
 
// Making the namespaces searched by default
$wgNamespacesToBeSearchedDefault[WB_NS_DATA] = true;
$wgNamespacesToBeSearchedDefault[WB_NS_PROPERTY] = true;
 
// Assigning the correct content models to the namespaces
$wgNamespaceContentModels[WB_NS_DATA] = CONTENT_MODEL_WIKIBASE_ITEM;
$wgNamespaceContentModels[WB_NS_PROPERTY] = CONTENT_MODEL_WIKIBASE_PROPERTY;

If you are using (and enabling) the query components of Wikibase, then you can add the following in addition:

define( 'WB_NS_QUERY', $baseNs + 4 );
define( 'WB_NS_QUERY_TALK', $baseNs + 5 );
 
$wgExtraNamespaces[WB_NS_QUERY] = 'Query';
$wgExtraNamespaces[WB_NS_QUERY_TALK] = 'Query_talk';
 
$wgNamespacesToBeSearchedDefault[WB_NS_QUERY] = true;
$wgNamespaceContentModels[WB_NS_QUERY] = CONTENT_MODEL_WIKIBASE_QUERY;

HTML5[edit | edit source]

The extension uses HTML5 specific attributes, and because of this the $wgHtml5 must be set to true in pre MW 1.22. In MW 1.22 and later versions this configurable feature is removed and the returned code is always HTML5.

Configuration[edit | edit source]


Configuration of Wikibase Repository is done by assigning to $wgWBRepoSettings in your LocalSettings.php file. The options are listed below and their default is set in the Wikibase Repository settings file. You should not modify the settings file, but can have a look at it to get an idea of how to use the settings, in case the below descriptions do not suffice.

The extension use the variable name $wgWBRepoSettings, note the initial prefix $wg, while configuration of other extensions might use the initial prefix $eg. The difference is important and the configuration will fail if the latter is used.

Example of how to change a setting:

$wgWBRepoSettings['serializationFormat'] = 'application/json';

Available settings:

  • The available settings are documented in extensions/Wikibase/docs/options.wiki docs/options.wiki


Maintenance scripts[edit | edit source]

This extension has some maintenance scripts in the maintenance subdirectory. They assume that the extension is installed in the extensions directory of the MediaWiki software (i.e. files are in the extensions/Wikibase directory), if this is not the case, you can set the MW_INSTALL_PATH environment variable to the path of your MediaWiki installation and the scripts will use it.

An usual way to set the environment for scripts run by cron jobs is to do something like

env 'MW_INSTALL_PATH=/var/www/repo' php …

This should then run whatever php-script you want to append after the php interpreter.

rebuildAllData.php[edit | edit source]

This script should rebuild all the Wikidata data in secondary storage from articles in Data namespace. You may use it to rebuild data after testing.

deleteAllData.php[edit | edit source]

This script should delete all the Wikidata data in secondary storage and articles in Data namespace. You may use it to delete the data after testing.

populateSitesTable.php[edit | edit source]

This script will load the wiki matrix from meta.wikimedia.org and use that information to populate the local sites table. This provides Wikibase with the information it needs to connect to other wikis, e.g. to suggest or normalize the titles of pages when creating site links.

extractInterlang.sql[edit | edit source]

This is an SQL query that extracts interlanguage links from a wiki in a format readable by importInterlang.php. You may use it in a database of a wiki that has interlanguage links, so that you can later import them for testings.

importInterlang.php[edit | edit source]

This script imports interlanguage links from a file into a wiki, also creating labels in the process. The file is a tab-separated CSV file, in the following format:

page_title     ll_lang   ll_title
-архија        cs        Seznam forem vlády
-архија        de        Liste der Staatsformen und Regierungssysteme
-архија        en        Government#Forms of government
-архија        eo        Listo de formoj de registaro
-архија        es        Anexo:Formas de gobierno
-архија        fr        Liste de formes de gouvernements
-архија        jv        Daftar wangun pamaréntahan
-архија        ku        Lîsteya pergalên siyasî
-архија        mk        Список на општествени уредувања
-графија       de        -graphie
-графија       en        -graphy
-графија       id        -grafi
-графија       ka        ...გრაფია
-графија       sv        -grafi

The first row of the file is ignored.

  • The first column contains article titles of articles on the base wiki (the wiki the links are linked from).
  • The second column contains language codes of the links.
  • The third column contains article titles of the linked articles.

Script options:

  • --verbose: if set, the script will print API requests, responses, and other information.
  • --ignore-errors: if set, the script will ignore API errors and continue importing even if it encounters an error.
  • <lang>: This should be the language code of the base wiki, the wiki you have extracted interlanguage links from.
  • <filename>: The file with interlanguage links, presumably generated by extractInterlang.sql.
  • <api>: Base API url of the wiki you are importing the link into. For example, http://localhost/wiki/w/api.php

Example command line:

php importInterlang.php --verbose --ignore-errors sr sr_interwiki.csv http://localhost/wiki/w/api.php

To import the test items from extensions/Wikibase/repo/maintenance run

php importInterlang.php --verbose --ignore-errors simple simple-elements.csv

pruneChanges.php[edit | edit source]

This script is located in Wikibase/repo/maintenance/pruneChanges.php. It allows to prune the Wikibase changes table. If you run it without any parameters, it will delete all changes older than 7 days. To delete all changes older than 1 day run

php pruneChanges.php --number-of-days 1
11:07:46 pruning entries older than 2012-12-11T11:07:46Z
11:07:47 151 rows pruned
11:07:47 done, exiting

createBlacklistedItems.php[edit | edit source]

This script creates blacklisted items in Wikidata Data namespace, typically to create easter eggs and similar. The actual data is hardcoded in the script. You may use it before the item ids reaches the first blacklisted items.

importProperties.php[edit | edit source]

Maintenance script for importing properties in Wikidata. Usually this will use the example file in en-elements-properties.csv as source while building the example entries. You may also use it to create other entries for testing.

To import the test properties from extensions/Wikibase/repo/maintenance run

php importProperties.php --verbose en en-elements-properties.csv

rebuildEntityPerPage.php[edit | edit source]

Maintenance script for rebuilding the items_per_page table.

rebuildTermsSearchKey.php[edit | edit source]

Maintenance script for rebuilding the search key of the TermSQLCache. The search key is an additional column in the wb_terms table. This column is optional in the table and is used for caseless searches.

searchEntityArtefacts.php[edit | edit source]

This is a maintenance script that queries the database for entity artifacts. During use the database accumulates failed entries and this script tries to find them and print them.

Version[edit | edit source]

This is a copy of the release notes file on Git, which might be more up to date than this page.

Internationalization[edit | edit source]

Wikibase Repository is fully internationalized. Translation of Wikibase Repository messages is done through translatewiki.net. The translation for this extension can be found here. To add language values or change existing ones, you should create an account on translatewiki.net, then request permission from the administrators to translate a certain language or languages on this page (this is a very simple process). Once you have permission for a given language, you can log in and add or edit whatever messages you want to in that language.

Screenshots[edit | edit source]

See also[edit | edit source]

External links[edit | edit source]


This page contains changes which are not marked for translation.