Exemple #1
0
 function formatRow($result)
 {
     $title = new TitleValue(NS_CATEGORY, $result->cat_title);
     $text = $title->getText();
     $link = $this->linkRenderer->makeLink($title, $text);
     $count = $this->msg('nmembers')->numParams($result->cat_pages)->escaped();
     return Html::rawElement('li', null, $this->getLanguage()->specialList($link, $count)) . "\n";
 }
 public function testMakeLink()
 {
     $linkRenderer = new LinkRenderer($this->titleFormatter);
     $foobar = new TitleValue(NS_SPECIAL, 'Foobar');
     $blankpage = new TitleValue(NS_SPECIAL, 'Blankpage');
     $this->assertEquals('<a href="/wiki/Special:Foobar" class="new" title="Special:Foobar ' . '(page does not exist)">foo</a>', $linkRenderer->makeLink($foobar, 'foo'));
     $this->assertEquals('<a href="/wiki/Special:BlankPage" title="Special:BlankPage">blank</a>', $linkRenderer->makeLink($blankpage, 'blank'));
     $this->assertEquals('<a href="/wiki/Special:Foobar" class="new" title="Special:Foobar ' . '(page does not exist)">&lt;script&gt;evil()&lt;/script&gt;</a>', $linkRenderer->makeLink($foobar, '<script>evil()</script>'));
     $this->assertEquals('<a href="/wiki/Special:Foobar" class="new" title="Special:Foobar ' . '(page does not exist)"><script>evil()</script></a>', $linkRenderer->makeLink($foobar, new HtmlArmor('<script>evil()</script>')));
 }
 /**
  * Return a link to the edit page, with the text
  * saying "view source" if the user can't edit the page
  *
  * @param Title $titleObj
  * @return string
  */
 private function buildEditLink(Title $titleObj)
 {
     if ($titleObj->quickUserCan('edit', $this->context->getUser())) {
         $linkMsg = 'editlink';
     } else {
         $linkMsg = 'viewsourcelink';
     }
     return $this->linkRenderer->makeLink($titleObj, $this->context->msg($linkMsg)->text(), [], ['action' => 'edit']);
 }
 /**
  * @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;
 }
 public function testGetLinkClasses()
 {
     $wanCache = ObjectCache::getMainWANInstance();
     $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
     $linkCache = new LinkCache($titleFormatter, $wanCache);
     $foobarTitle = new TitleValue(NS_MAIN, 'FooBar');
     $redirectTitle = new TitleValue(NS_MAIN, 'Redirect');
     $userTitle = new TitleValue(NS_USER, 'Someuser');
     $linkCache->addGoodLinkObj(1, $foobarTitle, 10, 0);
     $linkCache->addGoodLinkObj(2, $redirectTitle, 10, 1);
     $linkCache->addGoodLinkObj(3, $userTitle, 10, 0);
     $linkRenderer = new LinkRenderer($titleFormatter, $linkCache);
     $linkRenderer->setStubThreshold(0);
     $this->assertEquals('', $linkRenderer->getLinkClasses($foobarTitle));
     $linkRenderer->setStubThreshold(20);
     $this->assertEquals('stub', $linkRenderer->getLinkClasses($foobarTitle));
     $linkRenderer->setStubThreshold(0);
     $this->assertEquals('mw-redirect', $linkRenderer->getLinkClasses($redirectTitle));
     $linkRenderer->setStubThreshold(20);
     $this->assertEquals('', $linkRenderer->getLinkClasses($userTitle));
 }
Exemple #6
0
 /**
  * @param RecentChange $rc
  * @param bool $unpatrolled
  * @param bool $watched
  * @return string HTML
  * @since 1.26
  */
 public function getArticleLink(&$rc, $unpatrolled, $watched)
 {
     $params = [];
     if ($rc->getTitle()->isRedirect()) {
         $params = ['redirect' => 'no'];
     }
     $articlelink = $this->linkRenderer->makeLink($rc->getTitle(), null, ['class' => 'mw-changeslist-title'], $params);
     if ($this->isDeleted($rc, Revision::DELETED_TEXT)) {
         $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
     }
     # To allow for boldening pages watched by this user
     $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
     # RTL/LTR marker
     $articlelink .= $this->getLanguage()->getDirMark();
     # TODO: Deprecate the $s argument, it seems happily unused.
     $s = '';
     Hooks::run('ChangesListInsertArticleLink', [&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched]);
     return "{$s} {$articlelink}";
 }
 /**
  * @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;
 }
Exemple #8
0
 /**
  * Get a LinkRenderer instance to make links with
  *
  * @since 1.28
  * @return LinkRenderer
  */
 public function getLinkRenderer()
 {
     if (!$this->mLinkRenderer) {
         $this->mLinkRenderer = MediaWikiServices::getInstance()->getLinkRendererFactory()->create();
         $this->mLinkRenderer->setStubThreshold($this->getOptions()->getStubThreshold());
     }
     return $this->mLinkRenderer;
 }