Skip to content

Commit

Permalink
Merge pull request #239 from inpageedit/dragon-fish/issue238
Browse files Browse the repository at this point in the history
Add timestamp to page diff function
  • Loading branch information
dragon-fish authored Dec 29, 2023
2 parents 36a7aa7 + 2650281 commit 87d3c34
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 184 deletions.
6 changes: 3 additions & 3 deletions src/method/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { updateNotice } from './updateNotice'
import { syncI18nData } from './syncI18nData'

import version from '../module/version'
import { pluginCDN } from '../module/api'
import { pluginCDN } from '../module/endpoints'

// 导入全部模块
import { _analytics } from '../module/_analytics'
import { _msg } from '../module/_msg'
import { about } from '../module/about'
import * as api from '../module/api'
import * as endpoints from '../module/endpoints'
import { articleLink } from '../module/articleLink'
import { linksHere } from '../module/linksHere'
import { loadQuickDiff } from '../module/loadQuickDiff'
Expand Down Expand Up @@ -68,7 +68,7 @@ export default async function init() {
const InPageEdit = {
_dir,
about,
api,
endpoints,
articleLink,
linksHere,
loadQuickDiff,
Expand Down
2 changes: 1 addition & 1 deletion src/method/loadStyles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pluginCDN } from '../module/api'
import { pluginCDN } from '../module/endpoints'

// 放在越上面优先级越高
const styleList = [
Expand Down
10 changes: 5 additions & 5 deletions src/module/_analytics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { analyticsApi } from './api'
import { analyticsApi } from './endpoints'
import { preference } from './preference'
import { config } from './util'
import { mwConfig } from './mw'
import version from './version'

/**
Expand All @@ -14,8 +14,8 @@ export function _analytics(featID) {
}
const submitData = {
siteUrl: getSiteID(),
siteName: config.wgSiteName,
userName: config.wgUserName,
siteName: mwConfig.wgSiteName,
userName: mwConfig.wgUserName,
featureID: featID,
ipeVersion: version,
}
Expand All @@ -30,7 +30,7 @@ export function _analytics(featID) {
}

export function getSiteID() {
return `${config.wgServer}${config.wgArticlePath.replace('$1', '')}`
return `${mwConfig.wgServer}${mwConfig.wgArticlePath.replace('$1', '')}`
}

export {
Expand Down
21 changes: 11 additions & 10 deletions src/module/_hasRight.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
var config = mw.config.get()

/**
* @module _hasRight 是否拥有权限
* @param {String} right
* @return {Boolean}
* @param {string} right
* @return {boolean}
*/
export const _hasRight = function (right) {
if (config.wgUserIsBlocked === true) {
return false
}
if (mw.config.get('wgUserRights').indexOf(right) > -1) {
return true
} else {
const conf = window.mw.config.get()
console.info(
'[InPageEdit] _hasRight',
right,
conf.wgUserIsBlocked,
conf.wgUserRights
)
if (conf.wgUserIsBlocked) {
return false
}
return (conf.wgUserRights || []).includes(right)
}
2 changes: 1 addition & 1 deletion src/module/about.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { _msg } from './_msg'
import { aboutUrl } from './api'
import { aboutUrl } from './endpoints'

/**
* @module about 关于插件模块
Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions src/module/linksHere.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import { _analytics } from './_analytics'
import { $progress, $link } from './_elements'
import { _msg } from './_msg'
import { mwApi, config } from './util'
import { mwApi, mwConfig } from './mw'
import { quickEdit } from './quickEdit'

/**
* @function isFile
* @returns {Boolean} Is file page?
*/
const isFile = (title) => {
const fileReg = new RegExp(`^(File|${config.wgFormattedNamespaces[6]}):`)
const fileReg = new RegExp(`^(File|${mwConfig.wgFormattedNamespaces[6]}):`)
return fileReg.test(title)
}

Expand Down Expand Up @@ -55,7 +56,7 @@ const makeList = (list) => {
}),
' | ',
$link({ text: _msg('quick-edit') }).on('click', function () {
require('./quickEdit').quickEdit({
quickEdit({
page: title,
reload: false,
})
Expand All @@ -71,10 +72,10 @@ const makeList = (list) => {
* @module linksHere
* @param {string} title page title
*/
export async function linksHere(title = config.wgPageName) {
export async function linksHere(title = mwConfig.wgPageName) {
_analytics('linkshere')

if (!title || typeof title !== 'string') title = config.wgPageName
if (!title || typeof title !== 'string') title = mwConfig.wgPageName

// 构建内容
var $progressBar = $($progress)
Expand Down
11 changes: 5 additions & 6 deletions src/module/loadQuickDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { _msg } from './_msg'
import { _analytics } from './_analytics'
import { quickDiff } from './quickDiff'
import { quickEdit } from './quickEdit'

const config = mw.config.get()
import { mwConfig } from './mw'
const { getParamValue } = mw.util

function injectLinks(container) {
Expand All @@ -30,8 +29,8 @@ function injectLinks(container) {
?.aliases.map((i) => [i, encodeURI(i)])
.flat() || ['Diff']
).join('|')
const articlePath = config.wgArticlePath.replace('$1', '')
const specialNS = `Special|${config.wgFormattedNamespaces[-1]}`
const articlePath = mwConfig.wgArticlePath.replace('$1', '')
const specialNS = `Special|${mwConfig.wgFormattedNamespaces[-1]}`
const specialDiffReg = new RegExp(
`^${articlePath}(?:${specialNS}):(?:${specialDiffNames})/(\\d+|${RELATIVE_TYPES.join(
'|'
Expand Down Expand Up @@ -104,7 +103,7 @@ export function loadQuickDiff(container) {
injectLinks(container)

// 查看历史页面的比较按钮与快速编辑
if (config.wgAction === 'history') {
if (mwConfig.wgAction === 'history') {
$('.historysubmit.mw-history-compareselectedversions-button').after(
$('<button>')
.text(_msg('quick-diff'))
Expand Down Expand Up @@ -132,7 +131,7 @@ export function loadQuickDiff(container) {
text: _msg('quick-edit'),
}).on('click', function () {
quickEdit({
page: config.wgPageName,
page: mwConfig.wgPageName,
revision: oldid,
})
})
Expand Down
14 changes: 14 additions & 0 deletions src/module/mw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import version from './version'

export const mwConfig = mw.config.get()
export const mwApi = new mw.Api({
parameters: {
formatversion: 2,
format: 'json',
},
ajax: {
headers: {
'Api-User-Agent': `InPageEdit-v2/${version}`,
},
},
})
2 changes: 1 addition & 1 deletion src/module/pluginStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import _dir from '../method/_dir';
// import { _msg } from './_msg';
import { pluginCDN } from './api'
import { pluginCDN } from './endpoints'
import { preference } from './preference'
import { loadScript } from '../method/loadScript'

Expand Down
2 changes: 1 addition & 1 deletion src/module/preference.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
analyticsApi,
analyticsDash,
pluginCDN,
} from './api'
} from './endpoints'
import version from './version'
import { pluginStore } from './pluginStore'
import { _analytics, getSiteID } from './_analytics'
Expand Down
10 changes: 4 additions & 6 deletions src/module/quickDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { _analysis } from './_analytics'
import { _msg } from './_msg'
import { _hasRight } from './_hasRight'
import { $br } from './_elements'

var mwApi = new mw.Api()
var config = mw.config.get()
import { mwApi, mwConfig } from './mw'

/**
* @module quickDelete 删除页面模块
Expand All @@ -13,8 +11,8 @@ var config = mw.config.get()
export function quickDelete(page, givenReason = '') {
mw.hook('InPageEdit.quickDelete').fire()
console.log('Quick delete', page, givenReason)
var reason
page = page || config.wgPageName
let reason = ''
page = page || mwConfig.wgPageName

ssi_modal.show({
outSideClose: false,
Expand Down Expand Up @@ -112,7 +110,7 @@ export function quickDelete(page, givenReason = '') {
content:
_msg('notify-delete-error') +
': <br/><span style="font-size:amall">' +
errorThrown.error['*'] +
errorThrown.error.info +
'(<code>' +
errorThrown.error['code'] +
'</code>)</span>',
Expand Down
Loading

0 comments on commit 87d3c34

Please sign in to comment.