r93239 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93238‎ | r93239 | r93240 >
Date:20:01, 26 July 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added links to watchlist to prefs and group admin, an display mesage when there are no results
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
@@ -60,7 +60,7 @@
6161 * @param string $arg
6262 */
6363 public function execute( $subPage ) {
64 - global $wgOut, $wgUser, $wgRequest, $wgLang;
 64+ global $wgOut, $wgUser;
6565
6666 $this->setHeaders();
6767 $this->outputHeader();
@@ -73,6 +73,35 @@
7474
7575 $this->registerUserView( $wgUser );
7676
 77+ $wgOut->addHTML( '<p>' );
 78+
 79+ if ( $wgUser->isAllowed( 'semanticwatchgroups' ) ) {
 80+ $wgOut->addHTML( wfMsgExt( 'swl-watchlist-can-mod-groups', 'parseinline', 'Special:WatchlistConditions' ) . '&#160' );
 81+ }
 82+
 83+ if ( $this->userHasWatchlistGroups( $wgUser ) ) {
 84+ $wgOut->addHTML( wfMsgExt( 'swl-watchlist-can-mod-prefs', 'parseinline', 'Special:Preferences#prefsection-swl' ) );
 85+ $wgOut->addHTML( '</p>' );
 86+
 87+ $this->getAndDisplaySets( $subPage );
 88+ }
 89+ else {
 90+ $wgOut->addHTML( wfMsgExt( 'swl-watchlist-no-groups', 'parseinline', 'Special:Preferences#prefsection-swl' ) );
 91+ $wgOut->addHTML( '</p>' );
 92+ }
 93+ }
 94+
 95+ /**
 96+ * Obtains the change sets and displays them by calling displayWatchlist.
 97+ * Also takes care of pagination and displaying appropriate message when there are no results.
 98+ *
 99+ * @since 0.1
 100+ *
 101+ * @param string $subPage
 102+ */
 103+ protected function getAndDisplaySets( $subPage ) {
 104+ global $wgRequest, $wgOut, $wgLang;
 105+
77106 $limit = $wgRequest->getInt( 'limit', 20 );
78107 $offset = $wgRequest->getInt( 'offset', 0 );
79108 $continue = $wgRequest->getVal( 'continue' );
@@ -91,16 +120,23 @@
92121 $newContinue = $changeSetData['query-continue']['semanticwatchlist']['swcontinue'];
93122 }
94123
95 - $wgOut->addHTML( '<p>' . wfMsgExt(
96 - 'swl-watchlist-position',
97 - array( 'parseinline' ),
98 - $wgLang->formatNum( count( $sets ) ),
99 - $wgLang->formatNum( $offset + 1 )
100 - ) . '</p>' );
 124+ if ( $offset != 0 || count( $sets ) > 0 ) {
 125+ $wgOut->addHTML( '<p>' . wfMsgExt(
 126+ 'swl-watchlist-position',
 127+ array( 'parseinline' ),
 128+ $wgLang->formatNum( count( $sets ) ),
 129+ $wgLang->formatNum( $offset + 1 )
 130+ ) . '</p>' );
 131+
 132+ $wgOut->addHTML( $this->getPagingControlHTML( $limit, $continue, $subPage, $newContinue, $offset ) );
 133+ }
101134
102 - $wgOut->addHTML( $this->getPagingControlHTML( $limit, $continue, $subPage, $newContinue, $offset ) );
103 -
104 - $this->displayWatchlist( $sets );
 135+ if ( count( $sets ) > 0 ) {
 136+ $this->displayWatchlist( $sets );
 137+ }
 138+ else {
 139+ $wgOut->addWikiMsg( 'swl-watchlist-no-items' );
 140+ }
105141 }
106142
107143 /**
@@ -380,4 +416,29 @@
381417 return $html;
382418 }
383419
 420+ /**
 421+ * Rteurns if the specified user has any watchlist groups in his notification list.
 422+ *
 423+ * @since 0.1
 424+ *
 425+ * @param User $user
 426+ *
 427+ * @return boolean
 428+ */
 429+ protected function userHasWatchlistGroups( User $user ) {
 430+ if ( !$user->isLoggedIn() ) {
 431+ return false;
 432+ }
 433+
 434+ $dbr = wfGetDB( DB_SLAVE );
 435+
 436+ $group = $dbr->selectRow(
 437+ 'swl_users_per_group',
 438+ array( 'upg_group_id' ),
 439+ array( 'upg_user_id' => $user->getId() )
 440+ );
 441+
 442+ return $group !== false;
 443+ }
 444+
384445 }
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
@@ -53,7 +53,11 @@
5454 'swl-watchlist-pagincontrol' => 'View ($1) ($2)',
5555 'swl-watchlist-firstn' => 'first $1',
5656 'swl-watchlist-firstn-title' => 'First $1 {{PLURAL:$1|result|results}}',
57 -
 57+ 'swl-watchlist-no-items' => 'You have no items on your watchlist.',
 58+ 'swl-watchlist-can-mod-groups' => 'You can [[$1|modify the watchlist groups]].',
 59+ 'swl-watchlist-can-mod-prefs' => 'You can [[$1|modify your watchlist preferences]].',
 60+ 'swl-watchlist-no-groups' => 'You are not yet watching any watchlist groups. [[$1|Modify your watchlist preferences]].',
 61+
5862 // Email
5963 'swl-email-propschanged' => 'Properties have changed at $1',
6064 'swl-email-propschanged-long' => "One or more properties you watch at '''$1''' have been changed by user '''$2''' at $4 on $5. You can view these and other changes on [$3 your semantic watchlist].",
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -290,8 +290,12 @@
291291 * Called after the personal URLs have been set up, before they are shown.
292292 * https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Manual:Hooks/PersonalUrls
293293 *
 294+ * @since 0.1
 295+ *
294296 * @param array $personal_urls
295297 * @param Title $title
 298+ *
 299+ * @return true
296300 */
297301 public static function onPersonalUrls( array &$personal_urls, Title &$title ) {
298302 if ( $GLOBALS['egSWLEnableTopLink'] ) {