Skip to content

Commit 217d47d

Browse files
committed
Replace direct use of $wgRestPath with wfScript()
Follows-up Idb5b0d21adc6. Avoid hardcoded references to REST internal configuration variables, which create awkward "APIs" in the long run. These are hard to deprecate or detect use of, and even harder to normalize/support once variations exist. E.g. in T189966 and T233886, I've been working to remove the concept of dynamic config in favour of the uncomputed values being only valid as configuration for the component that owns the variable, instead of using Config as public API to read non-normalized information that belongs to a different component. By making the recipient responsible for any dynamic computation, it also becomes clear that these are in fact not normalized or validated, which can expose any number of unpredictable behaviours if used directly. Consider special values like `false` or `null` and the responsibility for interpreting that. Accessing these from a stable function also gives a natural place for deprecation to happen. The alternative, is for dynamic computation to happen in Setup.php for all variabls, and only ever grow and become an append-only dumping ground for every thing that we feel at some point needs validation, normalization or expansion, which doesn't scale well, hence I reversed this trend in T189966/T233886. As it happens, RestPath actually is already computed, albeit very trivially. This patch opens the way for someone to remove that in favour of PathRouter accept `false` directly and expanding (and testing) that code there instead. As for REST API, the only stable and universally supported entrypoint is /w/rest.php. Unlike some older entry points, we don't support moving or removing the rest.php file. We do support routing/aliasing additional paths to it. Change-Id: I589a8aed8db3b8e7b72e4505749bb7ef25a755d9
1 parent d8783f8 commit 217d47d

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

includes/Output/OutputPage.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4133,11 +4133,10 @@ public function getHeadLinksArray() {
41334133
}
41344134

41354135
# OpenSearch description link
4136-
$restPath = $config->get( MainConfigNames::RestPath );
41374136
$tags['opensearch'] = Html::element( 'link', [
41384137
'rel' => 'search',
41394138
'type' => 'application/opensearchdescription+xml',
4140-
'href' => "$restPath/v1/search",
4139+
'href' => wfScript( 'rest' ) . '/v1/search',
41414140
'title' => $this->msg( 'opensearch-desc' )->inContentLanguage()->text(),
41424141
] );
41434142

opensearch_desc.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
require_once __DIR__ . '/includes/WebStart.php';
3636

37-
$url = $wgRestPath . '/v1/search';
38-
$ctype = $wgRequest->getVal( 'ctype' );
37+
$url = wfScript( 'rest' ) . '/v1/search';
38+
$ctype = $wgRequest->getRawVal( 'ctype' );
3939

4040
if ( $ctype !== null ) {
4141
$url = wfAppendQuery( $url, [ 'ctype' => $ctype ] );

tests/qunit/resources/mediawiki.util/util.test.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,11 @@ QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( {
192192
wgScriptPath: '/w'
193193
} );
194194

195-
assert.strictEqual( util.wikiScript(), mw.config.get( 'wgScript' ),
196-
'wikiScript() returns wgScript'
197-
);
198-
assert.strictEqual( util.wikiScript( 'index' ), mw.config.get( 'wgScript' ),
199-
'wikiScript( index ) returns wgScript'
200-
);
201-
assert.strictEqual( util.wikiScript( 'load' ), '/w/l.php',
202-
'wikiScript( load ) returns /w/l.php'
203-
);
204-
assert.strictEqual( util.wikiScript( 'api' ), '/w/api.php', 'API path' );
195+
assert.strictEqual( util.wikiScript(), '/w/i.php', 'default' );
196+
assert.strictEqual( util.wikiScript( 'index' ), '/w/i.php', 'index' );
197+
assert.strictEqual( util.wikiScript( 'load' ), '/w/l.php', 'load' );
198+
assert.strictEqual( util.wikiScript( 'api' ), '/w/api.php', 'api' );
199+
assert.strictEqual( util.wikiScript( 'rest' ), '/w/rest.php', 'rest' );
205200
} );
206201

207202
QUnit.test( 'addCSS', ( assert ) => {

0 commit comments

Comments
 (0)