「MediaWiki:Forum.js」の版間の差分

編集の要約なし
編集の要約なし
233行目: 233行目:
                             headers: { 'Content-Type': 'application/json' },
                             headers: { 'Content-Type': 'application/json' },
                             body: JSON.stringify({
                             body: JSON.stringify({
                                 title: mw.config.get('wgPageName'),
                                 title:   mw.config.get('wgPageName'),
                                 appendtext: `\n{{post|...}}`,  // feditの場合は text: を使う
                                 text:    newText,
                                summary: summary
                                summary: `${msg.deletesummary} #${postId}`
                             })
                             })
                         }).then(r => r.json()).then(data => {
                         }).then(r => r.json()).then(data => {
241行目: 241行目:
                                 location.reload();
                                 location.reload();
                             } else {
                             } else {
                                 mw.notify(msg.posterror);
                                 mw.notify(msg.deleteerror);
                                document.querySelector('#f-post').disabled = false;
                             }
                             }
                         }).catch(() => {
                         }).catch(() => {
                             mw.notify(msg.posterror);
                             mw.notify(msg.deleteerror);
                            document.querySelector('#f-post').disabled = false;
                         });
                         });
                     },
                     },
313行目: 311行目:
                             const anonParam = isAnon ? '|anon=1' : '';
                             const anonParam = isAnon ? '|anon=1' : '';
                             content += `{{post|${mw.forum.username}|1|{{subst:#timel:Y/m/d H:i:s}}|4=${document.querySelector('#wpTextbox1').value}${anonParam}}}`;
                             content += `{{post|${mw.forum.username}|1|{{subst:#timel:Y/m/d H:i:s}}|4=${document.querySelector('#wpTextbox1').value}${anonParam}}}`;
                             new mw.Api().postWithToken('csrf', {
                             fetch('/mediawiki/forum-proxy.php', {
                                 action: 'edit',
                                method: 'POST',
                                 title: `${mw.forum.toppage}/${document.querySelector('#f-threadname').value}`,
                                 headers: { 'Content-Type': 'application/json' },
                                text: content,
                                 body: JSON.stringify({
                                summary: msg.createthreadsummary,
                                    title: `${mw.forum.toppage}/${document.querySelector('#f-threadname').value}`,
                                 format: 'json'
                                    text: content,
                             }).done(() => {
                                    summary: msg.createthreadsummary,
                                 location.href = `${mw.config.get('wgArticlePath').replace('$1', mw.forum.toppage)}/${document.querySelector('#f-threadname').value}`;
                                    protect: true
                             }).fail(() => {
                                 })
                             }).then(r => r.json()).then(data => {
                                 if (data.result === 'Success') {
                                    location.href = `${mw.config.get('wgArticlePath').replace('$1', mw.forum.toppage)}/${document.querySelector('#f-threadname').value}`;
                                } else {
                                    mw.notify(msg.posterror);
                                }
                             }).catch(() => {
                                 mw.notify(msg.posterror);
                                 mw.notify(msg.posterror);
                             });
                             });
379行目: 384行目:
                         const anonParam = isAnon ? '|anon=1' : '';
                         const anonParam = isAnon ? '|anon=1' : '';


                         new mw.Api().postWithToken('csrf', {
                         // プロキシ経由でBot名義に編集する
                            action: 'edit',
                        const postBody = {
                             title: mw.config.get('wgPageName'),
                             title:   mw.config.get('wgPageName'),
                             [fedit ? 'text' : 'appendtext']: fedit
                             summary: summary
                                ? source.replace(new RegExp(`\\{\\{post\\|(.*?)\\|${fedit}\\|(.*?)\\|4=((.|\n)*?)}}`), `{{post|$1|${fedit}|$2|4=${document.querySelector('#wpTextbox1').value}}}`)
                        };
                                : `\n{{post|${mw.forum.username}|${lp}|{{subst:#timel:Y/m/d H:i:s}}|4=${document.querySelector('#wpTextbox1').value}${document.querySelector('#f-reply-cb').checked ? '|re=' + document.querySelector('#f-reply').value : ''}${anonParam}}}`,
                        if (fedit) {
                             summary: summary,
                            postBody.text = source.replace(new RegExp(`\\{\\{post\\|(.*?)\\|${fedit}\\|(.*?)\\|4=((.|\n)*?)}}`), `{{post|$1|${fedit}|$2|4=${document.querySelector('#wpTextbox1').value}}}`);
                             format: 'json'
                        } else {
                         }).done(() => {
                            postBody.appendtext = `\n{{post|${mw.forum.username}|${lp}|{{subst:#timel:Y/m/d H:i:s}}|4=${document.querySelector('#wpTextbox1').value}${document.querySelector('#f-reply-cb').checked ? '|re=' + document.querySelector('#f-reply').value : ''}${anonParam}}}`;
                             if (fedit) {
                        }
                                location.href = `${mw.util.getUrl()}#post-${fedit}`;
                        fetch('/mediawiki/forum-proxy.php', {
                             method: 'POST',
                             headers: { 'Content-Type': 'application/json' },
                            body: JSON.stringify(postBody)
                         }).then(r => r.json()).then(data => {
                             if (data.result === 'Success') {
                                if (fedit) {
                                    location.href = `${mw.util.getUrl()}#post-${fedit}`;
                                } else {
                                    location.reload();
                                }
                             } else {
                             } else {
                                 location.reload();
                                 mw.notify(msg.posterror);
                                document.querySelector('#f-post').disabled = false;
                             }
                             }
                         }).fail(() => {
                         }).catch(() => {
                             mw.notify(msg.posterror);
                             mw.notify(msg.posterror);
                             document.querySelector('#f-post').disabled = false;
                             document.querySelector('#f-post').disabled = false;