aboutsummaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/OutputPage.php9
-rw-r--r--includes/Request/FauxResponse.php2
-rw-r--r--includes/Request/PathRouter.php2
-rw-r--r--includes/ResourceLoader/OOUIIconPackModule.php2
-rw-r--r--includes/ResourceLoader/OOUIImageModule.php2
-rw-r--r--includes/WebRequest.php5
-rw-r--r--includes/libs/ParamValidator/TypeDef/UploadDef.php2
-rw-r--r--includes/libs/filebackend/SwiftFileBackend.php2
-rw-r--r--includes/libs/mime/MimeAnalyzer.php8
-rw-r--r--includes/libs/objectcache/MemcachedBagOStuff.php5
-rw-r--r--includes/libs/rdbms/database/DatabasePostgres.php2
-rw-r--r--includes/registration/MissingExtensionException.php2
-rw-r--r--includes/upload/UploadBase.php2
13 files changed, 22 insertions, 23 deletions
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index a6be95fac590..e1b5f48a4a69 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -4410,9 +4410,10 @@ class OutputPage extends ContextSource {
$media = 'all';
}
- if ( substr( $style, 0, 1 ) == '/' ||
- substr( $style, 0, 5 ) == 'http:' ||
- substr( $style, 0, 6 ) == 'https:' ) {
+ if ( str_starts_with( $style, '/' ) ||
+ str_starts_with( $style, 'http:' ) ||
+ str_starts_with( $style, 'https:' )
+ ) {
$url = $style;
} else {
$config = $this->getConfig();
@@ -4463,7 +4464,7 @@ class OutputPage extends ContextSource {
} else {
$remotePath = $remotePathPrefix;
}
- if ( strpos( $path, $remotePath ) !== 0 || substr( $path, 0, 2 ) === '//' ) {
+ if ( !str_starts_with( $path, $remotePath ) || str_starts_with( $path, '//' ) ) {
// - Path is outside wgResourceBasePath, ignore.
// - Path is protocol-relative. Fixes T155310. Not supported by RelPath lib.
return $path;
diff --git a/includes/Request/FauxResponse.php b/includes/Request/FauxResponse.php
index 6154efef73d1..4aee59d89dd4 100644
--- a/includes/Request/FauxResponse.php
+++ b/includes/Request/FauxResponse.php
@@ -45,7 +45,7 @@ class FauxResponse extends WebResponse {
* @param null|int $http_response_code Forces the HTTP response code to the specified value.
*/
public function header( $string, $replace = true, $http_response_code = null ) {
- if ( substr( $string, 0, 5 ) == 'HTTP/' ) {
+ if ( str_starts_with( $string, 'HTTP/' ) ) {
$parts = explode( ' ', $string, 3 );
$this->code = intval( $parts[1] );
} else {
diff --git a/includes/Request/PathRouter.php b/includes/Request/PathRouter.php
index 1082fa9a7017..444aea7be0f7 100644
--- a/includes/Request/PathRouter.php
+++ b/includes/Request/PathRouter.php
@@ -101,7 +101,7 @@ class PathRouter {
if ( !isset( $options['strict'] ) || !$options['strict'] ) {
// Unless this is a strict path make sure that the path has a $1
if ( strpos( $path, '$1' ) === false ) {
- if ( substr( $path, -1 ) !== '/' ) {
+ if ( $path[-1] !== '/' ) {
$path .= '/';
}
$path .= '$1';
diff --git a/includes/ResourceLoader/OOUIIconPackModule.php b/includes/ResourceLoader/OOUIIconPackModule.php
index ac72ca88947f..e59e99c5cfbd 100644
--- a/includes/ResourceLoader/OOUIIconPackModule.php
+++ b/includes/ResourceLoader/OOUIIconPackModule.php
@@ -54,7 +54,7 @@ class OOUIIconPackModule extends OOUIImageModule {
$data[$theme] = [];
// Load and merge the JSON data for all "icons-foo" modules
foreach ( self::$knownImagesModules as $module ) {
- if ( substr( $module, 0, 5 ) === 'icons' ) {
+ if ( str_starts_with( $module, 'icons' ) ) {
$moreData = $this->readJSONFile( $this->getThemeImagesPath( $theme, $module ) );
if ( $moreData ) {
$data[$theme] = array_replace_recursive( $data[$theme], $moreData );
diff --git a/includes/ResourceLoader/OOUIImageModule.php b/includes/ResourceLoader/OOUIImageModule.php
index b794d7c6fcb3..c3de3f28c4d6 100644
--- a/includes/ResourceLoader/OOUIImageModule.php
+++ b/includes/ResourceLoader/OOUIImageModule.php
@@ -77,7 +77,7 @@ class OOUIImageModule extends ImageModule {
}
// Extra selectors to allow using the same icons for old-style MediaWiki UI code
- if ( substr( $module, 0, 5 ) === 'icons' ) {
+ if ( str_starts_with( $module, 'icons' ) ) {
$definition['selectorWithoutVariant'] = '.oo-ui-icon-{name}, .mw-ui-icon-{name}:before';
$definition['selectorWithVariant'] = '.oo-ui-image-{variant}.oo-ui-icon-{name}, ' .
'.mw-ui-icon-{name}-{variant}:before';
diff --git a/includes/WebRequest.php b/includes/WebRequest.php
index b3ce0abcda82..ed6613ceef31 100644
--- a/includes/WebRequest.php
+++ b/includes/WebRequest.php
@@ -405,9 +405,8 @@ class WebRequest {
foreach ( (array)$bases as $keyValue => $base ) {
// Find the part after $wgArticlePath
$base = str_replace( '$1', '', $base );
- $baseLen = strlen( $base );
- if ( substr( $path, 0, $baseLen ) == $base ) {
- $raw = substr( $path, $baseLen );
+ if ( str_starts_with( $path, $base ) ) {
+ $raw = substr( $path, strlen( $base ) );
if ( $raw !== '' ) {
$matches = [ 'title' => rawurldecode( $raw ) ];
if ( $key ) {
diff --git a/includes/libs/ParamValidator/TypeDef/UploadDef.php b/includes/libs/ParamValidator/TypeDef/UploadDef.php
index 4449ded09a9c..b651c9671e12 100644
--- a/includes/libs/ParamValidator/TypeDef/UploadDef.php
+++ b/includes/libs/ParamValidator/TypeDef/UploadDef.php
@@ -115,7 +115,7 @@ class UploadDef extends TypeDef {
$constant = '';
foreach ( get_defined_constants() as $c => $v ) {
// @phan-suppress-next-line PhanTypeComparisonFromArray
- if ( $v === $err && substr( $c, 0, 11 ) === 'UPLOAD_ERR_' ) {
+ if ( $v === $err && str_starts_with( $c, 'UPLOAD_ERR_' ) ) {
$constant = " ($c?)";
}
}
diff --git a/includes/libs/filebackend/SwiftFileBackend.php b/includes/libs/filebackend/SwiftFileBackend.php
index e2e0718a110a..61a4b55f871b 100644
--- a/includes/libs/filebackend/SwiftFileBackend.php
+++ b/includes/libs/filebackend/SwiftFileBackend.php
@@ -1792,7 +1792,7 @@ class SwiftFileBackend extends FileBackendStore {
}
}
// Ceph RGW does not use <account> in URLs (OpenStack Swift uses "/v1/<account>")
- if ( substr( $this->authCreds['storage_url'], -3 ) === '/v1' ) {
+ if ( str_ends_with( $this->authCreds['storage_url'], '/v1' ) ) {
$this->isRGW = true; // take advantage of strong consistency in Ceph
}
}
diff --git a/includes/libs/mime/MimeAnalyzer.php b/includes/libs/mime/MimeAnalyzer.php
index 16d82a3d0218..1ae00fa990e4 100644
--- a/includes/libs/mime/MimeAnalyzer.php
+++ b/includes/libs/mime/MimeAnalyzer.php
@@ -708,13 +708,13 @@ class MimeAnalyzer implements LoggerAwareInterface {
$script_type = null;
# detect by shebang
- if ( substr( $head, 0, 2 ) == "#!" ) {
+ if ( str_starts_with( $head, "#!" ) ) {
$script_type = "ASCII";
- } elseif ( substr( $head, 0, 5 ) == "\xef\xbb\xbf#!" ) {
+ } elseif ( str_starts_with( $head, "\xef\xbb\xbf#!" ) ) {
$script_type = "UTF-8";
- } elseif ( substr( $head, 0, 7 ) == "\xfe\xff\x00#\x00!" ) {
+ } elseif ( str_starts_with( $head, "\xfe\xff\x00#\x00!" ) ) {
$script_type = "UTF-16BE";
- } elseif ( substr( $head, 0, 7 ) == "\xff\xfe#\x00!" ) {
+ } elseif ( str_starts_with( $head, "\xff\xfe#\x00!" ) ) {
$script_type = "UTF-16LE";
}
diff --git a/includes/libs/objectcache/MemcachedBagOStuff.php b/includes/libs/objectcache/MemcachedBagOStuff.php
index 55c1442e4e61..65b35165dad0 100644
--- a/includes/libs/objectcache/MemcachedBagOStuff.php
+++ b/includes/libs/objectcache/MemcachedBagOStuff.php
@@ -134,9 +134,8 @@ abstract class MemcachedBagOStuff extends MediumSpecificBagOStuff {
return $key;
}
- $prefixLength = strlen( $this->routingPrefix );
- if ( substr( $key, 0, $prefixLength ) === $this->routingPrefix ) {
- return substr( $key, $prefixLength );
+ if ( str_starts_with( $key, $this->routingPrefix ) ) {
+ return substr( $key, strlen( $this->routingPrefix ) );
}
return $key;
diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php
index 24d2aefbfd3a..e99c827aae9d 100644
--- a/includes/libs/rdbms/database/DatabasePostgres.php
+++ b/includes/libs/rdbms/database/DatabasePostgres.php
@@ -1062,7 +1062,7 @@ SQL;
public function streamStatementEnd( &$sql, &$newLine ) {
# Allow dollar quoting for function declarations
- if ( substr( $newLine, 0, 4 ) == '$mw$' ) {
+ if ( str_starts_with( $newLine, '$mw$' ) ) {
if ( $this->delimiter ) {
$this->delimiter = false;
} else {
diff --git a/includes/registration/MissingExtensionException.php b/includes/registration/MissingExtensionException.php
index 0b6ece93c1b2..74f9703a59c5 100644
--- a/includes/registration/MissingExtensionException.php
+++ b/includes/registration/MissingExtensionException.php
@@ -28,7 +28,7 @@ class MissingExtensionException extends Exception {
* @param string $error Text of error mtime gave
*/
public function __construct( $path, $error ) {
- $this->isSkin = substr( $path, -10 ) === "/skin.json";
+ $this->isSkin = str_ends_with( $path, "/skin.json" );
$m = [];
preg_match( "!/([^/]*)/[^/]*.json$!", $path, $m );
if ( $m ) {
diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php
index 73289338f2c8..8ac08772488e 100644
--- a/includes/upload/UploadBase.php
+++ b/includes/upload/UploadBase.php
@@ -1710,7 +1710,7 @@ abstract class UploadBase {
# use set/animate to add event-handler attribute to parent
if ( ( $strippedElement === 'set' || $strippedElement === 'animate' )
&& $stripped === 'attributename'
- && substr( $value, 0, 2 ) === 'on'
+ && str_starts_with( $value, 'on' )
) {
wfDebug( __METHOD__ . ": Found svg setting event-handler attribute with "
. "\"<$strippedElement $stripped='$value'...\" in uploaded file." );