r49447 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49446‎ | r49447 | r49448 >
Date:17:56, 13 April 2009
Author:ialex
Status:deferred
Tags:
Comment:
* Added log to track wiki creation and deletion
* Added reason field on creation and deletion forms
* Wiki deletion now require confirmation
Modified paths:
  • /trunk/extensions/Farmer/Farmer.i18n.php (modified) (history)
  • /trunk/extensions/Farmer/Farmer.php (modified) (history)
  • /trunk/extensions/Farmer/SpecialFarmer.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Farmer/Farmer.i18n.php
@@ -46,9 +46,10 @@
4747 'farmer-wikiexists-text' => 'The wiki you are attempting to create, \'\'\'$1\'\'\', already exists.
4848 Please go back and try another name.',
4949 'farmer-confirmsetting' => 'Confirm wiki settings',
50 - 'farmer-confirmsetting-name' => 'Name: $1',
51 - 'farmer-confirmsetting-title' => 'Title: $1',
52 - 'farmer-confirmsetting-description' => 'Description: $1',
 50+ 'farmer-confirmsetting-name' => 'Name',
 51+ 'farmer-confirmsetting-title' => 'Title',
 52+ 'farmer-confirmsetting-description' => 'Description',
 53+ 'farmer-confirmsetting-reason' => 'Reason',
5354 'farmer-description' => 'Description',
5455 'farmer-confirmsetting-text' => 'Your wiki, \'\'\'$1\'\'\', will be accessible via http://$1.myfarm.
5556 The project namespace will be \'\'\'$2\'\'\'.
@@ -73,6 +74,7 @@
7475 'farmer-createwiki-name' => 'Wiki name',
7576 'farmer-createwiki-title' => 'Wiki title',
7677 'farmer-createwiki-description' => 'Description',
 78+ 'farmer-createwiki-reason' => 'Reason',
7779 'farmer-updatedlist' => 'Updated list',
7880 'farmer-notaccessible' => 'Not accessible',
7981 'farmer-notaccessible-test' => 'This feature is only available on the parent wiki in the farm',
@@ -80,6 +82,9 @@
8183 'farmer-permissiondenied-text' => 'You do not have permission to delete a wiki from the farm',
8284 'farmer-permissiondenied-text1' => 'You do not have permission to access this page',
8385 'farmer-deleting' => 'Deleting $1',
 86+ 'farmer-delete-confirm' => 'I confirm that I want to delete this wiki',
 87+ 'farmer-delete-confirm-wiki' => "Wiki to delete: '''$1'''.",
 88+ 'farmer-delete-reason' => 'Reason for the deletion:',
8489 'farmer-delete-title' => 'Delete wiki',
8590 'farmer-delete-text' => 'Please select the wiki from the list below that you wish to delete',
8691 'farmer-delete-form' => 'Select a wiki',
@@ -128,6 +133,10 @@
129134 'farmer-extensions-register-includefile' => 'Include file',
130135 'farmer-error-exists' => 'Cannot create wiki. It already exists: $1',
131136 'farmer-error-noextwrite' => 'Unable to write out extension file:',
 137+ 'farmer-log-name' => 'Wiki farm log',
 138+ 'farmer-log-header' => 'This is a log of changes made to the wiki farm.',
 139+ 'farmer-log-create' => 'created the wiki "$2"',
 140+ 'farmer-log-delete' => 'deleted the wiki "$2"',
132141 );
133142
134143 /** Message documentation (Message documentation)
Index: trunk/extensions/Farmer/Farmer.php
@@ -18,7 +18,7 @@
1919 'url' => 'http://www.mediawiki.org/wiki/Extension:Farmer',
2020 'description' => 'Manage a MediaWiki farm',
2121 'descriptionmsg' => 'farmer-desc',
22 - 'version' => '0.0.5',
 22+ 'version' => '0.0.6',
2323 );
2424
2525 /**
@@ -95,3 +95,10 @@
9696 $wgGroupPermissions['sysop']['farmeradmin'] = true;
9797 $wgGroupPermissions['*']['createwiki'] = false;
9898 $wgGroupPermissions['sysop']['createwiki'] = true;
 99+
 100+# New log
 101+$wgLogTypes[] = 'farmer';
 102+$wgLogNames['farmer'] = 'farmer-log-name';
 103+$wgLogHeaders['farmer'] = 'farmer-log-header';
 104+$wgLogActions['farmer/create'] = 'farmer-log-create';
 105+$wgLogActions['farmer/delete'] = 'farmer-log-delete';
Index: trunk/extensions/Farmer/SpecialFarmer.php
@@ -107,8 +107,6 @@
108108 protected function _executeCreate( $wgFarmer, $wiki ){
109109 global $wgOut, $wgUser, $wgRequest;
110110
111 - $confirmaccount = wfMsg( 'farmer-button-confirm' );
112 -
113111 if( !$wgFarmer->getActiveWiki()->isDefaultWiki() ) {
114112 $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-notavailable' );
115113 $wgOut->addWikiMsg( 'farmer-notavailable-text' );
@@ -120,18 +118,22 @@
121119 return;
122120 }
123121
124 - $name = MediaWikiFarmer_Wiki::sanitizeName( $wgRequest->getVal( 'name', $wiki ) );
125 - $title = MediaWikiFarmer_Wiki::sanitizeTitle( $wgRequest->getVal( 'wikititle' ) );
126 - $description = $wgRequest->getVal( 'description' );
 122+ $name = MediaWikiFarmer_Wiki::sanitizeName( $wgRequest->getVal( 'wpName', $wiki ) );
 123+ $title = MediaWikiFarmer_Wiki::sanitizeTitle( $wgRequest->getVal( 'wpTitle' ) );
 124+ $description = $wgRequest->getVal( 'wpDescription', '' );
 125+ $reason = $wgRequest->getVal( 'wpReason' );
127126 $action = $this->getTitle( 'create' )->escapeLocalURL();
128127
129128 //if something was POST'd
130129 if( $wgRequest->wasPosted() ){
131130 //we create the wiki if the user pressed 'Confirm'
132 - if( $wgRequest->getCheck( 'confirm' ) ) {
 131+ if( $wgRequest->getCheck( 'wpConfirm' ) ) {
133132 $wikiObj = MediaWikiFarmer_Wiki::newFromParams( $name, $title, $description, $wgUser->getName() );
134133 $wikiObj->create();
135134
 135+ $log = new LogPage( 'farmer' );
 136+ $log->addEntry( 'create', $this->getTitle(), $reason, array( $name ) );
 137+
136138 $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-wikicreated' );
137139 $wgOut->addWikiMsg( 'farmer-wikicreated-text', $wikiObj->getUrl( wfUrlencode( wfMsgNoDB( 'mainpage' ) ) ) );
138140 $wgOut->addWikiMsg( 'farmer-default', '[['.$title.':Special:Farmer|Special:Farmer]]' );
@@ -147,25 +149,33 @@
148150 }
149151
150152 $url = $wiki->getUrl( '' );
151 - $wgOut->wrapWikiMsg(
152 - "== $1 ==\n; $2\n; $3\n; $4\n$5",
153 - 'farmer-confirmsetting',
154 - array( 'farmer-confirmsetting-name', $name ),
155 - array( 'farmer-confirmsetting-title', $title ),
156 - array( 'farmer-confirmsetting-description', $description ),
157 - array( 'farmer-confirmsetting-text', $name, $title, $url )
 153+ $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-confirmsetting' );
 154+
 155+ $wgOut->addHtml( Xml::openElement( 'table', array( 'class' => 'wikitable' ) ) . "\n" .
 156+ Xml::tags( 'tr', array(), Xml::tags( 'th', array(),
 157+ wfMsgExt( 'farmer-confirmsetting-name', 'parseinline' ) ) . Xml::element( 'td', array(), $name ) ) . "\n" .
 158+ Xml::tags( 'tr', array(), Xml::tags( 'th', array(),
 159+ wfMsgExt( 'farmer-confirmsetting-title', 'parseinline' ) ) . Xml::element( 'td', array(), $title ) ) . "\n" .
 160+ Xml::tags( 'tr', array(), Xml::tags( 'th', array(),
 161+ wfMsgExt( 'farmer-confirmsetting-description', 'parseinline' ) ) . Xml::element( 'td', array(), $description ) ) . "\n" .
 162+ Xml::tags( 'tr', array(), Xml::tags( 'th', array(),
 163+ wfMsgExt( 'farmer-confirmsetting-reason', 'parseinline' ) ) . Xml::element( 'td', array(), $reason ) ) . "\n" .
 164+ Xml::closeElement( 'table' )
158165 );
 166+ $wgOut->addWikiMsg( 'farmer-confirmsetting-text', $name, $title, $url );
159167
160168 $nameaccount = htmlspecialchars( $name );
161169 $nametitle = htmlspecialchars( $title );
162170 $namedescript = htmlspecialchars( $description );
 171+ $confirmaccount = wfMsgHtml( 'farmer-button-confirm' );
163172 $wgOut->addHTML("
164173
165174 <form id=\"farmercreate2\" method=\"post\" action=\"$action\">
166 -<input type=\"hidden\" name=\"name\" value=\"{$nameaccount}\" />
167 -<input type=\"hidden\" name=\"wikititle\" value=\"{$nametitle}\" />
168 -<input type=\"hidden\" name=\"description\" value=\"{$namedescript}\" />
169 -<input type=\"submit\" name=\"confirm\" value=\"{$confirmaccount}\" />
 175+<input type=\"hidden\" name=\"wpName\" value=\"{$nameaccount}\" />
 176+<input type=\"hidden\" name=\"wpTitle\" value=\"{$nametitle}\" />
 177+<input type=\"hidden\" name=\"wpDescription\" value=\"{$namedescript}\" />
 178+<input type=\"hidden\" name=\"wpReason\" value=\"{$reason}\" />
 179+<input type=\"submit\" name=\"wpConfirm\" value=\"{$confirmaccount}\" />
170180 </form>"
171181 );
172182
@@ -194,33 +204,20 @@
195205
196206 $token = htmlspecialchars( $wgUser->editToken() );
197207
198 - $wgOut->addHTML( "
199 -<form id='farmercreate1' method='post' action=\"$action\">
200 - <table>
201 - <tr>
202 - <td align=\"right\">". wfMsg( 'farmer-createwiki-user' ) . "</td>
203 - <td align=\"left\"><b>{$wgUser->getName()}</b></td>
204 - </tr>
205 - <tr>
206 - <td align='right'>". wfMsg( 'farmer-createwiki-name' ) . "</td>
207 - <td align='left'><input tabindex='1' type='text' size='20' name='name' value=\"" . htmlspecialchars( $name ) . "\" /></td>
208 - </tr>
209 - <tr>
210 - <td align='right'>". wfMsg( 'farmer-createwiki-title' ) ."</td>
211 - <td align='left'><input tabindex='1' type='text' size='20' name='wikititle' value=\"" . htmlspecialchars( $title ) . "\"/></td>
212 - </tr>
213 - <tr>
214 - <td align='right'>". wfMsg( 'farmer-createwiki-description' ) ."</td>
215 - <td align='left'><textarea tabindex='1' cols=\"40\" rows=\"5\" name='description'>" . htmlspecialchars( $description ) . "</textarea></td>
216 - </tr>
217 - <tr>
218 - <td>&nbsp;</td>
219 - <td align='right'><input type='submit' name='submit' value=\"". wfMsgHtml( 'farmer-button-submit' ) . "\" /></td>
220 - </tr>
221 - </table>
222 - <input type='hidden' name='token' value=\"$token\" />
223 -</form>");
224 -
 208+ $wgOut->addHTML(
 209+ Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) . "\n" .
 210+ Xml::buildForm(
 211+ array(
 212+ 'farmer-createwiki-user' => Xml::element( 'b', array(), $wgUser->getName() ),
 213+ 'farmer-createwiki-name' => Xml::input( 'wpName', 20, $name ),
 214+ 'farmer-createwiki-title' => Xml::input( 'wpTitle', 20, $title ),
 215+ 'farmer-createwiki-description' => Xml::textarea( 'wpDescription', $description ),
 216+ 'farmer-createwiki-reason' => Xml::input( 'wpReason', 20, $reason ),
 217+ ), 'farmer-button-submit'
 218+ ) . "\n" .
 219+ Xml::hidden( 'token', $token ) . "\n" .
 220+ Xml::closeElement( 'form' )
 221+ );
225222 }
226223
227224 protected function _executeUpdateList( $wgFarmer ) {
@@ -233,7 +230,7 @@
234231
235232 $wgFarmer->updateFarmList();
236233 $wgFarmer->updateInterwikiTable();
237 - $wgOut->wrapWikiMsg( '<div class="successbox">$1</div>', 'farmer-updatedlist' );
 234+ $wgOut->wrapWikiMsg( '<div class="successbox">$1</div><br clear="all" />', 'farmer-updatedlist' );
238235 $wgOut->returnToMain( null, $this->getTitle() );
239236 }
240237
@@ -250,29 +247,50 @@
251248 return;
252249 }
253250
254 - if( ( $wiki = $wgRequest->getVal( 'wiki' ) ) && $wiki != '-1' ) {
255 - $wgOut->wrapWikiMsg( "== $1 ==", array( 'farmer-deleting', $wiki ) );
 251+ if( $wgRequest->wasPosted() && ( $wiki = $wgRequest->getVal( 'wpWiki' ) ) && $wiki != '-1' ) {
 252+ if( $wgRequest->getCheck( 'wpConfirm' ) ) {
 253+ $wgOut->wrapWikiMsg( '== $1 ==', array( 'farmer-deleting', $wiki ) );
256254
257 - $deleteWiki = MediaWikiFarmer_Wiki::factory( $wiki );
 255+ $log = new LogPage( 'farmer' );
 256+ $log->addEntry( 'delete', $this->getTitle(), $wgRequest->getVal( 'wpReason' ), array( $wiki ) );
258257
259 - $deleteWiki->deleteWiki();
 258+ $deleteWiki = MediaWikiFarmer_Wiki::factory( $wiki );
 259+ $deleteWiki->deleteWiki();
 260+ } else {
 261+ $wgOut->addWikiMsg( 'farmer-delete-confirm-wiki', $wiki );
 262+ $wgOut->addHTML(
 263+ Xml::openElement( 'form', array( 'method' => 'post', 'name' => 'deleteWiki' ) ) . "\n" .
 264+ Xml::buildForm( array(
 265+ 'farmer-delete-reason' => Xml::input( 'wpReason', false, $wgRequest->getVal( 'wpReason' ) ),
 266+ 'farmer-delete-confirm' => Xml::check( 'wpConfirm' )
 267+ ), 'farmer-delete-form-submit' ) . "\n" .
 268+ Xml::hidden( 'wpWiki', $wiki ) . "\n" .
 269+ Xml::closeElement( 'form' )
 270+ );
 271+ }
 272+ return;
260273 }
261274
262275 $list = $wgFarmer->getFarmList();
263276
264277 $wgOut->wrapWikiMsg( "== $1 ==\n$2", 'farmer-delete-title', 'farmer-delete-text' );
265278
266 - $wgOut->addHTML('<form method="post" name="deleteWiki"><select name="wiki"><option value="-1">'.wfMsgExt( 'farmer-delete-form', 'parseinline' )."</option>\n" );
267 -
 279+ $select = new XmlSelect( 'wpWiki', false, $wgRequest->getVal( 'wpWiki' ) );
 280+ $select->addOption( wfMsg( 'farmer-delete-form' ), '-1' );
268281 foreach ( $list as $wiki ) {
269282 if( $wiki['name'] != $wgFarmer->getDefaultWiki() ) {
270 - $name = htmlspecialchars( $wiki['name'] );
271 - $title = htmlspecialchars( $wiki['title'] );
272 - $wgOut->addHTML("<option value=\"$name\">$name - $title</option>\n" );
 283+ $name = $wiki['name'];
 284+ $title = $wiki['title'];
 285+ $select->addOption( "$name - $title", $name );
273286 }
274287 }
275288
276 - $wgOut->addHTML('</select><input type="submit" name="submit" value="'. wfMsgExt( 'farmer-delete-form-submit', 'parseinline' ).'" /></form>');
 289+ $wgOut->addHTML(
 290+ Xml::openElement( 'form', array( 'method' => 'post', 'name' => 'deleteWiki' ) ) . "\n" .
 291+ $select->getHTML() . "\n" .
 292+ Xml::submitButton( wfMsg( 'farmer-delete-form-submit' ) ) . "\n" .
 293+ Xml::closeElement( 'form' )
 294+ );
277295
278296 }
279297

Status & tagging log