Index: trunk/extensions/CentralAuth/SpecialEditWikiSets.php |
— | — | @@ -1,219 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Special page to allow managing global groups |
5 | | - * Prototype for a similar system in core. |
6 | | - * |
7 | | - * @addtogroup Extensions |
8 | | - */ |
9 | | - |
10 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
11 | | - echo "CentralAuth extension\n"; |
12 | | - exit( 1 ); |
13 | | -} |
14 | | - |
15 | | - |
16 | | -class SpecialEditWikiSets extends SpecialPage |
17 | | -{ |
18 | | - function __construct() { |
19 | | - parent::__construct('EditWikiSets', 'globalgrouppermissions'); |
20 | | - wfLoadExtensionMessages('SpecialCentralAuth'); |
21 | | - } |
22 | | - |
23 | | - function getDescription() { |
24 | | - return wfMsg( 'centralauth-editset' ); |
25 | | - } |
26 | | - |
27 | | - function userCanExecute($user) { |
28 | | - global $wgUser; |
29 | | - return $wgUser->isAllowed( 'globalgrouppermissions' ); |
30 | | - $globalUser = CentralAuthUser::getInstance( $user ); |
31 | | - |
32 | | - ## Should be a global user |
33 | | - if (!$globalUser->exists() || !$globalUser->isAttached()) { |
34 | | - return false; |
35 | | - } |
36 | | - |
37 | | - ## Permission MUST be gained from global rights. |
38 | | - return $globalUser->hasGlobalPermission( 'globalgrouppermissions' ); |
39 | | - } |
40 | | - |
41 | | - function execute( $subpage ) { |
42 | | - global $wgRequest, $wgOut, $wgUser; |
43 | | - |
44 | | - if( !$this->userCanExecute( $wgUser ) ) { |
45 | | - $this->displayRestrictionError(); |
46 | | - return; |
47 | | - } |
48 | | - |
49 | | - $this->setHeaders(); |
50 | | - |
51 | | - if( $subpage && !is_numeric( $subpage ) ) { |
52 | | - $set = WikiSet::newFromName( $subpage ); |
53 | | - if( $set ) { |
54 | | - $subpage = $set->getID(); |
55 | | - } else { |
56 | | - $wgOut->setPageTitle( wfMsg( 'error' ) ); |
57 | | - $error = wfMsgExt( 'centralauth-editset-notfound', array( 'escapenoentities' ), $subpage ); |
58 | | - $this->buildMainView( "<strong class='error'>{$error}</strong>" ); |
59 | | - return; |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - if( ( $subpage || $subpage === '0' ) && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
64 | | - $this->doSubmit( $subpage ); |
65 | | - } else if( ( $subpage || $subpage === '0' ) && is_numeric( $subpage ) ) { |
66 | | - $this->buildSetView( $subpage ); |
67 | | - } else { |
68 | | - $this->buildMainView(); |
69 | | - } |
70 | | - } |
71 | | - |
72 | | - function buildMainView( $msg = '' ) { |
73 | | - global $wgOut, $wgScript, $wgUser; |
74 | | - $sk = $wgUser->getSkin(); |
75 | | - |
76 | | - $legend = wfMsg( 'centralauth-editset-legend' ); |
77 | | - $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" ); |
78 | | - if( $msg ) |
79 | | - $wgOut->addHTML( $msg ); |
80 | | - $wgOut->addWikiMsg( 'centralauth-editset-intro' ); |
81 | | - $wgOut->addHTML( '<ul>' ); |
82 | | - |
83 | | - $sets = WikiSet::getAllWikiSets(); |
84 | | - foreach( $sets as $set ) { |
85 | | - $text = wfMsgExt( 'centralauth-editset-item', array( 'parseinline' ), $set->getName(), $set->getID() ); |
86 | | - $wgOut->addHTML( "<li>{$text}</li>" ); |
87 | | - } |
88 | | - |
89 | | - $target = SpecialPage::getTitleFor( 'EditWikiSets', '0' ); |
90 | | - $newlink = $sk->makeLinkObj( $target, wfMsgHtml( 'centralauth-editset-new' ) ); |
91 | | - $wgOut->addHTML( "<li>{$newlink}</li>" ); |
92 | | - |
93 | | - $wgOut->addHTML( '</ul></fieldset>' ); |
94 | | - } |
95 | | - |
96 | | - function buildSetView( $subpage, $error = false, $name = null, $type = null, $wikis = null, $reason = null ) { |
97 | | - global $wgOut, $wgUser; |
98 | | - |
99 | | - $set = $subpage ? WikiSet::newFromID( $subpage ) : null; |
100 | | - if( !$name ) $name = $set ? $set->getName() : ''; |
101 | | - if( !$type ) $type = $set ? $set->getType() : WikiSet::OPTIN; |
102 | | - if( !$wikis ) $wikis = implode( "\n", $set ? $set->getWikisRaw() : array() ); |
103 | | - else $wikis = implode( "\n", $wikis ); |
104 | | - $url = SpecialPage::getTitleFor( 'EditWikiSets', $subpage )->getLocalUrl(); |
105 | | - $legend = wfMsgHtml( 'centralauth-editset-legend-' . ($set ? 'edit' : 'new'), $name ); |
106 | | - |
107 | | - $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" ); |
108 | | - if( $error ) |
109 | | - $wgOut->addHTML( "<strong class='error'>{$error}</strong>" ); |
110 | | - $wgOut->addHTML( "<form action='{$url}' method='post'>" ); |
111 | | - |
112 | | - if( $set ) { |
113 | | - $groups = $set->getRestrictedGroups(); |
114 | | - if ( $groups ) { |
115 | | - $usage = "<ul>\n"; |
116 | | - foreach( $groups as $group ) |
117 | | - $usage .= "<li>" . wfMsgExt( 'centralauth-editset-grouplink', array('parseinline'), $group ) . "</li>\n"; |
118 | | - $usage .= "</ul>"; |
119 | | - } else { |
120 | | - $usage = wfMsgWikiHtml('centralauth-editset-nouse'); |
121 | | - } |
122 | | - } else { |
123 | | - $usage = ''; |
124 | | - } |
125 | | - |
126 | | - $form = array(); |
127 | | - $form['centralauth-editset-name'] = Xml::input( 'wpName', false, $name ); |
128 | | - if( $usage ) |
129 | | - $form['centralauth-editset-usage'] = $usage; |
130 | | - $form['centralauth-editset-type'] = $this->buildTypeSelector( 'wpType', $type ); |
131 | | - $form['centralauth-editset-wikis'] = Xml::textarea( 'wpWikis', $wikis ); |
132 | | - $form['centralauth-editset-reason'] = Xml::input( 'wpReason', false, $reason ); |
133 | | - |
134 | | - $wgOut->addHTML( Xml::buildForm( $form, 'centralauth-editset-submit' ) ); |
135 | | - |
136 | | - $edittoken = Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
137 | | - $wgOut->addHTML( "<p>{$edittoken}</p></form></fieldset>" ); |
138 | | - } |
139 | | - |
140 | | - function buildTypeSelector( $name, $value ) { |
141 | | - $select = new XmlSelect( $name, 'set-type', $value ); |
142 | | - foreach( array( WikiSet::OPTIN, WikiSet::OPTOUT ) as $type ) |
143 | | - $select->addOption( wfMsg( "centralauth-editset-{$type}" ), $type ); |
144 | | - return $select->getHTML(); |
145 | | - } |
146 | | - |
147 | | - function doSubmit( $id ) { |
148 | | - global $wgRequest, $wgContLang; |
149 | | - |
150 | | - $name = $wgContLang->ucfirst( $wgRequest->getVal( 'wpName' ) ); |
151 | | - $type = $wgRequest->getVal( 'wpType' ); |
152 | | - $wikis = array_unique( preg_split( '/(\s+|\s*\W\s*)/', $wgRequest->getVal( 'wpWikis' ), -1, PREG_SPLIT_NO_EMPTY ) ); |
153 | | - $reason = $wgRequest->getVal( 'wpReason' ); |
154 | | - $set = WikiSet::newFromId( $id ); |
155 | | - |
156 | | - if( !Title::newFromText( $name ) ) { |
157 | | - $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-badname' ), $name, $type, $wikis, $reason ); |
158 | | - return; |
159 | | - } |
160 | | - if( (!$id || $set->getName() != $name ) && WikiSet::newFromName( $name ) ) { |
161 | | - $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-setexists' ), $name, $type, $wikis, $reason ); |
162 | | - return; |
163 | | - } |
164 | | - if( !in_array( $type, array( WikiSet::OPTIN, WikiSet::OPTOUT ) ) ) { |
165 | | - $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-badtype' ), $name, $type, $wikis, $reason ); |
166 | | - return; |
167 | | - } |
168 | | - if( !$wikis ) { |
169 | | - $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-nowikis' ), $name, $type, $wikis, $reason ); |
170 | | - return; |
171 | | - } |
172 | | - $badwikis = array(); |
173 | | - $allwikis = CentralAuthUser::getWikiList(); |
174 | | - foreach( $wikis as $wiki ) |
175 | | - if( !in_array( $wiki, $allwikis ) ) |
176 | | - $badwikis[] = $wiki; |
177 | | - if( $badwikis ) { |
178 | | - $this->buildSetView( $id, wfMsgExt( 'centralauth-editset-badwikis', array( 'escapenoentities', 'parsemag' ), |
179 | | - implode( ', ', $badwikis ), count( $badwikis ) ), $name, $type, $wikis, $reason ); |
180 | | - return; |
181 | | - } |
182 | | - |
183 | | - if( $set ) { |
184 | | - $oldname = $set->getName(); |
185 | | - $oldtype = $set->getType(); |
186 | | - $oldwikis = $set->getWikisRaw(); |
187 | | - } else { |
188 | | - $set = new WikiSet(); |
189 | | - $oldname = $oldtype = null; $oldwikis = array(); |
190 | | - } |
191 | | - $set->setName( $name ); |
192 | | - $set->setType( $type ); |
193 | | - $set->setWikisRaw( $wikis ); |
194 | | - $set->commit(); |
195 | | - |
196 | | - // Now logging |
197 | | - $log = new LogPage( 'gblrights' ); |
198 | | - $title = SpecialPage::getTitleFor( 'EditWikiSets', $set->getID() ); |
199 | | - if( !$oldname ) { |
200 | | - // New set |
201 | | - $log->addEntry( 'newset', $title, $reason, array( $name, $type, implode( ', ', $wikis ) ) ); |
202 | | - } else { |
203 | | - if( $oldname != $name ) |
204 | | - $log->addEntry( 'setrename', $title, $reason, array( $name, $oldname ) ); |
205 | | - if( $oldtype != $type ) |
206 | | - $log->addEntry( 'setnewtype', $title, $reason, array( $name, $oldtype, $type ) ); |
207 | | - $added = implode( ', ', array_diff( $wikis, $oldwikis ) ); |
208 | | - $removed = implode( ', ', array_diff( $oldwikis, $wikis ) ); |
209 | | - if( $added || $removed ) { |
210 | | - $log->addEntry( 'setchange', $title, $reason, array( $name, $added, $removed ) ); |
211 | | - } |
212 | | - } |
213 | | - |
214 | | - global $wgUser,$wgOut; |
215 | | - $sk = $wgUser->getSkin(); |
216 | | - $returnLink = $sk->makeKnownLinkObj( $this->getTitle(), wfMsg( 'centralauth-editset-return' ) ); |
217 | | - |
218 | | - $wgOut->addHTML( '<strong class="success">' . wfMsgHtml( 'centralauth-editset-success' ) . '</strong> <p>'.$returnLink.'</p>' ); |
219 | | - } |
220 | | -} |
Index: trunk/extensions/CentralAuth/CentralAuth.alias.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | 'MergeAccount' => array( 'MergeAccount' ), |
18 | 18 | 'GlobalGroupMembership' => array( 'GlobalUserRights', 'GlobalGroupMembership' ), |
19 | 19 | 'GlobalGroupPermissions' => array( 'GlobalGroupPermissions' ), |
20 | | - 'EditWikiSets' => array( 'EditWikiSets' ), |
| 20 | + 'EditWikiSets' => array( 'WikiSets', 'EditWikiSets' ), |
21 | 21 | 'GlobalUsers' => array( 'GlobalUsers' ), |
22 | 22 | ); |
23 | 23 | |
Index: trunk/extensions/CentralAuth/SpecialWikiSets.php |
— | — | @@ -0,0 +1,283 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special page to allow to edit "wikisets" which are used to restrict |
| 5 | + * specific global group permissions to certain wikis. |
| 6 | + * |
| 7 | + * @addtogroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 11 | + echo "CentralAuth extension\n"; |
| 12 | + exit( 1 ); |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +class SpecialWikiSets extends SpecialPage { |
| 17 | + var $mCanEdit; |
| 18 | + |
| 19 | + function __construct() { |
| 20 | + parent::__construct( 'WikiSets' ); |
| 21 | + wfLoadExtensionMessages( 'SpecialCentralAuth' ); |
| 22 | + } |
| 23 | + |
| 24 | + function getDescription() { |
| 25 | + return wfMsg( 'centralauth-editset' ); |
| 26 | + } |
| 27 | + |
| 28 | + function execute( $subpage ) { |
| 29 | + global $wgRequest, $wgOut, $wgUser; |
| 30 | + |
| 31 | + $this->mCanEdit = $wgUser->isAllowed( 'globalgrouppermissions' ); |
| 32 | + |
| 33 | + $this->setHeaders(); |
| 34 | + |
| 35 | + if( strpos( $subpage, 'delete/' ) === 0 && $this->mCanEdit ) { |
| 36 | + $subpage = substr( $subpage, 7 ); // Remove delete/ part |
| 37 | + if( is_numeric( $subpage ) ) { |
| 38 | + if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) |
| 39 | + $this->doDelete( $subpage ); |
| 40 | + else |
| 41 | + $this->buildDeleteView( $subpage ); |
| 42 | + } else { |
| 43 | + $this->buildMainView(); |
| 44 | + } |
| 45 | + } else { |
| 46 | + if( $subpage && !is_numeric( $subpage ) ) { |
| 47 | + $set = WikiSet::newFromName( $subpage ); |
| 48 | + if( $set ) { |
| 49 | + $subpage = $set->getID(); |
| 50 | + } else { |
| 51 | + $wgOut->setPageTitle( wfMsg( 'error' ) ); |
| 52 | + $error = wfMsgExt( 'centralauth-editset-notfound', array( 'escapenoentities' ), $subpage ); |
| 53 | + $this->buildMainView( "<strong class='error'>{$error}</strong>" ); |
| 54 | + return; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + if( ( $subpage || $subpage === '0' ) && $this->mCanEdit && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
| 59 | + $this->doSubmit( $subpage ); |
| 60 | + } else if( ( $subpage || $subpage === '0' ) && is_numeric( $subpage ) ) { |
| 61 | + $this->buildSetView( $subpage ); |
| 62 | + } else { |
| 63 | + $this->buildMainView(); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + function buildMainView( $msg = '' ) { |
| 69 | + global $wgOut, $wgScript, $wgUser; |
| 70 | + $sk = $wgUser->getSkin(); |
| 71 | + |
| 72 | + $msgPostfix = $this->mCanEdit ? 'rw' : 'ro'; |
| 73 | + $legend = wfMsg( "centralauth-editset-legend-{$msgPostfix}" ); |
| 74 | + $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" ); |
| 75 | + if( $msg ) |
| 76 | + $wgOut->addHTML( $msg ); |
| 77 | + $wgOut->addWikiMsg( "centralauth-editset-intro-{$msgPostfix}" ); |
| 78 | + $wgOut->addHTML( '<ul>' ); |
| 79 | + |
| 80 | + $sets = WikiSet::getAllWikiSets(); |
| 81 | + foreach( $sets as $set ) { |
| 82 | + $text = wfMsgExt( "centralauth-editset-item-{$msgPostfix}", array( 'parseinline' ), $set->getName(), $set->getID() ); |
| 83 | + $wgOut->addHTML( "<li>{$text}</li>" ); |
| 84 | + } |
| 85 | + |
| 86 | + if( $this->mCanEdit ) { |
| 87 | + $target = SpecialPage::getTitleFor( 'WikiSets', '0' ); |
| 88 | + $newlink = $sk->makeLinkObj( $target, wfMsgHtml( 'centralauth-editset-new' ) ); |
| 89 | + $wgOut->addHTML( "<li>{$newlink}</li>" ); |
| 90 | + } |
| 91 | + |
| 92 | + $wgOut->addHTML( '</ul></fieldset>' ); |
| 93 | + } |
| 94 | + |
| 95 | + function buildSetView( $subpage, $error = false, $name = null, $type = null, $wikis = null, $reason = null ) { |
| 96 | + global $wgOut, $wgUser; |
| 97 | + |
| 98 | + $wgOut->setSubtitle( wfMsgExt( 'centralauth-editset-subtitle', 'parseinline' ) ); |
| 99 | + |
| 100 | + $set = $subpage ? WikiSet::newFromID( $subpage ) : null; |
| 101 | + if( !$name ) $name = $set ? $set->getName() : ''; |
| 102 | + if( !$type ) $type = $set ? $set->getType() : WikiSet::OPTIN; |
| 103 | + if( !$wikis ) $wikis = implode( "\n", $set ? $set->getWikisRaw() : array() ); |
| 104 | + else $wikis = implode( "\n", $wikis ); |
| 105 | + $url = SpecialPage::getTitleFor( 'WikiSets', $subpage )->getLocalUrl(); |
| 106 | + if( $this->mCanEdit ) |
| 107 | + $legend = wfMsgHtml( 'centralauth-editset-legend-' . ($set ? 'edit' : 'new'), $name ); |
| 108 | + else |
| 109 | + $legend = wfMsgHtml( 'centralauth-editset-legend-view', $name ); |
| 110 | + |
| 111 | + $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" ); |
| 112 | + |
| 113 | + if( $set ) { |
| 114 | + $groups = $set->getRestrictedGroups(); |
| 115 | + if ( $groups ) { |
| 116 | + $usage = "<ul>\n"; |
| 117 | + foreach( $groups as $group ) |
| 118 | + $usage .= "<li>" . wfMsgExt( 'centralauth-editset-grouplink', array('parseinline'), $group ) . "</li>\n"; |
| 119 | + $usage .= "</ul>"; |
| 120 | + } else { |
| 121 | + $usage = wfMsgWikiHtml('centralauth-editset-nouse'); |
| 122 | + } |
| 123 | + } else { |
| 124 | + $usage = ''; |
| 125 | + } |
| 126 | + |
| 127 | + if( $this->mCanEdit ) { |
| 128 | + if( $error ) |
| 129 | + $wgOut->addHTML( "<strong class='error'>{$error}</strong>" ); |
| 130 | + $wgOut->addHTML( "<form action='{$url}' method='post'>" ); |
| 131 | + |
| 132 | + $form = array(); |
| 133 | + $form['centralauth-editset-name'] = Xml::input( 'wpName', false, $name ); |
| 134 | + if( $usage ) |
| 135 | + $form['centralauth-editset-usage'] = $usage; |
| 136 | + $form['centralauth-editset-type'] = $this->buildTypeSelector( 'wpType', $type ); |
| 137 | + $form['centralauth-editset-wikis'] = Xml::textarea( 'wpWikis', $wikis ); |
| 138 | + $form['centralauth-editset-reason'] = Xml::input( 'wpReason', false, $reason ); |
| 139 | + |
| 140 | + $wgOut->addHTML( Xml::buildForm( $form, 'centralauth-editset-submit' ) ); |
| 141 | + |
| 142 | + $edittoken = Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
| 143 | + $wgOut->addHTML( "<p>{$edittoken}</p></form></fieldset>" ); |
| 144 | + } else { |
| 145 | + $form = array(); |
| 146 | + $form['centralauth-editset-name'] = htmlspecialchars( $name ); |
| 147 | + $form['centralauth-editset-usage'] = $usage; |
| 148 | + $form['centralauth-editset-type'] = wfMsg( "centralauth-editset-{$type}" ); |
| 149 | + $form['centralauth-editset-wikis'] = $this->buildWikiList( $set->getWikisRaw() ); |
| 150 | + |
| 151 | + $wgOut->addHTML( Xml::buildForm( $form ) ); |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + function buildTypeSelector( $name, $value ) { |
| 156 | + $select = new XmlSelect( $name, 'set-type', $value ); |
| 157 | + foreach( array( WikiSet::OPTIN, WikiSet::OPTOUT ) as $type ) |
| 158 | + $select->addOption( wfMsg( "centralauth-editset-{$type}" ), $type ); |
| 159 | + return $select->getHTML(); |
| 160 | + } |
| 161 | + |
| 162 | + function buildWikiList( $list ) { |
| 163 | + sort( $list ); |
| 164 | + $html = '<ul>'; |
| 165 | + foreach( $list as $wiki ) |
| 166 | + $html .= "<li>{$wiki}</li>"; |
| 167 | + $html .= '</ul>'; |
| 168 | + return $html; |
| 169 | + } |
| 170 | + |
| 171 | + function buildDeleteView( $subpage ) { |
| 172 | + global $wgOut, $wgUser; |
| 173 | + $wgOut->setSubtitle( wfMsgExt( 'centralauth-editset-subtitle', 'parseinline' ) ); |
| 174 | + |
| 175 | + $set = WikiSet::newFromID( $subpage ); |
| 176 | + if( !$set ) { |
| 177 | + $this->buildMainView( '<strong class="error">' . wfMsgHtml( 'centralauth-editset-notfound', $subpage ) . '</strong>' ); |
| 178 | + return; |
| 179 | + } |
| 180 | + |
| 181 | + $legend = wfMsgHtml( 'centralauth-editset-legend-delete', $set->getName() ); |
| 182 | + $form = array( 'centralauth-editset-reason' => Xml::input( 'wpReason' ) ); |
| 183 | + $url = htmlspecialchars( SpecialPage::getTitleFor( 'WikiSets', "delete/{$subpage}" )->getLocalUrl() ); |
| 184 | + $edittoken = Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
| 185 | + |
| 186 | + $wgOut->addHTML( "<fieldset><legend>{$legend}</legend><form action='{$url}' method='post'>" ); |
| 187 | + $wgOut->addHTML( Xml::buildForm( $form, 'centralauth-editset-submit-delete' ) ); |
| 188 | + $wgOut->addHTML( "<p>{$edittoken}</p></form></fieldset>" ); |
| 189 | + } |
| 190 | + |
| 191 | + function doSubmit( $id ) { |
| 192 | + global $wgRequest, $wgContLang; |
| 193 | + |
| 194 | + $name = $wgContLang->ucfirst( $wgRequest->getVal( 'wpName' ) ); |
| 195 | + $type = $wgRequest->getVal( 'wpType' ); |
| 196 | + $wikis = array_unique( preg_split( '/(\s+|\s*\W\s*)/', $wgRequest->getVal( 'wpWikis' ), -1, PREG_SPLIT_NO_EMPTY ) ); |
| 197 | + $reason = $wgRequest->getVal( 'wpReason' ); |
| 198 | + $set = WikiSet::newFromId( $id ); |
| 199 | + |
| 200 | + if( !Title::newFromText( $name ) ) { |
| 201 | + $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-badname' ), $name, $type, $wikis, $reason ); |
| 202 | + return; |
| 203 | + } |
| 204 | + if( (!$id || $set->getName() != $name ) && WikiSet::newFromName( $name ) ) { |
| 205 | + $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-setexists' ), $name, $type, $wikis, $reason ); |
| 206 | + return; |
| 207 | + } |
| 208 | + if( !in_array( $type, array( WikiSet::OPTIN, WikiSet::OPTOUT ) ) ) { |
| 209 | + $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-badtype' ), $name, $type, $wikis, $reason ); |
| 210 | + return; |
| 211 | + } |
| 212 | + if( !$wikis ) { |
| 213 | + $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-nowikis' ), $name, $type, $wikis, $reason ); |
| 214 | + return; |
| 215 | + } |
| 216 | + $badwikis = array(); |
| 217 | + $allwikis = CentralAuthUser::getWikiList(); |
| 218 | + foreach( $wikis as $wiki ) |
| 219 | + if( !in_array( $wiki, $allwikis ) ) |
| 220 | + $badwikis[] = $wiki; |
| 221 | + if( $badwikis ) { |
| 222 | + $this->buildSetView( $id, wfMsgExt( 'centralauth-editset-badwikis', array( 'escapenoentities', 'parsemag' ), |
| 223 | + implode( ', ', $badwikis ), count( $badwikis ) ), $name, $type, $wikis, $reason ); |
| 224 | + return; |
| 225 | + } |
| 226 | + |
| 227 | + if( $set ) { |
| 228 | + $oldname = $set->getName(); |
| 229 | + $oldtype = $set->getType(); |
| 230 | + $oldwikis = $set->getWikisRaw(); |
| 231 | + } else { |
| 232 | + $set = new WikiSet(); |
| 233 | + $oldname = $oldtype = null; $oldwikis = array(); |
| 234 | + } |
| 235 | + $set->setName( $name ); |
| 236 | + $set->setType( $type ); |
| 237 | + $set->setWikisRaw( $wikis ); |
| 238 | + $set->commit(); |
| 239 | + |
| 240 | + // Now logging |
| 241 | + $log = new LogPage( 'gblrights' ); |
| 242 | + $title = SpecialPage::getTitleFor( 'WikiSets', $set->getID() ); |
| 243 | + if( !$oldname ) { |
| 244 | + // New set |
| 245 | + $log->addEntry( 'newset', $title, $reason, array( $name, $type, implode( ', ', $wikis ) ) ); |
| 246 | + } else { |
| 247 | + if( $oldname != $name ) |
| 248 | + $log->addEntry( 'setrename', $title, $reason, array( $name, $oldname ) ); |
| 249 | + if( $oldtype != $type ) |
| 250 | + $log->addEntry( 'setnewtype', $title, $reason, array( $name, $oldtype, $type ) ); |
| 251 | + $added = implode( ', ', array_diff( $wikis, $oldwikis ) ); |
| 252 | + $removed = implode( ', ', array_diff( $oldwikis, $wikis ) ); |
| 253 | + if( $added || $removed ) { |
| 254 | + $log->addEntry( 'setchange', $title, $reason, array( $name, $added, $removed ) ); |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + global $wgUser,$wgOut; |
| 259 | + $sk = $wgUser->getSkin(); |
| 260 | + $returnLink = $sk->makeKnownLinkObj( $this->getTitle(), wfMsg( 'centralauth-editset-return' ) ); |
| 261 | + |
| 262 | + $wgOut->addHTML( '<strong class="success">' . wfMsgHtml( 'centralauth-editset-success' ) . '</strong> <p>'.$returnLink.'</p>' ); |
| 263 | + } |
| 264 | + |
| 265 | + function doDelete( $set ) { |
| 266 | + global $wgRequest, $wgContLang; |
| 267 | + |
| 268 | + $set = WikiSet::newFromID( $set ); |
| 269 | + if( !$set ) { |
| 270 | + $this->buildMainView( '<strong class="error">' . wfMsgHtml( 'centralauth-editset-notfound', $subpage ) . '</strong>' ); |
| 271 | + return; |
| 272 | + } |
| 273 | + |
| 274 | + $reason = $wgRequest->getVal( 'wpReason' ); |
| 275 | + $name = $set->getName(); |
| 276 | + $set->delete(); |
| 277 | + |
| 278 | + $title = SpecialPage::getTitleFor( 'WikiSets', $set->getID() ); |
| 279 | + $log = new LogPage( 'gblrights' ); |
| 280 | + $log->addEntry( 'deleteset', $title, $reason, array( $name ) ); |
| 281 | + |
| 282 | + $this->buildMainView( '<strong class="success">' . wfMsg( 'centralauth-editset-success-delete' ) . '</strong>' ); |
| 283 | + } |
| 284 | +} |
Property changes on: trunk/extensions/CentralAuth/SpecialWikiSets.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 285 | + native |
Index: trunk/extensions/CentralAuth/CentralAuth.php |
— | — | @@ -160,7 +160,7 @@ |
161 | 161 | $wgAutoloadClasses['SpecialGlobalGroupMembership'] = "$caBase/SpecialGlobalGroupMembership.php"; |
162 | 162 | $wgAutoloadClasses['CentralAuthGroupMembershipProxy'] = "$caBase/CentralAuthGroupMembershipProxy.php"; |
163 | 163 | $wgAutoloadClasses['SpecialGlobalGroupPermissions'] = "$caBase/SpecialGlobalGroupPermissions.php"; |
164 | | -$wgAutoloadClasses['SpecialEditWikiSets'] = "$caBase/SpecialEditWikiSets.php"; |
| 164 | +$wgAutoloadClasses['SpecialWikiSets'] = "$caBase/SpecialWikiSets.php"; |
165 | 165 | $wgAutoloadClasses['ApiQueryGlobalUserInfo'] = "$caBase/ApiQueryGlobalUserInfo.php"; |
166 | 166 | |
167 | 167 | $wgExtensionMessagesFiles['SpecialCentralAuth'] = "$caBase/CentralAuth.i18n.php"; |
— | — | @@ -213,13 +213,13 @@ |
214 | 214 | $wgSpecialPages['MergeAccount'] = 'SpecialMergeAccount'; |
215 | 215 | $wgSpecialPages['GlobalGroupMembership'] = 'SpecialGlobalGroupMembership'; |
216 | 216 | $wgSpecialPages['GlobalGroupPermissions'] = 'SpecialGlobalGroupPermissions'; |
217 | | -$wgSpecialPages['EditWikiSets'] = 'SpecialEditWikiSets'; |
| 217 | +$wgSpecialPages['WikiSets'] = 'SpecialWikiSets'; |
218 | 218 | $wgSpecialPages['GlobalUsers'] = 'SpecialGlobalUsers'; |
219 | 219 | $wgSpecialPageGroups['CentralAuth'] = 'users'; |
220 | 220 | $wgSpecialPageGroups['MergeAccount'] = 'login'; |
221 | 221 | $wgSpecialPageGroups['GlobalGroupMembership'] = 'users'; |
222 | 222 | $wgSpecialPageGroups['GlobalGroupPermissions'] = 'users'; |
223 | | -$wgSpecialPageGroups['EditWikiSets'] = 'wiki'; |
| 223 | +$wgSpecialPageGroups['WikiSets'] = 'wiki'; |
224 | 224 | $wgSpecialPageGroups['GlobalUsers'] = 'users'; |
225 | 225 | |
226 | 226 | $wgAPIMetaModules['globaluserinfo'] = 'ApiQueryGlobalUserInfo'; |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | $wgLogActions['gblrights/groupperms'] = 'centralauth-rightslog-entry-groupperms'; |
245 | 245 | $wgLogActions['gblrights/groupprms2'] = 'centralauth-rightslog-entry-groupperms2'; |
246 | 246 | $wgLogActions['gblrights/groupprms3'] = 'centralauth-rightslog-entry-groupperms3'; |
247 | | -foreach( array( 'newset', 'setrename', 'setnewtype', 'setchange' ) as $type ) |
| 247 | +foreach( array( 'newset', 'setrename', 'setnewtype', 'setchange', 'deleteset' ) as $type ) |
248 | 248 | $wgLogActionsHandlers["gblrights/{$type}"] = 'efHandleWikiSetLogEntry'; |
249 | 249 | |
250 | 250 | function efHandleWikiSetLogEntry( $type, $action, $title, $skin, $params, $filterWikilinks = false ) { |
— | — | @@ -257,5 +257,7 @@ |
258 | 258 | $args = array( WikiSet::formatType( $params[1] ), WikiSet::formatType( $params[2] ) ); |
259 | 259 | if( $action == 'setchange' ) |
260 | 260 | $args = array( $params[1] ? $params[1] : wfMsg( 'rightsnone' ), $params[2] ? $params[2] : wfMsg( 'rightsnone' ) ); |
| 261 | + if( $action == 'deleteset' ) |
| 262 | + $args = array(); |
261 | 263 | return wfMsgReal( "centralauth-rightslog-entry-{$action}", array_merge( array( $link ), $args ), true, !$skin ); |
262 | 264 | } |
Index: trunk/extensions/CentralAuth/WikiSet.php |
— | — | @@ -5,11 +5,11 @@ |
6 | 6 | const OPTOUT = 'optout'; |
7 | 7 | const VERSION = 1; |
8 | 8 | |
9 | | - private $mId; //ID of the group |
10 | | - private $mName; //Display name of the group |
11 | | - private $mType; //Opt-in based or opt-out based |
12 | | - private $mWikis; //List of wikis |
13 | | - private $mVersion = self::VERSION; //Caching purposes |
| 9 | + private $mId; // ID of the group |
| 10 | + private $mName; // Display name of the group |
| 11 | + private $mType; // Opt-in based or opt-out based |
| 12 | + private $mWikis; // List of wikis |
| 13 | + private $mVersion = self::VERSION; // Caching purposes |
14 | 14 | |
15 | 15 | static $mCacheVars = array( |
16 | 16 | 'mId', |
— | — | @@ -123,6 +123,14 @@ |
124 | 124 | return (bool)$dbw->affectedRows(); |
125 | 125 | } |
126 | 126 | |
| 127 | + public function delete() { |
| 128 | + $dbw = CentralAuthUser::getCentralDB(); |
| 129 | + $dbw->delete( 'wikiset', array( 'ws_id' => $this->mId ), __METHOD__ ); |
| 130 | + $dbw->commit(); |
| 131 | + $this->purge(); |
| 132 | + return (bool)$dbw->affectedRows(); |
| 133 | + } |
| 134 | + |
127 | 135 | public function purge() { |
128 | 136 | global $wgMemc; |
129 | 137 | $wgMemc->delete( self::memcKey( $this->mId ) ); |
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php |
— | — | @@ -270,6 +270,7 @@ |
271 | 271 | 'centralauth-rightslog-entry-setrename' => 'renamed wiki set "$2" to "$1"', |
272 | 272 | 'centralauth-rightslog-entry-setnewtype' => 'changed type of "$1" from $2 to $3', |
273 | 273 | 'centralauth-rightslog-entry-setchange' => 'changed wikis in "$1": added: $2; removed: $3', |
| 274 | + 'centralauth-rightslog-entry-deleteset' => 'deleted wiki set "$1"', |
274 | 275 | 'centralauth-rightslog-set-optin' => 'opt-in based', |
275 | 276 | 'centralauth-rightslog-set-optout' => 'opt-out based', |
276 | 277 | |
— | — | @@ -318,22 +319,29 @@ |
319 | 320 | You may be attempting to assign rights to the wrong user!", |
320 | 321 | |
321 | 322 | // Wiki sets editing |
322 | | - 'centralauth-editset' => 'Edit wiki sets', |
323 | | - 'centralauth-editset-legend' => 'Edit or create wiki set', |
324 | | - 'centralauth-editset-intro' => 'The following wiki sets have already been created. |
| 323 | + 'centralauth-editset' => 'Wiki sets', |
| 324 | + 'centralauth-editset-legend-rw' => 'Edit or create wiki set', |
| 325 | + 'centralauth-editset-legend-ro' => 'List of wiki sets', |
| 326 | + 'centralauth-editset-intro-rw' => 'The following wiki sets have already been created. |
325 | 327 | You may view and modify any of them, or create a new set.', |
326 | | - 'centralauth-editset-item' => '$1 ([[Special:EditWikiSets/$2|view/edit]])', |
| 328 | + 'centralauth-editset-intro-ro' => 'Below is the list of existing wiki sets.', |
| 329 | + 'centralauth-editset-item-rw' => '[[Special:WikiSets/$2|$1]] ([[Special:WikiSets/delete/$2|delete]])', |
| 330 | + 'centralauth-editset-item-ro' => '[[Special:WikiSets/$2|$1]]', |
327 | 331 | 'centralauth-editset-new' => 'Create a new set', |
328 | 332 | 'centralauth-editset-notfound' => 'Wiki set "$1" not found.', |
329 | 333 | 'centralauth-editset-optin' => 'Opt-in based (includes only specified wikis)', |
330 | 334 | 'centralauth-editset-optout' => 'Opt-out based (includes all wikis except specified)', |
331 | 335 | 'centralauth-editset-legend-edit' => 'Editing wiki set "$1"', |
| 336 | + 'centralauth-editset-legend-view' => 'Wiki set "$1"', |
332 | 337 | 'centralauth-editset-legend-new' => 'Creating new wiki set', |
| 338 | + 'centralauth-editset-legend-delete' => 'Deleting wiki set "$1"', |
| 339 | + 'centralauth-editset-subtitle' => '< [[Special:WikiSets|List of sets]]', |
333 | 340 | 'centralauth-editset-name' => 'Name:', |
334 | 341 | 'centralauth-editset-type' => 'Type:', |
335 | 342 | 'centralauth-editset-wikis' => 'Wikis:', |
336 | 343 | 'centralauth-editset-reason' => 'Reason:', |
337 | 344 | 'centralauth-editset-submit' => 'Submit', |
| 345 | + 'centralauth-editset-submit-delete' => 'Delete', |
338 | 346 | 'centralauth-editset-badname' => 'Invalid or empty set name.', |
339 | 347 | 'centralauth-editset-badtype' => 'Invalid set type.', |
340 | 348 | 'centralauth-editset-setexists' => 'Set with that name already exists', |
— | — | @@ -343,6 +351,7 @@ |
344 | 352 | 'centralauth-editset-usage' => 'Used in groups:', |
345 | 353 | 'centralauth-editset-badwikis' => 'The following {{PLURAL:$2|wiki does not|wikis do not}} exist: $1.', |
346 | 354 | 'centralauth-editset-success' => 'Successfully changed wiki set.', |
| 355 | + 'centralauth-editset-success-delete' => 'Successfully deleted wiki set.', |
347 | 356 | 'centralauth-editset-return' => 'Return to main view', |
348 | 357 | |
349 | 358 | // User rights |