/** * @group Slow * @slowExecutionTime 0.03205 ms */ function testCheckDomainIsCorrectDomainExists() { $this->getGlobalFunctionMock('wfMsg')->expects($this->exactly(1))->method('wfMsg')->with($this->equalTo('autocreatewiki-name-taken'))->will($this->returnValue('mocked-string')); $this->mockStaticMethod('AutoCreateWiki', 'checkBadWords', true); $this->mockStaticMethod('AutoCreateWiki', 'checkDomainExists', true); $this->mockStaticMethod('AutoCreateWiki', 'getLanguageNames', array('pl' => 'pl')); $result = AutoCreateWiki::checkDomainIsCorrect('woohooo', 'pl'); $this->assertEquals('mocked-string', $result); }
/** * Ajax call to validate domain. * Called via nirvana dispatcher */ public function CheckDomain() { wfProfileIn(__METHOD__); global $wgRequest; $name = $wgRequest->getVal('name'); $lang = $wgRequest->getVal('lang'); $type = $wgRequest->getVal('type'); $this->res = AutoCreateWiki::checkDomainIsCorrect($name, $lang, $type); wfProfileOut(__METHOD__); }
/** * check if domain is not taken or is creatable */ private function checkDomain() { global $wgUser; $status = 0; wfProfileIn(__METHOD__); if (strlen($this->mDomain) === 0) { // empty field $status = self::ERROR_DOMAIN_IS_EMPTY; } elseif (strlen($this->mDomain) < 3) { // too short $status = self::ERROR_DOMAIN_TOO_SHORT; } elseif (strlen($this->mDomain) > 50) { // too long $status = self::ERROR_DOMAIN_TOO_LONG; } elseif (preg_match('/[^a-z0-9-]/i', $this->mDomain)) { // invalid name $status = self::ERROR_DOMAIN_BAD_NAME; } elseif (in_array($this->mDomain, array_keys(Language::getLanguageNames()))) { // invalid name (name is used language) $status = self::ERROR_DOMAIN_POLICY_VIOLATIONS; } elseif (!$wgUser->isAllowed("staff") && AutoCreateWiki::checkBadWords($this->mDomain, "domain") === false) { // invalid name (bad words) $status = self::ERROR_DOMAIN_POLICY_VIOLATIONS; } else { if (AutoCreateWiki::domainExists($this->mDomain, $this->mLanguage)) { $status = self::ERROR_DOMAIN_NAME_TAKEN; } } wfProfileOut(__METHOD__); return $status; }
public static function checkDomainIsCorrect($sName, $sLang, $type = false) { global $wgUser; wfProfileIn(__METHOD__); $sResponse = ""; if (strlen($sName) === 0) { #-- empty field $sResponse = wfMsg('autocreatewiki-empty-field'); } elseif (strlen($sName) < 3) { #-- too short $sResponse = wfMsg('autocreatewiki-name-too-short'); } elseif (strlen($sName) > 50) { #-- too short $sResponse = wfMsg('autocreatewiki-name-too-long'); } elseif (preg_match('/[^a-z0-9-]/i', $sName)) { #-- invalid name $sResponse = wfMsg('autocreatewiki-bad-name'); } elseif (in_array($sName, array_keys(Language::getLanguageNames()))) { #-- invalid name $sResponse = wfMsg('autocreatewiki-violate-policy'); } elseif (!in_array('staff', $wgUser->getGroups()) && self::checkBadWords($sName, "domain") === false) { #-- invalid name (bad words) $sResponse = wfMsg('autocreatewiki-violate-policy'); } else { $iExists = AutoCreateWiki::domainExists($sName, $sLang, $type); if (!empty($iExists)) { #--- domain exists $sResponse = wfMsg('autocreatewiki-name-taken', !is_null($sLang) && $sLang != 'en' ? sprintf("%s.%s", $sLang, $sName) : $sName); } } wfProfileOut(__METHOD__); return $sResponse; }
/** * Ajax call for validate wiki name. */ public function CheckWikiName() { wfProfileIn(__METHOD__); $wgRequest = $this->wg->Request; $name = $wgRequest->getVal('name'); $lang = $wgRequest->getVal('lang'); $this->res = AutoCreateWiki::checkWikiNameIsCorrect($name, $lang); wfProfileOut(__METHOD__); }
function axACWRequestCheckLog() { $sInfo = ""; if (!empty($_SESSION) && isset($_SESSION['awcName'])) { $sInfo = AutoCreateWiki::logMemcKey("get", array('awcName' => $_SESSION['awcName'], 'awcDomain' => $_SESSION['awcDomain'], 'awcCategory' => $_SESSION['awcCategory'], 'awcLanguage' => $_SESSION['awcLanguage'])); } if (isset($sInfo)) { $aResponse = $sInfo; } else { $aResponse = array('type' => '', 'info' => wfMsg('autocreatewiki-stepdefault')); } return json_encode($aResponse); }
public static function checkDomainExists($sName, $sLang, $type) { return AutoCreateWiki::domainExists($sName, $sLang, $type); }
/** * set log to display info by js AJAX functions */ private function setInfoLog($msgType, $sInfo) { wfProfileIn(__METHOD__); $aParams = array('awcName' => $this->awcName, 'awcDomain' => $this->awcDomain, 'awcCategory' => $this->awcCategory, 'awcLanguage' => $this->awcLanguage); $aInfo = array('type' => $msgType, 'info' => $sInfo); $key = AutoCreateWiki::logMemcKey("set", $aParams, $aInfo); wfProfileOut(__METHOD__); return $key; }