+
+/**
+ * Makes change an option link which carries all the other options
+ */
+function makeOptionsLink( $title, $override, $options ) {
+ global $wgUser, $wgLang, $wgContLang;
+ $sk = $wgUser->getSkin();
+ return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
+ $title, wfArrayToCGI( $override, $options ) );
+}
+
+/**
+ * Creates the options panel
+ */
+function rcOptionsPanel( $defaults, $nondefaults ) {
+ global $wgLang;
+
+ $options = $nondefaults + $defaults;
+
+ if( $options['from'] )
+ $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $options['limit'] ), $wgLang->timeanddate( $options['from'], true ) );
+ else
+ $note = wfMsg( 'rcnote', $wgLang->formatNum( $options['limit'] ), $wgLang->formatNum( $options['days'] ) );
+
+ // limit links
+ $cl = '';
+ $options_limit = array(50, 100, 250, 500);
+ $i = 0;
+ while ( $i+1 < count($options_limit) ) {
+ $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) . ' | ' ;
+ $i++;
+ }
+ $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) ;
+
+ // day links, reset 'from' to none
+ $dl = '';
+ $options_days = array(1, 3, 7, 14, 30);
+ $i = 0;
+ while ( $i+1 < count($options_days) ) {
+ $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) . ' | ' ;
+ $i++;
+ }
+ $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) ;
+
+ // show/hide links
+ $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
+ $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
+ array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
+ $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
+ array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
+ $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
+ array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
+ $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
+ array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
+
+ $hl = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
+
+ // show from this onward link
+ $now = $wgLang->timeanddate( wfTimestampNow(), true );
+ $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
+
+ $rclinks = wfMsg( 'rclinks', $cl, $dl, $hl );
+ $rclistfrom = wfMsg( 'rclistfrom', $tl );
+ return "$note<br />$rclinks<br />$rclistfrom";
+
+}
+
+/**<F2>
+ * Creates the choose namespace selection
+ *
+ * @access private
+ *
+ * @param mixed $namespace The key of the currently selected namespace, empty string
+ * if there is none
+ * @param bool $invert Whether to invert the namespace selection
+ * @param array $nondefaults An array of non default options to be remembered
+ *
+ * @return string
+ */
+function rcNamespaceForm ( $namespace, $invert, $nondefaults ) {
+ global $wgContLang, $wgScript;
+ $t = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
+
+ $namespaceselect = "<select name='namespace' id='nsselectbox'>";
+ $namespaceselect .= '<option value="" ' . ($namespace === '' ? ' selected="selected"' : '') . '>' . wfMsg( 'contributionsall' ) . '</option>';
+ $arr = $wgContLang->getFormattedNamespaces();
+ foreach ( $arr as $ns => $name ) {
+ if( $ns < NS_MAIN )
+ continue;
+ $n = $ns === NS_MAIN ? wfMsg ( 'blanknamespace' ) : $name;
+ $sel = $namespace === (string) $ns ? ' selected="selected"' : '';
+ $namespaceselect .= "<option value='$ns'$sel>$n</option>";
+ }
+ $namespaceselect .= '</select>';
+
+ $out = '';
+ $out .= "<div class='namespaceselector'><form method='get' action='{$wgScript}'>\n";
+ foreach ( $nondefaults as $key => $value ) {
+ if ($key != 'namespace' && $key != 'invert')
+ $out .= "<input type='hidden' name='$key' value='$value' />";
+ }
+
+ $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
+ $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
+
+
+ $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
+ $out .= "
+<div id='nsselect' class='recentchanges'>
+ <label for='nsselectbox'>" . wfMsg('namespace') . "</label>
+ $namespaceselect $submitbutton $invertbox <label for='nsinvert'>" . wfMsg('invert') . "</label>
+</div>";
+ $out .= '</form></div>';
+ return $out;
+}
+
+
+/**
+ * Format a diff for the newsfeed
+ */
+function rcFormatDiff( $row ) {
+ $fname = 'rcFormatDiff';
+ wfProfileIn( $fname );
+
+ require_once( 'DifferenceEngine.php' );
+ $comment = "<p>" . htmlspecialchars( $row->rc_comment ) . "</p>\n";
+
+ if( $row->rc_namespace >= 0 ) {
+ global $wgContLang;
+
+ #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id );
+ #$diff->showDiffPage();
+
+ $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
+ $dbr =& wfGetDB( DB_SLAVE );
+ $newrev =& Revision::newFromTitle( $titleObj, $row->rc_this_oldid );
+ if( $newrev ) {
+ $newtext = $newrev->getText();
+ } else {
+ $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
+ wfProfileOut( $fname );
+ return $comment . $diffText;
+ }
+
+ if( $row->rc_last_oldid ) {
+ wfProfileIn( "$fname-dodiff" );
+ $oldrev =& Revision::newFromId( $row->rc_last_oldid );
+ if( !$oldrev ) {
+ $diffText = "<p>Can't load old revision $row->rc_last_oldid</p>";
+ wfProfileOut( $fname );
+ return $comment . $diffText;
+ }
+ $oldtext = $oldrev->getText();
+
+ # Old entries may contain illegal characters
+ # which will damage output
+ $oldtext = UtfNormal::cleanUp( $oldtext );
+
+ global $wgFeedDiffCutoff;
+ if( strlen( $newtext ) > $wgFeedDiffCutoff ||
+ strlen( $oldtext ) > $wgFeedDiffCutoff ) {
+ $diffLink = $titleObj->escapeFullUrl(
+ 'diff=' . $row->rc_this_oldid .
+ '&oldid=' . $row->rc_last_oldid );
+ $diffText = '<a href="' .
+ $diffLink .
+ '">' .
+ htmlspecialchars( wfMsgForContent( 'difference' ) ) .
+ '</a>';
+ } else {
+ $diffText = DifferenceEngine::getDiff( $oldtext, $newtext,
+ wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
+ wfMsg( 'currentrev' ) );
+ }
+ wfProfileOut( "$fname-dodiff" );
+ } else {
+ $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
+ '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
+ }
+
+ wfProfileOut( $fname );
+ return $comment . $diffText;
+ }
+
+ wfProfileOut( $fname );
+ return $comment;
+}
+
+
+/**
+ * Appends to second array if $value differs from that in $default
+ */
+function appendToArrayIfNotDefault( $key, $value, $default, &$changed )