diff --git a/CourseEditorOperations.php b/CourseEditorOperations.php
index 815bf12..d576edb 100644
--- a/CourseEditorOperations.php
+++ b/CourseEditorOperations.php
@@ -1,265 +1,275 @@
type) {
case 'fromTopic':
self::createNewCourseFromTopic($operation->params);
break;
case 'fromDepartment':
self::createNewCourseFromDepartment($operation->params);
break;
}
//FIXME Must be a serius return object and error handling
return "ok";
}
public static function manageCourseMetadataOp($operationRequested){
$operation = json_decode($operationRequested);
$params = $operation->params;
$title = $params[0];
$topic = $params[1];
$description = $params[2];
$externalReferences = $params[3];
$isImported = $params[4];
$originalAuthors = $params[5];
$isReviewed = $params[6];
$reviewedOn = $params[7];
$pageTitle = MWNamespace::getCanonicalName(NS_COURSEMETADATA) . ':' . $title;
$metadata = "" . $topic . "\r\n";
if($description !== '' && $description !== null){
$metadata .= "" . $description . "\r\n";
}
if($externalReferences !== '' && $externalReferences !== null){
$metadata .= "" . $externalReferences . "\r\n";
}
if($isImported !== false || $isReviewed !== false){
$metadata .= "" . true . "\r\n";
if($isImported !== false){
$metadata .= "" . $isImported . "\r\n";
$metadata .= "" . $originalAuthors . "\r\n";
}
if($isReviewed !== false){
$metadata .= "" . $isReviewed . "\r\n";
$metadata .= "" . $reviewedOn . "\r\n";
}
}
$resultCreateMetadataPage = CourseEditorUtils::editWrapper($pageTitle, $metadata , null, null);
CourseEditorUtils::setSingleOperationSuccess($operation, $resultCreateMetadataPage);
return json_encode($operation);
//FIXME Return an object with results in order to display error to the user
}
private function createBasicCourseMetadata($topic, $title, $description){
$topic = ($topic === null ? $title : $topic);
$pageTitle = MWNamespace::getCanonicalName(NS_COURSEMETADATA) . ':' . $title;
$metadata = "" . $topic . "\r\n";
if($description !== '' && $description !== null){
$metadata .= "" . $description . "\r\n";
}
$resultCreateMetadataPage = CourseEditorUtils::editWrapper($pageTitle, $metadata , null, null);
//FIXME Return an object with results in order to display error to the user
}
private function createNewCourseFromDepartment($params){
$department = $params[0];
$title = $params[1];
$description = $params[2];
$namespace = $params[3];
if($department != null && $title != null && $namespace != null){
$compareResult = strcmp($namespace, 'NS_COURSE');
$namespaceCostant = ($compareResult == 0 ? NS_COURSE : NS_USER);
$pageTitle = MWNamespace::getCanonicalName($namespaceCostant) . ':';
if($namespaceCostant == NS_USER){
self::createPrivateCourse($pageTitle, null, $title, $description);
}else{
self::createPublicCourseFromDepartment($pageTitle, $department, $title, $description);
}
}
}
private function createNewCourseFromTopic($params){
$topic = $params[0];
$title = $params[1];
$description = $params[2];
$namespace = $params[3];
if($topic != null && $title != null && $namespace != null){
$compareResult = strcmp($namespace, 'NS_COURSE');
$namespaceCostant = ($compareResult === 0 ? NS_COURSE : NS_USER);
$pageTitle = MWNamespace::getCanonicalName($namespaceCostant) . ':';
if($namespaceCostant == NS_USER){
self::createPrivateCourse($pageTitle, $topic, $title, $description);
}else{
self::createPublicCourseFromTopic($pageTitle, $topic, $title, $description);
}
}
}
private function createPrivateCourse($pageTitle, $topic, $title, $description){
$context = CourseEditorUtils::getRequestContext();
$user = $context->getUser();
$userPage = $pageTitle . $user->getName();
$titleWithUser = $user->getName() . '/' . $title;
$pageTitle = $userPage . "/" . $title;
$resultCreateCourse = CourseEditorUtils::editWrapper($pageTitle, "{{CCourse|}}", null, null);
$resultCreateMetadataPage = self::createBasicCourseMetadata($topic, $titleWithUser, $description);
$textToPrepend = "{{Course|" . $title . "|" . $user->getName() . "}}";
$resultPrependToUserPage = CourseEditorUtils::editWrapper($userPage, null, $textToPrepend, null);
//FIXME Return an object with results in order to display error to the user
}
private function createPublicCourseFromTopic($pageTitle, $topic, $title, $description){
$pageTitle .= $title;
$resultCreateCourse = CourseEditorUtils::editWrapper($pageTitle, "{{CCourse|}}", null, null);
$topicCourses = CourseEditorUtils::getTopicCourses($topic);
$text = $topicCourses . "{{Course|" . $title . "}}}}";
$resultCreateMetadataPage = self::createBasicCourseMetadata($topic, $title, $description);
$resultAppendToTopic = CourseEditorUtils::editWrapper($topic, $text, null, null);
//FIXME Return an object with results in order to display error to the user
}
private function createPublicCourseFromDepartment($pageTitle, $department, $title, $description){
$pageTitle .= $title;
$resultCreateCourse = CourseEditorUtils::editWrapper($pageTitle, "{{CCourse|}}", null, null);
$text = "{{Topic|" . "{{Course|" . $title . "}}}}";
$listElementText = "\r\n* [[" . $title . "]]";
$resultCreateMetadataPage = self::createBasicCourseMetadata(null, $title, $description);
$resultAppendToTopic = CourseEditorUtils::editWrapper($title, $text, null, null);
$resultAppendToDepartment = CourseEditorUtils::editWrapper($department, null, null, $listElementText);
//FIXME Return an object with results in order to display error to the user
}
public static function applyCourseOp($courseName, $operation){
$value = json_decode($operation);
switch ($value->action) {
case 'rename':
$sectionName = $value->elementName;
$newSectionName = $value->newElementName;
$chapters = CourseEditorUtils::getChapters($courseName . '/' .$sectionName);
$newSectionText = "";
foreach ($chapters as $chapter) {
$newSectionText .= "* [[" . $courseName . "/" . $newSectionName . "/" . $chapter ."|". $chapter ."]]\r\n";
}
$pageTitle = $courseName . "/" . $sectionName;
$newPageTitle = $courseName . '/' . $newSectionName;
$resultMove = CourseEditorUtils::moveWrapper($pageTitle, $newPageTitle);
$resultEdit = CourseEditorUtils::editWrapper($newPageTitle, $newSectionText, null, null);
$apiResult = array($resultMove, $resultEdit);
CourseEditorUtils::setComposedOperationSuccess($value, $apiResult);
break;
case 'delete':
$user = CourseEditorUtils::getRequestContext()->getUser();
$sectionName = $value->elementName;
$chapters = CourseEditorUtils::getChapters($courseName . '/' . $sectionName);
$title = Title::newFromText( $courseName . '/' . $sectionName, $defaultNamespace=NS_MAIN );
if(!$title->userCan('delete', $user, 'secure')){
$resultChapters = true;
$pageTitle = $courseName . '/' . $sectionName;
$prependText = "\r\n{{DeleteMe}}";
$resultSection = CourseEditorUtils::editWrapper($pageTitle, null, $prependText, null);
foreach ($chapters as $chapter) {
$pageTitle = $courseName . '/' . $sectionName . '/' . $chapter;
$prependText = "\r\n{{DeleteMe}}";
$resultChapters = CourseEditorUtils::editWrapper($pageTitle, null, $prependText, null);
}
}else {
$resultChapters = true;
foreach ($chapters as $chapter) {
$pageTitle = $courseName . '/' . $sectionName . '/' . $chapter;
$resultChapters = CourseEditorUtils::deleteWrapper($pageTitle);
}
$pageTitle = $courseName . '/' . $sectionName;
$resultSection = CourseEditorUtils::deleteWrapper($pageTitle);
}
$apiResult = array($resultSection, $resultChapters);
CourseEditorUtils::setComposedOperationSuccess($value, $apiResult);
break;
case 'add':
$sectionName = $value->elementName;
$pageTitle = $courseName . '/' . $sectionName;
$text = "";
$apiResult = CourseEditorUtils::editWrapper($pageTitle, $text, null, null);
CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
break;
case 'update':
$newCourseText = "{{CCourse|\r\n";
$newSectionsArray = json_decode($value->elementsList);
foreach ($newSectionsArray as $section) {
$newCourseText .= "{{SSection|" . $section ."}}\r\n";
}
$newCourseText .= "}}";
$categories = CourseEditorUtils::getCategories($courseName);
if(sizeof($categories) > 0){
foreach ($categories as $category) {
$newCourseText .= "\r\n[[" . $category['title'] . "]]";
}
}
$apiResult = CourseEditorUtils::editWrapper($courseName, $newCourseText, null, null);
CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
break;
+ case 'update-collection':
+ $apiResult = CourseEditorUtils::updateCollection($courseName);
+ CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
+ break;
}
return json_encode($value);
}
public static function applySectionOp($sectionName, $operation){
$context = CourseEditorUtils::getRequestContext();
$value = json_decode($operation);
switch ($value->action) {
case 'rename':
$chapterName = $value->elementName;
$newChapterName = $value->newElementName;
$from = $sectionName . '/' . $chapterName;
$to = $sectionName . '/' . $newChapterName;
$apiResult = CourseEditorUtils::moveWrapper($from, $to);
CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
break;
case 'delete':
$user = $context->getUser();
$chapterName = $value->elementName;
$title = Title::newFromText($sectionName . '/' . $chapterName, $defaultNamespace=NS_MAIN);
if(!$title->userCan('delete', $user, 'secure')){
$pageTitle = $sectionName . '/' . $chapterName;
$prependText = "\r\n{{DeleteMe}}";
$apiResult = CourseEditorUtils::editWrapper($pageTitle, null, $prependText, null);
}else {
$pageTitle = $sectionName . '/' . $chapterName;
$apiResult = CourseEditorUtils::deleteWrapper($pageTitle);
}
CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
break;
case 'add':
$chapterName = $value->elementName;
$pageTitle = $sectionName . '/' . $chapterName;
$text = "";
$apiResult = CourseEditorUtils::editWrapper($pageTitle, $text, null, null);
CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
break;
case 'update':
$newSectionText = "";
$newChaptersArray = json_decode($value->elementsList);
foreach ($newChaptersArray as $chapter) {
$newSectionText .= "* [[" . $sectionName . "/" . $chapter ."|". $chapter ."]]\r\n";
}
$apiResult = CourseEditorUtils::editWrapper($sectionName, $newSectionText);
CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
break;
case 'purge':
$explodedString = explode("/", $sectionName);
$pageToBePurged = (sizeof($explodedString) > 2 ? $explodedString[0] . "/" . $explodedString[1] : $explodedString[0]);
$apiResult = CourseEditorUtils::purgeWrapper($pageToBePurged);
CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
break;
+ case 'update-collection':
+ $explodedString = explode("/", $sectionName);
+ $courseName = (sizeof($explodedString) > 2 ? $explodedString[0] . "/" . $explodedString[1] : $explodedString[0]);
+ $apiResult = CourseEditorUtils::updateCollection($courseName);
+ CourseEditorUtils::setSingleOperationSuccess($value, $apiResult);
+ break;
}
return json_encode($value);
}
}
diff --git a/CourseEditorUtils.php b/CourseEditorUtils.php
index 0851c8a..36fa0db 100644
--- a/CourseEditorUtils.php
+++ b/CourseEditorUtils.php
@@ -1,220 +1,271 @@
getNamespace();
+
+ if(MWNamespace::equals($namespaceIndex, NS_USER)){
+ self::updateUserCollection($courseName);
+ }else {
+ $pageTitle = "Project:" . wfMessage('courseeditor-collection-book-category') ."/" . $name;
+ $collectionText = "{{" . wfMessage('courseeditor-collection-savedbook-template') . "
+ \n| setting-papersize = a4
+ \n| setting-toc = auto
+ \n| setting-columns = 1
+ \n| setting-footer = yes\n}}\n";
+ $collectionText .= "== " . $name . "==\r\n";
+ $sections = self::getSections($courseName);
+ foreach ($sections as $section) {
+ $chapters = self::getChapters($courseName . '/' .$section);
+ $collectionText .= ";" . $section . "\r\n";
+ foreach ($chapters as $chapter) {
+ $collectionText .= ":[[" . $courseName . "/" . $section . "/" . $chapter . "]]\r\n";
+ }
+ }
+ $collectionText .= "[[Category:" . wfMessage('courseeditor-collection-book-category') ."|" . $name . "]]";
+ $editResult = self::editWrapper($pageTitle, $collectionText, null, null);
+ return $editResult;
+ }
+ }
+
+ private function updateUserCollection($courseName){
+ list($namespaceAndUser, $title) = explode('/', $courseName, 2);
+ $pageTitle = $namespaceAndUser . "/" . wfMessage('courseeditor-collection-book-category') . "/" . $title;
+ $collectionText = "{{" . wfMessage('courseeditor-collection-savedbook-template') . "
+ \n| setting-papersize = a4
+ \n| setting-toc = auto
+ \n| setting-columns = 1
+ \n| setting-footer = yes\n}}\n";
+ $collectionText .= "== " . $title. "==\r\n";
+ $sections = self::getSections($courseName);
+ foreach ($sections as $section) {
+ $chapters = self::getChapters($courseName . '/' .$section);
+ $collectionText .= ";" . $section . "\r\n";
+ foreach ($chapters as $chapter) {
+ $collectionText .= ":[[" . $courseName . "/" . $section . "/" . $chapter . "]]\r\n";
+ }
+ }
+ $collectionText .= "[[Category:" . wfMessage('courseeditor-collection-book-category') ."|" . $title. "]]";
+ $editResult = self::editWrapper($pageTitle, $collectionText, null, null);
+ return $editResult;
+ }
+
public static function getMetadata($courseName){
$title = Title::newFromText($courseName, $defaultNamespace=NS_COURSEMETADATA );
$page = WikiPage::factory( $title );
$content = $page->getContent( Revision::RAW );
$text = ContentHandler::getContentText( $content );
if($text === ''){
return null;
}
$regex = "/(.*?)/s";
preg_match_all($regex, $text, $matches, PREG_PATTERN_ORDER);
$metadataResult = array();
$metadataKeys = $matches[1];
$metadataValues = $matches[2];
for ($i=0; $i < sizeof($metadataKeys); $i++) {
$metadataResult[$metadataKeys[$i]] = $metadataValues[$i];
}
return $metadataResult;
}
public static function getTopicCourses($topic){
$title = Title::newFromText($topic, $defaultNamespace=NS_MAIN );
$page = WikiPage::factory( $title );
$content = $page->getContent( Revision::RAW );
$text = ContentHandler::getContentText( $content );
$textNoNewLines = trim(preg_replace('/\n+/', '', $text));
$regex = "/({{Topic|.+)}}.*$/";
preg_match_all($regex, $textNoNewLines, $matches, PREG_PATTERN_ORDER);
return $matches[1][0];
}
/**
* This method is a workaround (read it HACK) to check the API results.
* MediaWiki ApiResult object is not "standard" but if an error/exception
* occurs the result variable is a string.
*/
public static function setSingleOperationSuccess(&$operation, $result){
$isSuccess = true;
if (is_string($result)) {
$isSuccess = false;
}
$operation->success = $isSuccess;
}
/**
* This method is a workaround (read it HACK) to check the API results.
* MediaWiki ApiResult object is not "standard" but if an error/exception
* occurs the result variable is a string.
*/
public static function setComposedOperationSuccess(&$operation, $result){
$isSuccess = true;
if (is_string($result[0]) || is_string($result[1])) {
$isSuccess = false;
}
$operation->success = $isSuccess;
}
public static function getRequestContext(){
if(self::$requestContext == null)
{
$context = new RequestContext();
self::$requestContext = $context;
}
return self::$requestContext;
}
public static function getCategories($courseName){
try {
$api = new ApiMain(
new DerivativeRequest(
self::getRequestContext()->getRequest(),
array(
'action' => 'query',
'titles' => $courseName,
'prop' => 'categories'
)
),
true
);
$api->execute();
$results = $api->getResult()->getResultData(null, array('Strip' => 'all'));
$page = reset($results['query']['pages']);
return $page['categories'];
} catch(UsageException $e){
return $e->getMessage();
}
}
public static function getChapters($sectionName){
$title = Title::newFromText($sectionName, $defaultNamespace=NS_MAIN );
$page = WikiPage::factory( $title );
$content = $page->getContent( Revision::RAW );
$text = ContentHandler::getContentText( $content );
$regex = "/\*\s*\[{2}([^|]*)\|?([^\]]*)\]{2}\s*/";
preg_match_all($regex, $text, $matches, PREG_PATTERN_ORDER);
return $matches[2];
}
public static function getSections($courseName){
$title = Title::newFromText( $courseName, $defaultNamespace=NS_MAIN );
$page = WikiPage::factory( $title );
$content = $page->getContent( Revision::RAW );
$text = ContentHandler::getContentText( $content );
$regex = "/\{{2}SSection\|(.*)\}{2}/";
preg_match_all($regex, $text, $matches, PREG_PATTERN_ORDER);
return $matches[1];
}
public static function deleteWrapper($title){
$context = self::getRequestContext();
try {
$user = $context->getUser();
$token = $user->getEditToken();
$api = new ApiMain(
new DerivativeRequest(
$context->getRequest(),
array(
'action' => 'delete',
'title' => $title,
'token' => $token
),
true
),
true
);
$api->execute();
return $api->getResult()->getResultData(null, array('Strip' => 'all'));
} catch(UsageException $e){
return $e->getMessage();
}
}
public static function purgeWrapper($titles){
$context = self::getRequestContext();
try {
$api = new ApiMain(
new DerivativeRequest(
$context->getRequest(),
array(
'action' => 'purge',
'titles' => $titles,
'forcerecursivelinkupdate' => true
),
true
),
true
);
$api->execute();
return $api->getResult()->getResultData(null, array('Strip' => 'all'));
} catch(UsageException $e){
return $e->getMessage();
}
}
public static function editWrapper($title, $text, $textToPrepend, $textToAppend){
$context = self::getRequestContext();
try {
$user = $context->getUser();
$token = $user->getEditToken();
//$token = $this->getCsrfToken();
$api = new ApiMain(
new DerivativeRequest(
$context->getRequest(),
array(
'action' => 'edit',
'title' => $title,
'text' => $text,
// automatically override text
'prependtext' => $textToPrepend,
// automatically override text
'appendtext' => $textToAppend,
'notminor' => true,
'token' => $token
),
true
),
true
);
$api->execute();
return $api->getResult()->getResultData(null, array('Strip' => 'all'));
} catch(UsageException $e){
return $e->getMessage();
}
}
public static function moveWrapper($from, $to){
$context = self::getRequestContext();
try {
$user = $context->getUser();
$token = $user->getEditToken();
$api = new ApiMain(
new DerivativeRequest(
$context->getRequest(),
array(
'action' => 'move',
'from' => $from,
'to' => $to,
'noredirect' => true,
'movetalk' => true,
'movesubpages' => true,
'token' => $token
),
true
),
true
);
$api->execute();
return $api->getResult()->getResultData(null, array('Strip' => 'all'));
} catch(UsageException $e){
return $e->getMessage();
}
}
}
diff --git a/i18n/en.json b/i18n/en.json
index d0c6967..704ff6e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -1,49 +1,52 @@
{
"courseeditor" : "Course editor",
"courseeditor-managemetata-pagetitle": "Metadata management",
"courseeditor-credits-info": "CourseEditor is an extension to create and manage courses.",
"courseeditor-add-new-section" : "Add a new section",
"courseeditor-save-course": "Save course",
"courseeditor-add-new-chapter" : "Add New Chapter",
"courseeditor-save-section" : "Save Section",
"courseeditor-cancel" : "Cancel",
"courseeditor-edit-dialog" : "Edit",
"courseeditor-rename" : "Rename",
"courseeditor-organize-chapters" : "You can organize, add and delete chapters",
"courseeditor-organize-sections" : "You can organize, add and delete sections",
"courseeditor-input-department-label" : "Department:",
"courseeditor-input-topic-label" : "Topic:",
"courseeditor-input-course-label" : "Title:",
"courseeditor-input-course-placeholder" : "Insert the title of the course",
"courseeditor-input-description-label" : "Description:",
"courseeditor-input-description-placeholder" : "Insert a description",
"courseeditor-input-externalreferences-label" : "External references:",
"courseeditor-input-externalreferences-placeholder" : "Insert external references",
"courseeditor-input-reviewed-label" : "Reviewed",
"courseeditor-input-imported-label" : "Imported",
"courseeditor-input-originalauthors-label" : "Original authors:",
"courseeditor-input-originalauthors-placeholder" : "Insert the original authors",
"courseeditor-input-reviewedon-label" : "Reviewed on:",
"courseeditor-input-reviewedon-placeholder" : "Insert the date (dd/mm/yyyy)",
"courseeditor-save-button" : "Save",
"courseeditor-create-button" : "Create!",
"courseeditor-alert-message" : "Hey, there is a course with the same title yet!
Choose another title or start to contribute immediately to the existing course.",
"courseeditor-validate-form" : "Please, insert a topic and a name",
"courseeditor-radiobutton-namespace" : "Do you want to creatre a private course in your personal page or a public one?",
"courseeditor-radiobutton-namespace-private" : "Private",
"courseeditor-radiobutton-namespace-public" : "Public",
"courseeditor-message-dialog-title" : "Oops...",
"courseeditor-message-dialog-message" : "There's an element in the recycle bin with the same name, what do you want to do?",
"courseeditor-message-dialog-cancel" : "Cancel",
"courseeditor-message-dialog-restore" : "Restore",
"courseeditor-message-dialog-create-new" : "Create new",
"courseeditor-alert-message-existing-element" : "There is already an element with the same name. Please, enter a different one.",
"courseeditor-recycle-bin" : "Recycle bin",
"courseeditor-error-operation" : "Sorry, something went wrong! :(
",
"courseeditor-error-operation-action-add" : "Add",
"courseeditor-error-operation-action-rename" : "Rename",
"courseeditor-error-operation-action-delete" : "Delete",
"courseeditor-error-operation-action-purge" : "Purge",
"courseeditor-error-operation-action-update" : "Update",
- "courseeditor-error-operation-fail" : " fails!"
+ "courseeditor-error-operation-action-updatecollection" : "Update book",
+ "courseeditor-error-operation-fail" : " fails!",
+ "courseeditor-collection-book-category": "Books",
+ "courseeditor-collection-savedbook-template": "saved_book"
}
diff --git a/i18n/it.json b/i18n/it.json
index a7c93a2..4230258 100644
--- a/i18n/it.json
+++ b/i18n/it.json
@@ -1,49 +1,52 @@
{
"courseeditor" : "Editor di corsi",
"courseeditor-managemetata-pagetitle": "Gestione metadati",
"courseeditor-credits-info": "CourseEditor è una estensione per creare ed organizzare corsi.",
"courseeditor-add-new-section" : "Aggiungi una nuova sezione",
"courseeditor-save-course": "Salva corso",
"courseeditor-add-new-chapter" : "Aggiungi un nuovo capitolo",
"courseeditor-save-section" : "Salva sezione",
"courseeditor-cancel" : "Cancella",
"courseeditor-edit-dialog" : "Modifica",
"courseeditor-rename" : "Rinomina",
"courseeditor-organize-chapters" : "Qui puoi organizzare, aggiungere e rimuovere capitoli",
"courseeditor-organize-sections" : "Qui puoi organizzare, aggiungere e rimuovere sezioni",
"courseeditor-input-department-label" : "Dipartmento:",
"courseeditor-input-topic-label" : "Argomento:",
"courseeditor-input-course-label" : "Titolo:",
"courseeditor-input-course-placeholder" : "Inserisci il titolo del corso",
"courseeditor-input-description-label" : "Descrizione:",
"courseeditor-input-description-placeholder" : "Insersci la descrizione",
"courseeditor-input-externalreferences-label" : "Riferimenti esterni:",
"courseeditor-input-externalreferences-placeholder" : "Inserisci i riferimenti esterni",
"courseeditor-input-reviewed-label" : "Revisionato",
"courseeditor-input-imported-label" : "Importato",
"courseeditor-input-originalauthors-label" : "Autori originali:",
"courseeditor-input-originalauthors-placeholder" : "Inserisci gli autori originali",
"courseeditor-input-reviewedon-label" : "Revisionato il:",
"courseeditor-input-reviewedon-placeholder" : "Inserisci la data (gg/mm/aaaa)",
"courseeditor-save-button" : "Salva",
"courseeditor-create-button" : "Crea!",
"courseeditor-alert-message" : "Ehi, c'è un corso con lo stesso titolo!
Scegli un altro titolo o inizia a contribuire subito al corso esitente.
",
"courseeditor-validate-form" : "Inserisci l'argomento e il corso!",
"courseeditor-radiobutton-namespace" : "Vuoi creare un corso privato nella tua pagina personale o uno pubblico?",
"courseeditor-radiobutton-namespace-private" : "Privato",
"courseeditor-radiobutton-namespace-public" : "Pubblico",
"courseeditor-message-dialog-title" : "Ops...",
"courseeditor-message-dialog-message" : "C'è un elemento nel cestino con lo stesso nome, cosa vuoi fare?",
"courseeditor-message-dialog-cancel" : "Indietro",
"courseeditor-message-dialog-restore" : "Ripristina",
"courseeditor-message-dialog-create-new" : "Crea nuovo",
"courseeditor-alert-message-existing-element" : "È già presente un elemento con lo stesso nome. Per favore, inserire un nome diverso.",
"courseeditor-recycle-bin" : "Cestino",
"courseeditor-error-operation" : "Scusa, qualcosa è andato storto! :(
",
"courseeditor-error-operation-action-add" : "Aggiungi",
"courseeditor-error-operation-action-rename" : "Rinomina ",
"courseeditor-error-operation-action-delete" : "Elimina",
"courseeditor-error-operation-action-purge" : "Purga",
"courseeditor-error-operation-action-update" : "Aggiorna",
- "courseeditor-error-operation-fail" : " fallito!"
+ "courseeditor-error-operation-action-updatecollection" : "Aggiorna libro",
+ "courseeditor-error-operation-fail" : " fallito!",
+ "courseeditor-collection-book-category": "Libri",
+ "courseeditor-collection-savedbook-template": "libro_salvato"
}
diff --git a/modules/courseEditor.js b/modules/courseEditor.js
index 6d5f4ac..097c649 100644
--- a/modules/courseEditor.js
+++ b/modules/courseEditor.js
@@ -1,89 +1,92 @@
$(function () {
var dragElements = [];
//Add all existing sections to the dragSections array
$.each(sections, function(key, value){
var dragItem = new DraggableHandledItemWidget( {
data: value,
icon: 'menu',
label: value
} );
dragItem.$label.append("",
"");
dragElements.push(dragItem);
});
//Create a draggableWidget with the items in the dragSections array
var draggableWidget = new DraggableGroupWidget( {
items: dragElements
} );
var fieldDrag = new OO.ui.FieldLayout(draggableWidget);
//Create a textInputWidget for new sections
var textInputWidget = new OO.ui.TextInputWidget( { placeholder: OO.ui.deferMsg( 'courseeditor-add-new-section' ) } );
var fieldInput = new OO.ui.FieldLayout( textInputWidget);
//Append all created elements to DOM
$('#sectionsList').append(fieldDrag.$element, fieldInput.$element);
initHandlers(draggableWidget, textInputWidget, editStack);
$('#saveCourseButton').click(function(){
var newSections = [];
$.each(draggableWidget.getItems(), function(key, value){
newSections.push(value.data);
});
editStack.push({
action: 'update',
elementsList: JSON.stringify(newSections)
});
+ editStack.push({
+ action: 'update-collection'
+ });
var progressDialog = new ProgressDialog( {
size: 'medium'
} );
windowManager.addWindows( [ progressDialog ] );
windowManager.openWindow( progressDialog );
var createTask = function(operation){
return function(next){
doTask(operation, next);
}
};
var doTask = function(operation, next){
$.getJSON( mw.util.wikiScript(), {
action: 'ajax',
rs: 'CourseEditorOperations::applyCourseOp',
rsargs: [$('#courseName').text(), JSON.stringify(operation)]
}, function ( data ) {
if (data.success !== true) {
var alert = '
';
$('#saveDiv').after(alert);
$('#alert').html(OO.ui.deferMsg('courseeditor-error-operation'));
$('#alert').append(OO.ui.deferMsg('courseeditor-error-operation-action-' + data.action));
if(data.elementName){
var localizedMsg = " " + data.elementName + OO.ui.msg('courseeditor-error-operation-fail');
$('#alert').append(localizedMsg);
}else {
$('#alert').append(OO.ui.deferMsg('courseeditor-error-operation-fail'));
}
windowManager.closeWindow(progressDialog);
$(document).clearQueue('tasks');
}else {
next();
}
});
};
while( editStack.length > 0 ) {
var operation = editStack.shift();
$(document).queue('tasks', createTask(operation));
};
$(document).queue('tasks', function(){
windowManager.closeWindow(progressDialog);
window.location.assign('/' + $('#courseName').text());
});
dequeue('tasks');
});
})
diff --git a/modules/sectionEditor.js b/modules/sectionEditor.js
index 4ffcb4a..4f6385a 100644
--- a/modules/sectionEditor.js
+++ b/modules/sectionEditor.js
@@ -1,94 +1,97 @@
$(function () {
var dragElements = [];
//Add all existing chapters to the dragElements array
$.each(chapters, function(key, value){
var dragItem = new DraggableHandledItemWidget( {
data: value,
icon: 'menu',
label: value
} );
dragItem.$label.append("",
"");
dragElements.push(dragItem);
});
//Create a draggableWidget with the items in the dragElements array
var draggableWidget = new DraggableGroupWidget( {
items: dragElements
} );
var fieldDrag = new OO.ui.FieldLayout(draggableWidget);
//Create a textInputWidget for new chapters
var textInputWidget = new OO.ui.TextInputWidget( { placeholder: OO.ui.deferMsg( 'courseeditor-add-new-chapter' ) } );
var fieldInput = new OO.ui.FieldLayout( textInputWidget);
//Append all created elements to DOM
$('#chaptersList').append(fieldDrag.$element, fieldInput.$element);
//Init Handlers
initHandlers(draggableWidget, textInputWidget, editStack);
$('#saveSectionButton').click(function(){
var newChapters = [];
$.each(draggableWidget.getItems(), function(key, value){
newChapters.push(value.data);
});
editStack.push({
action: 'update',
elementsList: JSON.stringify(newChapters)
});
editStack.push({
action: 'purge'
});
+ editStack.push({
+ action: 'update-collection'
+ });
var progressDialog = new ProgressDialog( {
size: 'medium'
} );
windowManager.addWindows( [ progressDialog ] );
windowManager.openWindow( progressDialog );
var createTask = function(operation){
return function(next){
doTask(operation, next);
}
};
var doTask = function(operation, next){
$.getJSON( mw.util.wikiScript(), {
action: 'ajax',
rs: 'CourseEditorOperations::applySectionOp',
rsargs: [$('#sectionName').text(), JSON.stringify(operation)]
}, function ( data ) {
if (data.success !== true) {
var alert = '
';
$('#saveDiv').after(alert);
$('#alert').html(OO.ui.msg('courseeditor-error-operation'));
$('#alert').append(OO.ui.msg('courseeditor-error-operation-action-' + data.action));
if(data.elementName){
var localizedMsg = " " + data.elementName + OO.ui.msg('courseeditor-error-operation-fail');
$('#alert').append(localizedMsg);
}else {
$('#alert').append(OO.ui.msg('courseeditor-error-operation-fail'));
}
windowManager.closeWindow(progressDialog);
$(document).clearQueue('tasks');
}else{
next();
}
});
};
while( editStack.length > 0 ) {
var operation = editStack.shift();
$(document).queue('tasks', createTask(operation));
};
$(document).queue('tasks', function(){
windowManager.closeWindow(progressDialog);
window.location.assign('/' + $('#sectionName').text());
});
dequeue('tasks')
});
})