jenkins-bot has submitted this change and it was merged.
Change subject: Disable write actions when a page is not LQT
......................................................................
Disable write actions when a page is not LQT
LQT can be enabled by adding a property to a page. When that
property is later removed, all threads created on that page
are now made read-only.
Bug: T107894
Change-Id: Iead8229d8a715ebc81b21e6e8868f5b03de5e05b
---
M api/ApiThreadAction.php
M classes/View.php
M i18n/en.json
M i18n/qqq.json
M lqt.js
5 files changed, 90 insertions(+), 68 deletions(-)
Approvals:
Mattflaschen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/api/ApiThreadAction.php b/api/ApiThreadAction.php
index c22b7bb..d20a17a 100644
--- a/api/ApiThreadAction.php
+++ b/api/ApiThreadAction.php
@@ -9,6 +9,7 @@
}
$allowedAllActions = array( 'markread' );
+ $actionsAllowedOnNonLqtPage = array( 'markread', 'markunread' );
$action = $params['threadaction'];
// Pull the threads from the parameters
@@ -29,6 +30,12 @@
if ( $threadObj instanceof Thread ) {
$threads[] = $threadObj;
+
+ if ( !in_array( $action,
$actionsAllowedOnNonLqtPage ) && !LqtDispatch::isLqtPage(
$threadObj->getTitle() ) ) {
+ $articleTitleDBKey =
$threadObj->getTitle()->getDBkey();
+ $message = wfMessage(
'lqt-not-a-liquidthreads-page', $articleTitleDBKey )->text();
+ $this->dieUsageMsg( $message );
+ }
}
}
}
diff --git a/classes/View.php b/classes/View.php
index b3e60ad..bbdb26b 100644
--- a/classes/View.php
+++ b/classes/View.php
@@ -1158,6 +1158,7 @@
*/
function threadCommands( $thread ) {
$commands = array();
+ $isLqtPage = LqtDispatch::isLqtPage( $thread->getTitle() );
$history_url = self::permalinkUrlWithQuery( $thread, array(
'action' => 'history' ) );
$commands['history'] = array(
@@ -1172,16 +1173,18 @@
$user_can_edit = $thread->root()->getTitle()->quickUserCan(
'edit' );
$editMsg = $user_can_edit ? 'edit' : 'viewsource';
- $commands['edit'] = array(
- 'label' => wfMessage( $editMsg )->parse(),
- 'href' => $this->talkpageUrl(
- $this->title,
- 'edit', $thread,
- true, /* include fragment */
- $this->request
- ),
- 'enabled' => true
- );
+ if ( $isLqtPage ) {
+ $commands['edit'] = array(
+ 'label' => wfMessage( $editMsg )->parse(),
+ 'href' => $this->talkpageUrl(
+ $this->title,
+ 'edit', $thread,
+ true, /* include fragment */
+ $this->request
+ ),
+ 'enabled' => true
+ );
+ }
if ( $this->user->isAllowed( 'delete' ) ) {
$delete_url = $thread->title()->getLocalURL(
'action=delete' );
@@ -1194,30 +1197,32 @@
);
}
- if ( !$thread->isTopmostThread() && $this->user->isAllowed(
'lqt-split' ) ) {
- $splitUrl = SpecialPage::getTitleFor( 'SplitThread',
+ if ( $isLqtPage ) {
+ if ( !$thread->isTopmostThread() &&
$this->user->isAllowed( 'lqt-split' ) ) {
+ $splitUrl = SpecialPage::getTitleFor(
'SplitThread',
$thread->title()->getPrefixedText()
)->getLocalURL();
- $commands['split'] = array(
- 'label' => wfMessage( 'lqt-thread-split'
)->parse(),
- 'href' => $splitUrl,
- 'enabled' => true
- );
- }
+ $commands['split'] = array(
+ 'label' => wfMessage(
'lqt-thread-split' )->parse(),
+ 'href' => $splitUrl,
+ 'enabled' => true
+ );
+ }
- if ( $this->user->isAllowed( 'lqt-merge' ) ) {
- $mergeParams = $_GET;
- $mergeParams['lqt_merge_from'] = $thread->id();
+ if ( $this->user->isAllowed( 'lqt-merge' ) ) {
+ $mergeParams = $_GET;
+ $mergeParams['lqt_merge_from'] = $thread->id();
- unset( $mergeParams['title'] );
+ unset( $mergeParams['title'] );
- $mergeUrl = $this->title->getLocalURL( wfArrayToCgi(
$mergeParams ) );
- $label = wfMessage( 'lqt-thread-merge' )->parse();
+ $mergeUrl = $this->title->getLocalURL(
wfArrayToCgi( $mergeParams ) );
+ $label = wfMessage( 'lqt-thread-merge'
)->parse();
- $commands['merge'] = array(
- 'label' => $label,
- 'href' => $mergeUrl,
- 'enabled' => true
- );
+ $commands['merge'] = array(
+ 'label' => $label,
+ 'href' => $mergeUrl,
+ 'enabled' => true
+ );
+ }
}
$commands['link'] = array(
@@ -1238,6 +1243,8 @@
* @param $thread Thread
*/
function threadMajorCommands( $thread ) {
+ $isLqtPage = LqtDispatch::isLqtPage( $thread->getTitle() );
+
if ( $thread->isHistorical() ) {
// No links for historical threads.
$history_url = self::permalinkUrlWithQuery( $thread,
@@ -1254,32 +1261,35 @@
$commands = array();
- if ( $this->user->isAllowed( 'lqt-merge' ) &&
- $this->request->getCheck( 'lqt_merge_from' ) ) {
- $srcThread = Threads::withId( $this->request->getVal(
'lqt_merge_from' ) );
- $par = $srcThread->title()->getPrefixedText();
- $mergeTitle = SpecialPage::getTitleFor( 'MergeThread',
$par );
- $mergeUrl = $mergeTitle->getLocalURL( 'dest=' .
$thread->id() );
- $label = wfMessage( 'lqt-thread-merge-to' )->parse();
+ if ( $isLqtPage ) {
+ if ( $this->user->isAllowed( 'lqt-merge' ) &&
+ $this->request->getCheck( 'lqt_merge_from' )
+ ) {
+ $srcThread = Threads::withId(
$this->request->getVal( 'lqt_merge_from' ) );
+ $par = $srcThread->title()->getPrefixedText();
+ $mergeTitle = SpecialPage::getTitleFor(
'MergeThread', $par );
+ $mergeUrl = $mergeTitle->getLocalURL( 'dest=' .
$thread->id() );
+ $label = wfMessage( 'lqt-thread-merge-to'
)->parse();
- $commands['merge-to'] = array(
- 'label' => $label,
- 'href' => $mergeUrl,
- 'enabled' => true,
- 'tooltip' => $label
- );
- }
+ $commands['merge-to'] = array(
+ 'label' => $label,
+ 'href' => $mergeUrl,
+ 'enabled' => true,
+ 'tooltip' => $label
+ );
+ }
- if ( $thread->canUserReply( $this->user, 'quick' ) === true ) {
- $commands['reply'] = array(
- 'label' => wfMessage( 'lqt_reply' )->parse(),
- 'href' => $this->talkpageUrl( $this->title,
'reply', $thread,
- true /* include fragment */,
$this->request ),
- 'enabled' => true,
- 'showlabel' => 1,
- 'tooltip' => wfMessage( 'lqt_reply' )->parse(),
- 'icon' => 'reply.png',
- );
+ if ( $thread->canUserReply( $this->user, 'quick' ) ===
true ) {
+ $commands['reply'] = array(
+ 'label' => wfMessage( 'lqt_reply'
)->parse(),
+ 'href' => $this->talkpageUrl(
$this->title, 'reply', $thread,
+ true /* include fragment */,
$this->request ),
+ 'enabled' => true,
+ 'showlabel' => 1,
+ 'tooltip' => wfMessage( 'lqt_reply'
)->parse(),
+ 'icon' => 'reply.png',
+ );
+ }
}
// Parent post link
@@ -1359,12 +1369,14 @@
);
}
- $summarizeUrl = self::permalinkUrl( $thread, 'summarize',
$thread->id() );
- $commands['summarize'] = array(
- 'label' => wfMessage( 'lqt_summarize_link' )->parse(),
- 'href' => $summarizeUrl,
- 'enabled' => true,
- );
+ if ( LqtDispatch::isLqtPage( $thread->getTitle() ) ) {
+ $summarizeUrl = self::permalinkUrl( $thread,
'summarize', $thread->id() );
+ $commands['summarize'] = array(
+ 'label' => wfMessage( 'lqt_summarize_link'
)->parse(),
+ 'href' => $summarizeUrl,
+ 'enabled' => true,
+ );
+ }
Hooks::run( 'LiquidThreadsTopLevelCommands', array( $thread,
&$commands ) );
@@ -2069,7 +2081,7 @@
$class .= ' lqt-thread-no-subthreads';
}
- if ( ! $thread->title()->quickUserCan( 'edit' ) ) {
+ if ( ! $thread->title()->quickUserCan( 'edit' ) || !
LqtDispatch::isLqtPage( $thread->getTitle() ) ) {
$class .= ' lqt-thread-uneditable';
}
diff --git a/i18n/en.json b/i18n/en.json
index 567f46f..44d61b3 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -235,6 +235,7 @@
"lqt-historicalrevision-error": "The revision you have selected is
corrupt, and cannot be viewed.",
"lqt-reply-subpage": "reply",
"lqt-pagechange-editformopen": "You have unsaved text open on this
page. You may lose it if you go away from this page.",
+ "lqt-not-a-liquidthreads-page": "$1 is not a LiquidThreads page",
"nstab-thread": "Thread",
"nstab-summary": "Summary",
"pageinfo-usinglqt": "Threaded discussion enabled",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 493ab18..d2e3ef1 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -212,6 +212,7 @@
"lqt-edit-bump": "See {{msg-mw|Lqt-edit-bump-tooltip}} for the
explanation of this feature.",
"lqt-reply-subpage": "Part of the page title when a LiquidThread answer
is given. Should probably be translated as a noun and not as a
verb.\n\n{{Identical|Reply}}",
"lqt-pagechange-editformopen": "Shown as a JavaScript confirmation
dialog to the user when they try to leave the page while an LQT editing form is
open.",
+ "lqt-not-a-liquidthreads-page": "Returned by the API when a write
action is attempted on a thread that belong to a page that is not a
LiquidThreads page. Parameters:\n* $1 - title of the page that contains the
thread",
"nstab-thread": "Used as tab title of the Thread
namespace.\n{{Identical|Thread}}",
"nstab-summary": "Used as tab title for the Summary
namespace.\n{{Identical|Summary}}",
"pageinfo-usinglqt": "Entry for whether the page uses LiquidThreads or
not",
diff --git a/lqt.js b/lqt.js
index 69e163e..02271b5 100644
--- a/lqt.js
+++ b/lqt.js
@@ -326,14 +326,15 @@
replyLink.data( 'thread-id', threadID );
replyLink.click( liquidThreads.handleReplyLink );
- // Add "Drag to new location" to menu
- var dragLI = $( '<li class="lqt-command-drag lqt-command" />' );
- var dragLink = $( '<a/>' ).text( mw.msg( 'lqt-drag-activate' )
);
- dragLink.attr( 'href', '#' );
- dragLI.append( dragLink );
- dragLink.click( liquidThreads.activateDragDrop );
-
- menu.append( dragLI );
+ if ( ! menu.closest( '.lqt_thread' ).is(
'.lqt-thread-uneditable' ) ) {
+ // Add "Drag to new location" to menu
+ var dragLI = $( '<li class="lqt-command-drag
lqt-command" />' );
+ var dragLink = $( '<a/>' ).text( mw.msg(
'lqt-drag-activate' ) );
+ dragLink.attr( 'href', '#' );
+ dragLI.append( dragLink );
+ dragLink.click( liquidThreads.activateDragDrop );
+ menu.append( dragLI );
+ }
// Remove split and merge
menu.contents().filter( '.lqt-command-split,.lqt-command-merge'
).remove();
--
To view, visit https://gerrit.wikimedia.org/r/230224
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iead8229d8a715ebc81b21e6e8868f5b03de5e05b
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/LiquidThreads
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits