コード例 #1
0
ファイル: ResourceLoader.php プロジェクト: richhl/kalturaCE
 function transformScriptText($scriptText, $moduleName)
 {
     global $wgEnableScriptLocalization;
     // Strip out mw.log debug lines (if not in debug mode)
     if (!$this->debug) {
         $scriptText = $this->removeLogStatements($scriptText);
     }
     // Do language swap by index:
     if ($wgEnableScriptLocalization) {
         // NOTE getResourceMessageJS could identify which mode we are in and we would not need to
         // try each of these search patterns in the same order as before.
         // Get the mw.addMessage javascript
         self::$addMessageJs = $this->getAddMessagesFromScriptText($scriptText, $moduleName);
         // Check for mw.includeAllModuleMsgs() call to be replaced with all the msgs
         // Use preg_replace_callback to avoid back-refrence substitution
         $scriptText = preg_replace_callback(self::$includeAllMsgsRegEx, 'ResourceLoader::preg_addMessageJs', $scriptText, 1, $count);
         if ($count != 0) {
             return $scriptText;
         }
         // Replace mw.addMessages with localized msgs in javascript string
         $inx = self::getAddMessagesIndex($scriptText);
         if ($inx) {
             // Return the final string (without double {})
             return substr($scriptText, 0, $inx['sfull']) . self::$addMessageJs . substr($scriptText, $inx['efull']);
         }
         // Replace mw.addMessageKeys with localized msgs in javascript string
         $inx = self::getAddMessageKeyIndex($scriptText);
         if ($inx) {
             // Return the final string (without double {})
             return substr($scriptText, 0, $inx['sfull']) . self::$addMessageJs . substr($scriptText, $inx['efull']);
         }
     }
     // Return the javascript str unmodified if we did not transform with the localisation
     return $scriptText;
 }