r32866 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32865‎ | r32866 | r32867 >
Date:18:16, 6 April 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Small cleanups
Modified paths:
  • /trunk/phase3/includes/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DifferenceEngine.php
@@ -40,7 +40,7 @@
4141 * @param $rcid Integer: ??? FIXME (default 0)
4242 * @param $refreshCache boolean If set, refreshes the diff cache
4343 */
44 - function DifferenceEngine( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false ) {
 44+ function __construct( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false ) {
4545 $this->mTitle = $titleObj;
4646 wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n");
4747
@@ -74,8 +74,7 @@
7575
7676 function showDiffPage( $diffOnly = false ) {
7777 global $wgUser, $wgOut, $wgUseExternalEditor, $wgUseRCPatrol;
78 - $fname = 'DifferenceEngine::showDiffPage';
79 - wfProfileIn( $fname );
 78+ wfProfileIn( __METHOD__ );
8079
8180 # If external diffs are enabled both globally and for the user,
8281 # we'll use the application/x-external-editor interface to call
@@ -111,7 +110,7 @@
112111 $t = $this->mTitle->getPrefixedText() . " (Diff: {$this->mOldid}, {$this->mNewid})";
113112 $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
114113 $wgOut->addWikiMsg( 'missingarticle', "<nowiki>$t</nowiki>" );
115 - wfProfileOut( $fname );
 114+ wfProfileOut( __METHOD__ );
116115 return;
117116 }
118117
@@ -127,7 +126,7 @@
128127 if ( $this->mOldid === false ) {
129128 $this->showFirstRevision();
130129 $this->renderNewRevision(); // should we respect $diffOnly here or not?
131 - wfProfileOut( $fname );
 130+ wfProfileOut( __METHOD__ );
132131 return;
133132 }
134133
@@ -146,7 +145,7 @@
147146 if ( !( $this->mOldPage->userCanRead() && $this->mNewPage->userCanRead() ) ) {
148147 $wgOut->loginToUse();
149148 $wgOut->output();
150 - wfProfileOut( $fname );
 149+ wfProfileOut( __METHOD__ );
151150 exit;
152151 }
153152
@@ -211,13 +210,11 @@
212211 $newminor = '';
213212
214213 if ($this->mOldRev->mMinorEdit == 1) {
215 - $oldminor = wfElement( 'span', array( 'class' => 'minor' ),
216 - wfMsg( 'minoreditletter') ) . ' ';
 214+ $oldminor = Xml::span( wfMsg( 'minoreditletter'), 'minor' ) . ' ';
217215 }
218216
219217 if ($this->mNewRev->mMinorEdit == 1) {
220 - $newminor = wfElement( 'span', array( 'class' => 'minor' ),
221 - wfMsg( 'minoreditletter') ) . ' ';
 218+ $newminor = Xml::span( wfMsg( 'minoreditletter'), 'minor' ) . ' ';
222219 }
223220
224221 $rdel = ''; $ldel = '';
@@ -225,7 +222,7 @@
226223 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
227224 if( !$this->mOldRev->userCan( Revision::DELETED_RESTRICTED ) ) {
228225 // If revision was hidden from sysops
229 - $ldel = wfMsgHtml('rev-delundel');
 226+ $ldel = wfMsgHtml('rev-delundel');
230227 } else {
231228 $ldel = $sk->makeKnownLinkObj( $revdel,
232229 wfMsgHtml('rev-delundel'),
@@ -269,7 +266,7 @@
270267 if ( !$diffOnly )
271268 $this->renderNewRevision();
272269
273 - wfProfileOut( $fname );
 270+ wfProfileOut( __METHOD__ );
274271 }
275272
276273 /**
@@ -277,8 +274,7 @@
278275 */
279276 function renderNewRevision() {
280277 global $wgOut;
281 - $fname = 'DifferenceEngine::renderNewRevision';
282 - wfProfileIn( $fname );
 278+ wfProfileIn( __METHOD__ );
283279
284280 $wgOut->addHTML( "<hr /><h2>{$this->mPagetitle}</h2>\n" );
285281 #add deleted rev tag if needed
@@ -316,7 +312,7 @@
317313 $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
318314 }
319315
320 - wfProfileOut( $fname );
 316+ wfProfileOut( __METHOD__ );
321317 }
322318
323319 /**
@@ -325,10 +321,8 @@
326322 */
327323 function showFirstRevision() {
328324 global $wgOut, $wgUser;
 325+ wfProfileIn( __METHOD__ );
329326
330 - $fname = 'DifferenceEngine::showFirstRevision';
331 - wfProfileIn( $fname );
332 -
333327 # Get article text from the DB
334328 #
335329 if ( ! $this->loadNewText() ) {
@@ -336,7 +330,7 @@
337331 "{$this->mNewid})";
338332 $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
339333 $wgOut->addWikiMsg( 'missingarticle', "<nowiki>$t</nowiki>" );
340 - wfProfileOut( $fname );
 334+ wfProfileOut( __METHOD__ );
341335 return;
342336 }
343337 if ( $this->mNewRev->isCurrent() ) {
@@ -348,7 +342,7 @@
349343 if ( !( $this->mTitle->userCanRead() ) ) {
350344 $wgOut->loginToUse();
351345 $wgOut->output();
352 - wfProfileOut( $fname );
 346+ wfProfileOut( __METHOD__ );
353347 exit;
354348 }
355349
@@ -367,7 +361,7 @@
368362 $wgOut->setSubtitle( wfMsg( 'difference' ) );
369363 $wgOut->setRobotpolicy( 'noindex,nofollow' );
370364
371 - wfProfileOut( $fname );
 365+ wfProfileOut( __METHOD__ );
372366 }
373367
374368 /**
@@ -422,8 +416,7 @@
423417 */
424418 function getDiffBody() {
425419 global $wgMemc;
426 - $fname = 'DifferenceEngine::getDiffBody';
427 - wfProfileIn( $fname );
 420+ wfProfileIn( __METHOD__ );
428421 // Check if the diff should be hidden from this user
429422 if ( $this->mOldRev && !$this->mOldRev->userCan(Revision::DELETED_TEXT) ) {
430423 return '';
@@ -441,7 +434,7 @@
442435 wfIncrStats( 'diff_cache_hit' );
443436 $difftext = $this->localiseLineNumbers( $difftext );
444437 $difftext .= "\n<!-- diff cache key $key -->\n";
445 - wfProfileOut( $fname );
 438+ wfProfileOut( __METHOD__ );
446439 return $difftext;
447440 }
448441 } // don't try to load but save the result
@@ -449,7 +442,7 @@
450443
451444 // Loadtext is permission safe, this just clears out the diff
452445 if ( !$this->loadText() ) {
453 - wfProfileOut( $fname );
 446+ wfProfileOut( __METHOD__ );
454447 return false;
455448 }
456449
@@ -466,7 +459,7 @@
467460 if ( $difftext !== false ) {
468461 $difftext = $this->localiseLineNumbers( $difftext );
469462 }
470 - wfProfileOut( $fname );
 463+ wfProfileOut( __METHOD__ );
471464 return $difftext;
472465 }
473466
@@ -476,7 +469,6 @@
477470 */
478471 function generateDiffBody( $otext, $ntext ) {
479472 global $wgExternalDiffEngine, $wgContLang;
480 - $fname = 'DifferenceEngine::generateDiffBody';
481473
482474 $otext = str_replace( "\r\n", "\n", $otext );
483475 $ntext = str_replace( "\r\n", "\n", $ntext );
@@ -496,9 +488,9 @@
497489 # Better external diff engine, the 2 may some day be dropped
498490 # This one does the escaping and segmenting itself
499491 if ( !function_exists( 'wikidiff2_do_diff' ) ) {
500 - wfProfileIn( "$fname-dl" );
 492+ wfProfileIn( __METHOD__ . "-dl" );
501493 @dl('php_wikidiff2.so');
502 - wfProfileOut( "$fname-dl" );
 494+ wfProfileOut( __METHOD__ . "-dl" );
503495 }
504496 if ( function_exists( 'wikidiff2_do_diff' ) ) {
505497 wfProfileIn( 'wikidiff2_do_diff' );
@@ -515,12 +507,12 @@
516508
517509 $tempFile1 = fopen( $tempName1, "w" );
518510 if ( !$tempFile1 ) {
519 - wfProfileOut( $fname );
 511+ wfProfileOut( __METHOD__ );
520512 return false;
521513 }
522514 $tempFile2 = fopen( $tempName2, "w" );
523515 if ( !$tempFile2 ) {
524 - wfProfileOut( $fname );
 516+ wfProfileOut( __METHOD__ );
525517 return false;
526518 }
527519 fwrite( $tempFile1, $otext );
@@ -528,9 +520,9 @@
529521 fclose( $tempFile1 );
530522 fclose( $tempFile2 );
531523 $cmd = wfEscapeShellArg( $wgExternalDiffEngine, $tempName1, $tempName2 );
532 - wfProfileIn( "$fname-shellexec" );
 524+ wfProfileIn( __METHOD__ . "-shellexec" );
533525 $difftext = wfShellExec( $cmd );
534 - wfProfileOut( "$fname-shellexec" );
 526+ wfProfileOut( __METHOD__ . "-shellexec" );
535527 unlink( $tempName1 );
536528 unlink( $tempName2 );
537529 return $difftext;
@@ -894,13 +886,11 @@
895887 * @private
896888 * @addtogroup DifferenceEngine
897889 */
898 -class _DiffEngine
899 -{
 890+class _DiffEngine {
900891 const MAX_XREF_LENGTH = 10000;
901892
902893 function diff ($from_lines, $to_lines) {
903 - $fname = '_DiffEngine::diff';
904 - wfProfileIn( $fname );
 894+ wfProfileIn( __METHOD__ );
905895
906896 $n_from = sizeof($from_lines);
907897 $n_to = sizeof($to_lines);
@@ -987,7 +977,7 @@
988978 elseif ($add)
989979 $edits[] = new _DiffOp_Add($add);
990980 }
991 - wfProfileOut( $fname );
 981+ wfProfileOut( __METHOD__ );
992982 return $edits;
993983 }
994984
@@ -1020,8 +1010,7 @@
10211011 * of the portions it is going to specify.
10221012 */
10231013 function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) {
1024 - $fname = '_DiffEngine::_diag';
1025 - wfProfileIn( $fname );
 1014+ wfProfileIn( __METHOD__ );
10261015 $flip = false;
10271016
10281017 if ($xlim - $xoff > $ylim - $yoff) {
@@ -1047,7 +1036,7 @@
10481037 $numer = $xlim - $xoff + $nchunks - 1;
10491038 $x = $xoff;
10501039 for ($chunk = 0; $chunk < $nchunks; $chunk++) {
1051 - wfProfileIn( "$fname-chunk" );
 1040+ wfProfileIn( __METHOD__ . "-chunk" );
10521041 if ($chunk > 0)
10531042 for ($i = 0; $i <= $this->lcs; $i++)
10541043 $ymids[$i][$chunk-1] = $this->seq[$i];
@@ -1081,7 +1070,7 @@
10821071 }
10831072 }
10841073 }
1085 - wfProfileOut( "$fname-chunk" );
 1074+ wfProfileOut( __METHOD__ . "-chunk" );
10861075 }
10871076
10881077 $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
@@ -1093,19 +1082,18 @@
10941083 }
10951084 $seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim);
10961085
1097 - wfProfileOut( $fname );
 1086+ wfProfileOut( __METHOD__ );
10981087 return array($this->lcs, $seps);
10991088 }
11001089
11011090 function _lcs_pos ($ypos) {
1102 - $fname = '_DiffEngine::_lcs_pos';
1103 - wfProfileIn( $fname );
 1091+ wfProfileIn( __METHOD__ );
11041092
11051093 $end = $this->lcs;
11061094 if ($end == 0 || $ypos > $this->seq[$end]) {
11071095 $this->seq[++$this->lcs] = $ypos;
11081096 $this->in_seq[$ypos] = 1;
1109 - wfProfileOut( $fname );
 1097+ wfProfileOut( __METHOD__ );
11101098 return $this->lcs;
11111099 }
11121100
@@ -1123,7 +1111,7 @@
11241112 $this->in_seq[$this->seq[$end]] = false;
11251113 $this->seq[$end] = $ypos;
11261114 $this->in_seq[$ypos] = 1;
1127 - wfProfileOut( $fname );
 1115+ wfProfileOut( __METHOD__ );
11281116 return $end;
11291117 }
11301118
@@ -1139,8 +1127,7 @@
11401128 * All line numbers are origin-0 and discarded lines are not counted.
11411129 */
11421130 function _compareseq ($xoff, $xlim, $yoff, $ylim) {
1143 - $fname = '_DiffEngine::_compareseq';
1144 - wfProfileIn( $fname );
 1131+ wfProfileIn( __METHOD__ );
11451132
11461133 // Slide down the bottom initial diagonal.
11471134 while ($xoff < $xlim && $yoff < $ylim
@@ -1183,7 +1170,7 @@
11841171 $pt1 = $pt2;
11851172 }
11861173 }
1187 - wfProfileOut( $fname );
 1174+ wfProfileOut( __METHOD__ );
11881175 }
11891176
11901177 /* Adjust inserts/deletes of identical lines to join changes
@@ -1199,8 +1186,7 @@
12001187 * This is extracted verbatim from analyze.c (GNU diffutils-2.7).
12011188 */
12021189 function _shift_boundaries ($lines, &$changed, $other_changed) {
1203 - $fname = '_DiffEngine::_shift_boundaries';
1204 - wfProfileIn( $fname );
 1190+ wfProfileIn( __METHOD__ );
12051191 $i = 0;
12061192 $j = 0;
12071193
@@ -1305,7 +1291,7 @@
13061292 USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
13071293 }
13081294 }
1309 - wfProfileOut( $fname );
 1295+ wfProfileOut( __METHOD__ );
13101296 }
13111297 }
13121298
@@ -1423,8 +1409,7 @@
14241410 * This is here only for debugging purposes.
14251411 */
14261412 function _check ($from_lines, $to_lines) {
1427 - $fname = 'Diff::_check';
1428 - wfProfileIn( $fname );
 1413+ wfProfileIn( __METHOD__ );
14291414 if (serialize($from_lines) != serialize($this->orig()))
14301415 trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
14311416 if (serialize($to_lines) != serialize($this->closing()))
@@ -1446,7 +1431,7 @@
14471432
14481433 $lcs = $this->lcs();
14491434 trigger_error('Diff okay: LCS = '.$lcs, E_USER_NOTICE);
1450 - wfProfileOut( $fname );
 1435+ wfProfileOut( __METHOD__ );
14511436 }
14521437 }
14531438
@@ -1481,9 +1466,8 @@
14821467 * have the same number of elements as $to_lines.
14831468 */
14841469 function MappedDiff($from_lines, $to_lines,
1485 - $mapped_from_lines, $mapped_to_lines) {
1486 - $fname = 'MappedDiff::MappedDiff';
1487 - wfProfileIn( $fname );
 1470+ $mapped_from_lines, $mapped_to_lines) {
 1471+ wfProfileIn( __METHOD__ );
14881472
14891473 assert(sizeof($from_lines) == sizeof($mapped_from_lines));
14901474 assert(sizeof($to_lines) == sizeof($mapped_to_lines));
@@ -1504,7 +1488,7 @@
15051489 $yi += sizeof($closing);
15061490 }
15071491 }
1508 - wfProfileOut( $fname );
 1492+ wfProfileOut( __METHOD__ );
15091493 }
15101494 }
15111495
@@ -1518,8 +1502,7 @@
15191503 * @private
15201504 * @addtogroup DifferenceEngine
15211505 */
1522 -class DiffFormatter
1523 -{
 1506+class DiffFormatter {
15241507 /**
15251508 * Number of leading context "lines" to preserve.
15261509 *
@@ -1543,8 +1526,7 @@
15441527 * @return string The formatted output.
15451528 */
15461529 function format($diff) {
1547 - $fname = 'DiffFormatter::format';
1548 - wfProfileIn( $fname );
 1530+ wfProfileIn( __METHOD__ );
15491531
15501532 $xi = $yi = 1;
15511533 $block = false;
@@ -1598,13 +1580,12 @@
15991581 $block);
16001582
16011583 $end = $this->_end_diff();
1602 - wfProfileOut( $fname );
 1584+ wfProfileOut( __METHOD__ );
16031585 return $end;
16041586 }
16051587
16061588 function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) {
1607 - $fname = 'DiffFormatter::_block';
1608 - wfProfileIn( $fname );
 1589+ wfProfileIn( __METHOD__ );
16091590 $this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen));
16101591 foreach ($edits as $edit) {
16111592 if ($edit->type == 'copy')
@@ -1619,7 +1600,7 @@
16201601 trigger_error('Unknown edit type', E_USER_ERROR);
16211602 }
16221603 $this->_end_block();
1623 - wfProfileOut( $fname );
 1604+ wfProfileOut( __METHOD__ );
16241605 }
16251606
16261607 function _start_diff() {
@@ -1676,8 +1657,7 @@
16771658 * @addtogroup DifferenceEngine
16781659 */
16791660
1680 -class UnifiedDiffFormatter extends DiffFormatter
1681 -{
 1661+class UnifiedDiffFormatter extends DiffFormatter {
16821662 var $leading_context_lines = 2;
16831663 var $trailing_context_lines = 2;
16841664
@@ -1700,19 +1680,15 @@
17011681 * A pseudo-formatter that just passes along the Diff::$edits array
17021682 * @addtogroup DifferenceEngine
17031683 */
1704 -class ArrayDiffFormatter extends DiffFormatter
1705 -{
1706 - function format($diff)
1707 - {
 1684+class ArrayDiffFormatter extends DiffFormatter {
 1685+ function format($diff) {
17081686 $oldline = 1;
17091687 $newline = 1;
17101688 $retval = array();
17111689 foreach($diff->edits as $edit)
1712 - switch($edit->type)
1713 - {
 1690+ switch($edit->type) {
17141691 case 'add':
1715 - foreach($edit->closing as $l)
1716 - {
 1692+ foreach($edit->closing as $l) {
17171693 $retval[] = array(
17181694 'action' => 'add',
17191695 'new'=> $l,
@@ -1721,8 +1697,7 @@
17221698 }
17231699 break;
17241700 case 'delete':
1725 - foreach($edit->orig as $l)
1726 - {
 1701+ foreach($edit->orig as $l) {
17271702 $retval[] = array(
17281703 'action' => 'delete',
17291704 'old' => $l,
@@ -1731,8 +1706,7 @@
17321707 }
17331708 break;
17341709 case 'change':
1735 - foreach($edit->orig as $i => $l)
1736 - {
 1710+ foreach($edit->orig as $i => $l) {
17371711 $retval[] = array(
17381712 'action' => 'change',
17391713 'old' => $l,
@@ -1747,7 +1721,7 @@
17481722 $newline += count($edit->orig);
17491723 }
17501724 return $retval;
1751 - }
 1725+ }
17521726 }
17531727
17541728 /**
@@ -1755,7 +1729,7 @@
17561730 *
17571731 */
17581732
1759 -define('NBSP', '&#160;'); // iso-8859-x non-breaking space.
 1733+define('NBSP', '&#160;'); // iso-8859-x non-breaking space.
17601734
17611735 /**
17621736 * @todo document
@@ -1823,25 +1797,22 @@
18241798 * @private
18251799 * @addtogroup DifferenceEngine
18261800 */
1827 -class WordLevelDiff extends MappedDiff
1828 -{
 1801+class WordLevelDiff extends MappedDiff {
18291802 const MAX_LINE_LENGTH = 10000;
18301803
18311804 function WordLevelDiff ($orig_lines, $closing_lines) {
1832 - $fname = 'WordLevelDiff::WordLevelDiff';
1833 - wfProfileIn( $fname );
 1805+ wfProfileIn( __METHOD__ );
18341806
18351807 list ($orig_words, $orig_stripped) = $this->_split($orig_lines);
18361808 list ($closing_words, $closing_stripped) = $this->_split($closing_lines);
18371809
18381810 $this->MappedDiff($orig_words, $closing_words,
1839 - $orig_stripped, $closing_stripped);
1840 - wfProfileOut( $fname );
 1811+ $orig_stripped, $closing_stripped);
 1812+ wfProfileOut( __METHOD__ );
18411813 }
18421814
18431815 function _split($lines) {
1844 - $fname = 'WordLevelDiff::_split';
1845 - wfProfileIn( $fname );
 1816+ wfProfileIn( __METHOD__ );
18461817
18471818 $words = array();
18481819 $stripped = array();
@@ -1868,13 +1839,12 @@
18691840 }
18701841 }
18711842 }
1872 - wfProfileOut( $fname );
 1843+ wfProfileOut( __METHOD__ );
18731844 return array($words, $stripped);
18741845 }
18751846
18761847 function orig () {
1877 - $fname = 'WordLevelDiff::orig';
1878 - wfProfileIn( $fname );
 1848+ wfProfileIn( __METHOD__ );
18791849 $orig = new _HWLDF_WordAccumulator;
18801850
18811851 foreach ($this->edits as $edit) {
@@ -1884,13 +1854,12 @@
18851855 $orig->addWords($edit->orig, 'del');
18861856 }
18871857 $lines = $orig->getLines();
1888 - wfProfileOut( $fname );
 1858+ wfProfileOut( __METHOD__ );
18891859 return $lines;
18901860 }
18911861
18921862 function closing () {
1893 - $fname = 'WordLevelDiff::closing';
1894 - wfProfileIn( $fname );
 1863+ wfProfileIn( __METHOD__ );
18951864 $closing = new _HWLDF_WordAccumulator;
18961865
18971866 foreach ($this->edits as $edit) {
@@ -1900,19 +1869,18 @@
19011870 $closing->addWords($edit->closing, 'ins');
19021871 }
19031872 $lines = $closing->getLines();
1904 - wfProfileOut( $fname );
 1873+ wfProfileOut( __METHOD__ );
19051874 return $lines;
19061875 }
19071876 }
19081877
19091878 /**
1910 - * Wikipedia Table style diff formatter.
 1879+ * Wikipedia Table style diff formatter.
19111880 * @todo document
19121881 * @private
19131882 * @addtogroup DifferenceEngine
19141883 */
1915 -class TableDiffFormatter extends DiffFormatter
1916 -{
 1884+class TableDiffFormatter extends DiffFormatter {
19171885 function TableDiffFormatter() {
19181886 $this->leading_context_lines = 2;
19191887 $this->trailing_context_lines = 2;
@@ -1993,8 +1961,7 @@
19941962 }
19951963
19961964 function _changed( $orig, $closing ) {
1997 - $fname = 'TableDiffFormatter::_changed';
1998 - wfProfileIn( $fname );
 1965+ wfProfileIn( __METHOD__ );
19991966
20001967 $diff = new WordLevelDiff( $orig, $closing );
20011968 $del = $diff->orig();
@@ -2012,7 +1979,7 @@
20131980 echo '<tr>' . $this->emptyLine() .
20141981 $this->addedLine( $line ) . "</tr>\n";
20151982 }
2016 - wfProfileOut( $fname );
 1983+ wfProfileOut( __METHOD__ );
20171984 }
20181985 }
20191986

Status & tagging log