SpecialUnlockdb.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. *
  8. */
  9. function wfSpecialUnlockdb() {
  10. global $wgUser, $wgOut, $wgRequest;
  11. if( !$wgUser->isAllowed( 'siteadmin' ) ) {
  12. $wgOut->permissionRequired( 'siteadmin' );
  13. return;
  14. }
  15. $action = $wgRequest->getVal( 'action' );
  16. $f = new DBUnlockForm();
  17. if ( "success" == $action ) {
  18. $f->showSuccess();
  19. } else if ( "submit" == $action && $wgRequest->wasPosted() &&
  20. $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
  21. $f->doSubmit();
  22. } else {
  23. $f->showForm( "" );
  24. }
  25. }
  26. /**
  27. * @ingroup SpecialPage
  28. */
  29. class DBUnlockForm {
  30. function showForm( $err )
  31. {
  32. global $wgOut, $wgUser;
  33. global $wgReadOnlyFile;
  34. if( !file_exists( $wgReadOnlyFile ) ) {
  35. $wgOut->addWikiMsg( 'databasenotlocked' );
  36. return;
  37. }
  38. $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
  39. $wgOut->addWikiMsg( "unlockdbtext" );
  40. if ( "" != $err ) {
  41. $wgOut->setSubtitle( wfMsg( "formerror" ) );
  42. $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
  43. }
  44. $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
  45. $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
  46. $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
  47. $action = $titleObj->escapeLocalURL( "action=submit" );
  48. $token = htmlspecialchars( $wgUser->editToken() );
  49. $wgOut->addHTML( <<<END
  50. <form id="unlockdb" method="post" action="{$action}">
  51. <table border="0">
  52. <tr>
  53. <td align="right">
  54. <input type="checkbox" name="wpLockConfirm" />
  55. </td>
  56. <td align="left">{$lc}</td>
  57. </tr>
  58. <tr>
  59. <td>&nbsp;</td>
  60. <td align="left">
  61. <input type="submit" name="wpLock" value="{$lb}" />
  62. </td>
  63. </tr>
  64. </table>
  65. <input type="hidden" name="wpEditToken" value="{$token}" />
  66. </form>
  67. END
  68. );
  69. }
  70. function doSubmit() {
  71. global $wgOut, $wgRequest, $wgReadOnlyFile;
  72. $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
  73. if ( ! $wpLockConfirm ) {
  74. $this->showForm( wfMsg( "locknoconfirm" ) );
  75. return;
  76. }
  77. if ( @! unlink( $wgReadOnlyFile ) ) {
  78. $wgOut->showFileDeleteError( $wgReadOnlyFile );
  79. return;
  80. }
  81. $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
  82. $success = $titleObj->getFullURL( "action=success" );
  83. $wgOut->redirect( $success );
  84. }
  85. function showSuccess() {
  86. global $wgOut;
  87. $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
  88. $wgOut->setSubtitle( wfMsg( "unlockdbsuccesssub" ) );
  89. $wgOut->addWikiMsg( "unlockdbsuccesstext" );
  90. }
  91. }