| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use SUC\HookRegistry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use SUC\Options; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @see https://github.com/SemanticMediaWiki/SummaryCards/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @defgroup SummaryCards Summary Cards | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  | SummaryCards::initExtension(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | $GLOBALS['wgExtensionFunctions'][] = function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	SummaryCards::onExtensionFunction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | class SummaryCards { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 * @since 1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	public static function initExtension() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		// Load DefaultSettings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		require_once __DIR__ . '/DefaultSettings.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		define( 'SUC_VERSION', '1.0.0-alpha' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		// Register the extension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		$GLOBALS['wgExtensionCredits']['others'][ ] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			'path'           => __DIR__, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			'name'           => 'Summary Cards', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			'author'         => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 				'James Hong Kong' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			'url'            => 'https://github.com/SemanticMediaWiki/SummaryCards/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			'descriptionmsg' => 'suc-desc', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			'version'        => SUC_VERSION, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			'license-name'   => 'GPL-2.0+', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		// Register message files | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$GLOBALS['wgMessagesDirs']['SummaryCards'] = __DIR__ . '/i18n'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		$GLOBALS['wgAPIModules']['ctparse'] = '\SUC\ApiCacheableTemplateParse'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$GLOBALS['wgResourceModules']['ext.summary.cards.styles'] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			'styles'  => 'res/ext.suc.styles.css', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			'localBasePath' => __DIR__ , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			'remoteExtPath' => 'SummaryCards', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			'position' => 'top', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			'targets' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 				'mobile', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 				'desktop' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$GLOBALS['wgResourceModules']['ext.summary.cards.tooltip'] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			'localBasePath' => __DIR__ , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			'remoteExtPath' => 'SummaryCards', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			'position' => 'bottom', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			'dependencies'  => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 				'onoi.qtip', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 				'onoi.md5', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 				'onoi.blobstore', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 				'onoi.util' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			'targets' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 				'mobile', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 				'desktop' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$GLOBALS['wgResourceModules']['ext.summary.cards'] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			'scripts' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 				'res/ext.suc.cards.js' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			'localBasePath' => __DIR__ , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			'remoteExtPath' => 'SummaryCards', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 			'position' => 'bottom', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			'dependencies'  => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 				'mediawiki.api', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 				'mediawiki.api.parse', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 				'ext.summary.cards.styles', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 				'ext.summary.cards.tooltip', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			'messages' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 				'suc-tooltip-title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 				'suc-tooltip-error' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 			'targets' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 				'mobile', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 				'desktop' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 			) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	 * @since 1.0 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 116 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  | 	public static function onExtensionFunction() { | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  | 		$hookRegistry = new HookRegistry( | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  | 			Options::newFromGlobals() | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  | 		$hookRegistry->register(); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	 * @since 1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	 * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	public static function getVersion() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 		return SUC_VERSION; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 135 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 136 |  |  |  | 
            
                        
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.