Add non-empty-string phpdoc types to NodaWikidataFetcher
This commit is contained in:
parent
0ab6f5e608
commit
ea280fc144
@ -90,7 +90,7 @@ final class NodaWikidataFetcher {
|
||||
/**
|
||||
* Attempts to fetch a Wikidata ID from a provided URL.
|
||||
*
|
||||
* @param string $linkUrl Link to a page.
|
||||
* @param non-empty-string $linkUrl Link to a page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -138,7 +138,7 @@ final class NodaWikidataFetcher {
|
||||
/**
|
||||
* Attempts to fetch a Wikidata ID from a provided URL.
|
||||
*
|
||||
* @param string $linkUrl Link to a Wikipedia page.
|
||||
* @param non-empty-string $linkUrl Link to a Wikipedia page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -169,7 +169,7 @@ final class NodaWikidataFetcher {
|
||||
}
|
||||
$t_wikibase = (string)$t_wikibase_href;
|
||||
|
||||
if (!empty($t_wikibase)) {
|
||||
// if (!empty($t_wikibase)) {
|
||||
if (($wikidata_id_end = strrpos($t_wikibase, '/')) !== false) {
|
||||
$wikidata_id = trim(substr($t_wikibase, $wikidata_id_end + 1), '/');
|
||||
|
||||
@ -177,7 +177,7 @@ final class NodaWikidataFetcher {
|
||||
return $wikidata_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
return '';
|
||||
|
||||
@ -279,7 +279,7 @@ final class NodaWikidataFetcher {
|
||||
* @param array<string> $checkagainstLanguage The language to check against.
|
||||
* @param array<mixed> $data Data fetched from Wikidata.
|
||||
*
|
||||
* @return array<array<string>>
|
||||
* @return array{0: array<string, non-empty-string>, 1: array<string, string>}
|
||||
*/
|
||||
public static function getWikidataWikipediaTranslationSources(array $checkagainstLanguage, array $data) {
|
||||
|
||||
@ -477,12 +477,11 @@ final class NodaWikidataFetcher {
|
||||
// Cut off overly long articles
|
||||
if (mb_strlen($input) > 600) {
|
||||
if (strpos($input, PHP_EOL . PHP_EOL, 600) !== false) {
|
||||
$input = substr($input, 0, strpos($input, PHP_EOL . PHP_EOL, 600));
|
||||
$input = trim(substr($input, 0, strpos($input, PHP_EOL . PHP_EOL, 600)));
|
||||
}
|
||||
}
|
||||
|
||||
// Trim again to make really, really no superfluous whitespaces remain
|
||||
$input = trim($input);
|
||||
if (empty($input)) return '';
|
||||
|
||||
$input = str_replace("'", "´", MD_STD::preg_replace_str("/\&\#91\;[0-9]\&\#93\;/", '', $input));
|
||||
|
||||
@ -814,13 +813,14 @@ final class NodaWikidataFetcher {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getWikidataTranslationsForPersinst(array $data, int $persinst_id) {
|
||||
public function getWikidataTranslationsForPersinst(array $data, int $persinst_id):void {
|
||||
|
||||
$checkagainstLanguage = self::LANGUAGES_TO_CHECK;
|
||||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("CALL nodaInsertPersinstTranslation(?, ?, ?, ?, ?)");
|
||||
|
||||
list($languagesToFetch, $wikilinks) = self::getWikidataWikipediaTranslationSources($checkagainstLanguage, $data);
|
||||
if (empty($languagesToFetch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$contents = MD_STD::runCurlMulti($languagesToFetch, 10000);
|
||||
@ -829,6 +829,8 @@ final class NodaWikidataFetcher {
|
||||
throw new MDExpectedException("Failed to initialize a request. Try pressing F5 to run the requests again.");
|
||||
}
|
||||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("CALL nodaInsertPersinstTranslation(?, ?, ?, ?, ?)");
|
||||
|
||||
$this->_mysqli_noda->autocommit(false);
|
||||
|
||||
foreach ($checkagainstLanguage as $lang) {
|
||||
@ -1220,6 +1222,9 @@ final class NodaWikidataFetcher {
|
||||
$checkagainstLanguage = self::LANGUAGES_TO_CHECK;
|
||||
|
||||
list($languagesToFetch, $wikilinks) = self::getWikidataWikipediaTranslationSources($checkagainstLanguage, $data);
|
||||
if (empty($languagesToFetch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$contents = MD_STD::runCurlMulti($languagesToFetch, 10000);
|
||||
@ -1542,9 +1547,10 @@ final class NodaWikidataFetcher {
|
||||
|
||||
$checkagainstLanguage = self::LANGUAGES_TO_CHECK;
|
||||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("CALL nodaInsertTagTranslation(?, ?, ?, ?, ?)");
|
||||
|
||||
list($languagesToFetch, $wikilinks) = self::getWikidataWikipediaTranslationSources($checkagainstLanguage, $data);
|
||||
if (empty($languagesToFetch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$contents = MD_STD::runCurlMulti($languagesToFetch, 10000);
|
||||
@ -1553,6 +1559,8 @@ final class NodaWikidataFetcher {
|
||||
throw new MDExpectedException("Failed to initialize a request. Try pressing F5 to run the requests again.");
|
||||
}
|
||||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("CALL nodaInsertTagTranslation(?, ?, ?, ?, ?)");
|
||||
|
||||
$this->_mysqli_noda->autocommit(false);
|
||||
|
||||
foreach ($checkagainstLanguage as $lang) {
|
||||
|
Loading…
Reference in New Issue
Block a user