jenkins-bot has submitted this change and it was merged. Change subject: New BSApiWikiPageTasks ......................................................................
New BSApiWikiPageTasks Provides common tasks that can pe performed on a WikiPage ATM only "setCategories" is available PatchSet 3: Implemented comments by MGlaser Change-Id: I847788c88fe5443457ae897a479598e4e1b05756 --- M BlueSpiceFoundation.php M i18n/api/en.json M i18n/api/qqq.json M includes/AutoLoader.php A includes/api/BSApiWikiPageTasks.php 5 files changed, 140 insertions(+), 3 deletions(-) Approvals: Mglaser: Looks good to me, approved jenkins-bot: Verified diff --git a/BlueSpiceFoundation.php b/BlueSpiceFoundation.php index e3c708b..e8d0200 100644 --- a/BlueSpiceFoundation.php +++ b/BlueSpiceFoundation.php @@ -69,6 +69,7 @@ $wgAPIModules['bs-filebackend-store'] = 'BSApiFileBackendStore'; $wgAPIModules['bs-user-store'] = 'BSApiUserStore'; $wgAPIModules['bs-group-store'] = 'BSApiGroupStore'; +$wgAPIModules['bs-wikipage-tasks'] = 'BSApiWikiPageTasks'; //I18N MW1.23+ $wgMessagesDirs['BlueSpice'] = __DIR__ . '/i18n/core'; diff --git a/i18n/api/en.json b/i18n/api/en.json index 456697e..a6014c5 100644 --- a/i18n/api/en.json +++ b/i18n/api/en.json @@ -7,6 +7,7 @@ "apihelp-bs-filebackend-store-description": "Lists all files from the file backend. Allows sorting, filtering and pagination. Implements ExtJS Store parameters.", "apihelp-bs-user-store-description": "Lists all users from the database. Allows sorting, filtering and pagination. Implements ExtJS Store parameters.", "apihelp-bs-group-store-description": "Lists all groups except $wgImplicitGroups. Allows sorting, filtering and pagination. Implements ExtJS Store parameters.", + "apihelp-bs-wikipage-tasks-description": "Provides common operations for WikiPages", "apihelp-bs-store-param-sort": "JSON string with sorting info; deserializes to <code>array of objects</code> that hold field name and direction for each sorting option", "apihelp-bs-store-param-group": "JSON string with grouping info; deserializes to <code>array of objects</code> that hold field name and direction for each grouping option", "apihelp-bs-store-param-filter": "JSON string with filter info; deserializes to <code>array of objects</code> that hold field name, filter type, and filter value for each filtering option", @@ -19,5 +20,11 @@ "apihelp-bs-store-param-format": "The format of the output (only JSON or formatted JSON)", "apihelp-bs-task-param-task": "The task that should be executed", "apihelp-bs-task-param-taskdata": "JSON string encoded object with arbitrary data for the task", - "apihelp-bs-task-param-format": "The format of the result" -} \ No newline at end of file + "apihelp-bs-task-param-format": "The format of the result", + "bs-wikipage-tasks-error-contentmodel" : "The task could not be perfomed with the content model of the provided page.", + "bs-wikipage-tasks-error-page-not-valid" : "The provided page is not valid.", + "bs-wikipage-tasks-setcategories-edit-summary": "Changed categories.", + "bs-wikipage-tasks-error-page-edit-not-allowed": "You are not allowed to edit page '$1'.", + "bs-wikipage-tasks-error-categories-not-valid": "Invalid {{PLURAL:$2|category|categories}}: $1", + "bs-wikipage-tasks-setcategories-success": "Categories have successfully been set." +} diff --git a/i18n/api/qqq.json b/i18n/api/qqq.json index de68a3c..7de7e4d 100644 --- a/i18n/api/qqq.json +++ b/i18n/api/qqq.json @@ -7,6 +7,7 @@ "apihelp-bs-filebackend-store-description": "Describes the API endpoint that lists uploaded files", "apihelp-bs-user-store-description": "Describes the API endpoint that lists users", "apihelp-bs-group-store-description": "Describes the API endpoint that lists groups", + "apihelp-bs-wikipage-tasks-description": "Describes the API endpoint that allows manipulation of wikipages", "apihelp-bs-store-param-sort": "Describes the <var>sort</var> parameter of the API module", "apihelp-bs-store-param-group": "Describes the <var>group</var> parameter of the API module", "apihelp-bs-store-param-filter": "Describes the <var>filter</var> parameter of the API module", @@ -19,5 +20,11 @@ "apihelp-bs-store-param-format": "Describes the <var>format</var> parameter of the API module", "apihelp-bs-task-param-task": "Describes the <var>task</var> parameter of the API module", "apihelp-bs-task-param-taskdata": "Describes the <var>taskData</var> parameter of the API module", - "apihelp-bs-task-param-format": "Describes the <var>format</var> parameter of the API module\n\n{{msg-mw|Bs-store-param-format}}" + "apihelp-bs-task-param-format": "Describes the <var>format</var> parameter of the API module\n\n{{msg-mw|Bs-store-param-format}}", + "bs-wikipage-tasks-error-contentmodel" : "An error message in case that the task was not supported by the content model of the provided page", + "bs-wikipage-tasks-error-page-not-valid" : "An error message in case that the provided page was not valid", + "bs-wikipage-tasks-setcategories-edit-summary": "The summary of an edit made by the <code>bs-wikipage-tasks</code> API <code>setCategories</code> task", + "bs-wikipage-tasks-error-page-edit-not-allowed": "An error message that occurs if a user is not allowed to edit page with name '$1'.\n\nParameters:\n* $1 - a page title", + "bs-wikipage-tasks-error-categories-not-valid": "An error message that tells if the category names in $1 are invalid.\n\nParameters:\n* $1 - a comma seperated list of provided invalid category names\n* $2 - a positive number for the plural rule", + "bs-wikipage-tasks-setcategories-success": "A success message that indicated that the categories have successfully been set" } diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 5f27a8f..cb2633f 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -63,6 +63,7 @@ $GLOBALS['wgAutoloadClasses']['BSApiFileBackendStore'] = __DIR__."/api/BSApiFileBackendStore.php"; $GLOBALS['wgAutoloadClasses']['BSApiUserStore'] = __DIR__."/api/BSApiUserStore.php"; $GLOBALS['wgAutoloadClasses']['BSApiGroupStore'] = __DIR__ . '/api/BSApiGroupStore.php'; +$GLOBALS['wgAutoloadClasses']['BSApiWikiPageTasks'] = __DIR__ . '/api/BSApiWikiPageTasks.php'; //adapter $GLOBALS['wgAutoloadClasses']['BsExtensionMW'] = __DIR__."/ExtensionMW.class.php"; diff --git a/includes/api/BSApiWikiPageTasks.php b/includes/api/BSApiWikiPageTasks.php new file mode 100644 index 0000000..d917644 --- /dev/null +++ b/includes/api/BSApiWikiPageTasks.php @@ -0,0 +1,121 @@ +<?php +/** + * Provides common tasks that can pe performed on a WikiPage. + * + * 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. + * + * This file is part of BlueSpice for MediaWiki + * For further information visit http://www.blue-spice.org + * + * @author Robert Vogel <vo...@hallowelt.biz> + * @package Bluespice_Foundation + * @copyright Copyright (C) 2016 Hallo Welt! - Medienwerkstatt GmbH, All rights reserved. + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or later + * @filesource + */ + +/** + * Provides common tasks that can pe performed on a WikiPage + * @package BlueSpice_Foundation + */ +class BSApiWikiPageTasks extends BSApiTasksBase { + protected $aTasks = array( 'setCategories' ); + + /** + * Configures the global permission requirements + * @return array + */ + protected function getRequiredPermissions() { + return array( + 'setCategories' => array( 'edit' ) + ); + } + + protected function task_setCategories( $oTaskData, $aParams ) { + $oResponse = $this->makeStandardReturn(); + + $aCategories = $oTaskData->categories; + $aCategories = ( !is_array( $aCategories ) ) ? array() : $aCategories; + + $oTitle = Title::newFromID( $oTaskData->page_id ); + if ( $oTitle instanceof Title === false ) { + $oResponse->message = wfMessage( 'bs-wikipage-tasks-error-page-not-valid' )->plain(); + return $oResponse; + } + + //Check for actual title permissions + if ( !$oTitle->userCan( 'edit' ) ) { + $oResponse->message = wfMessage( + 'bs-wikipage-tasks-error-page-edit-not-allowed', + $oTitle->getPrefixedText() + )->plain(); + return $oResponse; + } + + //Check for category validity + $aInvalidCategories = array(); + foreach ( $aCategories as $sCategoryName ) { + if ( Category::newFromName( $sCategoryName ) === false ) { + $aInvalidCategories[] = $sCategoryName; + } + } + + if( !empty( $aInvalidCategories ) ) { + $iCount = count( $aInvalidCategories ); + $oResponse->message = wfMessage( + 'bs-wikipage-tasks-error-categories-not-valid', + implode( ', ', $aInvalidCategories ), + $iCount + )->text(); + $oResponse->payload = $aInvalidCategories; + $oResponse->payload_count = $iCount; + return $oResponse; + } + + $oWikiPage = WikiPage::factory( $oTitle ); + if ( $oWikiPage->getContentModel() === CONTENT_MODEL_WIKITEXT ){ + $sText = $oWikiPage->getContent()->getNativeData(); + } + else { + $oResponse->message = wfMessage( 'bs-wikipage-tasks-error-contentmodel' )->plain(); + return $oResponse; + } + + // Remove all category links before adding the new ones + $sCanonicalNSName = MWNamespace::getCanonicalName( NS_CATEGORY ); + $sLocalNSName = BsNamespaceHelper::getNamespaceName( NS_CATEGORY ); + $sPattern = "#\[\[($sLocalNSName|$sCanonicalNSName):.*?\]\]#si"; + $sText = preg_replace( $sPattern, '', $sText ); + + foreach ( $aCategories as $sCategoryName ) { + $sText .= "\n[[" . $sLocalNSName . ":$sCategoryName]]"; + } + + $oContent = ContentHandler::makeContent( $sText, $oTitle ); + $oStatus = $oWikiPage->doEditContent( + $oContent, + wfMessage( 'bs-wikipage-tasks-setcategories-edit-summary' )->plain() + ); + if ( !$oStatus->isGood() ) { + $oResponse->message = $oStatus->getMessage(); + } + else { + $oResponse->success = true; + $oResponse->message = wfMessage( 'bs-wikipage-tasks-setcategories-success' )->plain(); + } + + return $oResponse; + } +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/268670 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I847788c88fe5443457ae897a479598e4e1b05756 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation Gerrit-Branch: master Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz> Gerrit-Reviewer: Dvogel hallowelt <daniel.vo...@hallowelt.com> Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com> Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz> Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz> Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits