http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89909
Revision: 89909 Author: yaron Date: 2011-06-12 02:33:36 +0000 (Sun, 12 Jun 2011) Log Message: ----------- Moved code to display "Yes" or "No" language value into a new method, SFUtils::getWordForYesOrNo() Modified Paths: -------------- trunk/extensions/SemanticForms/includes/SF_FormPrinter.php trunk/extensions/SemanticForms/includes/SF_Utils.php Modified: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php =================================================================== --- trunk/extensions/SemanticForms/includes/SF_FormPrinter.php 2011-06-12 01:56:17 UTC (rev 89908) +++ trunk/extensions/SemanticForms/includes/SF_FormPrinter.php 2011-06-12 02:33:36 UTC (rev 89909) @@ -886,42 +886,9 @@ // - this handling will have to get more complex if other // possibilities get added if ( count( $cur_value ) == 1 ) { - // manually load SMW's message values here, in case they - // didn't get loaded before - global $wgVersion; - if ( version_compare( $wgVersion, '1.16', '<' ) ) { - wfLoadExtensionMessages( 'SemanticMediaWiki' ); - } - $words_for_false = explode( ',', wfMsgForContent( 'smw_false_words' ) ); - // for each language, there's a series of words that are - // equal to false - get the word in the series that matches - // "no"; generally, that's the third word - $index_of_no = 2; - if ( count( $words_for_false ) > $index_of_no ) { - $no = ucwords( $words_for_false[$index_of_no] ); - } elseif ( count( $words_for_false ) == 0 ) { - $no = "0"; // some safe value if no words are found - } else { - $no = ucwords( $words_for_false[0] ); - } - $cur_value_in_template = $no; + $cur_value_in_template = SFUtils::getWordForYesOrNo( false ); } elseif ( count( $cur_value ) == 2 ) { - global $wgVersion; - if ( version_compare( $wgVersion, '1.16', '<' ) ) { - wfLoadExtensionMessages( 'SemanticMediaWiki' ); - } - $words_for_true = explode( ',', wfMsgForContent( 'smw_true_words' ) ); - // get the value in the 'true' series that tends to be "yes", - // and go with that one - generally, that's the third word - $index_of_yes = 2; - if ( count( $words_for_true ) > $index_of_yes ) { - $yes = ucwords( $words_for_true[$index_of_yes] ); - } elseif ( count( $words_for_true ) == 0 ) { - $yes = "1"; // some safe value if no words are found - } else { - $yes = ucwords( $words_for_true[0] ); - } - $cur_value_in_template = $yes; + $cur_value_in_template = SFUtils::getWordForYesOrNo( true ); // if it's 3 or greater, assume it's a date or datetime } elseif ( count( $cur_value ) >= 3 ) { $month = $cur_value['month']; Modified: trunk/extensions/SemanticForms/includes/SF_Utils.php =================================================================== --- trunk/extensions/SemanticForms/includes/SF_Utils.php 2011-06-12 01:56:17 UTC (rev 89908) +++ trunk/extensions/SemanticForms/includes/SF_Utils.php 2011-06-12 02:33:36 UTC (rev 89909) @@ -705,6 +705,32 @@ } /** + * Gets the word in the wiki's language, as defined in Semantic + * MediaWiki, for either the value 'yes' or 'no'. + */ + public static function getWordForYesOrNo( $isYes ) { + global $wgVersion; + // Manually load SMW's message values here, in case they + // didn't get loaded before. + if ( version_compare( $wgVersion, '1.16', '<' ) ) { + wfLoadExtensionMessages( 'SemanticMediaWiki' ); + } + + $wordsMsg = ( $isYes ) ? 'smw_true_words' : 'smw_false_words'; + $possibleWords = explode( ',', wfMsgForContent( $wordsMsg ) ); + // Get the value in the series that tends to be "yes" or "no" - + // generally, that's the third word. + $preferredIndex = 2; + if ( count( $possibleWords ) > $preferredIndex ) { + return ucwords( $possibleWords[$preferredIndex] ); + } elseif ( count( $possibleWords ) > 0 ) { + return ucwords( $possibleWords[0] ); + } + // If no values are found, just return a number. + return ( $isYes ) ? '1' : '0'; + } + + /** * Translates an EditPage error code into a corresponding message ID * @param $error The error code * @return String _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs