- require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
- ini_set('memory_limit', '800M');
- ini_set('display_errors', 'stderr');
-
- $aCMDOptions = array(
- "Import and export special phrases",
- array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
- array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
- array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
- array('countries', '', 0, 1, 0, 0, 'bool', 'Create import script for coutry codes and names'),
- array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
- );
- getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
+require_once(CONST_LibDir.'/init-cmd.php');
+ini_set('memory_limit', '800M');
+ini_set('display_errors', 'stderr');
+
+$aCMDOptions
+= array(
+ 'Import and export special phrases',
+ array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
+ array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
+ array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
+ array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
+ array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'),
+ );
+getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
+
+loadSettings($aCMDResult['project-dir'] ?? getcwd());
+setupHTTPProxy();
+
+include(getSettingConfig('PHRASE_CONFIG', 'phrase_settings.php'));
+
+if ($aCMDResult['wiki-import']) {
+ $oNormalizer = Transliterator::createFromRules(getSetting('TERM_NORMALIZATION'));
+ $aPairs = array();
+
+ $sLanguageIn = getSetting(
+ 'LANGUAGES',
+ 'af,ar,br,ca,cs,de,en,es,et,eu,fa,fi,fr,gl,hr,hu,'.
+ 'ia,is,it,ja,mk,nl,no,pl,ps,pt,ru,sk,sl,sv,uk,vi'
+ );
+
+ foreach (explode(',', $sLanguageIn) as $sLanguage) {
+ $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
+ $sWikiPageXML = file_get_contents($sURL);
+
+ if (!preg_match_all(
+ '#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#',
+ $sWikiPageXML,
+ $aMatches,
+ PREG_SET_ORDER
+ )) {
+ continue;
+ }