Sbisson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/205284

Change subject: Special:EnableFlow archives pre-existing talk page
......................................................................

Special:EnableFlow archives pre-existing talk page

Enabling flow on an existing talk page is now accepted.
It tries to archive the talk page to a subpage.

The name of the archive is configurable using a new
form field. The default value is %s/Archive_%d and
is not localized.

It uses a template named "Wikitext talk page converted to Flow"
to add a reference to the archive page at the top of
the flow board.

It uses a template named "Archive for converted wikitext talk page"
to add a reference to the flow board at the top of
the archive page.

Bug: T72073
Change-Id: If3b23383e4289290cde1237b74a4bbbb6bdcb455
---
M i18n/en.json
M i18n/qqq.json
M includes/Import/Wikitext/ConversionStrategy.php
M includes/Specials/SpecialEnableFlow.php
4 files changed, 84 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/84/205284/1

diff --git a/i18n/en.json b/i18n/en.json
index 79dd21f..33f6a5f 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -389,10 +389,11 @@
        "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-archive-title-format": "Where to archive 
existing content",
        "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-invalid-title": "The provided page is not a 
valid page title",
-       "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-board-creation-not-allowed": "You are not 
allowed to create a Flow board at [[$1]].",
        "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.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index fa4496d..a8b1d18 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -394,10 +394,11 @@
        "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-archive-title-format": "Label for the archive 
format field of Special:EnableFlow",
        "flow-special-enableflow-header": "Label for the header field of 
Special:EnableFlow",
        "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-invalid-title": "Error given on 
Special:EnableFlow if the provided page is not a valid page name.",
-       "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-special-enableflow-board-creation-not-allowed": "Error given on 
Special:EnableFlow if the current user is not allowed to create a Flow board.  
Parameters:\n$1 - Page name where user requested to put Flow board",
        "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-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).",
diff --git a/includes/Import/Wikitext/ConversionStrategy.php 
b/includes/Import/Wikitext/ConversionStrategy.php
index 546c9d8..b9c4151 100644
--- a/includes/Import/Wikitext/ConversionStrategy.php
+++ b/includes/Import/Wikitext/ConversionStrategy.php
@@ -38,12 +38,28 @@
        protected $parser;
 
        /**
+        * @var string $archiveTitleSuggestions
+        */
+       protected $archiveTitleSuggestions;
+
+       /**
         * @param Parser|StubObject $parser
         * @param ImportSourceStore $sourceStore
         */
-       public function __construct( $parser, ImportSourceStore $sourceStore ) {
+       public function __construct( $parser, ImportSourceStore $sourceStore, 
$preferredArchiveTitle = null ) {
                $this->parser = $parser;
                $this->sourceStore = $sourceStore;
+
+               if ( isset( $preferredArchiveTitle ) && !empty( 
$preferredArchiveTitle ) ) {
+                       $this->archiveTitleSuggestions = array( 
$preferredArchiveTitle );
+               } else {
+                       $this->archiveTitleSuggestions = array(
+                               '%s/Archive %d',
+                               '%s/Archive%d',
+                               '%s/archive %d',
+                               '%s/archive%d',
+                       );
+               }
        }
 
        /**
@@ -90,12 +106,7 @@
         * {@inheritDoc}
         */
        public function decideArchiveTitle( Title $source ) {
-               return Converter::decideArchiveTitle( $source, array(
-                       '%s/Archive %d',
-                       '%s/Archive%d',
-                       '%s/archive %d',
-                       '%s/archive%d',
-               ) );
+               return Converter::decideArchiveTitle( $source, 
$this->archiveTitleSuggestions );
        }
 
        /**
diff --git a/includes/Specials/SpecialEnableFlow.php 
b/includes/Specials/SpecialEnableFlow.php
index d6f22fb..99d4895 100644
--- a/includes/Specials/SpecialEnableFlow.php
+++ b/includes/Specials/SpecialEnableFlow.php
@@ -6,6 +6,7 @@
 use Status;
 use Title;
 use Flow\Container;
+use Psr\Log\NullLogger;
 
 /**
  * A special page that allows users with the flow-create-board right to create
@@ -38,6 +39,11 @@
                                'type' => 'text',
                                'label-message' => 
'flow-special-enableflow-page',
                        ),
+                       'archive-title-format' => array(
+                               'type' => 'text',
+                               'label-message' => 
'flow-special-enableflow-archive-title-format',
+                               'default' => '%s/Archive_%d',
+                       ),
                        'header' => array(
                                'type' => 'textarea',
                                'label-message' => 
'flow-special-enableflow-header'
@@ -54,12 +60,15 @@
        }
 
        /**
-        * Check that Flow board does not exist, then create it
+        * Creates a flow board.
+        * Archives any pre-existing wikitext talk page.
         *
         * @param array $data Form data
         * @return Status Status indicating result
         */
        public function onSubmit( array $data ) {
+               global $wgParser;
+
                $page = $data['page'];
                $title = Title::newFromText( $page );
                if ( !$title ) {
@@ -73,47 +82,69 @@
                        return Status::newFatal( 
'flow-special-enableflow-board-already-exists', $page );
                }
 
-               if ( !$this->occupationController->allowCreation( $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 );
+               if ( !$this->occupationController->allowCreation( $title, 
$this->getUser(), false ) ) {
+                       return Status::newFatal( 
'flow-special-enableflow-board-creation-not-allowed', $page );
                }
 
-               $loader = $this->loaderFactory->createWorkflowLoader( $title );
-               $blocks = $loader->getBlocks();
+               if ( $title->exists() ) {
 
-               $action = 'edit-header';
+                       if ( class_exists( 'LqtDispatch' ) && 
LqtDispatch::isLqtPage( $title ) ) {
+                               return Status::newFatal( 
'flow-special-enableflow-page-is-liquidthread', $page );
+                       }
 
-               $params = array(
-                       'header' => array(
-                               'content' => $data['header'],
-                               'format' => 'wikitext',
-                       ),
-               );
+                       $converter = new \Flow\Import\Converter(
+                               wfGetDB( DB_SLAVE ),
+                               Container::get( 'importer' ),
+                               new NullLogger(),
+                               
$this->occupationController->getTalkpageManager(),
+                               new \Flow\Import\Wikitext\ConversionStrategy(
+                                       $wgParser,
+                                       new 
\Flow\Import\NullImportSourceStore(),
+                                       $data['archive-title-format']
+                               )
+                       );
 
-               $blocksToCommit = $loader->handleSubmit(
-                       $this->getContext(),
-                       $action,
-                       $params
-               );
 
-               $status = Status::newGood();
+                       $converter->convert( array( $title ) );
 
-               foreach( $blocks as $block ) {
-                       if ( $block->hasErrors() ) {
-                               $errors = $block->getErrors();
+                       $this->page = $data['page'];
+                       return Status::newGood();
 
-                               foreach( $errors as $errorKey ) {
-                                       $status->fatal( 
$block->getErrorMessage( $errorKey ) );
+               } else {
+                       $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 ) );
+                                       }
                                }
                        }
+
+                       $loader->commit( $blocksToCommit );
+
+                       $this->page = $data['page'];
+                       return $status;
                }
-
-               $loader->commit( $blocksToCommit );
-
-               $this->page = $data['page'];
-               return $status;
        }
 
        public function onSuccess() {

-- 
To view, visit https://gerrit.wikimedia.org/r/205284
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If3b23383e4289290cde1237b74a4bbbb6bdcb455
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to