r95126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95125‎ | r95126 | r95127 >
Date:10:05, 21 August 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
cleaned up and structured initial registration code for better readability
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -31,44 +31,56 @@
3232 * @return true
3333 */
3434 function enableSemantics( $namespace = null, $complete = false ) {
35 - global $wgVersion, $wgFooterIcons, $wgExtensionFunctions, $wgAutoloadClasses, $wgSpecialPages;
36 - global $wgSpecialPageGroups, $wgHooks, $wgExtensionMessagesFiles;
37 - global $smwgIP, $smwgNamespace, $wgJobClasses, $wgExtensionAliasesFiles, $wgServer;
38 - global $wgResourceModules, $smwgScriptPath, $wgAPIModules;
39 -
 35+ global $smwgIP, $wgFooterIcons, $wgExtensionFunctions,
 36+ $wgExtensionMessagesFiles, $wgExtensionAliasesFiles,
 37+ $smwgNamespace, $wgServer, $wgAPIModules;
 38+
 39+ $wgExtensionFunctions[] = 'smwfSetupExtension';
 40+ $wgExtensionMessagesFiles['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Messages.php';
 41+ $wgExtensionAliasesFiles['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Aliases.php';
 42+
 43+ smwfRegisterHooks();
 44+ smwfRegisterResourceLoaderModules();
 45+ smwfRegisterClasses();
 46+ smwfRegisterSpecialPages();
 47+
 48+ $wgAPIModules['smwinfo'] = 'ApiSMWInfo';
 49+
4050 $wgFooterIcons['poweredby']['semanticmediawiki'] = array(
4151 'src' => null,
4252 'url' => 'http://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki',
4353 'alt' => 'Powered by Semantic MediaWiki',
4454 );
45 -
46 - // The dot tells that the domain is not complete. It will be completed
47 - // in the Export since we do not want to create a title object here when
48 - // it is not needed in many cases.
49 - if ( $namespace === null ) {
 55+
 56+ // Initialize base namespace for URIs in data exports:
 57+ if ( $namespace === null ) { // fallback (bad because data URL will change depending on client URL)
5058 wfWarn( 'You should be providing the domain name to enableSemantics()' );
5159 $namespace = parse_url( $wgServer, PHP_URL_HOST );
5260 }
5361 if ( !$complete && ( $smwgNamespace !== '' ) ) {
 62+ // The dot tells that the domain is not complete. It will be completed
 63+ // in the Export since we do not want to create a title object here when
 64+ // it is not needed in many cases.
5465 $smwgNamespace = '.' . $namespace;
5566 } else {
5667 $smwgNamespace = $namespace;
5768 }
5869
59 - $wgExtensionFunctions[] = 'smwfSetupExtension';
60 - // FIXME: Can be removed when new style magic words are used (introduced in r52503)
61 - $wgHooks['PageSchemasGetObject'][] = 'smwfCreatePageSchemasObject' ; //Hook for returning PageSchema(extension) object from a given xml
62 - $wgHooks['PageSchemasGeneratePages'][] = 'smwfGeneratePages' ; //Hook for creating Pages
63 - $wgHooks['getHtmlTextForFieldInputs'][] = 'smwfgetHtmlTextForPS' ; //Hook for retuning html text to PS schema
64 - $wgHooks['getFilledHtmlTextForFieldInputs'][] = 'smwfgetFilledHtmlTextForPS' ; //Hook for retuning html text to PS schema
65 - $wgHooks['getXmlTextForFieldInputs'][] = 'smwfgetXMLTextForPS' ; //Hook for retuning html text to PS schema
66 - $wgHooks['PSParseFieldElements'][] = 'smwfParseFieldElements' ; //Hook for creating Pages
67 - $wgHooks['PageSchemasGetPageList'][] = 'smwfGetPageList' ; //Hook for creating Pages
68 - $wgHooks['LanguageGetMagic'][] = 'smwfAddMagicWords'; // setup names for parser functions (needed here)
69 - $wgExtensionMessagesFiles['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Messages.php'; // register messages (requires MW=>1.11)
 70+ return true;
 71+}
7072
71 - $wgHooks['ParserTestTables'][] = 'smwfOnParserTestTables';
72 - $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks';
 73+/**
 74+ * Register all SMW hooks with MediaWiki.
 75+ */
 76+function smwfRegisterHooks() {
 77+ global $wgHooks, $wgVersion;
 78+
 79+ // FIXME: The following can be removed when new style magic words are used (introduced in r52503)
 80+ $wgHooks['LanguageGetMagic'][] = 'smwfAddMagicWords'; // setup names for parser functions (needed here)
 81+ $wgHooks['ParserTestTables'][] = 'smwfOnParserTestTables';
 82+ $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks';
 83+ $wgHooks['ParserFirstCallInit'][] = 'SMWSMWDoc::staticInit';
 84+ $wgHooks['LanguageGetMagic'][] = 'SMWSMWDoc::staticMagic';
7385
7486 if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) {
7587 // For MediaWiki 1.17 alpha and later.
@@ -78,7 +90,23 @@
7991 $wgHooks['SpecialVersionExtensionTypes'][] = 'smwfOldAddSemanticExtensionType';
8092 }
8193
82 - // Register client-side modules
 94+ /* Hooks related to Pageschemas extension. TODO: Should be moved to separate file. */
 95+ $wgHooks['PageSchemasGetObject'][] = 'smwfCreatePageSchemasObject' ; // Hook for returning PageSchema(extension) object from a given xml
 96+ $wgHooks['PageSchemasGeneratePages'][] = 'smwfGeneratePages' ; // Hook for creating Pages
 97+ $wgHooks['getHtmlTextForFieldInputs'][] = 'smwfgetHtmlTextForPS' ; // Hook for retuning html text to PS schema
 98+ $wgHooks['getFilledHtmlTextForFieldInputs'][] = 'smwfgetFilledHtmlTextForPS' ; //Hook for retuning html text to PS schema
 99+ $wgHooks['getXmlTextForFieldInputs'][] = 'smwfgetXMLTextForPS' ; // Hook for retuning html text to PS schema
 100+ $wgHooks['PSParseFieldElements'][] = 'smwfParseFieldElements' ; // Hook for creating Pages
 101+ $wgHooks['PageSchemasGetPageList'][] = 'smwfGetPageList' ; //Hook for creating Pages
 102+ /* End: Hooks related to Pageschemas extension */
 103+}
 104+
 105+/**
 106+ * Register all SMW modules with the MediaWiki Resource Loader.
 107+ */
 108+function smwfRegisterResourceLoaderModules() {
 109+ global $wgResourceModules, $smwgIP, $smwgScriptPath;
 110+
83111 $moduleTemplate = array(
84112 'localBasePath' => $smwgIP . '/skins',
85113 'remoteBasePath' => $smwgScriptPath . '/skins',
@@ -94,11 +122,14 @@
95123 'ext.smw.style'
96124 )
97125 );
 126+}
98127
99 - // Register special pages aliases file
100 - $wgExtensionAliasesFiles['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Aliases.php';
 128+/**
 129+ * Register all SMW classes with the MediaWiki autoloader.
 130+ */
 131+function smwfRegisterClasses() {
 132+ global $smwgIP, $wgAutoloadClasses, $wgJobClasses;
101133
102 - // Set up autoloading; essentially all classes should be autoloaded!
103134 $incDir = $smwgIP . 'includes/';
104135 $wgAutoloadClasses['SMWCompatibilityHelpers'] = $incDir . 'SMW_CompatibilityHelpers.php';
105136 $wgAutoloadClasses['SMWDataValueFactory'] = $incDir . 'SMW_DataValueFactory.php';
@@ -185,14 +216,14 @@
186217
187218 // Parser hooks
188219 $phDir = $smwgIP . 'includes/parserhooks/';
189 - $wgAutoloadClasses['SMWAsk'] = $phDir . 'SMW_Ask.php';
190 - $wgAutoloadClasses['SMWShow'] = $phDir . 'SMW_Show.php';
191 - $wgAutoloadClasses['SMWInfo'] = $phDir . 'SMW_Info.php';
192 - $wgAutoloadClasses['SMWConcept'] = $phDir . 'SMW_Concept.php';
193 - $wgAutoloadClasses['SMWSet'] = $phDir . 'SMW_Set.php';
 220+ $wgAutoloadClasses['SMWAsk'] = $phDir . 'SMW_Ask.php';
 221+ $wgAutoloadClasses['SMWShow'] = $phDir . 'SMW_Show.php';
 222+ $wgAutoloadClasses['SMWInfo'] = $phDir . 'SMW_Info.php';
 223+ $wgAutoloadClasses['SMWConcept'] = $phDir . 'SMW_Concept.php';
 224+ $wgAutoloadClasses['SMWSet'] = $phDir . 'SMW_Set.php';
194225 $wgAutoloadClasses['SMWSetRecurringEvent'] = $phDir . 'SMW_SetRecurringEvent.php';
195 - $wgAutoloadClasses['SMWDeclare'] = $phDir . 'SMW_Declare.php';
196 - $wgAutoloadClasses['SMWSMWDoc'] = $phDir . 'SMW_SMWDoc.php';
 226+ $wgAutoloadClasses['SMWDeclare'] = $phDir . 'SMW_Declare.php';
 227+ $wgAutoloadClasses['SMWSMWDoc'] = $phDir . 'SMW_SMWDoc.php';
197228
198229 // Stores & queries
199230 $wgAutoloadClasses['SMWQueryProcessor'] = $smwgIP . 'includes/SMW_QueryProcessor.php';
@@ -226,85 +257,88 @@
227258 $wgAutoloadClasses['SMWSQLHelpers'] = $stoDir . 'SMW_SQLHelpers.php';
228259 $wgAutoloadClasses['SMWSparqlStore'] = $stoDir . 'SMW_SparqlStore.php';
229260 $wgAutoloadClasses['SMWSparqlStoreQueryEngine'] = $stoDir . 'SMW_SparqlStoreQueryEngine.php';
 261+ $wgAutoloadClasses['SMWTestStore'] = $stoDir . 'SMW_TestStore.php';
230262
231263 // To ensure SMW remains compatible with pre 1.16.
232264 if ( !class_exists( 'Html' ) ) {
233265 $wgAutoloadClasses['Html'] = $smwgIP . 'compat/Html.php';
234266 }
235267
236 - $wgHooks['ParserFirstCallInit'][] = 'SMWSMWDoc::staticInit';
237 - $wgHooks['LanguageGetMagic'][] = 'SMWSMWDoc::staticMagic';
238 -
239 - $wgAutoloadClasses['SMWTestStore'] = $smwgIP . 'includes/storage/SMW_TestStore.php';
 268+ // Special pages and closely related helper classes
 269+ $specDir = $smwgIP . 'specials/';
 270+ $wgAutoloadClasses['SMWQueryPage'] = $specDir . 'QueryPages/SMW_QueryPage.php';
 271+ $wgAutoloadClasses['SMWAskPage'] = $specDir . 'AskSpecial/SMW_SpecialAsk.php';
 272+ $wgAutoloadClasses['SMWQueryUIHelper'] = $specDir . 'AskSpecial/SMW_QueryUIHelper.php';
 273+ $wgAutoloadClasses['SMWQueryUI'] = $specDir . 'AskSpecial/SMW_QueryUI.php';
 274+ $wgAutoloadClasses['SMWQueryCreatorPage'] = $specDir . 'AskSpecial/SMW_SpecialQueryCreator.php';
 275+ $wgAutoloadClasses['SMWSpecialBrowse'] = $specDir . 'SearchTriple/SMW_SpecialBrowse.php';
 276+ $wgAutoloadClasses['SMWPageProperty'] = $specDir . 'SearchTriple/SMW_SpecialPageProperty.php';
 277+ $wgAutoloadClasses['SMWSearchByProperty'] = $specDir . 'SearchTriple/SMW_SpecialSearchByProperty.php';
 278+ $wgAutoloadClasses['SMWURIResolver'] = $specDir . 'URIResolver/SMW_SpecialURIResolver.php';
 279+ $wgAutoloadClasses['SMWAdmin'] = $specDir . 'SMWAdmin/SMW_SpecialSMWAdmin.php';
 280+ $wgAutoloadClasses['SMWSpecialSemanticStatistics'] = $specDir . 'Statistics/SMW_SpecialStatistics.php';
 281+ $wgAutoloadClasses['SMWSpecialOWLExport'] = $specDir . 'Export/SMW_SpecialOWLExport.php';
 282+ $wgAutoloadClasses['SMWSpecialProperties'] = $specDir . 'QueryPages/SMW_SpecialProperties.php';
 283+ $wgAutoloadClasses['SMWSpecialTypes'] = $specDir . 'QueryPages/SMW_SpecialTypes.php';
 284+ $wgAutoloadClasses['SMWSpecialUnusedProperties'] = $specDir . 'QueryPages/SMW_SpecialUnusedProperties.php';
 285+ $wgAutoloadClasses['SMWSpecialWantedProperties'] = $specDir . 'QueryPages/SMW_SpecialWantedProperties.php';
240286
241 - ///// Register specials, do that early on in case some other extension calls "addPage" /////
242 - $wgAutoloadClasses['SMWQueryPage'] = $smwgIP . 'specials/QueryPages/SMW_QueryPage.php';
243 - $wgAutoloadClasses['SMWAskPage'] = $smwgIP . 'specials/AskSpecial/SMW_SpecialAsk.php';
 287+ // Jobs
 288+ $wgJobClasses['SMWUpdateJob'] = 'SMWUpdateJob';
 289+ $wgAutoloadClasses['SMWUpdateJob'] = $smwgIP . 'includes/jobs/SMW_UpdateJob.php';
 290+ $wgJobClasses['SMWRefreshJob'] = 'SMWRefreshJob';
 291+ $wgAutoloadClasses['SMWRefreshJob'] = $smwgIP . 'includes/jobs/SMW_RefreshJob.php';
 292+
 293+ // API modules
 294+ //$wgAutoloadClasses['ApiSMWQuery'] = $smwgIP . 'includes/api/ApiSMWQuery.php';
 295+ //$wgAPIModules['smwquery'] = 'ApiSMWQuery';
 296+ $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php';
 297+}
 298+
 299+/**
 300+ * Register all SMW special pages with MediaWiki.
 301+ */
 302+function smwfRegisterSpecialPages() {
 303+ global $wgSpecialPages, $wgSpecialPageGroups;
 304+
244305 $wgSpecialPages['Ask'] = 'SMWAskPage';
245306 $wgSpecialPageGroups['Ask'] = 'smw_group';
246307
247 - /* Query Creator disabled for release SMW 1.6
248 - $wgAutoloadClasses['SMWQueryCreatorPage'] = $smwgIP . 'specials/AskSpecial/SMW_SpecialQueryCreator.php';
249 - $wgSpecialPages['QueryCreator'] = 'SMWQueryCreatorPage';
250 - $wgSpecialPageGroups['QueryCreator'] = 'smw_group';
251 - */
252 - $wgAutoloadClasses['SMWSpecialBrowse'] = $smwgIP . 'specials/SearchTriple/SMW_SpecialBrowse.php';
 308+ /* Query Creator currently still disabled by default: */
 309+// $wgSpecialPages['QueryCreator'] = 'SMWQueryCreatorPage';
 310+// $wgSpecialPageGroups['QueryCreator'] = 'smw_group';
 311+
253312 $wgSpecialPages['Browse'] = 'SMWSpecialBrowse';
254313 $wgSpecialPageGroups['Browse'] = 'smw_group';
255314
256 - $wgAutoloadClasses['SMWPageProperty'] = $smwgIP . 'specials/SearchTriple/SMW_SpecialPageProperty.php';
257315 $wgSpecialPages['PageProperty'] = 'SMWPageProperty';
258316 $wgSpecialPageGroups['PageProperty'] = 'smw_group';
259317
260 - $wgAutoloadClasses['SMWSearchByProperty'] = $smwgIP . 'specials/SearchTriple/SMW_SpecialSearchByProperty.php';
261318 $wgSpecialPages['SearchByProperty'] = 'SMWSearchByProperty';
262319 $wgSpecialPageGroups['SearchByProperty'] = 'smw_group';
263320
264 - $wgAutoloadClasses['SMWURIResolver'] = $smwgIP . 'specials/URIResolver/SMW_SpecialURIResolver.php';
265321 $wgSpecialPages['URIResolver'] = 'SMWURIResolver';
266322
267 - $wgAutoloadClasses['SMWAdmin'] = $smwgIP . 'specials/SMWAdmin/SMW_SpecialSMWAdmin.php';
268323 $wgSpecialPages['SMWAdmin'] = 'SMWAdmin';
269324 $wgSpecialPageGroups['SMWAdmin'] = 'smw_group';
270325
271 - $wgAutoloadClasses['SMWSpecialSemanticStatistics'] = $smwgIP . 'specials/Statistics/SMW_SpecialStatistics.php';
272326 $wgSpecialPages['SemanticStatistics'] = 'SMWSpecialSemanticStatistics';
273327 $wgSpecialPageGroups['SemanticStatistics'] = 'wiki'; // Similar to Special:Statistics
274328
275 - $wgAutoloadClasses['SMWSpecialOWLExport'] = $smwgIP . 'specials/Export/SMW_SpecialOWLExport.php';
276329 $wgSpecialPages['ExportRDF'] = 'SMWSpecialOWLExport';
277330 $wgSpecialPageGroups['ExportRDF'] = 'smw_group';
278331
279 - $wgAutoloadClasses['SMWSpecialProperties'] = $smwgIP . 'specials/QueryPages/SMW_SpecialProperties.php';
280332 $wgSpecialPages['Properties'] = 'SMWSpecialProperties';
281333 $wgSpecialPageGroups['Properties'] = 'pages';
282334
283 - $wgAutoloadClasses['SMWSpecialTypes'] = $smwgIP . 'specials/QueryPages/SMW_SpecialTypes.php';
284335 $wgSpecialPages['Types'] = 'SMWSpecialTypes';
285336 $wgSpecialPageGroups['Types'] = 'pages';
286337
287 - $wgAutoloadClasses['SMWSpecialUnusedProperties'] = $smwgIP . 'specials/QueryPages/SMW_SpecialUnusedProperties.php';
288338 $wgSpecialPages['UnusedProperties'] = 'SMWSpecialUnusedProperties';
289339 $wgSpecialPageGroups['UnusedProperties'] = 'maintenance';
290340
291 - $wgAutoloadClasses['SMWSpecialWantedProperties'] = $smwgIP . 'specials/QueryPages/SMW_SpecialWantedProperties.php';
292341 $wgSpecialPages['WantedProperties'] = 'SMWSpecialWantedProperties';
293342 $wgSpecialPageGroups['WantedProperties'] = 'maintenance';
294 -
295 - // Register Jobs
296 - $wgJobClasses['SMWUpdateJob'] = 'SMWUpdateJob';
297 - $wgAutoloadClasses['SMWUpdateJob'] = $smwgIP . 'includes/jobs/SMW_UpdateJob.php';
298 -
299 - $wgJobClasses['SMWRefreshJob'] = 'SMWRefreshJob';
300 - $wgAutoloadClasses['SMWRefreshJob'] = $smwgIP . 'includes/jobs/SMW_RefreshJob.php';
301 -
302 - //$wgAutoloadClasses['ApiSMWQuery'] = $smwgIP . 'includes/api/ApiSMWQuery.php';
303 - //$wgAPIModules['smwquery'] = 'ApiSMWQuery';
304 -
305 - $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php';
306 - $wgAPIModules['smwinfo'] = 'ApiSMWInfo';
307 -
308 - return true;
309343 }
310344
311345 /**
@@ -424,11 +458,11 @@
425459
426460
427461 /**
428 - * Register special classes for displaying semantic content on Property/Type
429 - * pages.
 462+ * Register special classes for displaying semantic content on Property and
 463+ * Concept pages.
430464 *
431 - * @param $title: Title
432 - * @param $article: Article or null
 465+ * @param $title Title
 466+ * @param $article Article or null
433467 *
434468 * @return true
435469 */
@@ -528,27 +562,28 @@
529563
530564 function smwfParseFieldElements( $field_xml, &$text_object ) {
531565 foreach ( $field_xml->children() as $tag => $child ) {
532 - if ( $tag == "Property" ) {
533 - $text = "";
534 - $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticMediaWiki", (string)$tag );
535 - $propName = $child->attributes()->name;
536 - //this means object has already been initialized by some other extension.
537 - $text .= PageSchemas::tableMessageRowHTML( "paramAttrMsg", "name", (string)$propName );
538 - foreach ( $child->children() as $prop => $value ) {
539 - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop, (string)$value );
540 - }
541 - $text_object['smw']=$text;
542 - }
 566+ if ( $tag == "Property" ) {
 567+ $text = "";
 568+ $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticMediaWiki", (string)$tag );
 569+ $propName = $child->attributes()->name;
 570+ //this means object has already been initialized by some other extension.
 571+ $text .= PageSchemas::tableMessageRowHTML( "paramAttrMsg", "name", (string)$propName );
 572+ foreach ( $child->children() as $prop => $value ) {
 573+ $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop, (string)$value );
 574+ }
 575+ $text_object['smw']=$text;
543576 }
544 - return true;
 577+ }
 578+ return true;
545579 }
 580+
546581 function smwfGetPageList( $psSchemaObj , &$genPageList ) {
547582 $template_all = $psSchemaObj->getTemplates();
548583 foreach ( $template_all as $template ) {
549584 $field_all = $template->getFields();
550585 $field_count = 0; //counts the number of fields
551586 foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
552 - $field_count++;
 587+ $field_count++;
553588 $smw_array = $field->getObject('Property'); //this returns an array with property values filled
554589 $prop_array = $smw_array['smw'];
555590 if($prop_array != null){
@@ -559,6 +594,7 @@
560595 }
561596 return true;
562597 }
 598+
563599 function smwfgetXMLTextForPS( $wgRequest, &$text_extensions ){
564600
565601 $Xmltext = "";

Sign-offs

UserFlagDate
Nikerabbitinspected16:30, 21 August 2011