Exemplo n.º 1
0
 public function testMakeKnownLink()
 {
     $target = new TitleValue(NS_MAIN, 'Foobar');
     $linkRenderer = new LinkRenderer($this->titleFormatter);
     // Query added
     $this->assertEquals('<a href="/w/index.php?title=Foobar&amp;foo=bar" ' . 'title="Foobar">Foobar</a>', $linkRenderer->makeKnownLink($target, null, [], ['foo' => 'bar']));
     // forcearticlepath
     $linkRenderer->setForceArticlePath(true);
     $this->assertEquals('<a href="/wiki/Foobar?foo=bar" title="Foobar">Foobar</a>', $linkRenderer->makeKnownLink($target, null, [], ['foo' => 'bar']));
     // expand = HTTPS
     $linkRenderer->setForceArticlePath(false);
     $linkRenderer->setExpandURLs(PROTO_HTTPS);
     $this->assertEquals('<a href="https://example.org/wiki/Foobar" title="Foobar">Foobar</a>', $linkRenderer->makeKnownLink($target));
 }
Exemplo n.º 2
0
 /**
  * @param RecentChange $cacheEntry
  * @param bool $showDiffLinks
  *
  * @return string
  */
 private function buildLastLink(RecentChange $cacheEntry, $showDiffLinks)
 {
     $lastOldid = $cacheEntry->mAttribs['rc_last_oldid'];
     $lastMessage = $this->getMessage('last');
     $type = $cacheEntry->mAttribs['rc_type'];
     $logTypes = [RC_LOG];
     // Make "last" link
     if (!$showDiffLinks || !$lastOldid || in_array($type, $logTypes)) {
         $lastLink = $lastMessage;
     } else {
         $lastLink = $this->linkRenderer->makeKnownLink($cacheEntry->getTitle(), new HtmlArmor($lastMessage), [], $this->buildDiffQueryParams($cacheEntry));
     }
     return $lastLink;
 }
Exemplo n.º 3
0
 /**
  * @param string $s HTML to update
  * @param RecentChange $rc
  * @param bool|null $unpatrolled Unused variable, since 1.27.
  */
 public function insertDiffHist(&$s, &$rc, $unpatrolled = null)
 {
     # Diff link
     if ($rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG || $rc->mAttribs['rc_type'] == RC_CATEGORIZE) {
         $diffLink = $this->message['diff'];
     } elseif (!self::userCan($rc, Revision::DELETED_TEXT, $this->getUser())) {
         $diffLink = $this->message['diff'];
     } else {
         $query = ['curid' => $rc->mAttribs['rc_cur_id'], 'diff' => $rc->mAttribs['rc_this_oldid'], 'oldid' => $rc->mAttribs['rc_last_oldid']];
         $diffLink = $this->linkRenderer->makeKnownLink($rc->getTitle(), new HtmlArmor($this->message['diff']), [], $query);
     }
     if ($rc->mAttribs['rc_type'] == RC_CATEGORIZE) {
         $diffhist = $diffLink . $this->message['pipe-separator'] . $this->message['hist'];
     } else {
         $diffhist = $diffLink . $this->message['pipe-separator'];
         # History link
         $diffhist .= $this->linkRenderer->makeKnownLink($rc->getTitle(), new HtmlArmor($this->message['hist']), [], ['curid' => $rc->mAttribs['rc_cur_id'], 'action' => 'history']);
     }
     // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
     $s .= $this->msg('parentheses')->rawParams($diffhist)->escaped() . ' <span class="mw-changeslist-separator">. .</span> ';
 }
Exemplo n.º 4
0
 /**
  * @param string $field
  * @param string $value
  * @return string HTML
  * @throws MWException
  */
 function formatValue($field, $value)
 {
     /** @var $row object */
     $row = $this->mCurrentRow;
     switch ($field) {
         case 'log_timestamp':
             // when timestamp is null, this is a old protection row
             if ($value === null) {
                 $formatted = Html::rawElement('span', ['class' => 'mw-protectedpages-unknown'], $this->msg('protectedpages-unknown-timestamp')->escaped());
             } else {
                 $formatted = htmlspecialchars($this->getLanguage()->userTimeAndDate($value, $this->getUser()));
             }
             break;
         case 'pr_page':
             $title = Title::makeTitleSafe($row->page_namespace, $row->page_title);
             if (!$title) {
                 $formatted = Html::element('span', ['class' => 'mw-invalidtitle'], Linker::getInvalidTitleDescription($this->getContext(), $row->page_namespace, $row->page_title));
             } else {
                 $formatted = $this->linkRenderer->makeLink($title);
             }
             if (!is_null($row->page_len)) {
                 $formatted .= $this->getLanguage()->getDirMark() . ' ' . Html::rawElement('span', ['class' => 'mw-protectedpages-length'], Linker::formatRevisionSize($row->page_len));
             }
             break;
         case 'pr_expiry':
             $formatted = htmlspecialchars($this->getLanguage()->formatExpiry($value, true));
             $title = Title::makeTitleSafe($row->page_namespace, $row->page_title);
             if ($this->getUser()->isAllowed('protect') && $title) {
                 $changeProtection = $this->linkRenderer->makeKnownLink($title, $this->msg('protect_change')->text(), [], ['action' => 'unprotect']);
                 $formatted .= ' ' . Html::rawElement('span', ['class' => 'mw-protectedpages-actions'], $this->msg('parentheses')->rawParams($changeProtection)->escaped());
             }
             break;
         case 'log_user':
             // when timestamp is null, this is a old protection row
             if ($row->log_timestamp === null) {
                 $formatted = Html::rawElement('span', ['class' => 'mw-protectedpages-unknown'], $this->msg('protectedpages-unknown-performer')->escaped());
             } else {
                 $username = UserCache::singleton()->getProp($value, 'name');
                 if (LogEventsList::userCanBitfield($row->log_deleted, LogPage::DELETED_USER, $this->getUser())) {
                     if ($username === false) {
                         $formatted = htmlspecialchars($value);
                     } else {
                         $formatted = Linker::userLink($value, $username) . Linker::userToolLinks($value, $username);
                     }
                 } else {
                     $formatted = $this->msg('rev-deleted-user')->escaped();
                 }
                 if (LogEventsList::isDeleted($row, LogPage::DELETED_USER)) {
                     $formatted = '<span class="history-deleted">' . $formatted . '</span>';
                 }
             }
             break;
         case 'pr_params':
             $params = [];
             // Messages: restriction-level-sysop, restriction-level-autoconfirmed
             $params[] = $this->msg('restriction-level-' . $row->pr_level)->escaped();
             if ($row->pr_cascade) {
                 $params[] = $this->msg('protect-summary-cascade')->escaped();
             }
             $formatted = $this->getLanguage()->commaList($params);
             break;
         case 'log_comment':
             // when timestamp is null, this is an old protection row
             if ($row->log_timestamp === null) {
                 $formatted = Html::rawElement('span', ['class' => 'mw-protectedpages-unknown'], $this->msg('protectedpages-unknown-reason')->escaped());
             } else {
                 if (LogEventsList::userCanBitfield($row->log_deleted, LogPage::DELETED_COMMENT, $this->getUser())) {
                     $formatted = Linker::formatComment($value !== null ? $value : '');
                 } else {
                     $formatted = $this->msg('rev-deleted-comment')->escaped();
                 }
                 if (LogEventsList::isDeleted($row, LogPage::DELETED_COMMENT)) {
                     $formatted = '<span class="history-deleted">' . $formatted . '</span>';
                 }
             }
             break;
         default:
             throw new MWException("Unknown field '{$field}'");
     }
     return $formatted;
 }