Fixed interwiki bug
[lhc/web/wiklou.git] / includes / SpecialWatchlist.php
index 8b9f7db..a8344da 100644 (file)
@@ -14,10 +14,10 @@ require_once( 'WatchedItem.php' );
 /**
  * constructor
  */
-function wfSpecialWatchlist() {
-       global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest;
+function wfSpecialWatchlist( $par ) {
+       global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest, $wgContLang;;
        global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
-       global $wgEnotif, $wgShowUpdatedMarker, $wgRCShowWatchingUsers;
+       global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
        $fname = 'wfSpecialWatchlist';
 
        $wgOut->setPagetitle( wfMsg( 'watchlist' ) );
@@ -27,8 +27,7 @@ function wfSpecialWatchlist() {
 
        $specialTitle = Title::makeTitle( NS_SPECIAL, 'Watchlist' );
 
-       $uid = $wgUser->getID();
-       if( $uid == 0 ) {
+       if( $wgUser->isAnon() ) {
                $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
                return;
        }
@@ -37,20 +36,21 @@ function wfSpecialWatchlist() {
        $days = $wgRequest->getVal( 'days' );
        $action = $wgRequest->getVal( 'action' );
        $remove = $wgRequest->getVal( 'remove' );
+       $hideOwn = $wgRequest->getBool( 'hideOwn' );    
        $id = $wgRequest->getArray( 'id' );
 
-       $wgOut->addWikiText( wfMsg( 'email_notification_infotext' ) );
-
-       if( $wgRequest->getVal( 'reset' ) == 'all' ) {
+       $uid = $wgUser->getID();
+       if( $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
                $wgUser->clearAllNotifications( $uid );
        }
 
+
        if(($action == 'submit') && isset($remove) && is_array($id)) {
                $wgOut->addWikiText( wfMsg( 'removingchecked' ) );
                $wgOut->addHTML( '<p>' );
                foreach($id as $one) {
                        $t = Title::newFromURL( $one );
-                       if($t->getDBkey() != '') {
+                       if( !is_null( $t ) ) {
                                $wl = WatchedItem::fromUserTitle( $wgUser, $t );
                                if( $wl->removeWatch() === false ) {
                                        $wgOut->addHTML( "<br />\n" . wfMsg( 'couldntremove', htmlspecialchars($one) ) );
@@ -87,10 +87,10 @@ function wfSpecialWatchlist() {
        $nitems = $s->n;
 
        if($nitems == 0) {
-        $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
-        return;
+               $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
+               return;
        }
-       
+
        if ( is_null( $days ) ) {
                $big = 1000;
                if($nitems > $big) {
@@ -106,7 +106,7 @@ function wfSpecialWatchlist() {
        if ( $days <= 0 ) {
                $docutoff = '';
                $cutoff = false;
-               $npages = wfMsg( 'all' );
+               $npages = wfMsg( 'watchlistall1' );
        } else {
                $docutoff = "AND rev_timestamp > '" .
                  ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
@@ -118,14 +118,13 @@ function wfSpecialWatchlist() {
 
        }
 
-       if(isset($_REQUEST['magic'])) {
+       if($wgRequest->getBool('edit') || $par == 'edit' ) {
                $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) .
-                       '<p>' . wfMsg( 'watcheditlist' ) . "</p>\n" );
+                       "\n\n" . wfMsg( 'watcheditlist' ) );
 
                $wgOut->addHTML( '<form action=\'' .
                        $specialTitle->escapeLocalUrl( 'action=submit' ) .
-                       "' method='post'>\n" .
-                       "<ul>\n" );
+                       "' method='post'>\n" );
 
 #              Patch A2
 #              The following was proposed by KTurner 07.11.2004 to T.Gries
@@ -134,21 +133,40 @@ function wfSpecialWatchlist() {
 
                $res = $dbr->query( $sql, $fname );
                $sk = $wgUser->getSkin();
+
+               $list = array();
                while( $s = $dbr->fetchObject( $res ) ) {
-                       $t = Title::makeTitle( $s->wl_namespace, $s->wl_title );
-                       if( is_null( $t ) ) {
-                               $wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title ) . '" in namespace ' . IntVal( $s->wl_namespace ) . " -->\n" );
-                       } else {
-                               $t = $t->getPrefixedText();
-                               $wgOut->addHTML( '<li><input type="checkbox" name="id[]" value="' . htmlspecialchars($t) . '" />' .
-                                       $sk->makeLink( $t, $t ) .
-                                       "</li>\n" );
+                       $list[$s->wl_namespace][] = $s->wl_title;
+               }
+               
+               // TODO: Display a t TOC
+               foreach($list as $ns => $titles) {
+                       if ($ns != NS_MAIN) 
+                               $wgOut->addHTML( '<h2>' . $wgContLang->getFormattedNsText( $ns ) . '</h2>' );
+                       $wgOut->addHTML( '<ul>' );
+                       foreach($titles as $title) {
+                               $t = Title::makeTitle( $ns, $title );
+                               if( is_null( $t ) ) {
+                                       $wgOut->addHTML(
+                                               '<!-- bad title "' .
+                                               htmlspecialchars( $s->wl_title ) . '" in namespace ' . $s->wl_namespace . " -->\n"
+                                       );
+                               } else {
+                                       $t = $t->getPrefixedText();
+                                       $wgOut->addHTML(
+                                               '<li><input type="checkbox" name="id[]" value="' . htmlspecialchars($t) . '" />' .
+                                               $sk->makeLink( $t, $t ) .
+                                               "</li>\n"
+                                       );
+                               }
                        }
+                       $wgOut->addHTML( '</ul>' );
                }
-               $wgOut->addHTML( "</ul>\n" .
+               $wgOut->addHTML(
                        "<input type='submit' name='remove' value=\"" .
                        htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
-                       "</form>\n" );
+                       "</form>\n"
+               );
 
                return;
        }
@@ -176,10 +194,30 @@ function wfSpecialWatchlist() {
                $z = 'wl_namespace=page_namespace';
        }
 
+       $andHideOwn = $hideOwn ? "AND (rev_user <> $uid)" : '';
+
+       # Show watchlist header
+       $header = '';
+       if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
+               $header .= wfMsg( 'wlheader-enotif' ) . "\n";
+       }
+       if ( $wgShowUpdatedMarker ) {
+               $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
+       }
 
-       $wgOut->addHTML( '<i>' . wfMsg( 'watchdetails',
-               $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
-               $specialTitle->escapeLocalUrl( 'magic=yes' ) ) . "</i><br />\n" );
+       $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ), 
+               $wgLang->formatNum( $npages ), $y,
+               $specialTitle->getFullUrl( 'edit=yes' ) );
+       $wgOut->addWikiText( $header );
+       
+       if ( $wgShowUpdatedMarker ) {
+               $wgOut->addHTML( '<form action="' .
+                       $specialTitle->escapeLocalUrl() .
+                       '" method="post"><input type="submit" name="dummy" value="' .
+                       htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
+                       '" /><input type="hidden" name="reset" value="all" /></form>' .
+                       "\n\n" );
+       }
 
        $use_index = $dbr->useIndexClause( $x );
        $sql = "SELECT
@@ -187,6 +225,7 @@ function wfSpecialWatchlist() {
   rev_user,rev_user_text,rev_timestamp,rev_minor_edit,page_is_new,wl_notificationtimestamp
   FROM $watchlist,$page,$revision  $use_index
   WHERE wl_user=$uid
+  $andHideOwn
   AND $z
   AND wl_title=page_title
   AND page_latest=rev_id
@@ -205,7 +244,16 @@ function wfSpecialWatchlist() {
        $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
        $note = wlCutoffLinks( $days );
        $wgOut->addHTML( "{$note}\n" );
-
+       
+       $sk = $wgUser->getSkin();
+       $s = $sk->makeKnownLink(
+               $wgContLang->specialPage( 'Watchlist' ),
+               (0 == $hideOwn) ? wfMsg( 'wlhide' ) : wfMsg( 'wlshow' ),        
+               'hideOwn=' . $wgLang->formatNum( 1-$hideOwn ) );
+               
+       $note = wfMsg( "wlhideshowown", $s );
+       $wgOut->addHTML( "\n<br />{$note}\n<br />" );
+       
        if ( $numRows == 0 ) {
                $wgOut->addHTML( '<p><i>' . wfMsg( 'watchnochange' ) . '</i></p>' );
                return;
@@ -220,14 +268,15 @@ function wfSpecialWatchlist() {
                $rc = RecentChange::newFromCurRow( $obj );
                $rc->counter = $counter++;
 
-               if ($wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' )) {
-                       $rc->notificationtimestamp = $obj->wl_notificationtimestamp;
+               if ( $wgShowUpdatedMarker ) {
+                       $updated = $obj->wl_notificationtimestamp;
                } else {
-                       $rc->notificationtimestamp = false;
+                       // Same visual appearance as MW 1.4
+                       $updated = true;
                }
 
                if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
-                       $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->cur_title). "' AND wl_namespace='{$obj->cur_namespace}'" ;
+                       $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->page_title). "' AND wl_namespace='{$obj->page_namespace}'" ;
                        $res3 = $dbr->query( $sql3, DB_READ, $fname );
                        $x = $dbr->fetchObject( $res3 );
                        $rc->numberofWatchingusers = $x->n;
@@ -235,7 +284,7 @@ function wfSpecialWatchlist() {
                        $rc->numberofWatchingusers = 0;
                }
 
-               $s .= $list->recentChangesLine( $rc, true);
+               $s .= $list->recentChangesLine( $rc, $updated );
        }
        $s .= $list->endRecentChangesList();
 
@@ -265,7 +314,7 @@ function wlDaysLink( $d, $page ) {
        $sk = $wgUser->getSkin();
        $s = $sk->makeKnownLink(
          $wgContLang->specialPage( $page ),
-         ($d ? $wgLang->formatNum( $d ) : wfMsg( 'all' ) ), "days=$d" );
+         ($d ? $wgLang->formatNum( $d ) : wfMsg( 'watchlistall2' ) ), "days=$d" );
        return $s;
 }