| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use SESP\HookRegistry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Extension SemanticExtraSpecialProperties - Adds some extra special properties to all pages. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @see https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @defgroup SemanticExtraSpecialProperties Semantic Extra Special Properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | if ( !defined( 'MEDIAWIKI' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	die( 'This file is part of the SemanticExtraSpecialProperties extension, it is not a valid entry point.' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | if ( version_compare( $GLOBALS['wgVersion'], '1.25', '<' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	die( '<b>Error:</b> This version of Semantic Extra Special Properties requires MediaWiki 1.25 or above.' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | if ( !defined( 'SMW_VERSION' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	die( '<b>Error:</b> This version of Semantic Extra Special Properties requires <a href="http://semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> installed.<br />' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | if ( defined( 'SESP_VERSION' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	// Do not initialize more than once. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	return 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | SemanticExtraSpecialProperties::load(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | class SemanticExtraSpecialProperties { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 * @since 1.4 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * @note It is expected that this function is loaded before LocalSettings.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * to ensure that settings and global functions are available by the time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 * the extension is activated. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	public static function load() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		// Load DefaultSettings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		require_once __DIR__ . '/DefaultSettings.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			include_once __DIR__ . '/vendor/autoload.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		// In case extension.json is being used, the the succeeding steps will | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		// be handled by the ExtensionRegistry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		self::initExtension(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		// PHP 5.3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		// "Fatal error: Cannot access self:: when no class scope is active" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$GLOBALS['wgExtensionFunctions'][] = function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			SemanticExtraSpecialProperties::onExtensionFunction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * @since 1.4 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | 	public static function initExtension() { | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 		define( 'SESP_VERSION', '1.4.0-alpha' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 		// Register extension info | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  | 		$GLOBALS['wgExtensionCredits']['semantic'][] = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  | 			'path'           => __FILE__, | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  | 			'name'           => 'Semantic Extra Special Properties', | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  | 			'author'         => array( | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 				'[https://github.com/rotsee Leo Wallentin]', | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 				'[https://www.semantic-mediawiki.org/wiki/User:MWJames James Hong Kong]', | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 				'...' | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 			), | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | 			'version'        => SESP_VERSION, | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 			'url'            => 'https://www.mediawiki.org/wiki/Extension:SemanticExtraSpecialProperties', | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 			'descriptionmsg' => 'sesp-desc', | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 			'license-name'   => 'GPL-2.0+' | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 		$GLOBALS['wgMessagesDirs']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n'; | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 		$GLOBALS['wgExtensionMessagesFiles']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n/SemanticExtraSpecialProperties.i18n.php'; | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 		self::onBeforeExtensionFunction(); | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	 * Register hooks that require to be listed as soon as possible and preferable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	 * before the execution of onExtensionFunction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * @since 1.4 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	public static function onBeforeExtensionFunction() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$GLOBALS['wgHooks']['SMW::Config::BeforeCompletion'][] = '\SESP\HookRegistry::onBeforeConfigCompletion'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	 * @since 1.4 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	public static function onExtensionFunction() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		$configuration = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 			'wgDisableCounters'     => $GLOBALS['wgDisableCounters'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 			'sespUseAsFixedTables'  => $GLOBALS['sespUseAsFixedTables'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 			'sespSpecialProperties' => $GLOBALS['sespSpecialProperties'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 			'wgSESPExcludeBots'     => $GLOBALS['wgSESPExcludeBots'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 			'wgShortUrlPrefix'      => $GLOBALS['wgShortUrlPrefix'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			'sespCacheType'         => $GLOBALS['sespCacheType'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		$hookRegistry = new HookRegistry( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 			$configuration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$hookRegistry->register(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	 * @since 1.4 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	 * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	public static function getVersion() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		return SESP_VERSION; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 131 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 132 |  |  |  | 
            
                        
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.