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 SCI\HookRegistry; |
||
4 | use SCI\Options; |
||
5 | use SMW\ApplicationFactory; |
||
6 | |||
7 | /** |
||
8 | * @see https://github.com/SemanticMediaWiki/SemanticCite/ |
||
9 | * |
||
10 | * @defgroup SCI Semantic Citation |
||
11 | */ |
||
12 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
13 | die( 'This file is part of the SemanticCite extension, it is not a valid entry point.' ); |
||
14 | } |
||
15 | |||
16 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.24', 'lt' ) ) { |
||
17 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticCite/">SemanticCite</a> is only compatible with MediaWiki 1.24 or above. You need to upgrade MediaWiki first.' ); |
||
18 | } |
||
19 | |||
20 | if ( defined( 'SCI_VERSION' ) ) { |
||
21 | // Do not initialize more than once. |
||
22 | return 1; |
||
23 | } |
||
24 | |||
25 | define( 'SCI_VERSION', '1.1.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 Cite', |
||
36 | 'author' => array( 'James Hong Kong' ), |
||
37 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticCite/', |
||
38 | 'descriptionmsg' => 'sci-desc', |
||
39 | 'version' => SCI_VERSION, |
||
40 | 'license-name' => 'GPL-2.0+', |
||
41 | ); |
||
42 | |||
43 | // Register message files |
||
44 | $GLOBALS['wgMessagesDirs']['semantic-cite'] = __DIR__ . '/i18n'; |
||
45 | $GLOBALS['wgExtensionMessagesFiles']['semantic-cite-magic'] = __DIR__ . '/i18n/SemanticCite.magic.php'; |
||
46 | $GLOBALS['wgExtensionMessagesFiles']['semantic-cite-alias'] = __DIR__ . '/i18n/SemanticCite.alias.php'; |
||
47 | |||
48 | $GLOBALS['wgSpecialPages']['FindCitableMetadata'] = '\SCI\Specials\SpecialFindCitableMetadata'; |
||
49 | |||
50 | // Restrict access to the meta search for registered users only |
||
51 | $GLOBALS['wgAvailableRights'][] = 'sci-metadatasearch'; |
||
52 | $GLOBALS['wgGroupPermissions']['user']['sci-metadatasearch'] = true; |
||
53 | |||
54 | // Register resource files |
||
55 | $extensionPathParts = explode( DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR , __DIR__, 2 ); |
||
56 | |||
57 | $GLOBALS['wgResourceModules']['ext.scite.styles'] = array( |
||
58 | 'styles' => 'res/scite.styles.css', |
||
59 | 'localBasePath' => __DIR__ , |
||
60 | 'remoteExtPath' => end( $extensionPathParts ), |
||
61 | 'position' => 'top', |
||
62 | 'group' => 'ext.smw', |
||
63 | 'targets' => array( |
||
64 | 'mobile', |
||
65 | 'desktop' |
||
66 | ) |
||
67 | ); |
||
68 | |||
69 | $GLOBALS['wgResourceModules']['ext.scite.metadata'] = array( |
||
70 | 'scripts' => array( |
||
71 | 'res/scite.text.selector.js', |
||
72 | 'res/scite.page.creator.js' |
||
73 | ), |
||
74 | 'localBasePath' => __DIR__ , |
||
75 | 'remoteExtPath' => end( $extensionPathParts ), |
||
76 | 'position' => 'top', |
||
77 | 'group' => 'ext.smw', |
||
78 | 'dependencies' => array( |
||
79 | 'ext.scite.styles', |
||
80 | 'mediawiki.api' |
||
81 | ), |
||
82 | 'targets' => array( |
||
83 | 'mobile', |
||
84 | 'desktop' |
||
85 | ) |
||
86 | ); |
||
87 | |||
88 | $GLOBALS['wgResourceModules']['ext.scite.tooltip'] = array( |
||
89 | 'styles' => 'res/jquery.qtip.css', |
||
90 | 'scripts' => array( |
||
91 | 'res/scite.cache.js', |
||
92 | 'res/scite.tooltip.js' |
||
93 | ), |
||
94 | 'localBasePath' => __DIR__ , |
||
95 | 'remoteExtPath' => end( $extensionPathParts ), |
||
96 | 'dependencies' => array( |
||
97 | 'ext.jquery.qtip', |
||
98 | 'ext.scite.styles', |
||
99 | 'mediawiki.api.parse' |
||
100 | ), |
||
101 | 'messages' => array( |
||
102 | 'sci-tooltip-citation-lookup-failure', |
||
103 | 'sci-tooltip-citation-lookup-failure-multiple' |
||
104 | ), |
||
105 | 'targets' => array( |
||
106 | 'mobile', |
||
107 | 'desktop' |
||
108 | ) |
||
109 | ); |
||
110 | |||
111 | // In-text citation reference format options |
||
112 | define( 'SCI_CITEREF_NUM', 1 ); |
||
113 | define( 'SCI_CITEREF_KEY', 2 ); |
||
114 | |||
115 | /** |
||
116 | * Specifies the caption format of the citation reference, either as a number |
||
117 | * or as the annotated key |
||
118 | */ |
||
119 | $GLOBALS['scigCitationReferenceCaptionFormat'] = SCI_CITEREF_NUM; |
||
120 | |||
121 | /** |
||
122 | * Enables a tooltip for a specific citation reference format |
||
123 | * |
||
124 | * The requestCacheTTL specifies the expiry for a citation text that is locally |
||
125 | * cached in a browser before a new ajax-request is made. |
||
126 | * |
||
127 | * To force a browser to renew the display before the cache is expired, delete |
||
128 | * the "scite.cache" localStorage from the browser |
||
129 | */ |
||
130 | $GLOBALS['scigShowTooltipForCitationReference'] = array( |
||
131 | SCI_CITEREF_NUM, |
||
132 | SCI_CITEREF_KEY |
||
133 | ); |
||
134 | |||
135 | $GLOBALS['scigTooltipRequestCacheTTLInSeconds'] = 60 * 60 * 24; // false to disable the Cache |
||
136 | |||
137 | /** |
||
138 | * Setting to regulate the caching of response for received from a metadata |
||
139 | * provider |
||
140 | */ |
||
141 | $GLOBALS['scigMetadataResponseCacheType'] = CACHE_ANYTHING; |
||
142 | $GLOBALS['scigMetadataResponseCacheLifetime'] = 60 * 60 * 24; |
||
143 | |||
144 | /** |
||
145 | * Number of columns displayed for the reference list |
||
146 | */ |
||
147 | $GLOBALS['scigNumberOfReferenceListColumns'] = 0; // 0 = responsive columns |
||
148 | |||
149 | /** |
||
150 | * Specifies the reference list type of which can be either 'ol' or 'ul' |
||
151 | */ |
||
152 | $GLOBALS['scigReferenceListType'] = 'ol'; |
||
153 | |||
154 | /** |
||
155 | * Whether to generate a "Browse" link to a citation resource or not. |
||
156 | */ |
||
157 | $GLOBALS['scigBrowseLinkToCitationResource'] = true; |
||
158 | |||
159 | /** |
||
160 | * Specify which cache type to be used, if no cache should be used at all, |
||
161 | * use CACHE_NONE |
||
162 | */ |
||
163 | $GLOBALS['scigReferenceListCacheType'] = CACHE_ANYTHING; |
||
164 | |||
165 | /** |
||
166 | * Whether a strict validation on behalf of the #scite parser should be |
||
167 | * enabled or not |
||
168 | */ |
||
169 | $GLOBALS['scigEnabledStrictParserValidation'] = true; |
||
170 | |||
171 | /** |
||
172 | * Whether an update job should be dispatched for changed citation text |
||
173 | * entities or not |
||
174 | */ |
||
175 | $GLOBALS['scigEnabledCitationTextChangeUpdateJob'] = true; |
||
176 | |||
177 | /** |
||
178 | * Whether an article should collect meta information about citation |
||
179 | * resources (i.e citation frequency etc.) |
||
180 | */ |
||
181 | $GLOBALS['scigEnabledCitationMetaRecord'] = false; |
||
182 | |||
183 | // Finalize registration process |
||
184 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
185 | |||
186 | // Require a global because MW's Special page is missing an interface |
||
187 | // to inject dependencies |
||
188 | $GLOBALS['scigCachePrefix'] = $GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix']; |
||
189 | |||
190 | $configuration = array( |
||
191 | 'numberOfReferenceListColumns' => $GLOBALS['scigNumberOfReferenceListColumns'], |
||
192 | 'browseLinkToCitationResource' => $GLOBALS['scigBrowseLinkToCitationResource'], |
||
193 | 'showTooltipForCitationReference' => $GLOBALS['scigShowTooltipForCitationReference'], |
||
194 | 'tooltipRequestCacheTTL' => $GLOBALS['scigTooltipRequestCacheTTLInSeconds'], |
||
195 | 'citationReferenceCaptionFormat' => $GLOBALS['scigCitationReferenceCaptionFormat'], |
||
196 | 'referenceListType' => $GLOBALS['scigReferenceListType'], |
||
197 | 'enabledstrictParserValidation' => $GLOBALS['scigEnabledStrictParserValidation'], |
||
198 | 'cachePrefix' => $GLOBALS['scigCachePrefix'], |
||
199 | 'enabledCitationTextChangeUpdateJob' => $GLOBALS['scigEnabledCitationTextChangeUpdateJob'], |
||
200 | 'enabledCitationMetaRecord' => $GLOBALS['scigEnabledCitationMetaRecord'] |
||
201 | ); |
||
202 | |||
203 | $applicationFactory = ApplicationFactory::getInstance(); |
||
204 | |||
205 | $hookRegistry = new HookRegistry( |
||
206 | $applicationFactory->getStore(), |
||
207 | $applicationFactory->newCacheFactory()->newMediaWikiCompositeCache( $GLOBALS['scigReferenceListCacheType'] ), |
||
208 | new Options( $configuration ) |
||
209 | ); |
||
210 | |||
211 | $hookRegistry->register(); |
||
212 | }; |
||
213 | |||
214 | } ); |
||
215 |
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.