miscellaneous doxygen warnings
[lhc/web/wiklou.git] / includes / site / SitesTable.php
1 <?php
2
3 /**
4 * Represents the sites database table.
5 * All access to this table should be done through this class.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @since 1.21
23 *
24 * @file
25 * @ingroup Site
26 *
27 * @license GNU GPL v2+
28 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
29 */
30 class SitesTable extends ORMTable {
31
32 /**
33 * @see IORMTable::getName()
34 * @since 1.21
35 * @return string
36 */
37 public function getName() {
38 return 'sites';
39 }
40
41 /**
42 * @see IORMTable::getFieldPrefix()
43 * @since 1.21
44 * @return string
45 */
46 public function getFieldPrefix() {
47 return 'site_';
48 }
49
50 /**
51 * @see IORMTable::getRowClass()
52 * @since 1.21
53 * @return string
54 */
55 public function getRowClass() {
56 return 'SiteObject';
57 }
58
59 /**
60 * @see IORMTable::getFields()
61 * @since 1.21
62 * @return array
63 */
64 public function getFields() {
65 return array(
66 'id' => 'id',
67
68 // Site data
69 'global_key' => 'str',
70 'type' => 'str',
71 'group' => 'str',
72 'source' => 'str',
73 'language' => 'str',
74 'protocol' => 'str',
75 'domain' => 'str',
76 'data' => 'array',
77
78 // Site config
79 'forward' => 'bool',
80 'config' => 'array',
81 );
82 }
83
84 /**
85 * @see IORMTable::getDefaults()
86 * @since 1.21
87 * @return array
88 */
89 public function getDefaults() {
90 return array(
91 'type' => Site::TYPE_UNKNOWN,
92 'group' => Site::GROUP_NONE,
93 'source' => Site::SOURCE_LOCAL,
94 'data' => array(),
95
96 'forward' => false,
97 'config' => array(),
98 );
99 }
100
101 /**
102 * Returns the class name for the provided site type.
103 *
104 * @since 1.21
105 *
106 * @param integer $siteType
107 *
108 * @return string
109 */
110 protected static function getClassForType( $siteType ) {
111 global $wgSiteTypes;
112 return array_key_exists( $siteType, $wgSiteTypes ) ? $wgSiteTypes[$siteType] : 'SiteObject';
113 }
114
115 /**
116 * Factory method to construct a new Site instance.
117 *
118 * @since 1.21
119 *
120 * @param array $data
121 * @param boolean $loadDefaults
122 *
123 * @return Site
124 */
125 public function newRow( array $data, $loadDefaults = false ) {
126 if ( !array_key_exists( 'type', $data ) ) {
127 $data['type'] = Site::TYPE_UNKNOWN;
128 }
129
130 $class = static::getClassForType( $data['type'] );
131
132 return new $class( $this, $data, $loadDefaults );
133 }
134
135 }