Commits

seb26  committed 5704244

fixed AllowLangs array, fixed internal lang params not recognising the null output for {{#langswitch:}} versus {{#langswitch: {{{foo|}}} }} (the former returns 'null', the latter returns an empty string).

  • Participants
  • Parent commits c6c7dee

Comments (0)

Files changed (3)

File LangSwitch/LangSwitch.php

     $wgHooks['ParserFirstCallInit'][] = array( &$wgLsInstance, 'getPageLang' );
     $wgHooks['ParserFirstCallInit'][] = array( &$wgLsInstance, 'registerParser' );
 
-    $wgHooks['ParserGetVariableValueSwitch'][] = array( &$wgLsInstance, 'getLangVar');
+    $wgHooks['ParserGetVariableValueSwitch'][] = array( &$wgLsInstance, 'currentpagename');
     $wgHooks['MagicWordwgVariableIDs'][] = array( &$wgLsInstance, 'declareMagicVar');
     $wgHooks['LanguageGetMagic'][] = array( &$wgLsInstance, 'registerMagic');
     
     # Actual functions
     
     function getPageLang( $parser ) {
-        global $wgLangSwitchAllowedLang;
+        global $wgLangSwitchAllowedLangs;
+        
         $title = $parser->getTitle();
         # TODO: Consider ditching these string methods and see if $parser can spit out a Title object instead.
         if ( strpos($title, '/') !== false ) {
             # If there is a '/' in the title...
             $sub = substr( strrchr($title, '/'), 1); # Return last occurence of "/xxx", then return "/xxx" without its first character.
-            if ( in_array( $sub, array('en', 'ru', 'fr') ) ) {
+            if ( in_array( $sub, $wgLangSwitchAllowedLangs ) ) {
                 $this->pageLang = $sub;
             }
             else {
         return true;
     }
     
-    function getLangVar( &$parser, &$cache, &$magicWordId, &$ret ) {
+    function currentpagename( &$parser, &$cache, &$magicWordId, &$ret ) {
         if ( $magicWordId == 'currentpagename' ) {
             $ret = $this->pageLang;
         }
         # Depending on whether or not it is, $lang will serve as the working variable (force or not).
 
         $forceLang = trim( $frame->expand( $args[0] ) );
-        if ( $forceLang == '' ) {
+        if ( $forceLang == '' || $forceLang == null ) {
             $lang = $this->pageLang;
         }
         else {
 TODO:
 
-- Fix args[0] for instances like {{#langswitch:}} where simply nothing is given (as opposed to {{#langswitch:{{{x|}}}}} where the parser expands it to nothing).
-- Test stuff.
+- fix {{CURRENTPAGELANG}}
+MediaWiki extension ideas:
+
+- LangSwitch
+- RedirectList
+- YouTube
+- Dictionary