/**
  * Enqueue a task to rebuild the special pages localization cache
  *
  * @param string $wikiaDomain The domain name of the wikia in need of a cache rebuild
  * @return string Generated task ID for the rebuild task
  * @throws \InvalidArgumentException
  */
 public function enqueue($wikiaDomain)
 {
     $wikiaDomain = \Wikia::fixDomainName($wikiaDomain);
     $wikiId = \WikiFactory::DomainToID($wikiaDomain);
     if (!$wikiId) {
         // TODO localize?
         throw new \InvalidArgumentException("No wikia exists for domain {$wikiaDomain}");
     }
     $localizationTask = new UpdateSpecialPagesTask();
     $localizationTask->wikiId($wikiId);
     $localizationTask->call('rebuildLocalizationCache');
     return $localizationTask->queue();
 }
Ejemplo n.º 2
0
 /**
  * getDomainsLikeOrExact
  *
  * check if name is similar or the same, using sql like queries
  *
  * @access public
  * @author Krzysztof Krzyżaniak <*****@*****.**>
  *
  * @param string $name: name to check
  * @param string $language default null - choosen language
  * @param mixed  $type type of domain, default false = wikia.com
  *
  * @return array with matches
  */
 public static function getDomainsLikeOrExact($name, $language = null, $type = false)
 {
     global $wgExternalSharedDB;
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     $domains = array();
     $unique = array();
     $name = self::deleteCommonPostfix($name);
     $condition = $conditionSimilar = "";
     /**
      * don't check short names
      */
     if (strlen($name) > 3) {
         $names = explode(" ", $name);
         $skip = false;
         $tmp_array = array();
         if (is_array($names)) {
             foreach ($names as $n) {
                 if (!preg_match("/^[\\w\\.]+\$/", $n)) {
                     continue;
                 }
                 $sDomain = Wikia::fixDomainName($n, $language, $type);
                 $tmp_array['exact'][] = "city_domain = '{$sDomain}'";
                 $n = strtr($n, '0123456789-', '%%%%%%%%%%%%');
                 if (empty($type)) {
                     $tmp_array['similar'][] = "city_domain like '%{$n}%'";
                 } else {
                     switch ($type) {
                         case "answers":
                             $__domains = Wikia::getAnswersDomains();
                             if ($__domains && $language && isset($__domains[$language])) {
                                 $likeName = $__domains[$language];
                             } elseif ($__domains && isset($__domains["default"])) {
                                 $likeName = $__domains["default"];
                             }
                             if ($likeName) {
                                 $tmp_array['similar'][] = "city_domain like '%{$n}.{$likeName}%'";
                             }
                             $tmp_array['similar'][] = "city_domain like '%{$n}.{$type}%'";
                             break;
                         default:
                             $tmp_array['similar'][] = "city_domain like '%{$n}.{$type}%'";
                     }
                 }
             }
             if (sizeof($tmp_array)) {
                 $condition = implode(" or ", $tmp_array['exact']);
                 $conditionSimilar = implode(" or ", $tmp_array['similar']);
             } else {
                 $skip = true;
             }
         } else {
             $sDomain = Wikia::fixDomainName($name, $language, $type);
             $condition = "city_domain = '{$sDomain}'";
             $conditionSimilar = empty($type) ? "city_domain like '%{$name}%'" : "city_domain like '%{$name}.{$type}%'";
         }
         $conditionLanguage = "";
         if ($skip === false) {
             #--- exact (but with language prefixes)
             list($city_domains, $city_list) = array("city_domains", "city_list");
             $oRes = $dbr->select(array($city_domains, $city_list), array("*"), array($condition, "{$city_domains}.city_id = {$city_list}.city_id"), __METHOD__, array("LIMIT" => 20));
             while ($oRow = $dbr->fetchObject($oRes)) {
                 if (preg_match("/^www\\./", strtolower($oRow->city_domain))) {
                     continue;
                 }
                 if ($oRow->city_public == 1) {
                     $unique[strtolower($oRow->city_domain)] = 1;
                     $domains["exact"][] = $oRow;
                 } else {
                     $domains["closed"][] = $oRow;
                 }
             }
             $dbr->freeResult($oRes);
             if (!is_null($language)) {
                 $conditionLanguage = "city_lang = '{$language}'";
             }
             #--
             # Similar domains
             $oRes = $dbr->select(array($city_domains, $city_list), array("*"), array($conditionSimilar, "{$city_domains}.city_id = {$city_list}.city_id", $conditionLanguage), __METHOD__, array("LIMIT" => 20));
             while ($oRow = $dbr->fetchObject($oRes)) {
                 if (preg_match("/^www\\./", strtolower($oRow->city_domain))) {
                     continue;
                 }
                 if ($oRow->city_public == 1) {
                     if (array_key_exists(strtolower($oRow->city_domain), $unique) && $unique[strtolower($oRow->city_domain)] == 1) {
                         continue;
                     }
                     $domains["like"][] = $oRow;
                 } else {
                     $domains["closed"][] = $oRow;
                 }
             }
             $dbr->freeResult($oRes);
         }
     }
     return $domains;
 }
Ejemplo n.º 3
0
 static function normalizeName($name)
 {
     return Wikia::fixDomainName($name);
 }
Ejemplo n.º 4
0
 /**
  * submitForm
  * 
  * Creates the corresponding entry in the TaskManager queue.
  * 
  * @return boolean true
  * @access public
  */
 function submitForm()
 {
     global $wgOut, $wgUser, $wgRequest;
     $wikiDomain = Wikia::fixDomainName($wgRequest->getText('task-usp-wiki'));
     // check if the wiki exists
     $dbr = WikiFactory::db(DB_MASTER);
     $oRow = $dbr->selectRow(array('city_list', 'city_domains'), array('city_public', 'city_list.city_id'), array('city_list.city_id = city_domains.city_id', 'city_domain' => $wikiDomain), __METHOD__);
     if (empty($oRow->city_id) || 1 != $oRow->city_public) {
         return false;
     }
     $wikiId = $oRow->city_id;
     if (!empty($wikiId)) {
         $this->mTaskID = $this->createTask(array('wikiId' => $wikiId));
     }
     $wgOut->addHTML(Wikia::successbox('Task added'));
     return true;
 }