Index: trunk/extensions/wikiwyg/share/MediaWiki/extensions/CreatePage/js/createpage.js |
— | — | @@ -0,0 +1,518 @@ |
| 2 | + |
| 3 | +/* |
| 4 | +* @author Bartek Łapiński |
| 5 | +* @copyright Copyright © 2007, Wikia Inc. |
| 6 | +* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 7 | +*/ |
| 8 | + |
| 9 | +var WikiwygInstance; |
| 10 | + |
| 11 | +/* copied and adapted from upload image script... */ |
| 12 | +// apply tagOpen/tagClose to selection in textarea, |
| 13 | +// use sampleText instead of selection if there is none |
| 14 | +// copied and adapted from phpBB |
| 15 | +function insertTags(tagOpen, tagClose, sampleText) { |
| 16 | + if (WikiwygInstance.enabled) { |
| 17 | + var out = WikiwygInstance.current_mode ; |
| 18 | + out.insert_html (tagOpen + sampleText + tagClose) ; |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +/* fall back if edit mode not supported - provide a normal interface */ |
| 23 | +function CreatePageFallBack () { |
| 24 | + var loading_mesg = document.getElementById ('loading_mesg') ; |
| 25 | + loading_mesg.style.display = 'none' ; |
| 26 | + var input1 = document.createElement ('textarea') ; |
| 27 | + input1.setAttribute ('name','wpTextbox1') ; |
| 28 | + input1.setAttribute ('id','wpTextbox1') ; |
| 29 | + input1.setAttribute ('rows', 25) ; |
| 30 | + input1.setAttribute ('cols', 80) ; |
| 31 | + var backup_txt = document.getElementById ('backup_textarea_placeholder') ; |
| 32 | + backup_txt.appendChild (input1) ; |
| 33 | + /* todo give standard edit toolbar - mainly for Opera users */ |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +document.insertTags = insertTags ; |
| 38 | + |
| 39 | +/* modified function for image upload (omitting HACK section for non-existing watchthis link )*/ |
| 40 | +var imageUploadDialog = null; |
| 41 | + |
| 42 | +/* provide an old-way edit */ |
| 43 | +function CreatePageNormalEdit () { |
| 44 | + var title = document.getElementById ('title') ; |
| 45 | + var error_msg = document.getElementById ('createpage_messenger') ; |
| 46 | + if (title.value == '') { |
| 47 | + error_msg.innerHTML = 'Please specify title first' ; |
| 48 | + error_msg.style.display = '' ; |
| 49 | + return ; |
| 50 | + } |
| 51 | + /* check for unsaved changes (they will always be *unsaved* here... ) */ |
| 52 | + var textarea = WikiwygInstance.current_mode.get_edit_document().body.innerHTML ; |
| 53 | + textarea = textarea.replace ("<br>", "") ; |
| 54 | + if (textarea != "") { |
| 55 | + var abandon_changes = confirm ("You have unsaved changes. Clicking OK will result in abandoning them.","Unsaved changes") ; |
| 56 | + if (!abandon_changes) { |
| 57 | + return ; |
| 58 | + } |
| 59 | + } |
| 60 | + var fixed_article_path = wgArticlePath.replace ('$1','') ; |
| 61 | + fixed_article_path = fixed_article_path.replace ('index.php[^\/]','index.php?title=') ; |
| 62 | + window.location = fixed_article_path + title.value + '?action=edit' ; |
| 63 | +} |
| 64 | + |
| 65 | +function fixupRelativeUrl(url) { |
| 66 | + var loc = String(location); |
| 67 | + if (loc.match (/\?index\.php/i) != '') { |
| 68 | + var base = loc.replace (/&action=.*$/i, ''); |
| 69 | + return base ; |
| 70 | + } else { |
| 71 | + var base = loc.replace(/index\.php.*/, ''); |
| 72 | + if (base == loc) |
| 73 | + base = loc.replace(/(.*\/wiki\/).*/, '$1'); |
| 74 | + if (base == loc) |
| 75 | + throw("fixupRelativeUrl error: " + loc); |
| 76 | + return base + url; |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +function CreatePageShowSection (section) { |
| 81 | + var this_section = document.getElementById ('createpage_' + section + '_section') ; |
| 82 | + var show_this = document.getElementById ('createpage_show_' + section) ; |
| 83 | + var hide_this = document.getElementById ('createpage_hide_' + section) ; |
| 84 | + |
| 85 | + this_section.style.display = '' ; |
| 86 | + show_this.style.display = 'none' ; |
| 87 | + hide_this.style.display = '' ; |
| 88 | +} |
| 89 | + |
| 90 | +function CreatePageHideSection (section) { |
| 91 | + var this_section = document.getElementById ('createpage_' + section + '_section') ; |
| 92 | + var show_this = document.getElementById ('createpage_show_' + section) ; |
| 93 | + var hide_this = document.getElementById ('createpage_hide_' + section) ; |
| 94 | + |
| 95 | + this_section.style.display = 'none' ; |
| 96 | + show_this.style.display = '' ; |
| 97 | + hide_this.style.display = 'none' ; |
| 98 | +} |
| 99 | + |
| 100 | +function CreatePageAddCategory (category, num) { |
| 101 | + if (category != '') { |
| 102 | + if (document.editform.category.value == '') { |
| 103 | + document.editform.category.value += category ; |
| 104 | + } else { |
| 105 | + document.editform.category.value += ',' + category ; |
| 106 | + } |
| 107 | + /* change colour */ |
| 108 | + this_button = document.getElementById ('cloud_'+ num) ; |
| 109 | + this_span = document.getElementById ('tag-' + num) ; |
| 110 | + this_button.onclick = function() { eval("CreatePageRemoveCategory('" + category + "', " + num + ")"); return false }; |
| 111 | + this_button.style["color"] = "#419636" ; |
| 112 | + } |
| 113 | +} |
| 114 | +function CreatePageRemoveCategory (category, num) { |
| 115 | + category_text = document.editform.category.value ; |
| 116 | + this_pos = category_text.indexOf(category) ; |
| 117 | + if (this_pos != -1) { |
| 118 | + category_text = category_text.substr (0, this_pos-1 ) + category_text.substr (this_pos + category.length) ; |
| 119 | + document.editform.category.value = category_text ; |
| 120 | + } |
| 121 | + |
| 122 | + this_button = document.getElementById ('cloud_'+ num) ; |
| 123 | + this_button.onclick = function() { eval("CreatePageAddCategory('" + category + "', " + num + ")"); return false }; |
| 124 | + this_button.style["color"] = "" ; |
| 125 | +} |
| 126 | + |
| 127 | +function CreatePageShowThrobber (text) { |
| 128 | +// var Throbber = document.getElementById ('ajaxProgressIcon') ; |
| 129 | +// Throbber.style.visibility = 'visible' ; |
| 130 | +} |
| 131 | + |
| 132 | +function CreatePageHideThrobber (text) { |
| 133 | +// var Throbber = document.getElementById ('ajaxProgressIcon') ; |
| 134 | +// Throbber.style.visibility = 'hidden' ; |
| 135 | +} |
| 136 | + |
| 137 | + |
| 138 | +window.onload = function() { |
| 139 | + var WikiwygDiv = document.getElementById ('wikiwyg') ; |
| 140 | + var category_wrapper = document.getElementById ('category_wrapper') ; |
| 141 | + var subtitle = document.getElementById ('contentSub') ; |
| 142 | + var cp_subtitle = document.getElementById ('createpage_subtitle') ; |
| 143 | + subtitle.innerHTML = cp_subtitle.innerHTML ; |
| 144 | + CreatePageShowThrobber ('') ; |
| 145 | + category_wrapper.style.display = 'block' ; |
| 146 | + var WikiwygConfig = { |
| 147 | + doubleClickToEdit: true , |
| 148 | + editHeightMinimum: 300 , |
| 149 | + wysiwyg: { |
| 150 | + iframeId: 'wikiwyg-iframe' |
| 151 | + }, |
| 152 | + toolbar: { |
| 153 | + imagesLocation: wgScriptPath + '/extensions/wikiwyg/share/MediaWiki/images/', |
| 154 | + markupRules: { |
| 155 | + link: ['bound_phrase', '[', ']'] |
| 156 | + }, |
| 157 | + controlLayout: [ |
| 158 | + 'bold' , |
| 159 | + 'italic' , |
| 160 | + 'strike' , |
| 161 | + 'www' , |
| 162 | + 'unlink' , |
| 163 | + 'wikify' , |
| 164 | + 'h1' , |
| 165 | + 'h2' , |
| 166 | + 'h3' , |
| 167 | + 'pre' , |
| 168 | + 'hr' , |
| 169 | + 'unordered' , |
| 170 | + 'ordered' , |
| 171 | + 'youtube' , |
| 172 | + 'table' , |
| 173 | + '|l' , |
| 174 | + 'insertimage' , |
| 175 | + '|l' , |
| 176 | + 'help' |
| 177 | + ] |
| 178 | + }, |
| 179 | + modeClasses: [ |
| 180 | + 'Wikiwyg.Wysiwyg.Custom' , |
| 181 | + 'Wikiwyg.Wikitext.Custom' |
| 182 | + ] |
| 183 | + } ; |
| 184 | + WikiwygInstance = new Wikiwyg.Test (); |
| 185 | + WikiwygInstance.createWikiwygArea(WikiwygDiv, WikiwygConfig); |
| 186 | + if (WikiwygInstance.enabled) { |
| 187 | + setTimeout("WikiwygInstance.editMode();",400); |
| 188 | + } else { |
| 189 | + CreatePageFallBack () ; |
| 190 | + } |
| 191 | + document.getElementById ('loading_mesg').style.display = 'none' ; |
| 192 | + |
| 193 | + // register edit page |
| 194 | + var CreatePageLinkBottom = document.getElementById ('wpSaveBottom') ; |
| 195 | + var self = WikiwygInstance ; |
| 196 | + CreatePageLinkBottom.onclick = function() { eval('WikiwygInstance.saveChanges()'); return false }; |
| 197 | + CreatePageHideThrobber ('') ; |
| 198 | +} |
| 199 | + |
| 200 | +proto = new Subclass('Wikiwyg.Test', 'Wikiwyg'); |
| 201 | + |
| 202 | + proto.modeClasses = [ |
| 203 | + 'Wikiwyg.Wysiwyg.Custom', |
| 204 | + 'Wikiwyg.Wikitext.Custom' |
| 205 | + ]; |
| 206 | + |
| 207 | +proto.saveChanges = function () { |
| 208 | + if (!this.checkContents()) { |
| 209 | + return false ; |
| 210 | + } |
| 211 | + var title = document.getElementById ('title') ; |
| 212 | + if (!this.checkIfArticleExists (title.value)) { |
| 213 | + return false ; |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | +proto.imageUpload = function (tagOpen, tagClose, sampleText) { |
| 218 | + Wikiwyg.prototype.imageUpload.call (this, tagOpen, tagClose, sampleText) ; |
| 219 | +} |
| 220 | + |
| 221 | +proto.checkContents = function () { |
| 222 | + var error_msg = document.getElementById ('createpage_messenger') ; |
| 223 | + var title = document.getElementById ('title') ; |
| 224 | + article_text = this.current_mode.get_edit_document().body.innerHTML ; |
| 225 | + article_text = article_text.replace(/<br[^>]+./gi,"<br>") ; |
| 226 | +// article_text = article_text.replace(/<br><br>/gi,"<p>") ; |
| 227 | + var class_name = this.config.modeClasses[1]; |
| 228 | + var mode_object = this.mode_objects[class_name]; |
| 229 | + article_text = mode_object.convert_html_to_wikitext(article_text) ; |
| 230 | + if ( (title.value == '') || (article_text == '') ) { |
| 231 | + error_msg.innerHTML = "You need to specify both title and some content to create an article." ; |
| 232 | + error_msg.style.display = 'block' ; |
| 233 | + return false ; |
| 234 | + } |
| 235 | + return true ; |
| 236 | +} |
| 237 | + |
| 238 | +proto.checkIfArticleExists = function (article) { |
| 239 | + CreatePageShowThrobber ('') ; |
| 240 | + WKWAjax.post ( |
| 241 | + fixupRelativeUrl('Special:Createpage') , |
| 242 | + 'action=check&to_check=' + article , |
| 243 | + function (response) { |
| 244 | + WikiwygInstance.handleArticleExistsResponse (response) |
| 245 | + } |
| 246 | + ) ; |
| 247 | +} |
| 248 | + |
| 249 | +proto.handleArticleExistsResponse = function (response) { |
| 250 | + if (response.indexOf("pagetitleexists") != -1) { |
| 251 | + var error_msg = document.getElementById ('createpage_messenger') ; |
| 252 | + var title = document.getElementById ('title') ; |
| 253 | + error_msg.innerHTML = "That title already exists. Please choose another title." ; |
| 254 | + error_msg.style.display = 'block' ; |
| 255 | + CreatePageHideThrobber ('') ; |
| 256 | + return false ; |
| 257 | + } else { |
| 258 | + /* select wikitext mode */ |
| 259 | + var class_name = this.config.modeClasses[1]; |
| 260 | + var mode_object = this.mode_objects[class_name]; |
| 261 | + this.current_mode.saveChanges (mode_object) ; |
| 262 | + CreatePageHideThrobber ('') ; |
| 263 | + return true ; |
| 264 | + } |
| 265 | +} |
| 266 | + |
| 267 | +proto = new Subclass('Wikiwyg.Wysiwyg.Custom', 'Wikiwyg.Wysiwyg'); |
| 268 | + |
| 269 | +/* taken from Wysiwig.MediaWiki */ |
| 270 | + |
| 271 | +proto.insert_html = function(html) { // See IE |
| 272 | + this.get_edit_window().focus(); |
| 273 | + this.exec_command('inserthtml', html); |
| 274 | +} |
| 275 | + |
| 276 | +proto.apply_stylesheets = function() { |
| 277 | + Wikiwyg.Wysiwyg.prototype.apply_stylesheets.apply(this, arguments); |
| 278 | + var head = this.get_edit_document().getElementsByTagName("head")[0]; |
| 279 | + var style_string = "body { font-size: small; }"; |
| 280 | + this.append_inline_style_element(style_string, head); |
| 281 | +} |
| 282 | + |
| 283 | +proto.enableStarted = function () { |
| 284 | + this.wikiwyg.toolbarObject.disableThis(); |
| 285 | + this.wikiwyg.toolbarObject.enableMessage(); |
| 286 | +} |
| 287 | + |
| 288 | +proto.enableFinished = function (){ |
| 289 | + this.wikiwyg.toolbarObject.enableThis(); |
| 290 | + this.wikiwyg.toolbarObject.disableMessage(); |
| 291 | +} |
| 292 | + |
| 293 | +proto.disableCreateButtons = function () { |
| 294 | + var CreatePageLinkBottom = document.getElementById ('wpSaveBottom') ; |
| 295 | + CreatePageLinkBottom.disabled = true ; |
| 296 | +} |
| 297 | + |
| 298 | +proto.saveChanges = function (mode) { |
| 299 | + var title = document.getElementById ('title') ; |
| 300 | + document.editform.action="index.php?title=" + title.value + "&action=submit" ; |
| 301 | + this.disableCreateButtons () ; |
| 302 | + var input1 = document.createElement ('input') ; |
| 303 | + input1.setAttribute ('name','wpTextbox1') ; |
| 304 | + input1.setAttribute ('id','wpTextbox1') ; |
| 305 | + input1.setAttribute ('type','hidden') ; |
| 306 | + document.editform.appendChild (input1) ; |
| 307 | + var article_text = this.get_edit_document().body.innerHTML ; |
| 308 | + article_text = article_text.replace(/<br[^>]+./gi,"<br>") ; |
| 309 | + article_text = article_text.replace(/<br><br>/gi,"<p>") ; |
| 310 | + article_text = mode.convert_html_to_wikitext(article_text) ; |
| 311 | + document.editform.wpTextbox1.value = article_text ; |
| 312 | + this.getCategories () ; |
| 313 | + document.editform.submit() ; |
| 314 | +} |
| 315 | + |
| 316 | +proto.getCategories = function () { |
| 317 | + /* get categories separated by commas */ |
| 318 | + var categories = document.getElementById ('category').value ; |
| 319 | + categories = categories.split (",") ; |
| 320 | + for (i=0;i<categories.length;i++) { |
| 321 | + this.addCategory (categories[i]) ; |
| 322 | + } |
| 323 | +} |
| 324 | + |
| 325 | +proto.addCategory = function (text) { |
| 326 | + if (text != '') { |
| 327 | + document.editform.wpTextbox1.value += '[[Category:'+text+']]' ; |
| 328 | + } |
| 329 | +} |
| 330 | + |
| 331 | +proto = new Subclass('Wikiwyg.Wikitext.Custom', 'Wikiwyg.Wikitext'); |
| 332 | + |
| 333 | +proto.do_p = function() { |
| 334 | + this.selection_mangle( |
| 335 | + function(that) { |
| 336 | + if (that.sel == '') return false; |
| 337 | + that.sel = that.sel.replace(/^\=* */gm, ''); |
| 338 | + that.sel = that.sel.replace(/ *\=*$/gm, ''); |
| 339 | + return true; |
| 340 | + } |
| 341 | + ) |
| 342 | +} |
| 343 | + |
| 344 | +proto.do_youtube = function () { |
| 345 | + this.make_do ('youtube') ; |
| 346 | +} |
| 347 | + |
| 348 | +Wikiwyg.Wysiwyg.prototype.do_wikify = function() { |
| 349 | + var selection = this.get_link_selection_text(); |
| 350 | + if (!selection) return ; |
| 351 | + var self = this ; |
| 352 | + WKWAjax.post ( |
| 353 | + fixupRelativeUrl('Special:Createpage') , |
| 354 | + 'action=check&to_check=' + selection , |
| 355 | + function (response) { |
| 356 | + if (response.indexOf("pagetitleexists") != -1) { |
| 357 | + link_color = "26579A"; |
| 358 | + } else { |
| 359 | + link_color = "FF0000"; |
| 360 | + } |
| 361 | + var url; |
| 362 | + var match = selection.match(/(.*?)\b((?:http|https|ftp|irc):\/\/\S+)(.*)/); |
| 363 | + if (match) { |
| 364 | + if (match[1] || match[3]) return null; |
| 365 | + url = match[2]; |
| 366 | + } |
| 367 | + else { |
| 368 | + url = '?' + escape(selection); |
| 369 | + } |
| 370 | + |
| 371 | + self.exec_command('createlink', url); |
| 372 | + self.exec_command('underline', selection); |
| 373 | + self.exec_command('ForeColor', "#" + link_color); |
| 374 | + } |
| 375 | + ) ; |
| 376 | +} |
| 377 | + |
| 378 | +Wikiwyg.Wysiwyg.Custom.prototype.do_youtube = function() { |
| 379 | + |
| 380 | + if (Wikiwyg.is_ie) { |
| 381 | + //hack to remember Caret Position in IE |
| 382 | + this.ieRange = this.get_edit_document().selection.createRange(); |
| 383 | + this.ieRange.moveStart ('character', -this.get_inner_html().length) ; |
| 384 | + this.ieCaretPos = this.ieRange.text.length; |
| 385 | + } |
| 386 | + |
| 387 | + var url = prompt("Add YouTube Video. Copy and paste the video's URL or Embed code.", ""); |
| 388 | + if (url == null) return ; |
| 389 | + |
| 390 | + if(Wikiwyg.is_ie){ |
| 391 | + // Move selection start and end to 0 position |
| 392 | + self.ieRange.moveStart ('character', -self.get_inner_html().length); |
| 393 | + |
| 394 | + // Move selection start and end to desired position |
| 395 | + self.ieRange.moveStart ('character', self.ieCaretPos); |
| 396 | + self.ieRange.moveEnd ('character', 0); |
| 397 | + self.ieRange.select (); |
| 398 | + } |
| 399 | + this.insert_youtube(url) ; |
| 400 | +} |
| 401 | + |
| 402 | +Wikiwyg.Wysiwyg.Custom.prototype.extract_youtube_id = function(youTubeCode) { |
| 403 | + id = 0; |
| 404 | + inURL = youTubeCode.indexOf("watch?v=") |
| 405 | + if(inURL > -1){ |
| 406 | + id = youTubeCode.substring(inURL+8) |
| 407 | + }else{ |
| 408 | + r = /http:\/\/www.youtube.com\/v\/\w+/ |
| 409 | + test = r.exec(youTubeCode); |
| 410 | + if(test){ |
| 411 | + id = test.toString().replace("http://www.youtube.com/v/","") |
| 412 | + } |
| 413 | + } |
| 414 | + return id; |
| 415 | +} |
| 416 | + |
| 417 | +Wikiwyg.Wysiwyg.Custom.prototype.insert_youtube = function(url) { |
| 418 | + youTubeID = this.extract_youtube_id(url); |
| 419 | + if(!id){ |
| 420 | + alert("Invalid Youtube url"); |
| 421 | + return; |
| 422 | + } |
| 423 | + TheURL = window.location.href |
| 424 | + TheURL = TheURL.substring(0,TheURL.lastIndexOf("/")) |
| 425 | + this.exec_command('InsertImage', TheURL + "/images/YouTube_placeholder.gif?id=" + youTubeID); |
| 426 | +} |
| 427 | + |
| 428 | +proto.format_table = function(element) { |
| 429 | + this.insert_new_line(); |
| 430 | + this.appendOutput ('{|') ; |
| 431 | + this.assert_blank_line() ; |
| 432 | + this.walk(element); |
| 433 | + this.assert_blank_line() ; |
| 434 | + this.appendOutput ('|}') ; |
| 435 | + this.insert_new_line(); |
| 436 | +} |
| 437 | + |
| 438 | +proto.format_tr = function(element) { |
| 439 | + this.appendOutput('|-') ; |
| 440 | + this.assert_new_line() ; |
| 441 | + this.appendOutput('|') ; |
| 442 | + this.walk(element) ; |
| 443 | + this.assert_blank_line() ; |
| 444 | + this.assert_new_line() ; |
| 445 | +} |
| 446 | + |
| 447 | +proto.format_br = function (element) { |
| 448 | + this.insert_new_line () ; |
| 449 | + this.insert_new_line () ; |
| 450 | +} |
| 451 | + |
| 452 | +proto.format_p = function(element) { |
| 453 | + if (this.is_indented(element)) { |
| 454 | + this.format_blockquote(element); |
| 455 | + return; |
| 456 | + } |
| 457 | + this.insert_new_line(); |
| 458 | + this.insert_new_line(); |
| 459 | + this.insert_new_line(); |
| 460 | + this.walk(element); |
| 461 | +} |
| 462 | + |
| 463 | +proto.format_td = function(element) { |
| 464 | + this.no_following_whitespace(); |
| 465 | + this.walk(element); |
| 466 | + this.chomp(); |
| 467 | + this.appendOutput('||'); |
| 468 | +} |
| 469 | + |
| 470 | + |
| 471 | + proto.format_div = function(element) { |
| 472 | + if (! this.previous_was_newline_or_start()) |
| 473 | + this.insert_new_line(); |
| 474 | + |
| 475 | + this.walk(element); |
| 476 | + this.assert_blank_line(); |
| 477 | + } |
| 478 | + |
| 479 | + |
| 480 | +proto.normalizeDomWhitespace = function(dom) { |
| 481 | + Wikiwyg.Wikitext.prototype.normalizeDomWhitespace.call(this, dom); |
| 482 | + var tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li']; |
| 483 | + for (var ii = 0; ii < tags.length; ii++) { |
| 484 | + var elements = dom.getElementsByTagName(tags[ii]); |
| 485 | + for (var i = 0; i < elements.length; i++) { |
| 486 | + var element = elements[i]; |
| 487 | + if (element.firstChild && element.firstChild.nodeType == '3') { |
| 488 | + element.firstChild.nodeValue = |
| 489 | + element.firstChild.nodeValue.replace(/^\s*/, ''); |
| 490 | + } |
| 491 | + if (element.lastChild && element.lastChild.nodeType == '3') { |
| 492 | + element.lastChild.nodeValue = |
| 493 | + element.lastChild.nodeValue.replace(/\s*$/, ''); |
| 494 | + } |
| 495 | + } |
| 496 | + } |
| 497 | +} |
| 498 | + |
| 499 | +proto.config = { |
| 500 | +markupRules: { |
| 501 | +link: ['bound_phrase', '[[', ']]'], |
| 502 | + www: ['bound_phrase', '[', ']'], |
| 503 | + bold: ['bound_phrase', "'''", "'''"], |
| 504 | + italic: ['bound_phrase', "''", "''"], |
| 505 | + strike: ['bound_phrase', "<s>", "</s>"], |
| 506 | + pre: ['start_lines', ' '], |
| 507 | + p: ['bound_line', '', ''], |
| 508 | + h1: ['bound_line', '= ', ' ='], |
| 509 | + h2: ['bound_line', '== ', ' =='], |
| 510 | + h3: ['bound_line', '=== ', ' ==='], |
| 511 | + h4: ['bound_line', '==== ', ' ===='], |
| 512 | + ordered: ['start_lines', '#'], |
| 513 | + unordered: ['start_lines', '*'], |
| 514 | + indent: ['start_lines', ''], |
| 515 | + hr: ['line_alone', '----'], |
| 516 | + table: ['line_alone', '{ | A | B | C |\n| | | |\n| | | | }'] |
| 517 | + } |
| 518 | +} |
| 519 | + |
Property changes on: trunk/extensions/wikiwyg/share/MediaWiki/extensions/CreatePage/js/createpage.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 520 | + native |
Index: trunk/extensions/wikiwyg/share/MediaWiki/extensions/CreatePage/CreatePageCore.php |
— | — | @@ -0,0 +1,32 @@ |
| 2 | +<? |
| 3 | + |
| 4 | +/* |
| 5 | +* @author Bartek Łapiński |
| 6 | +* @copyright Copyright © 2007, Wikia Inc. |
| 7 | +* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | +*/ |
| 9 | + |
| 10 | +if ( ! defined( 'MEDIAWIKI' ) ) |
| 11 | + die(); |
| 12 | + |
| 13 | +$wgHooks ['EditFilter'][] = 'wfCreatePageSanityCheck' ; |
| 14 | + |
| 15 | +function wfCreatePageSanityCheck () { |
| 16 | + global $wgRequest, $wgOut ; |
| 17 | + |
| 18 | + $isCreatePage = $wgRequest->getBool ('wpCreatePage') ; |
| 19 | + |
| 20 | + if ($isCreatePage) { |
| 21 | + if ($wgRequest->getVal ('title') == '' ) { |
| 22 | + /* do not allow blanking Main Page each time non-js user hits 'Create Article' |
| 23 | + go back to SpecialCreatePage and display error |
| 24 | + */ |
| 25 | + $titleObj = Title::makeTitle (NS_SPECIAL, 'Createpage') ; |
| 26 | + $wgOut->redirect ( $titleObj->getFullURL ('action=failure')) ; |
| 27 | + return false ; |
| 28 | + } |
| 29 | + } |
| 30 | + return true ; |
| 31 | +} |
| 32 | + |
| 33 | +?> |
Property changes on: trunk/extensions/wikiwyg/share/MediaWiki/extensions/CreatePage/CreatePageCore.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 34 | + native |
Index: trunk/extensions/wikiwyg/share/MediaWiki/extensions/CreatePage/SpecialCreatePage.php |
— | — | @@ -0,0 +1,274 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | +* A special page to create a new article, attempting to use wikiwyg, a wysiwig wikitext editor |
| 6 | +* @author Bartek Łapiński |
| 7 | +* @copyright Copyright © 2007, Wikia Inc. |
| 8 | +* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 9 | +*/ |
| 10 | +if(!defined('MEDIAWIKI')) |
| 11 | + die(); |
| 12 | + |
| 13 | +$wgExtensionFunctions[] = 'wfCreatePageSetup'; |
| 14 | +$wgExtensionCredits['specialpage'][] = array( |
| 15 | + 'name' => 'Create Page', |
| 16 | + 'author' => 'Bartek Lapinski', |
| 17 | + 'url' => 'http://www.wikia.com' , |
| 18 | + 'description' => 'allows to create a new page - with the wysiwyg editor ' |
| 19 | +); |
| 20 | + |
| 21 | +/* special page init */ |
| 22 | +function wfCreatePageSetup() { |
| 23 | + global $IP, $wgMessageCache, $wgOut ; |
| 24 | + require_once($IP. '/includes/SpecialPage.php'); |
| 25 | + |
| 26 | + /* add messages to all the translator people out there to play with */ |
| 27 | + $wgMessageCache->addMessages( |
| 28 | + array( |
| 29 | + 'createpage' => 'Create a new article' , |
| 30 | + 'createpage_button' => 'Create a new article' , |
| 31 | + 'createpage_help' => '' , |
| 32 | + 'createpage_caption' => 'title' , |
| 33 | + 'createpage_button_caption' => 'Create!' , |
| 34 | + 'createpage_title' => 'Create a new article' , |
| 35 | + 'createpage_categories' => 'Categories:' , |
| 36 | + 'createpage_title_caption' => 'Title:' , |
| 37 | + 'createpage_loading_mesg' => 'Loading... please wait...' , |
| 38 | + 'createpage_enter_text' => 'Text:' , |
| 39 | + 'createpage_here' => 'here' , |
| 40 | + 'createpage_show_cloud' => '[show category cloud]' , |
| 41 | + 'createpage_hide_cloud' => '[hide category cloud]' , |
| 42 | + 'createpage_alternate_creation' => 'or click $1 to use original editor' , |
| 43 | + 'createpage_categories_help' => 'Categories help organize information in this wiki. Please choose from the list below or type a new one.' |
| 44 | + ) |
| 45 | + ); |
| 46 | + SpecialPage::addPage(new SpecialPage('Createpage', '', true, 'wfCreatePageSpecial', false)); |
| 47 | +} |
| 48 | + |
| 49 | +/* the core */ |
| 50 | +function wfCreatePageSpecial( $par ) { |
| 51 | + global $wgOut, $wgUser, $wgRequest, $wgServer, $wgScriptPath, $wgEnableAjaxLogin, $wgContLang ; |
| 52 | + require_once($IP. 'extensions/TagCloud/TagCloudClass.php') ; |
| 53 | + |
| 54 | + if (! isset($wgWikiwygPath)) { |
| 55 | + $wgWikiwygPath = "{$wgServer}/{$wgScriptPath}/extensions/wikiwyg"; |
| 56 | + } |
| 57 | + if (! isset($wgWikiwygJsPath)) { |
| 58 | + $wgWikiwygJsPath = "$wgWikiwygPath/share/MediaWiki"; |
| 59 | + } |
| 60 | + if (! isset($wgWikiwygCssPath)) { |
| 61 | + $wgWikiwygCssPath = "$wgWikiwygPath/share/MediaWiki/css"; |
| 62 | + } |
| 63 | + if (! isset($wgWikiwygImagePath)) { |
| 64 | + $wgWikiwygImagePath = "$wgWikiwygPath/share/MediaWiki/images"; |
| 65 | + } |
| 66 | + |
| 67 | + $wgOut->addScript("<style type=\"text/css\" media=\"screen,projection\">/*<![CDATA[*/ @import \"$wgWikiwygCssPath/MediaWikiwyg.css\"; /*]]>*/</style>\n"); |
| 68 | + /* load main js file when not loaded yet */ |
| 69 | + if (wfGetDependingOnSkin () == 0) { |
| 70 | + if (isset($wgWysiwygEnabled) && ($wgWysiwygEnabled == true)) { |
| 71 | + $useWysiwygTrue = 1 ; |
| 72 | + } else { |
| 73 | + $useWysiwygTrue = 0 ; |
| 74 | + } |
| 75 | + |
| 76 | + if (! isset($wgEnableAjaxLogin) || ($wgEnableAjaxLogin == false)) { |
| 77 | + $wgEnableAjaxLogin = 0 ; |
| 78 | + } |
| 79 | + $wgOut->addScript(" |
| 80 | + <script type=\"text/javascript\"> |
| 81 | + if (typeof(Wikiwyg) == 'undefined') Wikiwyg = function() {}; |
| 82 | + Wikiwyg.mediawiki_source_path = \"$wgWikiwygPath\"; |
| 83 | + var wgEditCaption = \"".mb_strtolower(wfMsg('qbedit'))."\"; |
| 84 | + var wgSaveCaption = \"".mb_strtolower(wfMsg ('save'))."\"; |
| 85 | + var wgCancelCaption = \"".mb_strtolower(wfMsg ('cancel'))."\"; |
| 86 | + var wgSummaryCaption = \"".wfMsg ('edit-summary')."\"; |
| 87 | + var wgPreviewCaption = \"".wfMsg ('preview')."\"; |
| 88 | + var wgHelpCaption = \"".wfMsg ('help')."\" ; |
| 89 | + var wgBoldTip = \"".wfMsg ('bold_tip')."\"; |
| 90 | + var wgItalicTip = \"".wfMsg ('italic_tip')."\"; |
| 91 | + var wgIntlinkTip = \"".wfMsg ('link_tip')."\"; |
| 92 | + var wgExtlinkTip = \"".wfMsg ('extlink_tip')."\"; |
| 93 | + var wgNowikiTip = \"".wfMsg ('nowiki_tip')."\"; |
| 94 | + var wgHrTip = \"".wfMsg ('hr_tip')."\"; |
| 95 | + var wgTimestampTip = \"".wfMsg ('sig_tip')."\"; |
| 96 | + var wgUseWysiwyg = " .$useWysiwygTrue." ; |
| 97 | + var wgUseInPage = ".wfGetDependingOnSkin ()."; |
| 98 | + var wgFullPageEditing = false ; |
| 99 | + var wgWysiwygCaption = \"".wfMsg ('wysiwygcaption') ."\" ; |
| 100 | + var wgInsertImageCaption = \"".wfMsg ('insertimage') ."\" ; |
| 101 | + var wgDefaultMode = \"".$wgUser->getOption ('visualeditormode','wysiwyg') ."\" ; |
| 102 | + var wgCategoryPrefix = \"".urlencode ($wgContLang->getNsText (NS_CATEGORY) ) ."\" ; |
| 103 | + var wgSpecialPrefix = \"".urlencode ($wgContLang->getNsText (NS_SPECIAL) ) ."\" ; |
| 104 | + var wgEnableAjaxLogin = ".$wgEnableAjaxLogin." ; |
| 105 | + </script> |
| 106 | + "); |
| 107 | + $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgWikiwygJsPath/MediaWikiWyg.js?".$GLOBALS['wgStyleVersion']."\"></script>\n"); |
| 108 | + } |
| 109 | + |
| 110 | + $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgScriptPath/extensions/wikia/CreatePage/js/createpage.js\"></script>\n"); |
| 111 | + |
| 112 | + if (! isset($wgEnableAjaxLogin) || ($wgEnableAjaxLogin == false)) { |
| 113 | + $wgEnableAjaxLogin = 0 ; |
| 114 | + } |
| 115 | + $wgOut->addHTML (" |
| 116 | + <script type=\"text/javascript\"> |
| 117 | + var wgEnableAjaxLogin = $wgEnableAjaxLogin ; |
| 118 | + </script>" |
| 119 | + ) ; |
| 120 | + $wgOut->setPageTitle (wfMsg('createpage_title')); |
| 121 | + $cSF = new CreatePageForm ($par) ; |
| 122 | + |
| 123 | + $action = $wgRequest->getVal ('action') ; |
| 124 | + if ('success' == $action) { |
| 125 | + /* do something */ |
| 126 | + } else if ( $wgRequest->wasPosted() && 'submit' == $action && |
| 127 | + $wgUser->matchEditToken( $wgRequest->getVal ('wpEditToken') ) ) { |
| 128 | + $cSF->doSubmit () ; |
| 129 | + } else if ('failure' == $action) { |
| 130 | + $cSF->showForm ('Please specify title') ; |
| 131 | + } else if ('check' == $action) { |
| 132 | + $cSF->checkArticleExists ($wgRequest->getVal ('to_check')) ; |
| 133 | + } else { |
| 134 | + $cSF->showForm ('') ; |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +/* the form for blocking names and addresses */ |
| 139 | +class CreatePageForm { |
| 140 | + var $mMode, $mLink, $mDo, $mFile ; |
| 141 | + |
| 142 | + /* constructor */ |
| 143 | + function CreatePageForm ( $par ) { |
| 144 | + global $wgRequest ; |
| 145 | + } |
| 146 | + |
| 147 | + /* output */ |
| 148 | + function showForm ( $err ) { |
| 149 | + global $wgOut, $wgUser, $wgRequest ; |
| 150 | + |
| 151 | + if ($wgUser->isLoggedIn()) { |
| 152 | + $token = htmlspecialchars( $wgUser->editToken() ); |
| 153 | + } else { |
| 154 | + $token = EDIT_TOKEN_SUFFIX; |
| 155 | + } |
| 156 | + $titleObj = Title::makeTitle( NS_SPECIAL, 'Createpage' ); |
| 157 | + $action = $titleObj->escapeLocalURL( "action=submit" ) ; |
| 158 | + |
| 159 | + if ( "" != $err ) { |
| 160 | + $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); |
| 161 | + $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); |
| 162 | + } |
| 163 | + $alternate_link = "<a href=\"#\" onclick=\"CreatePageNormalEdit(); return false;\" >".wfMsg ('createpage_here')."</a>" ; |
| 164 | + $wgOut->addHTML ("<div id=\"createpage_subtitle\" style=\"display:none\">".wfMsg ('createpage_alternate_creation', $alternate_link)."</div>") ; |
| 165 | + |
| 166 | + $edittime = wfTimestamp(TS_MW, $this->mTimestamp) ; |
| 167 | + /* make a TagCloud html */ |
| 168 | + $cloud_html = "" ; |
| 169 | + $MyCloud = new TagCloud ; |
| 170 | + $num = 0 ; |
| 171 | + |
| 172 | + if (is_array ($MyCloud->tags)) { |
| 173 | + foreach ($MyCloud->tags as $name => $tag) { |
| 174 | + $cloud_html .= ("<span id=\"tag-$num\" style=\"font-size:". $tag["size"]."pt\"> |
| 175 | + <a href=\"#\" id=\"cloud_$num\" onclick=\"CreatePageAddCategory ('$name', $num) ; return false ;\">$name</a> |
| 176 | + </span> |
| 177 | + ") ; |
| 178 | + $num++ ; |
| 179 | + |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + $html = " |
| 184 | +<form name=\"editform\" method=\"post\" action=\"{$action}\"> |
| 185 | + <div id=\"createpage_messenger\" style=\"display:none; color:red \" ></div> |
| 186 | + <b>".wfMsg ('createpage_title_caption')."</b> |
| 187 | + <br/> |
| 188 | + <input name=\"title\" id=\"title\" value=\"\" size=\"100\" /><br/><br/> |
| 189 | + <b>".wfMsg ('createpage_enter_text')."</b> |
| 190 | + <br><div id=\"wikiwyg\"></div> |
| 191 | + <div id=\"loading_mesg\"><b>".wfMsg('createpage_loading_mesg')."</b></div> |
| 192 | + |
| 193 | + <noscript> |
| 194 | + <style type=\"text/css\"> |
| 195 | + #loading_mesg, #image_upload { |
| 196 | + display: none ; |
| 197 | + } |
| 198 | + </style> |
| 199 | + <textarea tabindex=\"1\" accesskey=\",\" name=\"wpTextbox1\" id=\"wpTextbox1\" rows=\"25\" cols=\"80\" ></textarea> |
| 200 | + </noscript> |
| 201 | + <div id=\"backup_textarea_placeholder\"></div> |
| 202 | + <iframe id=\"wikiwyg-iframe\" height=\"0\" width=\"0\" frameborder=\"0\"></iframe> |
| 203 | + <input type=\"submit\" name=\"wpSave\" id=\"wpSaveBottom\" value=\"".wfMsg ('createpage_button_caption') ."\" /> |
| 204 | + <input type='hidden' name='wpEditToken' value=\"{$token}\" /> |
| 205 | + <input type=\"hidden\" name=\"wpCreatePage\" value=\"true\" /> |
| 206 | + |
| 207 | + <input type=\"hidden\" value=\"{$this->edittime}\" name=\"wpEdittime\" /> |
| 208 | + <br/> |
| 209 | + <div id=\"category_wrapper\"> |
| 210 | + <table id=\"editpage_table\"> |
| 211 | + <tr style=\"padding: 6px 0px 6px 0px\"> |
| 212 | + <td class=\"editpage_header\"> </td> |
| 213 | + <td>".wfMsg ('createpage_categories_help')."</td> |
| 214 | + </tr> |
| 215 | + <tr> |
| 216 | + <td class=\"editpage_header\">".wfMsg ('createpage_categories')."</td> |
| 217 | + <td> |
| 218 | + <textarea name=\"category\" id=\"category\" rows=\"1\" cols=\"80\" /></textarea> |
| 219 | + <div id=\"category_cloud_wrapper\" class=\editpage_inside\"> |
| 220 | + <div id=\"editpage_cloud_section\" style=\"line-height: 22pt; border: 1px solid gray; padding: 15px 15px 15px 15px\"> ".$cloud_html." |
| 221 | + </div> |
| 222 | + </td> |
| 223 | + </tr> |
| 224 | + </table>" ; |
| 225 | + |
| 226 | + $wgOut->addHtml( $html ); |
| 227 | + $wgOut->addHTML (" |
| 228 | + </div><br/> |
| 229 | +</form>" |
| 230 | + ); |
| 231 | + |
| 232 | + } |
| 233 | + |
| 234 | + /* draws select and selects it properly */ |
| 235 | + function makeSelect ($name, $options_array, $current, $tabindex) { |
| 236 | + global $wgOut ; |
| 237 | + $wgOut->addHTML ("<select tabindex=\"$tabindex\" name=\"$name\" id=\"$name\">") ; |
| 238 | + foreach ($options_array as $key => $value) { |
| 239 | + if ($value == $current ) |
| 240 | + $wgOut->addHTML ("<option value=\"$value\" selected=\"selected\">$key</option>") ; |
| 241 | + else |
| 242 | + $wgOut->addHTML ("<option value=\"$value\">$key</option>") ; |
| 243 | + } |
| 244 | + $wgOut->addHTML ("</select>") ; |
| 245 | + } |
| 246 | + |
| 247 | + /* check if article exists */ |
| 248 | + function checkArticleExists ($given) { |
| 249 | + global $wgOut ; |
| 250 | + $wgOut->setArticleBodyOnly( true ); |
| 251 | + $title = Title::newFromText( $given ); |
| 252 | + $page = $title->getText () ; |
| 253 | + $page = str_replace( ' ', '_', $page ) ; |
| 254 | + $dbr =& wfGetDB (DB_SLAVE); |
| 255 | + $exists = $dbr->selectField ('page', 'page_title', array ('page_title' => $page)) ; |
| 256 | + if ($exists != '') |
| 257 | + $wgOut->addHTML('pagetitleexists'); |
| 258 | + } |
| 259 | + |
| 260 | + /* on success */ |
| 261 | + function showSuccess () { |
| 262 | + global $wgOut, $wgRequest ; |
| 263 | + $wgOut->setPageTitle (wfMsg('createpage_success_title') ) ; |
| 264 | + $wgOut->setSubTitle(wfMsg('createpage_success_subtitle')) ; |
| 265 | + } |
| 266 | + |
| 267 | + |
| 268 | + /* on submit */ |
| 269 | + function doSubmit () { |
| 270 | + global $wgOut, $wgUser, $wgRequest ; |
| 271 | + $wgOut->setSubTitle ( wfMsg ('createpage_success_subtitle', wfMsg('createpage_'.$this->mMode) ) ) ; |
| 272 | + } |
| 273 | +} |
| 274 | + |
| 275 | +?> |
Property changes on: trunk/extensions/wikiwyg/share/MediaWiki/extensions/CreatePage/SpecialCreatePage.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 276 | + native |