diff --git a/.gitignore b/.gitignore index f995160991d..10e967c0470 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,4 @@ extensions/AdminLinks extensions/PageForms extensions/SemanticMediaWiki extensions/SemanticResultFormats +extensions/Headscript diff --git a/LocalSettings.php b/LocalSettings.php index 757af5ced28..6436dee728e 100644 --- a/LocalSettings.php +++ b/LocalSettings.php @@ -185,9 +185,8 @@ wfLoadExtension( 'Nuke' ); wfLoadExtension( 'ParserFunctions' ); wfLoadExtension( 'TextExtracts' ); wfLoadExtension( 'WikiEditor' ); - wfLoadExtension( 'PageForms' ); - +wfLoadExtension( 'Headscript' ); wfLoadExtension( 'SemanticMediaWiki' ); wfLoadExtension( 'SemanticResultFormats' ); @@ -238,4 +237,8 @@ $wgGroupPermissions['emailconfirmed']['edit'] = true; #$wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; #$wgIgnoreImageErrors = true; +$wgHeadScriptCode = <<<'START_END_MARKER' + +START_END_MARKER; + $wgMemoryLimit = "64M"; diff --git a/composer.local.json b/composer.local.json index 15ea5cc9851..446a225402b 100644 --- a/composer.local.json +++ b/composer.local.json @@ -9,7 +9,8 @@ "mediawiki/semantic-result-formats": "dev-master#616fd091cdce78d706d13e8b10bf70087615bcd4", "mediawiki/admin-links": "dev-master#4cec145ad82dbea4e0155bf9abc0ae566547da7b", "mediawiki/page-forms": "dev-master#d8109745866f0860f66aecd31e009b68e5bedaf1", - "x-mediawiki/confirm-edit": "^1.43" + "x-mediawiki/confirm-edit": "^1.43", + "x-mediawiki/headscript": "^1.43" }, "repositories": [ { @@ -28,6 +29,19 @@ "reference": "REL1_43" } } + }, + { + "type": "package", + "package": { + "name": "x-mediawiki/headscript", + "type": "mediawiki-extension", + "version": "1.43.0", + "source": { + "type": "git", + "url": "https://gerrit.wikimedia.org/r/mediawiki/extensions/HeadScript.git", + "reference": "REL1_43" + } + } } ], "extra": { diff --git a/spacestate.php b/spacestate.php index dde043bc2e1..35800d968ad 100644 --- a/spacestate.php +++ b/spacestate.php @@ -1,45 +1,87 @@ "https://techinc.nl/space/spacestate.json", + CURLOPT_TIMEOUT => 1, + CURLOPT_FORBID_REUSE => true, + CURLOPT_RETURNTRANSFER => true + )); + + $request = curl_exec($ch); + + // Request failed either because the server is offline, or it took too long to respond. + // In that case, just return the default response of Unknown. Also cache this result + // to make sure we are not hammering the space state endpoint when it failed. + if ($request === false) { + apcu_store(CACHE_KEY, $spacestate, CACHE_TTL); + return $spacestate; } - $json = json_decode($state); + // The returned JSON failed to be parsed somehow. + // This should never happen if the spacestate outputs correct JSON. + $json = json_decode($request); if (is_null($json)) { - return false; + apcu_store(CACHE_KEY, $spacestate, CACHE_TTL); + return $spacestate; } - $is_open = $json?->open ?? false; + // Retrieve the state from the 'open' key in the JSON. If it does not exist, + // the space state JSON is incorrect and we don't actually know what the spacestate is. + $state = $json?->state ?? SpaceState::Unknown; + if ($state === SpaceState::Unknown) { + apcu_store(CACHE_KEY, $spacestate, CACHE_TTL); + return $spacestate; + } - apcu_store(CACHE_KEY, $is_open, CACHE_TTL); + $spacestate = $state?->open ?? SpaceState::Unknown; + if ($spacestate === SpaceState::Unknown) { + apcu_store(CACHE_KEY, $spacestate, CACHE_TTL); + return $spacestate; + } - return $is_open; + if ($spacestate) { + $spacestate = SpaceState::Open; + } else { + $spacestate = SpaceState::Closed; + } + + apcu_store(CACHE_KEY, $spacestate, CACHE_TTL); + + return $spacestate; } $spaceState = getSpaceState(); +if ($spaceState !== SpaceState::Unknown) { ?> #p-navigation:before { content: " "; white-space: pre; } - + #p-logo:after { content: "OPEN" ; border-radius: 3px; @@ -48,7 +90,7 @@ $spaceState = getSpaceState(); margin-left: 51px; padding: 3px 7px; } - + #p-logo:after { content: "CLOSED" ; border-radius: 3px; @@ -57,4 +99,4 @@ $spaceState = getSpaceState(); margin-left: 43px; padding: 3px 7px; } - +