コード例 #1
0
 /**
  * Checks if an URL produced by any of the AssetsManager::getGroup*Url() methods is associated to a package registered for a specific skin
  * This method is used to filter our unwanted assets when outputting references in skin logic (e.g. in the WikiaMobile skin)
  *
  * @author Federico "Lox" Lucignano <federico(at)wikia-inc.com>
  *
  * @param string $url the url to get the package config for
  * @param WikiaSkin $skin the skin instance
  *
  * @throws WikiaException
  *
  * @return bool wether the package has been registered for the specified skin or not
  */
 public function checkAssetUrlForSkin($url, WikiaSkin $skin)
 {
     wfProfileIn(__METHOD__);
     //lazy loading of AssetsConfig
     $this->loadConfig();
     $group = null;
     $skinName = $skin->getSkinName();
     $strict = $skin->isStrict();
     if (is_string($url) && array_key_exists($url, $this->mGeneratedUrls)) {
         $group = $this->mGeneratedUrls[$url];
     } else {
         /**
          * One of the following scenarios:
          * - the url passed in is not a string
          * - the package has not been processed by any of the getGroup*Url methods so far
          * - this is a URL of a single asset generated by one of the getOne*Url methods
          * - this is an hardcoded URL passed directly to e.g. OutputPage::addScript
          *
          * If we're in strict mode then return false, the asset should be registered for $skin in config.php and
          * it should have been generated by getGroup*Url if the developer knew what he was trying to do.
          *
          * If we're in non-strict mode then return true as assets not bound to a skin are allowed anyways
          */
         wfProfileOut(__METHOD__);
         return !$strict;
     }
     $registeredSkin = $this->mAssetsConfig->getGroupSkin($group);
     $check = is_array($registeredSkin) ? in_array($skinName, $registeredSkin) : $skinName === $registeredSkin;
     //if not strict packages with no skin registered are positive
     if ($strict === false) {
         $check = $check || empty($registeredSkin);
     }
     wfProfileOut(__METHOD__);
     return $check;
 }