r94094 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94093‎ | r94094 | r94095 >
Date:00:36, 9 August 2011
Author:jlemley
Status:deferred
Tags:
Comment:
Fixed conflict with simplesecurity. Code cleanup.
Modified paths:
  • /branches/REL1_16/extensions/Favorites/FavParser.php (modified) (history)
  • /branches/REL1_16/extensions/Favorites/FavTitle.php (modified) (history)

Diff [purge]

Index: branches/REL1_16/extensions/Favorites/FavParser.php
@@ -7,7 +7,7 @@
88 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgArticle;
99 global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, $wgShowUpdatedMarker;
1010 $output = '';
11 -
 11+
1212 $skin = $wgUser->getSkin();
1313 $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' );
1414 //$wgOut->setRobotPolicy( 'noindex,nofollow' );
@@ -50,17 +50,6 @@
5151 private function viewFavList ($user, $output, $request, $argv) {
5252 global $wgOut, $wgLang, $wgRequest;
5353 $output = $this->showNormalForm( $output, $user );
54 - $uid=$user->getId();
55 - $dbr = wfGetDB( DB_SLAVE, 'favoritelist' );
56 -
57 - $favoritelistCount = $dbr->selectField( 'favoritelist', 'COUNT(*)',
58 - array( 'fl_user' => $uid ), __METHOD__ );
59 - $nitems = floor($favoritelistCount);
60 -
61 - if( $nitems == 0 ) {
62 - $output = wfmsg('nofavoritelist');
63 -
64 - }
6554
6655 return $output;
6756 }
@@ -88,31 +77,8 @@
8978 return $output;
9079 }
9180
 81+
9282
93 - /**
94 - * Extract a list of titles from a blob of text, returning
95 - * (prefixed) strings; unfavoritable titles are ignored
96 - *
97 - * @param $list mixed
98 - * @return array
99 - */
100 - private function extractTitles( $list ) {
101 - $titles = array();
102 - if( !is_array( $list ) ) {
103 - $list = explode( "\n", trim( $list ) );
104 - if( !is_array( $list ) )
105 - return array();
106 - }
107 - foreach( $list as $text ) {
108 - $text = trim( $text );
109 - if( strlen( $text ) > 0 ) {
110 - $title = Title::newFromText( $text );
111 - //if( $title instanceof Title && $title->isFavoritable() )
112 - $titles[] = $title->getPrefixedText();
113 - }
114 - }
115 - return array_unique( $titles );
116 - }
11783
11884
11985 /**
@@ -123,39 +89,11 @@
12490 */
12591 private function countFavoritelist( $user ) {
12692 $dbr = wfGetDB( DB_MASTER );
127 - $res = $dbr->select( 'favoritelist', 'COUNT(*) AS count', array( 'fl_user' => $user->getId() ), __METHOD__ );
 93+ $res = $dbr->select( 'favoritelist', 'COUNT(fl_user) AS count', array( 'fl_user' => $user->getId() ), __METHOD__ );
12894 $row = $dbr->fetchObject( $res );
129 - return ceil( $row->count); // Paranoia
 95+ return ceil( $row->count);
13096 }
13197
132 - /**
133 - * Prepare a list of titles on a user's favoritelist (excluding talk pages)
134 - * and return an array of (prefixed) strings
135 - *
136 - * @param $user User
137 - * @return array
138 - */
139 - private function getFavoritelist( $user ) {
140 - $list = array();
141 - $dbr = wfGetDB( DB_MASTER );
142 - $res = $dbr->select(
143 - 'favoritelist',
144 - '*',
145 - array(
146 - 'fl_user' => $user->getId(),
147 - ),
148 - __METHOD__
149 - );
150 - if( $res->numRows() > 0 ) {
151 - while( $row = $res->fetchObject() ) {
152 - $title = Title::makeTitleSafe( $row->fl_namespace, $row->fl_title );
153 - if( $title instanceof Title && !$title->isTalkPage() )
154 - $list[] = $title->getPrefixedText();
155 - }
156 - $res->free();
157 - }
158 - return $list;
159 - }
16098
16199 /**
162100 * Get a list of titles on a user's favoritelist, excluding talk pages,
@@ -194,32 +132,8 @@
195133 return $titles;
196134 }
197135
198 - /**
199 - * Show a message indicating the number of items on the user's favoritelist,
200 - * and return this count for additional checking
201 - *
202 - * @param $output OutputPage
203 - * @param $user User
204 - * @return int
205 - */
206 - private function showItemCount( $output, $user ) {
207 - if( ( $count = $this->countFavoritelist( $user ) ) > 0 ) {
208 - //$output->addHTML( wfMsgExt( 'favoritelistedit-numitems', 'parse',
209 - // $GLOBALS['wgLang']->formatNum( $count ) ) );
210 - } else {
211 - //$output->addHTML( wfMsg( 'favoritelistedit-noitems', 'parse' ) );
212 - }
213 - return $count;
214 - }
215136
216137 /**
217 - * Remove all titles from a user's favoritelist
218 - *
219 - * @param $user User
220 -// */
221 -
222 -
223 - /**
224138 * Show the standard favoritelist
225139 *
226140 * @param $output OutputPage
@@ -228,10 +142,14 @@
229143 private function showNormalForm( $output, $user ) {
230144 global $wgOut;
231145 $skin = $user->getSkin();
232 - if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) {
 146+
 147+ if ( $this->countFavoritelist($user ) > 0 ) {
233148 $form = $this->buildRemoveList( $user, $skin );
234149 $output .= $form ;
235150 return $output;
 151+ } else {
 152+ $output = wfmsg('nofavoritelist');
 153+ return $output;
236154 }
237155 }
238156
@@ -275,25 +193,3 @@
276194 }
277195
278196 }
279 -/**
280 - * Count the number of items on a user's favoritelist
281 - *
282 - * @param $talk Include talk pages
283 - * @return integer
284 - */
285 -function flCountItems( &$user, $talk = true ) {
286 - $dbr = wfGetDB( DB_SLAVE, 'favoritelist' );
287 -
288 - # Fetch the raw count
289 - $res = $dbr->select( 'favoritelist', 'COUNT(*) AS count',
290 - array( 'fl_user' => $user->mId ), 'flCountItems' );
291 - $row = $dbr->fetchObject( $res );
292 - $count = $row->count;
293 - $dbr->freeResult( $res );
294 -
295 - # Halve to remove talk pages if needed
296 - if( !$talk )
297 - $count = floor( $count);
298 -
299 - return( $count );
300 -}
Index: branches/REL1_16/extensions/Favorites/FavTitle.php
@@ -18,11 +18,13 @@
1919
2020 global $wgUser, $wgArticle;
2121 $favUser = new FavUser();
22 - if ( is_null( $this->mFav ) ) {
23 - if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) {
24 - $this->mFav = false;
25 - } else {
26 - $this->mFav = $favUser->isFavorited( $wgArticle->mTitle );
 22+ if ($wgArticle) {
 23+ if ( is_null( $this->mFav ) ) {
 24+ if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) {
 25+ $this->mFav = false;
 26+ } else {
 27+ $this->mFav = $favUser->isFavorited( $wgArticle->mTitle );
 28+ }
2729 }
2830 }
2931 return $this->mFav;

Status & tagging log