r51870 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51869‎ | r51870 | r51871 >
Date:09:40, 15 June 2009
Author:jojo
Status:ok (Comments)
Tags:
Comment:
use hardcoded rights collectionsaveas{user|community}page.
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)
  • /trunk/extensions/Collection/Collection.templates.php (modified) (history)
  • /trunk/extensions/Collection/README.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.php
@@ -95,9 +95,6 @@
9696
9797 $wgCollectionPortletForLoggedInUsersOnly = false;
9898
99 -$wgCollectionSaveAsUserPageRight = null;
100 -$wgCollectionSaveAsCommunityPageRight = 'autoconfirmed';
101 -
10299 $wgCollectionNavPopups = false;
103100
104101 # ==============================================================================
Index: trunk/extensions/Collection/README.txt
@@ -217,8 +217,21 @@
218218
219219 $wgEnableWriteAPI = true;
220220
221 - (This is the default for MediaWiki >= 1.14.)
 221+ (This is the default for MediaWiki >= 1.14.).
222222
 223+ There are two MediaWiki rights that are checked, before users are allowed
 224+ to save collections: To be able to save collection pages under the User
 225+ namespace, users must have the right 'collectionsaveasuserpage'; to be able
 226+ to save collection pages under the community namespace
 227+ (see $wgCommunityCollectionNamespace), users must have the right
 228+ 'collectionsaveascommunitypage'. For example, if all logged-in users shall
 229+ be allowed to save collection pages under the User namespace, but only
 230+ autoconfirmed users, shall be allowed to save collection pages under the
 231+ community namespace, add this to your LocalSettings.php::
 232+
 233+ $wgGroupPermissions['user']['collectionsaveasuserpage'] = true;
 234+ $wgGroupPermissions['autoconfirmed']['collectionsaveascommunitypage'] = true;
 235+
223236 * As the current collection of articles is stored in the session, the session
224237 timeout should be set to some sensible value (at least a few hours, maybe
225238 one day). Adjust session.cookie_lifetime and session.gc_maxlifetime in your
Index: trunk/extensions/Collection/Collection.body.php
@@ -148,39 +148,42 @@
149149 $partner = $wgRequest->getVal( 'partner', 'pediapress' );
150150 return $this->postZIP( $collection, $partner );
151151 case 'save_collection/':
152 - $collTitle = $wgRequest->getVal( 'colltitle' );
153 - if ( $wgRequest->getVal( 'overwrite' ) && !empty( $collTitle ) ) {;
154 - $title = Title::newFromText( $collTitle );
155 - $this->saveCollection( $title, $overwrite=true );
156 - $wgOut->redirect( $title->getFullURL() );
 152+ if ( $wgRequest->getVal( 'abort' ) ) {
 153+ $wgOut->redirect( SkinTemplate::makeSpecialUrl( 'Book' ) );
157154 return;
158155 }
159 - $collType = $wgRequest->getVal( 'colltype' );
160 - $overwrite = $wgRequest->getBool( 'overwrite' );
161 - $saveCalled = false;
162 - if ( $collType == 'personal' ) {
 156+ $colltype = $wgRequest->getVal( 'colltype' );
 157+ if ( $colltype == 'personal' ) {
 158+ $collname = $wgRequest->getVal( 'pcollname' );
 159+ if ( !$wgUser->isAllowed( 'collectionsaveasuserpage' ) || empty( $collname ) ) {
 160+ return;
 161+ }
163162 $userPageTitle = $wgUser->getUserPage()->getPrefixedText();
164 - $name = $wgRequest->getVal( 'pcollname', '' );
165 - if ( !empty( $name ) ) {
166 - $title = Title::newFromText( $userPageTitle . '/' . wfMsgForContent( 'coll-collections' ) . '/' . $name );
167 - $saveCalled = true;
168 - $saved = $this->saveCollection( $title, $overwrite );
 163+ $title = Title::newFromText(
 164+ $userPageTitle . '/' . wfMsgForContent( 'coll-collections' ) . '/' . $collname
 165+ );
 166+ } else if ( $colltype == 'community' ) {
 167+ $collname = $wgRequest->getVal( 'ccollname' );
 168+ if ( !$wgUser->isAllowed( 'collectionsaveascommunitypage' ) || empty( $collname ) ) {
 169+ return;
169170 }
170 - } else if ( $collType == 'community' ) {
171 - $name = $wgRequest->getVal( 'ccollname', '' );
172 - if ( !empty( $name ) ) {
173 - $title = Title::makeTitle( $wgCommunityCollectionNamespace, wfMsgForContent( 'coll-collections' ) . '/' . $name );
174 - $saveCalled = true;
175 - $saved = $this->saveCollection( $title, $overwrite );
176 - }
 171+ $title = Title::makeTitle(
 172+ $wgCommunityCollectionNamespace,
 173+ wfMsgForContent( 'coll-collections' ) . '/' . $collname
 174+ );
177175 }
178 -
179 - if ( !$saveCalled) {
180 - $wgOut->redirect( SkinTemplate::makeSpecialUrl( 'Book' ) );
181 - } else if ( $saved ) {
 176+ if ( !isset( $title ) ) {
 177+ return;
 178+ }
 179+ if ( $this->saveCollection( $title, $wgRequest->getBool( 'overwrite' ) ) ) {
182180 $wgOut->redirect( $title->getFullURL() );
183181 } else {
184 - $this->renderSaveOverwritePage( $title );
 182+ $this->renderSaveOverwritePage(
 183+ $colltype,
 184+ $title,
 185+ $wgRequest->getVal( 'pcollname' ),
 186+ $wgRequest->getVal( 'ccollname' )
 187+ );
185188 }
186189 return;
187190 case 'render/':
@@ -892,7 +895,7 @@
893896 $wgOut->redirect( $response['redirect_url'] );
894897 }
895898
896 - private function renderSaveOverwritePage( $title ) {
 899+ private function renderSaveOverwritePage( $colltype, $title, $pcollname, $ccollname ) {
897900 global $wgOut;
898901
899902 $this->setHeaders();
@@ -900,6 +903,9 @@
901904
902905 $template = new CollectionSaveOverwriteTemplate();
903906 $template->set( 'title', $title );
 907+ $template->set( 'pcollname', $pcollname );
 908+ $template->set( 'ccollname', $ccollname );
 909+ $template->set( 'colltype', $colltype );
904910 $wgOut->addTemplate( $template );
905911 }
906912
Index: trunk/extensions/Collection/Collection.templates.php
@@ -132,10 +132,10 @@
133133 <?php
134134 if ($GLOBALS['wgUser']->isLoggedIn()) {
135135 $showLoginInfo = false;
136 - $canSaveUserPage = (empty($GLOBALS['wgCollectionSaveAsUserPageRight']) || $GLOBALS['wgUser']->isAllowed($GLOBALS['wgCollectionSaveAsUserPageRight']));
137 - $canSaveCommunityPage = (empty($GLOBALS['wgCollectionSaveAsCommunityPageRight']) || $GLOBALS['wgUser']->isAllowed($GLOBALS['wgCollectionSaveAsCommunityPageRight']));
 136+ $canSaveUserPage = $GLOBALS['wgUser']->isAllowed('collectionsaveasuserpage');
 137+ $canSaveCommunityPage = $GLOBALS['wgUser']->isAllowed('collectionsaveascommunitypage');
138138 } else {
139 - $showLoginInfo = (empty($GLOBALS['wgCollectionSaveAsCommunityPageRight']) || empty($GLOBALS['wgCollectionSaveAsUserPageRight']));
 139+ $showLoginInfo = true;
140140 }
141141 if ($GLOBALS['wgEnableWriteAPI'] && ($showLoginInfo || $canSaveUserPage || $canSaveCommunityPage)) {
142142 ?>
@@ -326,7 +326,9 @@
327327 <form action="<?php echo htmlspecialchars(SkinTemplate::makeSpecialUrlSubpage('Book', 'save_collection/')) ?>" method="post">
328328 <input name="overwrite" type="submit" value="<?php $this->msg('coll-yes') ?>" />
329329 <input name="abort" type="submit" value="<?php $this->msg('coll-no') ?>" />
330 - <input name="colltitle" type="hidden" value="<?php echo htmlspecialchars($this->data['title']->getPrefixedText()) ?>" />
 330+ <input name="pcollname" type="hidden" value="<?php echo htmlspecialchars($this->data['pcollname']) ?>" />
 331+ <input name="ccollname" type="hidden" value="<?php echo htmlspecialchars($this->data['ccollname']) ?>" />
 332+ <input name="colltype" type="hidden" value="<?php echo htmlspecialchars($this->data['colltype']) ?>" />
331333 </form>
332334
333335 <?php

Follow-up revisions

RevisionCommit summaryAuthorDate
r51943* Add $wgAvailableRights for rights defined in r51870...tstarling00:14, 16 June 2009
r52180Follow-up r51870, r51943: remove now-bogus bits in README about removed varia...brion22:07, 19 June 2009

Comments

#Comment by Tim Starling (talk | contribs)   23:29, 15 June 2009

I will add $wgAvailableRights.

Status & tagging log