/**
  * @brief Helper function which determines whether to display the Admin Dashboard Chrome in the Oasis Skin
  * @param WikiaApp $app
  * @param Title $title Title of page we are on
  * @return boolean
  */
 public static function displayAdminDashboard($app, $title)
 {
     // Admin Dashboard is only for logged in plus a list of groups
     if (!$app->wg->User->isLoggedIn()) {
         return false;
     }
     if (!$app->wg->User->isAllowed('admindashboard')) {
         return false;
     }
     if ($title && $title->isSpecialPage()) {
         $bits = explode('/', $title->getDBkey(), 2);
         $alias = array_shift(SpecialPageFactory::resolveAlias($bits[0]));
         // NOTE: keep this list in alphabetical order
         static $exclusionList = array("AbTesting", "ApiExplorer", "ApiGate", "Chat", "CloseWiki", "Code", "Confirmemail", "Connect", "Contact", "Contributions", "CreateBlogPage", "CreatePage", "CreateNewWiki", "CreateTopList", "Crunchyroll", "EditAccount", "EditTopList", "Following", "Forum", "ImageReview", "Invalidateemail", "LandingPageSmurfs", "LayoutBuilder", "LayoutBuilderForm", "Leaderboard", "LookupContribs", "LookupUser", "ManageWikiaHome", "MiniEditor", "MovePage", "MultiLookup", "NewFiles", "Newimages", "Our404Handler", "PageLayoutBuilder", "PageLayoutBuilderForm", "Phalanx", "PhalanxStats", "PhotoPopSetup", "Places", "Play", "Preferences", "PromoteImageReview", "ScavengerHunt", "Search", "Signup", "SiteWideMessages", "SponsorshipDashboard", "StructuredData", "TaskManager", "ThemeDesigner", "ThemeDesignerPreview", "UserLogin", "UserManagement", "UserPathPrediction", "UserSignup", "Version", "Videos", "WhereIsExtension", "WikiActivity", "WikiaHubsV2", "WikiaSearch", "WikiaStyleGuide", "WikiFactory", "WikiFactoryReporter", "WikiStats");
         return !in_array($alias, $exclusionList);
     }
     return false;
 }
 /**
  * Takes a title and returns classes to apply to the body tag
  * @param Title $title
  * @return string
  */
 public function getPageClasses($title)
 {
     $className = $this->getMode();
     if ($title->isMainPage()) {
         $className .= ' page-Main_Page ';
     } elseif ($title->isSpecialPage()) {
         $className .= ' mw-mf-special ';
     }
     if ($this->isMobileMode) {
         $className .= ' mw-mobile-mode';
     } else {
         $className .= ' mw-desktop-mode';
     }
     if ($this->isAuthenticatedUser()) {
         $className .= ' is-authenticated';
     }
     return $className;
 }
Пример #3
0
 /**
  * Get the Title object or URL to use for a redirect. We use Title
  * objects for same-wiki, non-special redirects and URLs for everything
  * else.
  * @param Title $rt Redirect target
  * @return bool|Title|string False, Title object of local target, or string with URL
  */
 public function getRedirectURL($rt)
 {
     if (!$rt) {
         return false;
     }
     if ($rt->isExternal()) {
         if ($rt->isLocal()) {
             // Offsite wikis need an HTTP redirect.
             // This can be hard to reverse and may produce loops,
             // so they may be disabled in the site configuration.
             $source = $this->mTitle->getFullURL('redirect=no');
             return $rt->getFullURL(['rdfrom' => $source]);
         } else {
             // External pages without "local" bit set are not valid
             // redirect targets
             return false;
         }
     }
     if ($rt->isSpecialPage()) {
         // Gotta handle redirects to special pages differently:
         // Fill the HTTP response "Location" header and ignore the rest of the page we're on.
         // Some pages are not valid targets.
         if ($rt->isValidRedirectTarget()) {
             return $rt->getFullURL();
         } else {
             return false;
         }
     }
     return $rt;
 }
Пример #4
0
 /**
  * @param $title Title
  * @return Title
  */
 static function normaliseSpecialPage(Title $title)
 {
     if ($title->isSpecialPage()) {
         list($name, $subpage) = SpecialPageFactory::resolveAlias($title->getDBkey());
         if (!$name) {
             return $title;
         }
         $ret = SpecialPage::getTitleFor($name, $subpage);
         $ret->mFragment = $title->getFragment();
         return $ret;
     } else {
         return $title;
     }
 }
Пример #5
0
 /**
  * @todo Document
  * @param string $type
  * @param Language|null $lang
  * @param Title $title
  * @param array $params
  * @return string
  */
 protected static function getTitleLink($type, $lang, $title, &$params)
 {
     if (!$lang) {
         return $title->getPrefixedText();
     }
     if ($title->isSpecialPage()) {
         list($name, $par) = SpecialPageFactory::resolveAlias($title->getDBkey());
         # Use the language name for log titles, rather than Log/X
         if ($name == 'Log') {
             $logPage = new LogPage($par);
             $titleLink = Linker::link($title, $logPage->getName()->escaped());
             $titleLink = wfMessage('parentheses')->inLanguage($lang)->rawParams($titleLink)->escaped();
         } else {
             $titleLink = Linker::link($title);
         }
     } else {
         $titleLink = Linker::link($title);
     }
     return $titleLink;
 }
Пример #6
0
 /**
  * Handle redirects for uncanonical title requests.
  *
  * Handles:
  * - Redirect loops.
  * - No title in URL.
  * - $wgUsePathInfo URLs.
  * - URLs with a variant.
  * - Other non-standard URLs (as long as they have no extra query parameters).
  *
  * Behaviour:
  * - Normalise title values:
  *   /wiki/Foo%20Bar -> /wiki/Foo_Bar
  * - Normalise empty title:
  *   /wiki/ -> /wiki/Main
  *   /w/index.php?title= -> /wiki/Main
  * - Normalise non-standard title urls:
  *   /w/index.php?title=Foo_Bar -> /wiki/Foo_Bar
  * - Don't redirect anything with query parameters other than 'title' or 'action=view'.
  *
  * @param Title $title
  * @return bool True if a redirect was set.
  * @throws HttpError
  */
 private function tryNormaliseRedirect(Title $title)
 {
     $request = $this->context->getRequest();
     $output = $this->context->getOutput();
     if ($request->getVal('action', 'view') != 'view' || $request->wasPosted() || count($request->getValueNames(['action', 'title'])) || !Hooks::run('TestCanonicalRedirect', [$request, $title, $output])) {
         return false;
     }
     if ($title->isSpecialPage()) {
         list($name, $subpage) = SpecialPageFactory::resolveAlias($title->getDBkey());
         if ($name) {
             $title = SpecialPage::getTitleFor($name, $subpage);
         }
     }
     // Redirect to canonical url, make it a 301 to allow caching
     $targetUrl = wfExpandUrl($title->getFullURL(), PROTO_CURRENT);
     if ($targetUrl != $request->getFullRequestURL()) {
         $output->setCdnMaxage(1200);
         $output->redirect($targetUrl, '301');
         return true;
     }
     // If there is no title, or the title is in a non-standard encoding, we demand
     // a redirect. If cgi somehow changed the 'title' query to be non-standard while
     // the url is standard, the server is misconfigured.
     if ($request->getVal('title') === null || $title->getPrefixedDBkey() != $request->getVal('title')) {
         $message = "Redirect loop detected!\n\n" . "This means the wiki got confused about what page was " . "requested; this sometimes happens when moving a wiki " . "to a new server or changing the server configuration.\n\n";
         if ($this->config->get('UsePathInfo')) {
             $message .= "The wiki is trying to interpret the page " . "title from the URL path portion (PATH_INFO), which " . "sometimes fails depending on the web server. Try " . "setting \"\$wgUsePathInfo = false;\" in your " . "LocalSettings.php, or check that \$wgArticlePath " . "is correct.";
         } else {
             $message .= "Your web server was detected as possibly not " . "supporting URL path components (PATH_INFO) correctly; " . "check your LocalSettings.php for a customized " . "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . "to true.";
         }
         throw new HttpError(500, $message);
     }
     return false;
 }
Пример #7
0
 /**
  * TODO: document
  * @param Title $title
  * @return string
  */
 function getPageClasses($title)
 {
     $numeric = 'ns-' . $title->getNamespace();
     if ($title->isSpecialPage()) {
         $type = 'ns-special';
         // bug 23315: provide a class based on the canonical special page name without subpages
         list($canonicalName) = SpecialPageFactory::resolveAlias($title->getDBkey());
         if ($canonicalName) {
             $type .= ' ' . Sanitizer::escapeClass("mw-special-{$canonicalName}");
         } else {
             $type .= ' mw-invalidspecialpage';
         }
     } elseif ($title->isTalkPage()) {
         $type = 'ns-talk';
     } else {
         $type = 'ns-subject';
     }
     $name = Sanitizer::escapeClass('page-' . $title->getPrefixedText());
     return "{$numeric} {$type} {$name}";
 }
Пример #8
0
 /**
  * Check if the current page should be rendered using Venus
  *
  * @param Title $title
  * @return bool
  */
 public static function showVenusSkin(Title $title)
 {
     global $wgEnableVenusSkin, $wgEnableVenusSpecialSearch, $wgEnableVenusArticle, $wgRequest;
     $wrapper = new GlobalStateWrapper(['wgTitle' => $title]);
     $isSearch = false;
     $isArticlePage = false;
     $wrapper->wrap(function () use(&$isSearch, &$isArticlePage) {
         $isSearch = WikiaPageType::isSearch();
         $isArticlePage = WikiaPageType::isArticlePage();
     });
     $action = $wgRequest->getVal('action');
     $diff = $wgRequest->getVal('diff');
     $isSpecialSearch = $isSearch && $wgEnableVenusSpecialSearch;
     $isSpecialVenusTest = $title->isSpecialPage() && $title->getText() == 'VenusTest';
     $isVenusArticle = $isArticlePage && $wgEnableVenusArticle && (empty($action) || $action == 'view') && empty($diff);
     return $wgEnableVenusSkin && ($isSpecialSearch || $isSpecialVenusTest || $isVenusArticle);
 }
 /**
  * Creates MoreLinkThis View
  * @param Title $oTitle Current title object
  * @param string $sOrigin origin of request
  * @return View $oViewMlt MoreLikeThis view
  */
 public function getViewMoreLikeThis($oTitle)
 {
     $oViewMlt = new ViewMoreLikeThis();
     if ($oTitle->isSpecialPage()) {
         return $oViewMlt;
     }
     $oResults = $this->getMltData($oTitle);
     $aMlt = array();
     //$aMlt[] = implode( ', ', $oResults->interestingTerms );
     if ($oResults !== null && !empty($oResults->response->docs)) {
         foreach ($oResults->response->docs as $oRes) {
             if (count($aMlt) === 5) {
                 break;
             }
             $oMltTitle = $oRes->namespace != 999 ? Title::makeTitle($oRes->namespace, $oRes->title) : Title::makeTitle(NS_FILE, $oRes->title);
             if (!$oMltTitle->userCan('read') || $oMltTitle->getArticleID() === $oTitle->getArticleID() || $oMltTitle->isRedirect()) {
                 continue;
             }
             $sHtml = $oMltTitle->getPrefixedText();
             $aMlt[] = Linker::link($oMltTitle, $sHtml);
         }
     }
     if (empty($aMlt)) {
         $aMlt[] = wfMessage('bs-extendedsearch-no-mlt-found')->text();
     }
     $oViewMlt->setOption('mlt', $aMlt);
     return $oViewMlt;
 }