Index: branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php |
— | — | @@ -235,14 +235,17 @@ |
236 | 236 | // $wgDefaultUserOptions['lqtdisplaycount'] = 25; |
237 | 237 | // $wgDefaultUserOptions['lqtcustomsignatures'] = true; |
238 | 238 | // |
239 | | -// // API |
| 239 | +// API |
240 | 240 | // $wgAutoloadClasses['ApiQueryLQTThreads'] = $dir . 'api/ApiQueryLQTThreads.php'; |
241 | 241 | // $wgAPIListModules['threads'] = 'ApiQueryLQTThreads'; |
242 | 242 | // $wgAutoloadClasses['ApiFeedLQTThreads'] = $dir . 'api/ApiFeedLQTThreads.php'; |
243 | 243 | // $wgAPIModules['feedthreads'] = 'ApiFeedLQTThreads'; |
244 | 244 | // $wgAutoloadClasses['ApiThreadAction'] = $dir . '/api/ApiThreadAction.php'; |
245 | 245 | // $wgAPIModules['threadaction'] = 'ApiThreadAction'; |
246 | | -// |
| 246 | + |
| 247 | +$wgAutoloadClasses['ApiLqtForm'] = $dir.'/api/ApiLqtForm.php'; |
| 248 | +$wgAPIModules['lqtform'] = 'ApiLqtForm'; |
| 249 | + |
247 | 250 | // // Path to the LQT directory |
248 | 251 | // $wgLiquidThreadsExtensionPath = "{$wgScriptPath}/extensions/LiquidThreads"; |
249 | 252 | |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php |
— | — | @@ -458,7 +458,7 @@ |
459 | 459 | * @return String |
460 | 460 | */ |
461 | 461 | public function getUniqueIdentifier() { |
462 | | - return 'lqt-topic:'.$this->getID(); |
| 462 | + return 'lqt-topic_'.$this->getID(); |
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php |
— | — | @@ -468,7 +468,7 @@ |
469 | 469 | * @return String |
470 | 470 | */ |
471 | 471 | public function getUniqueIdentifier() { |
472 | | - return 'lqt-post:'.$this->getID(); |
| 472 | + return 'lqt-post_'.$this->getID(); |
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Channel.php |
— | — | @@ -196,6 +196,6 @@ |
197 | 197 | * @return String |
198 | 198 | */ |
199 | 199 | public function getUniqueIdentifier() { |
200 | | - return 'lqt-channel:'.$this->getID(); |
| 200 | + return 'lqt-channel_'.$this->getID(); |
201 | 201 | } |
202 | 202 | } |
Index: branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php |
— | — | @@ -0,0 +1,135 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ApiLqtForm extends ApiBase { |
| 5 | + |
| 6 | + public function execute() { |
| 7 | + $params = $this->extractRequestParams(); |
| 8 | + $result = $this->getResult(); |
| 9 | + |
| 10 | + $form = $this->getForm( $params ); |
| 11 | + |
| 12 | + global $wgUser; |
| 13 | + if ( $params['submit'] ) { |
| 14 | + if ( ! $wgUser->matchEditToken( $params['token'] ) ) { |
| 15 | + $this->dieUsage( "Invalid edit token", 'invalid-token' ); |
| 16 | + } |
| 17 | + |
| 18 | + $requestParams = array(); |
| 19 | + |
| 20 | + $requestParams['edittoken'] = $params['token']; |
| 21 | + $requestParams['lqt-subject'] = $params['subject']; |
| 22 | + $requestParams['lqt-edit-content'] = $params['content']; |
| 23 | + $requestParams['lqt-signature'] = $params['signature']; |
| 24 | + |
| 25 | + $request = new FauxRequest( $requestParams ); |
| 26 | + |
| 27 | + if ( ! $form->validate( $request ) ) { |
| 28 | + $this->dieUsage( "Invalid parameters", 'invalid-param' ); |
| 29 | + } |
| 30 | + |
| 31 | + $formResult = $form->submit( $request ); |
| 32 | + |
| 33 | + if ( $formResult ) { |
| 34 | + $formOutput = array( 'submit' => 'success' ); |
| 35 | + |
| 36 | + $result->addValue( null, 'form', $formOutput ); |
| 37 | + } |
| 38 | + } else { |
| 39 | + $formOutput = array( |
| 40 | + 'html' => $form->getFormHTML(), |
| 41 | + 'token' => $wgUser->editToken(), |
| 42 | + ); |
| 43 | + |
| 44 | + $result->addValue( null, 'form', $formOutput ); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Get an array of valid forms and their corresponding classes. |
| 50 | + */ |
| 51 | + public function getForms() { |
| 52 | + return array( |
| 53 | + 'new' => 'LiquidThreadsNewTopicForm', |
| 54 | + 'reply' => 'LiquidThreadsReplyForm', |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Creates the appropriate LiquidThreadsEditForm object |
| 60 | + * @param $params Array: The parameters passed to the API module. |
| 61 | + */ |
| 62 | + public function getForm( $params ) { |
| 63 | + global $wgUser; |
| 64 | + |
| 65 | + $formName = $params['form']; |
| 66 | + |
| 67 | + if ( $formName == 'new' ) { |
| 68 | + if ( ! $params['channel'] ) { |
| 69 | + $this->dieUsage( 'You must specify a channel for the new form', 'missing-param' ); |
| 70 | + } |
| 71 | + |
| 72 | + try { |
| 73 | + $channel = LiquidThreadsChannel::newFromID( $params['channel'] ); |
| 74 | + } catch ( MWException $excep ) { |
| 75 | + $this->dieUsage( "You must specify a valid channel", 'invalid-param' ); |
| 76 | + } |
| 77 | + |
| 78 | + return new LiquidThreadsNewTopicForm( $wgUser, $channel ); |
| 79 | + } elseif ( $formName == 'reply' ) { |
| 80 | + if ( ! $params['topic'] ) { |
| 81 | + $this->dieUsage( 'You must specify a topic to reply to', 'missing-param' ); |
| 82 | + } |
| 83 | + |
| 84 | + $replyPost = null; |
| 85 | + |
| 86 | + try { |
| 87 | + $topic = LiquidThreadsTopic::newFromID( $params['topic'] ); |
| 88 | + } catch ( MWException $e ) { |
| 89 | + $this->dieUsage( "You must specify a valid topic", 'invalid-param' ); |
| 90 | + } |
| 91 | + |
| 92 | + if ( $params['reply-post'] ) { |
| 93 | + try { |
| 94 | + $replyPost = LiquidThreadsPost::newFromID( $params['reply-post'] ); |
| 95 | + } catch ( MWException $e ) { |
| 96 | + $this->dieUsage( "Invalid reply-post", 'invalid-param' ); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + return new LiquidThreadsReplyForm( $wgUser, $topic, $replyPost ); |
| 101 | + } else { |
| 102 | + $this->dieUsage( "Not yet implemented", 'not-implemented' ); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + public function getAllowedParams() { |
| 107 | + return array( |
| 108 | + 'form' => array( |
| 109 | + ApiBase::PARAM_REQUIRED => true, |
| 110 | + ApiBase::PARAM_TYPE => array_keys( $this->getForms() ), |
| 111 | + ), |
| 112 | + |
| 113 | + // Parameters for new form |
| 114 | + 'channel' => NULL, |
| 115 | + |
| 116 | + // Parameters for reply form |
| 117 | + 'topic' => NULL, |
| 118 | + 'reply-post' => NULL, |
| 119 | + |
| 120 | + // Submission parameters |
| 121 | + 'submit' => array( |
| 122 | + ApiBase::PARAM_TYPE => 'boolean', |
| 123 | + ), |
| 124 | + |
| 125 | + 'subject' => NULL, |
| 126 | + 'content' => NULL, |
| 127 | + 'signature' => NULL, |
| 128 | + |
| 129 | + 'token' => NULL, |
| 130 | + ); |
| 131 | + } |
| 132 | + |
| 133 | + public function getVersion() { |
| 134 | + return __CLASS__ . ': $Id: ApiLqtForm.php 79941 2011-01-10 17:18:57Z hartman $'; |
| 135 | + } |
| 136 | +} |
Index: branches/lqt-updates/extensions/LiquidThreads/lqt.js |
— | — | @@ -16,6 +16,14 @@ |
17 | 17 | var liquidThreads = { |
18 | 18 | currentReplyThread : null, |
19 | 19 | currentToolbar : null, |
| 20 | + |
| 21 | + 'removePrefix' : function(string, prefix) { |
| 22 | + if ( string.substr(0,prefix.length) != prefix ) { |
| 23 | + throw "Invalid prefix for this string"; |
| 24 | + } |
| 25 | + |
| 26 | + return string.substr(prefix.length); |
| 27 | + }, |
20 | 28 | |
21 | 29 | 'handleReplyLink' : function(e) { |
22 | 30 | if (e.preventDefault) |
— | — | @@ -27,27 +35,33 @@ |
28 | 36 | target = $j(e.target); |
29 | 37 | } |
30 | 38 | |
31 | | - var container = $j(target).closest('.lqt-post-tree-wrapper')[0]; |
32 | | - var thread_id = $j(this).data('thread-id'); |
| 39 | + var postContainer = $j(target).closest('.lqt-post-tree-wrapper')[0]; |
| 40 | + var topicContainer = $j(target).closest('.lqt-topic')[0]; |
33 | 41 | |
34 | | - // hide the form for this thread if it's currently being shown |
35 | | - if ( thread_id == liquidThreads.currentReplyThread && $j( '#wpTextbox1' ).is( ':visible' ) ) { |
36 | | - liquidThreads.cancelEdit({}); |
37 | | - return; |
| 42 | +// // hide the form for this thread if it's currently being shown |
| 43 | +// if ( thread_id == liquidThreads.currentReplyThread && $j( '#wpTextbox1' ).is( ':visible' ) ) { |
| 44 | +// liquidThreads.cancelEdit({}); |
| 45 | +// return; |
| 46 | +// } |
| 47 | + |
| 48 | + var topicID = liquidThreads.removePrefix( topicContainer.id, 'lqt-topic_' ); |
| 49 | + var params = { 'form' : 'reply', 'topic' : topicID }; |
| 50 | + |
| 51 | + if ( $j(postContainer).parent()[0] != topicContainer ) { |
| 52 | + var postID = liquidThreads.removePrefix( postContainer.id, 'lqt-post_' ); |
| 53 | + params['reply-post'] = postID; |
38 | 54 | } |
39 | 55 | |
40 | | - var params = { 'method' : 'reply', 'thread' : thread_id }; |
41 | | - |
42 | | - var repliesElement = $j(container).contents().filter('.lqt-replies'); |
| 56 | + var repliesElement = $j(postContainer).contents().filter('.lqt-replies'); |
43 | 57 | var replyDiv = repliesElement.contents().filter('.lqt-reply-form'); |
44 | | - replyDiv = replyDiv.add( $j(container).contents().filter('.lqt-reply-form') ); |
| 58 | + replyDiv = replyDiv.add( $j(postContainer).contents().filter('.lqt-reply-form') ); |
45 | 59 | if (!replyDiv.length) { |
46 | 60 | // Create a div for it |
47 | 61 | replyDiv = $j('<div class="lqt-reply-form lqt-edit-form"/>'); |
48 | 62 | |
49 | 63 | // Try to find a place for it |
50 | 64 | if ( !repliesElement.length ) { |
51 | | - repliesElement = liquidThreads.getRepliesElement( $j(container) ); |
| 65 | + repliesElement = liquidThreads.getRepliesElement( $j(postContainer) ); |
52 | 66 | } |
53 | 67 | |
54 | 68 | repliesElement.find('.lqt-replies-finish').before( replyDiv ); |
— | — | @@ -57,7 +71,6 @@ |
58 | 72 | replyDiv = replyDiv[0]; |
59 | 73 | |
60 | 74 | liquidThreads.injectEditForm( params, replyDiv, e.preload ); |
61 | | - liquidThreads.currentReplyThread = thread_id; |
62 | 75 | }, |
63 | 76 | |
64 | 77 | 'getRepliesElement' : function(thread /* a .lqt-post-tree-wrapper */ ) { |
— | — | @@ -99,10 +112,16 @@ |
100 | 113 | 'handleNewLink' : function(e) { |
101 | 114 | e.preventDefault(); |
102 | 115 | |
103 | | - var talkpage = $j(this).attr('lqt_talkpage'); |
104 | | - var params = {'talkpage' : talkpage, 'method' : 'talkpage_new_thread' }; |
| 116 | + var talkpage = $j(this).attr('lqt_channel'); |
| 117 | + var params = {'form' : 'new', 'channel' : talkpage }; |
105 | 118 | |
106 | 119 | var container = $j('.lqt-new-thread' ); |
| 120 | + |
| 121 | + if ( container.length == 0 ) { |
| 122 | + container = $j('<div class="lqt-new-thread" />') |
| 123 | + .prependTo('#lqt-channel_'+talkpage); |
| 124 | + } |
| 125 | + |
107 | 126 | container.data('lqt-talkpage', talkpage); |
108 | 127 | |
109 | 128 | liquidThreads.injectEditForm( params, container ); |
— | — | @@ -157,7 +176,7 @@ |
158 | 177 | $j(container).find('#lqt_subject_field').focus(); |
159 | 178 | |
160 | 179 | // Update signature editor |
161 | | - $j(container).find('input[name=wpLqtSignature]').hide(); |
| 180 | + $j(container).find('input[name=lqt-signature]').hide(); |
162 | 181 | $j(container).find('.lqt-signature-preview').show(); |
163 | 182 | var editLink = $j('<a class="lqt-signature-edit-button"/>' ); |
164 | 183 | editLink.text( mediaWiki.msg('lqt-edit-signature') ); |
— | — | @@ -241,13 +260,14 @@ |
242 | 261 | }, |
243 | 262 | |
244 | 263 | 'loadInlineEditForm' : function( params, container, callback ) { |
245 | | - params['action'] = 'threadaction'; |
246 | | - params['threadaction'] = 'inlineeditform'; |
| 264 | + params['action'] = 'lqtform'; |
247 | 265 | |
248 | 266 | liquidThreads.apiRequest( params, |
249 | 267 | function(result) { |
250 | | - var content = $j(result.threadaction.inlineeditform.html); |
| 268 | + var content = $j(result.form.html); |
251 | 269 | $j(container).empty().append(content); |
| 270 | + content.data('token', result.form.token); |
| 271 | + content.data('params', params ); |
252 | 272 | |
253 | 273 | callback(); |
254 | 274 | } ); |
— | — | @@ -885,25 +905,117 @@ |
886 | 906 | callback(token); |
887 | 907 | }, 'json' ); |
888 | 908 | }, |
| 909 | + |
| 910 | + // Old AJAX save code |
| 911 | +// var replyCallback = function( data ) { |
| 912 | +// $parent = $j( '#lqt-post-tree-wrapper_id_' + data.threadaction.thread['parent-id'] ); |
| 913 | +// $html = $j( data.threadaction.thread['html'] ); |
| 914 | +// $newThread = $html.find( '#lqt-post-tree-wrapper_id_' + data.threadaction.thread['thread-id'] ); |
| 915 | +// $parent.find( '.lqt-replies:first' ).append( $newThread ); |
| 916 | +// $parent.closest( '.lqt-thread-topmost' ) |
| 917 | +// .find( 'input.lqt-thread-modified' ) |
| 918 | +// .val( data.threadaction.thread['modified'] ); |
| 919 | +// liquidThreads.setupThread( $newThread.find( '.lqt-post-wrapper' ) ); |
| 920 | +// $j( 'html,body' ).animate({scrollTop: $newThread.offset().top}, 'slow'); |
| 921 | +// }; |
| 922 | +// |
| 923 | +// var newCallback = function( data ) { |
| 924 | +// var $newThread = $j( data.threadaction.thread['html'] ); |
| 925 | +// $j( '.lqt-threads' ).prepend( $newThread ); |
| 926 | +// // remove the no threads message if it's on the page |
| 927 | +// $j('.lqt-no-threads').remove(); |
| 928 | +// liquidThreads.setupThread( $newThread.find( '.lqt-post-wrapper' ) ); |
| 929 | +// $j( 'html,body' ).animate( { scrollTop: $newThread.offset().top }, 'slow' ); |
| 930 | +// }; |
| 931 | +// |
| 932 | +// var editCallback = function( data ) { |
| 933 | +// var thread = editform.closest('.lqt-thread-topmost'); |
| 934 | +// |
| 935 | +// liquidThreads.doReloadThread( thread ); |
| 936 | +// } |
| 937 | +// |
| 938 | +// var doneCallback = function(data) { |
| 939 | +// try { |
| 940 | +// var result = data.threadaction.thread.result; |
| 941 | +// } catch ( err ) { |
| 942 | +// result = 'error'; |
| 943 | +// } |
| 944 | +// |
| 945 | +// if ( result != 'Success' ) { |
| 946 | +// // Create a hidden field to mimic the save button, and |
| 947 | +// // submit it normally, so they'll get a real error message. |
| 948 | +// |
| 949 | +// var saveHidden = $j('<input/>'); |
| 950 | +// saveHidden.attr( 'type', 'hidden' ); |
| 951 | +// saveHidden.attr( 'name', 'wpSave' ); |
| 952 | +// saveHidden.attr( 'value', 'Save' ); |
| 953 | +// |
| 954 | +// var form = editform.find('#editform'); |
| 955 | +// form.append(saveHidden); |
| 956 | +// form.submit(); |
| 957 | +// return; |
| 958 | +// } |
| 959 | +// |
| 960 | +// var callback; |
| 961 | +// |
| 962 | +// if ( type == 'reply' ) { |
| 963 | +// callback = replyCallback; |
| 964 | +// } |
| 965 | +// |
| 966 | +// if ( type == 'talkpage_new_thread' ) { |
| 967 | +// callback = newCallback; |
| 968 | +// } |
| 969 | +// |
| 970 | +// if ( type == 'edit' ) { |
| 971 | +// callback = editCallback; |
| 972 | +// } |
| 973 | +// |
| 974 | +// editform.empty().hide(); |
| 975 | +// |
| 976 | +// callback(data); |
| 977 | +// |
| 978 | +// // Load the new TOC |
| 979 | +// liquidThreads.reloadTOC(); |
| 980 | +// }; |
| 981 | +// |
| 982 | +// if ( type == 'reply' ) { |
| 983 | +// liquidThreads.doReply( replyThread, text, summary, |
| 984 | +// doneCallback, bump, signature ); |
| 985 | +// |
| 986 | +// e.preventDefault(); |
| 987 | +// } else if ( type == 'new' ) { |
| 988 | +// var container = editform.closest('.lqt-new-thread'); |
| 989 | +// var page = container.data('lqt-talkpage'); |
| 990 | +// liquidThreads.doNewThread( page, subject, text, summary, |
| 991 | +// doneCallback, bump, signature ); |
| 992 | +// |
| 993 | +// e.preventDefault(); |
| 994 | +// } else if ( type == 'edit' ) { |
| 995 | +// liquidThreads.doEditThread( replyThread, subject, text, summary, |
| 996 | +// doneCallback, bump, signature ); |
| 997 | +// e.preventDefault(); |
| 998 | +// } |
889 | 999 | |
890 | 1000 | 'handleAJAXSave' : function( e ) { |
| 1001 | + e.preventDefault(); |
891 | 1002 | var editform = $j(this).closest('.lqt-edit-form'); |
892 | | - var type = editform.find('input[name=lqt_method]').val(); |
893 | | - var wikiEditorContext = editform.find('#wpTextbox1').data( 'wikiEditor-context' ); |
| 1003 | + var params = $.extend( {}, editform.data('params') ); |
| 1004 | + var type = params.form; |
| 1005 | + var wikiEditorContext = editform.find('.lqt-editform-textbox').data( 'wikiEditor-context' ); |
894 | 1006 | var text; |
895 | 1007 | |
896 | 1008 | if ( !wikiEditorContext || typeof(wikiEditorContext) == 'undefined' || |
897 | 1009 | ! wikiEditorContext.$iframe) { |
898 | | - text = editform.find('#wpTextbox1').val(); |
| 1010 | + text = editform.find('.lqt-editform-textbox').val(); |
899 | 1011 | } else { |
900 | 1012 | text = wikiEditorContext.$textarea.textSelection( 'getContents' ); |
901 | 1013 | } |
902 | 1014 | |
903 | | - var summary = editform.find('#wpSummary').val(); |
| 1015 | + var summary = editform.find('#lqt-summary').val(); |
904 | 1016 | |
905 | 1017 | var signature; |
906 | | - if ( editform.find('input[name=wpLqtSignature]').length ) { |
907 | | - signature = editform.find('input[name=wpLqtSignature]').val(); |
| 1018 | + if ( editform.find('input[name=lqt-signature]').length ) { |
| 1019 | + signature = editform.find('input[name=lqt-signature]').val(); |
908 | 1020 | } else { |
909 | 1021 | signature = undefined |
910 | 1022 | } |
— | — | @@ -913,101 +1025,29 @@ |
914 | 1026 | summary = ''; |
915 | 1027 | } |
916 | 1028 | |
917 | | - var subject = editform.find( '#lqt_subject_field' ).val(); |
918 | | - var replyThread = editform.find('input[name=lqt_operand]').val(); |
919 | | - var bump = editform.find('#wpBumpThread').is(':checked') ? 1 : 0; |
| 1029 | + var subject = editform.find( '#lqt-subject' ).val(); |
920 | 1030 | |
921 | 1031 | var spinner = $j('<div class="mw-ajax-loader"/>'); |
922 | 1032 | editform.prepend(spinner); |
923 | | - |
924 | | - var replyCallback = function( data ) { |
925 | | - $parent = $j( '#lqt-post-tree-wrapper_id_' + data.threadaction.thread['parent-id'] ); |
926 | | - $html = $j( data.threadaction.thread['html'] ); |
927 | | - $newThread = $html.find( '#lqt-post-tree-wrapper_id_' + data.threadaction.thread['thread-id'] ); |
928 | | - $parent.find( '.lqt-replies:first' ).append( $newThread ); |
929 | | - $parent.closest( '.lqt-thread-topmost' ) |
930 | | - .find( 'input.lqt-thread-modified' ) |
931 | | - .val( data.threadaction.thread['modified'] ); |
932 | | - liquidThreads.setupThread( $newThread.find( '.lqt-post-wrapper' ) ); |
933 | | - $j( 'html,body' ).animate({scrollTop: $newThread.offset().top}, 'slow'); |
934 | | - }; |
935 | | - |
936 | | - var newCallback = function( data ) { |
937 | | - var $newThread = $j( data.threadaction.thread['html'] ); |
938 | | - $j( '.lqt-threads' ).prepend( $newThread ); |
939 | | - // remove the no threads message if it's on the page |
940 | | - $j('.lqt-no-threads').remove(); |
941 | | - liquidThreads.setupThread( $newThread.find( '.lqt-post-wrapper' ) ); |
942 | | - $j( 'html,body' ).animate( { scrollTop: $newThread.offset().top }, 'slow' ); |
943 | | - }; |
944 | | - |
945 | | - var editCallback = function( data ) { |
946 | | - var thread = editform.closest('.lqt-thread-topmost'); |
947 | | - |
948 | | - liquidThreads.doReloadThread( thread ); |
| 1033 | + |
| 1034 | + params.token = editform.data('token'); |
| 1035 | + params.submit = 1; |
| 1036 | + if ( type == 'new' ) { |
| 1037 | + params.subject = subject; |
| 1038 | + params.content = text; |
| 1039 | + params.signature = signature; |
| 1040 | + |
| 1041 | + liquidThreads.apiRequest( params, function() { |
| 1042 | + window.location.reload(true); |
| 1043 | + } ); |
| 1044 | + } else if ( type == 'reply' ) { |
| 1045 | + params.content = text; |
| 1046 | + params.signature = signature; |
| 1047 | + |
| 1048 | + liquidThreads.apiRequest( params, function() { |
| 1049 | + window.location.reload(true); |
| 1050 | + } ); |
949 | 1051 | } |
950 | | - |
951 | | - var doneCallback = function(data) { |
952 | | - try { |
953 | | - var result = data.threadaction.thread.result; |
954 | | - } catch ( err ) { |
955 | | - result = 'error'; |
956 | | - } |
957 | | - |
958 | | - if ( result != 'Success' ) { |
959 | | - // Create a hidden field to mimic the save button, and |
960 | | - // submit it normally, so they'll get a real error message. |
961 | | - |
962 | | - var saveHidden = $j('<input/>'); |
963 | | - saveHidden.attr( 'type', 'hidden' ); |
964 | | - saveHidden.attr( 'name', 'wpSave' ); |
965 | | - saveHidden.attr( 'value', 'Save' ); |
966 | | - |
967 | | - var form = editform.find('#editform'); |
968 | | - form.append(saveHidden); |
969 | | - form.submit(); |
970 | | - return; |
971 | | - } |
972 | | - |
973 | | - var callback; |
974 | | - |
975 | | - if ( type == 'reply' ) { |
976 | | - callback = replyCallback; |
977 | | - } |
978 | | - |
979 | | - if ( type == 'talkpage_new_thread' ) { |
980 | | - callback = newCallback; |
981 | | - } |
982 | | - |
983 | | - if ( type == 'edit' ) { |
984 | | - callback = editCallback; |
985 | | - } |
986 | | - |
987 | | - editform.empty().hide(); |
988 | | - |
989 | | - callback(data); |
990 | | - |
991 | | - // Load the new TOC |
992 | | - liquidThreads.reloadTOC(); |
993 | | - }; |
994 | | - |
995 | | - if ( type == 'reply' ) { |
996 | | - liquidThreads.doReply( replyThread, text, summary, |
997 | | - doneCallback, bump, signature ); |
998 | | - |
999 | | - e.preventDefault(); |
1000 | | - } else if ( type == 'talkpage_new_thread' ) { |
1001 | | - var container = editform.closest('.lqt-new-thread'); |
1002 | | - var page = container.data('lqt-talkpage'); |
1003 | | - liquidThreads.doNewThread( page, subject, text, summary, |
1004 | | - doneCallback, bump, signature ); |
1005 | | - |
1006 | | - e.preventDefault(); |
1007 | | - } else if ( type == 'edit' ) { |
1008 | | - liquidThreads.doEditThread( replyThread, subject, text, summary, |
1009 | | - doneCallback, bump, signature ); |
1010 | | - e.preventDefault(); |
1011 | | - } |
1012 | 1052 | }, |
1013 | 1053 | |
1014 | 1054 | 'reloadTOC' : function() { |
— | — | @@ -1031,87 +1071,6 @@ |
1032 | 1072 | } ); |
1033 | 1073 | }, |
1034 | 1074 | |
1035 | | - 'doNewThread' : function( talkpage, subject, text, summary, callback, bump, signature ) { |
1036 | | - liquidThreads.getToken( |
1037 | | - function(token) { |
1038 | | - var newTopicParams = |
1039 | | - { |
1040 | | - 'action' : 'threadaction', |
1041 | | - 'threadaction' : 'newthread', |
1042 | | - 'talkpage' : talkpage, |
1043 | | - 'subject' : subject, |
1044 | | - 'text' : text, |
1045 | | - 'token' : token, |
1046 | | - 'format' : 'json', |
1047 | | - 'render' : '1', |
1048 | | - 'reason' : summary, |
1049 | | - 'bump' : bump |
1050 | | - }; |
1051 | | - |
1052 | | - if ( typeof signature != 'undefined' ) { |
1053 | | - newTopicParams.signature = signature; |
1054 | | - } |
1055 | | - |
1056 | | - $j.post( wgScriptPath+'/api'+wgScriptExtension, newTopicParams, |
1057 | | - function(data) { |
1058 | | - if (callback) { |
1059 | | - callback(data); |
1060 | | - } |
1061 | | - }, 'json' ); |
1062 | | - } ); |
1063 | | - }, |
1064 | | - |
1065 | | - 'doReply' : function( thread, text, summary, callback, bump, signature ) { |
1066 | | - liquidThreads.getToken( |
1067 | | - function(token) { |
1068 | | - var replyParams = |
1069 | | - { |
1070 | | - 'action' : 'threadaction', |
1071 | | - 'threadaction' : 'reply', |
1072 | | - 'thread' : thread, |
1073 | | - 'text' : text, |
1074 | | - 'token' : token, |
1075 | | - 'format' : 'json', |
1076 | | - 'render' : '1', |
1077 | | - 'reason' : summary, |
1078 | | - 'bump' : bump |
1079 | | - }; |
1080 | | - |
1081 | | - if ( typeof signature != 'undefined' ) { |
1082 | | - replyParams.signature = signature; |
1083 | | - } |
1084 | | - |
1085 | | - $j.post( wgScriptPath+'/api'+wgScriptExtension, replyParams, |
1086 | | - function(data) { |
1087 | | - if (callback) { |
1088 | | - callback(data); |
1089 | | - } |
1090 | | - }, 'json' ); |
1091 | | - } ); |
1092 | | - }, |
1093 | | - |
1094 | | - 'doEditThread' : function( thread, subject, text, summary, |
1095 | | - callback, bump, signature ) { |
1096 | | - var request = |
1097 | | - { |
1098 | | - 'action' : 'threadaction', |
1099 | | - 'threadaction' : 'edit', |
1100 | | - 'thread' : thread, |
1101 | | - 'text' : text, |
1102 | | - 'format' : 'json', |
1103 | | - 'render' : 1, |
1104 | | - 'reason' : summary, |
1105 | | - 'bump' : bump, |
1106 | | - 'subject':subject |
1107 | | - }; |
1108 | | - |
1109 | | - if ( typeof signature != 'undefined' ) { |
1110 | | - request.signature = signature; |
1111 | | - } |
1112 | | - |
1113 | | - liquidThreads.apiRequest( request, callback ); |
1114 | | - }, |
1115 | | - |
1116 | 1075 | 'onTextboxKeyUp' : function(e) { |
1117 | 1076 | // Check if a user has signed their post, and if so, tell them they don't have to. |
1118 | 1077 | var text = $j(this).val().trim(); |
— | — | @@ -1133,25 +1092,15 @@ |
1134 | 1093 | }, |
1135 | 1094 | |
1136 | 1095 | 'apiRequest' : function( request, callback ) { |
1137 | | - // Set new subject through API. |
1138 | | - liquidThreads.getToken( function(token) { |
| 1096 | + request.format = 'json'; |
1139 | 1097 | |
1140 | | - if ( typeof request == 'function' ) { |
1141 | | - request = request(token); |
1142 | | - } else { |
1143 | | - request.token = token; |
1144 | | - } |
1145 | | - |
1146 | | - request.format = 'json'; |
1147 | | - |
1148 | | - var path = wgScriptPath+'/api'+wgScriptExtension; |
1149 | | - $j.post( path, request, |
1150 | | - function(data) { |
1151 | | - if (callback) { |
1152 | | - callback(data); |
1153 | | - } |
1154 | | - }, 'json' ); |
1155 | | - } ); |
| 1098 | + var path = wgScriptPath+'/api'+wgScriptExtension; |
| 1099 | + $j.post( path, request, |
| 1100 | + function(data) { |
| 1101 | + if (callback) { |
| 1102 | + callback(data); |
| 1103 | + } |
| 1104 | + }, 'json' ); |
1156 | 1105 | }, |
1157 | 1106 | |
1158 | 1107 | 'activateDragDrop' : function(e) { |
— | — | @@ -1537,7 +1486,7 @@ |
1538 | 1487 | var container = $j(this).parent(); |
1539 | 1488 | |
1540 | 1489 | container.find('.lqt-signature-preview').hide(); |
1541 | | - container.find('input[name=wpLqtSignature]').show(); |
| 1490 | + container.find('input[name=lqt-signature]').show(); |
1542 | 1491 | $j(this).hide(); |
1543 | 1492 | |
1544 | 1493 | // Add a save button |
— | — | @@ -1545,7 +1494,7 @@ |
1546 | 1495 | saveButton.text( mediaWiki.msg('lqt-preview-signature') ); |
1547 | 1496 | saveButton.click( liquidThreads.handlePreviewSignature ); |
1548 | 1497 | |
1549 | | - container.find('input[name=wpLqtSignature]').after(saveButton); |
| 1498 | + container.find('input[name=lqt-signature]').after(saveButton); |
1550 | 1499 | }, |
1551 | 1500 | |
1552 | 1501 | 'handlePreviewSignature' : function(e) { |
— | — | @@ -1556,7 +1505,7 @@ |
1557 | 1506 | var spinner = $j('<span class="mw-small-spinner"/>'); |
1558 | 1507 | $j(this).replaceWith(spinner); |
1559 | 1508 | |
1560 | | - var textbox = container.find('input[name=wpLqtSignature]'); |
| 1509 | + var textbox = container.find('input[name=lqt-signature]'); |
1561 | 1510 | var preview = container.find('.lqt-signature-preview'); |
1562 | 1511 | |
1563 | 1512 | textbox.hide(); |
— | — | @@ -1570,11 +1519,11 @@ |
1571 | 1520 | 'prop' : 'text' |
1572 | 1521 | }; |
1573 | 1522 | |
1574 | | - liquidThreads.apiRequest( function() { return apiReq; }, |
| 1523 | + liquidThreads.apiRequest( apiReq, |
1575 | 1524 | function(data) { |
1576 | 1525 | var html = $j(data.parse.text['*'].trim()); |
1577 | 1526 | |
1578 | | - if (html.length == 2) { // Not 1, because of the NewPP report |
| 1527 | + if (html.length == 3) { // Not 1, because of the NewPP report and space |
1579 | 1528 | html = html.contents(); |
1580 | 1529 | } |
1581 | 1530 | |
— | — | @@ -1628,8 +1577,8 @@ |
1629 | 1578 | $j('.lqt-command-edit > a').live( 'click', liquidThreads.handleEditLink ); |
1630 | 1579 | |
1631 | 1580 | // Save handlers |
1632 | | - $j('#wpSave').live( 'click', liquidThreads.handleAJAXSave ); |
1633 | | - $j('#wpTextbox1').live( 'keyup', liquidThreads.onTextboxKeyUp ); |
| 1581 | + $j('.lqt-save').live( 'click', liquidThreads.handleAJAXSave ); |
| 1582 | + $j('.lqt-edit-content').live( 'keyup', liquidThreads.onTextboxKeyUp ); |
1634 | 1583 | $j('#wpPreview').die('click'); |
1635 | 1584 | $j('#wpPreview').live('click', liquidThreads.doLivePreview ); |
1636 | 1585 | |