Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ResourceLoader often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ResourceLoader, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | class ResourceLoader implements LoggerAwareInterface { |
||
| 37 | /** @var int */ |
||
| 38 | protected static $filterCacheVersion = 7; |
||
| 39 | |||
| 40 | /** @var bool */ |
||
| 41 | protected static $debugMode = null; |
||
| 42 | |||
| 43 | /** @var array */ |
||
| 44 | private $lessVars = null; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Module name/ResourceLoaderModule object pairs |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | protected $modules = []; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Associative array mapping module name to info associative array |
||
| 54 | * @var array |
||
| 55 | */ |
||
| 56 | protected $moduleInfos = []; |
||
| 57 | |||
| 58 | /** @var Config $config */ |
||
| 59 | private $config; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Associative array mapping framework ids to a list of names of test suite modules |
||
| 63 | * like array( 'qunit' => array( 'mediawiki.tests.qunit.suites', 'ext.foo.tests', .. ), .. ) |
||
| 64 | * @var array |
||
| 65 | */ |
||
| 66 | protected $testModuleNames = []; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * E.g. array( 'source-id' => 'http://.../load.php' ) |
||
| 70 | * @var array |
||
| 71 | */ |
||
| 72 | protected $sources = []; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Errors accumulated during current respond() call. |
||
| 76 | * @var array |
||
| 77 | */ |
||
| 78 | protected $errors = []; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var MessageBlobStore |
||
| 82 | */ |
||
| 83 | protected $blobStore; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var LoggerInterface |
||
| 87 | */ |
||
| 88 | private $logger; |
||
| 89 | |||
| 90 | /** @var string JavaScript / CSS pragma to disable minification. **/ |
||
| 91 | const FILTER_NOMIN = '/*@nomin*/'; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Load information stored in the database about modules. |
||
| 95 | * |
||
| 96 | * This method grabs modules dependencies from the database and updates modules |
||
| 97 | * objects. |
||
| 98 | * |
||
| 99 | * This is not inside the module code because it is much faster to |
||
| 100 | * request all of the information at once than it is to have each module |
||
| 101 | * requests its own information. This sacrifice of modularity yields a substantial |
||
| 102 | * performance improvement. |
||
| 103 | * |
||
| 104 | * @param array $moduleNames List of module names to preload information for |
||
| 105 | * @param ResourceLoaderContext $context Context to load the information within |
||
| 106 | */ |
||
| 107 | public function preloadModuleInfo( array $moduleNames, ResourceLoaderContext $context ) { |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Run JavaScript or CSS data through a filter, caching the filtered result for future calls. |
||
| 160 | * |
||
| 161 | * Available filters are: |
||
| 162 | * |
||
| 163 | * - minify-js \see JavaScriptMinifier::minify |
||
| 164 | * - minify-css \see CSSMin::minify |
||
| 165 | * |
||
| 166 | * If $data is empty, only contains whitespace or the filter was unknown, |
||
| 167 | * $data is returned unmodified. |
||
| 168 | * |
||
| 169 | * @param string $filter Name of filter to run |
||
| 170 | * @param string $data Text to filter, such as JavaScript or CSS text |
||
| 171 | * @param array $options Keys: |
||
| 172 | * - (bool) cache: Whether to allow caching this data. Default: true. |
||
| 173 | * @return string Filtered data, or a comment containing an error message |
||
| 174 | */ |
||
| 175 | public static function filter( $filter, $data, array $options = [] ) { |
||
| 209 | |||
| 210 | private static function applyFilter( $filter, $data ) { |
||
| 224 | |||
| 225 | /* Methods */ |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Register core modules and runs registration hooks. |
||
| 229 | * @param Config $config [optional] |
||
| 230 | * @param LoggerInterface $logger [optional] |
||
| 231 | */ |
||
| 232 | public function __construct( Config $config = null, LoggerInterface $logger = null ) { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @return Config |
||
| 265 | */ |
||
| 266 | public function getConfig() { |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @since 1.26 |
||
| 272 | * @param LoggerInterface $logger |
||
| 273 | */ |
||
| 274 | public function setLogger( LoggerInterface $logger ) { |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @since 1.27 |
||
| 280 | * @return LoggerInterface |
||
| 281 | */ |
||
| 282 | public function getLogger() { |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @since 1.26 |
||
| 288 | * @return MessageBlobStore |
||
| 289 | */ |
||
| 290 | public function getMessageBlobStore() { |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @since 1.25 |
||
| 296 | * @param MessageBlobStore $blobStore |
||
| 297 | */ |
||
| 298 | public function setMessageBlobStore( MessageBlobStore $blobStore ) { |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Register a module with the ResourceLoader system. |
||
| 304 | * |
||
| 305 | * @param mixed $name Name of module as a string or List of name/object pairs as an array |
||
| 306 | * @param array $info Module info array. For backwards compatibility with 1.17alpha, |
||
| 307 | * this may also be a ResourceLoaderModule object. Optional when using |
||
| 308 | * multiple-registration calling style. |
||
| 309 | * @throws MWException If a duplicate module registration is attempted |
||
| 310 | * @throws MWException If a module name contains illegal characters (pipes or commas) |
||
| 311 | * @throws MWException If something other than a ResourceLoaderModule is being registered |
||
| 312 | * @return bool False if there were any errors, in which case one or more modules were |
||
| 313 | * not registered |
||
| 314 | */ |
||
| 315 | public function register( $name, $info = null ) { |
||
| 389 | |||
| 390 | /** |
||
| 391 | */ |
||
| 392 | public function registerTestModules() { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Add a foreign source of modules. |
||
| 432 | * |
||
| 433 | * Source IDs are typically the same as the Wiki ID or database name (e.g. lowercase a-z). |
||
| 434 | * |
||
| 435 | * @param array|string $id Source ID (string), or array( id1 => loadUrl, id2 => loadUrl, ... ) |
||
| 436 | * @param string|array $loadUrl load.php url (string), or array with loadUrl key for |
||
| 437 | * backwards-compatibility. |
||
| 438 | * @throws MWException |
||
| 439 | */ |
||
| 440 | public function addSource( $id, $loadUrl = null ) { |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Get a list of module names. |
||
| 473 | * |
||
| 474 | * @return array List of module names |
||
| 475 | */ |
||
| 476 | public function getModuleNames() { |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Get a list of test module names for one (or all) frameworks. |
||
| 482 | * |
||
| 483 | * If the given framework id is unknkown, or if the in-object variable is not an array, |
||
| 484 | * then it will return an empty array. |
||
| 485 | * |
||
| 486 | * @param string $framework Get only the test module names for one |
||
| 487 | * particular framework (optional) |
||
| 488 | * @return array |
||
| 489 | */ |
||
| 490 | public function getTestModuleNames( $framework = 'all' ) { |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Check whether a ResourceLoader module is registered |
||
| 505 | * |
||
| 506 | * @since 1.25 |
||
| 507 | * @param string $name |
||
| 508 | * @return bool |
||
| 509 | */ |
||
| 510 | public function isModuleRegistered( $name ) { |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Get the ResourceLoaderModule object for a given module name. |
||
| 516 | * |
||
| 517 | * If an array of module parameters exists but a ResourceLoaderModule object has not |
||
| 518 | * yet been instantiated, this method will instantiate and cache that object such that |
||
| 519 | * subsequent calls simply return the same object. |
||
| 520 | * |
||
| 521 | * @param string $name Module name |
||
| 522 | * @return ResourceLoaderModule|null If module has been registered, return a |
||
| 523 | * ResourceLoaderModule instance. Otherwise, return null. |
||
| 524 | */ |
||
| 525 | public function getModule( $name ) { |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Return whether the definition of a module corresponds to a simple ResourceLoaderFileModule. |
||
| 557 | * |
||
| 558 | * @param string $name Module name |
||
| 559 | * @return bool |
||
| 560 | */ |
||
| 561 | protected function isFileModule( $name ) { |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Get the list of sources. |
||
| 574 | * |
||
| 575 | * @return array Like array( id => load.php url, .. ) |
||
| 576 | */ |
||
| 577 | public function getSources() { |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Get the URL to the load.php endpoint for the given |
||
| 583 | * ResourceLoader source |
||
| 584 | * |
||
| 585 | * @since 1.24 |
||
| 586 | * @param string $source |
||
| 587 | * @throws MWException On an invalid $source name |
||
| 588 | * @return string |
||
| 589 | */ |
||
| 590 | public function getLoadScript( $source ) { |
||
| 596 | |||
| 597 | /** |
||
| 598 | * @since 1.26 |
||
| 599 | * @param string $value |
||
| 600 | * @return string Hash |
||
| 601 | */ |
||
| 602 | public static function makeHash( $value ) { |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Helper method to get and combine versions of multiple modules. |
||
| 611 | * |
||
| 612 | * @since 1.26 |
||
| 613 | * @param ResourceLoaderContext $context |
||
| 614 | * @param array $modules List of ResourceLoaderModule objects |
||
| 615 | * @return string Hash |
||
| 616 | */ |
||
| 617 | public function getCombinedVersion( ResourceLoaderContext $context, array $modules ) { |
||
| 626 | |||
| 627 | /** |
||
| 628 | * Output a response to a load request, including the content-type header. |
||
| 629 | * |
||
| 630 | * @param ResourceLoaderContext $context Context in which a response should be formed |
||
| 631 | */ |
||
| 632 | public function respond( ResourceLoaderContext $context ) { |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Send main response headers to the client. |
||
| 753 | * |
||
| 754 | * Deals with Content-Type, CORS (for stylesheets), and caching. |
||
| 755 | * |
||
| 756 | * @param ResourceLoaderContext $context |
||
| 757 | * @param string $etag ETag header value |
||
| 758 | * @param bool $errors Whether there are errors in the response |
||
| 759 | * @return void |
||
| 760 | */ |
||
| 761 | protected function sendResponseHeaders( ResourceLoaderContext $context, $etag, $errors ) { |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Respond with HTTP 304 Not Modified if appropiate. |
||
| 804 | * |
||
| 805 | * If there's an If-None-Match header, respond with a 304 appropriately |
||
| 806 | * and clear out the output buffer. If the client cache is too old then do nothing. |
||
| 807 | * |
||
| 808 | * @param ResourceLoaderContext $context |
||
| 809 | * @param string $etag ETag header value |
||
| 810 | * @return bool True if HTTP 304 was sent and output handled |
||
| 811 | */ |
||
| 812 | protected function tryRespondNotModified( ResourceLoaderContext $context, $etag ) { |
||
| 836 | |||
| 837 | /** |
||
| 838 | * Send out code for a response from file cache if possible. |
||
| 839 | * |
||
| 840 | * @param ResourceFileCache $fileCache Cache object for this request URL |
||
| 841 | * @param ResourceLoaderContext $context Context in which to generate a response |
||
| 842 | * @param string $etag ETag header value |
||
| 843 | * @return bool If this found a cache file and handled the response |
||
| 844 | */ |
||
| 845 | protected function tryRespondFromFileCache( |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Generate a CSS or JS comment block. |
||
| 892 | * |
||
| 893 | * Only use this for public data, not error message details. |
||
| 894 | * |
||
| 895 | * @param string $text |
||
| 896 | * @return string |
||
| 897 | */ |
||
| 898 | public static function makeComment( $text ) { |
||
| 902 | |||
| 903 | /** |
||
| 904 | * Handle exception display. |
||
| 905 | * |
||
| 906 | * @param Exception $e Exception to be shown to the user |
||
| 907 | * @return string Sanitized text in a CSS/JS comment that can be returned to the user |
||
| 908 | */ |
||
| 909 | public static function formatException( $e ) { |
||
| 912 | |||
| 913 | /** |
||
| 914 | * Handle exception display. |
||
| 915 | * |
||
| 916 | * @since 1.25 |
||
| 917 | * @param Exception $e Exception to be shown to the user |
||
| 918 | * @return string Sanitized text that can be returned to the user |
||
| 919 | */ |
||
| 920 | protected static function formatExceptionNoComment( $e ) { |
||
| 929 | |||
| 930 | /** |
||
| 931 | * Generate code for a response. |
||
| 932 | * |
||
| 933 | * @param ResourceLoaderContext $context Context in which to generate a response |
||
| 934 | * @param ResourceLoaderModule[] $modules List of module objects keyed by module name |
||
| 935 | * @param string[] $missing List of requested module names that are unregistered (optional) |
||
| 936 | * @return string Response data |
||
| 937 | */ |
||
| 938 | public function makeModuleResponse( ResourceLoaderContext $context, |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Get names of modules that use a certain message. |
||
| 1056 | * |
||
| 1057 | * @param string $messageKey |
||
| 1058 | * @return array List of module names |
||
| 1059 | */ |
||
| 1060 | public function getModulesByMessage( $messageKey ) { |
||
| 1070 | |||
| 1071 | /* Static Methods */ |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Return JS code that calls mw.loader.implement with given module properties. |
||
| 1075 | * |
||
| 1076 | * @param string $name Module name |
||
| 1077 | * @param mixed $scripts List of URLs to JavaScript files or String of JavaScript code |
||
| 1078 | * @param mixed $styles Array of CSS strings keyed by media type, or an array of lists of URLs |
||
| 1079 | * to CSS files keyed by media type |
||
| 1080 | * @param mixed $messages List of messages associated with this module. May either be an |
||
| 1081 | * associative array mapping message key to value, or a JSON-encoded message blob containing |
||
| 1082 | * the same data, wrapped in an XmlJsCode object. |
||
| 1083 | * @param array $templates Keys are name of templates and values are the source of |
||
| 1084 | * the template. |
||
| 1085 | * @throws MWException |
||
| 1086 | * @return string |
||
| 1087 | */ |
||
| 1088 | public static function makeLoaderImplementScript( |
||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Returns JS code which, when called, will register a given list of messages. |
||
| 1123 | * |
||
| 1124 | * @param mixed $messages Either an associative array mapping message key to value, or a |
||
| 1125 | * JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object. |
||
| 1126 | * @return string |
||
| 1127 | */ |
||
| 1128 | public static function makeMessageSetScript( $messages ) { |
||
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Combines an associative array mapping media type to CSS into a |
||
| 1138 | * single stylesheet with "@media" blocks. |
||
| 1139 | * |
||
| 1140 | * @param array $stylePairs Array keyed by media type containing (arrays of) CSS strings |
||
| 1141 | * @return array |
||
| 1142 | */ |
||
| 1143 | public static function makeCombinedStyles( array $stylePairs ) { |
||
| 1169 | |||
| 1170 | /** |
||
| 1171 | * Returns a JS call to mw.loader.state, which sets the state of a |
||
| 1172 | * module or modules to a given value. Has two calling conventions: |
||
| 1173 | * |
||
| 1174 | * - ResourceLoader::makeLoaderStateScript( $name, $state ): |
||
| 1175 | * Set the state of a single module called $name to $state |
||
| 1176 | * |
||
| 1177 | * - ResourceLoader::makeLoaderStateScript( array( $name => $state, ... ) ): |
||
| 1178 | * Set the state of modules with the given names to the given states |
||
| 1179 | * |
||
| 1180 | * @param string $name |
||
| 1181 | * @param string $state |
||
| 1182 | * @return string |
||
| 1183 | */ |
||
| 1184 | View Code Duplication | public static function makeLoaderStateScript( $name, $state = null ) { |
|
| 1199 | |||
| 1200 | /** |
||
| 1201 | * Returns JS code which calls the script given by $script. The script will |
||
| 1202 | * be called with local variables name, version, dependencies and group, |
||
| 1203 | * which will have values corresponding to $name, $version, $dependencies |
||
| 1204 | * and $group as supplied. |
||
| 1205 | * |
||
| 1206 | * @param string $name Module name |
||
| 1207 | * @param string $version Module version hash |
||
| 1208 | * @param array $dependencies List of module names on which this module depends |
||
| 1209 | * @param string $group Group which the module is in. |
||
| 1210 | * @param string $source Source of the module, or 'local' if not foreign. |
||
| 1211 | * @param string $script JavaScript code |
||
| 1212 | * @return string |
||
| 1213 | */ |
||
| 1214 | public static function makeCustomLoaderScript( $name, $version, $dependencies, |
||
| 1224 | |||
| 1225 | private static function isEmptyObject( stdClass $obj ) { |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Remove empty values from the end of an array. |
||
| 1234 | * |
||
| 1235 | * Values considered empty: |
||
| 1236 | * |
||
| 1237 | * - null |
||
| 1238 | * - array() |
||
| 1239 | * - new XmlJsCode( '{}' ) |
||
| 1240 | * - new stdClass() // (object) array() |
||
| 1241 | * |
||
| 1242 | * @param Array $array |
||
| 1243 | */ |
||
| 1244 | private static function trimArray( array &$array ) { |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Returns JS code which calls mw.loader.register with the given |
||
| 1261 | * parameters. Has three calling conventions: |
||
| 1262 | * |
||
| 1263 | * - ResourceLoader::makeLoaderRegisterScript( $name, $version, |
||
| 1264 | * $dependencies, $group, $source, $skip |
||
| 1265 | * ): |
||
| 1266 | * Register a single module. |
||
| 1267 | * |
||
| 1268 | * - ResourceLoader::makeLoaderRegisterScript( array( $name1, $name2 ) ): |
||
| 1269 | * Register modules with the given names. |
||
| 1270 | * |
||
| 1271 | * - ResourceLoader::makeLoaderRegisterScript( array( |
||
| 1272 | * array( $name1, $version1, $dependencies1, $group1, $source1, $skip1 ), |
||
| 1273 | * array( $name2, $version2, $dependencies1, $group2, $source2, $skip2 ), |
||
| 1274 | * ... |
||
| 1275 | * ) ): |
||
| 1276 | * Registers modules with the given names and parameters. |
||
| 1277 | * |
||
| 1278 | * @param string $name Module name |
||
| 1279 | * @param string $version Module version hash |
||
| 1280 | * @param array $dependencies List of module names on which this module depends |
||
| 1281 | * @param string $group Group which the module is in |
||
| 1282 | * @param string $source Source of the module, or 'local' if not foreign |
||
| 1283 | * @param string $skip Script body of the skip function |
||
| 1284 | * @return string |
||
| 1285 | */ |
||
| 1286 | public static function makeLoaderRegisterScript( $name, $version = null, |
||
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Returns JS code which calls mw.loader.addSource() with the given |
||
| 1328 | * parameters. Has two calling conventions: |
||
| 1329 | * |
||
| 1330 | * - ResourceLoader::makeLoaderSourcesScript( $id, $properties ): |
||
| 1331 | * Register a single source |
||
| 1332 | * |
||
| 1333 | * - ResourceLoader::makeLoaderSourcesScript( array( $id1 => $loadUrl, $id2 => $loadUrl, ... ) ); |
||
| 1334 | * Register sources with the given IDs and properties. |
||
| 1335 | * |
||
| 1336 | * @param string $id Source ID |
||
| 1337 | * @param array $properties Source properties (see addSource()) |
||
| 1338 | * @return string |
||
| 1339 | */ |
||
| 1340 | View Code Duplication | public static function makeLoaderSourcesScript( $id, $properties = null ) { |
|
| 1355 | |||
| 1356 | /** |
||
| 1357 | * Returns JS code which runs given JS code if the client-side framework is |
||
| 1358 | * present. |
||
| 1359 | * |
||
| 1360 | * @deprecated since 1.25; use makeInlineScript instead |
||
| 1361 | * @param string $script JavaScript code |
||
| 1362 | * @return string |
||
| 1363 | */ |
||
| 1364 | public static function makeLoaderConditionalScript( $script ) { |
||
| 1368 | |||
| 1369 | /** |
||
| 1370 | * Construct an inline script tag with given JS code. |
||
| 1371 | * |
||
| 1372 | * The code will be wrapped in a closure, and it will be executed by ResourceLoader |
||
| 1373 | * only if the client has adequate support for MediaWiki JavaScript code. |
||
| 1374 | * |
||
| 1375 | * @param string $script JavaScript code |
||
| 1376 | * @return WrappedString HTML |
||
| 1377 | */ |
||
| 1378 | public static function makeInlineScript( $script ) { |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Returns JS code which will set the MediaWiki configuration array to |
||
| 1389 | * the given value. |
||
| 1390 | * |
||
| 1391 | * @param array $configuration List of configuration values keyed by variable name |
||
| 1392 | * @return string |
||
| 1393 | */ |
||
| 1394 | public static function makeConfigSetScript( array $configuration ) { |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Convert an array of module names to a packed query string. |
||
| 1404 | * |
||
| 1405 | * For example, array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ) |
||
| 1406 | * becomes 'foo.bar,baz|bar.baz,quux' |
||
| 1407 | * @param array $modules List of module names (strings) |
||
| 1408 | * @return string Packed query string |
||
| 1409 | */ |
||
| 1410 | public static function makePackedModulesString( $modules ) { |
||
| 1427 | |||
| 1428 | /** |
||
| 1429 | * Determine whether debug mode was requested |
||
| 1430 | * Order of priority is 1) request param, 2) cookie, 3) $wg setting |
||
| 1431 | * @return bool |
||
| 1432 | */ |
||
| 1433 | public static function inDebugMode() { |
||
| 1442 | |||
| 1443 | /** |
||
| 1444 | * Reset static members used for caching. |
||
| 1445 | * |
||
| 1446 | * Global state and $wgRequest are evil, but we're using it right |
||
| 1447 | * now and sometimes we need to be able to force ResourceLoader to |
||
| 1448 | * re-evaluate the context because it has changed (e.g. in the test suite). |
||
| 1449 | */ |
||
| 1450 | public static function clearCache() { |
||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Build a load.php URL |
||
| 1456 | * |
||
| 1457 | * @since 1.24 |
||
| 1458 | * @param string $source Name of the ResourceLoader source |
||
| 1459 | * @param ResourceLoaderContext $context |
||
| 1460 | * @param array $extraQuery |
||
| 1461 | * @return string URL to load.php. May be protocol-relative if $wgLoadScript is, too. |
||
| 1462 | */ |
||
| 1463 | public function createLoaderURL( $source, ResourceLoaderContext $context, |
||
| 1471 | |||
| 1472 | /** |
||
| 1473 | * Build a load.php URL |
||
| 1474 | * @deprecated since 1.24 Use createLoaderURL() instead |
||
| 1475 | * @param array $modules Array of module names (strings) |
||
| 1476 | * @param string $lang Language code |
||
| 1477 | * @param string $skin Skin name |
||
| 1478 | * @param string|null $user User name. If null, the &user= parameter is omitted |
||
| 1479 | * @param string|null $version Versioning timestamp |
||
| 1480 | * @param bool $debug Whether the request should be in debug mode |
||
| 1481 | * @param string|null $only &only= parameter |
||
| 1482 | * @param bool $printable Printable mode |
||
| 1483 | * @param bool $handheld Handheld mode |
||
| 1484 | * @param array $extraQuery Extra query parameters to add |
||
| 1485 | * @return string URL to load.php. May be protocol-relative if $wgLoadScript is, too. |
||
| 1486 | */ |
||
| 1487 | public static function makeLoaderURL( $modules, $lang, $skin, $user = null, |
||
| 1499 | |||
| 1500 | /** |
||
| 1501 | * Helper for createLoaderURL() |
||
| 1502 | * |
||
| 1503 | * @since 1.24 |
||
| 1504 | * @see makeLoaderQuery |
||
| 1505 | * @param ResourceLoaderContext $context |
||
| 1506 | * @param array $extraQuery |
||
| 1507 | * @return array |
||
| 1508 | */ |
||
| 1509 | public static function createLoaderQuery( ResourceLoaderContext $context, $extraQuery = [] ) { |
||
| 1523 | |||
| 1524 | /** |
||
| 1525 | * Build a query array (array representation of query string) for load.php. Helper |
||
| 1526 | * function for makeLoaderURL(). |
||
| 1527 | * |
||
| 1528 | * @param array $modules |
||
| 1529 | * @param string $lang |
||
| 1530 | * @param string $skin |
||
| 1531 | * @param string $user |
||
| 1532 | * @param string $version |
||
| 1533 | * @param bool $debug |
||
| 1534 | * @param string $only |
||
| 1535 | * @param bool $printable |
||
| 1536 | * @param bool $handheld |
||
| 1537 | * @param array $extraQuery |
||
| 1538 | * |
||
| 1539 | * @return array |
||
| 1540 | */ |
||
| 1541 | public static function makeLoaderQuery( $modules, $lang, $skin, $user = null, |
||
| 1572 | |||
| 1573 | /** |
||
| 1574 | * Check a module name for validity. |
||
| 1575 | * |
||
| 1576 | * Module names may not contain pipes (|), commas (,) or exclamation marks (!) and can be |
||
| 1577 | * at most 255 bytes. |
||
| 1578 | * |
||
| 1579 | * @param string $moduleName Module name to check |
||
| 1580 | * @return bool Whether $moduleName is a valid module name |
||
| 1581 | */ |
||
| 1582 | public static function isValidModuleName( $moduleName ) { |
||
| 1585 | |||
| 1586 | /** |
||
| 1587 | * Returns LESS compiler set up for use with MediaWiki |
||
| 1588 | * |
||
| 1589 | * @since 1.27 |
||
| 1590 | * @param array $extraVars Associative array of extra (i.e., other than the |
||
| 1591 | * globally-configured ones) that should be used for compilation. |
||
| 1592 | * @throws MWException |
||
| 1593 | * @return Less_Parser |
||
| 1594 | */ |
||
| 1595 | public function getLessCompiler( $extraVars = [] ) { |
||
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Get global LESS variables. |
||
| 1616 | * |
||
| 1617 | * @since 1.27 |
||
| 1618 | * @return array Map of variable names to string CSS values. |
||
| 1619 | */ |
||
| 1620 | public function getLessVars() { |
||
| 1628 | } |
||
| 1629 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.