| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Skins\Vector; |
| 4 |
|
| 5 |
use MediaWiki\MediaWikiServices; |
| 6 |
use MediaWiki\Request\WebRequest; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class ConfigHelper { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public static function shouldDisable( array $options, WebRequest $request, ?Title $title = null ) { |
| 36 |
$canonicalTitle = $title ? $title->getRootTitle() : null; |
| 37 |
|
| 38 |
$exclusions = $options[ 'exclude' ] ?? []; |
| 39 |
$inclusions = $options[ 'include' ] ?? []; |
| 40 |
|
| 41 |
$excludeQueryString = $exclusions[ 'querystring' ] ?? []; |
| 42 |
foreach ( $excludeQueryString as $param => $excludedParamPattern ) { |
| 43 |
$paramValue = $request->getRawVal( $param ); |
| 44 |
if ( $paramValue !== null ) { |
| 45 |
if ( $excludedParamPattern === '*' ) { |
| 46 |
|
| 47 |
$excludedParamPattern = '.+'; |
| 48 |
} |
| 49 |
return (bool)preg_match( "/$excludedParamPattern/", $paramValue ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
if ( $title && $title->isMainPage() ) { |
| 54 |
|
| 55 |
return $exclusions[ 'mainpage' ] ?? false; |
| 56 |
} |
| 57 |
if ( $canonicalTitle && $canonicalTitle->isSpecialPage() ) { |
| 58 |
$spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); |
| 59 |
[ $canonicalName, $par ] = $spFactory->resolveAlias( $canonicalTitle->getDBKey() ); |
| 60 |
if ( $canonicalName ) { |
| 61 |
$canonicalTitle = Title::makeTitle( NS_SPECIAL, $canonicalName ); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
foreach ( $inclusions as $titleText ) { |
| 71 |
$includedTitle = Title::newFromText( $titleText ); |
| 72 |
|
| 73 |
if ( $canonicalTitle->equals( $includedTitle ) ) { |
| 74 |
return false; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
$pageTitles = $exclusions[ 'pagetitles' ] ?? []; |
| 83 |
foreach ( $pageTitles as $titleText ) { |
| 84 |
|
| 85 |
|
| 86 |
$excludedTitle = Title::newFromText( $titleText ); |
| 87 |
|
| 88 |
if ( $canonicalTitle && $canonicalTitle->equals( $excludedTitle ) ) { |
| 89 |
return true; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
$excludeNamespaces = $exclusions[ 'namespaces' ] ?? []; |
| 98 |
return $title && $title->inNamespaces( $excludeNamespaces ); |
| 99 |
} |
| 100 |
} |