Mattflaschen has uploaded a new change for review. https://gerrit.wikimedia.org/r/196538
Change subject: Create Special:EnableFlow ...................................................................... Create Special:EnableFlow This allows any user with the flow-create-board right to create a Flow board at a non-existent page name. They provide the initial header. Bug: T91838 Change-Id: Ic0d78b6eeb24b251ac5363af3f0580c3d0ef8569 --- M Flow.alias.php M Flow.php M autoload.php M i18n/en.json M i18n/qqq.json M includes/TalkpageManager.php A includes/specials/SpecialEnableFlow.php R includes/specials/SpecialFlow.php 8 files changed, 154 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/38/196538/1 diff --git a/Flow.alias.php b/Flow.alias.php index ca50441..3e82edc 100644 --- a/Flow.alias.php +++ b/Flow.alias.php @@ -11,6 +11,7 @@ /** English (English) */ $specialPageAliases['en'] = array( 'Flow' => array( 'Flow' ), + 'EnableFlow' => array( 'EnableFlow' ), ); /** Arabic (العربية) */ diff --git a/Flow.php b/Flow.php index 8a09e39..fdc1f25 100644 --- a/Flow.php +++ b/Flow.php @@ -53,8 +53,10 @@ // Special:Flow $wgExtensionMessagesFiles['FlowAlias'] = $dir . 'Flow.alias.php'; -$wgSpecialPages['Flow'] = 'Flow\SpecialFlow'; +$wgSpecialPages['Flow'] = 'Flow\Specials\SpecialFlow'; +$wgSpecialPages['EnableFlow'] = 'Flow\Specials\SpecialEnableFlow'; $wgSpecialPageGroups['Flow'] = 'redirects'; +$wgSpecialPageGroups['EnableFlow'] = 'wiki'; // Housekeeping hooks $wgHooks['LoadExtensionSchemaUpdates'][] = 'FlowHooks::getSchemaUpdates'; diff --git a/autoload.php b/autoload.php index 170a4ca..6d2e9ec 100644 --- a/autoload.php +++ b/autoload.php @@ -278,7 +278,8 @@ 'Flow\\SpamFilter\\SpamBlacklist' => __DIR__ . '/includes/SpamFilter/SpamBlacklist.php', 'Flow\\SpamFilter\\SpamFilter' => __DIR__ . '/includes/SpamFilter/SpamFilter.php', 'Flow\\SpamFilter\\SpamRegex' => __DIR__ . '/includes/SpamFilter/SpamRegex.php', - 'Flow\\SpecialFlow' => __DIR__ . '/includes/SpecialFlow.php', + 'Flow\\Specials\\SpecialEnableFlow' => __DIR__ . '/includes/specials/SpecialEnableFlow.php', + 'Flow\\Specials\\SpecialFlow' => __DIR__ . '/includes/specials/SpecialFlow.php', 'Flow\\SubmissionHandler' => __DIR__ . '/includes/SubmissionHandler.php', 'Flow\\TalkpageManager' => __DIR__ . '/includes/TalkpageManager.php', 'Flow\\TemplateHelper' => __DIR__ . '/includes/TemplateHelper.php', diff --git a/i18n/en.json b/i18n/en.json index 6390453..b6c237f 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -9,6 +9,7 @@ "Amir E. Aharoni" ] }, + "enableflow": "Enable Flow", "flow-desc": "Workflow management system", "flow-talk-taken-over": "This talk page is using [https://www.mediawiki.org/wiki/Special:MyLanguage/Flow_Portal Flow].", "flow-talk-username": "Flow talk page manager", @@ -342,6 +343,7 @@ "flow-compare-revisions-header-post": "This page shows the {{GENDER:$3|changes}} between two versions of a post by $3 in the topic \"[$5 $2]\" on [$4 $1].\nYou can see other versions of this post at its [$6 history page].", "flow-compare-revisions-header-postsummary": "This page shows the changes between two versions of a post summary in the post \"[$4 $2]\" on [$3 $1].\nYou can see other versions of this post at its [$5 history page].", "flow-compare-revisions-header-header": "This page shows the {{GENDER:$2|changes}} between two versions of the header on [$3 $1].\nYou can see other versions of the header at its [$4 history page].", + "action-flow-create-board": "create Flow boards in any location", "right-flow-create-board": "Create Flow boards in any location", "right-flow-hide": "Hide Flow topics and posts", "right-flow-lock": "Lock Flow topics", @@ -378,6 +380,12 @@ "flow-special-type-workflow": "Workflow", "flow-special-uuid": "UUID", "flow-special-invalid-uuid": "Could not find content matching the type and the UUID.", + "flow-special-enableflow-legend": "Enable Flow on a new page", + "flow-special-enableflow-page": "Page to enable Flow on", + "flow-special-enableflow-header": "Initial header of Flow board (wikitext)", + "flow-special-enableflow-board-already-exists": "There is already a Flow board at [[$1]].", + "flow-special-enableflow-page-already-exists": "There is already a non-Flow page at [[$1]]. If you still want to locate a Flow board there, please move the existing page to an archive, delete the redirect, then use Special:EnableFlow again. Include the archive name in the header", + "flow-special-enableflow-confirmation": "You have successfully created a Flow board at [[$1]].", "flow-spam-confirmedit-form": "Please confirm you are a human by solving the below captcha: $1", "flow-preview-warning": "You are seeing a preview. Click \"{{int:flow-newtopic-save}}\" to post, or click \"{{int:flow-preview-return-edit-post}}\" to continue writing.", "flow-preview-return-edit-post": "Keep editing", diff --git a/i18n/qqq.json b/i18n/qqq.json index a8c8ba1..7701d9e 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -14,6 +14,7 @@ "Nemo bis" ] }, + "enableflow": "{{doc-special|EnableFlow}}", "flow-desc": "{{desc|name=Flow|url=http://www.mediawiki.org/wiki/Extension:Flow}}", "flow-talk-taken-over": "Content to replace existing page content by for pages that are turned into Flow boards.", "flow-talk-username": "Username used for the revision added when Flow takes over a talk page. Avoid changing this unnecessarily, as it will cause a new user to be used for future actions.", @@ -347,6 +348,7 @@ "flow-compare-revisions-header-post": "Header for a page showing a \"diff\" between two revisions of a Flow post. Parameters:\n* $1 - the title of the Board on which this post sits. Example: User talk:Andrew\n* $2 - the subject of the Topic in which this post sits\n* $3 - the username of the author of the post\n* $4 - URL to the Board, with the fragment set to the post in question\n* $5 - URL to the Topic, with the fragment set to the post in question\n* $6 - URL to the history page for this post\n{{Related|Flow-compare-revisions-header}}", "flow-compare-revisions-header-postsummary": "Header for a page showing a \"diff\" between two revisions of a Flow post summary. Parameters:\n* $1 - the title of the Board on which this post sits. Example: User talk:Andrew\n* $2 - the subject of the Topic in which this post sits\n* $3 - URL to the Board, with the fragment set to the post in question\n* $4 - URL to the Topic, with the fragment set to the post in question\n* $5 - URL to the history page for this post\n{{Related|Flow-compare-revisions-header}}", "flow-compare-revisions-header-header": "Header for a page showing a \"diff\" between two revisions of a Flow board header. Parameters:\n* $1 - the title of the Board on which this header sits. Example: User talk:Andrew\n* $2 - the username of the author of the header\n* $3 - URL to the Board, with the fragment set to the post in question\n* $4 - URL to the history page for this post\n{{Related|Flow-compare-revisions-header}}", + "action-flow-create-board": "{{doc-action|flow-create-board}}", "right-flow-create-board": "{{doc-right|flow-create-board}}", "right-flow-hide": "{{doc-right|flow-hide}}", "right-flow-lock": "{{doc-right|flow-lock}}", @@ -383,6 +385,12 @@ "flow-special-type-workflow": "Label for Workflow in the type dropdown.\n{{Identical|Workflow}}", "flow-special-uuid": "Label for the UUID field on the redirector special page.\n\nUUID is unique identifier for the revisioned object containing the reference.", "flow-special-invalid-uuid": "Error message shown on the redirector special page if the specified type / UUID combination is invalid", + "flow-special-enableflow-legend": "Legend for Special:EnableFlow form", + "flow-special-enableflow-page": "Label for the page field of Special:EnableFlow", + "flow-special-enableflow-header": "Label for the header field of Special:EnableFlow", + "flow-special-enableflow-confirmation": "Confirmation message on Special:EnableFlow saying that you have successfully created a board Parameters:\n$1 - Page name of new Flow board", + "flow-special-enableflow-board-already-exists": "Error given on Special:EnableFlow if board already exists at requested page name. Parameters:\n$1 - Page name where user requested to put Flow board", + "flow-special-enableflow-page-already-exists": "Error given on Special:EnableFlow if a non-Flow page already exists at requested page name. Parameters:\n$1 - Page name where user requested to put Flow board", "flow-spam-confirmedit-form": "Error message when ConfirmEdit flagged the submitted content (because an anonymous user submitted external links, possibly spam). A captcha will be displayed after this error message. Parameters:\n* $1 - the HTML for the captcha form.", "flow-preview-warning": "Refers to {{msg-mw|flow-newtopic-save}} (Add topic) and {{msg-mw|Flow-preview-return-edit-post}} (Keep editing).", "flow-preview-return-edit-post": "Used as text for a button that hides previewed text and returns to the editing view", diff --git a/includes/TalkpageManager.php b/includes/TalkpageManager.php index 4146ae5..43ff3b2 100644 --- a/includes/TalkpageManager.php +++ b/includes/TalkpageManager.php @@ -161,6 +161,16 @@ return null; } + // TODO: This is confusing. An is...Allowed method should not be mutating state. + /** + * Checks whether the given user is allowed to create a board at the given + * title. + * + * If so, changes the state of the talk page manager to record this fact. + * + * @param Title $title Title to check + * @param User $user User who wants to create a board + */ public function isCreationAllowed( Title $title, User $user ) { global $wgContentHandlerUseDB; diff --git a/includes/specials/SpecialEnableFlow.php b/includes/specials/SpecialEnableFlow.php new file mode 100644 index 0000000..3fef36d --- /dev/null +++ b/includes/specials/SpecialEnableFlow.php @@ -0,0 +1,121 @@ +<?php + +namespace Flow\Specials; + +use FormSpecialPage; +use Status; +use Title; +use Flow\Container; + +/** + * A special page that allows users with the flow-create-board right to create + * boards where there no page exists + */ +class SpecialEnableFlow extends FormSpecialPage { + /** + * @var WorkflowLoaderFactory $loaderFactory + */ + protected $loaderFactory; + + /** @var Flow\TalkpageManager $controller */ + protected $occupationController; + + /** + * @var string $page Full page name that was converted to a board + */ + protected $page; + + public function __construct() { + parent::__construct( 'EnableFlow', 'flow-create-board' ); + + $this->loaderFactory = Container::get( 'factory.loader.workflow' ); + $this->occupationController = Container::get( 'occupation_controller' ); + } + + protected function getFormFields() { + return array( + 'page' => array( + 'type' => 'text', + 'label-message' => 'flow-special-enableflow-page', + ), + 'header' => array( + 'type' => 'textarea', + 'label-message' => 'flow-special-enableflow-header' + ), + ); + } + + protected function getDisplayFormat() { + return 'vform'; + } + + protected function getMessagePrefix() { + return 'flow-special-enableflow'; + } + + /** + * Check that Flow board does not exist, then create it + * + * @param array $data Form data + * @return Status Status indicating result + */ + public function onSubmit( array $data ) { + $page = $data['page']; + $title = Title::newFromText( $page ); + + // Canonicalize so the error or confirmation message looks nicer (no underscores). + $page = $title->getPrefixedText(); + + if ( $this->occupationController->isTalkpageOccupied( $title, true ) ) { + return Status::newFatal( 'flow-special-enableflow-board-already-exists', $page ); + } + + // This also *records* that it's allowed. + if ( !$this->occupationController->isCreationAllowed( $title, $this->getUser() ) ) { + // This is the only plausible reason this method would return false here. + // If there is another possible reason, we should have the method return a + // Status. + return Status::newFatal( 'flow-special-enableflow-page-already-exists', $page ); + } + + $loader = $this->loaderFactory->createWorkflowLoader( $title ); + $blocks = $loader->getBlocks(); + + $action = 'edit-header'; + + $params = array( + 'header' => array( + 'content' => $data['header'], + 'format' => 'wikitext', + ), + ); + + $blocksToCommit = $loader->handleSubmit( + $this->getContext(), + $action, + $params + ); + + $status = Status::newGood(); + + foreach( $blocks as $block ) { + if ( $block->hasErrors() ) { + $errors = $block->getErrors(); + + foreach( $errors as $errorKey ) { + $status->fatal( $block->getErrorMessage( $errorKey ) ); + } + } + } + + $commitMetadata = $loader->commit( $blocksToCommit ); + + $this->page = $data['page']; + return $status; + } + + public function onSuccess() { + $confirmationMessage = $this->msg( 'flow-special-enableflow-confirmation', $this->page )->parse(); + $this->getOutput()->addHTML( $confirmationMessage ); + } +} diff --git a/includes/SpecialFlow.php b/includes/specials/SpecialFlow.php similarity index 99% rename from includes/SpecialFlow.php rename to includes/specials/SpecialFlow.php index 7faba3c..fa1cdec 100644 --- a/includes/SpecialFlow.php +++ b/includes/specials/SpecialFlow.php @@ -4,7 +4,7 @@ * A special page that redirects to a workflow or PostRevision given a UUID */ -namespace Flow; +namespace Flow\Specials; use Flow\Data\ObjectManager; use Flow\Exception\FlowException; -- To view, visit https://gerrit.wikimedia.org/r/196538 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic0d78b6eeb24b251ac5363af3f0580c3d0ef8569 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits