if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'archive', '*',
- array( 'ar_rev_id' => $id ),
+ [ 'ar_rev_id' => $id ],
__METHOD__ );
if ( $row ) {
$rev = Revision::newFromArchiveRow( $row );
$title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
- return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( array(
+ return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( [
'target' => $title->getPrefixedText(),
'timestamp' => $rev->getTimestamp()
- ) );
+ ] );
}
}
private function showMissingRevision() {
$out = $this->getOutput();
- $missing = array();
+ $missing = [];
if ( $this->mOldRev === null ||
( $this->mOldRev && $this->mOldContent === null )
) {
->params( $this->getLanguage()->listToText( $missing ) )
->numParams( count( $missing ) )
->parseAsBlock();
- $out->addHtml( $msg );
+ $out->addHTML( $msg );
}
public function showDiffPage( $diffOnly = false ) {
$rollback = '';
- $query = array();
+ $query = [];
# Carry over 'diffonly' param via navigation links
if ( $diffOnly != $user->getBoolOption( 'diffonly' ) ) {
$query['diffonly'] = $diffOnly;
$deleted = $suppressed = false;
$allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT, $user );
- $revisionTools = array();
+ $revisionTools = [];
# mOldRev is false if the difference engine is called with a "vague" query for
# a diff between a version V and its previous version V' AND the version V
$samePage = true;
$oldHeader = '';
} else {
- Hooks::run( 'DiffViewHeader', array( $this, $this->mOldRev, $this->mNewRev ) );
+ Hooks::run( 'DiffViewHeader', [ $this, $this->mOldRev, $this->mNewRev ] );
if ( $this->mNewPage->equals( $this->mOldPage ) ) {
$out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) &&
!$this->mNewRev->isDeleted( Revision::DELETED_TEXT )
) {
- $undoLink = Html::element( 'a', array(
- 'href' => $this->mNewPage->getLocalURL( array(
+ $undoLink = Html::element( 'a', [
+ 'href' => $this->mNewPage->getLocalURL( [
'action' => 'edit',
'undoafter' => $this->mOldid,
'undo' => $this->mNewid
- ) ),
+ ] ),
'title' => Linker::titleAttrib( 'undo' ),
- ),
+ ],
$this->msg( 'editundo' )->text()
);
$revisionTools['mw-diff-undo'] = $undoLink;
$prevlink = Linker::linkKnown(
$this->mOldPage,
$this->msg( 'previousdiff' )->escaped(),
- array( 'id' => 'differences-prevlink' ),
- array( 'diff' => 'prev', 'oldid' => $this->mOldid ) + $query
+ [ 'id' => 'differences-prevlink' ],
+ [ 'diff' => 'prev', 'oldid' => $this->mOldid ] + $query
);
} else {
$prevlink = ' ';
$nextlink = Linker::linkKnown(
$this->mNewPage,
$this->msg( 'nextdiff' )->escaped(),
- array( 'id' => 'differences-nextlink' ),
- array( 'diff' => 'next', 'oldid' => $this->mNewid ) + $query
+ [ 'id' => 'differences-nextlink' ],
+ [ 'diff' => 'next', 'oldid' => $this->mNewid ] + $query
);
} else {
$nextlink = ' ';
# Allow extensions to define their own revision tools
Hooks::run( 'DiffRevisionTools',
- array( $this->mNewRev, &$revisionTools, $this->mOldRev, $user ) );
- $formattedRevisionTools = array();
+ [ $this->mNewRev, &$revisionTools, $this->mOldRev, $user ] );
+ $formattedRevisionTools = [];
// Put each one in parentheses (poor man's button)
foreach ( $revisionTools as $key => $tool ) {
$toolClass = is_string( $key ) ? $key : 'mw-diff-tool';
$element = Html::rawElement(
'span',
- array( 'class' => $toolClass ),
+ [ 'class' => $toolClass ],
$this->msg( 'parentheses' )->rawParams( $tool )->escaped()
);
$formattedRevisionTools[] = $element;
$msg = $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff';
# Give explanation for why revision is not visible
$out->wrapWikiMsg( "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
- array( $msg ) );
+ [ $msg ] );
} else {
# Give explanation and add a link to view the diff...
$query = $this->getRequest()->appendQueryValue( 'unhide', '1' );
$msg = $suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff';
$out->wrapWikiMsg(
"<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
- array( $msg, $link )
+ [ $msg, $link ]
);
}
# Otherwise, output a regular diff...
$this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
$this->mNewPage,
$this->msg( 'markaspatrolleddiff' )->escaped(),
- array(),
- array(
+ [],
+ [
'action' => 'markpatrolled',
'rcid' => $linkInfo['rcid'],
'token' => $linkInfo['token'],
- )
+ ]
) . ']</span>';
}
}
// Look for an unpatrolled change corresponding to this diff
$db = wfGetDB( DB_SLAVE );
$change = RecentChange::newFromConds(
- array(
+ [
'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ),
'rc_this_oldid' => $this->mNewid,
'rc_patrolled' => 0
- ),
+ ],
__METHOD__
);
}
$token = $user->getEditToken( $rcid );
- return array(
+ return [
'rcid' => $rcid,
'token' => $token,
- );
+ ];
}
}
<h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
# Page content may be handled by a hooked call instead...
# @codingStandardsIgnoreStart Ignoring long lines.
- if ( Hooks::run( 'ArticleContentOnDiff', array( $this, $out ) ) ) {
+ if ( Hooks::run( 'ArticleContentOnDiff', [ $this, $out ] ) ) {
$this->loadNewText();
$out->setRevisionId( $this->mNewid );
$out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
// This needs to be synchronised with Article::showCssOrJsPage(), which sucks
// Give hooks a chance to customise the output
// @todo standardize this crap into one function
- if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+ if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
// NOTE: deprecated hook, B/C only
// use the content object's own rendering
$cnt = $this->mNewRev->getContent();
$out->addParserOutputContent( $po );
}
}
- } elseif ( !Hooks::run( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+ } elseif ( !Hooks::run( 'ArticleContentViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
// Handled by extension
- } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+ } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
// NOTE: deprecated hook, B/C only
// Handled by extension
} else {
}
// Short-circuit
if ( $this->mOldRev === false || ( $this->mOldRev && $this->mNewRev
- && $this->mOldRev->getID() == $this->mNewRev->getID() )
+ && $this->mOldRev->getId() == $this->mNewRev->getId() )
) {
return '';
}
$difftext = $this->generateContentDiffBody( $this->mOldContent, $this->mNewContent );
// Save to cache for 7 days
- if ( !Hooks::run( 'AbortDiffCache', array( &$this ) ) ) {
+ if ( !Hooks::run( 'AbortDiffCache', [ &$this ] ) ) {
wfIncrStats( 'diff_cache.uncacheable' );
} elseif ( $key !== false && $difftext !== false ) {
wfIncrStats( 'diff_cache.miss' );
* @return bool|string
*/
public function generateTextDiffBody( $otext, $ntext ) {
+ $time = microtime( true );
+
+ $result = $this->textDiff( $otext, $ntext );
+
+ $time = intval( ( microtime( true ) - $time ) * 1000 );
+ $this->getStats()->timing( 'diff_time', $time );
+ // Log requests slower than 99th percentile
+ if ( $time > 100 && $this->mOldPage && $this->mNewPage ) {
+ wfDebugLog( 'diff',
+ "$time ms diff: {$this->mOldid} -> {$this->mNewid} {$this->mNewPage}" );
+ }
+
+ return $result;
+ }
+
+ /**
+ * Generates diff, to be wrapped internally in a logging/instrumentation
+ *
+ * @param string $otext Old text, must be already segmented
+ * @param string $ntext New text, must be already segmented
+ * @return bool|string
+ */
+ protected function textDiff( $otext, $ntext ) {
global $wgExternalDiffEngine, $wgContLang;
$otext = str_replace( "\r\n", "\n", $otext );
$ntext = str_replace( "\r\n", "\n", $ntext );
- if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
- # For historical reasons, external diff engine expects
- # input text to be HTML-escaped already
- $otext = htmlspecialchars( $wgContLang->segmentForDiff( $otext ) );
- $ntext = htmlspecialchars( $wgContLang->segmentForDiff( $ntext ) );
-
- return $wgContLang->unsegmentForDiff( wikidiff_do_diff( $otext, $ntext, 2 ) ) .
- $this->debug( 'wikidiff1' );
+ if ( $wgExternalDiffEngine == 'wikidiff' ) {
+ wfDeprecated( 'wikidiff support', '1.27' );
+ $wgExternalDiffEngine = false;
}
- if ( $wgExternalDiffEngine == 'wikidiff2' && function_exists( 'wikidiff2_do_diff' ) ) {
- # Better external diff engine, the 2 may some day be dropped
- # This one does the escaping and segmenting itself
- $text = wikidiff2_do_diff( $otext, $ntext, 2 );
- $text .= $this->debug( 'wikidiff2' );
+ if ( $wgExternalDiffEngine == 'wikidiff2' ) {
+ if ( function_exists( 'wikidiff2_do_diff' ) ) {
+ # Better external diff engine, the 2 may some day be dropped
+ # This one does the escaping and segmenting itself
+ $text = wikidiff2_do_diff( $otext, $ntext, 2 );
+ $text .= $this->debug( 'wikidiff2' );
- return $text;
- }
- if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
+ return $text;
+ }
+ } elseif ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
# Diff via the shell
$tmpDir = wfTempDir();
$tempName1 = tempnam( $tmpDir, 'diff_' );
if ( !$this->enableDebugComment ) {
return '';
}
- $data = array( $generator );
+ $data = [ $generator ];
if ( $wgShowHostnames ) {
$data[] = wfHostname();
}
public function localiseLineNumbers( $text ) {
return preg_replace_callback(
'/<!--LINE (\d+)-->/',
- array( &$this, 'localiseLineNumbersCb' ),
+ [ &$this, 'localiseLineNumbersCb' ],
$text
);
}
$title = $rev->getTitle();
- $header = Linker::linkKnown( $title, $header, array(),
- array( 'oldid' => $rev->getID() ) );
+ $header = Linker::linkKnown( $title, $header, [],
+ [ 'oldid' => $rev->getId() ] );
if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
- $editQuery = array( 'action' => 'edit' );
+ $editQuery = [ 'action' => 'edit' ];
if ( !$rev->isCurrent() ) {
- $editQuery['oldid'] = $rev->getID();
+ $editQuery['oldid'] = $rev->getId();
}
$key = $title->quickUserCan( 'edit', $user ) ? 'editold' : 'viewsourceold';
$msg = $this->msg( $key )->escaped();
$editLink = $this->msg( 'parentheses' )->rawParams(
- Linker::linkKnown( $title, $msg, array(), $editQuery ) )->escaped();
+ Linker::linkKnown( $title, $msg, [], $editQuery ) )->escaped();
$header .= ' ' . Html::rawElement(
'span',
- array( 'class' => 'mw-diff-edit' ),
+ [ 'class' => 'mw-diff-edit' ],
$editLink
);
if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
$header = Html::rawElement(
'span',
- array( 'class' => 'history-deleted' ),
+ [ 'class' => 'history-deleted' ],
$header
);
}
} else {
- $header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header );
+ $header = Html::rawElement( 'span', [ 'class' => 'history-deleted' ], $header );
}
return $header;
public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
// shared.css sets diff in interface language/dir, but the actual content
// is often in a different language, mostly the page content language/dir
- $header = Html::openElement( 'table', array(
- 'class' => array( 'diff', 'diff-contentalign-' . $this->getDiffLang()->alignStart() ),
+ $header = Html::openElement( 'table', [
+ 'class' => [ 'diff', 'diff-contentalign-' . $this->getDiffLang()->alignStart() ],
'data-mw' => 'interface',
- ) );
+ ] );
$userLang = htmlspecialchars( $this->getLanguage()->getHtmlCode() );
if ( !$diff && !$otitle ) {
$newid = intval( $new );
}
- return array( $oldid, $newid );
+ return [ $oldid, $newid ];
}
/**
Hooks::run(
'NewDifferenceEngine',
- array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new )
+ [ $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ]
);
}
$this->mOldTags = $dbr->selectField(
'tag_summary',
'ts_tags',
- array( 'ts_rev_id' => $this->mOldid ),
+ [ 'ts_rev_id' => $this->mOldid ],
__METHOD__
);
} else {
$this->mNewTags = $dbr->selectField(
'tag_summary',
'ts_tags',
- array( 'ts_rev_id' => $this->mNewid ),
+ [ 'ts_rev_id' => $this->mNewid ],
__METHOD__
);