Index: trunk/extensions/ChangeAuthor/ChangeAuthor.body.php |
— | — | @@ -5,364 +5,357 @@ |
6 | 6 | * the Free Software Foundation; either version 3 of the License, or |
7 | 7 | * (at your option) any later version. |
8 | 8 | * |
| 9 | + * @file |
| 10 | + * @ingroup Extensions |
9 | 11 | * @author Roan Kattouw <roan.kattouw@home.nl> |
10 | | - * @copyright Copyright (C) 2007 Roan Kattouw |
| 12 | + * @copyright Copyright © 2007 Roan Kattouw |
11 | 13 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License |
12 | 14 | * |
13 | 15 | * An extension that allows changing the author of a revision |
14 | 16 | * Written for the Bokt Wiki <http://www.bokt.nl/wiki/> by Roan Kattouw <roan.kattouw@home.nl> |
15 | 17 | * For information how to install and use this extension, see the README file. |
16 | | - * |
17 | 18 | */ |
18 | 19 | # 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' ) ) { |
20 | 21 | echo <<<EOT |
21 | 22 | To install the ChangeAuthor extension, put the following line in LocalSettings.php: |
22 | 23 | require_once( "\$IP/extensions/ChangeAuthor/ChangeAuthor.setup.php" ); |
23 | 24 | EOT; |
24 | | - exit(1); |
| 25 | + exit( 1 ); |
25 | 26 | } |
26 | 27 | |
27 | | -class ChangeAuthor extends SpecialPage |
28 | | -{ |
| 28 | +class ChangeAuthor extends SpecialPage { |
29 | 29 | var $selfTitle, $skin; |
30 | | - function __construct() |
31 | | - { |
| 30 | + |
| 31 | + /** |
| 32 | + * Constructor |
| 33 | + */ |
| 34 | + public function __construct(){ |
32 | 35 | 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' ); |
36 | 39 | $this->skin = $wgUser->getSkin(); |
37 | 40 | } |
38 | 41 | |
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 ){ |
41 | 48 | global $wgRequest, $wgOut, $wgContLang, $wgUser; |
42 | 49 | $this->setHeaders(); |
43 | | - if(!$this->userCanExecute($wgUser)) |
44 | | - { |
| 50 | + |
| 51 | + // Check permissions |
| 52 | + if( !$this->userCanExecute( $wgUser ) ){ |
45 | 53 | $this->displayRestrictionError(); |
46 | 54 | return; |
47 | 55 | } |
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 ) ); |
58 | 64 | else |
59 | | - $wgOut->addHTML($this->buildInitialForm(wfMsg('changeauthor-nosuchtitle', $obj->getPrefixedText()))); |
| 65 | + $wgOut->addHTML( $this->buildInitialForm( wfMsg( 'changeauthor-nosuchtitle', $obj->getPrefixedText() ) ) ); |
60 | 66 | 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 ) ); |
65 | 69 | return; |
66 | 70 | } |
67 | 71 | } |
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' ){ |
72 | 75 | $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 ) ); |
79 | 80 | return; |
80 | 81 | } |
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 ) ); |
85 | 85 | return; |
86 | 86 | } |
87 | | - $wgOut->addHTML($this->buildInitialForm()); |
| 87 | + $wgOut->addHTML( $this->buildInitialForm() ); |
| 88 | + } else { |
| 89 | + $this->changeRevAuthors( $arr, $wgRequest->getVal( 'comment' ) ); |
| 90 | + $wgOut->addWikiMsg( 'changeauthor-success' ); |
88 | 91 | } |
89 | | - else |
90 | | - { |
91 | | - $this->changeRevAuthors($arr, $wgRequest->getVal('comment')); |
92 | | - $wgOut->addWikiText(wfMsg('changeauthor-success')); |
93 | | - } |
94 | 92 | return; |
95 | 93 | } |
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 ) ); |
103 | 99 | 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 ) ); |
105 | 103 | } |
106 | | - else if($obj instanceof Revision) |
107 | | - { |
108 | | - $wgOut->addHTML($this->buildOneRevForm($obj)); |
109 | | - } |
110 | 104 | return; |
111 | 105 | } |
112 | | - $wgOut->addHTML($this->buildInitialForm()); |
| 106 | + $wgOut->addHTML( $this->buildInitialForm() ); |
113 | 107 | } |
114 | 108 | |
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 ){ |
119 | 115 | $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 ); |
124 | 120 | return $retval; |
125 | 121 | } |
126 | 122 | |
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 = '' ){ |
133 | 129 | 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' ); |
147 | 142 | } |
148 | | - $retval .= Xml::closeElement('fieldset'); |
149 | | - $retval .= Xml::closeElement('form'); |
| 143 | + $retval .= Xml::closeElement( 'fieldset' ); |
| 144 | + $retval .= Xml::closeElement( 'form' ); |
150 | 145 | return $retval; |
151 | 146 | } |
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 ){ |
163 | 159 | // Build curlink |
164 | | - if($isFirst) |
165 | | - $curLink = wfMsgExt('cur', array('escape')); |
| 160 | + if( $isFirst ) |
| 161 | + $curLink = wfMsgExt( 'cur', 'escape' ); |
166 | 162 | 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' ); |
173 | 169 | 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 | + |
178 | 174 | // Build oldid link |
179 | 175 | 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()}" ); |
183 | 179 | else |
184 | 180 | $link = $date; |
185 | | - |
| 181 | + |
186 | 182 | // Build user textbox |
187 | 183 | 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' ); |
195 | 190 | else |
196 | | - $stxt = wfMsgHtml('historysize', $wgLang->formatNum( $size ) ); |
197 | | - } |
198 | | - else |
| 191 | + $stxt = wfMsgHtml( 'historysize', $wgLang->formatNum( $size ) ); |
| 192 | + } else |
199 | 193 | $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 | + |
202 | 196 | // Now put it all together |
203 | 197 | return "<li>($curLink) ($lastLink) $link . . $userBox ($userText) $stxt $comment</li>\n"; |
204 | 198 | } |
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 = '' ){ |
213 | 207 | global $wgScript; |
214 | | - $dbr = wfGetDB(DB_SLAVE); |
| 208 | + $dbr = wfGetDB( DB_SLAVE ); |
215 | 209 | $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 ) |
221 | 215 | ); |
222 | 216 | $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 ) ) |
226 | 220 | // 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' ); |
243 | 237 | } |
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' ); |
252 | 246 | return $retval; |
253 | 247 | } |
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 = '' ){ |
261 | 256 | 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' ); |
275 | 269 | } |
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; |
283 | 277 | } |
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(){ |
289 | 284 | global $wgRequest; |
290 | 285 | $vals = $wgRequest->getValues(); |
291 | 286 | $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-' ) |
295 | 289 | continue; |
296 | | - $revid = substr($name, 9); |
297 | | - if(!is_numeric($revid)) |
| 290 | + $revid = substr( $name, 9 ); |
| 291 | + if( !is_numeric( $revid ) ) |
298 | 292 | 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 ); |
310 | 304 | } |
311 | 305 | return $retval; |
312 | 306 | } |
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 ); |
319 | 315 | $dbw->begin(); |
320 | 316 | $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() ) ); |
331 | 330 | $editcounts[$users[1]->getId()]++; |
332 | 331 | $editcounts[$users[0]->getId()]--; |
333 | 332 | } |
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 ) |
337 | 335 | continue; |
338 | | - if($mutation > 0) |
| 336 | + if( $mutation > 0 ) |
339 | 337 | $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 ){ |
346 | 344 | // Let's have mercy on those who don't have a proper DB server |
347 | 345 | // (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 | + ); |
354 | 357 | } |
355 | 358 | } |
356 | 359 | $dbw->commit(); |
357 | 360 | } |
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 @@ |
6 | 6 | * the Free Software Foundation; either version 3 of the License, or |
7 | 7 | * (at your option) any later version. |
8 | 8 | * |
| 9 | + * @file |
| 10 | + * @ingroup Extensions |
9 | 11 | * @author Roan Kattouw <roan.kattouw@home.nl> |
10 | | - * @copyright Copyright (C) 2007 Roan Kattouw |
| 12 | + * @copyright Copyright © 2007 Roan Kattouw |
11 | 13 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License |
12 | 14 | * |
13 | 15 | * An extension that allows changing the author of a revision |
14 | 16 | * Written for the Bokt Wiki <http://www.bokt.nl/wiki/> by Roan Kattouw <roan.kattouw@home.nl> |
15 | 17 | * For information how to install and use this extension, see the README file. |
16 | | - * |
17 | 18 | */ |
18 | 19 | # 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' ) ) { |
20 | 21 | echo <<<EOT |
21 | 22 | To install the ChangeAuthor extension, put the following line in LocalSettings.php: |
22 | 23 | require_once( "\$IP/extensions/ChangeAuthor/ChangeAuthor.setup.php" ); |
23 | 24 | EOT; |
24 | | - exit(1); |
| 25 | + exit( 1 ); |
25 | 26 | } |
26 | 27 | |
27 | 28 | $messages = array(); |
— | — | @@ -30,19 +31,18 @@ |
31 | 32 | */ |
32 | 33 | $messages['en'] = array( |
33 | 34 | '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", |
36 | 36 | 'changeauthor-title' => 'Change the author of a revision', |
37 | 37 | 'changeauthor-search-box' => 'Search revisions', |
38 | 38 | 'changeauthor-pagename-or-revid' => 'Page name or revision ID:', |
39 | 39 | 'changeauthor-pagenameform-go' => 'Go', |
40 | 40 | 'changeauthor-comment' => 'Comment:', |
41 | 41 | '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.", |
44 | 44 | '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.", |
47 | 47 | 'changeauthor-invalid-username' => 'Invalid username "$1".', |
48 | 48 | 'changeauthor-nosuchuser' => 'No such user "$1".', |
49 | 49 | 'changeauthor-revview' => 'Revision #$1 of $2', |
Index: trunk/extensions/ChangeAuthor/ChangeAuthor.setup.php |
— | — | @@ -5,33 +5,36 @@ |
6 | 6 | * the Free Software Foundation; either version 3 of the License, or |
7 | 7 | * (at your option) any later version. |
8 | 8 | * |
| 9 | + * @file |
| 10 | + * @ingroup Extensions |
9 | 11 | * @author Roan Kattouw <roan.kattouw@home.nl> |
10 | | - * @copyright Copyright (C) 2007 Roan Kattouw |
| 12 | + * @copyright Copyright © 2007 Roan Kattouw |
11 | 13 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License |
12 | 14 | * |
13 | 15 | * An extension that allows changing the author of a revision |
14 | 16 | * Written for the Bokt Wiki <http://www.bokt.nl/wiki/> by Roan Kattouw <roan.kattouw@home.nl> |
15 | 17 | * For information how to install and use this extension, see the README file. |
16 | | - * |
17 | 18 | */ |
18 | 19 | # 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 |
21 | 22 | To install the ChangeAuthor extension, put the following line in LocalSettings.php: |
22 | 23 | require_once( "\$IP/extensions/ChangeAuthor/ChangeAuthor.setup.php" ); |
23 | 24 | EOT; |
24 | | - exit(1); |
| 25 | + exit( 1 ); |
25 | 26 | } |
26 | 27 | |
| 28 | +// Extension credits that will show up on Special:Version |
27 | 29 | $wgExtensionCredits['specialpage'][] = array( |
28 | 30 | 'name' => 'ChangeAuthor', |
29 | 31 | 'author' => 'Roan Kattouw', |
30 | 32 | 'url' => 'http://www.mediawiki.org/wiki/Extension:ChangeAuthor', |
31 | 33 | 'version' => '1.1', |
32 | | - 'description' => 'Allows changing a revision\'s author', |
| 34 | + 'description' => "Allows changing a revision's author", |
33 | 35 | 'descriptionmsg' => 'changeauthor-desc', |
34 | 36 | ); |
35 | 37 | |
| 38 | +// Set up the new special page |
36 | 39 | $dir = dirname(__FILE__) . '/'; |
37 | 40 | $wgExtensionMessagesFiles['ChangeAuthor'] = $dir . 'ChangeAuthor.i18n.php'; |
38 | 41 | $wgExtensionAliasesFiles['ChangeAuthor'] = $dir . 'ChangeAuthor.alias.php'; |
— | — | @@ -40,7 +43,8 @@ |
41 | 44 | $wgSpecialPages['ChangeAuthor'] = 'ChangeAuthor'; |
42 | 45 | $wgSpecialPageGroups['ChangeAuthor'] = 'pagetools'; |
43 | 46 | |
| 47 | +// Add new log type |
44 | 48 | $wgLogTypes[] = 'changeauth'; |
45 | 49 | $wgLogNames['changeauth'] = 'changeauthor-logpagename'; |
46 | 50 | $wgLogHeaders['changeauth'] = 'changeauthor-logpagetext'; |
47 | | -$wgLogActions['changeauth/changeauth'] = 'changeauthor-logentry'; |
| 51 | +$wgLogActions['changeauth/changeauth'] = 'changeauthor-logentry'; |
\ No newline at end of file |