Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.inc |
— | — | @@ -1,355 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * A class for static helper functions for Semantic Drilldown |
5 | | - * |
6 | | - * @author Yaron Koren |
7 | | - */ |
8 | | - |
9 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
10 | | - |
11 | | -class SDUtils { |
12 | | - |
13 | | - /** |
14 | | - * Gets a list of the names of all categories in the wiki that aren't |
15 | | - * children of some other category - this list additionally includes, |
16 | | - * and excludes, categories that are manually set with |
17 | | - * 'SHOWINDRILLDOWN' and 'HIDEFROMDRILLDOWN', respectively. |
18 | | - */ |
19 | | - static function getTopLevelCategories() { |
20 | | - $categories = array(); |
21 | | - $dbr = wfGetDB( DB_SLAVE ); |
22 | | - extract( $dbr->tableNames( 'page', 'categorylinks', 'page_props' ) ); |
23 | | - $cat_ns = NS_CATEGORY; |
24 | | - $sql = "SELECT page_title FROM $page p LEFT OUTER JOIN $categorylinks cl ON p.page_id = cl.cl_from WHERE p.page_namespace = $cat_ns AND cl.cl_to IS NULL"; |
25 | | - $res = $dbr->query( $sql ); |
26 | | - if ( $dbr->numRows( $res ) > 0 ) { |
27 | | - while ( $row = $dbr->fetchRow( $res ) ) { |
28 | | - $categories[] = str_replace( '_', ' ', $row[0] ); |
29 | | - } |
30 | | - } |
31 | | - $dbr->freeResult( $res ); |
32 | | - |
33 | | - // get 'hide' and 'show' categories |
34 | | - $hidden_cats = $shown_cats = array(); |
35 | | - $sql2 = "SELECT p.page_title, pp.pp_propname FROM $page p JOIN $page_props pp ON p.page_id = pp.pp_page WHERE p.page_namespace = $cat_ns AND (pp.pp_propname = 'hidefromdrilldown' OR pp.pp_propname = 'showindrilldown') AND pp.pp_value = 'y'"; |
36 | | - $res2 = $dbr->query( $sql2 ); |
37 | | - if ( $dbr->numRows( $res2 ) > 0 ) { |
38 | | - while ( $row = $dbr->fetchRow( $res2 ) ) { |
39 | | - if ( $row[1] == 'hidefromdrilldown' ) |
40 | | - $hidden_cats[] = str_replace( '_', ' ', $row[0] ); |
41 | | - else |
42 | | - $shown_cats[] = str_replace( '_', ' ', $row[0] ); |
43 | | - } |
44 | | - } |
45 | | - $dbr->freeResult( $res2 ); |
46 | | - $categories = array_merge( $categories, $shown_cats ); |
47 | | - foreach ( $hidden_cats as $hidden_cat ) { |
48 | | - foreach ( $categories as $i => $cat ) { |
49 | | - if ( $cat == $hidden_cat ) { |
50 | | - unset( $categories[$i] ); |
51 | | - } |
52 | | - } |
53 | | - } |
54 | | - sort( $categories ); |
55 | | - return $categories; |
56 | | - } |
57 | | - |
58 | | - /** |
59 | | - * Gets a list of the names of all properties in the wiki |
60 | | - */ |
61 | | - static function getSemanticProperties() { |
62 | | - global $smwgContLang; |
63 | | - $smw_namespace_labels = $smwgContLang->getNamespaces(); |
64 | | - $all_properties = array(); |
65 | | - |
66 | | - // $options = new SMWRequestOptions(); |
67 | | - // $options->limit = 10000; |
68 | | - // $used_properties = smwfGetStore()->getPropertiesSpecial($options); |
69 | | - $used_properties = smwfGetStore()->getPropertiesSpecial(); |
70 | | - foreach ( $used_properties as $property ) { |
71 | | - $all_properties[] = $property[0]->getWikiValue(); |
72 | | - } |
73 | | - $unused_properties = smwfGetStore()->getUnusedPropertiesSpecial( $options ); |
74 | | - foreach ( $unused_properties as $property ) { |
75 | | - $all_properties[] = $property->getWikiValue(); |
76 | | - } |
77 | | - // remove the special properties of Semantic Drilldown from this list... |
78 | | - global $sdgContLang; |
79 | | - $sd_props = $sdgContLang->getPropertyLabels(); |
80 | | - $sd_prop_aliases = $sdgContLang->getPropertyAliases(); |
81 | | - foreach ( $all_properties as $i => $prop_name ) { |
82 | | - foreach ( $sd_props as $prop => $label ) { |
83 | | - if ( $prop_name == $label ) { |
84 | | - unset( $all_properties[$i] ); |
85 | | - } |
86 | | - } |
87 | | - foreach ( $sd_prop_aliases as $alias => $cur_prop ) { |
88 | | - if ( $prop_name == $alias ) { |
89 | | - unset( $all_properties[$i] ); |
90 | | - } |
91 | | - } |
92 | | - } |
93 | | - sort( $all_properties ); |
94 | | - return $all_properties; |
95 | | - } |
96 | | - |
97 | | - /** |
98 | | - * Gets the names of all the filter pages, i.e. pages in the Filter |
99 | | - * namespace |
100 | | - */ |
101 | | - static function getFilters() { |
102 | | - $dbr = wfGetDB( DB_SLAVE ); |
103 | | - $res = $dbr->select( 'page', 'page_title', array( 'page_namespace' => SD_NS_FILTER ) ); |
104 | | - $filters = array(); |
105 | | - while ( $row = $dbr->fetchRow( $res ) ) { |
106 | | - $filters[] = $row[0]; |
107 | | - } |
108 | | - $dbr->freeResult( $res ); |
109 | | - return $filters; |
110 | | - } |
111 | | - |
112 | | - /** |
113 | | - * Generic static function - gets all the values that a specific page |
114 | | - * points to with a specific property |
115 | | - * ($special_prop and $prop represent the same value, depending on |
116 | | - * whether we're using SMW 1.4 or an earlier version) |
117 | | - */ |
118 | | - static function getValuesForProperty( $subject, $subject_namespace, $special_prop ) { |
119 | | - $store = smwfGetStore(); |
120 | | - $subject_title = Title::newFromText( $subject, $subject_namespace ); |
121 | | - $property = SMWPropertyValue::makeProperty( $special_prop ); |
122 | | - $res = $store->getPropertyValues( $subject_title, $property ); |
123 | | - $values = array(); |
124 | | - foreach ( $res as $prop_val ) { |
125 | | - // depends on version of SMW |
126 | | - if ( method_exists( $prop_val, 'getValueKey' ) ) { |
127 | | - $actual_val = $prop_val->getValueKey(); |
128 | | - } else { |
129 | | - $actual_val = $prop_val->getXSDValue(); |
130 | | - } |
131 | | - $values[] = html_entity_decode( str_replace( '_', ' ', $actual_val ) ); |
132 | | - } |
133 | | - return $values; |
134 | | - } |
135 | | - |
136 | | - /** |
137 | | - * Gets all the filters specified for a category. |
138 | | - */ |
139 | | - static function loadFiltersForCategory( $category ) { |
140 | | - $filters = array(); |
141 | | - $filter_names = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_F' ); |
142 | | - foreach ( $filter_names as $filter_name ) { |
143 | | - $filters[] = SDFilter::load( $filter_name ); |
144 | | - } |
145 | | - return $filters; |
146 | | - } |
147 | | - |
148 | | - /** |
149 | | - * Gets all the display parameters defined for a category |
150 | | - */ |
151 | | - static function getDisplayParamsForCategory( $category ) { |
152 | | - $all_display_params = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_DP' ); |
153 | | - |
154 | | - $return_display_params = array(); |
155 | | - foreach ( $all_display_params as $display_params ) { |
156 | | - $return_display_params[] = explode( ';', $display_params ); |
157 | | - } |
158 | | - return $return_display_params; |
159 | | - } |
160 | | - |
161 | | - static function getCategoryChildren( $category_name, $get_categories, $levels ) { |
162 | | - if ( $levels == 0 ) { |
163 | | - return array(); |
164 | | - } |
165 | | - $pages = array(); |
166 | | - $subcategories = array(); |
167 | | - $dbr = wfGetDB( DB_SLAVE ); |
168 | | - extract( $dbr->tableNames( 'page', 'categorylinks' ) ); |
169 | | - $cat_ns = NS_CATEGORY; |
170 | | - $query_category = str_replace( ' ', '_', $category_name ); |
171 | | - $query_category = str_replace( "'", "\'", $query_category ); |
172 | | - $sql = "SELECT p.page_title, p.page_namespace FROM $categorylinks cl |
173 | | - JOIN $page p on cl.cl_from = p.page_id |
174 | | - WHERE cl.cl_to = '$query_category'\n"; |
175 | | - if ( $get_categories ) |
176 | | - $sql .= "AND p.page_namespace = $cat_ns\n"; |
177 | | - $sql .= "ORDER BY cl.cl_sortkey"; |
178 | | - $res = $dbr->query( $sql ); |
179 | | - while ( $row = $dbr->fetchRow( $res ) ) { |
180 | | - if ( $get_categories ) { |
181 | | - $subcategories[] = $row[0]; |
182 | | - $pages[] = $row[0]; |
183 | | - } else { |
184 | | - if ( $row[1] == $cat_ns ) |
185 | | - $subcategories[] = $row[0]; |
186 | | - else |
187 | | - $pages[] = $row[0]; |
188 | | - } |
189 | | - } |
190 | | - $dbr->freeResult( $res ); |
191 | | - foreach ( $subcategories as $subcategory ) { |
192 | | - $pages = array_merge( $pages, SDUtils::getCategoryChildren( $subcategory, $get_categories, $levels - 1 ) ); |
193 | | - } |
194 | | - return $pages; |
195 | | - } |
196 | | - |
197 | | - static function monthToString( $month ) { |
198 | | - if ( $month == 1 ) { |
199 | | - return wfMsg( 'january' ); |
200 | | - } elseif ( $month == 2 ) { |
201 | | - return wfMsg( 'february' ); |
202 | | - } elseif ( $month == 3 ) { |
203 | | - return wfMsg( 'march' ); |
204 | | - } elseif ( $month == 4 ) { |
205 | | - return wfMsg( 'april' ); |
206 | | - } elseif ( $month == 5 ) { |
207 | | - return wfMsg( 'may' ); |
208 | | - } elseif ( $month == 6 ) { |
209 | | - return wfMsg( 'june' ); |
210 | | - } elseif ( $month == 7 ) { |
211 | | - return wfMsg( 'july' ); |
212 | | - } elseif ( $month == 8 ) { |
213 | | - return wfMsg( 'august' ); |
214 | | - } elseif ( $month == 9 ) { |
215 | | - return wfMsg( 'september' ); |
216 | | - } elseif ( $month == 10 ) { |
217 | | - return wfMsg( 'october' ); |
218 | | - } elseif ( $month == 11 ) { |
219 | | - return wfMsg( 'november' ); |
220 | | - } else { // if ($month == 12) { |
221 | | - return wfMsg( 'december' ); |
222 | | - } |
223 | | - } |
224 | | - |
225 | | - static function stringToMonth( $str ) { |
226 | | - if ( $str == wfMsg( 'january' ) ) { |
227 | | - return 1; |
228 | | - } elseif ( $str == wfMsg( 'february' ) ) { |
229 | | - return 2; |
230 | | - } elseif ( $str == wfMsg( 'march' ) ) { |
231 | | - return 3; |
232 | | - } elseif ( $str == wfMsg( 'april' ) ) { |
233 | | - return 4; |
234 | | - } elseif ( $str == wfMsg( 'may' ) ) { |
235 | | - return 5; |
236 | | - } elseif ( $str == wfMsg( 'june' ) ) { |
237 | | - return 6; |
238 | | - } elseif ( $str == wfMsg( 'july' ) ) { |
239 | | - return 7; |
240 | | - } elseif ( $str == wfMsg( 'august' ) ) { |
241 | | - return 8; |
242 | | - } elseif ( $str == wfMsg( 'september' ) ) { |
243 | | - return 9; |
244 | | - } elseif ( $str == wfMsg( 'october' ) ) { |
245 | | - return 10; |
246 | | - } elseif ( $str == wfMsg( 'november' ) ) { |
247 | | - return 11; |
248 | | - } else { // if ($strmonth == wfMsg('december')) { |
249 | | - return 12; |
250 | | - } |
251 | | - } |
252 | | - |
253 | | - static function booleanToString( $bool_value ) { |
254 | | - wfLoadExtensionMessages( 'SemanticMediaWiki' ); |
255 | | - $words_field_name = ( $bool_value == true ) ? 'smw_true_words' : 'smw_false_words'; |
256 | | - $words_array = explode( ',', wfMsgForContent( $words_field_name ) ); |
257 | | - // go with the value in the array that tends to be "yes" or |
258 | | - // "no", which is the 3rd |
259 | | - $index_of_word = 2; |
260 | | - // capitalize first letter of word |
261 | | - if ( count( $words_array ) > $index_of_word ) { |
262 | | - $string_value = ucwords( $words_array[$index_of_word] ); |
263 | | - } elseif ( count( $words_array ) == 0 ) { |
264 | | - $string_value = $bool_value; // a safe value if no words are found |
265 | | - } else { |
266 | | - $string_value = ucwords( $words_array[0] ); |
267 | | - } |
268 | | - return $string_value; |
269 | | - } |
270 | | - |
271 | | - /** |
272 | | - * Prints the mini-form contained at the bottom of various pages, that |
273 | | - * allows pages to spoof a normal edit page, that can preview, save, |
274 | | - * etc. |
275 | | - */ |
276 | | - static function printRedirectForm( $title, $page_contents, $edit_summary, $is_save, $is_preview, $is_diff, $is_minor_edit, $watch_this ) { |
277 | | - $article = new Article( $title ); |
278 | | - $new_url = $title->getLocalURL( 'action=submit' ); |
279 | | - $starttime = wfTimestampNow(); |
280 | | - $edittime = $article->getTimestamp(); |
281 | | - global $wgUser; |
282 | | - if ( $wgUser->isLoggedIn() ) |
283 | | - $token = htmlspecialchars( $wgUser->editToken() ); |
284 | | - else |
285 | | - $token = EDIT_TOKEN_SUFFIX; |
286 | | - |
287 | | - if ( $is_save ) |
288 | | - $action = "wpSave"; |
289 | | - elseif ( $is_preview ) |
290 | | - $action = "wpPreview"; |
291 | | - else // $is_diff |
292 | | - $action = "wpDiff"; |
293 | | - |
294 | | - $text = <<<END |
295 | | - <form id="editform" name="editform" method="post" action="$new_url"> |
296 | | - <input type="hidden" name="wpTextbox1" id="wpTextbox1" value="$page_contents" /> |
297 | | - <input type="hidden" name="wpSummary" value="$edit_summary" /> |
298 | | - <input type="hidden" name="wpStarttime" value="$starttime" /> |
299 | | - <input type="hidden" name="wpEdittime" value="$edittime" /> |
300 | | - <input type="hidden" name="wpEditToken" value="$token" /> |
301 | | - <input type="hidden" name="$action" /> |
302 | | - |
303 | | -END; |
304 | | - if ( $is_minor_edit ) |
305 | | - $text .= ' <input type="hidden" name="wpMinoredit">' . "\n"; |
306 | | - if ( $watch_this ) |
307 | | - $text .= ' <input type="hidden" name="wpWatchthis">' . "\n"; |
308 | | - $text .= <<<END |
309 | | - </form> |
310 | | - <script type="text/javascript"> |
311 | | - document.editform.submit(); |
312 | | - </script> |
313 | | - |
314 | | -END; |
315 | | - return $text; |
316 | | - } |
317 | | - |
318 | | - /** |
319 | | - * Register magic-word variable IDs |
320 | | - */ |
321 | | - static function addMagicWordVariableIDs( &$magicWordVariableIDs ) { |
322 | | - $magicWordVariableIDs[] = 'MAG_HIDEFROMDRILLDOWN'; |
323 | | - $magicWordVariableIDs[] = 'MAG_SHOWINDRILLDOWN'; |
324 | | - return true; |
325 | | - } |
326 | | - |
327 | | - /** |
328 | | - * Set the actual value of the magic words |
329 | | - */ |
330 | | - static function addMagicWordLanguage( &$magicWords, $langCode ) { |
331 | | - switch( $langCode ) { |
332 | | - default: |
333 | | - $magicWords['MAG_HIDEFROMDRILLDOWN'] = array( 0, '__HIDEFROMDRILLDOWN__' ); |
334 | | - $magicWords['MAG_SHOWINDRILLDOWN'] = array( 0, '__SHOWINDRILLDOWN__' ); |
335 | | - } |
336 | | - return true; |
337 | | - } |
338 | | - |
339 | | - /** |
340 | | - * Set values in the page_props table based on the presence of the |
341 | | - * 'HIDEFROMDRILLDOWN' and 'SHOWINDRILLDOWN' magic words in a page |
342 | | - */ |
343 | | - static function handleShowAndHide( &$parser, &$text ) { |
344 | | - global $wgOut, $wgAction; |
345 | | - $mw_hide = MagicWord::get( 'MAG_HIDEFROMDRILLDOWN' ); |
346 | | - if ( $mw_hide->matchAndRemove( $text ) ) { |
347 | | - $parser->mOutput->setProperty( 'hidefromdrilldown', 'y' ); |
348 | | - } |
349 | | - $mw_show = MagicWord::get( 'MAG_SHOWINDRILLDOWN' ); |
350 | | - if ( $mw_show->matchAndRemove( $text ) ) { |
351 | | - $parser->mOutput->setProperty( 'showindrilldown', 'y' ); |
352 | | - } |
353 | | - return true; |
354 | | - } |
355 | | - |
356 | | -} |
Index: trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | |
9 | 9 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
10 | 10 | |
11 | | -define( 'SD_VERSION', '0.7.1' ); |
| 11 | +define( 'SD_VERSION', '0.7.2' ); |
12 | 12 | |
13 | 13 | // constants for special properties |
14 | 14 | define( 'SD_SP_HAS_FILTER', 1 ); |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | $wgAutoloadClasses['SDBrowseData'] = $sdgIP . '/specials/SD_BrowseData.php'; |
48 | 48 | $wgSpecialPageGroups['BrowseData'] = 'sd_group'; |
49 | 49 | |
50 | | -$wgAutoloadClasses['SDUtils'] = $sdgIP . '/includes/SD_Utils.inc'; |
| 50 | +$wgAutoloadClasses['SDUtils'] = $sdgIP . '/includes/SD_Utils.php'; |
51 | 51 | $wgAutoloadClasses['SDFilter'] = $sdgIP . '/includes/SD_Filter.php'; |
52 | 52 | $wgAutoloadClasses['SDFilterValue'] = $sdgIP . '/includes/SD_FilterValue.php'; |
53 | 53 | $wgAutoloadClasses['SDAppliedFilter'] = $sdgIP . '/includes/SD_AppliedFilter.php'; |
Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.php |
— | — | @@ -0,0 +1,355 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A class for static helper functions for Semantic Drilldown |
| 5 | + * |
| 6 | + * @author Yaron Koren |
| 7 | + */ |
| 8 | + |
| 9 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 10 | + |
| 11 | +class SDUtils { |
| 12 | + |
| 13 | + /** |
| 14 | + * Gets a list of the names of all categories in the wiki that aren't |
| 15 | + * children of some other category - this list additionally includes, |
| 16 | + * and excludes, categories that are manually set with |
| 17 | + * 'SHOWINDRILLDOWN' and 'HIDEFROMDRILLDOWN', respectively. |
| 18 | + */ |
| 19 | + static function getTopLevelCategories() { |
| 20 | + $categories = array(); |
| 21 | + $dbr = wfGetDB( DB_SLAVE ); |
| 22 | + extract( $dbr->tableNames( 'page', 'categorylinks', 'page_props' ) ); |
| 23 | + $cat_ns = NS_CATEGORY; |
| 24 | + $sql = "SELECT page_title FROM $page p LEFT OUTER JOIN $categorylinks cl ON p.page_id = cl.cl_from WHERE p.page_namespace = $cat_ns AND cl.cl_to IS NULL"; |
| 25 | + $res = $dbr->query( $sql ); |
| 26 | + if ( $dbr->numRows( $res ) > 0 ) { |
| 27 | + while ( $row = $dbr->fetchRow( $res ) ) { |
| 28 | + $categories[] = str_replace( '_', ' ', $row[0] ); |
| 29 | + } |
| 30 | + } |
| 31 | + $dbr->freeResult( $res ); |
| 32 | + |
| 33 | + // get 'hide' and 'show' categories |
| 34 | + $hidden_cats = $shown_cats = array(); |
| 35 | + $sql2 = "SELECT p.page_title, pp.pp_propname FROM $page p JOIN $page_props pp ON p.page_id = pp.pp_page WHERE p.page_namespace = $cat_ns AND (pp.pp_propname = 'hidefromdrilldown' OR pp.pp_propname = 'showindrilldown') AND pp.pp_value = 'y'"; |
| 36 | + $res2 = $dbr->query( $sql2 ); |
| 37 | + if ( $dbr->numRows( $res2 ) > 0 ) { |
| 38 | + while ( $row = $dbr->fetchRow( $res2 ) ) { |
| 39 | + if ( $row[1] == 'hidefromdrilldown' ) |
| 40 | + $hidden_cats[] = str_replace( '_', ' ', $row[0] ); |
| 41 | + else |
| 42 | + $shown_cats[] = str_replace( '_', ' ', $row[0] ); |
| 43 | + } |
| 44 | + } |
| 45 | + $dbr->freeResult( $res2 ); |
| 46 | + $categories = array_merge( $categories, $shown_cats ); |
| 47 | + foreach ( $hidden_cats as $hidden_cat ) { |
| 48 | + foreach ( $categories as $i => $cat ) { |
| 49 | + if ( $cat == $hidden_cat ) { |
| 50 | + unset( $categories[$i] ); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + sort( $categories ); |
| 55 | + return $categories; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Gets a list of the names of all properties in the wiki |
| 60 | + */ |
| 61 | + static function getSemanticProperties() { |
| 62 | + global $smwgContLang; |
| 63 | + $smw_namespace_labels = $smwgContLang->getNamespaces(); |
| 64 | + $all_properties = array(); |
| 65 | + |
| 66 | + // $options = new SMWRequestOptions(); |
| 67 | + // $options->limit = 10000; |
| 68 | + // $used_properties = smwfGetStore()->getPropertiesSpecial($options); |
| 69 | + $used_properties = smwfGetStore()->getPropertiesSpecial(); |
| 70 | + foreach ( $used_properties as $property ) { |
| 71 | + $all_properties[] = $property[0]->getWikiValue(); |
| 72 | + } |
| 73 | + $unused_properties = smwfGetStore()->getUnusedPropertiesSpecial( $options ); |
| 74 | + foreach ( $unused_properties as $property ) { |
| 75 | + $all_properties[] = $property->getWikiValue(); |
| 76 | + } |
| 77 | + // remove the special properties of Semantic Drilldown from this list... |
| 78 | + global $sdgContLang; |
| 79 | + $sd_props = $sdgContLang->getPropertyLabels(); |
| 80 | + $sd_prop_aliases = $sdgContLang->getPropertyAliases(); |
| 81 | + foreach ( $all_properties as $i => $prop_name ) { |
| 82 | + foreach ( $sd_props as $prop => $label ) { |
| 83 | + if ( $prop_name == $label ) { |
| 84 | + unset( $all_properties[$i] ); |
| 85 | + } |
| 86 | + } |
| 87 | + foreach ( $sd_prop_aliases as $alias => $cur_prop ) { |
| 88 | + if ( $prop_name == $alias ) { |
| 89 | + unset( $all_properties[$i] ); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + sort( $all_properties ); |
| 94 | + return $all_properties; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Gets the names of all the filter pages, i.e. pages in the Filter |
| 99 | + * namespace |
| 100 | + */ |
| 101 | + static function getFilters() { |
| 102 | + $dbr = wfGetDB( DB_SLAVE ); |
| 103 | + $res = $dbr->select( 'page', 'page_title', array( 'page_namespace' => SD_NS_FILTER ) ); |
| 104 | + $filters = array(); |
| 105 | + while ( $row = $dbr->fetchRow( $res ) ) { |
| 106 | + $filters[] = $row[0]; |
| 107 | + } |
| 108 | + $dbr->freeResult( $res ); |
| 109 | + return $filters; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Generic static function - gets all the values that a specific page |
| 114 | + * points to with a specific property |
| 115 | + * ($special_prop and $prop represent the same value, depending on |
| 116 | + * whether we're using SMW 1.4 or an earlier version) |
| 117 | + */ |
| 118 | + static function getValuesForProperty( $subject, $subject_namespace, $special_prop ) { |
| 119 | + $store = smwfGetStore(); |
| 120 | + $subject_title = Title::newFromText( $subject, $subject_namespace ); |
| 121 | + $property = SMWPropertyValue::makeProperty( $special_prop ); |
| 122 | + $res = $store->getPropertyValues( $subject_title, $property ); |
| 123 | + $values = array(); |
| 124 | + foreach ( $res as $prop_val ) { |
| 125 | + // depends on version of SMW |
| 126 | + if ( method_exists( $prop_val, 'getValueKey' ) ) { |
| 127 | + $actual_val = $prop_val->getValueKey(); |
| 128 | + } else { |
| 129 | + $actual_val = $prop_val->getXSDValue(); |
| 130 | + } |
| 131 | + $values[] = html_entity_decode( str_replace( '_', ' ', $actual_val ) ); |
| 132 | + } |
| 133 | + return $values; |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Gets all the filters specified for a category. |
| 138 | + */ |
| 139 | + static function loadFiltersForCategory( $category ) { |
| 140 | + $filters = array(); |
| 141 | + $filter_names = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_F' ); |
| 142 | + foreach ( $filter_names as $filter_name ) { |
| 143 | + $filters[] = SDFilter::load( $filter_name ); |
| 144 | + } |
| 145 | + return $filters; |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Gets all the display parameters defined for a category |
| 150 | + */ |
| 151 | + static function getDisplayParamsForCategory( $category ) { |
| 152 | + $all_display_params = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_DP' ); |
| 153 | + |
| 154 | + $return_display_params = array(); |
| 155 | + foreach ( $all_display_params as $display_params ) { |
| 156 | + $return_display_params[] = explode( ';', $display_params ); |
| 157 | + } |
| 158 | + return $return_display_params; |
| 159 | + } |
| 160 | + |
| 161 | + static function getCategoryChildren( $category_name, $get_categories, $levels ) { |
| 162 | + if ( $levels == 0 ) { |
| 163 | + return array(); |
| 164 | + } |
| 165 | + $pages = array(); |
| 166 | + $subcategories = array(); |
| 167 | + $dbr = wfGetDB( DB_SLAVE ); |
| 168 | + extract( $dbr->tableNames( 'page', 'categorylinks' ) ); |
| 169 | + $cat_ns = NS_CATEGORY; |
| 170 | + $query_category = str_replace( ' ', '_', $category_name ); |
| 171 | + $query_category = str_replace( "'", "\'", $query_category ); |
| 172 | + $sql = "SELECT p.page_title, p.page_namespace FROM $categorylinks cl |
| 173 | + JOIN $page p on cl.cl_from = p.page_id |
| 174 | + WHERE cl.cl_to = '$query_category'\n"; |
| 175 | + if ( $get_categories ) |
| 176 | + $sql .= "AND p.page_namespace = $cat_ns\n"; |
| 177 | + $sql .= "ORDER BY cl.cl_sortkey"; |
| 178 | + $res = $dbr->query( $sql ); |
| 179 | + while ( $row = $dbr->fetchRow( $res ) ) { |
| 180 | + if ( $get_categories ) { |
| 181 | + $subcategories[] = $row[0]; |
| 182 | + $pages[] = $row[0]; |
| 183 | + } else { |
| 184 | + if ( $row[1] == $cat_ns ) |
| 185 | + $subcategories[] = $row[0]; |
| 186 | + else |
| 187 | + $pages[] = $row[0]; |
| 188 | + } |
| 189 | + } |
| 190 | + $dbr->freeResult( $res ); |
| 191 | + foreach ( $subcategories as $subcategory ) { |
| 192 | + $pages = array_merge( $pages, SDUtils::getCategoryChildren( $subcategory, $get_categories, $levels - 1 ) ); |
| 193 | + } |
| 194 | + return $pages; |
| 195 | + } |
| 196 | + |
| 197 | + static function monthToString( $month ) { |
| 198 | + if ( $month == 1 ) { |
| 199 | + return wfMsg( 'january' ); |
| 200 | + } elseif ( $month == 2 ) { |
| 201 | + return wfMsg( 'february' ); |
| 202 | + } elseif ( $month == 3 ) { |
| 203 | + return wfMsg( 'march' ); |
| 204 | + } elseif ( $month == 4 ) { |
| 205 | + return wfMsg( 'april' ); |
| 206 | + } elseif ( $month == 5 ) { |
| 207 | + return wfMsg( 'may' ); |
| 208 | + } elseif ( $month == 6 ) { |
| 209 | + return wfMsg( 'june' ); |
| 210 | + } elseif ( $month == 7 ) { |
| 211 | + return wfMsg( 'july' ); |
| 212 | + } elseif ( $month == 8 ) { |
| 213 | + return wfMsg( 'august' ); |
| 214 | + } elseif ( $month == 9 ) { |
| 215 | + return wfMsg( 'september' ); |
| 216 | + } elseif ( $month == 10 ) { |
| 217 | + return wfMsg( 'october' ); |
| 218 | + } elseif ( $month == 11 ) { |
| 219 | + return wfMsg( 'november' ); |
| 220 | + } else { // if ($month == 12) { |
| 221 | + return wfMsg( 'december' ); |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + static function stringToMonth( $str ) { |
| 226 | + if ( $str == wfMsg( 'january' ) ) { |
| 227 | + return 1; |
| 228 | + } elseif ( $str == wfMsg( 'february' ) ) { |
| 229 | + return 2; |
| 230 | + } elseif ( $str == wfMsg( 'march' ) ) { |
| 231 | + return 3; |
| 232 | + } elseif ( $str == wfMsg( 'april' ) ) { |
| 233 | + return 4; |
| 234 | + } elseif ( $str == wfMsg( 'may' ) ) { |
| 235 | + return 5; |
| 236 | + } elseif ( $str == wfMsg( 'june' ) ) { |
| 237 | + return 6; |
| 238 | + } elseif ( $str == wfMsg( 'july' ) ) { |
| 239 | + return 7; |
| 240 | + } elseif ( $str == wfMsg( 'august' ) ) { |
| 241 | + return 8; |
| 242 | + } elseif ( $str == wfMsg( 'september' ) ) { |
| 243 | + return 9; |
| 244 | + } elseif ( $str == wfMsg( 'october' ) ) { |
| 245 | + return 10; |
| 246 | + } elseif ( $str == wfMsg( 'november' ) ) { |
| 247 | + return 11; |
| 248 | + } else { // if ($strmonth == wfMsg('december')) { |
| 249 | + return 12; |
| 250 | + } |
| 251 | + } |
| 252 | + |
| 253 | + static function booleanToString( $bool_value ) { |
| 254 | + wfLoadExtensionMessages( 'SemanticMediaWiki' ); |
| 255 | + $words_field_name = ( $bool_value == true ) ? 'smw_true_words' : 'smw_false_words'; |
| 256 | + $words_array = explode( ',', wfMsgForContent( $words_field_name ) ); |
| 257 | + // go with the value in the array that tends to be "yes" or |
| 258 | + // "no", which is the 3rd |
| 259 | + $index_of_word = 2; |
| 260 | + // capitalize first letter of word |
| 261 | + if ( count( $words_array ) > $index_of_word ) { |
| 262 | + $string_value = ucwords( $words_array[$index_of_word] ); |
| 263 | + } elseif ( count( $words_array ) == 0 ) { |
| 264 | + $string_value = $bool_value; // a safe value if no words are found |
| 265 | + } else { |
| 266 | + $string_value = ucwords( $words_array[0] ); |
| 267 | + } |
| 268 | + return $string_value; |
| 269 | + } |
| 270 | + |
| 271 | + /** |
| 272 | + * Prints the mini-form contained at the bottom of various pages, that |
| 273 | + * allows pages to spoof a normal edit page, that can preview, save, |
| 274 | + * etc. |
| 275 | + */ |
| 276 | + static function printRedirectForm( $title, $page_contents, $edit_summary, $is_save, $is_preview, $is_diff, $is_minor_edit, $watch_this ) { |
| 277 | + $article = new Article( $title ); |
| 278 | + $new_url = $title->getLocalURL( 'action=submit' ); |
| 279 | + $starttime = wfTimestampNow(); |
| 280 | + $edittime = $article->getTimestamp(); |
| 281 | + global $wgUser; |
| 282 | + if ( $wgUser->isLoggedIn() ) |
| 283 | + $token = htmlspecialchars( $wgUser->editToken() ); |
| 284 | + else |
| 285 | + $token = EDIT_TOKEN_SUFFIX; |
| 286 | + |
| 287 | + if ( $is_save ) |
| 288 | + $action = "wpSave"; |
| 289 | + elseif ( $is_preview ) |
| 290 | + $action = "wpPreview"; |
| 291 | + else // $is_diff |
| 292 | + $action = "wpDiff"; |
| 293 | + |
| 294 | + $text = <<<END |
| 295 | + <form id="editform" name="editform" method="post" action="$new_url"> |
| 296 | + <input type="hidden" name="wpTextbox1" id="wpTextbox1" value="$page_contents" /> |
| 297 | + <input type="hidden" name="wpSummary" value="$edit_summary" /> |
| 298 | + <input type="hidden" name="wpStarttime" value="$starttime" /> |
| 299 | + <input type="hidden" name="wpEdittime" value="$edittime" /> |
| 300 | + <input type="hidden" name="wpEditToken" value="$token" /> |
| 301 | + <input type="hidden" name="$action" /> |
| 302 | + |
| 303 | +END; |
| 304 | + if ( $is_minor_edit ) |
| 305 | + $text .= ' <input type="hidden" name="wpMinoredit">' . "\n"; |
| 306 | + if ( $watch_this ) |
| 307 | + $text .= ' <input type="hidden" name="wpWatchthis">' . "\n"; |
| 308 | + $text .= <<<END |
| 309 | + </form> |
| 310 | + <script type="text/javascript"> |
| 311 | + document.editform.submit(); |
| 312 | + </script> |
| 313 | + |
| 314 | +END; |
| 315 | + return $text; |
| 316 | + } |
| 317 | + |
| 318 | + /** |
| 319 | + * Register magic-word variable IDs |
| 320 | + */ |
| 321 | + static function addMagicWordVariableIDs( &$magicWordVariableIDs ) { |
| 322 | + $magicWordVariableIDs[] = 'MAG_HIDEFROMDRILLDOWN'; |
| 323 | + $magicWordVariableIDs[] = 'MAG_SHOWINDRILLDOWN'; |
| 324 | + return true; |
| 325 | + } |
| 326 | + |
| 327 | + /** |
| 328 | + * Set the actual value of the magic words |
| 329 | + */ |
| 330 | + static function addMagicWordLanguage( &$magicWords, $langCode ) { |
| 331 | + switch( $langCode ) { |
| 332 | + default: |
| 333 | + $magicWords['MAG_HIDEFROMDRILLDOWN'] = array( 0, '__HIDEFROMDRILLDOWN__' ); |
| 334 | + $magicWords['MAG_SHOWINDRILLDOWN'] = array( 0, '__SHOWINDRILLDOWN__' ); |
| 335 | + } |
| 336 | + return true; |
| 337 | + } |
| 338 | + |
| 339 | + /** |
| 340 | + * Set values in the page_props table based on the presence of the |
| 341 | + * 'HIDEFROMDRILLDOWN' and 'SHOWINDRILLDOWN' magic words in a page |
| 342 | + */ |
| 343 | + static function handleShowAndHide( &$parser, &$text ) { |
| 344 | + global $wgOut, $wgAction; |
| 345 | + $mw_hide = MagicWord::get( 'MAG_HIDEFROMDRILLDOWN' ); |
| 346 | + if ( $mw_hide->matchAndRemove( $text ) ) { |
| 347 | + $parser->mOutput->setProperty( 'hidefromdrilldown', 'y' ); |
| 348 | + } |
| 349 | + $mw_show = MagicWord::get( 'MAG_SHOWINDRILLDOWN' ); |
| 350 | + if ( $mw_show->matchAndRemove( $text ) ) { |
| 351 | + $parser->mOutput->setProperty( 'showindrilldown', 'y' ); |
| 352 | + } |
| 353 | + return true; |
| 354 | + } |
| 355 | + |
| 356 | +} |
Property changes on: trunk/extensions/SemanticDrilldown/includes/SD_Utils.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 357 | + native |