r105792 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105791‎ | r105792 | r105793 >
Date:13:05, 11 December 2011
Author:cervidae
Status:deferred
Tags:
Comment:
Adding ReassignEdits extension
Modified paths:
  • /trunk/extensions/HelpCommons/HelpCommons.i18n.php (modified) (history)
  • /trunk/extensions/ReassignEdits (added) (history)
  • /trunk/extensions/ReassignEdits/ReassignEdits.alias.php (added) (history)
  • /trunk/extensions/ReassignEdits/ReassignEdits.i18n.php (added) (history)
  • /trunk/extensions/ReassignEdits/ReassignEdits.php (added) (history)
  • /trunk/extensions/ReassignEdits/ReassignEdits_body.php (added) (history)

Diff [purge]

Index: trunk/extensions/HelpCommons/HelpCommons.i18n.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Internationalization file for the HelpCommons extension
 4+ * Internationalization file for HelpCommons extension
55 *
66 * @since 1.0
77 *
@@ -17,7 +17,7 @@
1818 * @author SVG
1919 */
2020 $messages['en'] = array(
21 - 'helpcommons-desc' => 'Fetches the help pages from a help wiki and includes them into other wikis on the wiki family',
 21+ 'helpcommons-desc' => 'Fetches help pages from a help wiki and includes them into other wikis on the wiki family',
2222 );
2323
2424 /** Message documentation (Message documentation)
Index: trunk/extensions/ReassignEdits/ReassignEdits.alias.php
@@ -0,0 +1,29 @@
 2+<?php
 3+/**
 4+* Aliases file for ReassignEdits extension
 5+*
 6+* @package MediaWiki
 7+* @subpackage Extensions
 8+*
 9+* @author: Tim 'SVG' Weyer <SVG@Wikiunity.com>
 10+*
 11+* @copyright Copyright (C) 2011 Tim Weyer, Wikiunity
 12+* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+*
 14+*/
 15+
 16+$specialPageAliases = array();
 17+
 18+/** English
 19+ * @author SVG
 20+ */
 21+$specialPageAliases['en'] = array(
 22+ 'ReassignEdits' => array( 'ReassignEdits', 'ReassignUserEdits' ),
 23+);
 24+
 25+/** German (Deutsch)
 26+ * @author SVG
 27+ */
 28+$specialPageAliases['de'] = array(
 29+ 'ReassignEdits' => array( 'Bearbeitungen_übertragen', 'Benutzerbearbeitungen_übertragen' ),
 30+);
Property changes on: trunk/extensions/ReassignEdits/ReassignEdits.alias.php
___________________________________________________________________
Added: svn:eol-style
131 + native
Index: trunk/extensions/ReassignEdits/ReassignEdits_body.php
@@ -0,0 +1,275 @@
 2+<?php
 3+/**
 4+* ReassignEdits
 5+*
 6+* @package MediaWiki
 7+* @subpackage Extensions
 8+*
 9+* @author: Tim 'SVG' Weyer <SVG@Wikiunity.com>
 10+*
 11+* @copyright Copyright (C) 2011 Tim Weyer, Wikiunity
 12+* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+*
 14+*/
 15+
 16+if (!defined('MEDIAWIKI')) {
 17+ echo "THIS IS NOT VALID ENTRY POINT";
 18+ exit(1);
 19+}
 20+
 21+class SpecialReassignEdits extends SpecialPage {
 22+ /**
 23+ * Constructor
 24+ */
 25+ public function __construct() {
 26+ parent::__construct( 'ReassignEdits', 'reassignedits' );
 27+ }
 28+
 29+ /**
 30+ * Show the special page
 31+ *
 32+ * @param mixed $par Parameter passed to the page
 33+ */
 34+ public function execute( $par ) {
 35+ global $wgOut, $wgUser, $wgRequest, $wgContLang;
 36+ global $wgCapitalLinks;
 37+
 38+ $this->setHeaders();
 39+ $wgOut->addWikiMsg( 'reassignedits-summary' );
 40+
 41+ // If the user doesn't have 'reassignedits' permission, display an error
 42+ if ( !$wgUser->isAllowed( 'reassignedits' ) ) {
 43+ $this->displayRestrictionError();
 44+ return;
 45+ }
 46+
 47+ // Show a message if the database is in read-only mode
 48+ if ( wfReadOnly() ) {
 49+ $wgOut->readOnlyPage();
 50+ return;
 51+ }
 52+
 53+ // If user is blocked, s/he doesn't need to access this page
 54+ if ( $wgUser->isBlocked() ) {
 55+ $wgOut->blockedPage();
 56+ return;
 57+ }
 58+
 59+ $oldnamePar = trim( str_replace( '_', ' ', $wgRequest->getText( 'oldusername', $par ) ) );
 60+ $oldusername = Title::makeTitle( NS_USER, $oldnamePar );
 61+ // Force uppercase of newusername, otherwise wikis with wgCapitalLinks=false can create lc usernames
 62+ $newusername = Title::makeTitleSafe( NS_USER, $wgContLang->ucfirst( $wgRequest->getText( 'newusername' ) ) );
 63+ $oun = is_object( $oldusername ) ? $oldusername->getText() : '';
 64+ $nun = is_object( $newusername ) ? $newusername->getText() : '';
 65+ $token = $wgUser->editToken();
 66+
 67+ $updatelogging_user = $wgRequest->getBool( 'updatelogginguser', !$wgRequest->wasPosted());
 68+ $updatelogging_title = $wgRequest->getCheck( 'updateloggingtitle' );
 69+
 70+ $wgOut->addHTML(
 71+ Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl(), 'id' => 'reassignedits' ) ) .
 72+ Xml::openElement( 'fieldset' ) .
 73+ Xml::element( 'legend', null, wfMsg( 'reassignedits' ) ) .
 74+ Xml::openElement( 'table', array( 'id' => 'mw-reassignedits-table' ) ) .
 75+ "<tr>
 76+ <td class='mw-label'>" .
 77+ Xml::label( wfMsg( 'reassignedits-old' ), 'oldusername' ) .
 78+ "</td>
 79+ <td class='mw-input'>" .
 80+ Xml::input( 'oldusername', 20, $oun, array( 'type' => 'text', 'tabindex' => '1' ) ) . ' ' .
 81+ "</td>
 82+ </tr>
 83+ <tr>
 84+ <td class='mw-label'>" .
 85+ Xml::label( wfMsg( 'reassignedits-new' ), 'newusername' ) .
 86+ "</td>
 87+ <td class='mw-input'>" .
 88+ Xml::input( 'newusername', 20, $nun, array( 'type' => 'text', 'tabindex' => '2' ) ) .
 89+ "</td>
 90+ </tr>"
 91+ );
 92+ $wgOut->addHTML( "
 93+ <tr>
 94+ <td>&#160;
 95+ </td>
 96+ <td class='mw-input'>" .
 97+ Xml::checkLabel( wfMsg( 'reassignedits-updatelog-user' ), 'updatelogginguser', 'updatelogginguser',
 98+ $updatelogging_user, array( 'tabindex' => '3' ) ) .
 99+ "</td>
 100+ </tr>"
 101+ );
 102+ $wgOut->addHTML( "
 103+ <tr>
 104+ <td>&#160;
 105+ </td>
 106+ <td class='mw-input'>" .
 107+ Xml::checkLabel( wfMsg( 'reassignedits-updatelog-title' ), 'updateloggingtitle', 'updateloggingtitle',
 108+ $updatelogging_title, array( 'tabindex' => '4' ) ) .
 109+ "</td>
 110+ </tr>"
 111+ );
 112+ $wgOut->addHTML( "
 113+ <tr>
 114+ <td>&#160;
 115+ </td>
 116+ <td class='mw-submit'>" .
 117+ Xml::submitButton( wfMsg( 'reassignedits-submit' ), array( 'name' => 'submit',
 118+ 'tabindex' => '5', 'id' => 'submit' ) ) .
 119+ "</td>
 120+ </tr>" .
 121+ Xml::closeElement( 'table' ) .
 122+ Xml::closeElement( 'fieldset' ) .
 123+ Html::hidden( 'token', $token ) .
 124+ Xml::closeElement( 'form' ) . "\n"
 125+ );
 126+
 127+ if ( $wgRequest->getText( 'token' ) === '' ) {
 128+ // They probably haven't even submitted the form, so don't go further
 129+ return;
 130+ } elseif ( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
 131+ $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'reassignedits-error-request' ) . "</div>" );
 132+ return;
 133+ } elseif ( !is_object( $oldusername ) ) {
 134+ $wgOut->addWikiText(
 135+ "<div class=\"errorbox\">"
 136+ . wfMsg( 'reassignedits-error-invalid', $wgRequest->getText( 'oldusername' ) )
 137+ . "</div>"
 138+ );
 139+ return;
 140+ } elseif ( !is_object( $newusername ) ) {
 141+ $wgOut->addWikiText(
 142+ "<div class=\"errorbox\">"
 143+ . wfMsg( 'reassignedits-error-invalid', $wgRequest->getText( 'newusername' ) )
 144+ . "</div>"
 145+ );
 146+ return;
 147+ }
 148+
 149+ // Get usernames by id
 150+ $olduser = User::newFromName( $oldusername->getText() );
 151+ $newuser = User::newFromName( $newusername->getText() );
 152+
 153+ // It won't be an object if for instance "|" is supplied as a value
 154+ if ( !is_object( $olduser ) ) {
 155+ $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'reassignedits-error-invalid',
 156+ $oldusername->getText() ) . "</div>" );
 157+ return;
 158+ }
 159+ if ( !is_object( $newuser ) ) {
 160+ $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'reassignedits-error-invalid',
 161+ $newusername->getText() ) . "</div>" );
 162+ return;
 163+ }
 164+
 165+ // Check for the existence of lowercase oldusername in database
 166+ if ( $oldusername->getText() !== $wgContLang->ucfirst( $oldusername->getText() ) ) {
 167+ // oldusername was entered as lowercase -> check for existence in table 'user'
 168+ $dbr = wfGetDB( DB_SLAVE );
 169+ $uid = $dbr->selectField( 'user', 'user_id',
 170+ array( 'user_name' => $oldusername->getText() ),
 171+ __METHOD__ );
 172+ if ( $uid === false ) {
 173+ if ( !$wgCapitalLinks ) {
 174+ $uid = 0; // We are on a lowercase wiki but lowercase username does not exists
 175+ } else {
 176+ // We are on a standard uppercase wiki, use normal
 177+ $uid = $olduser->idForName();
 178+ $oldusername = Title::makeTitleSafe( NS_USER, $olduser->getName() );
 179+ }
 180+ }
 181+ } else {
 182+ // oldusername was entered as upperase -> standard procedure
 183+ $uid = $olduser->idForName();
 184+ }
 185+
 186+ // Do the heavy lifting...
 187+ $reassign = new ReassignEditsSQL( $oldusername->getText(), $newusername->getText() );
 188+ if ( !$reassign->reassign() ) {
 189+ return;
 190+ }
 191+
 192+ // Output success message
 193+ $wgOut->addWikiText( "<div class=\"successbox\">" . wfMsg( 'reassignedits-success', $oldusername->getText(),
 194+ $newusername->getText() ) . "</div><br style=\"clear:both\" />" );
 195+ }
 196+}
 197+
 198+class ReassignEditsSQL {
 199+ /**
 200+ * The old username
 201+ *
 202+ * @var string
 203+ * @access private
 204+ */
 205+ var $old;
 206+
 207+ /**
 208+ * The new username
 209+ *
 210+ * @var string
 211+ * @access private
 212+ */
 213+ var $new;
 214+
 215+ /**
 216+ * Constructor
 217+ *
 218+ * @param string $old The old username
 219+ * @param string $new The new username
 220+ */
 221+ function __construct( $old, $new ) {
 222+ $this->old = $old;
 223+ $this->new = $new;
 224+ }
 225+
 226+ /**
 227+ * Do the reassign operation
 228+ */
 229+ function reassign() {
 230+ global $wgRequest;
 231+
 232+ wfProfileIn( __METHOD__ );
 233+
 234+ $dbw = wfGetDB( DB_MASTER );
 235+ $dbw->begin();
 236+
 237+ $newname = $this->new;
 238+ $newid = User::idFromName( $this->new );
 239+ $oldname = $this->old;
 240+
 241+ // Update archive table (deleted revisions)
 242+ $dbw->update( 'archive',
 243+ array( 'ar_user_text' => $newname, 'ar_user' => $newid ),
 244+ array( 'ar_user_text' => $oldname ),
 245+ __METHOD__ );
 246+ // Update user in logging table if checkbox is true
 247+ if ( $wgRequest->getCheck( 'updatelogginguser' ) ) {
 248+ $dbw->update( 'logging',
 249+ array( 'log_user_text' => $newname, 'log_user' => $newid ),
 250+ array( 'log_user_text' => $oldname ),
 251+ __METHOD__ );
 252+ }
 253+ // Update title in logging table if checkbox is true
 254+ if ( $wgRequest->getCheck( 'updateloggingtitle' ) ) {
 255+ $oldTitle = Title::makeTitle( NS_USER, $this->old );
 256+ $newTitle = Title::makeTitle( NS_USER, $this->new );
 257+ $dbw->update( 'logging',
 258+ array( 'log_title' => $newTitle->getDBkey() ),
 259+ array( 'log_type' => array( 'block', 'rights' ),
 260+ 'log_namespace' => NS_USER,
 261+ 'log_title' => $oldTitle->getDBkey() ),
 262+ __METHOD__ );
 263+ }
 264+ // Update revision table
 265+ $dbw->update( 'revision',
 266+ array( 'rev_user_text' => $newname, 'rev_user' => $newid ),
 267+ array( 'rev_user_text' => $oldname ),
 268+ __METHOD__ );
 269+
 270+ // Commit the transaction
 271+ $dbw->commit();
 272+
 273+ wfProfileOut( __METHOD__ );
 274+ return true;
 275+ }
 276+}
Property changes on: trunk/extensions/ReassignEdits/ReassignEdits_body.php
___________________________________________________________________
Added: svn:eol-style
1277 + native
Index: trunk/extensions/ReassignEdits/ReassignEdits.i18n.php
@@ -0,0 +1,69 @@
 2+<?php
 3+/**
 4+* Internationlization file for ReassignEdits extension
 5+*
 6+* @package MediaWiki
 7+* @subpackage Extensions
 8+*
 9+* @author: Tim 'SVG' Weyer <SVG@Wikiunity.com>
 10+*
 11+* @copyright Copyright (C) 2011 Tim Weyer, Wikiunity
 12+* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+*
 14+*/
 15+
 16+$messages = array();
 17+
 18+/** English
 19+ * @author SVG
 20+ */
 21+$messages['en'] = array(
 22+ 'reassignedits' => 'Reassign user edits',
 23+ 'reassignedits-desc' => 'Allows reassigning edits from an old user to a new one',
 24+ 'reassignedits-error-invalid' => 'The username "<nowiki>$1</nowiki>" is invalid.',
 25+ 'reassignedits-new' => 'New user name',
 26+ 'reassignedits-old' => 'Old user name',
 27+ 'reassignedits-submit' => 'Submit',
 28+ 'reassignedits-success' => 'The user edits by "<nowiki>$1</nowiki>" has been added to "<nowiki>$2</nowiki>".',
 29+ 'reassignedits-summary' => 'Reassign edits from an old user to a new one.',
 30+ 'reassignedits-updatelog-title' => 'Update user name in log titles',
 31+ 'reassignedits-updatelog-user' => 'Update executive user in logs',
 32+
 33+ 'right-reassignedits' => 'Reassign edits from an old user to a new one',
 34+);
 35+
 36+/** Message documentation (Message documentation)
 37+ * @author SVG
 38+ */
 39+$messages['qqq'] = array(
 40+ 'reassignedits' => 'Name of Special:ReassignEdits in Special:SpecialPages and title of Special:ReassignEdits page',
 41+ 'reassignedits-desc' => '{{desc}}',
 42+ 'reassignedits-error-invalid' => 'Error message which will be shown if given user name is invalid',
 43+ 'reassignedits-new' => '{{msg-mw|reassignedits-new}}',
 44+ 'reassignedits-old' => '{{msg-mw|reassignedits-old}}',
 45+ 'reassignedits-submit' => '{{msg-mw|reassignedits-submit}}',
 46+ 'reassignedits-success' => 'Success message when user edits has been successfully moved from one user to another one',
 47+ 'reassignedits-summary' => 'Short summary on Special:ReassignEdits how-to-use this extensions',
 48+ 'reassignedits-updatelog-title' => 'Checkbox: {{msg-mw|reassignedits-updatelog-title}}',
 49+ 'reassignedits-updatelog-user' => 'Checkbox: {{msg-mw|reassignedits-updatelog-user}}',
 50+
 51+ 'right-reassignedits' => '{{doc-right|reassignedits}}',
 52+);
 53+
 54+/** German (Deutsch)
 55+ * @author SVG
 56+ */
 57+$messages['de'] = array(
 58+ 'reassignedits' => 'Bearbeitungen übertragen',
 59+ 'reassignedits-desc' => 'Erlaubt das Übertragen von Bearbeitungen eines alten Benutzer zu einem neuen Benutzer',
 60+ 'reassignedits-error-invalid' => 'Der Benutzername „<nowiki>$1</nowiki>“ ist ungültig.',
 61+ 'reassignedits-new' => 'Name des neuen Benutzers',
 62+ 'reassignedits-old' => 'Name des alten Benutzers',
 63+ 'reassignedits-submit' => 'Ausführen',
 64+ 'reassignedits-success' => 'Die Bearbeitungen von Benutzer „<nowiki>$1</nowiki>“ wurden dem Benutzer „<nowiki>$2</nowiki>“ hinzugefügt.',
 65+ 'reassignedits-summary' => 'Übertrage Bearbeitungen von einem alten Benutzer einem neuen Benutzer.',
 66+ 'reassignedits-updatelog-title' => 'Erneuere den Benutzernamen in Logbuch-Titeln',
 67+ 'reassignedits-updatelog-user' => 'Ändere den Benutzernamen des ausführenden Benutzers in den Logbüchern',
 68+
 69+ 'right-reassignedits' => 'Übertragen von Bearbeitungen eines alten Benutzers zu einem neuen Benutzer',
 70+);
Property changes on: trunk/extensions/ReassignEdits/ReassignEdits.i18n.php
___________________________________________________________________
Added: svn:eol-style
171 + native
Index: trunk/extensions/ReassignEdits/ReassignEdits.php
@@ -0,0 +1,40 @@
 2+<?php
 3+/**
 4+* ReassignEdits
 5+*
 6+* @package MediaWiki
 7+* @subpackage Extensions
 8+*
 9+* @author: Tim 'SVG' Weyer <SVG@Wikiunity.com>
 10+*
 11+* @copyright Copyright (C) 2011 Tim Weyer, Wikiunity
 12+* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+*
 14+*/
 15+
 16+if (!defined('MEDIAWIKI')) {
 17+ echo "THIS IS NOT VALID ENTRY POINT";
 18+ exit(1);
 19+}
 20+
 21+$wgExtensionCredits['specialpage'][] = array(
 22+ 'path' => __FILE__,
 23+ 'name' => 'ReassignEdits',
 24+ 'author' => array( 'Tim Weyer' ),
 25+ 'url' => 'http://www.mediawiki.org/wiki/Extension:ReassignEdits',
 26+ 'descriptionmsg' => 'reassignedits-desc',
 27+ 'version' => '0.1.0',
 28+);
 29+
 30+// Add permission required to use Special:ReassignEdits
 31+$wgAvailableRights[] = 'reassignedits';
 32+
 33+// Internationalization files
 34+$dir = dirname( __FILE__ ) . '/';
 35+$wgExtensionMessagesFiles['ReassignEdits'] = $dir . 'ReassignEdits.i18n.php';
 36+$wgExtensionMessagesFiles['ReassignEditsAliases'] = $dir . 'ReassignEdits.alias.php';
 37+
 38+// Special page classes
 39+$wgAutoloadClasses['SpecialReassignEdits'] = $dir . 'ReassignEdits_body.php';
 40+$wgSpecialPages['ReassignEdits'] = 'SpecialReassignEdits';
 41+$wgSpecialPageGroups['ReassignEdits'] = 'users';

Follow-up revisions

RevisionCommit summaryAuthorDate
r105793adding svn:eol-style nativecervidae13:14, 11 December 2011
r106381r105792: Consistency tweaks in preparation for adding extension to translatew...raymond21:57, 15 December 2011
r106382r105792: Adding extension to translatewiki.netraymond21:58, 15 December 2011

Status & tagging log