http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94094
Revision: 94094 Author: jlemley Date: 2011-08-09 00:36:18 +0000 (Tue, 09 Aug 2011) Log Message: ----------- Fixed conflict with simplesecurity. Code cleanup. Modified Paths: -------------- branches/REL1_16/extensions/Favorites/FavParser.php branches/REL1_16/extensions/Favorites/FavTitle.php Modified: branches/REL1_16/extensions/Favorites/FavParser.php =================================================================== --- branches/REL1_16/extensions/Favorites/FavParser.php 2011-08-09 00:36:00 UTC (rev 94093) +++ branches/REL1_16/extensions/Favorites/FavParser.php 2011-08-09 00:36:18 UTC (rev 94094) @@ -7,7 +7,7 @@ global $wgUser, $wgOut, $wgLang, $wgRequest, $wgArticle; global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, $wgShowUpdatedMarker; $output = ''; - + $skin = $wgUser->getSkin(); $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' ); //$wgOut->setRobotPolicy( 'noindex,nofollow' ); @@ -50,17 +50,6 @@ private function viewFavList ($user, $output, $request, $argv) { global $wgOut, $wgLang, $wgRequest; $output = $this->showNormalForm( $output, $user ); - $uid=$user->getId(); - $dbr = wfGetDB( DB_SLAVE, 'favoritelist' ); - - $favoritelistCount = $dbr->selectField( 'favoritelist', 'COUNT(*)', - array( 'fl_user' => $uid ), __METHOD__ ); - $nitems = floor($favoritelistCount); - - if( $nitems == 0 ) { - $output = wfmsg('nofavoritelist'); - - } return $output; } @@ -88,31 +77,8 @@ return $output; } + - /** - * Extract a list of titles from a blob of text, returning - * (prefixed) strings; unfavoritable titles are ignored - * - * @param $list mixed - * @return array - */ - private function extractTitles( $list ) { - $titles = array(); - if( !is_array( $list ) ) { - $list = explode( "\n", trim( $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->isFavoritable() ) - $titles[] = $title->getPrefixedText(); - } - } - return array_unique( $titles ); - } /** @@ -123,39 +89,11 @@ */ private function countFavoritelist( $user ) { $dbr = wfGetDB( DB_MASTER ); - $res = $dbr->select( 'favoritelist', 'COUNT(*) AS count', array( 'fl_user' => $user->getId() ), __METHOD__ ); + $res = $dbr->select( 'favoritelist', 'COUNT(fl_user) AS count', array( 'fl_user' => $user->getId() ), __METHOD__ ); $row = $dbr->fetchObject( $res ); - return ceil( $row->count); // Paranoia + return ceil( $row->count); } - /** - * Prepare a list of titles on a user's favoritelist (excluding talk pages) - * and return an array of (prefixed) strings - * - * @param $user User - * @return array - */ - private function getFavoritelist( $user ) { - $list = array(); - $dbr = wfGetDB( DB_MASTER ); - $res = $dbr->select( - 'favoritelist', - '*', - array( - 'fl_user' => $user->getId(), - ), - __METHOD__ - ); - if( $res->numRows() > 0 ) { - while( $row = $res->fetchObject() ) { - $title = Title::makeTitleSafe( $row->fl_namespace, $row->fl_title ); - if( $title instanceof Title && !$title->isTalkPage() ) - $list[] = $title->getPrefixedText(); - } - $res->free(); - } - return $list; - } /** * Get a list of titles on a user's favoritelist, excluding talk pages, @@ -194,32 +132,8 @@ return $titles; } - /** - * Show a message indicating the number of items on the user's favoritelist, - * and return this count for additional checking - * - * @param $output OutputPage - * @param $user User - * @return int - */ - private function showItemCount( $output, $user ) { - if( ( $count = $this->countFavoritelist( $user ) ) > 0 ) { - //$output->addHTML( wfMsgExt( 'favoritelistedit-numitems', 'parse', - // $GLOBALS['wgLang']->formatNum( $count ) ) ); - } else { - //$output->addHTML( wfMsg( 'favoritelistedit-noitems', 'parse' ) ); - } - return $count; - } /** - * Remove all titles from a user's favoritelist - * - * @param $user User -// */ - - - /** * Show the standard favoritelist * * @param $output OutputPage @@ -228,10 +142,14 @@ private function showNormalForm( $output, $user ) { global $wgOut; $skin = $user->getSkin(); - if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) { + + if ( $this->countFavoritelist($user ) > 0 ) { $form = $this->buildRemoveList( $user, $skin ); $output .= $form ; return $output; + } else { + $output = wfmsg('nofavoritelist'); + return $output; } } @@ -275,25 +193,3 @@ } } -/** - * Count the number of items on a user's favoritelist - * - * @param $talk Include talk pages - * @return integer - */ -function flCountItems( &$user, $talk = true ) { - $dbr = wfGetDB( DB_SLAVE, 'favoritelist' ); - - # Fetch the raw count - $res = $dbr->select( 'favoritelist', 'COUNT(*) AS count', - array( 'fl_user' => $user->mId ), 'flCountItems' ); - $row = $dbr->fetchObject( $res ); - $count = $row->count; - $dbr->freeResult( $res ); - - # Halve to remove talk pages if needed - if( !$talk ) - $count = floor( $count); - - return( $count ); -} Modified: branches/REL1_16/extensions/Favorites/FavTitle.php =================================================================== --- branches/REL1_16/extensions/Favorites/FavTitle.php 2011-08-09 00:36:00 UTC (rev 94093) +++ branches/REL1_16/extensions/Favorites/FavTitle.php 2011-08-09 00:36:18 UTC (rev 94094) @@ -18,11 +18,13 @@ global $wgUser, $wgArticle; $favUser = new FavUser(); - if ( is_null( $this->mFav ) ) { - if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) { - $this->mFav = false; - } else { - $this->mFav = $favUser->isFavorited( $wgArticle->mTitle ); + if ($wgArticle) { + if ( is_null( $this->mFav ) ) { + if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) { + $this->mFav = false; + } else { + $this->mFav = $favUser->isFavorited( $wgArticle->mTitle ); + } } } return $this->mFav; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs