r93176 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93175‎ | r93176 | r93177 >
Date:13:40, 26 July 2011
Author:flohack
Status:deferred
Tags:
Comment:
Fixed parts of https://bugzilla.wikimedia.org/show_bug.cgi?id=30051 (old coding style for DB upgrades, function level docs)
Modified paths:
  • /trunk/extensions/CollabWatchlist/CollabWatchlist.php (modified) (history)
  • /trunk/extensions/CollabWatchlist/includes/CollabWatchlistEditor.php (modified) (history)
  • /trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CollabWatchlist/CollabWatchlist.php
@@ -36,15 +36,30 @@
3737 $wgHooks['GetPreferences'][] = 'fnCollabWatchlistPreferences';
3838
3939 function fnCollabWatchlistDbSchema() {
40 - global $wgExtNewTables;
41 - $wgSql = dirname( __FILE__ ) . '/sql/';
42 - $wgExtNewTables[] = array( 'collabwatchlist', $wgSql . 'collabwatchlist.sql' );
43 - $wgExtNewTables[] = array( 'collabwatchlistuser', $wgSql . 'collabwatchlistuser.sql' );
44 - $wgExtNewTables[] = array( 'collabwatchlistcategory', $wgSql . 'collabwatchlistcategory.sql' );
45 - $wgExtNewTables[] = array( 'collabwatchlistrevisiontag', $wgSql . 'collabwatchlistrevisiontag.sql' );
46 - $wgExtNewTables[] = array( 'collabwatchlisttag', $wgSql . 'collabwatchlisttag.sql' );
47 - $wgExtNewFields[] = array( 'change_tag', 'ct_id', $wgSql . 'patch-change_tag_id.sql' );
48 - return true;
 40+ $wgSql = dirname(__FILE__) . '/sql/';
 41+ if ( $updater === null ) { // <= 1.16 support
 42+ global $wgExtNewTables;
 43+ $wgExtNewTables[] = array('collabwatchlist', $wgSql . 'collabwatchlist.sql');
 44+ $wgExtNewTables[] = array('collabwatchlistuser', $wgSql . 'collabwatchlistuser.sql');
 45+ $wgExtNewTables[] = array('collabwatchlistcategory', $wgSql . 'collabwatchlistcategory.sql');
 46+ $wgExtNewTables[] = array('collabwatchlistrevisiontag', $wgSql . 'collabwatchlistrevisiontag.sql');
 47+ $wgExtNewTables[] = array('collabwatchlisttag', $wgSql . 'collabwatchlisttag.sql');
 48+ $wgExtNewFields[] = array('change_tag', 'ct_id', $wgSql . 'patch-change_tag_id.sql');
 49+ } else { // >= 1.17 support
 50+ $updater->addExtensionUpdate( array ( 'addTable', 'collabwatchlist',
 51+ $wgSql . 'collabwatchlist.sql', true ) );
 52+ $updater->addExtensionUpdate( array ( 'addTable', 'collabwatchlistuser',
 53+ $wgSql . 'collabwatchlistuser.sql', true ) );
 54+ $updater->addExtensionUpdate( array ( 'addTable', 'collabwatchlistcategory',
 55+ $wgSql . 'collabwatchlistcategory.sql', true ) );
 56+ $updater->addExtensionUpdate( array ( 'addTable', 'collabwatchlistrevisiontag',
 57+ $wgSql . 'collabwatchlistrevisiontag.sql', true ) );
 58+ $updater->addExtensionUpdate( array ( 'addTable', 'collabwatchlisttag',
 59+ $wgSql . 'collabwatchlisttag.sql', true ) );
 60+ $updater->addExtensionUpdate( array( 'modifyField', 'change_tag', 'ct_id',
 61+ $wgSql . 'patch-change_tag_id.sql', true ) );
 62+ }
 63+ return true;
4964 }
5065
5166 function fnCollabWatchlistPreferences( $user, &$preferences ) {
Index: trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php
@@ -1,9 +1,35 @@
22 <?php
 3+/**
 4+ * Implements Special:CollabWatchlist
 5+ *
 6+ * This program is free software; you can redistribute it and/or modify
 7+ * it under the terms of the GNU General Public License as published by
 8+ * the Free Software Foundation; either version 2 of the License, or
 9+ * (at your option) any later version.
 10+ *
 11+ * This program is distributed in the hope that it will be useful,
 12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+ * GNU General Public License for more details.
 15+ *
 16+ * You should have received a copy of the GNU General Public License along
 17+ * with this program; if not, write to the Free Software Foundation, Inc.,
 18+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 19+ * http://www.gnu.org/copyleft/gpl.html
 20+ *
 21+ * @file
 22+ * @ingroup SpecialPage CollabWatchlist
 23+ */
324 class SpecialCollabWatchlist extends SpecialPage {
425 function __construct() {
526 parent::__construct( 'CollabWatchlist' );
627 }
728
 29+ /**
 30+ * Main execution point
 31+ *
 32+ * @param $par Parameter passed to the page
 33+ */
834 function execute( $par ) {
935 global $wgUser, $wgOut, $wgLang, $wgRequest;
1036 global $wgRCShowWatchingUsers;
@@ -433,8 +459,14 @@
434460
435461 return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
436462 }
437 -
438 -
 463+
 464+ /**
 465+ * Creates a link for the days query parameter with hours
 466+ * @param $h The number of hours
 467+ * @param $page String: The name of the target page for the link
 468+ * @param $options Mixed: Additional query parameters
 469+ * @return String: Html for the link
 470+ */
439471 function wlHoursLink( $h, $page, $options = array() ) {
440472 global $wgUser, $wgLang, $wgContLang;
441473
@@ -452,6 +484,13 @@
453485 return $s;
454486 }
455487
 488+ /**
 489+ * Creates a link for the days query parameter with days
 490+ * @param $d The number of days
 491+ * @param $page String: The name of the target page for the link
 492+ * @param $options Mixed: Additional query parameters
 493+ * @return String: Html for the link
 494+ */
456495 function wlDaysLink( $d, $page, $options = array() ) {
457496 global $wgUser, $wgLang, $wgContLang;
458497
@@ -559,6 +598,16 @@
560599 return $tags;
561600 }
562601
 602+ /**
 603+ * Constructs the filter SQL clause for the given collaborative watchlist ids.
 604+ * It filters entries which are not relevant for the given watchlists. I.e.
 605+ * entries which don't belong to a category and are not listed explicitly as a
 606+ * page for one of the given watchlists.
 607+ * @param $rl_ids Array: A list of collaborative watchlist ids
 608+ * @param $catNameCol String: The name of the column containing category names
 609+ * @param $pageIdCol String: The name of the column containing page ids
 610+ * @return String: An SQL clause usable in the conditions parameter of $db->select()
 611+ */
563612 function wlGetFilterClauseForCollabWatchlistIds( $rl_ids, $catNameCol, $pageIdCol ) {
564613 $excludedCatPageIds = array();
565614 $includedCatPageIds = array();
@@ -583,7 +632,7 @@
584633 $includedPageIds[$row->cat_page_id] = $row->page_title;
585634 }
586635 }
587 -
 636+
588637 if ( $includedCatPageIds ) {
589638 $catTree = new CategoryTreeManip();
590639 $catTree->initialiseFromCategoryNames( array_values( $includedCatPageIds ) );
@@ -601,7 +650,13 @@
602651 }
603652 return $collabWatchlistClause;
604653 }
605 -
 654+
 655+ /**
 656+ * Constructs the user filter SQL clause for the given collaborative watchlist ids.
 657+ * It filters entries from the users of the given watchlists.
 658+ * @param $rl_ids Array: A list of collaborative watchlist ids
 659+ * @return String: An SQL clause usable in the conditions parameter of $db->select()
 660+ */
606661 function wlGetFilterClauseListUser( $rl_id ) {
607662 $excludedUserIds = array();
608663 $dbr = wfGetDB( DB_SLAVE );
@@ -620,6 +675,12 @@
621676 return $clause;
622677 }
623678
 679+ /**
 680+ * Runs $db->addQuotes() for each of the strings
 681+ * @param $db Database: The db object to use
 682+ * @param $strings Array: A list of strings to quote
 683+ * @return Array: The $strings quoted by $db->addQuotes()
 684+ */
624685 public static function addQuotes( $db, $strings ) {
625686 $result = array();
626687 foreach ( $strings as $string ) {
Index: trunk/extensions/CollabWatchlist/includes/CollabWatchlistEditor.php
@@ -66,7 +66,7 @@
6767 $toWatch = array_diff( $wanted, $current );
6868 $toUnwatch = array_diff( $current, $wanted );
6969 $toWatch = $this->watchTitles( $toWatch, $rlId );
70 - $this->unwatchTitles( $toUnwatch, $rlId );
 70+ $this->unwatchTitles( $toUnwatch, $rlId, $wgUser );
7171 if ( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 )
7272 $output->addHTML( wfMsgExt( 'collabwatchlistedit-raw-done', 'parse' ) );
7373 if ( ( $count = count( $toWatch ) ) > 0 ) {
@@ -168,7 +168,7 @@
169169 break;
170170 }
171171 $titles = $this->extractCollabWatchlistCategories( $request->getArray( 'titles' ) );
172 - $this->unwatchTitles( $titles, $rlId );
 172+ $this->unwatchTitles( $titles, $rlId, $wgUser );
173173 $output->addHTML( wfMsgExt( 'collabwatchlistedit-normal-done', 'parse',
174174 $GLOBALS['wgLang']->formatNum( count( $titles ) ) ) );
175175 $this->showTitles( $titles, $output, $wgUser->getSkin() );
@@ -863,7 +863,7 @@
864864 * @param $titles An array of strings
865865 * @param $rlId The id of the collaborative watchlist
866866 */
867 - private function unwatchTitles( $titles, $rlId ) {
 867+ private function unwatchTitles( $titles, $rlId, $user ) {
868868 $dbw = wfGetDB( DB_MASTER );
869869 foreach ( $titles as $title ) {
870870 $subtract = false;

Status & tagging log