protected static function isFlagSet($wikiId = null, $flag = null)
 {
     if ($wikiId && $flag) {
         $flags = WikiFactory::getFlags($wikiId);
         if ($flags & $flag) {
             return true;
         }
     }
     return false;
 }
 /**
  * doWikiForm
  *
  * show wiki data
  *
  * @access public
  * @author Krzysztof Krzyżaniak <*****@*****.**>
  *
  * @return nothing
  */
 public function doWikiForm()
 {
     global $wgOut, $wgRequest, $wgStylePath, $wgUser;
     global $wgDevelEnvironment;
     $info = null;
     /**
      * check maybe something was posted
      */
     if ($wgRequest->wasPosted()) {
         switch ($this->mTab) {
             case "hubs":
                 $info = $this->doUpdateHubs($wgRequest);
                 break;
             case "domains":
                 $info = $this->doUpdateDomains($wgRequest);
                 break;
             case "tags":
                 $info = $this->doUpdateTags($wgRequest);
                 break;
             case "findtags":
                 #we have 2 things that post from this page :(
                 if ($wgRequest->getVal('wpSearchTag') != null) {
                     $this->mSearchTag = $wgRequest->getVal('wpSearchTag');
                     $info = $this->doSearchTags($this->mSearchTag);
                 }
                 $this->mRemoveTag = $wgRequest->getVal('remove_tag');
                 $this->mRemoveTags = $wgRequest->getIntArray('remove_tag_id');
                 if ($this->mRemoveTag != null && $this->mRemoveTags != null) {
                     $info = $this->doMultiRemoveTags();
                 }
                 break;
             case "masstags":
                 $this->mMassTag = $wgRequest->getVal('wpMassTag');
                 $this->mMassTagWikis = $wgRequest->getVal('wfMassTagWikis');
                 if ($this->mMassTag != null && $this->mMassTagWikis != null) {
                     $info = $this->doMassTag();
                 } else {
                     if ($this->mMassTag == null) {
                         $info = Wikia::errorbox('missing tag to apply to wikis');
                     }
                     if ($this->mMassTagWikis == null) {
                         $info = Wikia::errorbox('missing wikis to apply tag to');
                     }
                 }
                 break;
             case "ezsharedupload":
                 if ($wgRequest->getVal('ezsuSave') != null) {
                     $info = $this->doSharedUploadEnable($wgRequest);
                 }
                 break;
             case "google":
                 if ($wgRequest->getVal('wt-add-site')) {
                     $this->doAddToWebmasterTools();
                 } else {
                     if ($wgRequest->getVal('wt-rem-site')) {
                         $this->doRemoveFromWebmasterTools();
                     } else {
                         if ($wgRequest->getVal('wt-verify-site')) {
                             $this->doVerifyWithWebmasterTools();
                         } else {
                             if ($wgRequest->getVal('wt-add-verify-site')) {
                                 if ($this->doAddToWebmasterTools()) {
                                     $this->doVerifyWithWebmasterTools();
                                 }
                             }
                         }
                     }
                 }
                 break;
         }
         wfRunHooks('WikiFactory::onPostChangesApplied', array($this->mWiki->city_id));
     } else {
         /**
          * maybe some other action but with GET not POST
          */
         switch ($this->mTab) {
             case "tags":
                 $tag_id = $wgRequest->getVal("wpTagId", false);
                 if ($tag_id) {
                     $info = $this->doUpdateTags($wgRequest, $tag_id);
                 }
                 break;
             case "findtags":
                 if (!empty($this->mSearchTag)) {
                     $info = $this->doSearchTags($this->mSearchTag);
                 }
                 break;
         }
     }
     $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
     $vars = array("tab" => $this->mTab, "hub" => WikiFactoryHub::getInstance(), "wiki" => $this->mWiki, "tags" => $this->mTags->getTags(), "info" => $info, "title" => $this->mTitle, "groups" => WikiFactory::getGroups(), "cluster" => WikiFactory::getVarValueByName("wgDBcluster", $this->mWiki->city_id), "domains" => WikiFactory::getDomains($this->mWiki->city_id), "protected" => WikiFactory::getFlags($this->mWiki->city_id) & WikiFactory::FLAG_PROTECTED, "statuses" => $this->mStatuses, "variables" => WikiFactory::getVariables(), "variableName" => $this->mVariableName, "isDevel" => $wgDevelEnvironment, 'wikiFactoryUrl' => Title::makeTitle(NS_SPECIAL, 'WikiFactory')->getFullUrl(), 'wgStylePath' => $wgStylePath);
     if ($this->mTab === 'info') {
         $vars['founder_id'] = $this->mWiki->city_founding_user;
         #this is the static stored email
         $vars['founder_email'] = $this->mWiki->city_founding_email;
         if (!empty($this->mWiki->city_founding_user)) {
             #if we knew who they were, get their current info
             $fu = User::newFromId($this->mWiki->city_founding_user);
             $vars['founder_username'] = $fu->getName();
             $vars['founder_usermail'] = $fu->getEmail();
             $vars['founder_metrics_url'] = $vars['wikiFactoryUrl'] . "/Metrics?founder=" . rawurlencode($fu->getName());
             $vars['founder_usermail_metrics_url'] = $vars['wikiFactoryUrl'] . "/Metrics?email=" . urlencode($vars['founder_usermail']);
             $vars['founder_email_metrics_url'] = $vars['wikiFactoryUrl'] . "/Metrics?email=" . urlencode($vars['founder_email']);
         } else {
             #dont know who made the wiki, so dont try to do lookups
             $vars['founder_username'] = null;
             $vars['founder_usermail'] = null;
         }
         if ($wgUser->isAllowed('lookupuser')) {
             $vars['lookupuser_by_founder_email_url'] = Title::newFromText("LookupUser", NS_SPECIAL)->getFullURL(array("target" => $vars['founder_email']));
             if (!empty($vars['founder_username'])) {
                 $vars['lookupuser_by_founder_username_url'] = Title::newFromText("LookupUser", NS_SPECIAL)->getFullURL(array("target" => $vars['founder_username']));
             }
             if (!empty($vars['founder_usermail'])) {
                 $vars['lookupuser_by_founder_usermail_url'] = Title::newFromText("LookupUser", NS_SPECIAL)->getFullURL(array("target" => $vars['founder_usermail']));
             }
         }
     }
     if ($this->mTab === "tags" || $this->mTab === "findtags") {
         $vars['searchTag'] = $this->mSearchTag;
         $vars['searchTagWikiIds'] = $this->mTagWikiIds;
     }
     if ($this->mTab === "hubs") {
         $hub = WikiFactoryHub::getInstance();
         $vars['vertical_id'] = $hub->getVerticalId($this->mWiki->city_id);
         $vars['verticals'] = $hub->getAllVerticals();
         $wiki_old_categories = $hub->getWikiCategories($this->mWiki->city_id, false);
         $wiki_new_categories = $hub->getWikiCategories($this->mWiki->city_id, true);
         $wiki_categories = array_merge($wiki_old_categories, $wiki_new_categories);
         $wiki_cat_ids = array();
         foreach ($wiki_categories as $cat) {
             $wiki_cat_ids[] = $cat['cat_id'];
         }
         $vars['wiki_categoryids'] = $wiki_cat_ids;
         $all_old_categories = $hub->getAllCategories(false);
         $all_new_categories = $hub->getAllCategories(true);
         $all_categories = array_replace($all_old_categories, $all_new_categories);
         $vars['all_categories'] = $all_categories;
     }
     if ($this->mTab === "clog") {
         $pager = new ChangeLogPager($this->mWiki->city_id);
         $vars["changelog"] = array("limit" => $pager->getForm(), "body" => $pager->getBody(), "nav" => $pager->getNavigationBar());
     }
     if ($this->mTab === "google") {
         global $wgGoogleWebToolsAccts;
         $api = new WebmasterToolsAPI('', '', $this->mWiki);
         $info = $api->site_info();
         $vars["google"] = array("info" => $info, "accounts" => $wgGoogleWebToolsAccts, "api" => $api);
     }
     if ($this->mTab === "ezsharedupload") {
         global $wgServer;
         $vars["EZSharedUpload"] = array("active" => WikiFactory::getVarValueByName("wgUseSharedUploads", $this->mWiki->city_id), "varTitle" => Title::makeTitle(NS_SPECIAL, 'WikiFactory')->getFullUrl() . ("/" . $this->mWiki->city_id . "/variables/"), "info" => isset($info) ? $info : "", "local" => array("wgServer" => $this->mWiki->city_url, "wgSharedUploadDBname" => WikiFactory::getVarValueByName("wgSharedUploadDBname", $this->mWiki->city_id), "wgSharedUploadDirectory" => WikiFactory::getVarValueByName("wgSharedUploadDirectory", $this->mWiki->city_id), "wgSharedUploadPath" => WikiFactory::getVarValueByName("wgSharedUploadPath", $this->mWiki->city_id), "wgRepositoryBaseUrl" => WikiFactory::getVarValueByName("wgRepositoryBaseUrl", $this->mWiki->city_id), "wgFetchCommonsDescriptions" => WikiFactory::getVarValueByName("wgFetchCommonsDescriptions", $this->mWiki->city_id)), "remote" => array("wikiId" => 0, "wgServer" => "", "wgDBname" => "", "wgUploadDirectory" => "", "wgUploadPath" => "", "baseUrl" => ""));
         if ($wgRequest->wasPosted() && $wgRequest->getVal("ezsuWikiId")) {
             $ezsuRemoteWikiId = $wgRequest->getVal("ezsuWikiId");
             $vars["EZSharedUpload"]["remote"] = array("wikiId" => $ezsuRemoteWikiId, "wgServer" => WikiFactory::getVarValueByName("wgServer", $ezsuRemoteWikiId), "wgDBname" => WikiFactory::getVarValueByName("wgDBname", $ezsuRemoteWikiId), "wgUploadDirectory" => WikiFactory::getVarValueByName("wgUploadDirectory", $ezsuRemoteWikiId), "wgUploadPath" => WikiFactory::getVarValueByName("wgUploadPath", $ezsuRemoteWikiId), "baseUrl" => WikiFactory::getVarValueByName("wgServer", $ezsuRemoteWikiId) . WikiFactory::getVarValueByName("wgScriptPath", $ezsuRemoteWikiId) . str_replace('$1', 'File:', WikiFactory::getVarValueByName("wgArticlePath", $ezsuRemoteWikiId)));
         }
     }
     $oTmpl->set_vars($vars);
     $wgOut->addHTML($oTmpl->render("form"));
 }