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 SUC\HookRegistry; |
||
4 | use SUC\Options; |
||
5 | |||
6 | /** |
||
7 | * @see https://github.com/SemanticMediaWiki/SummaryCards/ |
||
8 | * |
||
9 | * @defgroup suc Semantic Citation |
||
10 | */ |
||
11 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
12 | die( 'This file is part of the SummaryCards extension, it is not a valid entry point.' ); |
||
13 | } |
||
14 | |||
15 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.24', 'lt' ) ) { |
||
16 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SummaryCards/">SummaryCards</a> is only compatible with MediaWiki 1.24 or above. You need to upgrade MediaWiki first.' ); |
||
17 | } |
||
18 | |||
19 | if ( defined( 'SUC_VERSION' ) ) { |
||
20 | // Do not initialize more than once. |
||
21 | return 1; |
||
22 | } |
||
23 | |||
24 | define( 'SUC_VERSION', '1.0.0-alpha' ); |
||
25 | |||
26 | /** |
||
27 | * @codeCoverageIgnore |
||
28 | */ |
||
29 | call_user_func( function () { |
||
30 | |||
31 | // mediawiki/link-summary-cards |
||
32 | // mediawiki/summary-hovercards |
||
33 | |||
34 | // Register the extension |
||
35 | $GLOBALS['wgExtensionCredits']['others'][ ] = array( |
||
36 | 'path' => __DIR__, |
||
37 | 'name' => 'Summary Cards', |
||
38 | 'author' => array( |
||
39 | 'James Hong Kong' |
||
40 | ), |
||
41 | 'url' => 'https://github.com/SemanticMediaWiki/SummaryCards/', |
||
42 | 'descriptionmsg' => 'suc-desc', |
||
43 | 'version' => SUC_VERSION, |
||
44 | 'license-name' => 'GPL-2.0+', |
||
45 | ); |
||
46 | |||
47 | // Register message files |
||
48 | $GLOBALS['wgMessagesDirs']['summary-cards'] = __DIR__ . '/i18n'; |
||
49 | |||
50 | $GLOBALS['wgResourceModules']['ext.summary.cards.styles'] = array( |
||
51 | 'styles' => 'res/ext.suc.styles.css', |
||
52 | 'localBasePath' => __DIR__ , |
||
53 | 'remoteExtPath' => 'SummaryCards', |
||
54 | 'position' => 'top', |
||
55 | 'targets' => array( |
||
56 | 'mobile', |
||
57 | 'desktop' |
||
58 | ) |
||
59 | ); |
||
60 | |||
61 | $GLOBALS['wgResourceModules']['ext.summary.cards.tooltip'] = array( |
||
62 | 'localBasePath' => __DIR__ , |
||
63 | 'remoteExtPath' => 'SummaryCards', |
||
64 | 'position' => 'bottom', |
||
65 | 'dependencies' => array( |
||
66 | 'onoi.qtip', |
||
67 | 'onoi.md5', |
||
68 | 'onoi.blobstore', |
||
69 | 'onoi.util' |
||
70 | ), |
||
71 | 'targets' => array( |
||
72 | 'mobile', |
||
73 | 'desktop' |
||
74 | ) |
||
75 | ); |
||
76 | |||
77 | $GLOBALS['wgResourceModules']['ext.summary.cards'] = array( |
||
78 | 'scripts' => array( |
||
79 | 'res/ext.suc.cards.js' |
||
80 | ), |
||
81 | 'localBasePath' => __DIR__ , |
||
82 | 'remoteExtPath' => 'SummaryCards', |
||
83 | 'position' => 'bottom', |
||
84 | 'dependencies' => array( |
||
85 | 'mediawiki.api', |
||
86 | 'mediawiki.api.parse', |
||
87 | 'ext.summary.cards.styles', |
||
88 | 'ext.summary.cards.tooltip', |
||
89 | ), |
||
90 | 'messages' => array( |
||
91 | 'suc-tooltip-title', |
||
92 | 'suc-tooltip-error' |
||
93 | ), |
||
94 | 'targets' => array( |
||
95 | 'mobile', |
||
96 | 'desktop' |
||
97 | ) |
||
98 | ); |
||
99 | |||
100 | /** |
||
101 | * Only enabled namespaces with a template assignment |
||
102 | * are used to display a summary card |
||
103 | */ |
||
104 | $GLOBALS['sucgEnabledNamespaceWithTemplate'] = array(); |
||
105 | |||
106 | /** |
||
107 | * Whether anon users are able to see summary cards or not. |
||
108 | */ |
||
109 | $GLOBALS['sucgEnabledForAnonUser'] = true; |
||
110 | |||
111 | /** |
||
112 | * Setting to regulate the local client caching of responses received from |
||
113 | * the API |
||
114 | * |
||
115 | * @default: 30 min, false to disable the cache |
||
116 | */ |
||
117 | $GLOBALS['sucgTooltipRequestCacheLifetime'] = 60 * 30; |
||
118 | |||
119 | /** |
||
120 | * This cache is to serve already parsed result from a cache layer without |
||
121 | * requiring to parse a template and itscontent again. It allows to serve |
||
122 | * all users that request data for the same subject from a central cache |
||
123 | * which is independent from a browser (see sucgTooltipRequestCacheLifetime). |
||
124 | * |
||
125 | * Changes to a template or alteration of a subject will trigger a new parse |
||
126 | * of content before retrievng them from cache. |
||
127 | * |
||
128 | * @default: 24 h, CACHE_NONE to disable the cache |
||
129 | */ |
||
130 | $GLOBALS['sucgBackendParserCacheType'] = CACHE_NONE; |
||
131 | |||
132 | /** |
||
133 | * @default: 1d, false to disable the cache |
||
134 | */ |
||
135 | $GLOBALS['sucgBackendParserCacheLifetime'] = 60 * 60 * 24; |
||
136 | |||
137 | // Finalize registration process |
||
138 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
139 | |||
140 | $GLOBALS['wgAPIModules']['ctparse'] = '\SUC\ApiCacheableTemplateParse'; |
||
141 | |||
142 | $options = new Options(); |
||
143 | $options->init(); |
||
144 | |||
145 | $hookRegistry = new HookRegistry( |
||
146 | $options |
||
147 | ); |
||
148 | |||
149 | $hookRegistry->register(); |
||
150 | }; |
||
151 | |||
152 | } ); |
||
153 |
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.