* urlencode username so rollback-on-history works for users with funny names
authorAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 16 Nov 2006 22:53:01 +0000 (22:53 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 16 Nov 2006 22:53:01 +0000 (22:53 +0000)
* Move rollback-link-generating code to Linker::generateRollback

includes/DifferenceEngine.php
includes/Linker.php
includes/PageHistory.php
includes/SpecialContributions.php

index 72ba346..2bccc8f 100644 (file)
@@ -148,11 +148,7 @@ CONTROL;
                $contribs = wfMsg( 'contribslink' );
 
                if ( $this->mNewRev->isCurrent() && $wgUser->isAllowed('rollback') ) {
-                       $username = $this->mNewRev->getUserText();
-                       $rollback = '&nbsp;&nbsp;&nbsp;<strong>[' . $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'rollbacklink' ),
-                               'action=rollback&from=' . urlencode( $username ) .
-                               '&token=' . urlencode( $wgUser->editToken( array( $this->mTitle->getPrefixedText(), $username ) ) ) ) .
-                               ']</strong>';
+                       $rollback = '&nbsp;&nbsp;&nbsp;' . $sk->generateRollback( $this->mNewRev );
                } else {
                        $rollback = '';
                }
index 9bebea2..ff86912 100644 (file)
@@ -1095,5 +1095,29 @@ class Linker {
                return array( $inside, $trail );
        }
 
+       /**
+        * Generate a rollback link for a given revision.  Currently it's the
+        * caller's responsibility to ensure that the revision is the top one. If
+        * it's not, of course, the user will get an error message.
+        *
+        * If the calling page is called with the parameter &bot=1, all rollback
+        * links also get that parameter. It causes the edit itself and the rollback
+        * to be marked as "bot" edits. Bot edits are hidden by default from recent
+        * changes, so this allows sysops to combat a busy vandal without bothering
+        * other users.
+        *
+        * @param Revision $rev
+        */
+       function generateRollback( $rev ) {
+               global $wgUser, $wgRequest;
+               $title = $rev->getTitle();
+
+               $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
+               $extraRollback .= '&token=' . urlencode(
+                       $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ) );
+               return '<span class="mw-rollback-link">['. $this->makeKnownLinkObj( $title,
+                       wfMsg('rollbacklink'),
+                       'action=rollback&from=' . urlencode( $rev->getUserText() ) . $extraRollback ) .']</span>';
+       }
 }
 ?>
index 780b5a0..16c405c 100644 (file)
@@ -168,7 +168,7 @@ class PageHistory {
 
        /** @todo document */
        function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false, $firstInList = false ) {
-               global $wgUser, $wgRequest, $wgTitle;
+               global $wgUser;
                $rev = new Revision( $row );
                $rev->setTitle( $this->mTitle );
 
@@ -211,12 +211,7 @@ class PageHistory {
                        $s .= ' ' . wfMsgHtml( 'deletedrev' );
                }
                if( $wgUser->isAllowed( 'rollback' ) && $firstInList ) {
-                       $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
-                       $extraRollback .= '&token=' . urlencode(
-                               $wgUser->editToken( array( $wgTitle->getPrefixedText(), $rev->getUserText() ) ) );
-                       $s .= ' ['. $this->mSkin->makeKnownLinkObj( $wgTitle,
-                               wfMsg('rollbacklink'),
-                               'action=rollback&from=' . $rev->getUserText() . $extraRollback ) .']';
+                       $s .= ' '.$this->mSkin->generateRollback( $rev );
                }
                $s .= "</li>\n";
 
index 29198bb..239fb8b 100644 (file)
@@ -369,12 +369,6 @@ function contributionsForm( $options ) {
  * privileges. The rollback link restores the most recent version that was not
  * written by the target user.
  *
- * If the contributions page is called with the parameter &bot=1, all rollback
- * links also get that parameter. It causes the edit itself and the rollback
- * to be marked as "bot" edits. Bot edits are hidden by default from recent
- * changes, so this allows sysops to combat a busy vandal without bothering
- * other users.
- *
  * @todo This would probably look a lot nicer in a table.
  */
 function ucListEdit( $sk, $row ) {
@@ -390,7 +384,7 @@ function ucListEdit( $sk, $row ) {
        }
 
        $rev = new Revision( $row );
-       
+
        $page = Title::makeTitle( $row->page_namespace, $row->page_title );
        $link = $sk->makeKnownLinkObj( $page );
        $difftext = $topmarktext = '';
@@ -403,12 +397,7 @@ function ucListEdit( $sk, $row ) {
                }
 
                if( $wgUser->isAllowed( 'rollback' ) ) {
-                       $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
-                       $extraRollback .= '&token=' . urlencode(
-                               $wgUser->editToken( array( $page->getPrefixedText(), $row->rev_user_text ) ) );
-                       $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
-                               $messages['rollbacklink'],
-                               'action=rollback&from=' . urlencode( $row->rev_user_text ) . $extraRollback ) .']';
+                       $topmarktext .= ' '.$sk->generateRollback( $rev );
                }
 
        }