SemanticMediaWiki /
SemanticBreadcrumbLinks
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | use SBL\HookRegistry; |
||
| 4 | use SBL\Options; |
||
| 5 | use SMW\ApplicationFactory; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * @see https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/ |
||
| 9 | * |
||
| 10 | * @defgroup SBL Semantic Breadcrumb Links |
||
| 11 | */ |
||
| 12 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
| 13 | die( 'This file is part of the Semantic Breadcrumb Links extension. It is not a valid entry point.' ); |
||
| 14 | } |
||
| 15 | |||
| 16 | if ( defined( 'SBL_VERSION' ) ) { |
||
| 17 | // Do not initialize more than once. |
||
| 18 | return 1; |
||
| 19 | } |
||
| 20 | |||
| 21 | SemanticBreadcrumbLinks::load(); |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @codeCoverageIgnore |
||
| 25 | */ |
||
| 26 | class SemanticBreadcrumbLinks { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @since 1.3 |
||
| 30 | */ |
||
| 31 | public static function load() { |
||
|
0 ignored issues
–
show
|
|||
| 32 | |||
| 33 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
| 34 | include_once __DIR__ . '/vendor/autoload.php'; |
||
| 35 | } |
||
| 36 | |||
| 37 | // Load DefaultSettings |
||
| 38 | require_once __DIR__ . '/DefaultSettings.php'; |
||
| 39 | |||
| 40 | // In case extension.json is being used, the succeeding steps will |
||
| 41 | // be handled by the ExtensionRegistry |
||
| 42 | self::initExtension(); |
||
| 43 | |||
| 44 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
| 45 | self::onExtensionFunction(); |
||
| 46 | }; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @since 1.3 |
||
| 51 | */ |
||
| 52 | public static function initExtension() { |
||
|
0 ignored issues
–
show
initExtension uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
Loading history...
|
|||
| 53 | |||
| 54 | define( 'SBL_VERSION', '1.5.0' ); |
||
| 55 | define( 'SBL_PROP_PARENTPAGE', 'Has parent page' ); |
||
| 56 | |||
| 57 | // Register the extension |
||
| 58 | $GLOBALS['wgExtensionCredits']['semantic'][ ] = [ |
||
| 59 | 'path' => __FILE__, |
||
| 60 | 'name' => 'Semantic Breadcrumb Links', |
||
| 61 | 'author' => [ 'James Hong Kong' ], |
||
| 62 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/', |
||
| 63 | 'descriptionmsg' => 'sbl-desc', |
||
| 64 | 'version' => SBL_VERSION, |
||
| 65 | 'license-name' => 'GPL-2.0-or-later', |
||
| 66 | ]; |
||
| 67 | |||
| 68 | // Register message files |
||
| 69 | $GLOBALS['wgMessagesDirs']['SemanticBreadcrumbLinks'] = __DIR__ . '/i18n'; |
||
| 70 | $GLOBALS['wgExtensionMessagesFiles']['SemanticBreadcrumbLinksMagic'] = __DIR__ . '/i18n/SemanticBreadcrumbLinks.magic.php'; |
||
| 71 | |||
| 72 | // Register resource files |
||
| 73 | $GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks.styles'] = [ |
||
| 74 | 'styles' => 'res/sbl.styles.css', |
||
| 75 | 'localBasePath' => __DIR__ , |
||
| 76 | 'remoteExtPath' => 'SemanticBreadcrumbLinks', |
||
| 77 | 'position' => 'top', |
||
| 78 | 'group' => 'ext.smw', |
||
| 79 | 'targets' => [ |
||
| 80 | 'mobile', |
||
| 81 | 'desktop' |
||
| 82 | ] |
||
| 83 | ]; |
||
| 84 | |||
| 85 | $GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks'] = [ |
||
| 86 | 'scripts' => 'res/sbl.tooltip.js', |
||
| 87 | 'localBasePath' => __DIR__ , |
||
| 88 | 'remoteExtPath' => 'SemanticBreadcrumbLinks', |
||
| 89 | 'position' => 'top', |
||
| 90 | 'group' => 'ext.smw', |
||
| 91 | 'dependencies' => [ |
||
| 92 | 'ext.semanticbreadcrumblinks.styles', |
||
| 93 | 'onoi.qtip' |
||
| 94 | ], |
||
| 95 | 'targets' => [ |
||
| 96 | 'mobile', |
||
| 97 | 'desktop' |
||
| 98 | ] |
||
| 99 | ]; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @since 1.3 |
||
| 104 | */ |
||
| 105 | public static function checkRequirements() { |
||
|
0 ignored issues
–
show
checkRequirements uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
Loading history...
|
|||
| 106 | |||
| 107 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.27', 'lt' ) ) { |
||
| 108 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> is only compatible with MediaWiki 1.27 or above. You need to upgrade MediaWiki first.' ); |
||
|
0 ignored issues
–
show
The method
checkRequirements() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an Loading history...
|
|||
| 109 | } |
||
| 110 | |||
| 111 | if ( !defined( 'SMW_VERSION' ) ) { |
||
| 112 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> requires <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a>. Please enable or install the extension first.' ); |
||
|
0 ignored issues
–
show
The method
checkRequirements() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an Loading history...
|
|||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @since 1.3 |
||
| 118 | */ |
||
| 119 | public static function onExtensionFunction() { |
||
| 120 | |||
| 121 | // Check requirements after LocalSetting.php has been processed |
||
| 122 | self::checkRequirements(); |
||
| 123 | |||
| 124 | // Default values are defined at this point to ensure |
||
| 125 | // NS contants are specified prior |
||
| 126 | $defaultPropertySearchPatternByNamespace = [ |
||
| 127 | NS_CATEGORY => [ |
||
| 128 | '_SUBC', |
||
| 129 | '_SUBC', |
||
| 130 | '_SUBC' |
||
| 131 | ], |
||
| 132 | SMW_NS_PROPERTY => [ |
||
| 133 | '_SUBP', |
||
| 134 | '_SUBP', |
||
| 135 | '_SUBP' |
||
| 136 | ], |
||
| 137 | NS_MAIN => [ |
||
| 138 | SBL_PROP_PARENTPAGE, |
||
| 139 | SBL_PROP_PARENTPAGE, |
||
| 140 | SBL_PROP_PARENTPAGE |
||
| 141 | ], |
||
| 142 | NS_HELP => [ |
||
| 143 | SBL_PROP_PARENTPAGE, |
||
| 144 | SBL_PROP_PARENTPAGE, |
||
| 145 | SBL_PROP_PARENTPAGE |
||
| 146 | ] |
||
| 147 | ]; |
||
| 148 | |||
| 149 | $configuration = [ |
||
| 150 | 'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'], |
||
| 151 | 'breadcrumbTrailStyleClass' => $GLOBALS['egSBLBreadcrumbTrailStyleClass'], |
||
| 152 | 'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'], |
||
| 153 | 'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'], |
||
| 154 | 'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'], |
||
| 155 | 'enabledSubpageParentAnnotation' => $GLOBALS['egSBLEnabledSubpageParentAnnotation'], |
||
| 156 | 'disableTranslationSubpageAnnotation' => $GLOBALS['egSBLDisableTranslationSubpageAnnotation'], |
||
| 157 | 'wgNamespacesWithSubpages' => $GLOBALS['wgNamespacesWithSubpages'], |
||
| 158 | 'propertySearchPatternByNamespace' => $GLOBALS['egSBLPropertySearchPatternByNamespace'] + $defaultPropertySearchPatternByNamespace |
||
| 159 | ]; |
||
| 160 | |||
| 161 | $hookRegistry = new HookRegistry( |
||
| 162 | ApplicationFactory::getInstance()->getStore(), |
||
| 163 | new Options( $configuration ) |
||
| 164 | ); |
||
| 165 | |||
| 166 | $hookRegistry->register(); |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @since 1.3 |
||
| 171 | * |
||
| 172 | * @return string|null |
||
| 173 | */ |
||
| 174 | public static function getVersion() { |
||
| 175 | return SBL_VERSION; |
||
| 176 | } |
||
| 177 | |||
| 178 | } |
||
| 179 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: