Zhuyifei1999 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/233207
Change subject: Cascade-protection: Fixes for files
......................................................................
Cascade-protection: Fixes for files
* Cascade-protected files via imagelink is no longer edit-protected, but
upload-protected (T24521)
** Move-protection depends on the cascade-protecting/image-using page
* Cascade-protected files via templatelink (transclusion) is now
upload-protected (T62109)
** Move-protection depends on the cascade-protecting/transcluding page
* Reuploading no longer require edit permission, but only upload permission
(T109435)
** Though uploading when the file page doesn't exist require all of the three
permissions (create, edit, upload), as the file description page will be
changed.
* The "You cannot overwrite this file." check now works for cascade-protected
files. (T109410)
** The check is done only on the upload permission, which was originally
available even when cascade-protected.
** The edit permission was originally revoked to prevent reuploading, and this
logic is inconsistant with the "You cannot overwrite this file." check.
Bug: T24521 T62109 T109410 T109435
Change-Id: Ifd59d3fd653b93cdea5b6d8b642715a1f4fb57b3
---
M includes/Title.php
M includes/upload/UploadBase.php
2 files changed, 71 insertions(+), 32 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/07/233207/1
diff --git a/includes/Title.php b/includes/Title.php
index 8a15b54..abe245c 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -2748,24 +2748,64 @@
return array( $this->mHasCascadingRestrictions,
$pagerestrictions );
}
- $dbr = wfGetDB( DB_SLAVE );
-
- if ( $this->getNamespace() == NS_FILE ) {
- $tables = array( 'imagelinks', 'page_restrictions' );
- $where_clauses = array(
- 'il_to' => $this->getDBkey(),
- 'il_from=pr_page',
- 'pr_cascade' => 1
- );
- } else {
- $tables = array( 'templatelinks', 'page_restrictions' );
- $where_clauses = array(
+ $sources = $this->getCascadeProtectionSourcesInternal(
+ $getPages,
+ $pagerestrictions,
+ array( 'templatelinks' ),
+ array(
'tl_namespace' => $this->getNamespace(),
'tl_title' => $this->getDBkey(),
'tl_from=pr_page',
- 'pr_cascade' => 1
- );
+ )
+ );
+
+ # For upload protections
+ if ( $this->getNamespace() == NS_FILE ) {
+ $sources = array_merge( $sources,
$this->getCascadeProtectionSourcesInternal(
+ $getPages,
+ $pagerestrictions,
+ array( 'imagelinks' ),
+ array(
+ 'il_to' => $this->getDBkey(),
+ 'il_from=pr_page',
+ 'pr_cascade' => 1
+ ),
+ array( 'edit' => 'upload' )
+ ) );
}
+
+ if ( $getPages ) {
+ $this->mCascadeSources = $sources;
+ $this->mCascadingRestrictions = $pagerestrictions;
+ } else {
+ $this->mHasCascadingRestrictions = $sources;
+ }
+
+ return array( $sources, $pagerestrictions );
+ }
+
+ /**
+ * Cascading protection: Query database for cascading restrictions for
different link types.
+ *
+ * @param bool $getPages Whether or not to retrieve the actual pages
+ * that the restrictions have come from and the actual
restrictions
+ * themselves.
+ * @param array &$pagerestrictions array like that returned by
Title::getAllRestrictions()
+ * @param array $tables Additional tables for the query.
+ * @param array $where_clauses Additional where clauses for the query
+ * @param array $rewrites Rewrites for the key (action) for
$pagerestrictions
+ * (Eg. 'edit' => 'upload' for image links)
+ * @return array Title objects of the pages from which cascading
restrictions
+ * have come, false for none, or true if such restrictions exist
but
+ * $getPages was not set.
+ */
+ protected function getCascadeProtectionSourcesInternal( $getPages,
&$pagerestrictions,
+ $tables, $where_clauses, $rewrites = array()
+ ) {
+ $dbr = wfGetDB( DB_SLAVE );
+
+ $tables[] = 'page_restrictions';
+ $where_clauses['pr_cascade'] = 1;
if ( $getPages ) {
$cols = array( 'pr_page', 'page_namespace',
'page_title',
@@ -2792,15 +2832,20 @@
# Add groups needed for each
restriction type if its not already there
# Make sure this restriction type still
exists
- if ( !isset(
$pagerestrictions[$row->pr_type] ) ) {
-
$pagerestrictions[$row->pr_type] = array();
+ $type = $row->pr_type;
+ if ( isset( $rewrites[$type] ) ) {
+ $type = $rewrites[$type];
+ }
+
+ if ( !isset( $pagerestrictions[$type] )
) {
+ $pagerestrictions[$type] =
array();
}
if (
- isset(
$pagerestrictions[$row->pr_type] )
- && !in_array( $row->pr_level,
$pagerestrictions[$row->pr_type] )
+ isset(
$pagerestrictions[$type] )
+ && !in_array(
$row->pr_level, $pagerestrictions[$type] )
) {
-
$pagerestrictions[$row->pr_type][] = $row->pr_level;
+ $pagerestrictions[$type][] =
$row->pr_level;
}
} else {
$sources = true;
@@ -2808,14 +2853,7 @@
}
}
- if ( $getPages ) {
- $this->mCascadeSources = $sources;
- $this->mCascadingRestrictions = $pagerestrictions;
- } else {
- $this->mHasCascadingRestrictions = $sources;
- }
-
- return array( $sources, $pagerestrictions );
+ return $sources;
}
/**
diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php
index 493df2e..94cbd14 100644
--- a/includes/upload/UploadBase.php
+++ b/includes/upload/UploadBase.php
@@ -119,7 +119,7 @@
* @return bool|string
*/
public static function isAllowed( $user ) {
- foreach ( array( 'upload', 'edit' ) as $permission ) {
+ foreach ( array( 'upload' ) as $permission ) {
if ( !$user->isAllowed( $permission ) ) {
return $permission;
}
@@ -570,15 +570,16 @@
if ( is_null( $nt ) ) {
return true;
}
- $permErrors = $nt->getUserPermissionsErrors( 'edit', $user );
- $permErrorsUpload = $nt->getUserPermissionsErrors( 'upload',
$user );
+ $permErrors = $nt->getUserPermissionsErrors( 'upload', $user );
if ( !$nt->exists() ) {
+ $permErrorsEdit = $nt->getUserPermissionsErrors(
'edit', $user );
$permErrorsCreate = $nt->getUserPermissionsErrors(
'create', $user );
} else {
+ $permErrorsEdit = array();
$permErrorsCreate = array();
}
- if ( $permErrors || $permErrorsUpload || $permErrorsCreate ) {
- $permErrors = array_merge( $permErrors, wfArrayDiff2(
$permErrorsUpload, $permErrors ) );
+ if ( $permErrors || $permErrorsEdit || $permErrorsCreate ) {
+ $permErrors = array_merge( $permErrors, wfArrayDiff2(
$permErrorsEdit, $permErrors ) );
$permErrors = array_merge( $permErrors, wfArrayDiff2(
$permErrorsCreate, $permErrors ) );
return $permErrors;
--
To view, visit https://gerrit.wikimedia.org/r/233207
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifd59d3fd653b93cdea5b6d8b642715a1f4fb57b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Zhuyifei1999 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits