Mattflaschen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172925
Change subject: WIP: Import: Cleanup header by removing LQT magic word and
adding template
......................................................................
WIP: Import: Cleanup header by removing LQT magic word and adding template
In support of this, the script user Flow uses (for this and for
ensureFlowRevision) has been made to actually exist.
Known issues: The cleanup edit is not showing in the script user's
contributions page.
Change-Id: I45b140358c32196018159cfc0c6cf0d7f16e339a
---
M i18n/qqq.json
M includes/Import/Importer.php
M includes/TalkpageManager.php
3 files changed, 87 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/25/172925/1
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 9dfb037..6fba5dd 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -15,7 +15,7 @@
},
"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.",
+ "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.",
"log-name-flow": "{{doc-logpage}}\nName of the Flow log filter on the
[[Special:Log]] page.",
"logentry-delete-flow-delete-post": "Text for a deletion log entry when
a post was deleted. Parameters:\n* $1 - the user: link to the user page\n* $2 -
the username. Can be used for GENDER.\n* $3 - the page where the post was
moderated\n* $4 - permalink URL to the moderated
post\n{{Related|Flow-logentry}}",
"logentry-delete-flow-restore-post": "Text for a deletion log entry
when a deleted post was restored. Parameters:\n* $1 - the user: link to the
user page\n* $2 - the username. Can be used for GENDER.\n* $3 - the page where
the post was moderated\n* $4 - permalink URL to the moderated
post\n{{Related|Flow-logentry}}",
diff --git a/includes/Import/Importer.php b/includes/Import/Importer.php
index 8bb8d55..0178d01 100644
--- a/includes/Import/Importer.php
+++ b/includes/Import/Importer.php
@@ -11,9 +11,12 @@
use Flow\Model\UUID;
use Flow\Model\Workflow;
use Flow\WorkflowLoaderFactory;
+use FlowHooks;
+
use MWCryptRand;
use ReflectionProperty;
use Title;
+use User;
use UIDGenerator;
/**
@@ -44,7 +47,9 @@
* @return TalkpageImportOperation
*/
public function import( IImportSource $source, Title $targetPage,
ImportSourceStore $sourceStore ) {
- $operation = new TalkpageImportOperation( $source );
+ $occupationController = FlowHooks::getOccupationController();
+ $destinationScriptUser =
$occupationController->getTalkpageManager();
+ $operation = new TalkpageImportOperation( $source,
$destinationScriptUser );
$operation->import( new PageImportState(
$this->workflowLoaderFactory
->createWorkflowLoader( $targetPage )
@@ -342,10 +347,18 @@
protected $importSource;
/**
+ * User used to take actions that the script originates (such as adding
{{LQT page converted to Flow}}).
+ *
+ * @var User
+ */
+ protected $destinationScriptUser;
+
+ /**
* @param IImportSource $source
*/
- public function __construct( IImportSource $source ) {
+ public function __construct( IImportSource $source, User
$destinationScriptUser ) {
$this->importSource = $source;
+ $this->destinationScriptUser = $destinationScriptUser;
}
/**
@@ -395,6 +408,13 @@
$pageState,
$pageState->boardWorkflow->getArticleTitle()
);
+
+ $finalHeaderCleanupRevision =
$this->createHeaderCleanupRevision(
+ $pageState,
+ end( $revisions ),
+ $pageState->boardWorkflow->getArticleTitle()
+ );
+ $revisions[] = $finalHeaderCleanupRevision;
$pageState->put( $revisions, array() );
$pageState->recordAssociation(
@@ -402,6 +422,32 @@
$importHeader
);
}
+
+ /**
+ * @param PageImportState $pageState
+ * @param AbstractRevision $lastRevision last imported header revision
+ * @param Title $boardTitle board title associated with header
+ * @return AbstractRevision generated revision for cleanup edit
+ */
+ protected function createHeaderCleanupRevision( PageImportState
$pageState, AbstractRevision $lastRevision, $boardTitle ) {
+ $wikitextForLastRevision = $lastRevision->getContent(
'wikitext' );
+ // This is will remove all instances, without attempting to
check if it's in
+ // nowiki, etc. It also ignores case and spaces in places
where it doesn't
+ // matter.
+ $newWikitext = preg_replace(
+ '/{{\s*#useliquidthreads:\s*1\s*}}/i',
+ '',
+ $wikitextForLastRevision
+ );
+ $newWikitext .= "\n{{LQT page converted to Flow}}";
+ $cleanupRevision = $lastRevision->newNextRevision(
+ $this->destinationScriptUser,
+ $newWikitext,
+ 'edit-header',
+ $boardTitle
+ );
+ return $cleanupRevision;
+ }
/**
* @param PageImportState $pageState
diff --git a/includes/TalkpageManager.php b/includes/TalkpageManager.php
index 699c6de..08de8e8 100644
--- a/includes/TalkpageManager.php
+++ b/includes/TalkpageManager.php
@@ -132,18 +132,49 @@
* Gives a user object used to manage talk pages
*
* @return User User to manage talkpages
+ * @throws MWException If both of the names already exist, but are not
properly
+ * configured.
*/
public function getTalkpageManager() {
- $user = User::newFromName(
- wfMessage( 'flow-talk-username'
)->inContentLanguage()->text()
+ $userNameCandidates = array(
+ wfMessage( 'flow-talk-username'
)->inContentLanguage()->text(),
+ 'Flow talk page manager',
);
- // Use the English fallback if the localized username is
invalid or if a user
- // with the name exists.
- if ( $user === false || $user->getId() !== 0 ) {
- $user = User::newFromName( 'Flow talk page manager',
false );
+
+ $user = null;
+
+ foreach ( $userNameCandidates as $name ) {
+ $candidateUser = User::newFromName( $name );
+
+ if ( $candidateUser->getId() !== 0 ) {
+ // Exists
+
+ $groups = $candidateUser->getGroups();
+ if ( in_array( 'bot', $groups ) ) {
+ // We created this user earlier.
+ $user = $candidateUser;
+ break;
+ }
+
+ // If it exists, but is not a bot, someone
created this
+ // without setting it up as expected, so go on
to the next
+ // user.
+ } else {
+ $user = User::createNew( $name );
+ $user->addGroup( 'bot' );
+ break;
+ }
}
- // prevent newtalk notification for takeover edit
+ if ( $user === null ) {
+ throw new MWException( 'All of the candidate usernames
exist, but they are not configured as expected.' );
+ }
+
+ // Prevent newtalk notification for takeover edit.
+ // We could potentially do this through a group instead.
+ // getRights() call is so we don't confuse the in-object
caching when we
+ // modify mRights.
+ $user->getRights();
$user->mRights[] = 'nominornewtalk';
return $user;
--
To view, visit https://gerrit.wikimedia.org/r/172925
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I45b140358c32196018159cfc0c6cf0d7f16e339a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits