MediaWiki Diskussion:If-search.js

Letzter Kommentar: vor 8 Jahren von Amire80 in Abschnitt ContentTranslation

Replace $ Bearbeiten

It might be a good idea to replace the $ function with something more specific, like $id. $ is used by several libraries and other scripts, its a conflict waiting to happen. --Tgr (Diskussion) 22:52, 4. Mär. 2009 (MEZ)Beantworten

I agree! Helder (Diskussion) 17:17, 21. Okt. 2010 (MESZ)
I too. I faced an issue with jQuery in tamil wiki - Mahir78 (Diskussion) 20:21, 11. Dez. 2010 (MEZ)Beantworten
hi. thanks for your comments. however, i fear we're having a lack of js proficient users here. is it an easy thing to implement? if so, could you perhaps give us some details about what exactly needs to be changed? we could try to find someone then to have a second look over it. —Pill (Kontakt) 17:10, 12. Dez. 2010 (MEZ)Beantworten
// You may have to adapt this?
function $search(ID) {return document.getElementById(ID);}
function $inp(ID) {return $search(ID).getElementsByTagName("input")[0];}
 
function tfSearch(f,i) {
 if ($search(f)) {
  $search(f).setAttribute("onsubmit", "SubSearch('"+f+"','"+i+"','/')");
 $search(f).parentNode.innerHTML = $search(f).parentNode.innerHTML; // f***ing IE
 }
}
function LogSearch() {
 tfSearch("searchform","searchInput");
 tfSearch("search","searchText");
 tfSearch("powersearch","powerSearchText");
 tfSearch("bodySearch","bodySearchIput");
 if ($search("searchform").action.indexOf(wgScript) > -1) {
  oSEAp = $inp("searchform").value;
 } else {
  oSEAp = $search("searchform").action.replace(/^.*\/([^\/]+)$/, "$1");
 }
}
addOnloadHook(LogSearch);
function SubSearch(f,i,x) {
 if ($search(i).value == "") {x="";}
 $search(f).action = wgScriptPath+"iki/"+oSEAp+x+$search(i).value;
 if ($inp(f).name == "title") {
  if ($inp(f).parentNode == $search(f)) {
   $search(f).removeChild($inp(f));
  } else {
$search(f).firstChild.removeChild($inp(f));
  }
 }
}

could be this one helps. replaced $( with $search(.-- Mahir78 (Diskussion) 14:23, 13. Dez. 2010 (MEZ)Beantworten

I agree. The change proposed by Mahir78 would help us to solve the errors we get on pt.wikibooks:
$(f).setAttribute is not a function
http://de.wiktionary.org/w/index.php?title=MediaWiki:If-search.js&action=raw&ctype=text/javascript
Line 12
Helder 11:53, 24. Jan 2011 (MEZ)

Suggestion Bearbeiten

Vorlage:editprotected I suggest to replace this line:

 $(f).action = wgScriptPath+"iki/"+oSEAp+x+$(i).value;

by the following:

 $(f).action = wgArticlePath.replace("$1", oSEAp+x+$(i).value);

--DavidL (Diskussion) 23:20, 22. Mai 2010 (MESZ)Beantworten

I agree! Helder (Diskussion) 17:17, 21. Okt. 2010 (MESZ)

Charakteristische Wortkombinationen:


Action, 2011 Bearbeiten

I've put the above suggestions in a rewrite of the script:

// This script is needed for (anonymously) logging search terms by our Squids!
// The search URL will contain the search term,
// please modify retroactively at [[wikt:de:MediaWiki:If-search.js]];
// rather IMPORT this script; example: [[wikt:de:MediaWiki:If-search.js/import]].
// --
// Updated on de.wiktionary by Krinkle 2011-02-08

function getID( ID ) {
 return document.getElementById(ID);
}
function firstInputInID( ID ) {
 return getID( ID ).getElementsByTagName( 'input' )[0];
}

function fixSearchForm( id, input ) {
 var fNode = getID( id );
 if ( fNode ) {
  fNode.setAttribute( 'onsubmit', "SubSearch('" + id + "', '" + input + "', '/')" );
  fNode.parentNode.innerHTML = getID( id ).parentNode.innerHTML; // f***ing IE
 }
}

function SubSearch( id, input, delimeter ) {
 var inputNode = getID(input);
 var formNode = getID(id);
 if ( inputNode.value === '' ) {
  delimeter = '';
 }
 formNode.action = wgArticlePath.replace( '$1', oSEAp + delimeter + inputNode.value );

 // Try to remove <input name="title"> from the <form>
 if ( firstInputInID(id).name === 'title' ) {
  if ( firstInputInID(id).parentNode == formNode ) {
   formNode.removeChild( firstInputInID(id) );
  } else {
   formNode.firstChild.removeChild( firstInputInID(id) );
  }
 }
}

function LogSearch() {
 fixSearchForm( 'searchform', 'searchInput' );
 fixSearchForm( 'search', 'searchText' );
 fixSearchForm( 'powersearch', 'powerSearchText' );
 fixSearchForm( 'bodySearch', 'bodySearchIput' );
 var searchform = getID( 'searchform' );
 if ( searchform && searchform.action.indexOf(wgScript) !== -1) {
  window.oSEAp = firstInputInID( 'searchform' ).value;
 } else {
  window.oSEAp = searchform.action.replace( /^.*\/([^\/]+)$/, '$1' );
 }
}

// Execute it when the page is ready
jQuery( document ).ready( LogSearch );

Krinkle (Diskussion) 20:53, 8. Feb 2011 (MEZ)

Bugs Bearbeiten

This script is causing bugzilla:29516 and bugzilla:29801. Could someone fix it? Helder 22:47, 17. Aug. 2011 (MESZ)

Yeah it appears to just destroy all event handlers and other attached DOM stuff on things in the search form, by wiping out the entire form and replacing it with a freshly-parsed HTML version of itself. I've simply removed it from https://als.wikipedia.org (bugzilla:29595) entirely as it doesn't look like it serves useful purposes. (If it was useful/required to do this for logging, it would need to be done for *all* sites, not just a few opt-ins with site JS... so something isn't being done right here.) --Brion VIBBER (Diskussion) 23:35, 14. Nov. 2011 (MEZ)Beantworten

ContentTranslation Bearbeiten

Hi,

It looks like this script breaks the ContentTranslation in the pms.wikipedia, and it will do so in other sites that import it. In ContentTranslaiton searchform will be undefined, because it doesn't have a search box, so it fails on line 50.

It can probably be fixed by changing linmes 47-51 to something like this:

 if (searchform) {
   if (searchform.action.indexOf(wgScript) !== -1) {
    window.oSEAp = firstInputInID( 'searchform' ).value;
   } else {
    window.oSEAp = searchform.action.replace( /^.*\/([^\/]+)$/, '$1' );
   }
 }

Thanks! --Amir E. Aharoni (Diskussion) 19:51, 11. Jun. 2015 (MESZ)Beantworten

Tagging relevant admins: User:Akinom, User:Balû, User:Caligari, User:Elleff Groom, User:Susann Schweden, User:Tragopogon. --Amire80 (Diskussion) 19:55, 11. Jun. 2015 (MESZ)Beantworten
Zurück zur Seite „If-search.js“.