Skip to content

Commit

Permalink
Create Special:EnableFlow
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Matthew Flaschen authored and ebernhardson committed Mar 16, 2015
1 parent ce30f57 commit 8a4e004
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 3 deletions.
1 change: 1 addition & 0 deletions Flow.alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/** English (English) */
$specialPageAliases['en'] = array(
'Flow' => array( 'Flow' ),
'EnableFlow' => array( 'EnableFlow' ),
);

/** Arabic (العربية) */
Expand Down
4 changes: 3 additions & 1 deletion Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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}}",
Expand Down Expand Up @@ -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",
Expand Down
121 changes: 121 additions & 0 deletions includes/Specials/SpecialEnableFlow.php
Original file line number Diff line number Diff line change
@@ -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 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions includes/TalkpageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ public function ensureFlowRevision( Article $article, Workflow $workflow ) {
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;

Expand Down

0 comments on commit 8a4e004

Please sign in to comment.