Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
674992a
#1 cleaned up the branch and implmented numbering to overview and con…
vidhyasagargm Sep 12, 2024
90d7840
Update widgets/PageListItemTitle.php
vidhyasagargm Sep 18, 2024
e591a41
Delete widgets/.WikiRichText.php.swp
vidhyasagargm Sep 18, 2024
59ee21d
added unit testing for numbering logic
vidhyasagargm Sep 18, 2024
b1e21c5
Merge branch '1-content-overview-title-numbering' of https://github.c…
vidhyasagargm Sep 18, 2024
0dc8f5d
Revert "Merge branch '1-content-overview-title-numbering' of https://…
vidhyasagargm Sep 18, 2024
3d1df8b
#1 Toggle button for numbering pagelist with unit testing
vidhyasagargm Sep 18, 2024
b1c56d5
#1 Fixed double numbering in content and added a button
vidhyasagargm Sep 20, 2024
7dd22b1
#1 Fixed double numbering in content and added a button
vidhyasagargm Sep 20, 2024
531d360
Delete widgets/.WikiRichText.php.swp
vidhyasagargm Sep 20, 2024
c9e2ba4
#1 Implemented German Language for button content
vidhyasagargm Sep 25, 2024
ffeb277
Update _view_body.php
vidhyasagargm Sep 25, 2024
f886205
Update _view_content.php
vidhyasagargm Sep 25, 2024
855c04c
Update _view_content.php
vidhyasagargm Sep 25, 2024
e1979a5
#1 toggle for numbering fixed appearance on edit page
vidhyasagargm Oct 1, 2024
6d93c5e
Update _view_body.php
vidhyasagargm Oct 1, 2024
f17a7ad
Restore menu.php
vidhyasagargm Oct 1, 2024
add39f1
Update widgets/PageListItemTitle.php
vidhyasagargm Oct 2, 2024
b14519e
Update widgets/PageListItemTitle.php
vidhyasagargm Oct 2, 2024
6dc658c
#1 Added CSS styling to css file and changed naming convention
vidhyasagargm Oct 4, 2024
1a67e0f
#1 changed the test case with html render
vidhyasagargm Oct 4, 2024
b9492e5
#1 implemented preserve settings
vidhyasagargm Oct 9, 2024
733b08d
#1 Matched numbering with TOC
vidhyasagargm Oct 17, 2024
fbe27ec
#1 used grunt build to generate min and less files
vidhyasagargm Oct 21, 2024
3f11786
#1 changed all the test files added a functional testing
vidhyasagargm Oct 21, 2024
9c1fb5e
#1 Added Numbering Setting Checkmark in wiki/config
vidhyasagargm Oct 22, 2024
5f5ea4a
Update DefaultSettings.php
vidhyasagargm Oct 22, 2024
c45de85
Update PageController.php
vidhyasagargm Oct 22, 2024
8ae5bfd
Update ConfigForm.php
vidhyasagargm Oct 22, 2024
7d652ad
Update messages/de/base.php
vidhyasagargm Oct 24, 2024
d788aff
Update resources/css/humhub.wiki.less
vidhyasagargm Oct 24, 2024
9ec7b1a
Update resources/css/humhub.wiki.css
vidhyasagargm Oct 24, 2024
6e8442b
Update resources/js/humhub.wiki.Page.js
vidhyasagargm Oct 24, 2024
ef94b75
Update resources/js/humhub.wiki.bundle.js
vidhyasagargm Oct 24, 2024
1b4162d
Update resources/js/humhub.wiki.Page.js
vidhyasagargm Oct 24, 2024
96d04a3
#1 updated code to show numbering on wiki/config
vidhyasagargm Oct 24, 2024
0cc7113
#1 removed min file
vidhyasagargm Oct 24, 2024
bec369f
#1 Added translation to the config page
vidhyasagargm Nov 1, 2024
b22ead0
#1 Changed button content of config form
vidhyasagargm Nov 6, 2024
c70fbad
#1 Added partial reload after sorting and removed unwanted comment
vidhyasagargm Nov 8, 2024
f7deb4c
#1 added condition for partial reload
vidhyasagargm Nov 11, 2024
7778235
Merge pull request #2 from Neo-Atlas/1-content-overview-title-numbering
marius-meissner Nov 24, 2024
49db92e
#4 Wiki Editing in tree structure - toggle button
vidhyasagargm Dec 21, 2024
3a24ca5
#4 Added additional test cases
vidhyasagargm Dec 23, 2024
ebe492b
#4 Added drop down menu
vidhyasagargm Jan 4, 2025
87d67f7
#4 Added icon to the options button
vidhyasagargm Jan 6, 2025
e8996be
Merge pull request #5 from Neo-Atlas/wiki-editing-toggle-button
marius-meissner Jan 17, 2025
1380d79
#6 Create merge and create copy functions
vidhyasagargm Jan 27, 2025
95b93d1
file type reverted
vidhyasagargm Jan 27, 2025
73b600b
Edited PageController
vidhyasagargm Jan 27, 2025
4fa5980
#6 Code cleanup suggested changes
vidhyasagargm Jan 27, 2025
74653c6
#6 Collaborative editing added notification feature
vidhyasagargm Feb 9, 2025
b1a314d
#6 updated is_editing feature
vidhyasagargm Feb 10, 2025
f96bcc9
#6 Updated Collaborative editing notification feature
vidhyasagargm Feb 17, 2025
f04d7a6
#6 Updated Translations
vidhyasagargm Feb 17, 2025
7b7d067
#6 Added TTL logic and made suggested changes
vidhyasagargm Feb 25, 2025
1f7257c
updated Pagecontroller
vidhyasagargm Feb 25, 2025
45bb1e5
updated Pagecontroller
vidhyasagargm Feb 25, 2025
4ccd087
#6 Code cleanup and suggested changes
vidhyasagargm Feb 28, 2025
3b8ade3
#6 Updated TTL constant
vidhyasagargm Feb 28, 2025
fc5df94
#6 Database correction and suggested changes
vidhyasagargm Mar 5, 2025
a725d5f
updated Pagecontroller.php
vidhyasagargm Mar 5, 2025
e8c8234
Updated PageController.php
vidhyasagargm Mar 6, 2025
6880cf8
Changes for PR
vidhyasagargm Mar 19, 2025
9dd906a
updated files
vidhyasagargm Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 162 additions & 2 deletions controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@
use humhub\modules\wiki\permissions\CreatePage;
use humhub\modules\wiki\permissions\EditPages;
use humhub\modules\wiki\permissions\ViewHistory;
use humhub\modules\user\models\User;
use Throwable;
use Yii;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\db\StaleObjectException;
use yii\web\HttpException;
use yii\web\Response;
use DateTime;

/**
* PageController
*
* @author luke
*/
class PageController extends BaseController
{
{
public const TTL = 300;

/**
* @return $this|Response
* @throws Exception
Expand Down Expand Up @@ -211,6 +215,7 @@ public function actionEdit($id = null, $title = null, $categoryId = null)
]);
}

$form->page->updateIsEditing();
return $this->renderSidebarContent('edit', $params);
}

Expand Down Expand Up @@ -335,7 +340,7 @@ public function actionDelete(int $id)
}

$page->delete();

$page->doneEditing();
return $this->redirect($this->contentContainer->createUrl('index'));
}

Expand Down Expand Up @@ -439,5 +444,160 @@ protected function getAccessRules()
];
}

/**
* @param int $id
* @return $this|Response
* @throws HttpException
*/
public function actionMerge(int $id)
{
$dateTime = new DateTime();
$userIdentity = Yii::$app->user->identity->username;

$page = $this->getWikiPage($id);
if (!$page) {
throw new HttpException(404, 'Wiki page not found!');
}

$form = (new PageEditForm(['container' => $this->contentContainer]))->forPage($id);
if (!$form->load(Yii::$app->request->post())) {
throw new HttpException(404);
}

$submittedRevision = new WikiPageRevision();
$submittedRevision->revision = time();
$submittedRevision->content = $form->revision->content;
$submittedRevision->isCurrentlyEditing = true;

$mergedRevision = $page->createRevision();
$changedContentSepeartor = '**conflicting changes of '. $userIdentity .' from '. $dateTime->format('Y-m-d H:i:s').'**';
$mergedRevision->content = $page->latestRevision->content.'<br><br>'.$changedContentSepeartor.'<br>'.$submittedRevision->content;
$mergedRevision->save();

$page->doneEditing();

return $this->redirect(Url::toWiki($page));
}

/**
* @param int $id
* @return $this|Response
* @throws HttpException
*/
public function actionCreateCopy(int $id)
{
$userIdentity = Yii::$app->user->identity->username;
$dateTime = new DateTime();

$page = $this->getWikiPage($id);
if (!$page) {
throw new HttpException(404, 'Wiki page not found!');
}

$parentId = $page->parent_page_id;

$form = (new PageEditForm(['container' => $this->contentContainer]))->forPage($id);
if (!$form->load(Yii::$app->request->post())) {
throw new HttpException(404);
}

$childPage = new WikiPage();
$childPage->title = $page->title.' conflicting copy of '. $userIdentity .' from '. $dateTime->format('Y-m-d H:i:s');
$childPage->parent_page_id = $parentId;
$childPage->content->contentcontainer_id= $page->content->contentcontainer_id;

if (!$childPage->save()) {
throw new HttpException(500, 'Failed to create the child page!');
}

if (!$childPage->id) {
throw new HttpException('Child page ID is not available after saving.');
}

$revision = new WikiPageRevision();
$revision->content = $form->revision->content;
$revision->wiki_page_id = $childPage->id;
$revision->revision = 1;
$revision->user_id = Yii::$app->user->id;

if (!$revision->save()) {
throw new HttpException('Failed to add content to the child page.');
}

$page->doneEditing();

return $this->redirect(Url::toWiki($page));
}

/**
* @param int $id
* @return $this|Response
* @throws HttpException
*/
public function actionEditingStatus(int $id)
{
$page = $this->getWikiPage($id);
if (!$page) {
throw new HttpException(404, 'Wiki page not found!');
}

$user = User::find()->where(['username' => $page->is_currently_editing])->one();
if($user) {
$firstName = $user->profile->firstname;
$lastName = $user->profile->lastname;
$fullName = $firstName.' '.$lastName.' ('.$page->is_currently_editing.')';
}
else { $fullName = ''; }

return $this->asJson([
'success' => true,
'isEditing' => $page->isEditing(),
'body' => $fullName .' '. Yii::t('WikiModule.base', 'is already editing.<br> Editing it would cause conflict. Do you really want to continue?'),
]);
}

/**
* @return $this|Response
*/
public function actionEditingTimerUpdate(int $id = null)
{
$conflictingEditing = false;
$page = $this->getWikiPage($id);
if (!$page) {
return $this->asJson([
'sucess' => false,
]);
}

$user = Yii::$app->user->identity->username;

$editingUser = User::find()->where(['username' => $page->is_currently_editing])->one();
if($editingUser) {
$firstName = $editingUser->profile->firstname;
$lastName = $editingUser->profile->lastname;
$fullName = $firstName.' '.$lastName.' ('.$page->is_currently_editing.')';
}
else { $fullName = ''; }

if ($page->is_currently_editing == NULL) {
$page->updateIsEditing();
}

if ($page->is_currently_editing == $user) {
$page->updateEditingTime();
}
elseif (time() - $page->editing_started_at < self::TTL) {
$conflictingEditing = true;
}

return $this->asJson([
'success' => true,
'conflictingEditing' => $conflictingEditing,
'url' => Url::toWiki($page),
'header' => Yii::t('WikiModule.base', 'Confirm Edit'),
'body' => $fullName .' '. Yii::t('WikiModule.base', 'is already editing.<br> Editing it would cause conflict. Do you really want to continue?'),
'confirmText' => Yii::t('WikiModule.base', 'Cancel'),
'cancelText' => Yii::t('WikiModule.base', 'Continue'),
]);
}
}
24 changes: 24 additions & 0 deletions helpers/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class Url extends \yii\helpers\Url
public const ROUTE_WIKI_DIFF_EDITING = '/wiki/page/diff-editing';
public const ROUTE_WIKI_REVERT = '/wiki/page/revert';
public const ROUTE_EXTRACT_TITLES = '/wiki/page/headlines';
public const ROUTE_WIKI_MERGE = '/wiki/page/merge';
public const ROUTE_WIKI_CREATE_COPY = '/wiki/page/create-copy';
public const ROUTE_WIKI_EDITING_STATUS = '/wiki/page/editing-status';
public const ROUTE_WIKI_EDITING_TIMER_UPDATE = '/wiki/page/editing-timer-update';

public static function toHome(ContentContainerActiveRecord $container)
{
Expand Down Expand Up @@ -129,4 +133,24 @@ public static function toWikiEntry(WikiPage $page)
return static::to([static::ROUTE_WIKI_ENTRY, 'id' => $page->id, 'container' => $page->content->container]);
}

public static function toWikiMerge(WikiPage $page)
{
return static::to([static::ROUTE_WIKI_MERGE, 'id' => $page->id, 'container' => $page->content->container]);
}

public static function toWikiCreateCopy(WikiPage $page)
{
return static::to([static::ROUTE_WIKI_CREATE_COPY, 'id' => $page->id, 'container' => $page->content->container]);
}

public static function toWikiEditingStatus(WikiPage $page)
{
return static::to([static::ROUTE_WIKI_EDITING_STATUS, 'id' => $page->id, 'container' => $page->content->container]);
}

public static function toWikiEditingTimerUpdate(WikiPage $page)
{
return static::to([static::ROUTE_WIKI_EDITING_TIMER_UPDATE, 'id' => $page->id, 'container' => $page->content->container]);
}

}
8 changes: 7 additions & 1 deletion messages/de/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return [
'({n,plural,=1{+1 subpage}other{+{count} subpages}})' => '({n,plural,=1{+1 Unterseite}other{+{count} Unterseiten}})',
'<strong>Confirm</strong> page reverting' => 'Seite rückgängig machen <strong>bestätigen</strong>',
'<strong>Warning!</strong><br><br>Another user has updated this page since you have started editing it. Please confirm that you want to overwrite those changes.<br>:linkToCompare' => '<strong>Warnung!</strong><br><br>Ein anderer Benutzer hat diese Seite gespeichert, seit mit der Bearbeitung begonnen wurde. Sollen diese Änderungen überschreiben werden?<br>:linkToCompare',
'<strong>Warning!</strong><br><br>Another user has updated this page since you have started editing it. Please confirm that you want to overwrite those changes.<br>:linkToCompare' => '<strong>Warnung!</strong><br><br>Ein anderer Benutzer bearbeitet gerade diese Seite. Durch eine parallele Bearbeitung kann es zu Konflikten oder Datenverlust kommen. Möchten Sie trotzdem fortfahren?<br>:linkZuVergleichen',
'<strong>Wiki</strong> link' => '<strong>Wiki</strong>-Verweis',
'<strong>Wiki</strong> module configuration' => '<strong>Wiki</strong> Modulkonfiguration',
'Add Page' => 'Seite hinzufügen',
Expand Down Expand Up @@ -86,4 +86,10 @@
'Hide Navigation Entries of this module globally by default' => '',
'Hide Navigation Entry' => '',
'No wiki pages found.' => '',
'Merge' => 'Zusammenführen',
'Create Copy' => 'Kopie erstellen',
'<strong>Confirm Page Edit</strong>' => '<strong>Seite wird gerade bearbeitet</strong>',
'Continue' => 'Weiter',
'Confirm Edit' => 'Bearbeitung bestätigen',
'is already editing.<br> Editing it would cause conflict. Do you really want to continue?' => 'bearbeitet diese Seite.<br> Durch die Bearbeitung kommt es zu einem Dateikonflikt. Trotzdem fortfahren?',
];
26 changes: 26 additions & 0 deletions migrations/m250203_094213_is_currently_editing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;

/**
* Class m250203_094213_is_currently_editing
*/
class m250203_094213_is_currently_editing extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('wiki_page', 'is_currently_editing', $this->string(50)->null());
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('wiki_page', 'is_currently_editing');

}
}
26 changes: 26 additions & 0 deletions migrations/m250219_192950_editing_started_at.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;

/**
* Class m250219_192950_editing_started_at
*/
class m250219_192950_editing_started_at extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('wiki_page', 'editing_started_at', $this->integer()->null());
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('wiki_page', 'editing_started_at');
}

}
47 changes: 47 additions & 0 deletions models/WikiPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* @property int $sort_order
* @property int $is_container_menu
* @property int $container_menu_order
* @property string|null $is_currently_editing
* @property int|null $editing_started_at
*
* @property-read WikiPage|null $categoryPage
* @property-read WikiPageRevision $latestRevision
Expand All @@ -42,6 +44,7 @@ class WikiPage extends ContentActiveRecord implements Searchable
public const SCENARIO_EDIT = 'edit';
public const CACHE_CHILDREN_COUNT_KEY = 'wikiChildrenCount_%s';
public $moduleId = 'wiki';
public const TTL = 300;
/**
* @inheritdoc
*/
Expand Down Expand Up @@ -540,4 +543,48 @@ public function getIsCategory(): bool

return $this->_isCategory;
}

/**
* Function to check if any other user is currently editing the page
*
* @return bool
*/
public function isEditing() {
$user = Yii::$app->user->identity->username;

if ($this->is_currently_editing == NULL || $this->is_currently_editing == $user) {
return false;
}

if (time() - $this->editing_started_at > self::TTL) {
$this->doneEditing();
return false;
}

return true;
}

/**
* Function to update the Attribute value to the new user in the edit page
*/
public function updateIsEditing() {
$user = Yii::$app->user->identity->username;
if ($this->is_currently_editing == NULL) {
$this->updateAttributes(['is_currently_editing' => $user, 'editing_started_at' => time()]);
}
}

/**
* Function to make the editing attributes null to show that no user is currently editing the page.
*/
public function doneEditing() {
$this->updateAttributes(['is_currently_editing' => new Expression('NULL'), 'editing_started_at' => new Expression('NULL')]);
}

/**
* Function to update the time stamp i.e editing_started_at
*/
public function updateEditingTime() {
$this->updateAttributes(['editing_started_at' => time()]);
}
}
2 changes: 2 additions & 0 deletions models/forms/PageEditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ public function save()
$this->page->content->hidden = $this->hidden;
}

$this->page->doneEditing();

return WikiPage::getDb()->transaction(function ($db) {
if ($this->page->save()) {
$this->revision->wiki_page_id = $this->page->id;
Expand Down
Loading