Skip to content

Commit

Permalink
Handle redirected/merged items properly
Browse files Browse the repository at this point in the history
Return the item id that the lookup actually used,
and if different to the item id in the location
(i.e. the api followed a redirect), set a new
location with the redirection target's id.
  • Loading branch information
evad37 committed Feb 15, 2019
1 parent 9d382ba commit da62c0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inc/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ function lookupFormatterUrl($property_id) {
$i18n = $GLOBALS['i18n'];

$item_data = $api->lookupItemData($item_id, $lang_code, $sites);
if ( isset($item_data["redirects"]) ) {
$item_id = $item_data["redirects"]["to"];
}
$item_label = getDeepData($item_data, ["labels", $lang_code, "value"], "({$item_id}: {$i18n['nolabel']})");
$item_desc = getDeepData($item_data, ["descriptions", $lang_code, "value"]);
$sitelinks = sortByKey(
Expand All @@ -406,6 +409,7 @@ function lookupFormatterUrl($property_id) {
$image_credits = getRelevantImageCredits($sites_linked);

return [
"item_id" => $item_id,
"item_label" => $item_label,
"item_desc" => $item_desc,
"sitelinks" => $sitelinks,
Expand Down
4 changes: 4 additions & 0 deletions web/portal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

$portal = $getPortalInfo();

if ( $item_id !== $portal["item_id"] ) {
header("Location:{$self}/{$portal["item_id"]}/{$lang_code}");
}

$jquerySrc = ( htmlspecialchars($_SERVER['HTTP_HOST']) == 'localhost' ) ? "http://code.jquery.com/jquery-3.3.1.min.js" : "https://tools-static.wmflabs.org/cdnjs/ajax/libs/jquery/3.3.1/jquery.min.js";
$scripts = "<script type='text/javascript' src='{$jquerySrc}' defer></script>
<script type='text/javascript' src='{$self}/js/loadmore.js' defer></script>";
Expand Down

0 comments on commit da62c0d

Please sign in to comment.