This is an old revision of this page, as edited by Proteins(talk | contribs) at 16:06, 3 November 2008(check that the basic loop is OK before going on). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 16:06, 3 November 2008 by Proteins(talk | contribs)(check that the basic loop is OK before going on)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>//Summarizes the differences between two page versions in pop-up windows// Perhaps calculate fractional change in document functionquickDiffs(){varalert_string="";varbody_content;vararticle_tables;vartemp_article_table;varnum_article_tables=0;vararticle_table_index=0;vardiff_table;varnum_diff_tables=0;vardiff_table_body;vardiff_table_bodies;varnum_diff_table_bodies=0;vartemp_table_row;vardiff_table_rows;vartable_row_index=0;varnum_diff_table_rows=0;vartable_row_data;vartemp_table_datum;vartable_datum_index=0;varnum_table_row_data=0;vardiff_old_version_info;//className = "diff-otitle"vardiff_new_version_info;//className = "diff-ntitle"varmw_diff_otitle1="";varmw_diff_otitle2="";varmw_diff_otitle3="";varmw_diff_otitle4="";varmw_diff_ntitle1="";varmw_diff_ntitle2="";varmw_diff_ntitle3="";varmw_diff_ntitle4="";varintermediate_revisions="";varnum_line_numbers=0;vartemp_diff_old_line_numbers=0;vartemp_diff_new_line_numbers=0;vardiff_old_line_numbers=newArray();vardiff_new_line_numbers=newArray();varnum_additions=0;varnum_deletions=0;varnum_replacements=0;varnum_changed_lines=0;vardiff_added_lines=newArray();vardiff_deleted_lines=newArray();varnum_changes_in_line=newArray();vardiff_changes=newArray();vardiff_change_line_numbers=newArray();// Check that there is exactly one table on this page with the className "diff"body_content=document.getElementById('bodyContent');if(!body_content){alert_string="ERROR: This article has no bodyContent element.";window.alert(alert_string);return;}article_tables=body_content.getElementsByTagName("TABLE");if(!article_tables){alert_string="ERROR: This article has no TABLE elements.";window.alert(alert_string);return;}num_article_tables=article_tables.length;if(!num_article_tables){alert_string="ERROR: This article has no TABLE elements.";window.alert(alert_string);return;}num_diff_tables=0;for(article_table_index=0;article_table_index<num_article_tables;article_table_index++){temp_article_table=article_tables[article_table_index];if(!temp_article_table){continue;}if(temp_article_table.className=="diff"){num_diff_tables++;diff_table=temp_article_table;}}// closes loop searching for the diff tableif(num_diff_tables==0){alert_string="ERROR: This article has no TABLE elements belonging to the \"diff\" class.";window.alert(alert_string);return;}elseif(num_diff_tables!=1){alert_string="ERROR: This article has "+num_diff_tables+" TABLE elements belonging to the \"diff\" class.";alert_string+="An article should have at most one \"diff\" table.\n";window.alert(alert_string);return;}// Check that there is exactly one table bodydiff_table_bodies=diff_table.getElementsByTagName("TBODY");if(!diff_table_bodies){alert_string="ERROR: This article has no TBODY element within its \"diff\" table.";window.alert(alert_string);return;}num_diff_table_bodies=diff_table_bodies.length;if(!num_diff_table_bodies){alert_string="ERROR: This article has no TBODY element within its \"diff\" table.";window.alert(alert_string);return;}elseif(num_diff_table_bodies!=1){alert_string="ERROR: This article has "+num_diff_table_bodies+" TBODY elements within its \"diff\" table.";alert_string+="A \"diff\" table should have at most one TBODY element.\n";window.alert(alert_string);return;}diff_table_body=diff_table_bodies[0];if(!diff_table_body){alert_string="ERROR: This article has a null TBODY element within its \"diff\" table.";window.alert(alert_string);return;}// Loop over the table rows in the table body diff_table_rows=diff_table_body.getElementsByTagName("TR");if(!diff_table_rows){alert_string="ERROR: This article has no TR elements within its \"diff\" table body.";window.alert(alert_string);return;}num_diff_table_rows=diff_table_rows.length;if(!num_diff_table_rows){alert_string="ERROR: This article has no TR elements within its \"diff\" table body.";window.alert(alert_string);return;}elseif(num_diff_table_rows<3){alert_string="ERROR: This article has "+num_diff_table_rows+" rows (TR elements) within its \"diff\" table body.";alert_string+="A \"diff\" table body should have at least three rows.\n";window.alert(alert_string);return;}// Loop over the rows in the difference tablefor(table_row_index=0;table_row_index<num_diff_table_rows;table_row_index++){temp_table_row=diff_table_rows[table_row_index];if(!temp_table_row){continue;}table_row_data=temp_table_row.getElementsByTagName("TD");if(!table_row_data){continue;}num_table_row_data=table_row_data.length;if(!num_table_row_data){continue;}for(table_datum_index=0;table_datum_index<num_table_row_data;table_datum_index++){temp_table_datum=table_row_data[table_datum_index];if(!temp_table_datum){continue;}}// closes loop over the data within a table row}// closes loop over the table rows// Report the resultsalert_string="";alert_string="This articles has "+num_diff_table_rows+" lines in its difference table.\n\n";alert_string+="The newer version of this article has "+num_additions+" additions, "+num_deletions+" deletions, and "+num_replacements+" replacements.\n\n";window.alert(alert_string);}// closes function quickDiffs()addOnloadHook(function(){addPortletLink('p-cactions','javascript:quickDiffs()','qd','ca-diff','Summarizes the differences between two page versions','b','');});//</pre>