Tpt has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/331416 )
Change subject: Use custom actions for editing Index: pages ...................................................................... Use custom actions for editing Index: pages Change-Id: I96bfbf31e17da95e874bb036a211b7b866c1c7a3 --- M ProofreadPage.body.php M extension.json R includes/index/EditIndexPage.php M includes/index/IndexContentHandler.php A includes/index/IndexEditAction.php A includes/index/IndexSubmitAction.php 6 files changed, 92 insertions(+), 62 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage refs/changes/16/331416/1 diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php index 904ffe6..6a390fc 100644 --- a/ProofreadPage.body.php +++ b/ProofreadPage.body.php @@ -20,9 +20,10 @@ */ use ProofreadPage\Context; +use ProofreadPage\FileNotFoundException; +use ProofreadPage\Index\EditIndexPage; use ProofreadPage\Page\PageContent; use ProofreadPage\Page\PageContentBuilder; -use ProofreadPage\FileNotFoundException; use ProofreadPage\Pagination\PageNotInPaginationException; /* @@ -93,23 +94,6 @@ return false; } elseif ( $title->inNamespace( self::getIndexNamespaceId() ) ) { $model = CONTENT_MODEL_PROOFREAD_INDEX; - return false; - } else { - return true; - } - } - - /** - * Set up our custom edition system. - * - * @param Article $article being edited - * @param User $user User performing the edit - * @return boolean hook return value - */ - public static function onCustomEditor( Article $article, User $user ) { - if ( $article->getTitle()->inNamespace( self::getIndexNamespaceId() ) ) { // TODO ExternalEditor case - $editor = new EditProofreadIndexPage( $article ); - $editor->edit(); return false; } else { return true; diff --git a/extension.json b/extension.json index c16616f..e3ed6b4 100644 --- a/extension.json +++ b/extension.json @@ -44,7 +44,6 @@ "ProofreadPage\\DiffFormatterUtils": "includes/DiffFormatterUtils.php", "ProofreadPage\\FileNotFoundException": "includes/FileNotFoundException.php", "ProofreadPage\\FileProvider": "includes/FileProvider.php", - "EditProofreadIndexPage": "includes/index/EditProofreadIndexPage.php", "ProofreadIndexEntry": "includes/index/ProofreadIndexEntry.php", "ProofreadIndexValue": "includes/index/ProofreadIndexValue.php", "ProofreadIndexValueString": "includes/index/ProofreadIndexValue.php", @@ -62,6 +61,9 @@ "ProofreadPage\\Index\\IndexContent": "includes/index/IndexContent.php", "ProofreadPage\\Index\\IndexRedirectContent": "includes/index/IndexRedirectContent.php", "ProofreadPage\\Index\\IndexContentHandler": "includes/index/IndexContentHandler.php", + "ProofreadPage\\Index\\IndexEditAction": "includes/index/IndexEditAction.php", + "ProofreadPage\\Index\\IndexSubmitAction": "includes/index/IndexSubmitAction.php", + "ProofreadPage\\Index\\EditIndexPage": "includes/index/EditIndexPage.php", "ProofreadIndexDbConnector": "includes/index/ProofreadIndexDbConnector.php", "ProofreadPage\\Pagination\\PaginationFactory": "includes/Pagination/PaginationFactory.php", "ProofreadPage\\Pagination\\PageNumber": "includes/Pagination/PageNumber.php", @@ -293,9 +295,6 @@ ], "GetPreferences": [ "ProofreadPage::onGetPreferences" - ], - "CustomEditor": [ - "ProofreadPage::onCustomEditor" ], "CanonicalNamespaces": [ "ProofreadPage::addCanonicalNamespaces" diff --git a/includes/index/EditProofreadIndexPage.php b/includes/index/EditIndexPage.php similarity index 76% rename from includes/index/EditProofreadIndexPage.php rename to includes/index/EditIndexPage.php index 38d9707..819389e 100644 --- a/includes/index/EditProofreadIndexPage.php +++ b/includes/index/EditIndexPage.php @@ -1,33 +1,37 @@ <?php +namespace ProofreadPage\Index; + +use EditPage; +use Html; +use OutputPage; +use ProofreadIndexEntry; +use ProofreadIndexPage; +use Status; +use Xml; +use XmlSelect; + /** - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * @file - * @ingroup ProofreadPage + * @licence GNU GPL v2+ */ +class EditIndexPage extends EditPage { -class EditProofreadIndexPage extends EditPage { - + /** + * @see EditPage::isSectionEditSupported + */ protected function isSectionEditSupported() { return false; // sections and forms don't mix } /** - * Add custom fields + * @see EditPage::isSupportedContentModel + */ + public function isSupportedContentModel( $modelId ) { + return $modelId === CONTENT_MODEL_PROOFREAD_INDEX; + } + + /** + * @see EditPage::showContentForm */ protected function showContentForm() { $pageLang = $this->mTitle->getPageLanguage(); @@ -65,21 +69,14 @@ $key = $this->getFieldNameForEntry( $entry->getKey() ); $val = $this->safeUnicodeOutput( $entry->getStringValue() ); - $out->addHTML( - Html::openElement( 'tr' ) . - Html::openElement( 'th', [ 'scope' => 'row' ] ) . - Xml::label( $entry->getLabel(), $key ) - ); + $out->addHTML( Html::openElement( 'tr' ) . Html::openElement( 'th', [ 'scope' => 'row' ] ) . Xml::label( $entry->getLabel(), $key ) ); $help = $entry->getHelp(); if ( $help !== '' ) { $out->addHTML( Html::element( 'span', [ 'title' => $help, 'class' => 'prp-help-field' ] ) ); } - $out->addHTML( - Html::closeElement( 'th' ) . - Html::openElement( 'td' ) - ); + $out->addHTML( Html::closeElement( 'th' ) . Html::openElement( 'td' ) ); $values = $entry->getPossibleValues(); if ( $values !== null ) { @@ -109,10 +106,7 @@ } } - $out->addHTML( - Html::closeElement( 'td' ) . - Html::closeElement( 'tr' ) - ); + $out->addHTML( Html::closeElement( 'td' ) . Html::closeElement( 'tr' ) ); } /** @@ -126,10 +120,7 @@ } /** - * Extract the page content data from the posted form - * - * @param WebRequest $request - * @return string + * @see EditPage::importContentFormData */ protected function importContentFormData( &$request ) { if ( $this->textbox1 !== '' ) { @@ -146,6 +137,7 @@ $text .= "\n|" . $entry->getKey() . "=" . $entry->getStringValue(); } } + return $text . "\n}}"; } @@ -182,6 +174,8 @@ /** * Check the validity of the page + * + * @see EditPage::internalAttemptSave */ public function internalAttemptSave( &$result, $bot = false ) { $index = new ProofreadIndexPage( $this->mTitle, ProofreadIndexPage::getDataConfig(), $this->textbox1 ); @@ -194,12 +188,11 @@ } if ( count( $linksTitle ) !== count( array_unique( $linksTitle ) ) ) { - $this->context - ->getOutput() - ->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' ); + $this->context->getOutput()->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' ); $status = Status::newGood(); $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR; + return $status; } diff --git a/includes/index/IndexContentHandler.php b/includes/index/IndexContentHandler.php index e76c867..7ded3bb 100644 --- a/includes/index/IndexContentHandler.php +++ b/includes/index/IndexContentHandler.php @@ -170,6 +170,16 @@ } /** + * @see ContentHandler::getActionOverrides + */ + public function getActionOverrides() { + return [ + 'edit' => '\ProofreadPage\Index\IndexEditAction', + 'submit' => '\ProofreadPage\Index\IndexSubmitAction' + ]; + } + + /** * @see ContentHandler::makeEmptyContent */ public function makeEmptyContent() { diff --git a/includes/index/IndexEditAction.php b/includes/index/IndexEditAction.php new file mode 100644 index 0000000..9a120b3 --- /dev/null +++ b/includes/index/IndexEditAction.php @@ -0,0 +1,23 @@ +<?php + +namespace ProofreadPage\Index; + +use EditAction; +use ProofreadPage\Context; +use ProofreadPagePage; + +/** + * @licence GNU GPL v2+ + * + * EditAction for a Index: page + */ +class IndexEditAction extends EditAction { + + /** + * @see FormlessAction:show + */ + public function show() { + $editor = new EditIndexPage( $this->page ); + $editor->edit(); + } +} diff --git a/includes/index/IndexSubmitAction.php b/includes/index/IndexSubmitAction.php new file mode 100644 index 0000000..ced7f1c --- /dev/null +++ b/includes/index/IndexSubmitAction.php @@ -0,0 +1,21 @@ +<?php + +namespace ProofreadPage\Index; + +use SubmitAction; + +/** + * @licence GNU GPL v2+ + * + * SubmitAction for a Index: page + */ +class IndexSubmitAction extends SubmitAction { + + /** + * @see FormlessAction:show + */ + public function show() { + $editor = new EditIndexPage( $this->page ); + $editor->edit(); + } +} -- To view, visit https://gerrit.wikimedia.org/r/331416 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I96bfbf31e17da95e874bb036a211b7b866c1c7a3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ProofreadPage Gerrit-Branch: master Gerrit-Owner: Tpt <thoma...@hotmail.fr> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits