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)"><script>evil()</script></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>'))); }
/** * @param RecentChange $cacheEntry * * @return string */ private function buildCLink(RecentChange $cacheEntry) { $type = $cacheEntry->mAttribs['rc_type']; // New unpatrolled pages if ($cacheEntry->unpatrolled && $type == RC_NEW) { $clink = $this->linkRenderer->makeKnownLink($cacheEntry->getTitle()); // Log entries } elseif ($type == RC_LOG) { $logType = $cacheEntry->mAttribs['rc_log_type']; if ($logType) { $clink = $this->getLogLink($logType); } else { wfDebugLog('recentchanges', 'Unexpected log entry with no log type in recent changes'); $clink = $this->linkRenderer->makeLink($cacheEntry->getTitle()); } // Log entries (old format) and special pages } elseif ($cacheEntry->mAttribs['rc_namespace'] == NS_SPECIAL) { wfDebugLog('recentchanges', 'Unexpected special page in recentchanges'); $clink = ''; // Edits } else { $clink = $this->linkRenderer->makeKnownLink($cacheEntry->getTitle()); } return $clink; }
/** * 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 $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; }