X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWatchlistEditor.php;h=b5a994d5e878f66db109075faee166d5b583175f;hb=36be4d521f7a07c4c329e44ec3af4712511dbf39;hp=82c524c65e01bbd86da0c42280952cf7dccab561;hpb=0a9af4a8848b0d19f496f8c27ab78a040dd69911;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WatchlistEditor.php b/includes/WatchlistEditor.php index 82c524c65e..b5a994d5e8 100644 --- a/includes/WatchlistEditor.php +++ b/includes/WatchlistEditor.php @@ -100,15 +100,17 @@ class WatchlistEditor { $titles = array(); if( !is_array( $list ) ) { $list = explode( "\n", trim( $list ) ); - if( !is_array( $list ) ) + if( !is_array( $list ) ) { return array(); + } } foreach( $list as $text ) { $text = trim( $text ); if( strlen( $text ) > 0 ) { $title = Title::newFromText( $text ); - if( $title instanceof Title && $title->isWatchable() ) + if( $title instanceof Title && $title->isWatchable() ) { $titles[] = $title->getPrefixedText(); + } } } return array_unique( $titles ); @@ -129,8 +131,9 @@ class WatchlistEditor { // Do a batch existence check $batch = new LinkBatch(); foreach( $titles as $title ) { - if( !$title instanceof Title ) + if( !$title instanceof Title ) { $title = Title::newFromText( $title ); + } if( $title instanceof Title ) { $batch->addObj( $title ); $batch->addObj( $title->getTalkPage() ); @@ -140,11 +143,12 @@ class WatchlistEditor { // Print out the list $output->addHTML( "\n" ); @@ -182,7 +186,7 @@ class WatchlistEditor { __METHOD__ ); if( $res->numRows() > 0 ) { - while( $row = $res->fetchObject() ) { + foreach ( $res as $row ) { $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title ); if( $title instanceof Title && !$title->isTalkPage() ) $list[] = $title->getPrefixedText(); @@ -203,26 +207,32 @@ class WatchlistEditor { private function getWatchlistInfo( $user ) { $titles = array(); $dbr = wfGetDB( DB_MASTER ); - $uid = intval( $user->getId() ); - list( $watchlist, $page ) = $dbr->tableNamesN( 'watchlist', 'page' ); - $sql = "SELECT wl_namespace, wl_title, page_id, page_len, page_is_redirect - FROM {$watchlist} LEFT JOIN {$page} ON ( wl_namespace = page_namespace - AND wl_title = page_title ) WHERE wl_user = {$uid}"; - $res = $dbr->query( $sql, __METHOD__ ); + + $res = $dbr->select( + array( 'watchlist', 'page' ), + array( 'wl_namespace', 'wl_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ), + array( 'wl_user' => $user->getId() ), + __METHOD__, + array( 'ORDER BY' => 'wl_namespace, wl_title' ), + array( 'page' => + array( 'LEFT JOIN', 'wl_namespace = page_namespace AND wl_title = page_title' ) ) + ); + if( $res && $dbr->numRows( $res ) > 0 ) { $cache = LinkCache::singleton(); - while( $row = $dbr->fetchObject( $res ) ) { + foreach ( $res as $row ) { $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title ); if( $title instanceof Title ) { // Update the link cache while we're at it if( $row->page_id ) { - $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect ); + $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect, $row->page_latest ); } else { $cache->addBadLinkObj( $title ); } // Ignore non-talk - if( !$title->isTalkPage() ) + if( !$title->isTalkPage() ) { $titles[$row->wl_namespace][$row->wl_title] = $row->page_is_redirect; + } } } } @@ -270,8 +280,9 @@ class WatchlistEditor { $dbw = wfGetDB( DB_MASTER ); $rows = array(); foreach( $titles as $title ) { - if( !$title instanceof Title ) + if( !$title instanceof Title ) { $title = Title::newFromText( $title ); + } if( $title instanceof Title ) { $rows[] = array( 'wl_user' => $user->getId(), @@ -302,8 +313,9 @@ class WatchlistEditor { private function unwatchTitles( $titles, $user ) { $dbw = wfGetDB( DB_MASTER ); foreach( $titles as $title ) { - if( !$title instanceof Title ) + if( !$title instanceof Title ) { $title = Title::newFromText( $title ); + } if( $title instanceof Title ) { $dbw->delete( 'watchlist', @@ -337,28 +349,55 @@ class WatchlistEditor { */ private function showNormalForm( $output, $user ) { global $wgUser; - if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) { + $count = $this->showItemCount( $output, $user ); + if( $count > 0 ) { $self = SpecialPage::getTitleFor( 'Watchlist' ); $form = Xml::openElement( 'form', array( 'method' => 'post', - 'action' => $self->getLocalUrl( 'action=edit' ) ) ); - $form .= Xml::hidden( 'token', $wgUser->editToken( 'watchlistedit' ) ); + 'action' => $self->getLocalUrl( array( 'action' => 'edit' ) ) ) ); + $form .= Html::hidden( 'token', $wgUser->editToken( 'watchlistedit' ) ); $form .= "
\n" . wfMsgHtml( 'watchlistedit-normal-legend' ) . ""; $form .= wfMsgExt( 'watchlistedit-normal-explain', 'parse' ); - foreach( $this->getWatchlistInfo( $user ) as $namespace => $pages ) { - $form .= "

" . $this->getNamespaceHeading( $namespace ) . "

\n"; - $form .= "\n"; - } + $form .= $this->buildRemoveList( $user, $wgUser->getSkin() ); $form .= '

' . Xml::submitButton( wfMsg( 'watchlistedit-normal-submit' ) ) . '

'; $form .= '
'; $output->addHTML( $form ); } } + /** + * Build the part of the standard watchlist editing form with the actual + * title selection checkboxes and stuff. Also generates a table of + * contents if there's more than one heading. + * + * @param $user User + * @param $skin Skin (really, Linker) + */ + private function buildRemoveList( $user, $skin ) { + $list = ""; + $toc = $skin->tocIndent(); + $tocLength = 0; + foreach( $this->getWatchlistInfo( $user ) as $namespace => $pages ) { + $tocLength++; + $heading = htmlspecialchars( $this->getNamespaceHeading( $namespace ) ); + $anchor = "editwatchlist-ns" . $namespace; + + $list .= $skin->makeHeadLine( 2, ">", $anchor, $heading, "" ); + $toc .= $skin->tocLine( $anchor, $heading, $tocLength, 1 ) . $skin->tocLineEnd(); + + $list .= "\n"; + } + // ISSUE: omit the TOC if the total number of titles is low? + if( $tocLength > 1 ) { + $list = $skin->tocList( $toc ) . $list; + } + return $list; + } + /** * Get the correct "heading" for a namespace * @@ -381,20 +420,38 @@ class WatchlistEditor { * @return string */ private function buildRemoveLine( $title, $redirect, $skin ) { - $link = $skin->makeLinkObj( $title ); - if( $redirect ) + global $wgLang; + + $link = $skin->link( $title ); + if( $redirect ) { $link = '' . $link . ''; - $tools[] = $skin->makeLinkObj( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) ); + } + $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) ); if( $title->exists() ) { - $tools[] = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'history_short' ), 'action=history' ); + $tools[] = $skin->link( + $title, + wfMsgHtml( 'history_short' ), + array(), + array( 'action' => 'history' ), + array( 'known', 'noclasses' ) + ); } if( $title->getNamespace() == NS_USER && !$title->isSubpage() ) { - $tools[] = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $title->getText() ), wfMsgHtml( 'contributions' ) ); + $tools[] = $skin->link( + SpecialPage::getTitleFor( 'Contributions', $title->getText() ), + wfMsgHtml( 'contributions' ), + array(), + array(), + array( 'known', 'noclasses' ) + ); } + + wfRunHooks( 'WatchlistEditorBuildRemoveLine', array( &$tools, $title, $redirect, $skin ) ); + return "
  • " . Xml::check( 'titles[]', false, array( 'value' => $title->getPrefixedText() ) ) - . $link . " (" . implode( ' | ', $tools ) . ")" . "
  • \n"; - } + . $link . " (" . $wgLang->pipeList( $tools ) . ")" . "\n"; + } /** * Show a form for editing the watchlist in "raw" mode @@ -406,9 +463,9 @@ class WatchlistEditor { global $wgUser; $this->showItemCount( $output, $user ); $self = SpecialPage::getTitleFor( 'Watchlist' ); - $form = Xml::openElement( 'form', array( 'method' => 'post', - 'action' => $self->getLocalUrl( 'action=raw' ) ) ); - $form .= Xml::hidden( 'token', $wgUser->editToken( 'watchlistedit' ) ); + $form = Xml::openElement( 'form', array( 'method' => 'post', + 'action' => $self->getLocalUrl( array( 'action' => 'raw' ) ) ) ); + $form .= Html::hidden( 'token', $wgUser->editToken( 'watchlistedit' ) ); $form .= '
    ' . wfMsgHtml( 'watchlistedit-raw-legend' ) . ''; $form .= wfMsgExt( 'watchlistedit-raw-explain', 'parse' ); $form .= Xml::label( wfMsg( 'watchlistedit-raw-titles' ), 'titles' ); @@ -416,8 +473,9 @@ class WatchlistEditor { $form .= Xml::openElement( 'textarea', array( 'id' => 'titles', 'name' => 'titles', 'rows' => $wgUser->getIntOption( 'rows' ), 'cols' => $wgUser->getIntOption( 'cols' ) ) ); $titles = $this->getWatchlist( $user ); - foreach( $titles as $title ) + foreach( $titles as $title ) { $form .= htmlspecialchars( $title ) . "\n"; + } $form .= ''; $form .= '

    ' . Xml::submitButton( wfMsg( 'watchlistedit-raw-submit' ) ) . '

    '; $form .= '
    '; @@ -454,11 +512,19 @@ class WatchlistEditor { * @return string */ public static function buildTools( $skin ) { + global $wgLang; + $tools = array(); $modes = array( 'view' => false, 'edit' => 'edit', 'raw' => 'raw' ); foreach( $modes as $mode => $subpage ) { - $tools[] = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Watchlist', $subpage ), wfMsgHtml( "watchlisttools-{$mode}" ) ); + // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw' + $tools[] = $skin->linkKnown( + SpecialPage::getTitleFor( 'Watchlist', $subpage ), + wfMsgHtml( "watchlisttools-{$mode}" ) + ); } - return implode( ' | ', $tools ); + return Html::rawElement( 'span', + array( 'class' => 'mw-watchlist-toollinks' ), + wfMsg( 'parentheses', $wgLang->pipeList( $tools ) ) ); } }