Ejemplo n.º 1
0
function fnForumIndexProtector(Title &$title, User &$user, $action, &$result)
{
    if ($user->isLoggedIn()) {
        #this doesnt apply to logged in users, bail, but keep going
        return true;
    }
    if ($action != 'edit' && $action != 'create') {
        #only kill editing actions (what else can anons even do?), bail, but keep going
        return true;
    }
    #this only applies to Forum:Index and Forum_talk:Index
    #check pagename
    if ($title->getText() != 'Index') {
        #wrong pagename, bail, but keep going
        return true;
    }
    $ns = $title->getNamespace();
    #check namespace(s)
    if ($ns == NS_FORUM || $ns == NS_FORUM_TALK) {
        #bingo bango, its a match!
        $result = array('protectedpagetext');
        Wikia::log(__METHOD__, __LINE__, "anon trying to edit forum:index, killing request");
        #bail, and stop the request
        return false;
    }
    return true;
}
	/**
	 * Invalidate the base pages for this title, so that any SubPageList
	 * there gets refreshed after doing a subpage delete, move or creation.
	 * 
	 * @since 0.3
	 * 
	 * @param Title $title
	 */
	protected static function invalidateBasePages( Title $title ) {
		global $egSPLAutorefresh;
		
		if ( !$egSPLAutorefresh ) {
			return;
		}
		
		$slashPosition = strpos( $title->getDBkey(), '/' );

		if ( $slashPosition !== false ) {
			$baseTitleText = substr( $title->getDBkey(), 0, $slashPosition );
			
			$titleArray = self::getBaseSubPages(
				$baseTitleText,
				$title->getNamespace()
			);
			
			foreach ( $titleArray as $parentTitle ) {
				// No point in invalidating the page itself
				if ( $parentTitle->getArticleID() != $title->getArticleID() ) {
					$parentTitle->invalidateCache();
				}
			}
			
			$baseTitle = Title::newFromText( $baseTitleText, $title->getNamespace() );
			if ( $baseTitle->getArticleID() != $title->getArticleID() ) {
				$baseTitle->invalidateCache();
			}					
		}
	}
Ejemplo n.º 3
0
	/**
	 * @param $title Title
	 * @param $repo ForeignApiRepo
	 * @return ForeignAPIFile|null
	 */
	static function newFromTitle( Title $title, $repo ) {
		$data = $repo->fetchImageQuery( array(
			'titles' => 'File:' . $title->getDBkey(),
			'iiprop' => self::getProps(),
			'prop' => 'imageinfo',
			'iimetadataversion' => MediaHandler::getMetadataVersion()
		) );

		$info = $repo->getImageInfo( $data );

		if ( $info ) {
			$lastRedirect = isset( $data['query']['redirects'] )
				? count( $data['query']['redirects'] ) - 1
				: -1;
			if ( $lastRedirect >= 0 ) {
				$newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to'] );
				$img = new self( $newtitle, $repo, $info, true );
				if ( $img ) {
					$img->redirectedFrom( $title->getDBkey() );
				}
			} else {
				$img = new self( $title, $repo, $info, true );
			}
			return $img;
		} else {
			return null;
		}
	}
Ejemplo n.º 4
0
 /**
  * Determine which FilePage to show based on skin and File type (image/video)
  *
  * @param Title $oTitle
  * @param Article $oArticle
  * @return bool true
  */
 public static function onArticleFromTitle(&$oTitle, &$oArticle)
 {
     if ($oTitle instanceof Title && $oTitle->getNamespace() == NS_FILE) {
         $oArticle = WikiaFileHelper::getMediaPage($oTitle);
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Checks if a given article has been fixed by a user
  * inside a productivity loop.
  * @param Title $title
  * @return bool
  */
 public function isItemFixed(Title $title)
 {
     if ($title->getArticleID() !== 0) {
         return $this->removeFixedItem(ucfirst(self::INSIGHT_TYPE), $title);
     }
     return false;
 }
 /**
  * Target URL for a link provided by a support button/aid.
  *
  * @param $title Title Title object for the translation message.
  * @since 2015.09
  */
 public static function getSupportUrl(Title $title)
 {
     global $wgTranslateSupportUrl, $wgTranslateSupportUrlNamespace;
     $namespace = $title->getNamespace();
     // Fetch the configuration for this namespace if possible, or the default.
     if (isset($wgTranslateSupportUrlNamespace[$namespace])) {
         $config = $wgTranslateSupportUrlNamespace[$namespace];
     } elseif ($wgTranslateSupportUrl) {
         $config = $wgTranslateSupportUrl;
     } else {
         throw new TranslationHelperException("Support page not configured");
     }
     // Preprocess params
     $params = array();
     if (isset($config['params'])) {
         foreach ($config['params'] as $key => $value) {
             $params[$key] = str_replace('%MESSAGE%', $title->getPrefixedText(), $value);
         }
     }
     // Return the URL or make one from the page
     if (isset($config['url'])) {
         return wfAppendQuery($config['url'], $params);
     } elseif (isset($config['page'])) {
         $page = Title::newFromText($config['page']);
         if (!$page) {
             throw new TranslationHelperException("Support page not configured properly");
         }
         return $page->getFullUrl($params);
     } else {
         throw new TranslationHelperException("Support page not configured properly");
     }
 }
Ejemplo n.º 7
0
	/**
	 * @param Title $title
	 * @return array of SisterSiteLink
	 */
	function siblings( $title ) {
		$normal = self::normalize( $title->getPrefixedText() );
		$dbr = wfGetDB( DB_SLAVE );
		$result = $dbr->select(
			array( 'sistersites_page', 'sistersites_site' ),
			array(
				'ssp_url',
				'ssp_title',
				'sss_name',
				'sss_interwiki',
			),
			array(
				'ssp_normalized_title' => $normal,
				'ssp_site=sss_id',
			),
			__METHOD__ );
		
		$out = array();
		while( $row = $dbr->fetchObject( $result ) ) {
			$out[] = new SisterSitesLink( $row );
		}
		
		$dbr->freeResult( $result );
		return $out;
	}
Ejemplo n.º 8
0
 public function fileCacheName()
 {
     if (!$this->mFileCache) {
         global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth;
         if ($wgFileCacheDirectory) {
             $dir = $wgFileCacheDirectory;
         } elseif ($wgCacheDirectory) {
             $dir = "{$wgCacheDirectory}/html";
         } else {
             throw new MWException('Please set $wgCacheDirectory in LocalSettings.php if you wish to use the HTML file cache');
         }
         # Store raw pages (like CSS hits) elsewhere
         $subdir = $this->mType === 'raw' ? 'raw/' : '';
         $key = $this->mTitle->getPrefixedDbkey();
         if ($wgFileCacheDepth > 0) {
             $hash = md5($key);
             for ($i = 1; $i <= $wgFileCacheDepth; $i++) {
                 $subdir .= substr($hash, 0, $i) . '/';
             }
         }
         # Avoid extension confusion
         $key = str_replace('.', '%2E', urlencode($key));
         $this->mFileCache = "{$dir}/{$subdir}{$key}.html";
         if ($this->useGzip()) {
             $this->mFileCache .= '.gz';
         }
         wfDebug(__METHOD__ . ": {$this->mFileCache}\n");
     }
     return $this->mFileCache;
 }
 /**
  * @since 1.9
  *
  * @return true
  */
 public function process()
 {
     $applicationFactory = ApplicationFactory::getInstance();
     // Delete all data for a non-enabled target NS
     if (!$applicationFactory->getNamespaceExaminer()->isSemanticEnabled($this->newTitle->getNamespace()) || $this->newId == 0) {
         $applicationFactory->getStore()->deleteSubject($this->oldTitle);
     } else {
         // Using a different approach since the hook is not triggered
         // by #REDIRECT which can cause inconsistencies
         // @see 2.3 / StoreUpdater
         //	$applicationFactory->getStore()->changeTitle(
         //		$this->oldTitle,
         //		$this->newTitle,
         //		$this->oldId,
         //		$this->newId
         //	);
     }
     $eventHandler = EventHandler::getInstance();
     $dispatchContext = $eventHandler->newDispatchContext();
     $dispatchContext->set('title', $this->oldTitle);
     $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     $dispatchContext = $eventHandler->newDispatchContext();
     $dispatchContext->set('title', $this->newTitle);
     $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Declares JSON as the code editor language for Schema: pages.
  * This hook only runs if the CodeEditor extension is enabled.
  * @param Title $title
  * @param string &$lang: Page language.
  * @return bool
  */
 static function onCodeEditorGetPageLanguage($title, &$lang)
 {
     if ($title->getNamespace() === NS_SCHEMA) {
         $lang = 'json';
     }
     return true;
 }
Ejemplo n.º 11
0
 private function watchTitle(Title $title, User $user, array $params, $compatibilityMode = false)
 {
     if (!$title->isWatchable()) {
         return array('title' => $title->getPrefixedText(), 'watchable' => 0);
     }
     $res = array('title' => $title->getPrefixedText());
     if ($params['unwatch']) {
         $status = UnwatchAction::doUnwatch($title, $user);
         $res['unwatched'] = $status->isOK();
         if ($status->isOK()) {
             $res['message'] = $this->msg('removedwatchtext', $title->getPrefixedText())->title($title)->parseAsBlock();
         }
     } else {
         $status = WatchAction::doWatch($title, $user);
         $res['watched'] = $status->isOK();
         if ($status->isOK()) {
             $res['message'] = $this->msg('addedwatchtext', $title->getPrefixedText())->title($title)->parseAsBlock();
         }
     }
     if (!$status->isOK()) {
         if ($compatibilityMode) {
             $this->dieStatus($status);
         }
         $res['error'] = $this->getErrorFromStatus($status);
     }
     return $res;
 }
Ejemplo n.º 12
0
 /**
  * Create a redirect that is also valid JavaScript
  *
  * @param Title $destination
  * @param string $text ignored
  * @return JavaScriptContent
  */
 public function makeRedirectContent(Title $destination, $text = '')
 {
     // The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi
     $url = $destination->getFullURL('action=raw&ctype=text/javascript', false, PROTO_RELATIVE);
     $class = $this->getContentClass();
     return new $class('/* #REDIRECT */' . Xml::encodeJsCall('mw.loader.load', [$url]));
 }
Ejemplo n.º 13
0
 protected function invalidateTitle(\Title $title)
 {
     global $wgParsoidCacheServers, $wgContentNamespaces;
     if (!in_array($title->getNamespace(), $wgContentNamespaces)) {
         return false;
     }
     # First request the new version
     $parsoidInfo = array();
     $parsoidInfo['cacheID'] = $title->getPreviousRevisionID($title->getLatestRevID());
     $parsoidInfo['changedTitle'] = $this->title->getPrefixedDBkey();
     $requests = array();
     foreach ($wgParsoidCacheServers as $server) {
         $singleUrl = $this->getParsoidURL($title);
         $requests[] = array('url' => $singleUrl, 'headers' => array('X-Parsoid: ' . json_encode($parsoidInfo), 'Cache-control: no-cache'));
         $this->wikiaLog(array("action" => "invalidateTitle", "get_url" => $singleUrl));
     }
     $this->checkCurlResults(\CurlMultiClient::request($requests));
     # And now purge the previous revision so that we make efficient use of
     # the Varnish cache space without relying on LRU. Since the URL
     # differs we can't use implicit refresh.
     $requests = array();
     foreach ($wgParsoidCacheServers as $server) {
         // @TODO: this triggers a getPreviousRevisionID() query per server
         $singleUrl = $this->getParsoidURL($title, true);
         $requests[] = array('url' => $singleUrl);
         $this->wikiaLog(array("action" => "invalidateTitle", "purge_url" => $singleUrl));
     }
     $options = \CurlMultiClient::getDefaultOptions();
     $options[CURLOPT_CUSTOMREQUEST] = "PURGE";
     return $this->checkCurlResults(\CurlMultiClient::request($requests, $options));
 }
 public function getExhibitionItems(Title $title)
 {
     wfProfileIn(__METHOD__);
     if (class_exists('CategoryDataService')) {
         $cacheKey = $this->getExhibitionItemsCacheKey($title->getText());
         $items = $this->wg->memc->get($cacheKey);
         if (!is_array($items)) {
             $exh = CategoryDataService::getMostVisited($title->getDBkey(), null, self::EXHIBITION_ITEMS_LIMIT);
             $ids = array_keys($exh);
             $length = count($ids);
             $items = array();
             for ($i = 0; $i < $length; $i++) {
                 $pageId = $ids[$i];
                 $imgRespnse = $this->app->sendRequest('ImageServing', 'index', array('ids' => array($pageId), 'height' => 150, 'width' => 150, 'count' => 1));
                 $img = $imgRespnse->getVal('result');
                 if (!empty($img[$pageId])) {
                     $img = $img[$pageId][0]['url'];
                 } else {
                     $img = false;
                 }
                 $oTitle = Title::newFromID($pageId);
                 $items[] = ['img' => $img, 'title' => $oTitle->getText(), 'url' => $oTitle->getFullURL()];
             }
             $this->wg->memc->set($cacheKey, $items, self::CACHE_TTL_EXHIBITION);
         }
         wfProfileOut(__METHOD__);
         return $items;
     }
     wfProfileOut(__METHOD__);
     return false;
 }
Ejemplo n.º 15
0
 /**
  * Make a "what links here" link for a given title
  *
  * @param Title $title Title to make the link for
  * @param Skin $skin Skin to use
  * @param object $result Result row
  * @return string
  */
 private function makeWlhLink($title, $skin, $result)
 {
     global $wgLang;
     $wlh = SpecialPage::getTitleFor('Whatlinkshere');
     $label = wfMsgExt('nlinks', array('parsemag', 'escape'), $wgLang->formatNum($result->value));
     return $skin->link($wlh, $label, array(), array('target' => $title->getPrefixedText()));
 }
 /**
  * @brief remove User:: from back link
  *
  * @author Tomek Odrobny
  *
  * @param Title $title
  * @param String $ptext
  *
  * @return Boolean
  */
 public static function onSkinSubPageSubtitleAfterTitle($title, &$ptext)
 {
     if (!empty($title) && $title->getNamespace() == NS_USER) {
         $ptext = $title->getText();
     }
     return true;
 }
Ejemplo n.º 17
0
 /**
  * Create a redirect that is also valid CSS
  *
  * @param Title $destination
  * @param string $text ignored
  * @return CssContent
  */
 public function makeRedirectContent(Title $destination, $text = '')
 {
     // The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi
     $url = $destination->getFullURL('action=raw&ctype=text/css', false, PROTO_RELATIVE);
     $class = $this->getContentClass();
     return new $class('/* #REDIRECT */@import ' . CSSMin::buildUrlValue($url) . ';');
 }
 /**
  * Deal with external interwiki links: add exitstitial class to them if needed
  *
  * @param $skin
  * @param $target
  * @param $options
  * @param $text
  * @param $attribs
  * @param $ret
  *
  * @return bool
  */
 public static function onLinkEnd($skin, Title $target, array $options, &$text, array &$attribs, &$ret)
 {
     if ($target->isExternal()) {
         static::handleExternalLink($attribs['href'], $attribs);
     }
     return true;
 }
Ejemplo n.º 19
0
 /**
  * Intercept pages in the Layer namespace to handle them correctly.
  *
  * @param $title: Title
  * @param $article: Article or null
  *
  * @return true
  */
 public static function onArticleFromTitle(Title &$title, &$article)
 {
     if ($title->getNamespace() == Maps_NS_LAYER) {
         $article = new MapsLayerPage($title);
     }
     return true;
 }
Ejemplo n.º 20
0
 /**
  * @param Title $Title
  * @param User $User
  * @param int $articleId
  * @param string $text
  */
 public function __construct($Title, $User, $articleId = 0, $text = '')
 {
     global $wgEnableBlogArticles;
     /**
      * initialization
      */
     $this->mPageNs = $Title->getNamespace();
     if (empty($articleId)) {
         $this->mPageId = $Title->getArticleID();
         if (empty($this->mPageId)) {
             $Title->getArticleID(Title::GAID_FOR_UPDATE);
         }
     } else {
         $this->setPageId($articleId);
     }
     if (is_object($User)) {
         $this->mUserId = intval($User->getID());
     } else {
         $this->mUserId = intval($User);
     }
     $this->mIsContent = $Title->isContentPage() && ($wgEnableBlogArticles && !in_array($this->mPageNs, array(NS_BLOG_ARTICLE, NS_BLOG_ARTICLE_TALK, NS_BLOG_LISTING, NS_BLOG_LISTING_TALK)));
     $this->mDate = date('Y-m-d');
     if ($text) {
         $this->mText = preg_replace('/\\[\\[[^\\:\\]]+\\:[^\\]]*\\]\\]/', '', $text);
     }
 }
Ejemplo n.º 21
0
 /**
  * Check if the page is sitemap page
  * @param Title $title
  * @return bool
  */
 public function isSitemapPage($title)
 {
     if (WikiaPageType::isCorporatePage() && $title->getDBkey() == self::SITEMAP_PAGE) {
         return true;
     }
     return false;
 }
 protected function placesForCategory(Title $oTitle)
 {
     $placesModel = F::build('PlacesModel');
     $categoryName = $oTitle->getText();
     $this->wg->Out->setPageTitle(wfMsg('places-in-category', $categoryName));
     return $placesModel->getFromCategories($categoryName);
 }
 /**
  * Only allow this content handler to be used in the Module namespace
  * @param Title $title
  * @return bool
  */
 public function canBeUsedOn(Title $title)
 {
     if ($title->getNamespace() !== NS_MODULE) {
         return false;
     }
     return parent::canBeUsedOn($title);
 }
 /**
  * set appropriate status code for deleted pages
  *
  * @author ADi
  * @param Title $title
  * @param Article $article
  * @return bool
  */
 public function onArticleFromTitle(&$title, &$article)
 {
     if (!$title->exists() && $title->isDeleted()) {
         F::app()->wg->Out->setStatusCode(SEOTweaksHooksHelper::DELETED_PAGES_STATUS_CODE);
     }
     return true;
 }
Ejemplo n.º 25
0
 /**
  * If requested title doesn't exist, redirect to duplicate title (same name but different case) if exists.
  * NOTE: As of MediaWiki 1.18.0, $article is NULL 
  * @param Title $title
  * @param type $article
  * @param type $output
  * @param type $user
  * @param type $request
  * @param type $mediaWiki
  * @return boolean 
  */
 public static function redirectDuplicate(&$title, $article, &$output, &$user, $request, $mediaWiki)
 {
     if ($title->getNamespace() != NS_SPECIAL && !$title->isKnown() && ($duplicate = TitleKey::exactMatchTitle($title))) {
         wfDebugLog('preventduplicate', "{$title->getPrefixedDBkey()} asked, doesn't exist, suggest to use {$duplicate->getPrefixedDBkey()} instead");
         $title = $duplicate;
     }
     return true;
 }
 /**
  * @deprecated since 1.24
  * @param int $pageid
  * @param Title $title
  * @param Revision $rev
  * @return bool|string
  */
 public static function getRollbackToken($pageid, $title, $rev)
 {
     global $wgUser;
     if (!$wgUser->isAllowed('rollback')) {
         return false;
     }
     return $wgUser->getEditToken(array($title->getPrefixedText(), $rev->getUserText()));
 }
Ejemplo n.º 27
0
 protected function getOutput()
 {
     $this->setBlock(false);
     return '<a
         ' . $this->getClass() . '
         ' . $this->getStyle() . '
         href="' . $this->title->getOutput() . '">' . $this->caption->getOutput() . '</a>';
 }
 /** @brief Allows to edit or not archived talk pages and its subpages
  *
  * @author Andrzej 'nAndy' Łukaszewski
  *
  * @param $pernErrors
  * @param Title $title
  *
  * @return boolean true -- because it's a hook
  */
 public function onAfterEditPermissionErrors($permErrors, $title, $removeArray)
 {
     $app = F::App();
     if (empty($app->wg->EnableWallExt) && ($title->getNamespace() == NS_USER_WALL || $title->getNamespace() == NS_USER_WALL_MESSAGE || $title->getNamespace() == NS_USER_WALL_MESSAGE_GREETING)) {
         $permErrors[] = array(0 => 'protectedpagetext', 1 => 'archived');
     }
     return true;
 }
Ejemplo n.º 29
0
 /**
  * Returns primary coordinates of the given page, if any
  * @param Title $title
  * @return Coord|false: Coordinates or false
  */
 public static function getPageCoordinates(Title $title)
 {
     $coords = self::getAllCoordinates($title->getArticleID(), array('gt_primary' => 1));
     if ($coords) {
         return $coords[0];
     }
     return false;
 }
Ejemplo n.º 30
0
/**
 * Add a link to Special:LookupUser from Special:Contributions/USERNAME
 * if the user has 'lookupuser' permission
 *
 * @param integer $id
 * @param Title $nt
 *
 * @return bool true
 */
function efLoadLookupUserLink($id, $nt, &$links)
{
    global $wgUser;
    if ($wgUser->isAllowed('lookupuser') && $id !== 0) {
        $links[] = Linker::linkKnown(SpecialPage::getTitleFor('LookupUser'), wfMsgHtml('lookupuser'), array(), array('target' => $nt->getText()));
    }
    return true;
}