Index: branches/REL1_17/extensions/Favorites/FavParser.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | global $wgUser, $wgOut, $wgLang, $wgRequest, $wgArticle; |
9 | 9 | global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, $wgShowUpdatedMarker; |
10 | 10 | $output = ''; |
11 | | - |
| 11 | + |
12 | 12 | $skin = $wgUser->getSkin(); |
13 | 13 | $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' ); |
14 | 14 | //$wgOut->setRobotPolicy( 'noindex,nofollow' ); |
— | — | @@ -50,17 +50,6 @@ |
51 | 51 | private function viewFavList ($user, $output, $request, $argv) { |
52 | 52 | global $wgOut, $wgLang, $wgRequest; |
53 | 53 | $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 | | - } |
65 | 54 | |
66 | 55 | return $output; |
67 | 56 | } |
— | — | @@ -88,31 +77,8 @@ |
89 | 78 | return $output; |
90 | 79 | } |
91 | 80 | |
| 81 | + |
92 | 82 | |
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 | | - } |
117 | 83 | |
118 | 84 | |
119 | 85 | /** |
— | — | @@ -123,39 +89,11 @@ |
124 | 90 | */ |
125 | 91 | private function countFavoritelist( $user ) { |
126 | 92 | $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__ ); |
128 | 94 | $row = $dbr->fetchObject( $res ); |
129 | | - return ceil( $row->count); // Paranoia |
| 95 | + return ceil( $row->count); |
130 | 96 | } |
131 | 97 | |
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 | | - } |
160 | 98 | |
161 | 99 | /** |
162 | 100 | * Get a list of titles on a user's favoritelist, excluding talk pages, |
— | — | @@ -194,32 +132,8 @@ |
195 | 133 | return $titles; |
196 | 134 | } |
197 | 135 | |
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 | | - } |
215 | 136 | |
216 | 137 | /** |
217 | | - * Remove all titles from a user's favoritelist |
218 | | - * |
219 | | - * @param $user User |
220 | | -// */ |
221 | | - |
222 | | - |
223 | | - /** |
224 | 138 | * Show the standard favoritelist |
225 | 139 | * |
226 | 140 | * @param $output OutputPage |
— | — | @@ -228,10 +142,14 @@ |
229 | 143 | private function showNormalForm( $output, $user ) { |
230 | 144 | global $wgOut; |
231 | 145 | $skin = $user->getSkin(); |
232 | | - if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) { |
| 146 | + |
| 147 | + if ( $this->countFavoritelist($user ) > 0 ) { |
233 | 148 | $form = $this->buildRemoveList( $user, $skin ); |
234 | 149 | $output .= $form ; |
235 | 150 | return $output; |
| 151 | + } else { |
| 152 | + $output = wfmsg('nofavoritelist'); |
| 153 | + return $output; |
236 | 154 | } |
237 | 155 | } |
238 | 156 | |
— | — | @@ -275,25 +193,3 @@ |
276 | 194 | } |
277 | 195 | |
278 | 196 | } |
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_17/extensions/Favorites/FavTitle.php |
— | — | @@ -18,11 +18,13 @@ |
19 | 19 | |
20 | 20 | global $wgUser, $wgArticle; |
21 | 21 | $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 | + } |
27 | 29 | } |
28 | 30 | } |
29 | 31 | return $this->mFav; |