WMDE-Fisch has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/367898 )
Change subject: [WIP] Make file info editable
......................................................................
[WIP] Make file info editable
Questions:
- To show the WikiEditor toolbar should I,
-- run the hook like it is now?
-- run the WikiEditorHooks method?
-- better do not show toolbars at all?
ToDo:
- check correct parsing of content to the editor
- add validation of changed text
- create a text revison from the changed text
- reflect changes in preview
- add tests
Bug: T171467
Change-Id: I191649700ab5ca8eea145cae8df4f82b645450a9
---
M extension.json
M src/Data/ImportPlan.php
A src/Html/ChangeFileInfoForm.php
A src/Html/WikiTextEditor.php
M src/SpecialImportFile.php
5 files changed, 183 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FileImporter
refs/changes/98/367898/1
diff --git a/extension.json b/extension.json
index 996002c..11b6cd7 100644
--- a/extension.json
+++ b/extension.json
@@ -59,6 +59,7 @@
"FileImporter\\Services\\SourceSite":
"src/Services/SourceSite.php",
"FileImporter\\Services\\SourceSiteLocator":
"src/Services/SourceSiteLocator.php",
"FileImporter\\Services\\WikiRevisionFactory":
"src/Services/WikiRevisionFactory.php",
+ "FileImporter\\Html\\ChangeFileInfoForm":
"src/Html/ChangeFileInfoForm.php",
"FileImporter\\Html\\ChangeFileNameForm":
"src/Html/ChangeFileNameForm.php",
"FileImporter\\Html\\DuplicateFilesPage":
"src/Html/DuplicateFilesPage.php",
"FileImporter\\Html\\ImportIdentityFormSnippet":
"src/Html/ImportIdentityFormSnippet.php",
@@ -67,6 +68,7 @@
"FileImporter\\Html\\InputFormPage":
"src/Html/InputFormPage.php",
"FileImporter\\Html\\RecoverableTitleExceptionPage":
"src/Html/RecoverableTitleExceptionPage.php",
"FileImporter\\Html\\TextRevisionSnippet":
"src/Html/TextRevisionSnippet.php",
+ "FileImporter\\Html\\WikiTextEditor":
"src/Html/WikiTextEditor.php",
"FileImporter\\Remote\\MediaWiki\\ApiDetailRetriever":
"src/Remote/MediaWiki/ApiDetailRetriever.php",
"FileImporter\\Remote\\MediaWiki\\HttpApiLookup":
"src/Remote/MediaWiki/HttpApiLookup.php",
"FileImporter\\Remote\\MediaWiki\\RemoteApiImportTitleChecker":
"src/Remote/MediaWiki/RemoteApiImportTitleChecker.php",
diff --git a/src/Data/ImportPlan.php b/src/Data/ImportPlan.php
index a0690d7..4db2446 100644
--- a/src/Data/ImportPlan.php
+++ b/src/Data/ImportPlan.php
@@ -30,6 +30,11 @@
private $title = null;
/**
+ * @var string|null
+ */
+ private $fileInfoText = null;
+
+ /**
* ImportPlan constructor, should not be constructed directly in
production code.
* Use an ImportPlanFactory instance.
*
@@ -100,4 +105,17 @@
return pathinfo( $this->getTitleText() )['extension'];
}
+ /**
+ * @return string
+ */
+ public function getFileInfoText() {
+ if ( $this->fileInfoText === null ) {
+ $intendedWikiText = $this->request->getIntendedText();
+ if ( $intendedWikiText ) {
+ return $intendedWikiText;
+ }
+ }
+ return
$this->getDetails()->getTextRevisions()->getLatest()->getField( '*' );
+ }
+
}
diff --git a/src/Html/ChangeFileInfoForm.php b/src/Html/ChangeFileInfoForm.php
new file mode 100644
index 0000000..6f89dde
--- /dev/null
+++ b/src/Html/ChangeFileInfoForm.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace FileImporter\Html;
+
+use FileImporter\Data\ImportPlan;
+use Html;
+use Message;
+use OOUI\ButtonInputWidget;
+use SpecialPage;
+
+/**
+ * Form allowing the user to change the file info text.
+ */
+class ChangeFileInfoForm {
+
+ /**
+ * @var SpecialPage
+ */
+ private $specialPage;
+
+ /**
+ * @var ImportPlan
+ */
+ private $importPlan;
+
+ public function __construct( SpecialPage $specialPage, ImportPlan
$importPlan ) {
+ $this->specialPage = $specialPage;
+ $this->importPlan = $importPlan;
+ }
+
+ public function getHtml() {
+ // Try showing the user provided value first if present
+ $wikiTextValue =
$this->importPlan->getRequest()->getIntendedText();
+ if ( $wikiTextValue === null ) {
+ $wikiTextValue = $this->importPlan->getFileInfoText();
+ }
+
+ return Html::openElement(
+ 'form',
+ [
+ 'action' =>
$this->specialPage->getPageTitle()->getLocalURL(),
+ 'method' => 'POST',
+ ]
+ ) .
+ Html::element(
+ 'p',
+ [],
+ ( new Message( 'fileimporter-changefileinfo' )
)->plain()
+ ) .
+ ( new WikiTextEditor( $this->specialPage ) )->getHtml(
$wikiTextValue ) .
+ ( new ImportIdentityFormSnippet( [
+ 'clientUrl' =>
$this->importPlan->getRequest()->getUrl(),
+ 'importDetailsHash' =>
$this->specialPage->getRequest()->getVal( 'importDetailsHash' ),
+ ] ) )->getHtml() .
+ new ButtonInputWidget(
+ [
+ 'label' => ( new Message(
'fileimporter-changefileinfo' ) )->plain(),
+ 'type' => 'submit',
+ 'flags' => [ 'primary', 'progressive' ],
+ ]
+ ) .
+ Html::closeElement( 'form' );
+ }
+
+}
diff --git a/src/Html/WikiTextEditor.php b/src/Html/WikiTextEditor.php
new file mode 100644
index 0000000..ed8dc79
--- /dev/null
+++ b/src/Html/WikiTextEditor.php
@@ -0,0 +1,92 @@
+<?php
+
+namespace FileImporter\Html;
+
+use EditPage;
+use Html;
+use SpecialPage;
+
+class WikiTextEditor {
+
+ /**
+ * @var SpecialPage
+ */
+ private $specialPage;
+
+ public function __construct( SpecialPage $specialPage ) {
+ $this->specialPage = $specialPage;
+ }
+
+ public function getHtml( $text ) {
+ $this->loadModules();
+ $this->runEditFormInitialHook();
+
+ return EditPage::getEditToolbar() .
+ $this->buildEditor( $text );
+ }
+
+ /**
+ * Load modules mainly related to the toolbar functions
+ */
+ private function loadModules() {
+ $this->specialPage->getOutput()->addModules(
'mediawiki.action.edit' );
+ $this->specialPage->getOutput()->addModuleStyles(
'mediawiki.action.edit.styles' );
+ }
+
+ /**
+ * Run EditPage::showEditForm:initial hook mainly for the WikiEditor
toolbar
+ * See WikiEditor::editPageShowEditFormInitial
+ */
+ private function runEditFormInitialHook() {
+ $editPage = new EditPage(
+ \Article::newFromTitle(
+ $this->specialPage->getPageTitle(),
+ $this->specialPage->getContext()
+ )
+ );
+
+ \Hooks::run( 'EditPage::showEditForm:initial',
+ [ &$editPage, $this->specialPage->getOutput() ]
+ );
+ }
+
+ /**
+ * Build editor HTML see EditPage->showTextbox()
+ */
+ private function buildEditor( $wikitext ) {
+ $class = 'mw-editfont-' .
$this->specialPage->getUser()->getOption( 'editfont' );
+ $pageLang = $this->specialPage->getLanguage();
+
+ // $wikitext = $this->safeUnicodeOutput( $text );
+ $wikiText = $this->addNewLineAtEnd( $wikitext );
+
+ $attributes = [
+ 'id' => 'wpTextbox1',
+ 'class' => $class,
+ 'cols' => 80,
+ 'rows' => 25,
+ 'accesskey' => ',',
+ 'tabindex' => 1,
+ 'lang' => $pageLang->getHtmlCode(),
+ 'dir' => $pageLang->getDir(),
+ ];
+
+ return Html::textarea( 'intendedWikiText', $wikiText,
$attributes );
+ }
+
+ /**
+ * Build editor HTML see EditPage->addNewLineAtEnd()
+ */
+ private function addNewLineAtEnd( $wikitext ) {
+ if ( strval( $wikitext ) !== '' ) {
+ // Ensure there's a newline at the end, otherwise
adding lines
+ // is awkward.
+ // But don't add a newline if the text is empty, or
Firefox in XHTML
+ // mode will show an extra newline. A bit annoying.
+ $wikitext .= "\n";
+ return $wikitext;
+ }
+ return $wikitext;
+ }
+
+}
diff --git a/src/SpecialImportFile.php b/src/SpecialImportFile.php
index d8e76b9..a605071 100644
--- a/src/SpecialImportFile.php
+++ b/src/SpecialImportFile.php
@@ -10,6 +10,7 @@
use FileImporter\Exceptions\DuplicateFilesException;
use FileImporter\Exceptions\ImportException;
use FileImporter\Exceptions\RecoverableTitleException;
+use FileImporter\Html\ChangeFileInfoForm;
use FileImporter\Html\ChangeFileNameForm;
use FileImporter\Html\DuplicateFilesPage;
use FileImporter\Html\ImportPreviewPage;
@@ -134,7 +135,10 @@
);
break;
case 'editinfo':
- // TODO implement
+ $this->getOutput()->addHTML(
+ ( new ChangeFileInfoForm( $this,
$importPlan ) )->getHtml()
+ );
+ break;
default:
$this->showImportPage( $importPlan );
}
@@ -171,7 +175,7 @@
$importRequest = new ImportRequest(
$this->getRequest()->getVal( 'clientUrl' ),
$this->getRequest()->getVal( 'intendedFileName' ),
- null
+ $this->getRequest()->getVal( 'intendedWikiText' )
);
$url = $importRequest->getUrl();
--
To view, visit https://gerrit.wikimedia.org/r/367898
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I191649700ab5ca8eea145cae8df4f82b645450a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: WMDE-Fisch <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits