r67944 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67943‎ | r67944 | r67945 >
Date:13:52, 13 June 2010
Author:ialex
Status:ok
Tags:
Comment:
Changes to Special:Lockdb and Special:Unlockdb:
* Subclass SpecialPage instead of using wfSpecial*() functions
* Now validate correctly when output is HTML5
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialLockdb.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUnlockdb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -580,6 +580,7 @@
581581 'SpecialExport' => 'includes/specials/SpecialExport.php',
582582 'SpecialImport' => 'includes/specials/SpecialImport.php',
583583 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php',
 584+ 'SpecialLockdb' => 'includes/specials/SpecialLockdb.php',
584585 'SpecialMergeHistory' => 'includes/specials/SpecialMergeHistory.php',
585586 'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php',
586587 'SpecialPreferences' => 'includes/specials/SpecialPreferences.php',
@@ -590,6 +591,7 @@
591592 'SpecialSearch' => 'includes/specials/SpecialSearch.php',
592593 'SpecialStatistics' => 'includes/specials/SpecialStatistics.php',
593594 'SpecialTags' => 'includes/specials/SpecialTags.php',
 595+ 'SpecialUnlockdb' => 'includes/specials/SpecialUnlockdb.php',
594596 'SpecialUpload' => 'includes/specials/SpecialUpload.php',
595597 'SpecialVersion' => 'includes/specials/SpecialVersion.php',
596598 'SpecialWhatlinkshere' => 'includes/specials/SpecialWhatlinkshere.php',
Index: trunk/phase3/includes/specials/SpecialLockdb.php
@@ -1,97 +1,87 @@
22 <?php
 3+
34 /**
4 - * @file
 5+ * A form to make the database readonly (eg for maintenance purposes).
 6+ *
57 * @ingroup SpecialPage
68 */
 9+class SpecialLockdb extends SpecialPage {
 10+ var $reason = '';
711
8 -/**
9 - * Constructor
10 - */
11 -function wfSpecialLockdb() {
12 - global $wgUser, $wgOut, $wgRequest;
13 -
14 - if( !$wgUser->isAllowed( 'siteadmin' ) ) {
15 - $wgOut->permissionRequired( 'siteadmin' );
16 - return;
 12+ public function __construct() {
 13+ parent::__construct( 'Lockdb', 'siteadmin' );
1714 }
1815
19 - # If the lock file isn't writable, we can do sweet bugger all
20 - global $wgReadOnlyFile;
21 - if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
22 - DBLockForm::notWritable();
23 - return;
24 - }
 16+ public function execute( $par ) {
 17+ global $wgUser, $wgOut, $wgRequest;
2518
26 - $action = $wgRequest->getVal( 'action' );
27 - $f = new DBLockForm();
 19+ $this->setHeaders();
2820
29 - if ( 'success' == $action ) {
30 - $f->showSuccess();
31 - } else if ( 'submit' == $action && $wgRequest->wasPosted() &&
32 - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
33 - $f->doSubmit();
34 - } else {
35 - $f->showForm( '' );
36 - }
37 -}
 21+ if( !$wgUser->isAllowed( 'siteadmin' ) ) {
 22+ $wgOut->permissionRequired( 'siteadmin' );
 23+ return;
 24+ }
3825
39 -/**
40 - * A form to make the database readonly (eg for maintenance purposes).
41 - * @ingroup SpecialPage
42 - */
43 -class DBLockForm {
44 - var $reason = '';
 26+ $this->outputHeader();
4527
46 - function DBLockForm() {
47 - global $wgRequest;
48 - $this->reason = $wgRequest->getText( 'wpLockReason' );
 28+ # If the lock file isn't writable, we can do sweet bugger all
 29+ global $wgReadOnlyFile;
 30+ if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
 31+ self::notWritable();
 32+ return;
 33+ }
 34+
 35+ $action = $wgRequest->getVal( 'action' );
 36+ $this->reason = $wgRequest->getVal( 'wpLockReason', '' );
 37+
 38+ if ( $action == 'success' ) {
 39+ $this->showSuccess();
 40+ } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
 41+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 42+ $this->doSubmit();
 43+ } else {
 44+ $this->showForm();
 45+ }
4946 }
5047
51 - function showForm( $err ) {
 48+ private function showForm( $err = '' ) {
5249 global $wgOut, $wgUser;
5350
54 - $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
5551 $wgOut->addWikiMsg( 'lockdbtext' );
5652
57 - if ( $err != "" ) {
 53+ if ( $err != '' ) {
5854 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
5955 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
6056 }
61 - $lc = htmlspecialchars( wfMsg( 'lockconfirm' ) );
62 - $lb = htmlspecialchars( wfMsg( 'lockbtn' ) );
63 - $elr = htmlspecialchars( wfMsg( 'enterlockreason' ) );
64 - $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
65 - $action = $titleObj->escapeLocalURL( 'action=submit' );
66 - $reason = htmlspecialchars( $this->reason );
67 - $token = htmlspecialchars( $wgUser->editToken() );
6857
69 - $wgOut->addHTML( <<<HTML
70 -<form id="lockdb" method="post" action="{$action}">
71 -{$elr}:
72 -<textarea name="wpLockReason" rows="10" cols="60" wrap="virtual">{$reason}</textarea>
73 -<table border="0">
 58+ $wgOut->addHTML(
 59+ Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
 60+ 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
 61+ wfMsgHtml( 'enterlockreason' ) . ":\n" .
 62+ Html::textarea( 'wpLockReason', $this->reason, array( 'rows' => 4 ) ). "
 63+<table>
7464 <tr>
75 - <td align="right">
76 - <input type="checkbox" name="wpLockConfirm" />
 65+ " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
 66+ " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
7767 </td>
78 - <td align="left">{$lc}</td>
 68+ " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
 69+ wfMsgHtml( 'lockconfirm' ) . "</td>
7970 </tr>
8071 <tr>
8172 <td>&#160;</td>
82 - <td align="left">
83 - <input type="submit" name="wpLock" value="{$lb}" />
 73+ " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
 74+ " . Html::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
8475 </td>
8576 </tr>
86 -</table>
87 -<input type="hidden" name="wpEditToken" value="{$token}" />
88 -</form>
89 -HTML
90 -);
 77+</table>\n" .
 78+ Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
 79+ Html::closeElement( 'form' )
 80+ );
9181
9282 }
9383
94 - function doSubmit() {
95 - global $wgOut, $wgUser, $wgLang, $wgRequest;
 84+ private function doSubmit() {
 85+ global $wgOut, $wgUser, $wgContLang, $wgRequest;
9686 global $wgReadOnlyFile;
9787
9888 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
@@ -109,14 +99,13 @@
110100 }
111101 fwrite( $fp, $this->reason );
112102 fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
113 - $wgLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
 103+ $wgContLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
114104 fclose( $fp );
115105
116 - $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
117 - $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) );
 106+ $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
118107 }
119108
120 - function showSuccess() {
 109+ private function showSuccess() {
121110 global $wgOut;
122111
123112 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
Index: trunk/phase3/includes/specials/SpecialUnlockdb.php
@@ -1,39 +1,41 @@
22 <?php
3 -/**
4 - * @file
5 - * @ingroup SpecialPage
6 - */
73
84 /**
 5+ * Implements Special:Unlockdb
96 *
 7+ * @ingroup SpecialPage
108 */
11 -function wfSpecialUnlockdb() {
12 - global $wgUser, $wgOut, $wgRequest;
 9+class SpecialUnlockdb extends SpecialPage {
1310
14 - if( !$wgUser->isAllowed( 'siteadmin' ) ) {
15 - $wgOut->permissionRequired( 'siteadmin' );
16 - return;
 11+ public function __construct() {
 12+ parent::__construct( 'Unlockdb', 'siteadmin' );
1713 }
1814
19 - $action = $wgRequest->getVal( 'action' );
20 - $f = new DBUnlockForm();
 15+ public function execute( $par ) {
 16+ global $wgUser, $wgOut, $wgRequest;
2117
22 - if ( "success" == $action ) {
23 - $f->showSuccess();
24 - } else if ( "submit" == $action && $wgRequest->wasPosted() &&
25 - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
26 - $f->doSubmit();
27 - } else {
28 - $f->showForm( "" );
 18+ $this->setHeaders();
 19+
 20+ if( !$wgUser->isAllowed( 'siteadmin' ) ) {
 21+ $wgOut->permissionRequired( 'siteadmin' );
 22+ return;
 23+ }
 24+
 25+ $this->outputHeader();
 26+
 27+ $action = $wgRequest->getVal( 'action' );
 28+
 29+ if ( $action == 'success' ) {
 30+ $this->showSuccess();
 31+ } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
 32+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 33+ $this->doSubmit();
 34+ } else {
 35+ $this->showForm();
 36+ }
2937 }
30 -}
3138
32 -/**
33 - * @ingroup SpecialPage
34 - */
35 -class DBUnlockForm {
36 - function showForm( $err )
37 - {
 39+ private function showForm( $err = '' ) {
3840 global $wgOut, $wgUser;
3941
4042 global $wgReadOnlyFile;
@@ -42,65 +44,57 @@
4345 return;
4446 }
4547
46 - $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
47 - $wgOut->addWikiMsg( "unlockdbtext" );
 48+ $wgOut->addWikiMsg( 'unlockdbtext' );
4849
49 - if ( $err != "" ) {
50 - $wgOut->setSubtitle( wfMsg( "formerror" ) );
 50+ if ( $err != '' ) {
 51+ $wgOut->setSubtitle( wfMsg( 'formerror' ) );
5152 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
5253 }
53 - $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
54 - $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
55 - $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
56 - $action = $titleObj->escapeLocalURL( "action=submit" );
57 - $token = htmlspecialchars( $wgUser->editToken() );
5854
59 - $wgOut->addHTML( <<<HTML
60 -
61 -<form id="unlockdb" method="post" action="{$action}">
62 -<table border="0">
 55+ $wgOut->addHTML(
 56+ Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
 57+ 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
 58+<table>
6359 <tr>
64 - <td align="right">
65 - <input type="checkbox" name="wpLockConfirm" />
 60+ " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
 61+ " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
6662 </td>
67 - <td align="left">{$lc}</td>
 63+ " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
 64+ wfMsgHtml( 'unlockconfirm' ) . "</td>
6865 </tr>
6966 <tr>
7067 <td>&#160;</td>
71 - <td align="left">
72 - <input type="submit" name="wpLock" value="{$lb}" />
 68+ " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
 69+ " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . "
7370 </td>
7471 </tr>
75 -</table>
76 -<input type="hidden" name="wpEditToken" value="{$token}" />
77 -</form>
78 -HTML
79 -);
 72+</table>\n" .
 73+ Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
 74+ Html::closeElement( 'form' )
 75+ );
8076
8177 }
8278
83 - function doSubmit() {
 79+ private function doSubmit() {
8480 global $wgOut, $wgRequest, $wgReadOnlyFile;
8581
8682 $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
87 - if ( ! $wpLockConfirm ) {
88 - $this->showForm( wfMsg( "locknoconfirm" ) );
 83+ if ( !$wpLockConfirm ) {
 84+ $this->showForm( wfMsg( 'locknoconfirm' ) );
8985 return;
9086 }
91 - if ( @! unlink( $wgReadOnlyFile ) ) {
 87+ if ( @!unlink( $wgReadOnlyFile ) ) {
9288 $wgOut->showFileDeleteError( $wgReadOnlyFile );
9389 return;
9490 }
95 - $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
96 - $success = $titleObj->getFullURL( "action=success" );
97 - $wgOut->redirect( $success );
 91+
 92+ $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
9893 }
9994
100 - function showSuccess() {
 95+ private function showSuccess() {
10196 global $wgOut;
10297
103 - $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
104 - $wgOut->setSubtitle( wfMsg( "unlockdbsuccesssub" ) );
105 - $wgOut->addWikiMsg( "unlockdbsuccesstext" );
 98+ $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
 99+ $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
106100 }
107101 }
Index: trunk/phase3/includes/SpecialPage.php
@@ -152,8 +152,8 @@
153153 'Statistics' => 'SpecialStatistics',
154154 'Allmessages' => 'SpecialAllmessages',
155155 'Version' => 'SpecialVersion',
156 - 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
157 - 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
 156+ 'Lockdb' => 'SpecialLockdb',
 157+ 'Unlockdb' => 'SpecialUnlockdb',
158158
159159 # Redirecting special pages
160160 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),

Status & tagging log