Permalink
Browse files

Update userpage if the course name is changed

Hide the feature to create a new topic from the select menu within manage metadata
Comment some functions

Signed-off-by: Alessandro Tundo <alessandrotundo94@gmail.com>
  • Loading branch information...
aletundo committed Feb 28, 2017
1 parent 43009ea commit 5d8c9ad789fdd144b72dd7e9a2db5dd212be86a4
Showing with 79 additions and 11 deletions.
  1. +52 −0 CourseEditorOperations.php
  2. +2 −2 CourseEditorTemplates.php
  3. +1 −1 SpecialCourseEditor.php
  4. +24 −8 modules/manageMetadata.js
View
@@ -71,8 +71,16 @@ public static function createCourseOp($operationRequested){
return json_encode($operation);
}
/**
* Update the metadata page with new data submitted by the user.
* Moreover the course root page cache is purged.
* @param string $operationRequested JSON object with new new data
* @return string $operation JSON object with the operation requested plus
* a success field
*/
public static function manageCourseMetadataOp($operationRequested){
$operation = json_decode($operationRequested);
// Get all the params
$params = $operation->params;;
$title = $params[0];
$topic = $params[1];
@@ -86,7 +94,9 @@ public static function manageCourseMetadataOp($operationRequested){
$isReviewed = $params[9];
$reviewedOn = $params[10];
// Create the page title prepending the namespace
$pageTitle = MWNamespace::getCanonicalName(NS_COURSEMETADATA) . ':' . $title;
// Add the new metadata submitted
$metadata = "<section begin=topic />" . $topic . "<section end=topic />\r\n";
if($description !== '' && $description !== null){
$metadata .= "<section begin=description />" . $description . "<section end=description />\r\n";
@@ -120,6 +130,13 @@ public static function manageCourseMetadataOp($operationRequested){
return json_encode($operation);
}
/**
* Create the basic metadata page when a new course is created.
* @param string $title the title of the course
* @param string $topic the topic of the course
* @param string $description the description of the course
* @return $apiResult the result of the edit
*/
private function createBasicCourseMetadata($topic, $title, $description){
//Remove username from title (if present) to be used as topic if $topic is null
$explodedString = explode('/', $title, 2);
@@ -229,6 +246,15 @@ private function createPublicCourseFromDepartment($pageTitle, $department, $titl
return array($resultCreateCourse, $resultCreateMetadataPage, $resultAppendToTopic, $resultAppendToDepartment, $resultPurgeCourse);
}
/**
* All the possible small tasks to publish a course from a userpage.
* This function is used also for course renaming because "techinally" the
* tasks are the same.
* @param string $operation JSON object with the action requested and the
* params needed
* @return string $operationObj JSON object with the request and the a success
* field
*/
public static function applyPublishCourseOp($operation){
global $wgCourseEditorTemplates, $wgCourseEditorCategories, $wgContLang;
$operationObj = json_decode($operation);
@@ -284,10 +310,29 @@ public static function applyPublishCourseOp($operation){
$apiResult = CourseEditorUtils::editWrapper($title, $replacedText, null, null);
CourseEditorUtils::setSingleOperationSuccess($operationObj, $apiResult);
break;
case 'update-user-page':
$title = Title::newFromText($wgContLang->getNsText( NS_USER ) . ":" . $operationObj->username);
$page = WikiPage::factory($title);
$pageText = $page->getText();
$replacedText = str_replace(
"{{". $wgCourseEditorTemplates['Course'] ."|" . $operationObj->elementName . "|" . $operationObj->username . "}}",
"{{". $wgCourseEditorTemplates['Course'] ."|" . $operationObj->newElementName . "|". $operationObj->username . "}}",
$pageText
);
$apiResult = CourseEditorUtils::editWrapper($title, $replacedText, null, null);
CourseEditorUtils::setSingleOperationSuccess($operationObj, $apiResult);
break;
}
return json_encode($operationObj);
}
/**
* All the possible small tasks that can be performed on a levelTwo.
* @param string $operation JSON object with the action requested and the
* params needed
* @return string $operationObj JSON object with the request and the a success
* field
*/
public static function applyCourseOp($operation){
global $wgCourseEditorTemplates, $wgCourseEditorCategories, $wgContLang;
$operationObj = json_decode($operation);
@@ -333,6 +378,13 @@ public static function applyCourseOp($operation){
return json_encode($operationObj);
}
/**
* All the possible small tasks that can be performed on a course.
* @param string $operation JSON object with the action requested and the
* params needed
* @return string $operationObj JSON object with the request and the a success
* field
*/
public static function applyLevelTwoOp($operation){
global $wgCourseEditorTemplates, $wgCourseEditorCategories, $wgContLang;
$context = CourseEditorUtils::getRequestContext();
@@ -193,8 +193,8 @@ public function execute(){
<div class="form-group">
<label for="courseTopic"><?php echo wfMessage( 'courseeditor-input-topic-label' ) ?></label>
<!-- <input type="text" class="form-control" id="courseTopic" value="<?php echo $metadataResult['topic'] ?>" placeholder="<?php echo wfMessage( 'courseeditor-input-topic-placeholder' ) ?>"> -->
<select class="form-control" id="courseTopic">
<option value="New">Crea nuovo...</option>
<select class="form-control" id="courseTopic" <?php if($isPrivate) echo "disabled"; ?>>
<!-- <option value="New">Crea nuovo...</option> -->
<?php
foreach ($topics as $t) {
echo "<option value='". str_replace('_', ' ', $t) . "'";
View
@@ -176,7 +176,7 @@ private function manageMetadata($courseName){
$out->addModules('ext.courseEditor.manageMetadata');
$out->setPageTitle(wfMessage('courseeditor-managemetata-pagetitle'));
$out->addJsConfigVars('wgCourseEditor', $wgCourseEditorNamespaces);
// Remove username from courseName (in present)
// Remove username from courseName (if there is)
$explodedString = explode('/', $courseName, 2);
$courseNameNoUser = (sizeof($explodedString) === 1) ? $explodedString[0] : $explodedString[1];
$username = (sizeof($explodedString) === 1) ? 'null' : $explodedString[0];
View
@@ -199,13 +199,15 @@ var renameAndUpdateMetadata = function(courseName, originalCourseName, originalT
courseNameWithNamespace = courseNamespace + ':' + courseName;
}
// Get the courseTree and then build the editStack
$.getJSON( mw.util.wikiScript(), {
action: 'ajax',
rs: 'CourseEditorUtils::getCourseTree',
rsargs: [originalCourseNameWithNamespace]
}).success(function(result){
courseTree = result;
}).then(function(){
// Move the levelsThree, move and update the parent levelTwo
$.each(courseTree.levelsThree, function(index, array){
$.each(array, function(key, value){
editStack.push({
@@ -224,21 +226,24 @@ var renameAndUpdateMetadata = function(courseName, originalCourseName, originalT
elementName: courseNameWithNamespace + '/' + courseTree.levelsTwo[index]
});
});
// Move the course root
editStack.push({
action: 'move-root',
elementName: courseTree.root,
newElementName: courseNameWithNamespace
});
// Move the metadata page
editStack.push({
action: 'move-metadata',
elementName: originalMetadataPage,
newElementName: newMetadataPage
});
// Update the collection
editStack.push({
action: 'update-collection',
elementName: courseNameWithNamespace
});
// If the topic is changed move the course from the old to the new one
if (originalTopic !== $('#courseTopic').val()) {
editStack.push({
action: 'remove-from-topic-page',
@@ -253,13 +258,24 @@ var renameAndUpdateMetadata = function(courseName, originalCourseName, originalT
newElementName: $('#courseTopic').val()
});
}else {
editStack.push({
action: 'update-topic-page',
topicName: $('#courseTopic').val(),
elementName: originalCourseName,
newElementName: courseName
});
// Otherwise updated the topic page or the userpage for private courses
if ($('#private').val() != 1) {
editStack.push({
action: 'update-topic-page',
topicName: $('#courseTopic').val(),
elementName: originalCourseName,
newElementName: courseName
});
}else {
editStack.push({
action: 'update-user-page',
username: $('#username').val(),
elementName: originalCourseName,
newElementName: courseName
});
}
}
// Purge cache of the course root page
editStack.push({
action: 'purge',
elementName: courseNameWithNamespace
@@ -301,7 +317,7 @@ var renameAndUpdateMetadata = function(courseName, originalCourseName, originalT
});
};
// Create tasks form editStack
// Create tasks from editStack
$.each(editStack, function(key, value){
$(document).queue('tasks', createTask(value));
});

0 comments on commit 5d8c9ad

Please sign in to comment.