r38118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38117‎ | r38118 | r38119 >
Date:05:15, 28 July 2008
Author:brion
Status:old
Tags:
Comment:
Revert another part of r37975 pending review (new tables etc)
Modified paths:
  • /trunk/extensions/CentralAuth/SpecialEditWikiSets.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/SpecialEditWikiSets.php
@@ -1,193 +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 - $globalUser = CentralAuthUser::getInstance( $user );
29 -
30 - ## Should be a global user
31 - if (!$globalUser->exists() || !$globalUser->isAttached()) {
32 - return false;
33 - }
34 -
35 - ## Permission MUST be gained from global rights.
36 - return $globalUser->hasGlobalPermission( 'globalgrouppermissions' );
37 - }
38 -
39 - function execute( $subpage ) {
40 - global $wgRequest, $wgOut, $wgUser;
41 -
42 - if( !$this->userCanExecute( $wgUser ) ) {
43 - $this->displayRestrictionError();
44 - return;
45 - }
46 -
47 - $this->setHeaders();
48 -
49 - if( $subpage && !is_numeric( $subpage ) ) {
50 - $set = WikiSet::newFromName( $subpage );
51 - if( $set ) {
52 - $subpage = $set->getID();
53 - } else {
54 - $wgOut->setPageTitle( wfMsg( 'error' ) );
55 - $error = wfMsgExt( 'centralauth-editset-notfound', array( 'escapenoentities' ), $subpage );
56 - $this->buildMainView( "<strong class='error'>{$error}</strong>" );
57 - return;
58 - }
59 - }
60 -
61 - if( ( $subpage || $subpage === '0' ) && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
62 - $this->doSubmit( $subpage );
63 - } else if( ( $subpage || $subpage === '0' ) && is_numeric( $subpage ) ) {
64 - $this->buildSetView( $subpage );
65 - } else {
66 - $this->buildMainView();
67 - }
68 - }
69 -
70 - function buildMainView( $msg = '' ) {
71 - global $wgOut, $wgScript, $wgUser;
72 - $sk = $wgUser->getSkin();
73 -
74 - $legend = wfMsg( 'centralauth-editset-legend' );
75 - $wgOut->addHtml( "<fieldset><legend>{$legend}</legend>" );
76 - if( $msg )
77 - $wgOut->addHTML( $msg );
78 - $wgOut->addWikiMsg( 'centralauth-editset-intro' );
79 - $wgOut->addHTML( '<ul>' );
80 -
81 - $sets = WikiSet::getAllWikiSets();
82 - foreach( $sets as $set ) {
83 - $text = wfMsgExt( 'centralauth-editset-item', array( 'parseinline' ), $set->getName(), $set->getID() );
84 - $wgOut->addHTML( "<li>{$text}</li>" );
85 - }
86 -
87 - $target = SpecialPage::getTitleFor( 'EditWikiSets', '0' );
88 - $newlink = $sk->makeLinkObj( $target, wfMsgHtml( 'centralauth-editset-new' ) );
89 - $wgOut->addHTML( "<li>{$newlink}</li>" );
90 -
91 - $wgOut->addHtml( '</ul></fieldset>' );
92 - }
93 -
94 - function buildSetView( $subpage, $error = false, $name = null, $type = null, $wikis = null, $reason = null ) {
95 - global $wgOut, $wgUser;
96 -
97 - $set = $subpage ? WikiSet::newFromID( $subpage ) : null;
98 - if( !$name ) $name = $set ? $set->getName() : '';
99 - if( !$type ) $type = $set ? $set->getType() : WikiSet::OPTIN;
100 - if( !$wikis ) $wikis = implode( "\n", $set ? $set->getWikisRaw() : array() );
101 - else $wikis = implode( "\n", $wikis );
102 - $url = SpecialPage::getTitleFor( 'EditWikiSets', $subpage )->getLocalUrl();
103 - $legend = wfMsgHtml( 'centralauth-editset-legend-' . ($set ? 'edit' : 'new'), $name );
104 -
105 - $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" );
106 - if( $error )
107 - $wgOut->addHTML( "<strong class='error'>{$error}</strong>" );
108 - $wgOut->addHTML( "<form action='{$url}' method='post'>" );
109 -
110 - $form = array();
111 - $form['centralauth-editset-name'] = Xml::input( 'wpName', false, $name );
112 - $form['centralauth-editset-type'] = $this->buildTypeSelector( 'wpType', $type );
113 - $form['centralauth-editset-wikis'] = Xml::textarea( 'wpWikis', $wikis );
114 - $form['centralauth-editset-reason'] = Xml::input( 'wpReason', $reason );
115 -
116 - $wgOut->addHTML( Xml::buildForm( $form, 'centralauth-editset-submit' ) );
117 -
118 - $edittoken = Xml::hidden( 'wpEditToken', $wgUser->editToken() );
119 - $wgOut->addHTML( "<p>{$edittoken}</p></form></fieldset>" );
120 - }
121 -
122 - function buildTypeSelector( $name, $value ) {
123 - $select = new XmlSelect( $name, 'set-type', $value );
124 - foreach( array( WikiSet::OPTIN, WikiSet::OPTOUT ) as $type )
125 - $select->addOption( wfMsg( "centralauth-editset-{$type}" ), $type );
126 - return $select->getHTML();
127 - }
128 -
129 - function doSubmit( $id ) {
130 - global $wgRequest, $wgContLang;
131 -
132 - $name = $wgContLang->ucfirst( $wgRequest->getVal( 'wpName' ) );
133 - $type = $wgRequest->getVal( 'wpType' );
134 - $wikis = array_unique( preg_split( '/(\s+|\s*\W\s*)/', $wgRequest->getVal( 'wpWikis' ), -1, PREG_SPLIT_NO_EMPTY ) );
135 - $reason = $wgRequest->getVal( 'wpReason' );
136 -
137 - if( !Title::newFromText( $name ) ) {
138 - $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-badname' ), $name, $type, $wikis, $reason );
139 - return;
140 - }
141 - if( !in_array( $type, array( WikiSet::OPTIN, WikiSet::OPTOUT ) ) ) {
142 - $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-badtype' ), $name, $type, $wikis, $reason );
143 - return;
144 - }
145 - if( !$wikis ) {
146 - $this->buildSetView( $id, wfMsgHtml( 'centralauth-editset-nowikis' ), $name, $type, $wikis, $reason );
147 - return;
148 - }
149 - $badwikis = array();
150 - $allwikis = CentralAuthUser::getWikiList();
151 - foreach( $wikis as $wiki )
152 - if( !in_array( $wiki, $allwikis ) )
153 - $badwikis[] = $wiki;
154 - if( $badwikis ) {
155 - $this->buildSetView( $id, wfMsgExt( 'centralauth-editset-badwikis', array( 'escapenoentities' ), implode( ', ', $badwikis ) ),
156 - $name, $type, $wikis, $reason );
157 - return;
158 - }
159 -
160 - $set = WikiSet::newFromID( $id );
161 - if( $set ) {
162 - $oldname = $set->getName();
163 - $oldtype = $set->getType();
164 - $oldwikis = $set->getWikisRaw();
165 - } else {
166 - $set = new WikiSet();
167 - $oldname = $oldtype = null; $oldwikis = array();
168 - }
169 - $set->setName( $name );
170 - $set->setType( $type );
171 - $set->setWikisRaw( $wikis );
172 - $set->commit();
173 -
174 - // Now logging
175 - $log = new LogPage( 'gblrights' );
176 - $title = SpecialPage::getTitleFor( 'EditWikiSets', $id );
177 - if( !$oldname ) {
178 - // New set
179 - $log->addEntry( 'newset', $title, $reason, array( $name, $type, implode( ', ', $wikis ) ) );
180 - } else {
181 - if( $oldname != $name )
182 - $log->addEntry( 'setrename', $title, $reason, array( $name, $oldname ) );
183 - if( $oldtype != $type )
184 - $log->addEntry( 'setnewtype', $title, $reason, array( $name, $oldtype, $type ) );
185 - $added = implode( ', ', array_diff( $wikis, $oldwikis ) );
186 - $removed = implode( ', ', array_diff( $oldwikis, $wikis ) );
187 - if( $added || $removed ) {
188 - $log->addEntry( 'setchange', $title, $reason, array( $name, $added, $removed ) );
189 - }
190 - }
191 -
192 - $this->buildMainView( '<strong class="success">' . wfMsgHtml( 'centralauth-editset-success' ) . '</strong>' );
193 - }
194 -}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r37975* (bug 14556) Global groups defined for certain sets of wikis...vasilievvv20:24, 23 July 2008

Status & tagging log