Index: trunk/extensions/CloseWikis/tables.sql |
— | — | @@ -1,8 +0,0 @@ |
2 | | - |
3 | | -CREATE TABLE /*$wgDBprefix*/closedwikis ( |
4 | | - cw_wiki varchar(255) NOT NULL, |
5 | | - cw_reason mediumblob NOT NULL, |
6 | | - |
7 | | - UNIQUE INDEX cw_wiki (cw_wiki) |
8 | | -) /*$wgDBTableOptions*/; |
Index: trunk/extensions/CloseWikis/CloseWikis.i18n.php |
— | — | @@ -12,7 +12,6 @@ |
13 | 13 | $messages['en'] = array( |
14 | 14 | 'closewikis-desc' => 'Allows to close wiki sites in wiki farms', |
15 | 15 | 'closewikis-closed' => '$1', |
16 | | - 'closewikis-closed-default' => 'This wiki is closed', |
17 | 16 | 'closewikis-page' => 'Close wiki', |
18 | 17 | |
19 | 18 | 'closewikis-page-close' => 'Close wiki', |
— | — | @@ -30,11 +29,19 @@ |
31 | 30 | 'closewikis-page-err-closed' => 'Wiki is already closed', |
32 | 31 | 'closewikis-page-err-opened' => 'Wiki is not closed', |
33 | 32 | |
| 33 | + 'closewikis-list' => 'Closed wikis list', |
| 34 | + 'closewikis-list-intro' => 'This list contains wikis which were closed by stewards.', |
| 35 | + 'closewikis-list-header-wiki' => 'Wiki', |
| 36 | + 'closewikis-list-header-by' => 'Closer', |
| 37 | + 'closewikis-list-header-timestamp' => 'Closure time', |
| 38 | + 'closewikis-list-header-dispreason' => 'Displayed reason', |
| 39 | + |
34 | 40 | 'closewikis-log' => 'Wikis closure log', |
35 | 41 | 'closewikis-log-header' => 'Here is a log of all wiki closures and reopenings made by stewards', |
36 | 42 | 'closewikis-log-close' => 'closed $2', |
37 | 43 | 'closewikis-log-reopen' => 'reopened $2', |
38 | 44 | 'right-editclosedwikis' => 'Edit closed wikis', |
| 45 | + 'right-closewikis' => 'Close wikis', |
39 | 46 | ); |
40 | 47 | |
41 | 48 | /** Message documentation (Message documentation) |
Index: trunk/extensions/CloseWikis/CloseWikis.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | $dir = dirname( __FILE__ ); |
36 | 36 | $wgExtensionMessagesFiles['CloseWikis'] = "$dir/CloseWikis.i18n.php"; |
37 | 37 | $wgExtensionAliasesFiles['CloseWikis'] = "$dir/CloseWikis.alias.php"; |
38 | | -$wgHooks['getUserPermissionsErrors'][] = "CloseWikis::userCan"; |
| 38 | +$wgHooks['getUserPermissionsErrors'][] = "CloseWikisHooks::userCan"; |
39 | 39 | |
40 | 40 | $wgGroupPermissions['steward']['closewikis'] = true; |
41 | 41 | $wgAvailableRights[] = 'closewikis'; |
— | — | @@ -42,7 +42,9 @@ |
43 | 43 | $wgAvailableRights[] = 'editclosedwikis'; |
44 | 44 | |
45 | 45 | $wgAutoloadClasses['SpecialCloseWiki'] = "$dir/CloseWikis.page.php"; |
| 46 | +$wgAutoloadClasses['SpecialListClosedWikis'] = "$dir/CloseWikis.list.php"; |
46 | 47 | $wgSpecialPages['CloseWiki'] = 'SpecialCloseWiki'; |
| 48 | +$wgSpecialPages['ListClosedWikis'] = 'SpecialListClosedWikis'; |
47 | 49 | |
48 | 50 | $wgCloseWikisDatabase = 'closedwikis'; |
49 | 51 | |
— | — | @@ -52,7 +54,37 @@ |
53 | 55 | $wgLogActions['closewiki/close'] = 'closewikis-log-close'; |
54 | 56 | $wgLogActions['closewiki/reopen'] = 'closewikis-log-reopen'; |
55 | 57 | |
| 58 | +class CloseWikisRow { |
| 59 | + private $mRow; |
| 60 | + |
| 61 | + public function __construct( $row ) { |
| 62 | + $this->mRow = $row; |
| 63 | + } |
| 64 | + |
| 65 | + public function isClosed() { |
| 66 | + return (bool)$this->mRow; |
| 67 | + } |
| 68 | + |
| 69 | + public function getWiki() { |
| 70 | + return $this->mRow ? $this->mRow->cw_wiki : null; |
| 71 | + } |
| 72 | + |
| 73 | + public function getReason() { |
| 74 | + return $this->mRow ? $this->mRow->cw_reason : null; |
| 75 | + } |
| 76 | + |
| 77 | + public function getTimestamp() { |
| 78 | + return $this->mRow ? wfTimestamp( TS_MW, $this->mRow->cw_timestamp ) : null; |
| 79 | + } |
| 80 | + |
| 81 | + public function getBy() { |
| 82 | + return $this->mRow ? $this->mRow->cw_by : null; |
| 83 | + } |
| 84 | +} |
| 85 | + |
56 | 86 | class CloseWikis { |
| 87 | + static $cachedList = null; |
| 88 | + |
57 | 89 | static function getSlaveDB() { |
58 | 90 | global $wgCloseWikisDatabase; |
59 | 91 | return wfGetDB( DB_SLAVE, 'closewikis', $wgCloseWikisDatabase ); |
— | — | @@ -63,35 +95,108 @@ |
64 | 96 | return wfGetDB( DB_MASTER, 'closewikis', $wgCloseWikisDatabase ); |
65 | 97 | } |
66 | 98 | |
67 | | - static function getList() { |
68 | | - global $wgMemc; |
69 | | - $cached = $wgMemc->get( 'closedwikis' ); |
70 | | - if( is_array( $cached ) ) |
71 | | - return $cached; |
| 99 | + /** Returns list of all closed wikis in form of CloseWikisRow array. Not cached */ |
| 100 | + static function getAll() { |
72 | 101 | $list = array(); |
73 | 102 | $dbr = self::getSlaveDB(); |
74 | 103 | $result = $dbr->select( 'closedwikis', '*', false, __METHOD__ ); |
75 | 104 | foreach( $result as $row ) { |
76 | | - $list[$row->cw_wiki] = $row->cw_reason; |
| 105 | + $list[] = new CloseWikisRow( $row ); |
77 | 106 | } |
78 | 107 | $dbr->freeResult( $result ); |
79 | | - $wgMemc->set( 'closedwikis', $list ); |
80 | 108 | return $list; |
81 | 109 | } |
82 | 110 | |
| 111 | + /** Returns list of closed wikis in form of string array. Cached in CloseWikis::$cachedList */ |
| 112 | + static function getList() { |
| 113 | + if( self::$cachedList ) |
| 114 | + return self::$cachedList; |
| 115 | + $list = array(); |
| 116 | + $dbr = self::getMasterDB(); // Used only on writes |
| 117 | + $result = $dbr->select( 'closedwikis', 'cw_wiki', false, __METHOD__ ); |
| 118 | + foreach( $result as $row ) { |
| 119 | + $list[] = $row->cw_wiki; |
| 120 | + } |
| 121 | + $dbr->freeResult( $result ); |
| 122 | + self::$cachedList = $list; |
| 123 | + return $list; |
| 124 | + } |
| 125 | + |
| 126 | + /** Returns list of unclosed wikis in form of string array. Based on getList() */ |
83 | 127 | static function getUnclosedList() { |
84 | 128 | global $wgLocalDatabases; |
85 | | - return array_diff( $wgLocalDatabases, array_keys( self::getList() ) ); |
| 129 | + return array_diff( $wgLocalDatabases, self::getList() ); |
86 | 130 | } |
87 | 131 | |
| 132 | + /** Returns a CloseWikisRow for specific wiki. Cached in $wgMemc */ |
| 133 | + static function getClosedRow( $wiki ) { |
| 134 | + global $wgMemc; |
| 135 | + $memcKey = "closedwikis:{$wiki}"; |
| 136 | + $cached = $wgMemc->get( $memcKey ); |
| 137 | + if( is_object( $cached ) ) |
| 138 | + return $cached; |
| 139 | + $dbr = self::getSlaveDB(); |
| 140 | + $result = new CloseWikisRow( $dbr->selectRow( 'closedwikis', '*', array( 'cw_wiki' => $wiki ), __METHOD__ ) ); |
| 141 | + $wgMemc->set( $memcKey, $result ); |
| 142 | + return $result; |
| 143 | + } |
| 144 | + |
| 145 | + /** Closes a wiki */ |
| 146 | + static function close( $wiki, $dispreason, $by ) { |
| 147 | + global $wgMemc; |
| 148 | + $dbw = CloseWikis::getMasterDB(); |
| 149 | + $dbw->begin(); |
| 150 | + $dbw->insert( |
| 151 | + 'closedwikis', |
| 152 | + array( |
| 153 | + 'cw_wiki' => $wiki, |
| 154 | + 'cw_reason' => $dispreason, |
| 155 | + 'cw_timestamp' => $dbw->timestamp( wfTimestampNow() ), |
| 156 | + 'cw_by' => $by->getName(), |
| 157 | + ), |
| 158 | + __METHOD__, |
| 159 | + array( 'IGNORE' ) // Better error handling |
| 160 | + ); |
| 161 | + $result = (bool)$dbw->affectedRows(); |
| 162 | + $dbw->commit(); |
| 163 | + $wgMemc->delete( "closedwikis:{$wiki}" ); |
| 164 | + self::$cachedList = null; |
| 165 | + return $result; |
| 166 | + } |
| 167 | + |
| 168 | + /** Reopens a wiki */ |
| 169 | + static function reopen( $wiki ) { |
| 170 | + global $wgMemc; |
| 171 | + $dbw = self::getMasterDB(); |
| 172 | + $dbw->begin(); |
| 173 | + $dbw->delete( |
| 174 | + 'closedwikis', |
| 175 | + array( 'cw_wiki' => $wiki ), |
| 176 | + __METHOD__ |
| 177 | + ); |
| 178 | + $result = (bool)$dbw->affectedRows(); |
| 179 | + $dbw->commit(); |
| 180 | + $wgMemc->delete( "closedwikis:{$wiki}" ); |
| 181 | + self::$cachedList = null; |
| 182 | + return $result; |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +class CloseWikisHooks { |
88 | 187 | static function userCan( &$title, &$user, $action, &$result ) { |
89 | | - $list = self::getList(); |
90 | | - if( isset( $list[wfWikiID()] ) && !$user->isAllowed( 'editclosedwikis' ) ) { |
| 188 | + static $closed = null; |
| 189 | + global $wgLang; |
| 190 | + if( $action == 'read' ) |
| 191 | + return true; |
| 192 | + if( is_null( $closed ) ) |
| 193 | + $closed = CloseWikis::getClosedRow( wfWikiID() ); |
| 194 | + if( $closed->isClosed() && !$user->isAllowed( 'editclosedwikis' ) ) { |
91 | 195 | wfLoadExtensionMessages( 'CloseWikis' ); |
92 | | - $reason = $list[wfWikiID()]; |
93 | | - $result[] = $reason ? |
94 | | - array( 'closewikis-closed', $reason ) : |
95 | | - array( 'closewikis-closed-default' ); |
| 196 | + $reason = $closed->getReason(); |
| 197 | + $ts = $closed->getTimestamp(); |
| 198 | + $by = $closed->getBy(); |
| 199 | + $result[] = array( 'closewikis-closed', $reason, $by, |
| 200 | + $wgLang->timeanddate( $ts ), $wgLang->time( $ts ), $wgLang->date( $ts ) ); |
96 | 201 | return false; |
97 | 202 | } |
98 | 203 | return true; |
Index: trunk/extensions/CloseWikis/closewikis.sql |
— | — | @@ -0,0 +1,10 @@ |
| 2 | +-- Tables for CloseWikis extension |
| 3 | + |
| 4 | +CREATE TABLE /*$wgDBprefix*/closedwikis ( |
| 5 | + cw_wiki varchar(255) NOT NULL, |
| 6 | + cw_reason mediumblob NOT NULL, |
| 7 | + cw_timestamp binary(14) NOT NULL, |
| 8 | + cw_by tinyblob NOT NULL, |
| 9 | + |
| 10 | + UNIQUE INDEX cw_wiki (cw_wiki) |
| 11 | +) /*$wgDBTableOptions*/; |
Property changes on: trunk/extensions/CloseWikis/closewikis.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 12 | + native |
Index: trunk/extensions/CloseWikis/CloseWikis.list.php |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * Copyright (C) 2008 Victor Vasiliev <vasilvv@gmail.com> |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 | + * MA 02110-1301, USA. |
| 20 | + */ |
| 21 | + |
| 22 | +if( !defined( 'MEDIAWIKI' ) ) |
| 23 | + exit; |
| 24 | + |
| 25 | +class SpecialListClosedWikis extends SpecialPage { |
| 26 | + public function __construct() { |
| 27 | + wfLoadExtensionMessages( 'CloseWikis' ); |
| 28 | + parent::__construct( 'ListClosedWikis' ); |
| 29 | + } |
| 30 | + |
| 31 | + public function getDescription() { |
| 32 | + return wfMsg( 'closewikis-list' ); |
| 33 | + } |
| 34 | + |
| 35 | + public function execute( $par ) { |
| 36 | + global $wgUser, $wgOut, $wgLang; |
| 37 | + |
| 38 | + $this->setHeaders(); |
| 39 | + $wgOut->addWikiMsg( 'closewikis-list-intro' ); |
| 40 | + $wgOut->addHtml( '<table class="TablePager" style="width: 100%"><tr>' ); |
| 41 | + foreach( array( 'wiki', 'by', 'timestamp', 'dispreason' ) as $column ) |
| 42 | + $wgOut->addHtml( '<th>' . wfMsgExt( "closewikis-list-header-{$column}", 'parseinline' ) . '</th>' ); |
| 43 | + $wgOut->addHtml( '</tr>' ); |
| 44 | + $list = CloseWikis::getAll(); |
| 45 | + foreach( $list as $entry ) { |
| 46 | + $wgOut->addHTML( '<tr>' ); |
| 47 | + $wgOut->addHTML( '<td>' . $entry->getWiki() . '</td>' ); |
| 48 | + $wgOut->addHTML( '<td>' . $entry->getBy() . '</td>' ); |
| 49 | + $wgOut->addHTML( '<td>' . $wgLang->timeanddate( $entry->getTimestamp() ) . '</td>' ); |
| 50 | + $wgOut->addHTML( '<td>' ); $wgOut->addWikiText( $entry->getReason() ); $wgOut->addHTML( '</td>' ); |
| 51 | + $wgOut->addHTML( '</tr>' ); |
| 52 | + } |
| 53 | + $wgOut->addHtml( '</table>' ); |
| 54 | + } |
| 55 | +} |
Property changes on: trunk/extensions/CloseWikis/CloseWikis.list.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 56 | + native |
Index: trunk/extensions/CloseWikis/CloseWikis.page.php |
— | — | @@ -41,7 +41,8 @@ |
42 | 42 | } |
43 | 43 | |
44 | 44 | $this->closeForm(); |
45 | | - $this->reopenForm(); |
| 45 | + if( CloseWikis::getList() ) |
| 46 | + $this->reopenForm(); |
46 | 47 | } |
47 | 48 | |
48 | 49 | protected function buildSelect( $list, $name, $default = '' ) { |
— | — | @@ -66,7 +67,7 @@ |
67 | 68 | if( !in_array( $wiki, $wgLocalDatabases ) ) { |
68 | 69 | $status = wfMsgExt( 'closewikis-page-err-nowiki', 'parseinline' ); |
69 | 70 | } else { |
70 | | - $statusOK = $this->doClose( $wiki, $dreason ); |
| 71 | + $statusOK = CloseWikis::close( $wiki, $dreason, $wgUser ); |
71 | 72 | if( $statusOK ) { |
72 | 73 | $status = wfMsgExt( 'closewikis-page-close-success', 'parseinline' ); |
73 | 74 | $logpage = new LogPage( 'closewiki' ); |
— | — | @@ -92,7 +93,7 @@ |
93 | 94 | $statusStyle = $statusOK ? 'success' : 'error'; |
94 | 95 | $wgOut->addHTML( "<p><strong class=\"{$statusStyle}\">{$status}</strong></p>" ); |
95 | 96 | } |
96 | | - $wgOut->addHTML( '<form method="post" action="' . $wgTitle->getLocalURL() . '">' ); |
| 97 | + $wgOut->addHTML( '<form method="post" action="' . htmlspecialchars( $wgTitle->getLocalURL() ) . '">' ); |
97 | 98 | $form = array(); |
98 | 99 | $form['closewikis-page-close-wiki'] = $this->buildSelect( CloseWikis::getUnclosedList(), 'wpcWiki', $defaultWiki ); |
99 | 100 | $form['closewikis-page-close-dreason'] = Xml::textarea( 'wpcDisplayReason', $defaultDisplayReason ); |
— | — | @@ -102,25 +103,6 @@ |
103 | 104 | $wgOut->addHTML( "</form></fieldset>" ); |
104 | 105 | } |
105 | 106 | |
106 | | - public function doClose( $wiki, $dispreason ) { |
107 | | - global $wgMemc; |
108 | | - $dbw = CloseWikis::getMasterDB(); |
109 | | - $dbw->begin(); |
110 | | - $dbw->insert( |
111 | | - 'closedwikis', |
112 | | - array( |
113 | | - 'cw_wiki' => $wiki, |
114 | | - 'cw_reason' => $dispreason, |
115 | | - ), |
116 | | - __METHOD__, |
117 | | - array( 'IGNORE' ) // Better error handling |
118 | | - ); |
119 | | - $result = (bool)$dbw->affectedRows(); |
120 | | - $dbw->commit(); |
121 | | - $wgMemc->delete( 'closedwikis' ); |
122 | | - return $result; |
123 | | - } |
124 | | - |
125 | 107 | protected function reopenForm() { |
126 | 108 | global $wgOut, $wgUser, $wgRequest, $wgTitle; |
127 | 109 | |
— | — | @@ -133,7 +115,7 @@ |
134 | 116 | if( !in_array( $wiki, $wgLocalDatabases ) ) { |
135 | 117 | $status = wfMsgExt( 'closewikis-page-err-nowiki', 'parseinline' ); |
136 | 118 | } else { |
137 | | - $statusOK = $this->doReopen( $wiki ); |
| 119 | + $statusOK = CloseWikis::reopen( $wiki ); |
138 | 120 | if( $statusOK ) { |
139 | 121 | $status = wfMsgExt( 'closewikis-page-reopen-success', 'parseinline' ); |
140 | 122 | $logpage = new LogPage( 'closewiki' ); |
— | — | @@ -155,27 +137,14 @@ |
156 | 138 | $statusStyle = $statusOK ? 'success' : 'error'; |
157 | 139 | $wgOut->addHTML( "<p><strong class=\"{$statusStyle}\">{$status}</strong></p>" ); |
158 | 140 | } |
159 | | - $wgOut->addHTML( '<form method="post" action="' . $wgTitle->getLocalURL() . '">' ); |
| 141 | + $wgOut->addHTML( '<form method="post" action="' . htmlspecialchars( $wgTitle->getLocalURL() ) . '">' ); |
160 | 142 | $form = array(); |
161 | | - $form['closewikis-page-reopen-wiki'] = $this->buildSelect( array_keys( CloseWikis::getList() ), 'wprWiki', $defaultWiki ); |
| 143 | + $form['closewikis-page-reopen-wiki'] = $this->buildSelect( CloseWikis::getList(), 'wprWiki', $defaultWiki ); |
162 | 144 | $form['closewikis-page-reopen-reason'] = Xml::input( 'wprReason', false, $defaultReason ); |
163 | 145 | $wgOut->addHTML( Xml::buildForm( $form, 'closewikis-page-reopen-submit' ) ); |
164 | 146 | $wgOut->addHTML( Xml::hidden( 'wprEdittoken', $wgUser->editToken() ) ); |
165 | 147 | $wgOut->addHTML( "</form></fieldset>" ); |
166 | 148 | } |
167 | 149 | |
168 | | - public function doReopen( $wiki ) { |
169 | | - global $wgMemc; |
170 | | - $dbw = CloseWikis::getMasterDB(); |
171 | | - $dbw->begin(); |
172 | | - $dbw->delete( |
173 | | - 'closedwikis', |
174 | | - array( 'cw_wiki' => $wiki ), |
175 | | - __METHOD__ |
176 | | - ); |
177 | | - $result = (bool)$dbw->affectedRows(); |
178 | | - $dbw->commit(); |
179 | | - $wgMemc->delete( 'closedwikis' ); |
180 | | - return $result; |
181 | | - } |
| 150 | + |
182 | 151 | } |