Index: trunk/extensions/Maintenance/Maintenance_body.php |
— | — | @@ -6,6 +6,11 @@ |
7 | 7 | |
8 | 8 | class Maintenance extends SpecialPage { |
9 | 9 | var $type = ''; |
| 10 | + static $scripts = array( |
| 11 | + 'changePassword', 'createAndPromote', 'deleteBatch', 'deleteRevision', |
| 12 | + 'initEditCount', 'initStats', 'moveBatch', 'runJobs', 'showJobs', 'stats', |
| 13 | + 'sql', 'eval', |
| 14 | + ); |
10 | 15 | |
11 | 16 | /** |
12 | 17 | * Constructor |
— | — | @@ -51,48 +56,53 @@ |
52 | 57 | } |
53 | 58 | |
54 | 59 | 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 | + |
55 | 68 | //scripts that we allow to run via this interface. keep them to the same name as the xxx.php in the /maintenance dir |
56 | 69 | //(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 ); |
70 | 72 | 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>' ); |
72 | 76 | } |
73 | 77 | $wgOut->addHTML( '</ul>' ); |
74 | 78 | } |
75 | 79 | |
76 | 80 | function makeForm( $type ) { |
77 | | - global $wgOut; |
78 | | - wfLoadExtensionMessages('Maintenance'); |
| 81 | + global $wgOut, $wgUser; |
| 82 | + wfLoadExtensionMessages( 'Maintenance' ); |
79 | 83 | $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() ) ) ); |
84 | 94 | switch( $type ) { |
85 | 95 | 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 />' ); |
88 | 98 | break; |
89 | 99 | 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 />' ); |
93 | 103 | break; |
94 | 104 | case 'deleteBatch': |
95 | 105 | $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 />' ); |
97 | 107 | break; |
98 | 108 | case 'deleteRevision': |
99 | 109 | $wgOut->addHTML('<textarea name="wpDelete" rows="25" cols="80"></textarea><br /><br />'); |
— | — | @@ -104,12 +114,12 @@ |
105 | 115 | //just hit the button to start this, no additional settings are needed :) |
106 | 116 | break; |
107 | 117 | 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 />' ); |
110 | 120 | break; |
111 | 121 | case 'moveBatch': |
112 | 122 | $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 />' ); |
114 | 124 | break; |
115 | 125 | case 'runJobs': |
116 | 126 | //just hit the button to start this, no additional settings are needed :) |
— | — | @@ -124,10 +134,11 @@ |
125 | 135 | $wgOut->addHTML('<textarea name="wpQuery" rows="25" cols="80"></textarea><br /><br />'); |
126 | 136 | break; |
127 | 137 | default: |
128 | | - $wgOut->addHTML('<p>'.wfMsg('maintenance-invalidtype').'</p></form>'); |
| 138 | + $wgOut->addHTML( '</form>' ); |
| 139 | + $wgOut->addWikiMsg( 'maintenance-invalidtype' ); |
129 | 140 | return; |
130 | 141 | } |
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>' ); |
132 | 143 | return; |
133 | 144 | } |
134 | 145 | |
— | — | @@ -136,15 +147,14 @@ |
137 | 148 | wfLoadExtensionMessages('Maintenance'); |
138 | 149 | @set_time_limit(0); //if we can, disable the time limit |
139 | 150 | $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 />' ); |
142 | 152 | switch( $type ) { |
143 | 153 | 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' ); |
149 | 159 | return; |
150 | 160 | } |
151 | 161 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -154,38 +164,38 @@ |
155 | 165 | $wgOut->addWikiMsg( 'maintenance-success', $type ); |
156 | 166 | break; |
157 | 167 | 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' ); |
164 | 174 | return; |
165 | 175 | } elseif( 0 != $user->idForName() ) { |
166 | | - $wgOut->addWikiMsg('maintenance-userexists'); |
| 176 | + $wgOut->addWikiMsg( 'maintenance-userexists' ); |
167 | 177 | return; |
168 | 178 | } |
169 | 179 | $user->addToDatabase(); |
170 | 180 | $user->setPassword( $password ); |
171 | 181 | $user->saveSettings(); |
172 | | - $user->addGroup('sysop'); |
| 182 | + $user->addGroup( 'sysop'); |
173 | 183 | if( $bcrat ) |
174 | | - $user->addGroup('bureaucrat'); |
| 184 | + $user->addGroup( 'bureaucrat' ); |
175 | 185 | $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); |
176 | 186 | $ssu->doUpdate(); |
177 | 187 | $wgOut->addWikiMsg( 'maintenance-success', $type ); |
178 | 188 | break; |
179 | 189 | case 'deleteBatch': |
180 | | - $reason = $wgRequest->getText('wpReason', ''); |
| 190 | + $reason = $wgRequest->getText( 'wpReason', '' ); |
181 | 191 | $interval = 0; |
182 | | - $pages = $wgRequest->getText('wpDelete'); |
| 192 | + $pages = $wgRequest->getText( 'wpDelete' ); |
183 | 193 | $dbw = wfGetDB( DB_MASTER ); |
184 | 194 | $lines = explode( "\n", $pages ); |
185 | 195 | foreach( $lines as &$line ) { |
186 | | - $line = trim($line); |
| 196 | + $line = trim( $line ); |
187 | 197 | if( $line == '' ) |
188 | 198 | continue; |
189 | | - $page = Title::newFromText($line); |
| 199 | + $page = Title::newFromText( $line ); |
190 | 200 | if( is_null( $page ) ) { |
191 | 201 | $wgOut->addWikiMsg( 'maintenance-invalidtitle', $line ); |
192 | 202 | continue; |
— | — | @@ -215,17 +225,17 @@ |
216 | 226 | // ...and switch user back to the old user |
217 | 227 | $wgUser = $OldUser; |
218 | 228 | if ( $success ) { |
219 | | - $return .= '... ' . wfMsg('maintenance-deleted'); |
| 229 | + $return .= '... ' . wfMsg( 'maintenance-deleted' ); |
220 | 230 | } else { |
221 | | - $return .= '... ' . wfMsg('maintenance-failed'); |
| 231 | + $return .= '... ' . wfMsg( 'maintenance-failed' ); |
222 | 232 | } |
223 | | - $wgOut->addWikiText($return); |
| 233 | + $wgOut->addWikiText( $return ); |
224 | 234 | waitForSlaves( 5 ); |
225 | 235 | } |
226 | 236 | $wgOut->addWikiMsg( 'maintenance-success', $type ); |
227 | 237 | break; |
228 | 238 | case 'deleteRevision': |
229 | | - $delete = $wgRequest->getText('wpDelete'); |
| 239 | + $delete = $wgRequest->getText( 'wpDelete' ); |
230 | 240 | $revisions = explode( "\n", $delete ); |
231 | 241 | $wgOut->addWikiMsg( 'maintenance-revdelete', implode( ', ', $revisions ), wfWikiID() ); |
232 | 242 | $affected = 0; |
— | — | @@ -381,11 +391,9 @@ |
382 | 392 | break; |
383 | 393 | case 'runJobs': |
384 | 394 | $maxJobs = 10000; |
385 | | - $type = false; |
386 | 395 | $dbw = wfGetDB( DB_MASTER ); |
387 | 396 | $n = 0; |
388 | | - $conds = ''; |
389 | | - while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) { |
| 397 | + while ( $dbw->selectField( 'job', 'count(*)', '', 'runJobs.php' ) ) { |
390 | 398 | $offset = 0; |
391 | 399 | for (;;) { |
392 | 400 | $job = Job::pop($offset); |
— | — | @@ -506,7 +514,7 @@ |
507 | 515 | $wgOut->addWikiMsg( 'maintenance-success', $type ); |
508 | 516 | break; |
509 | 517 | default: |
510 | | - $wgOut->addHTML('<p>'.wfMsg('maintenance-invalidtype').'</p></form>'); |
| 518 | + $wgOut->addWikiMsg( 'maintenance-invalidtype' ); |
511 | 519 | return; |
512 | 520 | } |
513 | 521 | } |