Page MenuHomePhabricator

0001-Block-page-titles-which-are-marked-as-fully-protected.patch

Authored By
Andrew-WMDE
Sep 15 2020, 10:45 AM
Size
5 KB
Referenced Files
None
Subscribers
None

0001-Block-page-titles-which-are-marked-as-fully-protected.patch

From 4dc0f7b32263f70a21a76b51d092f72524607cf6 Mon Sep 17 00:00:00 2001
From: Andrew Kostka <andrew@minifile.com>
Date: Tue, 15 Sep 2020 12:37:07 +0200
Subject: [PATCH] Block page titles which are marked as fully protected on the
target wiki
Bug: T262628
Change-Id: Iacc25782aa425893f911697d158f737f83600247
---
i18n/en.json | 1 +
i18n/qqq.json | 1 +
src/Operations/FileRevisionFromRemoteUrl.php | 5 +++++
src/Operations/TextRevisionFromTextRevision.php | 5 +++++
src/Services/ImportPlanValidator.php | 7 +++++++
5 files changed, 19 insertions(+)
diff --git a/i18n/en.json b/i18n/en.json
index f09e01f..5dfe3c1 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -40,6 +40,7 @@
"fileimporter-filenameerror-nosourceextension": "The source file name does not have an extension.",
"fileimporter-filenameerror-noplannedextension": "The planned file name does not have an extension.",
"fileimporter-filenameerror-missmatchextension": "Target file extension does not match the extension of the original file.",
+ "fileimporter-filenameerror-protected": "The file name you are currently trying to import to is protected.",
"fileimporter-localtitleexists": "The title you are currently trying to import to already exists on this wiki.",
"fileimporter-sourcetitleexists": "The title you are currently trying to import to already exists on the source wiki.",
"fileimporter-illegalfilenamechars": "The title you are currently trying to import to contains invalid filename characters.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index c813bed..cbef725 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -47,6 +47,7 @@
"fileimporter-filenameerror-nosourceextension": "Error message for cases where the file provided by the user does not have a file extension.",
"fileimporter-filenameerror-noplannedextension": "Error message for cases where the planned import name provided by the user does not have a file extension.",
"fileimporter-filenameerror-missmatchextension": "Error message for cases where the original and planned importer name file extensions do not match.",
+ "fileimporter-filenameerror-protected": "Error message for cases where when the file name to be imported to is reported as protected by MediaWiki.",
"fileimporter-localtitleexists": "Error message for cases where when the title to be imported to already exists on the local wiki.",
"fileimporter-sourcetitleexists": "Error message for situations in which the user wants to import a file with a modified file name, but another file with the requested file name also exists on the source wiki. Such an attempt gets blocked with this error message so the other file can still be imported with it's original file name.",
"fileimporter-illegalfilenamechars": "Error message for cases where when the title to be imported to contains invalid characters as defined by MediaWiki.",
diff --git a/src/Operations/FileRevisionFromRemoteUrl.php b/src/Operations/FileRevisionFromRemoteUrl.php
index f4379de..6b62ece 100644
--- a/src/Operations/FileRevisionFromRemoteUrl.php
+++ b/src/Operations/FileRevisionFromRemoteUrl.php
@@ -173,6 +173,11 @@ class FileRevisionFromRemoteUrl implements ImportOperation {
return Status::newFatal( 'fileimporter-filenameerror-illegal' );
}
+ if ( $this->plannedTitle->isProtected() ) {
+ $this->logger->error( __METHOD__ . ' failed to validate title, title is marked as protected.' );
+ return Status::newFatal( 'fileimporter-filenameerror-protected' );
+ }
+
$fileValidationStatus = $this->uploadBase->validateFile();
if ( !$fileValidationStatus->isOK() ) {
return Status::newFatal( 'fileimporter-cantimportfileinvalid', $fileValidationStatus->getMessage() );
diff --git a/src/Operations/TextRevisionFromTextRevision.php b/src/Operations/TextRevisionFromTextRevision.php
index 57c2e4c..231764e 100644
--- a/src/Operations/TextRevisionFromTextRevision.php
+++ b/src/Operations/TextRevisionFromTextRevision.php
@@ -105,6 +105,11 @@ class TextRevisionFromTextRevision implements ImportOperation {
* @return Status isOK on success
*/
public function validate() : Status {
+ if ( $this->plannedTitle->isProtected() ) {
+ $this->logger->error( __METHOD__ . ' failed to validate title, title is marked as protected.' );
+ return Status::newFatal( 'fileimporter-filenameerror-protected' );
+ }
+
return $this->textRevisionValidator->validate(
$this->plannedTitle,
$this->user,
diff --git a/src/Services/ImportPlanValidator.php b/src/Services/ImportPlanValidator.php
index 8e45adc..4862ff6 100644
--- a/src/Services/ImportPlanValidator.php
+++ b/src/Services/ImportPlanValidator.php
@@ -111,6 +111,7 @@ class ImportPlanValidator {
// Solvable errors
$this->warnOnAutomaticTitleChanges( $importPlan );
$this->runFileTitleCheck( $importPlan );
+ $this->runFileTitleProtectedCheck( $importPlan );
$this->runLocalTitleConflictCheck( $importPlan );
$this->runRemoteTitleConflictCheck( $importPlan );
}
@@ -218,6 +219,12 @@ class ImportPlanValidator {
return $language->listToText( $fileExtensions );
}
+ private function runFileTitleProtectedCheck( ImportPlan $importPlan ) {
+ if ( $importPlan->getTitle()->isProtected() ) {
+ throw new RecoverableTitleException( 'fileimporter-filenameerror-protected', $importPlan );
+ }
+ }
+
private function runFileTitleCheck( ImportPlan $importPlan ) {
$plannedTitleText = $importPlan->getTitle()->getText();
if ( $plannedTitleText != wfStripIllegalFilenameChars( $plannedTitleText ) ) {
--
2.22.0

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8569557
Default Alt Text
0001-Block-page-titles-which-are-marked-as-fully-protected.patch (5 KB)

Event Timeline