| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @see https://github.com/SemanticMediaWiki/SemanticCompoundQueries/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @defgroup SemanticCompoundQueries SemanticCompoundQueries | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | if ( !defined( 'MEDIAWIKI' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	die( 'This file is part of the SemanticCompoundQueries extension, it is not a valid entry point.' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | if ( defined( 'SCQ_VERSION' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	// Do not initialize more than once. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	return 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | SemanticCompoundQueries::load(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class SemanticCompoundQueries { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 * @since 1.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 * @note It is expected that this function is loaded before LocalSettings.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * to ensure that settings and global functions are available by the time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * the extension is activated. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	public static function load() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 			include_once __DIR__ . '/vendor/autoload.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		 * In case extension.json is being used, the succeeding steps are | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		 * expected to be handled by the ExtensionRegistry aka extension.json | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		 * ... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		 * 	"callback": "SemanticCompoundQueries::initExtension", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		 * 	"ExtensionFunctions": [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		 * 		"SemanticCompoundQueries::onExtensionFunction" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		 * 	], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		self::initExtension(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		$GLOBALS['wgExtensionFunctions'][] = function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			self::onExtensionFunction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	 * @since 1.1 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 	public static function initExtension() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 		define( 'SCQ_VERSION', '1.1.0-alpha' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 		// Register the extension | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  | 		$GLOBALS['wgExtensionCredits']['semantic'][] = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 			'path' => __FILE__, | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  | 			'name' => 'Semantic Compound Queries', | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  | 			'version' => SCQ_VERSION, | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | 			'author' => array( | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  | 				'[https://www.semantic-mediawiki.org/ Semantic MediaWiki project]', | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 				'Yaron Koren' | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  | 			), | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 			'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries', | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  | 			'descriptionmsg' => 'semanticcompoundqueries-desc', | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  | 			'license-name' => 'GPL-2.0+' | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 		// Register message files | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 		$GLOBALS['wgMessagesDirs']['SemanticCompoundQueries'] = __DIR__ . '/i18n'; | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 		$GLOBALS['wgExtensionMessagesFiles']['SemanticCompoundQueriesMagic'] = __DIR__ . '/i18n/SemanticCompoundQueries.i18n.magic.php'; | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | 		//$GLOBALS['wgAutoloadClasses']['SCQQueryProcessor'] = __DIR__ . '/SCQ_QueryProcessor.php'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 		//$GLOBALS['wgAutoloadClasses']['SCQQueryResult'] = __DIR__ . '/SCQ_QueryResult.php'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 		//$GLOBALS['wgAutoloadClasses']['SCQCompoundQueryApi'] = __DIR__ . '/SCQ_CompoundQueryApi.php'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * @since 1.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	public static function checkRequirements() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.13', 'lt' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticCompoundQueries/">Semantic Compound Queries</a> is only compatible with MediaWiki 1.13 or above. You need to upgrade MediaWiki first.' ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		if ( !defined( 'SMW_VERSION' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticCompoundQueries/">Semantic Compound Queries</a> requires the <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> extension, please enable or install the extension first.' ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	 * @since 1.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	public static function onExtensionFunction() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		// Check requirements after LocalSetting.php has been processed, thid has | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		// be done here to ensure SMW is loaded in case | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		// wfLoadExtension( 'SemanticMediaWiki' ) is used | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		self::checkRequirements(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		// wgAPIModules | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		$GLOBALS['wgAPIModules']['compoundquery'] = 'SCQ\Api\CompoundQuery'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser  ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			$parser->setFunctionHook( 'compound_query', array( '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			// always return true, in order not to stop MW's hook processing! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 			return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	 * @since 1.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	 * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	public static function getVersion() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		return SCQ_VERSION; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 130 |  |  |  | 
            
                        
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.