r48717 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48716‎ | r48717 | r48718 >
Date:20:18, 23 March 2009
Author:ashley
Status:deferred
Tags:
Comment:
ChangeAuthor:
*coding style tweaks
*spacing
*removed function loadMessages() since it basically called wfLoadExtensionMessages() and nothing else
*removed 'changeauthor-short' message; we can just use special page aliases instead
*marked visibility of constructor and execute functions
*broke up a long line
Modified paths:
  • /trunk/extensions/ChangeAuthor/ChangeAuthor.body.php (modified) (history)
  • /trunk/extensions/ChangeAuthor/ChangeAuthor.i18n.php (modified) (history)
  • /trunk/extensions/ChangeAuthor/ChangeAuthor.setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ChangeAuthor/ChangeAuthor.body.php
@@ -5,364 +5,357 @@
66 * the Free Software Foundation; either version 3 of the License, or
77 * (at your option) any later version.
88 *
 9+ * @file
 10+ * @ingroup Extensions
911 * @author Roan Kattouw <roan.kattouw@home.nl>
10 - * @copyright Copyright (C) 2007 Roan Kattouw
 12+ * @copyright Copyright © 2007 Roan Kattouw
1113 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
1214 *
1315 * An extension that allows changing the author of a revision
1416 * Written for the Bokt Wiki <http://www.bokt.nl/wiki/> by Roan Kattouw <roan.kattouw@home.nl>
1517 * For information how to install and use this extension, see the README file.
16 - *
1718 */
1819 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the extension file directly.
19 -if (!defined('MEDIAWIKI')) {
 20+if( !defined( 'MEDIAWIKI' ) ) {
2021 echo <<<EOT
2122 To install the ChangeAuthor extension, put the following line in LocalSettings.php:
2223 require_once( "\$IP/extensions/ChangeAuthor/ChangeAuthor.setup.php" );
2324 EOT;
24 - exit(1);
 25+ exit( 1 );
2526 }
2627
27 -class ChangeAuthor extends SpecialPage
28 -{
 28+class ChangeAuthor extends SpecialPage {
2929 var $selfTitle, $skin;
30 - function __construct()
31 - {
 30+
 31+ /**
 32+ * Constructor
 33+ */
 34+ public function __construct(){
3235 global $wgUser;
33 - self::loadMessages();
34 - parent::__construct(wfMsg('changeauthor-short'), 'changeauthor');
35 - $this->selfTitle = Title::makeTitleSafe(NS_SPECIAL, wfMsg('changeauthor-short'));
 36+ wfLoadExtensionMessages( 'ChangeAuthor' );
 37+ parent::__construct( 'ChangeAuthor'/* class */, 'changeauthor'/* restriction */ );
 38+ $this->selfTitle = SpecialPage::getTitleFor( 'ChangeAuthor' );
3639 $this->skin = $wgUser->getSkin();
3740 }
3841
39 - function execute($par)
40 - {
 42+ /**
 43+ * Show the special page
 44+ *
 45+ * @param $par Mixed: parameter passed to the page or null
 46+ */
 47+ public function execute( $par ){
4148 global $wgRequest, $wgOut, $wgContLang, $wgUser;
4249 $this->setHeaders();
43 - if(!$this->userCanExecute($wgUser))
44 - {
 50+
 51+ // Check permissions
 52+ if( !$this->userCanExecute( $wgUser ) ){
4553 $this->displayRestrictionError();
4654 return;
4755 }
48 -
49 - $wgOut->setPageTitle(wfMsg('changeauthor-title'));
50 -
51 - if(!is_null($par))
52 - {
53 - $obj = $this->parseTitleOrRevID($par);
54 - if($obj instanceof Title)
55 - {
56 - if($obj->exists())
57 - $wgOut->addHTML($this->buildRevisionList($obj));
 56+
 57+ $wgOut->setPageTitle( wfMsg( 'changeauthor-title' ) );
 58+
 59+ if( !is_null( $par ) ){
 60+ $obj = $this->parseTitleOrRevID( $par );
 61+ if( $obj instanceof Title ){
 62+ if( $obj->exists() )
 63+ $wgOut->addHTML( $this->buildRevisionList( $obj ) );
5864 else
59 - $wgOut->addHTML($this->buildInitialForm(wfMsg('changeauthor-nosuchtitle', $obj->getPrefixedText())));
 65+ $wgOut->addHTML( $this->buildInitialForm( wfMsg( 'changeauthor-nosuchtitle', $obj->getPrefixedText() ) ) );
6066 return;
61 - }
62 - else if($obj instanceof Revision)
63 - {
64 - $wgOut->addHTML($this->buildOneRevForm($obj));
 67+ } else if( $obj instanceof Revision ){
 68+ $wgOut->addHTML( $this->buildOneRevForm( $obj ) );
6569 return;
6670 }
6771 }
68 -
69 - $action = $wgRequest->getVal('action');
70 - if($wgRequest->wasPosted() && $action == 'change')
71 - {
 72+
 73+ $action = $wgRequest->getVal( 'action' );
 74+ if( $wgRequest->wasPosted() && $action == 'change' ){
7275 $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));
 76+ if( !is_array( $arr ) ){
 77+ $targetPage = $wgRequest->getVal( 'targetpage' );
 78+ if( !is_null( $targetPage ) ){
 79+ $wgOut->addHTML( $this->buildRevisionList( Title::newFromURL( $targetPage ), $arr ) );
7980 return;
8081 }
81 - $targetRev = $wgRequest->getVal('targetrev');
82 - if(!is_null($targetRev))
83 - {
84 - $wgOut->addHTML($this->buildOneRevForm(Revision::newFromId($targetRev), $arr));
 82+ $targetRev = $wgRequest->getVal( 'targetrev' );
 83+ if( !is_null( $targetRev ) ){
 84+ $wgOut->addHTML( $this->buildOneRevForm( Revision::newFromId( $targetRev ), $arr ) );
8585 return;
8686 }
87 - $wgOut->addHTML($this->buildInitialForm());
 87+ $wgOut->addHTML( $this->buildInitialForm() );
 88+ } else {
 89+ $this->changeRevAuthors( $arr, $wgRequest->getVal( 'comment' ) );
 90+ $wgOut->addWikiMsg( 'changeauthor-success' );
8891 }
89 - else
90 - {
91 - $this->changeRevAuthors($arr, $wgRequest->getVal('comment'));
92 - $wgOut->addWikiText(wfMsg('changeauthor-success'));
93 - }
9492 return;
9593 }
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));
 94+ if( $wgRequest->wasPosted() && $action == 'list' ){
 95+ $obj = $this->parseTitleOrRevID( $wgRequest->getVal( 'pagename-revid' ) );
 96+ if( $obj instanceof Title ){
 97+ if( $obj->exists() )
 98+ $wgOut->addHTML( $this->buildRevisionList( $obj ) );
10399 else
104 - $wgOut->addHTML($this->buildInitialForm(wfMsg('changeauthor-nosuchtitle', $obj->getPrefixedText())));
 100+ $wgOut->addHTML( $this->buildInitialForm( wfMsg( 'changeauthor-nosuchtitle', $obj->getPrefixedText() ) ) );
 101+ } else if( $obj instanceof Revision ){
 102+ $wgOut->addHTML( $this->buildOneRevForm( $obj ) );
105103 }
106 - else if($obj instanceof Revision)
107 - {
108 - $wgOut->addHTML($this->buildOneRevForm($obj));
109 - }
110104 return;
111105 }
112 - $wgOut->addHTML($this->buildInitialForm());
 106+ $wgOut->addHTML( $this->buildInitialForm() );
113107 }
114108
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
 109+ /**
 110+ * Parse what can be a revision ID or an article name
 111+ * @param $str Mixed: revision ID or an article name
 112+ * @return Title or Revision object, or NULL
 113+ */
 114+ private function parseTitleOrRevID( $str ){
119115 $retval = false;
120 - if(is_numeric($str))
121 - $retval = Revision::newFromID($str);
122 - if(!$retval)
123 - $retval = Title::newFromURL($str);
 116+ if( is_numeric( $str ) )
 117+ $retval = Revision::newFromID( $str );
 118+ if( !$retval )
 119+ $retval = Title::newFromURL( $str );
124120 return $retval;
125121 }
126122
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 -
 123+ /**
 124+ * Builds the form that asks for a page name or revid
 125+ * @param $errMsg String: Error message
 126+ * @return HTML
 127+ */
 128+ private function buildInitialForm( $errMsg = '' ){
133129 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');
 130+ $retval = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript ) );
 131+ $retval .= Xml::hidden( 'title', $this->selfTitle->getPrefixedDBkey() );
 132+ $retval .= Xml::hidden( 'action', 'list' );
 133+ $retval .= Xml::openElement( 'fieldset' );
 134+ $retval .= Xml::element( 'legend', array(), wfMsg( 'changeauthor-search-box' ) );
 135+ $retval .= Xml::inputLabel( wfMsg( 'changeauthor-pagename-or-revid' ),
 136+ 'pagename-revid', 'pagename-revid' );
 137+ $retval .= Xml::submitButton( wfMsg( 'changeauthor-pagenameform-go' ) );
 138+ if( $errMsg != '' ){
 139+ $retval .= Xml::openElement( 'p' ) . Xml::openElement( 'b' );
 140+ $retval .= Xml::element( 'font', array( 'color' => 'red' ), $errMsg );
 141+ $retval .= Xml::closeElement( 'b' ) . Xml::closeElement( 'p' );
147142 }
148 - $retval .= Xml::closeElement('fieldset');
149 - $retval .= Xml::closeElement('form');
 143+ $retval .= Xml::closeElement( 'fieldset' );
 144+ $retval .= Xml::closeElement( 'form' );
150145 return $retval;
151146 }
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
162 -
 147+
 148+ /**
 149+ * Builds a line for revision $rev
 150+ * Helper to buildRevisionList() and buildOneRevForm()
 151+ *
 152+ * @param $rev Revision object
 153+ * @param $title Title object
 154+ * @param $isFirst Boolean: set to true if $rev is the first revision
 155+ * @param $isLast Boolean: set to true if $rev is the last revision
 156+ * @return HTML
 157+ */
 158+ private function buildRevisionLine( $rev, $title, $isFirst = false, $isLast = false ){
163159 // Build curlink
164 - if($isFirst)
165 - $curLink = wfMsgExt('cur', array('escape'));
 160+ if( $isFirst )
 161+ $curLink = wfMsgExt( 'cur', 'escape' );
166162 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'));
 163+ $curLink = $this->skin->makeKnownLinkObj( $title,
 164+ wfMsgExt( 'cur', 'escape' ),
 165+ "oldid={$rev->getId()}&diff=cur" );
 166+
 167+ if( $isLast )
 168+ $lastLink = wfMsgExt( 'last', 'escape' );
173169 else
174 - $lastLink = $this->skin->makeKnownLinkObj($title,
175 - wfMsgExt('last', array('escape')),
176 - "oldid=prev&diff={$rev->getId()}");
177 -
 170+ $lastLink = $this->skin->makeKnownLinkObj( $title,
 171+ wfMsgExt( 'last', 'escape' ),
 172+ "oldid=prev&diff={$rev->getId()}" );
 173+
178174 // Build oldid link
179175 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()}");
 176+ $date = $wgLang->timeanddate( wfTimestamp( TS_MW, $rev->getTimestamp() ), true );
 177+ if( $rev->userCan( Revision::DELETED_TEXT ) )
 178+ $link = $this->skin->makeKnownLinkObj( $title, $date, "oldid={$rev->getId()}" );
183179 else
184180 $link = $date;
185 -
 181+
186182 // Build user textbox
187183 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');
 184+ $userBox = Xml::input( "user-new-{$rev->getId()}", 50, $wgRequest->getVal( "user-{$rev->getId()}", $rev->getUserText() ) );
 185+ $userText = Xml::hidden( "user-old-{$rev->getId()}", $rev->getUserText() ) . $rev->getUserText();
 186+
 187+ if( !is_null( $size = $rev->getSize() ) ){
 188+ if( $size == 0 )
 189+ $stxt = wfMsgHtml( 'historyempty' );
195190 else
196 - $stxt = wfMsgHtml('historysize', $wgLang->formatNum( $size ) );
197 - }
198 - else
 191+ $stxt = wfMsgHtml( 'historysize', $wgLang->formatNum( $size ) );
 192+ } else
199193 $stxt = ''; // Stop PHP from whining about unset variables
200 - $comment = $this->skin->commentBlock($rev->getComment(), $title);
201 -
 194+ $comment = $this->skin->commentBlock( $rev->getComment(), $title );
 195+
202196 // Now put it all together
203197 return "<li>($curLink) ($lastLink) $link . . $userBox ($userText) $stxt $comment</li>\n";
204198 }
205 -
206 - private function buildRevisionList($title, $errMsg = '')
207 - {
208 - // Builds a form listing the last 50 revisions of $pagename
209 - // that allows changing authors
210 - // $pagename: Title object
211 - // $errMsg: Error message
212 - // Returns: HTML.
 199+
 200+ /**
 201+ * Builds a form listing the last 50 revisions of $title that allows changing authors
 202+ * @param $title Title object
 203+ * @param $errMsg String: error message
 204+ * @return HTML
 205+ */
 206+ private function buildRevisionList( $title, $errMsg = '' ){
213207 global $wgScript;
214 - $dbr = wfGetDB(DB_SLAVE);
 208+ $dbr = wfGetDB( DB_SLAVE );
215209 $res = $dbr->select(
216 - 'revision',
217 - Revision::selectFields(),
218 - array('rev_page' => $title->getArticleId()),
219 - __METHOD__,
220 - array('ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 50)
 210+ 'revision',
 211+ Revision::selectFields(),
 212+ array( 'rev_page' => $title->getArticleId() ),
 213+ __METHOD__,
 214+ array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 50 )
221215 );
222216 $revs = array();
223 - while(($r = $dbr->fetchObject($res)))
224 - $revs[] = new Revision($r);
225 - if(empty($revs))
 217+ while( ( $r = $dbr->fetchObject($res ) ) )
 218+ $revs[] = new Revision( $r );
 219+ if( empty( $revs ) )
226220 // That's *very* weird
227 - return wfMsg('changeauthor-weirderror');
228 -
229 - $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
230 - $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
231 - $retval .= Xml::hidden('action', 'change');
232 - $retval .= Xml::hidden('targetpage', $title->getPrefixedDbKey());
233 - $retval .= Xml::openElement('fieldset');
234 - $retval .= Xml::element('p', array(), wfMsg('changeauthor-explanation-multi'));
235 - $retval .= Xml::inputLabel(wfMsg('changeauthor-comment'), 'comment', 'comment', 50);
236 - $retval .= Xml::submitButton(wfMsgExt('changeauthor-changeauthors-multi',
237 - array('parsemag', 'escape'), count($revs)));
238 - if($errMsg != '')
239 - {
240 - $retval .= Xml::openElement('p') . Xml::openElement('b');
241 - $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
242 - $retval .= Xml::closeElement('b') . Xml::closeElement('p');
 221+ return wfMsg( 'changeauthor-weirderror' );
 222+
 223+ $retval = Xml::openElement('form', array( 'method' => 'post', 'action' => $wgScript ) );
 224+ $retval .= Xml::hidden( 'title', $this->selfTitle->getPrefixedDBkey() );
 225+ $retval .= Xml::hidden( 'action', 'change' );
 226+ $retval .= Xml::hidden( 'targetpage', $title->getPrefixedDBkey() );
 227+ $retval .= Xml::openElement( 'fieldset' );
 228+ $retval .= Xml::element( 'p', array(), wfMsg('changeauthor-explanation-multi'));
 229+ $retval .= Xml::inputLabel( wfMsg( 'changeauthor-comment'), 'comment', 'comment', 50);
 230+ $retval .= Xml::submitButton(
 231+ wfMsgExt( 'changeauthor-changeauthors-multi', array( 'parsemag', 'escape' ),
 232+ count( $revs ) ) );
 233+ if( $errMsg != '' ){
 234+ $retval .= Xml::openElement( 'p' ) . Xml::openElement( 'b' );
 235+ $retval .= Xml::element( 'font', array( 'color' => 'red' ), $errMsg );
 236+ $retval .= Xml::closeElement( 'b' ) . Xml::closeElement( 'p' );
243237 }
244 - $retval .= Xml::element('h2', array(), $title->getPrefixedText());
245 - $retval .= Xml::openElement('ul');
246 - $count = count($revs);
247 - foreach($revs as $i => $rev)
248 - $retval .= $this->buildRevisionLine($rev, $title, ($i == 0), ($i == $count - 1));
249 - $retval .= Xml::closeElement('ul');
250 - $retval .= Xml::closeElement('fieldset');
251 - $retval .= Xml::closeElement('form');
 238+ $retval .= Xml::element( 'h2', array(), $title->getPrefixedText() );
 239+ $retval .= Xml::openElement( 'ul' );
 240+ $count = count( $revs );
 241+ foreach( $revs as $i => $rev )
 242+ $retval .= $this->buildRevisionLine( $rev, $title, ($i == 0), ($i == $count - 1) );
 243+ $retval .= Xml::closeElement( 'ul' );
 244+ $retval .= Xml::closeElement( 'fieldset' );
 245+ $retval .= Xml::closeElement( 'form' );
252246 return $retval;
253247 }
254 -
255 - private function buildOneRevForm($rev, $errMsg = '')
256 - {
257 - // Builds a form that allows changing one revision's author
258 - // $rev: Revision object
259 - // $errMsg: Error message
260 - // Returns: HTML
 248+
 249+ /**
 250+ * Builds a form that allows changing one revision's author
 251+ * @param $rev Revision object
 252+ * @param $errMsg String: error message
 253+ * @return HTML
 254+ */
 255+ private function buildOneRevForm( $rev, $errMsg = '' ){
261256 global $wgScript;
262 - $retval = Xml::openElement('form', array('method' => 'POST', 'action' => $wgScript));
263 - $retval .= Xml::hidden('title', $this->selfTitle->getPrefixedDbKey());
264 - $retval .= Xml::hidden('action', 'change');
265 - $retval .= Xml::hidden('targetrev', $rev->getId());
266 - $retval .= Xml::openElement('fieldset');
267 - $retval .= Xml::element('p', array(), wfMsg('changeauthor-explanation-single'));
268 - $retval .= Xml::inputLabel(wfMsg('changeauthor-comment'), 'comment', 'comment');
269 - $retval .= Xml::submitButton(wfMsg('changeauthor-changeauthors-single'));
270 - if($errMsg != '')
271 - {
272 - $retval .= Xml::openElement('p') . Xml::openElement('b');
273 - $retval .= Xml::element('font', array('color' => 'red'), $errMsg);
274 - $retval .= Xml::closeElement('b') . Xml::closeElement('p');
 257+ $retval = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript ) );
 258+ $retval .= Xml::hidden( 'title', $this->selfTitle->getPrefixedDBkey() );
 259+ $retval .= Xml::hidden( 'action', 'change' );
 260+ $retval .= Xml::hidden( 'targetrev', $rev->getId() );
 261+ $retval .= Xml::openElement( 'fieldset' );
 262+ $retval .= Xml::element( 'p', array(), wfMsg( 'changeauthor-explanation-single' ) );
 263+ $retval .= Xml::inputLabel( wfMsg( 'changeauthor-comment' ), 'comment', 'comment' );
 264+ $retval .= Xml::submitButton( wfMsg( 'changeauthor-changeauthors-single' ) );
 265+ if( $errMsg != '' ){
 266+ $retval .= Xml::openElement( 'p' ) . Xml::openElement( 'b' );
 267+ $retval .= Xml::element( 'font', array( 'color' => 'red' ), $errMsg );
 268+ $retval .= Xml::closeElement( 'b' ) . Xml::closeElement( 'p' );
275269 }
276 - $retval .= Xml::element('h2', array(), wfMsg('changeauthor-revview', $rev->getId(), $rev->getTitle()->getPrefixedText()));
277 - $retval .= Xml::openElement('ul');
278 - $retval .= $this->buildRevisionLine($rev, $rev->getTitle());
279 - $retval .= Xml::closeElement('ul');
280 - $retval .= Xml::closeElement('fieldset');
281 - $retval .= Xml::closeElement('form');
282 - return $retval;
 270+ $retval .= Xml::element( 'h2', array(), wfMsg( 'changeauthor-revview', $rev->getId(), $rev->getTitle()->getPrefixedText() ) );
 271+ $retval .= Xml::openElement( 'ul' );
 272+ $retval .= $this->buildRevisionLine( $rev, $rev->getTitle() );
 273+ $retval .= Xml::closeElement( 'ul' );
 274+ $retval .= Xml::closeElement( 'fieldset' );
 275+ $retval .= Xml::closeElement( 'form' );
 276+ return $retval;
283277 }
284 -
285 - private function parseChangeRequest()
286 - {
287 - // Extracts an array needed by changeRevAuthors() from $wgRequest
288 - // Returns: array
 278+
 279+ /**
 280+ * Extracts an array needed by changeRevAuthors() from $wgRequest
 281+ * @return array
 282+ */
 283+ private function parseChangeRequest(){
289284 global $wgRequest;
290285 $vals = $wgRequest->getValues();
291286 $retval = array();
292 - foreach($vals as $name => $val)
293 - {
294 - if(substr($name, 0, 9) != 'user-new-')
 287+ foreach( $vals as $name => $val ){
 288+ if( substr( $name, 0, 9 ) != 'user-new-' )
295289 continue;
296 - $revid = substr($name, 9);
297 - if(!is_numeric($revid))
 290+ $revid = substr( $name, 9 );
 291+ if( !is_numeric( $revid ) )
298292 continue;
299 -
300 - $new = User::newFromName($val, false);
301 - if(!$new) // Can this even happen?
302 - return wfMsg('changeauthor-invalid-username', $val);
303 - if($new->getId() == 0 && $val != 'MediaWiki default' && !User::isIP($new->getName()))
304 - return wfMsg('changeauthor-nosuchuser', $val);
305 - $old = User::newFromName($wgRequest->getVal("user-old-$revid"), false);
306 - if(!$old->getName())
307 - return wfMsg('changeauthor-invalidform');
308 - if($old->getName() != $new->getName())
309 - $retval[$revid] = array($old, $new);
 293+
 294+ $new = User::newFromName( $val, false );
 295+ if( !$new ) // Can this even happen?
 296+ return wfMsg( 'changeauthor-invalid-username', $val );
 297+ if( $new->getId() == 0 && $val != 'MediaWiki default' && !User::isIP( $new->getName() ) )
 298+ return wfMsg( 'changeauthor-nosuchuser', $val );
 299+ $old = User::newFromName( $wgRequest->getVal( "user-old-$revid" ), false );
 300+ if( !$old->getName() )
 301+ return wfMsg( 'changeauthor-invalidform' );
 302+ if( $old->getName() != $new->getName() )
 303+ $retval[$revid] = array( $old, $new );
310304 }
311305 return $retval;
312306 }
313 -
314 - private function changeRevAuthors($authors, $comment)
315 - {
316 - // Changes revision authors in the database
317 - // $authors: array, key=revid value=array(User from, User to)
318 - $dbw = wfGetDB(DB_MASTER);
 307+
 308+ /**
 309+ * Changes revision authors in the database
 310+ * @param $authors Array: key=revid value=array(User from, User to)
 311+ * @param $comment Mixed: log comment
 312+ */
 313+ private function changeRevAuthors( $authors, $comment ){
 314+ $dbw = wfGetDB( DB_MASTER );
319315 $dbw->begin();
320316 $editcounts = array(); // Array to keep track of EC mutations; key=userid, value=mutation
321 - $log = new LogPage('changeauth');
322 - foreach($authors as $id => $users)
323 - {
324 - $dbw->update('revision',
325 - array( 'rev_user' => $users[1]->getId(), // SET
326 - 'rev_user_text' => $users[1]->getName()),
327 - array( 'rev_id' => $id), // WHERE
328 - __METHOD__);
329 - $rev = Revision::newFromId($id);
330 - $log->addEntry('changeauth', $rev->getTitle(), $comment, array(wfMsg('changeauthor-rev', $id), $users[0]->getName(), $users[1]->getName()));
 317+ $log = new LogPage( 'changeauth' );
 318+ foreach( $authors as $id => $users ){
 319+ $dbw->update( 'revision',
 320+ /* SET */array(
 321+ 'rev_user' => $users[1]->getId(),
 322+ 'rev_user_text' => $users[1]->getName()
 323+ ),
 324+ array( 'rev_id' => $id ), // WHERE
 325+ __METHOD__
 326+ );
 327+ $rev = Revision::newFromId( $id );
 328+ $log->addEntry( 'changeauth', $rev->getTitle(), $comment, array(
 329+ wfMsg( 'changeauthor-rev', $id ), $users[0]->getName(), $users[1]->getName() ) );
331330 $editcounts[$users[1]->getId()]++;
332331 $editcounts[$users[0]->getId()]--;
333332 }
334 - foreach($editcounts as $userid => $mutation)
335 - {
336 - if($mutation == 0 || $userid == 0)
 333+ foreach( $editcounts as $userid => $mutation ){
 334+ if( $mutation == 0 || $userid == 0 )
337335 continue;
338 - if($mutation > 0)
 336+ if( $mutation > 0 )
339337 $mutation = "+$mutation";
340 - $dbw->update('user',
341 - array( "user_editcount=user_editcount$mutation"),
342 - array( 'user_id' => $userid),
343 - __METHOD__);
344 - if($dbw->affectedRows() == 0)
345 - {
 338+ $dbw->update( 'user',
 339+ array( "user_editcount=user_editcount$mutation" ),
 340+ array( 'user_id' => $userid ),
 341+ __METHOD__
 342+ );
 343+ if( $dbw->affectedRows() == 0 ){
346344 // Let's have mercy on those who don't have a proper DB server
347345 // (but not enough to spare their master)
348 - $count = $dbw->selectField('revision', 'COUNT(rev_user)',
349 - array('rev_user' => $userid), __METHOD__);
350 - $dbw->update('user',
351 - array( 'user_editcount' => $count),
352 - array( 'user_id' => $userid),
353 - __METHOD);
 346+ $count = $dbw->selectField(
 347+ 'revision',
 348+ 'COUNT(rev_user)',
 349+ array( 'rev_user' => $userid ),
 350+ __METHOD__
 351+ );
 352+ $dbw->update( 'user',
 353+ array( 'user_editcount' => $count ),
 354+ array( 'user_id' => $userid ),
 355+ __METHOD__
 356+ );
354357 }
355358 }
356359 $dbw->commit();
357360 }
358 -
359 - static function loadMessages()
360 - {
361 - static $messagesLoaded = false;
362 - if (!$messagesLoaded)
363 - {
364 - $messagesLoaded = true;
365 - wfLoadExtensionMessages('ChangeAuthor');
366 - }
367 - return true;
368 - }
369 -}
 361+
 362+}
\ No newline at end of file
Index: trunk/extensions/ChangeAuthor/ChangeAuthor.i18n.php
@@ -5,22 +5,23 @@
66 * the Free Software Foundation; either version 3 of the License, or
77 * (at your option) any later version.
88 *
 9+ * @file
 10+ * @ingroup Extensions
911 * @author Roan Kattouw <roan.kattouw@home.nl>
10 - * @copyright Copyright (C) 2007 Roan Kattouw
 12+ * @copyright Copyright © 2007 Roan Kattouw
1113 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
1214 *
1315 * An extension that allows changing the author of a revision
1416 * Written for the Bokt Wiki <http://www.bokt.nl/wiki/> by Roan Kattouw <roan.kattouw@home.nl>
1517 * For information how to install and use this extension, see the README file.
16 - *
1718 */
1819 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the extension file directly.
19 -if (!defined('MEDIAWIKI')) {
 20+if( !defined( 'MEDIAWIKI' ) ) {
2021 echo <<<EOT
2122 To install the ChangeAuthor extension, put the following line in LocalSettings.php:
2223 require_once( "\$IP/extensions/ChangeAuthor/ChangeAuthor.setup.php" );
2324 EOT;
24 - exit(1);
 25+ exit( 1 );
2526 }
2627
2728 $messages = array();
@@ -30,19 +31,18 @@
3132 */
3233 $messages['en'] = array(
3334 'changeauthor' => 'Change revision author',
34 - 'changeauthor-short' => 'ChangeAuthor',
35 - 'changeauthor-desc' => 'Allows changing a revision\'s author',
 35+ 'changeauthor-desc' => "Allows changing a revision's author",
3636 'changeauthor-title' => 'Change the author of a revision',
3737 'changeauthor-search-box' => 'Search revisions',
3838 'changeauthor-pagename-or-revid' => 'Page name or revision ID:',
3939 'changeauthor-pagenameform-go' => 'Go',
4040 'changeauthor-comment' => 'Comment:',
4141 'changeauthor-changeauthors-multi' => 'Change {{PLURAL:$1|author|authors}}',
42 - 'changeauthor-explanation-multi' => 'With this form you can change revision authors.
43 -Simply change one or more usernames in the list below, add a comment (optional) and click the \'Change author(s)\' button.',
 42+ 'changeauthor-explanation-multi' => "With this form you can change revision authors.
 43+Simply change one or more usernames in the list below, add a comment (optional) and click the 'Change author(s)' button.",
4444 'changeauthor-changeauthors-single' => 'Change author',
45 - 'changeauthor-explanation-single' => 'With this form you can change a revision author.
46 -Simply change the username below, add a comment (optional) and click the \'Change author\' button.',
 45+ 'changeauthor-explanation-single' => "With this form you can change a revision author.
 46+Simply change the username below, add a comment (optional) and click the 'Change author' button.",
4747 'changeauthor-invalid-username' => 'Invalid username "$1".',
4848 'changeauthor-nosuchuser' => 'No such user "$1".',
4949 'changeauthor-revview' => 'Revision #$1 of $2',
Index: trunk/extensions/ChangeAuthor/ChangeAuthor.setup.php
@@ -5,33 +5,36 @@
66 * the Free Software Foundation; either version 3 of the License, or
77 * (at your option) any later version.
88 *
 9+ * @file
 10+ * @ingroup Extensions
911 * @author Roan Kattouw <roan.kattouw@home.nl>
10 - * @copyright Copyright (C) 2007 Roan Kattouw
 12+ * @copyright Copyright © 2007 Roan Kattouw
1113 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
1214 *
1315 * An extension that allows changing the author of a revision
1416 * Written for the Bokt Wiki <http://www.bokt.nl/wiki/> by Roan Kattouw <roan.kattouw@home.nl>
1517 * For information how to install and use this extension, see the README file.
16 - *
1718 */
1819 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the extension file directly.
19 -if (!defined('MEDIAWIKI')) {
20 - echo <<<EOT
 20+if( !defined( 'MEDIAWIKI' ) ) {
 21+ echo <<<EOT
2122 To install the ChangeAuthor extension, put the following line in LocalSettings.php:
2223 require_once( "\$IP/extensions/ChangeAuthor/ChangeAuthor.setup.php" );
2324 EOT;
24 - exit(1);
 25+ exit( 1 );
2526 }
2627
 28+// Extension credits that will show up on Special:Version
2729 $wgExtensionCredits['specialpage'][] = array(
2830 'name' => 'ChangeAuthor',
2931 'author' => 'Roan Kattouw',
3032 'url' => 'http://www.mediawiki.org/wiki/Extension:ChangeAuthor',
3133 'version' => '1.1',
32 - 'description' => 'Allows changing a revision\'s author',
 34+ 'description' => "Allows changing a revision's author",
3335 'descriptionmsg' => 'changeauthor-desc',
3436 );
3537
 38+// Set up the new special page
3639 $dir = dirname(__FILE__) . '/';
3740 $wgExtensionMessagesFiles['ChangeAuthor'] = $dir . 'ChangeAuthor.i18n.php';
3841 $wgExtensionAliasesFiles['ChangeAuthor'] = $dir . 'ChangeAuthor.alias.php';
@@ -40,7 +43,8 @@
4144 $wgSpecialPages['ChangeAuthor'] = 'ChangeAuthor';
4245 $wgSpecialPageGroups['ChangeAuthor'] = 'pagetools';
4346
 47+// Add new log type
4448 $wgLogTypes[] = 'changeauth';
4549 $wgLogNames['changeauth'] = 'changeauthor-logpagename';
4650 $wgLogHeaders['changeauth'] = 'changeauthor-logpagetext';
47 -$wgLogActions['changeauth/changeauth'] = 'changeauthor-logentry';
 51+$wgLogActions['changeauth/changeauth'] = 'changeauthor-logentry';
\ No newline at end of file

Status & tagging log