From f664cf10ef5ddf43dc5fc3b927e85df54284297f Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 26 Feb 2011 13:51:46 +0000 Subject: [PATCH] (bug 27700) The upload protection can now also be set for files that do not exist. Sort of follow-up to r79655, adds create to $wgRestrictionTypes in DefaultSettings.php as well and removes it when not applicable. --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 4 ++-- includes/Title.php | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c19e677e39..928f710b9f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -144,6 +144,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 27560) Search queries no longer fail in walloon language * (bug 27679) Broken embedded files with special characters longer double HTML escaped +* (bug 27700) The upload protection can now also be set for files that do not + exist. === API changes in 1.18 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index bdee3f984e..5e5fb678ca 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3371,9 +3371,9 @@ $wgGroupsRemoveFromSelf = array(); * You probably shouldn't change this. * Translated through restriction-* messages. * Title::getRestrictionTypes() will remove restrictions that are not - * applicable to a specific title (upload currently) + * applicable to a specific title (create and upload) */ -$wgRestrictionTypes = array( 'edit', 'move', 'upload' ); +$wgRestrictionTypes = array( 'create', 'edit', 'move', 'upload' ); /** * Rights which can be required for each protection level (via action=protect) diff --git a/includes/Title.php b/includes/Title.php index 409467bbdf..c6c225ab21 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4118,13 +4118,21 @@ class Title { public function getRestrictionTypes() { global $wgRestrictionTypes; - $types = $this->exists() ? $wgRestrictionTypes : array( 'create' ); + $types = $wgRestrictionTypes; + if ( !$this->exists() ) { + # Only the create and upload types are applicable for non-existing titles + $types = array_intersect( $types, array( 'create', 'upload' ) ); + } if ( $this->getNamespace() != NS_FILE ) { + # Remove the upload restriction for non-file titles $types = array_diff( $types, array( 'upload' ) ); } wfRunHooks( 'TitleGetRestrictionTypes', array( $this, &$types ) ); + + wfDebug( __METHOD__ . ': applicable restriction types for ' . + $this->getPrefixedText() . ' are ' . implode( ',', $types ) ); return $types; } -- 2.20.1