/var/www/wordpress/wp-admin/includes/admin.php
/var/www/wordpress/wp-admin/includes/bookmark.php
/var/www/wordpress/wp-admin/includes/class-ftp-pure.php
/var/www/wordpress/wp-admin/includes/class-ftp-sockets.php
/var/www/wordpress/wp-admin/includes/class-ftp.php
/var/www/wordpress/wp-admin/includes/class-pclzip.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-base.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-direct.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php
/var/www/wordpress/wp-admin/includes/class-wp-importer.php
/var/www/wordpress/wp-admin/includes/class-wp-upgrader.php
/var/www/wordpress/wp-admin/includes/comment.php
/var/www/wordpress/wp-admin/includes/continents-cities.php
/var/www/wordpress/wp-admin/includes/dashboard.php
/var/www/wordpress/wp-admin/includes/deprecated.php
/var/www/wordpress/wp-admin/includes/export.php
/var/www/wordpress/wp-admin/includes/file.php
/var/www/wordpress/wp-admin/includes/image-edit.php
/var/www/wordpress/wp-admin/includes/image.php
/var/www/wordpress/wp-admin/includes/import.php
/var/www/wordpress/wp-admin/includes/manifest.php
/var/www/wordpress/wp-admin/includes/media.php
/var/www/wordpress/wp-admin/includes/meta-boxes.php
/var/www/wordpress/wp-admin/includes/misc.php
/var/www/wordpress/wp-admin/includes/ms-deprecated.php
/var/www/wordpress/wp-admin/includes/ms.php
/var/www/wordpress/wp-admin/includes/nav-menu.php
/var/www/wordpress/wp-admin/includes/plugin-install.php
/var/www/wordpress/wp-admin/includes/plugin.php
/var/www/wordpress/wp-admin/includes/post.php
/var/www/wordpress/wp-admin/includes/schema.php
/var/www/wordpress/wp-admin/includes/taxonomy.php
/var/www/wordpress/wp-admin/includes/template.php
/var/www/wordpress/wp-admin/includes/theme-install.php
/var/www/wordpress/wp-admin/includes/theme.php
/var/www/wordpress/wp-admin/includes/update-core.php
/var/www/wordpress/wp-admin/includes/update.php
/var/www/wordpress/wp-admin/includes/upgrade.php
/var/www/wordpress/wp-admin/includes/user.php
/var/www/wordpress/wp-admin/includes/widgets.php
/var/www/wordpress/wp-admin/js/revisions-js.php
/var/www/wordpress/wp-admin/maint/repair.php
/var/www/wordpress/wp-admin/admin-ajax.php
/var/www/wordpress/wp-admin/admin-footer.php
/var/www/wordpress/wp-admin/admin-functions.php
/var/www/wordpress/wp-admin/admin-header.php
/var/www/wordpress/wp-admin/admin-post.php
/var/www/wordpress/wp-admin/admin.php
/var/www/wordpress/wp-admin/async-upload.php
/var/www/wordpress/wp-admin/comment.php
/var/www/wordpress/wp-admin/custom-background.php
/var/www/wordpress/wp-admin/custom-header.php
/var/www/wordpress/wp-admin/edit-attachment-rows.php
/var/www/wordpress/wp-admin/edit-comments.php
/var/www/wordpress/wp-admin/edit-form-advanced.php
/var/www/wordpress/wp-admin/edit-form-comment.php
/var/www/wordpress/wp-admin/edit-link-categories.php
/var/www/wordpress/wp-admin/edit-link-category-form.php
/var/www/wordpress/wp-admin/edit-link-form.php
/var/www/wordpress/wp-admin/edit-post-rows.php
/var/www/wordpress/wp-admin/edit-tag-form.php
/var/www/wordpress/wp-admin/edit-tags.php
/var/www/wordpress/wp-admin/edit.php
/var/www/wordpress/wp-admin/export.php
/var/www/wordpress/wp-admin/gears-manifest.php
/var/www/wordpress/wp-admin/import.php
/var/www/wordpress/wp-admin/index-extra.php
/var/www/wordpress/wp-admin/index.php
/var/www/wordpress/wp-admin/install-helper.php
/var/www/wordpress/wp-admin/install.php
/var/www/wordpress/wp-admin/link-add.php
/var/www/wordpress/wp-admin/link-category.php
/var/www/wordpress/wp-admin/link-manager.php
/var/www/wordpress/wp-admin/link-parse-opml.php
/var/www/wordpress/wp-admin/link.php
/var/www/wordpress/wp-admin/load-scripts.php
/var/www/wordpress/wp-admin/load-styles.php
/var/www/wordpress/wp-admin/media-new.php
/var/www/wordpress/wp-admin/media-upload.php
/var/www/wordpress/wp-admin/media.php
/var/www/wordpress/wp-admin/menu-header.php
/var/www/wordpress/wp-admin/menu.php
/var/www/wordpress/wp-admin/moderation.php
/var/www/wordpress/wp-admin/ms-admin.php
/var/www/wordpress/wp-admin/ms-delete-site.php
/var/www/wordpress/wp-admin/ms-edit.php
/var/www/wordpress/wp-admin/ms-options.php
/var/www/wordpress/wp-admin/ms-sites.php
/var/www/wordpress/wp-admin/ms-themes.php
/var/www/wordpress/wp-admin/ms-upgrade-network.php
/var/www/wordpress/wp-admin/ms-users.php
/var/www/wordpress/wp-admin/my-sites.php
/var/www/wordpress/wp-admin/nav-menus.php
/var/www/wordpress/wp-admin/network.php
/var/www/wordpress/wp-admin/options-discussion.php
/var/www/wordpress/wp-admin/options-general.php
/var/www/wordpress/wp-admin/options-head.php
/var/www/wordpress/wp-admin/options-media.php
/var/www/wordpress/wp-admin/options-permalink.php
/var/www/wordpress/wp-admin/options-privacy.php
/var/www/wordpress/wp-admin/options-reading.php
/var/www/wordpress/wp-admin/options-writing.php
/var/www/wordpress/wp-admin/options.php
/var/www/wordpress/wp-admin/plugin-editor.php
/var/www/wordpress/wp-admin/plugin-install.php
/var/www/wordpress/wp-admin/plugins.php
/var/www/wordpress/wp-admin/post-new.php
/var/www/wordpress/wp-admin/post.php
/var/www/wordpress/wp-admin/press-this.php
/var/www/wordpress/wp-admin/profile.php
/var/www/wordpress/wp-admin/revision.php
/var/www/wordpress/wp-admin/setup-config.php
/var/www/wordpress/wp-admin/sidebar.php
/var/www/wordpress/wp-admin/theme-editor.php
/var/www/wordpress/wp-admin/theme-install.php
/var/www/wordpress/wp-admin/themes.php
/var/www/wordpress/wp-admin/tools.php
/var/www/wordpress/wp-admin/update-core.php
/var/www/wordpress/wp-admin/update.php
/var/www/wordpress/wp-admin/upgrade-functions.php
/var/www/wordpress/wp-admin/upgrade.php
/var/www/wordpress/wp-admin/upload.php
/var/www/wordpress/wp-admin/user-edit.php
/var/www/wordpress/wp-admin/user-new.php
/var/www/wordpress/wp-admin/users.php
/var/www/wordpress/wp-admin/widgets.php
/var/www/wordpress/wp-content/languages/ru_RU.php
/var/www/wordpress/wp-content/plugins/akismet/akismet.php
/var/www/wordpress/wp-content/plugins/rh/rh.php
/var/www/wordpress/wp-content/plugins/hello.php
/var/www/wordpress/wp-content/plugins/index.php
/var/www/wordpress/wp-content/themes/twentyten/404.php
/var/www/wordpress/wp-content/themes/twentyten/archive.php
/var/www/wordpress/wp-content/themes/twentyten/attachment.php
/var/www/wordpress/wp-content/themes/twentyten/author.php
/var/www/wordpress/wp-content/themes/twentyten/category.php
/var/www/wordpress/wp-content/themes/twentyten/comments.php
/var/www/wordpress/wp-content/themes/twentyten/footer.php
/var/www/wordpress/wp-content/themes/twentyten/functions.php
/var/www/wordpress/wp-content/themes/twentyten/header.php
/var/www/wordpress/wp-content/themes/twentyten/index.php
/var/www/wordpress/wp-content/themes/twentyten/loop.php
/var/www/wordpress/wp-content/themes/twentyten/onecolumn-page.php
/var/www/wordpress/wp-content/themes/twentyten/page.php
/var/www/wordpress/wp-content/themes/twentyten/search.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar-footer.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar.php
/var/www/wordpress/wp-content/themes/twentyten/single.php
/var/www/wordpress/wp-content/themes/twentyten/tag.php
/var/www/wordpress/wp-content/themes/index.php
/var/www/wordpress/wp-content/index.php
/var/www/wordpress/wp-includes/js/tinymce/langs/wp-langs.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/EnchantSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/GoogleSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/SpellChecker.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/includes/general.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/config.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/rpc.php
/var/www/wordpress/wp-includes/js/tinymce/wp-mce-help.php
/var/www/wordpress/wp-includes/js/tinymce/wp-tinymce.php
/var/www/wordpress/wp-includes/pomo/entry.php
/var/www/wordpress/wp-includes/pomo/mo.php
/var/www/wordpress/wp-includes/pomo/po.php
/var/www/wordpress/wp-includes/pomo/streams.php
/var/www/wordpress/wp-includes/pomo/translations.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/native.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/shell.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/string.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/xdiff.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer/inline.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer.php
/var/www/wordpress/wp-includes/Text/Diff.php
/var/www/wordpress/wp-includes/theme-compat/comments-popup.php
/var/www/wordpress/wp-includes/theme-compat/comments.php
/var/www/wordpress/wp-includes/theme-compat/footer.php
/var/www/wordpress/wp-includes/theme-compat/header.php
/var/www/wordpress/wp-includes/theme-compat/sidebar.php
/var/www/wordpress/wp-includes/atomlib.php
/var/www/wordpress/wp-includes/author-template.php
/var/www/wordpress/wp-includes/bookmark-template.php
/var/www/wordpress/wp-includes/bookmark.php
/var/www/wordpress/wp-includes/cache.php
/var/www/wordpress/wp-includes/canonical.php
/var/www/wordpress/wp-includes/capabilities.php
/var/www/wordpress/wp-includes/category-template.php
/var/www/wordpress/wp-includes/category.php
/var/www/wordpress/wp-includes/class-feed.php
/var/www/wordpress/wp-includes/class-http.php
/var/www/wordpress/wp-includes/class-IXR.php
/var/www/wordpress/wp-includes/class-json.php
/var/www/wordpress/wp-includes/class-oembed.php
/var/www/wordpress/wp-includes/class-phpass.php
/var/www/wordpress/wp-includes/class-phpmailer.php
/var/www/wordpress/wp-includes/class-pop3.php
/var/www/wordpress/wp-includes/class-simplepie.php
/var/www/wordpress/wp-includes/class-smtp.php
/var/www/wordpress/wp-includes/class-snoopy.php
/var/www/wordpress/wp-includes/class.wp-dependencies.php
/var/www/wordpress/wp-includes/class.wp-scripts.php
/var/www/wordpress/wp-includes/class.wp-styles.php
/var/www/wordpress/wp-includes/classes.php
/var/www/wordpress/wp-includes/comment-template.php
/var/www/wordpress/wp-includes/comment.php
/var/www/wordpress/wp-includes/compat.php
/var/www/wordpress/wp-includes/cron.php
/var/www/wordpress/wp-includes/default-constants.php
/var/www/wordpress/wp-includes/default-embeds.php
/var/www/wordpress/wp-includes/default-filters.php
/var/www/wordpress/wp-includes/default-widgets.php
/var/www/wordpress/wp-includes/deprecated.php
/var/www/wordpress/wp-includes/feed-atom-comments.php
/var/www/wordpress/wp-includes/feed-atom.php
/var/www/wordpress/wp-includes/feed-rdf.php
/var/www/wordpress/wp-includes/feed-rss.php
/var/www/wordpress/wp-includes/feed-rss2-comments.php
/var/www/wordpress/wp-includes/feed-rss2.php
/var/www/wordpress/wp-includes/feed.php
/var/www/wordpress/wp-includes/formatting.php
/var/www/wordpress/wp-includes/functions.php
/var/www/wordpress/wp-includes/functions.wp-scripts.php
/var/www/wordpress/wp-includes/functions.wp-styles.php
/var/www/wordpress/wp-includes/general-template.php
/var/www/wordpress/wp-includes/http.php
/var/www/wordpress/wp-includes/kses.php
/var/www/wordpress/wp-includes/l10n.php
/var/www/wordpress/wp-includes/link-template.php
/var/www/wordpress/wp-includes/load.php
/var/www/wordpress/wp-includes/locale.php
/var/www/wordpress/wp-includes/media.php
/var/www/wordpress/wp-includes/meta.php
/var/www/wordpress/wp-includes/ms-blogs.php
/var/www/wordpress/wp-includes/ms-default-constants.php
/var/www/wordpress/wp-includes/ms-default-filters.php
/var/www/wordpress/wp-includes/ms-deprecated.php
/var/www/wordpress/wp-includes/ms-files.php
/var/www/wordpress/wp-includes/ms-functions.php
/var/www/wordpress/wp-includes/ms-load.php
/var/www/wordpress/wp-includes/ms-settings.php
/var/www/wordpress/wp-includes/nav-menu-template.php
/var/www/wordpress/wp-includes/nav-menu.php
/var/www/wordpress/wp-includes/pluggable-deprecated.php
/var/www/wordpress/wp-includes/pluggable.php
/var/www/wordpress/wp-includes/plugin.php
/var/www/wordpress/wp-includes/post-template.php
/var/www/wordpress/wp-includes/post-thumbnail-template.php
/var/www/wordpress/wp-includes/post.php
/var/www/wordpress/wp-includes/query.php
/var/www/wordpress/wp-includes/registration-functions.php
/var/www/wordpress/wp-includes/registration.php
/var/www/wordpress/wp-includes/rewrite.php
/var/www/wordpress/wp-includes/rss-functions.php
/var/www/wordpress/wp-includes/rss.php
/var/www/wordpress/wp-includes/script-loader.php
/var/www/wordpress/wp-includes/shortcodes.php
/var/www/wordpress/wp-includes/taxonomy.php
/var/www/wordpress/wp-includes/template-loader.php
/var/www/wordpress/wp-includes/theme.php
/var/www/wordpress/wp-includes/update.php
/var/www/wordpress/wp-includes/user.php
/var/www/wordpress/wp-includes/vars.php
/var/www/wordpress/wp-includes/version.php
/var/www/wordpress/wp-includes/widgets.php
/var/www/wordpress/wp-includes/wp-db.php
/var/www/wordpress/wp-includes/wp-diff.php
#CodeDescriptions
1<?php
2/**
3 * WordPress Diff bastard child of old MediaWiki Diff Formatter.
4 *
5 * Basically all that remains is the table structure and some method names.
6 *
7 * @package WordPress
8 * @subpackage Diff
9 */
10
11if ( !class_exists( 'Text_Diff' ) ) {
12 /** Text_Diff class */
13 require( dirname(__FILE__).'/Text/Diff.php' );
14 /** Text_Diff_Renderer class */
15 require( dirname(__FILE__).'/Text/Diff/Renderer.php' );
16 /** Text_Diff_Renderer_inline class */
17 require( dirname(__FILE__).'/Text/Diff/Renderer/inline.php' );
18}
19
20/**
21 * Table renderer to display the diff lines.
22 *
23 * @since 2.6.0
24 * @uses Text_Diff_Renderer Extends
25 */
26class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
27
28 /**
29 * @see Text_Diff_Renderer::_leading_context_lines
30 * @var int
31 * @access protected
32 * @since 2.6.0
33 */
34 var $_leading_context_lines = 10000;
35
36 /**
37 * @see Text_Diff_Renderer::_trailing_context_lines
38 * @var int
39 * @access protected
40 * @since 2.6.0
41 */
42 var $_trailing_context_lines = 10000;
43
44 /**
45 * {@internal Missing Description}}
46 *
47 * @var float
48 * @access protected
49 * @since 2.6.0
50 */
51 var $_diff_threshold = 0.6;
52
53 /**
54 * Inline display helper object name.
55 *
56 * @var string
57 * @access protected
58 * @since 2.6.0
59 */
60 var $inline_diff_renderer = 'WP_Text_Diff_Renderer_inline';
61
62 /**
63 * PHP4 Constructor - Call parent constructor with params array.
64 *
65 * This will set class properties based on the key value pairs in the array.
66 *
67 * @since unknown
68 *
69 * @param array $params
70 */
71 function Text_Diff_Renderer_Table( $params = array() ) {
72 $parent = get_parent_class($this);
73 $this->$parent( $params );
74 }
75
76 /**
77 * @ignore
78 *
79 * @param string $header
80 * @return string
81 */
82 function _startBlock( $header ) {
83 return '';
84 }
85
86 /**
87 * @ignore
88 *
89 * @param array $lines
90 * @param string $prefix
91 */
92 function _lines( $lines, $prefix=' ' ) {
93 }
94
95 /**
96 * @ignore
97 *
98 * @param string $line HTML-escape the value.
99 * @return string
100 */
101 function addedLine( $line ) {
102 return "<td>+</td><td class='diff-addedline'>{$line}</td>";
103 }
104
105 /**
106 * @ignore
107 *
108 * @param string $line HTML-escape the value.
109 * @return string
110 */
111 function deletedLine( $line ) {
112 return "<td>-</td><td class='diff-deletedline'>{$line}</td>";
113 }
114
115 /**
116 * @ignore
117 *
118 * @param string $line HTML-escape the value.
119 * @return string
120 */
121 function contextLine( $line ) {
122 return "<td> </td><td class='diff-context'>{$line}</td>";
123 }
124
125 /**
126 * @ignore
127 *
128 * @return string
129 */
130 function emptyLine() {
131 return '<td colspan="2"> </td>';
132 }
133
134 /**
135 * @ignore
136 * @access private
137 *
138 * @param array $lines
139 * @param bool $encode
140 * @return string
141 */
142 function _added( $lines, $encode = true ) {
143 $r = '';
144 foreach ($lines as $line) {
145 if ( $encode )
146 $line = htmlspecialchars( $line );
147 $r .= '<tr>' . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
148 }
149 return $r;
150 }
151
152 /**
153 * @ignore
154 * @access private
155 *
156 * @param array $lines
157 * @param bool $encode
158 * @return string
159 */
160 function _deleted( $lines, $encode = true ) {
161 $r = '';
162 foreach ($lines as $line) {
163 if ( $encode )
164 $line = htmlspecialchars( $line );
165 $r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . "</tr>\n";
166 }
167 return $r;
168 }
169
170 /**
171 * @ignore
172 * @access private
173 *
174 * @param array $lines
175 * @param bool $encode
176 * @return string
177 */
178 function _context( $lines, $encode = true ) {
179 $r = '';
180 foreach ($lines as $line) {
181 if ( $encode )
182 $line = htmlspecialchars( $line );
183 $r .= '<tr>' .
184 $this->contextLine( $line ) . $this->contextLine( $line ) . "</tr>\n";
185 }
186 return $r;
187 }
188
189 /**
190 * Process changed lines to do word-by-word diffs for extra highlighting.
191 *
192 * (TRAC style) sometimes these lines can actually be deleted or added rows.
193 * We do additional processing to figure that out
194 *
195 * @access private
196 * @since 2.6.0
197 *
198 * @param array $orig
199 * @param array $final
200 * @return string
201 */
202 function _changed( $orig, $final ) {
203 $r = '';
204
205 // Does the aforementioned additional processing
206 // *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes
207 // match is numeric: an index in other column
208 // match is 'X': no match. It is a new row
209 // *_rows are column vectors for the orig column and the final column.
210 // row >= 0: an indix of the $orig or $final array
211 // row < 0: a blank row for that column
212 list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final );
213
214
215 // These will hold the word changes as determined by an inline diff
216 $orig_diffs = array();
217 $final_diffs = array();
218
219 // Compute word diffs for each matched pair using the inline diff
220 foreach ( $orig_matches as $o => $f ) {
221 if ( is_numeric($o) && is_numeric($f) ) {
222 $text_diff = new Text_Diff( 'auto', array( array($orig[$o]), array($final[$f]) ) );
223 $renderer = new $this->inline_diff_renderer;
224 $diff = $renderer->render( $text_diff );
225
226 // If they're too different, don't include any <ins> or <dels>
227 if ( $diff_count = preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) {
228 // length of all text between <ins> or <del>
229 $stripped_matches = strlen(strip_tags( join(' ', $diff_matches[0]) ));
230 // since we count lengith of text between <ins> or <del> (instead of picking just one),
231 // we double the length of chars not in those tags.
232 $stripped_diff = strlen(strip_tags( $diff )) * 2 - $stripped_matches;
233 $diff_ratio = $stripped_matches / $stripped_diff;
234 if ( $diff_ratio > $this->_diff_threshold )
235 continue; // Too different. Don't save diffs.
236 }
237
238 // Un-inline the diffs by removing del or ins
239 $orig_diffs[$o] = preg_replace( '|<ins>.*?</ins>|', '', $diff );
240 $final_diffs[$f] = preg_replace( '|<del>.*?</del>|', '', $diff );
241 }
242 }
243
244 foreach ( array_keys($orig_rows) as $row ) {
245 // Both columns have blanks. Ignore them.
246 if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 )
247 continue;
248
249 // If we have a word based diff, use it. Otherwise, use the normal line.
250 if ( isset( $orig_diffs[$orig_rows[$row]] ) )
251 $orig_line = $orig_diffs[$orig_rows[$row]];
252 elseif ( isset( $orig[$orig_rows[$row]] ) )
253 $orig_line = htmlspecialchars($orig[$orig_rows[$row]]);
254 else
255 $orig_line = '';
256
257 if ( isset( $final_diffs[$final_rows[$row]] ) )
258 $final_line = $final_diffs[$final_rows[$row]];
259 elseif ( isset( $final[$final_rows[$row]] ) )
260 $final_line = htmlspecialchars($final[$final_rows[$row]]);
261 else
262 $final_line = '';
263
264 if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row.
265 $r .= $this->_added( array($final_line), false );
266 } elseif ( $final_rows[$row] < 0 ) { // Final is blank. This is really a deleted row.
267 $r .= $this->_deleted( array($orig_line), false );
268 } else { // A true changed row.
269 $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->addedLine( $final_line ) . "</tr>\n";
270 }
271 }
272
273 return $r;
274 }
275
276 /**
277 * Takes changed blocks and matches which rows in orig turned into which rows in final.
278 *
279 * Returns
280 * *_matches ( which rows match with which )
281 * *_rows ( order of rows in each column interleaved with blank rows as
282 * necessary )
283 *
284 * @since 2.6.0
285 *
286 * @param unknown_type $orig
287 * @param unknown_type $final
288 * @return unknown
289 */
290 function interleave_changed_lines( $orig, $final ) {
291
292 // Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array.
293 $matches = array();
294 foreach ( array_keys($orig) as $o ) {
295 foreach ( array_keys($final) as $f ) {
296 $matches["$o,$f"] = $this->compute_string_distance( $orig[$o], $final[$f] );
297 }
298 }
299 asort($matches); // Order by string distance.
300
301 $orig_matches = array();
302 $final_matches = array();
303
304 foreach ( $matches as $keys => $difference ) {
305 list($o, $f) = explode(',', $keys);
306 $o = (int) $o;
307 $f = (int) $f;
308
309 // Already have better matches for these guys
310 if ( isset($orig_matches[$o]) && isset($final_matches[$f]) )
311 continue;
312
313 // First match for these guys. Must be best match
314 if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) {
315 $orig_matches[$o] = $f;
316 $final_matches[$f] = $o;
317 continue;
318 }
319
320 // Best match of this final is already taken? Must mean this final is a new row.
321 if ( isset($orig_matches[$o]) )
322 $final_matches[$f] = 'x';
323
324 // Best match of this orig is already taken? Must mean this orig is a deleted row.
325 elseif ( isset($final_matches[$f]) )
326 $orig_matches[$o] = 'x';
327 }
328
329 // We read the text in this order
330 ksort($orig_matches);
331 ksort($final_matches);
332
333
334 // Stores rows and blanks for each column.
335 $orig_rows = $orig_rows_copy = array_keys($orig_matches);
336 $final_rows = array_keys($final_matches);
337
338 // Interleaves rows with blanks to keep matches aligned.
339 // We may end up with some extraneous blank rows, but we'll just ignore them later.
340 foreach ( $orig_rows_copy as $orig_row ) {
341 $final_pos = array_search($orig_matches[$orig_row], $final_rows, true);
342 $orig_pos = (int) array_search($orig_row, $orig_rows, true);
343
344 if ( false === $final_pos ) { // This orig is paired with a blank final.
345 array_splice( $final_rows, $orig_pos, 0, -1 );
346 } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows.
347 $diff_pos = $final_pos - $orig_pos;
348 while ( $diff_pos < 0 )
349 array_splice( $final_rows, $orig_pos, 0, $diff_pos++ );
350 } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows.
351 $diff_pos = $orig_pos - $final_pos;
352 while ( $diff_pos < 0 )
353 array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ );
354 }
355 }
356
357
358 // Pad the ends with blank rows if the columns aren't the same length
359 $diff_count = count($orig_rows) - count($final_rows);
360 if ( $diff_count < 0 ) {
361 while ( $diff_count < 0 )
362 array_push($orig_rows, $diff_count++);
363 } elseif ( $diff_count > 0 ) {
364 $diff_count = -1 * $diff_count;
365 while ( $diff_count < 0 )
366 array_push($final_rows, $diff_count++);
367 }
368
369 return array($orig_matches, $final_matches, $orig_rows, $final_rows);
370
371/*
372 // Debug
373 echo "\n\n\n\n\n";
374
375 echo "-- DEBUG Matches: Orig -> Final --";
376
377 foreach ( $orig_matches as $o => $f ) {
378 echo "\n\n\n\n\n";
379 echo "ORIG: $o, FINAL: $f\n";
380 var_dump($orig[$o],$final[$f]);
381 }
382 echo "\n\n\n\n\n";
383
384 echo "-- DEBUG Matches: Final -> Orig --";
385
386 foreach ( $final_matches as $f => $o ) {
387 echo "\n\n\n\n\n";
388 echo "FINAL: $f, ORIG: $o\n";
389 var_dump($final[$f],$orig[$o]);
390 }
391 echo "\n\n\n\n\n";
392
393 echo "-- DEBUG Rows: Orig -- Final --";
394
395 echo "\n\n\n\n\n";
396 foreach ( $orig_rows as $row => $o ) {
397 if ( $o < 0 )
398 $o = 'X';
399 $f = $final_rows[$row];
400 if ( $f < 0 )
401 $f = 'X';
402 echo "$o -- $f\n";//Cross Site Scripting
403 }
404 echo "\n\n\n\n\n";
405
406 echo "-- END DEBUG --";
407
408 echo "\n\n\n\n\n";
409
410 return array($orig_matches, $final_matches, $orig_rows, $final_rows);
411*/
412 }
413
414 /**
415 * Computes a number that is intended to reflect the "distance" between two strings.
416 *
417 * @since 2.6.0
418 *
419 * @param string $string1
420 * @param string $string2
421 * @return int
422 */
423 function compute_string_distance( $string1, $string2 ) {
424 // Vectors containing character frequency for all chars in each string
425 $chars1 = count_chars($string1);
426 $chars2 = count_chars($string2);
427
428 // L1-norm of difference vector.
429 $difference = array_sum( array_map( array(&$this, 'difference'), $chars1, $chars2 ) );
430
431 // $string1 has zero length? Odd. Give huge penalty by not dividing.
432 if ( !$string1 )
433 return $difference;
434
435 // Return distance per charcter (of string1)
436 return $difference / strlen($string1);
437 }
438
439 /**
440 * @ignore
441 * @since 2.6.0
442 *
443 * @param int $a
444 * @param int $b
445 * @return int
446 */
447 function difference( $a, $b ) {
448 return abs( $a - $b );
449 }
450
451}
452
453/**
454 * Better word splitting than the PEAR package provides.
455 *
456 * @since 2.6.0
457 * @uses Text_Diff_Renderer_inline Extends
458 */
459class WP_Text_Diff_Renderer_inline extends Text_Diff_Renderer_inline {
460
461 /**
462 * @ignore
463 * @since 2.6.0
464 *
465 * @param string $string
466 * @param string $newlineEscape
467 * @return string
468 */
469 function _splitOnWords($string, $newlineEscape = "\n") {
470 $string = str_replace("\0", '', $string);
471 $words = preg_split( '/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
472 $words = str_replace( "\n", $newlineEscape, $words );
473 return $words;
474 }
475
476}
477
478?>
479
/var/www/wordpress/index.php
/var/www/wordpress/wp-activate.php
/var/www/wordpress/wp-app.php
/var/www/wordpress/wp-atom.php
/var/www/wordpress/wp-blog-header.php
/var/www/wordpress/wp-comments-post.php
/var/www/wordpress/wp-commentsrss2.php
/var/www/wordpress/wp-config-sample.php
/var/www/wordpress/wp-cron.php
/var/www/wordpress/wp-feed.php
/var/www/wordpress/wp-links-opml.php
/var/www/wordpress/wp-load.php
/var/www/wordpress/wp-login.php
/var/www/wordpress/wp-mail.php
/var/www/wordpress/wp-pass.php
/var/www/wordpress/wp-rdf.php
/var/www/wordpress/wp-register.php
/var/www/wordpress/wp-rss.php
/var/www/wordpress/wp-rss2.php
/var/www/wordpress/wp-settings.php
/var/www/wordpress/wp-signup.php
/var/www/wordpress/wp-trackback.php
/var/www/wordpress/xmlrpc.php