/** * @return CityVisualization */ protected function getVisualization() { if (empty($this->visualization)) { $this->visualization = F::build('CityVisualization'); } return $this->visualization; }
/** * @desc Uploads an image on a wki * * @static * @param string $imageUrl url address to original file * @param Object $oImageData an object with obligatory field "name" and optional fields: "comment", "description" * @param User | null $user optional User's class instance (the file will be "uploaded" by this user) * * @return array */ public static function uploadImageFromUrl($imageUrl, $oImageData, $user = null) { // disable recentchange hooks global $wgHooks; $wgHooks['RecentChange_save'] = array(); $wgHooks['RecentChange_beforeSave'] = array(); /* prepare temporary file */ $data = array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => $imageUrl); //validate of optional image data foreach (array(self::FILE_DATA_COMMENT_OPION_NAME, self::FILE_DATA_DESC_OPION_NAME) as $option) { if (!isset($oImageData->{$option})) { $oImageData->{$option} = $oImageData->name; } } $upload = F::build('UploadFromUrl'); /* @var $upload UploadFromUrl */ $upload->initializeFromRequest(F::build('FauxRequest', array($data, true))); $upload->fetchFile(); $upload->verifyUpload(); // create destination file $title = Title::newFromText($oImageData->name, NS_FILE); $file = F::build('WikiaLocalFile', array($title, RepoGroup::singleton()->getLocalRepo())); /* @var $file WikiaLocalFile */ /* real upload */ $result = $file->upload($upload->getTempPath(), $oImageData->comment, $oImageData->description, File::DELETE_SOURCE, false, false, $user); return array('status' => $result->ok, 'page_id' => $title->getArticleID(), 'errors' => $result->errors); }
/** * Load WelcomeBar front-end code for anonymous visitors only * * @param Skin $skin current skin object * @param string $text content of bottom scripts * @return boolean it't a hook */ public function onSkinAfterBottomScripts(Skin $skin, &$text) { if ($this->wg->User->isAnon()) { $text .= F::build('JSSnippets')->addToStack(array('/extensions/wikia/hacks/WelcomeBar/js/WelcomeBar.js'), array(), 'WelcomeBar.init'); } return true; }
public function init() { $this->privateData[] = 'foo'; $this->privateData[] = 'bar'; $this->privateData[] = 'baz'; $this->helper = F::build('HelloWorld', array('currentTitle' => $this->app->wg->Title)); }
public function getUrl() { wfProfileIn(__METHOD__); $title = F::build('title', array($this->getUser()->getName(), NS_USER_WALL), 'newFromText'); wfProfileOut(__METHOD__); return $title->getFullUrl(); }
public function getHTML() { wfProfileIn(__METHOD__); $this->report->loadSources(); $aData = array(); $aLabel = array(); if (count($this->report->reportSources) == 0) { return ''; } foreach ($this->report->reportSources as $reportSource) { $reportSource->getData(); $this->actualDate = $reportSource->actualDate; if (!empty($reportSource->dataAll) && !empty($reportSource->dataTitles)) { if (is_array($reportSource->dataAll)) { foreach ($reportSource->dataAll as $key => $val) { if (isset($aData[$key])) { $aData[$key] = array_merge($aData[$key], $val); } else { $aData[$key] = $val; } } } $aLabel += $reportSource->dataTitles; } } sort($aData); $this->sourceData = array_reverse($aData); $this->sourceLabels = array_reverse($aLabel); $oTmpl = F::build('EasyTemplate', array(dirname(__FILE__) . "/templates/")); /** @var $oTmpl EasyTemplate */ $oTmpl->set_vars(array('data' => $this->sourceData, 'labels' => $this->sourceLabels)); wfProfileOut(__METHOD__); $this->beforePrint(); return $oTmpl->render('../../templates/output/' . self::TEMPLATE_MAIN); }
/** * @param $requestedWidth * @param $requestedHeight * @param $originalWidth * @param $originalHeight * @param $expParams * @dataProvider testGetImageResizeParamsDataProvider */ public function testGetImageResizeParams($originalWidth, $originalHeight, $requestedWidth, $requestedHeight, $expParams) { /* @var $helper WikiaHomePageHelper */ $helper = F::build('WikiaHomePageHelper'); $params = $helper->getImageServingParamsForResize($requestedWidth, $requestedHeight, $originalWidth, $originalHeight); $this->assertEquals($expParams, $params); }
protected function setUp() { global $wgCityId; $this->wgCityId = $wgCityId; $this->setupFile = dirname(__FILE__) . '/../FounderProgressBar.setup.php'; parent::setUp(); // Mock response using $this->getValCallBack() $mockR = $this->getMock('WikiaResponse', array('getVal'), array('raw')); $mockR->expects($this->any())->method('getVal')->will($this->returnCallback(array($this, "getValCallback"))); $mock_result = $this->getMock('ResultWrapper', array(), array(), '', false); $this->mock_db = $this->getMock('DatabaseMysql', array('select', 'query', 'update', 'commit', 'fetchObject', 'fetchRow')); $this->mock_db->expects($this->any())->method('select')->will($this->returnValue($mock_result)); $this->mock_db->expects($this->any())->method('query'); $this->mock_db->expects($this->any())->method('update'); $this->mock_db->expects($this->any())->method('commit'); $cache = $this->getMock('stdClass', array('get', 'set', 'delete')); $cache->expects($this->any())->method('get')->will($this->returnValue(null)); $cache->expects($this->any())->method('set'); $cache->expects($this->any())->method('delete'); $mock = $this->getMock('FounderProgressBarController', array('sendSelfRequest', 'getDb', 'getMCache')); $mock->expects($this->any())->method('sendSelfRequest')->will($this->returnValue($mockR)); $mock->expects($this->any())->method('getDb')->will($this->returnValue($this->mock_db)); $mock->expects($this->any())->method('getMCache')->will($this->returnValue($cache)); F::setInstance("FounderProgressBarController", $mock); $this->object = F::build('FounderProgressBarController'); $this->task_id = 0; }
protected function getLocalFileLogic() { if (empty($this->oLocalFileLogic)) { $this->oLocalFileLogic = F::build('WikiaLocalFileShared', array($this)); } return $this->oLocalFileLogic; }
function ActivityFeedTag_render($content, $attributes, $parser, $frame) { global $wgExtensionsPath, $wgEnableAchievementsInActivityFeed, $wgEnableAchievementsExt; if (!class_exists('ActivityFeedHelper')) { return ''; } wfProfileIn(__METHOD__); $parameters = ActivityFeedHelper::parseParameters($attributes); $tagid = str_replace('.', '_', uniqid('activitytag_', true)); //jQuery might have a problem with . in ID $jsParams = "size={$parameters['maxElements']}"; if (!empty($parameters['includeNamespaces'])) { $jsParams .= "&ns={$parameters['includeNamespaces']}"; } if (!empty($parameters['flags'])) { $jsParams .= '&flags=' . implode('|', $parameters['flags']); } $parameters['tagid'] = $tagid; $feedHTML = ActivityFeedHelper::getList($parameters); $style = empty($parameters['style']) ? '' : ' style="' . $parameters['style'] . '"'; $timestamp = wfTimestampNow(); $snippetsDependencies = array('/extensions/wikia/MyHome/ActivityFeedTag.js', '/extensions/wikia/MyHome/ActivityFeedTag.css'); if (!empty($wgEnableAchievementsInActivityFeed) && !empty($wgEnableAchievementsExt)) { array_push($snippetsDependencies, '/extensions/wikia/AchievementsII/css/achievements_sidebar.css'); } $snippets = F::build('JSSnippets')->addToStack($snippetsDependencies, null, 'ActivityFeedTag.initActivityTag', array('tagid' => $tagid, 'jsParams' => $jsParams, 'timestamp' => $timestamp)); wfProfileOut(__METHOD__); return "<div{$style}>{$feedHTML}</div>{$snippets}"; }
public function setTitle($title) { $this->title = $title; $globalTitleObj = (array) F::build('GlobalTitle', array($this->title), 'explodeURL'); $this->setArticleName($globalTitleObj['articleName']); $this->setWikiId($globalTitleObj['wikiId']); }
/** * @brief Displays the main menu for the admin dashboard * */ public function index() { $this->wg->Out->setPageTitle(wfMsg('admindashboard-title')); if (!$this->wg->User->isAllowed('admindashboard')) { $this->displayRestrictionError(); return false; // skip rendering } $this->tab = $this->getVal('tab', 'general'); // links $this->urlThemeDesigner = Title::newFromText('ThemeDesigner', NS_SPECIAL)->getFullURL(); $this->urlRecentChanges = Title::newFromText('RecentChanges', NS_SPECIAL)->getFullURL(); $this->urlTopNavigation = Title::newFromText('Wiki-navigation', NS_MEDIAWIKI)->getFullURL('action=edit'); $this->urlWikiFeatures = Title::newFromText('WikiFeatures', NS_SPECIAL)->getFullURL(); $this->urlPageLayoutBuilder = Title::newFromText('PageLayoutBuilder', NS_SPECIAL)->getFullURL('action=list'); $this->urlListUsers = Title::newFromText('ListUsers', NS_SPECIAL)->getFullURL(); $this->urlUserRights = Title::newFromText('UserRights', NS_SPECIAL)->getFullURL(); $this->urlCommunityCorner = Title::newFromText('Community-corner', NS_MEDIAWIKI)->getFullURL('action=edit'); $this->urlAllCategories = Title::newFromText('Categories', NS_SPECIAL)->getFullURL(); $this->urlAddPage = Title::newFromText('CreatePage', NS_SPECIAL)->getFullURL(); $this->urlAddPhoto = Title::newFromText('Upload', NS_SPECIAL)->getFullURL(); $this->urlCreateBlogPage = Title::newFromText('CreateBlogPage', NS_SPECIAL)->getFullURL(); $this->urlMultipleUpload = Title::newFromText('MultipleUpload', NS_SPECIAL)->getFullURL(); $this->urlGetPromoted = Title::newFromText('Promote', NS_SPECIAL)->getFullURL(); // special:specialpages $this->advancedSection = (string) $this->app->sendRequest('AdminDashboardSpecialPage', 'getAdvancedSection', array()); // icon display logic $this->displayPageLayoutBuilder = !empty($this->wg->EnablePageLayoutBuilder); $this->displayWikiFeatures = !empty($this->wg->EnableWikiFeatures); $this->displaySpecialPromote = !empty($this->wg->EnableSpecialPromoteExt); // add messages package F::build('JSMessages')->enqueuePackage('AdminDashboard', JSMessages::INLINE); }
/** * Page Not Found * * Get 20 most recent edited page * get 5 images per page * * display random image on 404 page * example: * * Open non existent page on any wiki * */ function pageNotFound() { //setup all needed assets on 404 page /** * @var $out OutputPage */ $out = $this->request->getVal('out', $this->wg->Out); $assetManager = F::build('AssetsManager', array(), 'getInstance'); //add styles that belongs only to 404 page $styles = $assetManager->getURL(array('wikiamobile_404_scss')); //this is going to be additional call but at least it won't be loaded on every page foreach ($styles as $s) { $out->addStyle($s); } //this is mainly for tracking $scipts = $assetManager->getURL(array('wikiamobile_404_js')); foreach ($scipts as $s) { $out->addScript('<script src="' . $s . '"></script>'); } //suppress rendering stuff that is not to be on 404 page WikiaMobileFooterService::setSkipRendering(true); WikiaMobilePageHeaderService::setSkipRendering(true); /** * @var $wikiaMobileStatsModel WikiaMobileStatsModel */ $wikiaMobileStatsModel = F::build('WikiaMobileStatsModel'); $ret = $wikiaMobileStatsModel->getRandomPopularPage(); $this->response->setVal('title', $this->wg->Out->getTitle()); $this->response->setVal('link', $ret[0]); $this->response->setVal('img', $ret[1]); }
/** * add video * @requestParam integer articleId * @requestParam string url * @responseParam string html * @responseParam string error - error message */ public function addVideo() { if (!$this->wg->User->isLoggedIn()) { $this->error = $this->wf->Msg('videos-error-not-logged-in'); return; } $url = urldecode($this->getVal('url', '')); if (empty($url)) { $this->error = $this->wf->Msg('videos-error-no-video-url'); return; } if ($this->wg->User->isBlocked()) { $this->error = $this->wf->Msg('videos-error-blocked-user'); return; } $videoService = F::build('VideoService'); $retval = $videoService->addVideo($url); if (is_array($retval)) { $this->html = '<div></div>'; $this->error = null; } else { $this->html = null; $this->error = $retval; } }
public function index() { if (!$this->wg->User->isAllowed('gameguidescontent')) { $this->displayRestrictionError(); return false; // skip rendering } $title = $this->wf->Msg('wikiagameguides-content-title'); $this->wg->Out->setPageTitle($title); $this->wg->Out->setHTMLTitle($title); $this->wg->Out->addModules('jquery.autocomplete'); $assetManager = AssetsManager::getInstance(); $styles = $assetManager->getUrl('extensions/wikia/GameGuides/css/GameGuidesContentManagmentTool.scss'); foreach ($styles as $s) { $this->wg->Out->addStyle($s); } $scripts = $assetManager->getURL('extensions/wikia/GameGuides/js/GameGuidesContentManagmentTool.js'); foreach ($scripts as $s) { $this->wg->Out->addScriptFile($s); } F::build('JSMessages')->enqueuePackage('GameGuidesContentMsg', JSMessages::INLINE); $tags = WikiFactory::getVarValueByName('wgWikiaGameGuidesContent', $this->wg->CityId); $this->response->setVal('tags', $tags); return true; }
public function getData() { $inStartDate = $this->getVal('startDate', date('Y-m-d')); $inEndDate = $this->getVal('endDate', date('Y-m-d')); $inParam = $this->getVal('param', ''); $aAllOptions = array_merge($this->aAvailableLanguages, $this->aAvailableOtherOptions); $inParam = in_array($inParam, $aAllOptions) ? $inParam : ''; $startDate = DateTime::createFromFormat('Y-m-d', $inStartDate); $endDate = DateTime::createFromFormat('Y-m-d', $inEndDate); unset($inStartDate, $inEndDate); if (!$startDate || !$endDate) { $endDate = new DateTime(date('Y-m-d')); $endDate->sub(new DateInterval('P1D')); $startDate = clone $endDate; $startDate->sub(new DateInterval('P1M')); } $oOutput = F::build('SpecialNewWikisGraphOutput'); $oOutput->set($this->getReport($startDate, $endDate, $inParam)); $mOut = $oOutput->getRaw(); $this->setVal('chartId', $mOut->chartId); $this->setVal('datasets', $mOut->datasets); $this->setVal('fullTicks', $mOut->fullTicks); $this->setVal('hiddenSeries', $mOut->hiddenSeries); $this->setVal('monthly', $mOut->monthly); $this->setVal('ticks', $mOut->ticks); }
public function __construct($url, $login = '', $passwd = '', $HTTPProxy = null) { $this->setCurl(F::build('Curl', array('url' => $url))); $this->setLogin($login); $this->setPasswd($passwd); $this->setHTTPProxy($HTTPProxy); }
public function getWikiData($wikiId, $langCode) { $visualization = F::build('CityVisualization'); /** @var $visualization CityVisualization */ $wikiData = $visualization->getWikiDataForPromote($wikiId, $langCode); return $this->sanitizeWikiData($wikiData); }
public function getUserDetails() { if (is_null($this->usersData)) { $users = preg_split("/[\r\n]+/", $this->users); foreach ($users as $k => $v) { if (trim($v) == '') { unset($users[$k]); } } $users = array_values($users); foreach ($users as $k => $name) { $userName = User::isIP($name) ? $name : User::getCanonicalName($name); $user = null; if ($userName !== false) { $user = F::build('User', array($userName), 'newFromName'); if (empty($user) || $user->getId() == 0) { $user = null; } } $users[$k] = array('id' => !empty($user) ? $user->getId() : 0, 'ip' => User::isIP($name) ? $name : '', 'name' => $name, 'canonical' => $userName); } $this->usersData = $users; } return $this->usersData; }
public function uploadImage() { if (!$this->checkAccess()) { return false; } wfProfileIn(__METHOD__); $upload = F::build('UploadVisualizationImageFromFile'); $status = $this->helper->uploadImage($upload); $result = array(); if ($status['status'] === 'uploadattempted' && $status['isGood']) { $file = $upload->getLocalFile(); $result['uploadType'] = $this->request->getVal('uploadType'); $result['imageIndex'] = $this->request->getVal('imageIndex', null); if ($result['uploadType'] == 'additional') { $width = SpecialPromoteHelper::SMALL_IMAGE_WIDTH; $height = SpecialPromoteHelper::SMALL_IMAGE_HEIGHT; } else { $width = SpecialPromoteHelper::LARGE_IMAGE_WIDTH; $height = SpecialPromoteHelper::LARGE_IMAGE_HEIGHT; } $result['fileUrl'] = $this->helper->getImageUrl($file->getName(), $width, $height); $result['fileName'] = $file->getName(); if ($result['fileUrl'] == null || $result['fileName'] == null) { $result['errorMessages'] = array(wfMsg('promote-error-unknown-upload-error')); } } else { if ($status['status'] === 'error') { $result['errorMessages'] = $status['errors']; } } $this->result = $result; wfProfileOut(__METHOD__); }
public static function onWFAfterErrorDetection($cv_id, $city_id, $cv_name, $cv_value, &$return, &$error) { if (self::isWikiaBarConfig($city_id, $cv_name)) { /* @var $validator WikiaBarMessageDataValidator */ $validator = F::build('WikiaBarMessageDataValidator'); /* @var $model WikiaBarModel */ $model = F::build('WikiaBarModel'); $errorCount = 0; $errors = array(); if (is_array($cv_value)) { foreach ($cv_value as $vertical => $languages) { foreach ($languages as $language => $content) { $validator->clearErrors(); $model->parseBarConfigurationMessage(trim($content), $validator); $messageErrorCount = $validator->getErrorCount(); if ($messageErrorCount) { $errorMessages = $validator->getErrors(); foreach ($errorMessages as &$errorMessage) { $errorMessage = Wikia::errormsg('vertical: ' . $vertical . ', language: ' . $language . ' : ' . $errorMessage); } $errors = array_merge($errors, $errorMessages); $errorCount += $messageErrorCount; } } } } if ($errorCount) { $error = $errorCount; $return = trim(implode("<br/>", $errors)); } } return true; }
public function __construct() { parent::__construct(); //TODO: use Factory here //$this->setProvider(F::build('MysqlWikiaHubsV2SliderModuleDataProvider')); $this->setProvider(F::build('StaticWikiaHubsV2SliderModuleDataProvider')); }
/** * get video data from file * @param File $file * @param boolean $premiumOnly * @return array|null $video */ public function getVideoDataByFile($file, $premiumOnly = false) { $app = F::app(); $app->wf->ProfileIn(__METHOD__); $video = null; if ($file instanceof File && $file->exists() && F::build('WikiaFileHelper', array($file), 'isFileTypeVideo')) { if (!($premiumOnly && $file->isLocal())) { $fileMetadata = $file->getMetadata(); $userId = $file->getUser('id'); $addedAt = $file->getTimestamp() ? $file->getTimestamp() : $this->wf->Timestamp(TS_MW); $duration = 0; $hdfile = 0; if ($fileMetadata) { $fileMetadata = unserialize($fileMetadata); if (array_key_exists('duration', $fileMetadata)) { $duration = $fileMetadata['duration']; } if (array_key_exists('hd', $fileMetadata)) { $hdfile = $fileMetadata['hd'] ? 1 : 0; } } $premium = $file->isLocal() ? 0 : 1; $video = array('videoTitle' => $file->getTitle()->getDBKey(), 'addedAt' => $addedAt, 'addedBy' => $userId, 'duration' => $duration, 'premium' => $premium, 'hdfile' => $hdfile); } } $app->wf->ProfileOut(__METHOD__); return $video; }
/** * @param string $imageName * * @return bool|Title */ protected function getImageTitle($imageName) { $title = F::build('Title', array($imageName, NS_FILE), 'newFromText'); if (!$title instanceof Title) { return false; } return $title; }
function efSetupComboAjaxLogin() { wfProfileIn(__METHOD__); // register messages package for JS F::build('JSMessages')->registerPackage('ComboAjaxLogin', array('comboajaxlogin-ajaxerror')); wfProfileOut(__METHOD__); return true; }
/** * @param $url * @return array * @throws Exception */ protected function addVideoVideoHandlers($url) { $title = F::build('VideoFileUploader', array($url), 'URLtoTitle'); if (!$title) { throw new Exception($this->wf->Msg('videos-error-unknown', 876463)); } return array($title, $title->getArticleID(), null); }
/** * Returns instances of given metrics providers * * @param array $providers list of providers to get instance of * @return mixed array of PerformanceMetricsProvider instances */ public function getProviders(array $providers) { $instances = array(); foreach ($providers as $providerName) { $instances[] = F::build($providerName); } return $instances; }
public function testDispatchInternal() { //$app = $this->getMock( 'WikiaApp' ); $response = $this->object->dispatch(F::build('App'), new WikiaRequest(array('controller' => 'Test', 'method' => 'sendTest'))); $this->assertTrue($response->hasException()); $this->assertInstanceOf('WikiaException', $response->getException()); $this->assertEquals(WikiaResponse::RESPONSE_CODE_ERROR, $response->getCode()); }
public function testAddToStack() { F::unsetInstance('JSSnippets'); $instance = F::build('JSSnippets'); $snippet = $instance->addToStack(array('/extensions/wikia/Feature/js/Feature.js', '/extensions/wikia/Feature/css/Feature.css')); $this->assertEquals('<script>JSSnippetsStack.push({dependencies:["/extensions/wikia/Feature/js/Feature.js","/extensions/wikia/Feature/css/Feature.css"]})</script>', $snippet); $snippet = $instance->addToStack(array('/extensions/wikia/Feature/js/Feature.js'), array('$.loadJQueryUI'), 'Feature.init', array('foo' => 'bar')); $this->assertEquals('<script>JSSnippetsStack.push({dependencies:["/extensions/wikia/Feature/js/Feature.js"],getLoaders:function(){return [$.loadJQueryUI]},callback:function(json){Feature.init(json)},id:"Feature.init",options:{"foo":"bar"}})</script>', $snippet); }
public function testGooglePlusShareBox() { $googleplus = F::build('ShareButton', array('app' => $this->app, 'id' => 'GooglePlus'), 'factory'); $box = $googleplus->getShareBox(); $url = $this->app->wg->Title->getFullUrl(); $this->assertContains('class="g-plusone"', $box); $this->assertContains('data-size="tall"', $box); $this->assertContains('data-href="' . htmlspecialchars($url) . '"', $box); }