| Conditions | 92 |
| Paths | > 20000 |
| Total Lines | 545 |
| Code Lines | 386 |
| Lines | 33 |
| Ratio | 6.06 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 224 | private static function getHelpInternal( IContextSource $context, array $modules, |
||
| 225 | array $options, &$haveModules |
||
| 226 | ) { |
||
| 227 | $out = ''; |
||
| 228 | |||
| 229 | $level = empty( $options['headerlevel'] ) ? 2 : $options['headerlevel']; |
||
| 230 | if ( empty( $options['tocnumber'] ) ) { |
||
| 231 | $tocnumber = [ 2 => 0 ]; |
||
| 232 | } else { |
||
| 233 | $tocnumber = &$options['tocnumber']; |
||
| 234 | } |
||
| 235 | |||
| 236 | foreach ( $modules as $module ) { |
||
| 237 | $tocnumber[$level]++; |
||
| 238 | $path = $module->getModulePath(); |
||
| 239 | $module->setContext( $context ); |
||
| 240 | $help = [ |
||
| 241 | 'header' => '', |
||
| 242 | 'flags' => '', |
||
| 243 | 'description' => '', |
||
| 244 | 'help-urls' => '', |
||
| 245 | 'parameters' => '', |
||
| 246 | 'examples' => '', |
||
| 247 | 'submodules' => '', |
||
| 248 | ]; |
||
| 249 | |||
| 250 | if ( empty( $options['noheader'] ) || !empty( $options['toc'] ) ) { |
||
| 251 | $anchor = $path; |
||
| 252 | $i = 1; |
||
| 253 | while ( isset( $haveModules[$anchor] ) ) { |
||
| 254 | $anchor = $path . '|' . ++$i; |
||
| 255 | } |
||
| 256 | |||
| 257 | if ( $module->isMain() ) { |
||
| 258 | $headerContent = $context->msg( 'api-help-main-header' )->parse(); |
||
| 259 | $headerAttr = [ |
||
| 260 | 'class' => 'apihelp-header', |
||
| 261 | ]; |
||
| 262 | } else { |
||
| 263 | $name = $module->getModuleName(); |
||
| 264 | $headerContent = $module->getParent()->getModuleManager()->getModuleGroup( $name ) . |
||
| 265 | "=$name"; |
||
| 266 | if ( $module->getModulePrefix() !== '' ) { |
||
| 267 | $headerContent .= ' ' . |
||
| 268 | $context->msg( 'parentheses', $module->getModulePrefix() )->parse(); |
||
| 269 | } |
||
| 270 | // Module names are always in English and not localized, |
||
| 271 | // so English language and direction must be set explicitly, |
||
| 272 | // otherwise parentheses will get broken in RTL wikis |
||
| 273 | $headerAttr = [ |
||
| 274 | 'class' => 'apihelp-header apihelp-module-name', |
||
| 275 | 'dir' => 'ltr', |
||
| 276 | 'lang' => 'en', |
||
| 277 | ]; |
||
| 278 | } |
||
| 279 | |||
| 280 | $headerAttr['id'] = $anchor; |
||
| 281 | |||
| 282 | $haveModules[$anchor] = [ |
||
| 283 | 'toclevel' => count( $tocnumber ), |
||
| 284 | 'level' => $level, |
||
| 285 | 'anchor' => $anchor, |
||
| 286 | 'line' => $headerContent, |
||
| 287 | 'number' => implode( '.', $tocnumber ), |
||
| 288 | 'index' => false, |
||
| 289 | ]; |
||
| 290 | if ( empty( $options['noheader'] ) ) { |
||
| 291 | $help['header'] .= Html::element( |
||
| 292 | 'h' . min( 6, $level ), |
||
| 293 | $headerAttr, |
||
| 294 | $headerContent |
||
| 295 | ); |
||
| 296 | } |
||
| 297 | } else { |
||
| 298 | $haveModules[$path] = true; |
||
| 299 | } |
||
| 300 | |||
| 301 | $links = []; |
||
| 302 | $any = false; |
||
| 303 | for ( $m = $module; $m !== null; $m = $m->getParent() ) { |
||
| 304 | $name = $m->getModuleName(); |
||
| 305 | if ( $name === 'main_int' ) { |
||
| 306 | $name = 'main'; |
||
| 307 | } |
||
| 308 | |||
| 309 | if ( count( $modules ) === 1 && $m === $modules[0] && |
||
| 310 | !( !empty( $options['submodules'] ) && $m->getModuleManager() ) |
||
| 311 | ) { |
||
| 312 | $link = Html::element( 'b', null, $name ); |
||
| 313 | } else { |
||
| 314 | $link = SpecialPage::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL(); |
||
| 315 | $link = Html::element( 'a', |
||
| 316 | [ 'href' => $link, 'class' => 'apihelp-linktrail' ], |
||
| 317 | $name |
||
| 318 | ); |
||
| 319 | $any = true; |
||
| 320 | } |
||
| 321 | array_unshift( $links, $link ); |
||
| 322 | } |
||
| 323 | if ( $any ) { |
||
| 324 | $help['header'] .= self::wrap( |
||
| 325 | $context->msg( 'parentheses' ) |
||
| 326 | ->rawParams( $context->getLanguage()->pipeList( $links ) ), |
||
| 327 | 'apihelp-linktrail', 'div' |
||
| 328 | ); |
||
| 329 | } |
||
| 330 | |||
| 331 | $flags = $module->getHelpFlags(); |
||
| 332 | $help['flags'] .= Html::openElement( 'div', |
||
| 333 | [ 'class' => 'apihelp-block apihelp-flags' ] ); |
||
| 334 | $msg = $context->msg( 'api-help-flags' ); |
||
| 335 | if ( !$msg->isDisabled() ) { |
||
| 336 | $help['flags'] .= self::wrap( |
||
| 337 | $msg->numParams( count( $flags ) ), 'apihelp-block-head', 'div' |
||
| 338 | ); |
||
| 339 | } |
||
| 340 | $help['flags'] .= Html::openElement( 'ul' ); |
||
| 341 | foreach ( $flags as $flag ) { |
||
| 342 | $help['flags'] .= Html::rawElement( 'li', null, |
||
| 343 | self::wrap( $context->msg( "api-help-flag-$flag" ), "apihelp-flag-$flag" ) |
||
| 344 | ); |
||
| 345 | } |
||
| 346 | $sourceInfo = $module->getModuleSourceInfo(); |
||
| 347 | if ( $sourceInfo ) { |
||
| 348 | if ( isset( $sourceInfo['namemsg'] ) ) { |
||
| 349 | $extname = $context->msg( $sourceInfo['namemsg'] )->text(); |
||
| 350 | } else { |
||
| 351 | $extname = $sourceInfo['name']; |
||
| 352 | } |
||
| 353 | $help['flags'] .= Html::rawElement( 'li', null, |
||
| 354 | self::wrap( |
||
| 355 | $context->msg( 'api-help-source', $extname, $sourceInfo['name'] ), |
||
| 356 | 'apihelp-source' |
||
| 357 | ) |
||
| 358 | ); |
||
| 359 | |||
| 360 | $link = SpecialPage::getTitleFor( 'Version', 'License/' . $sourceInfo['name'] ); |
||
| 361 | if ( isset( $sourceInfo['license-name'] ) ) { |
||
| 362 | $msg = $context->msg( 'api-help-license', $link, $sourceInfo['license-name'] ); |
||
| 363 | } elseif ( SpecialVersion::getExtLicenseFileName( dirname( $sourceInfo['path'] ) ) ) { |
||
| 364 | $msg = $context->msg( 'api-help-license-noname', $link ); |
||
| 365 | } else { |
||
| 366 | $msg = $context->msg( 'api-help-license-unknown' ); |
||
| 367 | } |
||
| 368 | $help['flags'] .= Html::rawElement( 'li', null, |
||
| 369 | self::wrap( $msg, 'apihelp-license' ) |
||
| 370 | ); |
||
| 371 | } else { |
||
| 372 | $help['flags'] .= Html::rawElement( 'li', null, |
||
| 373 | self::wrap( $context->msg( 'api-help-source-unknown' ), 'apihelp-source' ) |
||
| 374 | ); |
||
| 375 | $help['flags'] .= Html::rawElement( 'li', null, |
||
| 376 | self::wrap( $context->msg( 'api-help-license-unknown' ), 'apihelp-license' ) |
||
| 377 | ); |
||
| 378 | } |
||
| 379 | $help['flags'] .= Html::closeElement( 'ul' ); |
||
| 380 | $help['flags'] .= Html::closeElement( 'div' ); |
||
| 381 | |||
| 382 | foreach ( $module->getFinalDescription() as $msg ) { |
||
| 383 | $msg->setContext( $context ); |
||
| 384 | $help['description'] .= $msg->parseAsBlock(); |
||
| 385 | } |
||
| 386 | |||
| 387 | $urls = $module->getHelpUrls(); |
||
| 388 | if ( $urls ) { |
||
| 389 | $help['help-urls'] .= Html::openElement( 'div', |
||
| 390 | [ 'class' => 'apihelp-block apihelp-help-urls' ] |
||
| 391 | ); |
||
| 392 | $msg = $context->msg( 'api-help-help-urls' ); |
||
| 393 | if ( !$msg->isDisabled() ) { |
||
| 394 | $help['help-urls'] .= self::wrap( |
||
| 395 | $msg->numParams( count( $urls ) ), 'apihelp-block-head', 'div' |
||
| 396 | ); |
||
| 397 | } |
||
| 398 | if ( !is_array( $urls ) ) { |
||
| 399 | $urls = [ $urls ]; |
||
| 400 | } |
||
| 401 | $help['help-urls'] .= Html::openElement( 'ul' ); |
||
| 402 | foreach ( $urls as $url ) { |
||
| 403 | $help['help-urls'] .= Html::rawElement( 'li', null, |
||
| 404 | Html::element( 'a', [ 'href' => $url ], $url ) |
||
| 405 | ); |
||
| 406 | } |
||
| 407 | $help['help-urls'] .= Html::closeElement( 'ul' ); |
||
| 408 | $help['help-urls'] .= Html::closeElement( 'div' ); |
||
| 409 | } |
||
| 410 | |||
| 411 | $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP ); |
||
| 412 | $dynamicParams = $module->dynamicParameterDocumentation(); |
||
| 413 | $groups = []; |
||
| 414 | if ( $params || $dynamicParams !== null ) { |
||
| 415 | $help['parameters'] .= Html::openElement( 'div', |
||
| 416 | [ 'class' => 'apihelp-block apihelp-parameters' ] |
||
| 417 | ); |
||
| 418 | $msg = $context->msg( 'api-help-parameters' ); |
||
| 419 | if ( !$msg->isDisabled() ) { |
||
| 420 | $help['parameters'] .= self::wrap( |
||
| 421 | $msg->numParams( count( $params ) ), 'apihelp-block-head', 'div' |
||
| 422 | ); |
||
| 423 | } |
||
| 424 | $help['parameters'] .= Html::openElement( 'dl' ); |
||
| 425 | |||
| 426 | $descriptions = $module->getFinalParamDescription(); |
||
| 427 | |||
| 428 | foreach ( $params as $name => $settings ) { |
||
| 429 | if ( !is_array( $settings ) ) { |
||
| 430 | $settings = [ ApiBase::PARAM_DFLT => $settings ]; |
||
| 431 | } |
||
| 432 | |||
| 433 | $help['parameters'] .= Html::element( 'dt', null, |
||
| 434 | $module->encodeParamName( $name ) ); |
||
| 435 | |||
| 436 | // Add description |
||
| 437 | $description = []; |
||
| 438 | if ( isset( $descriptions[$name] ) ) { |
||
| 439 | foreach ( $descriptions[$name] as $msg ) { |
||
| 440 | $msg->setContext( $context ); |
||
| 441 | $description[] = $msg->parseAsBlock(); |
||
| 442 | } |
||
| 443 | } |
||
| 444 | |||
| 445 | // Add usage info |
||
| 446 | $info = []; |
||
| 447 | |||
| 448 | // Required? |
||
| 449 | if ( !empty( $settings[ApiBase::PARAM_REQUIRED] ) ) { |
||
| 450 | $info[] = $context->msg( 'api-help-param-required' )->parse(); |
||
| 451 | } |
||
| 452 | |||
| 453 | // Custom info? |
||
| 454 | if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) { |
||
| 455 | foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) { |
||
| 456 | $tag = array_shift( $i ); |
||
| 457 | $info[] = $context->msg( "apihelp-{$path}-paraminfo-{$tag}" ) |
||
| 458 | ->numParams( count( $i ) ) |
||
| 459 | ->params( $context->getLanguage()->commaList( $i ) ) |
||
| 460 | ->params( $module->getModulePrefix() ) |
||
| 461 | ->parse(); |
||
| 462 | } |
||
| 463 | } |
||
| 464 | |||
| 465 | // Type documentation |
||
| 466 | View Code Duplication | if ( !isset( $settings[ApiBase::PARAM_TYPE] ) ) { |
|
| 467 | $dflt = isset( $settings[ApiBase::PARAM_DFLT] ) |
||
| 468 | ? $settings[ApiBase::PARAM_DFLT] |
||
| 469 | : null; |
||
| 470 | if ( is_bool( $dflt ) ) { |
||
| 471 | $settings[ApiBase::PARAM_TYPE] = 'boolean'; |
||
| 472 | } elseif ( is_string( $dflt ) || is_null( $dflt ) ) { |
||
| 473 | $settings[ApiBase::PARAM_TYPE] = 'string'; |
||
| 474 | } elseif ( is_int( $dflt ) ) { |
||
| 475 | $settings[ApiBase::PARAM_TYPE] = 'integer'; |
||
| 476 | } |
||
| 477 | } |
||
| 478 | if ( isset( $settings[ApiBase::PARAM_TYPE] ) ) { |
||
| 479 | $type = $settings[ApiBase::PARAM_TYPE]; |
||
| 480 | $multi = !empty( $settings[ApiBase::PARAM_ISMULTI] ); |
||
| 481 | $hintPipeSeparated = true; |
||
| 482 | $count = ApiBase::LIMIT_SML2 + 1; |
||
| 483 | |||
| 484 | if ( is_array( $type ) ) { |
||
| 485 | $count = count( $type ); |
||
| 486 | $links = isset( $settings[ApiBase::PARAM_VALUE_LINKS] ) |
||
| 487 | ? $settings[ApiBase::PARAM_VALUE_LINKS] |
||
| 488 | : []; |
||
| 489 | $type = array_map( function ( $v ) use ( $links ) { |
||
| 490 | $ret = wfEscapeWikiText( $v ); |
||
| 491 | if ( isset( $links[$v] ) ) { |
||
| 492 | $ret = "[[{$links[$v]}|$ret]]"; |
||
| 493 | } |
||
| 494 | return $ret; |
||
| 495 | }, $type ); |
||
| 496 | $i = array_search( '', $type, true ); |
||
| 497 | if ( $i === false ) { |
||
| 498 | $type = $context->getLanguage()->commaList( $type ); |
||
| 499 | } else { |
||
| 500 | unset( $type[$i] ); |
||
| 501 | $type = $context->msg( 'api-help-param-list-can-be-empty' ) |
||
| 502 | ->numParams( count( $type ) ) |
||
| 503 | ->params( $context->getLanguage()->commaList( $type ) ) |
||
| 504 | ->parse(); |
||
| 505 | } |
||
| 506 | $info[] = $context->msg( 'api-help-param-list' ) |
||
| 507 | ->params( $multi ? 2 : 1 ) |
||
| 508 | ->params( $type ) |
||
| 509 | ->parse(); |
||
| 510 | $hintPipeSeparated = false; |
||
| 511 | } else { |
||
| 512 | switch ( $type ) { |
||
| 513 | case 'submodule': |
||
| 514 | $groups[] = $name; |
||
| 515 | if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) { |
||
| 516 | $map = $settings[ApiBase::PARAM_SUBMODULE_MAP]; |
||
| 517 | ksort( $map ); |
||
| 518 | $submodules = []; |
||
| 519 | foreach ( $map as $v => $m ) { |
||
| 520 | $submodules[] = "[[Special:ApiHelp/{$m}|{$v}]]"; |
||
| 521 | } |
||
| 522 | } else { |
||
| 523 | $submodules = $module->getModuleManager()->getNames( $name ); |
||
| 524 | sort( $submodules ); |
||
| 525 | $prefix = $module->isMain() |
||
| 526 | ? '' : ( $module->getModulePath() . '+' ); |
||
| 527 | $submodules = array_map( function ( $name ) use ( $prefix ) { |
||
| 528 | return "[[Special:ApiHelp/{$prefix}{$name}|{$name}]]"; |
||
| 529 | }, $submodules ); |
||
| 530 | } |
||
| 531 | $count = count( $submodules ); |
||
| 532 | $info[] = $context->msg( 'api-help-param-list' ) |
||
| 533 | ->params( $multi ? 2 : 1 ) |
||
| 534 | ->params( $context->getLanguage()->commaList( $submodules ) ) |
||
| 535 | ->parse(); |
||
| 536 | $hintPipeSeparated = false; |
||
| 537 | // No type message necessary, we have a list of values. |
||
| 538 | $type = null; |
||
| 539 | break; |
||
| 540 | |||
| 541 | View Code Duplication | case 'namespace': |
|
| 542 | $namespaces = MWNamespace::getValidNamespaces(); |
||
| 543 | $count = count( $namespaces ); |
||
| 544 | $info[] = $context->msg( 'api-help-param-list' ) |
||
| 545 | ->params( $multi ? 2 : 1 ) |
||
| 546 | ->params( $context->getLanguage()->commaList( $namespaces ) ) |
||
| 547 | ->parse(); |
||
| 548 | $hintPipeSeparated = false; |
||
| 549 | // No type message necessary, we have a list of values. |
||
| 550 | $type = null; |
||
| 551 | break; |
||
| 552 | |||
| 553 | View Code Duplication | case 'tags': |
|
| 554 | $tags = ChangeTags::listExplicitlyDefinedTags(); |
||
| 555 | $count = count( $tags ); |
||
| 556 | $info[] = $context->msg( 'api-help-param-list' ) |
||
| 557 | ->params( $multi ? 2 : 1 ) |
||
| 558 | ->params( $context->getLanguage()->commaList( $tags ) ) |
||
| 559 | ->parse(); |
||
| 560 | $hintPipeSeparated = false; |
||
| 561 | $type = null; |
||
| 562 | break; |
||
| 563 | |||
| 564 | case 'limit': |
||
| 565 | if ( isset( $settings[ApiBase::PARAM_MAX2] ) ) { |
||
| 566 | $info[] = $context->msg( 'api-help-param-limit2' ) |
||
| 567 | ->numParams( $settings[ApiBase::PARAM_MAX] ) |
||
| 568 | ->numParams( $settings[ApiBase::PARAM_MAX2] ) |
||
| 569 | ->parse(); |
||
| 570 | } else { |
||
| 571 | $info[] = $context->msg( 'api-help-param-limit' ) |
||
| 572 | ->numParams( $settings[ApiBase::PARAM_MAX] ) |
||
| 573 | ->parse(); |
||
| 574 | } |
||
| 575 | break; |
||
| 576 | |||
| 577 | case 'integer': |
||
| 578 | // Possible messages: |
||
| 579 | // api-help-param-integer-min, |
||
| 580 | // api-help-param-integer-max, |
||
| 581 | // api-help-param-integer-minmax |
||
| 582 | $suffix = ''; |
||
| 583 | $min = $max = 0; |
||
| 584 | if ( isset( $settings[ApiBase::PARAM_MIN] ) ) { |
||
| 585 | $suffix .= 'min'; |
||
| 586 | $min = $settings[ApiBase::PARAM_MIN]; |
||
| 587 | } |
||
| 588 | if ( isset( $settings[ApiBase::PARAM_MAX] ) ) { |
||
| 589 | $suffix .= 'max'; |
||
| 590 | $max = $settings[ApiBase::PARAM_MAX]; |
||
| 591 | } |
||
| 592 | if ( $suffix !== '' ) { |
||
| 593 | $info[] = |
||
| 594 | $context->msg( "api-help-param-integer-$suffix" ) |
||
| 595 | ->params( $multi ? 2 : 1 ) |
||
| 596 | ->numParams( $min, $max ) |
||
| 597 | ->parse(); |
||
| 598 | } |
||
| 599 | break; |
||
| 600 | |||
| 601 | case 'upload': |
||
| 602 | $info[] = $context->msg( 'api-help-param-upload' ) |
||
| 603 | ->parse(); |
||
| 604 | // No type message necessary, api-help-param-upload should handle it. |
||
| 605 | $type = null; |
||
| 606 | break; |
||
| 607 | |||
| 608 | case 'string': |
||
| 609 | case 'text': |
||
| 610 | // Displaying a type message here would be useless. |
||
| 611 | $type = null; |
||
| 612 | break; |
||
| 613 | } |
||
| 614 | } |
||
| 615 | |||
| 616 | // Add type. Messages for grep: api-help-param-type-limit |
||
| 617 | // api-help-param-type-integer api-help-param-type-boolean |
||
| 618 | // api-help-param-type-timestamp api-help-param-type-user |
||
| 619 | // api-help-param-type-password |
||
| 620 | if ( is_string( $type ) ) { |
||
| 621 | $msg = $context->msg( "api-help-param-type-$type" ); |
||
| 622 | if ( !$msg->isDisabled() ) { |
||
| 623 | $info[] = $msg->params( $multi ? 2 : 1 )->parse(); |
||
| 624 | } |
||
| 625 | } |
||
| 626 | |||
| 627 | if ( $multi ) { |
||
| 628 | $extra = []; |
||
| 629 | if ( $hintPipeSeparated ) { |
||
| 630 | $extra[] = $context->msg( 'api-help-param-multi-separate' )->parse(); |
||
| 631 | } |
||
| 632 | if ( $count > ApiBase::LIMIT_SML1 ) { |
||
| 633 | $extra[] = $context->msg( 'api-help-param-multi-max' ) |
||
| 634 | ->numParams( ApiBase::LIMIT_SML1, ApiBase::LIMIT_SML2 ) |
||
| 635 | ->parse(); |
||
| 636 | } |
||
| 637 | if ( $extra ) { |
||
| 638 | $info[] = implode( ' ', $extra ); |
||
| 639 | } |
||
| 640 | } |
||
| 641 | } |
||
| 642 | |||
| 643 | // Add default |
||
| 644 | $default = isset( $settings[ApiBase::PARAM_DFLT] ) |
||
| 645 | ? $settings[ApiBase::PARAM_DFLT] |
||
| 646 | : null; |
||
| 647 | if ( $default === '' ) { |
||
| 648 | $info[] = $context->msg( 'api-help-param-default-empty' ) |
||
| 649 | ->parse(); |
||
| 650 | } elseif ( $default !== null && $default !== false ) { |
||
| 651 | $info[] = $context->msg( 'api-help-param-default' ) |
||
| 652 | ->params( wfEscapeWikiText( $default ) ) |
||
| 653 | ->parse(); |
||
| 654 | } |
||
| 655 | |||
| 656 | if ( !array_filter( $description ) ) { |
||
| 657 | $description = [ self::wrap( |
||
| 658 | $context->msg( 'api-help-param-no-description' ), |
||
| 659 | 'apihelp-empty' |
||
| 660 | ) ]; |
||
| 661 | } |
||
| 662 | |||
| 663 | // Add "deprecated" flag |
||
| 664 | if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) { |
||
| 665 | $help['parameters'] .= Html::openElement( 'dd', |
||
| 666 | [ 'class' => 'info' ] ); |
||
| 667 | $help['parameters'] .= self::wrap( |
||
| 668 | $context->msg( 'api-help-param-deprecated' ), |
||
| 669 | 'apihelp-deprecated', 'strong' |
||
| 670 | ); |
||
| 671 | $help['parameters'] .= Html::closeElement( 'dd' ); |
||
| 672 | } |
||
| 673 | |||
| 674 | if ( $description ) { |
||
| 675 | $description = implode( '', $description ); |
||
| 676 | $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description ); |
||
| 677 | $help['parameters'] .= Html::rawElement( 'dd', |
||
| 678 | [ 'class' => 'description' ], $description ); |
||
| 679 | } |
||
| 680 | |||
| 681 | foreach ( $info as $i ) { |
||
| 682 | $help['parameters'] .= Html::rawElement( 'dd', [ 'class' => 'info' ], $i ); |
||
| 683 | } |
||
| 684 | } |
||
| 685 | |||
| 686 | if ( $dynamicParams !== null ) { |
||
| 687 | $dynamicParams = ApiBase::makeMessage( $dynamicParams, $context, [ |
||
| 688 | $module->getModulePrefix(), |
||
| 689 | $module->getModuleName(), |
||
| 690 | $module->getModulePath() |
||
| 691 | ] ); |
||
| 692 | $help['parameters'] .= Html::element( 'dt', null, '*' ); |
||
| 693 | $help['parameters'] .= Html::rawElement( 'dd', |
||
| 694 | [ 'class' => 'description' ], $dynamicParams->parse() ); |
||
| 695 | } |
||
| 696 | |||
| 697 | $help['parameters'] .= Html::closeElement( 'dl' ); |
||
| 698 | $help['parameters'] .= Html::closeElement( 'div' ); |
||
| 699 | } |
||
| 700 | |||
| 701 | $examples = $module->getExamplesMessages(); |
||
| 702 | if ( $examples ) { |
||
| 703 | $help['examples'] .= Html::openElement( 'div', |
||
| 704 | [ 'class' => 'apihelp-block apihelp-examples' ] ); |
||
| 705 | $msg = $context->msg( 'api-help-examples' ); |
||
| 706 | if ( !$msg->isDisabled() ) { |
||
| 707 | $help['examples'] .= self::wrap( |
||
| 708 | $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div' |
||
| 709 | ); |
||
| 710 | } |
||
| 711 | |||
| 712 | $help['examples'] .= Html::openElement( 'dl' ); |
||
| 713 | foreach ( $examples as $qs => $msg ) { |
||
| 714 | $msg = ApiBase::makeMessage( $msg, $context, [ |
||
| 715 | $module->getModulePrefix(), |
||
| 716 | $module->getModuleName(), |
||
| 717 | $module->getModulePath() |
||
| 718 | ] ); |
||
| 719 | |||
| 720 | $link = wfAppendQuery( wfScript( 'api' ), $qs ); |
||
| 721 | $sandbox = SpecialPage::getTitleFor( 'ApiSandbox' )->getLocalURL() . '#' . $qs; |
||
| 722 | $help['examples'] .= Html::rawElement( 'dt', null, $msg->parse() ); |
||
| 723 | $help['examples'] .= Html::rawElement( 'dd', null, |
||
| 724 | Html::element( 'a', [ 'href' => $link ], "api.php?$qs" ) . ' ' . |
||
| 725 | Html::rawElement( 'a', [ 'href' => $sandbox ], |
||
| 726 | $context->msg( 'api-help-open-in-apisandbox' )->parse() ) |
||
| 727 | ); |
||
| 728 | } |
||
| 729 | $help['examples'] .= Html::closeElement( 'dl' ); |
||
| 730 | $help['examples'] .= Html::closeElement( 'div' ); |
||
| 731 | } |
||
| 732 | |||
| 733 | $subtocnumber = $tocnumber; |
||
| 734 | $subtocnumber[$level + 1] = 0; |
||
| 735 | $suboptions = [ |
||
| 736 | 'submodules' => $options['recursivesubmodules'], |
||
| 737 | 'headerlevel' => $level + 1, |
||
| 738 | 'tocnumber' => &$subtocnumber, |
||
| 739 | 'noheader' => false, |
||
| 740 | ] + $options; |
||
| 741 | |||
| 742 | if ( $options['submodules'] && $module->getModuleManager() ) { |
||
| 743 | $manager = $module->getModuleManager(); |
||
| 744 | $submodules = []; |
||
| 745 | foreach ( $groups as $group ) { |
||
| 746 | $names = $manager->getNames( $group ); |
||
| 747 | sort( $names ); |
||
| 748 | foreach ( $names as $name ) { |
||
| 749 | $submodules[] = $manager->getModule( $name ); |
||
| 750 | } |
||
| 751 | } |
||
| 752 | $help['submodules'] .= self::getHelpInternal( |
||
| 753 | $context, |
||
| 754 | $submodules, |
||
| 755 | $suboptions, |
||
| 756 | $haveModules |
||
| 757 | ); |
||
| 758 | } |
||
| 759 | |||
| 760 | $module->modifyHelp( $help, $suboptions, $haveModules ); |
||
| 761 | |||
| 762 | Hooks::run( 'APIHelpModifyOutput', [ $module, &$help, $suboptions, &$haveModules ] ); |
||
| 763 | |||
| 764 | $out .= implode( "\n", $help ); |
||
| 765 | } |
||
| 766 | |||
| 767 | return $out; |
||
| 768 | } |
||
| 769 | |||
| 825 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: