From: Alexandre Emsenhuber
Date: Sun, 13 Jun 2010 13:52:20 +0000 (+0000)
Subject: Changes to Special:Lockdb and Special:Unlockdb:
X-Git-Tag: 1.31.0-rc.0~36521
X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=commitdiff_plain;h=2f0c3efd0929053001240bb1a59fb2a36701d563;p=lhc%2Fweb%2Fwiklou.git
Changes to Special:Lockdb and Special:Unlockdb:
* Subclass SpecialPage instead of using wfSpecial*() functions
* Now validate correctly when output is HTML5
---
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index ac03524013..bb631714bb 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -580,6 +580,7 @@ $wgAutoloadLocalClasses = array(
'SpecialExport' => 'includes/specials/SpecialExport.php',
'SpecialImport' => 'includes/specials/SpecialImport.php',
'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php',
+ 'SpecialLockdb' => 'includes/specials/SpecialLockdb.php',
'SpecialMergeHistory' => 'includes/specials/SpecialMergeHistory.php',
'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php',
'SpecialPreferences' => 'includes/specials/SpecialPreferences.php',
@@ -590,6 +591,7 @@ $wgAutoloadLocalClasses = array(
'SpecialSearch' => 'includes/specials/SpecialSearch.php',
'SpecialStatistics' => 'includes/specials/SpecialStatistics.php',
'SpecialTags' => 'includes/specials/SpecialTags.php',
+ 'SpecialUnlockdb' => 'includes/specials/SpecialUnlockdb.php',
'SpecialUpload' => 'includes/specials/SpecialUpload.php',
'SpecialVersion' => 'includes/specials/SpecialVersion.php',
'SpecialWhatlinkshere' => 'includes/specials/SpecialWhatlinkshere.php',
diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php
index c452b17eec..3c3cc6c592 100644
--- a/includes/SpecialPage.php
+++ b/includes/SpecialPage.php
@@ -152,8 +152,8 @@ class SpecialPage {
'Statistics' => 'SpecialStatistics',
'Allmessages' => 'SpecialAllmessages',
'Version' => 'SpecialVersion',
- 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
- 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
+ 'Lockdb' => 'SpecialLockdb',
+ 'Unlockdb' => 'SpecialUnlockdb',
# Redirecting special pages
'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
diff --git a/includes/specials/SpecialLockdb.php b/includes/specials/SpecialLockdb.php
index 6edd4caa45..cd4482f513 100644
--- a/includes/specials/SpecialLockdb.php
+++ b/includes/specials/SpecialLockdb.php
@@ -1,97 +1,87 @@
isAllowed( 'siteadmin' ) ) {
- $wgOut->permissionRequired( 'siteadmin' );
- return;
+ public function __construct() {
+ parent::__construct( 'Lockdb', 'siteadmin' );
}
- # If the lock file isn't writable, we can do sweet bugger all
- global $wgReadOnlyFile;
- if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
- DBLockForm::notWritable();
- return;
- }
+ public function execute( $par ) {
+ global $wgUser, $wgOut, $wgRequest;
- $action = $wgRequest->getVal( 'action' );
- $f = new DBLockForm();
+ $this->setHeaders();
- if ( 'success' == $action ) {
- $f->showSuccess();
- } else if ( 'submit' == $action && $wgRequest->wasPosted() &&
- $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
- $f->doSubmit();
- } else {
- $f->showForm( '' );
- }
-}
+ if( !$wgUser->isAllowed( 'siteadmin' ) ) {
+ $wgOut->permissionRequired( 'siteadmin' );
+ return;
+ }
-/**
- * A form to make the database readonly (eg for maintenance purposes).
- * @ingroup SpecialPage
- */
-class DBLockForm {
- var $reason = '';
+ $this->outputHeader();
+
+ # If the lock file isn't writable, we can do sweet bugger all
+ global $wgReadOnlyFile;
+ if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
+ self::notWritable();
+ return;
+ }
+
+ $action = $wgRequest->getVal( 'action' );
+ $this->reason = $wgRequest->getVal( 'wpLockReason', '' );
- function DBLockForm() {
- global $wgRequest;
- $this->reason = $wgRequest->getText( 'wpLockReason' );
+ if ( $action == 'success' ) {
+ $this->showSuccess();
+ } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+ $this->doSubmit();
+ } else {
+ $this->showForm();
+ }
}
- function showForm( $err ) {
+ private function showForm( $err = '' ) {
global $wgOut, $wgUser;
- $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
$wgOut->addWikiMsg( 'lockdbtext' );
- if ( $err != "" ) {
+ if ( $err != '' ) {
$wgOut->setSubtitle( wfMsg( 'formerror' ) );
$wgOut->addHTML( '' . htmlspecialchars( $err ) . "
\n" );
}
- $lc = htmlspecialchars( wfMsg( 'lockconfirm' ) );
- $lb = htmlspecialchars( wfMsg( 'lockbtn' ) );
- $elr = htmlspecialchars( wfMsg( 'enterlockreason' ) );
- $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
- $action = $titleObj->escapeLocalURL( 'action=submit' );
- $reason = htmlspecialchars( $this->reason );
- $token = htmlspecialchars( $wgUser->editToken() );
-
- $wgOut->addHTML( <<
-{$elr}:
-
-
+
+ $wgOut->addHTML(
+ Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
+ 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
+ wfMsgHtml( 'enterlockreason' ) . ":\n" .
+ Html::textarea( 'wpLockReason', $this->reason, array( 'rows' => 4 ) ). "
+
-
-
-HTML
-);
+
\n" .
+ Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
+ Html::closeElement( 'form' )
+ );
}
- function doSubmit() {
- global $wgOut, $wgUser, $wgLang, $wgRequest;
+ private function doSubmit() {
+ global $wgOut, $wgUser, $wgContLang, $wgRequest;
global $wgReadOnlyFile;
if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
@@ -109,14 +99,13 @@ HTML
}
fwrite( $fp, $this->reason );
fwrite( $fp, "\n(by " . $wgUser->getName() . " at " .
- $wgLang->timeanddate( wfTimestampNow() ) . ")
\n" );
+ $wgContLang->timeanddate( wfTimestampNow() ) . ")
\n" );
fclose( $fp );
- $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
- $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) );
+ $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
}
- function showSuccess() {
+ private function showSuccess() {
global $wgOut;
$wgOut->setPagetitle( wfMsg( 'lockdb' ) );
diff --git a/includes/specials/SpecialUnlockdb.php b/includes/specials/SpecialUnlockdb.php
index 0c52ff6ed7..9fd76a9374 100644
--- a/includes/specials/SpecialUnlockdb.php
+++ b/includes/specials/SpecialUnlockdb.php
@@ -1,39 +1,41 @@
isAllowed( 'siteadmin' ) ) {
- $wgOut->permissionRequired( 'siteadmin' );
- return;
+ public function __construct() {
+ parent::__construct( 'Unlockdb', 'siteadmin' );
}
- $action = $wgRequest->getVal( 'action' );
- $f = new DBUnlockForm();
+ public function execute( $par ) {
+ global $wgUser, $wgOut, $wgRequest;
+
+ $this->setHeaders();
+
+ if( !$wgUser->isAllowed( 'siteadmin' ) ) {
+ $wgOut->permissionRequired( 'siteadmin' );
+ return;
+ }
+
+ $this->outputHeader();
- if ( "success" == $action ) {
- $f->showSuccess();
- } else if ( "submit" == $action && $wgRequest->wasPosted() &&
- $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
- $f->doSubmit();
- } else {
- $f->showForm( "" );
+ $action = $wgRequest->getVal( 'action' );
+
+ if ( $action == 'success' ) {
+ $this->showSuccess();
+ } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+ $this->doSubmit();
+ } else {
+ $this->showForm();
+ }
}
-}
-/**
- * @ingroup SpecialPage
- */
-class DBUnlockForm {
- function showForm( $err )
- {
+ private function showForm( $err = '' ) {
global $wgOut, $wgUser;
global $wgReadOnlyFile;
@@ -42,65 +44,57 @@ class DBUnlockForm {
return;
}
- $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
- $wgOut->addWikiMsg( "unlockdbtext" );
+ $wgOut->addWikiMsg( 'unlockdbtext' );
- if ( $err != "" ) {
- $wgOut->setSubtitle( wfMsg( "formerror" ) );
+ if ( $err != '' ) {
+ $wgOut->setSubtitle( wfMsg( 'formerror' ) );
$wgOut->addHTML( '' . htmlspecialchars( $err ) . "
\n" );
}
- $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
- $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
- $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
- $action = $titleObj->escapeLocalURL( "action=submit" );
- $token = htmlspecialchars( $wgUser->editToken() );
- $wgOut->addHTML( <<
-
+ $wgOut->addHTML(
+ Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
+ 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
+
-
-
-HTML
-);
+
\n" .
+ Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
+ Html::closeElement( 'form' )
+ );
}
- function doSubmit() {
+ private function doSubmit() {
global $wgOut, $wgRequest, $wgReadOnlyFile;
$wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
- if ( ! $wpLockConfirm ) {
- $this->showForm( wfMsg( "locknoconfirm" ) );
+ if ( !$wpLockConfirm ) {
+ $this->showForm( wfMsg( 'locknoconfirm' ) );
return;
}
- if ( @! unlink( $wgReadOnlyFile ) ) {
+ if ( @!unlink( $wgReadOnlyFile ) ) {
$wgOut->showFileDeleteError( $wgReadOnlyFile );
return;
}
- $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
- $success = $titleObj->getFullURL( "action=success" );
- $wgOut->redirect( $success );
+
+ $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
}
- function showSuccess() {
+ private function showSuccess() {
global $wgOut;
- $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
- $wgOut->setSubtitle( wfMsg( "unlockdbsuccesssub" ) );
- $wgOut->addWikiMsg( "unlockdbsuccesstext" );
+ $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
+ $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
}
}