r88463 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88462‎ | r88463 | r88464 >
Date:16:57, 20 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some fixes to ns handling
Modified paths:
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Group.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php
@@ -62,8 +62,6 @@
6363 return;
6464 }
6565
66 - //$wgOut->addHTML( Html::element( 'h3', array(), wfMsg( '' ) ) );
67 -
6866 $groupsHtml = array();
6967
7068 foreach ( SWLGroups::getAll() as $group ) {
@@ -134,7 +132,7 @@
135133 $namespaces = $group->getNamespaces();
136134
137135 foreach ( $namespaces as &$ns ) {
138 - $ns = MWNamespace::getCanonicalName( $ns );
 136+ $ns = $ns == 0 ? 'Main' : MWNamespace::getCanonicalName( $ns );
139137 }
140138
141139 return Html::rawElement(
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
@@ -19,7 +19,7 @@
2020
2121 protected $categories;
2222
23 - protected $namespaces;
 23+ protected $namespaces = array();
2424
2525 protected $properties;
2626
@@ -27,26 +27,70 @@
2828
2929 protected $watchingUsers = false;
3030
 31+ /**
 32+ * Creates a new instance of SWLGroup from a DB result.
 33+ *
 34+ * @since 0.1
 35+ *
 36+ * @param $group
 37+ *
 38+ * @return SWLGroup
 39+ */
3140 public static function newFromDBResult( $group ) {
3241 return new SWLGroup(
3342 $group->group_id,
3443 $group->group_name,
3544 $group->group_categories == '' ? array() : explode( '|', $group->group_categories ),
36 - $group->group_namespaces == '' ? array() : array_map( 'intval', explode( '|', $group->group_namespaces ) ),
 45+ $group->group_namespaces == '' ? array() : explode( '|', $group->group_namespaces ),
3746 $group->group_properties == '' ? array() : explode( '|', $group->group_properties ),
3847 $group->group_concepts == '' ? array() : explode( '|', $group->group_group_concepts )
3948 );
4049 }
4150
 51+ /**
 52+ * Constructor.
 53+ *
 54+ * @since 0.1
 55+ *
 56+ * @param integer $id Can be null for new groups
 57+ * @param string $name
 58+ * @param array $categories List of category names
 59+ * @param array $namespaces List of namespace names or IDs
 60+ * @param array $properties List of property names
 61+ * @param array $concepts List of concept names
 62+ */
4263 public function __construct( $id, $name, array $categories, array $namespaces, array $properties, array $concepts ) {
4364 $this->id = $id;
4465 $this->name = $name;
4566 $this->categories = $categories;
46 - $this->namespaces = $namespaces;
4767 $this->properties = $properties;
48 - $this->concepts = $concepts;
 68+ $this->concepts = $concepts;
 69+
 70+ foreach ( $namespaces as $ns ) {
 71+ if ( preg_match( "/^-?([0-9])+$/", $ns ) ) {
 72+ $this->namespaces[] = $ns;
 73+ }
 74+ elseif ( $ns == '' || strtolower( $ns ) == 'main' ) {
 75+ $this->namespaces[] = 0;
 76+ }
 77+ else {
 78+ $ns = MWNamespace::getCanonicalIndex( strtolower( $ns ) );
 79+
 80+ if ( !is_null( $ns ) ) {
 81+ $this->namespaces[] = $ns;
 82+ }
 83+ }
 84+ }
4985 }
5086
 87+ /**
 88+ * Writes the group to the database, either updating it
 89+ * when it already exists, or inserting it when it doesn't.
 90+ *
 91+ * @since 0.1
 92+ *
 93+ * @return boolean Success indicator
 94+ */
5195 public function writeToDB() {
5296 if ( is_null( $this->id ) ) {
5397 return $this->insertIntoDB();
@@ -56,6 +100,13 @@
57101 }
58102 }
59103
 104+ /**
 105+ * Updates the group in the database.
 106+ *
 107+ * @since 0.1
 108+ *
 109+ * @return boolean Success indicator
 110+ */
60111 protected function updateInDB() {
61112 $dbr = wfGetDB( DB_MASTER );
62113
@@ -72,6 +123,13 @@
73124 );
74125 }
75126
 127+ /**
 128+ * Inserts the group into the database.
 129+ *
 130+ * @since 0.1
 131+ *
 132+ * @return boolean Success indicator
 133+ */
76134 protected function insertIntoDB() {
77135 $dbr = wfGetDB( DB_MASTER );
78136

Status & tagging log