Ejemplo n.º 1
0
	static function outputHook( $out, $parserOutput ) {
		global $wgUser;
		if ( isset( $parserOutput->spp_skin ) ) {
			$wgUser->mSkin =& Skin::newFromKey( $parserOutput->spp_skin );
		}
		return true;
	}
 function __construct()
 {
     //Some internal methods called from this controller need the skin to be wikiamobile
     //It makes sense to set it explicitly here as other skins shouldn't use it anyway
     RequestContext::getMain()->setSkin(Skin::newFromKey('wikiamobile'));
     parent::__construct();
 }
/**
 * Hook function for BeforePageDisplay
 */
function efSkinPerPageBeforePageDisplayHook( &$out, &$skin ){
	global $wgSkinPerNamespace, $wgSkinPerSpecialPage,
		$wgSkinPerNamespaceOverrideLoggedIn, $wgUser;

	if( !$wgSkinPerNamespaceOverrideLoggedIn && $wgUser->isLoggedIn() )
		return true;

	$title = $out->getTitle();
	$ns = $title->getNamespace();
	$skinName = null;

	if( $ns == NS_SPECIAL ) {
		list( $canonical, /* $subpage */ ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
		if( isset( $wgSkinPerSpecialPage[$canonical] ) ) {
			$skinName = $wgSkinPerSpecialPage[$canonical];
		}
	}

	if( $skinName === null && isset( $wgSkinPerNamespace[$ns] ) ) {
		$skinName = $wgSkinPerNamespace[$ns];
	}
	
	if( $skinName !== null ) {
		$skin = Skin::newFromKey( $skinName );
		$skin->setTitle( $out->getTitle() );
	}

	return true;
}
Ejemplo n.º 4
0
 public function testWikiaMobileUserProfilePageTemplate()
 {
     $mobileSkin = Skin::newFromKey('wikiamobile');
     $this->setUpMobileSkin($mobileSkin);
     $response = $this->app->sendRequest('UserProfilePage', 'index', array('format' => 'html'));
     $response->toString();
     $this->assertEquals(dirname($this->app->wg->AutoloadClasses['UserProfilePageController']) . '/templates/UserProfilePage_WikiaMobileIndex.php', $response->getView()->getTemplatePath());
     $this->tearDownMobileSkin();
 }
Ejemplo n.º 5
0
 /**
  * @group Slow
  * @slowExecutionTime 0.50775 ms
  */
 public function testWikiaMobileChangePasswordTemplate()
 {
     $mobileSkin = Skin::newFromKey('wikiamobile');
     $this->setUpMockObject('User', array('getSkin' => $mobileSkin), true, 'wgUser');
     $this->setUpMockObject('WebRequest', array('wasPosted' => true), false, 'wgRequest');
     $this->setUpMock();
     $this->setUpMobileSkin($mobileSkin);
     $response = $this->app->sendRequest('UserLoginSpecial', 'index', array('format' => 'html', 'action' => wfMessage('resetpass_submit')->escaped()));
     $response->toString();
     // triggers set up of template path
     $this->assertEquals(dirname($this->app->wg->AutoloadClasses['UserLoginSpecialController']) . '/templates/UserLoginSpecial_WikiaMobileChangePassword.php', $response->getView()->getTemplatePath());
     $this->tearDownMobileSkin();
 }
 /**
  * @brief this is a function that return rendered article
  *
  * @requestParam String title of a page
  */
 public function renderPage()
 {
     wfProfileIn(__METHOD__);
     $titleName = $this->request->getVal('page');
     $html = ApiService::call(array('action' => 'parse', 'page' => $titleName, 'prop' => 'text', 'redirects' => 1, 'useskin' => 'wikiamobile'));
     $this->response->setVal('globals', Skin::newFromKey('wikiamobile')->getTopScripts());
     $this->response->setVal('messages', JSMessages::getPackages(array('GameGuides')));
     $this->response->setVal('title', Title::newFromText($titleName)->getText());
     $this->response->setVal('html', $html['parse']['text']['*']);
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 7
0
 /**
  * Load a skin if it doesn't exist or return it
  * @todo FIXME : need to check the old failback system [AV]
  */
 function &getSkin()
 {
     global $IP, $wgRequest;
     if (!isset($this->mSkin)) {
         $fname = 'User::getSkin';
         wfProfileIn($fname);
         # get the user skin
         $userSkin = $this->getOption('skin');
         $userSkin = $wgRequest->getVal('useskin', $userSkin);
         $this->mSkin =& Skin::newFromKey($userSkin);
         wfProfileOut($fname);
     }
     return $this->mSkin;
 }
Ejemplo n.º 8
0
 /**
  * Load a skin if it doesn't exist or return it
  * @todo FIXME : need to check the old failback system [AV]
  */
 function &getSkin()
 {
     global $wgRequest;
     if (!isset($this->mSkin)) {
         wfProfileIn(__METHOD__);
         # get the user skin
         $userSkin = $this->getOption('skin');
         $userSkin = $wgRequest->getVal('useskin', $userSkin);
         $this->mSkin =& Skin::newFromKey($userSkin);
         wfProfileOut(__METHOD__);
     }
     return $this->mSkin;
 }
 public function getAsJson()
 {
     $articleId = $this->getRequest()->getInt(self::SIMPLE_JSON_ARTICLE_ID_PARAMETER_NAME, NULL);
     $articleTitle = $this->getRequest()->getVal(self::SIMPLE_JSON_ARTICLE_TITLE_PARAMETER_NAME, NULL);
     $redirect = $this->request->getVal('redirect');
     if (!empty($articleId) && !empty($articleTitle)) {
         throw new BadRequestApiException('Can\'t use id and title in the same request');
     }
     if (empty($articleId) && empty($articleTitle)) {
         throw new BadRequestApiException('You need to pass title or id of an article');
     }
     if (!empty($articleId)) {
         $article = Article::newFromID($articleId);
     } else {
         $title = Title::newFromText($articleTitle, NS_MAIN);
         if ($title instanceof Title && $title->exists()) {
             $article = Article::newFromTitle($title, RequestContext::getMain());
         }
     }
     if (empty($article)) {
         throw new NotFoundApiException("Unable to find any article");
     }
     if ($redirect !== 'no' && $article->getPage()->isRedirect()) {
         // false, Title object of local target or string with URL
         $followRedirect = $article->getPage()->followRedirect();
         if ($followRedirect && !is_string($followRedirect)) {
             $article = Article::newFromTitle($followRedirect, RequestContext::getMain());
         }
     }
     //Response is based on wikiamobile skin as this already removes inline style
     //and make response smaller
     RequestContext::getMain()->setSkin(Skin::newFromKey('wikiamobile'));
     global $wgArticleAsJson;
     $wgArticleAsJson = true;
     $parsedArticle = $article->getParserOutput();
     if ($parsedArticle instanceof ParserOutput) {
         $articleContent = json_decode($parsedArticle->getText());
     } else {
         throw new ArticleAsJsonParserException('Parser is currently not available');
     }
     $wgArticleAsJson = false;
     $categories = [];
     foreach (array_keys($parsedArticle->getCategories()) as $category) {
         $categoryTitle = Title::newFromText($category, NS_CATEGORY);
         if ($categoryTitle) {
             $categories[] = ['title' => $categoryTitle->getText(), 'url' => $categoryTitle->getLocalURL()];
         }
     }
     $result = ['content' => $articleContent->content, 'media' => $articleContent->media, 'users' => $articleContent->users, 'categories' => $categories];
     $this->setResponseData($result, '', self::SIMPLE_JSON_VARNISH_CACHE_EXPIRATION);
 }
 /**
  * Get the Skin object
  *
  * @return Skin
  */
 public function getSkin()
 {
     if ($this->skin === null) {
         wfProfileIn(__METHOD__ . '-createskin');
         $skin = null;
         wfRunHooks('RequestContextCreateSkin', array($this, &$skin));
         // If the hook worked try to set a skin from it
         if ($skin instanceof Skin) {
             $this->skin = $skin;
         } elseif (is_string($skin)) {
             $this->skin = Skin::newFromKey($skin);
         }
         // If this is still null (the hook didn't run or didn't work)
         // then go through the normal processing to load a skin
         if ($this->skin === null) {
             global $wgHiddenPrefs;
             if (!in_array('skin', $wgHiddenPrefs)) {
                 # get the user skin
                 $userSkin = $this->getUser()->getOption('skin');
                 $userSkin = $this->getRequest()->getVal('useskin', $userSkin);
             } else {
                 # if we're not allowing users to override, then use the default
                 global $wgDefaultSkin;
                 $userSkin = $wgDefaultSkin;
             }
             $this->skin = Skin::newFromKey($userSkin);
         }
         // After all that set a context on whatever skin got created
         $this->skin->setContext($this);
         wfProfileOut(__METHOD__ . '-createskin');
     }
     return $this->skin;
 }
Ejemplo n.º 11
0
 /**
  * Select proper skin and theme based on user preferences / default settings
  */
 public static function onGetSkin(RequestContext $context, &$skin)
 {
     global $wgDefaultSkin, $wgDefaultTheme, $wgSkinTheme, $wgForceSkin, $wgAdminSkin, $wgSkipSkins, $wgEnableAnswers;
     wfProfileIn(__METHOD__);
     $isOasisPublicBeta = $wgDefaultSkin == 'oasis';
     $request = $context->getRequest();
     $title = $context->getTitle();
     $user = $context->getUser();
     $useskin = $request->getVal('useskin', null);
     /**
      * check headers sent by varnish, if X-Skin is send force skin unless there is useskin param in url
      * @author eloy, requested by artur
      */
     if (is_null($useskin) && function_exists('apache_request_headers')) {
         $headers = apache_request_headers();
         if (isset($headers['X-Skin'])) {
             if (in_array($headers['X-Skin'], array('monobook', 'oasis', 'venus', 'wikia', 'wikiamobile', 'uncyclopedia'))) {
                 $skin = Skin::newFromKey($headers['X-Skin']);
                 // X-Skin header fallback for Mercury which is actually not a MediaWiki skin but a separate application
             } elseif ($headers['X-Skin'] === 'mercury') {
                 $skin = Skin::newFromKey('wikiamobile');
             }
             wfProfileOut(__METHOD__);
             return false;
         }
     }
     // useskin query param fallback for Mercury which is actually not a MediaWiki skin but a separate application
     if ($useskin === 'mercury') {
         $useskin = 'wikiamobile';
     }
     if (!$title instanceof Title || in_array(self::getUserOption('skin'), $wgSkipSkins)) {
         $skin = Skin::newFromKey(isset($wgDefaultSkin) ? $wgDefaultSkin : 'monobook');
         wfProfileOut(__METHOD__);
         return false;
     }
     // only allow useskin=wikia for beta & staff.
     if ($request->getVal('useskin') == 'wikia') {
         $request->setVal('useskin', 'oasis');
     }
     if (!empty($wgForceSkin)) {
         $wgForceSkin = $request->getVal('useskin', $wgForceSkin);
         $elems = explode('-', $wgForceSkin);
         $userSkin = array_key_exists(0, $elems) ? $elems[0] : null;
         $userTheme = array_key_exists(1, $elems) ? $elems[1] : null;
         $skin = Skin::newFromKey($userSkin);
         $skin->themename = $userTheme;
         self::log(__METHOD__, "forced skin to be {$wgForceSkin}");
         wfProfileOut(__METHOD__);
         return false;
     }
     # Get skin logic
     wfProfileIn(__METHOD__ . '::GetSkinLogic');
     if (!$user->isLoggedIn()) {
         # If user is not logged in
         if ($wgDefaultSkin == 'oasis') {
             $userSkin = $wgDefaultSkin;
             $userTheme = null;
         } else {
             if (!empty($wgAdminSkin) && !$isOasisPublicBeta) {
                 $adminSkinArray = explode('-', $wgAdminSkin);
                 $userSkin = isset($adminSkinArray[0]) ? $adminSkinArray[0] : null;
                 $userTheme = isset($adminSkinArray[1]) ? $adminSkinArray[1] : null;
             } else {
                 $userSkin = $wgDefaultSkin;
                 $userTheme = $wgDefaultTheme;
             }
         }
     } else {
         $userSkin = self::getUserOption('skin');
         $userTheme = self::getUserOption('theme');
         // RT:81173 Answers force hack.  It's in here because wgForceSkin is overwritten in CommonExtensions to '', most likely due to allowing admin skins and themes.  This will force answers and falls through to admin skin and theme logic if there is one.
         if (!empty($wgDefaultSkin) && $wgDefaultSkin == 'answers') {
             $userSkin = 'answers';
         }
         if (empty($userSkin)) {
             if (!empty($wgAdminSkin)) {
                 $adminSkinArray = explode('-', $wgAdminSkin);
                 $userSkin = isset($adminSkinArray[0]) ? $adminSkinArray[0] : null;
                 $userTheme = isset($adminSkinArray[1]) ? $adminSkinArray[1] : null;
             } else {
                 $userSkin = 'oasis';
             }
         } else {
             if (!empty($wgAdminSkin) && $userSkin != 'venus' && $userSkin != 'oasis' && $userSkin != 'monobook' && $userSkin != 'wowwiki' && $userSkin != 'lostbook') {
                 $adminSkinArray = explode('-', $wgAdminSkin);
                 $userSkin = isset($adminSkinArray[0]) ? $adminSkinArray[0] : null;
                 $userTheme = isset($adminSkinArray[1]) ? $adminSkinArray[1] : null;
             }
         }
     }
     wfProfileOut(__METHOD__ . '::GetSkinLogic');
     $chosenSkin = !is_null($useskin) ? $useskin : $userSkin;
     $elems = explode('-', $chosenSkin);
     $userSkin = array_key_exists(0, $elems) ? empty($wgEnableAnswers) && $elems[0] == 'answers' ? 'oasis' : $elems[0] : null;
     $userTheme = array_key_exists(1, $elems) ? $elems[1] : $userTheme;
     $userTheme = $request->getVal('usetheme', $userTheme);
     wfRunHooks('BeforeSkinLoad', [&$userSkin, $useskin, $title]);
     $skin = Skin::newFromKey($userSkin);
     $normalizedSkinName = substr(strtolower(get_class($skin)), 4);
     self::log(__METHOD__, "using skin {$normalizedSkinName}");
     # Normalize theme name and set it as a variable for skin object.
     if (isset($wgSkinTheme[$normalizedSkinName])) {
         wfProfileIn(__METHOD__ . '::NormalizeThemeName');
         if (!in_array($userTheme, $wgSkinTheme[$normalizedSkinName])) {
             if (in_array($wgDefaultTheme, $wgSkinTheme[$normalizedSkinName])) {
                 $userTheme = $wgDefaultTheme;
             } else {
                 $userTheme = $wgSkinTheme[$normalizedSkinName][0];
             }
         }
         $skin->themename = $userTheme;
         # force default theme on monaco and oasis when there is no admin setting
         if ($normalizedSkinName == 'oasis' && (empty($wgAdminSkin) && $isOasisPublicBeta)) {
             $skin->themename = $wgDefaultTheme;
         }
         self::log(__METHOD__, "using theme {$userTheme}");
         wfProfileOut(__METHOD__ . '::NormalizeThemeName');
     }
     // FIXME: add support for oasis themes
     if ($normalizedSkinName == 'oasis') {
         $skin->themename = $request->getVal('usetheme');
     }
     wfProfileOut(__METHOD__);
     return false;
 }
 /**
  * Renders the contents of a page of comments including post button/form and prev/next page
  * used in the WikiaMobile skin to deliver the first page of comments via AJAX and any page of comments for non-JS browsers
  *
  * @author Federico "Lox" Lucignano <federico(at)wikia-inc.com>
  **/
 public function executeWikiaMobileCommentsPage()
 {
     wfProfileIn(__METHOD__);
     $articleID = $this->request->getInt('articleID');
     $title = null;
     //set mobile skin as this is based on it
     RequestContext::getMain()->setSkin(Skin::newFromKey('wikiamobile'));
     if (!empty($articleID)) {
         $title = Title::newFromId($articleID);
     }
     if (!$title instanceof Title) {
         $title = $this->wg->title;
     }
     $this->getCommentsData($title, $this->wg->request->getInt('page', 1));
     if ($this->page > 1) {
         $this->response->setVal('prevPage', $this->page - 1);
     }
     if ($this->page < $this->pagesCount) {
         $this->response->setVal('nextPage', $this->page + 1);
     }
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 13
0
 /**
  * Parse provided wikitext to HTML using MW parser
  */
 public static function preview()
 {
     global $wgRequest;
     wfProfileIn(__METHOD__);
     $skin = $wgRequest->getVal('skin');
     if (!empty($skin)) {
         RequestContext::getMain()->setSkin(Skin::newFromKey($skin));
     }
     $res = self::resolveWikitextFromRequest('preview');
     // parse summary
     // DAR-2382 -- render edit summary the same way it's rendered on Special:WikiActivity and Special:RecentChanges
     $summary = $wgRequest->getText('summary');
     $summary = RequestContext::getMain()->getSkin()->formatComment($summary, false);
     if ($summary != '') {
         $res['summary'] = wfMessage('wikia-editor-preview-editSummary')->rawParams($summary)->parse();
     }
     wfProfileOut(__METHOD__);
     return $res;
 }
Ejemplo n.º 14
0
 /**
  * Get the current skin, loading it if required
  * @return \type{Skin} Current skin
  * @todo FIXME : need to check the old failback system [AV]
  */
 function &getSkin()
 {
     global $wgRequest, $wgAllowUserSkin, $wgDefaultSkin;
     if (!isset($this->mSkin)) {
         wfProfileIn(__METHOD__);
         if ($wgAllowUserSkin) {
             # get the user skin
             $userSkin = $this->getOption('skin');
             $userSkin = $wgRequest->getVal('useskin', $userSkin);
         } else {
             # if we're not allowing users to override, then use the default
             $userSkin = $wgDefaultSkin;
         }
         $this->mSkin =& Skin::newFromKey($userSkin);
         wfProfileOut(__METHOD__);
     }
     return $this->mSkin;
 }
 /**
  * function returns globals needed for an Article
  */
 public function getGlobals()
 {
     $wg = F::app()->wg;
     $skin = Skin::newFromKey('wikiamobile');
     //global variables
     //from Output class
     //and from ResourceLoaderStartUpModule
     $res = new ResourceVariablesGetter();
     $vars = array_intersect_key($wg->Out->getJSVars() + $res->get(), array_flip($wg->GameGuidesGlobalsWhiteList));
     $this->setVal('globals', WikiaSkin::makeInlineVariablesScript($vars) . $skin->getTopScripts());
 }
Ejemplo n.º 16
0
 /**
  * Get the Skin object
  *
  * @return Skin
  */
 public function getSkin()
 {
     if ($this->skin === null) {
         wfProfileIn(__METHOD__ . '-createskin');
         global $wgHiddenPrefs;
         if (!in_array('skin', $wgHiddenPrefs)) {
             # get the user skin
             $userSkin = $this->getUser()->getOption('skin');
             $userSkin = $this->getRequest()->getVal('useskin', $userSkin);
         } else {
             # if we're not allowing users to override, then use the default
             global $wgDefaultSkin;
             $userSkin = $wgDefaultSkin;
         }
         $this->skin = Skin::newFromKey($userSkin);
         $this->skin->setContext($this);
         wfProfileOut(__METHOD__ . '-createskin');
     }
     return $this->skin;
 }
Ejemplo n.º 17
0
 /**
  * Get the current skin, loading it if required, and setting a title
  * @param $t Title: the title to use in the skin
  * @return Skin The current skin
  * @todo FIXME : need to check the old failback system [AV]
  */
 function &getSkin($t = null)
 {
     if (!isset($this->mSkin)) {
         wfProfileIn(__METHOD__);
         global $wgHiddenPrefs;
         if (!in_array('skin', $wgHiddenPrefs)) {
             # get the user skin
             global $wgRequest;
             $userSkin = $this->getOption('skin');
             $userSkin = $wgRequest->getVal('useskin', $userSkin);
         } else {
             # if we're not allowing users to override, then use the default
             global $wgDefaultSkin;
             $userSkin = $wgDefaultSkin;
         }
         $this->mSkin =& Skin::newFromKey($userSkin);
         wfProfileOut(__METHOD__);
     }
     if ($t || !$this->mSkin->getTitle()) {
         if (!$t) {
             global $wgOut;
             $t = $wgOut->getTitle();
         }
         $this->mSkin->setTitle($t);
     }
     return $this->mSkin;
 }
Ejemplo n.º 18
0
 private function createSkinObject()
 {
     wfProfileIn(__METHOD__);
     global $wgHiddenPrefs;
     if (!in_array('skin', $wgHiddenPrefs)) {
         global $wgRequest;
         # get the user skin
         $userSkin = $this->getOption('skin');
         $userSkin = $wgRequest->getVal('useskin', $userSkin);
     } else {
         # if we're not allowing users to override, then use the default
         global $wgDefaultSkin;
         $userSkin = $wgDefaultSkin;
     }
     $skin = Skin::newFromKey($userSkin);
     wfProfileOut(__METHOD__);
     return $skin;
 }
 /**
  * @brief this is a function that return rendered article
  *
  * @requestParam String title of a page
  */
 public function renderPage()
 {
     wfProfileIn(__METHOD__);
     $titleName = $this->request->getVal('page');
     $html = ApiService::call(array('action' => 'parse', 'page' => $titleName, 'prop' => 'text', 'redirects' => 1, 'useskin' => 'wikiamobile'));
     $this->response->setVal('globals', Skin::newFromKey('wikiamobile')->getTopScripts());
     $this->response->setVal('messages', JSMessages::getPackages(array('CuratedContent')));
     $this->response->setVal('title', Title::newFromText($titleName)->getText());
     // TODO: Remove 'infoboxFixSectionReplace', it's temporary fix for mobile aps
     // See: DAT-2864 and DAT-2859
     $this->response->setVal('html', $this->infoboxFixSectionReplace($html['parse']['text']['*']));
     wfProfileOut(__METHOD__);
 }