From: Alexandre Emsenhuber Date: Fri, 15 Jul 2011 08:42:25 +0000 (+0000) Subject: * Use local context instead of global variables X-Git-Tag: 1.31.0-rc.0~28830 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/supprimer.php?a=commitdiff_plain;h=8c73abd507bfe777f2c6fbfb98156adfb5801dc7;p=lhc%2Fweb%2Fwiklou.git * Use local context instead of global variables * Removed parameters that could be replaced by context * Call Linker methods statically * Removed two unused methods: countWatchlist() and showItemCount() * The parameter of SpecialEditWatch::buildTools() is now unused --- diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index a56cf75020..bd918ef741 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -28,32 +28,33 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * @param $mode int */ public function execute( $mode ) { - global $wgUser, $wgOut, $wgRequest; if( wfReadOnly() ) { - $wgOut->readOnlyPage(); + throw new ReadOnlyError; return; } + $out = $this->getOutput(); + # Anons don't get a watchlist - if( $wgUser->isAnon() ) { - $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); - $llink = $this->getSkin()->linkKnown( + if( $this->getUser()->isAnon() ) { + $out->setPageTitle( wfMsg( 'watchnologin' ) ); + $llink = Linker::linkKnown( SpecialPage::getTitleFor( 'Userlogin' ), wfMsgHtml( 'loginreqlink' ), array(), array( 'returnto' => $this->getTitle()->getPrefixedText() ) ); - $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) ); + $out->addHTML( wfMessage( 'watchlistanontext' )->rawParam( $llink )->parse() ); return; } $sub = wfMsgExt( 'watchlistfor2', array( 'parseinline', 'replaceafter' ), - $wgUser->getName(), - SpecialEditWatchlist::buildTools( $this->getSkin() ) + $this->getUser()->getName(), + SpecialEditWatchlist::buildTools( null ) ); - $wgOut->setSubtitle( $sub ); + $out->setSubtitle( $sub ); # B/C: $mode used to be waaay down the parameter list, and the first parameter # was $wgUser @@ -63,7 +64,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $mode = $args[3]; } } - $mode = self::getMode( $wgRequest, $mode ); + $mode = self::getMode( $this->getRequest(), $mode ); switch( $mode ) { case self::EDIT_CLEAR: @@ -71,21 +72,21 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { // Pass on to the raw editor, from which it's very easy to clear. case self::EDIT_RAW: - $wgOut->setPageTitle( wfMsg( 'watchlistedit-raw-title' ) ); - $form = $this->getRawForm( $wgUser ); + $out->setPageTitle( wfMsg( 'watchlistedit-raw-title' ) ); + $form = $this->getRawForm(); if( $form->show() ){ - $wgOut->addHTML( $this->successMessage ); - $wgOut->returnToMain(); + $out->addHTML( $this->successMessage ); + $out->returnToMain(); } break; case self::EDIT_NORMAL: default: - $wgOut->setPageTitle( wfMsg( 'watchlistedit-normal-title' ) ); - $form = $this->getNormalForm( $wgUser ); + $out->setPageTitle( wfMsg( 'watchlistedit-normal-title' ) ); + $form = $this->getNormalForm(); if( $form->show() ){ - $wgOut->addHTML( $this->successMessage ); - $wgOut->returnToMain(); + $out->addHTML( $this->successMessage ); + $out->returnToMain(); } break; } @@ -117,16 +118,15 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } public function submitRaw( $data ){ - global $wgUser, $wgLang; $wanted = $this->extractTitles( $data['Titles'] ); - $current = $this->getWatchlist( $wgUser ); + $current = $this->getWatchlist(); if( count( $wanted ) > 0 ) { $toWatch = array_diff( $wanted, $current ); $toUnwatch = array_diff( $current, $wanted ); - $this->watchTitles( $toWatch, $wgUser ); - $this->unwatchTitles( $toUnwatch, $wgUser ); - $wgUser->invalidateCache(); + $this->watchTitles( $toWatch ); + $this->unwatchTitles( $toUnwatch ); + $this->getUser()->invalidateCache(); if( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 ){ $this->successMessage = wfMessage( 'watchlistedit-raw-done' )->parse(); @@ -137,26 +137,26 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { if( count( $toWatch ) > 0 ) { $this->successMessage .= wfMessage( 'watchlistedit-raw-added', - $wgLang->formatNum( count( $toWatch ) ) + $this->getLang()->formatNum( count( $toWatch ) ) ); - $this->showTitles( $toWatch, $this->successMessage, $this->getSkin() ); + $this->showTitles( $toWatch, $this->successMessage ); } if( count( $toUnwatch ) > 0 ) { $this->successMessage .= wfMessage( 'watchlistedit-raw-removed', - $wgLang->formatNum( count( $toUnwatch ) ) + $this->getLang()->formatNum( count( $toUnwatch ) ) ); - $this->showTitles( $toUnwatch, $this->successMessage, $this->getSkin() ); + $this->showTitles( $toUnwatch, $this->successMessage ); } } else { - $this->clearWatchlist( $wgUser ); - $wgUser->invalidateCache(); + $this->clearWatchlist(); + $this->getLang()->invalidateCache(); $this->successMessage .= wfMessage( 'watchlistedit-raw-removed', - $wgLang->formatNum( count( $current ) ) + $this->getLang()->formatNum( count( $current ) ) ); - $this->showTitles( $current, $this->successMessage, $this->getSkin() ); + $this->showTitles( $current, $this->successMessage ); } return true; } @@ -169,9 +169,8 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * * @param $titles array of strings, or Title objects * @param $output String - * @param $skin Skin */ - private function showTitles( $titles, &$output, $skin ) { + private function showTitles( $titles, &$output ) { $talk = wfMsgHtml( 'talkpagelinktext' ); // Do a batch existence check $batch = new LinkBatch(); @@ -193,42 +192,28 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } if( $title instanceof Title ) { $output .= "
  • " - . $skin->link( $title ) - . ' (' . $skin->link( $title->getTalkPage(), $talk ) + . Linker::link( $title ) + . ' (' . Linker::link( $title->getTalkPage(), $talk ) . ")
  • \n"; } } $output .= "\n"; } - /** - * Count the number of titles on a user's watchlist, excluding talk pages - * - * @param $user User - * @return int - */ - private function countWatchlist( $user ) { - $dbr = wfGetDB( DB_MASTER ); - $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->getId() ), __METHOD__ ); - $row = $dbr->fetchObject( $res ); - return ceil( $row->count / 2 ); // Paranoia - } - /** * Prepare a list of titles on a user's watchlist (excluding talk pages) * and return an array of (prefixed) strings * - * @param $user User * @return array */ - private function getWatchlist( $user ) { + private function getWatchlist() { $list = array(); $dbr = wfGetDB( DB_MASTER ); $res = $dbr->select( 'watchlist', '*', array( - 'wl_user' => $user->getId(), + 'wl_user' => $this->getUser()->getId(), ), __METHOD__ ); @@ -248,10 +233,9 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * and return as a two-dimensional array with namespace, title and * redirect status * - * @param $user User * @return array */ - private function getWatchlistInfo( $user ) { + private function getWatchlistInfo() { $titles = array(); $dbr = wfGetDB( DB_MASTER ); @@ -265,7 +249,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { 'page_is_redirect', 'page_latest' ), - array( 'wl_user' => $user->getId() ), + array( 'wl_user' => $this->getUser()->getId() ), __METHOD__, array( 'ORDER BY' => 'wl_namespace, wl_title' ), array( 'page' => array( @@ -295,34 +279,14 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { return $titles; } - /** - * Show a message indicating the number of items on the user's watchlist, - * and return this count for additional checking - * - * @param $output OutputPage - * @param $user User - * @return int - */ - private function showItemCount( $output, $user ) { - if( ( $count = $this->countWatchlist( $user ) ) > 0 ) { - $output->addHTML( wfMsgExt( 'watchlistedit-numitems', 'parse', - $GLOBALS['wgLang']->formatNum( $count ) ) ); - } else { - $output->addHTML( wfMsgExt( 'watchlistedit-noitems', 'parse' ) ); - } - return $count; - } - /** * Remove all titles from a user's watchlist - * - * @param $user User */ - private function clearWatchlist( $user ) { + private function clearWatchlist() { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'watchlist', - array( 'wl_user' => $user->getId() ), + array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ ); } @@ -334,9 +298,8 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * is preferred, since Titles are very memory-heavy * * @param $titles Array of strings, or Title objects - * @param $user User */ - private function watchTitles( $titles, $user ) { + private function watchTitles( $titles ) { $dbw = wfGetDB( DB_MASTER ); $rows = array(); foreach( $titles as $title ) { @@ -345,13 +308,13 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } if( $title instanceof Title ) { $rows[] = array( - 'wl_user' => $user->getId(), + 'wl_user' => $this->getUser()->getId(), 'wl_namespace' => ( $title->getNamespace() & ~1 ), 'wl_title' => $title->getDBkey(), 'wl_notificationtimestamp' => null, ); $rows[] = array( - 'wl_user' => $user->getId(), + 'wl_user' => $this->getUser()->getId(), 'wl_namespace' => ( $title->getNamespace() | 1 ), 'wl_title' => $title->getDBkey(), 'wl_notificationtimestamp' => null, @@ -368,9 +331,8 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * is preferred, since Titles are very memory-heavy * * @param $titles Array of strings, or Title objects - * @param $user User */ - private function unwatchTitles( $titles, $user ) { + private function unwatchTitles( $titles ) { $dbw = wfGetDB( DB_MASTER ); foreach( $titles as $title ) { if( !$title instanceof Title ) { @@ -380,7 +342,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $dbw->delete( 'watchlist', array( - 'wl_user' => $user->getId(), + 'wl_user' => $this->getUser()->getId(), 'wl_namespace' => ( $title->getNamespace() & ~1 ), 'wl_title' => $title->getDBkey(), ), @@ -389,34 +351,32 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $dbw->delete( 'watchlist', array( - 'wl_user' => $user->getId(), + 'wl_user' => $this->getUser()->getId(), 'wl_namespace' => ( $title->getNamespace() | 1 ), 'wl_title' => $title->getDBkey(), ), __METHOD__ ); - $article = new Article($title); - wfRunHooks('UnwatchArticleComplete',array(&$user,&$article)); + $article = new Article( $title, 0 ); + wfRunHooks( 'UnwatchArticleComplete', array( $this->getUser(), &$article ) ); } } } public function submitNormal( $data ) { - global $wgUser; $removed = array(); foreach( $data as $titles ) { - $this->unwatchTitles( $titles, $wgUser ); + $this->unwatchTitles( $titles ); $removed += $titles; } if( count( $removed ) > 0 ) { - global $wgLang; $this->successMessage = wfMessage( 'watchlistedit-normal-done', - $wgLang->formatNum( count( $removed ) ) + $this->getLang()->formatNum( count( $removed ) ) ); - $this->showTitles( $removed, $this->successMessage, $this->getSkin() ); + $this->showTitles( $removed, $this->successMessage ); return true; } else { return false; @@ -426,15 +386,14 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { /** * Get the standard watchlist editing form * - * @param $user User * @return HTMLForm */ - protected function getNormalForm( $user ){ + protected function getNormalForm(){ global $wgContLang; - $skin = $user->getSkin(); + $fields = array(); - foreach( $this->getWatchlistInfo( $user ) as $namespace => $pages ){ + foreach( $this->getWatchlistInfo() as $namespace => $pages ){ $namespace == NS_MAIN ? wfMsgHtml( 'blanknamespace' ) @@ -448,7 +407,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { foreach( $pages as $dbkey => $redirect ){ $title = Title::makeTitleSafe( $namespace, $dbkey ); - $text = $this->buildRemoveLine( $title, $redirect, $skin ); + $text = $this->buildRemoveLine( $title, $redirect ); $fields['TitlesNs'.$namespace]['options'][$text] = $title->getEscapedText(); } } @@ -467,49 +426,41 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * * @param $title Title * @param $redirect bool - * @param $skin Skin * @return string */ - private function buildRemoveLine( $title, $redirect, $skin ) { - global $wgLang; - - $link = $skin->link( $title ); + private function buildRemoveLine( $title, $redirect ) { + $link = Linker::link( $title ); if( $redirect ) { $link = '' . $link . ''; } - $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) ); + $tools[] = Linker::link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) ); if( $title->exists() ) { - $tools[] = $skin->link( + $tools[] = Linker::linkKnown( $title, wfMsgHtml( 'history_short' ), array(), - array( 'action' => 'history' ), - array( 'known', 'noclasses' ) + array( 'action' => 'history' ) ); } if( $title->getNamespace() == NS_USER && !$title->isSubpage() ) { - $tools[] = $skin->link( + $tools[] = Linker::linkKnown( SpecialPage::getTitleFor( 'Contributions', $title->getText() ), - wfMsgHtml( 'contributions' ), - array(), - array(), - array( 'known', 'noclasses' ) + wfMsgHtml( 'contributions' ) ); } - wfRunHooks( 'WatchlistEditorBuildRemoveLine', array( &$tools, $title, $redirect, $skin ) ); + wfRunHooks( 'WatchlistEditorBuildRemoveLine', array( &$tools, $title, $redirect, $this->getSkin() ) ); - return $link . " (" . $wgLang->pipeList( $tools ) . ")"; + return $link . " (" . $this->getLang()->pipeList( $tools ) . ")"; } /** * Get a form for editing the watchlist in "raw" mode * - * @param $user User * @return HTMLForm */ - protected function getRawForm( $user ){ - $titles = implode( array_map( 'htmlspecialchars', $this->getWatchlist( $user ) ), "\n" ); + protected function getRawForm(){ + $titles = implode( array_map( 'htmlspecialchars', $this->getWatchlist() ), "\n" ); $fields = array( 'Titles' => array( 'type' => 'textarea', @@ -560,10 +511,10 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * Build a set of links for convenient navigation * between watchlist viewing and editing modes * - * @param $skin Skin to use + * @param $unused Unused * @return string */ - public static function buildTools( $skin ) { + public static function buildTools( $unused ) { global $wgLang; $tools = array(); @@ -574,7 +525,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { ); foreach( $modes as $mode => $arr ) { // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw' - $tools[] = $skin->linkKnown( + $tools[] = Linker::linkKnown( SpecialPage::getTitleFor( $arr[0], $arr[1] ), wfMsgHtml( "watchlisttools-{$mode}" ) ); @@ -593,10 +544,9 @@ class WatchlistEditor extends SpecialEditWatchlist {} */ class EditWatchlistNormalHTMLForm extends HTMLForm { public function getLegend( $namespace ){ - global $wgLang; $namespace = substr( $namespace, 2 ); return $namespace == NS_MAIN ? wfMsgHtml( 'blanknamespace' ) - : htmlspecialchars( $wgLang->getFormattedNsText( $namespace ) ); + : htmlspecialchars( $this->getContext()->getLang()->getFormattedNsText( $namespace ) ); } }