r93870 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93869‎ | r93870 | r93871 >
Date:00:57, 4 August 2011
Author:jlemley
Status:deferred
Tags:
Comment:
Added parser argument. Fixed formatting. Fixed edit page count.
Modified paths:
  • /trunk/extensions/Favorites/FavParser.php (modified) (history)
  • /trunk/extensions/Favorites/FavoritedItem.php (modified) (history)
  • /trunk/extensions/Favorites/FavoritelistEditor.php (modified) (history)
  • /trunk/extensions/Favorites/Favorites.php (modified) (history)
  • /trunk/extensions/Favorites/SpecialFavoritelist.php (modified) (history)
  • /trunk/extensions/Favorites/favorites.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Favorites/FavParser.php
@@ -2,58 +2,66 @@
33
44 class FavParser {
55
6 -function wfSpecialFavoritelist() {
 6+ function wfSpecialFavoritelist($argv, $parser) {
 7+
 8+ global $wgUser, $wgOut, $wgLang, $wgRequest;
 9+ global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, $wgShowUpdatedMarker;
 10+ $output = '';
711
8 - global $wgUser, $wgOut, $wgLang, $wgRequest;
9 - global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, $wgShowUpdatedMarker;
10 - $output = '';
11 -
12 - $skin = $wgUser->getSkin();
13 - $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' );
14 - //$wgOut->setRobotPolicy( 'noindex,nofollow' );
15 -
16 - # Anons don't get a favoritelist
17 - if( $wgUser->isAnon() ) {
18 - //$wgOut->setPageTitle( wfMsg( 'favoritenologin' ) );
19 - $llink = $skin->linkKnown(
20 - SpecialPage::getTitleFor( 'Userlogin' ),
21 - wfMsg( 'loginreqlink' ),
22 - array(),
23 - array( 'returnto' => $specialTitle->getPrefixedText() )
24 - );
25 - $output = wfMsgHtml( 'favoritelistanontext', $llink ) ;
 12+ $skin = $wgUser->getSkin();
 13+ $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' );
 14+ //$wgOut->setRobotPolicy( 'noindex,nofollow' );
 15+
 16+ # Anons don't get a favoritelist
 17+ if( $wgUser->isAnon() ) {
 18+ //$wgOut->setPageTitle( wfMsg( 'favoritenologin' ) );
 19+ $llink = $skin->linkKnown(
 20+ SpecialPage::getTitleFor( 'Userlogin' ),
 21+ wfMsg( 'loginreqlink' ),
 22+ array(),
 23+ array( 'returnto' => $specialTitle->getPrefixedText() )
 24+ );
 25+ $output = wfMsgHtml( 'favoritelistanontext', $llink ) ;
 26+
 27+
 28+ return $output ;
 29+
 30+ }
 31+
 32+ $output = $this->viewFavList($wgUser, $output, $wgRequest);
 33+ if ( array_key_exists('editlink', $argv) && $argv['editlink']) {
 34+ # Add an edit link if you want it:
 35+ $output .= "<div id='contentSub'><br>" .
 36+ $skin->link(
 37+ SpecialPage::getTitleFor( 'Favoritelist', 'edit' ),
 38+ wfMsgHtml( "favoritelisttools-edit" ),
 39+ array(),
 40+ array(),
 41+ array( 'known', 'noclasses' )
 42+ ) . "</div>";
 43+ }
 44+
2645 return $output ;
27 -
2846 }
2947
30 -
31 -
3248
33 - $output = $this->viewFavList($wgUser, $output, $wgRequest);
34 - return $output ;
35 -}
36 -
37 -
3849 private function viewFavList ($user, $output, $request) {
39 - global $wgUser, $wgOut, $wgLang, $wgRequest;
40 - $uid = $wgUser->getId();
41 - $output = $this->showNormalForm( $output, $user );
42 -
43 - $dbr = wfGetDB( DB_SLAVE, 'favoritelist' );
 50+ global $wgUser, $wgOut, $wgLang, $wgRequest;
 51+ $uid = $wgUser->getId();
 52+ $output = $this->showNormalForm( $output, $user );
4453
45 -
46 - $favoritelistCount = $dbr->selectField( 'favoritelist', 'COUNT(*)',
47 - array( 'fl_user' => $uid ), __METHOD__ );
48 - // Adjust for page X, talk:page X, which are both stored separately,
49 - // but treated together
50 - $nitems = floor($favoritelistCount);
51 -
52 - if( $nitems == 0 ) {
53 - $output = wfmsg('nofavoritelist');
 54+ $dbr = wfGetDB( DB_SLAVE, 'favoritelist' );
5455
 56+ $favoritelistCount = $dbr->selectField( 'favoritelist', 'COUNT(*)',
 57+ array( 'fl_user' => $uid ), __METHOD__ );
 58+ $nitems = floor($favoritelistCount);
 59+
 60+ if( $nitems == 0 ) {
 61+ $output = wfmsg('nofavoritelist');
 62+
 63+ }
 64+ return $output;
5565 }
56 - return $output;
57 -}
5866
5967
6068 /**
@@ -193,9 +201,10 @@
194202 * @param $user User
195203 */
196204 private function showNormalForm( $output, $user ) {
197 - global $wgUser;
 205+ global $wgUser, $wgOut;
 206+ $skin = $wgUser->getSkin();
198207 if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) {
199 - $form = $this->buildRemoveList( $user, $wgUser->getSkin() );
 208+ $form = $this->buildRemoveList( $user, $skin );
200209 $output .= $form ;
201210 return $output;
202211 }
@@ -209,15 +218,14 @@
210219 */
211220 private function buildRemoveList( $user, $skin ) {
212221 $list = "";
 222+ $list .= "<ul>\n";
213223 foreach( $this->getFavoritelistInfo( $user ) as $namespace => $pages ) {
214 -
215 - $list .= "<ul>\n";
216224 foreach( $pages as $dbkey => $redirect ) {
217225 $title = Title::makeTitleSafe( $namespace, $dbkey );
218226 $list .= $this->buildRemoveLine( $title, $redirect, $skin );
219227 }
220 - $list .= "</ul>\n";
221228 }
 229+ $list .= "</ul>\n";
222230 return $list;
223231 }
224232
Index: trunk/extensions/Favorites/SpecialFavoritelist.php
@@ -449,12 +449,16 @@
450450 */
451451 private function buildRemoveLine( $title, $redirect, $skin ) {
452452 global $wgLang;
453 -
 453+ # In case the user adds something unusual to their list using the raw editor
 454+ # We moved the Tools array completely into the "if( $title->exists() )" section.
 455+ $showlinks=false;
454456 $link = $skin->link( $title );
455457 if( $redirect )
456458 $link = '<span class="favoritelistredir">' . $link . '</span>';
457 - $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) );
 459+
458460 if( $title->exists() ) {
 461+ $showlinks = true;
 462+ $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) );
459463 $tools[] = $skin->link(
460464 $title,
461465 wfMsgHtml( 'history_short' ),
@@ -472,10 +476,15 @@
473477 array( 'known', 'noclasses' )
474478 );
475479 }
476 - return "<li>"
477 - //. Xml::check( 'titles[]', false, array( 'value' => $title->getPrefixedText() ) )
 480+
 481+ if ($showlinks) {
 482+ return "<li>"
478483 . $link . " (" . $wgLang->pipeList( $tools ) . ")" . "</li>\n";
 484+ } else {
 485+ return "<li>"
 486+ . $link . "</li>\n";
479487 }
 488+ }
480489
481490 /**
482491 * Show a form for editing the favoritelist in "raw" mode
Index: trunk/extensions/Favorites/favorites.i18n.php
@@ -60,7 +60,7 @@
6161 'favoritelistall2' => 'all',
6262
6363 # Favoritelist editor
64 -'favoritelistedit-numitems' => 'Your favorites contain {{PLURAL:$1|1 title|$1 titles}}, excluding talk pages.',
 64+'favoritelistedit-numitems' => 'Your favorites contain {{PLURAL:$1|1 title|$1 titles}}.',
6565 'favoritelistedit-noitems' => 'Your favorites contain no titles.',
6666 'favoritelistedit-normal-title' => 'Edit favorites',
6767 'favoritelistedit-normal-legend' => 'Remove titles from favorites',
@@ -120,7 +120,7 @@
121121 'tooltip-ca-unfavorite' => 'Entferne diese Seite von deiner Favoritenliste',
122122 'tooltip-favorite' => 'Füge diese Seite zu deiner Favoritenliste hinzu',
123123 'favoritelistall2' => 'alle',
124 - 'favoritelistedit-numitems' => 'Deine Favoritenliste enthält {{PLURAL:$1|einen Eintrag |$1 Einträge}}. Die Diskussionsseiten wurden dabei nicht mitgezählt.',
 124+ 'favoritelistedit-numitems' => 'Deine Favoritenliste enthält {{PLURAL:$1|einen Eintrag |$1 Einträge}}.',
125125 'favoritelistedit-noitems' => 'Deine Favoritenliste enthält keine Einträge.',
126126 'favoritelistedit-normal-title' => 'Favoritenliste bearbeiten',
127127 'favoritelistedit-normal-legend' => 'Einträge aus der Favoritenliste entfernen',
@@ -158,7 +158,7 @@
159159 'tooltip-ca-favorite' => 'Fügen Sie diese Seite zu Ihrer Favoritenliste hinzu',
160160 'tooltip-ca-unfavorite' => 'Entfernen Sie diese Seite von Ihrer Favoritenliste',
161161 'tooltip-favorite' => 'Fügen Sie diese Seite zu Ihrer Favoritenliste hinzu',
162 - 'favoritelistedit-numitems' => 'Ihre Favoritenliste enthält {{PLURAL:$1|einen Eintrag|$1 Einträge}}. Die Diskussionsseiten wurden dabei nicht mitgezählt.',
 162+ 'favoritelistedit-numitems' => 'Ihre Favoritenliste enthält {{PLURAL:$1|einen Eintrag|$1 Einträge}}.',
163163 'favoritelistedit-noitems' => 'Ihre Favoritenliste enthält keine Einträge.',
164164 'favoritelistedit-normal-explain' => 'Dies sind die Einträge Ihrer Favoritenliste.
165165 Um Einträge zu entfernen, markieren Sie die Kästchen neben den Einträgen und klicken Sie am Ende der Seite auf „{{int:Favoritelistedit-normal-submit}}“.
@@ -233,7 +233,7 @@
234234 'tooltip-ca-unfavorite' => 'Отстрани ја страницава од бендисаните',
235235 'tooltip-favorite' => 'Додај ја страницава во бендисаните',
236236 'favoritelistall2' => 'сите',
237 - 'favoritelistedit-numitems' => 'Во бендисаните има {{PLURAL:$1|1 наслов|$1 наслови}}, без страниците за разговор.',
 237+ 'favoritelistedit-numitems' => 'Во бендисаните има {{PLURAL:$1|1 наслов|$1 наслови}}.',
238238 'favoritelistedit-noitems' => 'Немате наслови во бендисаните.',
239239 'favoritelistedit-normal-title' => 'Уреди бендисани',
240240 'favoritelistedit-normal-legend' => 'Отстрани наслови од бендисаните',
@@ -320,7 +320,7 @@
321321 'tooltip-ca-unfavorite' => 'Remover esta página das páginas preferidas',
322322 'tooltip-favorite' => 'Adicionar esta página às suas preferidas',
323323 'favoritelistall2' => 'todas',
324 - 'favoritelistedit-numitems' => 'A sua lista de páginas preferidas contém {{PLURAL:$1|uma página|$1 páginas}}, excluindo páginas de discussão.',
 324+ 'favoritelistedit-numitems' => 'A sua lista de páginas preferidas contém {{PLURAL:$1|uma página|$1 páginas}}.',
325325 'favoritelistedit-noitems' => 'A sua lista de página preferidas está vazia.',
326326 'favoritelistedit-normal-title' => 'Editar a lista de preferidas',
327327 'favoritelistedit-normal-legend' => 'Remover páginas das preferidas',
Index: trunk/extensions/Favorites/FavoritedItem.php
@@ -89,7 +89,7 @@
9090 */
9191 public static function duplicateEntries( $ot, $nt ) {
9292 FavoritedItem::doDuplicateEntries( $ot->getSubjectPage(), $nt->getSubjectPage() );
93 - FavoritedItem::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );
 93+ //FavoritedItem::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );
9494 }
9595
9696 /**
Index: trunk/extensions/Favorites/FavoritelistEditor.php
@@ -150,7 +150,7 @@
151151 }
152152
153153 /**
154 - * Count the number of titles on a user's favoritelist, excluding talk pages
 154+ * Count the number of titles on a user's favoritelist
155155 *
156156 * @param $user User
157157 * @return int
@@ -159,11 +159,11 @@
160160 $dbr = wfGetDB( DB_MASTER );
161161 $res = $dbr->select( 'favoritelist', 'COUNT(*) AS count', array( 'fl_user' => $user->getId() ), __METHOD__ );
162162 $row = $dbr->fetchObject( $res );
163 - return ceil( $row->count / 2 ); // Paranoia
 163+ return ceil( $row->count);
164164 }
165165
166166 /**
167 - * Prepare a list of titles on a user's favoritelist (excluding talk pages)
 167+ * Prepare a list of titles on a user's favoritelist
168168 * and return an array of (prefixed) strings
169169 *
170170 * @param $user User
@@ -192,7 +192,7 @@
193193 }
194194
195195 /**
196 - * Get a list of titles on a user's favoritelist, excluding talk pages,
 196+ * Get a list of titles on a user's favoritelist,
197197 * and return as a two-dimensional array with namespace, title and
198198 * redirect status
199199 *
@@ -220,7 +220,7 @@
221221 $cache->addBadLinkObj( $title );
222222 }
223223 // Ignore non-talk
224 - if( !$title->isTalkPage() )
 224+ //if( !$title->isTalkPage() )
225225 $titles[$row->fl_namespace][$row->fl_title] = $row->page_is_redirect;
226226 }
227227 }
@@ -274,12 +274,6 @@
275275 if( $title instanceof Title ) {
276276 $rows[] = array(
277277 'fl_user' => $user->getId(),
278 - 'fl_namespace' => ( $title->getNamespace() & ~1 ),
279 - 'fl_title' => $title->getDBkey(),
280 - 'fl_notificationtimestamp' => null,
281 - );
282 - $rows[] = array(
283 - 'fl_user' => $user->getId(),
284278 'fl_namespace' => ( $title->getNamespace() | 1 ),
285279 'fl_title' => $title->getDBkey(),
286280 'fl_notificationtimestamp' => null,
@@ -308,15 +302,6 @@
309303 'favoritelist',
310304 array(
311305 'fl_user' => $user->getId(),
312 - 'fl_namespace' => ( $title->getNamespace() & ~1 ),
313 - 'fl_title' => $title->getDBkey(),
314 - ),
315 - __METHOD__
316 - );
317 - $dbw->delete(
318 - 'favoritelist',
319 - array(
320 - 'fl_user' => $user->getId(),
321306 'fl_namespace' => ( $title->getNamespace() | 1 ),
322307 'fl_title' => $title->getDBkey(),
323308 ),
@@ -370,12 +355,12 @@
371356 $list .= $skin->makeHeadLine( 2, ">", $anchor, $heading, "" );
372357 $toc .= $skin->tocLine( $anchor, $heading, $tocLength, 1 ) . $skin->tocLineEnd();
373358
374 - $list .= "<ul>\n";
 359+ $list .= "\n";
375360 foreach( $pages as $dbkey => $redirect ) {
376361 $title = Title::makeTitleSafe( $namespace, $dbkey );
377362 $list .= $this->buildRemoveLine( $title, $redirect, $skin );
378363 }
379 - $list .= "</ul>\n";
 364+ $list .= "\n";
380365 }
381366 // ISSUE: omit the TOC if the total number of titles is low?
382367 if( $tocLength > 1 ) {
@@ -407,12 +392,15 @@
408393 */
409394 private function buildRemoveLine( $title, $redirect, $skin ) {
410395 global $wgLang;
411 -
 396+ # In case the user adds something unusual to their list using the raw editor
 397+ # We moved the Tools array completely into the "if( $title->exists() )" section.
 398+ $showlinks=false;
412399 $link = $skin->link( $title );
413400 if( $redirect )
414401 $link = '<span class="favoritelistredir">' . $link . '</span>';
415 - $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) );
416402 if( $title->exists() ) {
 403+ $showlinks = true;
 404+ $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) );
417405 $tools[] = $skin->link(
418406 $title,
419407 wfMsgHtml( 'history_short' ),
@@ -430,10 +418,18 @@
431419 array( 'known', 'noclasses' )
432420 );
433421 }
434 - return "<li>"
435 - . Xml::check( 'titles[]', false, array( 'value' => $title->getPrefixedText() ) )
436 - . $link . " (" . $wgLang->pipeList( $tools ) . ")" . "</li>\n";
 422+
 423+ if ($showlinks) {
 424+ return
 425+ Xml::check( 'titles[]', false, array( 'value' => $title->getPrefixedText() ) )
 426+ . $link . " (" . $wgLang->pipeList( $tools ) . ")" . "\n<br>";
 427+ } else {
 428+ return
 429+ Xml::check( 'titles[]', false, array( 'value' => $title->getPrefixedText() ) )
 430+ . $link . "\n<br>";
437431 }
 432+
 433+ }
438434
439435 /**
440436 * Show a form for editing the favoritelist in "raw" mode
Index: trunk/extensions/Favorites/Favorites.php
@@ -22,7 +22,7 @@
2323 'name' => 'Favorites',
2424 'author' => 'Jeremy Lemley',
2525 'descriptionmsg' => 'favorites-desc',
26 - 'version' => '0.1.0',
 26+ 'version' => '0.1.4',
2727 'url' => "http://www.mediawiki.org/wiki/Extension:Favorites",
2828 );
2929
@@ -124,10 +124,10 @@
125125 # The parser function itself
126126 # The input parameters are wikitext with templates expanded
127127 # The output should be wikitext too
128 - $output = "Parser Output goes here.";
 128+ //$output = "Parser Output goes here.";
129129
130130 $favParse = new FavParser();
131 - $output = $favParse->wfSpecialFavoritelist();
 131+ $output = $favParse->wfSpecialFavoritelist($argv, $parser);
132132 $parser->disableCache();
133133 return $output;
134134

Status & tagging log