Pwirth has uploaded a new change for review.
https://gerrit.wikimedia.org/r/269161
Change subject: WantedArticle: Used API instead of AjaxExportList
......................................................................
WantedArticle: Used API instead of AjaxExportList
Change-Id: I575346abe32e0a8b8f751b105d5f95c157886550
---
M WantedArticle/WantedArticle.class.php
M WantedArticle/WantedArticle.setup.php
A WantedArticle/includes/api/BSApiTasksWantedArticle.php
M WantedArticle/resources/bluespice.wantedArticle.js
4 files changed, 316 insertions(+), 175 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions
refs/changes/61/269161/1
diff --git a/WantedArticle/WantedArticle.class.php
b/WantedArticle/WantedArticle.class.php
index 86ca28a..0e5beb3 100644
--- a/WantedArticle/WantedArticle.class.php
+++ b/WantedArticle/WantedArticle.class.php
@@ -445,151 +445,6 @@
}
/**
- * Handles the suggestion ajax request.
- * A new title is entered into the list. Depending on configuration,
already existing articles are deleted.
- * @return bool true on correct processing. JSON answer is in $sOut
parameter.
- */
- public static function ajaxAddWantedArticle( $sSuggestedArticleWikiLink
) {
- if ( BsCore::checkAccessAdmission( 'wantedarticle-suggest' )
=== false )
- return json_encode( array( 'success' => false,
'message' => wfMessage( 'bs-permissionerror' )->plain() ) );
-
- if ( empty( $sSuggestedArticleWikiLink ) ) {
- $sErrorMsg = wfMessage(
'bs-wantedarticle-ajax-error-no-parameter' )->plain();
- return json_encode( array( 'success' => false,
'message' => $sErrorMsg ) ); // TODO RBV (01.07.11 09:07): XHRRequest object.
- }
-
- //Check suggestion for invalid characters (clientside
validation is not enough)
- $aFoundChars = array();
- foreach ( BsCore::getForbiddenCharsInArticleTitle() as $sChar )
{
- if ( strpos( $sSuggestedArticleWikiLink, $sChar ) ) {
- $aFoundChars[] = '"'.$sChar.'"';
- }
- }
-
- if ( count( $aFoundChars ) > 0 ) {
- $sChars = implode( ', ', $aFoundChars );
- $sErrorMsg = wfMessage(
'bs-wantedarticle-title-invalid-chars', count( $aFoundChars ), $sChars
)->plain();
- return json_encode( array('success' => false, 'message'
=> $sErrorMsg ) );
- }
-
- //Check if suggested page already exists
- $oSuggestedTitle = Title::newFromText(
$sSuggestedArticleWikiLink );
- $sSuggestedTitle = $oSuggestedTitle->getPrefixedText();
- if ( $oSuggestedTitle->exists() ) {
- $sErrorMsg = wfMessage(
-
'bs-wantedarticle-ajax-error-suggested-page-already-exists',
- $sSuggestedTitle
- )->plain();
- return json_encode( array('success' => false,
'message' => $sErrorMsg ) );
- }
-
- $oWantedArticle = BsExtensionManager::getExtension(
'WantedArticle' );
- $oDataSourceArticle =
$oWantedArticle->getDataSourceTemplateArticle();
- $aWishList = $oWantedArticle->getTitleListFromTitle(
$oDataSourceArticle->getTitle() );
-
- $bDeleteExisting = BsConfig::get(
'MW::WantedArticle::DeleteExisting' );
-
- foreach ( $aWishList as $key => $aWish ) {
- if ( $oSuggestedTitle->equals( $aWish['title'] ) ){
- $sErrorMsg = wfMessage(
-
'bs-wantedarticle-ajax-error-suggested-page-already-on-list',
- $oSuggestedTitle->getPrefixedText()
- )->plain();
- return json_encode( array('success' => true,
'message' => $sErrorMsg ) );
- }
- if ( $bDeleteExisting && $aWish['title']->exists() ===
true ){
- unset($aWishList[$key]);
- continue;
- }
- }
- array_unshift(
- $aWishList,
- array(
- 'title' => $oSuggestedTitle,
- 'signature' => '--~~~~',
- )
- );
-
- // Write new content
- $oEditStatus = $oWantedArticle->saveTitleListToTitle(
- $aWishList,
- $oDataSourceArticle->getTitle(),
- wfMessage(
'bs-wantedarticle-edit-comment-suggestion-added', $sSuggestedTitle )->plain()
- );
-
- if ( $oEditStatus->isGood() ) {
- return json_encode(
- array(
- 'success' => true,
- 'message' => wfMessage(
'bs-wantedarticle-success-suggestion-entered', $sSuggestedTitle )->plain()
- )
- );
- } else {
- $sErrorMsg = $oWantedArticle->mCore->parseWikiText(
$oEditStatus->getWikiText(), $this->getTitle() );
- return json_encode( array( 'success' => false,
'message' => $sErrorMsg ) );
- }
- }
-
- /**
- * Handles the get wanted articles ajax request.
- * @param string $sOut The server response string.
- * @return bool true on correct processing. JSON answer is in $sOut
parameter.
- */
- public static function ajaxGetWantedArticles( $iCount, $sSort, $sOrder,
$sType, $sTitle ) {
- if ( BsCore::checkAccessAdmission( 'read' ) === false ) return
true;
- $aResult = array(
- 'success' => false,
- 'view' => '',
- 'message' => ''
- );
-
- //Validation
- $oValidationICount = BsValidator::isValid( 'IntegerRange',
$iCount, array('fullResponse' => true, 'lowerBoundary' => 1, 'upperBoundary' =>
30) );
- if ( $oValidationICount->getErrorCode() ) {
- return false;
- }
- if ( !in_array( $sSort, array( '', 'time', 'title' ) ) ) {
- return false;
- }
- if ( !in_array( $sOrder, array( '', 'ASC', 'DESC' ) ) ) {
- return false;
- }
-
- $oWantedArticle = BsExtensionManager::getExtension(
'WantedArticle' );
- //Create list
- $aWishList = $oWantedArticle->getTitleListFromTitle(
-
$oWantedArticle->getDataSourceTemplateArticle()->getTitle()
- );
-
- switch( $sSort ) {
- case 'title':
- $aTitleList =
$oWantedArticle->sortWishListByTitle( $aWishList );
- break;
- case 'time':
- default:
- $aTitleList =
$oWantedArticle->getDefaultTitleList( $aWishList );
- }
- if ( $sOrder == 'ASC' ) {
- $aTitleList = array_reverse( $aTitleList );
- }
-
- $oWishListView = new ViewWantedArticleTag();
- $oWishListView
- ->setTitle( $sTitle )
- ->setType ( $sType )
- ->setOrder( $sOrder )
- ->setSort ( $sSort )
- ->setCount( $iCount )
- ->setList ( $aTitleList );
-
- //result
- $aResult['success'] = true;
- $aResult['view'] = $oWishListView->execute();
-
- return json_encode( $aResult );
- }
-
- /**
*
* @param Title $oTitle
* @return array An Array of Title objects
@@ -663,7 +518,7 @@
*
* @return Article
*/
- private function getDataSourceTemplateArticle() {
+ public function getDataSourceTemplateArticle() {
$sDataSourceTemplateTitle =
BsConfig::get('MW::WantedArticle::DataSourceTemplateTitle');
$oDataSourceTemplateTitle = Title::makeTitle( NS_TEMPLATE,
$sDataSourceTemplateTitle );
return new Article( $oDataSourceTemplateTitle );
@@ -675,7 +530,7 @@
* @param Title $oT2
* @return bool
*/
- private function compareTitles( $oT1, $oT2 ){
+ public function compareTitles( $oT1, $oT2 ){
return strcmp( $oT1->getPrefixedText(), $oT2->getPrefixedText()
);
}
@@ -686,7 +541,7 @@
* @param array $aTitleList
* @return array - Array of sorted title objects
*/
- private function sortWishListByTitle( $aWishList, $aTitleList = array()
) {
+ public function sortWishListByTitle( $aWishList, $aTitleList = array()
) {
foreach($aWishList as $aWish) $aTitleList[] = $aWish['title'];
usort( $aTitleList, array( $this, 'compareTitles' ) );
return $aTitleList;
@@ -700,7 +555,7 @@
* @param array $aTitleList
* @return array - Array of title objects
*/
- private function getDefaultTitleList( $aWishList, $aTitleList = array()
) {
+ public function getDefaultTitleList( $aWishList, $aTitleList = array()
) {
foreach( $aWishList as $aWish ) {
$aTitleList[] = $aWish['title'];
}
diff --git a/WantedArticle/WantedArticle.setup.php
b/WantedArticle/WantedArticle.setup.php
index 3b64a65..c6c1ee6 100644
--- a/WantedArticle/WantedArticle.setup.php
+++ b/WantedArticle/WantedArticle.setup.php
@@ -4,6 +4,10 @@
$GLOBALS['wgAutoloadClasses']['WantedArticle'] = __DIR__ .
'/WantedArticle.class.php';
+$wgAutoloadClasses['ViewWantedArticleForm'] = __DIR__ .
'/includes/ViewWantedArticleForm.php';
+$wgAutoloadClasses['ViewWantedArticleTag'] = __DIR__ .
'/includes/ViewWantedArticleTag.php';
+$wgAutoloadClasses['BSApiTasksWantedArticle'] = __DIR__ .
'/includes/api/BSApiTasksWantedArticle.php';
+
$wgMessagesDirs['WantedArticle'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['WantedArticle'] = __DIR__ .
'/languages/WantedArticle.i18n.php';
@@ -19,8 +23,4 @@
'remoteExtPath' => 'BlueSpiceExtensions/WantedArticle/resources'
);
-$wgAjaxExportList[] = 'WantedArticle::ajaxAddWantedArticle';
-$wgAjaxExportList[] = 'WantedArticle::ajaxGetWantedArticles';
-
-$wgAutoloadClasses['ViewWantedArticleForm'] = __DIR__ .
'/includes/ViewWantedArticleForm.php';
-$wgAutoloadClasses['ViewWantedArticleTag'] = __DIR__ .
'/includes/ViewWantedArticleTag.php';
\ No newline at end of file
+$wgAPIModules['bs-wantedarticle'] = 'BSApiTasksWantedArticle';
\ No newline at end of file
diff --git a/WantedArticle/includes/api/BSApiTasksWantedArticle.php
b/WantedArticle/includes/api/BSApiTasksWantedArticle.php
new file mode 100644
index 0000000..b83bdff
--- /dev/null
+++ b/WantedArticle/includes/api/BSApiTasksWantedArticle.php
@@ -0,0 +1,269 @@
+<?php
+/**
+ * Provides the wanted article api for BlueSpice.
+ *
+ * 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 Patric Wirth <[email protected]>
+ * @package Bluespice_Extensions
+ * @copyright Copyright (C) 2011 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or
later
+ */
+
+/**
+ * WantedArticle Api class
+ * @package BlueSpice_Extensions
+ */
+class BSApiTasksWantedArticle extends BSApiTasksBase {
+
+ /**
+ * Methods that can be called by task param
+ * @var array
+ */
+ protected $aTasks = array(
+ 'addWantedArticle',
+ 'getWantedArticles',
+ );
+
+ /**
+ * Methods that can be executed even when the wiki is in read-mode, as
+ * they do not alter the state/content of the wiki
+ * @var array
+ */
+ protected $aReadTasks = array(
+ 'getWantedArticles',
+ );
+
+ /**
+ * Returns an array of tasks and their required permissions
+ * array( 'taskname' => array('read', 'edit') )
+ * @return array
+ */
+ protected function getRequiredTaskPermissions() {
+ return array(
+ 'addWantedArticle' => array( 'wantedarticle-suggest' ),
+ 'getWantedArticles' => array( 'read' ),
+ );
+ }
+
+ /**
+ * Handles the suggestion ajax request.
+ * A new title is entered into the list. Depending on configuration,
+ * already existing articles are deleted.
+ * @return stdClass
+ */
+ protected function task_addWantedArticle( $oTaskData ) {
+ $oReturn = $this->makeStandardReturn();
+
+ $sTitle = isset( $oTaskData->title )
+ ? $oTaskData->title
+ : ''
+ ;
+
+ if ( empty( $sTitle ) ) {
+ $oReturn->message = wfMessage(
+ 'bs-wantedarticle-ajax-error-no-parameter'
+ )->plain();
+ return $oReturn;
+ }
+
+ //Check suggestion for invalid characters
+ $aFoundChars = array();
+ foreach( BsCore::getForbiddenCharsInArticleTitle() as $sChar ) {
+ if( false == strpos($sTitle, $sChar) ) {
+ continue;
+ }
+ $aFoundChars[] = "'$sChar'";
+ }
+
+ $oTitle = Title::newFromText( $sTitle );
+ if( !empty( $aFoundChars ) || !$oTitle ) {
+ $sChars = implode( ', ', $aFoundChars );
+ $oReturn->message = wfMessage(
+ 'bs-wantedarticle-title-invalid-chars',
+ count( $aFoundChars ),
+ $sChars
+ )->plain();
+ return $oReturn;
+ }
+
+ if ( $oTitle->exists() ) {
+ $oReturn->message = wfMessage(
+
'bs-wantedarticle-ajax-error-suggested-page-already-exists',
+ $oTitle->getPrefixedText()
+ )->plain();
+ return $oReturn;
+ }
+
+ $oWantedArticle = BsExtensionManager::getExtension(
'WantedArticle' );
+ $oDataSourceArticle =
$oWantedArticle->getDataSourceTemplateArticle();
+ $aWishList = $oWantedArticle->getTitleListFromTitle(
+ $oDataSourceArticle->getTitle()
+ );
+
+ $bDeleteExisting = BsConfig::get(
'MW::WantedArticle::DeleteExisting' );
+
+ foreach( $aWishList as $key => $a ) {
+ if( $oTitle->equals( $a['title'] ) ){
+ $oReturn->message = wfMessage(
+
'bs-wantedarticle-ajax-error-suggested-page-already-on-list',
+ $oTitle->getPrefixedText()
+ )->plain();
+ return $oReturn;
+ }
+ if( $bDeleteExisting && $a['title']->exists() === true
){
+ unset( $aWishList[$key] );
+ continue;
+ }
+ }
+ array_unshift( $aWishList, array(
+ 'title' => $oTitle,
+ 'signature' => '--~~~~',
+ ));
+
+ // Write new content
+ $oEditStatus = $oWantedArticle->saveTitleListToTitle(
+ $aWishList,
+ $oDataSourceArticle->getTitle(),
+ wfMessage(
+
'bs-wantedarticle-edit-comment-suggestion-added',
+ $oTitle->getPrefixedText()
+ )->plain()
+ );
+
+ if( !$oEditStatus->isOK() ) {
+ $oReturn->message = $oEditStatus->getHTML();
+ return $oReturn;
+ }
+
+ $oReturn->message = wfMessage(
+ 'bs-wantedarticle-success-suggestion-entered',
+ $oTitle->getPrefixedText()
+ )->plain();
+ $oReturn->success = true;
+
+ return $oReturn;
+ }
+
+ /**
+ * Handles the get wanted articles ajax request.
+ * @return stdClass
+ */
+ protected function task_getWantedArticles( $oTaskData ) {
+ $oReturn = $this->makeStandardReturn();
+
+ $iCount = isset( $oTaskData->count )
+ ? $oTaskData->count
+ : 10
+ ;
+ $sSort = isset( $oTaskData->sort )
+ ? $oTaskData->sort
+ : ''
+ ;
+ $sOrder = isset( $oTaskData->order )
+ ? $oTaskData->order
+ : ''
+ ;
+ $sType = isset( $oTaskData->type )
+ ? $oTaskData->type
+ : ''
+ ;
+ $sTitle = isset( $oTaskData->title )
+ ? (string) $oTaskData->title
+ : ''
+ ;
+
+ //Validation
+ $oValidationResult = BsValidator::isValid(
+ 'IntegerRange',
+ $iCount,
+ array(
+ 'fullResponse' => true,
+ 'lowerBoundary' => 1,
+ 'upperBoundary' => 30
+ )
+ );
+ if ( $oValidationResult->getErrorCode() ) {
+ $oReturn->message = $oValidationResult->getI18N();
+ return $oReturn;
+ }
+ $oValidationResult = BsValidator::isValid(
+ 'SetItem',
+ $sSort,
+ array(
+ 'fullResponse' => true,
+ 'set' => array( '', 'time', 'title' )
+ )
+ );
+ if( $oValidationResult->getErrorCode() ) {
+ $oReturn->message = $oValidationResult->getI18N();
+ return $oReturn;
+ }
+ $oValidationResult = BsValidator::isValid(
+ 'SetItem',
+ $sOrder,
+ array(
+ 'fullResponse' => true,
+ 'set' => array( '', 'ASC', 'DESC' )
+ )
+ );
+ if( $oValidationResult->getErrorCode() ) {
+ $oReturn->message = $oValidationResult->getI18N();
+ return $oReturn;
+ }
+
+ $oWantedArticle = BsExtensionManager::getExtension(
'WantedArticle' );
+ //Create list
+ $aWishList = $oWantedArticle->getTitleListFromTitle(
+
$oWantedArticle->getDataSourceTemplateArticle()->getTitle()
+ );
+
+ switch( $sSort ) {
+ case 'title':
+ $aTitleList =
$oWantedArticle->sortWishListByTitle(
+ $aWishList
+ );
+ break;
+ case 'time':
+ default:
+ $aTitleList =
$oWantedArticle->getDefaultTitleList(
+ $aWishList
+ );
+ }
+ if ( $sOrder == 'ASC' ) {
+ $aTitleList = array_reverse( $aTitleList );
+ }
+
+ $oWishListView = new ViewWantedArticleTag();
+ $oWishListView
+ ->setTitle( $sTitle )
+ ->setType ( $sType )
+ ->setOrder( $sOrder )
+ ->setSort ( $sSort )
+ ->setCount( $iCount )
+ ->setList ( $aTitleList )
+ ;
+
+ //result
+ $oReturn->success = true;
+ $oReturn->payload['view'] = $oWishListView->execute();
+ $oReturn->payload_count = count( $aTitleList );
+
+ return $oReturn;
+ }
+}
\ No newline at end of file
diff --git a/WantedArticle/resources/bluespice.wantedArticle.js
b/WantedArticle/resources/bluespice.wantedArticle.js
index 3a41e9c..5a78045 100644
--- a/WantedArticle/resources/bluespice.wantedArticle.js
+++ b/WantedArticle/resources/bluespice.wantedArticle.js
@@ -103,16 +103,28 @@
},
sendSuggestion: function( sArticleTitle ) {
- $.getJSON(
- bs.util.getAjaxDispatcherUrl(
'WantedArticle::ajaxAddWantedArticle', [ sArticleTitle ] ),
- function( oData, oTextStatus ) {
- bs.util.alert( 'WAsuc', { text: oData.message,
titleMsg: 'bs-extjs-title-success' } );
+ $.ajax({
+ dataType: "json",
+ url: mw.util.wikiScript( 'api' ),
+ data: {
+ action: 'bs-wantedarticle',
+ task: 'addWantedArticle',
+ format: 'json',
+ taskData: JSON.stringify({
+ title: sArticleTitle
+ })
+ },
+ success: function( oData, oTextStatus ) {
+ bs.util.alert( 'WAsuc', {
+ text: oData.message,
+ titleMsg: 'bs-extjs-title-success'
+ });
if( oData.success == true ) {
BsWantedArticle.resetDefaults();
BsWantedArticle.reloadAllWantedArticleTags();
}
}
- );
+ });
return false;
},
@@ -126,27 +138,32 @@
reloadAllWantedArticleTags: function() {
$( '.bs-wantedarticle-tag' ).each( function() {
//hint:
http://stackoverflow.com/questions/939032/jquery-pass-more-parameters-into-callback
- var callback = function(currentObject) {
+ var callback = function( currentObject ) {
return function( oData, oTextStatus ) {
- if( oData.success == true ) {
-
currentObject.replaceWith(oData.view);
+ if( oData.success === true ) {
+ currentObject.replaceWith(
oData.payload.view );
BsWantedArticle.toggleMoreHandler();
}
};
};
- $.getJSON(
- bs.util.getAjaxDispatcherUrl(
- 'WantedArticle::ajaxGetWantedArticles',
- [
- $(this).attr('data-count'),
- $(this).attr('data-sort'),
- $(this).attr('data-order'),
- $(this).attr('data-type'),
- $(this).find('h3').text()
- ]
- ),
- callback($(this))
- );
+
+ $.ajax({
+ dataType: "json",
+ url: mw.util.wikiScript( 'api' ),
+ data: {
+ action: 'bs-wantedarticle',
+ task: 'getWantedArticles',
+ format: 'json',
+ taskData: JSON.stringify({
+ count:
$(this).attr('data-count'),
+ sort: $(this).attr('data-sort'),
+ order:
$(this).attr('data-order'),
+ type: $(this).attr('data-type'),
+ title: $(this).find('h3').text()
+ })
+ },
+ success: callback($(this))
+ });
});
},
toggleMoreHandler: function() {
--
To view, visit https://gerrit.wikimedia.org/r/269161
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I575346abe32e0a8b8f751b105d5f95c157886550
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Pwirth <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits