r52532 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52531‎ | r52532 | r52533 >
Date:22:33, 28 June 2009
Author:siebrand
Status:deferred
Tags:
Comment:
* makeKnownLinkObj() -> linkKnown()
* remove use of strtoupper on 'delete'
* NS_IMAGE -> NS_FILE
* stylize.php
* bump version
Modified paths:
  • /trunk/extensions/DeleteBatch/DeleteBatch.body.php (modified) (history)
  • /trunk/extensions/DeleteBatch/DeleteBatch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DeleteBatch/DeleteBatch.body.php
@@ -47,13 +47,13 @@
4848 $cSF = new DeleteBatchForm( $par );
4949
5050 $action = $wgRequest->getVal( 'action' );
51 - if( 'success' == $action ) {
 51+ if ( 'success' == $action ) {
5252 /* do something */
53 - } else if( $wgRequest->wasPosted() && 'submit' == $action &&
 53+ } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
5454 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
5555 $cSF->doSubmit();
5656 } else {
57 - $cSF->showForm('');
 57+ $cSF->showForm( '' );
5858 }
5959 }
6060 }
@@ -102,37 +102,37 @@
103103 $scFile = '';
104104 }
105105
106 - $wgOut->addHTML("
 106+ $wgOut->addHTML( "
107107 <form name=\"deletebatch\" enctype=\"multipart/form-data\" method=\"post\" action=\"{$action}\">
108108 <table border=\"0\">
109109 <tr>
110 - <td align=\"right\">".wfMsg('deletebatch-as')."</td>
111 - <td align=\"left\">");
 110+ <td align=\"right\">" . wfMsg( 'deletebatch-as' ) . "</td>
 111+ <td align=\"left\">" );
112112 $this->makeSelect(
113113 'wpMode',
114114 array(
115 - wfMsg('deletebatch-select-script') => 'script',
116 - wfMsg('deletebatch-select-yourself') => 'you'
 115+ wfMsg( 'deletebatch-select-script' ) => 'script',
 116+ wfMsg( 'deletebatch-select-yourself' ) => 'you'
117117 ),
118118 $this->mMode,
119119 1
120120 );
121 - $wgOut->addHTML("</td>
 121+ $wgOut->addHTML( "</td>
122122 </tr>
123123 <tr>
124 - <td align=\"right\" style=\"vertical-align:top\">".wfMsg('deletebatch-page')."</td>
 124+ <td align=\"right\" style=\"vertical-align:top\">" . wfMsg( 'deletebatch-page' ) . "</td>
125125 <td align=\"left\">
126126 <textarea tabindex=\"3\" name=\"wpPage\" id=\"wpPage\" cols=\"40\" rows=\"10\"></textarea>
127127 </td>
128128 </tr>
129129 <tr>
130 - <td align=\"right\">".wfMsg('deletebatch-or')."&#160;</td>
 130+ <td align=\"right\">" . wfMsg( 'deletebatch-or' ) . "&#160;</td>
131131 <td align=\"left\">
132132 &#160;
133133 </td>
134134 </tr>
135135 <tr>
136 - <td align=\"right\">".wfMsg('deletebatch-caption')."</td>
 136+ <td align=\"right\">" . wfMsg( 'deletebatch-caption' ) . "</td>
137137 <td align=\"left\">
138138 <input type=\"file\" tabindex=\"4\" name=\"wpFile\" id=\"wpFile\" value=\"{$scFile}\" />
139139 </td>
@@ -140,25 +140,25 @@
141141 <tr>
142142 <td align=\"right\">&#160;</td>
143143 <td align=\"left\">
144 - <input tabindex=\"5\" name=\"wpdeletebatchSubmit\" type=\"submit\" value=\"".strtoupper( wfMsg( 'delete' ) )."\" />
 144+ <input tabindex=\"5\" name=\"wpdeletebatchSubmit\" type=\"submit\" value=\"" . wfMsg( 'delete' ) . "\" />
145145 </td>
146146 </tr>
147147 </table>
148148 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
149 -</form>");
 149+</form>" );
150150 }
151151
152152 /* draws select and selects it properly */
153153 function makeSelect( $name, $options_array, $current, $tabindex ) {
154154 global $wgOut;
155 - $wgOut->addHTML("<select tabindex=\"$tabindex\" name=\"$name\">");
156 - foreach( $options_array as $key => $value ) {
157 - if( $value == $current )
158 - $wgOut->addHTML("<option value=\"$value\" selected=\"selected\">$key</option>");
 155+ $wgOut->addHTML( "<select tabindex=\"$tabindex\" name=\"$name\">" );
 156+ foreach ( $options_array as $key => $value ) {
 157+ if ( $value == $current )
 158+ $wgOut->addHTML( "<option value=\"$value\" selected=\"selected\">$key</option>" );
159159 else
160 - $wgOut->addHTML("<option value=\"$value\">$key</option>");
 160+ $wgOut->addHTML( "<option value=\"$value\">$key</option>" );
161161 }
162 - $wgOut->addHTML("</select>");
 162+ $wgOut->addHTML( "</select>" );
163163 }
164164
165165 /* wraps up multi deletes */
@@ -166,27 +166,27 @@
167167 global $wgUser, $wgOut;
168168
169169 /* first, check the file if given */
170 - if( $filename ) {
 170+ if ( $filename ) {
171171 /* both a file and a given page? not too much? */
172 - if( '' != $this->mPage ) {
173 - $this->showForm( wfMsg('deletebatch-both-modes') );
 172+ if ( '' != $this->mPage ) {
 173+ $this->showForm( wfMsg( 'deletebatch-both-modes' ) );
174174 return;
175175 }
176 - if( "text/plain" != mime_content_type($filename) ) {
177 - $this->showForm( wfMsg('deletebatch-file-bad-format') );
 176+ if ( "text/plain" != mime_content_type( $filename ) ) {
 177+ $this->showForm( wfMsg( 'deletebatch-file-bad-format' ) );
178178 return;
179179 }
180 - $file = fopen($filename, 'r');
 180+ $file = fopen( $filename, 'r' );
181181 if ( !$file ) {
182 - $this->showForm( wfMsg('deletebatch-file-missing') );
 182+ $this->showForm( wfMsg( 'deletebatch-file-missing' ) );
183183 return;
184184 }
185185 }
186186 /* switch user if necessary */
187187 $OldUser = $wgUser;
188 - if( 'script' == $this->mMode ) {
 188+ if ( 'script' == $this->mMode ) {
189189 $username = 'Delete page script';
190 - $wgUser = User::newFromName($username);
 190+ $wgUser = User::newFromName( $username );
191191 /* Create the user if necessary */
192192 if ( !$wgUser->getID() ) {
193193 $wgUser->addToDatabase();
@@ -195,7 +195,7 @@
196196
197197 /* todo run tests - run many tests */
198198 $dbw = wfGetDB( DB_MASTER );
199 - if( $filename ) { /* if from filename, delete from filename */
 199+ if ( $filename ) { /* if from filename, delete from filename */
200200 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
201201 $line = trim( fgets( $file ) );
202202 if ( $line == false ) {
@@ -205,30 +205,30 @@
206206 the file should contain only "page title|reason"\n lines
207207 the rest is trash
208208 */
209 - $arr = explode("|", $line);
210 - is_null($arr[1]) ? $reason = '' : $reason = $arr[1];
211 - $this->deletePage($arr[0], $reason, $dbw, true, $linenum);
 209+ $arr = explode( "|", $line );
 210+ is_null( $arr[1] ) ? $reason = '' : $reason = $arr[1];
 211+ $this->deletePage( $arr[0], $reason, $dbw, true, $linenum );
212212 }
213213 } else {
214214 /* run through text and do all like it should be */
215215 $lines = explode( "\n", $line );
216 - foreach( $lines as $single_page ) {
 216+ foreach ( $lines as $single_page ) {
217217 /* explode and give me a reason */
218218 $page_data = explode( "|", trim( $single_page ) );
219 - if( count($page_data) < 2 )
 219+ if ( count( $page_data ) < 2 )
220220 $page_data[1] = '';
221 - $result = $this->deletePage($page_data[0], $page_data[1], $dbw, false, 0, $OldUser);
 221+ $result = $this->deletePage( $page_data[0], $page_data[1], $dbw, false, 0, $OldUser );
222222 }
223223 }
224224
225225 /* restore user back */
226 - if( 'script' == $this->mMode ) {
 226+ if ( 'script' == $this->mMode ) {
227227 $wgUser = $OldUser;
228228 }
229229
230230 $sk = $wgUser->getSkin();
231231 $titleObj = SpecialPage::getTitleFor( 'DeleteBatch' );
232 - $link_back = $sk->makeKnownLinkObj( $titleObj, wfMsg('deletebatch-link-back') );
 232+ $link_back = $sk->linkKnown( $titleObj, wfMsg( 'deletebatch-link-back' ) );
233233 $wgOut->addHTML( "<br /><b>" . $link_back . "</b>" );
234234 }
235235
@@ -240,19 +240,19 @@
241241 function deletePage( $line, $reason = '', &$db, $multi = false, $linenum = 0, $user = null ) {
242242 global $wgOut, $wgUser;
243243 $page = Title::newFromText( $line );
244 - if( is_null( $page ) ) { /* invalid title? */
 244+ if ( is_null( $page ) ) { /* invalid title? */
245245 $wgOut->addWikiMsg( 'deletebatch-omitting-invalid', $line );
246 - if( !$multi ) {
247 - if( !is_null( $user ) ) {
 246+ if ( !$multi ) {
 247+ if ( !is_null( $user ) ) {
248248 $wgUser = $user;
249249 }
250250 }
251251 return false;
252252 }
253 - if( !$page->exists() ) { /* no such page? */
 253+ if ( !$page->exists() ) { /* no such page? */
254254 $wgOut->addWikiMsg( 'deletebatch-omitting-nonexistant', $line );
255 - if( !$multi ) {
256 - if( !is_null( $user ) ) {
 255+ if ( !$multi ) {
 256+ if ( !is_null( $user ) ) {
257257 $wgUser = $user;
258258 }
259259 }
@@ -260,24 +260,24 @@
261261 }
262262
263263 $db->begin();
264 - if( NS_MEDIA == $page->getNamespace() ) {
265 - $page = Title::makeTitle( NS_IMAGE, $page->getDBkey() );
 264+ if ( NS_MEDIA == $page->getNamespace() ) {
 265+ $page = Title::makeTitle( NS_FILE, $page->getDBkey() );
266266 }
267267
268268 /* this stuff goes like articleFromTitle in Wiki.php */
269 - if( $page->getNamespace() == NS_IMAGE ) {
270 - $art = new ImagePage($page);
 269+ if ( $page->getNamespace() == NS_FILE ) {
 270+ $art = new ImagePage( $page );
271271 /*this is absolutely required - creating a new ImagePage object does not automatically
272272 provide it with image */
273273 $art->img = new Image( $art->mTitle );
274274 } else {
275 - $art = new Article($page);
 275+ $art = new Article( $page );
276276 }
277277
278278 /* what is the generic reason for page deletion?
279279 something about the content, I guess...
280280 */
281 - $art->doDelete($reason);
 281+ $art->doDelete( $reason );
282282 $db->commit();
283283 return true;
284284 }
@@ -286,14 +286,14 @@
287287 function doSubmit() {
288288 global $wgOut, $wgUser, $wgRequest, $wgLanguageCode;
289289 $wgOut->setPageTitle( wfMsg( 'deletebatch-title' ) );
290 - if( !$this->mPage && !$this->mFileTemp ) {
 290+ if ( !$this->mPage && !$this->mFileTemp ) {
291291 $this->showForm( wfMsg( 'deletebatch-no-page' ) );
292292 return;
293293 }
294 - if( $this->mPage ) {
295 - $wgOut->setSubTitle( wfMsg( 'deletebatch-processing-from-form') );
 294+ if ( $this->mPage ) {
 295+ $wgOut->setSubTitle( wfMsg( 'deletebatch-processing-from-form' ) );
296296 } else {
297 - $wgOut->setSubTitle( wfMsg( 'deletebatch-processing-from-file') );
 297+ $wgOut->setSubTitle( wfMsg( 'deletebatch-processing-from-file' ) );
298298 }
299299 $this->deleteBatch( $this->mUser, $this->mPage, $this->mFileTemp );
300300 }
Index: trunk/extensions/DeleteBatch/DeleteBatch.php
@@ -9,14 +9,14 @@
1010 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1111 * @link http://www.mediawiki.org/wiki/Extension:DeleteBatch Documentation
1212 */
13 -if( !defined( 'MEDIAWIKI' ) )
 13+if ( !defined( 'MEDIAWIKI' ) )
1414 die();
1515
1616 // Extension credits that will show up on Special:version
1717 $wgExtensionCredits['specialpage'][] = array(
1818 'path' => __FILE__,
1919 'name' => 'Delete Batch',
20 - 'version' => '1.2',
 20+ 'version' => '1.2.1',
2121 'author' => 'Bartek Łapiński',
2222 'url' => 'http://www.mediawiki.org/wiki/Extension:DeleteBatch',
2323 'description' => 'Deletes a batch of pages',
@@ -28,10 +28,10 @@
2929 $wgGroupPermissions['bureaucrat']['deletebatch'] = true;
3030
3131 // Set up the new special page
32 -$dir = dirname(__FILE__) . '/';
 32+$dir = dirname( __FILE__ ) . '/';
3333 $wgExtensionMessagesFiles['DeleteBatch'] = $dir . 'DeleteBatch.i18n.php';
3434 $wgExtensionAliasesFiles['DeleteBatch'] = $dir . 'DeleteBatch.alias.php';
35 -$wgAutoloadClasses['DeleteBatch'] = $dir. 'DeleteBatch.body.php';
 35+$wgAutoloadClasses['DeleteBatch'] = $dir . 'DeleteBatch.body.php';
3636 $wgSpecialPages['DeleteBatch'] = 'DeleteBatch';
3737 // Special page group for MW 1.13+
3838 $wgSpecialPageGroups['DeleteBatch'] = 'pagetools';

Status & tagging log