Skip to content

Commit

Permalink
Hide "Copy revision ID" on creation pages or non-existing pages.
Browse files Browse the repository at this point in the history
The "Creating X" or "There is currently no text in this page." pages do not have a valid revision ID (it is always 0).
  • Loading branch information
bonk-dev committed May 27, 2024
1 parent ee1547e commit dc4df80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/Tools/SidebarTools.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {CustomSidebarTool, sideTool} from "./Utils/ToolManager";
import {getMwApi} from "../Utilities/MediaWikiJsApi";
import {getCurrentPageInfo, getEnglishRevisionId, PageInfo} from "../Utilities/PageUtils";
import {getCurrentPageInfo, getEnglishRevisionId, PageInfo, PageType} from "../Utilities/PageUtils";
import {getCurrentLanguage, setCurrentLanguage} from "../Storage/ScriptDb";
import {getLangInfoFor, LanguagesInfo} from "../Internalization/I18nConstants";

export const copyCurrentRevisionIdTool = (): CustomSidebarTool => {
const showCallback = (info: PageInfo) => {
return info.pageType !== PageType.CreateEditor && info.pageType !== PageType.ReadNonExisting;
};

const toolHandler = async () => {
const revisionId = getMwApi()
.config
Expand All @@ -17,7 +21,8 @@ export const copyCurrentRevisionIdTool = (): CustomSidebarTool => {
return sideTool({
name: "copy-current-revision-id",
displayText: "Copy revision ID",
handler: toolHandler
handler: toolHandler,
showCallback: showCallback
});
};

Expand Down
21 changes: 17 additions & 4 deletions src/Utilities/PageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,30 @@ export enum PageType {
*/
Read = 0,

/**
* Read page of a non-existing article
*/
ReadNonExisting = 1,

/**
* Editing an existing page
*/
Editor = 1,
Editor = 2,

/**
* Creating a new page
*/
CreateEditor = 2,
CreateEditor = 3,

/**
* Viewing the source of an article (cannot edit due to lack of permissions)
*/
ViewOnlyEditor = 3,
ViewOnlyEditor = 4,

/**
* Other type of page (e.g. Recent changes)
*/
Other = 4
Other = 5
}

export type PageInfo = {
Expand Down Expand Up @@ -73,6 +78,14 @@ function getCurrentPageType(): PageType {
? PageType.Editor
: PageType.ViewOnlyEditor;
case 'view':
const revisionId = getMwApi()
.config
.values
.wgCurRevisionId;
if (revisionId === 0) {
return PageType.ReadNonExisting;
}

return isArticle
? PageType.Read
: PageType.Other;
Expand Down

0 comments on commit dc4df80

Please sign in to comment.