Example #1
0
 /** Inserts a rollback link
  *
  * @param $s string
  * @param $rc RecentChange
  */
 public function insertRollback(&$s, &$rc)
 {
     if (!$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id']) {
         $page = $rc->getTitle();
         /** Check for rollback and edit permissions, disallow special pages, and only
          * show a link on the top-most revision */
         if ($this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']) {
             $rev = new Revision(array('id' => $rc->mAttribs['rc_this_oldid'], 'user' => $rc->mAttribs['rc_user'], 'user_text' => $rc->mAttribs['rc_user_text'], 'deleted' => $rc->mAttribs['rc_deleted']));
             $rev->setTitle($page);
             $s .= ' ' . Linker::generateRollback($rev, $this->getContext());
         }
     }
 }
 public function showDiffPage($diffOnly = false)
 {
     # Allow frames except in certain special cases
     $out = $this->getOutput();
     $out->allowClickjacking();
     $out->setRobotPolicy('noindex,nofollow');
     if (!$this->loadRevisionData()) {
         $this->showMissingRevision();
         return;
     }
     $user = $this->getUser();
     $permErrors = $this->mNewPage->getUserPermissionsErrors('read', $user);
     if ($this->mOldPage) {
         # mOldPage might not be set, see below.
         $permErrors = wfMergeErrorArrays($permErrors, $this->mOldPage->getUserPermissionsErrors('read', $user));
     }
     if (count($permErrors)) {
         throw new PermissionsError('read', $permErrors);
     }
     $rollback = '';
     $query = array();
     # Carry over 'diffonly' param via navigation links
     if ($diffOnly != $user->getBoolOption('diffonly')) {
         $query['diffonly'] = $diffOnly;
     }
     # Cascade unhide param in links for easy deletion browsing
     if ($this->unhide) {
         $query['unhide'] = 1;
     }
     # Check if one of the revisions is deleted/suppressed
     $deleted = $suppressed = false;
     $allowed = $this->mNewRev->userCan(Revision::DELETED_TEXT, $user);
     $revisionTools = array();
     # mOldRev is false if the difference engine is called with a "vague" query for
     # a diff between a version V and its previous version V' AND the version V
     # is the first version of that article. In that case, V' does not exist.
     if ($this->mOldRev === false) {
         $out->setPageTitle($this->msg('difference-title', $this->mNewPage->getPrefixedText()));
         $samePage = true;
         $oldHeader = '';
     } else {
         Hooks::run('DiffViewHeader', array($this, $this->mOldRev, $this->mNewRev));
         if ($this->mNewPage->equals($this->mOldPage)) {
             $out->setPageTitle($this->msg('difference-title', $this->mNewPage->getPrefixedText()));
             $samePage = true;
         } else {
             $out->setPageTitle($this->msg('difference-title-multipage', $this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText()));
             $out->addSubtitle($this->msg('difference-multipage'));
             $samePage = false;
         }
         if ($samePage && $this->mNewPage->quickUserCan('edit', $user)) {
             if ($this->mNewRev->isCurrent() && $this->mNewPage->userCan('rollback', $user)) {
                 $rollbackLink = Linker::generateRollback($this->mNewRev, $this->getContext());
                 if ($rollbackLink) {
                     $out->preventClickjacking();
                     $rollback = '   ' . $rollbackLink;
                 }
             }
             if (!$this->mOldRev->isDeleted(Revision::DELETED_TEXT) && !$this->mNewRev->isDeleted(Revision::DELETED_TEXT)) {
                 $undoLink = Html::element('a', array('href' => $this->mNewPage->getLocalURL(array('action' => 'edit', 'undoafter' => $this->mOldid, 'undo' => $this->mNewid)), 'title' => Linker::titleAttrib('undo')), $this->msg('editundo')->text());
                 $revisionTools['mw-diff-undo'] = $undoLink;
             }
         }
         # Make "previous revision link"
         if ($samePage && $this->mOldRev->getPrevious()) {
             $prevlink = Linker::linkKnown($this->mOldPage, $this->msg('previousdiff')->escaped(), array('id' => 'differences-prevlink'), array('diff' => 'prev', 'oldid' => $this->mOldid) + $query);
         } else {
             $prevlink = ' ';
         }
         if ($this->mOldRev->isMinor()) {
             $oldminor = ChangesList::flag('minor');
         } else {
             $oldminor = '';
         }
         $ldel = $this->revisionDeleteLink($this->mOldRev);
         $oldRevisionHeader = $this->getRevisionHeader($this->mOldRev, 'complete');
         $oldChangeTags = ChangeTags::formatSummaryRow($this->mOldTags, 'diff');
         $oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' . '<div id="mw-diff-otitle2">' . Linker::revUserTools($this->mOldRev, !$this->unhide) . '</div>' . '<div id="mw-diff-otitle3">' . $oldminor . Linker::revComment($this->mOldRev, !$diffOnly, !$this->unhide) . $ldel . '</div>' . '<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' . '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
         if ($this->mOldRev->isDeleted(Revision::DELETED_TEXT)) {
             $deleted = true;
             // old revisions text is hidden
             if ($this->mOldRev->isDeleted(Revision::DELETED_RESTRICTED)) {
                 $suppressed = true;
                 // also suppressed
             }
         }
         # Check if this user can see the revisions
         if (!$this->mOldRev->userCan(Revision::DELETED_TEXT, $user)) {
             $allowed = false;
         }
     }
     # Make "next revision link"
     # Skip next link on the top revision
     if ($samePage && !$this->mNewRev->isCurrent()) {
         $nextlink = Linker::linkKnown($this->mNewPage, $this->msg('nextdiff')->escaped(), array('id' => 'differences-nextlink'), array('diff' => 'next', 'oldid' => $this->mNewid) + $query);
     } else {
         $nextlink = '&#160;';
     }
     if ($this->mNewRev->isMinor()) {
         $newminor = ChangesList::flag('minor');
     } else {
         $newminor = '';
     }
     # Handle RevisionDelete links...
     $rdel = $this->revisionDeleteLink($this->mNewRev);
     # Allow extensions to define their own revision tools
     Hooks::run('DiffRevisionTools', array($this->mNewRev, &$revisionTools, $this->mOldRev, $user));
     $formattedRevisionTools = array();
     // Put each one in parentheses (poor man's button)
     foreach ($revisionTools as $key => $tool) {
         $toolClass = is_string($key) ? $key : 'mw-diff-tool';
         $element = Html::rawElement('span', array('class' => $toolClass), $this->msg('parentheses')->rawParams($tool)->escaped());
         $formattedRevisionTools[] = $element;
     }
     $newRevisionHeader = $this->getRevisionHeader($this->mNewRev, 'complete') . ' ' . implode(' ', $formattedRevisionTools);
     $newChangeTags = ChangeTags::formatSummaryRow($this->mNewTags, 'diff');
     $newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' . '<div id="mw-diff-ntitle2">' . Linker::revUserTools($this->mNewRev, !$this->unhide) . " {$rollback}</div>" . '<div id="mw-diff-ntitle3">' . $newminor . Linker::revComment($this->mNewRev, !$diffOnly, !$this->unhide) . $rdel . '</div>' . '<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' . '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
     if ($this->mNewRev->isDeleted(Revision::DELETED_TEXT)) {
         $deleted = true;
         // new revisions text is hidden
         if ($this->mNewRev->isDeleted(Revision::DELETED_RESTRICTED)) {
             $suppressed = true;
             // also suppressed
         }
     }
     # If the diff cannot be shown due to a deleted revision, then output
     # the diff header and links to unhide (if available)...
     if ($deleted && (!$this->unhide || !$allowed)) {
         $this->showDiffStyle();
         $multi = $this->getMultiNotice();
         $out->addHTML($this->addHeader('', $oldHeader, $newHeader, $multi));
         if (!$allowed) {
             $msg = $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff';
             # Give explanation for why revision is not visible
             $out->wrapWikiMsg("<div id='mw-{$msg}' class='mw-warning plainlinks'>\n\$1\n</div>\n", array($msg));
         } else {
             # Give explanation and add a link to view the diff...
             $query = $this->getRequest()->appendQueryValue('unhide', '1');
             $link = $this->getTitle()->getFullURL($query);
             $msg = $suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff';
             $out->wrapWikiMsg("<div id='mw-{$msg}' class='mw-warning plainlinks'>\n\$1\n</div>\n", array($msg, $link));
         }
         # Otherwise, output a regular diff...
     } else {
         # Add deletion notice if the user is viewing deleted content
         $notice = '';
         if ($deleted) {
             $msg = $suppressed ? 'rev-suppressed-diff-view' : 'rev-deleted-diff-view';
             $notice = "<div id='mw-{$msg}' class='mw-warning plainlinks'>\n" . $this->msg($msg)->parse() . "</div>\n";
         }
         $this->showDiff($oldHeader, $newHeader, $notice);
         if (!$diffOnly) {
             $this->renderNewRevision();
         }
     }
 }
 /**
  * Returns a row from the history printout.
  *
  * @todo document some more, and maybe clean up the code (some params redundant?)
  *
  * @param stdClass $row The database row corresponding to the previous line.
  * @param mixed $next The database row corresponding to the next line
  *   (chronologically previous)
  * @param bool|string $notificationtimestamp
  * @param bool $latest Whether this row corresponds to the page's latest revision.
  * @param bool $firstInList Whether this row corresponds to the first
  *   displayed on this history page.
  * @return string HTML output for the row
  */
 function historyLine($row, $next, $notificationtimestamp = false, $latest = false, $firstInList = false)
 {
     $rev = new Revision($row);
     $rev->setTitle($this->getTitle());
     if (is_object($next)) {
         $prevRev = new Revision($next);
         $prevRev->setTitle($this->getTitle());
     } else {
         $prevRev = null;
     }
     $curlink = $this->curLink($rev, $latest);
     $lastlink = $this->lastLink($rev, $next);
     $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
     $histLinks = Html::rawElement('span', array('class' => 'mw-history-histlinks'), $this->msg('parentheses')->rawParams($curLastlinks)->escaped());
     $diffButtons = $this->diffButtons($rev, $firstInList);
     $s = $histLinks . $diffButtons;
     $link = $this->revLink($rev);
     $classes = array();
     $del = '';
     $user = $this->getUser();
     // Show checkboxes for each revision
     if ($user->isAllowed('deleterevision')) {
         $this->preventClickjacking();
         // If revision was hidden from sysops, disable the checkbox
         if (!$rev->userCan(Revision::DELETED_RESTRICTED, $user)) {
             $del = Xml::check('deleterevisions', false, array('disabled' => 'disabled'));
             // Otherwise, enable the checkbox...
         } else {
             $del = Xml::check('showhiderevisions', false, array('name' => 'ids[' . $rev->getId() . ']'));
         }
         // User can only view deleted revisions...
     } elseif ($rev->getVisibility() && $user->isAllowed('deletedhistory')) {
         // If revision was hidden from sysops, disable the link
         if (!$rev->userCan(Revision::DELETED_RESTRICTED, $user)) {
             $del = Linker::revDeleteLinkDisabled(false);
             // Otherwise, show the link...
         } else {
             $query = array('type' => 'revision', 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId());
             $del .= Linker::revDeleteLink($query, $rev->isDeleted(Revision::DELETED_RESTRICTED), false);
         }
     }
     if ($del) {
         $s .= " {$del} ";
     }
     $lang = $this->getLanguage();
     $dirmark = $lang->getDirMark();
     $s .= " {$link}";
     $s .= $dirmark;
     $s .= " <span class='history-user'>" . Linker::revUserTools($rev, true) . "</span>";
     $s .= $dirmark;
     if ($rev->isMinor()) {
         $s .= ' ' . ChangesList::flag('minor');
     }
     # Sometimes rev_len isn't populated
     if ($rev->getSize() !== null) {
         # Size is always public data
         $prevSize = isset($this->parentLens[$row->rev_parent_id]) ? $this->parentLens[$row->rev_parent_id] : 0;
         $sDiff = ChangesList::showCharacterDifference($prevSize, $rev->getSize());
         $fSize = Linker::formatRevisionSize($rev->getSize());
         $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "{$fSize} {$sDiff}";
     }
     # Text following the character difference is added just before running hooks
     $s2 = Linker::revComment($rev, false, true);
     if ($notificationtimestamp && $row->rev_timestamp >= $notificationtimestamp) {
         $s2 .= ' <span class="updatedmarker">' . $this->msg('updatedmarker')->escaped() . '</span>';
         $classes[] = 'mw-history-line-updated';
     }
     $tools = array();
     # Rollback and undo links
     if ($prevRev && $this->getTitle()->quickUserCan('edit', $user)) {
         if ($latest && $this->getTitle()->quickUserCan('rollback', $user)) {
             // Get a rollback link without the brackets
             $rollbackLink = Linker::generateRollback($rev, $this->getContext(), array('verify', 'noBrackets'));
             if ($rollbackLink) {
                 $this->preventClickjacking();
                 $tools[] = $rollbackLink;
             }
         }
         if (!$rev->isDeleted(Revision::DELETED_TEXT) && !$prevRev->isDeleted(Revision::DELETED_TEXT)) {
             # Create undo tooltip for the first (=latest) line only
             $undoTooltip = $latest ? array('title' => $this->msg('tooltip-undo')->text()) : array();
             $undolink = Linker::linkKnown($this->getTitle(), $this->msg('editundo')->escaped(), $undoTooltip, array('action' => 'edit', 'undoafter' => $prevRev->getId(), 'undo' => $rev->getId()));
             $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
         }
     }
     // Allow extension to add their own links here
     wfRunHooks('HistoryRevisionTools', array($rev, &$tools));
     if ($tools) {
         $s2 .= ' ' . $this->msg('parentheses')->rawParams($lang->pipeList($tools))->escaped();
     }
     # Tags
     list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow($row->ts_tags, 'history');
     $classes = array_merge($classes, $newClasses);
     if ($tagSummary !== '') {
         $s2 .= " {$tagSummary}";
     }
     # Include separator between character difference and following text
     if ($s2 !== '') {
         $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
     }
     wfRunHooks('PageHistoryLineEnding', array($this, &$row, &$s, &$classes));
     $attribs = array();
     if ($classes) {
         $attribs['class'] = implode(' ', $classes);
     }
     return Xml::tags('li', $attribs, $s) . "\n";
 }
 function showDiffPage($diffOnly = false)
 {
     wfProfileIn(__METHOD__);
     # Allow frames except in certain special cases
     $out = $this->getOutput();
     $out->allowClickjacking();
     $out->setRobotPolicy('noindex,nofollow');
     if (!$this->loadRevisionData()) {
         $this->showMissingRevision();
         wfProfileOut(__METHOD__);
         return;
     }
     $user = $this->getUser();
     $permErrors = $this->mNewPage->getUserPermissionsErrors('read', $user);
     if ($this->mOldPage) {
         # mOldPage might not be set, see below.
         $permErrors = wfMergeErrorArrays($permErrors, $this->mOldPage->getUserPermissionsErrors('read', $user));
     }
     if (count($permErrors)) {
         wfProfileOut(__METHOD__);
         throw new PermissionsError('read', $permErrors);
     }
     # If external diffs are enabled both globally and for the user,
     # we'll use the application/x-external-editor interface to call
     # an external diff tool like kompare, kdiff3, etc.
     if (ExternalEdit::useExternalEngine($this->getContext(), 'diff')) {
         //TODO: come up with a good solution for non-text content here.
         //      at least, the content format needs to be passed to the client somehow.
         //      Currently, action=raw will just fail for non-text content.
         $urls = array('File' => array('Extension' => 'wiki', 'URL' => $this->mNewPage->getCanonicalURL(array('action' => 'raw', 'oldid' => $this->mOldid))), 'File2' => array('Extension' => 'wiki', 'URL' => $this->mNewPage->getCanonicalURL(array('action' => 'raw', 'oldid' => $this->mNewid))));
         $externalEditor = new ExternalEdit($this->getContext(), $urls);
         $externalEditor->execute();
         wfProfileOut(__METHOD__);
         return;
     }
     $rollback = '';
     $undoLink = '';
     $query = array();
     # Carry over 'diffonly' param via navigation links
     if ($diffOnly != $user->getBoolOption('diffonly')) {
         $query['diffonly'] = $diffOnly;
     }
     # Cascade unhide param in links for easy deletion browsing
     if ($this->unhide) {
         $query['unhide'] = 1;
     }
     # Check if one of the revisions is deleted/suppressed
     $deleted = $suppressed = false;
     $allowed = $this->mNewRev->userCan(Revision::DELETED_TEXT, $user);
     # mOldRev is false if the difference engine is called with a "vague" query for
     # a diff between a version V and its previous version V' AND the version V
     # is the first version of that article. In that case, V' does not exist.
     if ($this->mOldRev === false) {
         $out->setPageTitle($this->msg('difference-title', $this->mNewPage->getPrefixedText()));
         $samePage = true;
         $oldHeader = '';
     } else {
         wfRunHooks('DiffViewHeader', array($this, $this->mOldRev, $this->mNewRev));
         $sk = $this->getSkin();
         if (method_exists($sk, 'suppressQuickbar')) {
             $sk->suppressQuickbar();
         }
         if ($this->mNewPage->equals($this->mOldPage)) {
             $out->setPageTitle($this->msg('difference-title', $this->mNewPage->getPrefixedText()));
             $samePage = true;
         } else {
             $out->setPageTitle($this->msg('difference-title-multipage', $this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText()));
             $out->addSubtitle($this->msg('difference-multipage'));
             $samePage = false;
         }
         if ($samePage && $this->mNewPage->quickUserCan('edit', $user)) {
             if ($this->mNewRev->isCurrent() && $this->mNewPage->userCan('rollback', $user)) {
                 $out->preventClickjacking();
                 $rollback = '&#160;&#160;&#160;' . Linker::generateRollback($this->mNewRev, $this->getContext());
             }
             if (!$this->mOldRev->isDeleted(Revision::DELETED_TEXT) && !$this->mNewRev->isDeleted(Revision::DELETED_TEXT)) {
                 $undoLink = ' ' . $this->msg('parentheses')->rawParams(Html::element('a', array('href' => $this->mNewPage->getLocalUrl(array('action' => 'edit', 'undoafter' => $this->mOldid, 'undo' => $this->mNewid)), 'title' => Linker::titleAttrib('undo')), $this->msg('editundo')->text()))->escaped();
             }
         }
         # Make "previous revision link"
         if ($samePage && $this->mOldRev->getPrevious()) {
             $prevlink = Linker::linkKnown($this->mOldPage, $this->msg('previousdiff')->escaped(), array('id' => 'differences-prevlink'), array('diff' => 'prev', 'oldid' => $this->mOldid) + $query);
         } else {
             $prevlink = '&#160;';
         }
         if ($this->mOldRev->isMinor()) {
             $oldminor = ChangesList::flag('minor');
         } else {
             $oldminor = '';
         }
         $ldel = $this->revisionDeleteLink($this->mOldRev);
         $oldRevisionHeader = $this->getRevisionHeader($this->mOldRev, 'complete');
         $oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' . '<div id="mw-diff-otitle2">' . Linker::revUserTools($this->mOldRev, !$this->unhide) . '</div>' . '<div id="mw-diff-otitle3">' . $oldminor . Linker::revComment($this->mOldRev, !$diffOnly, !$this->unhide) . $ldel . '</div>' . '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
         if ($this->mOldRev->isDeleted(Revision::DELETED_TEXT)) {
             $deleted = true;
             // old revisions text is hidden
             if ($this->mOldRev->isDeleted(Revision::DELETED_RESTRICTED)) {
                 $suppressed = true;
                 // also suppressed
             }
         }
         # Check if this user can see the revisions
         if (!$this->mOldRev->userCan(Revision::DELETED_TEXT, $user)) {
             $allowed = false;
         }
     }
     # Make "next revision link"
     # Skip next link on the top revision
     if ($samePage && !$this->mNewRev->isCurrent()) {
         $nextlink = Linker::linkKnown($this->mNewPage, $this->msg('nextdiff')->escaped(), array('id' => 'differences-nextlink'), array('diff' => 'next', 'oldid' => $this->mNewid) + $query);
     } else {
         $nextlink = '&#160;';
     }
     if ($this->mNewRev->isMinor()) {
         $newminor = ChangesList::flag('minor');
     } else {
         $newminor = '';
     }
     # Handle RevisionDelete links...
     $rdel = $this->revisionDeleteLink($this->mNewRev);
     $newRevisionHeader = $this->getRevisionHeader($this->mNewRev, 'complete') . $undoLink;
     $newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' . '<div id="mw-diff-ntitle2">' . Linker::revUserTools($this->mNewRev, !$this->unhide) . " {$rollback}</div>" . '<div id="mw-diff-ntitle3">' . $newminor . Linker::revComment($this->mNewRev, !$diffOnly, !$this->unhide) . $rdel . '</div>' . '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
     if ($this->mNewRev->isDeleted(Revision::DELETED_TEXT)) {
         $deleted = true;
         // new revisions text is hidden
         if ($this->mNewRev->isDeleted(Revision::DELETED_RESTRICTED)) {
             $suppressed = true;
         }
         // also suppressed
     }
     # If the diff cannot be shown due to a deleted revision, then output
     # the diff header and links to unhide (if available)...
     if ($deleted && (!$this->unhide || !$allowed)) {
         $this->showDiffStyle();
         $multi = $this->getMultiNotice();
         $out->addHTML($this->addHeader('', $oldHeader, $newHeader, $multi));
         if (!$allowed) {
             $msg = $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff';
             # Give explanation for why revision is not visible
             $out->wrapWikiMsg("<div id='mw-{$msg}' class='mw-warning plainlinks'>\n\$1\n</div>\n", array($msg));
         } else {
             # Give explanation and add a link to view the diff...
             $link = $this->getTitle()->getFullUrl($this->getRequest()->appendQueryValue('unhide', '1', true));
             $msg = $suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff';
             $out->wrapWikiMsg("<div id='mw-{$msg}' class='mw-warning plainlinks'>\n\$1\n</div>\n", array($msg, $link));
         }
         # Otherwise, output a regular diff...
     } else {
         # Add deletion notice if the user is viewing deleted content
         $notice = '';
         if ($deleted) {
             $msg = $suppressed ? 'rev-suppressed-diff-view' : 'rev-deleted-diff-view';
             $notice = "<div id='mw-{$msg}' class='mw-warning plainlinks'>\n" . $this->msg($msg)->parse() . "</div>\n";
         }
         $this->showDiff($oldHeader, $newHeader, $notice);
         if (!$diffOnly) {
             $this->renderNewRevision();
         }
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * 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 #6
0
 public function generateRollback($rev, IContextSource $context = null, $options = ['verify'])
 {
     return Linker::generateRollback($rev, $context, $options);
 }
Example #7
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";
 }
Example #8
0
 /** Inserts a rollback link
  *
  * @param $s string
  * @param $rc RecentChange
  */
 public function insertRollback(&$s, &$rc)
 {
     if (!$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id']) {
         $page = $rc->getTitle();
         /** Check for rollback and edit permissions, disallow special pages, and only
          * show a link on the top-most revision */
         if ($this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']) {
             $rev = new Revision(array('id' => $rc->mAttribs['rc_this_oldid'], 'user' => $rc->mAttribs['rc_user'], 'user_text' => $rc->mAttribs['rc_user_text'], 'deleted' => $rc->mAttribs['rc_deleted']));
             $rev->setTitle($page);
             /** Start of Wikia change @author nAndy */
             $rollbackLink = Linker::generateRollback($rev, $this->getContext());
             wfRunHooks('ChangesListInsertRollback', array($this, &$s, &$rollbackLink, $rc));
             $s .= ' ' . $rollbackLink;
             /*End of Wikia change*/
         }
     }
 }
Example #9
0
 /** @deprecated in 1.21 */
 public function generateRollback($rev, IContextSource $context = null, $options = ['verify'])
 {
     wfDeprecated(__METHOD__, '1.21');
     return Linker::generateRollback($rev, $context, $options);
 }