Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | * A very similar function to titleURLString(), to get the |
60 | 60 | * non-URL-encoded title string |
61 | 61 | */ |
62 | | - static function titleString( $title ) { |
| 62 | + public static function titleString( $title ) { |
63 | 63 | $namespace = $title->getNsText(); |
64 | 64 | if ( $namespace != '' ) { |
65 | 65 | $namespace .= ':'; |
— | — | @@ -83,12 +83,31 @@ |
84 | 84 | } else { |
85 | 85 | $page = new SMWDIWikiPage( $pageName, $pageNamespace, null ); |
86 | 86 | } |
87 | | - $property = new SMWDIProperty( $propID ); |
88 | | - return $store->getPropertyValues( $page, $property, $requestOptions ); |
| 87 | + $property = SMWDIProperty::newFromUserLabel( $propID ); |
| 88 | + $res = $store->getPropertyValues( $page, $property, $requestOptions ); |
| 89 | + $values = array(); |
| 90 | + foreach ( $res as $value ) { |
| 91 | + // getSortKey() seems to return the correct |
| 92 | + // value for every data type. |
| 93 | + $values[] = $value->getSortKey(); |
| 94 | + } |
| 95 | + return $values; |
89 | 96 | } else { |
90 | 97 | $title = Title::makeTitleSafe( $pageNamespace, $pageName ); |
91 | 98 | $property = SMWPropertyValue::makeProperty( $propID ); |
92 | | - return $store->getPropertyValues( $title, $property, $requestOptions ); |
| 99 | + $res = $store->getPropertyValues( $title, $property, $requestOptions ); |
| 100 | + $values = array(); |
| 101 | + foreach ( $res as $value ) { |
| 102 | + if ( method_exists( $value, 'getTitle' ) ) { |
| 103 | + $title = $value->getTitle(); |
| 104 | + if ( !is_null( $title ) ) { |
| 105 | + $values[] = $title->getText(); |
| 106 | + } |
| 107 | + } else { |
| 108 | + $values[] = str_replace( '_' , ' ', $title->getWikiValue() ); |
| 109 | + } |
| 110 | + } |
| 111 | + return array_unique( $values ); |
93 | 112 | } |
94 | 113 | } |
95 | 114 | |
— | — | @@ -98,7 +117,7 @@ |
99 | 118 | * - this function doubles as a function to get all categories on |
100 | 119 | * the site, if no article is specified |
101 | 120 | */ |
102 | | - static function getCategoriesForPage( $title = null ) { |
| 121 | + public static function getCategoriesForPage( $title = null ) { |
103 | 122 | $categories = array(); |
104 | 123 | $db = wfGetDB( DB_SLAVE ); |
105 | 124 | $conditions = null; |
— | — | @@ -121,7 +140,7 @@ |
122 | 141 | return $categories; |
123 | 142 | } |
124 | 143 | |
125 | | - static function registerProperty( $id, $typeid, $label ) { |
| 144 | + public static function registerProperty( $id, $typeid, $label ) { |
126 | 145 | if ( class_exists( 'SMWDIProperty' ) ) { |
127 | 146 | SMWDIProperty::registerProperty( $id, $typeid, $label, true ); |
128 | 147 | } else { |
— | — | @@ -129,7 +148,7 @@ |
130 | 149 | } |
131 | 150 | } |
132 | 151 | |
133 | | - static function initProperties() { |
| 152 | + public static function initProperties() { |
134 | 153 | global $sfgContLang; |
135 | 154 | $sf_props = $sfgContLang->getPropertyLabels(); |
136 | 155 | if ( array_key_exists( SF_SP_HAS_DEFAULT_FORM, $sf_props ) ) |
— | — | @@ -155,7 +174,7 @@ |
156 | 175 | /** |
157 | 176 | * Creates HTML linking to a wiki page |
158 | 177 | */ |
159 | | - static function linkText( $namespace, $name, $text = null ) { |
| 178 | + public static function linkText( $namespace, $name, $text = null ) { |
160 | 179 | $title = Title::makeTitleSafe( $namespace, $name ); |
161 | 180 | if ( is_null( $title ) ) { |
162 | 181 | return $name; // TODO maybe report an error here? |
— | — | @@ -172,7 +191,7 @@ |
173 | 192 | * allows pages to spoof a normal edit page, that can preview, save, |
174 | 193 | * etc. |
175 | 194 | */ |
176 | | - static function printRedirectForm( $title, $page_contents, $edit_summary, $is_save, $is_preview, $is_diff, $is_minor_edit, $watch_this, $start_time, $edit_time ) { |
| 195 | + public static function printRedirectForm( $title, $page_contents, $edit_summary, $is_save, $is_preview, $is_diff, $is_minor_edit, $watch_this, $start_time, $edit_time ) { |
177 | 196 | global $wgUser, $sfgScriptPath; |
178 | 197 | |
179 | 198 | if ( $is_save ) { |
— | — | @@ -189,17 +208,17 @@ |
190 | 209 | <p style="position: absolute; left: 45%; top: 45%;"><img src="$sfgScriptPath/skins/loading.gif" /></p> |
191 | 210 | |
192 | 211 | END; |
193 | | - $form_body = "\t" . Html::Hidden( 'wpTextbox1', $page_contents ) . "\n"; |
194 | | - $form_body .= "\t" . Html::Hidden( 'wpSummary', $edit_summary ) . "\n"; |
195 | | - $form_body .= "\t" . Html::Hidden( 'wpStarttime', $start_time ) . "\n"; |
196 | | - $form_body .= "\t" . Html::Hidden( 'wpEdittime', $edit_time ) . "\n"; |
197 | | - $form_body .= "\t" . Html::Hidden( 'wpEditToken', $wgUser->isLoggedIn() ? $wgUser->editToken() : EDIT_TOKEN_SUFFIX ) . "\n"; |
198 | | - $form_body .= "\t" . Html::Hidden( $action, null ) . "\n"; |
| 212 | + $form_body = "\t" . Html::hidden( 'wpTextbox1', $page_contents ) . "\n"; |
| 213 | + $form_body .= "\t" . Html::hidden( 'wpSummary', $edit_summary ) . "\n"; |
| 214 | + $form_body .= "\t" . Html::hidden( 'wpStarttime', $start_time ) . "\n"; |
| 215 | + $form_body .= "\t" . Html::hidden( 'wpEdittime', $edit_time ) . "\n"; |
| 216 | + $form_body .= "\t" . Html::hidden( 'wpEditToken', $wgUser->isLoggedIn() ? $wgUser->editToken() : EDIT_TOKEN_SUFFIX ) . "\n"; |
| 217 | + $form_body .= "\t" . Html::hidden( $action, null ) . "\n"; |
199 | 218 | |
200 | 219 | if ( $is_minor_edit ) |
201 | | - $form_body .= "\t" . Html::Hidden( 'wpMinoredit' , null ) . "\n"; |
| 220 | + $form_body .= "\t" . Html::hidden( 'wpMinoredit' , null ) . "\n"; |
202 | 221 | if ( $watch_this ) |
203 | | - $form_body .= "\t" . Html::Hidden( 'wpWatchthis', null ) . "\n"; |
| 222 | + $form_body .= "\t" . Html::hidden( 'wpWatchthis', null ) . "\n"; |
204 | 223 | $text .= Xml::tags( |
205 | 224 | 'form', |
206 | 225 | array( |
— | — | @@ -227,7 +246,7 @@ |
228 | 247 | * Uses the ResourceLoader (available with MediaWiki 1.17 and higher) |
229 | 248 | * to load all the necessary JS and CSS files for Semantic Forms. |
230 | 249 | */ |
231 | | - static function loadJavascriptAndCSS( $parser = null ) { |
| 250 | + public static function loadJavascriptAndCSS( $parser = null ) { |
232 | 251 | // Handling depends on whether or not this form is embedded |
233 | 252 | // in another page. |
234 | 253 | if ( !is_null( $parser ) ) { |
— | — | @@ -248,7 +267,7 @@ |
249 | 268 | * Javascript files to be added regardless of the MediaWiki version |
250 | 269 | * (i.e., even if the ResourceLoader is installed). |
251 | 270 | */ |
252 | | - static function addJavascriptFiles( $parser ) { |
| 271 | + public static function addJavascriptFiles( $parser ) { |
253 | 272 | global $wgOut, $wgFCKEditorDir, $wgScriptPath, $wgJsMimeType; |
254 | 273 | |
255 | 274 | $scripts = array(); |
— | — | @@ -278,7 +297,7 @@ |
279 | 298 | * |
280 | 299 | * Accepts an optional Parser instance, or uses $wgOut if omitted. |
281 | 300 | */ |
282 | | - static function addJavascriptAndCSS( $parser = null ) { |
| 301 | + public static function addJavascriptAndCSS( $parser = null ) { |
283 | 302 | global $wgOut; |
284 | 303 | |
285 | 304 | if ( !$parser ) { |
— | — | @@ -367,7 +386,7 @@ |
368 | 387 | /** |
369 | 388 | * Return an array of all form names on this wiki |
370 | 389 | */ |
371 | | - static function getAllForms() { |
| 390 | + public static function getAllForms() { |
372 | 391 | $dbr = wfGetDB( DB_SLAVE ); |
373 | 392 | $res = $dbr->select( 'page', |
374 | 393 | 'page_title', |
— | — | @@ -383,7 +402,7 @@ |
384 | 403 | return $form_names; |
385 | 404 | } |
386 | 405 | |
387 | | - static function formDropdownHTML() { |
| 406 | + public static function formDropdownHTML() { |
388 | 407 | // create a dropdown of possible form names |
389 | 408 | global $sfgContLang; |
390 | 409 | $namespace_labels = $sfgContLang->getNamespaces(); |
— | — | @@ -391,10 +410,9 @@ |
392 | 411 | $form_names = SFUtils::getAllForms(); |
393 | 412 | $select_body = ""; |
394 | 413 | foreach ( $form_names as $form_name ) { |
395 | | - $select_body .= ' ' . Xml::element( 'option', null, $form_name ) . "\n"; |
| 414 | + $select_body .= "\t" . Xml::element( 'option', null, $form_name ) . "\n"; |
396 | 415 | } |
397 | | - $str = " $form_label:" . Xml::tags( 'select', array( 'name' => 'form' ), $select_body ) . "\n"; |
398 | | - return $str; |
| 416 | + return "\t$form_label:" . Xml::tags( 'select', array( 'name' => 'form' ), $select_body ) . "\n"; |
399 | 417 | } |
400 | 418 | |
401 | 419 | /* |
— | — | @@ -403,21 +421,13 @@ |
404 | 422 | * case-insensitive queries; for queries with a substring, the |
405 | 423 | * function SFAutocompleteAPI::getAllValuesForProperty() exists. |
406 | 424 | */ |
407 | | - static function getAllValuesForProperty( $property_name ) { |
| 425 | + public static function getAllValuesForProperty( $property_name ) { |
408 | 426 | global $sfgMaxAutocompleteValues; |
409 | 427 | |
410 | 428 | $store = smwfGetStore(); |
411 | 429 | $requestoptions = new SMWRequestOptions(); |
412 | 430 | $requestoptions->limit = $sfgMaxAutocompleteValues; |
413 | | - $data_values = self::getSMWPropertyValues( $store, null, null, $property_name, $requestoptions ); |
414 | | - $values = array(); |
415 | | - foreach ( $data_values as $dv ) { |
416 | | - // getPropertyValues() gets many repeat values - we want |
417 | | - // only one of each value |
418 | | - $string_value = str_replace( '_', ' ', $dv->getWikiValue() ); |
419 | | - if ( array_search( $string_value, $values ) === false ) |
420 | | - $values[] = $string_value; |
421 | | - } |
| 431 | + $values = self::getSMWPropertyValues( $store, null, null, $property_name, $requestoptions ); |
422 | 432 | sort( $values ); |
423 | 433 | return $values; |
424 | 434 | } |
— | — | @@ -427,7 +437,7 @@ |
428 | 438 | * subcategories, down a certain number of levels - heavily based on |
429 | 439 | * SMW's SMWInlineQuery::includeSubcategories() |
430 | 440 | */ |
431 | | - static function getAllPagesForCategory( $top_category, $num_levels, $substring = null ) { |
| 441 | + public static function getAllPagesForCategory( $top_category, $num_levels, $substring = null ) { |
432 | 442 | if ( 0 == $num_levels ) return $top_category; |
433 | 443 | global $sfgMaxAutocompleteValues; |
434 | 444 | |
— | — | @@ -500,7 +510,7 @@ |
501 | 511 | return $pages; |
502 | 512 | } |
503 | 513 | |
504 | | - static function getAllPagesForConcept( $concept_name, $substring = null ) { |
| 514 | + public static function getAllPagesForConcept( $concept_name, $substring = null ) { |
505 | 515 | global $sfgMaxAutocompleteValues; |
506 | 516 | |
507 | 517 | $store = smwfGetStore(); |
— | — | @@ -542,7 +552,7 @@ |
543 | 553 | return $pages; |
544 | 554 | } |
545 | 555 | |
546 | | - static function getAllPagesForNamespace( $namespace_name, $substring = null ) { |
| 556 | + public static function getAllPagesForNamespace( $namespace_name, $substring = null ) { |
547 | 557 | // cycle through all the namespace names for this language, and |
548 | 558 | // if one matches the namespace specified in the form, add the |
549 | 559 | // names of all the pages in that namespace to $names_array |
— | — | @@ -581,7 +591,7 @@ |
582 | 592 | * Creates an array of values that match the specified source name and type, |
583 | 593 | * for use by both Javascript autocompletion and comboboxes. |
584 | 594 | */ |
585 | | - static function getAutocompleteValues( $source_name, $source_type ) { |
| 595 | + public static function getAutocompleteValues( $source_name, $source_type ) { |
586 | 596 | $names_array = array(); |
587 | 597 | // the query depends on whether this is a property, category, concept |
588 | 598 | // or namespace |
— | — | @@ -604,7 +614,7 @@ |
605 | 615 | * Helper function to get an array of values out of what may be either |
606 | 616 | * an array or a delimited string |
607 | 617 | */ |
608 | | - static function getValuesArray( $value, $delimiter ) { |
| 618 | + public static function getValuesArray( $value, $delimiter ) { |
609 | 619 | if ( is_array( $value ) ) { |
610 | 620 | return $value; |
611 | 621 | } else { |
— | — | @@ -613,7 +623,7 @@ |
614 | 624 | } |
615 | 625 | } |
616 | 626 | |
617 | | - static function getValuesFromExternalURL( $external_url_alias, $substring ) { |
| 627 | + public static function getValuesFromExternalURL( $external_url_alias, $substring ) { |
618 | 628 | global $sfgAutocompletionURLs; |
619 | 629 | if ( empty( $sfgAutocompletionURLs ) ) return array(); |
620 | 630 | $url = $sfgAutocompletionURLs[$external_url_alias]; |
— | — | @@ -633,7 +643,7 @@ |
634 | 644 | /** |
635 | 645 | * A helper function, used by getFormTagComponents(). |
636 | 646 | */ |
637 | | - static function convertBackToPipes( $s ) { |
| 647 | + public static function convertBackToPipes( $s ) { |
638 | 648 | return str_replace( "\1", '|', $s ); |
639 | 649 | } |
640 | 650 | |
— | — | @@ -643,7 +653,7 @@ |
644 | 654 | * that are within parser function calls - i.e., pipes within |
645 | 655 | * double curly brackets. |
646 | 656 | */ |
647 | | - static function getFormTagComponents( $str ) { |
| 657 | + public static function getFormTagComponents( $str ) { |
648 | 658 | // Turn each pipe within double curly brackets into another, |
649 | 659 | // unused character (here, "\1"), then do the explode, then |
650 | 660 | // convert them back. |
— | — | @@ -658,7 +668,7 @@ |
659 | 669 | * Parse the form definition and store the resulting HTML in the |
660 | 670 | * page_props table, if caching has been specified in LocalSettings.php |
661 | 671 | */ |
662 | | - static function cacheFormDefinition( $parser, $text ) { |
| 672 | + public static function cacheFormDefinition( $parser, $text ) { |
663 | 673 | global $sfgCacheFormDefinitions; |
664 | 674 | if ( ! $sfgCacheFormDefinitions ) |
665 | 675 | return true; |
— | — | @@ -694,11 +704,11 @@ |
695 | 705 | } |
696 | 706 | |
697 | 707 | /** |
698 | | - * Tranlates an EditPage storing error into the corresponding message id |
| 708 | + * Translates an EditPage error code into a corresponding message ID |
699 | 709 | * @param $error The error code |
700 | 710 | * @return String |
701 | 711 | */ |
702 | | - static function processEditErrors ( $error ) { |
| 712 | + public static function processEditErrors ( $error ) { |
703 | 713 | |
704 | 714 | switch ( $error ) { |
705 | 715 | case EditPage::AS_SUCCESS_NEW_ARTICLE: |
— | — | @@ -752,4 +762,26 @@ |
753 | 763 | } |
754 | 764 | } |
755 | 765 | |
| 766 | + public static function addToAdminLinks( &$admin_links_tree ) { |
| 767 | + $data_structure_label = wfMsg( 'smw_adminlinks_datastructure' ); |
| 768 | + $data_structure_section = $admin_links_tree->getSection( $data_structure_label ); |
| 769 | + if ( is_null( $data_structure_section ) ) { |
| 770 | + return true; |
| 771 | + } |
| 772 | + $smw_row = $data_structure_section->getRow( 'smw' ); |
| 773 | + $smw_row->addItem( ALItem::newFromSpecialPage( 'Templates' ), 'Properties' ); |
| 774 | + $smw_row->addItem( ALItem::newFromSpecialPage( 'Forms' ), 'SemanticStatistics' ); |
| 775 | + $smw_admin_row = $data_structure_section->getRow( 'smw_admin' ); |
| 776 | + $smw_admin_row->addItem( ALItem::newFromSpecialPage( 'CreateClass' ), 'SMWAdmin' ); |
| 777 | + $smw_admin_row->addItem( ALItem::newFromSpecialPage( 'CreateProperty' ), 'SMWAdmin' ); |
| 778 | + $smw_admin_row->addItem( ALItem::newFromSpecialPage( 'CreateTemplate' ), 'SMWAdmin' ); |
| 779 | + $smw_admin_row->addItem( ALItem::newFromSpecialPage( 'CreateForm' ), 'SMWAdmin' ); |
| 780 | + $smw_admin_row->addItem( ALItem::newFromSpecialPage( 'CreateCategory' ), 'SMWAdmin' ); |
| 781 | + $smw_docu_row = $data_structure_section->getRow( 'smw_docu' ); |
| 782 | + $sf_name = wfMsg( 'specialpages-group-sf_group' ); |
| 783 | + $sf_docu_label = wfMsg( 'adminlinks_documentation', $sf_name ); |
| 784 | + $smw_docu_row->addItem( ALItem::newFromExternalLink( "http://www.mediawiki.org/wiki/Extension:Semantic_Forms", $sf_docu_label ) ); |
| 785 | + |
| 786 | + return true; |
| 787 | + } |
756 | 788 | } |