Kullanıcı:Satirdan kahraman/common.js

Vikikaynak, özgür kütüphane

Not: Yayımladıktan sonra değişiklikleri görmek için tarayıcınızın önbelleğini temizlemeniz gerekebilir.

  • Firefox / Safari: Shift tuşuna basılıyken Yeniden Yükle'ye tıklayın ya da Ctrl-F5 ya da Ctrl-R tıklayın (Mac için ⌘-R).
  • Google Chrome: Ctrl-Shift-R'ye basın. (Mac için ⌘-Shift-R)
  • Internet Explorer / Edge: Ctrl basılıyken Yenile'ye tıklayın ya da Ctrl-F5 yapın.
  • Opera: Ctrl-F5 tıklayın.
/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:pathoschild/templatescript.js]]
 */
// <nowiki>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add([
		{ name:'eser başlığı', template:'{{eser başlığı\n | önceki      =\n | sonraki     =\n | başlık      ={{kopyala:SAYFAADI}} | bölüm       =\n | eser sahibi =\n | notlar      =\n}}' },
		{ name:'kişi', template:'{{Kişi\n |ismi        =\n | soyismi =\n |doğumyılı  = \n | ölümyılı = \n | soyismi başharfi=\n |yaşadığı tarih  =\n |açıklamalar   =\n |resim  =\n |vikipedi_bağlantısı     =\n |vikisöz_bağlantısı     =\n |commons_bağlantısı      =\n}}' },
		{ name:'hoş geldin', template:'{{subst:Hoşgeldin}}\n', editSummary:'Vikikaynak\'a hoş geldin!' },
		{ name:'düzenle', template:'{{Düzenle}}\n', editSummary:'Düzenle' },
		{ name:'telif', template:'{{telif}}\n', editSummary:'muhtemel telif ihlali!' },
		{ name:'çevirmensiz', template:'{{çevirmensiz}}\n', editSummary:'çevirmeni belli değil!' },
	    { name:'kanun künye', template:'{{Kanun künye\n | rg_tarihi =\n | rg_no     =\n | başlık      =\n | kanun_no       =\n |kabul_tarihi = \n}}' },
		{ name:'resim bağla', template:'{{#tag:pages||index=| \n |from= \n |to= \n}}'
 },
	]);
});
/* in case the ws_layouts object doesn't exist yet */
if (self.ws_layouts === undefined) {
  self.ws_layouts = {};
}

self.ws_layouts['My Layout'] = {
	 
};
// </nowiki>

/**
 * Easy Labelled Section Transclusion Syntax
 *
 * Configurations:
 *     enabled:    Set to false to disable this gadget on the current page
 *
 * Configure it like this, from your main JS:
 *
 * {
 *   var easySectSyntaxConfig = {
 *    enabled: true,
 *   };
 *
 *   mw.hook("easy_section_syntax.config").fire(easySectSyntaxConfig);
 * }
 */

"use strict";

// IIFE used when including as a user script (to allow debug or config)
// Default gadget use will get an IIFE wrapper as well
(function($, mw) {

  var gadget_name = "easy_section_syntax";

  var EasySS = {
    enabled: true,
    debug: true,
    configured: false,
  };

  function log(msg) {
    if (EasySS.debug) {
      console.log(gadget_name + ": ", msg);
    }
  }

  function error(msg) {
    console.error(gadget_name + ": ", msg);
  }

  /*
   * Read config from user. This function fired by hook
   */
  function apply_config(cfg) {
    console.log("Configuring " + gadget_name);

    // Bail if the config looks like junk
    if (!cfg || typeof cfg !== "object") {
      console.error("Invalid " + gadget_name + " config", cfg);
      return;
    }

    if (typeof cfg.enabled === "boolean") {
      EasySS.enabled = cfg.enabled;
    }

    if (typeof cfg.debug === "boolean") {
      EasySS.debug = cfg.debug;
    }

    EasySS.configured = true;
  }

  /*
   * Convert ## syntax to <section> syntax
   */
  function restore_lst() {

    log("Restoring section markers from ##-syntax");

    var editbox = $("#wpTextbox1");

    if (!editbox) {
      error("Couldn't find editbox");
      return;
    }

    var search = /##[\s]*(.*?)[\s]*##[\s]*\n/;
    var a = editbox.val().split(search);
    var s = a[0];
    var m = parseInt(a.length / 2);
    for (var i = 0; i < m; i++) {
      var title = a[i * 2 + 1];
      // Ensure we'll don't get twice quote.
      title = title.replace(/^"(.*)"$/, "$1");
      title = title.replace(/^'(.*)'$/, "$1");
      var content = a[i * 2 + 2];
      if (title && content.substring(0, 2) == "{|") {
        content = "\n" + content;
      }
      if (title) {
        s = s + "<section begin=\"" + title + "\" />" +
          content +
          "<section end=\"" + title + "\" />\n";
      } else {
        s = s + content;
      }
      /* if( i < m-1 ) s = s + "----\n"; */
    }
    editbox.val(s);
  }

  /**
   * easy lst: hide section markers
   */
  function easy_section_syntax() {

    log("Converting section markers to ##-syntax");

    var editbox = $("#wpTextbox1");

    if (!editbox) {
      error("Couldn't find editbox");
      return;
    }

    var search = /<section\sbegin=[\s]*(.*?)[\s]*\/>/;
    var a = editbox.val().split(search);
    var s = a[0];
    var ok = true;
    for (var i = 0; i < parseInt(a.length / 2); i++) {
      var title = a[i * 2 + 1];
      var content = a[i * 2 + 2];
      var r2 = /^([\s\S]*?)<section\send=(.*?)\/>(\n|)[\s]*([\s\S]*?)$/;
      var m2 = content.match(r2);
      if (m2) {
        title = title.replace(/^"(.*)"$/, "$1");
        title = title.replace(/^'(.*)'$/, "$1");
        if (s && s.charAt(s.length - 1) != "\n" &&
          s.charAt(s.length - 1) != "|") {
          s = s + "\n";
        }
        s = s + "## " + title + " ##\n" + m2[1];
        if (m2[4]) {
          if (m2[4] != "----\n") {
            if (s && s.charAt(s.length - 1) != "\n") {
              s = s + "\n";
            }
            s = s + "####\n" + m2[4];
          }
        }
      } else {
        ok = false;
        error("Error" + title);
      }
    }
    if (ok) {
      // val() function is important, as just setting .value on a raw
      // element doesn't work in CodeMirror
      editbox.val(s);
    }
  }

  /*
   * Run setup, and convert to ## syntax for LST
   */
  function on_load() {
    easy_section_syntax();

    // Install the on-save hook on all edit buttons
    $('.editButtons').click(restore_lst);
  }

  /**
   * Install a load hook in the editor
   * @param  {Function} callback: function to call when editor text is loaded
   */
  function install_load_hook(callback) {
    if ($.inArray(mw.config.get("wgAction"), ["edit", "submit"]) !== -1) {
      mw.loader.using("ext.proofreadpage.page", function() {
        // mimic code in the extension, there is a conditionnal deps on ext.wikiEditor.
        if (mw.user.options.get("usebetatoolbar") &&
          $.inArray("ext.wikiEditor", mw.loader.getModuleNames()) > -1) {
          var load_deps = ["ext.wikiEditor"];
          if (mw.user.options.get("codemirror-syntax-highlight") == 1) {
            load_deps.push("ext.CodeMirror.lib");
          }
          mw.loader.using(load_deps, function() {
            callback();
          });
        } else {
          callback();
        }
      });
    }
  }

  function easy_sect_syn_setup() {

    // Get user config, if any
    mw.hook(gadget_name + ".config").add(apply_config);

    // LST only in Page NS and if user has it enabled
    if (!EasySS.enabled || mw.config.get("wgCanonicalNamespace") !== "Page") {
      return;
    }

    install_load_hook(on_load);
  }
  $(easy_sect_syn_setup);

}(jQuery, mediaWiki));