r44950 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44949‎ | r44950 | r44951 >
Date:16:26, 23 December 2008
Author:ialex
Status:deferred
Tags:
Comment:
* Use $this->getTitle() rather than Title::makeTitle() to get a title object for the local page
* Use the Linker to make links
* Swicthed some input generation to use methods from the Xml class
* Fixed XHTML error
* Fixed PHP fatal error in changePassword script
* Spacing tweaks
Modified paths:
  • /trunk/extensions/Maintenance/Maintenance_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maintenance/Maintenance_body.php
@@ -6,6 +6,11 @@
77
88 class Maintenance extends SpecialPage {
99 var $type = '';
 10+ static $scripts = array(
 11+ 'changePassword', 'createAndPromote', 'deleteBatch', 'deleteRevision',
 12+ 'initEditCount', 'initStats', 'moveBatch', 'runJobs', 'showJobs', 'stats',
 13+ 'sql', 'eval',
 14+ );
1015
1116 /**
1217 * Constructor
@@ -51,48 +56,53 @@
5257 }
5358
5459 function makeInitialForm() {
 60+ global $wgOut, $wgUser;
 61+
 62+ wfLoadExtensionMessages( 'Maintenance' );
 63+ $this->setHeaders();
 64+ $wgOut->addWikiMsg( 'maintenance-header' );
 65+ $sk = $wgUser->getSkin();
 66+ $wgOut->addHTML( '<ul>' );
 67+
5568 //scripts that we allow to run via this interface. keep them to the same name as the xxx.php in the /maintenance dir
5669 //(minus the .php part... duh)
57 - $scripts = array(
58 - 'changePassword', 'createAndPromote', 'deleteBatch', 'deleteRevision',
59 - 'initEditCount', 'initStats', 'moveBatch', 'runJobs', 'showJobs', 'stats',
60 - 'sql', 'eval',
61 - );
62 - sort($scripts);
63 - global $wgOut;
64 - wfLoadExtensionMessages('Maintenance');
65 - $this->setHeaders();
66 - $title = Title::makeTitle( NS_SPECIAL, $this->getName() );
67 - $url = $title->getFullUrl() . '/';
68 - $wgOut->addWikiMsg('maintenance-header');
69 - $wgOut->addHTML( '<ul>' );
 70+ $scripts = self::$scripts;
 71+ sort( $scripts );
7072 foreach( $scripts as $type ) {
71 - $wgOut->addHTML( '<li><a href="'.$url.$type.'">'.$type.'</a> -- '.wfMsg('maintenance-'.$type.'-desc').'</li>' );
 73+ $title = $this->getTitle( $type );
 74+ $wgOut->addHTML( '<li>'. $sk->makeKnownLinkObj( $title, htmlspecialchars( $type ) ) . ' -- '.
 75+ wfMsgExt( 'maintenance-'.$type.'-desc', array( 'parseinline' ) ) . '</li>' );
7276 }
7377 $wgOut->addHTML( '</ul>' );
7478 }
7579
7680 function makeForm( $type ) {
77 - global $wgOut;
78 - wfLoadExtensionMessages('Maintenance');
 81+ global $wgOut, $wgUser;
 82+ wfLoadExtensionMessages( 'Maintenance' );
7983 $this->setHeaders();
80 - $title = Title::makeTitle( NS_SPECIAL, $this->getName() );
81 - $wgOut->addHTML('<a href="'.$title->getFullURL().'">'.wfMsg('maintenance-backlink').'</a><br />');
82 - $wgOut->addHTML('<form method="post" action="'.$title->getFullURL().'/'.$type.'">');
83 - $wgOut->addHTML('<p>'.wfMsg('maintenance-'.$type).'</p><br />');
 84+ $wgOut->addHTML( $wgUser->getSkin()->makeKnownLinkObj( $this->getTitle(), wfMsgHtml( 'maintenance-backlink' ) ). '<br />' );
 85+
 86+ if( !in_array( $type, self::$scripts ) ) {
 87+ $wgOut->addWikiMsg( 'maintenance-invalidtype' );
 88+ return;
 89+ }
 90+
 91+ $wgOut->addWikiMsg( 'maintenance-' . $type );
 92+
 93+ $wgOut->addHTML( Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle( $type )->getFullURL() ) ) );
8494 switch( $type ) {
8595 case 'changePassword':
86 - $wgOut->addHTML('<label for="wpName">'.wfMsg('maintenance-name').'</label> <input type="text" name="wpName" /><br /><br />');
87 - $wgOut->addHTML('<label for="wpPassword">'.wfMsg('maintenance-password').'</label> <input type="password" name="wpPassword" /><br /><br />');
 96+ $wgOut->addHTML( Xml::inputLabel( wfMsg( 'maintenance-name' ), 'wpName', 'wpName' ) . '<br /><br />' );
 97+ $wgOut->addHTML( Xml::inputLabel( wfMsg( 'maintenance-password' ), 'wpPassword', 'wpPassword', false, false, array( 'type' => 'password' ) ) . '<br /><br />' );
8898 break;
8999 case 'createAndPromote':
90 - $wgOut->addHTML('<label for="wpName">'.wfMsg('maintenance-name').'</label> <input type="text" name="wpName" /><br /><br />');
91 - $wgOut->addHTML('<label for="wpPassword">'.wfMsg('maintenance-password').'</label> <input type="password" name="wpPassword" /><br /><br />');
92 - $wgOut->addHTML('<input type="checkbox" name="wpBcrat" value="0" /><label for="wpBcrat">'.wfMsg('maintenance-bureaucrat').'</label><br /><br />');
 100+ $wgOut->addHTML( Xml::inputLabel( wfMsg( 'maintenance-name' ), 'wpName', 'wpName' ) . '<br /><br />' );
 101+ $wgOut->addHTML( Xml::inputLabel( wfMsg( 'maintenance-password' ), 'wpPassword', 'wpPassword', false, false, array( 'type' => 'password' ) ) . '<br /><br />' );
 102+ $wgOut->addHTML( Xml::checkLabel( wfMsg('maintenance-bureaucrat'), 'wpBcrat', 'wpBcrat' ) . '<br /><br />' );
93103 break;
94104 case 'deleteBatch':
95105 $wgOut->addHTML('<textarea name="wpDelete" rows="25" cols="80"></textarea><br /><br />');
96 - $wgOut->addHTML('<label for="wpReason">'.wfMsg('maintenance-reason').'</label> <input type="text" name="wpReason" maxlength="200" size="60" /><br /><br />');
 106+ $wgOut->addHTML( Xml::inputLabel( wfMsg( 'maintenance-reason' ), 'wpReason', 'wpReason', '60', false, array( 'maxlength' => 200 ) ) . '<br /><br />' );
97107 break;
98108 case 'deleteRevision':
99109 $wgOut->addHTML('<textarea name="wpDelete" rows="25" cols="80"></textarea><br /><br />');
@@ -104,12 +114,12 @@
105115 //just hit the button to start this, no additional settings are needed :)
106116 break;
107117 case 'initStats':
108 - $wgOut->addHTML('<input type="checkbox" name="wpUpdate" value="0" checked="checked"/><label for="wpUpdate">'.wfMsg('maintenance-update').'</label><br /><br />');
109 - $wgOut->addHTML('<input type="checkbox" name="wpNoviews" value="0" /><label for="wpNoviews">'.wfMsg('maintenance-noviews').'</label><br /><br />');
 118+ $wgOut->addHTML( Xml::checkLabel( wfMsg( 'maintenance-update' ), 'wpUpdate', 'wpUpdate', true ) . '<br /><br />' );
 119+ $wgOut->addHTML( Xml::checkLabel( wfMsg( 'maintenance-noviews' ), 'wpNoviews', 'wpNoviews' ) . '<br /><br />' );
110120 break;
111121 case 'moveBatch':
112122 $wgOut->addHTML('<textarea name="wpMove" rows="25" cols="80"></textarea><br /><br />');
113 - $wgOut->addHTML('<label for="wpReason">'.wfMsg('maintenance-reason').'</label> <input type="text" name="wpReason" maxlength="200" size="60" /><br /><br />');
 123+ $wgOut->addHTML( Xml::inputLabel( wfMsg( 'maintenance-reason' ), 'wpReason', 'wpReason', '60', false, array( 'maxlength' => 200 ) ) . '<br /><br />' );
114124 break;
115125 case 'runJobs':
116126 //just hit the button to start this, no additional settings are needed :)
@@ -124,10 +134,11 @@
125135 $wgOut->addHTML('<textarea name="wpQuery" rows="25" cols="80"></textarea><br /><br />');
126136 break;
127137 default:
128 - $wgOut->addHTML('<p>'.wfMsg('maintenance-invalidtype').'</p></form>');
 138+ $wgOut->addHTML( '</form>' );
 139+ $wgOut->addWikiMsg( 'maintenance-invalidtype' );
129140 return;
130141 }
131 - $wgOut->addHTML('<input type="submit" name="wpConfirm" value="'.wfMsg('maintenance-confirm').'" /></form>');
 142+ $wgOut->addHTML( Xml::submitButton( wfMsg( 'maintenance-confirm' ), array( 'name' => 'wpConfirm' ) ) . '</form>' );
132143 return;
133144 }
134145
@@ -136,15 +147,14 @@
137148 wfLoadExtensionMessages('Maintenance');
138149 @set_time_limit(0); //if we can, disable the time limit
139150 $this->setHeaders();
140 - $title = Title::makeTitle( NS_SPECIAL, $this->getName() );
141 - $wgOut->addHTML('<a href="'.$title->getFullURL().'">'.wfMsg('maintenance-backlink').'</a><br />');
 151+ $wgOut->addHTML( $wgUser->getSkin()->makeKnownLinkObj( $this->getTitle(), wfMsgHtml( 'maintenance-backlink' ) ). '<br />' );
142152 switch( $type ) {
143153 case 'changePassword':
144 - $name = $wgRequest->getText('wpName');
145 - $password = $wgRequest->getText('wpPassword');
146 - $user = User::newFromName($name);
147 - if( !$user->getId() ) {
148 - $wgOut->addWikiMsg('maintenance-invalidname');
 154+ $name = $wgRequest->getText( 'wpName' );
 155+ $password = $wgRequest->getText( 'wpPassword' );
 156+ $user = User::newFromName( $name );
 157+ if( !is_object( $user ) || !$user->getId() ) {
 158+ $wgOut->addWikiMsg( 'maintenance-invalidname' );
149159 return;
150160 }
151161 $dbw = wfGetDB( DB_MASTER );
@@ -154,38 +164,38 @@
155165 $wgOut->addWikiMsg( 'maintenance-success', $type );
156166 break;
157167 case 'createAndPromote':
158 - $name = $wgRequest->getText('wpName');
159 - $password = $wgRequest->getText('wpPassword');
160 - $bcrat = $wgRequest->getCheck('wpBcrat');
161 - $user = User::newFromName($name);
162 - if( !is_object($user) ) {
163 - $wgOut->addWikiMsg('maintenance-invalidname');
 168+ $name = $wgRequest->getText( 'wpName' );
 169+ $password = $wgRequest->getText( 'wpPassword' );
 170+ $bcrat = $wgRequest->getCheck( 'wpBcrat' );
 171+ $user = User::newFromName( $name );
 172+ if( !is_object( $user ) ) {
 173+ $wgOut->addWikiMsg( 'maintenance-invalidname' );
164174 return;
165175 } elseif( 0 != $user->idForName() ) {
166 - $wgOut->addWikiMsg('maintenance-userexists');
 176+ $wgOut->addWikiMsg( 'maintenance-userexists' );
167177 return;
168178 }
169179 $user->addToDatabase();
170180 $user->setPassword( $password );
171181 $user->saveSettings();
172 - $user->addGroup('sysop');
 182+ $user->addGroup( 'sysop');
173183 if( $bcrat )
174 - $user->addGroup('bureaucrat');
 184+ $user->addGroup( 'bureaucrat' );
175185 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
176186 $ssu->doUpdate();
177187 $wgOut->addWikiMsg( 'maintenance-success', $type );
178188 break;
179189 case 'deleteBatch':
180 - $reason = $wgRequest->getText('wpReason', '');
 190+ $reason = $wgRequest->getText( 'wpReason', '' );
181191 $interval = 0;
182 - $pages = $wgRequest->getText('wpDelete');
 192+ $pages = $wgRequest->getText( 'wpDelete' );
183193 $dbw = wfGetDB( DB_MASTER );
184194 $lines = explode( "\n", $pages );
185195 foreach( $lines as &$line ) {
186 - $line = trim($line);
 196+ $line = trim( $line );
187197 if( $line == '' )
188198 continue;
189 - $page = Title::newFromText($line);
 199+ $page = Title::newFromText( $line );
190200 if( is_null( $page ) ) {
191201 $wgOut->addWikiMsg( 'maintenance-invalidtitle', $line );
192202 continue;
@@ -215,17 +225,17 @@
216226 // ...and switch user back to the old user
217227 $wgUser = $OldUser;
218228 if ( $success ) {
219 - $return .= '... ' . wfMsg('maintenance-deleted');
 229+ $return .= '... ' . wfMsg( 'maintenance-deleted' );
220230 } else {
221 - $return .= '... ' . wfMsg('maintenance-failed');
 231+ $return .= '... ' . wfMsg( 'maintenance-failed' );
222232 }
223 - $wgOut->addWikiText($return);
 233+ $wgOut->addWikiText( $return );
224234 waitForSlaves( 5 );
225235 }
226236 $wgOut->addWikiMsg( 'maintenance-success', $type );
227237 break;
228238 case 'deleteRevision':
229 - $delete = $wgRequest->getText('wpDelete');
 239+ $delete = $wgRequest->getText( 'wpDelete' );
230240 $revisions = explode( "\n", $delete );
231241 $wgOut->addWikiMsg( 'maintenance-revdelete', implode( ', ', $revisions ), wfWikiID() );
232242 $affected = 0;
@@ -381,11 +391,9 @@
382392 break;
383393 case 'runJobs':
384394 $maxJobs = 10000;
385 - $type = false;
386395 $dbw = wfGetDB( DB_MASTER );
387396 $n = 0;
388 - $conds = '';
389 - while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) {
 397+ while ( $dbw->selectField( 'job', 'count(*)', '', 'runJobs.php' ) ) {
390398 $offset = 0;
391399 for (;;) {
392400 $job = Job::pop($offset);
@@ -506,7 +514,7 @@
507515 $wgOut->addWikiMsg( 'maintenance-success', $type );
508516 break;
509517 default:
510 - $wgOut->addHTML('<p>'.wfMsg('maintenance-invalidtype').'</p></form>');
 518+ $wgOut->addWikiMsg( 'maintenance-invalidtype' );
511519 return;
512520 }
513521 }

Status & tagging log