r88996 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88995‎ | r88996 | r88997 >
Date:20:47, 27 May 2011
Author:yaron
Status:deferred
Tags:
Comment:
Removing SD_GlobalFunctions.php, making SemanticDrilldown.php the true starting file for this extension
Modified paths:
  • /trunk/extensions/SemanticDrilldown/SemanticDrilldown.php (added) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php
@@ -1,203 +0,0 @@
2 -<?php
3 -/**
4 - * Global functions and constants for Semantic Drilldown.
5 - *
6 - * @author Yaron Koren
7 - */
8 -
9 -if ( !defined( 'MEDIAWIKI' ) ) die();
10 -
11 -define( 'SD_VERSION', '0.8.1' );
12 -
13 -// constants for special properties
14 -define( 'SD_SP_HAS_FILTER', 1 );
15 -define( 'SD_SP_COVERS_PROPERTY', 2 );
16 -define( 'SD_SP_HAS_VALUE', 3 );
17 -define( 'SD_SP_GETS_VALUES_FROM_CATEGORY', 4 );
18 -define( 'SD_SP_USES_TIME_PERIOD', 5 );
19 -define( 'SD_SP_REQUIRES_FILTER', 6 );
20 -define( 'SD_SP_HAS_LABEL', 7 );
21 -define( 'SD_SP_HAS_DRILLDOWN_TITLE', 8 );
22 -define( 'SD_SP_HAS_INPUT_TYPE', 9 );
23 -define( 'SD_SP_HAS_DISPLAY_PARAMETERS', 10 );
24 -
25 -$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'specialpage'][] = array(
26 - 'path' => __FILE__,
27 - 'name' => 'Semantic Drilldown',
28 - 'version' => SD_VERSION,
29 - 'author' => array( 'Yaron Koren', 'David Loomer' ),
30 - 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown',
31 - 'descriptionmsg' => 'semanticdrilldown-desc',
32 -);
33 -
34 -require_once( $sdgIP . '/languages/SD_Language.php' );
35 -
36 -$wgExtensionMessagesFiles['SemanticDrilldown'] = $sdgIP . '/languages/SD_Messages.php';
37 -$wgExtensionAliasesFiles['SemanticDrilldown'] = $sdgIP . '/languages/SD_Aliases.php';
38 -
39 -// register all special pages and other classes
40 -$wgSpecialPages['Filters'] = 'SDFilters';
41 -$wgAutoloadClasses['SDFilters'] = $sdgIP . '/specials/SD_Filters.php';
42 -$wgSpecialPageGroups['Filters'] = 'sd_group';
43 -$wgSpecialPages['CreateFilter'] = 'SDCreateFilter';
44 -$wgAutoloadClasses['SDCreateFilter'] = $sdgIP . '/specials/SD_CreateFilter.php';
45 -$wgSpecialPageGroups['CreateFilter'] = 'sd_group';
46 -$wgSpecialPages['BrowseData'] = 'SDBrowseData';
47 -$wgAutoloadClasses['SDBrowseData'] = $sdgIP . '/specials/SD_BrowseData.php';
48 -$wgSpecialPageGroups['BrowseData'] = 'sd_group';
49 -
50 -$wgAutoloadClasses['SDUtils'] = $sdgIP . '/includes/SD_Utils.php';
51 -$wgAutoloadClasses['SDFilter'] = $sdgIP . '/includes/SD_Filter.php';
52 -$wgAutoloadClasses['SDFilterValue'] = $sdgIP . '/includes/SD_FilterValue.php';
53 -$wgAutoloadClasses['SDAppliedFilter'] = $sdgIP . '/includes/SD_AppliedFilter.php';
54 -
55 -$wgHooks['smwInitProperties'][] = 'sdfInitProperties';
56 -$wgHooks['AdminLinks'][] = 'sdfAddToAdminLinks';
57 -$wgHooks['MagicWordwgVariableIDs'][] = 'SDUtils::addMagicWordVariableIDs';
58 -$wgHooks['LanguageGetMagic'][] = 'SDUtils::addMagicWordLanguage';
59 -$wgHooks['ParserBeforeTidy'][] = 'SDUtils::handleShowAndHide';
60 -
61 -/**********************************************/
62 -/***** namespace settings *****/
63 -/**********************************************/
64 -
65 -/**
66 - * Init the additional namespaces used by Semantic Drilldown.
67 - */
68 -function sdfInitNamespaces() {
69 - global $sdgNamespaceIndex, $wgExtraNamespaces, $wgNamespaceAliases, $wgNamespacesWithSubpages, $smwgNamespacesWithSemanticLinks;
70 - global $wgLanguageCode, $sdgContLang;
71 -
72 - if ( !isset( $sdgNamespaceIndex ) ) {
73 - $sdgNamespaceIndex = 170;
74 - }
75 -
76 - define( 'SD_NS_FILTER', $sdgNamespaceIndex );
77 - define( 'SD_NS_FILTER_TALK', $sdgNamespaceIndex + 1 );
78 -
79 - sdfInitContentLanguage( $wgLanguageCode );
80 -
81 - // Register namespace identifiers
82 - if ( !is_array( $wgExtraNamespaces ) ) { $wgExtraNamespaces = array(); }
83 - $wgExtraNamespaces = $wgExtraNamespaces + $sdgContLang->getNamespaces();
84 - $wgNamespaceAliases = $wgNamespaceAliases + $sdgContLang->getNamespaceAliases();
85 -
86 - // Support subpages only for talk pages by default
87 - $wgNamespacesWithSubpages = $wgNamespacesWithSubpages + array(
88 - SD_NS_FILTER_TALK => true
89 - );
90 -
91 - // Enable semantic links on filter pages
92 - $smwgNamespacesWithSemanticLinks = $smwgNamespacesWithSemanticLinks + array(
93 - SD_NS_FILTER => true,
94 - SD_NS_FILTER_TALK => false
95 - );
96 -}
97 -
98 -/**********************************************/
99 -/***** language settings *****/
100 -/**********************************************/
101 -
102 -/**
103 - * Initialize a global language object for content language. This
104 - * must happen early on, even before user language is known, to
105 - * determine labels for additional namespaces. In contrast, messages
106 - * can be initialized much later when they are actually needed.
107 - */
108 -function sdfInitContentLanguage( $langcode ) {
109 - global $sdgIP, $sdgContLang;
110 -
111 - if ( !empty( $sdgContLang ) ) { return; }
112 -
113 - $sdContLangClass = 'SD_Language' . str_replace( '-', '_', ucfirst( $langcode ) );
114 -
115 - if ( file_exists( $sdgIP . '/languages/' . $sdContLangClass . '.php' ) ) {
116 - include_once( $sdgIP . '/languages/' . $sdContLangClass . '.php' );
117 - }
118 -
119 - // fallback if language not supported
120 - if ( !class_exists( $sdContLangClass ) ) {
121 - include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
122 - $sdContLangClass = 'SD_LanguageEn';
123 - }
124 -
125 - $sdgContLang = new $sdContLangClass();
126 -}
127 -
128 -/**
129 - * Initialize the global language object for user language. This
130 - * must happen after the content language was initialized, since
131 - * this language is used as a fallback.
132 - */
133 -function sdfInitUserLanguage( $langcode ) {
134 - global $sdgIP, $sdgLang;
135 -
136 - if ( !empty( $sdgLang ) ) { return; }
137 -
138 - $sdLangClass = 'SD_Language' . str_replace( '-', '_', ucfirst( $langcode ) );
139 - if ( file_exists( $sdgIP . '/languages/' . $sdLangClass . '.php' ) ) {
140 - include_once( $sdgIP . '/languages/' . $sdLangClass . '.php' );
141 - }
142 -
143 - // fallback if language not supported
144 - if ( !class_exists( $sdLangClass ) ) {
145 - include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
146 - $sdLangClass = 'SD_LanguageEn';
147 - }
148 -
149 - $sdgLang = new $sdLangClass();
150 -}
151 -
152 -function sdfInitProperties() {
153 - global $sdgContLang, $wgLanguageCode;
154 - $sd_property_vals = array(
155 - SD_SP_HAS_FILTER => array( '_SD_F', '_wpg' ),
156 - SD_SP_COVERS_PROPERTY => array( '_SD_CP', '_wpp' ),
157 - SD_SP_HAS_VALUE => array( '_SD_V', '_str' ),
158 - SD_SP_GETS_VALUES_FROM_CATEGORY => array( '_SD_VC', '_wpc' ),
159 - SD_SP_USES_TIME_PERIOD => array( '_SD_TP', '_str' ),
160 - SD_SP_HAS_INPUT_TYPE => array( '_SD_IT', '_str' ),
161 - SD_SP_REQUIRES_FILTER => array( '_SD_RF', '_wpg' ),
162 - SD_SP_HAS_LABEL => array( '_SD_L', '_str' ),
163 - SD_SP_HAS_DRILLDOWN_TITLE => array( '_SD_DT', '_str' ),
164 - SD_SP_HAS_DISPLAY_PARAMETERS => array( '_SD_DP', '_str' ),
165 - );
166 - // register main property labels
167 - $sd_prop_labels = $sdgContLang->getPropertyLabels();
168 - foreach ( $sd_prop_labels as $prop_id => $prop_alias ) {
169 - $prop_vals = $sd_property_vals[$prop_id];
170 - if ( class_exists( 'SMWDIProperty' ) ) {
171 - SMWDIProperty::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
172 - } else {
173 - SMWPropertyValue::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
174 - }
175 - }
176 - // if it's not English, add the English-language aliases as well
177 - if ( $wgLanguageCode != 'en' ) {
178 - $sd_prop_aliases = $sdgContLang->getPropertyAliases();
179 - foreach ( $sd_prop_aliases as $prop_alias => $prop_id ) {
180 - $prop_vals = $sd_property_vals[$prop_id];
181 - if ( class_exists( 'SMWDIProperty' ) ) {
182 - SMWDIProperty::registerPropertyAlias( $prop_vals[0], $prop_alias );
183 - } else {
184 - SMWPropertyValue::registerPropertyAlias( $prop_vals[0], $prop_alias );
185 - }
186 - }
187 - }
188 - return true;
189 -}
190 -
191 -function sdfAddToAdminLinks( &$admin_links_tree ) {
192 - $browse_search_section = $admin_links_tree->getSection( wfMsg( 'adminlinks_browsesearch' ) );
193 - $sd_row = new ALRow( 'sd' );
194 - $sd_row->addItem( ALItem::newFromSpecialPage( 'BrowseData' ) );
195 - $sd_row->addItem( ALItem::newFromSpecialPage( 'Filters' ) );
196 - $sd_row->addItem( ALItem::newFromSpecialPage( 'CreateFilter' ) );
197 - $sd_name = wfMsg( 'specialpages-group-sd_group' );
198 - $sd_docu_label = wfMsg( 'adminlinks_documentation', $sd_name );
199 - $sd_row->addItem( AlItem::newFromExternalLink( "http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown", $sd_docu_label ) );
200 -
201 - $browse_search_section->addRow( $sd_row );
202 -
203 - return true;
204 -}
Index: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php
@@ -0,0 +1,203 @@
 2+<?php
 3+/**
 4+ * Global functions and constants for Semantic Drilldown.
 5+ *
 6+ * @author Yaron Koren
 7+ */
 8+
 9+if ( !defined( 'MEDIAWIKI' ) ) die();
 10+
 11+define( 'SD_VERSION', '0.8.1' );
 12+
 13+// constants for special properties
 14+define( 'SD_SP_HAS_FILTER', 1 );
 15+define( 'SD_SP_COVERS_PROPERTY', 2 );
 16+define( 'SD_SP_HAS_VALUE', 3 );
 17+define( 'SD_SP_GETS_VALUES_FROM_CATEGORY', 4 );
 18+define( 'SD_SP_USES_TIME_PERIOD', 5 );
 19+define( 'SD_SP_REQUIRES_FILTER', 6 );
 20+define( 'SD_SP_HAS_LABEL', 7 );
 21+define( 'SD_SP_HAS_DRILLDOWN_TITLE', 8 );
 22+define( 'SD_SP_HAS_INPUT_TYPE', 9 );
 23+define( 'SD_SP_HAS_DISPLAY_PARAMETERS', 10 );
 24+
 25+$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'specialpage'][] = array(
 26+ 'path' => __FILE__,
 27+ 'name' => 'Semantic Drilldown',
 28+ 'version' => SD_VERSION,
 29+ 'author' => array( 'Yaron Koren', 'David Loomer' ),
 30+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown',
 31+ 'descriptionmsg' => 'semanticdrilldown-desc',
 32+);
 33+
 34+require_once( $sdgIP . '/languages/SD_Language.php' );
 35+
 36+$wgExtensionMessagesFiles['SemanticDrilldown'] = $sdgIP . '/languages/SD_Messages.php';
 37+$wgExtensionAliasesFiles['SemanticDrilldown'] = $sdgIP . '/languages/SD_Aliases.php';
 38+
 39+// register all special pages and other classes
 40+$wgSpecialPages['Filters'] = 'SDFilters';
 41+$wgAutoloadClasses['SDFilters'] = $sdgIP . '/specials/SD_Filters.php';
 42+$wgSpecialPageGroups['Filters'] = 'sd_group';
 43+$wgSpecialPages['CreateFilter'] = 'SDCreateFilter';
 44+$wgAutoloadClasses['SDCreateFilter'] = $sdgIP . '/specials/SD_CreateFilter.php';
 45+$wgSpecialPageGroups['CreateFilter'] = 'sd_group';
 46+$wgSpecialPages['BrowseData'] = 'SDBrowseData';
 47+$wgAutoloadClasses['SDBrowseData'] = $sdgIP . '/specials/SD_BrowseData.php';
 48+$wgSpecialPageGroups['BrowseData'] = 'sd_group';
 49+
 50+$wgAutoloadClasses['SDUtils'] = $sdgIP . '/includes/SD_Utils.php';
 51+$wgAutoloadClasses['SDFilter'] = $sdgIP . '/includes/SD_Filter.php';
 52+$wgAutoloadClasses['SDFilterValue'] = $sdgIP . '/includes/SD_FilterValue.php';
 53+$wgAutoloadClasses['SDAppliedFilter'] = $sdgIP . '/includes/SD_AppliedFilter.php';
 54+
 55+$wgHooks['smwInitProperties'][] = 'sdfInitProperties';
 56+$wgHooks['AdminLinks'][] = 'sdfAddToAdminLinks';
 57+$wgHooks['MagicWordwgVariableIDs'][] = 'SDUtils::addMagicWordVariableIDs';
 58+$wgHooks['LanguageGetMagic'][] = 'SDUtils::addMagicWordLanguage';
 59+$wgHooks['ParserBeforeTidy'][] = 'SDUtils::handleShowAndHide';
 60+
 61+/**********************************************/
 62+/***** namespace settings *****/
 63+/**********************************************/
 64+
 65+/**
 66+ * Init the additional namespaces used by Semantic Drilldown.
 67+ */
 68+function sdfInitNamespaces() {
 69+ global $sdgNamespaceIndex, $wgExtraNamespaces, $wgNamespaceAliases, $wgNamespacesWithSubpages, $smwgNamespacesWithSemanticLinks;
 70+ global $wgLanguageCode, $sdgContLang;
 71+
 72+ if ( !isset( $sdgNamespaceIndex ) ) {
 73+ $sdgNamespaceIndex = 170;
 74+ }
 75+
 76+ define( 'SD_NS_FILTER', $sdgNamespaceIndex );
 77+ define( 'SD_NS_FILTER_TALK', $sdgNamespaceIndex + 1 );
 78+
 79+ sdfInitContentLanguage( $wgLanguageCode );
 80+
 81+ // Register namespace identifiers
 82+ if ( !is_array( $wgExtraNamespaces ) ) { $wgExtraNamespaces = array(); }
 83+ $wgExtraNamespaces = $wgExtraNamespaces + $sdgContLang->getNamespaces();
 84+ $wgNamespaceAliases = $wgNamespaceAliases + $sdgContLang->getNamespaceAliases();
 85+
 86+ // Support subpages only for talk pages by default
 87+ $wgNamespacesWithSubpages = $wgNamespacesWithSubpages + array(
 88+ SD_NS_FILTER_TALK => true
 89+ );
 90+
 91+ // Enable semantic links on filter pages
 92+ $smwgNamespacesWithSemanticLinks = $smwgNamespacesWithSemanticLinks + array(
 93+ SD_NS_FILTER => true,
 94+ SD_NS_FILTER_TALK => false
 95+ );
 96+}
 97+
 98+/**********************************************/
 99+/***** language settings *****/
 100+/**********************************************/
 101+
 102+/**
 103+ * Initialize a global language object for content language. This
 104+ * must happen early on, even before user language is known, to
 105+ * determine labels for additional namespaces. In contrast, messages
 106+ * can be initialized much later when they are actually needed.
 107+ */
 108+function sdfInitContentLanguage( $langcode ) {
 109+ global $sdgIP, $sdgContLang;
 110+
 111+ if ( !empty( $sdgContLang ) ) { return; }
 112+
 113+ $sdContLangClass = 'SD_Language' . str_replace( '-', '_', ucfirst( $langcode ) );
 114+
 115+ if ( file_exists( $sdgIP . '/languages/' . $sdContLangClass . '.php' ) ) {
 116+ include_once( $sdgIP . '/languages/' . $sdContLangClass . '.php' );
 117+ }
 118+
 119+ // fallback if language not supported
 120+ if ( !class_exists( $sdContLangClass ) ) {
 121+ include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
 122+ $sdContLangClass = 'SD_LanguageEn';
 123+ }
 124+
 125+ $sdgContLang = new $sdContLangClass();
 126+}
 127+
 128+/**
 129+ * Initialize the global language object for user language. This
 130+ * must happen after the content language was initialized, since
 131+ * this language is used as a fallback.
 132+ */
 133+function sdfInitUserLanguage( $langcode ) {
 134+ global $sdgIP, $sdgLang;
 135+
 136+ if ( !empty( $sdgLang ) ) { return; }
 137+
 138+ $sdLangClass = 'SD_Language' . str_replace( '-', '_', ucfirst( $langcode ) );
 139+ if ( file_exists( $sdgIP . '/languages/' . $sdLangClass . '.php' ) ) {
 140+ include_once( $sdgIP . '/languages/' . $sdLangClass . '.php' );
 141+ }
 142+
 143+ // fallback if language not supported
 144+ if ( !class_exists( $sdLangClass ) ) {
 145+ include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
 146+ $sdLangClass = 'SD_LanguageEn';
 147+ }
 148+
 149+ $sdgLang = new $sdLangClass();
 150+}
 151+
 152+function sdfInitProperties() {
 153+ global $sdgContLang, $wgLanguageCode;
 154+ $sd_property_vals = array(
 155+ SD_SP_HAS_FILTER => array( '_SD_F', '_wpg' ),
 156+ SD_SP_COVERS_PROPERTY => array( '_SD_CP', '_wpp' ),
 157+ SD_SP_HAS_VALUE => array( '_SD_V', '_str' ),
 158+ SD_SP_GETS_VALUES_FROM_CATEGORY => array( '_SD_VC', '_wpc' ),
 159+ SD_SP_USES_TIME_PERIOD => array( '_SD_TP', '_str' ),
 160+ SD_SP_HAS_INPUT_TYPE => array( '_SD_IT', '_str' ),
 161+ SD_SP_REQUIRES_FILTER => array( '_SD_RF', '_wpg' ),
 162+ SD_SP_HAS_LABEL => array( '_SD_L', '_str' ),
 163+ SD_SP_HAS_DRILLDOWN_TITLE => array( '_SD_DT', '_str' ),
 164+ SD_SP_HAS_DISPLAY_PARAMETERS => array( '_SD_DP', '_str' ),
 165+ );
 166+ // register main property labels
 167+ $sd_prop_labels = $sdgContLang->getPropertyLabels();
 168+ foreach ( $sd_prop_labels as $prop_id => $prop_alias ) {
 169+ $prop_vals = $sd_property_vals[$prop_id];
 170+ if ( class_exists( 'SMWDIProperty' ) ) {
 171+ SMWDIProperty::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
 172+ } else {
 173+ SMWPropertyValue::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
 174+ }
 175+ }
 176+ // if it's not English, add the English-language aliases as well
 177+ if ( $wgLanguageCode != 'en' ) {
 178+ $sd_prop_aliases = $sdgContLang->getPropertyAliases();
 179+ foreach ( $sd_prop_aliases as $prop_alias => $prop_id ) {
 180+ $prop_vals = $sd_property_vals[$prop_id];
 181+ if ( class_exists( 'SMWDIProperty' ) ) {
 182+ SMWDIProperty::registerPropertyAlias( $prop_vals[0], $prop_alias );
 183+ } else {
 184+ SMWPropertyValue::registerPropertyAlias( $prop_vals[0], $prop_alias );
 185+ }
 186+ }
 187+ }
 188+ return true;
 189+}
 190+
 191+function sdfAddToAdminLinks( &$admin_links_tree ) {
 192+ $browse_search_section = $admin_links_tree->getSection( wfMsg( 'adminlinks_browsesearch' ) );
 193+ $sd_row = new ALRow( 'sd' );
 194+ $sd_row->addItem( ALItem::newFromSpecialPage( 'BrowseData' ) );
 195+ $sd_row->addItem( ALItem::newFromSpecialPage( 'Filters' ) );
 196+ $sd_row->addItem( ALItem::newFromSpecialPage( 'CreateFilter' ) );
 197+ $sd_name = wfMsg( 'specialpages-group-sd_group' );
 198+ $sd_docu_label = wfMsg( 'adminlinks_documentation', $sd_name );
 199+ $sd_row->addItem( AlItem::newFromExternalLink( "http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown", $sd_docu_label ) );
 200+
 201+ $browse_search_section->addRow( $sd_row );
 202+
 203+ return true;
 204+}
Property changes on: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php
___________________________________________________________________
Added: svn:eol-style
1205 + native

Status & tagging log