Use __DIR__ instead of dirname( __FILE__ )
[lhc/web/wiklou.git] / languages / classes / LanguageSr.php
index e61f579..4b799f2 100644 (file)
@@ -1,8 +1,29 @@
 <?php
+/**
+ * Serbian (Српски / Srpski) specific code.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Language
+ */
 
-require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
-require_once( dirname( __FILE__ ) . '/LanguageSr_ec.php' );
-require_once( dirname( __FILE__ ) . '/LanguageSr_el.php' );
+require_once( __DIR__ . '/../LanguageConverter.php' );
+require_once( __DIR__ . '/LanguageSr_ec.php' );
+require_once( __DIR__ . '/LanguageSr_el.php' );
 
 /**
  * There are two levels of conversion for Serbian: the script level
@@ -58,11 +79,17 @@ class SrConverter extends LanguageConverter {
                );
        }
 
-       /* rules should be defined as -{ekavian | iyekavian-} -or-
-               -{code:text | code:text | ...}-
-               update: delete all rule parsing because it's not used
-                       currently, and just produces a couple of bugs
-       */
+       /**
+        * rules should be defined as -{ekavian | iyekavian-} -or-
+        * -{code:text | code:text | ...}-
+        *
+        * update: delete all rule parsing because it's not used
+        * currently, and just produces a couple of bugs
+        *
+        * @param $rule string
+        * @param $flags array
+        * @return array
+        */
        function parseManualRule( $rule, $flags = array() ) {
                if ( in_array( 'T', $flags ) ) {
                        return parent::parseManualRule( $rule, $flags );
@@ -82,6 +109,10 @@ class SrConverter extends LanguageConverter {
         *   - if there is no selected variant, leave the link
         *     names as they were
         *   - do not try to find variants for usernames
+        *
+        * @param $link string
+        * @param $nt Title
+        * @param $ignoreOtherCond bool
         */
        function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
                // check for user namespace
@@ -100,6 +131,11 @@ class SrConverter extends LanguageConverter {
        /**
         * We want our external link captions to be converted in variants,
         * so we return the original text instead -{$text}-, except for URLs
+        *
+        * @param $text string
+        * @param $noParse bool
+        *
+        * @return string
         */
        function markNoConversion( $text, $noParse = false ) {
                if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
@@ -110,6 +146,11 @@ class SrConverter extends LanguageConverter {
        /**
         * An ugly function wrapper for parsing Image titles
         * (to prevent image name conversion)
+        *
+        * @param $text string
+        * @param $toVariant bool
+        *
+        * @return string
         */
        function autoConvert( $text, $toVariant = false ) {
                global $wgTitle;
@@ -123,6 +164,12 @@ class SrConverter extends LanguageConverter {
        /**
         *  It translates text into variant, specials:
         *    - ommiting roman numbers
+        *
+        * @param $text string
+        * @param $toVariant string
+        *
+        * @throws MWException
+        * @return string
         */
        function translate( $text, $toVariant ) {
                $breaks = '[^\w\x80-\xff]';
@@ -151,18 +198,23 @@ class SrConverter extends LanguageConverter {
 
        /**
         * Guess if a text is written in Cyrillic or Latin.
+        * Overrides LanguageConverter::guessVariant()
+        *
+        * @param string  $text The text to be checked
+        * @param string  $variant Language code of the variant to be checked for
+        * @return bool  true if $text appears to be written in $variant
         *
         * @author Nikola Smolenski <smolensk@eunet.rs>
-        * @since 1.18
+        * @since 1.19
         */
        public function guessVariant( $text, $variant ) {
                $numCyrillic = preg_match_all("/[шђчћжШЂЧЋЖ]/u", $text, $dummy);
                $numLatin = preg_match_all("/[šđč枊ĐČĆŽ]/u", $text, $dummy);
 
                if( $variant == 'sr-ec' ) {
-                       return $numCyrillic > $numLatin;
-               } else if( $variant == 'sr-el' ) {
-                       return $numLatin > $numCyrillic;
+                       return (boolean) ($numCyrillic > $numLatin);
+               } elseif( $variant == 'sr-el' ) {
+                       return (boolean) ($numLatin > $numCyrillic);
                } else {
                        return false;
                }
@@ -197,12 +249,21 @@ class LanguageSr extends LanguageSr_ec {
                $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
        }
 
+       /**
+        * @param $count int
+        * @param $forms array
+        *
+        * @return string
+        */
        function convertPlural( $count, $forms ) {
                if ( !count( $forms ) ) {
                        return '';
                }
 
-               // if no number with word, then use $form[0] for singular and $form[1] for plural or zero
+               // If the actual number is not mentioned in the expression, then just two forms are enough:
+               // singular for $count == 1
+               // plural   for $count != 1
+               // For example, "This user belongs to {{PLURAL:$1|one group|several groups}}."
                if ( count( $forms ) === 2 ) {
                        return $count == 1 ? $forms[0] : $forms[1];
                }
@@ -223,5 +284,4 @@ class LanguageSr extends LanguageSr_ec {
                        }
                }
        }
-
 }