function formatRow($row)
 {
     wfProfileIn(__METHOD__);
     global $wgLang, $wgUser, $wgContLang;
     $rev = new Revision($row);
     $page = Title::makeTitle($row->page_namespace, $row->page_title);
     $link = Linker::link($page);
     $difftext = $topmarktext = '';
     if ($row->rev_id == $row->page_latest) {
         if (!$row->page_is_new) {
             $difftext .= '(' . Linker::link($page, $this->messages['diff'], array(), 'diff=0') . ')';
         } else {
             $difftext .= $this->messages['newarticle'];
         }
     }
     if ($rev->userCan(Revision::DELETED_TEXT)) {
         $difftext = '(' . Linker::link($page, $this->messages['diff'], array(), 'diff=prev&oldid=' . $row->rev_id) . ')';
     } else {
         $difftext = '(' . $this->messages['diff'] . ')';
     }
     $comment = $wgContLang->getDirMark() . Linker::revComment($rev);
     $d = $wgLang->timeanddate(wfTimestamp(TS_MW, $row->rev_timestamp), true);
     if ($this->target == 'newbies') {
         $userlink = ' . . ' . Linker::userLink($row->rev_user, $row->rev_user_text);
         $userlink .= ' (' . Linker::userTalkLink($row->rev_user, $row->rev_user_text) . ') ';
     } else {
         $userlink = '';
     }
     if ($rev->isDeleted(Revision::DELETED_TEXT)) {
         $d = '<span class="history-deleted">' . $d . '</span>';
     }
     if ($row->rev_minor_edit) {
         $mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
     } else {
         $mflag = '';
     }
     $ret = "{$d} {$difftext} {$mflag} {$link}{$userlink}{$comment} {$topmarktext}";
     if ($rev->isDeleted(Revision::DELETED_TEXT)) {
         $ret .= ' ' . wfMsgHtml('deletedrev');
     }
     $ret = "<li>{$ret}</li>\n";
     wfProfileOut(__METHOD__);
     return $ret;
 }
Example #2
0
 /**
  * Returns the tool links for this ambassador.
  * 
  * @since 0.1
  * 
  * @param EPIRole $role
  * @param IContextSource $context
  * @param EPCourse|null $course
  * 
  * @return string
  */
 public static function getRoleToolLinks(EPIRole $role, IContextSource $context, EPCourse $course = null)
 {
     $roleName = $role->getRoleName();
     $links = array();
     $links[] = Linker::userTalkLink($role->getUser()->getId(), $role->getUser()->getName());
     $links[] = Linker::link(SpecialPage::getTitleFor('Contributions', $role->getUser()->getName()), wfMsgHtml('contribslink'));
     if (!is_null($course) && ($context->getUser()->isAllowed('ep-' . $roleName) || $role->getUser()->getId() == $context->getUser()->getId())) {
         $links[] = Html::element('a', array('href' => '#', 'class' => 'ep-remove-role', 'data-role' => $roleName, 'data-courseid' => $course->getId(), 'data-coursename' => $course->getField('name'), 'data-userid' => $role->getUser()->getId(), 'data-username' => $role->getUser()->getName(), 'data-bestname' => $role->getName()), wfMsg('ep-' . $roleName . '-remove'));
         $context->getOutput()->addModules('ep.enlist');
     }
     return ' <span class="mw-usertoollinks">(' . $context->getLanguage()->pipeList($links) . ')</span>';
 }
Example #3
0
 public function userTalkLink($userId, $userText)
 {
     return Linker::userTalkLink($userId, $userText);
 }
 /**
  * Generates each row in the contributions list.
  *
  * Contributions which are marked "top" are currently on top of the history.
  * For these contributions, a [rollback] link is shown for users with roll-
  * back privileges. The rollback link restores the most recent version that
  * was not written by the target user.
  *
  * @todo This would probably look a lot nicer in a table.
  * @param $row
  * @return string
  */
 function formatRow($row)
 {
     wfProfileIn(__METHOD__);
     $ret = '';
     $classes = array();
     /*
      * There may be more than just revision rows. To make sure that we'll only be processing
      * revisions here, let's _try_ to build a revision out of our row (without displaying
      * notices though) and then trying to grab data from the built object. If we succeed,
      * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
      * to extensions to subscribe to the hook to parse the row.
      */
     wfSuppressWarnings();
     $rev = new Revision($row);
     $validRevision = $rev->getParentId() !== null;
     wfRestoreWarnings();
     if ($validRevision) {
         $classes = array();
         $page = Title::newFromRow($row);
         $link = Linker::link($page, htmlspecialchars($page->getPrefixedText()), array('class' => 'mw-contributions-title'), $page->isRedirect() ? array('redirect' => 'no') : array());
         # Mark current revisions
         $topmarktext = '';
         $user = $this->getUser();
         if ($row->rev_id == $row->page_latest) {
             $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
             # Add rollback link
             if (!$row->page_is_new && $page->quickUserCan('rollback', $user) && $page->quickUserCan('edit', $user)) {
                 $this->preventClickjacking();
                 $topmarktext .= ' ' . Linker::generateRollback($rev, $this->getContext());
             }
         }
         # Is there a visible previous revision?
         if ($rev->userCan(Revision::DELETED_TEXT, $user) && $rev->getParentId() !== 0) {
             $difftext = Linker::linkKnown($page, $this->messages['diff'], array(), array('diff' => 'prev', 'oldid' => $row->rev_id));
         } else {
             $difftext = $this->messages['diff'];
         }
         $histlink = Linker::linkKnown($page, $this->messages['hist'], array(), array('action' => 'history'));
         if ($row->rev_parent_id === null) {
             // For some reason rev_parent_id isn't populated for this row.
             // Its rumoured this is true on wikipedia for some revisions (bug 34922).
             // Next best thing is to have the total number of bytes.
             $chardiff = ' <span class="mw-changeslist-separator">. .</span> ' . Linker::formatRevisionSize($row->rev_len) . ' <span class="mw-changeslist-separator">. .</span> ';
         } else {
             $parentLen = isset($this->mParentLens[$row->rev_parent_id]) ? $this->mParentLens[$row->rev_parent_id] : 0;
             $chardiff = ' <span class="mw-changeslist-separator">. .</span> ' . ChangesList::showCharacterDifference($parentLen, $row->rev_len, $this->getContext()) . ' <span class="mw-changeslist-separator">. .</span> ';
         }
         $lang = $this->getLanguage();
         $comment = $lang->getDirMark() . Linker::revComment($rev, false, true);
         $date = $lang->userTimeAndDate($row->rev_timestamp, $user);
         if ($rev->userCan(Revision::DELETED_TEXT, $user)) {
             $d = Linker::linkKnown($page, htmlspecialchars($date), array('class' => 'mw-changeslist-date'), array('oldid' => intval($row->rev_id)));
         } else {
             $d = htmlspecialchars($date);
         }
         if ($rev->isDeleted(Revision::DELETED_TEXT)) {
             $d = '<span class="history-deleted">' . $d . '</span>';
         }
         # Show user names for /newbies as there may be different users.
         # Note that we already excluded rows with hidden user names.
         if ($this->contribs == 'newbie') {
             $userlink = ' . . ' . Linker::userLink($rev->getUser(), $rev->getUserText());
             $userlink .= ' ' . $this->msg('parentheses')->rawParams(Linker::userTalkLink($rev->getUser(), $rev->getUserText()))->escaped() . ' ';
         } else {
             $userlink = '';
         }
         if ($rev->getParentId() === 0) {
             $nflag = ChangesList::flag('newpage');
         } else {
             $nflag = '';
         }
         if ($rev->isMinor()) {
             $mflag = ChangesList::flag('minor');
         } else {
             $mflag = '';
         }
         $del = Linker::getRevDeleteLink($user, $rev, $page);
         if ($del !== '') {
             $del .= ' ';
         }
         $diffHistLinks = $this->msg('parentheses')->rawParams($difftext . $this->messages['pipe-separator'] . $histlink)->escaped();
         $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
         # Denote if username is redacted for this edit
         if ($rev->isDeleted(Revision::DELETED_USER)) {
             $ret .= " <strong>" . $this->msg('rev-deleted-user-contribs')->escaped() . "</strong>";
         }
         # Tags, if any.
         list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow($row->ts_tags, 'contributions');
         $classes = array_merge($classes, $newClasses);
         $ret .= " {$tagSummary}";
     }
     // Let extensions add data
     wfRunHooks('ContributionsLineEnding', array($this, &$ret, $row, &$classes));
     $classes = implode(' ', $classes);
     $ret = "<li class=\"{$classes}\">{$ret}</li>\n";
     wfProfileOut(__METHOD__);
     return $ret;
 }
Example #5
0
 /**
  * Generates each row in the contributions list.
  *
  * Contributions which are marked "top" are currently on top of the history.
  * For these contributions, a [rollback] link is shown for users with roll-
  * back privileges. The rollback link restores the most recent version that
  * was not written by the target user.
  *
  * @todo This would probably look a lot nicer in a table.
  * @param object $row
  * @return string
  */
 function formatRow($row)
 {
     $ret = '';
     $classes = [];
     /*
      * There may be more than just revision rows. To make sure that we'll only be processing
      * revisions here, let's _try_ to build a revision out of our row (without displaying
      * notices though) and then trying to grab data from the built object. If we succeed,
      * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
      * to extensions to subscribe to the hook to parse the row.
      */
     MediaWiki\suppressWarnings();
     try {
         $rev = new Revision($row);
         $validRevision = (bool) $rev->getId();
     } catch (Exception $e) {
         $validRevision = false;
     }
     MediaWiki\restoreWarnings();
     if ($validRevision) {
         $classes = [];
         $page = Title::newFromRow($row);
         $link = Linker::link($page, htmlspecialchars($page->getPrefixedText()), ['class' => 'mw-contributions-title'], $page->isRedirect() ? ['redirect' => 'no'] : []);
         # Mark current revisions
         $topmarktext = '';
         $user = $this->getUser();
         if ($row->rev_id === $row->page_latest) {
             $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
             $classes[] = 'mw-contributions-current';
             # Add rollback link
             if (!$row->page_is_new && $page->quickUserCan('rollback', $user) && $page->quickUserCan('edit', $user)) {
                 $this->preventClickjacking();
                 $topmarktext .= ' ' . Linker::generateRollback($rev, $this->getContext());
             }
         }
         # Is there a visible previous revision?
         if ($rev->userCan(Revision::DELETED_TEXT, $user) && $rev->getParentId() !== 0) {
             $difftext = Linker::linkKnown($page, $this->messages['diff'], [], ['diff' => 'prev', 'oldid' => $row->rev_id]);
         } else {
             $difftext = $this->messages['diff'];
         }
         $histlink = Linker::linkKnown($page, $this->messages['hist'], [], ['action' => 'history']);
         if ($row->rev_parent_id === null) {
             // For some reason rev_parent_id isn't populated for this row.
             // Its rumoured this is true on wikipedia for some revisions (bug 34922).
             // Next best thing is to have the total number of bytes.
             $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
             $chardiff .= Linker::formatRevisionSize($row->rev_len);
             $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
         } else {
             $parentLen = 0;
             if (isset($this->mParentLens[$row->rev_parent_id])) {
                 $parentLen = $this->mParentLens[$row->rev_parent_id];
             }
             $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
             $chardiff .= ChangesList::showCharacterDifference($parentLen, $row->rev_len, $this->getContext());
             $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
         }
         $lang = $this->getLanguage();
         $comment = $lang->getDirMark() . Linker::revComment($rev, false, true);
         $date = $lang->userTimeAndDate($row->rev_timestamp, $user);
         if ($rev->userCan(Revision::DELETED_TEXT, $user)) {
             $d = Linker::linkKnown($page, htmlspecialchars($date), ['class' => 'mw-changeslist-date'], ['oldid' => intval($row->rev_id)]);
         } else {
             $d = htmlspecialchars($date);
         }
         if ($rev->isDeleted(Revision::DELETED_TEXT)) {
             $d = '<span class="history-deleted">' . $d . '</span>';
         }
         # Show user names for /newbies as there may be different users.
         # Note that we already excluded rows with hidden user names.
         if ($this->contribs == 'newbie') {
             $userlink = ' . . ' . $lang->getDirMark() . Linker::userLink($rev->getUser(), $rev->getUserText());
             $userlink .= ' ' . $this->msg('parentheses')->rawParams(Linker::userTalkLink($rev->getUser(), $rev->getUserText()))->escaped() . ' ';
         } else {
             $userlink = '';
         }
         $flags = [];
         if ($rev->getParentId() === 0) {
             $flags[] = ChangesList::flag('newpage');
         }
         if ($rev->isMinor()) {
             $flags[] = ChangesList::flag('minor');
         }
         $del = Linker::getRevDeleteLink($user, $rev, $page);
         if ($del !== '') {
             $del .= ' ';
         }
         $diffHistLinks = $this->msg('parentheses')->rawParams($difftext . $this->messages['pipe-separator'] . $histlink)->escaped();
         # Tags, if any.
         list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow($row->ts_tags, 'contributions', $this->getContext());
         $classes = array_merge($classes, $newClasses);
         Hooks::run('SpecialContributions::formatRow::flags', [$this->getContext(), $row, &$flags]);
         $templateParams = ['del' => $del, 'timestamp' => $d, 'diffHistLinks' => $diffHistLinks, 'charDifference' => $chardiff, 'flags' => $flags, 'articleLink' => $link, 'userlink' => $userlink, 'logText' => $comment, 'topmarktext' => $topmarktext, 'tagSummary' => $tagSummary];
         # Denote if username is redacted for this edit
         if ($rev->isDeleted(Revision::DELETED_USER)) {
             $templateParams['rev-deleted-user-contribs'] = $this->msg('rev-deleted-user-contribs')->escaped();
         }
         $templateParser = new TemplateParser();
         $ret = $templateParser->processTemplate('SpecialContributionsLine', $templateParams);
     }
     // Let extensions add data
     Hooks::run('ContributionsLineEnding', [$this, &$ret, $row, &$classes]);
     // TODO: Handle exceptions in the catch block above.  Do any extensions rely on
     // receiving empty rows?
     if ($classes === [] && $ret === '') {
         wfDebug("Dropping Special:Contribution row that could not be formatted\n");
         return "<!-- Could not format Special:Contribution row. -->\n";
     }
     // FIXME: The signature of the ContributionsLineEnding hook makes it
     // very awkward to move this LI wrapper into the template.
     return Html::rawElement('li', ['class' => $classes], $ret) . "\n";
 }