Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 118
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CreateReservedLexemes
0.00% covered (danger)
0.00%
0 / 112
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 109
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Wikibase;
4
5use MediaWiki\Maintenance\Maintenance;
6use MediaWiki\User\User;
7use Wikibase\DataModel\Entity\ItemId;
8use Wikibase\DataModel\Term\Term;
9use Wikibase\DataModel\Term\TermList;
10use Wikibase\Lexeme\Domain\Model\Lexeme;
11use Wikibase\Lexeme\Domain\Model\LexemeId;
12use Wikibase\Lib\WikibaseSettings;
13use Wikibase\Repo\WikibaseRepo;
14
15$basePath = getenv( 'MW_INSTALL_PATH' ) !== false
16    ? getenv( 'MW_INSTALL_PATH' )
17    : __DIR__ . '/../../../..';
18
19require_once $basePath . '/maintenance/Maintenance.php';
20
21/**
22 * Maintenance script for creating reserved Lexeme entities.
23 *
24 * @license GPL-2.0-or-later
25 * @author Addshore
26 */
27class CreateReservedLexemes extends Maintenance {
28
29    private const LEMMA = 'lemma';
30    private const LANGUAGE = 'lang';
31    private const CATEGORY = 'cat';
32
33    public function __construct() {
34        parent::__construct();
35
36        $this->addDescription( 'Created reserved lexemes' );
37
38        $this->requireExtension( 'WikibaseLexeme' );
39    }
40
41    public function execute() {
42        $user = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
43        $store = WikibaseRepo::getEntityStore();
44
45        if ( !WikibaseSettings::isRepoEnabled() ) {
46            $this->fatalError(
47                "You need to have Wikibase enabled in order to use this maintenance script!\n\n"
48            );
49        }
50
51        $entities = [
52            'L1' => [
53                self::LEMMA => new Term( 'mis-x-Q36790', 'ama' ),
54                self::CATEGORY => new ItemId( 'Q1084' ),
55                self::LANGUAGE => new ItemId( 'Q36790' ),
56            ],
57
58            'L42' => [
59                self::LEMMA => new Term( 'en', 'answer' ),
60                self::CATEGORY => new ItemId( 'Q1084' ),
61                self::LANGUAGE => new ItemId( 'Q1860' ),
62            ],
63
64            'L99' => [
65                self::LEMMA => new Term( 'de', 'Luftballon' ),
66                self::CATEGORY => new ItemId( 'Q1084' ),
67                self::LANGUAGE => new ItemId( 'Q188' ),
68            ],
69
70            'L777' => [
71                self::LEMMA => new Term( 'pt', 'ganhar' ),
72                self::CATEGORY => new ItemId( 'Q24905' ),
73                self::LANGUAGE => new ItemId( 'Q5146' ),
74            ],
75
76            'L666' => [
77                self::LEMMA => new Term( 'ru', 'зверь' ),
78                self::CATEGORY => new ItemId( 'Q1084' ),
79                self::LANGUAGE => new ItemId( 'Q7737' ),
80            ],
81
82            'L8' => [
83                self::LEMMA => new Term( 'en', 'late' ),
84                self::CATEGORY => new ItemId( 'Q34698' ),
85                self::LANGUAGE => new ItemId( 'Q1860' ),
86            ],
87
88            'L55' => [
89                self::LEMMA => new Term( 'ja', 'こども' ),
90                self::CATEGORY => new ItemId( 'Q1084' ),
91                self::LANGUAGE => new ItemId( 'Q5287' ),
92            ],
93
94            'L221' => [
95                self::LEMMA => new Term( 'en', 'elementary' ),
96                self::CATEGORY => new ItemId( 'Q34698' ),
97                self::LANGUAGE => new ItemId( 'Q1860' ),
98            ],
99
100            'L314' => [
101                self::LEMMA => new Term( 'ca', 'pi' ),
102                self::CATEGORY => new ItemId( 'Q1084' ),
103                self::LANGUAGE => new ItemId( 'Q7026' ),
104            ],
105
106            'L1887' => [
107                self::LEMMA => new Term( 'eo', 'unua' ),
108                self::CATEGORY => new ItemId( 'Q34698' ),
109                self::LANGUAGE => new ItemId( 'Q143' ),
110            ],
111
112            'L117' => [
113                self::LEMMA => new Term( 'da', 'gentagelse' ),
114                self::CATEGORY => new ItemId( 'Q1084' ),
115                self::LANGUAGE => new ItemId( 'Q9035' ),
116            ],
117
118            'L12345' => [
119                self::LEMMA => new Term( 'ar', 'صِفْر' ),
120                self::CATEGORY => new ItemId( 'Q34698' ),
121                self::LANGUAGE => new ItemId( 'Q13955' ),
122            ],
123
124            'L5' => [
125                self::LEMMA => new Term( 'es', 'pino' ),
126                self::CATEGORY => new ItemId( 'Q1084' ),
127                self::LANGUAGE => new ItemId( 'Q1321' ),
128            ],
129
130            'L24601' => [
131                self::LEMMA => new Term( 'fr', 'condamné' ),
132                self::CATEGORY => new ItemId( 'Q1084' ),
133                self::LANGUAGE => new ItemId( 'Q150' ),
134            ],
135
136            'L18' => [
137                self::LEMMA => new Term( 'he', 'חי' ),
138                self::CATEGORY => new ItemId( 'Q34698' ),
139                self::LANGUAGE => new ItemId( 'Q9288' ),
140            ],
141
142            'L123' => [
143                self::LEMMA => new Term( 'mis-x-Q4115189', 'sandbox lexeme' ),
144                self::CATEGORY => new ItemId( 'Q4115189' ),
145                self::LANGUAGE => new ItemId( 'Q13406268' ),
146            ],
147
148            'L171081' => [
149                self::LEMMA => new Term( 'eu', 'izioki' ),
150                self::CATEGORY => new ItemId( 'Q24905' ),
151                self::LANGUAGE => new ItemId( 'Q8752' ),
152            ],
153
154        ];
155
156        $this->output( "Starting import...\n\n" );
157
158        foreach ( $entities as $idString => $dataMap ) {
159            /** @var Term $lemmaTerm */
160            $lemmaTerm = $dataMap[self::LEMMA];
161            /** @var ItemId $languageId */
162            $languageId = $dataMap[self::LANGUAGE];
163            /** @var ItemId $categoryId */
164            $categoryId = $dataMap[self::CATEGORY];
165
166            $this->output(
167                "Importing Lexeme with lemma " . $lemmaTerm->getText() . " as lexeme $idString... \n"
168            );
169
170            $entity = new Lexeme(
171                new LexemeId( $idString ),
172                new TermList( [ $lemmaTerm ] ),
173                $categoryId,
174                $languageId
175            );
176
177            $store->saveEntity( $entity, 'Import reserved Lexeme', $user, EDIT_NEW );
178        }
179
180        $this->output( 'Import completed.' );
181    }
182
183}
184
185$maintClass = CreateReservedLexemes::class;
186require_once RUN_MAINTENANCE_IF_MAIN;