r29557 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29556‎ | r29557 | r29558 >
Date:21:26, 10 January 2008
Author:catrope
Status:old
Tags:
Comment:
ChangeAuthor: fix hinky tab style and remove loadMessages hook
Modified paths:
  • /trunk/extensions/ChangeAuthor/ChangeAuthor.body.php (modified) (history)
  • /trunk/extensions/ChangeAuthor/ChangeAuthor.setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ChangeAuthor/ChangeAuthor.body.php
@@ -16,351 +16,350 @@
1717 */
1818 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the extension file directly.
1919 if (!defined('MEDIAWIKI')) {
20 - echo <<<EOT
 20+ echo <<<EOT
2121 To install the ChangeAuthor extension, put the following line in LocalSettings.php:
2222 require_once( "$IP/extensions/ChangeAuthor/ChangeAuthor.setup.php" );
2323 EOT;
24 - exit(1);
 24+ exit(1);
2525 }
2626
2727 class ChangeAuthor extends SpecialPage
2828 {
29 - var $selfTitle, $skin;
30 - function __construct()
 29+ var $selfTitle, $skin;
 30+ function __construct()
 31+ {
 32+ global $wgUser;
 33+ self::loadMessages();
 34+ parent::__construct(wfMsg('changeauthor-short'), 'changeauthor');
 35+ $this->selfTitle = Title::makeTitleSafe(NS_SPECIAL, wfMsg('changeauthor-short'));
 36+ $this->skin = $wgUser->getSkin();
 37+ }
 38+
 39+ function execute($par)
 40+ {
 41+ global $wgRequest, $wgOut, $wgContLang, $wgUser;
 42+ $this->setHeaders();
 43+ if(!$this->userCanExecute($wgUser))
3144 {
32 - global $wgUser;
33 - self::loadMessages();
34 - parent::__construct(wfMsg('changeauthor-short'), 'changeauthor');
35 - $this->selfTitle = Title::makeTitleSafe(NS_SPECIAL, wfMsg('changeauthor-short'));
36 - $this->skin = $wgUser->getSkin();
 45+ $this->displayRestrictionError();
 46+ return;
3747 }
38 -
39 - function execute($par)
 48+
 49+ $wgOut->setPageTitle(wfMsg('changeauthor-title'));
 50+
 51+ if(!is_null($par))
4052 {
41 - global $wgRequest, $wgOut, $wgContLang, $wgUser;
42 - $this->setHeaders();
43 - if(!$this->userCanExecute($wgUser))
 53+ $obj = $this->parseTitleOrRevID($par);
 54+ if($obj instanceof Title)
 55+ {
 56+ if($obj->exists())
 57+ $wgOut->addHTML($this->buildRevisionList($obj));
 58+ else
 59+ $wgOut->addHTML($this->buildInitialForm(wfMsg('changeauthor-nosuchtitle', $obj->getPrefixedText())));
 60+ return;
 61+ }
 62+ else if($obj instanceof Revision)
 63+ {
 64+ $wgOut->addHTML($this->buildOneRevForm($obj));
 65+ return;
 66+ }
 67+ }
 68+
 69+ $action = $wgRequest->getVal('action');
 70+ if($wgRequest->wasPosted() && $action == 'change')
 71+ {
 72+ $arr = $this->parseChangeRequest();
 73+ if(!is_array($arr))
 74+ {
 75+ $targetPage = $wgRequest->getVal('targetpage');
 76+ if(!is_null($targetPage))
4477 {
45 - $this->displayRestrictionError();
46 - return;
 78+ $wgOut->addHTML($this->buildRevisionList(Title::newFromURL($targetPage), $arr));
 79+ return;
4780 }
48 -
49 - $wgOut->setPageTitle(wfMsg('changeauthor-title'));
50 -
51 - if(!is_null($par))
 81+ $targetRev = $wgRequest->getVal('targetrev');
 82+ if(!is_null($targetRev))
5283 {
53 - $obj = $this->parseTitleOrRevID($par);
54 - if($obj instanceof Title)
55 - {
56 - if($obj->exists())
57 - $wgOut->addHTML($this->buildRevisionList($obj));
58 - else
59 - $wgOut->addHTML($this->buildInitialForm(wfMsg('changeauthor-nosuchtitle', $obj->getPrefixedText())));
60 - return;
61 - }
62 - else if($obj instanceof Revision)
63 - {
64 - $wgOut->addHTML($this->buildOneRevForm($obj));
65 - return;
66 - }
 84+ $wgOut->addHTML($this->buildOneRevForm(Revision::newFromId($targetRev), $arr));
 85+ return;
6786 }
68 -
69 - $action = $wgRequest->getVal('action');
70 - if($wgRequest->wasPosted() && $action == 'change')
71 - {
72 - $arr = $this->parseChangeRequest();
73 - if(!is_array($arr))
74 - {
75 - $targetPage = $wgRequest->getVal('targetpage');
76 - if(!is_null($targetPage))
77 - {
78 - $wgOut->addHTML($this->buildRevisionList(Title::newFromURL($targetPage), $arr));
79 - return;
80 - }
81 - $targetRev = $wgRequest->getVal('targetrev');
82 - if(!is_null($targetRev))
83 - {
84 - $wgOut->addHTML($this->buildOneRevForm(Revision::newFromId($targetRev), $arr));
85 - return;
86 - }
87 - $wgOut->addHTML($this->buildInitialForm());
88 - }
89 - else
90 - {
91 - $this->changeRevAuthors($arr, $wgRequest->getVal('comment'));
92 - $wgOut->addWikiText(wfMsg('changeauthor-success'));
93 - }
94 - return;
95 - }
96 - if($wgRequest->wasPosted() && $action == 'list')
97 - {
98 - $obj = $this->parseTitleOrRevID($wgRequest->getVal('pagename-revid'));
99 - if($obj instanceof Title)
100 - {
101 - if($obj->exists())
102 - $wgOut->addHTML($this->buildRevisionList($obj));
103 - else
104 - $wgOut->addHTML($this->buildInitialForm(wfMsg('changeauthor-nosuchtitle', $obj->getPrefixedText())));
105 - }
106 - else if($obj instanceof Revision)
107 - {
108 - $wgOut->addHTML($this->buildOneRevForm($obj));
109 - }
110 - return;
111 - }
11287 $wgOut->addHTML($this->buildInitialForm());
 88+ }
 89+ else
 90+ {
 91+ $this->changeRevAuthors($arr, $wgRequest->getVal('comment'));
 92+ $wgOut->addWikiText(wfMsg('changeauthor-success'));
 93+ }
 94+ return;
11395 }
114 -
115 - private function parseTitleOrRevID($str)
 96+ if($wgRequest->wasPosted() && $action == 'list')
11697 {
117 - // Parse what can be a revision ID or an article name
118 - // Returns: Title or Revision object, or NULL
119 - $retval = false;
120 - if(is_numeric($str))
121 - $retval = Revision::newFromID($str);
122 - if(!$retval)
123 - $retval = Title::newFromURL($str);
124 - return $retval;
 98+ $obj = $this->parseTitleOrRevID($wgRequest->getVal('pagename-revid'));
 99+ if($obj instanceof Title)
 100+ {
 101+ if($obj->exists())
 102+ $wgOut->addHTML($this->buildRevisionList($obj));
 103+ else
 104+ $wgOut->addHTML($this->buildInitialForm(wfMsg('changeauthor-nosuchtitle', $obj->getPrefixedText())));
 105+ }
 106+ else if($obj instanceof Revision)
 107+ {
 108+ $wgOut->addHTML($this->buildOneRevForm($obj));
 109+ }
 110+ return;
125111 }
 112+ $wgOut->addHTML($this->buildInitialForm());
 113+ }
126114
127 - private function buildInitialForm($errMsg = '')
128 - {
129 - // Builds the form that asks for a page name or revid
130 - // $errMsg: Error message
131 - // Returns: HTML
132 -
133 - global $wgScript;
134 - $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
135 - $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
136 - $retval .= Xml::hidden('action', 'list');
137 - $retval .= Xml::openElement('fieldset');
138 - $retval .= Xml::element('legend', array(), wfMsg('changeauthor-search-box'));
139 - $retval .= Xml::inputLabel(wfMsg('changeauthor-pagename-or-revid'),
140 - 'pagename-revid', 'pagename-revid');
141 - $retval .= Xml::submitButton(wfMsg('changeauthor-pagenameform-go'));
142 - if($errMsg != '')
143 - {
144 - $retval .= Xml::openElement('p') . Xml::openElement('b');
145 - $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
146 - $retval .= Xml::closeElement('b') . Xml::closeElement('p');
147 - }
148 - $retval .= Xml::closeElement('fieldset');
149 - $retval .= Xml::closeElement('form');
150 - return $retval;
 115+ private function parseTitleOrRevID($str)
 116+ {
 117+ // Parse what can be a revision ID or an article name
 118+ // Returns: Title or Revision object, or NULL
 119+ $retval = false;
 120+ if(is_numeric($str))
 121+ $retval = Revision::newFromID($str);
 122+ if(!$retval)
 123+ $retval = Title::newFromURL($str);
 124+ return $retval;
 125+ }
 126+
 127+ private function buildInitialForm($errMsg = '')
 128+ {
 129+ // Builds the form that asks for a page name or revid
 130+ // $errMsg: Error message
 131+ // Returns: HTML
 132+
 133+ global $wgScript;
 134+ $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
 135+ $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
 136+ $retval .= Xml::hidden('action', 'list');
 137+ $retval .= Xml::openElement('fieldset');
 138+ $retval .= Xml::element('legend', array(), wfMsg('changeauthor-search-box'));
 139+ $retval .= Xml::inputLabel(wfMsg('changeauthor-pagename-or-revid'),
 140+ 'pagename-revid', 'pagename-revid');
 141+ $retval .= Xml::submitButton(wfMsg('changeauthor-pagenameform-go'));
 142+ if($errMsg != '')
 143+ {
 144+ $retval .= Xml::openElement('p') . Xml::openElement('b');
 145+ $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
 146+ $retval .= Xml::closeElement('b') . Xml::closeElement('p');
151147 }
 148+ $retval .= Xml::closeElement('fieldset');
 149+ $retval .= Xml::closeElement('form');
 150+ return $retval;
 151+ }
 152+
 153+ private function buildRevisionLine($rev, $title, $isFirst = false, $isLast = false)
 154+ {
 155+ // Builds a line for revision $rev
 156+ // Helper to buildRevisionList() and buildOneRevForm()
 157+ // $rev: Revision object
 158+ // $title: Title object
 159+ // $isFirst: Set to true if $rev is the first revision
 160+ // $isLast: Set to true if $rev is the last revision
 161+ // Returns: HTML
152162
153 - private function buildRevisionLine($rev, $title, $isFirst = false, $isLast = false)
 163+ // Build curlink
 164+ if($isFirst)
 165+ $curLink = wfMsgExt('cur', array('escape'));
 166+ else
 167+ $curLink = $this->skin->makeKnownLinkObj($title,
 168+ wfMsgExt('cur', array('escape')),
 169+ "oldid={$rev->getId()}&diff=cur");
 170+
 171+ if($isLast)
 172+ $lastLink = wfMsgExt('last', array('escape'));
 173+ else
 174+ $lastLink = $this->skin->makeKnownLinkObj($title,
 175+ wfMsgExt('last', array('escape')),
 176+ "oldid=prev&diff={$rev->getId()}");
 177+
 178+ // Build oldid link
 179+ global $wgLang;
 180+ $date = $wgLang->timeanddate(wfTimeStamp(TS_MW, $rev->getTimestamp()), true);
 181+ if($rev->userCan(Revision::DELETED_TEXT))
 182+ $link = $this->skin->makeKnownLinkObj($title, $date, "oldid={$rev->getId()}");
 183+ else
 184+ $link = $date;
 185+
 186+ // Build user textbox
 187+ global $wgRequest;
 188+ $userBox = Xml::input("user-new-{$rev->getId()}", 50, $wgRequest->getVal("user-{$rev->getId()}", $rev->getUserText()));
 189+ $userText = Xml::hidden("user-old-{$rev->getId()}", $rev->getUserText()) . $rev->getUserText();
 190+
 191+ if (!is_null($size = $rev->getSize()))
154192 {
155 - // Builds a line for revision $rev
156 - // Helper to buildRevisionList() and buildOneRevForm()
157 - // $rev: Revision object
158 - // $title: Title object
159 - // $isFirst: Set to true if $rev is the first revision
160 - // $isLast: Set to true if $rev is the last revision
161 - // Returns: HTML
162 -
163 - // Build curlink
164 - if($isFirst)
165 - $curLink = wfMsgExt('cur', array('escape'));
166 - else
167 - $curLink = $this->skin->makeKnownLinkObj($title,
168 - wfMsgExt('cur', array('escape')),
169 - "oldid={$rev->getId()}&diff=cur");
170 -
171 - if($isLast)
172 - $lastLink = wfMsgExt('last', array('escape'));
173 - else
174 - $lastLink = $this->skin->makeKnownLinkObj($title,
175 - wfMsgExt('last', array('escape')),
176 - "oldid=prev&diff={$rev->getId()}");
177 -
178 - // Build oldid link
179 - global $wgLang;
180 - $date = $wgLang->timeanddate(wfTimeStamp(TS_MW, $rev->getTimestamp()), true);
181 - if($rev->userCan(Revision::DELETED_TEXT))
182 - $link = $this->skin->makeKnownLinkObj($title, $date, "oldid={$rev->getId()}");
183 - else
184 - $link = $date;
185 -
186 - // Build user textbox
187 - global $wgRequest;
188 - $userBox = Xml::input("user-new-{$rev->getId()}", 50, $wgRequest->getVal("user-{$rev->getId()}", $rev->getUserText()));
189 - $userText = Xml::hidden("user-old-{$rev->getId()}", $rev->getUserText()) . $rev->getUserText();
190 -
191 - if (!is_null($size = $rev->getSize()))
192 - {
193 - if ($size == 0)
194 - $stxt = wfMsgHtml('historyempty');
195 - else
196 - $stxt = wfMsgHtml('historysize', $wgLang->formatNum( $size ) );
197 - }
198 - $comment = $this->skin->commentBlock($rev->getComment(), $title);
199 -
200 - // Now put it all together
201 - return "<li>($curLink) ($lastLink) $link . . $userBox ($userText) $stxt $comment</li>\n";
 193+ if ($size == 0)
 194+ $stxt = wfMsgHtml('historyempty');
 195+ else
 196+ $stxt = wfMsgHtml('historysize', $wgLang->formatNum( $size ) );
202197 }
 198+ $comment = $this->skin->commentBlock($rev->getComment(), $title);
203199
204 - private function buildRevisionList($title, $errMsg = '')
 200+ // Now put it all together
 201+ return "<li>($curLink) ($lastLink) $link . . $userBox ($userText) $stxt $comment</li>\n";
 202+ }
 203+
 204+ private function buildRevisionList($title, $errMsg = '')
 205+ {
 206+ // Builds a form listing the last 50 revisions of $pagename
 207+ // that allows changing authors
 208+ // $pagename: Title object
 209+ // $errMsg: Error message
 210+ // Returns: HTML.
 211+ global $wgScript;
 212+ $dbr = wfGetDb(DB_SLAVE);
 213+ $res = $dbr->select(
 214+ 'revision',
 215+ Revision::selectFields(),
 216+ array('rev_page' => $title->getArticleId()),
 217+ __METHOD__,
 218+ array('ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 50)
 219+ );
 220+ $revs = array();
 221+ while(($r = $dbr->fetchObject($res)))
 222+ $revs[] = new Revision($r);
 223+ if(empty($revs))
 224+ // That's *very* weird
 225+ return wfMsg('changeauthor-weirderror');
 226+
 227+ $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
 228+ $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
 229+ $retval .= Xml::hidden('action', 'change');
 230+ $retval .= Xml::hidden('targetpage', $title->getPrefixedDbKey());
 231+ $retval .= Xml::openElement('fieldset');
 232+ $retval .= Xml::element('p', array(), wfMsg('changeauthor-explanation-multi'));
 233+ $retval .= Xml::inputLabel(wfMsg('changeauthor-comment'), 'comment', 'comment', 50);
 234+ $retval .= Xml::submitButton(wfMsg('changeauthor-changeauthors-multi'));
 235+ if($errMsg != '')
 236+ {
 237+ $retval .= Xml::openElement('p') . Xml::openElement('b');
 238+ $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
 239+ $retval .= Xml::closeElement('b') . Xml::closeElement('p');
 240+ }
 241+ $retval .= Xml::element('h2', array(), $title->getPrefixedText());
 242+ $retval .= Xml::openElement('ul');
 243+ $count = count($revs);
 244+ foreach($revs as $i => $rev)
 245+ $retval .= $this->buildRevisionLine($rev, $title, ($i == 0), ($i == $count - 1));
 246+ $retval .= Xml::closeElement('ul');
 247+ $retval .= Xml::closeElement('fieldset');
 248+ $retval .= Xml::closeElement('form');
 249+ return $retval;
 250+ }
 251+
 252+ private function buildOneRevForm($rev, $errMsg = '')
 253+ {
 254+ // Builds a form that allows changing one revision's author
 255+ // $rev: Revision object
 256+ // $errMsg: Error message
 257+ // Returns: HTML
 258+ global $wgScript;
 259+ $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
 260+ $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
 261+ $retval .= Xml::hidden('action', 'change');
 262+ $retval .= Xml::hidden('targetrev', $rev->getId());
 263+ $retval .= Xml::openElement('fieldset');
 264+ $retval .= Xml::element('p', array(), wfMsg('changeauthor-explanation-single'));
 265+ $retval .= Xml::inputLabel(wfMsg('changeauthor-comment'), 'comment', 'comment');
 266+ $retval .= Xml::submitButton(wfMsg('changeauthor-changeauthors-single'));
 267+ if($errMsg != '')
 268+ {
 269+ $retval .= Xml::openElement('p') . Xml::openElement('b');
 270+ $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
 271+ $retval .= Xml::closeElement('b') . Xml::closeElement('p');
 272+ }
 273+ $retval .= Xml::element('h2', array(), wfMsg('changeauthor-revview', $rev->getId(), $rev->getTitle()->getPrefixedText()));
 274+ $retval .= Xml::openElement('ul');
 275+ $retval .= $this->buildRevisionLine($rev, $rev->getTitle());
 276+ $retval .= Xml::closeElement('ul');
 277+ $retval .= Xml::closeElement('fieldset');
 278+ $retval .= Xml::closeElement('form');
 279+ return $retval;
 280+ }
 281+
 282+ private function parseChangeRequest()
 283+ {
 284+ // Extracts an array needed by changeRevAuthors() from $wgRequest
 285+ // Returns: array
 286+ global $wgRequest;
 287+ $vals = $wgRequest->getValues();
 288+ $retval = array();
 289+ foreach($vals as $name => $val)
205290 {
206 - // Builds a form listing the last 50 revisions of $pagename
207 - // that allows changing authors
208 - // $pagename: Title object
209 - // $errMsg: Error message
210 - // Returns: HTML.
211 - global $wgScript;
212 - $dbr = wfGetDb(DB_SLAVE);
213 - $res = $dbr->select(
214 - 'revision',
215 - Revision::selectFields(),
216 - array('rev_page' => $title->getArticleId()),
217 - __METHOD__,
218 - array('ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 50)
219 - );
220 - $revs = array();
221 - while(($r = $dbr->fetchObject($res)))
222 - $revs[] = new Revision($r);
223 - if(empty($revs))
224 - // That's *very* weird
225 - return wfMsg('changeauthor-weirderror');
 291+ if(substr($name, 0, 9) != 'user-new-')
 292+ continue;
 293+ $revid = substr($name, 9);
 294+ if(!is_numeric($revid))
 295+ continue;
226296
227 - $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
228 - $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
229 - $retval .= Xml::hidden('action', 'change');
230 - $retval .= Xml::hidden('targetpage', $title->getPrefixedDbKey());
231 - $retval .= Xml::openElement('fieldset');
232 - $retval .= Xml::element('p', array(), wfMsg('changeauthor-explanation-multi'));
233 - $retval .= Xml::inputLabel(wfMsg('changeauthor-comment'), 'comment', 'comment', 50);
234 - $retval .= Xml::submitButton(wfMsg('changeauthor-changeauthors-multi'));
235 - if($errMsg != '')
236 - {
237 - $retval .= Xml::openElement('p') . Xml::openElement('b');
238 - $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
239 - $retval .= Xml::closeElement('b') . Xml::closeElement('p');
240 - }
241 - $retval .= Xml::element('h2', array(), $title->getPrefixedText());
242 - $retval .= Xml::openElement('ul');
243 - $count = count($revs);
244 - foreach($revs as $i => $rev)
245 - $retval .= $this->buildRevisionLine($rev, $title, ($i == 0), ($i == $count - 1));
246 - $retval .= Xml::closeElement('ul');
247 - $retval .= Xml::closeElement('fieldset');
248 - $retval .= Xml::closeElement('form');
249 - return $retval;
 297+ $new = User::newFromName($val, false);
 298+ if(!$new) // Can this even happen?
 299+ return wfMsg('changeauthor-invalid-username', $val);
 300+ if($new->getId() == 0 && $val != 'MediaWiki default' && !User::isIP($new->getName()))
 301+ return wfMsg('changeauthor-nosuchuser', $val);
 302+ $old = User::newFromName($wgRequest->getVal("user-old-$revid"), false);
 303+ if(!$old->getName())
 304+ return wfMsg('changeauthor-invalidform');
 305+ if($old->getName() != $new->getName())
 306+ $retval[$revid] = array($old, $new);
250307 }
251 -
252 - private function buildOneRevForm($rev, $errMsg = '')
 308+ return $retval;
 309+ }
 310+
 311+ private function changeRevAuthors($authors, $comment)
 312+ {
 313+ // Changes revision authors in the database
 314+ // $authors: array, key=revid value=array(User from, User to)
 315+ $dbw = wfGetDb(DB_MASTER);
 316+ $dbw->begin();
 317+ $editcounts = array(); // Array to keep track of EC mutations; key=userid, value=mutation
 318+ $log = new LogPage('changeauth');
 319+ foreach($authors as $id => $users)
253320 {
254 - // Builds a form that allows changing one revision's author
255 - // $rev: Revision object
256 - // $errMsg: Error message
257 - // Returns: HTML
258 - global $wgScript;
259 - $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
260 - $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
261 - $retval .= Xml::hidden('action', 'change');
262 - $retval .= Xml::hidden('targetrev', $rev->getId());
263 - $retval .= Xml::openElement('fieldset');
264 - $retval .= Xml::element('p', array(), wfMsg('changeauthor-explanation-single'));
265 - $retval .= Xml::inputLabel(wfMsg('changeauthor-comment'), 'comment', 'comment');
266 - $retval .= Xml::submitButton(wfMsg('changeauthor-changeauthors-single'));
267 - if($errMsg != '')
268 - {
269 - $retval .= Xml::openElement('p') . Xml::openElement('b');
270 - $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
271 - $retval .= Xml::closeElement('b') . Xml::closeElement('p');
272 - }
273 - $retval .= Xml::element('h2', array(), wfMsg('changeauthor-revview', $rev->getId(), $rev->getTitle()->getPrefixedText()));
274 - $retval .= Xml::openElement('ul');
275 - $retval .= $this->buildRevisionLine($rev, $rev->getTitle());
276 - $retval .= Xml::closeElement('ul');
277 - $retval .= Xml::closeElement('fieldset');
278 - $retval .= Xml::closeElement('form');
279 - return $retval;
 321+ $dbw->update('revision',
 322+ array( 'rev_user' => $users[1]->getId(), // SET
 323+ 'rev_user_text' => $users[1]->getName()),
 324+ array( 'rev_id' => $id), // WHERE
 325+ __METHOD__);
 326+ $rev = Revision::newFromId($id);
 327+ $log->addEntry('changeauth', $rev->getTitle(), $comment, array(wfMsg('changeauthor-rev', $id), $users[0]->getName(), $users[1]->getName()));
 328+ $editcounts[$users[1]->getId()]++;
 329+ $editcounts[$users[0]->getId()]--;
280330 }
281 -
282 - private function parseChangeRequest()
 331+ foreach($editcounts as $userid => $mutation)
283332 {
284 - // Extracts an array needed by changeRevAuthors() from $wgRequest
285 - // Returns: array
286 - global $wgRequest;
287 - $vals = $wgRequest->getValues();
288 - $retval = array();
289 - foreach($vals as $name => $val)
290 - {
291 - if(substr($name, 0, 9) != 'user-new-')
292 - continue;
293 - $revid = substr($name, 9);
294 - if(!is_numeric($revid))
295 - continue;
296 -
297 - $new = User::newFromName($val, false);
298 - if(!$new) // Can this even happen?
299 - return wfMsg('changeauthor-invalid-username', $val);
300 - if($new->getId() == 0 && $val != 'MediaWiki default' && !User::isIP($new->getName()))
301 - return wfMsg('changeauthor-nosuchuser', $val);
302 - $old = User::newFromName($wgRequest->getVal("user-old-$revid"), false);
303 - if(!$old->getName())
304 - return wfMsg('changeauthor-invalidform');
305 - if($old->getName() != $new->getName())
306 - $retval[$revid] = array($old, $new);
307 - }
308 - return $retval;
 333+ if($mutation == 0 || $userid == 0)
 334+ continue;
 335+ if($mutation > 0)
 336+ $mutation = "+$mutation";
 337+ $dbw->update('user',
 338+ array( "user_editcount=user_editcount$mutation"),
 339+ array( 'user_id' => $userid),
 340+ __METHOD__);
 341+ if($dbw->affectedRows() == 0)
 342+ {
 343+ // Let's have mercy on those who don't have a proper DB server
 344+ // (but not enough to spare their master)
 345+ $count = $dbw->selectField('revision', 'COUNT(rev_user)',
 346+ array('rev_user' => $userid), __METHOD__);
 347+ $dbw->update('user',
 348+ array( 'user_editcount' => $count),
 349+ array( 'user_id' => $userid),
 350+ __METHOD);
 351+ }
309352 }
 353+ $dbw->commit();
 354+ }
310355
311 - private function changeRevAuthors($authors, $comment)
 356+ static function loadMessages()
 357+ {
 358+ static $messagesLoaded = false;
 359+ if (!$messagesLoaded)
312360 {
313 - // Changes revision authors in the database
314 - // $authors: array, key=revid value=array(User from, User to)
315 - $dbw = wfGetDb(DB_MASTER);
316 - $dbw->begin();
317 - $editcounts = array(); // Array to keep track of EC mutations; key=userid, value=mutation
318 - $log = new LogPage('changeauth');
319 - foreach($authors as $id => $users)
320 - {
321 - $dbw->update('revision',
322 - array( 'rev_user' => $users[1]->getId(), // SET
323 - 'rev_user_text' => $users[1]->getName()),
324 - array( 'rev_id' => $id), // WHERE
325 - __METHOD__);
326 - $rev = Revision::newFromId($id);
327 - $log->addEntry('changeauth', $rev->getTitle(), $comment, array(wfMsg('changeauthor-rev', $id), $users[0]->getName(), $users[1]->getName()));
328 - $editcounts[$users[1]->getId()]++;
329 - $editcounts[$users[0]->getId()]--;
330 - }
331 - foreach($editcounts as $userid => $mutation)
332 - {
333 - if($mutation == 0 || $userid == 0)
334 - continue;
335 - if($mutation > 0)
336 - $mutation = "+$mutation";
337 - $dbw->update('user',
338 - array( "user_editcount=user_editcount$mutation"),
339 - array( 'user_id' => $userid),
340 - __METHOD__);
341 - if($dbw->affectedRows() == 0)
342 - {
343 - // Let's have mercy on those who don't have a proper DB server
344 - // (but not enough to spare their master)
345 - $count = $dbw->selectField('revision', 'COUNT(rev_user)',
346 - array('rev_user' => $userid), __METHOD__);
347 - $dbw->update('user',
348 - array( 'user_editcount' => $count),
349 - array( 'user_id' => $userid),
350 - __METHOD);
351 - }
352 - }
353 - $dbw->commit();
 361+ $messagesLoaded = true;
 362+ wfLoadExtensionMessages('ChangeAuthor');
354363 }
355 -
356 - static function loadMessages()
357 - {
358 - static $messagesLoaded = false;
359 - global $wgMessageCache;
360 - if (!$messagesLoaded)
361 - {
362 - $messagesLoaded = true;
363 - wfLoadExtensionMessages('ChangeAuthor');
364 - }
365 - return true;
366 - }
 364+ return true;
 365+ }
367366 }
Index: trunk/extensions/ChangeAuthor/ChangeAuthor.setup.php
@@ -24,11 +24,11 @@
2525 }
2626
2727 $wgExtensionCredits['specialpage'][] = array(
28 - 'name' => 'ChangeAuthor',
29 - 'author' => 'Roan Kattouw',
30 - 'url' => 'http://www.mediawiki.org/wiki/Extension:ChangeAuthor',
31 - 'version' => '1.0',
32 - 'description' => 'Allows changing a revision\'s author'
 28+ 'name' => 'ChangeAuthor',
 29+ 'author' => 'Roan Kattouw',
 30+ 'url' => 'http://www.mediawiki.org/wiki/Extension:ChangeAuthor',
 31+ 'version' => '1.0',
 32+ 'description' => 'Allows changing a revision\'s author'
3333 );
3434
3535 $dir = dirname(__FILE__) . '/';
@@ -36,7 +36,6 @@
3737 $wgAutoloadClasses['ChangeAuthor'] = dirname(__FILE__) . '/ChangeAuthor.body.php';
3838
3939 $wgSpecialPages['ChangeAuthor'] = 'ChangeAuthor';
40 -$wgHooks['LoadAllMessages'][] = 'ChangeAuthor::loadMessages';
4140 $wgHooks['LanguageGetSpecialPageAliases'][] = 'ChangeAuthorLocalizedPageName';
4241
4342 $wgLogTypes[] = 'changeauth';
@@ -46,10 +45,10 @@
4746
4847 function ChangeAuthorLocalizedPageName(&$specialPageArray, $code)
4948 {
50 - ChangeAuthor::loadMessages();
51 - $text = wfMsg('changeauthor-short');
 49+ ChangeAuthor::loadMessages();
 50+ $text = wfMsg('changeauthor-short');
5251
53 - $title = Title::newFromText($text);
54 - $specialPageArray['ChangeAuthor'][] = $title->getDBKey();
55 - return true;
 52+ $title = Title::newFromText($text);
 53+ $specialPageArray['ChangeAuthor'][] = $title->getDBKey();
 54+ return true;
5655 }

Status & tagging log