/**
  * Display form for approving/denying request or process form submission.
  *
  * @param GlobalRenameRequest $req Pending request
  */
 protected function doShowProcessForm(GlobalRenameRequest $req)
 {
     $this->commonPreamble('globalrenamequeue-request-title', array($req->getName()));
     $form = HTMLForm::factory('vform', array('rid' => array('default' => $req->getId(), 'name' => 'rid', 'type' => 'hidden'), 'comments' => array('default' => $this->getRequest()->getVal('comments'), 'id' => 'mw-renamequeue-comments', 'label-message' => 'globalrenamequeue-request-comments-label', 'name' => 'comments', 'type' => 'textarea', 'rows' => 5), 'reason' => array('id' => 'mw-renamequeue-reason', 'label-message' => 'globalrenamequeue-request-reason-label', 'name' => 'reason', 'type' => 'text'), 'movepages' => array('id' => 'mw-renamequeue-movepages', 'name' => 'movepages', 'label-message' => 'globalrenamequeue-request-movepages', 'type' => 'check', 'default' => 1), 'suppressredirects' => array('id' => 'mw-renamequeue-suppressredirects', 'name' => 'suppressredirects', 'label-message' => 'globalrenamequeue-request-suppressredirects', 'type' => 'check')), $this->getContext(), 'globalrenamequeue');
     $form->suppressDefaultSubmit();
     $form->addButton('approve', $this->msg('globalrenamequeue-request-approve-text')->text(), 'mw-renamequeue-approve', array('class' => 'mw-ui-constructive mw-ui-flush-right'));
     $form->addButton('deny', $this->msg('globalrenamequeue-request-deny-text')->text(), 'mw-renamequeue-deny', array('class' => 'mw-ui-destructive mw-ui-flush-right'));
     $form->addButton('cancel', $this->msg('globalrenamequeue-request-cancel-text')->text(), 'mw-renamequeue-cancel', array('class' => 'mw-ui-quiet mw-ui-flush-left'));
     $form->setId('mw-globalrenamequeue-request');
     if ($req->userIsGlobal()) {
         $globalUser = new CentralAuthUser($req->getName());
         $homeWiki = $globalUser->getHomeWiki();
         $infoMsgKey = 'globalrenamequeue-request-userinfo-global';
     } else {
         $homeWiki = $req->getWiki();
         $infoMsgKey = 'globalrenamequeue-request-userinfo-local';
     }
     $headerMsg = $this->msg('globalrenamequeue-request-header', WikiMap::getForeignURL($homeWiki, "User:{$req->getName()}"), $req->getName(), $req->getNewName());
     $form->addHeaderText('<span class="plainlinks">' . $headerMsg->parseAsBlock() . '</span>');
     $homeWikiWiki = WikiMap::getWiki($homeWiki);
     $infoMsg = $this->msg($infoMsgKey, $req->getName(), $homeWikiWiki ? $homeWikiWiki->getDisplayName() : $homeWiki, $req->getNewName());
     $form->addHeaderText($infoMsg->parseAsBlock());
     if (class_exists('CentralAuthSpoofUser')) {
         $spoofUser = new CentralAuthSpoofUser($req->getNewName());
         // @todo move this code somewhere else
         $specialGblRename = new SpecialGlobalRenameUser();
         $specialGblRename->setContext($this->getContext());
         $conflicts = $specialGblRename->processAntiSpoofConflicts($req->getName(), $spoofUser->getConflicts());
         if ($conflicts) {
             $form->addHeaderText($this->msg('globalrenamequeue-request-antispoof-conflicts', $this->getLanguage()->commaList($conflicts))->numParams(count($conflicts))->parse());
         }
     }
     // Show a log entry of previous renames under the requesting user's username
     $caTitle = Title::makeTitleSafe(NS_SPECIAL, 'CentralAuth/' . $req->getName());
     $extract = '';
     $extractCount = LogEventsList::showLogExtract($extract, 'gblrename', $caTitle, '', array('showIfEmpty' => false));
     if ($extractCount) {
         $form->addHeaderText(Xml::fieldset($this->msg('globalrenamequeue-request-previous-renames')->numParams($extractCount)->text(), $extract));
     }
     $reason = $req->getReason() ?: $this->msg('globalrenamequeue-request-reason-sul')->parseAsBlock();
     $form->addHeaderText($this->msg('globalrenamequeue-request-reason', $reason)->parseAsBlock());
     $form->setSubmitCallback(array($this, 'onProcessSubmit'));
     $out = $this->getOutput();
     $out->addModuleStyles(array('mediawiki.ui', 'mediawiki.ui.button', 'mediawiki.ui.input', 'ext.centralauth.globalrenamequeue.styles'));
     $out->addModules('ext.centralauth.globalrenamequeue');
     $status = $form->show();
     if ($status instanceof Status && $status->isOk()) {
         $this->getOutput()->redirect($this->getPageTitle(self::PAGE_PROCESS_REQUEST . "/{$req->getId()}/{$status->value}")->getFullURL());
     }
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 /**
  * @dataProvider provideGetForeignURL
  */
 public function testGetForeignURL($expected, $wikiId, $page, $fragment = null)
 {
     $this->assertEquals($expected, WikiMap::getForeignURL($wikiId, $page, $fragment));
 }
    /**
     * 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);
    }
 /**
  * @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);
     }
 }
 /**
  * @param &$vars
  * @return bool
  */
 static function onResourceLoaderGetConfigVars(&$vars)
 {
     global $wgCentralAuthLoginWiki;
     if ($wgCentralAuthLoginWiki && $wgCentralAuthLoginWiki !== wfWikiID()) {
         $url = WikiMap::getForeignURL($wgCentralAuthLoginWiki, 'Special:CentralAutoLogin/checkLoggedIn');
         if ($url !== false) {
             $params = array('type' => 'script', 'wikiid' => wfWikiID());
             if (self::isMobileDomain()) {
                 $params['mobile'] = 1;
             }
             $vars['wgCentralAuthCheckLoggedInURL'] = wfAppendQuery($url, $params);
         }
     }
 }
 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;
 }
 private function do302Redirect($target, $state, $params)
 {
     $url = WikiMap::getForeignURL($target, "Special:CentralAutoLogin/{$state}");
     if (wfWikiID() == $this->loginWiki && class_exists('MobileContext') && isset($params['mobile']) && $params['mobile']) {
         $url = MobileContext::singleton()->getMobileUrl($url);
     }
     if ($url === false) {
         $this->doFinalOutput(false, 'Invalid target wiki');
     } else {
         $this->getOutput()->redirect(wfAppendQuery($url, $params));
     }
 }