Пример #1
0
 /**
  * Combine WrappedString chunks and filter out empty ones
  *
  * @param array $chunks
  * @return string|WrappedStringList HTML
  */
 protected static function combineWrappedStrings(array $chunks)
 {
     // Filter out empty values
     $chunks = array_filter($chunks, 'strlen');
     return WrappedString::join("\n", $chunks);
 }
Пример #2
0
 /**
  * Build html output from an array of links from makeResourceLoaderLink.
  * @param array $links
  * @return string HTML
  */
 protected static function getHtmlFromLoaderLinks(array $links)
 {
     $html = array();
     $states = array();
     foreach ($links as $link) {
         if (!is_array($link)) {
             $html[] = $link;
         } else {
             $html = array_merge($html, $link['html']);
             $states += $link['states'];
         }
     }
     // Filter out empty values
     $html = array_filter($html, 'strlen');
     if (count($states)) {
         array_unshift($html, ResourceLoader::makeInlineScript(ResourceLoader::makeLoaderStateScript($states)));
     }
     return WrappedString::join("\n", $html);
 }
 /**
  * BeforePageDisplay hook handler.
  * @param $out OutputPage
  * @return bool
  */
 public static function beforePageDisplay($out)
 {
     $repo = GadgetRepo::singleton();
     $ids = $repo->getGadgetIds();
     if (!$ids) {
         return true;
     }
     $lb = new LinkBatch();
     $lb->setCaller(__METHOD__);
     $enabledLegacyGadgets = array();
     /**
      * @var $gadget Gadget
      */
     $user = $out->getUser();
     foreach ($ids as $id) {
         $gadget = $repo->getGadget($id);
         if ($gadget->isEnabled($user) && $gadget->isAllowed($user)) {
             if ($gadget->hasModule()) {
                 $out->addModuleStyles($gadget->getModuleName());
                 $out->addModules($gadget->getModuleName());
             }
             if ($gadget->getLegacyScripts()) {
                 $enabledLegacyGadgets[] = $id;
             }
         }
     }
     $strings = array();
     foreach ($enabledLegacyGadgets as $id) {
         $strings[] = self::makeLegacyWarning($id);
     }
     $out->addHTML(WrappedString::join("\n", $strings));
     return true;
 }