コード例 #1
0
 /**
  * Show a global usage section on the image page
  *
  * @param object $imagePage The ImagePage
  * @param string $html HTML to add to the image page as global usage section
  * @return bool
  */
 public static function onImagePageAfterImageLinks($imagePage, &$html)
 {
     if (!self::hasResults($imagePage)) {
         return true;
     }
     $title = $imagePage->getFile()->getTitle();
     $targetName = $title->getText();
     $query = self::getImagePageQuery($title);
     $guHtml = '';
     foreach ($query->getSingleImageResult() as $wiki => $result) {
         $wikiName = WikiMap::getWikiName($wiki);
         $escWikiName = Sanitizer::escapeClass($wikiName);
         /* Wikia change begin */
         wfRunHooks('GlobalUsageImagePageWikiLink', array(&$wikiName));
         /* Wikia change end */
         $guHtml .= "<li class='mw-gu-onwiki-{$escWikiName}'>" . wfMsgExt('globalusage-on-wiki', 'parseinline', $targetName, $wikiName) . "\n<ul>";
         foreach ($result as $item) {
             $guHtml .= "\t<li>" . SpecialGlobalUsage::formatItem($item) . "</li>\n";
         }
         $guHtml .= "</ul></li>\n";
     }
     if ($guHtml) {
         $html .= '<h2 id="globalusage">' . wfMsgHtml('globalusage') . "</h2>\n" . '<div id="mw-imagepage-section-globalusage">' . wfMsgExt('globalusage-of-file', 'parse') . "<ul>\n" . $guHtml . "</ul>\n";
         if ($query->hasMore()) {
             $html .= wfMsgExt('globalusage-more', 'parse', $targetName);
         }
         $html .= '</div>';
     }
     return true;
 }
 protected function getLocalWikiLink($name, $wiki)
 {
     $text = "User:{$name}@{$wiki}";
     if ($this->plaintext) {
         return "[[{$text}]]";
     }
     return Message::rawParam(WikiMap::foreignUserLink($wiki, $name, $text));
 }
コード例 #3
0
ファイル: WikiMap.php プロジェクト: Tjorriemorrie/app
 /**
  * Convenience to get a url to a page on a foreign wiki
  *
  * @param $wikiID String: wiki'd id (generally database name)
  * @param $page String: page name (must be normalised before calling this function!)
  * @return String: URL or false if the wiki was not found
  */
 public static function getForeignURL($wikiID, $page)
 {
     $wiki = WikiMap::getWiki($wikiID);
     if ($wiki) {
         return $wiki->getUrl($page);
     }
     return false;
 }
コード例 #4
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
     if (!empty($pageIds[NS_FILE])) {
         # Create a query and set parameters
         $pageIds = $pageIds[NS_FILE];
         $query = new GlobalUsageQuery(array_keys($pageIds));
         if (!is_null($params['continue'])) {
             if (!$query->setOffset($params['continue'])) {
                 $this->dieUsage('Invalid continue parameter', 'badcontinue');
             }
         }
         $query->setLimit($params['limit']);
         $query->filterLocal($params['filterlocal']);
         # Execute the query
         $query->execute();
         # Create the result
         $apiResult = $this->getResult();
         foreach ($query->getResult() as $image => $wikis) {
             $pageId = intval($pageIds[$image]);
             foreach ($wikis as $wiki => $result) {
                 foreach ($result as $item) {
                     if ($item['namespace']) {
                         $title = "{$item['namespace']}:{$item['title']}";
                     } else {
                         $title = $item['title'];
                     }
                     $result = array('title' => $title, 'wiki' => WikiMap::getWikiName($wiki));
                     if (isset($prop['url'])) {
                         $result['url'] = WikiMap::getForeignUrl($item['wiki'], $title);
                     }
                     if (isset($prop['pageid'])) {
                         $result['pageid'] = $item['id'];
                     }
                     if (isset($prop['namespace'])) {
                         $result['ns'] = $item['namespace_id'];
                     }
                     $fit = $apiResult->addValue(array('query', 'pages', $pageId, 'globalusage'), null, $result);
                     if (!$fit) {
                         $continue = "{$item['image']}|{$item['wiki']}|{$item['id']}";
                         $this->setIndexedTagName();
                         $this->setContinueEnumParameter('continue', $continue);
                         return;
                     }
                 }
             }
         }
         $this->setIndexedTagName();
         if ($query->hasMore()) {
             $this->setContinueEnumParameter('continue', $query->getContinueString());
         }
     }
 }
コード例 #5
0
 protected function makePageLink(Title $title = null, $parameters = array())
 {
     global $wgContLang, $wgUserrightsInterwikiDelimiter;
     if (!$this->plaintext) {
         $text = $wgContLang->ucfirst($title->getText());
         $parts = explode($wgUserrightsInterwikiDelimiter, $text, 2);
         if (count($parts) === 2) {
             $titleLink = WikiMap::foreignUserLink($parts[1], $parts[0], htmlspecialchars($title->getPrefixedText()));
             if ($titleLink !== false) {
                 return $titleLink;
             }
         }
     }
     return parent::makePageLink($title, $parameters);
 }
コード例 #6
0
 /**
  * @param $row
  * @param $isListItem bool
  * @return String
  */
 function formatRow($row, $isListItem = true)
 {
     $user = $this->getUser();
     $lang = $this->getLanguage();
     $actionLinks = array();
     $title = Title::makeTitle($row->afl_namespace, $row->afl_title);
     $diffLink = false;
     if (self::isHidden($row) && !$this->canSeeHidden()) {
         return '';
     }
     if (!$row->afl_wiki) {
         $pageLink = Linker::link($title);
         if ($row->afl_rev_id) {
             $diffLink = Linker::link($title, wfMessage('abusefilter-log-diff')->parse(), array(), array('diff' => 'prev', 'oldid' => $row->afl_rev_id));
         }
     } else {
         $pageLink = WikiMap::makeForeignLink($row->afl_wiki, $row->afl_title);
         if ($row->afl_rev_id) {
             $diffUrl = WikiMap::getForeignURL($row->afl_wiki, $row->afl_title);
             $diffUrl = wfAppendQuery($diffUrl, array('diff' => 'prev', 'oldid' => $row->afl_rev_id));
             $diffLink = Linker::makeExternalLink($diffUrl, wfMessage('abusefilter-log-diff')->parse());
         }
     }
     if (!$row->afl_wiki) {
         // Local user
         $userLink = Linker::userLink($row->afl_user, $row->afl_user_text) . Linker::userToolLinks($row->afl_user, $row->afl_user_text, true);
     } else {
         $userLink = WikiMap::foreignUserLink($row->afl_wiki, $row->afl_user_text);
         $userLink .= ' (' . WikiMap::getWikiName($row->afl_wiki) . ')';
     }
     $timestamp = $lang->timeanddate($row->afl_timestamp, true);
     $actions_taken = $row->afl_actions;
     if (!strlen(trim($actions_taken))) {
         $actions_taken = $this->msg('abusefilter-log-noactions')->text();
     } else {
         $actions = explode(',', $actions_taken);
         $displayActions = array();
         foreach ($actions as $action) {
             $displayActions[] = AbuseFilter::getActionDisplay($action);
         }
         $actions_taken = $lang->commaList($displayActions);
     }
     $globalIndex = AbuseFilter::decodeGlobalName($row->afl_filter);
     if ($globalIndex) {
         // Pull global filter description
         $parsed_comments = $this->getOutput()->parseInline(AbuseFilter::getGlobalFilterDescription($globalIndex));
         $filter_hidden = null;
     } else {
         $parsed_comments = $this->getOutput()->parseInline($row->af_public_comments);
         $filter_hidden = $row->af_hidden;
     }
     if (self::canSeeDetails($row->afl_filter, $filter_hidden)) {
         if ($isListItem) {
             $detailsLink = Linker::linkKnown($this->getPageTitle($row->afl_id), $this->msg('abusefilter-log-detailslink')->escaped());
             $actionLinks[] = $detailsLink;
         }
         $examineTitle = SpecialPage::getTitleFor('AbuseFilter', 'examine/log/' . $row->afl_id);
         $examineLink = Linker::link($examineTitle, $this->msg('abusefilter-changeslist-examine')->parse(), array());
         $actionLinks[] = $examineLink;
         if ($diffLink) {
             $actionLinks[] = $diffLink;
         }
         if ($user->isAllowed('abusefilter-hide-log')) {
             $hideLink = Linker::link($this->getPageTitle(), $this->msg('abusefilter-log-hidelink')->text(), array(), array('hide' => $row->afl_id));
             $actionLinks[] = $hideLink;
         }
         if ($globalIndex) {
             global $wgAbuseFilterCentralDB;
             $globalURL = WikiMap::getForeignURL($wgAbuseFilterCentralDB, 'Special:AbuseFilter/' . $globalIndex);
             $linkText = wfMessage('abusefilter-log-detailedentry-global')->numParams($globalIndex)->escaped();
             $filterLink = Linker::makeExternalLink($globalURL, $linkText);
         } else {
             $title = SpecialPage::getTitleFor('AbuseFilter', $row->afl_filter);
             $linkText = wfMessage('abusefilter-log-detailedentry-local')->numParams($row->afl_filter)->escaped();
             $filterLink = Linker::link($title, $linkText);
         }
         $description = $this->msg('abusefilter-log-detailedentry-meta')->rawParams($timestamp, $userLink, $filterLink, $row->afl_action, $pageLink, $actions_taken, $parsed_comments, $lang->pipeList($actionLinks), $row->afl_user_text)->parse();
     } else {
         if ($diffLink) {
             $msg = 'abusefilter-log-entry-withdiff';
         } else {
             $msg = 'abusefilter-log-entry';
         }
         $description = $this->msg($msg)->rawParams($timestamp, $userLink, $row->afl_action, $pageLink, $actions_taken, $parsed_comments, $diffLink)->parse();
     }
     if (self::isHidden($row) === true) {
         $description .= ' ' . $this->msg('abusefilter-log-hidden')->parse();
         $class = 'afl-hidden';
     } elseif (self::isHidden($row) === 'implicit') {
         $description .= ' ' . $this->msg('abusefilter-log-hidden-implicit')->parse();
     }
     if ($isListItem) {
         return Xml::tags('li', isset($class) ? array('class' => $class) : null, $description);
     } else {
         return Xml::tags('span', isset($class) ? array('class' => $class) : null, $description);
     }
 }
コード例 #7
0
 /**
  * @param string $wikiID
  * @return string
  * @throws Exception
  */
 private function foreignUserLink($wikiID)
 {
     $wiki = WikiMap::getWiki($wikiID);
     if (!$wiki) {
         throw new Exception("Invalid wiki: {$wikiID}");
     }
     $wikiname = $wiki->getDisplayName();
     return self::foreignLink($wiki, MWNamespace::getCanonicalName(NS_USER) . ':' . $this->mUserName, $wikiname, $this->msg('centralauth-foreign-link', $this->mUserName, $wikiname)->text());
 }
 private function checkIsCentralWiki(&$wikiId)
 {
     if (wfWikiID() !== $this->loginWiki) {
         $this->doFinalOutput(false, 'Not central wiki');
         return false;
     }
     $wikiId = $this->getRequest()->getVal('wikiid');
     if ($wikiId === $this->loginWiki) {
         $this->doFinalOutput(false, 'Specified local wiki is the central wiki');
         return false;
     }
     $wiki = WikiMap::getWiki($wikiId);
     if (!$wiki) {
         $this->doFinalOutput(false, 'Specified local wiki not found');
         return false;
     }
     return true;
 }
コード例 #9
0
ファイル: WikiMapTest.php プロジェクト: rugby110/mediawiki
 /**
  * @dataProvider provideGetForeignURL
  */
 public function testGetForeignURL($expected, $wikiId, $page, $fragment = null)
 {
     $this->assertEquals($expected, WikiMap::getForeignURL($wikiId, $page, $fragment));
 }
コード例 #10
0
 /**
  * Build links to old version of the configuration
  */
 protected function buildOldVersionSelect()
 {
     global $wgConf;
     $count = 0;
     $links = array();
     $versions = $wgConf->getArchiveVersions(array('wiki' => $this->mWiki, 'limit' => 11));
     $title = $this->getTitle();
     $lang = $this->getLang();
     $prev = null;
     ksort($versions);
     ## Put in ascending order for now.
     foreach ($versions as $data) {
         $ts = $data['timestamp'];
         $count++;
         $datetime = $this->msg('configure-old-summary-datetime', $lang->timeanddate($ts), $lang->date($ts), $lang->time($ts))->escaped();
         $link = Linker::linkKnown($title, $datetime, array(), array('version' => $ts));
         $diffLink = '';
         if ($prev) {
             $diffLink = '(' . Linker::linkKnown(SpecialPage::getTitleFor('ViewConfig'), $this->msg('configure-old-changes')->escaped(), array(), array('version' => $ts, 'diff' => $prev)) . ')';
         }
         ## Make user link...
         $userLink = '';
         if (!$data['userwiki'] || !$data['username']) {
             $userLink = '';
             $username = '';
         } elseif ($data['userwiki'] == wfWikiId()) {
             $userLink = Linker::link(Title::makeTitle(NS_USER, $data['username']), htmlspecialchars($data['username']));
             $username = $data['username'];
         } elseif ($wiki = WikiMap::getWiki($data['userwiki'])) {
             $userLink = Linker::makeExternalLink($wiki->getUrl('User:'******'username']), htmlspecialchars($data['username'] . '@' . $data['userwiki']));
             $username = '';
         } else {
             ## Last-ditch
             $userLink = htmlspecialchars($data['username'] . '@' . $data['userwiki']);
             $username = '';
         }
         $comment = $data['reason'] ? Linker::commentBlock($data['reason']) : '';
         $text = $this->msg('configure-old-summary')->rawParams($link, $userLink, $diffLink, $comment)->params($username)->parse();
         $prev = $ts;
         $links[] = $text;
     }
     ## Reset into descending order
     $links = array_reverse($links);
     ## Take out the first ten...
     $links = array_slice($links, 0, 10);
     $text = Html::element('legend', null, $this->msg('configure-old')->text());
     if (!count($links)) {
         $text .= $this->msg('configure-no-old')->parseAsBlock();
     } else {
         $text .= $this->msg('configure-old-versions')->parseAsBlock();
         $text .= "<ul>\n<li>";
         $text .= implode("</li>\n<li>", $links);
         $text .= "</li>\n</ul>\n";
     }
     $link = SpecialPage::getTitleFor('ViewConfig');
     $text .= Html::rawElement('p', null, Linker::linkKnown($link, $this->msg('configure-view-all-versions')->escaped()));
     $text .= Html::rawElement('p', null, Linker::linkKnown($link, $this->msg('configure-view-default')->escaped(), array(), array('version' => 'default')));
     return Html::rawElement('fieldset', null, $text);
 }
コード例 #11
0
ファイル: WikiMap.php プロジェクト: claudinec/galan-wiki
 /**
  * Convenience to get a url to a page on a foreign wiki
  *
  * @param string $wikiID Wiki'd id (generally database name)
  * @param string $page Page name (must be normalised before calling this function!)
  * @param string|null $fragmentId
  *
  * @return string|bool URL or false if the wiki was not found
  */
 public static function getForeignURL($wikiID, $page, $fragmentId = null)
 {
     $wiki = WikiMap::getWiki($wikiID);
     if ($wiki) {
         return $wiki->getFullUrl($page, $fragmentId);
     }
     return false;
 }
コード例 #12
0
 /**
  * Unattach a list of local accounts from the global account
  * @param array $list List of wiki names
  * @return Status
  */
 public function adminUnattach($list)
 {
     if (!count($list)) {
         return Status::newFatal('centralauth-admin-none-selected');
     }
     $status = new Status();
     $valid = $this->validateList($list);
     $invalid = array_diff($list, $valid);
     foreach ($invalid as $wikiName) {
         $status->error('centralauth-invalid-wiki', $wikiName);
         $status->failCount++;
     }
     $dbcw = self::getCentralDB();
     $password = $this->getPassword();
     foreach ($valid as $wikiName) {
         # Delete the user from the central localuser table
         $dbcw->delete('localuser', array('lu_name' => $this->mName, 'lu_wiki' => $wikiName), __METHOD__);
         if (!$dbcw->affectedRows()) {
             $wiki = WikiMap::getWiki($wikiName);
             $status->error('centralauth-admin-already-unmerged', $wiki->getDisplayName());
             $status->failCount++;
             continue;
         }
         # Touch the local user row, update the password
         $lb = wfGetLB($wikiName);
         $dblw = $lb->getConnection(DB_MASTER, array(), $wikiName);
         $dblw->update('user', array('user_touched' => wfTimestampNow(), 'user_password' => $password), array('user_name' => $this->mName), __METHOD__);
         $id = $dblw->selectField('user', 'user_id', array('user_name' => $this->mName), __METHOD__);
         $this->clearLocalUserCache($wikiName, $id);
         $lb->reuseConnection($dblw);
         $status->successCount++;
     }
     if (in_array(wfWikiID(), $valid)) {
         $this->resetState();
     }
     $this->invalidateCache();
     return $status;
 }
コード例 #13
0
require( dirname(__FILE__).'/../cli.inc' );

$voters = array();
$batchSize = 1000;
$wikis = $wgLocalDatabases;

foreach ( $wikis as $wikiId ) {
	$lb = wfGetLB( $wikiId );
	$db = $lb->getConnection( DB_SLAVE, array(), $wikiId );

	if ( !$db->tableExists( 'securepoll_lists' ) ) {
		$lb->reuseConnection( $db );
		continue;
	}

	$wikiName = WikiMap::getWikiName( $wikiId );
	$userId = 0;
	while ( true ) {
		$res = $db->select(
			array( 'securepoll_lists', 'user' ),
			array( 'user_id', 'user_name', 'user_email', 'user_email_authenticated' ),
			array( 
				'user_id=li_member',
				'li_member > ' . $db->addQuotes( $userId )
			),
			__METHOD__,
			array( 'ORDER BY' => 'li_member', 'LIMIT' => $batchSize )
		);
		if ( !$res->numRows() ) {
			break;
		}
コード例 #14
0
 /**
  * Helper to format a specific item
  */
 public static function formatItem($item)
 {
     if (!$item['namespace']) {
         $page = $item['title'];
     } else {
         $page = "{$item['namespace']}:{$item['title']}";
     }
     /* Wikia change begin */
     $link = null;
     wfRunHooks('GlobalUsageFormatItemWikiLink', array($item, $page, &$link));
     if (is_null($link)) {
         $link = WikiMap::makeForeignLink($item['wiki'], $page, str_replace('_', ' ', $page));
     }
     /* Wikia change end */
     // Return only the title if no link can be constructed
     return $link === false ? $page : $link;
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $prop = array_flip((array) $params['prop']);
     if (is_null($params['user'])) {
         $params['user'] = $this->getUser()->getName();
     }
     $user = new CentralAuthUser($params['user']);
     // Add basic info
     $result = $this->getResult();
     $data = array();
     $userExists = $user->exists();
     if ($userExists && ($user->getHiddenLevel() === CentralAuthUser::HIDDEN_NONE || $this->getUser()->isAllowed('centralauth-oversight'))) {
         // The global user exists and it's not hidden or the current user is allowed to see it
         $data['home'] = $user->getHomeWiki();
         $data['id'] = $user->getId();
         $data['registration'] = wfTimestamp(TS_ISO_8601, $user->getRegistration());
         $data['name'] = $user->getName();
         if ($user->isLocked()) {
             $data['locked'] = '';
         }
         if ($user->isHidden()) {
             $data['hidden'] = '';
         }
     } else {
         // The user doesn't exist or we pretend it doesn't if it's hidden
         $data['missing'] = '';
     }
     $result->addValue('query', $this->getModuleName(), $data);
     // Add requested info
     if ($userExists && isset($prop['groups'])) {
         $groups = $user->getGlobalGroups();
         $result->setIndexedTagName($groups, 'g');
         $result->addValue(array('query', $this->getModuleName()), 'groups', $groups);
     }
     if ($userExists && isset($prop['rights'])) {
         $rights = $user->getGlobalRights();
         $result->setIndexedTagName($rights, 'r');
         $result->addValue(array('query', $this->getModuleName()), 'rights', $rights);
     }
     $attachedAccounts = null;
     if ($userExists && (isset($prop['merged']) || isset($prop['editcount']))) {
         $attachedAccounts = $user->queryAttached();
     }
     if ($userExists && isset($prop['merged'])) {
         foreach ($attachedAccounts as $account) {
             $dbname = $account['wiki'];
             $wiki = WikiMap::getWiki($dbname);
             $a = array('wiki' => $dbname, 'url' => $wiki->getCanonicalServer(), 'timestamp' => wfTimestamp(TS_ISO_8601, $account['attachedTimestamp']), 'method' => $account['attachedMethod'], 'editcount' => $account['editCount']);
             if ($account['blocked']) {
                 $a['blocked'] = array('expiry' => $this->getLanguage()->formatExpiry($account['block-expiry'], TS_ISO_8601), 'reason' => $account['block-reason']);
             }
             $result->addValue(array('query', $this->getModuleName(), 'merged'), null, $a);
         }
         if (defined('ApiResult::META_CONTENT')) {
             $result->addIndexedTagName(array('query', $this->getModuleName(), 'merged'), 'account');
         } else {
             $result->setIndexedTagName_internal(array('query', $this->getModuleName(), 'merged'), 'account');
         }
     }
     if ($userExists && isset($prop['editcount'])) {
         $editcount = 0;
         foreach ($attachedAccounts as $account) {
             $editcount += $account['editCount'];
         }
         $result->addValue('query', $this->getModuleName(), array('editcount' => $editcount));
     }
     if (isset($prop['unattached'])) {
         $accounts = $user->queryUnattached();
         foreach ($accounts as $account) {
             $a = array('wiki' => $account['wiki'], 'editcount' => $account['editCount']);
             if ($account['blocked']) {
                 $a['blocked'] = array('expiry' => $this->getLanguage()->formatExpiry($account['block-expiry'], TS_ISO_8601), 'reason' => $account['block-reason']);
             }
             $result->addValue(array('query', $this->getModuleName(), 'unattached'), null, $a);
         }
         if (defined('ApiResult::META_CONTENT')) {
             $result->addIndexedTagName(array('query', $this->getModuleName(), 'unattached'), 'account');
         } else {
             $result->setIndexedTagName_internal(array('query', $this->getModuleName(), 'unattached'), 'account');
         }
     }
 }
コード例 #16
0
    /**
     * Formats wiki links and media links in text; all other wiki formatting
     * is ignored
     *
     * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
     * @param string $comment Text to format links in
     * @param Title|null $title An optional title object used to links to sections
     * @param bool $local Whether section links should refer to local page
     * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), as used by WikiMap
     *
     * @return string
     */
    public static function formatLinksInComment($comment, $title = null, $local = false, $wikiId = null)
    {
        return preg_replace_callback('/
				\\[\\[
				:? # ignore optional leading colon
				([^\\]|]+) # 1. link target; page names cannot include ] or |
				(?:\\|
					# 2. a pipe-separated substring; only the last is captured
					# Stop matching at | and ]] without relying on backtracking.
					((?:]?[^\\]|])*+)
				)*
				\\]\\]
				([^[]*) # 3. link trail (the text up until the next link)
			/x', function ($match) use($title, $local, $wikiId) {
            global $wgContLang;
            $medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|';
            $medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):';
            $comment = $match[0];
            # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
            if (strpos($match[1], '%') !== false) {
                $match[1] = str_replace(array('<', '>'), array('&lt;', '&gt;'), rawurldecode($match[1]));
            }
            # Handle link renaming [[foo|text]] will show link as "text"
            if ($match[2] != "") {
                $text = $match[2];
            } else {
                $text = $match[1];
            }
            $submatch = array();
            $thelink = null;
            if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) {
                # Media link; trail not supported.
                $linkRegexp = '/\\[\\[(.*?)\\]\\]/';
                $title = Title::makeTitleSafe(NS_FILE, $submatch[1]);
                if ($title) {
                    $thelink = Linker::makeMediaLinkObj($title, $text);
                }
            } else {
                # Other kind of link
                if (preg_match($wgContLang->linkTrail(), $match[3], $submatch)) {
                    $trail = $submatch[1];
                } else {
                    $trail = "";
                }
                $linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/';
                if (isset($match[1][0]) && $match[1][0] == ':') {
                    $match[1] = substr($match[1], 1);
                }
                list($inside, $trail) = Linker::splitTrail($trail);
                $linkText = $text;
                $linkTarget = Linker::normalizeSubpageLink($title, $match[1], $linkText);
                $target = Title::newFromText($linkTarget);
                if ($target) {
                    if ($target->getText() == '' && !$target->isExternal() && !$local && $title) {
                        $newTarget = clone $title;
                        $newTarget->setFragment('#' . $target->getFragment());
                        $target = $newTarget;
                    }
                    if ($wikiId !== null) {
                        $thelink = Linker::makeExternalLink(WikiMap::getForeignURL($wikiId, $target->getFullText()), $linkText . $inside, false) . $trail;
                    } else {
                        $thelink = Linker::link($target, $linkText . $inside) . $trail;
                    }
                }
            }
            if ($thelink) {
                // If the link is still valid, go ahead and replace it in!
                $comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1);
            }
            return $comment;
        }, $comment);
    }
コード例 #17
0
 /**
  * @param $wikiID
  * @return string
  * @throws MWException
  */
 function foreignUserLink($wikiID)
 {
     $wiki = WikiMap::getWiki($wikiID);
     if (!$wiki) {
         throw new MWException("no wiki for {$wikiID}");
     }
     $hostname = $wiki->getDisplayName();
     $userPageName = 'User:'******'a', array('href' => $url, 'title' => wfMsg('centralauth-foreign-link', $this->mUserName, $hostname)), $hostname);
 }
コード例 #18
0
 public function formatVersionRow($arr)
 {
     $ts = $arr['timestamp'];
     $wikis = $arr['wikis'];
     $c = $arr['count'];
     $hasSelf = in_array($this->mWiki, $wikis);
     extract($this->formatConf);
     $lang = $this->getLang();
     $datime = $lang->timeanddate($ts);
     $date = $lang->date($ts);
     $time = $lang->time($ts);
     ## Make user link...
     $userLink = '';
     if (!$arr['user_wiki'] && !$arr['user_name']) {
         $userLink = '';
         # Nothing...
         $username = '';
     } elseif ($arr['user_wiki'] == wfWikiId()) {
         $userLink = Linker::link(Title::makeTitle(NS_USER, $arr['user_name']), htmlspecialchars($arr['user_name']));
         $username = $arr['user_name'];
     } elseif ($wiki = WikiMap::getWiki($arr['user_wiki'])) {
         $userLink = Linker::makeExternalLink($wiki->getUrl('User:'******'user_name']), htmlspecialchars($arr['user_name'] . '@' . $arr['user_wiki']));
         $username = '';
     } else {
         ## Last-ditch
         $userLink = htmlspecialchars($arr['user_name'] . '@' . $arr['user_wiki']);
         $username = '';
     }
     $actions = array();
     $view = '';
     if ($hasSelf) {
         $view .= Linker::linkKnown($self, $this->msg('configure-view')->escaped(), array(), array('version' => $ts));
     } elseif ($allowedAll) {
         $view .= $this->msg('configure-view')->escaped();
     }
     if ($allowedAll) {
         $viewWikis = array();
         foreach ($wikis as $wiki) {
             $viewWikis[] = Linker::linkKnown($self, htmlspecialchars($wiki), array(), array('version' => $ts, 'wiki' => $wiki));
         }
         $view .= ' (' . $lang->commaList($viewWikis) . ')';
     }
     if ($view) {
         $actions[] = $view;
     }
     $editDone = false;
     if ($allowedConfig) {
         if ($hasSelf) {
             $editCore = $editMsg . Linker::linkKnown($configTitle, $this->msg('configure-edit-core')->escaped(), array(), array('version' => $ts));
         } elseif ($allowedConfigAll) {
             $editCore = $editMsg . $this->msg('configure-edit-core')->escaped();
         } else {
             $editCore = $editMsg;
         }
         if ($allowedConfigAll) {
             $viewWikis = array();
             foreach ($wikis as $wiki) {
                 $viewWikis[] = Linker::linkKnown($configTitle, htmlspecialchars($wiki), array(), array('version' => $ts, 'wiki' => $wiki));
             }
             $editCore .= ' (' . $lang->commaList($viewWikis) . ')';
         }
         $actions[] = $editCore;
     }
     if ($allowedExtensions) {
         $editExt = '';
         if (!$allowedConfig) {
             $editExt .= $editMsg;
         }
         if ($hasSelf) {
             $editExt .= Linker::linkKnown($extTitle, $this->msg('configure-edit-ext')->escaped(), array(), array('version' => $ts));
         } elseif ($allowedExtensionsAll) {
             $editExt .= $this->msg('configure-edit-ext')->escaped();
         }
         if ($allowedExtensionsAll) {
             $viewWikis = array();
             foreach ($wikis as $wiki) {
                 $viewWikis[] = Linker::linkKnown($extTitle, htmlspecialchars($wiki), array(), array('version' => $ts, 'wiki' => $wiki));
             }
             $editExt .= ' (' . $lang->commaList($viewWikis) . ')';
         }
         $actions[] = $editExt;
     }
     if ($showDiff) {
         $diffCheck = $c == 2 ? array('checked' => 'checked') : array();
         $versionCheck = $c == 1 ? array('checked' => 'checked') : array();
         $buttons = Xml::element('input', array_merge(array('type' => 'radio', 'name' => 'diff', 'value' => $ts), $diffCheck)) . Xml::element('input', array_merge(array('type' => 'radio', 'name' => 'version', 'value' => $ts), $versionCheck));
         $actions[] = Linker::link($this->getTitle(), $this->msg('configure-viewconfig-default-diff')->escaped(), array(), array('version' => $ts, 'diff' => 'default'));
     } else {
         $buttons = '';
     }
     $comment = $arr['reason'] ? Linker::commentBlock($arr['reason']) : '';
     $action = $lang->commaList($actions);
     $msg = $this->msg('configure-viewconfig-line')->rawParams($buttons)->params($datime)->rawParams($userLink, $action, $comment)->params($date, $time, $username)->parse();
     return Xml::tags('li', null, $msg) . "\n";
 }
コード例 #19
0
ファイル: Linker.php プロジェクト: paladox/2
 /**
  * Generates a link to the given Title
  *
  * @note This is only public for technical reasons. It's not intended for use outside Linker.
  *
  * @param Title $title
  * @param string $text
  * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
  *  as used by WikiMap.
  * @param string|string[] $options See the $options parameter in Linker::link.
  *
  * @return string HTML link
  */
 public static function makeCommentLink(Title $title, $text, $wikiId = null, $options = array())
 {
     if ($wikiId !== null && !$title->isExternal()) {
         $link = Linker::makeExternalLink(WikiMap::getForeignURL($wikiId, $title->getPrefixedText(), $title->getFragment()), $text, false);
     } else {
         $link = Linker::link($title, $text, array(), array(), $options);
     }
     return $link;
 }
コード例 #20
0
 /**
  * @param $wikiID
  * @return string
  * @throws MWException
  */
 function foreignUserLink($wikiID)
 {
     $wiki = WikiMap::getWiki($wikiID);
     if (!$wiki) {
         throw new MWException("Invalid wiki: {$wikiID}");
     }
     $wikiname = $wiki->getDisplayName();
     return $this->foreignLink($wiki, 'User:'******'centralauth-foreign-link', $this->mUserName, $wikiname));
 }
コード例 #21
0
 static function maybeLinkUserpage($wiki_id, $user)
 {
     if (class_exists('WikiMap')) {
         $wiki = WikiMap::getWiki($wiki_id);
         if ($wiki) {
             return "[" . $wiki->getUrl("User:{$user}") . " {$user}]";
         }
     }
     return $user;
 }
コード例 #22
0
 /**
  * Helper to format a specific item
  */
 public static function formatItem($item)
 {
     if (!$item['namespace']) {
         $page = $item['title'];
     } else {
         $page = "{$item['namespace']}:{$item['title']}";
     }
     $link = WikiMap::makeForeignLink($item['wiki'], $page, str_replace('_', ' ', $page));
     // Return only the title if no link can be constructed
     return $link === false ? $page : $link;
 }
コード例 #23
0
 function formatRow($row, $li = true)
 {
     global $wgLang, $wgUser;
     # One-time setup
     static $sk = null;
     $actionLinks = array();
     if (is_null($sk)) {
         $sk = $wgUser->getSkin();
     }
     $title = Title::makeTitle($row->afl_namespace, $row->afl_title);
     if (!$row->afl_wiki) {
         $pageLink = $sk->link($title);
     } else {
         $pageLink = WikiMap::makeForeignLink($row->afl_wiki, $row->afl_title);
     }
     if (!$row->afl_wiki) {
         // Local user
         $user = $sk->userLink($row->afl_user, $row->afl_user_text) . $sk->userToolLinks($row->afl_user, $row->afl_user_text);
     } else {
         $user = WikiMap::foreignUserLink($row->afl_wiki, $row->afl_user_text);
         $user .= ' (' . WikiMap::getWikiName($row->afl_wiki) . ')';
     }
     $timestamp = $wgLang->timeanddate($row->afl_timestamp, true);
     $actions_taken = $row->afl_actions;
     if (!strlen(trim($actions_taken))) {
         $actions_taken = wfMsg('abusefilter-log-noactions');
     } else {
         $actions = explode(',', $actions_taken);
         $displayActions = array();
         foreach ($actions as $action) {
             $displayActions[] = AbuseFilter::getActionDisplay($action);
         }
         $actions_taken = $wgLang->commaList($displayActions);
     }
     $globalIndex = AbuseFilter::decodeGlobalName($row->afl_filter);
     global $wgOut;
     if ($globalIndex) {
         // Pull global filter description
         $parsed_comments = $wgOut->parseInline(AbuseFilter::getGlobalFilterDescription($globalIndex));
     } else {
         $parsed_comments = $wgOut->parseInline($row->af_public_comments);
     }
     if (self::canSeeDetails()) {
         $examineTitle = SpecialPage::getTitleFor('AbuseFilter', 'examine/log/' . $row->afl_id);
         $detailsLink = $sk->makeKnownLinkObj($this->getTitle($row->afl_id), wfMsg('abusefilter-log-detailslink'));
         $examineLink = $sk->link($examineTitle, wfMsgExt('abusefilter-changeslist-examine', 'parseinline'), array());
         $actionLinks[] = $detailsLink;
         $actionLinks[] = $examineLink;
         if ($wgUser->isAllowed('abusefilter-hide-log')) {
             $hideLink = $sk->link($this->getTitle(), wfMsg('abusefilter-log-hidelink'), array(), array('hide' => $row->afl_id));
             $actionLinks[] = $hideLink;
         }
         if ($globalIndex) {
             global $wgAbuseFilterCentralDB;
             $globalURL = WikiMap::getForeignURL($wgAbuseFilterCentralDB, 'Special:AbuseFilter/' . $globalIndex);
             $linkText = wfMsgExt('abusefilter-log-detailedentry-global', 'parseinline', array($globalIndex));
             $filterLink = $sk->makeExternalLink($globalURL, $linkText);
         } else {
             $title = SpecialPage::getTitleFor('AbuseFilter', $row->afl_filter);
             $linkText = wfMsgExt('abusefilter-log-detailedentry-local', 'parseinline', array($row->afl_filter));
             $filterLink = $sk->link($title, $linkText);
         }
         $description = wfMsgExt('abusefilter-log-detailedentry-meta', array('parseinline', 'replaceafter'), array($timestamp, $user, $filterLink, $row->afl_action, $pageLink, $actions_taken, $parsed_comments, $wgLang->pipeList($actionLinks)));
     } else {
         $description = wfMsgExt('abusefilter-log-entry', array('parseinline', 'replaceafter'), array($timestamp, $user, $row->afl_action, $sk->link($title), $actions_taken, $parsed_comments));
     }
     if ($row->afl_deleted) {
         $description .= ' ' . wfMsgExt('abusefilter-log-hidden', 'parseinline');
     }
     return $li ? Xml::tags('li', null, $description) : $description;
 }
コード例 #24
0
ファイル: LogPage.php プロジェクト: eFFemeer/seizamcore
 /**
  * TODO document
  * @param  $type String
  * @param  $lang Language or null
  * @param  $title Title
  * @param  $params Array
  * @return String
  */
 protected static function getTitleLink($type, $lang, $title, &$params)
 {
     global $wgContLang, $wgUserrightsInterwikiDelimiter;
     if (!$lang) {
         return $title->getPrefixedText();
     }
     switch ($type) {
         case 'move':
             $titleLink = Linker::link($title, htmlspecialchars($title->getPrefixedText()), array(), array('redirect' => 'no'));
             $targetTitle = Title::newFromText($params[0]);
             if (!$targetTitle) {
                 # Workaround for broken database
                 $params[0] = htmlspecialchars($params[0]);
             } else {
                 $params[0] = Linker::link($targetTitle, htmlspecialchars($params[0]));
             }
             break;
         case 'block':
             if (substr($title->getText(), 0, 1) == '#') {
                 $titleLink = $title->getText();
             } else {
                 // TODO: Store the user identifier in the parameters
                 // to make this faster for future log entries
                 $id = User::idFromName($title->getText());
                 $titleLink = Linker::userLink($id, $title->getText()) . Linker::userToolLinks($id, $title->getText(), false, Linker::TOOL_LINKS_NOBLOCK);
             }
             break;
         case 'rights':
             $text = $wgContLang->ucfirst($title->getText());
             $parts = explode($wgUserrightsInterwikiDelimiter, $text, 2);
             if (count($parts) == 2) {
                 $titleLink = WikiMap::foreignUserLink($parts[1], $parts[0], htmlspecialchars($title->getPrefixedText()));
                 if ($titleLink !== false) {
                     break;
                 }
             }
             $titleLink = Linker::link(Title::makeTitle(NS_USER, $text));
             break;
         case 'merge':
             $titleLink = Linker::link($title, $title->getPrefixedText(), array(), array('redirect' => 'no'));
             $params[0] = Linker::link(Title::newFromText($params[0]), htmlspecialchars($params[0]));
             $params[1] = $lang->timeanddate($params[1]);
             break;
         default:
             if ($title->getNamespace() == NS_SPECIAL) {
                 list($name, $par) = SpecialPageFactory::resolveAlias($title->getDBkey());
                 # Use the language name for log titles, rather than Log/X
                 if ($name == 'Log') {
                     $titleLink = '(' . Linker::link($title, LogPage::logName($par)) . ')';
                 } else {
                     $titleLink = Linker::link($title);
                 }
             } else {
                 $titleLink = Linker::link($title);
             }
     }
     return $titleLink;
 }
コード例 #25
0
 /**
  * @param $auth
  * @param $user User
  * @param $params
  * @return bool
  */
 static function onSecurePoll_GetUserParams($auth, $user, &$params)
 {
     if ($user->isAnon()) {
         return true;
     }
     $centralUser = CentralAuthUser::getInstance($user);
     if (!($centralUser->exists() && $centralUser->isAttached())) {
         return true;
     }
     $wikiID = $centralUser->getHomeWiki();
     if (strval($wikiID) === '') {
         return true;
     }
     $wiki = WikiMap::getWiki($wikiID);
     $wikiUrl = $wiki->getUrl('');
     $parts = explode('/', $wikiUrl);
     if (isset($parts[2])) {
         $params['properties']['ca-local-domain'] = $params['domain'];
         $params['domain'] = $parts[2];
     }
     $params['properties']['ca-local-url'] = $params['url'];
     $params['url'] = $wiki->getUrl(MWNamespace::getCanonicalName(NS_USER) . ':' . $user->getTitleKey());
     return true;
 }
 /**
  * @param string $name The database field name
  * @param string $value The value retrieved from the database
  * @return string HTML to place inside table cell
  */
 public function formatValue($name, $value)
 {
     $formatted = htmlspecialchars($value);
     switch ($name) {
         case 'rq_requested_ts':
         case 'rq_completed_ts':
             $formatted = $this->formatDateTime($value);
             break;
         case 'rq_name':
         case 'rq_newname':
             $title = SpecialPage::getTitleFor('CentralAuth', $value);
             $formatted = Linker::link($title, htmlspecialchars($value));
             break;
         case 'rq_performer':
             $steward = CentralAuthUser::newFromId($value);
             $formatted = '<span class="plainlinks">' . WikiMap::foreignUserLink($steward->getHomeWiki(), $steward->getName(), $steward->getName()) . '</span>';
             break;
         case 'row_actions':
             $formatted = $this->formatActionValue($this->mCurrentRow);
             break;
     }
     return $formatted;
 }
 function onSubmit(array $data)
 {
     if (!isset($data['username'])) {
         $this->showCurrentRenames();
         return false;
     }
     $name = User::getCanonicalName($data['username'], 'usable');
     if (!$name) {
         $this->showCurrentRenames();
         return false;
     }
     $out = $this->getOutput();
     $this->renameuserStatus = new GlobalRenameUserStatus($name);
     $names = $this->renameuserStatus->getNames();
     if (!$names) {
         $this->checkCachePurge($name);
         $out->addWikiMsg('centralauth-rename-notinprogress', $name);
         $this->getForm()->displayForm(false);
         $this->showLogExtract($name);
         return true;
     }
     list($oldName, $newName) = $names;
     $statuses = $this->renameuserStatus->getStatuses();
     $this->getForm()->displayForm(false);
     // $newname will always be defined since we check
     // for 0 result rows above
     $caUser = new CentralAuthUser($newName);
     $attached = $caUser->listAttached();
     foreach ($attached as $wiki) {
         // If it's not in the db table, and there is
         // an attached acount, assume it's done.
         if (!isset($statuses[$wiki])) {
             $statuses[$wiki] = 'done';
         }
     }
     ksort($statuses);
     $table = Html::openElement('table', array('class' => 'wikitable sortable'));
     $table .= Html::openElement('tr');
     $table .= Html::element('th', array(), $this->msg('centralauth-rename-table-domain')->text());
     $table .= Html::element('th', array(), $this->msg('centralauth-rename-table-status')->text());
     $table .= Html::closeElement('tr');
     foreach ($statuses as $wiki => $status) {
         $table .= Html::openElement('tr');
         $table .= Html::element('td', array(), WikiMap::getWiki($wiki)->getDisplayName());
         // Messages used: centralauth-rename-table-status-inprogress
         // centralauth-rename-table-status-queued, centralauth-rename-table-status-done
         $table .= Html::rawElement('td', array(), $this->msg("centralauth-rename-table-status-{$status}")->parse());
         $table .= Html::closeElement('tr');
     }
     $table .= Html::closeElement('table');
     $fieldset = Xml::fieldset($this->msg('centralauth-rename-progress-fieldset')->text(), $table);
     $this->showLogExtract($newName);
     $out->addHTML($fieldset);
     return true;
 }