These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
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 SemanticBreadcrumbLinks extension, it is not a valid entry point.' ); |
||
14 | } |
||
15 | |||
16 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) { |
||
17 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">SemanticBreadcrumbLinks</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' ); |
||
18 | } |
||
19 | |||
20 | if ( defined( 'SBL_VERSION' ) ) { |
||
21 | // Do not initialize more than once. |
||
22 | return 1; |
||
23 | } |
||
24 | |||
25 | define( 'SBL_VERSION', '1.3.0-alpha' ); |
||
26 | |||
27 | /** |
||
28 | * @codeCoverageIgnore |
||
29 | */ |
||
30 | call_user_func( function () { |
||
31 | |||
32 | // Register the extension |
||
33 | $GLOBALS['wgExtensionCredits']['semantic'][ ] = array( |
||
34 | 'path' => __FILE__, |
||
35 | 'name' => 'Semantic Breadcrumb Links', |
||
36 | 'author' => array( 'James Hong Kong' ), |
||
37 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/', |
||
38 | 'descriptionmsg' => 'sbl-desc', |
||
39 | 'version' => SBL_VERSION, |
||
40 | 'license-name' => 'GPL-2.0+', |
||
41 | ); |
||
42 | |||
43 | // Register message files |
||
44 | $GLOBALS['wgMessagesDirs']['semantic-breadcrumb-links'] = __DIR__ . '/i18n'; |
||
45 | |||
46 | // Register resource files |
||
47 | $extensionPathParts = explode( DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR , __DIR__, 2 ); |
||
48 | |||
49 | $GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks'] = array( |
||
50 | 'styles' => 'res/sbl.styles.css', |
||
51 | 'scripts' => 'res/sbl.tooltip.js', |
||
52 | 'localBasePath' => __DIR__ , |
||
53 | 'remoteExtPath' => end( $extensionPathParts ), |
||
54 | 'position' => 'top', |
||
55 | 'group' => 'ext.smw', |
||
56 | 'dependencies' => array( |
||
57 | 'ext.jquery.qtip' |
||
58 | ), |
||
59 | 'targets' => array( |
||
60 | 'mobile', |
||
61 | 'desktop' |
||
62 | ) |
||
63 | ); |
||
64 | |||
65 | // Declare property Id constant |
||
66 | define( 'SBL_PROP_PARENTPAGE', 'Has parent page' ); |
||
67 | |||
68 | // Register default settings |
||
69 | $GLOBALS['egSBLBreadcrumbTrailStyleClass'] = 'sbl-breadcrumb-trail-light'; |
||
70 | $GLOBALS['egSBLBreadcrumbDividerStyleClass'] = 'sbl-breadcrumb-arrow'; |
||
71 | $GLOBALS['egSBLPropertySearchPatternByNamespace'] = array(); |
||
72 | |||
73 | $GLOBALS['egSBLTryToFindClosestDescendant'] = true; |
||
74 | $GLOBALS['egSBLUseSubpageFinderFallback'] = true; |
||
75 | $GLOBALS['egSBLPageTitleToHideSubpageParent'] = true; |
||
76 | $GLOBALS['egSBLEnabledSubpageParentAnnotation'] = true; |
||
77 | |||
78 | // Finalize registration process |
||
79 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
80 | |||
81 | // Default values are defined at this point to ensure |
||
82 | // NS contants are specified prior |
||
83 | $defaultPropertySearchPatternByNamespace = array( |
||
84 | NS_CATEGORY => array( |
||
85 | '_SUBC', |
||
86 | '_SUBC', |
||
87 | '_SUBC' |
||
88 | ), |
||
89 | SMW_NS_PROPERTY => array( |
||
90 | '_SUBP', |
||
91 | '_SUBP', |
||
92 | '_SUBP' |
||
93 | ), |
||
94 | NS_MAIN => array( |
||
95 | SBL_PROP_PARENTPAGE, |
||
96 | SBL_PROP_PARENTPAGE, |
||
97 | SBL_PROP_PARENTPAGE |
||
98 | ), |
||
99 | NS_HELP => array( |
||
100 | SBL_PROP_PARENTPAGE, |
||
101 | SBL_PROP_PARENTPAGE, |
||
102 | SBL_PROP_PARENTPAGE |
||
103 | ) |
||
104 | ); |
||
105 | |||
106 | $configuration = array( |
||
107 | 'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'], |
||
108 | 'breadcrumbTrailStyleClass' => $GLOBALS['egSBLBreadcrumbTrailStyleClass'], |
||
109 | 'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'], |
||
110 | 'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'], |
||
111 | 'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'], |
||
112 | 'enabledSubpageParentAnnotation' => $GLOBALS['egSBLEnabledSubpageParentAnnotation'], |
||
113 | 'wgNamespacesWithSubpages' => $GLOBALS['wgNamespacesWithSubpages'], |
||
114 | 'propertySearchPatternByNamespace' => $GLOBALS['egSBLPropertySearchPatternByNamespace'] + $defaultPropertySearchPatternByNamespace |
||
115 | ); |
||
116 | |||
117 | $hookRegistry = new HookRegistry( |
||
118 | ApplicationFactory::getInstance()->getStore(), |
||
119 | new Options( $configuration ) |
||
120 | ); |
||
121 | |||
122 | $hookRegistry->register(); |
||
123 | }; |
||
124 | |||
125 | } ); |
||
126 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.